blob: bc711dc35f08de047f2a5c66db0672fdf043f04a [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");
Tim Northover93c7c442012-09-22 11:18:12 +00004447 // If <ShiftTy> #0, turn it into a no_shift.
4448 if (Imm == 0)
4449 St = ARM_AM::lsl;
4450 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4451 if (Imm == 32)
4452 Imm = 0;
Jim Grosbach7ce05792011-08-03 23:50:40 +00004453 Amount = Imm;
4454 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004455
4456 return false;
4457}
4458
Jim Grosbach9d390362011-10-03 23:38:36 +00004459/// parseFPImm - A floating point immediate expression operand.
4460ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4461parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach51222d12012-01-20 18:09:51 +00004462 // Anything that can accept a floating point constant as an operand
4463 // needs to go through here, as the regular ParseExpression is
4464 // integer only.
4465 //
4466 // This routine still creates a generic Immediate operand, containing
4467 // a bitcast of the 64-bit floating point value. The various operands
4468 // that accept floats can check whether the value is valid for them
4469 // via the standard is*() predicates.
4470
Jim Grosbach9d390362011-10-03 23:38:36 +00004471 SMLoc S = Parser.getTok().getLoc();
4472
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004473 if (Parser.getTok().isNot(AsmToken::Hash) &&
4474 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbach9d390362011-10-03 23:38:36 +00004475 return MatchOperand_NoMatch;
Jim Grosbach0e387b22011-10-17 22:26:03 +00004476
4477 // Disambiguate the VMOV forms that can accept an FP immediate.
4478 // vmov.f32 <sreg>, #imm
4479 // vmov.f64 <dreg>, #imm
4480 // vmov.f32 <dreg>, #imm @ vector f32x2
4481 // vmov.f32 <qreg>, #imm @ vector f32x4
4482 //
4483 // There are also the NEON VMOV instructions which expect an
4484 // integer constant. Make sure we don't try to parse an FPImm
4485 // for these:
4486 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4487 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4488 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4489 TyOp->getToken() != ".f64"))
4490 return MatchOperand_NoMatch;
4491
Jim Grosbach9d390362011-10-03 23:38:36 +00004492 Parser.Lex(); // Eat the '#'.
4493
4494 // Handle negation, as that still comes through as a separate token.
4495 bool isNegative = false;
4496 if (Parser.getTok().is(AsmToken::Minus)) {
4497 isNegative = true;
4498 Parser.Lex();
4499 }
4500 const AsmToken &Tok = Parser.getTok();
Jim Grosbachae69f702012-01-19 02:47:30 +00004501 SMLoc Loc = Tok.getLoc();
Jim Grosbach9d390362011-10-03 23:38:36 +00004502 if (Tok.is(AsmToken::Real)) {
Jim Grosbach51222d12012-01-20 18:09:51 +00004503 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbach9d390362011-10-03 23:38:36 +00004504 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4505 // If we had a '-' in front, toggle the sign bit.
Jim Grosbach51222d12012-01-20 18:09:51 +00004506 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbach9d390362011-10-03 23:38:36 +00004507 Parser.Lex(); // Eat the token.
Jim Grosbach51222d12012-01-20 18:09:51 +00004508 Operands.push_back(ARMOperand::CreateImm(
4509 MCConstantExpr::Create(IntVal, getContext()),
4510 S, Parser.getTok().getLoc()));
Jim Grosbach9d390362011-10-03 23:38:36 +00004511 return MatchOperand_Success;
4512 }
Jim Grosbach51222d12012-01-20 18:09:51 +00004513 // Also handle plain integers. Instructions which allow floating point
4514 // immediates also allow a raw encoded 8-bit value.
Jim Grosbach9d390362011-10-03 23:38:36 +00004515 if (Tok.is(AsmToken::Integer)) {
4516 int64_t Val = Tok.getIntVal();
4517 Parser.Lex(); // Eat the token.
4518 if (Val > 255 || Val < 0) {
Jim Grosbachae69f702012-01-19 02:47:30 +00004519 Error(Loc, "encoded floating point value out of range");
Jim Grosbach9d390362011-10-03 23:38:36 +00004520 return MatchOperand_ParseFail;
4521 }
Jim Grosbach51222d12012-01-20 18:09:51 +00004522 double RealVal = ARM_AM::getFPImmFloat(Val);
4523 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4524 Operands.push_back(ARMOperand::CreateImm(
4525 MCConstantExpr::Create(Val, getContext()), S,
4526 Parser.getTok().getLoc()));
Jim Grosbach9d390362011-10-03 23:38:36 +00004527 return MatchOperand_Success;
4528 }
4529
Jim Grosbachae69f702012-01-19 02:47:30 +00004530 Error(Loc, "invalid floating point immediate");
Jim Grosbach9d390362011-10-03 23:38:36 +00004531 return MatchOperand_ParseFail;
4532}
Jim Grosbach51222d12012-01-20 18:09:51 +00004533
Kevin Enderby9c41fa82009-10-30 22:55:57 +00004534/// Parse a arm instruction operand. For now this parses the operand regardless
4535/// of the mnemonic.
Jim Grosbach1355cf12011-07-26 17:10:22 +00004536bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004537 StringRef Mnemonic) {
Sean Callanan76264762010-04-02 22:27:05 +00004538 SMLoc S, E;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004539
4540 // Check if the current operand has a custom associated parser, if so, try to
4541 // custom parse the operand, or fallback to the general approach.
Jim Grosbachf922c472011-02-12 01:34:40 +00004542 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4543 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004544 return false;
Jim Grosbachf922c472011-02-12 01:34:40 +00004545 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4546 // there was a match, but an error occurred, in which case, just return that
4547 // the operand parsing failed.
4548 if (ResTy == MatchOperand_ParseFail)
4549 return true;
Bruno Cardoso Lopesfafde7f2011-02-07 21:41:25 +00004550
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004551 switch (getLexer().getKind()) {
Bill Wendling146018f2010-11-06 21:42:12 +00004552 default:
4553 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling50d0f582010-11-18 23:43:05 +00004554 return true;
Jim Grosbach19906722011-07-13 18:49:30 +00004555 case AsmToken::Identifier: {
Jim Grosbach1355cf12011-07-26 17:10:22 +00004556 if (!tryParseRegisterWithWriteBack(Operands))
Bill Wendling50d0f582010-11-18 23:43:05 +00004557 return false;
Jim Grosbach0d87ec22011-07-26 20:41:24 +00004558 int Res = tryParseShiftRegister(Operands);
Jim Grosbach19906722011-07-13 18:49:30 +00004559 if (Res == 0) // success
Owen Anderson00828302011-03-18 22:50:18 +00004560 return false;
Jim Grosbach19906722011-07-13 18:49:30 +00004561 else if (Res == -1) // irrecoverable error
4562 return true;
Jim Grosbach3cbe43f2011-12-20 22:26:38 +00004563 // If this is VMRS, check for the apsr_nzcv operand.
Jim Grosbachb84ad4a2012-03-15 21:34:14 +00004564 if (Mnemonic == "vmrs" &&
4565 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
Jim Grosbach5cd5ac62011-10-03 21:12:43 +00004566 S = Parser.getTok().getLoc();
4567 Parser.Lex();
Jim Grosbachb84ad4a2012-03-15 21:34:14 +00004568 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
Jim Grosbach5cd5ac62011-10-03 21:12:43 +00004569 return false;
4570 }
Owen Andersone4e5e2a2011-01-13 21:46:02 +00004571
4572 // Fall though for the Identifier case that is not a register or a
4573 // special name.
Jim Grosbach19906722011-07-13 18:49:30 +00004574 }
Jim Grosbach758a5192011-10-26 21:14:08 +00004575 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderby67b212e2011-01-13 20:32:36 +00004576 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach6284afc2011-11-01 22:38:31 +00004577 case AsmToken::String: // quoted label names.
Kevin Enderby67b212e2011-01-13 20:32:36 +00004578 case AsmToken::Dot: { // . as a branch target
Kevin Enderby515d5092009-10-15 20:48:48 +00004579 // This was not a register so parse other operands that start with an
4580 // identifier (like labels) as expressions and create them as immediates.
4581 const MCExpr *IdVal;
Sean Callanan76264762010-04-02 22:27:05 +00004582 S = Parser.getTok().getLoc();
Kevin Enderby515d5092009-10-15 20:48:48 +00004583 if (getParser().ParseExpression(IdVal))
Bill Wendling50d0f582010-11-18 23:43:05 +00004584 return true;
Sean Callanan76264762010-04-02 22:27:05 +00004585 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling50d0f582010-11-18 23:43:05 +00004586 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4587 return false;
4588 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004589 case AsmToken::LBrac:
Jim Grosbach1355cf12011-07-26 17:10:22 +00004590 return parseMemory(Operands);
Kevin Enderbyd7894f12009-10-09 21:12:28 +00004591 case AsmToken::LCurly:
Jim Grosbach1355cf12011-07-26 17:10:22 +00004592 return parseRegisterList(Operands);
Jim Grosbach8a12e3b2011-12-09 22:25:03 +00004593 case AsmToken::Dollar:
Owen Anderson63553c72011-08-29 17:17:09 +00004594 case AsmToken::Hash: {
Kevin Enderby079469f2009-10-13 23:33:38 +00004595 // #42 -> immediate.
Sean Callanan76264762010-04-02 22:27:05 +00004596 S = Parser.getTok().getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +00004597 Parser.Lex();
Jim Grosbachb8768dc2012-04-16 21:18:46 +00004598
4599 if (Parser.getTok().isNot(AsmToken::Colon)) {
4600 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4601 const MCExpr *ImmVal;
4602 if (getParser().ParseExpression(ImmVal))
4603 return true;
4604 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4605 if (CE) {
4606 int32_t Val = CE->getValue();
4607 if (isNegative && Val == 0)
4608 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4609 }
4610 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4611 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
4612 return false;
Owen Anderson63553c72011-08-29 17:17:09 +00004613 }
Jim Grosbachb8768dc2012-04-16 21:18:46 +00004614 // w/ a ':' after the '#', it's just like a plain ':'.
4615 // FALLTHROUGH
Owen Anderson63553c72011-08-29 17:17:09 +00004616 }
Jason W Kim9081b4b2011-01-11 23:53:41 +00004617 case AsmToken::Colon: {
4618 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng75972122011-01-13 07:58:56 +00004619 // FIXME: Check it's an expression prefix,
4620 // e.g. (FOO - :lower16:BAR) isn't legal.
4621 ARMMCExpr::VariantKind RefKind;
Jim Grosbach1355cf12011-07-26 17:10:22 +00004622 if (parsePrefix(RefKind))
Jason W Kim9081b4b2011-01-11 23:53:41 +00004623 return true;
4624
Evan Cheng75972122011-01-13 07:58:56 +00004625 const MCExpr *SubExprVal;
4626 if (getParser().ParseExpression(SubExprVal))
Jason W Kim9081b4b2011-01-11 23:53:41 +00004627 return true;
4628
Evan Cheng75972122011-01-13 07:58:56 +00004629 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach1f9f5992012-09-21 00:26:53 +00004630 getContext());
Jason W Kim9081b4b2011-01-11 23:53:41 +00004631 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng75972122011-01-13 07:58:56 +00004632 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim9081b4b2011-01-11 23:53:41 +00004633 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00004634 }
Jason W Kim9081b4b2011-01-11 23:53:41 +00004635 }
4636}
4637
Jim Grosbach1355cf12011-07-26 17:10:22 +00004638// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng75972122011-01-13 07:58:56 +00004639// :lower16: and :upper16:.
Jim Grosbach1355cf12011-07-26 17:10:22 +00004640bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng75972122011-01-13 07:58:56 +00004641 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim9081b4b2011-01-11 23:53:41 +00004642
4643 // :lower16: and :upper16: modifiers
Jason W Kim8a8696d2011-01-13 00:27:00 +00004644 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim9081b4b2011-01-11 23:53:41 +00004645 Parser.Lex(); // Eat ':'
4646
4647 if (getLexer().isNot(AsmToken::Identifier)) {
4648 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4649 return true;
4650 }
4651
4652 StringRef IDVal = Parser.getTok().getIdentifier();
4653 if (IDVal == "lower16") {
Evan Cheng75972122011-01-13 07:58:56 +00004654 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim9081b4b2011-01-11 23:53:41 +00004655 } else if (IDVal == "upper16") {
Evan Cheng75972122011-01-13 07:58:56 +00004656 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim9081b4b2011-01-11 23:53:41 +00004657 } else {
4658 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4659 return true;
4660 }
4661 Parser.Lex();
4662
4663 if (getLexer().isNot(AsmToken::Colon)) {
4664 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4665 return true;
4666 }
4667 Parser.Lex(); // Eat the last ':'
4668 return false;
4669}
4670
Daniel Dunbar352e1482011-01-11 15:59:50 +00004671/// \brief Given a mnemonic, split out possible predication code and carry
4672/// setting letters to form a canonical mnemonic and flags.
4673//
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004674// FIXME: Would be nice to autogen this.
Jim Grosbach89df9962011-08-26 21:43:41 +00004675// FIXME: This is a bit of a maze of special cases.
Jim Grosbach1355cf12011-07-26 17:10:22 +00004676StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5f160572011-07-19 20:10:31 +00004677 unsigned &PredicationCode,
4678 bool &CarrySetting,
Jim Grosbach89df9962011-08-26 21:43:41 +00004679 unsigned &ProcessorIMod,
4680 StringRef &ITMask) {
Daniel Dunbar352e1482011-01-11 15:59:50 +00004681 PredicationCode = ARMCC::AL;
4682 CarrySetting = false;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004683 ProcessorIMod = 0;
Daniel Dunbar352e1482011-01-11 15:59:50 +00004684
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004685 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar352e1482011-01-11 15:59:50 +00004686 //
4687 // FIXME: Would be nice to autogen this.
Jim Grosbach5f160572011-07-19 20:10:31 +00004688 if ((Mnemonic == "movs" && isThumb()) ||
4689 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4690 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4691 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4692 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
4693 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4694 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbach68490192011-12-19 19:43:50 +00004695 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
4696 Mnemonic == "fmuls")
Daniel Dunbar352e1482011-01-11 15:59:50 +00004697 return Mnemonic;
Daniel Dunbar5747b132010-08-11 06:37:16 +00004698
Jim Grosbach3f00e312011-07-11 17:09:57 +00004699 // First, split out any predication code. Ignore mnemonics we know aren't
4700 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbachab40f4b2011-07-20 18:20:31 +00004701 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach71725a02011-07-27 21:58:11 +00004702 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach04d55f12011-08-22 23:55:58 +00004703 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbach2f25d9b2011-09-01 18:22:13 +00004704 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbach3f00e312011-07-11 17:09:57 +00004705 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4706 .Case("eq", ARMCC::EQ)
4707 .Case("ne", ARMCC::NE)
4708 .Case("hs", ARMCC::HS)
4709 .Case("cs", ARMCC::HS)
4710 .Case("lo", ARMCC::LO)
4711 .Case("cc", ARMCC::LO)
4712 .Case("mi", ARMCC::MI)
4713 .Case("pl", ARMCC::PL)
4714 .Case("vs", ARMCC::VS)
4715 .Case("vc", ARMCC::VC)
4716 .Case("hi", ARMCC::HI)
4717 .Case("ls", ARMCC::LS)
4718 .Case("ge", ARMCC::GE)
4719 .Case("lt", ARMCC::LT)
4720 .Case("gt", ARMCC::GT)
4721 .Case("le", ARMCC::LE)
4722 .Case("al", ARMCC::AL)
4723 .Default(~0U);
4724 if (CC != ~0U) {
4725 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4726 PredicationCode = CC;
4727 }
Bill Wendling52925b62010-10-29 23:50:21 +00004728 }
Daniel Dunbar345a9a62010-08-11 06:37:20 +00004729
Daniel Dunbar352e1482011-01-11 15:59:50 +00004730 // Next, determine if we have a carry setting bit. We explicitly ignore all
4731 // the instructions we know end in 's'.
4732 if (Mnemonic.endswith("s") &&
Jim Grosbach00f5d982011-08-17 22:49:09 +00004733 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5f160572011-07-19 20:10:31 +00004734 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4735 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4736 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach67ca1ad2011-12-08 00:49:29 +00004737 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach48171e72011-12-10 00:01:02 +00004738 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach9c397892011-12-19 19:02:41 +00004739 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbach6357cae2012-03-15 20:48:18 +00004740 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
Evan Cheng82509e52012-04-11 00:13:00 +00004741 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
Jim Grosbache1cf5902011-07-29 20:26:09 +00004742 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar352e1482011-01-11 15:59:50 +00004743 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4744 CarrySetting = true;
4745 }
4746
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004747 // The "cps" instruction can have a interrupt mode operand which is glued into
4748 // the mnemonic. Check if this is the case, split it and parse the imod op
4749 if (Mnemonic.startswith("cps")) {
4750 // Split out any imod code.
4751 unsigned IMod =
4752 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4753 .Case("ie", ARM_PROC::IE)
4754 .Case("id", ARM_PROC::ID)
4755 .Default(~0U);
4756 if (IMod != ~0U) {
4757 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4758 ProcessorIMod = IMod;
4759 }
4760 }
4761
Jim Grosbach89df9962011-08-26 21:43:41 +00004762 // The "it" instruction has the condition mask on the end of the mnemonic.
4763 if (Mnemonic.startswith("it")) {
4764 ITMask = Mnemonic.slice(2, Mnemonic.size());
4765 Mnemonic = Mnemonic.slice(0, 2);
4766 }
4767
Daniel Dunbar352e1482011-01-11 15:59:50 +00004768 return Mnemonic;
4769}
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004770
4771/// \brief Given a canonical mnemonic, determine if the instruction ever allows
4772/// inclusion of carry set or predication code operands.
4773//
4774// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopesfdcee772011-01-18 20:55:11 +00004775void ARMAsmParser::
Jim Grosbach1355cf12011-07-26 17:10:22 +00004776getMnemonicAcceptInfo(StringRef Mnemonic, bool &CanAcceptCarrySet,
Bruno Cardoso Lopesfdcee772011-01-18 20:55:11 +00004777 bool &CanAcceptPredicationCode) {
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004778 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4779 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbach3443ed52011-09-16 18:05:48 +00004780 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004781 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachd5d0e812011-09-19 23:31:02 +00004782 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004783 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachd5d0e812011-09-19 23:31:02 +00004784 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Cheng82509e52012-04-11 00:13:00 +00004785 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbach3443ed52011-09-16 18:05:48 +00004786 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachd5d0e812011-09-19 23:31:02 +00004787 Mnemonic == "mla" || Mnemonic == "smlal" ||
4788 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004789 CanAcceptCarrySet = true;
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004790 } else
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004791 CanAcceptCarrySet = false;
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004792
Daniel Dunbareb9f3f92011-01-11 19:06:29 +00004793 if (Mnemonic == "cbnz" || Mnemonic == "setend" || Mnemonic == "dmb" ||
4794 Mnemonic == "cps" || Mnemonic == "mcr2" || Mnemonic == "it" ||
4795 Mnemonic == "mcrr2" || Mnemonic == "cbz" || Mnemonic == "cdp2" ||
4796 Mnemonic == "trap" || Mnemonic == "mrc2" || Mnemonic == "mrrc2" ||
Jim Grosbachad2dad92011-09-06 20:27:04 +00004797 Mnemonic == "dsb" || Mnemonic == "isb" || Mnemonic == "setend" ||
4798 (Mnemonic == "clrex" && !isThumb()) ||
Jim Grosbach0780b632011-08-19 23:24:36 +00004799 (Mnemonic == "nop" && isThumbOne()) ||
Jim Grosbach2bd01182011-10-11 21:55:36 +00004800 ((Mnemonic == "pld" || Mnemonic == "pli" || Mnemonic == "pldw" ||
4801 Mnemonic == "ldc2" || Mnemonic == "ldc2l" ||
4802 Mnemonic == "stc2" || Mnemonic == "stc2l") && !isThumb()) ||
Jim Grosbach4af54a42011-08-26 22:21:51 +00004803 ((Mnemonic.startswith("rfe") || Mnemonic.startswith("srs")) &&
4804 !isThumb()) ||
Jim Grosbach1ad60c22011-09-10 00:15:36 +00004805 Mnemonic.startswith("cps") || (Mnemonic == "movs" && isThumbOne())) {
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004806 CanAcceptPredicationCode = false;
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004807 } else
Daniel Dunbar3771dd02011-01-11 15:59:53 +00004808 CanAcceptPredicationCode = true;
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00004809
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004810 if (isThumb()) {
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00004811 if (Mnemonic == "bkpt" || Mnemonic == "mcr" || Mnemonic == "mcrr" ||
Jim Grosbach63b46fa2011-06-30 22:10:46 +00004812 Mnemonic == "mrc" || Mnemonic == "mrrc" || Mnemonic == "cdp")
Bruno Cardoso Lopesfa5bd272011-01-20 16:35:57 +00004813 CanAcceptPredicationCode = false;
Jim Grosbachfb9cffe2011-09-16 16:39:25 +00004814 }
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004815}
4816
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004817bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4818 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004819 // FIXME: This is all horribly hacky. We really need a better way to deal
4820 // with optional operands like this in the matcher table.
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004821
4822 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4823 // another does not. Specifically, the MOVW instruction does not. So we
4824 // special case it here and remove the defaulted (non-setting) cc_out
4825 // operand if that's the instruction we're trying to match.
4826 //
4827 // We do this as post-processing of the explicit operands rather than just
4828 // conditionally adding the cc_out in the first place because we need
4829 // to check the type of the parsed immediate operand.
Owen Anderson8adf6202011-09-14 22:46:14 +00004830 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004831 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4832 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4833 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4834 return true;
Jim Grosbach3912b732011-08-16 21:34:08 +00004835
4836 // Register-register 'add' for thumb does not have a cc_out operand
4837 // when there are only two register operands.
4838 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4839 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4840 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4841 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4842 return true;
Jim Grosbach72f39f82011-08-24 21:22:15 +00004843 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004844 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4845 // have to check the immediate range here since Thumb2 has a variant
4846 // that can handle a different range and has a cc_out operand.
Jim Grosbachf67e8552011-09-16 22:58:42 +00004847 if (((isThumb() && Mnemonic == "add") ||
4848 (isThumbTwo() && Mnemonic == "sub")) &&
4849 Operands.size() == 6 &&
Jim Grosbach72f39f82011-08-24 21:22:15 +00004850 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4851 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4852 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004853 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
Jim Grosbacha23ecc22012-04-10 17:31:55 +00004854 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004855 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach72f39f82011-08-24 21:22:15 +00004856 return true;
Jim Grosbachf67e8552011-09-16 22:58:42 +00004857 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4858 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004859 // selecting via the generic "add" mnemonic, so to know that we
4860 // should remove the cc_out operand, we have to explicitly check that
4861 // it's not one of the other variants. Ugh.
Jim Grosbachf67e8552011-09-16 22:58:42 +00004862 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4863 Operands.size() == 6 &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004864 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4865 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4866 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4867 // Nest conditions rather than one big 'if' statement for readability.
4868 //
4869 // If either register is a high reg, it's either one of the SP
4870 // variants (handled above) or a 32-bit encoding, so we just
Jim Grosbach12a88632012-01-21 00:07:56 +00004871 // check against T3. If the second register is the PC, this is an
4872 // alternate form of ADR, which uses encoding T4, so check for that too.
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004873 if ((!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4874 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg())) &&
Jim Grosbach12a88632012-01-21 00:07:56 +00004875 static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004876 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
4877 return false;
4878 // If both registers are low, we're in an IT block, and the immediate is
4879 // in range, we should use encoding T1 instead, which has a cc_out.
4880 if (inITBlock() &&
Jim Grosbach64944f42011-09-14 21:00:40 +00004881 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004882 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
4883 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
4884 return false;
4885
4886 // Otherwise, we use encoding T4, which does not have a cc_out
4887 // operand.
4888 return true;
4889 }
4890
Jim Grosbach64944f42011-09-14 21:00:40 +00004891 // The thumb2 multiply instruction doesn't have a CCOut register, so
4892 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
4893 // use the 16-bit encoding or not.
4894 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
4895 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4896 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4897 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4898 static_cast<ARMOperand*>(Operands[5])->isReg() &&
4899 // If the registers aren't low regs, the destination reg isn't the
4900 // same as one of the source regs, or the cc_out operand is zero
4901 // outside of an IT block, we have to use the 32-bit encoding, so
4902 // remove the cc_out operand.
4903 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4904 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach1de0bd12011-11-15 19:29:45 +00004905 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach64944f42011-09-14 21:00:40 +00004906 !inITBlock() ||
4907 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
4908 static_cast<ARMOperand*>(Operands[5])->getReg() &&
4909 static_cast<ARMOperand*>(Operands[3])->getReg() !=
4910 static_cast<ARMOperand*>(Operands[4])->getReg())))
4911 return true;
4912
Jim Grosbach7f1ec952011-11-15 19:55:16 +00004913 // Also check the 'mul' syntax variant that doesn't specify an explicit
4914 // destination register.
4915 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
4916 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4917 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4918 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4919 // If the registers aren't low regs or the cc_out operand is zero
4920 // outside of an IT block, we have to use the 32-bit encoding, so
4921 // remove the cc_out operand.
4922 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
4923 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
4924 !inITBlock()))
4925 return true;
4926
Jim Grosbach64944f42011-09-14 21:00:40 +00004927
Jim Grosbach20ed2e72011-09-01 00:28:52 +00004928
Jim Grosbachf69c8042011-08-24 21:42:27 +00004929 // Register-register 'add/sub' for thumb does not have a cc_out operand
4930 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
4931 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
4932 // right, this will result in better diagnostics (which operand is off)
4933 // anyway.
4934 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
4935 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach72f39f82011-08-24 21:22:15 +00004936 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4937 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
Jim Grosbacha23ecc22012-04-10 17:31:55 +00004938 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
4939 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
4940 (Operands.size() == 6 &&
4941 static_cast<ARMOperand*>(Operands[5])->isImm())))
Jim Grosbach72f39f82011-08-24 21:22:15 +00004942 return true;
Jim Grosbach3912b732011-08-16 21:34:08 +00004943
Jim Grosbachd54b4e62011-08-16 21:12:37 +00004944 return false;
4945}
4946
Jim Grosbach7aef99b2011-11-11 23:08:10 +00004947static bool isDataTypeToken(StringRef Tok) {
4948 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
4949 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
4950 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
4951 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
4952 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
4953 Tok == ".f" || Tok == ".d";
4954}
4955
4956// FIXME: This bit should probably be handled via an explicit match class
4957// in the .td files that matches the suffix instead of having it be
4958// a literal string token the way it is now.
4959static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
4960 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
4961}
4962
Jim Grosbach21d7fb82011-12-09 23:34:09 +00004963static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004964/// Parse an arm instruction mnemonic followed by its operands.
4965bool ARMAsmParser::ParseInstruction(StringRef Name, SMLoc NameLoc,
4966 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach21d7fb82011-12-09 23:34:09 +00004967 // Apply mnemonic aliases before doing anything else, as the destination
4968 // mnemnonic may include suffices and we want to handle them normally.
4969 // The generic tblgen'erated code does this later, at the start of
4970 // MatchInstructionImpl(), but that's too late for aliases that include
4971 // any sort of suffix.
4972 unsigned AvailableFeatures = getAvailableFeatures();
4973 applyMnemonicAliases(Name, AvailableFeatures);
4974
Jim Grosbacha39cda72011-12-14 02:16:11 +00004975 // First check for the ARM-specific .req directive.
4976 if (Parser.getTok().is(AsmToken::Identifier) &&
4977 Parser.getTok().getIdentifier() == ".req") {
4978 parseDirectiveReq(Name, NameLoc);
4979 // We always return 'error' for this, as we're done with this
4980 // statement and don't need to match the 'instruction."
4981 return true;
4982 }
4983
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004984 // Create the leading tokens for the mnemonic, split by '.' characters.
4985 size_t Start = 0, Next = Name.find('.');
Jim Grosbachffa32252011-07-19 19:13:28 +00004986 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004987
Daniel Dunbar352e1482011-01-11 15:59:50 +00004988 // Split out the predication code and carry setting flag from the mnemonic.
4989 unsigned PredicationCode;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00004990 unsigned ProcessorIMod;
Daniel Dunbar352e1482011-01-11 15:59:50 +00004991 bool CarrySetting;
Jim Grosbach89df9962011-08-26 21:43:41 +00004992 StringRef ITMask;
Jim Grosbach1355cf12011-07-26 17:10:22 +00004993 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach89df9962011-08-26 21:43:41 +00004994 ProcessorIMod, ITMask);
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00004995
Jim Grosbach0c49ac02011-08-25 17:23:55 +00004996 // In Thumb1, only the branch (B) instruction can be predicated.
4997 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
4998 Parser.EatToEndOfStatement();
4999 return Error(NameLoc, "conditional execution not supported in Thumb1");
5000 }
5001
Jim Grosbachffa32252011-07-19 19:13:28 +00005002 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5003
Jim Grosbach89df9962011-08-26 21:43:41 +00005004 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5005 // is the mask as it will be for the IT encoding if the conditional
5006 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5007 // where the conditional bit0 is zero, the instruction post-processing
5008 // will adjust the mask accordingly.
5009 if (Mnemonic == "it") {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005010 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5011 if (ITMask.size() > 3) {
5012 Parser.EatToEndOfStatement();
5013 return Error(Loc, "too many conditions on IT instruction");
5014 }
Jim Grosbach89df9962011-08-26 21:43:41 +00005015 unsigned Mask = 8;
5016 for (unsigned i = ITMask.size(); i != 0; --i) {
5017 char pos = ITMask[i - 1];
5018 if (pos != 't' && pos != 'e') {
5019 Parser.EatToEndOfStatement();
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005020 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach89df9962011-08-26 21:43:41 +00005021 }
5022 Mask >>= 1;
5023 if (ITMask[i - 1] == 't')
5024 Mask |= 8;
5025 }
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005026 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach89df9962011-08-26 21:43:41 +00005027 }
5028
Jim Grosbachffa32252011-07-19 19:13:28 +00005029 // FIXME: This is all a pretty gross hack. We should automatically handle
5030 // optional operands like this via tblgen.
Bill Wendling9717fa92010-11-21 10:56:05 +00005031
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005032 // Next, add the CCOut and ConditionCode operands, if needed.
5033 //
5034 // For mnemonics which can ever incorporate a carry setting bit or predication
5035 // code, our matching model involves us always generating CCOut and
5036 // ConditionCode operands to match the mnemonic "as written" and then we let
5037 // the matcher deal with finding the right instruction or generating an
5038 // appropriate error.
5039 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Jim Grosbach1355cf12011-07-26 17:10:22 +00005040 getMnemonicAcceptInfo(Mnemonic, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005041
Jim Grosbach33c16a22011-07-14 22:04:21 +00005042 // If we had a carry-set on an instruction that can't do that, issue an
5043 // error.
5044 if (!CanAcceptCarrySet && CarrySetting) {
5045 Parser.EatToEndOfStatement();
Jim Grosbachffa32252011-07-19 19:13:28 +00005046 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach33c16a22011-07-14 22:04:21 +00005047 "' can not set flags, but 's' suffix specified");
5048 }
Jim Grosbachc27d4f92011-07-22 17:44:50 +00005049 // If we had a predication code on an instruction that can't do that, issue an
5050 // error.
5051 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
5052 Parser.EatToEndOfStatement();
5053 return Error(NameLoc, "instruction '" + Mnemonic +
5054 "' is not predicable, but condition code specified");
5055 }
Jim Grosbach33c16a22011-07-14 22:04:21 +00005056
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005057 // Add the carry setting operand, if necessary.
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005058 if (CanAcceptCarrySet) {
5059 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005060 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005061 Loc));
5062 }
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005063
5064 // Add the predication code operand, if necessary.
5065 if (CanAcceptPredicationCode) {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005066 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5067 CarrySetting);
Daniel Dunbar3771dd02011-01-11 15:59:53 +00005068 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005069 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbarbadbd2f2011-01-10 12:24:52 +00005070 }
Daniel Dunbar345a9a62010-08-11 06:37:20 +00005071
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00005072 // Add the processor imod operand, if necessary.
5073 if (ProcessorIMod) {
5074 Operands.push_back(ARMOperand::CreateImm(
5075 MCConstantExpr::Create(ProcessorIMod, getContext()),
5076 NameLoc, NameLoc));
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00005077 }
5078
Daniel Dunbar345a9a62010-08-11 06:37:20 +00005079 // Add the remaining tokens in the mnemonic.
Daniel Dunbar5747b132010-08-11 06:37:16 +00005080 while (Next != StringRef::npos) {
5081 Start = Next;
5082 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00005083 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00005084
Jim Grosbach7aef99b2011-11-11 23:08:10 +00005085 // Some NEON instructions have an optional datatype suffix that is
5086 // completely ignored. Check for that.
5087 if (isDataTypeToken(ExtraToken) &&
5088 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5089 continue;
5090
Jim Grosbach81d2e392011-09-07 16:06:04 +00005091 if (ExtraToken != ".n") {
5092 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5093 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5094 }
Daniel Dunbar5747b132010-08-11 06:37:16 +00005095 }
5096
5097 // Read the remaining operands.
5098 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00005099 // Read the first operand.
Jim Grosbach1355cf12011-07-26 17:10:22 +00005100 if (parseOperand(Operands, Mnemonic)) {
Chris Lattnercbf8a982010-09-11 16:18:25 +00005101 Parser.EatToEndOfStatement();
5102 return true;
5103 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00005104
5105 while (getLexer().is(AsmToken::Comma)) {
Sean Callananb9a25b72010-01-19 20:27:46 +00005106 Parser.Lex(); // Eat the comma.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00005107
5108 // Parse and remember the operand.
Jim Grosbach1355cf12011-07-26 17:10:22 +00005109 if (parseOperand(Operands, Mnemonic)) {
Chris Lattnercbf8a982010-09-11 16:18:25 +00005110 Parser.EatToEndOfStatement();
5111 return true;
5112 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +00005113 }
5114 }
Jim Grosbach16c74252010-10-29 14:46:02 +00005115
Chris Lattnercbf8a982010-09-11 16:18:25 +00005116 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbach186ffac2011-10-07 18:27:04 +00005117 SMLoc Loc = getLexer().getLoc();
Chris Lattnercbf8a982010-09-11 16:18:25 +00005118 Parser.EatToEndOfStatement();
Jim Grosbach186ffac2011-10-07 18:27:04 +00005119 return Error(Loc, "unexpected token in argument list");
Chris Lattnercbf8a982010-09-11 16:18:25 +00005120 }
Bill Wendling146018f2010-11-06 21:42:12 +00005121
Chris Lattner34e53142010-09-08 05:10:46 +00005122 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbachffa32252011-07-19 19:13:28 +00005123
Jim Grosbachd54b4e62011-08-16 21:12:37 +00005124 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5125 // do and don't have a cc_out optional-def operand. With some spot-checks
5126 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach20ed2e72011-09-01 00:28:52 +00005127 // parse and adjust accordingly before actually matching. We shouldn't ever
5128 // try to remove a cc_out operand that was explicitly set on the the
5129 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5130 // table driven matcher doesn't fit well with the ARM instruction set.
5131 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbachffa32252011-07-19 19:13:28 +00005132 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5133 Operands.erase(Operands.begin() + 1);
5134 delete Op;
5135 }
5136
Jim Grosbachcf121c32011-07-28 21:57:55 +00005137 // ARM mode 'blx' need special handling, as the register operand version
5138 // is predicable, but the label operand version is not. So, we can't rely
5139 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach21ff17c2011-10-07 23:24:09 +00005140 // a k_CondCode operand in the list. If we're trying to match the label
5141 // version, remove the k_CondCode operand here.
Jim Grosbachcf121c32011-07-28 21:57:55 +00005142 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5143 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5144 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5145 Operands.erase(Operands.begin() + 1);
5146 delete Op;
5147 }
Jim Grosbach857e1a72011-08-11 23:51:13 +00005148
5149 // The vector-compare-to-zero instructions have a literal token "#0" at
5150 // the end that comes to here as an immediate operand. Convert it to a
5151 // token to play nicely with the matcher.
5152 if ((Mnemonic == "vceq" || Mnemonic == "vcge" || Mnemonic == "vcgt" ||
5153 Mnemonic == "vcle" || Mnemonic == "vclt") && Operands.size() == 6 &&
5154 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5155 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5156 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5157 if (CE && CE->getValue() == 0) {
5158 Operands.erase(Operands.begin() + 5);
5159 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5160 delete Op;
5161 }
5162 }
Jim Grosbach68259142011-10-03 22:30:24 +00005163 // VCMP{E} does the same thing, but with a different operand count.
5164 if ((Mnemonic == "vcmp" || Mnemonic == "vcmpe") && Operands.size() == 5 &&
5165 static_cast<ARMOperand*>(Operands[4])->isImm()) {
5166 ARMOperand *Op = static_cast<ARMOperand*>(Operands[4]);
5167 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
5168 if (CE && CE->getValue() == 0) {
5169 Operands.erase(Operands.begin() + 4);
5170 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5171 delete Op;
5172 }
5173 }
Jim Grosbach934755a2011-08-22 23:47:13 +00005174 // Similarly, the Thumb1 "RSB" instruction has a literal "#0" on the
Jim Grosbach55b02f22011-12-13 20:50:38 +00005175 // end. Convert it to a token here. Take care not to convert those
5176 // that should hit the Thumb2 encoding.
Jim Grosbach934755a2011-08-22 23:47:13 +00005177 if (Mnemonic == "rsb" && isThumb() && Operands.size() == 6 &&
Jim Grosbach55b02f22011-12-13 20:50:38 +00005178 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5179 static_cast<ARMOperand*>(Operands[4])->isReg() &&
Jim Grosbach934755a2011-08-22 23:47:13 +00005180 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5181 ARMOperand *Op = static_cast<ARMOperand*>(Operands[5]);
5182 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
Jim Grosbach55b02f22011-12-13 20:50:38 +00005183 if (CE && CE->getValue() == 0 &&
5184 (isThumbOne() ||
Jim Grosbachd7ea73a2011-12-13 21:06:41 +00005185 // The cc_out operand matches the IT block.
5186 ((inITBlock() != CarrySetting) &&
5187 // Neither register operand is a high register.
Jim Grosbach55b02f22011-12-13 20:50:38 +00005188 (isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbachd7ea73a2011-12-13 21:06:41 +00005189 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()))))){
Jim Grosbach934755a2011-08-22 23:47:13 +00005190 Operands.erase(Operands.begin() + 5);
5191 Operands.push_back(ARMOperand::CreateToken("#0", Op->getStartLoc()));
5192 delete Op;
5193 }
5194 }
5195
Chris Lattner98986712010-01-14 22:21:20 +00005196 return false;
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00005197}
5198
Jim Grosbach189610f2011-07-26 18:25:39 +00005199// Validate context-sensitive operand constraints.
Jim Grosbachaa875f82011-08-23 18:13:04 +00005200
5201// return 'true' if register list contains non-low GPR registers,
5202// 'false' otherwise. If Reg is in the register list or is HiReg, set
5203// 'containsReg' to true.
5204static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5205 unsigned HiReg, bool &containsReg) {
5206 containsReg = false;
5207 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5208 unsigned OpReg = Inst.getOperand(i).getReg();
5209 if (OpReg == Reg)
5210 containsReg = true;
5211 // Anything other than a low register isn't legal here.
5212 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5213 return true;
5214 }
5215 return false;
5216}
5217
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005218// Check if the specified regisgter is in the register list of the inst,
5219// starting at the indicated operand number.
5220static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5221 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5222 unsigned OpReg = Inst.getOperand(i).getReg();
5223 if (OpReg == Reg)
5224 return true;
5225 }
5226 return false;
5227}
5228
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005229// FIXME: We would really prefer to have MCInstrInfo (the wrapper around
5230// the ARMInsts array) instead. Getting that here requires awkward
5231// API changes, though. Better way?
5232namespace llvm {
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00005233extern const MCInstrDesc ARMInsts[];
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005234}
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00005235static const MCInstrDesc &getInstDesc(unsigned Opcode) {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005236 return ARMInsts[Opcode];
5237}
5238
Jim Grosbach189610f2011-07-26 18:25:39 +00005239// FIXME: We would really like to be able to tablegen'erate this.
5240bool ARMAsmParser::
5241validateInstruction(MCInst &Inst,
5242 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00005243 const MCInstrDesc &MCID = getInstDesc(Inst.getOpcode());
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005244 SMLoc Loc = Operands[0]->getStartLoc();
5245 // Check the IT block state first.
Jim Grosbach74423e32012-01-25 19:52:01 +00005246 // NOTE: BKPT instruction has the interesting property of being
5247 // allowed in IT blocks, but not being predicable. It just always
Owen Andersonb6b7f512011-09-13 17:59:19 +00005248 // executes.
Jim Grosbach74423e32012-01-25 19:52:01 +00005249 if (inITBlock() && Inst.getOpcode() != ARM::tBKPT &&
5250 Inst.getOpcode() != ARM::BKPT) {
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005251 unsigned bit = 1;
5252 if (ITState.FirstCond)
5253 ITState.FirstCond = false;
5254 else
Jim Grosbacha1109882011-09-02 23:22:08 +00005255 bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005256 // The instruction must be predicable.
5257 if (!MCID.isPredicable())
5258 return Error(Loc, "instructions in IT block must be predicable");
5259 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
5260 unsigned ITCond = bit ? ITState.Cond :
5261 ARMCC::getOppositeCondition(ITState.Cond);
5262 if (Cond != ITCond) {
5263 // Find the condition code Operand to get its SMLoc information.
5264 SMLoc CondLoc;
5265 for (unsigned i = 1; i < Operands.size(); ++i)
5266 if (static_cast<ARMOperand*>(Operands[i])->isCondCode())
5267 CondLoc = Operands[i]->getStartLoc();
5268 return Error(CondLoc, "incorrect condition in IT block; got '" +
5269 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5270 "', but expected '" +
5271 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5272 }
Jim Grosbachc9a9b442011-08-31 18:29:05 +00005273 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005274 } else if (isThumbTwo() && MCID.isPredicable() &&
5275 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Owen Anderson51f6a7a2011-09-09 21:48:23 +00005276 ARMCC::AL && Inst.getOpcode() != ARM::tB &&
5277 Inst.getOpcode() != ARM::t2B)
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00005278 return Error(Loc, "predicated instructions must be in IT block");
5279
Jim Grosbach189610f2011-07-26 18:25:39 +00005280 switch (Inst.getOpcode()) {
Jim Grosbach2fd2b872011-08-10 20:29:19 +00005281 case ARM::LDRD:
5282 case ARM::LDRD_PRE:
5283 case ARM::LDRD_POST:
Jim Grosbach189610f2011-07-26 18:25:39 +00005284 case ARM::LDREXD: {
5285 // Rt2 must be Rt + 1.
Eric Christopherdf1c6372012-08-09 22:10:21 +00005286 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5287 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbach189610f2011-07-26 18:25:39 +00005288 if (Rt2 != Rt + 1)
5289 return Error(Operands[3]->getStartLoc(),
5290 "destination operands must be sequential");
5291 return false;
5292 }
Jim Grosbach14605d12011-08-11 20:28:23 +00005293 case ARM::STRD: {
5294 // Rt2 must be Rt + 1.
Eric Christopherdf1c6372012-08-09 22:10:21 +00005295 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5296 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbach14605d12011-08-11 20:28:23 +00005297 if (Rt2 != Rt + 1)
5298 return Error(Operands[3]->getStartLoc(),
5299 "source operands must be sequential");
5300 return false;
5301 }
Jim Grosbach53642c52011-08-10 20:49:18 +00005302 case ARM::STRD_PRE:
5303 case ARM::STRD_POST:
Jim Grosbach189610f2011-07-26 18:25:39 +00005304 case ARM::STREXD: {
5305 // Rt2 must be Rt + 1.
Eric Christopherdf1c6372012-08-09 22:10:21 +00005306 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5307 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbach189610f2011-07-26 18:25:39 +00005308 if (Rt2 != Rt + 1)
Jim Grosbach14605d12011-08-11 20:28:23 +00005309 return Error(Operands[3]->getStartLoc(),
Jim Grosbach189610f2011-07-26 18:25:39 +00005310 "source operands must be sequential");
5311 return false;
5312 }
Jim Grosbachfb8989e2011-07-27 21:09:25 +00005313 case ARM::SBFX:
5314 case ARM::UBFX: {
5315 // width must be in range [1, 32-lsb]
5316 unsigned lsb = Inst.getOperand(2).getImm();
5317 unsigned widthm1 = Inst.getOperand(3).getImm();
5318 if (widthm1 >= 32 - lsb)
5319 return Error(Operands[5]->getStartLoc(),
5320 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach00c9a512011-08-16 21:42:31 +00005321 return false;
Jim Grosbachfb8989e2011-07-27 21:09:25 +00005322 }
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005323 case ARM::tLDMIA: {
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005324 // If we're parsing Thumb2, the .w variant is available and handles
5325 // most cases that are normally illegal for a Thumb1 LDM
5326 // instruction. We'll make the transformation in processInstruction()
5327 // if necessary.
5328 //
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005329 // Thumb LDM instructions are writeback iff the base register is not
5330 // in the register list.
5331 unsigned Rn = Inst.getOperand(0).getReg();
Jim Grosbach7260c6a2011-08-22 23:01:07 +00005332 bool hasWritebackToken =
5333 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5334 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Jim Grosbachaa875f82011-08-23 18:13:04 +00005335 bool listContainsBase;
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005336 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) && !isThumbTwo())
Jim Grosbachaa875f82011-08-23 18:13:04 +00005337 return Error(Operands[3 + hasWritebackToken]->getStartLoc(),
5338 "registers must be in range r0-r7");
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005339 // If we should have writeback, then there should be a '!' token.
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005340 if (!listContainsBase && !hasWritebackToken && !isThumbTwo())
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005341 return Error(Operands[2]->getStartLoc(),
5342 "writeback operator '!' expected");
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005343 // If we should not have writeback, there must not be a '!'. This is
5344 // true even for the 32-bit wide encodings.
Jim Grosbachaa875f82011-08-23 18:13:04 +00005345 if (listContainsBase && hasWritebackToken)
Jim Grosbach7260c6a2011-08-22 23:01:07 +00005346 return Error(Operands[3]->getStartLoc(),
5347 "writeback operator '!' not allowed when base register "
5348 "in register list");
Jim Grosbach93b3eff2011-08-18 21:50:53 +00005349
5350 break;
5351 }
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00005352 case ARM::t2LDMIA_UPD: {
5353 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
5354 return Error(Operands[4]->getStartLoc(),
5355 "writeback operator '!' not allowed when base register "
5356 "in register list");
5357 break;
5358 }
Chad Rosier64b34442012-08-30 23:20:38 +00005359 case ARM::tMUL: {
5360 // The second source operand must be the same register as the destination
5361 // operand.
Chad Rosier429af6f2012-08-31 17:24:10 +00005362 //
5363 // In this case, we must directly check the parsed operands because the
5364 // cvtThumbMultiply() function is written in such a way that it guarantees
5365 // this first statement is always true for the new Inst. Essentially, the
5366 // destination is unconditionally copied into the second source operand
5367 // without checking to see if it matches what we actually parsed.
Chad Rosier64b34442012-08-30 23:20:38 +00005368 if (Operands.size() == 6 &&
5369 (((ARMOperand*)Operands[3])->getReg() !=
5370 ((ARMOperand*)Operands[5])->getReg()) &&
5371 (((ARMOperand*)Operands[3])->getReg() !=
5372 ((ARMOperand*)Operands[4])->getReg())) {
Chad Rosierfafa2832012-08-30 23:22:05 +00005373 return Error(Operands[3]->getStartLoc(),
5374 "destination register must match source register");
Chad Rosier64b34442012-08-30 23:20:38 +00005375 }
5376 break;
5377 }
Jim Grosbach54026372011-11-10 23:17:11 +00005378 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5379 // so only issue a diagnostic for thumb1. The instructions will be
5380 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach6dcafc02011-08-22 23:17:34 +00005381 case ARM::tPOP: {
Jim Grosbachaa875f82011-08-23 18:13:04 +00005382 bool listContainsBase;
Jim Grosbach54026372011-11-10 23:17:11 +00005383 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase) &&
5384 !isThumbTwo())
Jim Grosbachaa875f82011-08-23 18:13:04 +00005385 return Error(Operands[2]->getStartLoc(),
5386 "registers must be in range r0-r7 or pc");
Jim Grosbach6dcafc02011-08-22 23:17:34 +00005387 break;
5388 }
5389 case ARM::tPUSH: {
Jim Grosbachaa875f82011-08-23 18:13:04 +00005390 bool listContainsBase;
Jim Grosbach54026372011-11-10 23:17:11 +00005391 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase) &&
5392 !isThumbTwo())
Jim Grosbachaa875f82011-08-23 18:13:04 +00005393 return Error(Operands[2]->getStartLoc(),
5394 "registers must be in range r0-r7 or lr");
Jim Grosbach6dcafc02011-08-22 23:17:34 +00005395 break;
5396 }
Jim Grosbach1e84f192011-08-23 18:15:37 +00005397 case ARM::tSTMIA_UPD: {
5398 bool listContainsBase;
Jim Grosbach8213c962011-09-16 20:50:13 +00005399 if (checkLowRegisterList(Inst, 4, 0, 0, listContainsBase) && !isThumbTwo())
Jim Grosbach1e84f192011-08-23 18:15:37 +00005400 return Error(Operands[4]->getStartLoc(),
5401 "registers must be in range r0-r7");
5402 break;
5403 }
Jim Grosbacha9cc08f2012-04-27 23:51:36 +00005404 case ARM::tADDrSP: {
5405 // If the non-SP source operand and the destination operand are not the
5406 // same, we need thumb2 (for the wide encoding), or we have an error.
5407 if (!isThumbTwo() &&
5408 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5409 return Error(Operands[4]->getStartLoc(),
5410 "source register must be the same as destination");
5411 }
5412 break;
5413 }
Jim Grosbach189610f2011-07-26 18:25:39 +00005414 }
5415
5416 return false;
5417}
5418
Jim Grosbachd7433e22012-01-23 23:45:44 +00005419static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach84defb52011-12-02 22:34:51 +00005420 switch(Opc) {
Craig Topperbc219812012-02-07 02:50:20 +00005421 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005422 // VST1LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005423 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5424 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5425 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5426 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5427 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5428 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5429 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5430 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5431 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005432
5433 // VST2LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005434 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5435 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5436 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5437 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5438 case ARM::VST2LNqWB_fixed_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::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5441 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5442 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5443 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5444 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach5b484312011-12-20 20:46:29 +00005445
Jim Grosbach7945ead2012-01-24 00:43:12 +00005446 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5447 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5448 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5449 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5450 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005451
Jim Grosbach4adb1822012-01-24 00:07:41 +00005452 // VST3LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005453 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5454 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5455 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5456 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5457 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5458 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5459 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5460 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5461 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5462 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5463 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5464 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5465 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5466 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5467 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbach4adb1822012-01-24 00:07:41 +00005468
Jim Grosbachd7433e22012-01-23 23:45:44 +00005469 // VST3
Jim Grosbach7945ead2012-01-24 00:43:12 +00005470 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5471 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5472 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5473 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5474 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5475 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5476 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5477 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5478 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5479 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5480 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5481 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5482 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5483 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5484 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5485 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5486 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5487 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbach539aab72012-01-24 00:58:13 +00005488
Jim Grosbach88a54de2012-01-24 18:53:13 +00005489 // VST4LN
5490 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5491 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5492 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5493 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5494 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5495 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5496 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5497 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5498 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5499 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5500 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5501 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5502 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5503 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5504 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5505
Jim Grosbach539aab72012-01-24 00:58:13 +00005506 // VST4
5507 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5508 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5509 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5510 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5511 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5512 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5513 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5514 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5515 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5516 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5517 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5518 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5519 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5520 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5521 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5522 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5523 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5524 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbach84defb52011-12-02 22:34:51 +00005525 }
5526}
5527
Jim Grosbachd7433e22012-01-23 23:45:44 +00005528static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach7636bf62011-12-02 00:35:16 +00005529 switch(Opc) {
Craig Topperbc219812012-02-07 02:50:20 +00005530 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005531 // VLD1LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005532 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5533 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5534 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5535 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5536 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5537 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5538 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5539 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5540 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005541
5542 // VLD2LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005543 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5544 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5545 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5546 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5547 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5548 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5549 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5550 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5551 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5552 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5553 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5554 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5555 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5556 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5557 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbach3a678af2012-01-23 21:53:26 +00005558
Jim Grosbach5e59f7e2012-01-24 23:47:04 +00005559 // VLD3DUP
5560 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5561 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5562 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5563 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5564 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5565 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5566 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5567 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5568 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5569 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5570 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5571 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5572 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5573 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5574 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5575 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5576 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5577 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5578
Jim Grosbach3a678af2012-01-23 21:53:26 +00005579 // VLD3LN
Jim Grosbach7945ead2012-01-24 00:43:12 +00005580 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5581 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5582 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5583 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5584 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5585 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5586 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5587 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5588 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5589 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5590 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5591 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5592 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5593 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5594 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachc387fc62012-01-23 23:20:46 +00005595
5596 // VLD3
Jim Grosbach7945ead2012-01-24 00:43:12 +00005597 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5598 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5599 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5600 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5601 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5602 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5603 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5604 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5605 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5606 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5607 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5608 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5609 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5610 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5611 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5612 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5613 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5614 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbach8abe7e32012-01-24 00:43:17 +00005615
Jim Grosbache983a132012-01-24 18:37:25 +00005616 // VLD4LN
5617 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5618 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5619 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5620 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5621 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5622 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5623 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5624 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5625 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5626 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5627 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5628 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5629 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5630 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5631 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5632
Jim Grosbacha57a36a2012-01-25 00:01:08 +00005633 // VLD4DUP
5634 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5635 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5636 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5637 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5638 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5639 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5640 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5641 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5642 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5643 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5644 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5645 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5646 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5647 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5648 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5649 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5650 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5651 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5652
Jim Grosbach8abe7e32012-01-24 00:43:17 +00005653 // VLD4
5654 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5655 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5656 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5657 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5658 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5659 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5660 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5661 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5662 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5663 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5664 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5665 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5666 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5667 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5668 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5669 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5670 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5671 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach7636bf62011-12-02 00:35:16 +00005672 }
5673}
5674
Jim Grosbach83ec8772011-11-10 23:42:14 +00005675bool ARMAsmParser::
Jim Grosbachf8fce712011-08-11 17:35:48 +00005676processInstruction(MCInst &Inst,
5677 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5678 switch (Inst.getOpcode()) {
Jim Grosbach0b4c6732012-01-18 22:46:46 +00005679 // Aliases for alternate PC+imm syntax of LDR instructions.
5680 case ARM::t2LDRpcrel:
5681 Inst.setOpcode(ARM::t2LDRpci);
5682 return true;
5683 case ARM::t2LDRBpcrel:
5684 Inst.setOpcode(ARM::t2LDRBpci);
5685 return true;
5686 case ARM::t2LDRHpcrel:
5687 Inst.setOpcode(ARM::t2LDRHpci);
5688 return true;
5689 case ARM::t2LDRSBpcrel:
5690 Inst.setOpcode(ARM::t2LDRSBpci);
5691 return true;
5692 case ARM::t2LDRSHpcrel:
5693 Inst.setOpcode(ARM::t2LDRSHpci);
5694 return true;
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005695 // Handle NEON VST complex aliases.
Jim Grosbach8b31f952012-01-23 19:39:08 +00005696 case ARM::VST1LNdWB_register_Asm_8:
5697 case ARM::VST1LNdWB_register_Asm_16:
5698 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbach84defb52011-12-02 22:34:51 +00005699 MCInst TmpInst;
5700 // Shuffle the operands around so the lane index operand is in the
5701 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005702 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005703 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach84defb52011-12-02 22:34:51 +00005704 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5705 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5706 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5707 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5708 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5709 TmpInst.addOperand(Inst.getOperand(1)); // lane
5710 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5711 TmpInst.addOperand(Inst.getOperand(6));
5712 Inst = TmpInst;
5713 return true;
5714 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005715
Jim Grosbach8b31f952012-01-23 19:39:08 +00005716 case ARM::VST2LNdWB_register_Asm_8:
5717 case ARM::VST2LNdWB_register_Asm_16:
5718 case ARM::VST2LNdWB_register_Asm_32:
5719 case ARM::VST2LNqWB_register_Asm_16:
5720 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005721 MCInst TmpInst;
5722 // Shuffle the operands around so the lane index operand is in the
5723 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005724 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005725 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005726 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5727 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5728 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5729 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5730 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach5b484312011-12-20 20:46:29 +00005731 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5732 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005733 TmpInst.addOperand(Inst.getOperand(1)); // lane
5734 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5735 TmpInst.addOperand(Inst.getOperand(6));
5736 Inst = TmpInst;
5737 return true;
5738 }
Jim Grosbach4adb1822012-01-24 00:07:41 +00005739
5740 case ARM::VST3LNdWB_register_Asm_8:
5741 case ARM::VST3LNdWB_register_Asm_16:
5742 case ARM::VST3LNdWB_register_Asm_32:
5743 case ARM::VST3LNqWB_register_Asm_16:
5744 case ARM::VST3LNqWB_register_Asm_32: {
5745 MCInst TmpInst;
5746 // Shuffle the operands around so the lane index operand is in the
5747 // right place.
5748 unsigned Spacing;
5749 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5750 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5751 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5752 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5753 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5754 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5755 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5756 Spacing));
5757 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5758 Spacing * 2));
5759 TmpInst.addOperand(Inst.getOperand(1)); // lane
5760 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5761 TmpInst.addOperand(Inst.getOperand(6));
5762 Inst = TmpInst;
5763 return true;
5764 }
5765
Jim Grosbach88a54de2012-01-24 18:53:13 +00005766 case ARM::VST4LNdWB_register_Asm_8:
5767 case ARM::VST4LNdWB_register_Asm_16:
5768 case ARM::VST4LNdWB_register_Asm_32:
5769 case ARM::VST4LNqWB_register_Asm_16:
5770 case ARM::VST4LNqWB_register_Asm_32: {
5771 MCInst TmpInst;
5772 // Shuffle the operands around so the lane index operand is in the
5773 // right place.
5774 unsigned Spacing;
5775 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5776 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5777 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5778 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5779 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5780 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5781 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5782 Spacing));
5783 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5784 Spacing * 2));
5785 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5786 Spacing * 3));
5787 TmpInst.addOperand(Inst.getOperand(1)); // lane
5788 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5789 TmpInst.addOperand(Inst.getOperand(6));
5790 Inst = TmpInst;
5791 return true;
5792 }
5793
Jim Grosbach8b31f952012-01-23 19:39:08 +00005794 case ARM::VST1LNdWB_fixed_Asm_8:
5795 case ARM::VST1LNdWB_fixed_Asm_16:
5796 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbach84defb52011-12-02 22:34:51 +00005797 MCInst TmpInst;
5798 // Shuffle the operands around so the lane index operand is in the
5799 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005800 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005801 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach84defb52011-12-02 22:34:51 +00005802 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5803 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5804 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5805 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5806 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5807 TmpInst.addOperand(Inst.getOperand(1)); // lane
5808 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5809 TmpInst.addOperand(Inst.getOperand(5));
5810 Inst = TmpInst;
5811 return true;
5812 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005813
Jim Grosbach8b31f952012-01-23 19:39:08 +00005814 case ARM::VST2LNdWB_fixed_Asm_8:
5815 case ARM::VST2LNdWB_fixed_Asm_16:
5816 case ARM::VST2LNdWB_fixed_Asm_32:
5817 case ARM::VST2LNqWB_fixed_Asm_16:
5818 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005819 MCInst TmpInst;
5820 // Shuffle the operands around so the lane index operand is in the
5821 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005822 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005823 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005824 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5825 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5826 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5827 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5828 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach5b484312011-12-20 20:46:29 +00005829 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5830 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005831 TmpInst.addOperand(Inst.getOperand(1)); // lane
5832 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5833 TmpInst.addOperand(Inst.getOperand(5));
5834 Inst = TmpInst;
5835 return true;
5836 }
Jim Grosbach4adb1822012-01-24 00:07:41 +00005837
5838 case ARM::VST3LNdWB_fixed_Asm_8:
5839 case ARM::VST3LNdWB_fixed_Asm_16:
5840 case ARM::VST3LNdWB_fixed_Asm_32:
5841 case ARM::VST3LNqWB_fixed_Asm_16:
5842 case ARM::VST3LNqWB_fixed_Asm_32: {
5843 MCInst TmpInst;
5844 // Shuffle the operands around so the lane index operand is in the
5845 // right place.
5846 unsigned Spacing;
5847 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5848 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5849 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5850 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5851 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5852 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5853 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5854 Spacing));
5855 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5856 Spacing * 2));
5857 TmpInst.addOperand(Inst.getOperand(1)); // lane
5858 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5859 TmpInst.addOperand(Inst.getOperand(5));
5860 Inst = TmpInst;
5861 return true;
5862 }
5863
Jim Grosbach88a54de2012-01-24 18:53:13 +00005864 case ARM::VST4LNdWB_fixed_Asm_8:
5865 case ARM::VST4LNdWB_fixed_Asm_16:
5866 case ARM::VST4LNdWB_fixed_Asm_32:
5867 case ARM::VST4LNqWB_fixed_Asm_16:
5868 case ARM::VST4LNqWB_fixed_Asm_32: {
5869 MCInst TmpInst;
5870 // Shuffle the operands around so the lane index operand is in the
5871 // right place.
5872 unsigned Spacing;
5873 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5874 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5875 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5876 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5877 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
5878 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5879 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5880 Spacing));
5881 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5882 Spacing * 2));
5883 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5884 Spacing * 3));
5885 TmpInst.addOperand(Inst.getOperand(1)); // lane
5886 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5887 TmpInst.addOperand(Inst.getOperand(5));
5888 Inst = TmpInst;
5889 return true;
5890 }
5891
Jim Grosbach8b31f952012-01-23 19:39:08 +00005892 case ARM::VST1LNdAsm_8:
5893 case ARM::VST1LNdAsm_16:
5894 case ARM::VST1LNdAsm_32: {
Jim Grosbach84defb52011-12-02 22:34:51 +00005895 MCInst TmpInst;
5896 // Shuffle the operands around so the lane index operand is in the
5897 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005898 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005899 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach84defb52011-12-02 22:34:51 +00005900 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5901 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5902 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5903 TmpInst.addOperand(Inst.getOperand(1)); // lane
5904 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5905 TmpInst.addOperand(Inst.getOperand(5));
5906 Inst = TmpInst;
5907 return true;
5908 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005909
Jim Grosbach8b31f952012-01-23 19:39:08 +00005910 case ARM::VST2LNdAsm_8:
5911 case ARM::VST2LNdAsm_16:
5912 case ARM::VST2LNdAsm_32:
5913 case ARM::VST2LNqAsm_16:
5914 case ARM::VST2LNqAsm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005915 MCInst TmpInst;
5916 // Shuffle the operands around so the lane index operand is in the
5917 // right place.
Jim Grosbach5b484312011-12-20 20:46:29 +00005918 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005919 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005920 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5921 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5922 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach5b484312011-12-20 20:46:29 +00005923 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5924 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005925 TmpInst.addOperand(Inst.getOperand(1)); // lane
5926 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5927 TmpInst.addOperand(Inst.getOperand(5));
5928 Inst = TmpInst;
5929 return true;
5930 }
Jim Grosbach4adb1822012-01-24 00:07:41 +00005931
5932 case ARM::VST3LNdAsm_8:
5933 case ARM::VST3LNdAsm_16:
5934 case ARM::VST3LNdAsm_32:
5935 case ARM::VST3LNqAsm_16:
5936 case ARM::VST3LNqAsm_32: {
5937 MCInst TmpInst;
5938 // Shuffle the operands around so the lane index operand is in the
5939 // right place.
5940 unsigned Spacing;
5941 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5942 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5943 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5944 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5945 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5946 Spacing));
5947 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5948 Spacing * 2));
5949 TmpInst.addOperand(Inst.getOperand(1)); // lane
5950 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5951 TmpInst.addOperand(Inst.getOperand(5));
5952 Inst = TmpInst;
5953 return true;
5954 }
5955
Jim Grosbach88a54de2012-01-24 18:53:13 +00005956 case ARM::VST4LNdAsm_8:
5957 case ARM::VST4LNdAsm_16:
5958 case ARM::VST4LNdAsm_32:
5959 case ARM::VST4LNqAsm_16:
5960 case ARM::VST4LNqAsm_32: {
5961 MCInst TmpInst;
5962 // Shuffle the operands around so the lane index operand is in the
5963 // right place.
5964 unsigned Spacing;
5965 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
5966 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5967 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5968 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5969 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5970 Spacing));
5971 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5972 Spacing * 2));
5973 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
5974 Spacing * 3));
5975 TmpInst.addOperand(Inst.getOperand(1)); // lane
5976 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
5977 TmpInst.addOperand(Inst.getOperand(5));
5978 Inst = TmpInst;
5979 return true;
5980 }
5981
Jim Grosbach9b1b3902011-12-14 23:25:46 +00005982 // Handle NEON VLD complex aliases.
Jim Grosbach8b31f952012-01-23 19:39:08 +00005983 case ARM::VLD1LNdWB_register_Asm_8:
5984 case ARM::VLD1LNdWB_register_Asm_16:
5985 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbach872eedb2011-12-02 22:01:52 +00005986 MCInst TmpInst;
5987 // Shuffle the operands around so the lane index operand is in the
5988 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00005989 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00005990 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach872eedb2011-12-02 22:01:52 +00005991 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5992 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5993 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5994 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5995 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5996 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
5997 TmpInst.addOperand(Inst.getOperand(1)); // lane
5998 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
5999 TmpInst.addOperand(Inst.getOperand(6));
6000 Inst = TmpInst;
6001 return true;
6002 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006003
Jim Grosbach8b31f952012-01-23 19:39:08 +00006004 case ARM::VLD2LNdWB_register_Asm_8:
6005 case ARM::VLD2LNdWB_register_Asm_16:
6006 case ARM::VLD2LNdWB_register_Asm_32:
6007 case ARM::VLD2LNqWB_register_Asm_16:
6008 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006009 MCInst TmpInst;
6010 // Shuffle the operands around so the lane index operand is in the
6011 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006012 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006013 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006014 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006015 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6016 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006017 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6018 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6019 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6020 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6021 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006022 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6023 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006024 TmpInst.addOperand(Inst.getOperand(1)); // lane
6025 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6026 TmpInst.addOperand(Inst.getOperand(6));
6027 Inst = TmpInst;
6028 return true;
6029 }
6030
Jim Grosbach3a678af2012-01-23 21:53:26 +00006031 case ARM::VLD3LNdWB_register_Asm_8:
6032 case ARM::VLD3LNdWB_register_Asm_16:
6033 case ARM::VLD3LNdWB_register_Asm_32:
6034 case ARM::VLD3LNqWB_register_Asm_16:
6035 case ARM::VLD3LNqWB_register_Asm_32: {
6036 MCInst TmpInst;
6037 // Shuffle the operands around so the lane index operand is in the
6038 // right place.
6039 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006040 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006041 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6042 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6043 Spacing));
6044 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006045 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006046 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6047 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6048 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6049 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6050 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6051 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6052 Spacing));
6053 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006054 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006055 TmpInst.addOperand(Inst.getOperand(1)); // lane
6056 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6057 TmpInst.addOperand(Inst.getOperand(6));
6058 Inst = TmpInst;
6059 return true;
6060 }
6061
Jim Grosbache983a132012-01-24 18:37:25 +00006062 case ARM::VLD4LNdWB_register_Asm_8:
6063 case ARM::VLD4LNdWB_register_Asm_16:
6064 case ARM::VLD4LNdWB_register_Asm_32:
6065 case ARM::VLD4LNqWB_register_Asm_16:
6066 case ARM::VLD4LNqWB_register_Asm_32: {
6067 MCInst TmpInst;
6068 // Shuffle the operands around so the lane index operand is in the
6069 // right place.
6070 unsigned Spacing;
6071 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6072 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6073 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6074 Spacing));
6075 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6076 Spacing * 2));
6077 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6078 Spacing * 3));
6079 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6080 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6081 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6082 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6083 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6084 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6085 Spacing));
6086 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6087 Spacing * 2));
6088 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6089 Spacing * 3));
6090 TmpInst.addOperand(Inst.getOperand(1)); // lane
6091 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6092 TmpInst.addOperand(Inst.getOperand(6));
6093 Inst = TmpInst;
6094 return true;
6095 }
6096
Jim Grosbach8b31f952012-01-23 19:39:08 +00006097 case ARM::VLD1LNdWB_fixed_Asm_8:
6098 case ARM::VLD1LNdWB_fixed_Asm_16:
6099 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbach872eedb2011-12-02 22:01:52 +00006100 MCInst TmpInst;
6101 // Shuffle the operands around so the lane index operand is in the
6102 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006103 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006104 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach872eedb2011-12-02 22:01:52 +00006105 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6106 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6107 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6108 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6109 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6110 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6111 TmpInst.addOperand(Inst.getOperand(1)); // lane
6112 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6113 TmpInst.addOperand(Inst.getOperand(5));
6114 Inst = TmpInst;
6115 return true;
6116 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006117
Jim Grosbach8b31f952012-01-23 19:39:08 +00006118 case ARM::VLD2LNdWB_fixed_Asm_8:
6119 case ARM::VLD2LNdWB_fixed_Asm_16:
6120 case ARM::VLD2LNdWB_fixed_Asm_32:
6121 case ARM::VLD2LNqWB_fixed_Asm_16:
6122 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006123 MCInst TmpInst;
6124 // Shuffle the operands around so the lane index operand is in the
6125 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006126 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006127 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006128 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006129 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6130 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006131 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6132 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6133 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6134 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6135 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006136 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6137 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006138 TmpInst.addOperand(Inst.getOperand(1)); // lane
6139 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6140 TmpInst.addOperand(Inst.getOperand(5));
6141 Inst = TmpInst;
6142 return true;
6143 }
6144
Jim Grosbach3a678af2012-01-23 21:53:26 +00006145 case ARM::VLD3LNdWB_fixed_Asm_8:
6146 case ARM::VLD3LNdWB_fixed_Asm_16:
6147 case ARM::VLD3LNdWB_fixed_Asm_32:
6148 case ARM::VLD3LNqWB_fixed_Asm_16:
6149 case ARM::VLD3LNqWB_fixed_Asm_32: {
6150 MCInst TmpInst;
6151 // Shuffle the operands around so the lane index operand is in the
6152 // right place.
6153 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006154 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006155 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6156 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6157 Spacing));
6158 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006159 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006160 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6161 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6162 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6163 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6164 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6165 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6166 Spacing));
6167 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006168 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006169 TmpInst.addOperand(Inst.getOperand(1)); // lane
6170 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6171 TmpInst.addOperand(Inst.getOperand(5));
6172 Inst = TmpInst;
6173 return true;
6174 }
6175
Jim Grosbache983a132012-01-24 18:37:25 +00006176 case ARM::VLD4LNdWB_fixed_Asm_8:
6177 case ARM::VLD4LNdWB_fixed_Asm_16:
6178 case ARM::VLD4LNdWB_fixed_Asm_32:
6179 case ARM::VLD4LNqWB_fixed_Asm_16:
6180 case ARM::VLD4LNqWB_fixed_Asm_32: {
6181 MCInst TmpInst;
6182 // Shuffle the operands around so the lane index operand is in the
6183 // right place.
6184 unsigned Spacing;
6185 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6186 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6187 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6188 Spacing));
6189 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6190 Spacing * 2));
6191 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6192 Spacing * 3));
6193 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6194 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6195 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6196 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6197 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6198 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6199 Spacing));
6200 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6201 Spacing * 2));
6202 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6203 Spacing * 3));
6204 TmpInst.addOperand(Inst.getOperand(1)); // lane
6205 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6206 TmpInst.addOperand(Inst.getOperand(5));
6207 Inst = TmpInst;
6208 return true;
6209 }
6210
Jim Grosbach8b31f952012-01-23 19:39:08 +00006211 case ARM::VLD1LNdAsm_8:
6212 case ARM::VLD1LNdAsm_16:
6213 case ARM::VLD1LNdAsm_32: {
Jim Grosbach7636bf62011-12-02 00:35:16 +00006214 MCInst TmpInst;
6215 // Shuffle the operands around so the lane index operand is in the
6216 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006217 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006218 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach7636bf62011-12-02 00:35:16 +00006219 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6220 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6221 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6222 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6223 TmpInst.addOperand(Inst.getOperand(1)); // lane
6224 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6225 TmpInst.addOperand(Inst.getOperand(5));
6226 Inst = TmpInst;
6227 return true;
6228 }
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006229
Jim Grosbach8b31f952012-01-23 19:39:08 +00006230 case ARM::VLD2LNdAsm_8:
6231 case ARM::VLD2LNdAsm_16:
6232 case ARM::VLD2LNdAsm_32:
6233 case ARM::VLD2LNqAsm_16:
6234 case ARM::VLD2LNqAsm_32: {
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006235 MCInst TmpInst;
6236 // Shuffle the operands around so the lane index operand is in the
6237 // right place.
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006238 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006239 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006240 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006241 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6242 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006243 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6244 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6245 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach95fad1c2011-12-20 19:21:26 +00006246 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6247 Spacing));
Jim Grosbach9b1b3902011-12-14 23:25:46 +00006248 TmpInst.addOperand(Inst.getOperand(1)); // lane
6249 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6250 TmpInst.addOperand(Inst.getOperand(5));
6251 Inst = TmpInst;
6252 return true;
6253 }
Jim Grosbach3a678af2012-01-23 21:53:26 +00006254
6255 case ARM::VLD3LNdAsm_8:
6256 case ARM::VLD3LNdAsm_16:
6257 case ARM::VLD3LNdAsm_32:
6258 case ARM::VLD3LNqAsm_16:
6259 case ARM::VLD3LNqAsm_32: {
6260 MCInst TmpInst;
6261 // Shuffle the operands around so the lane index operand is in the
6262 // right place.
6263 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006264 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006265 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6266 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6267 Spacing));
6268 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006269 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006270 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6271 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6272 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6273 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6274 Spacing));
6275 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachc387fc62012-01-23 23:20:46 +00006276 Spacing * 2));
Jim Grosbach3a678af2012-01-23 21:53:26 +00006277 TmpInst.addOperand(Inst.getOperand(1)); // lane
6278 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6279 TmpInst.addOperand(Inst.getOperand(5));
6280 Inst = TmpInst;
6281 return true;
6282 }
6283
Jim Grosbache983a132012-01-24 18:37:25 +00006284 case ARM::VLD4LNdAsm_8:
6285 case ARM::VLD4LNdAsm_16:
6286 case ARM::VLD4LNdAsm_32:
6287 case ARM::VLD4LNqAsm_16:
6288 case ARM::VLD4LNqAsm_32: {
6289 MCInst TmpInst;
6290 // Shuffle the operands around so the lane index operand is in the
6291 // right place.
6292 unsigned Spacing;
6293 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6294 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6295 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6296 Spacing));
6297 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6298 Spacing * 2));
6299 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6300 Spacing * 3));
6301 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6302 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6303 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6304 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6305 Spacing));
6306 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6307 Spacing * 2));
6308 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6309 Spacing * 3));
6310 TmpInst.addOperand(Inst.getOperand(1)); // lane
6311 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6312 TmpInst.addOperand(Inst.getOperand(5));
6313 Inst = TmpInst;
6314 return true;
6315 }
6316
Jim Grosbach5e59f7e2012-01-24 23:47:04 +00006317 // VLD3DUP single 3-element structure to all lanes instructions.
6318 case ARM::VLD3DUPdAsm_8:
6319 case ARM::VLD3DUPdAsm_16:
6320 case ARM::VLD3DUPdAsm_32:
6321 case ARM::VLD3DUPqAsm_8:
6322 case ARM::VLD3DUPqAsm_16:
6323 case ARM::VLD3DUPqAsm_32: {
6324 MCInst TmpInst;
6325 unsigned Spacing;
6326 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6327 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6328 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6329 Spacing));
6330 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6331 Spacing * 2));
6332 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6333 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6334 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6335 TmpInst.addOperand(Inst.getOperand(4));
6336 Inst = TmpInst;
6337 return true;
6338 }
6339
6340 case ARM::VLD3DUPdWB_fixed_Asm_8:
6341 case ARM::VLD3DUPdWB_fixed_Asm_16:
6342 case ARM::VLD3DUPdWB_fixed_Asm_32:
6343 case ARM::VLD3DUPqWB_fixed_Asm_8:
6344 case ARM::VLD3DUPqWB_fixed_Asm_16:
6345 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6346 MCInst TmpInst;
6347 unsigned Spacing;
6348 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6349 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6350 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6351 Spacing));
6352 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6353 Spacing * 2));
6354 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6355 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6356 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6357 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6358 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6359 TmpInst.addOperand(Inst.getOperand(4));
6360 Inst = TmpInst;
6361 return true;
6362 }
6363
6364 case ARM::VLD3DUPdWB_register_Asm_8:
6365 case ARM::VLD3DUPdWB_register_Asm_16:
6366 case ARM::VLD3DUPdWB_register_Asm_32:
6367 case ARM::VLD3DUPqWB_register_Asm_8:
6368 case ARM::VLD3DUPqWB_register_Asm_16:
6369 case ARM::VLD3DUPqWB_register_Asm_32: {
6370 MCInst TmpInst;
6371 unsigned Spacing;
6372 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6373 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6374 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6375 Spacing));
6376 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6377 Spacing * 2));
6378 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6379 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6380 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6381 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6382 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6383 TmpInst.addOperand(Inst.getOperand(5));
6384 Inst = TmpInst;
6385 return true;
6386 }
6387
Jim Grosbachc387fc62012-01-23 23:20:46 +00006388 // VLD3 multiple 3-element structure instructions.
6389 case ARM::VLD3dAsm_8:
6390 case ARM::VLD3dAsm_16:
6391 case ARM::VLD3dAsm_32:
6392 case ARM::VLD3qAsm_8:
6393 case ARM::VLD3qAsm_16:
6394 case ARM::VLD3qAsm_32: {
6395 MCInst TmpInst;
6396 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006397 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachc387fc62012-01-23 23:20:46 +00006398 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6399 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6400 Spacing));
6401 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6402 Spacing * 2));
6403 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6404 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6405 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6406 TmpInst.addOperand(Inst.getOperand(4));
6407 Inst = TmpInst;
6408 return true;
6409 }
6410
6411 case ARM::VLD3dWB_fixed_Asm_8:
6412 case ARM::VLD3dWB_fixed_Asm_16:
6413 case ARM::VLD3dWB_fixed_Asm_32:
6414 case ARM::VLD3qWB_fixed_Asm_8:
6415 case ARM::VLD3qWB_fixed_Asm_16:
6416 case ARM::VLD3qWB_fixed_Asm_32: {
6417 MCInst TmpInst;
6418 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006419 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachc387fc62012-01-23 23:20:46 +00006420 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6421 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6422 Spacing));
6423 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6424 Spacing * 2));
6425 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6426 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6427 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6428 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6429 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6430 TmpInst.addOperand(Inst.getOperand(4));
6431 Inst = TmpInst;
6432 return true;
6433 }
6434
6435 case ARM::VLD3dWB_register_Asm_8:
6436 case ARM::VLD3dWB_register_Asm_16:
6437 case ARM::VLD3dWB_register_Asm_32:
6438 case ARM::VLD3qWB_register_Asm_8:
6439 case ARM::VLD3qWB_register_Asm_16:
6440 case ARM::VLD3qWB_register_Asm_32: {
6441 MCInst TmpInst;
6442 unsigned Spacing;
Jim Grosbachd7433e22012-01-23 23:45:44 +00006443 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachc387fc62012-01-23 23:20:46 +00006444 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6445 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6446 Spacing));
6447 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6448 Spacing * 2));
6449 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6450 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6451 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6452 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6453 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6454 TmpInst.addOperand(Inst.getOperand(5));
6455 Inst = TmpInst;
6456 return true;
6457 }
6458
Jim Grosbacha57a36a2012-01-25 00:01:08 +00006459 // VLD4DUP single 3-element structure to all lanes instructions.
6460 case ARM::VLD4DUPdAsm_8:
6461 case ARM::VLD4DUPdAsm_16:
6462 case ARM::VLD4DUPdAsm_32:
6463 case ARM::VLD4DUPqAsm_8:
6464 case ARM::VLD4DUPqAsm_16:
6465 case ARM::VLD4DUPqAsm_32: {
6466 MCInst TmpInst;
6467 unsigned Spacing;
6468 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6469 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6470 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6471 Spacing));
6472 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6473 Spacing * 2));
6474 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6475 Spacing * 3));
6476 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6477 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6478 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6479 TmpInst.addOperand(Inst.getOperand(4));
6480 Inst = TmpInst;
6481 return true;
6482 }
6483
6484 case ARM::VLD4DUPdWB_fixed_Asm_8:
6485 case ARM::VLD4DUPdWB_fixed_Asm_16:
6486 case ARM::VLD4DUPdWB_fixed_Asm_32:
6487 case ARM::VLD4DUPqWB_fixed_Asm_8:
6488 case ARM::VLD4DUPqWB_fixed_Asm_16:
6489 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6490 MCInst TmpInst;
6491 unsigned Spacing;
6492 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6493 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6494 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6495 Spacing));
6496 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6497 Spacing * 2));
6498 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6499 Spacing * 3));
6500 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6501 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6502 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6503 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6504 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6505 TmpInst.addOperand(Inst.getOperand(4));
6506 Inst = TmpInst;
6507 return true;
6508 }
6509
6510 case ARM::VLD4DUPdWB_register_Asm_8:
6511 case ARM::VLD4DUPdWB_register_Asm_16:
6512 case ARM::VLD4DUPdWB_register_Asm_32:
6513 case ARM::VLD4DUPqWB_register_Asm_8:
6514 case ARM::VLD4DUPqWB_register_Asm_16:
6515 case ARM::VLD4DUPqWB_register_Asm_32: {
6516 MCInst TmpInst;
6517 unsigned Spacing;
6518 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6519 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6520 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6521 Spacing));
6522 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6523 Spacing * 2));
6524 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6525 Spacing * 3));
6526 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6527 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6528 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6529 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6530 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6531 TmpInst.addOperand(Inst.getOperand(5));
6532 Inst = TmpInst;
6533 return true;
6534 }
6535
6536 // VLD4 multiple 4-element structure instructions.
Jim Grosbach8abe7e32012-01-24 00:43:17 +00006537 case ARM::VLD4dAsm_8:
6538 case ARM::VLD4dAsm_16:
6539 case ARM::VLD4dAsm_32:
6540 case ARM::VLD4qAsm_8:
6541 case ARM::VLD4qAsm_16:
6542 case ARM::VLD4qAsm_32: {
6543 MCInst TmpInst;
6544 unsigned Spacing;
6545 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6546 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6547 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6548 Spacing));
6549 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6550 Spacing * 2));
6551 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6552 Spacing * 3));
6553 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6554 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6555 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6556 TmpInst.addOperand(Inst.getOperand(4));
6557 Inst = TmpInst;
6558 return true;
6559 }
6560
6561 case ARM::VLD4dWB_fixed_Asm_8:
6562 case ARM::VLD4dWB_fixed_Asm_16:
6563 case ARM::VLD4dWB_fixed_Asm_32:
6564 case ARM::VLD4qWB_fixed_Asm_8:
6565 case ARM::VLD4qWB_fixed_Asm_16:
6566 case ARM::VLD4qWB_fixed_Asm_32: {
6567 MCInst TmpInst;
6568 unsigned Spacing;
6569 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6570 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6571 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6572 Spacing));
6573 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6574 Spacing * 2));
6575 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6576 Spacing * 3));
6577 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6578 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6579 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6580 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6581 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6582 TmpInst.addOperand(Inst.getOperand(4));
6583 Inst = TmpInst;
6584 return true;
6585 }
6586
6587 case ARM::VLD4dWB_register_Asm_8:
6588 case ARM::VLD4dWB_register_Asm_16:
6589 case ARM::VLD4dWB_register_Asm_32:
6590 case ARM::VLD4qWB_register_Asm_8:
6591 case ARM::VLD4qWB_register_Asm_16:
6592 case ARM::VLD4qWB_register_Asm_32: {
6593 MCInst TmpInst;
6594 unsigned Spacing;
6595 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6596 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6597 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6598 Spacing));
6599 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6600 Spacing * 2));
6601 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6602 Spacing * 3));
6603 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6604 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6605 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6606 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6607 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6608 TmpInst.addOperand(Inst.getOperand(5));
6609 Inst = TmpInst;
6610 return true;
6611 }
6612
Jim Grosbachd7433e22012-01-23 23:45:44 +00006613 // VST3 multiple 3-element structure instructions.
6614 case ARM::VST3dAsm_8:
6615 case ARM::VST3dAsm_16:
6616 case ARM::VST3dAsm_32:
6617 case ARM::VST3qAsm_8:
6618 case ARM::VST3qAsm_16:
6619 case ARM::VST3qAsm_32: {
6620 MCInst TmpInst;
6621 unsigned Spacing;
6622 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6623 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6624 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6625 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6626 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6627 Spacing));
6628 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6629 Spacing * 2));
6630 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6631 TmpInst.addOperand(Inst.getOperand(4));
6632 Inst = TmpInst;
6633 return true;
6634 }
6635
6636 case ARM::VST3dWB_fixed_Asm_8:
6637 case ARM::VST3dWB_fixed_Asm_16:
6638 case ARM::VST3dWB_fixed_Asm_32:
6639 case ARM::VST3qWB_fixed_Asm_8:
6640 case ARM::VST3qWB_fixed_Asm_16:
6641 case ARM::VST3qWB_fixed_Asm_32: {
6642 MCInst TmpInst;
6643 unsigned Spacing;
6644 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6645 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6646 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6647 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6648 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6649 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6650 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6651 Spacing));
6652 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6653 Spacing * 2));
6654 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6655 TmpInst.addOperand(Inst.getOperand(4));
6656 Inst = TmpInst;
6657 return true;
6658 }
6659
6660 case ARM::VST3dWB_register_Asm_8:
6661 case ARM::VST3dWB_register_Asm_16:
6662 case ARM::VST3dWB_register_Asm_32:
6663 case ARM::VST3qWB_register_Asm_8:
6664 case ARM::VST3qWB_register_Asm_16:
6665 case ARM::VST3qWB_register_Asm_32: {
6666 MCInst TmpInst;
6667 unsigned Spacing;
6668 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6669 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6670 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6671 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6672 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6673 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6674 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6675 Spacing));
6676 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6677 Spacing * 2));
6678 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6679 TmpInst.addOperand(Inst.getOperand(5));
6680 Inst = TmpInst;
6681 return true;
6682 }
6683
Jim Grosbach539aab72012-01-24 00:58:13 +00006684 // VST4 multiple 3-element structure instructions.
6685 case ARM::VST4dAsm_8:
6686 case ARM::VST4dAsm_16:
6687 case ARM::VST4dAsm_32:
6688 case ARM::VST4qAsm_8:
6689 case ARM::VST4qAsm_16:
6690 case ARM::VST4qAsm_32: {
6691 MCInst TmpInst;
6692 unsigned Spacing;
6693 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6694 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6695 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6696 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6697 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6698 Spacing));
6699 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6700 Spacing * 2));
6701 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6702 Spacing * 3));
6703 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6704 TmpInst.addOperand(Inst.getOperand(4));
6705 Inst = TmpInst;
6706 return true;
6707 }
6708
6709 case ARM::VST4dWB_fixed_Asm_8:
6710 case ARM::VST4dWB_fixed_Asm_16:
6711 case ARM::VST4dWB_fixed_Asm_32:
6712 case ARM::VST4qWB_fixed_Asm_8:
6713 case ARM::VST4qWB_fixed_Asm_16:
6714 case ARM::VST4qWB_fixed_Asm_32: {
6715 MCInst TmpInst;
6716 unsigned Spacing;
6717 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6718 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6719 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6720 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6721 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6722 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6723 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6724 Spacing));
6725 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6726 Spacing * 2));
6727 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6728 Spacing * 3));
6729 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6730 TmpInst.addOperand(Inst.getOperand(4));
6731 Inst = TmpInst;
6732 return true;
6733 }
6734
6735 case ARM::VST4dWB_register_Asm_8:
6736 case ARM::VST4dWB_register_Asm_16:
6737 case ARM::VST4dWB_register_Asm_32:
6738 case ARM::VST4qWB_register_Asm_8:
6739 case ARM::VST4qWB_register_Asm_16:
6740 case ARM::VST4qWB_register_Asm_32: {
6741 MCInst TmpInst;
6742 unsigned Spacing;
6743 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6744 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6745 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6746 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6747 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6748 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6749 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6750 Spacing));
6751 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6752 Spacing * 2));
6753 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6754 Spacing * 3));
6755 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6756 TmpInst.addOperand(Inst.getOperand(5));
6757 Inst = TmpInst;
6758 return true;
6759 }
6760
Jim Grosbacha5378eb2012-04-11 00:15:16 +00006761 // Handle encoding choice for the shift-immediate instructions.
6762 case ARM::t2LSLri:
6763 case ARM::t2LSRri:
6764 case ARM::t2ASRri: {
6765 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6766 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6767 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
6768 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
6769 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
6770 unsigned NewOpc;
6771 switch (Inst.getOpcode()) {
6772 default: llvm_unreachable("unexpected opcode");
6773 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
6774 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
6775 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
6776 }
6777 // The Thumb1 operands aren't in the same order. Awesome, eh?
6778 MCInst TmpInst;
6779 TmpInst.setOpcode(NewOpc);
6780 TmpInst.addOperand(Inst.getOperand(0));
6781 TmpInst.addOperand(Inst.getOperand(5));
6782 TmpInst.addOperand(Inst.getOperand(1));
6783 TmpInst.addOperand(Inst.getOperand(2));
6784 TmpInst.addOperand(Inst.getOperand(3));
6785 TmpInst.addOperand(Inst.getOperand(4));
6786 Inst = TmpInst;
6787 return true;
6788 }
6789 return false;
6790 }
6791
Jim Grosbach863d2af2011-12-13 22:45:11 +00006792 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbach2cc5cda2011-12-21 20:54:00 +00006793 case ARM::t2MOVsr:
6794 case ARM::t2MOVSsr: {
6795 // Which instruction to expand to depends on the CCOut operand and
6796 // whether we're in an IT block if the register operands are low
6797 // registers.
6798 bool isNarrow = false;
6799 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6800 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6801 isARMLowRegister(Inst.getOperand(2).getReg()) &&
6802 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
6803 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
6804 isNarrow = true;
6805 MCInst TmpInst;
6806 unsigned newOpc;
6807 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
6808 default: llvm_unreachable("unexpected opcode!");
6809 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
6810 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
6811 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
6812 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
6813 }
6814 TmpInst.setOpcode(newOpc);
6815 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6816 if (isNarrow)
6817 TmpInst.addOperand(MCOperand::CreateReg(
6818 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6819 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6820 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6821 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6822 TmpInst.addOperand(Inst.getOperand(5));
6823 if (!isNarrow)
6824 TmpInst.addOperand(MCOperand::CreateReg(
6825 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
6826 Inst = TmpInst;
6827 return true;
6828 }
Jim Grosbach863d2af2011-12-13 22:45:11 +00006829 case ARM::t2MOVsi:
6830 case ARM::t2MOVSsi: {
6831 // Which instruction to expand to depends on the CCOut operand and
6832 // whether we're in an IT block if the register operands are low
6833 // registers.
6834 bool isNarrow = false;
6835 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
6836 isARMLowRegister(Inst.getOperand(1).getReg()) &&
6837 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
6838 isNarrow = true;
6839 MCInst TmpInst;
6840 unsigned newOpc;
6841 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
6842 default: llvm_unreachable("unexpected opcode!");
6843 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
6844 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
6845 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
6846 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach520dc782011-12-21 21:04:19 +00006847 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach863d2af2011-12-13 22:45:11 +00006848 }
Benjamin Kramerd9b0b022012-06-02 10:20:22 +00006849 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
6850 if (Amount == 32) Amount = 0;
Jim Grosbach863d2af2011-12-13 22:45:11 +00006851 TmpInst.setOpcode(newOpc);
6852 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6853 if (isNarrow)
6854 TmpInst.addOperand(MCOperand::CreateReg(
6855 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6856 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach520dc782011-12-21 21:04:19 +00006857 if (newOpc != ARM::t2RRX)
Benjamin Kramerd9b0b022012-06-02 10:20:22 +00006858 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach863d2af2011-12-13 22:45:11 +00006859 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6860 TmpInst.addOperand(Inst.getOperand(4));
6861 if (!isNarrow)
6862 TmpInst.addOperand(MCOperand::CreateReg(
6863 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
6864 Inst = TmpInst;
6865 return true;
6866 }
6867 // Handle the ARM mode MOV complex aliases.
Jim Grosbach23f22072011-11-16 18:31:45 +00006868 case ARM::ASRr:
6869 case ARM::LSRr:
6870 case ARM::LSLr:
6871 case ARM::RORr: {
6872 ARM_AM::ShiftOpc ShiftTy;
6873 switch(Inst.getOpcode()) {
6874 default: llvm_unreachable("unexpected opcode!");
6875 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
6876 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
6877 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
6878 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
6879 }
Jim Grosbach23f22072011-11-16 18:31:45 +00006880 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
6881 MCInst TmpInst;
6882 TmpInst.setOpcode(ARM::MOVsr);
6883 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6884 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6885 TmpInst.addOperand(Inst.getOperand(2)); // Rm
6886 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6887 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6888 TmpInst.addOperand(Inst.getOperand(4));
6889 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6890 Inst = TmpInst;
6891 return true;
6892 }
Jim Grosbachee10ff82011-11-10 19:18:01 +00006893 case ARM::ASRi:
6894 case ARM::LSRi:
6895 case ARM::LSLi:
6896 case ARM::RORi: {
6897 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachee10ff82011-11-10 19:18:01 +00006898 switch(Inst.getOpcode()) {
6899 default: llvm_unreachable("unexpected opcode!");
6900 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
6901 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
6902 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
6903 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
6904 }
6905 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach48b368b2011-11-16 19:05:59 +00006906 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachee10ff82011-11-10 19:18:01 +00006907 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonb56e4112012-04-25 18:00:18 +00006908 // A shift by 32 should be encoded as 0 when permitted
6909 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
6910 Amt = 0;
Jim Grosbachee10ff82011-11-10 19:18:01 +00006911 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach71810ab2011-11-10 16:44:55 +00006912 MCInst TmpInst;
Jim Grosbachee10ff82011-11-10 19:18:01 +00006913 TmpInst.setOpcode(Opc);
Jim Grosbach71810ab2011-11-10 16:44:55 +00006914 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6915 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachee10ff82011-11-10 19:18:01 +00006916 if (Opc == ARM::MOVsi)
6917 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach71810ab2011-11-10 16:44:55 +00006918 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6919 TmpInst.addOperand(Inst.getOperand(4));
6920 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
6921 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00006922 return true;
Jim Grosbach71810ab2011-11-10 16:44:55 +00006923 }
Jim Grosbach48b368b2011-11-16 19:05:59 +00006924 case ARM::RRXi: {
6925 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
6926 MCInst TmpInst;
6927 TmpInst.setOpcode(ARM::MOVsi);
6928 TmpInst.addOperand(Inst.getOperand(0)); // Rd
6929 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6930 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
6931 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6932 TmpInst.addOperand(Inst.getOperand(3));
6933 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
6934 Inst = TmpInst;
6935 return true;
6936 }
Jim Grosbach0352b462011-11-10 23:58:34 +00006937 case ARM::t2LDMIA_UPD: {
6938 // If this is a load of a single register, then we should use
6939 // a post-indexed LDR instruction instead, per the ARM ARM.
6940 if (Inst.getNumOperands() != 5)
6941 return false;
6942 MCInst TmpInst;
6943 TmpInst.setOpcode(ARM::t2LDR_POST);
6944 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6945 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6946 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6947 TmpInst.addOperand(MCOperand::CreateImm(4));
6948 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6949 TmpInst.addOperand(Inst.getOperand(3));
6950 Inst = TmpInst;
6951 return true;
6952 }
6953 case ARM::t2STMDB_UPD: {
6954 // If this is a store of a single register, then we should use
6955 // a pre-indexed STR instruction instead, per the ARM ARM.
6956 if (Inst.getNumOperands() != 5)
6957 return false;
6958 MCInst TmpInst;
6959 TmpInst.setOpcode(ARM::t2STR_PRE);
6960 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6961 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6962 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6963 TmpInst.addOperand(MCOperand::CreateImm(-4));
6964 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6965 TmpInst.addOperand(Inst.getOperand(3));
6966 Inst = TmpInst;
6967 return true;
6968 }
Jim Grosbachf8fce712011-08-11 17:35:48 +00006969 case ARM::LDMIA_UPD:
6970 // If this is a load of a single register via a 'pop', then we should use
6971 // a post-indexed LDR instruction instead, per the ARM ARM.
6972 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
6973 Inst.getNumOperands() == 5) {
6974 MCInst TmpInst;
6975 TmpInst.setOpcode(ARM::LDR_POST_IMM);
6976 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6977 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6978 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6979 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
6980 TmpInst.addOperand(MCOperand::CreateImm(4));
6981 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6982 TmpInst.addOperand(Inst.getOperand(3));
6983 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00006984 return true;
Jim Grosbachf8fce712011-08-11 17:35:48 +00006985 }
6986 break;
Jim Grosbachf6713912011-08-11 18:07:11 +00006987 case ARM::STMDB_UPD:
6988 // If this is a store of a single register via a 'push', then we should use
6989 // a pre-indexed STR instruction instead, per the ARM ARM.
6990 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
6991 Inst.getNumOperands() == 5) {
6992 MCInst TmpInst;
6993 TmpInst.setOpcode(ARM::STR_PRE_IMM);
6994 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
6995 TmpInst.addOperand(Inst.getOperand(4)); // Rt
6996 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
6997 TmpInst.addOperand(MCOperand::CreateImm(-4));
6998 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
6999 TmpInst.addOperand(Inst.getOperand(3));
7000 Inst = TmpInst;
7001 }
7002 break;
Jim Grosbachda847862011-12-05 21:06:26 +00007003 case ARM::t2ADDri12:
7004 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7005 // mnemonic was used (not "addw"), encoding T3 is preferred.
7006 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7007 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7008 break;
7009 Inst.setOpcode(ARM::t2ADDri);
7010 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7011 break;
7012 case ARM::t2SUBri12:
7013 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7014 // mnemonic was used (not "subw"), encoding T3 is preferred.
7015 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7016 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7017 break;
7018 Inst.setOpcode(ARM::t2SUBri);
7019 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7020 break;
Jim Grosbach89e2aa62011-08-16 23:57:34 +00007021 case ARM::tADDi8:
Jim Grosbach0f3abd82011-08-31 17:07:33 +00007022 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7023 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7024 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7025 // to encoding T1 if <Rd> is omitted."
Jim Grosbachc0164f82012-03-30 16:31:31 +00007026 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbach89e2aa62011-08-16 23:57:34 +00007027 Inst.setOpcode(ARM::tADDi3);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007028 return true;
7029 }
Jim Grosbach89e2aa62011-08-16 23:57:34 +00007030 break;
Jim Grosbachf67e8552011-09-16 22:58:42 +00007031 case ARM::tSUBi8:
7032 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
7033 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7034 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7035 // to encoding T1 if <Rd> is omitted."
Jim Grosbachc0164f82012-03-30 16:31:31 +00007036 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachf67e8552011-09-16 22:58:42 +00007037 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007038 return true;
7039 }
Jim Grosbachf67e8552011-09-16 22:58:42 +00007040 break;
Jim Grosbach2d30d942012-03-30 17:20:40 +00007041 case ARM::t2ADDri:
7042 case ARM::t2SUBri: {
7043 // If the destination and first source operand are the same, and
7044 // the flags are compatible with the current IT status, use encoding T2
7045 // instead of T3. For compatibility with the system 'as'. Make sure the
7046 // wide encoding wasn't explicit.
7047 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach8f1148b2012-03-30 18:39:43 +00007048 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbach2d30d942012-03-30 17:20:40 +00007049 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7050 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7051 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7052 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7053 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7054 break;
7055 MCInst TmpInst;
7056 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7057 ARM::tADDi8 : ARM::tSUBi8);
7058 TmpInst.addOperand(Inst.getOperand(0));
7059 TmpInst.addOperand(Inst.getOperand(5));
7060 TmpInst.addOperand(Inst.getOperand(0));
7061 TmpInst.addOperand(Inst.getOperand(2));
7062 TmpInst.addOperand(Inst.getOperand(3));
7063 TmpInst.addOperand(Inst.getOperand(4));
7064 Inst = TmpInst;
7065 return true;
7066 }
Jim Grosbach927b9df2011-12-05 22:16:39 +00007067 case ARM::t2ADDrr: {
7068 // If the destination and first source operand are the same, and
7069 // there's no setting of the flags, use encoding T2 instead of T3.
7070 // Note that this is only for ADD, not SUB. This mirrors the system
7071 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7072 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7073 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbach713c7022011-12-05 22:27:04 +00007074 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7075 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbach927b9df2011-12-05 22:16:39 +00007076 break;
7077 MCInst TmpInst;
7078 TmpInst.setOpcode(ARM::tADDhirr);
7079 TmpInst.addOperand(Inst.getOperand(0));
7080 TmpInst.addOperand(Inst.getOperand(0));
7081 TmpInst.addOperand(Inst.getOperand(2));
7082 TmpInst.addOperand(Inst.getOperand(3));
7083 TmpInst.addOperand(Inst.getOperand(4));
7084 Inst = TmpInst;
7085 return true;
7086 }
Jim Grosbacha9cc08f2012-04-27 23:51:36 +00007087 case ARM::tADDrSP: {
7088 // If the non-SP source operand and the destination operand are not the
7089 // same, we need to use the 32-bit encoding if it's available.
7090 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7091 Inst.setOpcode(ARM::t2ADDrr);
7092 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7093 return true;
7094 }
7095 break;
7096 }
Owen Anderson51f6a7a2011-09-09 21:48:23 +00007097 case ARM::tB:
7098 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbach83ec8772011-11-10 23:42:14 +00007099 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson51f6a7a2011-09-09 21:48:23 +00007100 Inst.setOpcode(ARM::tBcc);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007101 return true;
7102 }
Owen Anderson51f6a7a2011-09-09 21:48:23 +00007103 break;
7104 case ARM::t2B:
7105 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbach83ec8772011-11-10 23:42:14 +00007106 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson51f6a7a2011-09-09 21:48:23 +00007107 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007108 return true;
7109 }
Owen Anderson51f6a7a2011-09-09 21:48:23 +00007110 break;
Jim Grosbachc0755102011-08-31 21:17:31 +00007111 case ARM::t2Bcc:
Jim Grosbacha1109882011-09-02 23:22:08 +00007112 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbach83ec8772011-11-10 23:42:14 +00007113 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbachc0755102011-08-31 21:17:31 +00007114 Inst.setOpcode(ARM::t2B);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007115 return true;
7116 }
Jim Grosbachc0755102011-08-31 21:17:31 +00007117 break;
Jim Grosbach395b4532011-08-17 22:57:40 +00007118 case ARM::tBcc:
7119 // If the conditional is AL, we really want tB.
Jim Grosbach83ec8772011-11-10 23:42:14 +00007120 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbach395b4532011-08-17 22:57:40 +00007121 Inst.setOpcode(ARM::tB);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007122 return true;
7123 }
Jim Grosbach3ce23d32011-08-18 16:08:39 +00007124 break;
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00007125 case ARM::tLDMIA: {
7126 // If the register list contains any high registers, or if the writeback
7127 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7128 // instead if we're in Thumb2. Otherwise, this should have generated
7129 // an error in validateInstruction().
7130 unsigned Rn = Inst.getOperand(0).getReg();
7131 bool hasWritebackToken =
7132 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7133 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7134 bool listContainsBase;
7135 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7136 (!listContainsBase && !hasWritebackToken) ||
7137 (listContainsBase && hasWritebackToken)) {
7138 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7139 assert (isThumbTwo());
7140 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7141 // If we're switching to the updating version, we need to insert
7142 // the writeback tied operand.
7143 if (hasWritebackToken)
7144 Inst.insert(Inst.begin(),
7145 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbach83ec8772011-11-10 23:42:14 +00007146 return true;
Jim Grosbach76ecc3d2011-09-07 18:05:34 +00007147 }
7148 break;
7149 }
Jim Grosbach8213c962011-09-16 20:50:13 +00007150 case ARM::tSTMIA_UPD: {
7151 // If the register list contains any high registers, we need to use
7152 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7153 // should have generated an error in validateInstruction().
7154 unsigned Rn = Inst.getOperand(0).getReg();
7155 bool listContainsBase;
7156 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7157 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7158 assert (isThumbTwo());
7159 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbach83ec8772011-11-10 23:42:14 +00007160 return true;
Jim Grosbach8213c962011-09-16 20:50:13 +00007161 }
7162 break;
7163 }
Jim Grosbach54026372011-11-10 23:17:11 +00007164 case ARM::tPOP: {
7165 bool listContainsBase;
7166 // If the register list contains any high registers, we need to use
7167 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7168 // should have generated an error in validateInstruction().
7169 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbach83ec8772011-11-10 23:42:14 +00007170 return false;
Jim Grosbach54026372011-11-10 23:17:11 +00007171 assert (isThumbTwo());
7172 Inst.setOpcode(ARM::t2LDMIA_UPD);
7173 // Add the base register and writeback operands.
7174 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7175 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbach83ec8772011-11-10 23:42:14 +00007176 return true;
Jim Grosbach54026372011-11-10 23:17:11 +00007177 }
7178 case ARM::tPUSH: {
7179 bool listContainsBase;
7180 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbach83ec8772011-11-10 23:42:14 +00007181 return false;
Jim Grosbach54026372011-11-10 23:17:11 +00007182 assert (isThumbTwo());
7183 Inst.setOpcode(ARM::t2STMDB_UPD);
7184 // Add the base register and writeback operands.
7185 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7186 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbach83ec8772011-11-10 23:42:14 +00007187 return true;
Jim Grosbach54026372011-11-10 23:17:11 +00007188 }
Jim Grosbach1ad60c22011-09-10 00:15:36 +00007189 case ARM::t2MOVi: {
7190 // If we can use the 16-bit encoding and the user didn't explicitly
7191 // request the 32-bit variant, transform it here.
7192 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbachc0164f82012-03-30 16:31:31 +00007193 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbachc2d31642011-09-14 19:12:11 +00007194 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7195 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7196 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbach1ad60c22011-09-10 00:15:36 +00007197 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7198 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7199 // The operands aren't in the same order for tMOVi8...
7200 MCInst TmpInst;
7201 TmpInst.setOpcode(ARM::tMOVi8);
7202 TmpInst.addOperand(Inst.getOperand(0));
7203 TmpInst.addOperand(Inst.getOperand(4));
7204 TmpInst.addOperand(Inst.getOperand(1));
7205 TmpInst.addOperand(Inst.getOperand(2));
7206 TmpInst.addOperand(Inst.getOperand(3));
7207 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00007208 return true;
Jim Grosbach1ad60c22011-09-10 00:15:36 +00007209 }
7210 break;
7211 }
7212 case ARM::t2MOVr: {
7213 // If we can use the 16-bit encoding and the user didn't explicitly
7214 // request the 32-bit variant, transform it here.
7215 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7216 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7217 Inst.getOperand(2).getImm() == ARMCC::AL &&
7218 Inst.getOperand(4).getReg() == ARM::CPSR &&
7219 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7220 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7221 // The operands aren't the same for tMOV[S]r... (no cc_out)
7222 MCInst TmpInst;
7223 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7224 TmpInst.addOperand(Inst.getOperand(0));
7225 TmpInst.addOperand(Inst.getOperand(1));
7226 TmpInst.addOperand(Inst.getOperand(2));
7227 TmpInst.addOperand(Inst.getOperand(3));
7228 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00007229 return true;
Jim Grosbach1ad60c22011-09-10 00:15:36 +00007230 }
7231 break;
7232 }
Jim Grosbach326efe52011-09-19 20:29:33 +00007233 case ARM::t2SXTH:
Jim Grosbach50f1c372011-09-20 00:46:54 +00007234 case ARM::t2SXTB:
7235 case ARM::t2UXTH:
7236 case ARM::t2UXTB: {
Jim Grosbach326efe52011-09-19 20:29:33 +00007237 // If we can use the 16-bit encoding and the user didn't explicitly
7238 // request the 32-bit variant, transform it here.
7239 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7240 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7241 Inst.getOperand(2).getImm() == 0 &&
7242 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7243 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbach50f1c372011-09-20 00:46:54 +00007244 unsigned NewOpc;
7245 switch (Inst.getOpcode()) {
7246 default: llvm_unreachable("Illegal opcode!");
7247 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7248 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7249 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7250 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7251 }
Jim Grosbach326efe52011-09-19 20:29:33 +00007252 // The operands aren't the same for thumb1 (no rotate operand).
7253 MCInst TmpInst;
7254 TmpInst.setOpcode(NewOpc);
7255 TmpInst.addOperand(Inst.getOperand(0));
7256 TmpInst.addOperand(Inst.getOperand(1));
7257 TmpInst.addOperand(Inst.getOperand(3));
7258 TmpInst.addOperand(Inst.getOperand(4));
7259 Inst = TmpInst;
Jim Grosbach83ec8772011-11-10 23:42:14 +00007260 return true;
Jim Grosbach326efe52011-09-19 20:29:33 +00007261 }
7262 break;
7263 }
Jim Grosbach04b5d932011-12-20 00:59:38 +00007264 case ARM::MOVsi: {
7265 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonb56e4112012-04-25 18:00:18 +00007266 // rrx shifts and asr/lsr of #32 is encoded as 0
7267 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7268 return false;
Jim Grosbach04b5d932011-12-20 00:59:38 +00007269 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7270 // Shifting by zero is accepted as a vanilla 'MOVr'
7271 MCInst TmpInst;
7272 TmpInst.setOpcode(ARM::MOVr);
7273 TmpInst.addOperand(Inst.getOperand(0));
7274 TmpInst.addOperand(Inst.getOperand(1));
7275 TmpInst.addOperand(Inst.getOperand(3));
7276 TmpInst.addOperand(Inst.getOperand(4));
7277 TmpInst.addOperand(Inst.getOperand(5));
7278 Inst = TmpInst;
7279 return true;
7280 }
7281 return false;
7282 }
Jim Grosbach8d9550b2011-12-22 18:04:04 +00007283 case ARM::ANDrsi:
7284 case ARM::ORRrsi:
7285 case ARM::EORrsi:
7286 case ARM::BICrsi:
7287 case ARM::SUBrsi:
7288 case ARM::ADDrsi: {
7289 unsigned newOpc;
7290 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7291 if (SOpc == ARM_AM::rrx) return false;
7292 switch (Inst.getOpcode()) {
Craig Topperbc219812012-02-07 02:50:20 +00007293 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach8d9550b2011-12-22 18:04:04 +00007294 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7295 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7296 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7297 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7298 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7299 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7300 }
7301 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton8ed97ef2012-07-09 16:31:14 +00007302 // The exception is for right shifts, where 0 == 32
7303 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7304 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach8d9550b2011-12-22 18:04:04 +00007305 MCInst TmpInst;
7306 TmpInst.setOpcode(newOpc);
7307 TmpInst.addOperand(Inst.getOperand(0));
7308 TmpInst.addOperand(Inst.getOperand(1));
7309 TmpInst.addOperand(Inst.getOperand(2));
7310 TmpInst.addOperand(Inst.getOperand(4));
7311 TmpInst.addOperand(Inst.getOperand(5));
7312 TmpInst.addOperand(Inst.getOperand(6));
7313 Inst = TmpInst;
7314 return true;
7315 }
7316 return false;
7317 }
Jim Grosbach74423e32012-01-25 19:52:01 +00007318 case ARM::ITasm:
Jim Grosbach89df9962011-08-26 21:43:41 +00007319 case ARM::t2IT: {
7320 // The mask bits for all but the first condition are represented as
7321 // the low bit of the condition code value implies 't'. We currently
7322 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Barton4d2f0772012-04-27 08:42:59 +00007323 // of the condition code is zero.
Jim Grosbach89df9962011-08-26 21:43:41 +00007324 MCOperand &MO = Inst.getOperand(1);
7325 unsigned Mask = MO.getImm();
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007326 unsigned OrigMask = Mask;
7327 unsigned TZ = CountTrailingZeros_32(Mask);
Jim Grosbach89df9962011-08-26 21:43:41 +00007328 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach89df9962011-08-26 21:43:41 +00007329 assert(Mask && TZ <= 3 && "illegal IT mask value!");
7330 for (unsigned i = 3; i != TZ; --i)
7331 Mask ^= 1 << i;
Richard Barton4d2f0772012-04-27 08:42:59 +00007332 }
Jim Grosbach89df9962011-08-26 21:43:41 +00007333 MO.setImm(Mask);
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007334
7335 // Set up the IT block state according to the IT instruction we just
7336 // matched.
7337 assert(!inITBlock() && "nested IT blocks?!");
7338 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7339 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7340 ITState.CurPosition = 0;
7341 ITState.FirstCond = true;
Jim Grosbach89df9962011-08-26 21:43:41 +00007342 break;
7343 }
Richard Barton2b6652f2012-07-09 16:12:24 +00007344 case ARM::t2LSLrr:
7345 case ARM::t2LSRrr:
7346 case ARM::t2ASRrr:
7347 case ARM::t2SBCrr:
7348 case ARM::t2RORrr:
7349 case ARM::t2BICrr:
7350 {
Richard Bartonc985e6e2012-07-09 16:14:28 +00007351 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Barton2b6652f2012-07-09 16:12:24 +00007352 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7353 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7354 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton874b8632012-07-09 18:30:56 +00007355 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7356 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Barton2b6652f2012-07-09 16:12:24 +00007357 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7358 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7359 unsigned NewOpc;
7360 switch (Inst.getOpcode()) {
7361 default: llvm_unreachable("unexpected opcode");
7362 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7363 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7364 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7365 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7366 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7367 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7368 }
7369 MCInst TmpInst;
7370 TmpInst.setOpcode(NewOpc);
7371 TmpInst.addOperand(Inst.getOperand(0));
7372 TmpInst.addOperand(Inst.getOperand(5));
7373 TmpInst.addOperand(Inst.getOperand(1));
7374 TmpInst.addOperand(Inst.getOperand(2));
7375 TmpInst.addOperand(Inst.getOperand(3));
7376 TmpInst.addOperand(Inst.getOperand(4));
7377 Inst = TmpInst;
7378 return true;
7379 }
7380 return false;
7381 }
7382 case ARM::t2ANDrr:
7383 case ARM::t2EORrr:
7384 case ARM::t2ADCrr:
7385 case ARM::t2ORRrr:
7386 {
Richard Bartonc985e6e2012-07-09 16:14:28 +00007387 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Barton2b6652f2012-07-09 16:12:24 +00007388 // These instructions are special in that they are commutable, so shorter encodings
7389 // are available more often.
7390 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7391 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7392 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7393 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton874b8632012-07-09 18:30:56 +00007394 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7395 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Barton2b6652f2012-07-09 16:12:24 +00007396 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7397 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7398 unsigned NewOpc;
7399 switch (Inst.getOpcode()) {
7400 default: llvm_unreachable("unexpected opcode");
7401 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7402 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7403 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7404 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7405 }
7406 MCInst TmpInst;
7407 TmpInst.setOpcode(NewOpc);
7408 TmpInst.addOperand(Inst.getOperand(0));
7409 TmpInst.addOperand(Inst.getOperand(5));
7410 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7411 TmpInst.addOperand(Inst.getOperand(1));
7412 TmpInst.addOperand(Inst.getOperand(2));
7413 } else {
7414 TmpInst.addOperand(Inst.getOperand(2));
7415 TmpInst.addOperand(Inst.getOperand(1));
7416 }
7417 TmpInst.addOperand(Inst.getOperand(3));
7418 TmpInst.addOperand(Inst.getOperand(4));
7419 Inst = TmpInst;
7420 return true;
7421 }
7422 return false;
7423 }
Jim Grosbachf8fce712011-08-11 17:35:48 +00007424 }
Jim Grosbach83ec8772011-11-10 23:42:14 +00007425 return false;
Jim Grosbachf8fce712011-08-11 17:35:48 +00007426}
7427
Jim Grosbach47a0d522011-08-16 20:45:50 +00007428unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7429 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7430 // suffix depending on whether they're in an IT block or not.
Jim Grosbach194bd892011-08-16 22:20:01 +00007431 unsigned Opc = Inst.getOpcode();
Benjamin Kramer1a2f9882011-10-22 16:50:00 +00007432 const MCInstrDesc &MCID = getInstDesc(Opc);
Jim Grosbach47a0d522011-08-16 20:45:50 +00007433 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7434 assert(MCID.hasOptionalDef() &&
7435 "optionally flag setting instruction missing optional def operand");
7436 assert(MCID.NumOperands == Inst.getNumOperands() &&
7437 "operand count mismatch!");
7438 // Find the optional-def operand (cc_out).
7439 unsigned OpNo;
7440 for (OpNo = 0;
7441 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7442 ++OpNo)
7443 ;
7444 // If we're parsing Thumb1, reject it completely.
7445 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7446 return Match_MnemonicFail;
7447 // If we're parsing Thumb2, which form is legal depends on whether we're
7448 // in an IT block.
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007449 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7450 !inITBlock())
Jim Grosbach47a0d522011-08-16 20:45:50 +00007451 return Match_RequiresITBlock;
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007452 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7453 inITBlock())
7454 return Match_RequiresNotITBlock;
Jim Grosbach47a0d522011-08-16 20:45:50 +00007455 }
Jim Grosbach194bd892011-08-16 22:20:01 +00007456 // Some high-register supporting Thumb1 encodings only allow both registers
7457 // to be from r0-r7 when in Thumb2.
7458 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7459 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7460 isARMLowRegister(Inst.getOperand(2).getReg()))
7461 return Match_RequiresThumb2;
7462 // Others only require ARMv6 or later.
Jim Grosbach4ec6e882011-08-19 20:46:54 +00007463 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbach194bd892011-08-16 22:20:01 +00007464 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7465 isARMLowRegister(Inst.getOperand(1).getReg()))
7466 return Match_RequiresV6;
Jim Grosbach47a0d522011-08-16 20:45:50 +00007467 return Match_Success;
7468}
7469
Jim Grosbach14ce6fa2012-04-24 22:40:08 +00007470static const char *getSubtargetFeatureName(unsigned Val);
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007471bool ARMAsmParser::
7472MatchAndEmitInstruction(SMLoc IDLoc,
7473 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
7474 MCStreamer &Out) {
7475 MCInst Inst;
Chad Rosier3a86e132012-09-03 02:06:46 +00007476 unsigned Kind;
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007477 unsigned ErrorInfo;
Jim Grosbach19cb7f42011-08-15 23:03:29 +00007478 unsigned MatchResult;
Chad Rosier3a86e132012-09-03 02:06:46 +00007479
Chad Rosierc4d25602012-09-03 03:16:09 +00007480 MatchResult = MatchInstructionImpl(Operands, Kind, Inst, ErrorInfo);
Kevin Enderby193c3ac2010-12-09 19:19:43 +00007481 switch (MatchResult) {
Jim Grosbach19cb7f42011-08-15 23:03:29 +00007482 default: break;
Chris Lattnere73d4f82010-10-28 21:41:58 +00007483 case Match_Success:
Jim Grosbach189610f2011-07-26 18:25:39 +00007484 // Context sensitive operand constraints aren't handled by the matcher,
7485 // so check them here.
Jim Grosbacha1109882011-09-02 23:22:08 +00007486 if (validateInstruction(Inst, Operands)) {
7487 // Still progress the IT block, otherwise one wrong condition causes
7488 // nasty cascading errors.
7489 forwardITPosition();
Jim Grosbach189610f2011-07-26 18:25:39 +00007490 return true;
Jim Grosbacha1109882011-09-02 23:22:08 +00007491 }
Jim Grosbach189610f2011-07-26 18:25:39 +00007492
Jim Grosbachf8fce712011-08-11 17:35:48 +00007493 // Some instructions need post-processing to, for example, tweak which
Jim Grosbach83ec8772011-11-10 23:42:14 +00007494 // encoding is selected. Loop on it while changes happen so the
7495 // individual transformations can chain off each other. E.g.,
7496 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7497 while (processInstruction(Inst, Operands))
7498 ;
Jim Grosbachf8fce712011-08-11 17:35:48 +00007499
Jim Grosbacha1109882011-09-02 23:22:08 +00007500 // Only move forward at the very end so that everything in validate
7501 // and process gets a consistent answer about whether we're in an IT
7502 // block.
7503 forwardITPosition();
7504
Jim Grosbach74423e32012-01-25 19:52:01 +00007505 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7506 // doesn't actually encode.
7507 if (Inst.getOpcode() == ARM::ITasm)
7508 return false;
7509
Jim Grosbach42e6bd32012-01-26 23:20:15 +00007510 Inst.setLoc(IDLoc);
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007511 Out.EmitInstruction(Inst);
7512 return false;
Jim Grosbach14ce6fa2012-04-24 22:40:08 +00007513 case Match_MissingFeature: {
7514 assert(ErrorInfo && "Unknown missing feature!");
7515 // Special case the error message for the very common case where only
7516 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7517 std::string Msg = "instruction requires:";
7518 unsigned Mask = 1;
7519 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7520 if (ErrorInfo & Mask) {
7521 Msg += " ";
7522 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7523 }
7524 Mask <<= 1;
7525 }
7526 return Error(IDLoc, Msg);
7527 }
Chris Lattnere73d4f82010-10-28 21:41:58 +00007528 case Match_InvalidOperand: {
7529 SMLoc ErrorLoc = IDLoc;
7530 if (ErrorInfo != ~0U) {
7531 if (ErrorInfo >= Operands.size())
7532 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach16c74252010-10-29 14:46:02 +00007533
Chris Lattnere73d4f82010-10-28 21:41:58 +00007534 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7535 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7536 }
Jim Grosbach16c74252010-10-29 14:46:02 +00007537
Chris Lattnere73d4f82010-10-28 21:41:58 +00007538 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007539 }
Chris Lattnere73d4f82010-10-28 21:41:58 +00007540 case Match_MnemonicFail:
Benjamin Kramer362a05a2012-04-15 17:04:27 +00007541 return Error(IDLoc, "invalid instruction",
7542 ((ARMOperand*)Operands[0])->getLocRange());
Jim Grosbachf8e1e3e2011-08-29 22:24:09 +00007543 case Match_RequiresNotITBlock:
7544 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach47a0d522011-08-16 20:45:50 +00007545 case Match_RequiresITBlock:
7546 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbach194bd892011-08-16 22:20:01 +00007547 case Match_RequiresV6:
7548 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7549 case Match_RequiresThumb2:
7550 return Error(IDLoc, "instruction variant requires Thumb2");
Jim Grosbach70c9bf32012-06-22 23:56:48 +00007551 case Match_ImmRange0_15: {
7552 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7553 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7554 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7555 }
Chris Lattnere73d4f82010-10-28 21:41:58 +00007556 }
Jim Grosbach16c74252010-10-29 14:46:02 +00007557
Eric Christopherc223e2b2010-10-29 09:26:59 +00007558 llvm_unreachable("Implement any new match types added!");
Chris Lattnerfa42fad2010-10-28 21:28:01 +00007559}
7560
Jim Grosbach1355cf12011-07-26 17:10:22 +00007561/// parseDirective parses the arm specific directives
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007562bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7563 StringRef IDVal = DirectiveID.getIdentifier();
7564 if (IDVal == ".word")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007565 return parseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007566 else if (IDVal == ".thumb")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007567 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach9a70df92011-12-07 18:04:19 +00007568 else if (IDVal == ".arm")
7569 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007570 else if (IDVal == ".thumb_func")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007571 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007572 else if (IDVal == ".code")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007573 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +00007574 else if (IDVal == ".syntax")
Jim Grosbach1355cf12011-07-26 17:10:22 +00007575 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbacha39cda72011-12-14 02:16:11 +00007576 else if (IDVal == ".unreq")
7577 return parseDirectiveUnreq(DirectiveID.getLoc());
Jason W Kimd7c9e082011-12-20 17:38:12 +00007578 else if (IDVal == ".arch")
7579 return parseDirectiveArch(DirectiveID.getLoc());
7580 else if (IDVal == ".eabi_attribute")
7581 return parseDirectiveEabiAttr(DirectiveID.getLoc());
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007582 return true;
7583}
7584
Jim Grosbach1355cf12011-07-26 17:10:22 +00007585/// parseDirectiveWord
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007586/// ::= .word [ expression (, expression)* ]
Jim Grosbach1355cf12011-07-26 17:10:22 +00007587bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007588 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7589 for (;;) {
7590 const MCExpr *Value;
7591 if (getParser().ParseExpression(Value))
7592 return true;
7593
Chris Lattneraaec2052010-01-19 19:46:13 +00007594 getParser().getStreamer().EmitValue(Value, Size, 0/*addrspace*/);
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007595
7596 if (getLexer().is(AsmToken::EndOfStatement))
7597 break;
Jim Grosbach16c74252010-10-29 14:46:02 +00007598
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007599 // FIXME: Improve diagnostic.
7600 if (getLexer().isNot(AsmToken::Comma))
7601 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007602 Parser.Lex();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007603 }
7604 }
7605
Sean Callananb9a25b72010-01-19 20:27:46 +00007606 Parser.Lex();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007607 return false;
7608}
7609
Jim Grosbach1355cf12011-07-26 17:10:22 +00007610/// parseDirectiveThumb
Kevin Enderby515d5092009-10-15 20:48:48 +00007611/// ::= .thumb
Jim Grosbach1355cf12011-07-26 17:10:22 +00007612bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Kevin Enderby515d5092009-10-15 20:48:48 +00007613 if (getLexer().isNot(AsmToken::EndOfStatement))
7614 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007615 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007616
Jim Grosbach9a70df92011-12-07 18:04:19 +00007617 if (!isThumb())
7618 SwitchMode();
7619 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7620 return false;
7621}
7622
7623/// parseDirectiveARM
7624/// ::= .arm
7625bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7626 if (getLexer().isNot(AsmToken::EndOfStatement))
7627 return Error(L, "unexpected token in directive");
7628 Parser.Lex();
7629
7630 if (isThumb())
7631 SwitchMode();
7632 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby515d5092009-10-15 20:48:48 +00007633 return false;
7634}
7635
Jim Grosbach1355cf12011-07-26 17:10:22 +00007636/// parseDirectiveThumbFunc
Kevin Enderby515d5092009-10-15 20:48:48 +00007637/// ::= .thumbfunc symbol_name
Jim Grosbach1355cf12011-07-26 17:10:22 +00007638bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Rafael Espindola64695402011-05-16 16:17:21 +00007639 const MCAsmInfo &MAI = getParser().getStreamer().getContext().getAsmInfo();
7640 bool isMachO = MAI.hasSubsectionsViaSymbols();
7641 StringRef Name;
Jim Grosbachde4d8392011-12-21 22:30:16 +00007642 bool needFuncName = true;
Rafael Espindola64695402011-05-16 16:17:21 +00007643
Jim Grosbachde4d8392011-12-21 22:30:16 +00007644 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindola64695402011-05-16 16:17:21 +00007645 // ELF doesn't
7646 if (isMachO) {
7647 const AsmToken &Tok = Parser.getTok();
Jim Grosbachde4d8392011-12-21 22:30:16 +00007648 if (Tok.isNot(AsmToken::EndOfStatement)) {
7649 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7650 return Error(L, "unexpected token in .thumb_func directive");
7651 Name = Tok.getIdentifier();
7652 Parser.Lex(); // Consume the identifier token.
7653 needFuncName = false;
7654 }
Rafael Espindola64695402011-05-16 16:17:21 +00007655 }
7656
Jim Grosbachde4d8392011-12-21 22:30:16 +00007657 if (getLexer().isNot(AsmToken::EndOfStatement))
Kevin Enderby515d5092009-10-15 20:48:48 +00007658 return Error(L, "unexpected token in directive");
Jim Grosbachde4d8392011-12-21 22:30:16 +00007659
7660 // Eat the end of statement and any blank lines that follow.
7661 while (getLexer().is(AsmToken::EndOfStatement))
7662 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007663
Rafael Espindola64695402011-05-16 16:17:21 +00007664 // FIXME: assuming function name will be the line following .thumb_func
Jim Grosbachde4d8392011-12-21 22:30:16 +00007665 // We really should be checking the next symbol definition even if there's
7666 // stuff in between.
7667 if (needFuncName) {
Jim Grosbachd475f862011-11-10 20:48:53 +00007668 Name = Parser.getTok().getIdentifier();
Rafael Espindola64695402011-05-16 16:17:21 +00007669 }
7670
Jim Grosbach642fc9c2010-11-05 22:33:53 +00007671 // Mark symbol as a thumb symbol.
7672 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
7673 getParser().getStreamer().EmitThumbFunc(Func);
Kevin Enderby515d5092009-10-15 20:48:48 +00007674 return false;
7675}
7676
Jim Grosbach1355cf12011-07-26 17:10:22 +00007677/// parseDirectiveSyntax
Kevin Enderby515d5092009-10-15 20:48:48 +00007678/// ::= .syntax unified | divided
Jim Grosbach1355cf12011-07-26 17:10:22 +00007679bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan18b83232010-01-19 21:44:56 +00007680 const AsmToken &Tok = Parser.getTok();
Kevin Enderby515d5092009-10-15 20:48:48 +00007681 if (Tok.isNot(AsmToken::Identifier))
7682 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer38e59892010-07-14 22:38:02 +00007683 StringRef Mode = Tok.getString();
Duncan Sands58c86912010-06-29 13:04:35 +00007684 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callananb9a25b72010-01-19 20:27:46 +00007685 Parser.Lex();
Duncan Sands58c86912010-06-29 13:04:35 +00007686 else if (Mode == "divided" || Mode == "DIVIDED")
Kevin Enderby9e56fb12011-01-27 23:22:36 +00007687 return Error(L, "'.syntax divided' arm asssembly not supported");
Kevin Enderby515d5092009-10-15 20:48:48 +00007688 else
7689 return Error(L, "unrecognized syntax mode in .syntax directive");
7690
7691 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan18b83232010-01-19 21:44:56 +00007692 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007693 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007694
7695 // TODO tell the MC streamer the mode
7696 // getParser().getStreamer().Emit???();
7697 return false;
7698}
7699
Jim Grosbach1355cf12011-07-26 17:10:22 +00007700/// parseDirectiveCode
Kevin Enderby515d5092009-10-15 20:48:48 +00007701/// ::= .code 16 | 32
Jim Grosbach1355cf12011-07-26 17:10:22 +00007702bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan18b83232010-01-19 21:44:56 +00007703 const AsmToken &Tok = Parser.getTok();
Kevin Enderby515d5092009-10-15 20:48:48 +00007704 if (Tok.isNot(AsmToken::Integer))
7705 return Error(L, "unexpected token in .code directive");
Sean Callanan18b83232010-01-19 21:44:56 +00007706 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands58c86912010-06-29 13:04:35 +00007707 if (Val == 16)
Sean Callananb9a25b72010-01-19 20:27:46 +00007708 Parser.Lex();
Duncan Sands58c86912010-06-29 13:04:35 +00007709 else if (Val == 32)
Sean Callananb9a25b72010-01-19 20:27:46 +00007710 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007711 else
7712 return Error(L, "invalid operand to .code directive");
7713
7714 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan18b83232010-01-19 21:44:56 +00007715 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00007716 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00007717
Evan Cheng32869202011-07-08 22:36:29 +00007718 if (Val == 16) {
Jim Grosbach98447da2011-09-06 18:46:23 +00007719 if (!isThumb())
Evan Chengffc0e732011-07-09 05:47:46 +00007720 SwitchMode();
Jim Grosbach98447da2011-09-06 18:46:23 +00007721 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng32869202011-07-08 22:36:29 +00007722 } else {
Jim Grosbach98447da2011-09-06 18:46:23 +00007723 if (isThumb())
Evan Chengffc0e732011-07-09 05:47:46 +00007724 SwitchMode();
Jim Grosbach98447da2011-09-06 18:46:23 +00007725 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Chengeb0caa12011-07-08 22:49:55 +00007726 }
Jim Grosbach2a301702010-11-05 22:40:53 +00007727
Kevin Enderby515d5092009-10-15 20:48:48 +00007728 return false;
7729}
7730
Jim Grosbacha39cda72011-12-14 02:16:11 +00007731/// parseDirectiveReq
7732/// ::= name .req registername
7733bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
7734 Parser.Lex(); // Eat the '.req' token.
7735 unsigned Reg;
7736 SMLoc SRegLoc, ERegLoc;
7737 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
7738 Parser.EatToEndOfStatement();
7739 return Error(SRegLoc, "register name expected");
7740 }
7741
7742 // Shouldn't be anything else.
7743 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
7744 Parser.EatToEndOfStatement();
7745 return Error(Parser.getTok().getLoc(),
7746 "unexpected input in .req directive.");
7747 }
7748
7749 Parser.Lex(); // Consume the EndOfStatement
7750
7751 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
7752 return Error(SRegLoc, "redefinition of '" + Name +
7753 "' does not match original.");
7754
7755 return false;
7756}
7757
7758/// parseDirectiveUneq
7759/// ::= .unreq registername
7760bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
7761 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7762 Parser.EatToEndOfStatement();
7763 return Error(L, "unexpected input in .unreq directive.");
7764 }
7765 RegisterReqs.erase(Parser.getTok().getIdentifier());
7766 Parser.Lex(); // Eat the identifier.
7767 return false;
7768}
7769
Jason W Kimd7c9e082011-12-20 17:38:12 +00007770/// parseDirectiveArch
7771/// ::= .arch token
7772bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
7773 return true;
7774}
7775
7776/// parseDirectiveEabiAttr
7777/// ::= .eabi_attribute int, int
7778bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
7779 return true;
7780}
7781
Sean Callanan90b70972010-04-07 20:29:34 +00007782extern "C" void LLVMInitializeARMAsmLexer();
7783
Kevin Enderby9c41fa82009-10-30 22:55:57 +00007784/// Force static initialization.
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007785extern "C" void LLVMInitializeARMAsmParser() {
Evan Cheng94b95502011-07-26 00:24:13 +00007786 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
7787 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
Sean Callanan90b70972010-04-07 20:29:34 +00007788 LLVMInitializeARMAsmLexer();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00007789}
Daniel Dunbar3483aca2010-08-11 05:24:50 +00007790
Chris Lattner0692ee62010-09-06 19:11:01 +00007791#define GET_REGISTER_MATCHER
Craig Topper8030e1a2012-04-25 06:56:34 +00007792#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner0692ee62010-09-06 19:11:01 +00007793#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar3483aca2010-08-11 05:24:50 +00007794#include "ARMGenAsmMatcher.inc"