blob: 3e68a0b865a3f344a2caea3222382c2536a5d776 [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
Chad Rosierd717a062012-09-21 22:21:26 +0000260 bool mnemonicIsValid(StringRef Mnemonic) {
261 return mnemonicIsValidImpl(Mnemonic);
262 }
263
Jim Grosbach47a0d522011-08-16 20:45:50 +0000264 unsigned checkTargetMatchPredicate(MCInst &Inst);
265
Jim Grosbach1355cf12011-07-26 17:10:22 +0000266 bool MatchAndEmitInstruction(SMLoc IDLoc,
267 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
268 MCStreamer &Out);
Chad Rosier038f3e32012-09-03 18:47:45 +0000269
Chad Rosier5d637d72012-09-05 01:15:43 +0000270 unsigned getMCInstOperandNum(unsigned Kind, MCInst &Inst,
Chad Rosier038f3e32012-09-03 18:47:45 +0000271 const SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier2cc97de2012-09-03 20:31:23 +0000272 unsigned OperandNum, unsigned &NumMCOperands) {
Chad Rosier5d637d72012-09-05 01:15:43 +0000273 return getMCInstOperandNumImpl(Kind, Inst, Operands, OperandNum, NumMCOperands);
Chad Rosier038f3e32012-09-03 18:47:45 +0000274 }
Kevin Enderbyca9c42c2009-09-15 00:27:25 +0000275};
Jim Grosbach16c74252010-10-29 14:46:02 +0000276} // end anonymous namespace
277
Chris Lattner3a697562010-10-28 17:20:03 +0000278namespace {
279
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000280/// ARMOperand - Instances of this class represent a parsed ARM machine
281/// instruction.
Bill Wendling146018f2010-11-06 21:42:12 +0000282class ARMOperand : public MCParsedAsmOperand {
Sean Callanan76264762010-04-02 22:27:05 +0000283 enum KindTy {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000284 k_CondCode,
285 k_CCOut,
286 k_ITCondMask,
287 k_CoprocNum,
288 k_CoprocReg,
Jim Grosbach9b8f2a02011-10-12 17:34:41 +0000289 k_CoprocOption,
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000290 k_Immediate,
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000291 k_MemBarrierOpt,
292 k_Memory,
293 k_PostIndexRegister,
294 k_MSRMask,
295 k_ProcIFlags,
Jim Grosbach460a9052011-10-07 23:56:00 +0000296 k_VectorIndex,
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000297 k_Register,
298 k_RegisterList,
299 k_DPRRegisterList,
300 k_SPRRegisterList,
Jim Grosbach862019c2011-10-18 23:02:30 +0000301 k_VectorList,
Jim Grosbach98b05a52011-11-30 01:09:44 +0000302 k_VectorListAllLanes,
Jim Grosbach7636bf62011-12-02 00:35:16 +0000303 k_VectorListIndexed,
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000304 k_ShiftedRegister,
305 k_ShiftedImmediate,
306 k_ShifterImmediate,
307 k_RotateImmediate,
308 k_BitfieldDescriptor,
309 k_Token
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000310 } Kind;
311
Sean Callanan76264762010-04-02 22:27:05 +0000312 SMLoc StartLoc, EndLoc;
Bill Wendling24d22d22010-11-18 21:50:54 +0000313 SmallVector<unsigned, 8> Registers;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000314
315 union {
316 struct {
Daniel Dunbar8462b302010-08-11 06:36:53 +0000317 ARMCC::CondCodes Val;
318 } CC;
319
320 struct {
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000321 unsigned Val;
322 } Cop;
323
324 struct {
Jim Grosbach9b8f2a02011-10-12 17:34:41 +0000325 unsigned Val;
326 } CoprocOption;
327
328 struct {
Jim Grosbach89df9962011-08-26 21:43:41 +0000329 unsigned Mask:4;
330 } ITMask;
331
332 struct {
333 ARM_MB::MemBOpt Val;
334 } MBOpt;
335
336 struct {
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000337 ARM_PROC::IFlags Val;
338 } IFlags;
339
340 struct {
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000341 unsigned Val;
342 } MMask;
343
344 struct {
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000345 const char *Data;
346 unsigned Length;
347 } Tok;
348
349 struct {
350 unsigned RegNum;
351 } Reg;
352
Jim Grosbach862019c2011-10-18 23:02:30 +0000353 // A vector register list is a sequential list of 1 to 4 registers.
354 struct {
355 unsigned RegNum;
356 unsigned Count;
Jim Grosbach7636bf62011-12-02 00:35:16 +0000357 unsigned LaneIndex;
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +0000358 bool isDoubleSpaced;
Jim Grosbach862019c2011-10-18 23:02:30 +0000359 } VectorList;
360
Bill Wendling8155e5b2010-11-06 22:19:43 +0000361 struct {
Jim Grosbach460a9052011-10-07 23:56:00 +0000362 unsigned Val;
363 } VectorIndex;
364
365 struct {
Kevin Enderbycfe07242009-10-13 22:19:02 +0000366 const MCExpr *Val;
367 } Imm;
Jim Grosbach16c74252010-10-29 14:46:02 +0000368
Daniel Dunbar6a5c22e2011-01-10 15:26:21 +0000369 /// Combined record for all forms of ARM address expressions.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000370 struct {
371 unsigned BaseRegNum;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000372 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
373 // was specified.
374 const MCConstantExpr *OffsetImm; // Offset immediate value
375 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
376 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
Jim Grosbach57dcb852011-10-11 17:29:55 +0000377 unsigned ShiftImm; // shift for OffsetReg.
378 unsigned Alignment; // 0 = no alignment specified
Jim Grosbacheeaf1c12011-12-19 18:31:43 +0000379 // n = alignment in bytes (2, 4, 8, 16, or 32)
Jim Grosbach7ce05792011-08-03 23:50:40 +0000380 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
Jim Grosbache53c87b2011-10-11 15:59:20 +0000381 } Memory;
Owen Anderson00828302011-03-18 22:50:18 +0000382
383 struct {
Jim Grosbach7ce05792011-08-03 23:50:40 +0000384 unsigned RegNum;
Jim Grosbachf4fa3d62011-08-05 21:28:30 +0000385 bool isAdd;
386 ARM_AM::ShiftOpc ShiftTy;
387 unsigned ShiftImm;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000388 } PostIdxReg;
389
390 struct {
Jim Grosbach580f4a92011-07-25 22:20:28 +0000391 bool isASR;
Jim Grosbache8606dc2011-07-13 17:50:29 +0000392 unsigned Imm;
Jim Grosbach580f4a92011-07-25 22:20:28 +0000393 } ShifterImm;
Jim Grosbache8606dc2011-07-13 17:50:29 +0000394 struct {
395 ARM_AM::ShiftOpc ShiftTy;
396 unsigned SrcReg;
397 unsigned ShiftReg;
398 unsigned ShiftImm;
Jim Grosbachaf6981f2011-07-25 20:49:51 +0000399 } RegShiftedReg;
Owen Anderson92a20222011-07-21 18:54:16 +0000400 struct {
401 ARM_AM::ShiftOpc ShiftTy;
402 unsigned SrcReg;
403 unsigned ShiftImm;
Jim Grosbachaf6981f2011-07-25 20:49:51 +0000404 } RegShiftedImm;
Jim Grosbach7e1547e2011-07-27 20:15:40 +0000405 struct {
406 unsigned Imm;
407 } RotImm;
Jim Grosbach293a2ee2011-07-28 21:34:26 +0000408 struct {
409 unsigned LSB;
410 unsigned Width;
411 } Bitfield;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000412 };
Jim Grosbach16c74252010-10-29 14:46:02 +0000413
Bill Wendling146018f2010-11-06 21:42:12 +0000414 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
415public:
Sean Callanan76264762010-04-02 22:27:05 +0000416 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
417 Kind = o.Kind;
418 StartLoc = o.StartLoc;
419 EndLoc = o.EndLoc;
420 switch (Kind) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000421 case k_CondCode:
Daniel Dunbar8462b302010-08-11 06:36:53 +0000422 CC = o.CC;
423 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000424 case k_ITCondMask:
Jim Grosbach89df9962011-08-26 21:43:41 +0000425 ITMask = o.ITMask;
426 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000427 case k_Token:
Daniel Dunbar8462b302010-08-11 06:36:53 +0000428 Tok = o.Tok;
Sean Callanan76264762010-04-02 22:27:05 +0000429 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000430 case k_CCOut:
431 case k_Register:
Sean Callanan76264762010-04-02 22:27:05 +0000432 Reg = o.Reg;
433 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000434 case k_RegisterList:
435 case k_DPRRegisterList:
436 case k_SPRRegisterList:
Bill Wendling24d22d22010-11-18 21:50:54 +0000437 Registers = o.Registers;
Bill Wendling8d5acb72010-11-06 19:56:04 +0000438 break;
Jim Grosbach862019c2011-10-18 23:02:30 +0000439 case k_VectorList:
Jim Grosbach98b05a52011-11-30 01:09:44 +0000440 case k_VectorListAllLanes:
Jim Grosbach7636bf62011-12-02 00:35:16 +0000441 case k_VectorListIndexed:
Jim Grosbach862019c2011-10-18 23:02:30 +0000442 VectorList = o.VectorList;
443 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000444 case k_CoprocNum:
445 case k_CoprocReg:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000446 Cop = o.Cop;
447 break;
Jim Grosbach9b8f2a02011-10-12 17:34:41 +0000448 case k_CoprocOption:
449 CoprocOption = o.CoprocOption;
450 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000451 case k_Immediate:
Sean Callanan76264762010-04-02 22:27:05 +0000452 Imm = o.Imm;
453 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000454 case k_MemBarrierOpt:
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +0000455 MBOpt = o.MBOpt;
456 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000457 case k_Memory:
Jim Grosbache53c87b2011-10-11 15:59:20 +0000458 Memory = o.Memory;
Sean Callanan76264762010-04-02 22:27:05 +0000459 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000460 case k_PostIndexRegister:
Jim Grosbach7ce05792011-08-03 23:50:40 +0000461 PostIdxReg = o.PostIdxReg;
462 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000463 case k_MSRMask:
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000464 MMask = o.MMask;
465 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000466 case k_ProcIFlags:
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000467 IFlags = o.IFlags;
Owen Anderson00828302011-03-18 22:50:18 +0000468 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000469 case k_ShifterImmediate:
Jim Grosbach580f4a92011-07-25 22:20:28 +0000470 ShifterImm = o.ShifterImm;
Owen Anderson00828302011-03-18 22:50:18 +0000471 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000472 case k_ShiftedRegister:
Jim Grosbachaf6981f2011-07-25 20:49:51 +0000473 RegShiftedReg = o.RegShiftedReg;
Jim Grosbache8606dc2011-07-13 17:50:29 +0000474 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000475 case k_ShiftedImmediate:
Jim Grosbachaf6981f2011-07-25 20:49:51 +0000476 RegShiftedImm = o.RegShiftedImm;
Owen Anderson92a20222011-07-21 18:54:16 +0000477 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000478 case k_RotateImmediate:
Jim Grosbach7e1547e2011-07-27 20:15:40 +0000479 RotImm = o.RotImm;
480 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000481 case k_BitfieldDescriptor:
Jim Grosbach293a2ee2011-07-28 21:34:26 +0000482 Bitfield = o.Bitfield;
483 break;
Jim Grosbach460a9052011-10-07 23:56:00 +0000484 case k_VectorIndex:
485 VectorIndex = o.VectorIndex;
486 break;
Sean Callanan76264762010-04-02 22:27:05 +0000487 }
488 }
Jim Grosbach16c74252010-10-29 14:46:02 +0000489
Sean Callanan76264762010-04-02 22:27:05 +0000490 /// getStartLoc - Get the location of the first token of this operand.
491 SMLoc getStartLoc() const { return StartLoc; }
492 /// getEndLoc - Get the location of the last token of this operand.
493 SMLoc getEndLoc() const { return EndLoc; }
Chad Rosier4a6203a2012-09-21 20:51:43 +0000494 /// getLocRange - Get the range between the first and last token of this
495 /// operand.
Benjamin Kramer362a05a2012-04-15 17:04:27 +0000496 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
497
Daniel Dunbar8462b302010-08-11 06:36:53 +0000498 ARMCC::CondCodes getCondCode() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000499 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbar8462b302010-08-11 06:36:53 +0000500 return CC.Val;
501 }
502
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000503 unsigned getCoproc() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000504 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +0000505 return Cop.Val;
506 }
507
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000508 StringRef getToken() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000509 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000510 return StringRef(Tok.Data, Tok.Length);
511 }
512
513 unsigned getReg() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000514 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling7729e062010-11-09 22:44:22 +0000515 return Reg.RegNum;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000516 }
517
Bill Wendling5fa22a12010-11-09 23:28:44 +0000518 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000519 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
520 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling24d22d22010-11-18 21:50:54 +0000521 return Registers;
Bill Wendling8d5acb72010-11-06 19:56:04 +0000522 }
523
Kevin Enderbycfe07242009-10-13 22:19:02 +0000524 const MCExpr *getImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000525 assert(isImm() && "Invalid access!");
Kevin Enderbycfe07242009-10-13 22:19:02 +0000526 return Imm.Val;
527 }
528
Jim Grosbach460a9052011-10-07 23:56:00 +0000529 unsigned getVectorIndex() const {
530 assert(Kind == k_VectorIndex && "Invalid access!");
531 return VectorIndex.Val;
532 }
533
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +0000534 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000535 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +0000536 return MBOpt.Val;
537 }
538
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000539 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000540 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +0000541 return IFlags.Val;
542 }
543
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000544 unsigned getMSRMask() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000545 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +0000546 return MMask.Val;
547 }
548
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000549 bool isCoprocNum() const { return Kind == k_CoprocNum; }
550 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach9b8f2a02011-10-12 17:34:41 +0000551 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000552 bool isCondCode() const { return Kind == k_CondCode; }
553 bool isCCOut() const { return Kind == k_CCOut; }
554 bool isITMask() const { return Kind == k_ITCondMask; }
555 bool isITCondCode() const { return Kind == k_CondCode; }
556 bool isImm() const { return Kind == k_Immediate; }
Jim Grosbach51222d12012-01-20 18:09:51 +0000557 bool isFPImm() const {
558 if (!isImm()) return false;
559 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
560 if (!CE) return false;
561 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
562 return Val != -1;
563 }
Jim Grosbach4050bc42011-12-22 22:19:05 +0000564 bool isFBits16() const {
565 if (!isImm()) return false;
566 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
567 if (!CE) return false;
568 int64_t Value = CE->getValue();
569 return Value >= 0 && Value <= 16;
570 }
571 bool isFBits32() const {
572 if (!isImm()) return false;
573 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
574 if (!CE) return false;
575 int64_t Value = CE->getValue();
576 return Value >= 1 && Value <= 32;
577 }
Jim Grosbacha77295d2011-09-08 22:07:06 +0000578 bool isImm8s4() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000579 if (!isImm()) return false;
Jim Grosbacha77295d2011-09-08 22:07:06 +0000580 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
581 if (!CE) return false;
582 int64_t Value = CE->getValue();
583 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
584 }
Jim Grosbach72f39f82011-08-24 21:22:15 +0000585 bool isImm0_1020s4() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000586 if (!isImm()) return false;
Jim Grosbach72f39f82011-08-24 21:22:15 +0000587 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
588 if (!CE) return false;
589 int64_t Value = CE->getValue();
590 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
591 }
592 bool isImm0_508s4() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000593 if (!isImm()) return false;
Jim Grosbach72f39f82011-08-24 21:22:15 +0000594 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
595 if (!CE) return false;
596 int64_t Value = CE->getValue();
597 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
598 }
Jim Grosbach4e53fe82012-04-05 20:57:13 +0000599 bool isImm0_508s4Neg() const {
600 if (!isImm()) return false;
601 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
602 if (!CE) return false;
603 int64_t Value = -CE->getValue();
604 // explicitly exclude zero. we want that to use the normal 0_508 version.
605 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
606 }
Jim Grosbach6b8f1e32011-06-27 23:54:06 +0000607 bool isImm0_255() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000608 if (!isImm()) return false;
Jim Grosbach6b8f1e32011-06-27 23:54:06 +0000609 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
610 if (!CE) return false;
611 int64_t Value = CE->getValue();
612 return Value >= 0 && Value < 256;
613 }
Jim Grosbach4e53fe82012-04-05 20:57:13 +0000614 bool isImm0_4095() const {
615 if (!isImm()) return false;
616 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
617 if (!CE) return false;
618 int64_t Value = CE->getValue();
619 return Value >= 0 && Value < 4096;
620 }
621 bool isImm0_4095Neg() const {
622 if (!isImm()) return false;
623 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
624 if (!CE) return false;
625 int64_t Value = -CE->getValue();
626 return Value > 0 && Value < 4096;
627 }
Jim Grosbach587f5062011-12-02 23:34:39 +0000628 bool isImm0_1() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000629 if (!isImm()) return false;
Jim Grosbach587f5062011-12-02 23:34:39 +0000630 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
631 if (!CE) return false;
632 int64_t Value = CE->getValue();
633 return Value >= 0 && Value < 2;
634 }
635 bool isImm0_3() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000636 if (!isImm()) return false;
Jim Grosbach587f5062011-12-02 23:34:39 +0000637 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
638 if (!CE) return false;
639 int64_t Value = CE->getValue();
640 return Value >= 0 && Value < 4;
641 }
Jim Grosbach83ab0702011-07-13 22:01:08 +0000642 bool isImm0_7() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000643 if (!isImm()) return false;
Jim Grosbach83ab0702011-07-13 22:01:08 +0000644 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
645 if (!CE) return false;
646 int64_t Value = CE->getValue();
647 return Value >= 0 && Value < 8;
648 }
649 bool isImm0_15() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000650 if (!isImm()) return false;
Jim Grosbach83ab0702011-07-13 22:01:08 +0000651 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
652 if (!CE) return false;
653 int64_t Value = CE->getValue();
654 return Value >= 0 && Value < 16;
655 }
Jim Grosbach7c6e42e2011-07-21 23:26:25 +0000656 bool isImm0_31() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000657 if (!isImm()) return false;
Jim Grosbach7c6e42e2011-07-21 23:26:25 +0000658 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
659 if (!CE) return false;
660 int64_t Value = CE->getValue();
661 return Value >= 0 && Value < 32;
662 }
Jim Grosbach730fe6c2011-12-08 01:30:04 +0000663 bool isImm0_63() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000664 if (!isImm()) return false;
Jim Grosbach730fe6c2011-12-08 01:30:04 +0000665 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
666 if (!CE) return false;
667 int64_t Value = CE->getValue();
668 return Value >= 0 && Value < 64;
669 }
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000670 bool isImm8() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000671 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000672 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
673 if (!CE) return false;
674 int64_t Value = CE->getValue();
675 return Value == 8;
676 }
677 bool isImm16() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000678 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000679 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
680 if (!CE) return false;
681 int64_t Value = CE->getValue();
682 return Value == 16;
683 }
684 bool isImm32() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000685 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000686 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
687 if (!CE) return false;
688 int64_t Value = CE->getValue();
689 return Value == 32;
690 }
Jim Grosbach6b044c22011-12-08 22:06:06 +0000691 bool isShrImm8() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000692 if (!isImm()) return false;
Jim Grosbach6b044c22011-12-08 22:06:06 +0000693 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
694 if (!CE) return false;
695 int64_t Value = CE->getValue();
696 return Value > 0 && Value <= 8;
697 }
698 bool isShrImm16() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000699 if (!isImm()) return false;
Jim Grosbach6b044c22011-12-08 22:06:06 +0000700 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
701 if (!CE) return false;
702 int64_t Value = CE->getValue();
703 return Value > 0 && Value <= 16;
704 }
705 bool isShrImm32() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000706 if (!isImm()) return false;
Jim Grosbach6b044c22011-12-08 22:06:06 +0000707 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
708 if (!CE) return false;
709 int64_t Value = CE->getValue();
710 return Value > 0 && Value <= 32;
711 }
712 bool isShrImm64() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000713 if (!isImm()) return false;
Jim Grosbach6b044c22011-12-08 22:06:06 +0000714 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
715 if (!CE) return false;
716 int64_t Value = CE->getValue();
717 return Value > 0 && Value <= 64;
718 }
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000719 bool isImm1_7() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000720 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000721 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
722 if (!CE) return false;
723 int64_t Value = CE->getValue();
724 return Value > 0 && Value < 8;
725 }
726 bool isImm1_15() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000727 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000728 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
729 if (!CE) return false;
730 int64_t Value = CE->getValue();
731 return Value > 0 && Value < 16;
732 }
733 bool isImm1_31() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000734 if (!isImm()) return false;
Jim Grosbach3b8991c2011-12-07 01:07:24 +0000735 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
736 if (!CE) return false;
737 int64_t Value = CE->getValue();
738 return Value > 0 && Value < 32;
739 }
Jim Grosbachf4943352011-07-25 23:09:14 +0000740 bool isImm1_16() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000741 if (!isImm()) return false;
Jim Grosbachf4943352011-07-25 23:09:14 +0000742 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
743 if (!CE) return false;
744 int64_t Value = CE->getValue();
745 return Value > 0 && Value < 17;
746 }
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000747 bool isImm1_32() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000748 if (!isImm()) return false;
Jim Grosbach4a5ffb32011-07-22 23:16:18 +0000749 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
750 if (!CE) return false;
751 int64_t Value = CE->getValue();
752 return Value > 0 && Value < 33;
753 }
Jim Grosbachee10ff82011-11-10 19:18:01 +0000754 bool isImm0_32() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000755 if (!isImm()) return false;
Jim Grosbachee10ff82011-11-10 19:18:01 +0000756 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
757 if (!CE) return false;
758 int64_t Value = CE->getValue();
759 return Value >= 0 && Value < 33;
760 }
Jim Grosbachfff76ee2011-07-13 20:10:10 +0000761 bool isImm0_65535() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000762 if (!isImm()) return false;
Jim Grosbachfff76ee2011-07-13 20:10:10 +0000763 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
764 if (!CE) return false;
765 int64_t Value = CE->getValue();
766 return Value >= 0 && Value < 65536;
767 }
Jim Grosbachffa32252011-07-19 19:13:28 +0000768 bool isImm0_65535Expr() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000769 if (!isImm()) return false;
Jim Grosbachffa32252011-07-19 19:13:28 +0000770 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
771 // If it's not a constant expression, it'll generate a fixup and be
772 // handled later.
773 if (!CE) return true;
774 int64_t Value = CE->getValue();
775 return Value >= 0 && Value < 65536;
776 }
Jim Grosbached838482011-07-26 16:24:27 +0000777 bool isImm24bit() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000778 if (!isImm()) return false;
Jim Grosbached838482011-07-26 16:24:27 +0000779 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
780 if (!CE) return false;
781 int64_t Value = CE->getValue();
782 return Value >= 0 && Value <= 0xffffff;
783 }
Jim Grosbach70939ee2011-08-17 21:51:27 +0000784 bool isImmThumbSR() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000785 if (!isImm()) return false;
Jim Grosbach70939ee2011-08-17 21:51:27 +0000786 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
787 if (!CE) return false;
788 int64_t Value = CE->getValue();
789 return Value > 0 && Value < 33;
790 }
Jim Grosbachf6c05252011-07-21 17:23:04 +0000791 bool isPKHLSLImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000792 if (!isImm()) return false;
Jim Grosbachf6c05252011-07-21 17:23:04 +0000793 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
794 if (!CE) return false;
795 int64_t Value = CE->getValue();
796 return Value >= 0 && Value < 32;
797 }
798 bool isPKHASRImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000799 if (!isImm()) return false;
Jim Grosbachf6c05252011-07-21 17:23:04 +0000800 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
801 if (!CE) return false;
802 int64_t Value = CE->getValue();
803 return Value > 0 && Value <= 32;
804 }
Jiangning Liu1fb27ec2012-08-02 08:13:13 +0000805 bool isAdrLabel() const {
806 // If we have an immediate that's not a constant, treat it as a label
807 // reference needing a fixup. If it is a constant, but it can't fit
808 // into shift immediate encoding, we reject it.
809 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
810 else return (isARMSOImm() || isARMSOImmNeg());
811 }
Jim Grosbach6bc1dbc2011-07-19 16:50:30 +0000812 bool isARMSOImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000813 if (!isImm()) return false;
Jim Grosbach6bc1dbc2011-07-19 16:50:30 +0000814 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
815 if (!CE) return false;
816 int64_t Value = CE->getValue();
817 return ARM_AM::getSOImmVal(Value) != -1;
818 }
Jim Grosbache70ec842011-10-28 22:50:54 +0000819 bool isARMSOImmNot() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000820 if (!isImm()) return false;
Jim Grosbache70ec842011-10-28 22:50:54 +0000821 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
822 if (!CE) return false;
823 int64_t Value = CE->getValue();
824 return ARM_AM::getSOImmVal(~Value) != -1;
825 }
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000826 bool isARMSOImmNeg() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000827 if (!isImm()) return false;
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000828 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
829 if (!CE) return false;
830 int64_t Value = CE->getValue();
Jim Grosbachad353c62012-03-30 19:59:02 +0000831 // Only use this when not representable as a plain so_imm.
832 return ARM_AM::getSOImmVal(Value) == -1 &&
833 ARM_AM::getSOImmVal(-Value) != -1;
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000834 }
Jim Grosbach6b8f1e32011-06-27 23:54:06 +0000835 bool isT2SOImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000836 if (!isImm()) return false;
Jim Grosbach6b8f1e32011-06-27 23:54:06 +0000837 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
838 if (!CE) return false;
839 int64_t Value = CE->getValue();
840 return ARM_AM::getT2SOImmVal(Value) != -1;
841 }
Jim Grosbach89a63372011-10-28 22:36:30 +0000842 bool isT2SOImmNot() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000843 if (!isImm()) return false;
Jim Grosbach89a63372011-10-28 22:36:30 +0000844 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
845 if (!CE) return false;
846 int64_t Value = CE->getValue();
847 return ARM_AM::getT2SOImmVal(~Value) != -1;
848 }
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000849 bool isT2SOImmNeg() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000850 if (!isImm()) return false;
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000851 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
852 if (!CE) return false;
853 int64_t Value = CE->getValue();
Jim Grosbachad353c62012-03-30 19:59:02 +0000854 // Only use this when not representable as a plain so_imm.
855 return ARM_AM::getT2SOImmVal(Value) == -1 &&
856 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +0000857 }
Jim Grosbachc27d4f92011-07-22 17:44:50 +0000858 bool isSetEndImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000859 if (!isImm()) return false;
Jim Grosbachc27d4f92011-07-22 17:44:50 +0000860 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
861 if (!CE) return false;
862 int64_t Value = CE->getValue();
863 return Value == 1 || Value == 0;
864 }
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000865 bool isReg() const { return Kind == k_Register; }
866 bool isRegList() const { return Kind == k_RegisterList; }
867 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
868 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
869 bool isToken() const { return Kind == k_Token; }
870 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
Chad Rosier3d1f75a2012-09-11 23:02:35 +0000871 bool isMem() const { return Kind == k_Memory; }
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000872 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
873 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
874 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
875 bool isRotImm() const { return Kind == k_RotateImmediate; }
876 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
877 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachf4fa3d62011-08-05 21:28:30 +0000878 bool isPostIdxReg() const {
Jim Grosbach430052b2011-11-14 17:52:47 +0000879 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachf4fa3d62011-08-05 21:28:30 +0000880 }
Jim Grosbach57dcb852011-10-11 17:29:55 +0000881 bool isMemNoOffset(bool alignOK = false) const {
Chad Rosier3d1f75a2012-09-11 23:02:35 +0000882 if (!isMem())
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000883 return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000884 // No offset of any kind.
Jim Grosbach57dcb852011-10-11 17:29:55 +0000885 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
886 (alignOK || Memory.Alignment == 0);
887 }
Jim Grosbach0b4c6732012-01-18 22:46:46 +0000888 bool isMemPCRelImm12() const {
Chad Rosier3d1f75a2012-09-11 23:02:35 +0000889 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach0b4c6732012-01-18 22:46:46 +0000890 return false;
891 // Base register must be PC.
892 if (Memory.BaseRegNum != ARM::PC)
893 return false;
894 // Immediate offset in range [-4095, 4095].
895 if (!Memory.OffsetImm) return true;
896 int64_t Val = Memory.OffsetImm->getValue();
897 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
898 }
Jim Grosbach57dcb852011-10-11 17:29:55 +0000899 bool isAlignedMemory() const {
900 return isMemNoOffset(true);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +0000901 }
Jim Grosbach7ce05792011-08-03 23:50:40 +0000902 bool isAddrMode2() const {
Chad Rosier3d1f75a2012-09-11 23:02:35 +0000903 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000904 // Check for register offset.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000905 if (Memory.OffsetRegNum) return true;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000906 // Immediate offset in range [-4095, 4095].
Jim Grosbache53c87b2011-10-11 15:59:20 +0000907 if (!Memory.OffsetImm) return true;
908 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach7ce05792011-08-03 23:50:40 +0000909 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +0000910 }
Jim Grosbach039c2e12011-08-04 23:01:30 +0000911 bool isAM2OffsetImm() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +0000912 if (!isImm()) return false;
Jim Grosbach039c2e12011-08-04 23:01:30 +0000913 // Immediate offset in range [-4095, 4095].
914 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
915 if (!CE) return false;
916 int64_t Val = CE->getValue();
917 return Val > -4096 && Val < 4096;
918 }
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000919 bool isAddrMode3() const {
Jim Grosbach2f196742011-12-19 23:06:24 +0000920 // If we have an immediate that's not a constant, treat it as a label
921 // reference needing a fixup. If it is a constant, it's something else
922 // and we reject it.
Jim Grosbach21bcca82011-12-22 22:02:35 +0000923 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach2f196742011-12-19 23:06:24 +0000924 return true;
Chad Rosier3d1f75a2012-09-11 23:02:35 +0000925 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000926 // No shifts are legal for AM3.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000927 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000928 // Check for register offset.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000929 if (Memory.OffsetRegNum) return true;
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000930 // Immediate offset in range [-255, 255].
Jim Grosbache53c87b2011-10-11 15:59:20 +0000931 if (!Memory.OffsetImm) return true;
932 int64_t Val = Memory.OffsetImm->getValue();
Silviu Barangaca3cd412012-05-11 09:10:54 +0000933 // The #-0 offset is encoded as INT32_MIN, and we have to check
934 // for this too.
935 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000936 }
937 bool isAM3Offset() const {
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000938 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000939 return false;
Jim Grosbach21ff17c2011-10-07 23:24:09 +0000940 if (Kind == k_PostIndexRegister)
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000941 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
942 // Immediate offset in range [-255, 255].
943 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
944 if (!CE) return false;
945 int64_t Val = CE->getValue();
Jim Grosbach251bf252011-08-10 21:56:18 +0000946 // Special case, #-0 is INT32_MIN.
947 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach2fd2b872011-08-10 20:29:19 +0000948 }
Jim Grosbach7ce05792011-08-03 23:50:40 +0000949 bool isAddrMode5() const {
Jim Grosbach681460f2011-11-01 01:24:45 +0000950 // If we have an immediate that's not a constant, treat it as a label
951 // reference needing a fixup. If it is a constant, it's something else
952 // and we reject it.
Jim Grosbach21bcca82011-12-22 22:02:35 +0000953 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach681460f2011-11-01 01:24:45 +0000954 return true;
Chad Rosier3d1f75a2012-09-11 23:02:35 +0000955 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000956 // Check for register offset.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000957 if (Memory.OffsetRegNum) return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +0000958 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000959 if (!Memory.OffsetImm) return true;
960 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson0da10cf2011-08-29 19:36:44 +0000961 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbach681460f2011-11-01 01:24:45 +0000962 Val == INT32_MIN;
Bill Wendling87f4f9a2010-11-08 23:49:57 +0000963 }
Jim Grosbach7f739be2011-09-19 22:21:13 +0000964 bool isMemTBB() const {
Chad Rosier3d1f75a2012-09-11 23:02:35 +0000965 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbach57dcb852011-10-11 17:29:55 +0000966 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach7f739be2011-09-19 22:21:13 +0000967 return false;
968 return true;
969 }
970 bool isMemTBH() const {
Chad Rosier3d1f75a2012-09-11 23:02:35 +0000971 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbach57dcb852011-10-11 17:29:55 +0000972 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
973 Memory.Alignment != 0 )
Jim Grosbach7f739be2011-09-19 22:21:13 +0000974 return false;
975 return true;
976 }
Jim Grosbach7ce05792011-08-03 23:50:40 +0000977 bool isMemRegOffset() const {
Chad Rosier3d1f75a2012-09-11 23:02:35 +0000978 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendlingf4caf692010-12-14 03:36:38 +0000979 return false;
Daniel Dunbard3df5f32011-01-18 05:34:11 +0000980 return true;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000981 }
Jim Grosbachab899c12011-09-07 23:10:15 +0000982 bool isT2MemRegOffset() const {
Chad Rosier3d1f75a2012-09-11 23:02:35 +0000983 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbach57dcb852011-10-11 17:29:55 +0000984 Memory.Alignment != 0)
Jim Grosbachab899c12011-09-07 23:10:15 +0000985 return false;
986 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbache53c87b2011-10-11 15:59:20 +0000987 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbachab899c12011-09-07 23:10:15 +0000988 return true;
Jim Grosbache53c87b2011-10-11 15:59:20 +0000989 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbachab899c12011-09-07 23:10:15 +0000990 return false;
991 return true;
992 }
Jim Grosbach7ce05792011-08-03 23:50:40 +0000993 bool isMemThumbRR() const {
994 // Thumb reg+reg addressing is simple. Just two registers, a base and
995 // an offset. No shifts, negations or any other complicating factors.
Chad Rosier3d1f75a2012-09-11 23:02:35 +0000996 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbach57dcb852011-10-11 17:29:55 +0000997 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendlingef4a68b2010-11-30 07:44:32 +0000998 return false;
Jim Grosbache53c87b2011-10-11 15:59:20 +0000999 return isARMLowRegister(Memory.BaseRegNum) &&
1000 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach60f91a32011-08-19 17:55:24 +00001001 }
1002 bool isMemThumbRIs4() const {
Chad Rosier3d1f75a2012-09-11 23:02:35 +00001003 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbach57dcb852011-10-11 17:29:55 +00001004 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach60f91a32011-08-19 17:55:24 +00001005 return false;
1006 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001007 if (!Memory.OffsetImm) return true;
1008 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachecd85892011-08-19 18:13:48 +00001009 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1010 }
Jim Grosbach38466302011-08-19 18:55:51 +00001011 bool isMemThumbRIs2() const {
Chad Rosier3d1f75a2012-09-11 23:02:35 +00001012 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbach57dcb852011-10-11 17:29:55 +00001013 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach38466302011-08-19 18:55:51 +00001014 return false;
1015 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001016 if (!Memory.OffsetImm) return true;
1017 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach38466302011-08-19 18:55:51 +00001018 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1019 }
Jim Grosbach48ff5ff2011-08-19 18:49:59 +00001020 bool isMemThumbRIs1() const {
Chad Rosier3d1f75a2012-09-11 23:02:35 +00001021 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbach57dcb852011-10-11 17:29:55 +00001022 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach48ff5ff2011-08-19 18:49:59 +00001023 return false;
1024 // Immediate offset in range [0, 31].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001025 if (!Memory.OffsetImm) return true;
1026 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach48ff5ff2011-08-19 18:49:59 +00001027 return Val >= 0 && Val <= 31;
1028 }
Jim Grosbachecd85892011-08-19 18:13:48 +00001029 bool isMemThumbSPI() const {
Chad Rosier3d1f75a2012-09-11 23:02:35 +00001030 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbach57dcb852011-10-11 17:29:55 +00001031 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbachecd85892011-08-19 18:13:48 +00001032 return false;
1033 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001034 if (!Memory.OffsetImm) return true;
1035 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachecd85892011-08-19 18:13:48 +00001036 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendlingef4a68b2010-11-30 07:44:32 +00001037 }
Jim Grosbacha77295d2011-09-08 22:07:06 +00001038 bool isMemImm8s4Offset() const {
Jim Grosbach2f196742011-12-19 23:06:24 +00001039 // If we have an immediate that's not a constant, treat it as a label
1040 // reference needing a fixup. If it is a constant, it's something else
1041 // and we reject it.
Jim Grosbach21bcca82011-12-22 22:02:35 +00001042 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach2f196742011-12-19 23:06:24 +00001043 return true;
Chad Rosier3d1f75a2012-09-11 23:02:35 +00001044 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha77295d2011-09-08 22:07:06 +00001045 return false;
1046 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001047 if (!Memory.OffsetImm) return true;
1048 int64_t Val = Memory.OffsetImm->getValue();
Jiangning Liufd652df2012-08-02 08:29:50 +00001049 // Special case, #-0 is INT32_MIN.
1050 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
Jim Grosbacha77295d2011-09-08 22:07:06 +00001051 }
Jim Grosbachb6aed502011-09-09 18:37:27 +00001052 bool isMemImm0_1020s4Offset() const {
Chad Rosier3d1f75a2012-09-11 23:02:35 +00001053 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachb6aed502011-09-09 18:37:27 +00001054 return false;
1055 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001056 if (!Memory.OffsetImm) return true;
1057 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachb6aed502011-09-09 18:37:27 +00001058 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1059 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00001060 bool isMemImm8Offset() const {
Chad Rosier3d1f75a2012-09-11 23:02:35 +00001061 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7ce05792011-08-03 23:50:40 +00001062 return false;
Jim Grosbach0b4c6732012-01-18 22:46:46 +00001063 // Base reg of PC isn't allowed for these encodings.
1064 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +00001065 // Immediate offset in range [-255, 255].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001066 if (!Memory.OffsetImm) return true;
1067 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson4d2a0012011-09-23 22:25:02 +00001068 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbach7ce05792011-08-03 23:50:40 +00001069 }
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001070 bool isMemPosImm8Offset() const {
Chad Rosier3d1f75a2012-09-11 23:02:35 +00001071 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001072 return false;
1073 // Immediate offset in range [0, 255].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001074 if (!Memory.OffsetImm) return true;
1075 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001076 return Val >= 0 && Val < 256;
1077 }
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001078 bool isMemNegImm8Offset() const {
Chad Rosier3d1f75a2012-09-11 23:02:35 +00001079 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001080 return false;
Jim Grosbach0b4c6732012-01-18 22:46:46 +00001081 // Base reg of PC isn't allowed for these encodings.
1082 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001083 // Immediate offset in range [-255, -1].
Jim Grosbachdf33e0d2011-12-06 04:49:29 +00001084 if (!Memory.OffsetImm) return false;
Jim Grosbache53c87b2011-10-11 15:59:20 +00001085 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachdf33e0d2011-12-06 04:49:29 +00001086 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001087 }
1088 bool isMemUImm12Offset() const {
Chad Rosier3d1f75a2012-09-11 23:02:35 +00001089 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001090 return false;
1091 // Immediate offset in range [0, 4095].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001092 if (!Memory.OffsetImm) return true;
1093 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001094 return (Val >= 0 && Val < 4096);
1095 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00001096 bool isMemImm12Offset() const {
Jim Grosbach09176e12011-08-08 20:59:31 +00001097 // If we have an immediate that's not a constant, treat it as a label
1098 // reference needing a fixup. If it is a constant, it's something else
1099 // and we reject it.
Jim Grosbach21bcca82011-12-22 22:02:35 +00001100 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach09176e12011-08-08 20:59:31 +00001101 return true;
1102
Chad Rosier3d1f75a2012-09-11 23:02:35 +00001103 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7ce05792011-08-03 23:50:40 +00001104 return false;
1105 // Immediate offset in range [-4095, 4095].
Jim Grosbache53c87b2011-10-11 15:59:20 +00001106 if (!Memory.OffsetImm) return true;
1107 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson0da10cf2011-08-29 19:36:44 +00001108 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbach7ce05792011-08-03 23:50:40 +00001109 }
1110 bool isPostIdxImm8() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001111 if (!isImm()) return false;
Jim Grosbach7ce05792011-08-03 23:50:40 +00001112 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1113 if (!CE) return false;
1114 int64_t Val = CE->getValue();
Owen Anderson63553c72011-08-29 17:17:09 +00001115 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbach7ce05792011-08-03 23:50:40 +00001116 }
Jim Grosbach2bd01182011-10-11 21:55:36 +00001117 bool isPostIdxImm8s4() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001118 if (!isImm()) return false;
Jim Grosbach2bd01182011-10-11 21:55:36 +00001119 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1120 if (!CE) return false;
1121 int64_t Val = CE->getValue();
1122 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1123 (Val == INT32_MIN);
1124 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00001125
Jim Grosbach21ff17c2011-10-07 23:24:09 +00001126 bool isMSRMask() const { return Kind == k_MSRMask; }
1127 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001128
Jim Grosbach0e387b22011-10-17 22:26:03 +00001129 // NEON operands.
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00001130 bool isSingleSpacedVectorList() const {
1131 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1132 }
1133 bool isDoubleSpacedVectorList() const {
1134 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1135 }
Jim Grosbach862019c2011-10-18 23:02:30 +00001136 bool isVecListOneD() const {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00001137 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach862019c2011-10-18 23:02:30 +00001138 return VectorList.Count == 1;
1139 }
1140
Jim Grosbach28f08c92012-03-05 19:33:30 +00001141 bool isVecListDPair() const {
1142 if (!isSingleSpacedVectorList()) return false;
1143 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1144 .contains(VectorList.RegNum));
1145 }
1146
Jim Grosbachcdcfa282011-10-21 20:02:19 +00001147 bool isVecListThreeD() const {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00001148 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachcdcfa282011-10-21 20:02:19 +00001149 return VectorList.Count == 3;
1150 }
1151
Jim Grosbachb6310312011-10-21 20:35:01 +00001152 bool isVecListFourD() const {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00001153 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachb6310312011-10-21 20:35:01 +00001154 return VectorList.Count == 4;
1155 }
1156
Jim Grosbachc3384c92012-03-05 21:43:40 +00001157 bool isVecListDPairSpaced() const {
Kevin Enderby9f2e1602012-03-20 17:41:51 +00001158 if (isSingleSpacedVectorList()) return false;
Jim Grosbachc3384c92012-03-05 21:43:40 +00001159 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1160 .contains(VectorList.RegNum));
1161 }
1162
Jim Grosbachc387fc62012-01-23 23:20:46 +00001163 bool isVecListThreeQ() const {
1164 if (!isDoubleSpacedVectorList()) return false;
1165 return VectorList.Count == 3;
1166 }
1167
Jim Grosbach7945ead2012-01-24 00:43:12 +00001168 bool isVecListFourQ() const {
1169 if (!isDoubleSpacedVectorList()) return false;
1170 return VectorList.Count == 4;
1171 }
1172
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001173 bool isSingleSpacedVectorAllLanes() const {
1174 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1175 }
1176 bool isDoubleSpacedVectorAllLanes() const {
1177 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1178 }
Jim Grosbach98b05a52011-11-30 01:09:44 +00001179 bool isVecListOneDAllLanes() const {
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001180 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach98b05a52011-11-30 01:09:44 +00001181 return VectorList.Count == 1;
1182 }
1183
Jim Grosbachc0fc4502012-03-06 22:01:44 +00001184 bool isVecListDPairAllLanes() const {
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001185 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachc0fc4502012-03-06 22:01:44 +00001186 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1187 .contains(VectorList.RegNum));
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001188 }
1189
Jim Grosbach4d0983a2012-03-06 23:10:38 +00001190 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbach3471d4f2011-12-21 00:38:54 +00001191 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach13af2222011-11-30 18:21:25 +00001192 return VectorList.Count == 2;
1193 }
1194
Jim Grosbach5e59f7e2012-01-24 23:47:04 +00001195 bool isVecListThreeDAllLanes() const {
1196 if (!isSingleSpacedVectorAllLanes()) return false;
1197 return VectorList.Count == 3;
1198 }
1199
1200 bool isVecListThreeQAllLanes() const {
1201 if (!isDoubleSpacedVectorAllLanes()) return false;
1202 return VectorList.Count == 3;
1203 }
1204
Jim Grosbacha57a36a2012-01-25 00:01:08 +00001205 bool isVecListFourDAllLanes() const {
1206 if (!isSingleSpacedVectorAllLanes()) return false;
1207 return VectorList.Count == 4;
1208 }
1209
1210 bool isVecListFourQAllLanes() const {
1211 if (!isDoubleSpacedVectorAllLanes()) return false;
1212 return VectorList.Count == 4;
1213 }
1214
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001215 bool isSingleSpacedVectorIndexed() const {
1216 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1217 }
1218 bool isDoubleSpacedVectorIndexed() const {
1219 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1220 }
Jim Grosbach7636bf62011-12-02 00:35:16 +00001221 bool isVecListOneDByteIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001222 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach7636bf62011-12-02 00:35:16 +00001223 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1224 }
1225
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001226 bool isVecListOneDHWordIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001227 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001228 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1229 }
1230
1231 bool isVecListOneDWordIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001232 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001233 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1234 }
1235
Jim Grosbach9b1b3902011-12-14 23:25:46 +00001236 bool isVecListTwoDByteIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001237 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00001238 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1239 }
1240
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001241 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001242 if (!isSingleSpacedVectorIndexed()) return false;
1243 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1244 }
1245
1246 bool isVecListTwoQWordIndexed() const {
1247 if (!isDoubleSpacedVectorIndexed()) return false;
1248 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1249 }
1250
1251 bool isVecListTwoQHWordIndexed() const {
1252 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001253 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1254 }
1255
1256 bool isVecListTwoDWordIndexed() const {
Jim Grosbach95fad1c2011-12-20 19:21:26 +00001257 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach799ca9d2011-12-14 23:35:06 +00001258 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1259 }
1260
Jim Grosbach3a678af2012-01-23 21:53:26 +00001261 bool isVecListThreeDByteIndexed() const {
1262 if (!isSingleSpacedVectorIndexed()) return false;
1263 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1264 }
1265
1266 bool isVecListThreeDHWordIndexed() const {
1267 if (!isSingleSpacedVectorIndexed()) return false;
1268 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1269 }
1270
1271 bool isVecListThreeQWordIndexed() const {
1272 if (!isDoubleSpacedVectorIndexed()) return false;
1273 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1274 }
1275
1276 bool isVecListThreeQHWordIndexed() const {
1277 if (!isDoubleSpacedVectorIndexed()) return false;
1278 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1279 }
1280
1281 bool isVecListThreeDWordIndexed() const {
1282 if (!isSingleSpacedVectorIndexed()) return false;
1283 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1284 }
1285
Jim Grosbache983a132012-01-24 18:37:25 +00001286 bool isVecListFourDByteIndexed() const {
1287 if (!isSingleSpacedVectorIndexed()) return false;
1288 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1289 }
1290
1291 bool isVecListFourDHWordIndexed() const {
1292 if (!isSingleSpacedVectorIndexed()) return false;
1293 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1294 }
1295
1296 bool isVecListFourQWordIndexed() const {
1297 if (!isDoubleSpacedVectorIndexed()) return false;
1298 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1299 }
1300
1301 bool isVecListFourQHWordIndexed() const {
1302 if (!isDoubleSpacedVectorIndexed()) return false;
1303 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1304 }
1305
1306 bool isVecListFourDWordIndexed() const {
1307 if (!isSingleSpacedVectorIndexed()) return false;
1308 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1309 }
1310
Jim Grosbach460a9052011-10-07 23:56:00 +00001311 bool isVectorIndex8() const {
1312 if (Kind != k_VectorIndex) return false;
1313 return VectorIndex.Val < 8;
1314 }
1315 bool isVectorIndex16() const {
1316 if (Kind != k_VectorIndex) return false;
1317 return VectorIndex.Val < 4;
1318 }
1319 bool isVectorIndex32() const {
1320 if (Kind != k_VectorIndex) return false;
1321 return VectorIndex.Val < 2;
1322 }
1323
Jim Grosbach0e387b22011-10-17 22:26:03 +00001324 bool isNEONi8splat() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001325 if (!isImm()) return false;
Jim Grosbach0e387b22011-10-17 22:26:03 +00001326 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1327 // Must be a constant.
1328 if (!CE) return false;
1329 int64_t Value = CE->getValue();
1330 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1331 // value.
Jim Grosbach0e387b22011-10-17 22:26:03 +00001332 return Value >= 0 && Value < 256;
1333 }
Jim Grosbach460a9052011-10-07 23:56:00 +00001334
Jim Grosbachea461102011-10-17 23:09:09 +00001335 bool isNEONi16splat() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001336 if (!isImm()) return false;
Jim Grosbachea461102011-10-17 23:09:09 +00001337 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1338 // Must be a constant.
1339 if (!CE) return false;
1340 int64_t Value = CE->getValue();
1341 // i16 value in the range [0,255] or [0x0100, 0xff00]
1342 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1343 }
1344
Jim Grosbach6248a542011-10-18 00:22:00 +00001345 bool isNEONi32splat() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001346 if (!isImm()) return false;
Jim Grosbach6248a542011-10-18 00:22:00 +00001347 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1348 // Must be a constant.
1349 if (!CE) return false;
1350 int64_t Value = CE->getValue();
1351 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1352 return (Value >= 0 && Value < 256) ||
1353 (Value >= 0x0100 && Value <= 0xff00) ||
1354 (Value >= 0x010000 && Value <= 0xff0000) ||
1355 (Value >= 0x01000000 && Value <= 0xff000000);
1356 }
1357
1358 bool isNEONi32vmov() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001359 if (!isImm()) return false;
Jim Grosbach6248a542011-10-18 00:22:00 +00001360 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1361 // Must be a constant.
1362 if (!CE) return false;
1363 int64_t Value = CE->getValue();
1364 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1365 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1366 return (Value >= 0 && Value < 256) ||
1367 (Value >= 0x0100 && Value <= 0xff00) ||
1368 (Value >= 0x010000 && Value <= 0xff0000) ||
1369 (Value >= 0x01000000 && Value <= 0xff000000) ||
1370 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1371 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1372 }
Jim Grosbach9b087852011-12-19 23:51:07 +00001373 bool isNEONi32vmovNeg() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001374 if (!isImm()) return false;
Jim Grosbach9b087852011-12-19 23:51:07 +00001375 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1376 // Must be a constant.
1377 if (!CE) return false;
1378 int64_t Value = ~CE->getValue();
1379 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1380 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1381 return (Value >= 0 && Value < 256) ||
1382 (Value >= 0x0100 && Value <= 0xff00) ||
1383 (Value >= 0x010000 && Value <= 0xff0000) ||
1384 (Value >= 0x01000000 && Value <= 0xff000000) ||
1385 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1386 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1387 }
Jim Grosbach6248a542011-10-18 00:22:00 +00001388
Jim Grosbachf2f5bc62011-10-18 16:18:11 +00001389 bool isNEONi64splat() const {
Jim Grosbach21bcca82011-12-22 22:02:35 +00001390 if (!isImm()) return false;
Jim Grosbachf2f5bc62011-10-18 16:18:11 +00001391 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1392 // Must be a constant.
1393 if (!CE) return false;
1394 uint64_t Value = CE->getValue();
1395 // i64 value with each byte being either 0 or 0xff.
1396 for (unsigned i = 0; i < 8; ++i)
1397 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1398 return true;
1399 }
1400
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001401 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner14b93852010-10-29 00:27:31 +00001402 // Add as immediates when possible. Null MCExpr = 0.
1403 if (Expr == 0)
1404 Inst.addOperand(MCOperand::CreateImm(0));
1405 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001406 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1407 else
1408 Inst.addOperand(MCOperand::CreateExpr(Expr));
1409 }
1410
Daniel Dunbar8462b302010-08-11 06:36:53 +00001411 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar345a9a62010-08-11 06:37:20 +00001412 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbar8462b302010-08-11 06:36:53 +00001413 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach04f74942010-12-06 18:30:57 +00001414 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1415 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbar8462b302010-08-11 06:36:53 +00001416 }
1417
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00001418 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1419 assert(N == 1 && "Invalid number of operands!");
1420 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1421 }
1422
Jim Grosbach9b8f2a02011-10-12 17:34:41 +00001423 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1424 assert(N == 1 && "Invalid number of operands!");
1425 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1426 }
1427
1428 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1429 assert(N == 1 && "Invalid number of operands!");
1430 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1431 }
1432
Jim Grosbach89df9962011-08-26 21:43:41 +00001433 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1434 assert(N == 1 && "Invalid number of operands!");
1435 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1436 }
1437
1438 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1439 assert(N == 1 && "Invalid number of operands!");
1440 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1441 }
1442
Jim Grosbachd67641b2010-12-06 18:21:12 +00001443 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1444 assert(N == 1 && "Invalid number of operands!");
1445 Inst.addOperand(MCOperand::CreateReg(getReg()));
1446 }
1447
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00001448 void addRegOperands(MCInst &Inst, unsigned N) const {
1449 assert(N == 1 && "Invalid number of operands!");
1450 Inst.addOperand(MCOperand::CreateReg(getReg()));
1451 }
1452
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001453 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbache8606dc2011-07-13 17:50:29 +00001454 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach430052b2011-11-14 17:52:47 +00001455 assert(isRegShiftedReg() &&
1456 "addRegShiftedRegOperands() on non RegShiftedReg!");
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001457 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1458 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbache8606dc2011-07-13 17:50:29 +00001459 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001460 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbache8606dc2011-07-13 17:50:29 +00001461 }
1462
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001463 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson152d4a42011-07-21 23:38:37 +00001464 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach430052b2011-11-14 17:52:47 +00001465 assert(isRegShiftedImm() &&
1466 "addRegShiftedImmOperands() on non RegShiftedImm!");
Jim Grosbachaf6981f2011-07-25 20:49:51 +00001467 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonb56e4112012-04-25 18:00:18 +00001468 // Shift of #32 is encoded as 0 where permitted
1469 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Anderson92a20222011-07-21 18:54:16 +00001470 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonb56e4112012-04-25 18:00:18 +00001471 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Anderson92a20222011-07-21 18:54:16 +00001472 }
1473
Jim Grosbach580f4a92011-07-25 22:20:28 +00001474 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson00828302011-03-18 22:50:18 +00001475 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach580f4a92011-07-25 22:20:28 +00001476 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1477 ShifterImm.Imm));
Owen Anderson00828302011-03-18 22:50:18 +00001478 }
1479
Bill Wendling87f4f9a2010-11-08 23:49:57 +00001480 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling7729e062010-11-09 22:44:22 +00001481 assert(N == 1 && "Invalid number of operands!");
Bill Wendling5fa22a12010-11-09 23:28:44 +00001482 const SmallVectorImpl<unsigned> &RegList = getRegList();
1483 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +00001484 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1485 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling87f4f9a2010-11-08 23:49:57 +00001486 }
1487
Bill Wendling0f630752010-11-17 04:32:08 +00001488 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1489 addRegListOperands(Inst, N);
1490 }
1491
1492 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1493 addRegListOperands(Inst, N);
1494 }
1495
Jim Grosbach7e1547e2011-07-27 20:15:40 +00001496 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1497 assert(N == 1 && "Invalid number of operands!");
1498 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1499 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1500 }
1501
Jim Grosbach293a2ee2011-07-28 21:34:26 +00001502 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1503 assert(N == 1 && "Invalid number of operands!");
1504 // Munge the lsb/width into a bitfield mask.
1505 unsigned lsb = Bitfield.LSB;
1506 unsigned width = Bitfield.Width;
1507 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1508 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1509 (32 - (lsb + width)));
1510 Inst.addOperand(MCOperand::CreateImm(Mask));
1511 }
1512
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001513 void addImmOperands(MCInst &Inst, unsigned N) const {
1514 assert(N == 1 && "Invalid number of operands!");
1515 addExpr(Inst, getImm());
1516 }
Jim Grosbach16c74252010-10-29 14:46:02 +00001517
Jim Grosbach4050bc42011-12-22 22:19:05 +00001518 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1519 assert(N == 1 && "Invalid number of operands!");
1520 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1521 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1522 }
1523
1524 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1525 assert(N == 1 && "Invalid number of operands!");
1526 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1527 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1528 }
1529
Jim Grosbach9d390362011-10-03 23:38:36 +00001530 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1531 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach51222d12012-01-20 18:09:51 +00001532 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1533 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1534 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach9d390362011-10-03 23:38:36 +00001535 }
1536
Jim Grosbacha77295d2011-09-08 22:07:06 +00001537 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1538 assert(N == 1 && "Invalid number of operands!");
1539 // FIXME: We really want to scale the value here, but the LDRD/STRD
1540 // instruction don't encode operands that way yet.
1541 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1542 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1543 }
1544
Jim Grosbach72f39f82011-08-24 21:22:15 +00001545 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1546 assert(N == 1 && "Invalid number of operands!");
1547 // The immediate is scaled by four in the encoding and is stored
1548 // in the MCInst as such. Lop off the low two bits here.
1549 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1550 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1551 }
1552
Jim Grosbach4e53fe82012-04-05 20:57:13 +00001553 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1554 assert(N == 1 && "Invalid number of operands!");
1555 // The immediate is scaled by four in the encoding and is stored
1556 // in the MCInst as such. Lop off the low two bits here.
1557 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1558 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1559 }
1560
Jim Grosbach72f39f82011-08-24 21:22:15 +00001561 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1562 assert(N == 1 && "Invalid number of operands!");
1563 // The immediate is scaled by four in the encoding and is stored
1564 // in the MCInst as such. Lop off the low two bits here.
1565 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1566 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1567 }
1568
Jim Grosbachf4943352011-07-25 23:09:14 +00001569 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1570 assert(N == 1 && "Invalid number of operands!");
1571 // The constant encodes as the immediate-1, and we store in the instruction
1572 // the bits as encoded, so subtract off one here.
1573 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1574 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1575 }
1576
Jim Grosbach4a5ffb32011-07-22 23:16:18 +00001577 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1578 assert(N == 1 && "Invalid number of operands!");
1579 // The constant encodes as the immediate-1, and we store in the instruction
1580 // the bits as encoded, so subtract off one here.
1581 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1582 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1583 }
1584
Jim Grosbach70939ee2011-08-17 21:51:27 +00001585 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1586 assert(N == 1 && "Invalid number of operands!");
1587 // The constant encodes as the immediate, except for 32, which encodes as
1588 // zero.
1589 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1590 unsigned Imm = CE->getValue();
1591 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1592 }
1593
Jim Grosbachf6c05252011-07-21 17:23:04 +00001594 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1595 assert(N == 1 && "Invalid number of operands!");
1596 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1597 // the instruction as well.
1598 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1599 int Val = CE->getValue();
1600 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1601 }
1602
Jim Grosbach89a63372011-10-28 22:36:30 +00001603 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1604 assert(N == 1 && "Invalid number of operands!");
1605 // The operand is actually a t2_so_imm, but we have its bitwise
1606 // negation in the assembly source, so twiddle it here.
1607 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1608 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1609 }
1610
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +00001611 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1612 assert(N == 1 && "Invalid number of operands!");
1613 // The operand is actually a t2_so_imm, but we have its
1614 // negation in the assembly source, so twiddle it here.
1615 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1616 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1617 }
1618
Jim Grosbach4e53fe82012-04-05 20:57:13 +00001619 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1620 assert(N == 1 && "Invalid number of operands!");
1621 // The operand is actually an imm0_4095, but we have its
1622 // negation in the assembly source, so twiddle it here.
1623 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1624 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1625 }
1626
Jim Grosbache70ec842011-10-28 22:50:54 +00001627 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1628 assert(N == 1 && "Invalid number of operands!");
1629 // The operand is actually a so_imm, but we have its bitwise
1630 // negation in the assembly source, so twiddle it here.
1631 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1632 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1633 }
1634
Jim Grosbach3bc8a3d2011-12-08 00:31:07 +00001635 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1636 assert(N == 1 && "Invalid number of operands!");
1637 // The operand is actually a so_imm, but we have its
1638 // negation in the assembly source, so twiddle it here.
1639 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1640 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1641 }
1642
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00001643 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1644 assert(N == 1 && "Invalid number of operands!");
1645 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1646 }
1647
Jim Grosbach7ce05792011-08-03 23:50:40 +00001648 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1649 assert(N == 1 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001650 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +00001651 }
1652
Jim Grosbach0b4c6732012-01-18 22:46:46 +00001653 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1654 assert(N == 1 && "Invalid number of operands!");
1655 int32_t Imm = Memory.OffsetImm->getValue();
1656 // FIXME: Handle #-0
1657 if (Imm == INT32_MIN) Imm = 0;
1658 Inst.addOperand(MCOperand::CreateImm(Imm));
1659 }
1660
Jiangning Liu1fb27ec2012-08-02 08:13:13 +00001661 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1662 assert(N == 1 && "Invalid number of operands!");
1663 assert(isImm() && "Not an immediate!");
1664
1665 // If we have an immediate that's not a constant, treat it as a label
1666 // reference needing a fixup.
1667 if (!isa<MCConstantExpr>(getImm())) {
1668 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1669 return;
1670 }
1671
1672 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1673 int Val = CE->getValue();
1674 Inst.addOperand(MCOperand::CreateImm(Val));
1675 }
1676
Jim Grosbach57dcb852011-10-11 17:29:55 +00001677 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1678 assert(N == 2 && "Invalid number of operands!");
1679 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1680 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1681 }
1682
Jim Grosbach7ce05792011-08-03 23:50:40 +00001683 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1684 assert(N == 3 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001685 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1686 if (!Memory.OffsetRegNum) {
Jim Grosbach7ce05792011-08-03 23:50:40 +00001687 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1688 // Special case for #-0
1689 if (Val == INT32_MIN) Val = 0;
1690 if (Val < 0) Val = -Val;
1691 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1692 } else {
1693 // For register offset, we encode the shift type and negation flag
1694 // here.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001695 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1696 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00001697 }
Jim Grosbache53c87b2011-10-11 15:59:20 +00001698 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1699 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001700 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00001701 }
1702
Jim Grosbach039c2e12011-08-04 23:01:30 +00001703 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1704 assert(N == 2 && "Invalid number of operands!");
1705 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1706 assert(CE && "non-constant AM2OffsetImm operand!");
1707 int32_t Val = CE->getValue();
1708 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1709 // Special case for #-0
1710 if (Val == INT32_MIN) Val = 0;
1711 if (Val < 0) Val = -Val;
1712 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1713 Inst.addOperand(MCOperand::CreateReg(0));
1714 Inst.addOperand(MCOperand::CreateImm(Val));
1715 }
1716
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001717 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1718 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach2f196742011-12-19 23:06:24 +00001719 // If we have an immediate that's not a constant, treat it as a label
1720 // reference needing a fixup. If it is a constant, it's something else
1721 // and we reject it.
1722 if (isImm()) {
1723 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1724 Inst.addOperand(MCOperand::CreateReg(0));
1725 Inst.addOperand(MCOperand::CreateImm(0));
1726 return;
1727 }
1728
Jim Grosbache53c87b2011-10-11 15:59:20 +00001729 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1730 if (!Memory.OffsetRegNum) {
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001731 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1732 // Special case for #-0
1733 if (Val == INT32_MIN) Val = 0;
1734 if (Val < 0) Val = -Val;
1735 Val = ARM_AM::getAM3Opc(AddSub, Val);
1736 } else {
1737 // For register offset, we encode the shift type and negation flag
1738 // here.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001739 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001740 }
Jim Grosbache53c87b2011-10-11 15:59:20 +00001741 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1742 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001743 Inst.addOperand(MCOperand::CreateImm(Val));
1744 }
1745
1746 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1747 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach21ff17c2011-10-07 23:24:09 +00001748 if (Kind == k_PostIndexRegister) {
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001749 int32_t Val =
1750 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1751 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1752 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach251bf252011-08-10 21:56:18 +00001753 return;
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001754 }
1755
1756 // Constant offset.
1757 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1758 int32_t Val = CE->getValue();
1759 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1760 // Special case for #-0
1761 if (Val == INT32_MIN) Val = 0;
1762 if (Val < 0) Val = -Val;
Jim Grosbach251bf252011-08-10 21:56:18 +00001763 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach2fd2b872011-08-10 20:29:19 +00001764 Inst.addOperand(MCOperand::CreateReg(0));
1765 Inst.addOperand(MCOperand::CreateImm(Val));
1766 }
1767
Jim Grosbach7ce05792011-08-03 23:50:40 +00001768 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
1769 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach681460f2011-11-01 01:24:45 +00001770 // If we have an immediate that's not a constant, treat it as a label
1771 // reference needing a fixup. If it is a constant, it's something else
1772 // and we reject it.
1773 if (isImm()) {
1774 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1775 Inst.addOperand(MCOperand::CreateImm(0));
1776 return;
1777 }
1778
Jim Grosbach7ce05792011-08-03 23:50:40 +00001779 // The lower two bits are always zero and as such are not encoded.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001780 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbach7ce05792011-08-03 23:50:40 +00001781 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1782 // Special case for #-0
1783 if (Val == INT32_MIN) Val = 0;
1784 if (Val < 0) Val = -Val;
1785 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbache53c87b2011-10-11 15:59:20 +00001786 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001787 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00001788 }
1789
Jim Grosbacha77295d2011-09-08 22:07:06 +00001790 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
1791 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach2f196742011-12-19 23:06:24 +00001792 // If we have an immediate that's not a constant, treat it as a label
1793 // reference needing a fixup. If it is a constant, it's something else
1794 // and we reject it.
1795 if (isImm()) {
1796 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1797 Inst.addOperand(MCOperand::CreateImm(0));
1798 return;
1799 }
1800
Jim Grosbache53c87b2011-10-11 15:59:20 +00001801 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1802 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha77295d2011-09-08 22:07:06 +00001803 Inst.addOperand(MCOperand::CreateImm(Val));
1804 }
1805
Jim Grosbachb6aed502011-09-09 18:37:27 +00001806 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
1807 assert(N == 2 && "Invalid number of operands!");
1808 // The lower two bits are always zero and as such are not encoded.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001809 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
1810 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachb6aed502011-09-09 18:37:27 +00001811 Inst.addOperand(MCOperand::CreateImm(Val));
1812 }
1813
Jim Grosbach7ce05792011-08-03 23:50:40 +00001814 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1815 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001816 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1817 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001818 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner14b93852010-10-29 00:27:31 +00001819 }
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001820
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001821 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
1822 addMemImm8OffsetOperands(Inst, N);
1823 }
1824
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001825 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachf0eee6e2011-09-07 23:39:14 +00001826 addMemImm8OffsetOperands(Inst, N);
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001827 }
1828
1829 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1830 assert(N == 2 && "Invalid number of operands!");
1831 // If this is an immediate, it's a label reference.
Jim Grosbach21bcca82011-12-22 22:02:35 +00001832 if (isImm()) {
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001833 addExpr(Inst, getImm());
1834 Inst.addOperand(MCOperand::CreateImm(0));
1835 return;
1836 }
1837
1838 // Otherwise, it's a normal memory reg+offset.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001839 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1840 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha8307dd2011-09-07 20:58:57 +00001841 Inst.addOperand(MCOperand::CreateImm(Val));
1842 }
1843
Jim Grosbach7ce05792011-08-03 23:50:40 +00001844 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
1845 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach09176e12011-08-08 20:59:31 +00001846 // If this is an immediate, it's a label reference.
Jim Grosbach21bcca82011-12-22 22:02:35 +00001847 if (isImm()) {
Jim Grosbach09176e12011-08-08 20:59:31 +00001848 addExpr(Inst, getImm());
1849 Inst.addOperand(MCOperand::CreateImm(0));
1850 return;
1851 }
1852
1853 // Otherwise, it's a normal memory reg+offset.
Jim Grosbache53c87b2011-10-11 15:59:20 +00001854 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1855 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001856 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendlingf4caf692010-12-14 03:36:38 +00001857 }
Bill Wendlingef4a68b2010-11-30 07:44:32 +00001858
Jim Grosbach7f739be2011-09-19 22:21:13 +00001859 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
1860 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001861 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1862 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7f739be2011-09-19 22:21:13 +00001863 }
1864
1865 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
1866 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001867 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1868 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7f739be2011-09-19 22:21:13 +00001869 }
1870
Jim Grosbach7ce05792011-08-03 23:50:40 +00001871 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1872 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach430052b2011-11-14 17:52:47 +00001873 unsigned Val =
1874 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1875 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbache53c87b2011-10-11 15:59:20 +00001876 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1877 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001878 Inst.addOperand(MCOperand::CreateImm(Val));
1879 }
1880
Jim Grosbachab899c12011-09-07 23:10:15 +00001881 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
1882 assert(N == 3 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001883 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1884 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
1885 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbachab899c12011-09-07 23:10:15 +00001886 }
1887
Jim Grosbach7ce05792011-08-03 23:50:40 +00001888 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
1889 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001890 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1891 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach7ce05792011-08-03 23:50:40 +00001892 }
1893
Jim Grosbach60f91a32011-08-19 17:55:24 +00001894 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
1895 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001896 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1897 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach60f91a32011-08-19 17:55:24 +00001898 Inst.addOperand(MCOperand::CreateImm(Val));
1899 }
1900
Jim Grosbach38466302011-08-19 18:55:51 +00001901 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
1902 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001903 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
1904 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach38466302011-08-19 18:55:51 +00001905 Inst.addOperand(MCOperand::CreateImm(Val));
1906 }
1907
Jim Grosbach48ff5ff2011-08-19 18:49:59 +00001908 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
1909 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001910 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
1911 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach48ff5ff2011-08-19 18:49:59 +00001912 Inst.addOperand(MCOperand::CreateImm(Val));
1913 }
1914
Jim Grosbachecd85892011-08-19 18:13:48 +00001915 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
1916 assert(N == 2 && "Invalid number of operands!");
Jim Grosbache53c87b2011-10-11 15:59:20 +00001917 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
1918 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachecd85892011-08-19 18:13:48 +00001919 Inst.addOperand(MCOperand::CreateImm(Val));
1920 }
1921
Jim Grosbach7ce05792011-08-03 23:50:40 +00001922 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
1923 assert(N == 1 && "Invalid number of operands!");
1924 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1925 assert(CE && "non-constant post-idx-imm8 operand!");
1926 int Imm = CE->getValue();
1927 bool isAdd = Imm >= 0;
Owen Anderson63553c72011-08-29 17:17:09 +00001928 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbach7ce05792011-08-03 23:50:40 +00001929 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
1930 Inst.addOperand(MCOperand::CreateImm(Imm));
1931 }
1932
Jim Grosbach2bd01182011-10-11 21:55:36 +00001933 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
1934 assert(N == 1 && "Invalid number of operands!");
1935 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1936 assert(CE && "non-constant post-idx-imm8s4 operand!");
1937 int Imm = CE->getValue();
1938 bool isAdd = Imm >= 0;
1939 if (Imm == INT32_MIN) Imm = 0;
1940 // Immediate is scaled by 4.
1941 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
1942 Inst.addOperand(MCOperand::CreateImm(Imm));
1943 }
1944
Jim Grosbach7ce05792011-08-03 23:50:40 +00001945 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
1946 assert(N == 2 && "Invalid number of operands!");
1947 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00001948 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
1949 }
1950
1951 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
1952 assert(N == 2 && "Invalid number of operands!");
1953 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1954 // The sign, shift type, and shift amount are encoded in a single operand
1955 // using the AM2 encoding helpers.
1956 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
1957 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
1958 PostIdxReg.ShiftTy);
1959 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendlingef4a68b2010-11-30 07:44:32 +00001960 }
1961
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00001962 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
1963 assert(N == 1 && "Invalid number of operands!");
1964 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
1965 }
1966
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00001967 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
1968 assert(N == 1 && "Invalid number of operands!");
1969 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
1970 }
1971
Jim Grosbach6029b6d2011-11-29 23:51:09 +00001972 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach862019c2011-10-18 23:02:30 +00001973 assert(N == 1 && "Invalid number of operands!");
1974 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1975 }
1976
Jim Grosbach7636bf62011-12-02 00:35:16 +00001977 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
1978 assert(N == 2 && "Invalid number of operands!");
1979 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
1980 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
1981 }
1982
Jim Grosbach460a9052011-10-07 23:56:00 +00001983 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
1984 assert(N == 1 && "Invalid number of operands!");
1985 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1986 }
1987
1988 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
1989 assert(N == 1 && "Invalid number of operands!");
1990 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1991 }
1992
1993 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
1994 assert(N == 1 && "Invalid number of operands!");
1995 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
1996 }
1997
Jim Grosbach0e387b22011-10-17 22:26:03 +00001998 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
1999 assert(N == 1 && "Invalid number of operands!");
2000 // The immediate encodes the type of constant as well as the value.
2001 // Mask in that this is an i8 splat.
2002 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2003 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2004 }
2005
Jim Grosbachea461102011-10-17 23:09:09 +00002006 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2007 assert(N == 1 && "Invalid number of operands!");
2008 // The immediate encodes the type of constant as well as the value.
2009 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2010 unsigned Value = CE->getValue();
2011 if (Value >= 256)
2012 Value = (Value >> 8) | 0xa00;
2013 else
2014 Value |= 0x800;
2015 Inst.addOperand(MCOperand::CreateImm(Value));
2016 }
2017
Jim Grosbach6248a542011-10-18 00:22:00 +00002018 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2019 assert(N == 1 && "Invalid number of operands!");
2020 // The immediate encodes the type of constant as well as the value.
2021 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2022 unsigned Value = CE->getValue();
2023 if (Value >= 256 && Value <= 0xff00)
2024 Value = (Value >> 8) | 0x200;
2025 else if (Value > 0xffff && Value <= 0xff0000)
2026 Value = (Value >> 16) | 0x400;
2027 else if (Value > 0xffffff)
2028 Value = (Value >> 24) | 0x600;
2029 Inst.addOperand(MCOperand::CreateImm(Value));
2030 }
2031
2032 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2033 assert(N == 1 && "Invalid number of operands!");
2034 // The immediate encodes the type of constant as well as the value.
2035 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2036 unsigned Value = CE->getValue();
2037 if (Value >= 256 && Value <= 0xffff)
2038 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2039 else if (Value > 0xffff && Value <= 0xffffff)
2040 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2041 else if (Value > 0xffffff)
2042 Value = (Value >> 24) | 0x600;
2043 Inst.addOperand(MCOperand::CreateImm(Value));
2044 }
2045
Jim Grosbach9b087852011-12-19 23:51:07 +00002046 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2047 assert(N == 1 && "Invalid number of operands!");
2048 // The immediate encodes the type of constant as well as the value.
2049 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2050 unsigned Value = ~CE->getValue();
2051 if (Value >= 256 && Value <= 0xffff)
2052 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2053 else if (Value > 0xffff && Value <= 0xffffff)
2054 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2055 else if (Value > 0xffffff)
2056 Value = (Value >> 24) | 0x600;
2057 Inst.addOperand(MCOperand::CreateImm(Value));
2058 }
2059
Jim Grosbachf2f5bc62011-10-18 16:18:11 +00002060 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2061 assert(N == 1 && "Invalid number of operands!");
2062 // The immediate encodes the type of constant as well as the value.
2063 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2064 uint64_t Value = CE->getValue();
2065 unsigned Imm = 0;
2066 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2067 Imm |= (Value & 1) << i;
2068 }
2069 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2070 }
2071
Jim Grosbachb7f689b2011-07-13 15:34:57 +00002072 virtual void print(raw_ostream &OS) const;
Daniel Dunbarb3cb6962010-08-11 06:37:04 +00002073
Jim Grosbach89df9962011-08-26 21:43:41 +00002074 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002075 ARMOperand *Op = new ARMOperand(k_ITCondMask);
Jim Grosbach89df9962011-08-26 21:43:41 +00002076 Op->ITMask.Mask = Mask;
2077 Op->StartLoc = S;
2078 Op->EndLoc = S;
2079 return Op;
2080 }
2081
Chris Lattner3a697562010-10-28 17:20:03 +00002082 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002083 ARMOperand *Op = new ARMOperand(k_CondCode);
Daniel Dunbar345a9a62010-08-11 06:37:20 +00002084 Op->CC.Val = CC;
2085 Op->StartLoc = S;
2086 Op->EndLoc = S;
Chris Lattner3a697562010-10-28 17:20:03 +00002087 return Op;
Daniel Dunbar345a9a62010-08-11 06:37:20 +00002088 }
2089
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002090 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002091 ARMOperand *Op = new ARMOperand(k_CoprocNum);
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002092 Op->Cop.Val = CopVal;
2093 Op->StartLoc = S;
2094 Op->EndLoc = S;
2095 return Op;
2096 }
2097
2098 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002099 ARMOperand *Op = new ARMOperand(k_CoprocReg);
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002100 Op->Cop.Val = CopVal;
2101 Op->StartLoc = S;
2102 Op->EndLoc = S;
2103 return Op;
2104 }
2105
Jim Grosbach9b8f2a02011-10-12 17:34:41 +00002106 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2107 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2108 Op->Cop.Val = Val;
2109 Op->StartLoc = S;
2110 Op->EndLoc = E;
2111 return Op;
2112 }
2113
Jim Grosbachd67641b2010-12-06 18:21:12 +00002114 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002115 ARMOperand *Op = new ARMOperand(k_CCOut);
Jim Grosbachd67641b2010-12-06 18:21:12 +00002116 Op->Reg.RegNum = RegNum;
2117 Op->StartLoc = S;
2118 Op->EndLoc = S;
2119 return Op;
2120 }
2121
Chris Lattner3a697562010-10-28 17:20:03 +00002122 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002123 ARMOperand *Op = new ARMOperand(k_Token);
Sean Callanan76264762010-04-02 22:27:05 +00002124 Op->Tok.Data = Str.data();
2125 Op->Tok.Length = Str.size();
2126 Op->StartLoc = S;
2127 Op->EndLoc = S;
Chris Lattner3a697562010-10-28 17:20:03 +00002128 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002129 }
2130
Bill Wendling50d0f582010-11-18 23:43:05 +00002131 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002132 ARMOperand *Op = new ARMOperand(k_Register);
Sean Callanan76264762010-04-02 22:27:05 +00002133 Op->Reg.RegNum = RegNum;
Sean Callanan76264762010-04-02 22:27:05 +00002134 Op->StartLoc = S;
2135 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +00002136 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002137 }
2138
Jim Grosbache8606dc2011-07-13 17:50:29 +00002139 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2140 unsigned SrcReg,
2141 unsigned ShiftReg,
2142 unsigned ShiftImm,
2143 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002144 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
Jim Grosbachaf6981f2011-07-25 20:49:51 +00002145 Op->RegShiftedReg.ShiftTy = ShTy;
2146 Op->RegShiftedReg.SrcReg = SrcReg;
2147 Op->RegShiftedReg.ShiftReg = ShiftReg;
2148 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbache8606dc2011-07-13 17:50:29 +00002149 Op->StartLoc = S;
2150 Op->EndLoc = E;
2151 return Op;
2152 }
2153
Owen Anderson92a20222011-07-21 18:54:16 +00002154 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2155 unsigned SrcReg,
2156 unsigned ShiftImm,
2157 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002158 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
Jim Grosbachaf6981f2011-07-25 20:49:51 +00002159 Op->RegShiftedImm.ShiftTy = ShTy;
2160 Op->RegShiftedImm.SrcReg = SrcReg;
2161 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Anderson92a20222011-07-21 18:54:16 +00002162 Op->StartLoc = S;
2163 Op->EndLoc = E;
2164 return Op;
2165 }
2166
Jim Grosbach580f4a92011-07-25 22:20:28 +00002167 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
Owen Anderson00828302011-03-18 22:50:18 +00002168 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002169 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
Jim Grosbach580f4a92011-07-25 22:20:28 +00002170 Op->ShifterImm.isASR = isASR;
2171 Op->ShifterImm.Imm = Imm;
Owen Anderson00828302011-03-18 22:50:18 +00002172 Op->StartLoc = S;
2173 Op->EndLoc = E;
2174 return Op;
2175 }
2176
Jim Grosbach7e1547e2011-07-27 20:15:40 +00002177 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002178 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
Jim Grosbach7e1547e2011-07-27 20:15:40 +00002179 Op->RotImm.Imm = Imm;
2180 Op->StartLoc = S;
2181 Op->EndLoc = E;
2182 return Op;
2183 }
2184
Jim Grosbach293a2ee2011-07-28 21:34:26 +00002185 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2186 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002187 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
Jim Grosbach293a2ee2011-07-28 21:34:26 +00002188 Op->Bitfield.LSB = LSB;
2189 Op->Bitfield.Width = Width;
2190 Op->StartLoc = S;
2191 Op->EndLoc = E;
2192 return Op;
2193 }
2194
Bill Wendling7729e062010-11-09 22:44:22 +00002195 static ARMOperand *
Bill Wendling5fa22a12010-11-09 23:28:44 +00002196 CreateRegList(const SmallVectorImpl<std::pair<unsigned, SMLoc> > &Regs,
Matt Beaumont-Gaycc8d10e2010-11-10 00:08:58 +00002197 SMLoc StartLoc, SMLoc EndLoc) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002198 KindTy Kind = k_RegisterList;
Bill Wendling0f630752010-11-17 04:32:08 +00002199
Jim Grosbachd300b942011-09-13 22:56:44 +00002200 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().first))
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002201 Kind = k_DPRRegisterList;
Jim Grosbachd300b942011-09-13 22:56:44 +00002202 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Evan Cheng275944a2011-07-25 21:32:49 +00002203 contains(Regs.front().first))
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002204 Kind = k_SPRRegisterList;
Bill Wendling0f630752010-11-17 04:32:08 +00002205
2206 ARMOperand *Op = new ARMOperand(Kind);
Bill Wendling5fa22a12010-11-09 23:28:44 +00002207 for (SmallVectorImpl<std::pair<unsigned, SMLoc> >::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +00002208 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Bill Wendling24d22d22010-11-18 21:50:54 +00002209 Op->Registers.push_back(I->first);
Bill Wendlingcb21d1c2010-11-19 00:38:19 +00002210 array_pod_sort(Op->Registers.begin(), Op->Registers.end());
Matt Beaumont-Gaycc8d10e2010-11-10 00:08:58 +00002211 Op->StartLoc = StartLoc;
2212 Op->EndLoc = EndLoc;
Bill Wendling8d5acb72010-11-06 19:56:04 +00002213 return Op;
2214 }
2215
Jim Grosbach862019c2011-10-18 23:02:30 +00002216 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00002217 bool isDoubleSpaced, SMLoc S, SMLoc E) {
Jim Grosbach862019c2011-10-18 23:02:30 +00002218 ARMOperand *Op = new ARMOperand(k_VectorList);
2219 Op->VectorList.RegNum = RegNum;
2220 Op->VectorList.Count = Count;
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00002221 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach862019c2011-10-18 23:02:30 +00002222 Op->StartLoc = S;
2223 Op->EndLoc = E;
2224 return Op;
2225 }
2226
Jim Grosbach98b05a52011-11-30 01:09:44 +00002227 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
Jim Grosbach3471d4f2011-12-21 00:38:54 +00002228 bool isDoubleSpaced,
Jim Grosbach98b05a52011-11-30 01:09:44 +00002229 SMLoc S, SMLoc E) {
2230 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2231 Op->VectorList.RegNum = RegNum;
2232 Op->VectorList.Count = Count;
Jim Grosbach3471d4f2011-12-21 00:38:54 +00002233 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach98b05a52011-11-30 01:09:44 +00002234 Op->StartLoc = S;
2235 Op->EndLoc = E;
2236 return Op;
2237 }
2238
Jim Grosbach7636bf62011-12-02 00:35:16 +00002239 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
Jim Grosbach95fad1c2011-12-20 19:21:26 +00002240 unsigned Index,
2241 bool isDoubleSpaced,
2242 SMLoc S, SMLoc E) {
Jim Grosbach7636bf62011-12-02 00:35:16 +00002243 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2244 Op->VectorList.RegNum = RegNum;
2245 Op->VectorList.Count = Count;
2246 Op->VectorList.LaneIndex = Index;
Jim Grosbach95fad1c2011-12-20 19:21:26 +00002247 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach7636bf62011-12-02 00:35:16 +00002248 Op->StartLoc = S;
2249 Op->EndLoc = E;
2250 return Op;
2251 }
2252
Jim Grosbach460a9052011-10-07 23:56:00 +00002253 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2254 MCContext &Ctx) {
2255 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2256 Op->VectorIndex.Val = Idx;
2257 Op->StartLoc = S;
2258 Op->EndLoc = E;
2259 return Op;
2260 }
2261
Chris Lattner3a697562010-10-28 17:20:03 +00002262 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002263 ARMOperand *Op = new ARMOperand(k_Immediate);
Sean Callanan76264762010-04-02 22:27:05 +00002264 Op->Imm.Val = Val;
Sean Callanan76264762010-04-02 22:27:05 +00002265 Op->StartLoc = S;
2266 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +00002267 return Op;
Kevin Enderbycfe07242009-10-13 22:19:02 +00002268 }
2269
Jim Grosbach7ce05792011-08-03 23:50:40 +00002270 static ARMOperand *CreateMem(unsigned BaseRegNum,
2271 const MCConstantExpr *OffsetImm,
2272 unsigned OffsetRegNum,
2273 ARM_AM::ShiftOpc ShiftType,
Jim Grosbach0d6fac32011-08-05 22:03:36 +00002274 unsigned ShiftImm,
Jim Grosbach57dcb852011-10-11 17:29:55 +00002275 unsigned Alignment,
Jim Grosbach7ce05792011-08-03 23:50:40 +00002276 bool isNegative,
Chris Lattner3a697562010-10-28 17:20:03 +00002277 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002278 ARMOperand *Op = new ARMOperand(k_Memory);
Jim Grosbache53c87b2011-10-11 15:59:20 +00002279 Op->Memory.BaseRegNum = BaseRegNum;
2280 Op->Memory.OffsetImm = OffsetImm;
2281 Op->Memory.OffsetRegNum = OffsetRegNum;
2282 Op->Memory.ShiftType = ShiftType;
2283 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbach57dcb852011-10-11 17:29:55 +00002284 Op->Memory.Alignment = Alignment;
Jim Grosbache53c87b2011-10-11 15:59:20 +00002285 Op->Memory.isNegative = isNegative;
Jim Grosbach7ce05792011-08-03 23:50:40 +00002286 Op->StartLoc = S;
2287 Op->EndLoc = E;
2288 return Op;
2289 }
Jim Grosbach16c74252010-10-29 14:46:02 +00002290
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00002291 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2292 ARM_AM::ShiftOpc ShiftTy,
2293 unsigned ShiftImm,
Jim Grosbach7ce05792011-08-03 23:50:40 +00002294 SMLoc S, SMLoc E) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002295 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
Jim Grosbach7ce05792011-08-03 23:50:40 +00002296 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00002297 Op->PostIdxReg.isAdd = isAdd;
2298 Op->PostIdxReg.ShiftTy = ShiftTy;
2299 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan76264762010-04-02 22:27:05 +00002300 Op->StartLoc = S;
2301 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +00002302 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002303 }
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00002304
2305 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002306 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00002307 Op->MBOpt.Val = Opt;
2308 Op->StartLoc = S;
2309 Op->EndLoc = S;
2310 return Op;
2311 }
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00002312
2313 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002314 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00002315 Op->IFlags.Val = IFlags;
2316 Op->StartLoc = S;
2317 Op->EndLoc = S;
2318 return Op;
2319 }
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00002320
2321 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002322 ARMOperand *Op = new ARMOperand(k_MSRMask);
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00002323 Op->MMask.Val = MMask;
2324 Op->StartLoc = S;
2325 Op->EndLoc = S;
2326 return Op;
2327 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002328};
2329
2330} // end anonymous namespace.
2331
Jim Grosbachb7f689b2011-07-13 15:34:57 +00002332void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002333 switch (Kind) {
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002334 case k_CondCode:
Daniel Dunbar6a5c22e2011-01-10 15:26:21 +00002335 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002336 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002337 case k_CCOut:
Jim Grosbachd67641b2010-12-06 18:21:12 +00002338 OS << "<ccout " << getReg() << ">";
2339 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002340 case k_ITCondMask: {
Craig Topper032f4412012-05-24 04:11:15 +00002341 static const char *const MaskStr[] = {
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00002342 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2343 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2344 };
Jim Grosbach89df9962011-08-26 21:43:41 +00002345 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2346 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2347 break;
2348 }
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002349 case k_CoprocNum:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002350 OS << "<coprocessor number: " << getCoproc() << ">";
2351 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002352 case k_CoprocReg:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002353 OS << "<coprocessor register: " << getCoproc() << ">";
2354 break;
Jim Grosbach9b8f2a02011-10-12 17:34:41 +00002355 case k_CoprocOption:
2356 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2357 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002358 case k_MSRMask:
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00002359 OS << "<mask: " << getMSRMask() << ">";
2360 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002361 case k_Immediate:
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002362 getImm()->print(OS);
2363 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002364 case k_MemBarrierOpt:
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00002365 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt()) << ">";
2366 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002367 case k_Memory:
Daniel Dunbar6ec56202011-01-18 05:55:21 +00002368 OS << "<memory "
Jim Grosbache53c87b2011-10-11 15:59:20 +00002369 << " base:" << Memory.BaseRegNum;
Daniel Dunbar6ec56202011-01-18 05:55:21 +00002370 OS << ">";
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002371 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002372 case k_PostIndexRegister:
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00002373 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2374 << PostIdxReg.RegNum;
2375 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2376 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2377 << PostIdxReg.ShiftImm;
2378 OS << ">";
Jim Grosbach7ce05792011-08-03 23:50:40 +00002379 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002380 case k_ProcIFlags: {
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00002381 OS << "<ARM_PROC::";
2382 unsigned IFlags = getProcIFlags();
2383 for (int i=2; i >= 0; --i)
2384 if (IFlags & (1 << i))
2385 OS << ARM_PROC::IFlagsToString(1 << i);
2386 OS << ">";
2387 break;
2388 }
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002389 case k_Register:
Bill Wendling50d0f582010-11-18 23:43:05 +00002390 OS << "<register " << getReg() << ">";
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002391 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002392 case k_ShifterImmediate:
Jim Grosbach580f4a92011-07-25 22:20:28 +00002393 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2394 << " #" << ShifterImm.Imm << ">";
Jim Grosbache8606dc2011-07-13 17:50:29 +00002395 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002396 case k_ShiftedRegister:
Owen Anderson92a20222011-07-21 18:54:16 +00002397 OS << "<so_reg_reg "
Jim Grosbachefed3d12011-11-16 21:46:50 +00002398 << RegShiftedReg.SrcReg << " "
2399 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2400 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson00828302011-03-18 22:50:18 +00002401 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002402 case k_ShiftedImmediate:
Owen Anderson92a20222011-07-21 18:54:16 +00002403 OS << "<so_reg_imm "
Jim Grosbachefed3d12011-11-16 21:46:50 +00002404 << RegShiftedImm.SrcReg << " "
2405 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2406 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Anderson92a20222011-07-21 18:54:16 +00002407 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002408 case k_RotateImmediate:
Jim Grosbach7e1547e2011-07-27 20:15:40 +00002409 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2410 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002411 case k_BitfieldDescriptor:
Jim Grosbach293a2ee2011-07-28 21:34:26 +00002412 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2413 << ", width: " << Bitfield.Width << ">";
2414 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002415 case k_RegisterList:
2416 case k_DPRRegisterList:
2417 case k_SPRRegisterList: {
Bill Wendling8d5acb72010-11-06 19:56:04 +00002418 OS << "<register_list ";
Bill Wendling8d5acb72010-11-06 19:56:04 +00002419
Bill Wendling5fa22a12010-11-09 23:28:44 +00002420 const SmallVectorImpl<unsigned> &RegList = getRegList();
2421 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +00002422 I = RegList.begin(), E = RegList.end(); I != E; ) {
2423 OS << *I;
2424 if (++I < E) OS << ", ";
Bill Wendling8d5acb72010-11-06 19:56:04 +00002425 }
2426
2427 OS << ">";
2428 break;
2429 }
Jim Grosbach862019c2011-10-18 23:02:30 +00002430 case k_VectorList:
2431 OS << "<vector_list " << VectorList.Count << " * "
2432 << VectorList.RegNum << ">";
2433 break;
Jim Grosbach98b05a52011-11-30 01:09:44 +00002434 case k_VectorListAllLanes:
2435 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2436 << VectorList.RegNum << ">";
2437 break;
Jim Grosbach7636bf62011-12-02 00:35:16 +00002438 case k_VectorListIndexed:
2439 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2440 << VectorList.Count << " * " << VectorList.RegNum << ">";
2441 break;
Jim Grosbach21ff17c2011-10-07 23:24:09 +00002442 case k_Token:
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002443 OS << "'" << getToken() << "'";
2444 break;
Jim Grosbach460a9052011-10-07 23:56:00 +00002445 case k_VectorIndex:
2446 OS << "<vectorindex " << getVectorIndex() << ">";
2447 break;
Daniel Dunbarfa315de2010-08-11 06:37:12 +00002448 }
2449}
Daniel Dunbar3483aca2010-08-11 05:24:50 +00002450
2451/// @name Auto-generated Match Functions
2452/// {
2453
2454static unsigned MatchRegisterName(StringRef Name);
2455
2456/// }
2457
Bob Wilson69df7232011-02-03 21:46:10 +00002458bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2459 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbacha39cda72011-12-14 02:16:11 +00002460 StartLoc = Parser.getTok().getLoc();
Jim Grosbach1355cf12011-07-26 17:10:22 +00002461 RegNo = tryParseRegister();
Jim Grosbacha39cda72011-12-14 02:16:11 +00002462 EndLoc = Parser.getTok().getLoc();
Roman Divackybf755322011-01-27 17:14:22 +00002463
2464 return (RegNo == (unsigned)-1);
2465}
2466
Kevin Enderby9c41fa82009-10-30 22:55:57 +00002467/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattnere5658fa2010-10-30 04:09:10 +00002468/// and if it is a register name the token is eaten and the register number is
2469/// returned. Otherwise return -1.
2470///
Jim Grosbach1355cf12011-07-26 17:10:22 +00002471int ARMAsmParser::tryParseRegister() {
Chris Lattnere5658fa2010-10-30 04:09:10 +00002472 const AsmToken &Tok = Parser.getTok();
Jim Grosbach7ce05792011-08-03 23:50:40 +00002473 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbachd4462a52010-11-01 16:44:21 +00002474
Benjamin Kramer59085362011-11-06 20:37:06 +00002475 std::string lowerCase = Tok.getString().lower();
Owen Anderson0c9f2502011-01-13 22:50:36 +00002476 unsigned RegNum = MatchRegisterName(lowerCase);
2477 if (!RegNum) {
2478 RegNum = StringSwitch<unsigned>(lowerCase)
2479 .Case("r13", ARM::SP)
2480 .Case("r14", ARM::LR)
2481 .Case("r15", ARM::PC)
2482 .Case("ip", ARM::R12)
Jim Grosbach40e28552011-12-08 19:27:38 +00002483 // Additional register name aliases for 'gas' compatibility.
2484 .Case("a1", ARM::R0)
2485 .Case("a2", ARM::R1)
2486 .Case("a3", ARM::R2)
2487 .Case("a4", ARM::R3)
2488 .Case("v1", ARM::R4)
2489 .Case("v2", ARM::R5)
2490 .Case("v3", ARM::R6)
2491 .Case("v4", ARM::R7)
2492 .Case("v5", ARM::R8)
2493 .Case("v6", ARM::R9)
2494 .Case("v7", ARM::R10)
2495 .Case("v8", ARM::R11)
2496 .Case("sb", ARM::R9)
2497 .Case("sl", ARM::R10)
2498 .Case("fp", ARM::R11)
Owen Anderson0c9f2502011-01-13 22:50:36 +00002499 .Default(0);
2500 }
Jim Grosbacha39cda72011-12-14 02:16:11 +00002501 if (!RegNum) {
Jim Grosbachaee718b2011-12-20 23:11:00 +00002502 // Check for aliases registered via .req. Canonicalize to lower case.
2503 // That's more consistent since register names are case insensitive, and
2504 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2505 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbacha39cda72011-12-14 02:16:11 +00002506 // If no match, return failure.
2507 if (Entry == RegisterReqs.end())
2508 return -1;
2509 Parser.Lex(); // Eat identifier token.
2510 return Entry->getValue();
2511 }
Bob Wilson69df7232011-02-03 21:46:10 +00002512
Chris Lattnere5658fa2010-10-30 04:09:10 +00002513 Parser.Lex(); // Eat identifier token.
Jim Grosbach460a9052011-10-07 23:56:00 +00002514
Chris Lattnere5658fa2010-10-30 04:09:10 +00002515 return RegNum;
2516}
Jim Grosbachd4462a52010-11-01 16:44:21 +00002517
Jim Grosbach19906722011-07-13 18:49:30 +00002518// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2519// If a recoverable error occurs, return 1. If an irrecoverable error
2520// occurs, return -1. An irrecoverable error is one where tokens have been
2521// consumed in the process of trying to parse the shifter (i.e., when it is
2522// indeed a shifter operand, but malformed).
Jim Grosbach0d87ec22011-07-26 20:41:24 +00002523int ARMAsmParser::tryParseShiftRegister(
Owen Anderson00828302011-03-18 22:50:18 +00002524 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2525 SMLoc S = Parser.getTok().getLoc();
2526 const AsmToken &Tok = Parser.getTok();
2527 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2528
Benjamin Kramer59085362011-11-06 20:37:06 +00002529 std::string lowerCase = Tok.getString().lower();
Owen Anderson00828302011-03-18 22:50:18 +00002530 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbachaf4edea2011-12-07 23:40:58 +00002531 .Case("asl", ARM_AM::lsl)
Owen Anderson00828302011-03-18 22:50:18 +00002532 .Case("lsl", ARM_AM::lsl)
2533 .Case("lsr", ARM_AM::lsr)
2534 .Case("asr", ARM_AM::asr)
2535 .Case("ror", ARM_AM::ror)
2536 .Case("rrx", ARM_AM::rrx)
2537 .Default(ARM_AM::no_shift);
2538
2539 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbach19906722011-07-13 18:49:30 +00002540 return 1;
Owen Anderson00828302011-03-18 22:50:18 +00002541
Jim Grosbache8606dc2011-07-13 17:50:29 +00002542 Parser.Lex(); // Eat the operator.
Owen Anderson00828302011-03-18 22:50:18 +00002543
Jim Grosbache8606dc2011-07-13 17:50:29 +00002544 // The source register for the shift has already been added to the
2545 // operand list, so we need to pop it off and combine it into the shifted
2546 // register operand instead.
Benjamin Kramereac07962011-07-14 18:41:22 +00002547 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
Jim Grosbache8606dc2011-07-13 17:50:29 +00002548 if (!PrevOp->isReg())
2549 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2550 int SrcReg = PrevOp->getReg();
2551 int64_t Imm = 0;
2552 int ShiftReg = 0;
2553 if (ShiftTy == ARM_AM::rrx) {
2554 // RRX Doesn't have an explicit shift amount. The encoder expects
2555 // the shift register to be the same as the source register. Seems odd,
2556 // but OK.
2557 ShiftReg = SrcReg;
2558 } else {
2559 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00002560 if (Parser.getTok().is(AsmToken::Hash) ||
2561 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbache8606dc2011-07-13 17:50:29 +00002562 Parser.Lex(); // Eat hash.
2563 SMLoc ImmLoc = Parser.getTok().getLoc();
2564 const MCExpr *ShiftExpr = 0;
Jim Grosbach19906722011-07-13 18:49:30 +00002565 if (getParser().ParseExpression(ShiftExpr)) {
2566 Error(ImmLoc, "invalid immediate shift value");
2567 return -1;
2568 }
Jim Grosbache8606dc2011-07-13 17:50:29 +00002569 // The expression must be evaluatable as an immediate.
2570 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbach19906722011-07-13 18:49:30 +00002571 if (!CE) {
2572 Error(ImmLoc, "invalid immediate shift value");
2573 return -1;
2574 }
Jim Grosbache8606dc2011-07-13 17:50:29 +00002575 // Range check the immediate.
2576 // lsl, ror: 0 <= imm <= 31
2577 // lsr, asr: 0 <= imm <= 32
2578 Imm = CE->getValue();
2579 if (Imm < 0 ||
2580 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2581 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbach19906722011-07-13 18:49:30 +00002582 Error(ImmLoc, "immediate shift value out of range");
2583 return -1;
Jim Grosbache8606dc2011-07-13 17:50:29 +00002584 }
Jim Grosbachde626ad2011-12-22 17:37:00 +00002585 // shift by zero is a nop. Always send it through as lsl.
2586 // ('as' compatibility)
2587 if (Imm == 0)
2588 ShiftTy = ARM_AM::lsl;
Jim Grosbache8606dc2011-07-13 17:50:29 +00002589 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach1355cf12011-07-26 17:10:22 +00002590 ShiftReg = tryParseRegister();
Jim Grosbache8606dc2011-07-13 17:50:29 +00002591 SMLoc L = Parser.getTok().getLoc();
Jim Grosbach19906722011-07-13 18:49:30 +00002592 if (ShiftReg == -1) {
2593 Error (L, "expected immediate or register in shift operand");
2594 return -1;
2595 }
2596 } else {
2597 Error (Parser.getTok().getLoc(),
Jim Grosbache8606dc2011-07-13 17:50:29 +00002598 "expected immediate or register in shift operand");
Jim Grosbach19906722011-07-13 18:49:30 +00002599 return -1;
2600 }
Jim Grosbache8606dc2011-07-13 17:50:29 +00002601 }
2602
Owen Anderson92a20222011-07-21 18:54:16 +00002603 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2604 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachaf6981f2011-07-25 20:49:51 +00002605 ShiftReg, Imm,
Owen Anderson00828302011-03-18 22:50:18 +00002606 S, Parser.getTok().getLoc()));
Owen Anderson92a20222011-07-21 18:54:16 +00002607 else
2608 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
2609 S, Parser.getTok().getLoc()));
Owen Anderson00828302011-03-18 22:50:18 +00002610
Jim Grosbach19906722011-07-13 18:49:30 +00002611 return 0;
Owen Anderson00828302011-03-18 22:50:18 +00002612}
2613
2614
Bill Wendling50d0f582010-11-18 23:43:05 +00002615/// Try to parse a register name. The token must be an Identifier when called.
2616/// If it's a register, an AsmOperand is created. Another AsmOperand is created
2617/// if there is a "writeback". 'true' if it's not a register.
Chris Lattner3a697562010-10-28 17:20:03 +00002618///
Kevin Enderby9c41fa82009-10-30 22:55:57 +00002619/// TODO this is likely to change to allow different register types and or to
2620/// parse for a specific register type.
Bill Wendling50d0f582010-11-18 23:43:05 +00002621bool ARMAsmParser::
Jim Grosbach1355cf12011-07-26 17:10:22 +00002622tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Chris Lattnere5658fa2010-10-30 04:09:10 +00002623 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach1355cf12011-07-26 17:10:22 +00002624 int RegNo = tryParseRegister();
Bill Wendlinge7176102010-11-06 22:36:58 +00002625 if (RegNo == -1)
Bill Wendling50d0f582010-11-18 23:43:05 +00002626 return true;
Jim Grosbachd4462a52010-11-01 16:44:21 +00002627
Bill Wendling50d0f582010-11-18 23:43:05 +00002628 Operands.push_back(ARMOperand::CreateReg(RegNo, S, Parser.getTok().getLoc()));
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002629
Chris Lattnere5658fa2010-10-30 04:09:10 +00002630 const AsmToken &ExclaimTok = Parser.getTok();
2631 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling50d0f582010-11-18 23:43:05 +00002632 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2633 ExclaimTok.getLoc()));
Chris Lattnere5658fa2010-10-30 04:09:10 +00002634 Parser.Lex(); // Eat exclaim token
Jim Grosbach460a9052011-10-07 23:56:00 +00002635 return false;
2636 }
2637
2638 // Also check for an index operand. This is only legal for vector registers,
2639 // but that'll get caught OK in operand matching, so we don't need to
2640 // explicitly filter everything else out here.
2641 if (Parser.getTok().is(AsmToken::LBrac)) {
2642 SMLoc SIdx = Parser.getTok().getLoc();
2643 Parser.Lex(); // Eat left bracket token.
2644
2645 const MCExpr *ImmVal;
Jim Grosbach460a9052011-10-07 23:56:00 +00002646 if (getParser().ParseExpression(ImmVal))
Jim Grosbach24dda212012-01-31 23:51:09 +00002647 return true;
Jim Grosbach460a9052011-10-07 23:56:00 +00002648 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachef4d3eb2012-01-26 15:56:45 +00002649 if (!MCE)
2650 return TokError("immediate value expected for vector index");
Jim Grosbach460a9052011-10-07 23:56:00 +00002651
2652 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachef4d3eb2012-01-26 15:56:45 +00002653 if (Parser.getTok().isNot(AsmToken::RBrac))
2654 return Error(E, "']' expected");
Jim Grosbach460a9052011-10-07 23:56:00 +00002655
2656 Parser.Lex(); // Eat right bracket token.
2657
2658 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2659 SIdx, E,
2660 getContext()));
Kevin Enderby99e6d4e2009-10-07 18:01:35 +00002661 }
2662
Bill Wendling50d0f582010-11-18 23:43:05 +00002663 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00002664}
2665
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002666/// MatchCoprocessorOperandName - Try to parse an coprocessor related
2667/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2668/// "c5", ...
2669static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002670 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2671 // but efficient.
2672 switch (Name.size()) {
David Blaikie4d6ccb52012-01-20 21:51:11 +00002673 default: return -1;
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002674 case 2:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002675 if (Name[0] != CoprocOp)
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002676 return -1;
2677 switch (Name[1]) {
2678 default: return -1;
2679 case '0': return 0;
2680 case '1': return 1;
2681 case '2': return 2;
2682 case '3': return 3;
2683 case '4': return 4;
2684 case '5': return 5;
2685 case '6': return 6;
2686 case '7': return 7;
2687 case '8': return 8;
2688 case '9': return 9;
2689 }
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002690 case 3:
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002691 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002692 return -1;
2693 switch (Name[2]) {
2694 default: return -1;
2695 case '0': return 10;
2696 case '1': return 11;
2697 case '2': return 12;
2698 case '3': return 13;
2699 case '4': return 14;
2700 case '5': return 15;
2701 }
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002702 }
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002703}
2704
Jim Grosbach89df9962011-08-26 21:43:41 +00002705/// parseITCondCode - Try to parse a condition code for an IT instruction.
2706ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2707parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2708 SMLoc S = Parser.getTok().getLoc();
2709 const AsmToken &Tok = Parser.getTok();
2710 if (!Tok.is(AsmToken::Identifier))
2711 return MatchOperand_NoMatch;
Richard Barton04a09a42012-04-27 17:34:01 +00002712 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach89df9962011-08-26 21:43:41 +00002713 .Case("eq", ARMCC::EQ)
2714 .Case("ne", ARMCC::NE)
2715 .Case("hs", ARMCC::HS)
2716 .Case("cs", ARMCC::HS)
2717 .Case("lo", ARMCC::LO)
2718 .Case("cc", ARMCC::LO)
2719 .Case("mi", ARMCC::MI)
2720 .Case("pl", ARMCC::PL)
2721 .Case("vs", ARMCC::VS)
2722 .Case("vc", ARMCC::VC)
2723 .Case("hi", ARMCC::HI)
2724 .Case("ls", ARMCC::LS)
2725 .Case("ge", ARMCC::GE)
2726 .Case("lt", ARMCC::LT)
2727 .Case("gt", ARMCC::GT)
2728 .Case("le", ARMCC::LE)
2729 .Case("al", ARMCC::AL)
2730 .Default(~0U);
2731 if (CC == ~0U)
2732 return MatchOperand_NoMatch;
2733 Parser.Lex(); // Eat the token.
2734
2735 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2736
2737 return MatchOperand_Success;
2738}
2739
Jim Grosbach43904292011-07-25 20:14:50 +00002740/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002741/// token must be an Identifier when called, and if it is a coprocessor
2742/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbachf922c472011-02-12 01:34:40 +00002743ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00002744parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002745 SMLoc S = Parser.getTok().getLoc();
2746 const AsmToken &Tok = Parser.getTok();
Jim Grosbachc66e7af2011-10-12 20:54:17 +00002747 if (Tok.isNot(AsmToken::Identifier))
2748 return MatchOperand_NoMatch;
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002749
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002750 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002751 if (Num == -1)
Jim Grosbachf922c472011-02-12 01:34:40 +00002752 return MatchOperand_NoMatch;
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002753
2754 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002755 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbachf922c472011-02-12 01:34:40 +00002756 return MatchOperand_Success;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002757}
2758
Jim Grosbach43904292011-07-25 20:14:50 +00002759/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002760/// token must be an Identifier when called, and if it is a coprocessor
2761/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbachf922c472011-02-12 01:34:40 +00002762ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00002763parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002764 SMLoc S = Parser.getTok().getLoc();
2765 const AsmToken &Tok = Parser.getTok();
Jim Grosbachc66e7af2011-10-12 20:54:17 +00002766 if (Tok.isNot(AsmToken::Identifier))
2767 return MatchOperand_NoMatch;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002768
2769 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
2770 if (Reg == -1)
Jim Grosbachf922c472011-02-12 01:34:40 +00002771 return MatchOperand_NoMatch;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00002772
2773 Parser.Lex(); // Eat identifier token.
2774 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbachf922c472011-02-12 01:34:40 +00002775 return MatchOperand_Success;
Owen Andersone4e5e2a2011-01-13 21:46:02 +00002776}
2777
Jim Grosbach9b8f2a02011-10-12 17:34:41 +00002778/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
2779/// coproc_option : '{' imm0_255 '}'
2780ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2781parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2782 SMLoc S = Parser.getTok().getLoc();
2783
2784 // If this isn't a '{', this isn't a coprocessor immediate operand.
2785 if (Parser.getTok().isNot(AsmToken::LCurly))
2786 return MatchOperand_NoMatch;
2787 Parser.Lex(); // Eat the '{'
2788
2789 const MCExpr *Expr;
2790 SMLoc Loc = Parser.getTok().getLoc();
2791 if (getParser().ParseExpression(Expr)) {
2792 Error(Loc, "illegal expression");
2793 return MatchOperand_ParseFail;
2794 }
2795 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
2796 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
2797 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
2798 return MatchOperand_ParseFail;
2799 }
2800 int Val = CE->getValue();
2801
2802 // Check for and consume the closing '}'
2803 if (Parser.getTok().isNot(AsmToken::RCurly))
2804 return MatchOperand_ParseFail;
2805 SMLoc E = Parser.getTok().getLoc();
2806 Parser.Lex(); // Eat the '}'
2807
2808 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
2809 return MatchOperand_Success;
2810}
2811
Jim Grosbachd0588e22011-09-14 18:08:35 +00002812// For register list parsing, we need to map from raw GPR register numbering
2813// to the enumeration values. The enumeration values aren't sorted by
2814// register number due to our using "sp", "lr" and "pc" as canonical names.
2815static unsigned getNextRegister(unsigned Reg) {
2816 // If this is a GPR, we need to do it manually, otherwise we can rely
2817 // on the sort ordering of the enumeration since the other reg-classes
2818 // are sane.
2819 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2820 return Reg + 1;
2821 switch(Reg) {
Craig Topperbc219812012-02-07 02:50:20 +00002822 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbachd0588e22011-09-14 18:08:35 +00002823 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
2824 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
2825 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
2826 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
2827 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
2828 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
2829 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
2830 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
2831 }
2832}
2833
Jim Grosbachce485e72011-11-11 21:27:40 +00002834// Return the low-subreg of a given Q register.
2835static unsigned getDRegFromQReg(unsigned QReg) {
2836 switch (QReg) {
2837 default: llvm_unreachable("expected a Q register!");
2838 case ARM::Q0: return ARM::D0;
2839 case ARM::Q1: return ARM::D2;
2840 case ARM::Q2: return ARM::D4;
2841 case ARM::Q3: return ARM::D6;
2842 case ARM::Q4: return ARM::D8;
2843 case ARM::Q5: return ARM::D10;
2844 case ARM::Q6: return ARM::D12;
2845 case ARM::Q7: return ARM::D14;
2846 case ARM::Q8: return ARM::D16;
Jim Grosbach25e0a872011-11-15 21:01:30 +00002847 case ARM::Q9: return ARM::D18;
Jim Grosbachce485e72011-11-11 21:27:40 +00002848 case ARM::Q10: return ARM::D20;
2849 case ARM::Q11: return ARM::D22;
2850 case ARM::Q12: return ARM::D24;
2851 case ARM::Q13: return ARM::D26;
2852 case ARM::Q14: return ARM::D28;
2853 case ARM::Q15: return ARM::D30;
2854 }
2855}
2856
Jim Grosbachd0588e22011-09-14 18:08:35 +00002857/// Parse a register list.
Bill Wendling50d0f582010-11-18 23:43:05 +00002858bool ARMAsmParser::
Jim Grosbach1355cf12011-07-26 17:10:22 +00002859parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan18b83232010-01-19 21:44:56 +00002860 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendlinga60f1572010-11-06 10:48:18 +00002861 "Token is not a Left Curly Brace");
Bill Wendlinge7176102010-11-06 22:36:58 +00002862 SMLoc S = Parser.getTok().getLoc();
Jim Grosbachd0588e22011-09-14 18:08:35 +00002863 Parser.Lex(); // Eat '{' token.
2864 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbyd7894f12009-10-09 21:12:28 +00002865
Jim Grosbachd0588e22011-09-14 18:08:35 +00002866 // Check the first register in the list to see what register class
2867 // this is a list of.
2868 int Reg = tryParseRegister();
2869 if (Reg == -1)
2870 return Error(RegLoc, "register expected");
2871
Jim Grosbachce485e72011-11-11 21:27:40 +00002872 // The reglist instructions have at most 16 registers, so reserve
2873 // space for that many.
2874 SmallVector<std::pair<unsigned, SMLoc>, 16> Registers;
2875
2876 // Allow Q regs and just interpret them as the two D sub-registers.
2877 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2878 Reg = getDRegFromQReg(Reg);
2879 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2880 ++Reg;
2881 }
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00002882 const MCRegisterClass *RC;
Jim Grosbachd0588e22011-09-14 18:08:35 +00002883 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2884 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
2885 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
2886 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
2887 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
2888 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
2889 else
2890 return Error(RegLoc, "invalid register in register list");
2891
Jim Grosbachce485e72011-11-11 21:27:40 +00002892 // Store the register.
Jim Grosbachd0588e22011-09-14 18:08:35 +00002893 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
Kevin Enderbyd7894f12009-10-09 21:12:28 +00002894
Jim Grosbachd0588e22011-09-14 18:08:35 +00002895 // This starts immediately after the first register token in the list,
2896 // so we can see either a comma or a minus (range separator) as a legal
2897 // next token.
2898 while (Parser.getTok().is(AsmToken::Comma) ||
2899 Parser.getTok().is(AsmToken::Minus)) {
2900 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache43862b2011-11-15 23:19:15 +00002901 Parser.Lex(); // Eat the minus.
Jim Grosbachd0588e22011-09-14 18:08:35 +00002902 SMLoc EndLoc = Parser.getTok().getLoc();
2903 int EndReg = tryParseRegister();
2904 if (EndReg == -1)
2905 return Error(EndLoc, "register expected");
Jim Grosbachce485e72011-11-11 21:27:40 +00002906 // Allow Q regs and just interpret them as the two D sub-registers.
2907 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
2908 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbachd0588e22011-09-14 18:08:35 +00002909 // If the register is the same as the start reg, there's nothing
2910 // more to do.
2911 if (Reg == EndReg)
2912 continue;
2913 // The register must be in the same register class as the first.
2914 if (!RC->contains(EndReg))
2915 return Error(EndLoc, "invalid register in register list");
2916 // Ranges must go from low to high.
Eric Christopherdf1c6372012-08-09 22:10:21 +00002917 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jim Grosbachd0588e22011-09-14 18:08:35 +00002918 return Error(EndLoc, "bad range in register list");
Kevin Enderbyd7894f12009-10-09 21:12:28 +00002919
Jim Grosbachd0588e22011-09-14 18:08:35 +00002920 // Add all the registers in the range to the register list.
2921 while (Reg != EndReg) {
2922 Reg = getNextRegister(Reg);
2923 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
2924 }
2925 continue;
2926 }
2927 Parser.Lex(); // Eat the comma.
2928 RegLoc = Parser.getTok().getLoc();
2929 int OldReg = Reg;
Jim Grosbacha62d11e2011-12-08 21:34:20 +00002930 const AsmToken RegTok = Parser.getTok();
Jim Grosbachd0588e22011-09-14 18:08:35 +00002931 Reg = tryParseRegister();
2932 if (Reg == -1)
Jim Grosbach2d539692011-09-12 23:36:42 +00002933 return Error(RegLoc, "register expected");
Jim Grosbachce485e72011-11-11 21:27:40 +00002934 // Allow Q regs and just interpret them as the two D sub-registers.
2935 bool isQReg = false;
2936 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
2937 Reg = getDRegFromQReg(Reg);
2938 isQReg = true;
2939 }
Jim Grosbachd0588e22011-09-14 18:08:35 +00002940 // The register must be in the same register class as the first.
2941 if (!RC->contains(Reg))
2942 return Error(RegLoc, "invalid register in register list");
2943 // List must be monotonically increasing.
Eric Christopherdf1c6372012-08-09 22:10:21 +00002944 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbachbe7cf2b2012-03-16 20:48:38 +00002945 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
2946 Warning(RegLoc, "register list not in ascending order");
2947 else
2948 return Error(RegLoc, "register list not in ascending order");
2949 }
Eric Christopherdf1c6372012-08-09 22:10:21 +00002950 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbacha62d11e2011-12-08 21:34:20 +00002951 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
2952 ") in register list");
2953 continue;
2954 }
Jim Grosbachd0588e22011-09-14 18:08:35 +00002955 // VFP register lists must also be contiguous.
2956 // It's OK to use the enumeration values directly here rather, as the
2957 // VFP register classes have the enum sorted properly.
2958 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
2959 Reg != OldReg + 1)
2960 return Error(RegLoc, "non-contiguous register range");
2961 Registers.push_back(std::pair<unsigned, SMLoc>(Reg, RegLoc));
Jim Grosbachce485e72011-11-11 21:27:40 +00002962 if (isQReg)
2963 Registers.push_back(std::pair<unsigned, SMLoc>(++Reg, RegLoc));
Bill Wendlinge7176102010-11-06 22:36:58 +00002964 }
2965
Jim Grosbachd0588e22011-09-14 18:08:35 +00002966 SMLoc E = Parser.getTok().getLoc();
2967 if (Parser.getTok().isNot(AsmToken::RCurly))
2968 return Error(E, "'}' expected");
2969 Parser.Lex(); // Eat '}' token.
2970
Jim Grosbach27debd62011-12-13 21:48:29 +00002971 // Push the register list operand.
Bill Wendling50d0f582010-11-18 23:43:05 +00002972 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach27debd62011-12-13 21:48:29 +00002973
2974 // The ARM system instruction variants for LDM/STM have a '^' token here.
2975 if (Parser.getTok().is(AsmToken::Caret)) {
2976 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
2977 Parser.Lex(); // Eat '^' token.
2978 }
2979
Bill Wendling50d0f582010-11-18 23:43:05 +00002980 return false;
Kevin Enderbyd7894f12009-10-09 21:12:28 +00002981}
2982
Jim Grosbach98b05a52011-11-30 01:09:44 +00002983// Helper function to parse the lane index for vector lists.
2984ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach7636bf62011-12-02 00:35:16 +00002985parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index) {
2986 Index = 0; // Always return a defined index value.
Jim Grosbach98b05a52011-11-30 01:09:44 +00002987 if (Parser.getTok().is(AsmToken::LBrac)) {
2988 Parser.Lex(); // Eat the '['.
2989 if (Parser.getTok().is(AsmToken::RBrac)) {
2990 // "Dn[]" is the 'all lanes' syntax.
2991 LaneKind = AllLanes;
2992 Parser.Lex(); // Eat the ']'.
2993 return MatchOperand_Success;
2994 }
Jim Grosbachceee9842012-03-19 20:39:53 +00002995
2996 // There's an optional '#' token here. Normally there wouldn't be, but
2997 // inline assemble puts one in, and it's friendly to accept that.
2998 if (Parser.getTok().is(AsmToken::Hash))
2999 Parser.Lex(); // Eat the '#'
3000
Jim Grosbachc9313252011-12-21 01:19:23 +00003001 const MCExpr *LaneIndex;
3002 SMLoc Loc = Parser.getTok().getLoc();
3003 if (getParser().ParseExpression(LaneIndex)) {
3004 Error(Loc, "illegal expression");
3005 return MatchOperand_ParseFail;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003006 }
Jim Grosbachc9313252011-12-21 01:19:23 +00003007 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3008 if (!CE) {
3009 Error(Loc, "lane index must be empty or an integer");
3010 return MatchOperand_ParseFail;
3011 }
3012 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3013 Error(Parser.getTok().getLoc(), "']' expected");
3014 return MatchOperand_ParseFail;
3015 }
3016 Parser.Lex(); // Eat the ']'.
3017 int64_t Val = CE->getValue();
3018
3019 // FIXME: Make this range check context sensitive for .8, .16, .32.
3020 if (Val < 0 || Val > 7) {
3021 Error(Parser.getTok().getLoc(), "lane index out of range");
3022 return MatchOperand_ParseFail;
3023 }
3024 Index = Val;
3025 LaneKind = IndexedLane;
3026 return MatchOperand_Success;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003027 }
3028 LaneKind = NoLanes;
3029 return MatchOperand_Success;
3030}
3031
Jim Grosbach862019c2011-10-18 23:02:30 +00003032// parse a vector register list
3033ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3034parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003035 VectorLaneTy LaneKind;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003036 unsigned LaneIndex;
Jim Grosbach5c984e42011-11-15 21:45:55 +00003037 SMLoc S = Parser.getTok().getLoc();
3038 // As an extension (to match gas), support a plain D register or Q register
3039 // (without encosing curly braces) as a single or double entry list,
3040 // respectively.
3041 if (Parser.getTok().is(AsmToken::Identifier)) {
3042 int Reg = tryParseRegister();
3043 if (Reg == -1)
3044 return MatchOperand_NoMatch;
3045 SMLoc E = Parser.getTok().getLoc();
3046 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jim Grosbach7636bf62011-12-02 00:35:16 +00003047 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex);
Jim Grosbach98b05a52011-11-30 01:09:44 +00003048 if (Res != MatchOperand_Success)
3049 return Res;
3050 switch (LaneKind) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003051 case NoLanes:
3052 E = Parser.getTok().getLoc();
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003053 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00003054 break;
3055 case AllLanes:
3056 E = Parser.getTok().getLoc();
Jim Grosbach3471d4f2011-12-21 00:38:54 +00003057 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3058 S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00003059 break;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003060 case IndexedLane:
3061 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach95fad1c2011-12-20 19:21:26 +00003062 LaneIndex,
3063 false, S, E));
Jim Grosbach7636bf62011-12-02 00:35:16 +00003064 break;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003065 }
Jim Grosbach5c984e42011-11-15 21:45:55 +00003066 return MatchOperand_Success;
3067 }
3068 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3069 Reg = getDRegFromQReg(Reg);
Jim Grosbach7636bf62011-12-02 00:35:16 +00003070 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex);
Jim Grosbach98b05a52011-11-30 01:09:44 +00003071 if (Res != MatchOperand_Success)
3072 return Res;
3073 switch (LaneKind) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003074 case NoLanes:
3075 E = Parser.getTok().getLoc();
Jim Grosbach28f08c92012-03-05 19:33:30 +00003076 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbachc0fc4502012-03-06 22:01:44 +00003077 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003078 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00003079 break;
3080 case AllLanes:
3081 E = Parser.getTok().getLoc();
Jim Grosbachc0fc4502012-03-06 22:01:44 +00003082 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3083 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach3471d4f2011-12-21 00:38:54 +00003084 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3085 S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00003086 break;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003087 case IndexedLane:
3088 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach95fad1c2011-12-20 19:21:26 +00003089 LaneIndex,
3090 false, S, E));
Jim Grosbach7636bf62011-12-02 00:35:16 +00003091 break;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003092 }
Jim Grosbach5c984e42011-11-15 21:45:55 +00003093 return MatchOperand_Success;
3094 }
3095 Error(S, "vector register expected");
3096 return MatchOperand_ParseFail;
3097 }
3098
3099 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbach862019c2011-10-18 23:02:30 +00003100 return MatchOperand_NoMatch;
3101
Jim Grosbach862019c2011-10-18 23:02:30 +00003102 Parser.Lex(); // Eat '{' token.
3103 SMLoc RegLoc = Parser.getTok().getLoc();
3104
3105 int Reg = tryParseRegister();
3106 if (Reg == -1) {
3107 Error(RegLoc, "register expected");
3108 return MatchOperand_ParseFail;
3109 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003110 unsigned Count = 1;
Jim Grosbach276ed032011-12-15 21:54:55 +00003111 int Spacing = 0;
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003112 unsigned FirstReg = Reg;
3113 // The list is of D registers, but we also allow Q regs and just interpret
3114 // them as the two D sub-registers.
3115 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3116 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003117 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3118 // it's ambiguous with four-register single spaced.
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003119 ++Reg;
3120 ++Count;
3121 }
Jim Grosbach7636bf62011-12-02 00:35:16 +00003122 if (parseVectorLane(LaneKind, LaneIndex) != MatchOperand_Success)
Jim Grosbach98b05a52011-11-30 01:09:44 +00003123 return MatchOperand_ParseFail;
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003124
Jim Grosbache43862b2011-11-15 23:19:15 +00003125 while (Parser.getTok().is(AsmToken::Comma) ||
3126 Parser.getTok().is(AsmToken::Minus)) {
3127 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003128 if (!Spacing)
3129 Spacing = 1; // Register range implies a single spaced list.
3130 else if (Spacing == 2) {
3131 Error(Parser.getTok().getLoc(),
3132 "sequential registers in double spaced list");
3133 return MatchOperand_ParseFail;
3134 }
Jim Grosbache43862b2011-11-15 23:19:15 +00003135 Parser.Lex(); // Eat the minus.
3136 SMLoc EndLoc = Parser.getTok().getLoc();
3137 int EndReg = tryParseRegister();
3138 if (EndReg == -1) {
3139 Error(EndLoc, "register expected");
3140 return MatchOperand_ParseFail;
3141 }
3142 // Allow Q regs and just interpret them as the two D sub-registers.
3143 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3144 EndReg = getDRegFromQReg(EndReg) + 1;
3145 // If the register is the same as the start reg, there's nothing
3146 // more to do.
3147 if (Reg == EndReg)
3148 continue;
3149 // The register must be in the same register class as the first.
3150 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
3151 Error(EndLoc, "invalid register in register list");
3152 return MatchOperand_ParseFail;
3153 }
3154 // Ranges must go from low to high.
3155 if (Reg > EndReg) {
3156 Error(EndLoc, "bad range in register list");
3157 return MatchOperand_ParseFail;
3158 }
Jim Grosbach98b05a52011-11-30 01:09:44 +00003159 // Parse the lane specifier if present.
3160 VectorLaneTy NextLaneKind;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003161 unsigned NextLaneIndex;
3162 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
Jim Grosbach98b05a52011-11-30 01:09:44 +00003163 return MatchOperand_ParseFail;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003164 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003165 Error(EndLoc, "mismatched lane index in register list");
3166 return MatchOperand_ParseFail;
3167 }
3168 EndLoc = Parser.getTok().getLoc();
Jim Grosbache43862b2011-11-15 23:19:15 +00003169
3170 // Add all the registers in the range to the register list.
3171 Count += EndReg - Reg;
3172 Reg = EndReg;
3173 continue;
3174 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003175 Parser.Lex(); // Eat the comma.
3176 RegLoc = Parser.getTok().getLoc();
3177 int OldReg = Reg;
3178 Reg = tryParseRegister();
3179 if (Reg == -1) {
3180 Error(RegLoc, "register expected");
3181 return MatchOperand_ParseFail;
3182 }
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003183 // vector register lists must be contiguous.
Jim Grosbach862019c2011-10-18 23:02:30 +00003184 // It's OK to use the enumeration values directly here rather, as the
3185 // VFP register classes have the enum sorted properly.
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003186 //
3187 // The list is of D registers, but we also allow Q regs and just interpret
3188 // them as the two D sub-registers.
3189 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003190 if (!Spacing)
3191 Spacing = 1; // Register range implies a single spaced list.
3192 else if (Spacing == 2) {
3193 Error(RegLoc,
3194 "invalid register in double-spaced list (must be 'D' register')");
3195 return MatchOperand_ParseFail;
3196 }
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003197 Reg = getDRegFromQReg(Reg);
3198 if (Reg != OldReg + 1) {
3199 Error(RegLoc, "non-contiguous register range");
3200 return MatchOperand_ParseFail;
3201 }
3202 ++Reg;
3203 Count += 2;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003204 // Parse the lane specifier if present.
3205 VectorLaneTy NextLaneKind;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003206 unsigned NextLaneIndex;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003207 SMLoc EndLoc = Parser.getTok().getLoc();
Jim Grosbach7636bf62011-12-02 00:35:16 +00003208 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
Jim Grosbach98b05a52011-11-30 01:09:44 +00003209 return MatchOperand_ParseFail;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003210 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003211 Error(EndLoc, "mismatched lane index in register list");
3212 return MatchOperand_ParseFail;
3213 }
Jim Grosbachc73d73e2011-10-28 00:06:50 +00003214 continue;
3215 }
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003216 // Normal D register.
3217 // Figure out the register spacing (single or double) of the list if
3218 // we don't know it already.
3219 if (!Spacing)
3220 Spacing = 1 + (Reg == OldReg + 2);
3221
3222 // Just check that it's contiguous and keep going.
3223 if (Reg != OldReg + Spacing) {
Jim Grosbach862019c2011-10-18 23:02:30 +00003224 Error(RegLoc, "non-contiguous register range");
3225 return MatchOperand_ParseFail;
3226 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003227 ++Count;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003228 // Parse the lane specifier if present.
3229 VectorLaneTy NextLaneKind;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003230 unsigned NextLaneIndex;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003231 SMLoc EndLoc = Parser.getTok().getLoc();
Jim Grosbach7636bf62011-12-02 00:35:16 +00003232 if (parseVectorLane(NextLaneKind, NextLaneIndex) != MatchOperand_Success)
Jim Grosbach98b05a52011-11-30 01:09:44 +00003233 return MatchOperand_ParseFail;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003234 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003235 Error(EndLoc, "mismatched lane index in register list");
3236 return MatchOperand_ParseFail;
3237 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003238 }
3239
3240 SMLoc E = Parser.getTok().getLoc();
3241 if (Parser.getTok().isNot(AsmToken::RCurly)) {
3242 Error(E, "'}' expected");
3243 return MatchOperand_ParseFail;
3244 }
3245 Parser.Lex(); // Eat '}' token.
3246
Jim Grosbach98b05a52011-11-30 01:09:44 +00003247 switch (LaneKind) {
Jim Grosbach98b05a52011-11-30 01:09:44 +00003248 case NoLanes:
Jim Grosbachc0fc4502012-03-06 22:01:44 +00003249 // Two-register operands have been converted to the
Jim Grosbachc3384c92012-03-05 21:43:40 +00003250 // composite register classes.
3251 if (Count == 2) {
3252 const MCRegisterClass *RC = (Spacing == 1) ?
3253 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3254 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3255 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3256 }
Jim Grosbach28f08c92012-03-05 19:33:30 +00003257
Jim Grosbach0aaf4cd2011-12-15 21:44:33 +00003258 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3259 (Spacing == 2), S, E));
Jim Grosbach98b05a52011-11-30 01:09:44 +00003260 break;
3261 case AllLanes:
Jim Grosbachc0fc4502012-03-06 22:01:44 +00003262 // Two-register operands have been converted to the
3263 // composite register classes.
Jim Grosbach4d0983a2012-03-06 23:10:38 +00003264 if (Count == 2) {
3265 const MCRegisterClass *RC = (Spacing == 1) ?
3266 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3267 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbachc0fc4502012-03-06 22:01:44 +00003268 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3269 }
Jim Grosbach98b05a52011-11-30 01:09:44 +00003270 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbach3471d4f2011-12-21 00:38:54 +00003271 (Spacing == 2),
Jim Grosbach98b05a52011-11-30 01:09:44 +00003272 S, E));
3273 break;
Jim Grosbach7636bf62011-12-02 00:35:16 +00003274 case IndexedLane:
3275 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach95fad1c2011-12-20 19:21:26 +00003276 LaneIndex,
3277 (Spacing == 2),
3278 S, E));
Jim Grosbach7636bf62011-12-02 00:35:16 +00003279 break;
Jim Grosbach98b05a52011-11-30 01:09:44 +00003280 }
Jim Grosbach862019c2011-10-18 23:02:30 +00003281 return MatchOperand_Success;
3282}
3283
Jim Grosbach43904292011-07-25 20:14:50 +00003284/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
Jim Grosbachf922c472011-02-12 01:34:40 +00003285ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00003286parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003287 SMLoc S = Parser.getTok().getLoc();
3288 const AsmToken &Tok = Parser.getTok();
Jiangning Liuc1b7ca52012-08-02 08:21:27 +00003289 unsigned Opt;
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003290
Jiangning Liuc1b7ca52012-08-02 08:21:27 +00003291 if (Tok.is(AsmToken::Identifier)) {
3292 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003293
Jiangning Liuc1b7ca52012-08-02 08:21:27 +00003294 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3295 .Case("sy", ARM_MB::SY)
3296 .Case("st", ARM_MB::ST)
3297 .Case("sh", ARM_MB::ISH)
3298 .Case("ish", ARM_MB::ISH)
3299 .Case("shst", ARM_MB::ISHST)
3300 .Case("ishst", ARM_MB::ISHST)
3301 .Case("nsh", ARM_MB::NSH)
3302 .Case("un", ARM_MB::NSH)
3303 .Case("nshst", ARM_MB::NSHST)
3304 .Case("unst", ARM_MB::NSHST)
3305 .Case("osh", ARM_MB::OSH)
3306 .Case("oshst", ARM_MB::OSHST)
3307 .Default(~0U);
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003308
Jiangning Liuc1b7ca52012-08-02 08:21:27 +00003309 if (Opt == ~0U)
3310 return MatchOperand_NoMatch;
3311
3312 Parser.Lex(); // Eat identifier token.
3313 } else if (Tok.is(AsmToken::Hash) ||
3314 Tok.is(AsmToken::Dollar) ||
3315 Tok.is(AsmToken::Integer)) {
3316 if (Parser.getTok().isNot(AsmToken::Integer))
3317 Parser.Lex(); // Eat the '#'.
3318 SMLoc Loc = Parser.getTok().getLoc();
3319
3320 const MCExpr *MemBarrierID;
3321 if (getParser().ParseExpression(MemBarrierID)) {
3322 Error(Loc, "illegal expression");
3323 return MatchOperand_ParseFail;
3324 }
3325
3326 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3327 if (!CE) {
3328 Error(Loc, "constant expression expected");
3329 return MatchOperand_ParseFail;
3330 }
3331
3332 int Val = CE->getValue();
3333 if (Val & ~0xf) {
3334 Error(Loc, "immediate value out of range");
3335 return MatchOperand_ParseFail;
3336 }
3337
3338 Opt = ARM_MB::RESERVED_0 + Val;
3339 } else
3340 return MatchOperand_ParseFail;
3341
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003342 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbachf922c472011-02-12 01:34:40 +00003343 return MatchOperand_Success;
Bruno Cardoso Lopes706d9462011-02-07 22:09:15 +00003344}
3345
Jim Grosbach43904292011-07-25 20:14:50 +00003346/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003347ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00003348parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003349 SMLoc S = Parser.getTok().getLoc();
3350 const AsmToken &Tok = Parser.getTok();
Richard Bartona1c73672012-06-14 10:48:04 +00003351 if (!Tok.is(AsmToken::Identifier))
3352 return MatchOperand_NoMatch;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003353 StringRef IFlagsStr = Tok.getString();
3354
Owen Anderson2dbb46a2011-10-05 17:16:40 +00003355 // An iflags string of "none" is interpreted to mean that none of the AIF
3356 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003357 unsigned IFlags = 0;
Owen Anderson2dbb46a2011-10-05 17:16:40 +00003358 if (IFlagsStr != "none") {
3359 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3360 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3361 .Case("a", ARM_PROC::A)
3362 .Case("i", ARM_PROC::I)
3363 .Case("f", ARM_PROC::F)
3364 .Default(~0U);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003365
Owen Anderson2dbb46a2011-10-05 17:16:40 +00003366 // If some specific iflag is already set, it means that some letter is
3367 // present more than once, this is not acceptable.
3368 if (Flag == ~0U || (IFlags & Flag))
3369 return MatchOperand_NoMatch;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003370
Owen Anderson2dbb46a2011-10-05 17:16:40 +00003371 IFlags |= Flag;
3372 }
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003373 }
3374
3375 Parser.Lex(); // Eat identifier token.
3376 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3377 return MatchOperand_Success;
3378}
3379
Jim Grosbach43904292011-07-25 20:14:50 +00003380/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003381ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach43904292011-07-25 20:14:50 +00003382parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003383 SMLoc S = Parser.getTok().getLoc();
3384 const AsmToken &Tok = Parser.getTok();
3385 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
3386 StringRef Mask = Tok.getString();
3387
James Molloyacad68d2011-09-28 14:21:38 +00003388 if (isMClass()) {
3389 // See ARMv6-M 10.1.1
Jim Grosbachb84ad4a2012-03-15 21:34:14 +00003390 std::string Name = Mask.lower();
3391 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderby0fd4f3c2012-05-17 22:18:01 +00003392 // Note: in the documentation:
3393 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3394 // for MSR APSR_nzcvq.
3395 // but we do make it an alias here. This is so to get the "mask encoding"
3396 // bits correct on MSR APSR writes.
3397 //
3398 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3399 // should really only be allowed when writing a special register. Note
3400 // they get dropped in the MRS instruction reading a special register as
3401 // the SYSm field is only 8 bits.
3402 //
3403 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3404 // includes the DSP extension but that is not checked.
3405 .Case("apsr", 0x800)
3406 .Case("apsr_nzcvq", 0x800)
3407 .Case("apsr_g", 0x400)
3408 .Case("apsr_nzcvqg", 0xc00)
3409 .Case("iapsr", 0x801)
3410 .Case("iapsr_nzcvq", 0x801)
3411 .Case("iapsr_g", 0x401)
3412 .Case("iapsr_nzcvqg", 0xc01)
3413 .Case("eapsr", 0x802)
3414 .Case("eapsr_nzcvq", 0x802)
3415 .Case("eapsr_g", 0x402)
3416 .Case("eapsr_nzcvqg", 0xc02)
3417 .Case("xpsr", 0x803)
3418 .Case("xpsr_nzcvq", 0x803)
3419 .Case("xpsr_g", 0x403)
3420 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderbyf49a4092012-06-15 22:14:44 +00003421 .Case("ipsr", 0x805)
3422 .Case("epsr", 0x806)
3423 .Case("iepsr", 0x807)
3424 .Case("msp", 0x808)
3425 .Case("psp", 0x809)
3426 .Case("primask", 0x810)
3427 .Case("basepri", 0x811)
3428 .Case("basepri_max", 0x812)
3429 .Case("faultmask", 0x813)
3430 .Case("control", 0x814)
James Molloyacad68d2011-09-28 14:21:38 +00003431 .Default(~0U);
Jim Grosbach18c8d122011-12-22 17:17:10 +00003432
James Molloyacad68d2011-09-28 14:21:38 +00003433 if (FlagsVal == ~0U)
3434 return MatchOperand_NoMatch;
3435
Kevin Enderbyf49a4092012-06-15 22:14:44 +00003436 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloyacad68d2011-09-28 14:21:38 +00003437 // basepri, basepri_max and faultmask only valid for V7m.
3438 return MatchOperand_NoMatch;
Jim Grosbach18c8d122011-12-22 17:17:10 +00003439
James Molloyacad68d2011-09-28 14:21:38 +00003440 Parser.Lex(); // Eat identifier token.
3441 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3442 return MatchOperand_Success;
3443 }
3444
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003445 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3446 size_t Start = 0, Next = Mask.find('_');
3447 StringRef Flags = "";
Benjamin Kramer59085362011-11-06 20:37:06 +00003448 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003449 if (Next != StringRef::npos)
3450 Flags = Mask.slice(Next+1, Mask.size());
3451
3452 // FlagsVal contains the complete mask:
3453 // 3-0: Mask
3454 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3455 unsigned FlagsVal = 0;
3456
3457 if (SpecReg == "apsr") {
3458 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachb29b4dd2011-07-19 22:45:10 +00003459 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003460 .Case("g", 0x4) // same as CPSR_s
3461 .Case("nzcvqg", 0xc) // same as CPSR_fs
3462 .Default(~0U);
3463
Joerg Sonnenberger4b19c982011-02-19 00:43:45 +00003464 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003465 if (!Flags.empty())
3466 return MatchOperand_NoMatch;
3467 else
Jim Grosbachbf841cf2011-09-14 20:03:46 +00003468 FlagsVal = 8; // No flag
Joerg Sonnenberger4b19c982011-02-19 00:43:45 +00003469 }
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003470 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbachb657a902012-04-05 03:17:53 +00003471 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3472 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes56926a32011-05-25 00:35:03 +00003473 Flags = "fc";
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003474 for (int i = 0, e = Flags.size(); i != e; ++i) {
3475 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3476 .Case("c", 1)
3477 .Case("x", 2)
3478 .Case("s", 4)
3479 .Case("f", 8)
3480 .Default(~0U);
3481
3482 // If some specific flag is already set, it means that some letter is
3483 // present more than once, this is not acceptable.
3484 if (FlagsVal == ~0U || (FlagsVal & Flag))
3485 return MatchOperand_NoMatch;
3486 FlagsVal |= Flag;
3487 }
3488 } else // No match for special register.
3489 return MatchOperand_NoMatch;
3490
Owen Anderson7784f1d2011-10-21 18:43:28 +00003491 // Special register without flags is NOT equivalent to "fc" flags.
3492 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3493 // two lines would enable gas compatibility at the expense of breaking
3494 // round-tripping.
3495 //
3496 // if (!FlagsVal)
3497 // FlagsVal = 0x9;
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003498
3499 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3500 if (SpecReg == "spsr")
3501 FlagsVal |= 16;
3502
3503 Parser.Lex(); // Eat identifier token.
3504 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3505 return MatchOperand_Success;
3506}
3507
Jim Grosbachf6c05252011-07-21 17:23:04 +00003508ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3509parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3510 int Low, int High) {
3511 const AsmToken &Tok = Parser.getTok();
3512 if (Tok.isNot(AsmToken::Identifier)) {
3513 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3514 return MatchOperand_ParseFail;
3515 }
3516 StringRef ShiftName = Tok.getString();
Benjamin Kramer59085362011-11-06 20:37:06 +00003517 std::string LowerOp = Op.lower();
3518 std::string UpperOp = Op.upper();
Jim Grosbachf6c05252011-07-21 17:23:04 +00003519 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3520 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3521 return MatchOperand_ParseFail;
3522 }
3523 Parser.Lex(); // Eat shift type token.
3524
3525 // There must be a '#' and a shift amount.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003526 if (Parser.getTok().isNot(AsmToken::Hash) &&
3527 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbachf6c05252011-07-21 17:23:04 +00003528 Error(Parser.getTok().getLoc(), "'#' expected");
3529 return MatchOperand_ParseFail;
3530 }
3531 Parser.Lex(); // Eat hash token.
3532
3533 const MCExpr *ShiftAmount;
3534 SMLoc Loc = Parser.getTok().getLoc();
3535 if (getParser().ParseExpression(ShiftAmount)) {
3536 Error(Loc, "illegal expression");
3537 return MatchOperand_ParseFail;
3538 }
3539 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3540 if (!CE) {
3541 Error(Loc, "constant expression expected");
3542 return MatchOperand_ParseFail;
3543 }
3544 int Val = CE->getValue();
3545 if (Val < Low || Val > High) {
3546 Error(Loc, "immediate value out of range");
3547 return MatchOperand_ParseFail;
3548 }
3549
3550 Operands.push_back(ARMOperand::CreateImm(CE, Loc, Parser.getTok().getLoc()));
3551
3552 return MatchOperand_Success;
3553}
3554
Jim Grosbachc27d4f92011-07-22 17:44:50 +00003555ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3556parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3557 const AsmToken &Tok = Parser.getTok();
3558 SMLoc S = Tok.getLoc();
3559 if (Tok.isNot(AsmToken::Identifier)) {
3560 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3561 return MatchOperand_ParseFail;
3562 }
3563 int Val = StringSwitch<int>(Tok.getString())
3564 .Case("be", 1)
3565 .Case("le", 0)
3566 .Default(-1);
3567 Parser.Lex(); // Eat the token.
3568
3569 if (Val == -1) {
3570 Error(Tok.getLoc(), "'be' or 'le' operand expected");
3571 return MatchOperand_ParseFail;
3572 }
3573 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3574 getContext()),
3575 S, Parser.getTok().getLoc()));
3576 return MatchOperand_Success;
3577}
3578
Jim Grosbach580f4a92011-07-25 22:20:28 +00003579/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3580/// instructions. Legal values are:
3581/// lsl #n 'n' in [0,31]
3582/// asr #n 'n' in [1,32]
3583/// n == 32 encoded as n == 0.
3584ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3585parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3586 const AsmToken &Tok = Parser.getTok();
3587 SMLoc S = Tok.getLoc();
3588 if (Tok.isNot(AsmToken::Identifier)) {
3589 Error(S, "shift operator 'asr' or 'lsl' expected");
3590 return MatchOperand_ParseFail;
3591 }
3592 StringRef ShiftName = Tok.getString();
3593 bool isASR;
3594 if (ShiftName == "lsl" || ShiftName == "LSL")
3595 isASR = false;
3596 else if (ShiftName == "asr" || ShiftName == "ASR")
3597 isASR = true;
3598 else {
3599 Error(S, "shift operator 'asr' or 'lsl' expected");
3600 return MatchOperand_ParseFail;
3601 }
3602 Parser.Lex(); // Eat the operator.
3603
3604 // A '#' and a shift amount.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003605 if (Parser.getTok().isNot(AsmToken::Hash) &&
3606 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach580f4a92011-07-25 22:20:28 +00003607 Error(Parser.getTok().getLoc(), "'#' expected");
3608 return MatchOperand_ParseFail;
3609 }
3610 Parser.Lex(); // Eat hash token.
3611
3612 const MCExpr *ShiftAmount;
3613 SMLoc E = Parser.getTok().getLoc();
3614 if (getParser().ParseExpression(ShiftAmount)) {
3615 Error(E, "malformed shift expression");
3616 return MatchOperand_ParseFail;
3617 }
3618 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3619 if (!CE) {
3620 Error(E, "shift amount must be an immediate");
3621 return MatchOperand_ParseFail;
3622 }
3623
3624 int64_t Val = CE->getValue();
3625 if (isASR) {
3626 // Shift amount must be in [1,32]
3627 if (Val < 1 || Val > 32) {
3628 Error(E, "'asr' shift amount must be in range [1,32]");
3629 return MatchOperand_ParseFail;
3630 }
Owen Anderson0afa0092011-09-26 21:06:22 +00003631 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3632 if (isThumb() && Val == 32) {
3633 Error(E, "'asr #32' shift amount not allowed in Thumb mode");
3634 return MatchOperand_ParseFail;
3635 }
Jim Grosbach580f4a92011-07-25 22:20:28 +00003636 if (Val == 32) Val = 0;
3637 } else {
3638 // Shift amount must be in [1,32]
3639 if (Val < 0 || Val > 31) {
3640 Error(E, "'lsr' shift amount must be in range [0,31]");
3641 return MatchOperand_ParseFail;
3642 }
3643 }
3644
3645 E = Parser.getTok().getLoc();
3646 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, E));
3647
3648 return MatchOperand_Success;
3649}
3650
Jim Grosbach7e1547e2011-07-27 20:15:40 +00003651/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3652/// of instructions. Legal values are:
3653/// ror #n 'n' in {0, 8, 16, 24}
3654ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3655parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3656 const AsmToken &Tok = Parser.getTok();
3657 SMLoc S = Tok.getLoc();
Jim Grosbach326efe52011-09-19 20:29:33 +00003658 if (Tok.isNot(AsmToken::Identifier))
3659 return MatchOperand_NoMatch;
Jim Grosbach7e1547e2011-07-27 20:15:40 +00003660 StringRef ShiftName = Tok.getString();
Jim Grosbach326efe52011-09-19 20:29:33 +00003661 if (ShiftName != "ror" && ShiftName != "ROR")
3662 return MatchOperand_NoMatch;
Jim Grosbach7e1547e2011-07-27 20:15:40 +00003663 Parser.Lex(); // Eat the operator.
3664
3665 // A '#' and a rotate amount.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003666 if (Parser.getTok().isNot(AsmToken::Hash) &&
3667 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach7e1547e2011-07-27 20:15:40 +00003668 Error(Parser.getTok().getLoc(), "'#' expected");
3669 return MatchOperand_ParseFail;
3670 }
3671 Parser.Lex(); // Eat hash token.
3672
3673 const MCExpr *ShiftAmount;
3674 SMLoc E = Parser.getTok().getLoc();
3675 if (getParser().ParseExpression(ShiftAmount)) {
3676 Error(E, "malformed rotate expression");
3677 return MatchOperand_ParseFail;
3678 }
3679 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3680 if (!CE) {
3681 Error(E, "rotate amount must be an immediate");
3682 return MatchOperand_ParseFail;
3683 }
3684
3685 int64_t Val = CE->getValue();
3686 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
3687 // normally, zero is represented in asm by omitting the rotate operand
3688 // entirely.
3689 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
3690 Error(E, "'ror' rotate amount must be 8, 16, or 24");
3691 return MatchOperand_ParseFail;
3692 }
3693
3694 E = Parser.getTok().getLoc();
3695 Operands.push_back(ARMOperand::CreateRotImm(Val, S, E));
3696
3697 return MatchOperand_Success;
3698}
3699
Jim Grosbach293a2ee2011-07-28 21:34:26 +00003700ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3701parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3702 SMLoc S = Parser.getTok().getLoc();
3703 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003704 if (Parser.getTok().isNot(AsmToken::Hash) &&
3705 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach293a2ee2011-07-28 21:34:26 +00003706 Error(Parser.getTok().getLoc(), "'#' expected");
3707 return MatchOperand_ParseFail;
3708 }
3709 Parser.Lex(); // Eat hash token.
3710
3711 const MCExpr *LSBExpr;
3712 SMLoc E = Parser.getTok().getLoc();
3713 if (getParser().ParseExpression(LSBExpr)) {
3714 Error(E, "malformed immediate expression");
3715 return MatchOperand_ParseFail;
3716 }
3717 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
3718 if (!CE) {
3719 Error(E, "'lsb' operand must be an immediate");
3720 return MatchOperand_ParseFail;
3721 }
3722
3723 int64_t LSB = CE->getValue();
3724 // The LSB must be in the range [0,31]
3725 if (LSB < 0 || LSB > 31) {
3726 Error(E, "'lsb' operand must be in the range [0,31]");
3727 return MatchOperand_ParseFail;
3728 }
3729 E = Parser.getTok().getLoc();
3730
3731 // Expect another immediate operand.
3732 if (Parser.getTok().isNot(AsmToken::Comma)) {
3733 Error(Parser.getTok().getLoc(), "too few operands");
3734 return MatchOperand_ParseFail;
3735 }
3736 Parser.Lex(); // Eat hash token.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003737 if (Parser.getTok().isNot(AsmToken::Hash) &&
3738 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach293a2ee2011-07-28 21:34:26 +00003739 Error(Parser.getTok().getLoc(), "'#' expected");
3740 return MatchOperand_ParseFail;
3741 }
3742 Parser.Lex(); // Eat hash token.
3743
3744 const MCExpr *WidthExpr;
3745 if (getParser().ParseExpression(WidthExpr)) {
3746 Error(E, "malformed immediate expression");
3747 return MatchOperand_ParseFail;
3748 }
3749 CE = dyn_cast<MCConstantExpr>(WidthExpr);
3750 if (!CE) {
3751 Error(E, "'width' operand must be an immediate");
3752 return MatchOperand_ParseFail;
3753 }
3754
3755 int64_t Width = CE->getValue();
3756 // The LSB must be in the range [1,32-lsb]
3757 if (Width < 1 || Width > 32 - LSB) {
3758 Error(E, "'width' operand must be in the range [1,32-lsb]");
3759 return MatchOperand_ParseFail;
3760 }
3761 E = Parser.getTok().getLoc();
3762
3763 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, E));
3764
3765 return MatchOperand_Success;
3766}
3767
Jim Grosbach7ce05792011-08-03 23:50:40 +00003768ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3769parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3770 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00003771 // postidx_reg := '+' register {, shift}
3772 // | '-' register {, shift}
3773 // | register {, shift}
Jim Grosbach7ce05792011-08-03 23:50:40 +00003774
3775 // This method must return MatchOperand_NoMatch without consuming any tokens
3776 // in the case where there is no match, as other alternatives take other
3777 // parse methods.
3778 AsmToken Tok = Parser.getTok();
3779 SMLoc S = Tok.getLoc();
3780 bool haveEaten = false;
Jim Grosbach16578b52011-08-05 16:11:38 +00003781 bool isAdd = true;
Jim Grosbach7ce05792011-08-03 23:50:40 +00003782 int Reg = -1;
3783 if (Tok.is(AsmToken::Plus)) {
3784 Parser.Lex(); // Eat the '+' token.
3785 haveEaten = true;
3786 } else if (Tok.is(AsmToken::Minus)) {
3787 Parser.Lex(); // Eat the '-' token.
Jim Grosbach16578b52011-08-05 16:11:38 +00003788 isAdd = false;
Jim Grosbach7ce05792011-08-03 23:50:40 +00003789 haveEaten = true;
3790 }
3791 if (Parser.getTok().is(AsmToken::Identifier))
3792 Reg = tryParseRegister();
3793 if (Reg == -1) {
3794 if (!haveEaten)
3795 return MatchOperand_NoMatch;
3796 Error(Parser.getTok().getLoc(), "register expected");
3797 return MatchOperand_ParseFail;
3798 }
3799 SMLoc E = Parser.getTok().getLoc();
3800
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00003801 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
3802 unsigned ShiftImm = 0;
Jim Grosbach0d6fac32011-08-05 22:03:36 +00003803 if (Parser.getTok().is(AsmToken::Comma)) {
3804 Parser.Lex(); // Eat the ','.
3805 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
3806 return MatchOperand_ParseFail;
3807 }
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00003808
3809 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
3810 ShiftImm, S, E));
Jim Grosbach7ce05792011-08-03 23:50:40 +00003811
3812 return MatchOperand_Success;
3813}
3814
Jim Grosbach251bf252011-08-10 21:56:18 +00003815ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3816parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3817 // Check for a post-index addressing register operand. Specifically:
3818 // am3offset := '+' register
3819 // | '-' register
3820 // | register
3821 // | # imm
3822 // | # + imm
3823 // | # - imm
3824
3825 // This method must return MatchOperand_NoMatch without consuming any tokens
3826 // in the case where there is no match, as other alternatives take other
3827 // parse methods.
3828 AsmToken Tok = Parser.getTok();
3829 SMLoc S = Tok.getLoc();
3830
3831 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00003832 if (Parser.getTok().is(AsmToken::Hash) ||
3833 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach251bf252011-08-10 21:56:18 +00003834 Parser.Lex(); // Eat the '#'.
3835 // Explicitly look for a '-', as we need to encode negative zero
3836 // differently.
3837 bool isNegative = Parser.getTok().is(AsmToken::Minus);
3838 const MCExpr *Offset;
3839 if (getParser().ParseExpression(Offset))
3840 return MatchOperand_ParseFail;
3841 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
3842 if (!CE) {
3843 Error(S, "constant expression expected");
3844 return MatchOperand_ParseFail;
3845 }
3846 SMLoc E = Tok.getLoc();
3847 // Negative zero is encoded as the flag value INT32_MIN.
3848 int32_t Val = CE->getValue();
3849 if (isNegative && Val == 0)
3850 Val = INT32_MIN;
3851
3852 Operands.push_back(
3853 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
3854
3855 return MatchOperand_Success;
3856 }
3857
3858
3859 bool haveEaten = false;
3860 bool isAdd = true;
3861 int Reg = -1;
3862 if (Tok.is(AsmToken::Plus)) {
3863 Parser.Lex(); // Eat the '+' token.
3864 haveEaten = true;
3865 } else if (Tok.is(AsmToken::Minus)) {
3866 Parser.Lex(); // Eat the '-' token.
3867 isAdd = false;
3868 haveEaten = true;
3869 }
3870 if (Parser.getTok().is(AsmToken::Identifier))
3871 Reg = tryParseRegister();
3872 if (Reg == -1) {
3873 if (!haveEaten)
3874 return MatchOperand_NoMatch;
3875 Error(Parser.getTok().getLoc(), "register expected");
3876 return MatchOperand_ParseFail;
3877 }
3878 SMLoc E = Parser.getTok().getLoc();
3879
3880 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
3881 0, S, E));
3882
3883 return MatchOperand_Success;
3884}
3885
Jim Grosbacha77295d2011-09-08 22:07:06 +00003886/// cvtT2LdrdPre - Convert parsed operands to MCInst.
3887/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3888/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00003889void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00003890cvtT2LdrdPre(MCInst &Inst,
Jim Grosbacha77295d2011-09-08 22:07:06 +00003891 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3892 // Rt, Rt2
3893 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3894 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3895 // Create a writeback register dummy placeholder.
3896 Inst.addOperand(MCOperand::CreateReg(0));
3897 // addr
3898 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3899 // pred
3900 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbacha77295d2011-09-08 22:07:06 +00003901}
3902
3903/// cvtT2StrdPre - Convert parsed operands to MCInst.
3904/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3905/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00003906void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00003907cvtT2StrdPre(MCInst &Inst,
Jim Grosbacha77295d2011-09-08 22:07:06 +00003908 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3909 // Create a writeback register dummy placeholder.
3910 Inst.addOperand(MCOperand::CreateReg(0));
3911 // Rt, Rt2
3912 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3913 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
3914 // addr
3915 ((ARMOperand*)Operands[4])->addMemImm8s4OffsetOperands(Inst, 2);
3916 // pred
3917 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbacha77295d2011-09-08 22:07:06 +00003918}
3919
Jim Grosbacheeec0252011-09-08 00:39:19 +00003920/// cvtLdWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3921/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3922/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00003923void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00003924cvtLdWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbacheeec0252011-09-08 00:39:19 +00003925 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3926 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3927
3928 // Create a writeback register dummy placeholder.
3929 Inst.addOperand(MCOperand::CreateImm(0));
3930
3931 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3932 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbacheeec0252011-09-08 00:39:19 +00003933}
3934
Jim Grosbachee2c2a42011-09-16 21:55:56 +00003935/// cvtStWriteBackRegT2AddrModeImm8 - Convert parsed operands to MCInst.
3936/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3937/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00003938void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00003939cvtStWriteBackRegT2AddrModeImm8(MCInst &Inst,
Jim Grosbachee2c2a42011-09-16 21:55:56 +00003940 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3941 // Create a writeback register dummy placeholder.
3942 Inst.addOperand(MCOperand::CreateImm(0));
3943 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3944 ((ARMOperand*)Operands[3])->addMemImm8OffsetOperands(Inst, 2);
3945 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbachee2c2a42011-09-16 21:55:56 +00003946}
3947
Jim Grosbach1355cf12011-07-26 17:10:22 +00003948/// cvtLdWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003949/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3950/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00003951void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00003952cvtLdWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003953 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3954 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3955
3956 // Create a writeback register dummy placeholder.
3957 Inst.addOperand(MCOperand::CreateImm(0));
3958
Jim Grosbach7ce05792011-08-03 23:50:40 +00003959 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003960 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003961}
3962
Owen Anderson9ab0f252011-08-26 20:43:14 +00003963/// cvtLdWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3964/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3965/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00003966void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00003967cvtLdWriteBackRegAddrModeImm12(MCInst &Inst,
Owen Anderson9ab0f252011-08-26 20:43:14 +00003968 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3969 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3970
3971 // Create a writeback register dummy placeholder.
3972 Inst.addOperand(MCOperand::CreateImm(0));
3973
3974 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3975 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Owen Anderson9ab0f252011-08-26 20:43:14 +00003976}
3977
3978
Jim Grosbach548340c2011-08-11 19:22:40 +00003979/// cvtStWriteBackRegAddrModeImm12 - Convert parsed operands to MCInst.
3980/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3981/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00003982void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00003983cvtStWriteBackRegAddrModeImm12(MCInst &Inst,
Jim Grosbach548340c2011-08-11 19:22:40 +00003984 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3985 // Create a writeback register dummy placeholder.
3986 Inst.addOperand(MCOperand::CreateImm(0));
3987 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
3988 ((ARMOperand*)Operands[3])->addMemImm12OffsetOperands(Inst, 2);
3989 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach548340c2011-08-11 19:22:40 +00003990}
3991
Jim Grosbach1355cf12011-07-26 17:10:22 +00003992/// cvtStWriteBackRegAddrMode2 - Convert parsed operands to MCInst.
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003993/// Needed here because the Asm Gen Matcher can't handle properly tied operands
3994/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00003995void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00003996cvtStWriteBackRegAddrMode2(MCInst &Inst,
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00003997 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3998 // Create a writeback register dummy placeholder.
3999 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbach548340c2011-08-11 19:22:40 +00004000 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4001 ((ARMOperand*)Operands[3])->addAddrMode2Operands(Inst, 3);
4002 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach7ce05792011-08-03 23:50:40 +00004003}
4004
Jim Grosbach7b8f46c2011-08-11 21:17:22 +00004005/// cvtStWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
4006/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4007/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00004008void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004009cvtStWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbach7b8f46c2011-08-11 21:17:22 +00004010 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4011 // Create a writeback register dummy placeholder.
4012 Inst.addOperand(MCOperand::CreateImm(0));
4013 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4014 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4015 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach7b8f46c2011-08-11 21:17:22 +00004016}
4017
Jim Grosbach7ce05792011-08-03 23:50:40 +00004018/// cvtLdExtTWriteBackImm - Convert parsed operands to MCInst.
4019/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4020/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00004021void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004022cvtLdExtTWriteBackImm(MCInst &Inst,
Jim Grosbach7ce05792011-08-03 23:50:40 +00004023 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4024 // Rt
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00004025 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Jim Grosbach7ce05792011-08-03 23:50:40 +00004026 // Create a writeback register dummy placeholder.
4027 Inst.addOperand(MCOperand::CreateImm(0));
4028 // addr
4029 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4030 // offset
4031 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4032 // pred
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00004033 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesae085542011-03-31 23:26:08 +00004034}
4035
Jim Grosbach7ce05792011-08-03 23:50:40 +00004036/// cvtLdExtTWriteBackReg - Convert parsed operands to MCInst.
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004037/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4038/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00004039void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004040cvtLdExtTWriteBackReg(MCInst &Inst,
Jim Grosbach7ce05792011-08-03 23:50:40 +00004041 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4042 // Rt
Owen Andersonaa3402e2011-07-28 17:18:57 +00004043 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004044 // Create a writeback register dummy placeholder.
4045 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbach7ce05792011-08-03 23:50:40 +00004046 // addr
4047 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4048 // offset
4049 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4050 // pred
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004051 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004052}
4053
Jim Grosbach7ce05792011-08-03 23:50:40 +00004054/// cvtStExtTWriteBackImm - Convert parsed operands to MCInst.
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004055/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4056/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00004057void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004058cvtStExtTWriteBackImm(MCInst &Inst,
Jim Grosbach7ce05792011-08-03 23:50:40 +00004059 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004060 // Create a writeback register dummy placeholder.
4061 Inst.addOperand(MCOperand::CreateImm(0));
Jim Grosbach7ce05792011-08-03 23:50:40 +00004062 // Rt
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004063 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
Jim Grosbach7ce05792011-08-03 23:50:40 +00004064 // addr
4065 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4066 // offset
4067 ((ARMOperand*)Operands[4])->addPostIdxImm8Operands(Inst, 1);
4068 // pred
4069 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach7ce05792011-08-03 23:50:40 +00004070}
4071
4072/// cvtStExtTWriteBackReg - Convert parsed operands to MCInst.
4073/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4074/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00004075void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004076cvtStExtTWriteBackReg(MCInst &Inst,
Jim Grosbach7ce05792011-08-03 23:50:40 +00004077 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4078 // Create a writeback register dummy placeholder.
4079 Inst.addOperand(MCOperand::CreateImm(0));
4080 // Rt
4081 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4082 // addr
4083 ((ARMOperand*)Operands[3])->addMemNoOffsetOperands(Inst, 1);
4084 // offset
4085 ((ARMOperand*)Operands[4])->addPostIdxRegOperands(Inst, 2);
4086 // pred
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004087 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Bruno Cardoso Lopesac79e4c2011-04-04 17:18:19 +00004088}
4089
Jim Grosbach2fd2b872011-08-10 20:29:19 +00004090/// cvtLdrdPre - Convert parsed operands to MCInst.
4091/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4092/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00004093void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004094cvtLdrdPre(MCInst &Inst,
Jim Grosbach2fd2b872011-08-10 20:29:19 +00004095 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4096 // Rt, Rt2
4097 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4098 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4099 // Create a writeback register dummy placeholder.
4100 Inst.addOperand(MCOperand::CreateImm(0));
4101 // addr
4102 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4103 // pred
4104 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach2fd2b872011-08-10 20:29:19 +00004105}
4106
Jim Grosbach14605d12011-08-11 20:28:23 +00004107/// cvtStrdPre - Convert parsed operands to MCInst.
4108/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4109/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00004110void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004111cvtStrdPre(MCInst &Inst,
Jim Grosbach14605d12011-08-11 20:28:23 +00004112 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4113 // Create a writeback register dummy placeholder.
4114 Inst.addOperand(MCOperand::CreateImm(0));
4115 // Rt, Rt2
4116 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4117 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4118 // addr
4119 ((ARMOperand*)Operands[4])->addAddrMode3Operands(Inst, 3);
4120 // pred
4121 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach14605d12011-08-11 20:28:23 +00004122}
4123
Jim Grosbach623a4542011-08-10 22:42:16 +00004124/// cvtLdWriteBackRegAddrMode3 - Convert parsed operands to MCInst.
4125/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4126/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00004127void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004128cvtLdWriteBackRegAddrMode3(MCInst &Inst,
Jim Grosbach623a4542011-08-10 22:42:16 +00004129 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4130 ((ARMOperand*)Operands[2])->addRegOperands(Inst, 1);
4131 // Create a writeback register dummy placeholder.
4132 Inst.addOperand(MCOperand::CreateImm(0));
4133 ((ARMOperand*)Operands[3])->addAddrMode3Operands(Inst, 3);
4134 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach623a4542011-08-10 22:42:16 +00004135}
4136
Chad Rosier1122fc42012-08-30 23:00:00 +00004137/// cvtThumbMultiply - Convert parsed operands to MCInst.
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00004138/// Needed here because the Asm Gen Matcher can't handle properly tied operands
4139/// when they refer multiple MIOperands inside a single one.
Chad Rosier359956d2012-08-31 00:03:31 +00004140void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004141cvtThumbMultiply(MCInst &Inst,
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00004142 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00004143 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4144 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
Jim Grosbach1b332862011-11-10 22:10:12 +00004145 // If we have a three-operand form, make sure to set Rn to be the operand
4146 // that isn't the same as Rd.
4147 unsigned RegOp = 4;
4148 if (Operands.size() == 6 &&
4149 ((ARMOperand*)Operands[4])->getReg() ==
4150 ((ARMOperand*)Operands[3])->getReg())
4151 RegOp = 5;
4152 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4153 Inst.addOperand(Inst.getOperand(0));
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00004154 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
Jim Grosbach88ae2bc2011-08-19 22:07:46 +00004155}
Jim Grosbach623a4542011-08-10 22:42:16 +00004156
Chad Rosier359956d2012-08-31 00:03:31 +00004157void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004158cvtVLDwbFixed(MCInst &Inst,
Jim Grosbach12431322011-10-24 22:16:58 +00004159 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4160 // Vd
Jim Grosbach6029b6d2011-11-29 23:51:09 +00004161 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach12431322011-10-24 22:16:58 +00004162 // Create a writeback register dummy placeholder.
4163 Inst.addOperand(MCOperand::CreateImm(0));
4164 // Vn
4165 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4166 // pred
4167 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach12431322011-10-24 22:16:58 +00004168}
4169
Chad Rosier359956d2012-08-31 00:03:31 +00004170void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004171cvtVLDwbRegister(MCInst &Inst,
Jim Grosbach12431322011-10-24 22:16:58 +00004172 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4173 // Vd
Jim Grosbach6029b6d2011-11-29 23:51:09 +00004174 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach12431322011-10-24 22:16:58 +00004175 // Create a writeback register dummy placeholder.
4176 Inst.addOperand(MCOperand::CreateImm(0));
4177 // Vn
4178 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4179 // Vm
4180 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4181 // pred
4182 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach12431322011-10-24 22:16:58 +00004183}
4184
Chad Rosier359956d2012-08-31 00:03:31 +00004185void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004186cvtVSTwbFixed(MCInst &Inst,
Jim Grosbach4334e032011-10-31 21:50:31 +00004187 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4188 // Create a writeback register dummy placeholder.
4189 Inst.addOperand(MCOperand::CreateImm(0));
4190 // Vn
4191 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4192 // Vt
Jim Grosbach6029b6d2011-11-29 23:51:09 +00004193 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach4334e032011-10-31 21:50:31 +00004194 // pred
4195 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach4334e032011-10-31 21:50:31 +00004196}
4197
Chad Rosier359956d2012-08-31 00:03:31 +00004198void ARMAsmParser::
Chad Rosier756d2cc2012-08-31 22:12:31 +00004199cvtVSTwbRegister(MCInst &Inst,
Jim Grosbach4334e032011-10-31 21:50:31 +00004200 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4201 // Create a writeback register dummy placeholder.
4202 Inst.addOperand(MCOperand::CreateImm(0));
4203 // Vn
4204 ((ARMOperand*)Operands[4])->addAlignedMemoryOperands(Inst, 2);
4205 // Vm
4206 ((ARMOperand*)Operands[5])->addRegOperands(Inst, 1);
4207 // Vt
Jim Grosbach6029b6d2011-11-29 23:51:09 +00004208 ((ARMOperand*)Operands[3])->addVecListOperands(Inst, 1);
Jim Grosbach4334e032011-10-31 21:50:31 +00004209 // pred
4210 ((ARMOperand*)Operands[1])->addCondCodeOperands(Inst, 2);
Jim Grosbach4334e032011-10-31 21:50:31 +00004211}
4212
Bill Wendlinge7176102010-11-06 22:36:58 +00004213/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004214/// or an error. The first token must be a '[' when called.
Bill Wendling50d0f582010-11-18 23:43:05 +00004215bool ARMAsmParser::
Jim Grosbach7ce05792011-08-03 23:50:40 +00004216parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan76264762010-04-02 22:27:05 +00004217 SMLoc S, E;
Sean Callanan18b83232010-01-19 21:44:56 +00004218 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendlinga60f1572010-11-06 10:48:18 +00004219 "Token is not a Left Bracket");
Sean Callanan76264762010-04-02 22:27:05 +00004220 S = Parser.getTok().getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +00004221 Parser.Lex(); // Eat left bracket token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004222
Sean Callanan18b83232010-01-19 21:44:56 +00004223 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbach1355cf12011-07-26 17:10:22 +00004224 int BaseRegNum = tryParseRegister();
Jim Grosbach7ce05792011-08-03 23:50:40 +00004225 if (BaseRegNum == -1)
4226 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004227
Daniel Dunbar05710932011-01-18 05:34:17 +00004228 // The next token must either be a comma or a closing bracket.
4229 const AsmToken &Tok = Parser.getTok();
4230 if (!Tok.is(AsmToken::Comma) && !Tok.is(AsmToken::RBrac))
Jim Grosbach7ce05792011-08-03 23:50:40 +00004231 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar05710932011-01-18 05:34:17 +00004232
Jim Grosbach7ce05792011-08-03 23:50:40 +00004233 if (Tok.is(AsmToken::RBrac)) {
Sean Callanan76264762010-04-02 22:27:05 +00004234 E = Tok.getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +00004235 Parser.Lex(); // Eat right bracket token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004236
Jim Grosbach7ce05792011-08-03 23:50:40 +00004237 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
Jim Grosbach57dcb852011-10-11 17:29:55 +00004238 0, 0, false, S, E));
Jim Grosbach03f44a02010-11-29 23:18:01 +00004239
Jim Grosbachfb12f352011-09-19 18:42:21 +00004240 // If there's a pre-indexing writeback marker, '!', just add it as a token
4241 // operand. It's rather odd, but syntactically valid.
4242 if (Parser.getTok().is(AsmToken::Exclaim)) {
4243 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4244 Parser.Lex(); // Eat the '!'.
4245 }
4246
Jim Grosbach7ce05792011-08-03 23:50:40 +00004247 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004248 }
Daniel Dunbar05d8b712011-01-18 05:34:24 +00004249
Jim Grosbach7ce05792011-08-03 23:50:40 +00004250 assert(Tok.is(AsmToken::Comma) && "Lost comma in memory operand?!");
4251 Parser.Lex(); // Eat the comma.
Daniel Dunbar05d8b712011-01-18 05:34:24 +00004252
Jim Grosbach57dcb852011-10-11 17:29:55 +00004253 // If we have a ':', it's an alignment specifier.
4254 if (Parser.getTok().is(AsmToken::Colon)) {
4255 Parser.Lex(); // Eat the ':'.
4256 E = Parser.getTok().getLoc();
4257
4258 const MCExpr *Expr;
4259 if (getParser().ParseExpression(Expr))
4260 return true;
4261
4262 // The expression has to be a constant. Memory references with relocations
4263 // don't come through here, as they use the <label> forms of the relevant
4264 // instructions.
4265 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4266 if (!CE)
4267 return Error (E, "constant expression expected");
4268
4269 unsigned Align = 0;
4270 switch (CE->getValue()) {
4271 default:
Jim Grosbacheeaf1c12011-12-19 18:31:43 +00004272 return Error(E,
4273 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4274 case 16: Align = 2; break;
4275 case 32: Align = 4; break;
Jim Grosbach57dcb852011-10-11 17:29:55 +00004276 case 64: Align = 8; break;
4277 case 128: Align = 16; break;
4278 case 256: Align = 32; break;
4279 }
4280
4281 // Now we should have the closing ']'
4282 E = Parser.getTok().getLoc();
4283 if (Parser.getTok().isNot(AsmToken::RBrac))
4284 return Error(E, "']' expected");
4285 Parser.Lex(); // Eat right bracket token.
4286
4287 // Don't worry about range checking the value here. That's handled by
4288 // the is*() predicates.
4289 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4290 ARM_AM::no_shift, 0, Align,
4291 false, S, E));
4292
4293 // If there's a pre-indexing writeback marker, '!', just add it as a token
4294 // operand.
4295 if (Parser.getTok().is(AsmToken::Exclaim)) {
4296 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4297 Parser.Lex(); // Eat the '!'.
4298 }
4299
4300 return false;
4301 }
4302
4303 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach6cb4b082011-11-15 22:14:41 +00004304 // offset. Be friendly and also accept a plain integer (without a leading
4305 // hash) for gas compatibility.
4306 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004307 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach6cb4b082011-11-15 22:14:41 +00004308 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004309 if (Parser.getTok().isNot(AsmToken::Integer))
Jim Grosbach6cb4b082011-11-15 22:14:41 +00004310 Parser.Lex(); // Eat the '#'.
Jim Grosbach7ce05792011-08-03 23:50:40 +00004311 E = Parser.getTok().getLoc();
Daniel Dunbar05d8b712011-01-18 05:34:24 +00004312
Owen Anderson0da10cf2011-08-29 19:36:44 +00004313 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbach7ce05792011-08-03 23:50:40 +00004314 const MCExpr *Offset;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004315 if (getParser().ParseExpression(Offset))
4316 return true;
Jim Grosbach7ce05792011-08-03 23:50:40 +00004317
4318 // The expression has to be a constant. Memory references with relocations
4319 // don't come through here, as they use the <label> forms of the relevant
4320 // instructions.
4321 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4322 if (!CE)
4323 return Error (E, "constant expression expected");
4324
Owen Anderson0da10cf2011-08-29 19:36:44 +00004325 // If the constant was #-0, represent it as INT32_MIN.
4326 int32_t Val = CE->getValue();
4327 if (isNegative && Val == 0)
4328 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4329
Jim Grosbach7ce05792011-08-03 23:50:40 +00004330 // Now we should have the closing ']'
4331 E = Parser.getTok().getLoc();
4332 if (Parser.getTok().isNot(AsmToken::RBrac))
4333 return Error(E, "']' expected");
4334 Parser.Lex(); // Eat right bracket token.
4335
4336 // Don't worry about range checking the value here. That's handled by
4337 // the is*() predicates.
4338 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbach57dcb852011-10-11 17:29:55 +00004339 ARM_AM::no_shift, 0, 0,
4340 false, S, E));
Jim Grosbach7ce05792011-08-03 23:50:40 +00004341
4342 // If there's a pre-indexing writeback marker, '!', just add it as a token
4343 // operand.
4344 if (Parser.getTok().is(AsmToken::Exclaim)) {
4345 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4346 Parser.Lex(); // Eat the '!'.
4347 }
4348
4349 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004350 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00004351
4352 // The register offset is optionally preceded by a '+' or '-'
4353 bool isNegative = false;
4354 if (Parser.getTok().is(AsmToken::Minus)) {
4355 isNegative = true;
4356 Parser.Lex(); // Eat the '-'.
4357 } else if (Parser.getTok().is(AsmToken::Plus)) {
4358 // Nothing to do.
4359 Parser.Lex(); // Eat the '+'.
4360 }
4361
4362 E = Parser.getTok().getLoc();
4363 int OffsetRegNum = tryParseRegister();
4364 if (OffsetRegNum == -1)
4365 return Error(E, "register expected");
4366
4367 // If there's a shift operator, handle it.
4368 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach0d6fac32011-08-05 22:03:36 +00004369 unsigned ShiftImm = 0;
Jim Grosbach7ce05792011-08-03 23:50:40 +00004370 if (Parser.getTok().is(AsmToken::Comma)) {
4371 Parser.Lex(); // Eat the ','.
Jim Grosbach0d6fac32011-08-05 22:03:36 +00004372 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbach7ce05792011-08-03 23:50:40 +00004373 return true;
4374 }
4375
4376 // Now we should have the closing ']'
4377 E = Parser.getTok().getLoc();
4378 if (Parser.getTok().isNot(AsmToken::RBrac))
4379 return Error(E, "']' expected");
4380 Parser.Lex(); // Eat right bracket token.
4381
4382 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
Jim Grosbach57dcb852011-10-11 17:29:55 +00004383 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbach7ce05792011-08-03 23:50:40 +00004384 S, E));
4385
Jim Grosbachf4fa3d62011-08-05 21:28:30 +00004386 // If there's a pre-indexing writeback marker, '!', just add it as a token
4387 // operand.
4388 if (Parser.getTok().is(AsmToken::Exclaim)) {
4389 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4390 Parser.Lex(); // Eat the '!'.
4391 }
Jim Grosbach7ce05792011-08-03 23:50:40 +00004392
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004393 return false;
4394}
4395
Jim Grosbach7ce05792011-08-03 23:50:40 +00004396/// parseMemRegOffsetShift - one of these two:
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004397/// ( lsl | lsr | asr | ror ) , # shift_amount
4398/// rrx
Jim Grosbach7ce05792011-08-03 23:50:40 +00004399/// return true if it parses a shift otherwise it returns false.
4400bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4401 unsigned &Amount) {
4402 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan18b83232010-01-19 21:44:56 +00004403 const AsmToken &Tok = Parser.getTok();
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004404 if (Tok.isNot(AsmToken::Identifier))
4405 return true;
Benjamin Kramer38e59892010-07-14 22:38:02 +00004406 StringRef ShiftName = Tok.getString();
Jim Grosbachaf4edea2011-12-07 23:40:58 +00004407 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4408 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson00828302011-03-18 22:50:18 +00004409 St = ARM_AM::lsl;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004410 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson00828302011-03-18 22:50:18 +00004411 St = ARM_AM::lsr;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004412 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson00828302011-03-18 22:50:18 +00004413 St = ARM_AM::asr;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004414 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson00828302011-03-18 22:50:18 +00004415 St = ARM_AM::ror;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004416 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson00828302011-03-18 22:50:18 +00004417 St = ARM_AM::rrx;
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004418 else
Jim Grosbach7ce05792011-08-03 23:50:40 +00004419 return Error(Loc, "illegal shift operator");
Sean Callananb9a25b72010-01-19 20:27:46 +00004420 Parser.Lex(); // Eat shift type token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004421
Jim Grosbach7ce05792011-08-03 23:50:40 +00004422 // rrx stands alone.
4423 Amount = 0;
4424 if (St != ARM_AM::rrx) {
4425 Loc = Parser.getTok().getLoc();
4426 // A '#' and a shift amount.
4427 const AsmToken &HashTok = Parser.getTok();
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004428 if (HashTok.isNot(AsmToken::Hash) &&
4429 HashTok.isNot(AsmToken::Dollar))
Jim Grosbach7ce05792011-08-03 23:50:40 +00004430 return Error(HashTok.getLoc(), "'#' expected");
4431 Parser.Lex(); // Eat hash token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004432
Jim Grosbach7ce05792011-08-03 23:50:40 +00004433 const MCExpr *Expr;
4434 if (getParser().ParseExpression(Expr))
4435 return true;
4436 // Range check the immediate.
4437 // lsl, ror: 0 <= imm <= 31
4438 // lsr, asr: 0 <= imm <= 32
4439 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4440 if (!CE)
4441 return Error(Loc, "shift amount must be an immediate");
4442 int64_t Imm = CE->getValue();
4443 if (Imm < 0 ||
4444 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4445 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4446 return Error(Loc, "immediate shift value out of range");
4447 Amount = Imm;
4448 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004449
4450 return false;
4451}
4452
Jim Grosbach9d390362011-10-03 23:38:36 +00004453/// parseFPImm - A floating point immediate expression operand.
4454ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4455parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach51222d12012-01-20 18:09:51 +00004456 // Anything that can accept a floating point constant as an operand
4457 // needs to go through here, as the regular ParseExpression is
4458 // integer only.
4459 //
4460 // This routine still creates a generic Immediate operand, containing
4461 // a bitcast of the 64-bit floating point value. The various operands
4462 // that accept floats can check whether the value is valid for them
4463 // via the standard is*() predicates.
4464
Jim Grosbach9d390362011-10-03 23:38:36 +00004465 SMLoc S = Parser.getTok().getLoc();
4466
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004467 if (Parser.getTok().isNot(AsmToken::Hash) &&
4468 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbach9d390362011-10-03 23:38:36 +00004469 return MatchOperand_NoMatch;
Jim Grosbach0e387b22011-10-17 22:26:03 +00004470
4471 // Disambiguate the VMOV forms that can accept an FP immediate.
4472 // vmov.f32 <sreg>, #imm
4473 // vmov.f64 <dreg>, #imm
4474 // vmov.f32 <dreg>, #imm @ vector f32x2
4475 // vmov.f32 <qreg>, #imm @ vector f32x4
4476 //
4477 // There are also the NEON VMOV instructions which expect an
4478 // integer constant. Make sure we don't try to parse an FPImm
4479 // for these:
4480 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4481 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4482 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4483 TyOp->getToken() != ".f64"))
4484 return MatchOperand_NoMatch;
4485
Jim Grosbach9d390362011-10-03 23:38:36 +00004486 Parser.Lex(); // Eat the '#'.
4487
4488 // Handle negation, as that still comes through as a separate token.
4489 bool isNegative = false;
4490 if (Parser.getTok().is(AsmToken::Minus)) {
4491 isNegative = true;
4492 Parser.Lex();
4493 }
4494 const AsmToken &Tok = Parser.getTok();
Jim Grosbachae69f702012-01-19 02:47:30 +00004495 SMLoc Loc = Tok.getLoc();
Jim Grosbach9d390362011-10-03 23:38:36 +00004496 if (Tok.is(AsmToken::Real)) {
Jim Grosbach51222d12012-01-20 18:09:51 +00004497 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbach9d390362011-10-03 23:38:36 +00004498 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4499 // If we had a '-' in front, toggle the sign bit.
Jim Grosbach51222d12012-01-20 18:09:51 +00004500 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbach9d390362011-10-03 23:38:36 +00004501 Parser.Lex(); // Eat the token.
Jim Grosbach51222d12012-01-20 18:09:51 +00004502 Operands.push_back(ARMOperand::CreateImm(
4503 MCConstantExpr::Create(IntVal, getContext()),
4504 S, Parser.getTok().getLoc()));
Jim Grosbach9d390362011-10-03 23:38:36 +00004505 return MatchOperand_Success;
4506 }
Jim Grosbach51222d12012-01-20 18:09:51 +00004507 // Also handle plain integers. Instructions which allow floating point
4508 // immediates also allow a raw encoded 8-bit value.
Jim Grosbach9d390362011-10-03 23:38:36 +00004509 if (Tok.is(AsmToken::Integer)) {
4510 int64_t Val = Tok.getIntVal();
4511 Parser.Lex(); // Eat the token.
4512 if (Val > 255 || Val < 0) {
Jim Grosbachae69f702012-01-19 02:47:30 +00004513 Error(Loc, "encoded floating point value out of range");
Jim Grosbach9d390362011-10-03 23:38:36 +00004514 return MatchOperand_ParseFail;
4515 }
Jim Grosbach51222d12012-01-20 18:09:51 +00004516 double RealVal = ARM_AM::getFPImmFloat(Val);
4517 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4518 Operands.push_back(ARMOperand::CreateImm(
4519 MCConstantExpr::Create(Val, getContext()), S,
4520 Parser.getTok().getLoc()));
Jim Grosbach9d390362011-10-03 23:38:36 +00004521 return MatchOperand_Success;
4522 }
4523
Jim Grosbachae69f702012-01-19 02:47:30 +00004524 Error(Loc, "invalid floating point immediate");
Jim Grosbach9d390362011-10-03 23:38:36 +00004525 return MatchOperand_ParseFail;
4526}
Jim Grosbach51222d12012-01-20 18:09:51 +00004527
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004528/// Parse a arm instruction operand. For now this parses the operand regardless
4529/// of the mnemonic.
Jim Grosbach1355cf12011-07-26 17:10:22 +00004530bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004531 StringRef Mnemonic) {
Sean Callanan76264762010-04-02 22:27:05 +00004532 SMLoc S, E;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004533
4534 // Check if the current operand has a custom associated parser, if so, try to
4535 // custom parse the operand, or fallback to the general approach.
Jim Grosbachf922c472011-02-12 01:34:40 +00004536 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4537 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004538 return false;
Jim Grosbachf922c472011-02-12 01:34:40 +00004539 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4540 // there was a match, but an error occurred, in which case, just return that
4541 // the operand parsing failed.
4542 if (ResTy == MatchOperand_ParseFail)
4543 return true;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004544
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004545 switch (getLexer().getKind()) {
Bill Wendling146018f2010-11-06 21:42:12 +00004546 default:
4547 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling50d0f582010-11-18 23:43:05 +00004548 return true;
Jim Grosbach19906722011-07-13 18:49:30 +00004549 case AsmToken::Identifier: {
Jim Grosbach1355cf12011-07-26 17:10:22 +00004550 if (!tryParseRegisterWithWriteBack(Operands))
Bill Wendling50d0f582010-11-18 23:43:05 +00004551 return false;
Jim Grosbach0d87ec22011-07-26 20:41:24 +00004552 int Res = tryParseShiftRegister(Operands);
Jim Grosbach19906722011-07-13 18:49:30 +00004553 if (Res == 0) // success
Owen Anderson00828302011-03-18 22:50:18 +00004554 return false;
Jim Grosbach19906722011-07-13 18:49:30 +00004555 else if (Res == -1) // irrecoverable error
4556 return true;
Jim Grosbach3cbe43f2011-12-20 22:26:38 +00004557 // If this is VMRS, check for the apsr_nzcv operand.
Jim Grosbachb84ad4a2012-03-15 21:34:14 +00004558 if (Mnemonic == "vmrs" &&
4559 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
Jim Grosbach5cd5ac62011-10-03 21:12:43 +00004560 S = Parser.getTok().getLoc();
4561 Parser.Lex();
Jim Grosbachb84ad4a2012-03-15 21:34:14 +00004562 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
Jim Grosbach5cd5ac62011-10-03 21:12:43 +00004563 return false;
4564 }
Owen Andersone4e5e2a2011-01-13 21:46:02 +00004565
4566 // Fall though for the Identifier case that is not a register or a
4567 // special name.
Jim Grosbach19906722011-07-13 18:49:30 +00004568 }
Jim Grosbach758a5192011-10-26 21:14:08 +00004569 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderby67b212e2011-01-13 20:32:36 +00004570 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach6284afc2011-11-01 22:38:31 +00004571 case AsmToken::String: // quoted label names.
Kevin Enderby67b212e2011-01-13 20:32:36 +00004572 case AsmToken::Dot: { // . as a branch target
Kevin Enderby515d5092009-10-15 20:48:48 +00004573 // This was not a register so parse other operands that start with an
4574 // identifier (like labels) as expressions and create them as immediates.
4575 const MCExpr *IdVal;
Sean Callanan76264762010-04-02 22:27:05 +00004576 S = Parser.getTok().getLoc();
Kevin Enderby515d5092009-10-15 20:48:48 +00004577 if (getParser().ParseExpression(IdVal))
Bill Wendling50d0f582010-11-18 23:43:05 +00004578 return true;
Sean Callanan76264762010-04-02 22:27:05 +00004579 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling50d0f582010-11-18 23:43:05 +00004580 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4581 return false;
4582 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004583 case AsmToken::LBrac:
Jim Grosbach1355cf12011-07-26 17:10:22 +00004584 return parseMemory(Operands);
Kevin Enderbyd7894f12009-10-09 21:12:28 +00004585 case AsmToken::LCurly:
Jim Grosbach1355cf12011-07-26 17:10:22 +00004586 return parseRegisterList(Operands);
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004587 case AsmToken::Dollar:
Owen Anderson63553c72011-08-29 17:17:09 +00004588 case AsmToken::Hash: {
Kevin Enderby079469f2009-10-13 23:33:38 +00004589 // #42 -> immediate.
Sean Callanan76264762010-04-02 22:27:05 +00004590 S = Parser.getTok().getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +00004591 Parser.Lex();
Jim Grosbachb8768dc2012-04-16 21:18:46 +00004592
4593 if (Parser.getTok().isNot(AsmToken::Colon)) {
4594 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4595 const MCExpr *ImmVal;
4596 if (getParser().ParseExpression(ImmVal))
4597 return true;
4598 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4599 if (CE) {
4600 int32_t Val = CE->getValue();
4601 if (isNegative && Val == 0)
4602 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4603 }
4604 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4605 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
4606 return false;
Owen Anderson63553c72011-08-29 17:17:09 +00004607 }
Jim Grosbachb8768dc2012-04-16 21:18:46 +00004608 // w/ a ':' after the '#', it's just like a plain ':'.
4609 // FALLTHROUGH
Owen Anderson63553c72011-08-29 17:17:09 +00004610 }
Jason W Kim9081b4b2011-01-11 23:53:41 +00004611 case AsmToken::Colon: {
4612 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng75972122011-01-13 07:58:56 +00004613 // FIXME: Check it's an expression prefix,
4614 // e.g. (FOO - :lower16:BAR) isn't legal.
4615 ARMMCExpr::VariantKind RefKind;
Jim Grosbach1355cf12011-07-26 17:10:22 +00004616 if (parsePrefix(RefKind))
Jason W Kim9081b4b2011-01-11 23:53:41 +00004617 return true;
4618
Evan Cheng75972122011-01-13 07:58:56 +00004619 const MCExpr *SubExprVal;
4620 if (getParser().ParseExpression(SubExprVal))
Jason W Kim9081b4b2011-01-11 23:53:41 +00004621 return true;
4622
Evan Cheng75972122011-01-13 07:58:56 +00004623 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach1f9f5992012-09-21 00:26:53 +00004624 getContext());
Jason W Kim9081b4b2011-01-11 23:53:41 +00004625 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng75972122011-01-13 07:58:56 +00004626 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim9081b4b2011-01-11 23:53:41 +00004627 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004628 }
Jason W Kim9081b4b2011-01-11 23:53:41 +00004629 }
4630}
4631
Jim Grosbach1355cf12011-07-26 17:10:22 +00004632// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng75972122011-01-13 07:58:56 +00004633// :lower16: and :upper16:.
Jim Grosbach1355cf12011-07-26 17:10:22 +00004634bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng75972122011-01-13 07:58:56 +00004635 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim9081b4b2011-01-11 23:53:41 +00004636
4637 // :lower16: and :upper16: modifiers
Jason W Kim8a8696d2011-01-13 00:27:00 +00004638 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim9081b4b2011-01-11 23:53:41 +00004639 Parser.Lex(); // Eat ':'
4640
4641 if (getLexer().isNot(AsmToken::Identifier)) {
4642 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4643 return true;
4644 }
4645
4646 StringRef IDVal = Parser.getTok().getIdentifier();
4647 if (IDVal == "lower16") {
Evan Cheng75972122011-01-13 07:58:56 +00004648 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim9081b4b2011-01-11 23:53:41 +00004649 } else if (IDVal == "upper16") {
Evan Cheng75972122011-01-13 07:58:56 +00004650 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim9081b4b2011-01-11 23:53:41 +00004651 } else {
4652 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4653 return true;
4654 }
4655 Parser.Lex();
4656
4657 if (getLexer().isNot(AsmToken::Colon)) {
4658 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4659 return true;
4660 }
4661 Parser.Lex(); // Eat the last ':'
4662 return false;
4663}
4664
Daniel Dunbar352e1482011-01-11 15:59:50 +00004665/// \brief Given a mnemonic, split out possible predication code and carry
4666/// setting letters to form a canonical mnemonic and flags.
4667//
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004668// FIXME: Would be nice to autogen this.
Jim Grosbach89df9962011-08-26 21:43:41 +00004669// FIXME: This is a bit of a maze of special cases.
Jim Grosbach1355cf12011-07-26 17:10:22 +00004670StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5f160572011-07-19 20:10:31 +00004671 unsigned &PredicationCode,
4672 bool &CarrySetting,
Jim Grosbach89df9962011-08-26 21:43:41 +00004673 unsigned &ProcessorIMod,
4674 StringRef &ITMask) {
Daniel Dunbar352e1482011-01-11 15:59:50 +00004675 PredicationCode = ARMCC::AL;
4676 CarrySetting = false;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004677 ProcessorIMod = 0;
Daniel Dunbar352e1482011-01-11 15:59:50 +00004678
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004679 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar352e1482011-01-11 15:59:50 +00004680 //
4681 // FIXME: Would be nice to autogen this.
Jim Grosbach5f160572011-07-19 20:10:31 +00004682 if ((Mnemonic == "movs" && isThumb()) ||
4683 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4684 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4685 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4686 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
4687 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4688 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbach68490192011-12-19 19:43:50 +00004689 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4690 Mnemonic == "fmuls")
Daniel Dunbar352e1482011-01-11 15:59:50 +00004691 return Mnemonic;
Daniel Dunbar5747b132010-08-11 06:37:16 +00004692
Jim Grosbach3f00e312011-07-11 17:09:57 +00004693 // First, split out any predication code. Ignore mnemonics we know aren't
4694 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbachab40f4b2011-07-20 18:20:31 +00004695 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach71725a02011-07-27 21:58:11 +00004696 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach04d55f12011-08-22 23:55:58 +00004697 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbach2f25d9b2011-09-01 18:22:13 +00004698 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbach3f00e312011-07-11 17:09:57 +00004699 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4700 .Case("eq", ARMCC::EQ)
4701 .Case("ne", ARMCC::NE)
4702 .Case("hs", ARMCC::HS)
4703 .Case("cs", ARMCC::HS)
4704 .Case("lo", ARMCC::LO)
4705 .Case("cc", ARMCC::LO)
4706 .Case("mi", ARMCC::MI)
4707 .Case("pl", ARMCC::PL)
4708 .Case("vs", ARMCC::VS)
4709 .Case("vc", ARMCC::VC)
4710 .Case("hi", ARMCC::HI)
4711 .Case("ls", ARMCC::LS)
4712 .Case("ge", ARMCC::GE)
4713 .Case("lt", ARMCC::LT)
4714 .Case("gt", ARMCC::GT)
4715 .Case("le", ARMCC::LE)
4716 .Case("al", ARMCC::AL)
4717 .Default(~0U);
4718 if (CC != ~0U) {
4719 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4720 PredicationCode = CC;
4721 }
Bill Wendling52925b62010-10-29 23:50:21 +00004722 }
Daniel Dunbar345a9a62010-08-11 06:37:20 +00004723
Daniel Dunbar352e1482011-01-11 15:59:50 +00004724 // Next, determine if we have a carry setting bit. We explicitly ignore all
4725 // the instructions we know end in 's'.
4726 if (Mnemonic.endswith("s") &&
Jim Grosbach00f5d982011-08-17 22:49:09 +00004727 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5f160572011-07-19 20:10:31 +00004728 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4729 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4730 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach67ca1ad2011-12-08 00:49:29 +00004731 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach48171e72011-12-10 00:01:02 +00004732 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach9c397892011-12-19 19:02:41 +00004733 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbach6357cae2012-03-15 20:48:18 +00004734 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
Evan Cheng82509e52012-04-11 00:13:00 +00004735 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
Jim Grosbache1cf5902011-07-29 20:26:09 +00004736 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar352e1482011-01-11 15:59:50 +00004737 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4738 CarrySetting = true;
4739 }
4740
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004741 // The "cps" instruction can have a interrupt mode operand which is glued into
4742 // the mnemonic. Check if this is the case, split it and parse the imod op
4743 if (Mnemonic.startswith("cps")) {
4744 // Split out any imod code.
4745 unsigned IMod =
4746 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4747 .Case("ie", ARM_PROC::IE)
4748 .Case("id", ARM_PROC::ID)
4749 .Default(~0U);
4750 if (IMod != ~0U) {
4751 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4752 ProcessorIMod = IMod;
4753 }
4754 }
4755
Jim Grosbach89df9962011-08-26 21:43:41 +00004756 // The "it" instruction has the condition mask on the end of the mnemonic.
4757 if (Mnemonic.startswith("it")) {
4758 ITMask = Mnemonic.slice(2, Mnemonic.size());
4759 Mnemonic = Mnemonic.slice(0, 2);
4760 }
4761
Daniel Dunbar352e1482011-01-11 15:59:50 +00004762 return Mnemonic;
4763}
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004764
4765/// \brief Given a canonical mnemonic, determine if the instruction ever allows
4766/// inclusion of carry set or predication code operands.
4767//
4768// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopesfdcee772011-01-18 20:55:11 +00004769void ARMAsmParser::
Jim Grosbach1355cf12011-07-26 17:10:22 +00004770getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopesfdcee772011-01-18 20:55:11 +00004771 bool &CanAcceptPredicationCode) {
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004772 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4773 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbach3443ed52011-09-16 18:05:48 +00004774 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004775 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachd5d0e812011-09-19 23:31:02 +00004776 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004777 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachd5d0e812011-09-19 23:31:02 +00004778 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Cheng82509e52012-04-11 00:13:00 +00004779 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbach3443ed52011-09-16 18:05:48 +00004780 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachd5d0e812011-09-19 23:31:02 +00004781 Mnemonic == "mla" || Mnemonic == "smlal" ||
4782 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004783 CanAcceptCarrySet = true;
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004784 } else
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004785 CanAcceptCarrySet = false;
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004786
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004787 if (Mnemonic == "cbnz" || Mnemonic == "setend" || Mnemonic == "dmb" ||
4788 Mnemonic == "cps" || Mnemonic == "mcr2" || Mnemonic == "it" ||
4789 Mnemonic == "mcrr2" || Mnemonic == "cbz" || Mnemonic == "cdp2" ||
4790 Mnemonic == "trap" || Mnemonic == "mrc2" || Mnemonic == "mrrc2" ||
Jim Grosbachad2dad92011-09-06 20:27:04 +00004791 Mnemonic == "dsb" || Mnemonic == "isb" || Mnemonic == "setend" ||
4792 (Mnemonic == "clrex" && !isThumb()) ||
Jim Grosbach0780b632011-08-19 23:24:36 +00004793 (Mnemonic == "nop" && isThumbOne()) ||
Jim Grosbach2bd01182011-10-11 21:55:36 +00004794 ((Mnemonic == "pld" || Mnemonic == "pli" || Mnemonic == "pldw" ||
4795 Mnemonic == "ldc2" || Mnemonic == "ldc2l" ||
4796 Mnemonic == "stc2" || Mnemonic == "stc2l") && !isThumb()) ||
Jim Grosbach4af54a42011-08-26 22:21:51 +00004797 ((Mnemonic.startswith("rfe") || Mnemonic.startswith("srs")) &&
4798 !isThumb()) ||
Jim Grosbach1ad60c22011-09-10 00:15:36 +00004799 Mnemonic.startswith("cps") || (Mnemonic == "movs" && isThumbOne())) {
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004800 CanAcceptPredicationCode = false;
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004801 } else
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004802 CanAcceptPredicationCode = true;
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00004803
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004804 if (isThumb()) {
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00004805 if (Mnemonic == "bkpt" || Mnemonic == "mcr" || Mnemonic == "mcrr" ||
Jim Grosbach63b46fa2011-06-30 22:10:46 +00004806 Mnemonic == "mrc" || Mnemonic == "mrrc" || Mnemonic == "cdp")
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00004807 CanAcceptPredicationCode = false;
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004808 }
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004809}
4810
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004811bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4812 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004813 // FIXME: This is all horribly hacky. We really need a better way to deal
4814 // with optional operands like this in the matcher table.
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004815
4816 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4817 // another does not. Specifically, the MOVW instruction does not. So we
4818 // special case it here and remove the defaulted (non-setting) cc_out
4819 // operand if that's the instruction we're trying to match.
4820 //
4821 // We do this as post-processing of the explicit operands rather than just
4822 // conditionally adding the cc_out in the first place because we need
4823 // to check the type of the parsed immediate operand.
Owen Anderson8adf6202011-09-14 22:46:14 +00004824 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004825 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4826 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4827 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4828 return true;
Jim Grosbach3912b732011-08-16 21:34:08 +00004829
4830 // Register-register 'add' for thumb does not have a cc_out operand
4831 // when there are only two register operands.
4832 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4833 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4834 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4835 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4836 return true;
Jim Grosbach72f39f82011-08-24 21:22:15 +00004837 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004838 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4839 // have to check the immediate range here since Thumb2 has a variant
4840 // that can handle a different range and has a cc_out operand.
Jim Grosbachf67e8552011-09-16 22:58:42 +00004841 if (((isThumb() && Mnemonic == "add") ||
4842 (isThumbTwo() && Mnemonic == "sub")) &&
4843 Operands.size() == 6 &&
Jim Grosbach72f39f82011-08-24 21:22:15 +00004844 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4845 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4846 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004847 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
Jim Grosbacha23ecc22012-04-10 17:31:55 +00004848 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004849 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach72f39f82011-08-24 21:22:15 +00004850 return true;
Jim Grosbachf67e8552011-09-16 22:58:42 +00004851 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4852 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004853 // selecting via the generic "add" mnemonic, so to know that we
4854 // should remove the cc_out operand, we have to explicitly check that
4855 // it's not one of the other variants. Ugh.
Jim Grosbachf67e8552011-09-16 22:58:42 +00004856 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4857 Operands.size() == 6 &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004858 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4859 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4860 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4861 // Nest conditions rather than one big 'if' statement for readability.
4862 //
4863 // If either register is a high reg, it's either one of the SP
4864 // variants (handled above) or a 32-bit encoding, so we just
Jim Grosbach12a88632012-01-21 00:07:56 +00004865 // check against T3. If the second register is the PC, this is an
4866 // alternate form of ADR, which uses encoding T4, so check for that too.
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004867 if ((!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4868 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg())) &&
Jim Grosbach12a88632012-01-21 00:07:56 +00004869 static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004870 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4871 return false;
4872 // If both registers are low, we're in an IT block, and the immediate is
4873 // in range, we should use encoding T1 instead, which has a cc_out.
4874 if (inITBlock() &&
Jim Grosbach64944f42011-09-14 21:00:40 +00004875 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004876 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4877 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4878 return false;
4879
4880 // Otherwise, we use encoding T4, which does not have a cc_out
4881 // operand.
4882 return true;
4883 }
4884
Jim Grosbach64944f42011-09-14 21:00:40 +00004885 // The thumb2 multiply instruction doesn't have a CCOut register, so
4886 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4887 // use the 16-bit encoding or not.
4888 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4889 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4890 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4891 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4892 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4893 // If the registers aren't low regs, the destination reg isn't the
4894 // same as one of the source regs, or the cc_out operand is zero
4895 // outside of an IT block, we have to use the 32-bit encoding, so
4896 // remove the cc_out operand.
4897 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4898 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach1de0bd12011-11-15 19:29:45 +00004899 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach64944f42011-09-14 21:00:40 +00004900 !inITBlock() ||
4901 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4902 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4903 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4904 static_cast<ARMOperand*>(Operands[4])->getReg())))
4905 return true;
4906
Jim Grosbach7f1ec952011-11-15 19:55:16 +00004907 // Also check the 'mul' syntax variant that doesn't specify an explicit
4908 // destination register.
4909 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4910 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4911 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4912 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4913 // If the registers aren't low regs or the cc_out operand is zero
4914 // outside of an IT block, we have to use the 32-bit encoding, so
4915 // remove the cc_out operand.
4916 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4917 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4918 !inITBlock()))
4919 return true;
4920
Jim Grosbach64944f42011-09-14 21:00:40 +00004921
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004922
Jim Grosbachf69c8042011-08-24 21:42:27 +00004923 // Register-register 'add/sub' for thumb does not have a cc_out operand
4924 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4925 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4926 // right, this will result in better diagnostics (which operand is off)
4927 // anyway.
4928 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4929 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach72f39f82011-08-24 21:22:15 +00004930 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4931 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
Jim Grosbacha23ecc22012-04-10 17:31:55 +00004932 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4933 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
4934 (Operands.size() == 6 &&
4935 static_cast<ARMOperand*>(Operands[5])->isImm())))
Jim Grosbach72f39f82011-08-24 21:22:15 +00004936 return true;
Jim Grosbach3912b732011-08-16 21:34:08 +00004937
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004938 return false;
4939}
4940
Jim Grosbach7aef99b2011-11-11 23:08:10 +00004941static bool isDataTypeToken(StringRef Tok) {
4942 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4943 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4944 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4945 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4946 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4947 Tok == ".f" || Tok == ".d";
4948}
4949
4950// FIXME: This bit should probably be handled via an explicit match class
4951// in the .td files that matches the suffix instead of having it be
4952// a literal string token the way it is now.
4953static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4954 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4955}
4956
Jim Grosbach21d7fb82011-12-09 23:34:09 +00004957static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004958/// Parse an arm instruction mnemonic followed by its operands.
4959bool ARMAsmParser::ParseInstruction(StringRef Name, SMLoc NameLoc,
4960 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach21d7fb82011-12-09 23:34:09 +00004961 // Apply mnemonic aliases before doing anything else, as the destination
4962 // mnemnonic may include suffices and we want to handle them normally.
4963 // The generic tblgen'erated code does this later, at the start of
4964 // MatchInstructionImpl(), but that's too late for aliases that include
4965 // any sort of suffix.
4966 unsigned AvailableFeatures = getAvailableFeatures();
4967 applyMnemonicAliases(Name, AvailableFeatures);
4968
Jim Grosbacha39cda72011-12-14 02:16:11 +00004969 // First check for the ARM-specific .req directive.
4970 if (Parser.getTok().is(AsmToken::Identifier) &&
4971 Parser.getTok().getIdentifier() == ".req") {
4972 parseDirectiveReq(Name, NameLoc);
4973 // We always return 'error' for this, as we're done with this
4974 // statement and don't need to match the 'instruction."
4975 return true;
4976 }
4977
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004978 // Create the leading tokens for the mnemonic, split by '.' characters.
4979 size_t Start = 0, Next = Name.find('.');
Jim Grosbachffa32252011-07-19 19:13:28 +00004980 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004981
Daniel Dunbar352e1482011-01-11 15:59:50 +00004982 // Split out the predication code and carry setting flag from the mnemonic.
4983 unsigned PredicationCode;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004984 unsigned ProcessorIMod;
Daniel Dunbar352e1482011-01-11 15:59:50 +00004985 bool CarrySetting;
Jim Grosbach89df9962011-08-26 21:43:41 +00004986 StringRef ITMask;
Jim Grosbach1355cf12011-07-26 17:10:22 +00004987 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach89df9962011-08-26 21:43:41 +00004988 ProcessorIMod, ITMask);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004989
Jim Grosbach0c49ac02011-08-25 17:23:55 +00004990 // In Thumb1, only the branch (B) instruction can be predicated.
4991 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
4992 Parser.EatToEndOfStatement();
4993 return Error(NameLoc, "conditional execution not supported in Thumb1");
4994 }
4995
Jim Grosbachffa32252011-07-19 19:13:28 +00004996 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
4997
Jim Grosbach89df9962011-08-26 21:43:41 +00004998 // Handle the IT instruction ITMask. Convert it to a bitmask. This
4999 // is the mask as it will be for the IT encoding if the conditional
5000 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5001 // where the conditional bit0 is zero, the instruction post-processing
5002 // will adjust the mask accordingly.
5003 if (Mnemonic == "it") {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005004 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5005 if (ITMask.size() > 3) {
5006 Parser.EatToEndOfStatement();
5007 return Error(Loc, "too many conditions on IT instruction");
5008 }
Jim Grosbach89df9962011-08-26 21:43:41 +00005009 unsigned Mask = 8;
5010 for (unsigned i = ITMask.size(); i != 0; --i) {
5011 char pos = ITMask[i - 1];
5012 if (pos != 't' && pos != 'e') {
5013 Parser.EatToEndOfStatement();
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005014 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach89df9962011-08-26 21:43:41 +00005015 }
5016 Mask >>= 1;
5017 if (ITMask[i - 1] == 't')
5018 Mask |= 8;
5019 }
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005020 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach89df9962011-08-26 21:43:41 +00005021 }
5022
Jim Grosbachffa32252011-07-19 19:13:28 +00005023 // FIXME: This is all a pretty gross hack. We should automatically handle
5024 // optional operands like this via tblgen.
Bill Wendling9717fa92010-11-21 10:56:05 +00005025
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005026 // Next, add the CCOut and ConditionCode operands, if needed.
5027 //
5028 // For mnemonics which can ever incorporate a carry setting bit or predication
5029 // code, our matching model involves us always generating CCOut and
5030 // ConditionCode operands to match the mnemonic "as written" and then we let
5031 // the matcher deal with finding the right instruction or generating an
5032 // appropriate error.
5033 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Jim Grosbach1355cf12011-07-26 17:10:22 +00005034 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005035
Jim Grosbach33c16a22011-07-14 22:04:21 +00005036 // If we had a carry-set on an instruction that can't do that, issue an
5037 // error.
5038 if (!CanAcceptCarrySet && CarrySetting) {
5039 Parser.EatToEndOfStatement();
Jim Grosbachffa32252011-07-19 19:13:28 +00005040 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach33c16a22011-07-14 22:04:21 +00005041 "' can not set flags, but 's' suffix specified");
5042 }
Jim Grosbachc27d4f92011-07-22 17:44:50 +00005043 // If we had a predication code on an instruction that can't do that, issue an
5044 // error.
5045 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
5046 Parser.EatToEndOfStatement();
5047 return Error(NameLoc, "instruction '" + Mnemonic +
5048 "' is not predicable, but condition code specified");
5049 }
Jim Grosbach33c16a22011-07-14 22:04:21 +00005050
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005051 // Add the carry setting operand, if necessary.
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005052 if (CanAcceptCarrySet) {
5053 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005054 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005055 Loc));
5056 }
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005057
5058 // Add the predication code operand, if necessary.
5059 if (CanAcceptPredicationCode) {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005060 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5061 CarrySetting);
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005062 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005063 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00005064 }
Daniel Dunbar345a9a62010-08-11 06:37:20 +00005065
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00005066 // Add the processor imod operand, if necessary.
5067 if (ProcessorIMod) {
5068 Operands.push_back(ARMOperand::CreateImm(
5069 MCConstantExpr::Create(ProcessorIMod, getContext()),
5070 NameLoc, NameLoc));
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00005071 }
5072
Daniel Dunbar345a9a62010-08-11 06:37:20 +00005073 // Add the remaining tokens in the mnemonic.
Daniel Dunbar5747b132010-08-11 06:37:16 +00005074 while (Next != StringRef::npos) {
5075 Start = Next;
5076 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00005077 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00005078
Jim Grosbach7aef99b2011-11-11 23:08:10 +00005079 // Some NEON instructions have an optional datatype suffix that is
5080 // completely ignored. Check for that.
5081 if (isDataTypeToken(ExtraToken) &&
5082 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5083 continue;
5084
Jim Grosbach81d2e392011-09-07 16:06:04 +00005085 if (ExtraToken != ".n") {
5086 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5087 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5088 }
Daniel Dunbar5747b132010-08-11 06:37:16 +00005089 }
5090
5091 // Read the remaining operands.
5092 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00005093 // Read the first operand.
Jim Grosbach1355cf12011-07-26 17:10:22 +00005094 if (parseOperand(Operands, Mnemonic)) {
Chris Lattnercbf8a982010-09-11 16:18:25 +00005095 Parser.EatToEndOfStatement();
5096 return true;
5097 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00005098
5099 while (getLexer().is(AsmToken::Comma)) {
Sean Callananb9a25b72010-01-19 20:27:46 +00005100 Parser.Lex(); // Eat the comma.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00005101
5102 // Parse and remember the operand.
Jim Grosbach1355cf12011-07-26 17:10:22 +00005103 if (parseOperand(Operands, Mnemonic)) {
Chris Lattnercbf8a982010-09-11 16:18:25 +00005104 Parser.EatToEndOfStatement();
5105 return true;
5106 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00005107 }
5108 }
Jim Grosbach16c74252010-10-29 14:46:02 +00005109
Chris Lattnercbf8a982010-09-11 16:18:25 +00005110 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbach186ffac2011-10-07 18:27:04 +00005111 SMLoc Loc = getLexer().getLoc();
Chris Lattnercbf8a982010-09-11 16:18:25 +00005112 Parser.EatToEndOfStatement();
Jim Grosbach186ffac2011-10-07 18:27:04 +00005113 return Error(Loc, "unexpected token in argument list");
Chris Lattnercbf8a982010-09-11 16:18:25 +00005114 }
Bill Wendling146018f2010-11-06 21:42:12 +00005115
Chris Lattner34e53142010-09-08 05:10:46 +00005116 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbachffa32252011-07-19 19:13:28 +00005117
Jim Grosbachd54b4e62011-08-16 21:12:37 +00005118 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5119 // do and don't have a cc_out optional-def operand. With some spot-checks
5120 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach20ed2e72011-09-01 00:28:52 +00005121 // parse and adjust accordingly before actually matching. We shouldn't ever
5122 // try to remove a cc_out operand that was explicitly set on the the
5123 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5124 // table driven matcher doesn't fit well with the ARM instruction set.
5125 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbachffa32252011-07-19 19:13:28 +00005126 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5127 Operands.erase(Operands.begin() + 1);
5128 delete Op;
5129 }
5130
Jim Grosbachcf121c32011-07-28 21:57:55 +00005131 // ARM mode 'blx' need special handling, as the register operand version
5132 // is predicable, but the label operand version is not. So, we can't rely
5133 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach21ff17c2011-10-07 23:24:09 +00005134 // a k_CondCode operand in the list. If we're trying to match the label
5135 // version, remove the k_CondCode operand here.
Jim Grosbachcf121c32011-07-28 21:57:55 +00005136 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5137 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5138 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5139 Operands.erase(Operands.begin() + 1);
5140 delete Op;
5141 }
Jim Grosbach857e1a72011-08-11 23:51:13 +00005142
5143 // The vector-compare-to-zero instructions have a literal token "#0" at
5144 // the end that comes to here as an immediate operand. Convert it to a
5145 // token to play nicely with the matcher.
5146 if ((Mnemonic == "vceq" || Mnemonic == "vcge" || Mnemonic == "vcgt" ||
5147 Mnemonic == "vcle" || Mnemonic == "vclt") && Operands.size() == 6 &&
5148 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5149 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5150 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5151 if (CE && CE->getValue() == 0) {
5152 Operands.erase(Operands.begin() + 5);
5153 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5154 delete Op;
5155 }
5156 }
Jim Grosbach68259142011-10-03 22:30:24 +00005157 // VCMP{E} does the same thing, but with a different operand count.
5158 if ((Mnemonic == "vcmp" || Mnemonic == "vcmpe") && Operands.size() == 5 &&
5159 static_cast<ARMOperand*>(Operands[4])->isImm()) {
5160 ARMOperand *Op = static_cast<ARMOperand*>(Operands[4]);
5161 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5162 if (CE && CE->getValue() == 0) {
5163 Operands.erase(Operands.begin() + 4);
5164 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5165 delete Op;
5166 }
5167 }
Jim Grosbach934755a2011-08-22 23:47:13 +00005168 // Similarly, the Thumb1 "RSB" instruction has a literal "#0" on the
Jim Grosbach55b02f22011-12-13 20:50:38 +00005169 // end. Convert it to a token here. Take care not to convert those
5170 // that should hit the Thumb2 encoding.
Jim Grosbach934755a2011-08-22 23:47:13 +00005171 if (Mnemonic == "rsb" && isThumb() && Operands.size() == 6 &&
Jim Grosbach55b02f22011-12-13 20:50:38 +00005172 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5173 static_cast<ARMOperand*>(Operands[4])->isReg() &&
Jim Grosbach934755a2011-08-22 23:47:13 +00005174 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5175 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5176 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
Jim Grosbach55b02f22011-12-13 20:50:38 +00005177 if (CE && CE->getValue() == 0 &&
5178 (isThumbOne() ||
Jim Grosbachd7ea73a2011-12-13 21:06:41 +00005179 // The cc_out operand matches the IT block.
5180 ((inITBlock() != CarrySetting) &&
5181 // Neither register operand is a high register.
Jim Grosbach55b02f22011-12-13 20:50:38 +00005182 (isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbachd7ea73a2011-12-13 21:06:41 +00005183 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()))))){
Jim Grosbach934755a2011-08-22 23:47:13 +00005184 Operands.erase(Operands.begin() + 5);
5185 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5186 delete Op;
5187 }
5188 }
5189
Chris Lattner98986712010-01-14 22:21:20 +00005190 return false;
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00005191}
5192
Jim Grosbach189610f2011-07-26 18:25:39 +00005193// Validate context-sensitive operand constraints.
Jim Grosbachaa875f82011-08-23 18:13:04 +00005194
5195// return 'true' if register list contains non-low GPR registers,
5196// 'false' otherwise. If Reg is in the register list or is HiReg, set
5197// 'containsReg' to true.
5198static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5199 unsigned HiReg, bool &containsReg) {
5200 containsReg = false;
5201 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5202 unsigned OpReg = Inst.getOperand(i).getReg();
5203 if (OpReg == Reg)
5204 containsReg = true;
5205 // Anything other than a low register isn't legal here.
5206 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5207 return true;
5208 }
5209 return false;
5210}
5211
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005212// Check if the specified regisgter is in the register list of the inst,
5213// starting at the indicated operand number.
5214static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5215 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5216 unsigned OpReg = Inst.getOperand(i).getReg();
5217 if (OpReg == Reg)
5218 return true;
5219 }
5220 return false;
5221}
5222
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005223// FIXME: We would really prefer to have MCInstrInfo (the wrapper around
5224// the ARMInsts array) instead. Getting that here requires awkward
5225// API changes, though. Better way?
5226namespace llvm {
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00005227extern const MCInstrDesc ARMInsts[];
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005228}
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00005229static const MCInstrDesc &getInstDesc(unsigned Opcode) {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005230 return ARMInsts[Opcode];
5231}
5232
Jim Grosbach189610f2011-07-26 18:25:39 +00005233// FIXME: We would really like to be able to tablegen'erate this.
5234bool ARMAsmParser::
5235validateInstruction(MCInst &Inst,
5236 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00005237 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005238 SMLoc Loc = Operands[0]->getStartLoc();
5239 // Check the IT block state first.
Jim Grosbach74423e32012-01-25 19:52:01 +00005240 // NOTE: BKPT instruction has the interesting property of being
5241 // allowed in IT blocks, but not being predicable. It just always
Owen Andersonb6b7f512011-09-13 17:59:19 +00005242 // executes.
Jim Grosbach74423e32012-01-25 19:52:01 +00005243 if (inITBlock() && Inst.getOpcode() != ARM::tBKPT &&
5244 Inst.getOpcode() != ARM::BKPT) {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005245 unsigned bit = 1;
5246 if (ITState.FirstCond)
5247 ITState.FirstCond = false;
5248 else
Jim Grosbacha1109882011-09-02 23:22:08 +00005249 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005250 // The instruction must be predicable.
5251 if (!MCID.isPredicable())
5252 return Error(Loc, "instructions in IT block must be predicable");
5253 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5254 unsigned ITCond = bit ? ITState.Cond :
5255 ARMCC::getOppositeCondition(ITState.Cond);
5256 if (Cond != ITCond) {
5257 // Find the condition code Operand to get its SMLoc information.
5258 SMLoc CondLoc;
5259 for (unsigned i = 1; i < Operands.size(); ++i)
5260 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5261 CondLoc = Operands[i]->getStartLoc();
5262 return Error(CondLoc, "incorrect condition in IT block; got '" +
5263 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5264 "', but expected '" +
5265 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5266 }
Jim Grosbachc9a9b442011-08-31 18:29:05 +00005267 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005268 } else if (isThumbTwo() && MCID.isPredicable() &&
5269 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Owen Anderson51f6a7a2011-09-09 21:48:23 +00005270 ARMCC::AL && Inst.getOpcode() != ARM::tB &&
5271 Inst.getOpcode() != ARM::t2B)
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005272 return Error(Loc, "predicated instructions must be in IT block");
5273
Jim Grosbach189610f2011-07-26 18:25:39 +00005274 switch (Inst.getOpcode()) {
Jim Grosbach2fd2b872011-08-10 20:29:19 +00005275 case ARM::LDRD:
5276 case ARM::LDRD_PRE:
5277 case ARM::LDRD_POST:
Jim Grosbach189610f2011-07-26 18:25:39 +00005278 case ARM::LDREXD: {
5279 // Rt2 must be Rt + 1.
Eric Christopherdf1c6372012-08-09 22:10:21 +00005280 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5281 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbach189610f2011-07-26 18:25:39 +00005282 if (Rt2 != Rt + 1)
5283 return Error(Operands[3]->getStartLoc(),
5284 "destination operands must be sequential");
5285 return false;
5286 }
Jim Grosbach14605d12011-08-11 20:28:23 +00005287 case ARM::STRD: {
5288 // Rt2 must be Rt + 1.
Eric Christopherdf1c6372012-08-09 22:10:21 +00005289 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5290 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbach14605d12011-08-11 20:28:23 +00005291 if (Rt2 != Rt + 1)
5292 return Error(Operands[3]->getStartLoc(),
5293 "source operands must be sequential");
5294 return false;
5295 }
Jim Grosbach53642c52011-08-10 20:49:18 +00005296 case ARM::STRD_PRE:
5297 case ARM::STRD_POST:
Jim Grosbach189610f2011-07-26 18:25:39 +00005298 case ARM::STREXD: {
5299 // Rt2 must be Rt + 1.
Eric Christopherdf1c6372012-08-09 22:10:21 +00005300 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5301 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbach189610f2011-07-26 18:25:39 +00005302 if (Rt2 != Rt + 1)
Jim Grosbach14605d12011-08-11 20:28:23 +00005303 return Error(Operands[3]->getStartLoc(),
Jim Grosbach189610f2011-07-26 18:25:39 +00005304 "source operands must be sequential");
5305 return false;
5306 }
Jim Grosbachfb8989e2011-07-27 21:09:25 +00005307 case ARM::SBFX:
5308 case ARM::UBFX: {
5309 // width must be in range [1, 32-lsb]
5310 unsigned lsb = Inst.getOperand(2).getImm();
5311 unsigned widthm1 = Inst.getOperand(3).getImm();
5312 if (widthm1 >= 32 - lsb)
5313 return Error(Operands[5]->getStartLoc(),
5314 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach00c9a512011-08-16 21:42:31 +00005315 return false;
Jim Grosbachfb8989e2011-07-27 21:09:25 +00005316 }
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005317 case ARM::tLDMIA: {
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005318 // If we're parsing Thumb2, the .w variant is available and handles
5319 // most cases that are normally illegal for a Thumb1 LDM
5320 // instruction. We'll make the transformation in processInstruction()
5321 // if necessary.
5322 //
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005323 // Thumb LDM instructions are writeback iff the base register is not
5324 // in the register list.
5325 unsigned Rn = Inst.getOperand(0).getReg();
Jim Grosbach7260c6a2011-08-22 23:01:07 +00005326 bool hasWritebackToken =
5327 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5328 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Jim Grosbachaa875f82011-08-23 18:13:04 +00005329 bool listContainsBase;
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005330 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
Jim Grosbachaa875f82011-08-23 18:13:04 +00005331 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5332 "registers must be in range r0-r7");
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005333 // If we should have writeback, then there should be a '!' token.
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005334 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005335 return Error(Operands[2]->getStartLoc(),
5336 "writeback operator '!' expected");
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005337 // If we should not have writeback, there must not be a '!'. This is
5338 // true even for the 32-bit wide encodings.
Jim Grosbachaa875f82011-08-23 18:13:04 +00005339 if (listContainsBase && hasWritebackToken)
Jim Grosbach7260c6a2011-08-22 23:01:07 +00005340 return Error(Operands[3]->getStartLoc(),
5341 "writeback operator '!' not allowed when base register "
5342 "in register list");
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005343
5344 break;
5345 }
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005346 case ARM::t2LDMIA_UPD: {
5347 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5348 return Error(Operands[4]->getStartLoc(),
5349 "writeback operator '!' not allowed when base register "
5350 "in register list");
5351 break;
5352 }
Chad Rosier64b34442012-08-30 23:20:38 +00005353 case ARM::tMUL: {
5354 // The second source operand must be the same register as the destination
5355 // operand.
Chad Rosier429af6f2012-08-31 17:24:10 +00005356 //
5357 // In this case, we must directly check the parsed operands because the
5358 // cvtThumbMultiply() function is written in such a way that it guarantees
5359 // this first statement is always true for the new Inst. Essentially, the
5360 // destination is unconditionally copied into the second source operand
5361 // without checking to see if it matches what we actually parsed.
Chad Rosier64b34442012-08-30 23:20:38 +00005362 if (Operands.size() == 6 &&
5363 (((ARMOperand*)Operands[3])->getReg() !=
5364 ((ARMOperand*)Operands[5])->getReg()) &&
5365 (((ARMOperand*)Operands[3])->getReg() !=
5366 ((ARMOperand*)Operands[4])->getReg())) {
Chad Rosierfafa2832012-08-30 23:22:05 +00005367 return Error(Operands[3]->getStartLoc(),
5368 "destination register must match source register");
Chad Rosier64b34442012-08-30 23:20:38 +00005369 }
5370 break;
5371 }
Jim Grosbach54026372011-11-10 23:17:11 +00005372 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5373 // so only issue a diagnostic for thumb1. The instructions will be
5374 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach6dcafc02011-08-22 23:17:34 +00005375 case ARM::tPOP: {
Jim Grosbachaa875f82011-08-23 18:13:04 +00005376 bool listContainsBase;
Jim Grosbach54026372011-11-10 23:17:11 +00005377 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5378 !isThumbTwo())
Jim Grosbachaa875f82011-08-23 18:13:04 +00005379 return Error(Operands[2]->getStartLoc(),
5380 "registers must be in range r0-r7 or pc");
Jim Grosbach6dcafc02011-08-22 23:17:34 +00005381 break;
5382 }
5383 case ARM::tPUSH: {
Jim Grosbachaa875f82011-08-23 18:13:04 +00005384 bool listContainsBase;
Jim Grosbach54026372011-11-10 23:17:11 +00005385 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5386 !isThumbTwo())
Jim Grosbachaa875f82011-08-23 18:13:04 +00005387 return Error(Operands[2]->getStartLoc(),
5388 "registers must be in range r0-r7 or lr");
Jim Grosbach6dcafc02011-08-22 23:17:34 +00005389 break;
5390 }
Jim Grosbach1e84f192011-08-23 18:15:37 +00005391 case ARM::tSTMIA_UPD: {
5392 bool listContainsBase;
Jim Grosbach8213c962011-09-16 20:50:13 +00005393 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
Jim Grosbach1e84f192011-08-23 18:15:37 +00005394 return Error(Operands[4]->getStartLoc(),
5395 "registers must be in range r0-r7");
5396 break;
5397 }
Jim Grosbacha9cc08f2012-04-27 23:51:36 +00005398 case ARM::tADDrSP: {
5399 // If the non-SP source operand and the destination operand are not the
5400 // same, we need thumb2 (for the wide encoding), or we have an error.
5401 if (!isThumbTwo() &&
5402 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5403 return Error(Operands[4]->getStartLoc(),
5404 "source register must be the same as destination");
5405 }
5406 break;
5407 }
Jim Grosbach189610f2011-07-26 18:25:39 +00005408 }
5409
5410 return false;
5411}
5412
Jim Grosbachd7433e22012-01-23 23:45:44 +00005413static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach84defb52011-12-02 22:34:51 +00005414 switch(Opc) {
Craig Topperbc219812012-02-07 02:50:20 +00005415 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005416 // VST1LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005417 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5418 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5419 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5420 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5421 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5422 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5423 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5424 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5425 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005426
5427 // VST2LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005428 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5429 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5430 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5431 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5432 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach5b484312011-12-20 20:46:29 +00005433
Jim Grosbach7945ead2012-01-24 00:43:12 +00005434 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5435 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5436 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5437 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5438 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach5b484312011-12-20 20:46:29 +00005439
Jim Grosbach7945ead2012-01-24 00:43:12 +00005440 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5441 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5442 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5443 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5444 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005445
Jim Grosbach4adb1822012-01-24 00:07:41 +00005446 // VST3LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005447 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5448 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5449 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5450 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5451 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5452 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5453 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5454 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5455 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5456 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5457 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5458 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5459 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5460 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5461 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbach4adb1822012-01-24 00:07:41 +00005462
Jim Grosbachd7433e22012-01-23 23:45:44 +00005463 // VST3
Jim Grosbach7945ead2012-01-24 00:43:12 +00005464 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5465 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5466 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5467 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5468 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5469 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5470 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5471 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5472 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5473 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5474 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5475 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5476 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5477 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5478 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5479 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5480 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5481 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbach539aab72012-01-24 00:58:13 +00005482
Jim Grosbach88a54de2012-01-24 18:53:13 +00005483 // VST4LN
5484 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5485 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5486 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5487 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5488 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5489 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5490 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5491 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5492 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5493 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5494 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5495 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5496 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5497 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5498 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5499
Jim Grosbach539aab72012-01-24 00:58:13 +00005500 // VST4
5501 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5502 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5503 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5504 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5505 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5506 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5507 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5508 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5509 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5510 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5511 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5512 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5513 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5514 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5515 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5516 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5517 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5518 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbach84defb52011-12-02 22:34:51 +00005519 }
5520}
5521
Jim Grosbachd7433e22012-01-23 23:45:44 +00005522static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach7636bf62011-12-02 00:35:16 +00005523 switch(Opc) {
Craig Topperbc219812012-02-07 02:50:20 +00005524 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005525 // VLD1LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005526 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5527 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5528 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5529 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5530 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5531 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5532 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5533 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5534 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005535
5536 // VLD2LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005537 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5538 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5539 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5540 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5541 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5542 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5543 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5544 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5545 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5546 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5547 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5548 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5549 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5550 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5551 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbach3a678af2012-01-23 21:53:26 +00005552
Jim Grosbach5e59f7e2012-01-24 23:47:04 +00005553 // VLD3DUP
5554 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5555 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5556 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5557 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5558 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5559 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5560 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5561 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5562 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5563 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5564 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5565 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5566 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5567 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5568 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5569 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5570 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5571 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5572
Jim Grosbach3a678af2012-01-23 21:53:26 +00005573 // VLD3LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005574 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5575 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5576 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5577 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5578 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5579 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5580 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5581 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5582 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5583 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5584 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5585 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5586 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5587 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5588 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachc387fc62012-01-23 23:20:46 +00005589
5590 // VLD3
Jim Grosbach7945ead2012-01-24 00:43:12 +00005591 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5592 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5593 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5594 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5595 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5596 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5597 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5598 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5599 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5600 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5601 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5602 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5603 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5604 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5605 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5606 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5607 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5608 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbach8abe7e32012-01-24 00:43:17 +00005609
Jim Grosbache983a132012-01-24 18:37:25 +00005610 // VLD4LN
5611 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5612 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5613 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5614 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5615 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5616 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5617 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5618 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5619 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5620 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5621 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5622 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5623 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5624 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5625 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5626
Jim Grosbacha57a36a2012-01-25 00:01:08 +00005627 // VLD4DUP
5628 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5629 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5630 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5631 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5632 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5633 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5634 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5635 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5636 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5637 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5638 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5639 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5640 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5641 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5642 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5643 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5644 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5645 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5646
Jim Grosbach8abe7e32012-01-24 00:43:17 +00005647 // VLD4
5648 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5649 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5650 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5651 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5652 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5653 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5654 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5655 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5656 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5657 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5658 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5659 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5660 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5661 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5662 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5663 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5664 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5665 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach7636bf62011-12-02 00:35:16 +00005666 }
5667}
5668
Jim Grosbach83ec8772011-11-10 23:42:14 +00005669bool ARMAsmParser::
Jim Grosbachf8fce712011-08-11 17:35:48 +00005670processInstruction(MCInst &Inst,
5671 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5672 switch (Inst.getOpcode()) {
Jim Grosbach0b4c6732012-01-18 22:46:46 +00005673 // Aliases for alternate PC+imm syntax of LDR instructions.
5674 case ARM::t2LDRpcrel:
5675 Inst.setOpcode(ARM::t2LDRpci);
5676 return true;
5677 case ARM::t2LDRBpcrel:
5678 Inst.setOpcode(ARM::t2LDRBpci);
5679 return true;
5680 case ARM::t2LDRHpcrel:
5681 Inst.setOpcode(ARM::t2LDRHpci);
5682 return true;
5683 case ARM::t2LDRSBpcrel:
5684 Inst.setOpcode(ARM::t2LDRSBpci);
5685 return true;
5686 case ARM::t2LDRSHpcrel:
5687 Inst.setOpcode(ARM::t2LDRSHpci);
5688 return true;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005689 // Handle NEON VST complex aliases.
Jim Grosbach8b31f952012-01-23 19:39:08 +00005690 case ARM::VST1LNdWB_register_Asm_8:
5691 case ARM::VST1LNdWB_register_Asm_16:
5692 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbach84defb52011-12-02 22:34:51 +00005693 MCInst TmpInst;
5694 // Shuffle the operands around so the lane index operand is in the
5695 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005696 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005697 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach84defb52011-12-02 22:34:51 +00005698 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5699 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5700 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5701 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5702 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5703 TmpInst.addOperand(Inst.getOperand(1)); // lane
5704 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5705 TmpInst.addOperand(Inst.getOperand(6));
5706 Inst = TmpInst;
5707 return true;
5708 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005709
Jim Grosbach8b31f952012-01-23 19:39:08 +00005710 case ARM::VST2LNdWB_register_Asm_8:
5711 case ARM::VST2LNdWB_register_Asm_16:
5712 case ARM::VST2LNdWB_register_Asm_32:
5713 case ARM::VST2LNqWB_register_Asm_16:
5714 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005715 MCInst TmpInst;
5716 // Shuffle the operands around so the lane index operand is in the
5717 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005718 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005719 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005720 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5721 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5722 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5723 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5724 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach5b484312011-12-20 20:46:29 +00005725 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5726 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005727 TmpInst.addOperand(Inst.getOperand(1)); // lane
5728 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5729 TmpInst.addOperand(Inst.getOperand(6));
5730 Inst = TmpInst;
5731 return true;
5732 }
Jim Grosbach4adb1822012-01-24 00:07:41 +00005733
5734 case ARM::VST3LNdWB_register_Asm_8:
5735 case ARM::VST3LNdWB_register_Asm_16:
5736 case ARM::VST3LNdWB_register_Asm_32:
5737 case ARM::VST3LNqWB_register_Asm_16:
5738 case ARM::VST3LNqWB_register_Asm_32: {
5739 MCInst TmpInst;
5740 // Shuffle the operands around so the lane index operand is in the
5741 // right place.
5742 unsigned Spacing;
5743 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5744 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5745 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5746 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5747 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5748 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5749 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5750 Spacing));
5751 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5752 Spacing * 2));
5753 TmpInst.addOperand(Inst.getOperand(1)); // lane
5754 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5755 TmpInst.addOperand(Inst.getOperand(6));
5756 Inst = TmpInst;
5757 return true;
5758 }
5759
Jim Grosbach88a54de2012-01-24 18:53:13 +00005760 case ARM::VST4LNdWB_register_Asm_8:
5761 case ARM::VST4LNdWB_register_Asm_16:
5762 case ARM::VST4LNdWB_register_Asm_32:
5763 case ARM::VST4LNqWB_register_Asm_16:
5764 case ARM::VST4LNqWB_register_Asm_32: {
5765 MCInst TmpInst;
5766 // Shuffle the operands around so the lane index operand is in the
5767 // right place.
5768 unsigned Spacing;
5769 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5770 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5771 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5772 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5773 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5774 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5775 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5776 Spacing));
5777 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5778 Spacing * 2));
5779 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5780 Spacing * 3));
5781 TmpInst.addOperand(Inst.getOperand(1)); // lane
5782 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5783 TmpInst.addOperand(Inst.getOperand(6));
5784 Inst = TmpInst;
5785 return true;
5786 }
5787
Jim Grosbach8b31f952012-01-23 19:39:08 +00005788 case ARM::VST1LNdWB_fixed_Asm_8:
5789 case ARM::VST1LNdWB_fixed_Asm_16:
5790 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbach84defb52011-12-02 22:34:51 +00005791 MCInst TmpInst;
5792 // Shuffle the operands around so the lane index operand is in the
5793 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005794 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005795 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach84defb52011-12-02 22:34:51 +00005796 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5797 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5798 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5799 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5800 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5801 TmpInst.addOperand(Inst.getOperand(1)); // lane
5802 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5803 TmpInst.addOperand(Inst.getOperand(5));
5804 Inst = TmpInst;
5805 return true;
5806 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005807
Jim Grosbach8b31f952012-01-23 19:39:08 +00005808 case ARM::VST2LNdWB_fixed_Asm_8:
5809 case ARM::VST2LNdWB_fixed_Asm_16:
5810 case ARM::VST2LNdWB_fixed_Asm_32:
5811 case ARM::VST2LNqWB_fixed_Asm_16:
5812 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005813 MCInst TmpInst;
5814 // Shuffle the operands around so the lane index operand is in the
5815 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005816 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005817 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005818 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5819 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5820 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5821 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5822 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach5b484312011-12-20 20:46:29 +00005823 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5824 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005825 TmpInst.addOperand(Inst.getOperand(1)); // lane
5826 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5827 TmpInst.addOperand(Inst.getOperand(5));
5828 Inst = TmpInst;
5829 return true;
5830 }
Jim Grosbach4adb1822012-01-24 00:07:41 +00005831
5832 case ARM::VST3LNdWB_fixed_Asm_8:
5833 case ARM::VST3LNdWB_fixed_Asm_16:
5834 case ARM::VST3LNdWB_fixed_Asm_32:
5835 case ARM::VST3LNqWB_fixed_Asm_16:
5836 case ARM::VST3LNqWB_fixed_Asm_32: {
5837 MCInst TmpInst;
5838 // Shuffle the operands around so the lane index operand is in the
5839 // right place.
5840 unsigned Spacing;
5841 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5842 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5843 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5844 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5845 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5846 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5847 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5848 Spacing));
5849 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5850 Spacing * 2));
5851 TmpInst.addOperand(Inst.getOperand(1)); // lane
5852 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5853 TmpInst.addOperand(Inst.getOperand(5));
5854 Inst = TmpInst;
5855 return true;
5856 }
5857
Jim Grosbach88a54de2012-01-24 18:53:13 +00005858 case ARM::VST4LNdWB_fixed_Asm_8:
5859 case ARM::VST4LNdWB_fixed_Asm_16:
5860 case ARM::VST4LNdWB_fixed_Asm_32:
5861 case ARM::VST4LNqWB_fixed_Asm_16:
5862 case ARM::VST4LNqWB_fixed_Asm_32: {
5863 MCInst TmpInst;
5864 // Shuffle the operands around so the lane index operand is in the
5865 // right place.
5866 unsigned Spacing;
5867 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5868 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5869 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5870 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5871 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5872 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5873 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5874 Spacing));
5875 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5876 Spacing * 2));
5877 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5878 Spacing * 3));
5879 TmpInst.addOperand(Inst.getOperand(1)); // lane
5880 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5881 TmpInst.addOperand(Inst.getOperand(5));
5882 Inst = TmpInst;
5883 return true;
5884 }
5885
Jim Grosbach8b31f952012-01-23 19:39:08 +00005886 case ARM::VST1LNdAsm_8:
5887 case ARM::VST1LNdAsm_16:
5888 case ARM::VST1LNdAsm_32: {
Jim Grosbach84defb52011-12-02 22:34:51 +00005889 MCInst TmpInst;
5890 // Shuffle the operands around so the lane index operand is in the
5891 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005892 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005893 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach84defb52011-12-02 22:34:51 +00005894 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5895 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5896 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5897 TmpInst.addOperand(Inst.getOperand(1)); // lane
5898 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5899 TmpInst.addOperand(Inst.getOperand(5));
5900 Inst = TmpInst;
5901 return true;
5902 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005903
Jim Grosbach8b31f952012-01-23 19:39:08 +00005904 case ARM::VST2LNdAsm_8:
5905 case ARM::VST2LNdAsm_16:
5906 case ARM::VST2LNdAsm_32:
5907 case ARM::VST2LNqAsm_16:
5908 case ARM::VST2LNqAsm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005909 MCInst TmpInst;
5910 // Shuffle the operands around so the lane index operand is in the
5911 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005912 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005913 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005914 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5915 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5916 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach5b484312011-12-20 20:46:29 +00005917 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5918 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005919 TmpInst.addOperand(Inst.getOperand(1)); // lane
5920 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5921 TmpInst.addOperand(Inst.getOperand(5));
5922 Inst = TmpInst;
5923 return true;
5924 }
Jim Grosbach4adb1822012-01-24 00:07:41 +00005925
5926 case ARM::VST3LNdAsm_8:
5927 case ARM::VST3LNdAsm_16:
5928 case ARM::VST3LNdAsm_32:
5929 case ARM::VST3LNqAsm_16:
5930 case ARM::VST3LNqAsm_32: {
5931 MCInst TmpInst;
5932 // Shuffle the operands around so the lane index operand is in the
5933 // right place.
5934 unsigned Spacing;
5935 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5936 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5937 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5938 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5939 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5940 Spacing));
5941 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5942 Spacing * 2));
5943 TmpInst.addOperand(Inst.getOperand(1)); // lane
5944 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5945 TmpInst.addOperand(Inst.getOperand(5));
5946 Inst = TmpInst;
5947 return true;
5948 }
5949
Jim Grosbach88a54de2012-01-24 18:53:13 +00005950 case ARM::VST4LNdAsm_8:
5951 case ARM::VST4LNdAsm_16:
5952 case ARM::VST4LNdAsm_32:
5953 case ARM::VST4LNqAsm_16:
5954 case ARM::VST4LNqAsm_32: {
5955 MCInst TmpInst;
5956 // Shuffle the operands around so the lane index operand is in the
5957 // right place.
5958 unsigned Spacing;
5959 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5960 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5961 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5962 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5963 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5964 Spacing));
5965 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5966 Spacing * 2));
5967 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5968 Spacing * 3));
5969 TmpInst.addOperand(Inst.getOperand(1)); // lane
5970 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5971 TmpInst.addOperand(Inst.getOperand(5));
5972 Inst = TmpInst;
5973 return true;
5974 }
5975
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005976 // Handle NEON VLD complex aliases.
Jim Grosbach8b31f952012-01-23 19:39:08 +00005977 case ARM::VLD1LNdWB_register_Asm_8:
5978 case ARM::VLD1LNdWB_register_Asm_16:
5979 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbach872eedb2011-12-02 22:01:52 +00005980 MCInst TmpInst;
5981 // Shuffle the operands around so the lane index operand is in the
5982 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005983 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005984 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach872eedb2011-12-02 22:01:52 +00005985 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5986 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5987 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5988 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5989 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5990 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5991 TmpInst.addOperand(Inst.getOperand(1)); // lane
5992 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5993 TmpInst.addOperand(Inst.getOperand(6));
5994 Inst = TmpInst;
5995 return true;
5996 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005997
Jim Grosbach8b31f952012-01-23 19:39:08 +00005998 case ARM::VLD2LNdWB_register_Asm_8:
5999 case ARM::VLD2LNdWB_register_Asm_16:
6000 case ARM::VLD2LNdWB_register_Asm_32:
6001 case ARM::VLD2LNqWB_register_Asm_16:
6002 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006003 MCInst TmpInst;
6004 // Shuffle the operands around so the lane index operand is in the
6005 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006006 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006007 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006008 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006009 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6010 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006011 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6012 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6013 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6014 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6015 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006016 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6017 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006018 TmpInst.addOperand(Inst.getOperand(1)); // lane
6019 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6020 TmpInst.addOperand(Inst.getOperand(6));
6021 Inst = TmpInst;
6022 return true;
6023 }
6024
Jim Grosbach3a678af2012-01-23 21:53:26 +00006025 case ARM::VLD3LNdWB_register_Asm_8:
6026 case ARM::VLD3LNdWB_register_Asm_16:
6027 case ARM::VLD3LNdWB_register_Asm_32:
6028 case ARM::VLD3LNqWB_register_Asm_16:
6029 case ARM::VLD3LNqWB_register_Asm_32: {
6030 MCInst TmpInst;
6031 // Shuffle the operands around so the lane index operand is in the
6032 // right place.
6033 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006034 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006035 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6036 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6037 Spacing));
6038 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006039 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006040 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6041 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6042 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6043 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6044 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6045 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6046 Spacing));
6047 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006048 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006049 TmpInst.addOperand(Inst.getOperand(1)); // lane
6050 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6051 TmpInst.addOperand(Inst.getOperand(6));
6052 Inst = TmpInst;
6053 return true;
6054 }
6055
Jim Grosbache983a132012-01-24 18:37:25 +00006056 case ARM::VLD4LNdWB_register_Asm_8:
6057 case ARM::VLD4LNdWB_register_Asm_16:
6058 case ARM::VLD4LNdWB_register_Asm_32:
6059 case ARM::VLD4LNqWB_register_Asm_16:
6060 case ARM::VLD4LNqWB_register_Asm_32: {
6061 MCInst TmpInst;
6062 // Shuffle the operands around so the lane index operand is in the
6063 // right place.
6064 unsigned Spacing;
6065 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6066 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6067 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6068 Spacing));
6069 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6070 Spacing * 2));
6071 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6072 Spacing * 3));
6073 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6074 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6075 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6076 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6077 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6078 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6079 Spacing));
6080 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6081 Spacing * 2));
6082 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6083 Spacing * 3));
6084 TmpInst.addOperand(Inst.getOperand(1)); // lane
6085 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6086 TmpInst.addOperand(Inst.getOperand(6));
6087 Inst = TmpInst;
6088 return true;
6089 }
6090
Jim Grosbach8b31f952012-01-23 19:39:08 +00006091 case ARM::VLD1LNdWB_fixed_Asm_8:
6092 case ARM::VLD1LNdWB_fixed_Asm_16:
6093 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbach872eedb2011-12-02 22:01:52 +00006094 MCInst TmpInst;
6095 // Shuffle the operands around so the lane index operand is in the
6096 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006097 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006098 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach872eedb2011-12-02 22:01:52 +00006099 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6100 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6101 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6102 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6103 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6104 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6105 TmpInst.addOperand(Inst.getOperand(1)); // lane
6106 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6107 TmpInst.addOperand(Inst.getOperand(5));
6108 Inst = TmpInst;
6109 return true;
6110 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006111
Jim Grosbach8b31f952012-01-23 19:39:08 +00006112 case ARM::VLD2LNdWB_fixed_Asm_8:
6113 case ARM::VLD2LNdWB_fixed_Asm_16:
6114 case ARM::VLD2LNdWB_fixed_Asm_32:
6115 case ARM::VLD2LNqWB_fixed_Asm_16:
6116 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006117 MCInst TmpInst;
6118 // Shuffle the operands around so the lane index operand is in the
6119 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006120 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006121 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006122 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006123 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6124 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006125 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6126 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6127 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6128 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6129 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006130 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6131 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006132 TmpInst.addOperand(Inst.getOperand(1)); // lane
6133 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6134 TmpInst.addOperand(Inst.getOperand(5));
6135 Inst = TmpInst;
6136 return true;
6137 }
6138
Jim Grosbach3a678af2012-01-23 21:53:26 +00006139 case ARM::VLD3LNdWB_fixed_Asm_8:
6140 case ARM::VLD3LNdWB_fixed_Asm_16:
6141 case ARM::VLD3LNdWB_fixed_Asm_32:
6142 case ARM::VLD3LNqWB_fixed_Asm_16:
6143 case ARM::VLD3LNqWB_fixed_Asm_32: {
6144 MCInst TmpInst;
6145 // Shuffle the operands around so the lane index operand is in the
6146 // right place.
6147 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006148 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006149 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6150 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6151 Spacing));
6152 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006153 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006154 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6155 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6156 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6157 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6158 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6159 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6160 Spacing));
6161 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006162 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006163 TmpInst.addOperand(Inst.getOperand(1)); // lane
6164 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6165 TmpInst.addOperand(Inst.getOperand(5));
6166 Inst = TmpInst;
6167 return true;
6168 }
6169
Jim Grosbache983a132012-01-24 18:37:25 +00006170 case ARM::VLD4LNdWB_fixed_Asm_8:
6171 case ARM::VLD4LNdWB_fixed_Asm_16:
6172 case ARM::VLD4LNdWB_fixed_Asm_32:
6173 case ARM::VLD4LNqWB_fixed_Asm_16:
6174 case ARM::VLD4LNqWB_fixed_Asm_32: {
6175 MCInst TmpInst;
6176 // Shuffle the operands around so the lane index operand is in the
6177 // right place.
6178 unsigned Spacing;
6179 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6180 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6181 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6182 Spacing));
6183 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6184 Spacing * 2));
6185 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6186 Spacing * 3));
6187 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6188 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6189 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6190 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6191 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6192 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6193 Spacing));
6194 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6195 Spacing * 2));
6196 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6197 Spacing * 3));
6198 TmpInst.addOperand(Inst.getOperand(1)); // lane
6199 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6200 TmpInst.addOperand(Inst.getOperand(5));
6201 Inst = TmpInst;
6202 return true;
6203 }
6204
Jim Grosbach8b31f952012-01-23 19:39:08 +00006205 case ARM::VLD1LNdAsm_8:
6206 case ARM::VLD1LNdAsm_16:
6207 case ARM::VLD1LNdAsm_32: {
Jim Grosbach7636bf62011-12-02 00:35:16 +00006208 MCInst TmpInst;
6209 // Shuffle the operands around so the lane index operand is in the
6210 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006211 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006212 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach7636bf62011-12-02 00:35:16 +00006213 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6214 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6215 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6216 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6217 TmpInst.addOperand(Inst.getOperand(1)); // lane
6218 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6219 TmpInst.addOperand(Inst.getOperand(5));
6220 Inst = TmpInst;
6221 return true;
6222 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006223
Jim Grosbach8b31f952012-01-23 19:39:08 +00006224 case ARM::VLD2LNdAsm_8:
6225 case ARM::VLD2LNdAsm_16:
6226 case ARM::VLD2LNdAsm_32:
6227 case ARM::VLD2LNqAsm_16:
6228 case ARM::VLD2LNqAsm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006229 MCInst TmpInst;
6230 // Shuffle the operands around so the lane index operand is in the
6231 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006232 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006233 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006234 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006235 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6236 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006237 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6238 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6239 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006240 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6241 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006242 TmpInst.addOperand(Inst.getOperand(1)); // lane
6243 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6244 TmpInst.addOperand(Inst.getOperand(5));
6245 Inst = TmpInst;
6246 return true;
6247 }
Jim Grosbach3a678af2012-01-23 21:53:26 +00006248
6249 case ARM::VLD3LNdAsm_8:
6250 case ARM::VLD3LNdAsm_16:
6251 case ARM::VLD3LNdAsm_32:
6252 case ARM::VLD3LNqAsm_16:
6253 case ARM::VLD3LNqAsm_32: {
6254 MCInst TmpInst;
6255 // Shuffle the operands around so the lane index operand is in the
6256 // right place.
6257 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006258 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006259 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6260 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6261 Spacing));
6262 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006263 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006264 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6265 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6266 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6267 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6268 Spacing));
6269 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006270 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006271 TmpInst.addOperand(Inst.getOperand(1)); // lane
6272 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6273 TmpInst.addOperand(Inst.getOperand(5));
6274 Inst = TmpInst;
6275 return true;
6276 }
6277
Jim Grosbache983a132012-01-24 18:37:25 +00006278 case ARM::VLD4LNdAsm_8:
6279 case ARM::VLD4LNdAsm_16:
6280 case ARM::VLD4LNdAsm_32:
6281 case ARM::VLD4LNqAsm_16:
6282 case ARM::VLD4LNqAsm_32: {
6283 MCInst TmpInst;
6284 // Shuffle the operands around so the lane index operand is in the
6285 // right place.
6286 unsigned Spacing;
6287 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6288 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6289 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6290 Spacing));
6291 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6292 Spacing * 2));
6293 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6294 Spacing * 3));
6295 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6296 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6297 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6298 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6299 Spacing));
6300 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6301 Spacing * 2));
6302 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6303 Spacing * 3));
6304 TmpInst.addOperand(Inst.getOperand(1)); // lane
6305 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6306 TmpInst.addOperand(Inst.getOperand(5));
6307 Inst = TmpInst;
6308 return true;
6309 }
6310
Jim Grosbach5e59f7e2012-01-24 23:47:04 +00006311 // VLD3DUP single 3-element structure to all lanes instructions.
6312 case ARM::VLD3DUPdAsm_8:
6313 case ARM::VLD3DUPdAsm_16:
6314 case ARM::VLD3DUPdAsm_32:
6315 case ARM::VLD3DUPqAsm_8:
6316 case ARM::VLD3DUPqAsm_16:
6317 case ARM::VLD3DUPqAsm_32: {
6318 MCInst TmpInst;
6319 unsigned Spacing;
6320 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6321 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6322 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6323 Spacing));
6324 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6325 Spacing * 2));
6326 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6327 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6328 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6329 TmpInst.addOperand(Inst.getOperand(4));
6330 Inst = TmpInst;
6331 return true;
6332 }
6333
6334 case ARM::VLD3DUPdWB_fixed_Asm_8:
6335 case ARM::VLD3DUPdWB_fixed_Asm_16:
6336 case ARM::VLD3DUPdWB_fixed_Asm_32:
6337 case ARM::VLD3DUPqWB_fixed_Asm_8:
6338 case ARM::VLD3DUPqWB_fixed_Asm_16:
6339 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6340 MCInst TmpInst;
6341 unsigned Spacing;
6342 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6343 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6344 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6345 Spacing));
6346 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6347 Spacing * 2));
6348 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6349 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6350 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6351 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6352 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6353 TmpInst.addOperand(Inst.getOperand(4));
6354 Inst = TmpInst;
6355 return true;
6356 }
6357
6358 case ARM::VLD3DUPdWB_register_Asm_8:
6359 case ARM::VLD3DUPdWB_register_Asm_16:
6360 case ARM::VLD3DUPdWB_register_Asm_32:
6361 case ARM::VLD3DUPqWB_register_Asm_8:
6362 case ARM::VLD3DUPqWB_register_Asm_16:
6363 case ARM::VLD3DUPqWB_register_Asm_32: {
6364 MCInst TmpInst;
6365 unsigned Spacing;
6366 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6367 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6368 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6369 Spacing));
6370 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6371 Spacing * 2));
6372 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6373 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6374 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6375 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6376 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6377 TmpInst.addOperand(Inst.getOperand(5));
6378 Inst = TmpInst;
6379 return true;
6380 }
6381
Jim Grosbachc387fc62012-01-23 23:20:46 +00006382 // VLD3 multiple 3-element structure instructions.
6383 case ARM::VLD3dAsm_8:
6384 case ARM::VLD3dAsm_16:
6385 case ARM::VLD3dAsm_32:
6386 case ARM::VLD3qAsm_8:
6387 case ARM::VLD3qAsm_16:
6388 case ARM::VLD3qAsm_32: {
6389 MCInst TmpInst;
6390 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006391 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachc387fc62012-01-23 23:20:46 +00006392 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6393 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6394 Spacing));
6395 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6396 Spacing * 2));
6397 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6398 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6399 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6400 TmpInst.addOperand(Inst.getOperand(4));
6401 Inst = TmpInst;
6402 return true;
6403 }
6404
6405 case ARM::VLD3dWB_fixed_Asm_8:
6406 case ARM::VLD3dWB_fixed_Asm_16:
6407 case ARM::VLD3dWB_fixed_Asm_32:
6408 case ARM::VLD3qWB_fixed_Asm_8:
6409 case ARM::VLD3qWB_fixed_Asm_16:
6410 case ARM::VLD3qWB_fixed_Asm_32: {
6411 MCInst TmpInst;
6412 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006413 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachc387fc62012-01-23 23:20:46 +00006414 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6415 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6416 Spacing));
6417 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6418 Spacing * 2));
6419 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6420 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6421 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6422 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6423 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6424 TmpInst.addOperand(Inst.getOperand(4));
6425 Inst = TmpInst;
6426 return true;
6427 }
6428
6429 case ARM::VLD3dWB_register_Asm_8:
6430 case ARM::VLD3dWB_register_Asm_16:
6431 case ARM::VLD3dWB_register_Asm_32:
6432 case ARM::VLD3qWB_register_Asm_8:
6433 case ARM::VLD3qWB_register_Asm_16:
6434 case ARM::VLD3qWB_register_Asm_32: {
6435 MCInst TmpInst;
6436 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006437 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachc387fc62012-01-23 23:20:46 +00006438 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6439 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6440 Spacing));
6441 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6442 Spacing * 2));
6443 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6444 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6445 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6446 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6447 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6448 TmpInst.addOperand(Inst.getOperand(5));
6449 Inst = TmpInst;
6450 return true;
6451 }
6452
Jim Grosbacha57a36a2012-01-25 00:01:08 +00006453 // VLD4DUP single 3-element structure to all lanes instructions.
6454 case ARM::VLD4DUPdAsm_8:
6455 case ARM::VLD4DUPdAsm_16:
6456 case ARM::VLD4DUPdAsm_32:
6457 case ARM::VLD4DUPqAsm_8:
6458 case ARM::VLD4DUPqAsm_16:
6459 case ARM::VLD4DUPqAsm_32: {
6460 MCInst TmpInst;
6461 unsigned Spacing;
6462 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6463 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6464 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6465 Spacing));
6466 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6467 Spacing * 2));
6468 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6469 Spacing * 3));
6470 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6471 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6472 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6473 TmpInst.addOperand(Inst.getOperand(4));
6474 Inst = TmpInst;
6475 return true;
6476 }
6477
6478 case ARM::VLD4DUPdWB_fixed_Asm_8:
6479 case ARM::VLD4DUPdWB_fixed_Asm_16:
6480 case ARM::VLD4DUPdWB_fixed_Asm_32:
6481 case ARM::VLD4DUPqWB_fixed_Asm_8:
6482 case ARM::VLD4DUPqWB_fixed_Asm_16:
6483 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6484 MCInst TmpInst;
6485 unsigned Spacing;
6486 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6487 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6488 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6489 Spacing));
6490 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6491 Spacing * 2));
6492 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6493 Spacing * 3));
6494 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6495 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6496 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6497 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6498 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6499 TmpInst.addOperand(Inst.getOperand(4));
6500 Inst = TmpInst;
6501 return true;
6502 }
6503
6504 case ARM::VLD4DUPdWB_register_Asm_8:
6505 case ARM::VLD4DUPdWB_register_Asm_16:
6506 case ARM::VLD4DUPdWB_register_Asm_32:
6507 case ARM::VLD4DUPqWB_register_Asm_8:
6508 case ARM::VLD4DUPqWB_register_Asm_16:
6509 case ARM::VLD4DUPqWB_register_Asm_32: {
6510 MCInst TmpInst;
6511 unsigned Spacing;
6512 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6513 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6514 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6515 Spacing));
6516 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6517 Spacing * 2));
6518 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6519 Spacing * 3));
6520 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6521 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6522 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6523 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6524 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6525 TmpInst.addOperand(Inst.getOperand(5));
6526 Inst = TmpInst;
6527 return true;
6528 }
6529
6530 // VLD4 multiple 4-element structure instructions.
Jim Grosbach8abe7e32012-01-24 00:43:17 +00006531 case ARM::VLD4dAsm_8:
6532 case ARM::VLD4dAsm_16:
6533 case ARM::VLD4dAsm_32:
6534 case ARM::VLD4qAsm_8:
6535 case ARM::VLD4qAsm_16:
6536 case ARM::VLD4qAsm_32: {
6537 MCInst TmpInst;
6538 unsigned Spacing;
6539 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6540 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6541 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6542 Spacing));
6543 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6544 Spacing * 2));
6545 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6546 Spacing * 3));
6547 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6548 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6549 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6550 TmpInst.addOperand(Inst.getOperand(4));
6551 Inst = TmpInst;
6552 return true;
6553 }
6554
6555 case ARM::VLD4dWB_fixed_Asm_8:
6556 case ARM::VLD4dWB_fixed_Asm_16:
6557 case ARM::VLD4dWB_fixed_Asm_32:
6558 case ARM::VLD4qWB_fixed_Asm_8:
6559 case ARM::VLD4qWB_fixed_Asm_16:
6560 case ARM::VLD4qWB_fixed_Asm_32: {
6561 MCInst TmpInst;
6562 unsigned Spacing;
6563 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6564 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6565 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6566 Spacing));
6567 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6568 Spacing * 2));
6569 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6570 Spacing * 3));
6571 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6572 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6573 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6574 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6575 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6576 TmpInst.addOperand(Inst.getOperand(4));
6577 Inst = TmpInst;
6578 return true;
6579 }
6580
6581 case ARM::VLD4dWB_register_Asm_8:
6582 case ARM::VLD4dWB_register_Asm_16:
6583 case ARM::VLD4dWB_register_Asm_32:
6584 case ARM::VLD4qWB_register_Asm_8:
6585 case ARM::VLD4qWB_register_Asm_16:
6586 case ARM::VLD4qWB_register_Asm_32: {
6587 MCInst TmpInst;
6588 unsigned Spacing;
6589 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6590 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6591 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6592 Spacing));
6593 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6594 Spacing * 2));
6595 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6596 Spacing * 3));
6597 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6598 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6599 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6600 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6601 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6602 TmpInst.addOperand(Inst.getOperand(5));
6603 Inst = TmpInst;
6604 return true;
6605 }
6606
Jim Grosbachd7433e22012-01-23 23:45:44 +00006607 // VST3 multiple 3-element structure instructions.
6608 case ARM::VST3dAsm_8:
6609 case ARM::VST3dAsm_16:
6610 case ARM::VST3dAsm_32:
6611 case ARM::VST3qAsm_8:
6612 case ARM::VST3qAsm_16:
6613 case ARM::VST3qAsm_32: {
6614 MCInst TmpInst;
6615 unsigned Spacing;
6616 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6617 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6618 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6619 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6620 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6621 Spacing));
6622 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6623 Spacing * 2));
6624 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6625 TmpInst.addOperand(Inst.getOperand(4));
6626 Inst = TmpInst;
6627 return true;
6628 }
6629
6630 case ARM::VST3dWB_fixed_Asm_8:
6631 case ARM::VST3dWB_fixed_Asm_16:
6632 case ARM::VST3dWB_fixed_Asm_32:
6633 case ARM::VST3qWB_fixed_Asm_8:
6634 case ARM::VST3qWB_fixed_Asm_16:
6635 case ARM::VST3qWB_fixed_Asm_32: {
6636 MCInst TmpInst;
6637 unsigned Spacing;
6638 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6639 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6640 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6641 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6642 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6643 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6644 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6645 Spacing));
6646 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6647 Spacing * 2));
6648 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6649 TmpInst.addOperand(Inst.getOperand(4));
6650 Inst = TmpInst;
6651 return true;
6652 }
6653
6654 case ARM::VST3dWB_register_Asm_8:
6655 case ARM::VST3dWB_register_Asm_16:
6656 case ARM::VST3dWB_register_Asm_32:
6657 case ARM::VST3qWB_register_Asm_8:
6658 case ARM::VST3qWB_register_Asm_16:
6659 case ARM::VST3qWB_register_Asm_32: {
6660 MCInst TmpInst;
6661 unsigned Spacing;
6662 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6663 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6664 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6665 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6666 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6667 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6668 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6669 Spacing));
6670 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6671 Spacing * 2));
6672 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6673 TmpInst.addOperand(Inst.getOperand(5));
6674 Inst = TmpInst;
6675 return true;
6676 }
6677
Jim Grosbach539aab72012-01-24 00:58:13 +00006678 // VST4 multiple 3-element structure instructions.
6679 case ARM::VST4dAsm_8:
6680 case ARM::VST4dAsm_16:
6681 case ARM::VST4dAsm_32:
6682 case ARM::VST4qAsm_8:
6683 case ARM::VST4qAsm_16:
6684 case ARM::VST4qAsm_32: {
6685 MCInst TmpInst;
6686 unsigned Spacing;
6687 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6688 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6689 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6690 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6691 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6692 Spacing));
6693 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6694 Spacing * 2));
6695 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6696 Spacing * 3));
6697 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6698 TmpInst.addOperand(Inst.getOperand(4));
6699 Inst = TmpInst;
6700 return true;
6701 }
6702
6703 case ARM::VST4dWB_fixed_Asm_8:
6704 case ARM::VST4dWB_fixed_Asm_16:
6705 case ARM::VST4dWB_fixed_Asm_32:
6706 case ARM::VST4qWB_fixed_Asm_8:
6707 case ARM::VST4qWB_fixed_Asm_16:
6708 case ARM::VST4qWB_fixed_Asm_32: {
6709 MCInst TmpInst;
6710 unsigned Spacing;
6711 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6712 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6713 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6714 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6715 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6716 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6717 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6718 Spacing));
6719 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6720 Spacing * 2));
6721 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6722 Spacing * 3));
6723 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6724 TmpInst.addOperand(Inst.getOperand(4));
6725 Inst = TmpInst;
6726 return true;
6727 }
6728
6729 case ARM::VST4dWB_register_Asm_8:
6730 case ARM::VST4dWB_register_Asm_16:
6731 case ARM::VST4dWB_register_Asm_32:
6732 case ARM::VST4qWB_register_Asm_8:
6733 case ARM::VST4qWB_register_Asm_16:
6734 case ARM::VST4qWB_register_Asm_32: {
6735 MCInst TmpInst;
6736 unsigned Spacing;
6737 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6738 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6739 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6740 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6741 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6742 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6743 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6744 Spacing));
6745 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6746 Spacing * 2));
6747 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6748 Spacing * 3));
6749 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6750 TmpInst.addOperand(Inst.getOperand(5));
6751 Inst = TmpInst;
6752 return true;
6753 }
6754
Jim Grosbacha5378eb2012-04-11 00:15:16 +00006755 // Handle encoding choice for the shift-immediate instructions.
6756 case ARM::t2LSLri:
6757 case ARM::t2LSRri:
6758 case ARM::t2ASRri: {
6759 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6760 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6761 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6762 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6763 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6764 unsigned NewOpc;
6765 switch (Inst.getOpcode()) {
6766 default: llvm_unreachable("unexpected opcode");
6767 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6768 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6769 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6770 }
6771 // The Thumb1 operands aren't in the same order. Awesome, eh?
6772 MCInst TmpInst;
6773 TmpInst.setOpcode(NewOpc);
6774 TmpInst.addOperand(Inst.getOperand(0));
6775 TmpInst.addOperand(Inst.getOperand(5));
6776 TmpInst.addOperand(Inst.getOperand(1));
6777 TmpInst.addOperand(Inst.getOperand(2));
6778 TmpInst.addOperand(Inst.getOperand(3));
6779 TmpInst.addOperand(Inst.getOperand(4));
6780 Inst = TmpInst;
6781 return true;
6782 }
6783 return false;
6784 }
6785
Jim Grosbach863d2af2011-12-13 22:45:11 +00006786 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbach2cc5cda2011-12-21 20:54:00 +00006787 case ARM::t2MOVsr:
6788 case ARM::t2MOVSsr: {
6789 // Which instruction to expand to depends on the CCOut operand and
6790 // whether we're in an IT block if the register operands are low
6791 // registers.
6792 bool isNarrow = false;
6793 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6794 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6795 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6796 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6797 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6798 isNarrow = true;
6799 MCInst TmpInst;
6800 unsigned newOpc;
6801 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6802 default: llvm_unreachable("unexpected opcode!");
6803 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6804 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6805 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6806 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6807 }
6808 TmpInst.setOpcode(newOpc);
6809 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6810 if (isNarrow)
6811 TmpInst.addOperand(MCOperand::CreateReg(
6812 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6813 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6814 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6815 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6816 TmpInst.addOperand(Inst.getOperand(5));
6817 if (!isNarrow)
6818 TmpInst.addOperand(MCOperand::CreateReg(
6819 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6820 Inst = TmpInst;
6821 return true;
6822 }
Jim Grosbach863d2af2011-12-13 22:45:11 +00006823 case ARM::t2MOVsi:
6824 case ARM::t2MOVSsi: {
6825 // Which instruction to expand to depends on the CCOut operand and
6826 // whether we're in an IT block if the register operands are low
6827 // registers.
6828 bool isNarrow = false;
6829 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6830 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6831 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
6832 isNarrow = true;
6833 MCInst TmpInst;
6834 unsigned newOpc;
6835 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
6836 default: llvm_unreachable("unexpected opcode!");
6837 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
6838 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
6839 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
6840 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach520dc782011-12-21 21:04:19 +00006841 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach863d2af2011-12-13 22:45:11 +00006842 }
Benjamin Kramerd9b0b022012-06-02 10:20:22 +00006843 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
6844 if (Amount == 32) Amount = 0;
Jim Grosbach863d2af2011-12-13 22:45:11 +00006845 TmpInst.setOpcode(newOpc);
6846 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6847 if (isNarrow)
6848 TmpInst.addOperand(MCOperand::CreateReg(
6849 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6850 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach520dc782011-12-21 21:04:19 +00006851 if (newOpc != ARM::t2RRX)
Benjamin Kramerd9b0b022012-06-02 10:20:22 +00006852 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach863d2af2011-12-13 22:45:11 +00006853 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6854 TmpInst.addOperand(Inst.getOperand(4));
6855 if (!isNarrow)
6856 TmpInst.addOperand(MCOperand::CreateReg(
6857 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6858 Inst = TmpInst;
6859 return true;
6860 }
6861 // Handle the ARM mode MOV complex aliases.
Jim Grosbach23f22072011-11-16 18:31:45 +00006862 case ARM::ASRr:
6863 case ARM::LSRr:
6864 case ARM::LSLr:
6865 case ARM::RORr: {
6866 ARM_AM::ShiftOpc ShiftTy;
6867 switch(Inst.getOpcode()) {
6868 default: llvm_unreachable("unexpected opcode!");
6869 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
6870 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
6871 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
6872 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
6873 }
Jim Grosbach23f22072011-11-16 18:31:45 +00006874 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
6875 MCInst TmpInst;
6876 TmpInst.setOpcode(ARM::MOVsr);
6877 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6878 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6879 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6880 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6881 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6882 TmpInst.addOperand(Inst.getOperand(4));
6883 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6884 Inst = TmpInst;
6885 return true;
6886 }
Jim Grosbachee10ff82011-11-10 19:18:01 +00006887 case ARM::ASRi:
6888 case ARM::LSRi:
6889 case ARM::LSLi:
6890 case ARM::RORi: {
6891 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachee10ff82011-11-10 19:18:01 +00006892 switch(Inst.getOpcode()) {
6893 default: llvm_unreachable("unexpected opcode!");
6894 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
6895 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
6896 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
6897 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
6898 }
6899 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach48b368b2011-11-16 19:05:59 +00006900 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachee10ff82011-11-10 19:18:01 +00006901 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonb56e4112012-04-25 18:00:18 +00006902 // A shift by 32 should be encoded as 0 when permitted
6903 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
6904 Amt = 0;
Jim Grosbachee10ff82011-11-10 19:18:01 +00006905 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach71810ab2011-11-10 16:44:55 +00006906 MCInst TmpInst;
Jim Grosbachee10ff82011-11-10 19:18:01 +00006907 TmpInst.setOpcode(Opc);
Jim Grosbach71810ab2011-11-10 16:44:55 +00006908 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6909 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachee10ff82011-11-10 19:18:01 +00006910 if (Opc == ARM::MOVsi)
6911 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach71810ab2011-11-10 16:44:55 +00006912 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6913 TmpInst.addOperand(Inst.getOperand(4));
6914 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6915 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00006916 return true;
Jim Grosbach71810ab2011-11-10 16:44:55 +00006917 }
Jim Grosbach48b368b2011-11-16 19:05:59 +00006918 case ARM::RRXi: {
6919 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
6920 MCInst TmpInst;
6921 TmpInst.setOpcode(ARM::MOVsi);
6922 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6923 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6924 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6925 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6926 TmpInst.addOperand(Inst.getOperand(3));
6927 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
6928 Inst = TmpInst;
6929 return true;
6930 }
Jim Grosbach0352b462011-11-10 23:58:34 +00006931 case ARM::t2LDMIA_UPD: {
6932 // If this is a load of a single register, then we should use
6933 // a post-indexed LDR instruction instead, per the ARM ARM.
6934 if (Inst.getNumOperands() != 5)
6935 return false;
6936 MCInst TmpInst;
6937 TmpInst.setOpcode(ARM::t2LDR_POST);
6938 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6939 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6940 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6941 TmpInst.addOperand(MCOperand::CreateImm(4));
6942 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6943 TmpInst.addOperand(Inst.getOperand(3));
6944 Inst = TmpInst;
6945 return true;
6946 }
6947 case ARM::t2STMDB_UPD: {
6948 // If this is a store of a single register, then we should use
6949 // a pre-indexed STR instruction instead, per the ARM ARM.
6950 if (Inst.getNumOperands() != 5)
6951 return false;
6952 MCInst TmpInst;
6953 TmpInst.setOpcode(ARM::t2STR_PRE);
6954 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6955 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6956 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6957 TmpInst.addOperand(MCOperand::CreateImm(-4));
6958 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6959 TmpInst.addOperand(Inst.getOperand(3));
6960 Inst = TmpInst;
6961 return true;
6962 }
Jim Grosbachf8fce712011-08-11 17:35:48 +00006963 case ARM::LDMIA_UPD:
6964 // If this is a load of a single register via a 'pop', then we should use
6965 // a post-indexed LDR instruction instead, per the ARM ARM.
6966 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
6967 Inst.getNumOperands() == 5) {
6968 MCInst TmpInst;
6969 TmpInst.setOpcode(ARM::LDR_POST_IMM);
6970 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6971 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6972 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6973 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
6974 TmpInst.addOperand(MCOperand::CreateImm(4));
6975 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6976 TmpInst.addOperand(Inst.getOperand(3));
6977 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00006978 return true;
Jim Grosbachf8fce712011-08-11 17:35:48 +00006979 }
6980 break;
Jim Grosbachf6713912011-08-11 18:07:11 +00006981 case ARM::STMDB_UPD:
6982 // If this is a store of a single register via a 'push', then we should use
6983 // a pre-indexed STR instruction instead, per the ARM ARM.
6984 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
6985 Inst.getNumOperands() == 5) {
6986 MCInst TmpInst;
6987 TmpInst.setOpcode(ARM::STR_PRE_IMM);
6988 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6989 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6990 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
6991 TmpInst.addOperand(MCOperand::CreateImm(-4));
6992 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6993 TmpInst.addOperand(Inst.getOperand(3));
6994 Inst = TmpInst;
6995 }
6996 break;
Jim Grosbachda847862011-12-05 21:06:26 +00006997 case ARM::t2ADDri12:
6998 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
6999 // mnemonic was used (not "addw"), encoding T3 is preferred.
7000 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7001 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7002 break;
7003 Inst.setOpcode(ARM::t2ADDri);
7004 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7005 break;
7006 case ARM::t2SUBri12:
7007 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7008 // mnemonic was used (not "subw"), encoding T3 is preferred.
7009 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7010 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7011 break;
7012 Inst.setOpcode(ARM::t2SUBri);
7013 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7014 break;
Jim Grosbach89e2aa62011-08-16 23:57:34 +00007015 case ARM::tADDi8:
Jim Grosbach0f3abd82011-08-31 17:07:33 +00007016 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7017 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7018 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7019 // to encoding T1 if <Rd> is omitted."
Jim Grosbachc0164f82012-03-30 16:31:31 +00007020 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbach89e2aa62011-08-16 23:57:34 +00007021 Inst.setOpcode(ARM::tADDi3);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007022 return true;
7023 }
Jim Grosbach89e2aa62011-08-16 23:57:34 +00007024 break;
Jim Grosbachf67e8552011-09-16 22:58:42 +00007025 case ARM::tSUBi8:
7026 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7027 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7028 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7029 // to encoding T1 if <Rd> is omitted."
Jim Grosbachc0164f82012-03-30 16:31:31 +00007030 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachf67e8552011-09-16 22:58:42 +00007031 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007032 return true;
7033 }
Jim Grosbachf67e8552011-09-16 22:58:42 +00007034 break;
Jim Grosbach2d30d942012-03-30 17:20:40 +00007035 case ARM::t2ADDri:
7036 case ARM::t2SUBri: {
7037 // If the destination and first source operand are the same, and
7038 // the flags are compatible with the current IT status, use encoding T2
7039 // instead of T3. For compatibility with the system 'as'. Make sure the
7040 // wide encoding wasn't explicit.
7041 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach8f1148b2012-03-30 18:39:43 +00007042 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbach2d30d942012-03-30 17:20:40 +00007043 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7044 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7045 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7046 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7047 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7048 break;
7049 MCInst TmpInst;
7050 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7051 ARM::tADDi8 : ARM::tSUBi8);
7052 TmpInst.addOperand(Inst.getOperand(0));
7053 TmpInst.addOperand(Inst.getOperand(5));
7054 TmpInst.addOperand(Inst.getOperand(0));
7055 TmpInst.addOperand(Inst.getOperand(2));
7056 TmpInst.addOperand(Inst.getOperand(3));
7057 TmpInst.addOperand(Inst.getOperand(4));
7058 Inst = TmpInst;
7059 return true;
7060 }
Jim Grosbach927b9df2011-12-05 22:16:39 +00007061 case ARM::t2ADDrr: {
7062 // If the destination and first source operand are the same, and
7063 // there's no setting of the flags, use encoding T2 instead of T3.
7064 // Note that this is only for ADD, not SUB. This mirrors the system
7065 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7066 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7067 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbach713c7022011-12-05 22:27:04 +00007068 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7069 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbach927b9df2011-12-05 22:16:39 +00007070 break;
7071 MCInst TmpInst;
7072 TmpInst.setOpcode(ARM::tADDhirr);
7073 TmpInst.addOperand(Inst.getOperand(0));
7074 TmpInst.addOperand(Inst.getOperand(0));
7075 TmpInst.addOperand(Inst.getOperand(2));
7076 TmpInst.addOperand(Inst.getOperand(3));
7077 TmpInst.addOperand(Inst.getOperand(4));
7078 Inst = TmpInst;
7079 return true;
7080 }
Jim Grosbacha9cc08f2012-04-27 23:51:36 +00007081 case ARM::tADDrSP: {
7082 // If the non-SP source operand and the destination operand are not the
7083 // same, we need to use the 32-bit encoding if it's available.
7084 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7085 Inst.setOpcode(ARM::t2ADDrr);
7086 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7087 return true;
7088 }
7089 break;
7090 }
Owen Anderson51f6a7a2011-09-09 21:48:23 +00007091 case ARM::tB:
7092 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbach83ec8772011-11-10 23:42:14 +00007093 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson51f6a7a2011-09-09 21:48:23 +00007094 Inst.setOpcode(ARM::tBcc);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007095 return true;
7096 }
Owen Anderson51f6a7a2011-09-09 21:48:23 +00007097 break;
7098 case ARM::t2B:
7099 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbach83ec8772011-11-10 23:42:14 +00007100 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson51f6a7a2011-09-09 21:48:23 +00007101 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007102 return true;
7103 }
Owen Anderson51f6a7a2011-09-09 21:48:23 +00007104 break;
Jim Grosbachc0755102011-08-31 21:17:31 +00007105 case ARM::t2Bcc:
Jim Grosbacha1109882011-09-02 23:22:08 +00007106 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbach83ec8772011-11-10 23:42:14 +00007107 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbachc0755102011-08-31 21:17:31 +00007108 Inst.setOpcode(ARM::t2B);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007109 return true;
7110 }
Jim Grosbachc0755102011-08-31 21:17:31 +00007111 break;
Jim Grosbach395b4532011-08-17 22:57:40 +00007112 case ARM::tBcc:
7113 // If the conditional is AL, we really want tB.
Jim Grosbach83ec8772011-11-10 23:42:14 +00007114 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbach395b4532011-08-17 22:57:40 +00007115 Inst.setOpcode(ARM::tB);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007116 return true;
7117 }
Jim Grosbach3ce23d32011-08-18 16:08:39 +00007118 break;
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00007119 case ARM::tLDMIA: {
7120 // If the register list contains any high registers, or if the writeback
7121 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7122 // instead if we're in Thumb2. Otherwise, this should have generated
7123 // an error in validateInstruction().
7124 unsigned Rn = Inst.getOperand(0).getReg();
7125 bool hasWritebackToken =
7126 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7127 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7128 bool listContainsBase;
7129 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7130 (!listContainsBase && !hasWritebackToken) ||
7131 (listContainsBase && hasWritebackToken)) {
7132 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7133 assert (isThumbTwo());
7134 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7135 // If we're switching to the updating version, we need to insert
7136 // the writeback tied operand.
7137 if (hasWritebackToken)
7138 Inst.insert(Inst.begin(),
7139 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbach83ec8772011-11-10 23:42:14 +00007140 return true;
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00007141 }
7142 break;
7143 }
Jim Grosbach8213c962011-09-16 20:50:13 +00007144 case ARM::tSTMIA_UPD: {
7145 // If the register list contains any high registers, we need to use
7146 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7147 // should have generated an error in validateInstruction().
7148 unsigned Rn = Inst.getOperand(0).getReg();
7149 bool listContainsBase;
7150 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7151 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7152 assert (isThumbTwo());
7153 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007154 return true;
Jim Grosbach8213c962011-09-16 20:50:13 +00007155 }
7156 break;
7157 }
Jim Grosbach54026372011-11-10 23:17:11 +00007158 case ARM::tPOP: {
7159 bool listContainsBase;
7160 // If the register list contains any high registers, we need to use
7161 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7162 // should have generated an error in validateInstruction().
7163 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbach83ec8772011-11-10 23:42:14 +00007164 return false;
Jim Grosbach54026372011-11-10 23:17:11 +00007165 assert (isThumbTwo());
7166 Inst.setOpcode(ARM::t2LDMIA_UPD);
7167 // Add the base register and writeback operands.
7168 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7169 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbach83ec8772011-11-10 23:42:14 +00007170 return true;
Jim Grosbach54026372011-11-10 23:17:11 +00007171 }
7172 case ARM::tPUSH: {
7173 bool listContainsBase;
7174 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbach83ec8772011-11-10 23:42:14 +00007175 return false;
Jim Grosbach54026372011-11-10 23:17:11 +00007176 assert (isThumbTwo());
7177 Inst.setOpcode(ARM::t2STMDB_UPD);
7178 // Add the base register and writeback operands.
7179 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7180 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbach83ec8772011-11-10 23:42:14 +00007181 return true;
Jim Grosbach54026372011-11-10 23:17:11 +00007182 }
Jim Grosbach1ad60c22011-09-10 00:15:36 +00007183 case ARM::t2MOVi: {
7184 // If we can use the 16-bit encoding and the user didn't explicitly
7185 // request the 32-bit variant, transform it here.
7186 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbachc0164f82012-03-30 16:31:31 +00007187 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbachc2d31642011-09-14 19:12:11 +00007188 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7189 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7190 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbach1ad60c22011-09-10 00:15:36 +00007191 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7192 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7193 // The operands aren't in the same order for tMOVi8...
7194 MCInst TmpInst;
7195 TmpInst.setOpcode(ARM::tMOVi8);
7196 TmpInst.addOperand(Inst.getOperand(0));
7197 TmpInst.addOperand(Inst.getOperand(4));
7198 TmpInst.addOperand(Inst.getOperand(1));
7199 TmpInst.addOperand(Inst.getOperand(2));
7200 TmpInst.addOperand(Inst.getOperand(3));
7201 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00007202 return true;
Jim Grosbach1ad60c22011-09-10 00:15:36 +00007203 }
7204 break;
7205 }
7206 case ARM::t2MOVr: {
7207 // If we can use the 16-bit encoding and the user didn't explicitly
7208 // request the 32-bit variant, transform it here.
7209 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7210 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7211 Inst.getOperand(2).getImm() == ARMCC::AL &&
7212 Inst.getOperand(4).getReg() == ARM::CPSR &&
7213 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7214 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7215 // The operands aren't the same for tMOV[S]r... (no cc_out)
7216 MCInst TmpInst;
7217 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7218 TmpInst.addOperand(Inst.getOperand(0));
7219 TmpInst.addOperand(Inst.getOperand(1));
7220 TmpInst.addOperand(Inst.getOperand(2));
7221 TmpInst.addOperand(Inst.getOperand(3));
7222 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00007223 return true;
Jim Grosbach1ad60c22011-09-10 00:15:36 +00007224 }
7225 break;
7226 }
Jim Grosbach326efe52011-09-19 20:29:33 +00007227 case ARM::t2SXTH:
Jim Grosbach50f1c372011-09-20 00:46:54 +00007228 case ARM::t2SXTB:
7229 case ARM::t2UXTH:
7230 case ARM::t2UXTB: {
Jim Grosbach326efe52011-09-19 20:29:33 +00007231 // If we can use the 16-bit encoding and the user didn't explicitly
7232 // request the 32-bit variant, transform it here.
7233 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7234 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7235 Inst.getOperand(2).getImm() == 0 &&
7236 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7237 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbach50f1c372011-09-20 00:46:54 +00007238 unsigned NewOpc;
7239 switch (Inst.getOpcode()) {
7240 default: llvm_unreachable("Illegal opcode!");
7241 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7242 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7243 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7244 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7245 }
Jim Grosbach326efe52011-09-19 20:29:33 +00007246 // The operands aren't the same for thumb1 (no rotate operand).
7247 MCInst TmpInst;
7248 TmpInst.setOpcode(NewOpc);
7249 TmpInst.addOperand(Inst.getOperand(0));
7250 TmpInst.addOperand(Inst.getOperand(1));
7251 TmpInst.addOperand(Inst.getOperand(3));
7252 TmpInst.addOperand(Inst.getOperand(4));
7253 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00007254 return true;
Jim Grosbach326efe52011-09-19 20:29:33 +00007255 }
7256 break;
7257 }
Jim Grosbach04b5d932011-12-20 00:59:38 +00007258 case ARM::MOVsi: {
7259 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonb56e4112012-04-25 18:00:18 +00007260 // rrx shifts and asr/lsr of #32 is encoded as 0
7261 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7262 return false;
Jim Grosbach04b5d932011-12-20 00:59:38 +00007263 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7264 // Shifting by zero is accepted as a vanilla 'MOVr'
7265 MCInst TmpInst;
7266 TmpInst.setOpcode(ARM::MOVr);
7267 TmpInst.addOperand(Inst.getOperand(0));
7268 TmpInst.addOperand(Inst.getOperand(1));
7269 TmpInst.addOperand(Inst.getOperand(3));
7270 TmpInst.addOperand(Inst.getOperand(4));
7271 TmpInst.addOperand(Inst.getOperand(5));
7272 Inst = TmpInst;
7273 return true;
7274 }
7275 return false;
7276 }
Jim Grosbach8d9550b2011-12-22 18:04:04 +00007277 case ARM::ANDrsi:
7278 case ARM::ORRrsi:
7279 case ARM::EORrsi:
7280 case ARM::BICrsi:
7281 case ARM::SUBrsi:
7282 case ARM::ADDrsi: {
7283 unsigned newOpc;
7284 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7285 if (SOpc == ARM_AM::rrx) return false;
7286 switch (Inst.getOpcode()) {
Craig Topperbc219812012-02-07 02:50:20 +00007287 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach8d9550b2011-12-22 18:04:04 +00007288 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7289 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7290 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7291 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7292 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7293 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7294 }
7295 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton8ed97ef2012-07-09 16:31:14 +00007296 // The exception is for right shifts, where 0 == 32
7297 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7298 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach8d9550b2011-12-22 18:04:04 +00007299 MCInst TmpInst;
7300 TmpInst.setOpcode(newOpc);
7301 TmpInst.addOperand(Inst.getOperand(0));
7302 TmpInst.addOperand(Inst.getOperand(1));
7303 TmpInst.addOperand(Inst.getOperand(2));
7304 TmpInst.addOperand(Inst.getOperand(4));
7305 TmpInst.addOperand(Inst.getOperand(5));
7306 TmpInst.addOperand(Inst.getOperand(6));
7307 Inst = TmpInst;
7308 return true;
7309 }
7310 return false;
7311 }
Jim Grosbach74423e32012-01-25 19:52:01 +00007312 case ARM::ITasm:
Jim Grosbach89df9962011-08-26 21:43:41 +00007313 case ARM::t2IT: {
7314 // The mask bits for all but the first condition are represented as
7315 // the low bit of the condition code value implies 't'. We currently
7316 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Barton4d2f0772012-04-27 08:42:59 +00007317 // of the condition code is zero.
Jim Grosbach89df9962011-08-26 21:43:41 +00007318 MCOperand &MO = Inst.getOperand(1);
7319 unsigned Mask = MO.getImm();
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007320 unsigned OrigMask = Mask;
7321 unsigned TZ = CountTrailingZeros_32(Mask);
Jim Grosbach89df9962011-08-26 21:43:41 +00007322 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach89df9962011-08-26 21:43:41 +00007323 assert(Mask && TZ <= 3 && "illegal IT mask value!");
7324 for (unsigned i = 3; i != TZ; --i)
7325 Mask ^= 1 << i;
Richard Barton4d2f0772012-04-27 08:42:59 +00007326 }
Jim Grosbach89df9962011-08-26 21:43:41 +00007327 MO.setImm(Mask);
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007328
7329 // Set up the IT block state according to the IT instruction we just
7330 // matched.
7331 assert(!inITBlock() && "nested IT blocks?!");
7332 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7333 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7334 ITState.CurPosition = 0;
7335 ITState.FirstCond = true;
Jim Grosbach89df9962011-08-26 21:43:41 +00007336 break;
7337 }
Richard Barton2b6652f2012-07-09 16:12:24 +00007338 case ARM::t2LSLrr:
7339 case ARM::t2LSRrr:
7340 case ARM::t2ASRrr:
7341 case ARM::t2SBCrr:
7342 case ARM::t2RORrr:
7343 case ARM::t2BICrr:
7344 {
Richard Bartonc985e6e2012-07-09 16:14:28 +00007345 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Barton2b6652f2012-07-09 16:12:24 +00007346 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7347 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7348 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton874b8632012-07-09 18:30:56 +00007349 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7350 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Barton2b6652f2012-07-09 16:12:24 +00007351 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7352 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7353 unsigned NewOpc;
7354 switch (Inst.getOpcode()) {
7355 default: llvm_unreachable("unexpected opcode");
7356 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7357 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7358 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7359 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7360 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7361 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7362 }
7363 MCInst TmpInst;
7364 TmpInst.setOpcode(NewOpc);
7365 TmpInst.addOperand(Inst.getOperand(0));
7366 TmpInst.addOperand(Inst.getOperand(5));
7367 TmpInst.addOperand(Inst.getOperand(1));
7368 TmpInst.addOperand(Inst.getOperand(2));
7369 TmpInst.addOperand(Inst.getOperand(3));
7370 TmpInst.addOperand(Inst.getOperand(4));
7371 Inst = TmpInst;
7372 return true;
7373 }
7374 return false;
7375 }
7376 case ARM::t2ANDrr:
7377 case ARM::t2EORrr:
7378 case ARM::t2ADCrr:
7379 case ARM::t2ORRrr:
7380 {
Richard Bartonc985e6e2012-07-09 16:14:28 +00007381 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Barton2b6652f2012-07-09 16:12:24 +00007382 // These instructions are special in that they are commutable, so shorter encodings
7383 // are available more often.
7384 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7385 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7386 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7387 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton874b8632012-07-09 18:30:56 +00007388 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7389 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Barton2b6652f2012-07-09 16:12:24 +00007390 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7391 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7392 unsigned NewOpc;
7393 switch (Inst.getOpcode()) {
7394 default: llvm_unreachable("unexpected opcode");
7395 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7396 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7397 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7398 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7399 }
7400 MCInst TmpInst;
7401 TmpInst.setOpcode(NewOpc);
7402 TmpInst.addOperand(Inst.getOperand(0));
7403 TmpInst.addOperand(Inst.getOperand(5));
7404 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7405 TmpInst.addOperand(Inst.getOperand(1));
7406 TmpInst.addOperand(Inst.getOperand(2));
7407 } else {
7408 TmpInst.addOperand(Inst.getOperand(2));
7409 TmpInst.addOperand(Inst.getOperand(1));
7410 }
7411 TmpInst.addOperand(Inst.getOperand(3));
7412 TmpInst.addOperand(Inst.getOperand(4));
7413 Inst = TmpInst;
7414 return true;
7415 }
7416 return false;
7417 }
Jim Grosbachf8fce712011-08-11 17:35:48 +00007418 }
Jim Grosbach83ec8772011-11-10 23:42:14 +00007419 return false;
Jim Grosbachf8fce712011-08-11 17:35:48 +00007420}
7421
Jim Grosbach47a0d522011-08-16 20:45:50 +00007422unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7423 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7424 // suffix depending on whether they're in an IT block or not.
Jim Grosbach194bd892011-08-16 22:20:01 +00007425 unsigned Opc = Inst.getOpcode();
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00007426 const MCInstrDesc &MCID = getInstDesc(Opc);
Jim Grosbach47a0d522011-08-16 20:45:50 +00007427 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7428 assert(MCID.hasOptionalDef() &&
7429 "optionally flag setting instruction missing optional def operand");
7430 assert(MCID.NumOperands == Inst.getNumOperands() &&
7431 "operand count mismatch!");
7432 // Find the optional-def operand (cc_out).
7433 unsigned OpNo;
7434 for (OpNo = 0;
7435 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7436 ++OpNo)
7437 ;
7438 // If we're parsing Thumb1, reject it completely.
7439 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7440 return Match_MnemonicFail;
7441 // If we're parsing Thumb2, which form is legal depends on whether we're
7442 // in an IT block.
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007443 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7444 !inITBlock())
Jim Grosbach47a0d522011-08-16 20:45:50 +00007445 return Match_RequiresITBlock;
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007446 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7447 inITBlock())
7448 return Match_RequiresNotITBlock;
Jim Grosbach47a0d522011-08-16 20:45:50 +00007449 }
Jim Grosbach194bd892011-08-16 22:20:01 +00007450 // Some high-register supporting Thumb1 encodings only allow both registers
7451 // to be from r0-r7 when in Thumb2.
7452 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7453 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7454 isARMLowRegister(Inst.getOperand(2).getReg()))
7455 return Match_RequiresThumb2;
7456 // Others only require ARMv6 or later.
Jim Grosbach4ec6e882011-08-19 20:46:54 +00007457 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbach194bd892011-08-16 22:20:01 +00007458 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7459 isARMLowRegister(Inst.getOperand(1).getReg()))
7460 return Match_RequiresV6;
Jim Grosbach47a0d522011-08-16 20:45:50 +00007461 return Match_Success;
7462}
7463
Jim Grosbach14ce6fa2012-04-24 22:40:08 +00007464static const char *getSubtargetFeatureName(unsigned Val);
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007465bool ARMAsmParser::
7466MatchAndEmitInstruction(SMLoc IDLoc,
7467 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
7468 MCStreamer &Out) {
7469 MCInst Inst;
Chad Rosier3a86e132012-09-03 02:06:46 +00007470 unsigned Kind;
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007471 unsigned ErrorInfo;
Jim Grosbach19cb7f42011-08-15 23:03:29 +00007472 unsigned MatchResult;
Chad Rosier3a86e132012-09-03 02:06:46 +00007473
Chad Rosierc4d25602012-09-03 03:16:09 +00007474 MatchResult = MatchInstructionImpl(Operands, Kind, Inst, ErrorInfo);
Kevin Enderby193c3ac2010-12-09 19:19:43 +00007475 switch (MatchResult) {
Jim Grosbach19cb7f42011-08-15 23:03:29 +00007476 default: break;
Chris Lattnere73d4f82010-10-28 21:41:58 +00007477 case Match_Success:
Jim Grosbach189610f2011-07-26 18:25:39 +00007478 // Context sensitive operand constraints aren't handled by the matcher,
7479 // so check them here.
Jim Grosbacha1109882011-09-02 23:22:08 +00007480 if (validateInstruction(Inst, Operands)) {
7481 // Still progress the IT block, otherwise one wrong condition causes
7482 // nasty cascading errors.
7483 forwardITPosition();
Jim Grosbach189610f2011-07-26 18:25:39 +00007484 return true;
Jim Grosbacha1109882011-09-02 23:22:08 +00007485 }
Jim Grosbach189610f2011-07-26 18:25:39 +00007486
Jim Grosbachf8fce712011-08-11 17:35:48 +00007487 // Some instructions need post-processing to, for example, tweak which
Jim Grosbach83ec8772011-11-10 23:42:14 +00007488 // encoding is selected. Loop on it while changes happen so the
7489 // individual transformations can chain off each other. E.g.,
7490 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7491 while (processInstruction(Inst, Operands))
7492 ;
Jim Grosbachf8fce712011-08-11 17:35:48 +00007493
Jim Grosbacha1109882011-09-02 23:22:08 +00007494 // Only move forward at the very end so that everything in validate
7495 // and process gets a consistent answer about whether we're in an IT
7496 // block.
7497 forwardITPosition();
7498
Jim Grosbach74423e32012-01-25 19:52:01 +00007499 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7500 // doesn't actually encode.
7501 if (Inst.getOpcode() == ARM::ITasm)
7502 return false;
7503
Jim Grosbach42e6bd32012-01-26 23:20:15 +00007504 Inst.setLoc(IDLoc);
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007505 Out.EmitInstruction(Inst);
7506 return false;
Jim Grosbach14ce6fa2012-04-24 22:40:08 +00007507 case Match_MissingFeature: {
7508 assert(ErrorInfo && "Unknown missing feature!");
7509 // Special case the error message for the very common case where only
7510 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7511 std::string Msg = "instruction requires:";
7512 unsigned Mask = 1;
7513 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7514 if (ErrorInfo & Mask) {
7515 Msg += " ";
7516 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7517 }
7518 Mask <<= 1;
7519 }
7520 return Error(IDLoc, Msg);
7521 }
Chris Lattnere73d4f82010-10-28 21:41:58 +00007522 case Match_InvalidOperand: {
7523 SMLoc ErrorLoc = IDLoc;
7524 if (ErrorInfo != ~0U) {
7525 if (ErrorInfo >= Operands.size())
7526 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach16c74252010-10-29 14:46:02 +00007527
Chris Lattnere73d4f82010-10-28 21:41:58 +00007528 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7529 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7530 }
Jim Grosbach16c74252010-10-29 14:46:02 +00007531
Chris Lattnere73d4f82010-10-28 21:41:58 +00007532 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007533 }
Chris Lattnere73d4f82010-10-28 21:41:58 +00007534 case Match_MnemonicFail:
Benjamin Kramer362a05a2012-04-15 17:04:27 +00007535 return Error(IDLoc, "invalid instruction",
7536 ((ARMOperand*)Operands[0])->getLocRange());
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007537 case Match_RequiresNotITBlock:
7538 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach47a0d522011-08-16 20:45:50 +00007539 case Match_RequiresITBlock:
7540 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbach194bd892011-08-16 22:20:01 +00007541 case Match_RequiresV6:
7542 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7543 case Match_RequiresThumb2:
7544 return Error(IDLoc, "instruction variant requires Thumb2");
Jim Grosbach70c9bf32012-06-22 23:56:48 +00007545 case Match_ImmRange0_15: {
7546 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7547 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7548 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7549 }
Chris Lattnere73d4f82010-10-28 21:41:58 +00007550 }
Jim Grosbach16c74252010-10-29 14:46:02 +00007551
Eric Christopherc223e2b2010-10-29 09:26:59 +00007552 llvm_unreachable("Implement any new match types added!");
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007553}
7554
Jim Grosbach1355cf12011-07-26 17:10:22 +00007555/// parseDirective parses the arm specific directives
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007556bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7557 StringRef IDVal = DirectiveID.getIdentifier();
7558 if (IDVal == ".word")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007559 return parseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007560 else if (IDVal == ".thumb")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007561 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach9a70df92011-12-07 18:04:19 +00007562 else if (IDVal == ".arm")
7563 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007564 else if (IDVal == ".thumb_func")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007565 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007566 else if (IDVal == ".code")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007567 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007568 else if (IDVal == ".syntax")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007569 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbacha39cda72011-12-14 02:16:11 +00007570 else if (IDVal == ".unreq")
7571 return parseDirectiveUnreq(DirectiveID.getLoc());
Jason W Kimd7c9e082011-12-20 17:38:12 +00007572 else if (IDVal == ".arch")
7573 return parseDirectiveArch(DirectiveID.getLoc());
7574 else if (IDVal == ".eabi_attribute")
7575 return parseDirectiveEabiAttr(DirectiveID.getLoc());
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007576 return true;
7577}
7578
Jim Grosbach1355cf12011-07-26 17:10:22 +00007579/// parseDirectiveWord
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007580/// ::= .word [ expression (, expression)* ]
Jim Grosbach1355cf12011-07-26 17:10:22 +00007581bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007582 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7583 for (;;) {
7584 const MCExpr *Value;
7585 if (getParser().ParseExpression(Value))
7586 return true;
7587
Chris Lattneraaec2052010-01-19 19:46:13 +00007588 getParser().getStreamer().EmitValue(Value, Size, 0/*addrspace*/);
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007589
7590 if (getLexer().is(AsmToken::EndOfStatement))
7591 break;
Jim Grosbach16c74252010-10-29 14:46:02 +00007592
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007593 // FIXME: Improve diagnostic.
7594 if (getLexer().isNot(AsmToken::Comma))
7595 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007596 Parser.Lex();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007597 }
7598 }
7599
Sean Callananb9a25b72010-01-19 20:27:46 +00007600 Parser.Lex();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007601 return false;
7602}
7603
Jim Grosbach1355cf12011-07-26 17:10:22 +00007604/// parseDirectiveThumb
Kevin Enderby515d5092009-10-15 20:48:48 +00007605/// ::= .thumb
Jim Grosbach1355cf12011-07-26 17:10:22 +00007606bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Kevin Enderby515d5092009-10-15 20:48:48 +00007607 if (getLexer().isNot(AsmToken::EndOfStatement))
7608 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007609 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007610
Jim Grosbach9a70df92011-12-07 18:04:19 +00007611 if (!isThumb())
7612 SwitchMode();
7613 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7614 return false;
7615}
7616
7617/// parseDirectiveARM
7618/// ::= .arm
7619bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7620 if (getLexer().isNot(AsmToken::EndOfStatement))
7621 return Error(L, "unexpected token in directive");
7622 Parser.Lex();
7623
7624 if (isThumb())
7625 SwitchMode();
7626 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby515d5092009-10-15 20:48:48 +00007627 return false;
7628}
7629
Jim Grosbach1355cf12011-07-26 17:10:22 +00007630/// parseDirectiveThumbFunc
Kevin Enderby515d5092009-10-15 20:48:48 +00007631/// ::= .thumbfunc symbol_name
Jim Grosbach1355cf12011-07-26 17:10:22 +00007632bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Rafael Espindola64695402011-05-16 16:17:21 +00007633 const MCAsmInfo &MAI = getParser().getStreamer().getContext().getAsmInfo();
7634 bool isMachO = MAI.hasSubsectionsViaSymbols();
7635 StringRef Name;
Jim Grosbachde4d8392011-12-21 22:30:16 +00007636 bool needFuncName = true;
Rafael Espindola64695402011-05-16 16:17:21 +00007637
Jim Grosbachde4d8392011-12-21 22:30:16 +00007638 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindola64695402011-05-16 16:17:21 +00007639 // ELF doesn't
7640 if (isMachO) {
7641 const AsmToken &Tok = Parser.getTok();
Jim Grosbachde4d8392011-12-21 22:30:16 +00007642 if (Tok.isNot(AsmToken::EndOfStatement)) {
7643 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7644 return Error(L, "unexpected token in .thumb_func directive");
7645 Name = Tok.getIdentifier();
7646 Parser.Lex(); // Consume the identifier token.
7647 needFuncName = false;
7648 }
Rafael Espindola64695402011-05-16 16:17:21 +00007649 }
7650
Jim Grosbachde4d8392011-12-21 22:30:16 +00007651 if (getLexer().isNot(AsmToken::EndOfStatement))
Kevin Enderby515d5092009-10-15 20:48:48 +00007652 return Error(L, "unexpected token in directive");
Jim Grosbachde4d8392011-12-21 22:30:16 +00007653
7654 // Eat the end of statement and any blank lines that follow.
7655 while (getLexer().is(AsmToken::EndOfStatement))
7656 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007657
Rafael Espindola64695402011-05-16 16:17:21 +00007658 // FIXME: assuming function name will be the line following .thumb_func
Jim Grosbachde4d8392011-12-21 22:30:16 +00007659 // We really should be checking the next symbol definition even if there's
7660 // stuff in between.
7661 if (needFuncName) {
Jim Grosbachd475f862011-11-10 20:48:53 +00007662 Name = Parser.getTok().getIdentifier();
Rafael Espindola64695402011-05-16 16:17:21 +00007663 }
7664
Jim Grosbach642fc9c2010-11-05 22:33:53 +00007665 // Mark symbol as a thumb symbol.
7666 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7667 getParser().getStreamer().EmitThumbFunc(Func);
Kevin Enderby515d5092009-10-15 20:48:48 +00007668 return false;
7669}
7670
Jim Grosbach1355cf12011-07-26 17:10:22 +00007671/// parseDirectiveSyntax
Kevin Enderby515d5092009-10-15 20:48:48 +00007672/// ::= .syntax unified | divided
Jim Grosbach1355cf12011-07-26 17:10:22 +00007673bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan18b83232010-01-19 21:44:56 +00007674 const AsmToken &Tok = Parser.getTok();
Kevin Enderby515d5092009-10-15 20:48:48 +00007675 if (Tok.isNot(AsmToken::Identifier))
7676 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer38e59892010-07-14 22:38:02 +00007677 StringRef Mode = Tok.getString();
Duncan Sands58c86912010-06-29 13:04:35 +00007678 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callananb9a25b72010-01-19 20:27:46 +00007679 Parser.Lex();
Duncan Sands58c86912010-06-29 13:04:35 +00007680 else if (Mode == "divided" || Mode == "DIVIDED")
Kevin Enderby9e56fb12011-01-27 23:22:36 +00007681 return Error(L, "'.syntax divided' arm asssembly not supported");
Kevin Enderby515d5092009-10-15 20:48:48 +00007682 else
7683 return Error(L, "unrecognized syntax mode in .syntax directive");
7684
7685 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan18b83232010-01-19 21:44:56 +00007686 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007687 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007688
7689 // TODO tell the MC streamer the mode
7690 // getParser().getStreamer().Emit???();
7691 return false;
7692}
7693
Jim Grosbach1355cf12011-07-26 17:10:22 +00007694/// parseDirectiveCode
Kevin Enderby515d5092009-10-15 20:48:48 +00007695/// ::= .code 16 | 32
Jim Grosbach1355cf12011-07-26 17:10:22 +00007696bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan18b83232010-01-19 21:44:56 +00007697 const AsmToken &Tok = Parser.getTok();
Kevin Enderby515d5092009-10-15 20:48:48 +00007698 if (Tok.isNot(AsmToken::Integer))
7699 return Error(L, "unexpected token in .code directive");
Sean Callanan18b83232010-01-19 21:44:56 +00007700 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands58c86912010-06-29 13:04:35 +00007701 if (Val == 16)
Sean Callananb9a25b72010-01-19 20:27:46 +00007702 Parser.Lex();
Duncan Sands58c86912010-06-29 13:04:35 +00007703 else if (Val == 32)
Sean Callananb9a25b72010-01-19 20:27:46 +00007704 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007705 else
7706 return Error(L, "invalid operand to .code directive");
7707
7708 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan18b83232010-01-19 21:44:56 +00007709 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007710 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007711
Evan Cheng32869202011-07-08 22:36:29 +00007712 if (Val == 16) {
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_Code16);
Evan Cheng32869202011-07-08 22:36:29 +00007716 } else {
Jim Grosbach98447da2011-09-06 18:46:23 +00007717 if (isThumb())
Evan Chengffc0e732011-07-09 05:47:46 +00007718 SwitchMode();
Jim Grosbach98447da2011-09-06 18:46:23 +00007719 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Chengeb0caa12011-07-08 22:49:55 +00007720 }
Jim Grosbach2a301702010-11-05 22:40:53 +00007721
Kevin Enderby515d5092009-10-15 20:48:48 +00007722 return false;
7723}
7724
Jim Grosbacha39cda72011-12-14 02:16:11 +00007725/// parseDirectiveReq
7726/// ::= name .req registername
7727bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7728 Parser.Lex(); // Eat the '.req' token.
7729 unsigned Reg;
7730 SMLoc SRegLoc, ERegLoc;
7731 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
7732 Parser.EatToEndOfStatement();
7733 return Error(SRegLoc, "register name expected");
7734 }
7735
7736 // Shouldn't be anything else.
7737 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
7738 Parser.EatToEndOfStatement();
7739 return Error(Parser.getTok().getLoc(),
7740 "unexpected input in .req directive.");
7741 }
7742
7743 Parser.Lex(); // Consume the EndOfStatement
7744
7745 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7746 return Error(SRegLoc, "redefinition of '" + Name +
7747 "' does not match original.");
7748
7749 return false;
7750}
7751
7752/// parseDirectiveUneq
7753/// ::= .unreq registername
7754bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7755 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7756 Parser.EatToEndOfStatement();
7757 return Error(L, "unexpected input in .unreq directive.");
7758 }
7759 RegisterReqs.erase(Parser.getTok().getIdentifier());
7760 Parser.Lex(); // Eat the identifier.
7761 return false;
7762}
7763
Jason W Kimd7c9e082011-12-20 17:38:12 +00007764/// parseDirectiveArch
7765/// ::= .arch token
7766bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7767 return true;
7768}
7769
7770/// parseDirectiveEabiAttr
7771/// ::= .eabi_attribute int, int
7772bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7773 return true;
7774}
7775
Sean Callanan90b70972010-04-07 20:29:34 +00007776extern "C" void LLVMInitializeARMAsmLexer();
7777
Kevin Enderby9c41fa82009-10-30 22:55:57 +00007778/// Force static initialization.
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007779extern "C" void LLVMInitializeARMAsmParser() {
Evan Cheng94b95502011-07-26 00:24:13 +00007780 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
7781 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
Sean Callanan90b70972010-04-07 20:29:34 +00007782 LLVMInitializeARMAsmLexer();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007783}
Daniel Dunbar3483aca2010-08-11 05:24:50 +00007784
Chris Lattner0692ee62010-09-06 19:11:01 +00007785#define GET_REGISTER_MATCHER
Craig Topper8030e1a2012-04-25 06:56:34 +00007786#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner0692ee62010-09-06 19:11:01 +00007787#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar3483aca2010-08-11 05:24:50 +00007788#include "ARMGenAsmMatcher.inc"