blob: c1d2f7f3ee08e578cceae5c851831c772dec1c8d [file] [log] [blame]
Kevin Enderbyccab3172009-09-15 00:27:25 +00001//===-- ARMAsmParser.cpp - Parse ARM assembly to MCInst instructions ------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Logan Chien8cbb80d2013-10-28 17:51:12 +000010#include "ARMFPUName.h"
Amara Emerson52cfb6a2013-10-03 09:31:51 +000011#include "ARMFeatures.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000012#include "MCTargetDesc/ARMAddressingModes.h"
Logan Chien439e8f92013-12-11 17:16:25 +000013#include "MCTargetDesc/ARMArchName.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000014#include "MCTargetDesc/ARMBaseInfo.h"
15#include "MCTargetDesc/ARMMCExpr.h"
Evan Cheng11424442011-07-26 00:24:13 +000016#include "llvm/ADT/STLExtras.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000017#include "llvm/ADT/SmallVector.h"
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +000018#include "llvm/ADT/StringExtras.h"
Daniel Dunbar188b47b2010-08-11 06:37:20 +000019#include "llvm/ADT/StringSwitch.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000020#include "llvm/ADT/Twine.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000021#include "llvm/MC/MCAsmInfo.h"
Jack Carter718da0b2013-01-30 02:24:33 +000022#include "llvm/MC/MCAssembler.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000023#include "llvm/MC/MCContext.h"
Tim Northoverd6a729b2014-01-06 14:28:05 +000024#include "llvm/MC/MCDisassembler.h"
Jack Carter718da0b2013-01-30 02:24:33 +000025#include "llvm/MC/MCELFStreamer.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000026#include "llvm/MC/MCExpr.h"
27#include "llvm/MC/MCInst.h"
28#include "llvm/MC/MCInstrDesc.h"
Joey Gouly0e76fa72013-09-12 10:28:05 +000029#include "llvm/MC/MCInstrInfo.h"
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +000030#include "llvm/MC/MCObjectFileInfo.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000031#include "llvm/MC/MCParser/MCAsmLexer.h"
32#include "llvm/MC/MCParser/MCAsmParser.h"
33#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
34#include "llvm/MC/MCRegisterInfo.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000035#include "llvm/MC/MCSection.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000036#include "llvm/MC/MCStreamer.h"
37#include "llvm/MC/MCSubtargetInfo.h"
David Peixottoe407d092013-12-19 18:12:36 +000038#include "llvm/MC/MCSymbol.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000039#include "llvm/MC/MCTargetAsmParser.h"
Saleem Abdulrasool278a9f42014-01-19 08:25:27 +000040#include "llvm/Support/ARMBuildAttributes.h"
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +000041#include "llvm/Support/ARMEHABI.h"
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +000042#include "llvm/Support/COFF.h"
Tim Northoverd6a729b2014-01-06 14:28:05 +000043#include "llvm/Support/Debug.h"
Jack Carter718da0b2013-01-30 02:24:33 +000044#include "llvm/Support/ELF.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000045#include "llvm/Support/MathExtras.h"
46#include "llvm/Support/SourceMgr.h"
47#include "llvm/Support/TargetRegistry.h"
48#include "llvm/Support/raw_ostream.h"
Evan Cheng4d1ca962011-07-08 01:53:10 +000049
Kevin Enderbyccab3172009-09-15 00:27:25 +000050using namespace llvm;
51
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +000052namespace {
Bill Wendlingee7f1f92010-11-06 21:42:12 +000053
54class ARMOperand;
Jim Grosbach624bcc72010-10-29 14:46:02 +000055
Jim Grosbach04945c42011-12-02 00:35:16 +000056enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
Jim Grosbachcd6f5e72011-11-30 01:09:44 +000057
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000058class UnwindContext {
59 MCAsmParser &Parser;
60
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +000061 typedef SmallVector<SMLoc, 4> Locs;
62
63 Locs FnStartLocs;
64 Locs CantUnwindLocs;
65 Locs PersonalityLocs;
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +000066 Locs PersonalityIndexLocs;
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +000067 Locs HandlerDataLocs;
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000068 int FPReg;
69
70public:
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +000071 UnwindContext(MCAsmParser &P) : Parser(P), FPReg(ARM::SP) {}
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000072
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +000073 bool hasFnStart() const { return !FnStartLocs.empty(); }
74 bool cantUnwind() const { return !CantUnwindLocs.empty(); }
75 bool hasHandlerData() const { return !HandlerDataLocs.empty(); }
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +000076 bool hasPersonality() const {
77 return !(PersonalityLocs.empty() && PersonalityIndexLocs.empty());
78 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000079
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +000080 void recordFnStart(SMLoc L) { FnStartLocs.push_back(L); }
81 void recordCantUnwind(SMLoc L) { CantUnwindLocs.push_back(L); }
82 void recordPersonality(SMLoc L) { PersonalityLocs.push_back(L); }
83 void recordHandlerData(SMLoc L) { HandlerDataLocs.push_back(L); }
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +000084 void recordPersonalityIndex(SMLoc L) { PersonalityIndexLocs.push_back(L); }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000085
86 void saveFPReg(int Reg) { FPReg = Reg; }
87 int getFPReg() const { return FPReg; }
88
89 void emitFnStartLocNotes() const {
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +000090 for (Locs::const_iterator FI = FnStartLocs.begin(), FE = FnStartLocs.end();
91 FI != FE; ++FI)
92 Parser.Note(*FI, ".fnstart was specified here");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000093 }
94 void emitCantUnwindLocNotes() const {
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +000095 for (Locs::const_iterator UI = CantUnwindLocs.begin(),
96 UE = CantUnwindLocs.end(); UI != UE; ++UI)
97 Parser.Note(*UI, ".cantunwind was specified here");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000098 }
99 void emitHandlerDataLocNotes() const {
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +0000100 for (Locs::const_iterator HI = HandlerDataLocs.begin(),
101 HE = HandlerDataLocs.end(); HI != HE; ++HI)
102 Parser.Note(*HI, ".handlerdata was specified here");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +0000103 }
104 void emitPersonalityLocNotes() const {
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +0000105 for (Locs::const_iterator PI = PersonalityLocs.begin(),
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +0000106 PE = PersonalityLocs.end(),
107 PII = PersonalityIndexLocs.begin(),
108 PIE = PersonalityIndexLocs.end();
109 PI != PE || PII != PIE;) {
110 if (PI != PE && (PII == PIE || PI->getPointer() < PII->getPointer()))
111 Parser.Note(*PI++, ".personality was specified here");
112 else if (PII != PIE && (PI == PE || PII->getPointer() < PI->getPointer()))
113 Parser.Note(*PII++, ".personalityindex was specified here");
114 else
115 llvm_unreachable(".personality and .personalityindex cannot be "
116 "at the same location");
117 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +0000118 }
119
120 void reset() {
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +0000121 FnStartLocs = Locs();
122 CantUnwindLocs = Locs();
123 PersonalityLocs = Locs();
124 HandlerDataLocs = Locs();
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +0000125 PersonalityIndexLocs = Locs();
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +0000126 FPReg = ARM::SP;
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +0000127 }
128};
129
Evan Cheng11424442011-07-26 00:24:13 +0000130class ARMAsmParser : public MCTargetAsmParser {
Evan Cheng91111d22011-07-09 05:47:46 +0000131 MCSubtargetInfo &STI;
Joey Gouly0e76fa72013-09-12 10:28:05 +0000132 const MCInstrInfo &MII;
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000133 const MCRegisterInfo *MRI;
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +0000134 UnwindContext UC;
David Peixottoe407d092013-12-19 18:12:36 +0000135
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000136 ARMTargetStreamer &getTargetStreamer() {
Saleem Abdulrasoolbfdfb142014-09-18 04:28:29 +0000137 assert(getParser().getStreamer().getTargetStreamer() &&
138 "do not have a target streamer");
Rafael Espindola4a1a3602014-01-14 01:21:46 +0000139 MCTargetStreamer &TS = *getParser().getStreamer().getTargetStreamer();
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000140 return static_cast<ARMTargetStreamer &>(TS);
141 }
142
Jim Grosbachab5830e2011-12-14 02:16:11 +0000143 // Map of register aliases registers via the .req directive.
144 StringMap<unsigned> RegisterReqs;
145
Tim Northover1744d0a2013-10-25 12:49:50 +0000146 bool NextSymbolIsThumb;
147
Jim Grosbached16ec42011-08-29 22:24:09 +0000148 struct {
149 ARMCC::CondCodes Cond; // Condition for IT block.
150 unsigned Mask:4; // Condition mask for instructions.
151 // Starting at first 1 (from lsb).
152 // '1' condition as indicated in IT.
153 // '0' inverse of condition (else).
154 // Count of instructions in IT block is
155 // 4 - trailingzeroes(mask)
156
157 bool FirstCond; // Explicit flag for when we're parsing the
158 // First instruction in the IT block. It's
159 // implied in the mask, so needs special
160 // handling.
161
162 unsigned CurPosition; // Current position in parsing of IT
163 // block. In range [0,3]. Initialized
164 // according to count of instructions in block.
165 // ~0U if no active IT block.
166 } ITState;
Saleem Abdulrasool3a239172014-12-18 05:24:38 +0000167 bool inITBlock() { return ITState.CurPosition != ~0U; }
168 bool lastInITBlock() {
169 return ITState.CurPosition == 4 - countTrailingZeros(ITState.Mask);
170 }
Jim Grosbacha0d34d32011-09-02 23:22:08 +0000171 void forwardITPosition() {
172 if (!inITBlock()) return;
173 // Move to the next instruction in the IT block, if there is one. If not,
174 // mark the block as done.
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +0000175 unsigned TZ = countTrailingZeros(ITState.Mask);
Jim Grosbacha0d34d32011-09-02 23:22:08 +0000176 if (++ITState.CurPosition == 5 - TZ)
177 ITState.CurPosition = ~0U; // Done with the IT block after this.
178 }
Jim Grosbached16ec42011-08-29 22:24:09 +0000179
Saleem Abdulrasool69c7caf2014-01-07 02:28:31 +0000180 void Note(SMLoc L, const Twine &Msg, ArrayRef<SMRange> Ranges = None) {
Rafael Espindola961d4692014-11-11 05:18:41 +0000181 return getParser().Note(L, Msg, Ranges);
Saleem Abdulrasool69c7caf2014-01-07 02:28:31 +0000182 }
Benjamin Kramer673824b2012-04-15 17:04:27 +0000183 bool Warning(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000184 ArrayRef<SMRange> Ranges = None) {
Rafael Espindola961d4692014-11-11 05:18:41 +0000185 return getParser().Warning(L, Msg, Ranges);
Benjamin Kramer673824b2012-04-15 17:04:27 +0000186 }
187 bool Error(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000188 ArrayRef<SMRange> Ranges = None) {
Rafael Espindola961d4692014-11-11 05:18:41 +0000189 return getParser().Error(L, Msg, Ranges);
Benjamin Kramer673824b2012-04-15 17:04:27 +0000190 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000191
Saleem Abdulrasool3a239172014-12-18 05:24:38 +0000192 bool validatetLDMRegList(MCInst Inst, const OperandVector &Operands,
Jyoti Allur5a139142015-01-14 10:48:16 +0000193 unsigned ListNo, bool IsARPop = false);
Saleem Abdulrasool3a239172014-12-18 05:24:38 +0000194 bool validatetSTMRegList(MCInst Inst, const OperandVector &Operands,
195 unsigned ListNo);
196
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000197 int tryParseRegister();
David Blaikie960ea3f2014-06-08 16:18:35 +0000198 bool tryParseRegisterWithWriteBack(OperandVector &);
199 int tryParseShiftRegister(OperandVector &);
200 bool parseRegisterList(OperandVector &);
201 bool parseMemory(OperandVector &);
202 bool parseOperand(OperandVector &, StringRef Mnemonic);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000203 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
Jim Grosbachd3595712011-08-03 23:50:40 +0000204 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
205 unsigned &ShiftAmount);
Saleem Abdulrasool38976512014-02-23 06:22:09 +0000206 bool parseLiteralValues(unsigned Size, SMLoc L);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000207 bool parseDirectiveThumb(SMLoc L);
Jim Grosbach7f882392011-12-07 18:04:19 +0000208 bool parseDirectiveARM(SMLoc L);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000209 bool parseDirectiveThumbFunc(SMLoc L);
210 bool parseDirectiveCode(SMLoc L);
211 bool parseDirectiveSyntax(SMLoc L);
Jim Grosbachab5830e2011-12-14 02:16:11 +0000212 bool parseDirectiveReq(StringRef Name, SMLoc L);
213 bool parseDirectiveUnreq(SMLoc L);
Jason W Kim135d2442011-12-20 17:38:12 +0000214 bool parseDirectiveArch(SMLoc L);
215 bool parseDirectiveEabiAttr(SMLoc L);
Logan Chien8cbb80d2013-10-28 17:51:12 +0000216 bool parseDirectiveCPU(SMLoc L);
217 bool parseDirectiveFPU(SMLoc L);
Logan Chien4ea23b52013-05-10 16:17:24 +0000218 bool parseDirectiveFnStart(SMLoc L);
219 bool parseDirectiveFnEnd(SMLoc L);
220 bool parseDirectiveCantUnwind(SMLoc L);
221 bool parseDirectivePersonality(SMLoc L);
222 bool parseDirectiveHandlerData(SMLoc L);
223 bool parseDirectiveSetFP(SMLoc L);
224 bool parseDirectivePad(SMLoc L);
225 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +0000226 bool parseDirectiveInst(SMLoc L, char Suffix = '\0');
David Peixotto80c083a2013-12-19 18:26:07 +0000227 bool parseDirectiveLtorg(SMLoc L);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +0000228 bool parseDirectiveEven(SMLoc L);
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +0000229 bool parseDirectivePersonalityIndex(SMLoc L);
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +0000230 bool parseDirectiveUnwindRaw(SMLoc L);
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +0000231 bool parseDirectiveTLSDescSeq(SMLoc L);
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +0000232 bool parseDirectiveMovSP(SMLoc L);
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +0000233 bool parseDirectiveObjectArch(SMLoc L);
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +0000234 bool parseDirectiveArchExtension(SMLoc L);
Saleem Abdulrasoolfd6ed1e2014-02-23 17:45:32 +0000235 bool parseDirectiveAlign(SMLoc L);
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +0000236 bool parseDirectiveThumbSet(SMLoc L);
Kevin Enderby146dcf22009-10-15 20:48:48 +0000237
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000238 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000239 bool &CarrySetting, unsigned &ProcessorIMod,
240 StringRef &ITMask);
Amara Emerson33089092013-09-19 11:59:01 +0000241 void getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
242 bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +0000243 bool &CanAcceptPredicationCode);
Jim Grosbach624bcc72010-10-29 14:46:02 +0000244
Evan Cheng4d1ca962011-07-08 01:53:10 +0000245 bool isThumb() const {
246 // FIXME: Can tablegen auto-generate this?
Michael Kuperstein29704e72015-03-24 12:56:59 +0000247 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000248 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000249 bool isThumbOne() const {
Michael Kuperstein29704e72015-03-24 12:56:59 +0000250 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000251 }
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000252 bool isThumbTwo() const {
Michael Kuperstein29704e72015-03-24 12:56:59 +0000253 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000254 }
Tim Northovera2292d02013-06-10 23:20:58 +0000255 bool hasThumb() const {
Michael Kuperstein29704e72015-03-24 12:56:59 +0000256 return STI.getFeatureBits() & ARM::HasV4TOps;
Tim Northovera2292d02013-06-10 23:20:58 +0000257 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000258 bool hasV6Ops() const {
Michael Kuperstein29704e72015-03-24 12:56:59 +0000259 return STI.getFeatureBits() & ARM::HasV6Ops;
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000260 }
Tim Northoverf86d1f02013-10-07 11:10:47 +0000261 bool hasV6MOps() const {
Michael Kuperstein29704e72015-03-24 12:56:59 +0000262 return STI.getFeatureBits() & ARM::HasV6MOps;
Tim Northoverf86d1f02013-10-07 11:10:47 +0000263 }
James Molloy21efa7d2011-09-28 14:21:38 +0000264 bool hasV7Ops() const {
Michael Kuperstein29704e72015-03-24 12:56:59 +0000265 return STI.getFeatureBits() & ARM::HasV7Ops;
James Molloy21efa7d2011-09-28 14:21:38 +0000266 }
Joey Goulyb3f550e2013-06-26 16:58:26 +0000267 bool hasV8Ops() const {
Michael Kuperstein29704e72015-03-24 12:56:59 +0000268 return STI.getFeatureBits() & ARM::HasV8Ops;
Joey Goulyb3f550e2013-06-26 16:58:26 +0000269 }
Tim Northovera2292d02013-06-10 23:20:58 +0000270 bool hasARM() const {
Michael Kuperstein29704e72015-03-24 12:56:59 +0000271 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
Tim Northovera2292d02013-06-10 23:20:58 +0000272 }
Renato Golin92c816c2014-09-01 11:25:07 +0000273 bool hasThumb2DSP() const {
Michael Kuperstein29704e72015-03-24 12:56:59 +0000274 return STI.getFeatureBits() & ARM::FeatureDSPThumb2;
Renato Golin92c816c2014-09-01 11:25:07 +0000275 }
Oliver Stannard9e89d8c2014-11-05 12:06:39 +0000276 bool hasD16() const {
Michael Kuperstein29704e72015-03-24 12:56:59 +0000277 return STI.getFeatureBits() & ARM::FeatureD16;
Oliver Stannard9e89d8c2014-11-05 12:06:39 +0000278 }
Vladimir Sukharev2afdb322015-04-01 14:54:56 +0000279 bool hasV8_1aOps() const {
280 return STI.getFeatureBits() & ARM::HasV8_1aOps;
Vladimir Sukharevc632cda2015-03-26 17:05:54 +0000281 }
Tim Northovera2292d02013-06-10 23:20:58 +0000282
Evan Cheng284b4672011-07-08 22:36:29 +0000283 void SwitchMode() {
Tim Northover26bb14e2014-08-18 11:49:42 +0000284 uint64_t FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
Evan Cheng91111d22011-07-09 05:47:46 +0000285 setAvailableFeatures(FB);
Evan Cheng284b4672011-07-08 22:36:29 +0000286 }
James Molloy21efa7d2011-09-28 14:21:38 +0000287 bool isMClass() const {
Michael Kuperstein29704e72015-03-24 12:56:59 +0000288 return STI.getFeatureBits() & ARM::FeatureMClass;
James Molloy21efa7d2011-09-28 14:21:38 +0000289 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000290
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000291 /// @name Auto-generated Match Functions
292 /// {
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +0000293
Chris Lattner3e4582a2010-09-06 19:11:01 +0000294#define GET_ASSEMBLER_HEADER
295#include "ARMGenAsmMatcher.inc"
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000296
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000297 /// }
298
David Blaikie960ea3f2014-06-08 16:18:35 +0000299 OperandMatchResultTy parseITCondCode(OperandVector &);
300 OperandMatchResultTy parseCoprocNumOperand(OperandVector &);
301 OperandMatchResultTy parseCoprocRegOperand(OperandVector &);
302 OperandMatchResultTy parseCoprocOptionOperand(OperandVector &);
303 OperandMatchResultTy parseMemBarrierOptOperand(OperandVector &);
304 OperandMatchResultTy parseInstSyncBarrierOptOperand(OperandVector &);
305 OperandMatchResultTy parseProcIFlagsOperand(OperandVector &);
306 OperandMatchResultTy parseMSRMaskOperand(OperandVector &);
Tim Northoveree843ef2014-08-15 10:47:12 +0000307 OperandMatchResultTy parseBankedRegOperand(OperandVector &);
David Blaikie960ea3f2014-06-08 16:18:35 +0000308 OperandMatchResultTy parsePKHImm(OperandVector &O, StringRef Op, int Low,
309 int High);
310 OperandMatchResultTy parsePKHLSLImm(OperandVector &O) {
Jim Grosbach27c1e252011-07-21 17:23:04 +0000311 return parsePKHImm(O, "lsl", 0, 31);
312 }
David Blaikie960ea3f2014-06-08 16:18:35 +0000313 OperandMatchResultTy parsePKHASRImm(OperandVector &O) {
Jim Grosbach27c1e252011-07-21 17:23:04 +0000314 return parsePKHImm(O, "asr", 1, 32);
315 }
David Blaikie960ea3f2014-06-08 16:18:35 +0000316 OperandMatchResultTy parseSetEndImm(OperandVector &);
317 OperandMatchResultTy parseShifterImm(OperandVector &);
318 OperandMatchResultTy parseRotImm(OperandVector &);
Asiri Rathnayakea0199b92014-12-02 10:53:20 +0000319 OperandMatchResultTy parseModImm(OperandVector &);
David Blaikie960ea3f2014-06-08 16:18:35 +0000320 OperandMatchResultTy parseBitfield(OperandVector &);
321 OperandMatchResultTy parsePostIdxReg(OperandVector &);
322 OperandMatchResultTy parseAM3Offset(OperandVector &);
323 OperandMatchResultTy parseFPImm(OperandVector &);
324 OperandMatchResultTy parseVectorList(OperandVector &);
Jordan Rosee8f1eae2013-01-07 19:00:49 +0000325 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
326 SMLoc &EndLoc);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000327
328 // Asm Match Converter Methods
David Blaikie960ea3f2014-06-08 16:18:35 +0000329 void cvtThumbMultiply(MCInst &Inst, const OperandVector &);
330 void cvtThumbBranches(MCInst &Inst, const OperandVector &);
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +0000331
David Blaikie960ea3f2014-06-08 16:18:35 +0000332 bool validateInstruction(MCInst &Inst, const OperandVector &Ops);
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +0000333 bool processInstruction(MCInst &Inst, const OperandVector &Ops, MCStreamer &Out);
David Blaikie960ea3f2014-06-08 16:18:35 +0000334 bool shouldOmitCCOutOperand(StringRef Mnemonic, OperandVector &Operands);
335 bool shouldOmitPredicateOperand(StringRef Mnemonic, OperandVector &Operands);
336
Kevin Enderbyccab3172009-09-15 00:27:25 +0000337public:
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000338 enum ARMMatchResultTy {
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000339 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbached16ec42011-08-29 22:24:09 +0000340 Match_RequiresNotITBlock,
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000341 Match_RequiresV6,
Jim Grosbach087affe2012-06-22 23:56:48 +0000342 Match_RequiresThumb2,
343#define GET_OPERAND_DIAGNOSTIC_TYPES
344#include "ARMGenAsmMatcher.inc"
345
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000346 };
347
David Blaikie9f380a32015-03-16 18:06:57 +0000348 ARMAsmParser(MCSubtargetInfo &STI, MCAsmParser &Parser,
Rafael Espindola961d4692014-11-11 05:18:41 +0000349 const MCInstrInfo &MII, const MCTargetOptions &Options)
David Blaikie9f380a32015-03-16 18:06:57 +0000350 : STI(STI), MII(MII), UC(Parser) {
351 MCAsmParserExtension::Initialize(Parser);
Evan Cheng284b4672011-07-08 22:36:29 +0000352
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000353 // Cache the MCRegisterInfo.
Bill Wendlingbc07a892013-06-18 07:20:20 +0000354 MRI = getContext().getRegisterInfo();
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000355
Evan Cheng4d1ca962011-07-08 01:53:10 +0000356 // Initialize the set of available features.
Evan Cheng91111d22011-07-09 05:47:46 +0000357 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbached16ec42011-08-29 22:24:09 +0000358
359 // Not in an ITBlock to start with.
360 ITState.CurPosition = ~0U;
Tim Northover1744d0a2013-10-25 12:49:50 +0000361
362 NextSymbolIsThumb = false;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000363 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000364
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000365 // Implementation of the MCTargetAsmParser interface:
Craig Topperca7e3e52014-03-10 03:19:03 +0000366 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc) override;
David Blaikie960ea3f2014-06-08 16:18:35 +0000367 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
368 SMLoc NameLoc, OperandVector &Operands) override;
Craig Topperca7e3e52014-03-10 03:19:03 +0000369 bool ParseDirective(AsmToken DirectiveID) override;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000370
David Blaikie960ea3f2014-06-08 16:18:35 +0000371 unsigned validateTargetOperandClass(MCParsedAsmOperand &Op,
Craig Topperca7e3e52014-03-10 03:19:03 +0000372 unsigned Kind) override;
373 unsigned checkTargetMatchPredicate(MCInst &Inst) override;
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000374
Chad Rosier49963552012-10-13 00:26:04 +0000375 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
David Blaikie960ea3f2014-06-08 16:18:35 +0000376 OperandVector &Operands, MCStreamer &Out,
Tim Northover26bb14e2014-08-18 11:49:42 +0000377 uint64_t &ErrorInfo,
Craig Topperca7e3e52014-03-10 03:19:03 +0000378 bool MatchingInlineAsm) override;
379 void onLabelParsed(MCSymbol *Symbol) override;
Kevin Enderbyccab3172009-09-15 00:27:25 +0000380};
Jim Grosbach624bcc72010-10-29 14:46:02 +0000381} // end anonymous namespace
382
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +0000383namespace {
384
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000385/// ARMOperand - Instances of this class represent a parsed ARM machine
Joel Jones54597542013-01-09 22:34:16 +0000386/// operand.
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000387class ARMOperand : public MCParsedAsmOperand {
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000388 enum KindTy {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000389 k_CondCode,
390 k_CCOut,
391 k_ITCondMask,
392 k_CoprocNum,
393 k_CoprocReg,
Jim Grosbach48399582011-10-12 17:34:41 +0000394 k_CoprocOption,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000395 k_Immediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000396 k_MemBarrierOpt,
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000397 k_InstSyncBarrierOpt,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000398 k_Memory,
399 k_PostIndexRegister,
400 k_MSRMask,
Tim Northoveree843ef2014-08-15 10:47:12 +0000401 k_BankedReg,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000402 k_ProcIFlags,
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000403 k_VectorIndex,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000404 k_Register,
405 k_RegisterList,
406 k_DPRRegisterList,
407 k_SPRRegisterList,
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000408 k_VectorList,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000409 k_VectorListAllLanes,
Jim Grosbach04945c42011-12-02 00:35:16 +0000410 k_VectorListIndexed,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000411 k_ShiftedRegister,
412 k_ShiftedImmediate,
413 k_ShifterImmediate,
414 k_RotateImmediate,
Asiri Rathnayakea0199b92014-12-02 10:53:20 +0000415 k_ModifiedImmediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000416 k_BitfieldDescriptor,
417 k_Token
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000418 } Kind;
419
Kevin Enderby488f20b2014-04-10 20:18:58 +0000420 SMLoc StartLoc, EndLoc, AlignmentLoc;
Bill Wendling0ab0f672010-11-18 21:50:54 +0000421 SmallVector<unsigned, 8> Registers;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000422
Eric Christopher8996c5d2013-03-15 00:42:55 +0000423 struct CCOp {
424 ARMCC::CondCodes Val;
425 };
426
427 struct CopOp {
428 unsigned Val;
429 };
430
431 struct CoprocOptionOp {
432 unsigned Val;
433 };
434
435 struct ITMaskOp {
436 unsigned Mask:4;
437 };
438
439 struct MBOptOp {
440 ARM_MB::MemBOpt Val;
441 };
442
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000443 struct ISBOptOp {
444 ARM_ISB::InstSyncBOpt Val;
445 };
446
Eric Christopher8996c5d2013-03-15 00:42:55 +0000447 struct IFlagsOp {
448 ARM_PROC::IFlags Val;
449 };
450
451 struct MMaskOp {
452 unsigned Val;
453 };
454
Tim Northoveree843ef2014-08-15 10:47:12 +0000455 struct BankedRegOp {
456 unsigned Val;
457 };
458
Eric Christopher8996c5d2013-03-15 00:42:55 +0000459 struct TokOp {
460 const char *Data;
461 unsigned Length;
462 };
463
464 struct RegOp {
465 unsigned RegNum;
466 };
467
468 // A vector register list is a sequential list of 1 to 4 registers.
469 struct VectorListOp {
470 unsigned RegNum;
471 unsigned Count;
472 unsigned LaneIndex;
473 bool isDoubleSpaced;
474 };
475
476 struct VectorIndexOp {
477 unsigned Val;
478 };
479
480 struct ImmOp {
481 const MCExpr *Val;
482 };
483
484 /// Combined record for all forms of ARM address expressions.
485 struct MemoryOp {
486 unsigned BaseRegNum;
487 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
488 // was specified.
489 const MCConstantExpr *OffsetImm; // Offset immediate value
490 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
491 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
492 unsigned ShiftImm; // shift for OffsetReg.
493 unsigned Alignment; // 0 = no alignment specified
494 // n = alignment in bytes (2, 4, 8, 16, or 32)
495 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
496 };
497
498 struct PostIdxRegOp {
499 unsigned RegNum;
500 bool isAdd;
501 ARM_AM::ShiftOpc ShiftTy;
502 unsigned ShiftImm;
503 };
504
505 struct ShifterImmOp {
506 bool isASR;
507 unsigned Imm;
508 };
509
510 struct RegShiftedRegOp {
511 ARM_AM::ShiftOpc ShiftTy;
512 unsigned SrcReg;
513 unsigned ShiftReg;
514 unsigned ShiftImm;
515 };
516
517 struct RegShiftedImmOp {
518 ARM_AM::ShiftOpc ShiftTy;
519 unsigned SrcReg;
520 unsigned ShiftImm;
521 };
522
523 struct RotImmOp {
524 unsigned Imm;
525 };
526
Asiri Rathnayakea0199b92014-12-02 10:53:20 +0000527 struct ModImmOp {
528 unsigned Bits;
529 unsigned Rot;
530 };
531
Eric Christopher8996c5d2013-03-15 00:42:55 +0000532 struct BitfieldOp {
533 unsigned LSB;
534 unsigned Width;
535 };
536
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000537 union {
Eric Christopher8996c5d2013-03-15 00:42:55 +0000538 struct CCOp CC;
539 struct CopOp Cop;
540 struct CoprocOptionOp CoprocOption;
541 struct MBOptOp MBOpt;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000542 struct ISBOptOp ISBOpt;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000543 struct ITMaskOp ITMask;
544 struct IFlagsOp IFlags;
545 struct MMaskOp MMask;
Tim Northoveree843ef2014-08-15 10:47:12 +0000546 struct BankedRegOp BankedReg;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000547 struct TokOp Tok;
548 struct RegOp Reg;
549 struct VectorListOp VectorList;
550 struct VectorIndexOp VectorIndex;
551 struct ImmOp Imm;
552 struct MemoryOp Memory;
553 struct PostIdxRegOp PostIdxReg;
554 struct ShifterImmOp ShifterImm;
555 struct RegShiftedRegOp RegShiftedReg;
556 struct RegShiftedImmOp RegShiftedImm;
557 struct RotImmOp RotImm;
Asiri Rathnayakea0199b92014-12-02 10:53:20 +0000558 struct ModImmOp ModImm;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000559 struct BitfieldOp Bitfield;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000560 };
Jim Grosbach624bcc72010-10-29 14:46:02 +0000561
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000562public:
David Blaikie960ea3f2014-06-08 16:18:35 +0000563 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000564 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
565 Kind = o.Kind;
566 StartLoc = o.StartLoc;
567 EndLoc = o.EndLoc;
568 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000569 case k_CondCode:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000570 CC = o.CC;
571 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000572 case k_ITCondMask:
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000573 ITMask = o.ITMask;
574 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000575 case k_Token:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000576 Tok = o.Tok;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000577 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000578 case k_CCOut:
579 case k_Register:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000580 Reg = o.Reg;
581 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000582 case k_RegisterList:
583 case k_DPRRegisterList:
584 case k_SPRRegisterList:
Bill Wendling0ab0f672010-11-18 21:50:54 +0000585 Registers = o.Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000586 break;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000587 case k_VectorList:
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000588 case k_VectorListAllLanes:
Jim Grosbach04945c42011-12-02 00:35:16 +0000589 case k_VectorListIndexed:
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000590 VectorList = o.VectorList;
591 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000592 case k_CoprocNum:
593 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000594 Cop = o.Cop;
595 break;
Jim Grosbach48399582011-10-12 17:34:41 +0000596 case k_CoprocOption:
597 CoprocOption = o.CoprocOption;
598 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000599 case k_Immediate:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000600 Imm = o.Imm;
601 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000602 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000603 MBOpt = o.MBOpt;
604 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000605 case k_InstSyncBarrierOpt:
606 ISBOpt = o.ISBOpt;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000607 case k_Memory:
Jim Grosbach871dff72011-10-11 15:59:20 +0000608 Memory = o.Memory;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000609 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000610 case k_PostIndexRegister:
Jim Grosbachd3595712011-08-03 23:50:40 +0000611 PostIdxReg = o.PostIdxReg;
612 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000613 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000614 MMask = o.MMask;
615 break;
Tim Northoveree843ef2014-08-15 10:47:12 +0000616 case k_BankedReg:
617 BankedReg = o.BankedReg;
618 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000619 case k_ProcIFlags:
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000620 IFlags = o.IFlags;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000621 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000622 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000623 ShifterImm = o.ShifterImm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000624 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000625 case k_ShiftedRegister:
Jim Grosbachac798e12011-07-25 20:49:51 +0000626 RegShiftedReg = o.RegShiftedReg;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000627 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000628 case k_ShiftedImmediate:
Jim Grosbachac798e12011-07-25 20:49:51 +0000629 RegShiftedImm = o.RegShiftedImm;
Owen Andersonb595ed02011-07-21 18:54:16 +0000630 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000631 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +0000632 RotImm = o.RotImm;
633 break;
Asiri Rathnayakea0199b92014-12-02 10:53:20 +0000634 case k_ModifiedImmediate:
635 ModImm = o.ModImm;
636 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000637 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +0000638 Bitfield = o.Bitfield;
639 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000640 case k_VectorIndex:
641 VectorIndex = o.VectorIndex;
642 break;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000643 }
644 }
Jim Grosbach624bcc72010-10-29 14:46:02 +0000645
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000646 /// getStartLoc - Get the location of the first token of this operand.
Craig Topperca7e3e52014-03-10 03:19:03 +0000647 SMLoc getStartLoc() const override { return StartLoc; }
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000648 /// getEndLoc - Get the location of the last token of this operand.
Craig Topperca7e3e52014-03-10 03:19:03 +0000649 SMLoc getEndLoc() const override { return EndLoc; }
Chad Rosier143d0f72012-09-21 20:51:43 +0000650 /// getLocRange - Get the range between the first and last token of this
651 /// operand.
Benjamin Kramer673824b2012-04-15 17:04:27 +0000652 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
653
Kevin Enderby488f20b2014-04-10 20:18:58 +0000654 /// getAlignmentLoc - Get the location of the Alignment token of this operand.
655 SMLoc getAlignmentLoc() const {
656 assert(Kind == k_Memory && "Invalid access!");
657 return AlignmentLoc;
658 }
659
Daniel Dunbard8042b72010-08-11 06:36:53 +0000660 ARMCC::CondCodes getCondCode() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000661 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbard8042b72010-08-11 06:36:53 +0000662 return CC.Val;
663 }
664
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000665 unsigned getCoproc() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000666 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000667 return Cop.Val;
668 }
669
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000670 StringRef getToken() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000671 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000672 return StringRef(Tok.Data, Tok.Length);
673 }
674
Craig Topperca7e3e52014-03-10 03:19:03 +0000675 unsigned getReg() const override {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000676 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling2cae3272010-11-09 22:44:22 +0000677 return Reg.RegNum;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000678 }
679
Bill Wendlingbed94652010-11-09 23:28:44 +0000680 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000681 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
682 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling0ab0f672010-11-18 21:50:54 +0000683 return Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000684 }
685
Kevin Enderbyf5079942009-10-13 22:19:02 +0000686 const MCExpr *getImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000687 assert(isImm() && "Invalid access!");
Kevin Enderbyf5079942009-10-13 22:19:02 +0000688 return Imm.Val;
689 }
690
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000691 unsigned getVectorIndex() const {
692 assert(Kind == k_VectorIndex && "Invalid access!");
693 return VectorIndex.Val;
694 }
695
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000696 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000697 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000698 return MBOpt.Val;
699 }
700
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000701 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
702 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
703 return ISBOpt.Val;
704 }
705
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000706 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000707 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000708 return IFlags.Val;
709 }
710
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000711 unsigned getMSRMask() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000712 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000713 return MMask.Val;
714 }
715
Tim Northoveree843ef2014-08-15 10:47:12 +0000716 unsigned getBankedReg() const {
717 assert(Kind == k_BankedReg && "Invalid access!");
718 return BankedReg.Val;
719 }
720
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000721 bool isCoprocNum() const { return Kind == k_CoprocNum; }
722 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach48399582011-10-12 17:34:41 +0000723 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000724 bool isCondCode() const { return Kind == k_CondCode; }
725 bool isCCOut() const { return Kind == k_CCOut; }
726 bool isITMask() const { return Kind == k_ITCondMask; }
727 bool isITCondCode() const { return Kind == k_CondCode; }
Craig Topperca7e3e52014-03-10 03:19:03 +0000728 bool isImm() const override { return Kind == k_Immediate; }
Mihai Popad36cbaa2013-07-03 09:21:44 +0000729 // checks whether this operand is an unsigned offset which fits is a field
730 // of specified width and scaled by a specific number of bits
731 template<unsigned width, unsigned scale>
732 bool isUnsignedOffset() const {
733 if (!isImm()) return false;
Mihai Popaad18d3c2013-08-09 10:38:32 +0000734 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
Mihai Popad36cbaa2013-07-03 09:21:44 +0000735 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
736 int64_t Val = CE->getValue();
737 int64_t Align = 1LL << scale;
738 int64_t Max = Align * ((1LL << width) - 1);
739 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
740 }
741 return false;
742 }
Mihai Popaad18d3c2013-08-09 10:38:32 +0000743 // checks whether this operand is an signed offset which fits is a field
744 // of specified width and scaled by a specific number of bits
745 template<unsigned width, unsigned scale>
746 bool isSignedOffset() const {
747 if (!isImm()) return false;
748 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
749 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
750 int64_t Val = CE->getValue();
751 int64_t Align = 1LL << scale;
752 int64_t Max = Align * ((1LL << (width-1)) - 1);
753 int64_t Min = -Align * (1LL << (width-1));
754 return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max);
755 }
756 return false;
757 }
758
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000759 // checks whether this operand is a memory operand computed as an offset
760 // applied to PC. the offset may have 8 bits of magnitude and is represented
761 // with two bits of shift. textually it may be either [pc, #imm], #imm or
762 // relocable expression...
763 bool isThumbMemPC() const {
764 int64_t Val = 0;
765 if (isImm()) {
766 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
767 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val);
768 if (!CE) return false;
769 Val = CE->getValue();
770 }
771 else if (isMem()) {
772 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false;
773 if(Memory.BaseRegNum != ARM::PC) return false;
774 Val = Memory.OffsetImm->getValue();
775 }
776 else return false;
Mihai Popad79f00b2013-08-15 15:43:06 +0000777 return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020);
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000778 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +0000779 bool isFPImm() const {
780 if (!isImm()) return false;
781 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
782 if (!CE) return false;
783 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
784 return Val != -1;
785 }
Jim Grosbachea231912011-12-22 22:19:05 +0000786 bool isFBits16() const {
787 if (!isImm()) return false;
788 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
789 if (!CE) return false;
790 int64_t Value = CE->getValue();
791 return Value >= 0 && Value <= 16;
792 }
793 bool isFBits32() const {
794 if (!isImm()) return false;
795 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
796 if (!CE) return false;
797 int64_t Value = CE->getValue();
798 return Value >= 1 && Value <= 32;
799 }
Jim Grosbach7db8d692011-09-08 22:07:06 +0000800 bool isImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000801 if (!isImm()) return false;
Jim Grosbach7db8d692011-09-08 22:07:06 +0000802 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
803 if (!CE) return false;
804 int64_t Value = CE->getValue();
805 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
806 }
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000807 bool isImm0_1020s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000808 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000809 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
810 if (!CE) return false;
811 int64_t Value = CE->getValue();
812 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
813 }
814 bool isImm0_508s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000815 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000816 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
817 if (!CE) return false;
818 int64_t Value = CE->getValue();
819 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
820 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000821 bool isImm0_508s4Neg() const {
822 if (!isImm()) return false;
823 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
824 if (!CE) return false;
825 int64_t Value = -CE->getValue();
826 // explicitly exclude zero. we want that to use the normal 0_508 version.
827 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
828 }
Artyom Skrobovfc12e702013-10-23 10:14:40 +0000829 bool isImm0_239() const {
830 if (!isImm()) return false;
831 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
832 if (!CE) return false;
833 int64_t Value = CE->getValue();
834 return Value >= 0 && Value < 240;
835 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000836 bool isImm0_255() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000837 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000838 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
839 if (!CE) return false;
840 int64_t Value = CE->getValue();
841 return Value >= 0 && Value < 256;
842 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000843 bool isImm0_4095() const {
844 if (!isImm()) return false;
845 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
846 if (!CE) return false;
847 int64_t Value = CE->getValue();
848 return Value >= 0 && Value < 4096;
849 }
850 bool isImm0_4095Neg() const {
851 if (!isImm()) return false;
852 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
853 if (!CE) return false;
854 int64_t Value = -CE->getValue();
855 return Value > 0 && Value < 4096;
856 }
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000857 bool isImm0_1() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000858 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000859 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
860 if (!CE) return false;
861 int64_t Value = CE->getValue();
862 return Value >= 0 && Value < 2;
863 }
864 bool isImm0_3() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000865 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000866 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
867 if (!CE) return false;
868 int64_t Value = CE->getValue();
869 return Value >= 0 && Value < 4;
870 }
Jim Grosbach31756c22011-07-13 22:01:08 +0000871 bool isImm0_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000872 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000873 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
874 if (!CE) return false;
875 int64_t Value = CE->getValue();
876 return Value >= 0 && Value < 8;
877 }
878 bool isImm0_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000879 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000880 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
881 if (!CE) return false;
882 int64_t Value = CE->getValue();
883 return Value >= 0 && Value < 16;
884 }
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000885 bool isImm0_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000886 if (!isImm()) return false;
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000887 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
888 if (!CE) return false;
889 int64_t Value = CE->getValue();
890 return Value >= 0 && Value < 32;
891 }
Jim Grosbach00326402011-12-08 01:30:04 +0000892 bool isImm0_63() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000893 if (!isImm()) return false;
Jim Grosbach00326402011-12-08 01:30:04 +0000894 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
895 if (!CE) return false;
896 int64_t Value = CE->getValue();
897 return Value >= 0 && Value < 64;
898 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000899 bool isImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000900 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000901 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
902 if (!CE) return false;
903 int64_t Value = CE->getValue();
904 return Value == 8;
905 }
906 bool isImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000907 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000908 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
909 if (!CE) return false;
910 int64_t Value = CE->getValue();
911 return Value == 16;
912 }
913 bool isImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000914 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000915 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
916 if (!CE) return false;
917 int64_t Value = CE->getValue();
918 return Value == 32;
919 }
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000920 bool isShrImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000921 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000922 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
923 if (!CE) return false;
924 int64_t Value = CE->getValue();
925 return Value > 0 && Value <= 8;
926 }
927 bool isShrImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000928 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000929 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
930 if (!CE) return false;
931 int64_t Value = CE->getValue();
932 return Value > 0 && Value <= 16;
933 }
934 bool isShrImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000935 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000936 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
937 if (!CE) return false;
938 int64_t Value = CE->getValue();
939 return Value > 0 && Value <= 32;
940 }
941 bool isShrImm64() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000942 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000943 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
944 if (!CE) return false;
945 int64_t Value = CE->getValue();
946 return Value > 0 && Value <= 64;
947 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000948 bool isImm1_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000949 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000950 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
951 if (!CE) return false;
952 int64_t Value = CE->getValue();
953 return Value > 0 && Value < 8;
954 }
955 bool isImm1_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000956 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000957 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
958 if (!CE) return false;
959 int64_t Value = CE->getValue();
960 return Value > 0 && Value < 16;
961 }
962 bool isImm1_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000963 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000964 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
965 if (!CE) return false;
966 int64_t Value = CE->getValue();
967 return Value > 0 && Value < 32;
968 }
Jim Grosbach475c6db2011-07-25 23:09:14 +0000969 bool isImm1_16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000970 if (!isImm()) return false;
Jim Grosbach475c6db2011-07-25 23:09:14 +0000971 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
972 if (!CE) return false;
973 int64_t Value = CE->getValue();
974 return Value > 0 && Value < 17;
975 }
Jim Grosbach801e0a32011-07-22 23:16:18 +0000976 bool isImm1_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000977 if (!isImm()) return false;
Jim Grosbach801e0a32011-07-22 23:16:18 +0000978 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
979 if (!CE) return false;
980 int64_t Value = CE->getValue();
981 return Value > 0 && Value < 33;
982 }
Jim Grosbachc14871c2011-11-10 19:18:01 +0000983 bool isImm0_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000984 if (!isImm()) return false;
Jim Grosbachc14871c2011-11-10 19:18:01 +0000985 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
986 if (!CE) return false;
987 int64_t Value = CE->getValue();
988 return Value >= 0 && Value < 33;
989 }
Jim Grosbach975b6412011-07-13 20:10:10 +0000990 bool isImm0_65535() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000991 if (!isImm()) return false;
Jim Grosbach975b6412011-07-13 20:10:10 +0000992 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
993 if (!CE) return false;
994 int64_t Value = CE->getValue();
995 return Value >= 0 && Value < 65536;
996 }
Mihai Popaae1112b2013-08-21 13:14:58 +0000997 bool isImm256_65535Expr() const {
998 if (!isImm()) return false;
999 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1000 // If it's not a constant expression, it'll generate a fixup and be
1001 // handled later.
1002 if (!CE) return true;
1003 int64_t Value = CE->getValue();
1004 return Value >= 256 && Value < 65536;
1005 }
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00001006 bool isImm0_65535Expr() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001007 if (!isImm()) return false;
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00001008 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1009 // If it's not a constant expression, it'll generate a fixup and be
1010 // handled later.
1011 if (!CE) return true;
1012 int64_t Value = CE->getValue();
1013 return Value >= 0 && Value < 65536;
1014 }
Jim Grosbachf1637842011-07-26 16:24:27 +00001015 bool isImm24bit() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001016 if (!isImm()) return false;
Jim Grosbachf1637842011-07-26 16:24:27 +00001017 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1018 if (!CE) return false;
1019 int64_t Value = CE->getValue();
1020 return Value >= 0 && Value <= 0xffffff;
1021 }
Jim Grosbach46dd4132011-08-17 21:51:27 +00001022 bool isImmThumbSR() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001023 if (!isImm()) return false;
Jim Grosbach46dd4132011-08-17 21:51:27 +00001024 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1025 if (!CE) return false;
1026 int64_t Value = CE->getValue();
1027 return Value > 0 && Value < 33;
1028 }
Jim Grosbach27c1e252011-07-21 17:23:04 +00001029 bool isPKHLSLImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001030 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +00001031 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1032 if (!CE) return false;
1033 int64_t Value = CE->getValue();
1034 return Value >= 0 && Value < 32;
1035 }
1036 bool isPKHASRImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001037 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +00001038 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1039 if (!CE) return false;
1040 int64_t Value = CE->getValue();
1041 return Value > 0 && Value <= 32;
1042 }
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001043 bool isAdrLabel() const {
1044 // If we have an immediate that's not a constant, treat it as a label
Asiri Rathnayake52376ac2015-01-06 15:55:09 +00001045 // reference needing a fixup.
1046 if (isImm() && !isa<MCConstantExpr>(getImm()))
1047 return true;
1048
1049 // If it is a constant, it must fit into a modified immediate encoding.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001050 if (!isImm()) return false;
Jim Grosbach9720dcf2011-07-19 16:50:30 +00001051 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1052 if (!CE) return false;
1053 int64_t Value = CE->getValue();
Asiri Rathnayake52376ac2015-01-06 15:55:09 +00001054 return (ARM_AM::getSOImmVal(Value) != -1 ||
Asiri Rathnayake77436f82015-01-07 11:22:58 +00001055 ARM_AM::getSOImmVal(-Value) != -1);;
Jim Grosbach30506252011-12-08 00:31:07 +00001056 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +00001057 bool isT2SOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001058 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +00001059 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1060 if (!CE) return false;
1061 int64_t Value = CE->getValue();
1062 return ARM_AM::getT2SOImmVal(Value) != -1;
1063 }
Jim Grosbachb009a872011-10-28 22:36:30 +00001064 bool isT2SOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001065 if (!isImm()) return false;
Jim Grosbachb009a872011-10-28 22:36:30 +00001066 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1067 if (!CE) return false;
1068 int64_t Value = CE->getValue();
Mihai Popacf276b22013-08-16 11:55:44 +00001069 return ARM_AM::getT2SOImmVal(Value) == -1 &&
1070 ARM_AM::getT2SOImmVal(~Value) != -1;
Jim Grosbachb009a872011-10-28 22:36:30 +00001071 }
Jim Grosbach30506252011-12-08 00:31:07 +00001072 bool isT2SOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001073 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +00001074 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1075 if (!CE) return false;
1076 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +00001077 // Only use this when not representable as a plain so_imm.
1078 return ARM_AM::getT2SOImmVal(Value) == -1 &&
1079 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +00001080 }
Jim Grosbach0a547702011-07-22 17:44:50 +00001081 bool isSetEndImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001082 if (!isImm()) return false;
Jim Grosbach0a547702011-07-22 17:44:50 +00001083 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1084 if (!CE) return false;
1085 int64_t Value = CE->getValue();
1086 return Value == 1 || Value == 0;
1087 }
Craig Topperca7e3e52014-03-10 03:19:03 +00001088 bool isReg() const override { return Kind == k_Register; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001089 bool isRegList() const { return Kind == k_RegisterList; }
1090 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
1091 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
Craig Topperca7e3e52014-03-10 03:19:03 +00001092 bool isToken() const override { return Kind == k_Token; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001093 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00001094 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
Craig Topperca7e3e52014-03-10 03:19:03 +00001095 bool isMem() const override { return Kind == k_Memory; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001096 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
1097 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
1098 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
1099 bool isRotImm() const { return Kind == k_RotateImmediate; }
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00001100 bool isModImm() const { return Kind == k_ModifiedImmediate; }
1101 bool isModImmNot() const {
1102 if (!isImm()) return false;
1103 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1104 if (!CE) return false;
1105 int64_t Value = CE->getValue();
1106 return ARM_AM::getSOImmVal(~Value) != -1;
1107 }
1108 bool isModImmNeg() const {
1109 if (!isImm()) return false;
1110 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1111 if (!CE) return false;
1112 int64_t Value = CE->getValue();
1113 return ARM_AM::getSOImmVal(Value) == -1 &&
1114 ARM_AM::getSOImmVal(-Value) != -1;
1115 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001116 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
1117 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachc320c852011-08-05 21:28:30 +00001118 bool isPostIdxReg() const {
Jim Grosbachee201fa2011-11-14 17:52:47 +00001119 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachc320c852011-08-05 21:28:30 +00001120 }
Kevin Enderby488f20b2014-04-10 20:18:58 +00001121 bool isMemNoOffset(bool alignOK = false, unsigned Alignment = 0) const {
Chad Rosier41099832012-09-11 23:02:35 +00001122 if (!isMem())
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001123 return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001124 // No offset of any kind.
Craig Topper062a2ba2014-04-25 05:30:21 +00001125 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == nullptr &&
Kevin Enderby488f20b2014-04-10 20:18:58 +00001126 (alignOK || Memory.Alignment == Alignment);
Jim Grosbacha95ec992011-10-11 17:29:55 +00001127 }
Jim Grosbach94298a92012-01-18 22:46:46 +00001128 bool isMemPCRelImm12() const {
Chad Rosier41099832012-09-11 23:02:35 +00001129 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach94298a92012-01-18 22:46:46 +00001130 return false;
1131 // Base register must be PC.
1132 if (Memory.BaseRegNum != ARM::PC)
1133 return false;
1134 // Immediate offset in range [-4095, 4095].
1135 if (!Memory.OffsetImm) return true;
1136 int64_t Val = Memory.OffsetImm->getValue();
1137 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1138 }
Jim Grosbacha95ec992011-10-11 17:29:55 +00001139 bool isAlignedMemory() const {
1140 return isMemNoOffset(true);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001141 }
Kevin Enderby488f20b2014-04-10 20:18:58 +00001142 bool isAlignedMemoryNone() const {
1143 return isMemNoOffset(false, 0);
1144 }
1145 bool isDupAlignedMemoryNone() const {
1146 return isMemNoOffset(false, 0);
1147 }
1148 bool isAlignedMemory16() const {
1149 if (isMemNoOffset(false, 2)) // alignment in bytes for 16-bits is 2.
1150 return true;
1151 return isMemNoOffset(false, 0);
1152 }
1153 bool isDupAlignedMemory16() const {
1154 if (isMemNoOffset(false, 2)) // alignment in bytes for 16-bits is 2.
1155 return true;
1156 return isMemNoOffset(false, 0);
1157 }
1158 bool isAlignedMemory32() const {
1159 if (isMemNoOffset(false, 4)) // alignment in bytes for 32-bits is 4.
1160 return true;
1161 return isMemNoOffset(false, 0);
1162 }
1163 bool isDupAlignedMemory32() const {
1164 if (isMemNoOffset(false, 4)) // alignment in bytes for 32-bits is 4.
1165 return true;
1166 return isMemNoOffset(false, 0);
1167 }
1168 bool isAlignedMemory64() const {
1169 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1170 return true;
1171 return isMemNoOffset(false, 0);
1172 }
1173 bool isDupAlignedMemory64() const {
1174 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1175 return true;
1176 return isMemNoOffset(false, 0);
1177 }
1178 bool isAlignedMemory64or128() const {
1179 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1180 return true;
1181 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
1182 return true;
1183 return isMemNoOffset(false, 0);
1184 }
1185 bool isDupAlignedMemory64or128() const {
1186 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1187 return true;
1188 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
1189 return true;
1190 return isMemNoOffset(false, 0);
1191 }
1192 bool isAlignedMemory64or128or256() const {
1193 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1194 return true;
1195 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
1196 return true;
1197 if (isMemNoOffset(false, 32)) // alignment in bytes for 256-bits is 32.
1198 return true;
1199 return isMemNoOffset(false, 0);
1200 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001201 bool isAddrMode2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001202 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001203 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001204 if (Memory.OffsetRegNum) return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00001205 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001206 if (!Memory.OffsetImm) return true;
1207 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachd3595712011-08-03 23:50:40 +00001208 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001209 }
Jim Grosbachcd17c122011-08-04 23:01:30 +00001210 bool isAM2OffsetImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001211 if (!isImm()) return false;
Jim Grosbachcd17c122011-08-04 23:01:30 +00001212 // Immediate offset in range [-4095, 4095].
1213 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1214 if (!CE) return false;
1215 int64_t Val = CE->getValue();
Mihai Popac1d119e2013-06-11 09:48:35 +00001216 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
Jim Grosbachcd17c122011-08-04 23:01:30 +00001217 }
Jim Grosbach5b96b802011-08-10 20:29:19 +00001218 bool isAddrMode3() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001219 // If we have an immediate that's not a constant, treat it as a label
1220 // reference needing a fixup. If it is a constant, it's something else
1221 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001222 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001223 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001224 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001225 // No shifts are legal for AM3.
Jim Grosbach871dff72011-10-11 15:59:20 +00001226 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001227 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001228 if (Memory.OffsetRegNum) return true;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001229 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001230 if (!Memory.OffsetImm) return true;
1231 int64_t Val = Memory.OffsetImm->getValue();
Silviu Baranga5a719f92012-05-11 09:10:54 +00001232 // The #-0 offset is encoded as INT32_MIN, and we have to check
1233 // for this too.
1234 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001235 }
1236 bool isAM3Offset() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001237 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001238 return false;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001239 if (Kind == k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001240 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1241 // Immediate offset in range [-255, 255].
1242 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1243 if (!CE) return false;
1244 int64_t Val = CE->getValue();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001245 // Special case, #-0 is INT32_MIN.
1246 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001247 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001248 bool isAddrMode5() const {
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001249 // If we have an immediate that's not a constant, treat it as a label
1250 // reference needing a fixup. If it is a constant, it's something else
1251 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001252 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001253 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001254 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001255 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001256 if (Memory.OffsetRegNum) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001257 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbach871dff72011-10-11 15:59:20 +00001258 if (!Memory.OffsetImm) return true;
1259 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001260 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001261 Val == INT32_MIN;
Bill Wendling8d2aa032010-11-08 23:49:57 +00001262 }
Jim Grosbach05541f42011-09-19 22:21:13 +00001263 bool isMemTBB() const {
Chad Rosier41099832012-09-11 23:02:35 +00001264 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001265 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach05541f42011-09-19 22:21:13 +00001266 return false;
1267 return true;
1268 }
1269 bool isMemTBH() const {
Chad Rosier41099832012-09-11 23:02:35 +00001270 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001271 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1272 Memory.Alignment != 0 )
Jim Grosbach05541f42011-09-19 22:21:13 +00001273 return false;
1274 return true;
1275 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001276 bool isMemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001277 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendling092a7bd2010-12-14 03:36:38 +00001278 return false;
Daniel Dunbar7ed45592011-01-18 05:34:11 +00001279 return true;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001280 }
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001281 bool isT2MemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001282 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001283 Memory.Alignment != 0)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001284 return false;
1285 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbach871dff72011-10-11 15:59:20 +00001286 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001287 return true;
Jim Grosbach871dff72011-10-11 15:59:20 +00001288 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001289 return false;
1290 return true;
1291 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001292 bool isMemThumbRR() const {
1293 // Thumb reg+reg addressing is simple. Just two registers, a base and
1294 // an offset. No shifts, negations or any other complicating factors.
Chad Rosier41099832012-09-11 23:02:35 +00001295 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001296 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendling811c9362010-11-30 07:44:32 +00001297 return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001298 return isARMLowRegister(Memory.BaseRegNum) &&
1299 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001300 }
1301 bool isMemThumbRIs4() const {
Chad Rosier41099832012-09-11 23:02:35 +00001302 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001303 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001304 return false;
1305 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbach871dff72011-10-11 15:59:20 +00001306 if (!Memory.OffsetImm) return true;
1307 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001308 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1309 }
Jim Grosbach26d35872011-08-19 18:55:51 +00001310 bool isMemThumbRIs2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001311 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001312 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach26d35872011-08-19 18:55:51 +00001313 return false;
1314 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbach871dff72011-10-11 15:59:20 +00001315 if (!Memory.OffsetImm) return true;
1316 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach26d35872011-08-19 18:55:51 +00001317 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1318 }
Jim Grosbacha32c7532011-08-19 18:49:59 +00001319 bool isMemThumbRIs1() const {
Chad Rosier41099832012-09-11 23:02:35 +00001320 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001321 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbacha32c7532011-08-19 18:49:59 +00001322 return false;
1323 // Immediate offset in range [0, 31].
Jim Grosbach871dff72011-10-11 15:59:20 +00001324 if (!Memory.OffsetImm) return true;
1325 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha32c7532011-08-19 18:49:59 +00001326 return Val >= 0 && Val <= 31;
1327 }
Jim Grosbach23983d62011-08-19 18:13:48 +00001328 bool isMemThumbSPI() const {
Chad Rosier41099832012-09-11 23:02:35 +00001329 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001330 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbach23983d62011-08-19 18:13:48 +00001331 return false;
1332 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001333 if (!Memory.OffsetImm) return true;
1334 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001335 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendling811c9362010-11-30 07:44:32 +00001336 }
Jim Grosbach7db8d692011-09-08 22:07:06 +00001337 bool isMemImm8s4Offset() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001338 // If we have an immediate that's not a constant, treat it as a label
1339 // reference needing a fixup. If it is a constant, it's something else
1340 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001341 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001342 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001343 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7db8d692011-09-08 22:07:06 +00001344 return false;
1345 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001346 if (!Memory.OffsetImm) return true;
1347 int64_t Val = Memory.OffsetImm->getValue();
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001348 // Special case, #-0 is INT32_MIN.
1349 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
Jim Grosbach7db8d692011-09-08 22:07:06 +00001350 }
Jim Grosbacha05627e2011-09-09 18:37:27 +00001351 bool isMemImm0_1020s4Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001352 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha05627e2011-09-09 18:37:27 +00001353 return false;
1354 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001355 if (!Memory.OffsetImm) return true;
1356 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha05627e2011-09-09 18:37:27 +00001357 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1358 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001359 bool isMemImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001360 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001361 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001362 // Base reg of PC isn't allowed for these encodings.
1363 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001364 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001365 if (!Memory.OffsetImm) return true;
1366 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson49168402011-09-23 22:25:02 +00001367 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbachd3595712011-08-03 23:50:40 +00001368 }
Jim Grosbach2392c532011-09-07 23:39:14 +00001369 bool isMemPosImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001370 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach2392c532011-09-07 23:39:14 +00001371 return false;
1372 // Immediate offset in range [0, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001373 if (!Memory.OffsetImm) return true;
1374 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach2392c532011-09-07 23:39:14 +00001375 return Val >= 0 && Val < 256;
1376 }
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001377 bool isMemNegImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001378 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001379 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001380 // Base reg of PC isn't allowed for these encodings.
1381 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001382 // Immediate offset in range [-255, -1].
Jim Grosbach175c7d02011-12-06 04:49:29 +00001383 if (!Memory.OffsetImm) return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001384 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach175c7d02011-12-06 04:49:29 +00001385 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001386 }
1387 bool isMemUImm12Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001388 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001389 return false;
1390 // Immediate offset in range [0, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001391 if (!Memory.OffsetImm) return true;
1392 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001393 return (Val >= 0 && Val < 4096);
1394 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001395 bool isMemImm12Offset() const {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001396 // If we have an immediate that's not a constant, treat it as a label
1397 // reference needing a fixup. If it is a constant, it's something else
1398 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001399 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach95466ce2011-08-08 20:59:31 +00001400 return true;
1401
Chad Rosier41099832012-09-11 23:02:35 +00001402 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001403 return false;
1404 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001405 if (!Memory.OffsetImm) return true;
1406 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001407 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001408 }
1409 bool isPostIdxImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001410 if (!isImm()) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001411 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1412 if (!CE) return false;
1413 int64_t Val = CE->getValue();
Owen Andersonf02d98d2011-08-29 17:17:09 +00001414 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001415 }
Jim Grosbach93981412011-10-11 21:55:36 +00001416 bool isPostIdxImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001417 if (!isImm()) return false;
Jim Grosbach93981412011-10-11 21:55:36 +00001418 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1419 if (!CE) return false;
1420 int64_t Val = CE->getValue();
1421 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1422 (Val == INT32_MIN);
1423 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001424
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001425 bool isMSRMask() const { return Kind == k_MSRMask; }
Tim Northoveree843ef2014-08-15 10:47:12 +00001426 bool isBankedReg() const { return Kind == k_BankedReg; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001427 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001428
Jim Grosbach741cd732011-10-17 22:26:03 +00001429 // NEON operands.
Jim Grosbach2f50e922011-12-15 21:44:33 +00001430 bool isSingleSpacedVectorList() const {
1431 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1432 }
1433 bool isDoubleSpacedVectorList() const {
1434 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1435 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001436 bool isVecListOneD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001437 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001438 return VectorList.Count == 1;
1439 }
1440
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001441 bool isVecListDPair() const {
1442 if (!isSingleSpacedVectorList()) return false;
1443 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1444 .contains(VectorList.RegNum));
1445 }
1446
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001447 bool isVecListThreeD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001448 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001449 return VectorList.Count == 3;
1450 }
1451
Jim Grosbach846bcff2011-10-21 20:35:01 +00001452 bool isVecListFourD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001453 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach846bcff2011-10-21 20:35:01 +00001454 return VectorList.Count == 4;
1455 }
1456
Jim Grosbache5307f92012-03-05 21:43:40 +00001457 bool isVecListDPairSpaced() const {
Kevin Enderby56113982014-03-26 21:54:11 +00001458 if (Kind != k_VectorList) return false;
Kevin Enderby816ca272012-03-20 17:41:51 +00001459 if (isSingleSpacedVectorList()) return false;
Jim Grosbache5307f92012-03-05 21:43:40 +00001460 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1461 .contains(VectorList.RegNum));
1462 }
1463
Jim Grosbachac2af3f2012-01-23 23:20:46 +00001464 bool isVecListThreeQ() const {
1465 if (!isDoubleSpacedVectorList()) return false;
1466 return VectorList.Count == 3;
1467 }
1468
Jim Grosbach1e946a42012-01-24 00:43:12 +00001469 bool isVecListFourQ() const {
1470 if (!isDoubleSpacedVectorList()) return false;
1471 return VectorList.Count == 4;
1472 }
1473
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001474 bool isSingleSpacedVectorAllLanes() const {
1475 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1476 }
1477 bool isDoubleSpacedVectorAllLanes() const {
1478 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1479 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001480 bool isVecListOneDAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001481 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001482 return VectorList.Count == 1;
1483 }
1484
Jim Grosbach13a292c2012-03-06 22:01:44 +00001485 bool isVecListDPairAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001486 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach13a292c2012-03-06 22:01:44 +00001487 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1488 .contains(VectorList.RegNum));
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001489 }
1490
Jim Grosbached428bc2012-03-06 23:10:38 +00001491 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001492 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001493 return VectorList.Count == 2;
1494 }
1495
Jim Grosbachb78403c2012-01-24 23:47:04 +00001496 bool isVecListThreeDAllLanes() const {
1497 if (!isSingleSpacedVectorAllLanes()) return false;
1498 return VectorList.Count == 3;
1499 }
1500
1501 bool isVecListThreeQAllLanes() const {
1502 if (!isDoubleSpacedVectorAllLanes()) return false;
1503 return VectorList.Count == 3;
1504 }
1505
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001506 bool isVecListFourDAllLanes() const {
1507 if (!isSingleSpacedVectorAllLanes()) return false;
1508 return VectorList.Count == 4;
1509 }
1510
1511 bool isVecListFourQAllLanes() const {
1512 if (!isDoubleSpacedVectorAllLanes()) return false;
1513 return VectorList.Count == 4;
1514 }
1515
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001516 bool isSingleSpacedVectorIndexed() const {
1517 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1518 }
1519 bool isDoubleSpacedVectorIndexed() const {
1520 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1521 }
Jim Grosbach04945c42011-12-02 00:35:16 +00001522 bool isVecListOneDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001523 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach04945c42011-12-02 00:35:16 +00001524 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1525 }
1526
Jim Grosbachda511042011-12-14 23:35:06 +00001527 bool isVecListOneDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001528 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001529 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1530 }
1531
1532 bool isVecListOneDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001533 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001534 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1535 }
1536
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001537 bool isVecListTwoDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001538 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001539 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1540 }
1541
Jim Grosbachda511042011-12-14 23:35:06 +00001542 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001543 if (!isSingleSpacedVectorIndexed()) return false;
1544 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1545 }
1546
1547 bool isVecListTwoQWordIndexed() const {
1548 if (!isDoubleSpacedVectorIndexed()) return false;
1549 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1550 }
1551
1552 bool isVecListTwoQHWordIndexed() const {
1553 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001554 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1555 }
1556
1557 bool isVecListTwoDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001558 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001559 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1560 }
1561
Jim Grosbacha8b444b2012-01-23 21:53:26 +00001562 bool isVecListThreeDByteIndexed() const {
1563 if (!isSingleSpacedVectorIndexed()) return false;
1564 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1565 }
1566
1567 bool isVecListThreeDHWordIndexed() const {
1568 if (!isSingleSpacedVectorIndexed()) return false;
1569 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1570 }
1571
1572 bool isVecListThreeQWordIndexed() const {
1573 if (!isDoubleSpacedVectorIndexed()) return false;
1574 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1575 }
1576
1577 bool isVecListThreeQHWordIndexed() const {
1578 if (!isDoubleSpacedVectorIndexed()) return false;
1579 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1580 }
1581
1582 bool isVecListThreeDWordIndexed() const {
1583 if (!isSingleSpacedVectorIndexed()) return false;
1584 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1585 }
1586
Jim Grosbach14952a02012-01-24 18:37:25 +00001587 bool isVecListFourDByteIndexed() const {
1588 if (!isSingleSpacedVectorIndexed()) return false;
1589 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1590 }
1591
1592 bool isVecListFourDHWordIndexed() const {
1593 if (!isSingleSpacedVectorIndexed()) return false;
1594 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1595 }
1596
1597 bool isVecListFourQWordIndexed() const {
1598 if (!isDoubleSpacedVectorIndexed()) return false;
1599 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1600 }
1601
1602 bool isVecListFourQHWordIndexed() const {
1603 if (!isDoubleSpacedVectorIndexed()) return false;
1604 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1605 }
1606
1607 bool isVecListFourDWordIndexed() const {
1608 if (!isSingleSpacedVectorIndexed()) return false;
1609 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1610 }
1611
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001612 bool isVectorIndex8() const {
1613 if (Kind != k_VectorIndex) return false;
1614 return VectorIndex.Val < 8;
1615 }
1616 bool isVectorIndex16() const {
1617 if (Kind != k_VectorIndex) return false;
1618 return VectorIndex.Val < 4;
1619 }
1620 bool isVectorIndex32() const {
1621 if (Kind != k_VectorIndex) return false;
1622 return VectorIndex.Val < 2;
1623 }
1624
Jim Grosbach741cd732011-10-17 22:26:03 +00001625 bool isNEONi8splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001626 if (!isImm()) return false;
Jim Grosbach741cd732011-10-17 22:26:03 +00001627 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1628 // Must be a constant.
1629 if (!CE) return false;
1630 int64_t Value = CE->getValue();
1631 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1632 // value.
Jim Grosbach741cd732011-10-17 22:26:03 +00001633 return Value >= 0 && Value < 256;
1634 }
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001635
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001636 bool isNEONi16splat() const {
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00001637 if (isNEONByteReplicate(2))
1638 return false; // Leave that for bytes replication and forbid by default.
1639 if (!isImm())
1640 return false;
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001641 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1642 // Must be a constant.
1643 if (!CE) return false;
Renato Golinf5dd1da2014-09-25 11:31:24 +00001644 unsigned Value = CE->getValue();
1645 return ARM_AM::isNEONi16splat(Value);
1646 }
1647
1648 bool isNEONi16splatNot() const {
1649 if (!isImm())
1650 return false;
1651 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1652 // Must be a constant.
1653 if (!CE) return false;
1654 unsigned Value = CE->getValue();
1655 return ARM_AM::isNEONi16splat(~Value & 0xffff);
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001656 }
1657
Jim Grosbach8211c052011-10-18 00:22:00 +00001658 bool isNEONi32splat() const {
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00001659 if (isNEONByteReplicate(4))
1660 return false; // Leave that for bytes replication and forbid by default.
1661 if (!isImm())
1662 return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001663 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1664 // Must be a constant.
1665 if (!CE) return false;
Renato Golinf5dd1da2014-09-25 11:31:24 +00001666 unsigned Value = CE->getValue();
1667 return ARM_AM::isNEONi32splat(Value);
1668 }
1669
1670 bool isNEONi32splatNot() const {
1671 if (!isImm())
1672 return false;
1673 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1674 // Must be a constant.
1675 if (!CE) return false;
1676 unsigned Value = CE->getValue();
1677 return ARM_AM::isNEONi32splat(~Value);
Jim Grosbach8211c052011-10-18 00:22:00 +00001678 }
1679
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00001680 bool isNEONByteReplicate(unsigned NumBytes) const {
1681 if (!isImm())
1682 return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001683 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1684 // Must be a constant.
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00001685 if (!CE)
1686 return false;
1687 int64_t Value = CE->getValue();
1688 if (!Value)
1689 return false; // Don't bother with zero.
1690
1691 unsigned char B = Value & 0xff;
1692 for (unsigned i = 1; i < NumBytes; ++i) {
1693 Value >>= 8;
1694 if ((Value & 0xff) != B)
1695 return false;
1696 }
1697 return true;
1698 }
1699 bool isNEONi16ByteReplicate() const { return isNEONByteReplicate(2); }
1700 bool isNEONi32ByteReplicate() const { return isNEONByteReplicate(4); }
1701 bool isNEONi32vmov() const {
1702 if (isNEONByteReplicate(4))
1703 return false; // Let it to be classified as byte-replicate case.
1704 if (!isImm())
1705 return false;
1706 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1707 // Must be a constant.
1708 if (!CE)
1709 return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001710 int64_t Value = CE->getValue();
1711 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1712 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
Renato Golinf5dd1da2014-09-25 11:31:24 +00001713 // FIXME: This is probably wrong and a copy and paste from previous example
Jim Grosbach8211c052011-10-18 00:22:00 +00001714 return (Value >= 0 && Value < 256) ||
1715 (Value >= 0x0100 && Value <= 0xff00) ||
1716 (Value >= 0x010000 && Value <= 0xff0000) ||
1717 (Value >= 0x01000000 && Value <= 0xff000000) ||
1718 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1719 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1720 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00001721 bool isNEONi32vmovNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001722 if (!isImm()) return false;
Jim Grosbach045b6c72011-12-19 23:51:07 +00001723 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1724 // Must be a constant.
1725 if (!CE) return false;
1726 int64_t Value = ~CE->getValue();
1727 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1728 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
Renato Golinf5dd1da2014-09-25 11:31:24 +00001729 // FIXME: This is probably wrong and a copy and paste from previous example
Jim Grosbach045b6c72011-12-19 23:51:07 +00001730 return (Value >= 0 && Value < 256) ||
1731 (Value >= 0x0100 && Value <= 0xff00) ||
1732 (Value >= 0x010000 && Value <= 0xff0000) ||
1733 (Value >= 0x01000000 && Value <= 0xff000000) ||
1734 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1735 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1736 }
Jim Grosbach8211c052011-10-18 00:22:00 +00001737
Jim Grosbache4454e02011-10-18 16:18:11 +00001738 bool isNEONi64splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001739 if (!isImm()) return false;
Jim Grosbache4454e02011-10-18 16:18:11 +00001740 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1741 // Must be a constant.
1742 if (!CE) return false;
1743 uint64_t Value = CE->getValue();
1744 // i64 value with each byte being either 0 or 0xff.
1745 for (unsigned i = 0; i < 8; ++i)
1746 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1747 return true;
1748 }
1749
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001750 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001751 // Add as immediates when possible. Null MCExpr = 0.
Craig Topper062a2ba2014-04-25 05:30:21 +00001752 if (!Expr)
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001753 Inst.addOperand(MCOperand::CreateImm(0));
1754 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001755 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1756 else
1757 Inst.addOperand(MCOperand::CreateExpr(Expr));
1758 }
1759
Daniel Dunbard8042b72010-08-11 06:36:53 +00001760 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar188b47b2010-08-11 06:37:20 +00001761 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbard8042b72010-08-11 06:36:53 +00001762 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach968c9272010-12-06 18:30:57 +00001763 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1764 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbard8042b72010-08-11 06:36:53 +00001765 }
1766
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00001767 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1768 assert(N == 1 && "Invalid number of operands!");
1769 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1770 }
1771
Jim Grosbach48399582011-10-12 17:34:41 +00001772 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1773 assert(N == 1 && "Invalid number of operands!");
1774 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1775 }
1776
1777 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1778 assert(N == 1 && "Invalid number of operands!");
1779 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1780 }
1781
Jim Grosbach3d1eac82011-08-26 21:43:41 +00001782 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1783 assert(N == 1 && "Invalid number of operands!");
1784 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1785 }
1786
1787 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1788 assert(N == 1 && "Invalid number of operands!");
1789 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1790 }
1791
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00001792 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1793 assert(N == 1 && "Invalid number of operands!");
1794 Inst.addOperand(MCOperand::CreateReg(getReg()));
1795 }
1796
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00001797 void addRegOperands(MCInst &Inst, unsigned N) const {
1798 assert(N == 1 && "Invalid number of operands!");
1799 Inst.addOperand(MCOperand::CreateReg(getReg()));
1800 }
1801
Jim Grosbachac798e12011-07-25 20:49:51 +00001802 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001803 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001804 assert(isRegShiftedReg() &&
Alp Tokerf907b892013-12-05 05:44:44 +00001805 "addRegShiftedRegOperands() on non-RegShiftedReg!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001806 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1807 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001808 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachac798e12011-07-25 20:49:51 +00001809 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001810 }
1811
Jim Grosbachac798e12011-07-25 20:49:51 +00001812 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson04912702011-07-21 23:38:37 +00001813 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001814 assert(isRegShiftedImm() &&
Alp Tokerf907b892013-12-05 05:44:44 +00001815 "addRegShiftedImmOperands() on non-RegShiftedImm!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001816 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001817 // Shift of #32 is encoded as 0 where permitted
1818 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Andersonb595ed02011-07-21 18:54:16 +00001819 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001820 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Andersonb595ed02011-07-21 18:54:16 +00001821 }
1822
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001823 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001824 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001825 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1826 ShifterImm.Imm));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001827 }
1828
Bill Wendling8d2aa032010-11-08 23:49:57 +00001829 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling2cae3272010-11-09 22:44:22 +00001830 assert(N == 1 && "Invalid number of operands!");
Bill Wendlingbed94652010-11-09 23:28:44 +00001831 const SmallVectorImpl<unsigned> &RegList = getRegList();
1832 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00001833 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1834 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling8d2aa032010-11-08 23:49:57 +00001835 }
1836
Bill Wendling9898ac92010-11-17 04:32:08 +00001837 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1838 addRegListOperands(Inst, N);
1839 }
1840
1841 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1842 addRegListOperands(Inst, N);
1843 }
1844
Jim Grosbach833b9d32011-07-27 20:15:40 +00001845 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1846 assert(N == 1 && "Invalid number of operands!");
1847 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1848 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1849 }
1850
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00001851 void addModImmOperands(MCInst &Inst, unsigned N) const {
1852 assert(N == 1 && "Invalid number of operands!");
1853
1854 // Support for fixups (MCFixup)
1855 if (isImm())
1856 return addImmOperands(Inst, N);
1857
Asiri Rathnayake7835e9b2014-12-09 13:14:58 +00001858 Inst.addOperand(MCOperand::CreateImm(ModImm.Bits | (ModImm.Rot << 7)));
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00001859 }
1860
1861 void addModImmNotOperands(MCInst &Inst, unsigned N) const {
1862 assert(N == 1 && "Invalid number of operands!");
1863 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1864 uint32_t Enc = ARM_AM::getSOImmVal(~CE->getValue());
1865 Inst.addOperand(MCOperand::CreateImm(Enc));
1866 }
1867
1868 void addModImmNegOperands(MCInst &Inst, unsigned N) const {
1869 assert(N == 1 && "Invalid number of operands!");
1870 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1871 uint32_t Enc = ARM_AM::getSOImmVal(-CE->getValue());
1872 Inst.addOperand(MCOperand::CreateImm(Enc));
1873 }
1874
Jim Grosbach864b6092011-07-28 21:34:26 +00001875 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1876 assert(N == 1 && "Invalid number of operands!");
1877 // Munge the lsb/width into a bitfield mask.
1878 unsigned lsb = Bitfield.LSB;
1879 unsigned width = Bitfield.Width;
1880 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1881 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1882 (32 - (lsb + width)));
1883 Inst.addOperand(MCOperand::CreateImm(Mask));
1884 }
1885
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001886 void addImmOperands(MCInst &Inst, unsigned N) const {
1887 assert(N == 1 && "Invalid number of operands!");
1888 addExpr(Inst, getImm());
1889 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00001890
Jim Grosbachea231912011-12-22 22:19:05 +00001891 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1892 assert(N == 1 && "Invalid number of operands!");
1893 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1894 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1895 }
1896
1897 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1898 assert(N == 1 && "Invalid number of operands!");
1899 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1900 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1901 }
1902
Jim Grosbache7fbce72011-10-03 23:38:36 +00001903 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1904 assert(N == 1 && "Invalid number of operands!");
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00001905 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1906 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1907 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbache7fbce72011-10-03 23:38:36 +00001908 }
1909
Jim Grosbach7db8d692011-09-08 22:07:06 +00001910 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1911 assert(N == 1 && "Invalid number of operands!");
1912 // FIXME: We really want to scale the value here, but the LDRD/STRD
1913 // instruction don't encode operands that way yet.
1914 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1915 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1916 }
1917
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001918 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1919 assert(N == 1 && "Invalid number of operands!");
1920 // The immediate is scaled by four in the encoding and is stored
1921 // in the MCInst as such. Lop off the low two bits here.
1922 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1923 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1924 }
1925
Jim Grosbach930f2f62012-04-05 20:57:13 +00001926 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1927 assert(N == 1 && "Invalid number of operands!");
1928 // The immediate is scaled by four in the encoding and is stored
1929 // in the MCInst as such. Lop off the low two bits here.
1930 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1931 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1932 }
1933
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001934 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1935 assert(N == 1 && "Invalid number of operands!");
1936 // The immediate is scaled by four in the encoding and is stored
1937 // in the MCInst as such. Lop off the low two bits here.
1938 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1939 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1940 }
1941
Jim Grosbach475c6db2011-07-25 23:09:14 +00001942 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1943 assert(N == 1 && "Invalid number of operands!");
1944 // The constant encodes as the immediate-1, and we store in the instruction
1945 // the bits as encoded, so subtract off one here.
1946 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1947 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1948 }
1949
Jim Grosbach801e0a32011-07-22 23:16:18 +00001950 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1951 assert(N == 1 && "Invalid number of operands!");
1952 // The constant encodes as the immediate-1, and we store in the instruction
1953 // the bits as encoded, so subtract off one here.
1954 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1955 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1956 }
1957
Jim Grosbach46dd4132011-08-17 21:51:27 +00001958 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1959 assert(N == 1 && "Invalid number of operands!");
1960 // The constant encodes as the immediate, except for 32, which encodes as
1961 // zero.
1962 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1963 unsigned Imm = CE->getValue();
1964 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1965 }
1966
Jim Grosbach27c1e252011-07-21 17:23:04 +00001967 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1968 assert(N == 1 && "Invalid number of operands!");
1969 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1970 // the instruction as well.
1971 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1972 int Val = CE->getValue();
1973 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1974 }
1975
Jim Grosbachb009a872011-10-28 22:36:30 +00001976 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1977 assert(N == 1 && "Invalid number of operands!");
1978 // The operand is actually a t2_so_imm, but we have its bitwise
1979 // negation in the assembly source, so twiddle it here.
1980 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1981 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1982 }
1983
Jim Grosbach30506252011-12-08 00:31:07 +00001984 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1985 assert(N == 1 && "Invalid number of operands!");
1986 // The operand is actually a t2_so_imm, but we have its
1987 // negation in the assembly source, so twiddle it here.
1988 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1989 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1990 }
1991
Jim Grosbach930f2f62012-04-05 20:57:13 +00001992 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1993 assert(N == 1 && "Invalid number of operands!");
1994 // The operand is actually an imm0_4095, but we have its
1995 // negation in the assembly source, so twiddle it here.
1996 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1997 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1998 }
1999
Mihai Popad36cbaa2013-07-03 09:21:44 +00002000 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
2001 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
2002 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
2003 return;
2004 }
2005
2006 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
2007 assert(SR && "Unknown value type!");
2008 Inst.addOperand(MCOperand::CreateExpr(SR));
2009 }
2010
Mihai Popa8a9da5b2013-07-22 15:49:36 +00002011 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
2012 assert(N == 1 && "Invalid number of operands!");
2013 if (isImm()) {
2014 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2015 if (CE) {
2016 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
2017 return;
2018 }
2019
2020 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
2021 assert(SR && "Unknown value type!");
2022 Inst.addOperand(MCOperand::CreateExpr(SR));
2023 return;
2024 }
2025
2026 assert(isMem() && "Unknown value type!");
2027 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
2028 Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue()));
2029 }
2030
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002031 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
2032 assert(N == 1 && "Invalid number of operands!");
2033 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
2034 }
2035
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002036 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
2037 assert(N == 1 && "Invalid number of operands!");
2038 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
2039 }
2040
Jim Grosbachd3595712011-08-03 23:50:40 +00002041 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
2042 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002043 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +00002044 }
2045
Jim Grosbach94298a92012-01-18 22:46:46 +00002046 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
2047 assert(N == 1 && "Invalid number of operands!");
2048 int32_t Imm = Memory.OffsetImm->getValue();
Jim Grosbach94298a92012-01-18 22:46:46 +00002049 Inst.addOperand(MCOperand::CreateImm(Imm));
2050 }
2051
Jiangning Liu10dd40e2012-08-02 08:13:13 +00002052 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
2053 assert(N == 1 && "Invalid number of operands!");
2054 assert(isImm() && "Not an immediate!");
2055
2056 // If we have an immediate that's not a constant, treat it as a label
2057 // reference needing a fixup.
2058 if (!isa<MCConstantExpr>(getImm())) {
2059 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2060 return;
2061 }
2062
2063 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2064 int Val = CE->getValue();
2065 Inst.addOperand(MCOperand::CreateImm(Val));
2066 }
2067
Jim Grosbacha95ec992011-10-11 17:29:55 +00002068 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
2069 assert(N == 2 && "Invalid number of operands!");
2070 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2071 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
2072 }
2073
Kevin Enderby488f20b2014-04-10 20:18:58 +00002074 void addDupAlignedMemoryNoneOperands(MCInst &Inst, unsigned N) const {
2075 addAlignedMemoryOperands(Inst, N);
2076 }
2077
2078 void addAlignedMemoryNoneOperands(MCInst &Inst, unsigned N) const {
2079 addAlignedMemoryOperands(Inst, N);
2080 }
2081
2082 void addAlignedMemory16Operands(MCInst &Inst, unsigned N) const {
2083 addAlignedMemoryOperands(Inst, N);
2084 }
2085
2086 void addDupAlignedMemory16Operands(MCInst &Inst, unsigned N) const {
2087 addAlignedMemoryOperands(Inst, N);
2088 }
2089
2090 void addAlignedMemory32Operands(MCInst &Inst, unsigned N) const {
2091 addAlignedMemoryOperands(Inst, N);
2092 }
2093
2094 void addDupAlignedMemory32Operands(MCInst &Inst, unsigned N) const {
2095 addAlignedMemoryOperands(Inst, N);
2096 }
2097
2098 void addAlignedMemory64Operands(MCInst &Inst, unsigned N) const {
2099 addAlignedMemoryOperands(Inst, N);
2100 }
2101
2102 void addDupAlignedMemory64Operands(MCInst &Inst, unsigned N) const {
2103 addAlignedMemoryOperands(Inst, N);
2104 }
2105
2106 void addAlignedMemory64or128Operands(MCInst &Inst, unsigned N) const {
2107 addAlignedMemoryOperands(Inst, N);
2108 }
2109
2110 void addDupAlignedMemory64or128Operands(MCInst &Inst, unsigned N) const {
2111 addAlignedMemoryOperands(Inst, N);
2112 }
2113
2114 void addAlignedMemory64or128or256Operands(MCInst &Inst, unsigned N) const {
2115 addAlignedMemoryOperands(Inst, N);
2116 }
2117
Jim Grosbachd3595712011-08-03 23:50:40 +00002118 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
2119 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002120 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2121 if (!Memory.OffsetRegNum) {
Jim Grosbachd3595712011-08-03 23:50:40 +00002122 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2123 // Special case for #-0
2124 if (Val == INT32_MIN) Val = 0;
2125 if (Val < 0) Val = -Val;
2126 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
2127 } else {
2128 // For register offset, we encode the shift type and negation flag
2129 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00002130 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2131 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00002132 }
Jim Grosbach871dff72011-10-11 15:59:20 +00002133 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2134 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002135 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00002136 }
2137
Jim Grosbachcd17c122011-08-04 23:01:30 +00002138 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
2139 assert(N == 2 && "Invalid number of operands!");
2140 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2141 assert(CE && "non-constant AM2OffsetImm operand!");
2142 int32_t Val = CE->getValue();
2143 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2144 // Special case for #-0
2145 if (Val == INT32_MIN) Val = 0;
2146 if (Val < 0) Val = -Val;
2147 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
2148 Inst.addOperand(MCOperand::CreateReg(0));
2149 Inst.addOperand(MCOperand::CreateImm(Val));
2150 }
2151
Jim Grosbach5b96b802011-08-10 20:29:19 +00002152 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
2153 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00002154 // If we have an immediate that's not a constant, treat it as a label
2155 // reference needing a fixup. If it is a constant, it's something else
2156 // and we reject it.
2157 if (isImm()) {
2158 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2159 Inst.addOperand(MCOperand::CreateReg(0));
2160 Inst.addOperand(MCOperand::CreateImm(0));
2161 return;
2162 }
2163
Jim Grosbach871dff72011-10-11 15:59:20 +00002164 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2165 if (!Memory.OffsetRegNum) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00002166 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2167 // Special case for #-0
2168 if (Val == INT32_MIN) Val = 0;
2169 if (Val < 0) Val = -Val;
2170 Val = ARM_AM::getAM3Opc(AddSub, Val);
2171 } else {
2172 // For register offset, we encode the shift type and negation flag
2173 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00002174 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach5b96b802011-08-10 20:29:19 +00002175 }
Jim Grosbach871dff72011-10-11 15:59:20 +00002176 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2177 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach5b96b802011-08-10 20:29:19 +00002178 Inst.addOperand(MCOperand::CreateImm(Val));
2179 }
2180
2181 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
2182 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002183 if (Kind == k_PostIndexRegister) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00002184 int32_t Val =
2185 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
2186 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2187 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00002188 return;
Jim Grosbach5b96b802011-08-10 20:29:19 +00002189 }
2190
2191 // Constant offset.
2192 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
2193 int32_t Val = CE->getValue();
2194 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2195 // Special case for #-0
2196 if (Val == INT32_MIN) Val = 0;
2197 if (Val < 0) Val = -Val;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00002198 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach5b96b802011-08-10 20:29:19 +00002199 Inst.addOperand(MCOperand::CreateReg(0));
2200 Inst.addOperand(MCOperand::CreateImm(Val));
2201 }
2202
Jim Grosbachd3595712011-08-03 23:50:40 +00002203 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
2204 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00002205 // If we have an immediate that's not a constant, treat it as a label
2206 // reference needing a fixup. If it is a constant, it's something else
2207 // and we reject it.
2208 if (isImm()) {
2209 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2210 Inst.addOperand(MCOperand::CreateImm(0));
2211 return;
2212 }
2213
Jim Grosbachd3595712011-08-03 23:50:40 +00002214 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00002215 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002216 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2217 // Special case for #-0
2218 if (Val == INT32_MIN) Val = 0;
2219 if (Val < 0) Val = -Val;
2220 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbach871dff72011-10-11 15:59:20 +00002221 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002222 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00002223 }
2224
Jim Grosbach7db8d692011-09-08 22:07:06 +00002225 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
2226 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00002227 // If we have an immediate that's not a constant, treat it as a label
2228 // reference needing a fixup. If it is a constant, it's something else
2229 // and we reject it.
2230 if (isImm()) {
2231 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2232 Inst.addOperand(MCOperand::CreateImm(0));
2233 return;
2234 }
2235
Jim Grosbach871dff72011-10-11 15:59:20 +00002236 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2237 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7db8d692011-09-08 22:07:06 +00002238 Inst.addOperand(MCOperand::CreateImm(Val));
2239 }
2240
Jim Grosbacha05627e2011-09-09 18:37:27 +00002241 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
2242 assert(N == 2 && "Invalid number of operands!");
2243 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00002244 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
2245 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha05627e2011-09-09 18:37:27 +00002246 Inst.addOperand(MCOperand::CreateImm(Val));
2247 }
2248
Jim Grosbachd3595712011-08-03 23:50:40 +00002249 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2250 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002251 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2252 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002253 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner5d6f6a02010-10-29 00:27:31 +00002254 }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002255
Jim Grosbach2392c532011-09-07 23:39:14 +00002256 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2257 addMemImm8OffsetOperands(Inst, N);
2258 }
2259
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002260 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach2392c532011-09-07 23:39:14 +00002261 addMemImm8OffsetOperands(Inst, N);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002262 }
2263
2264 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2265 assert(N == 2 && "Invalid number of operands!");
2266 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00002267 if (isImm()) {
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002268 addExpr(Inst, getImm());
2269 Inst.addOperand(MCOperand::CreateImm(0));
2270 return;
2271 }
2272
2273 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00002274 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2275 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002276 Inst.addOperand(MCOperand::CreateImm(Val));
2277 }
2278
Jim Grosbachd3595712011-08-03 23:50:40 +00002279 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2280 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach95466ce2011-08-08 20:59:31 +00002281 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00002282 if (isImm()) {
Jim Grosbach95466ce2011-08-08 20:59:31 +00002283 addExpr(Inst, getImm());
2284 Inst.addOperand(MCOperand::CreateImm(0));
2285 return;
2286 }
2287
2288 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00002289 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2290 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002291 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendling092a7bd2010-12-14 03:36:38 +00002292 }
Bill Wendling811c9362010-11-30 07:44:32 +00002293
Jim Grosbach05541f42011-09-19 22:21:13 +00002294 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
2295 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002296 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2297 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002298 }
2299
2300 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
2301 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002302 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2303 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002304 }
2305
Jim Grosbachd3595712011-08-03 23:50:40 +00002306 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2307 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00002308 unsigned Val =
2309 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2310 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbach871dff72011-10-11 15:59:20 +00002311 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2312 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002313 Inst.addOperand(MCOperand::CreateImm(Val));
2314 }
2315
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002316 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2317 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002318 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2319 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2320 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002321 }
2322
Jim Grosbachd3595712011-08-03 23:50:40 +00002323 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2324 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002325 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2326 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002327 }
2328
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002329 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2330 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002331 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2332 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002333 Inst.addOperand(MCOperand::CreateImm(Val));
2334 }
2335
Jim Grosbach26d35872011-08-19 18:55:51 +00002336 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2337 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002338 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2339 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach26d35872011-08-19 18:55:51 +00002340 Inst.addOperand(MCOperand::CreateImm(Val));
2341 }
2342
Jim Grosbacha32c7532011-08-19 18:49:59 +00002343 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2344 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002345 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2346 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha32c7532011-08-19 18:49:59 +00002347 Inst.addOperand(MCOperand::CreateImm(Val));
2348 }
2349
Jim Grosbach23983d62011-08-19 18:13:48 +00002350 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2351 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002352 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2353 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach23983d62011-08-19 18:13:48 +00002354 Inst.addOperand(MCOperand::CreateImm(Val));
2355 }
2356
Jim Grosbachd3595712011-08-03 23:50:40 +00002357 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2358 assert(N == 1 && "Invalid number of operands!");
2359 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2360 assert(CE && "non-constant post-idx-imm8 operand!");
2361 int Imm = CE->getValue();
2362 bool isAdd = Imm >= 0;
Owen Andersonf02d98d2011-08-29 17:17:09 +00002363 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002364 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2365 Inst.addOperand(MCOperand::CreateImm(Imm));
2366 }
2367
Jim Grosbach93981412011-10-11 21:55:36 +00002368 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2369 assert(N == 1 && "Invalid number of operands!");
2370 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2371 assert(CE && "non-constant post-idx-imm8s4 operand!");
2372 int Imm = CE->getValue();
2373 bool isAdd = Imm >= 0;
2374 if (Imm == INT32_MIN) Imm = 0;
2375 // Immediate is scaled by 4.
2376 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2377 Inst.addOperand(MCOperand::CreateImm(Imm));
2378 }
2379
Jim Grosbachd3595712011-08-03 23:50:40 +00002380 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2381 assert(N == 2 && "Invalid number of operands!");
2382 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachc320c852011-08-05 21:28:30 +00002383 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2384 }
2385
2386 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2387 assert(N == 2 && "Invalid number of operands!");
2388 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2389 // The sign, shift type, and shift amount are encoded in a single operand
2390 // using the AM2 encoding helpers.
2391 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2392 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2393 PostIdxReg.ShiftTy);
2394 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendling811c9362010-11-30 07:44:32 +00002395 }
2396
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002397 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2398 assert(N == 1 && "Invalid number of operands!");
2399 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2400 }
2401
Tim Northoveree843ef2014-08-15 10:47:12 +00002402 void addBankedRegOperands(MCInst &Inst, unsigned N) const {
2403 assert(N == 1 && "Invalid number of operands!");
2404 Inst.addOperand(MCOperand::CreateImm(unsigned(getBankedReg())));
2405 }
2406
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002407 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2408 assert(N == 1 && "Invalid number of operands!");
2409 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2410 }
2411
Jim Grosbach182b6a02011-11-29 23:51:09 +00002412 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002413 assert(N == 1 && "Invalid number of operands!");
2414 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2415 }
2416
Jim Grosbach04945c42011-12-02 00:35:16 +00002417 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2418 assert(N == 2 && "Invalid number of operands!");
2419 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2420 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2421 }
2422
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002423 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2424 assert(N == 1 && "Invalid number of operands!");
2425 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2426 }
2427
2428 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2429 assert(N == 1 && "Invalid number of operands!");
2430 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2431 }
2432
2433 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2434 assert(N == 1 && "Invalid number of operands!");
2435 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2436 }
2437
Jim Grosbach741cd732011-10-17 22:26:03 +00002438 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2439 assert(N == 1 && "Invalid number of operands!");
2440 // The immediate encodes the type of constant as well as the value.
2441 // Mask in that this is an i8 splat.
2442 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2443 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2444 }
2445
Jim Grosbachcda32ae2011-10-17 23:09:09 +00002446 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2447 assert(N == 1 && "Invalid number of operands!");
2448 // The immediate encodes the type of constant as well as the value.
2449 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2450 unsigned Value = CE->getValue();
Renato Golinf5dd1da2014-09-25 11:31:24 +00002451 Value = ARM_AM::encodeNEONi16splat(Value);
2452 Inst.addOperand(MCOperand::CreateImm(Value));
2453 }
2454
2455 void addNEONi16splatNotOperands(MCInst &Inst, unsigned N) const {
2456 assert(N == 1 && "Invalid number of operands!");
2457 // The immediate encodes the type of constant as well as the value.
2458 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2459 unsigned Value = CE->getValue();
2460 Value = ARM_AM::encodeNEONi16splat(~Value & 0xffff);
Jim Grosbachcda32ae2011-10-17 23:09:09 +00002461 Inst.addOperand(MCOperand::CreateImm(Value));
2462 }
2463
Jim Grosbach8211c052011-10-18 00:22:00 +00002464 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2465 assert(N == 1 && "Invalid number of operands!");
2466 // The immediate encodes the type of constant as well as the value.
2467 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2468 unsigned Value = CE->getValue();
Renato Golinf5dd1da2014-09-25 11:31:24 +00002469 Value = ARM_AM::encodeNEONi32splat(Value);
2470 Inst.addOperand(MCOperand::CreateImm(Value));
2471 }
2472
2473 void addNEONi32splatNotOperands(MCInst &Inst, unsigned N) const {
2474 assert(N == 1 && "Invalid number of operands!");
2475 // The immediate encodes the type of constant as well as the value.
2476 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2477 unsigned Value = CE->getValue();
2478 Value = ARM_AM::encodeNEONi32splat(~Value);
Jim Grosbach8211c052011-10-18 00:22:00 +00002479 Inst.addOperand(MCOperand::CreateImm(Value));
2480 }
2481
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00002482 void addNEONinvByteReplicateOperands(MCInst &Inst, unsigned N) const {
2483 assert(N == 1 && "Invalid number of operands!");
2484 // The immediate encodes the type of constant as well as the value.
2485 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2486 unsigned Value = CE->getValue();
2487 assert((Inst.getOpcode() == ARM::VMOVv8i8 ||
2488 Inst.getOpcode() == ARM::VMOVv16i8) &&
2489 "All vmvn instructions that wants to replicate non-zero byte "
2490 "always must be replaced with VMOVv8i8 or VMOVv16i8.");
2491 unsigned B = ((~Value) & 0xff);
2492 B |= 0xe00; // cmode = 0b1110
2493 Inst.addOperand(MCOperand::CreateImm(B));
2494 }
Jim Grosbach8211c052011-10-18 00:22:00 +00002495 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2496 assert(N == 1 && "Invalid number of operands!");
2497 // The immediate encodes the type of constant as well as the value.
2498 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2499 unsigned Value = CE->getValue();
2500 if (Value >= 256 && Value <= 0xffff)
2501 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2502 else if (Value > 0xffff && Value <= 0xffffff)
2503 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2504 else if (Value > 0xffffff)
2505 Value = (Value >> 24) | 0x600;
2506 Inst.addOperand(MCOperand::CreateImm(Value));
2507 }
2508
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00002509 void addNEONvmovByteReplicateOperands(MCInst &Inst, unsigned N) const {
2510 assert(N == 1 && "Invalid number of operands!");
2511 // The immediate encodes the type of constant as well as the value.
2512 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2513 unsigned Value = CE->getValue();
2514 assert((Inst.getOpcode() == ARM::VMOVv8i8 ||
2515 Inst.getOpcode() == ARM::VMOVv16i8) &&
2516 "All instructions that wants to replicate non-zero byte "
2517 "always must be replaced with VMOVv8i8 or VMOVv16i8.");
2518 unsigned B = Value & 0xff;
2519 B |= 0xe00; // cmode = 0b1110
2520 Inst.addOperand(MCOperand::CreateImm(B));
2521 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00002522 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2523 assert(N == 1 && "Invalid number of operands!");
2524 // The immediate encodes the type of constant as well as the value.
2525 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2526 unsigned Value = ~CE->getValue();
2527 if (Value >= 256 && Value <= 0xffff)
2528 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2529 else if (Value > 0xffff && Value <= 0xffffff)
2530 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2531 else if (Value > 0xffffff)
2532 Value = (Value >> 24) | 0x600;
2533 Inst.addOperand(MCOperand::CreateImm(Value));
2534 }
2535
Jim Grosbache4454e02011-10-18 16:18:11 +00002536 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2537 assert(N == 1 && "Invalid number of operands!");
2538 // The immediate encodes the type of constant as well as the value.
2539 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2540 uint64_t Value = CE->getValue();
2541 unsigned Imm = 0;
2542 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2543 Imm |= (Value & 1) << i;
2544 }
2545 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2546 }
2547
Craig Topperca7e3e52014-03-10 03:19:03 +00002548 void print(raw_ostream &OS) const override;
Daniel Dunbarebace222010-08-11 06:37:04 +00002549
David Blaikie960ea3f2014-06-08 16:18:35 +00002550 static std::unique_ptr<ARMOperand> CreateITMask(unsigned Mask, SMLoc S) {
2551 auto Op = make_unique<ARMOperand>(k_ITCondMask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002552 Op->ITMask.Mask = Mask;
2553 Op->StartLoc = S;
2554 Op->EndLoc = S;
2555 return Op;
2556 }
2557
David Blaikie960ea3f2014-06-08 16:18:35 +00002558 static std::unique_ptr<ARMOperand> CreateCondCode(ARMCC::CondCodes CC,
2559 SMLoc S) {
2560 auto Op = make_unique<ARMOperand>(k_CondCode);
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002561 Op->CC.Val = CC;
2562 Op->StartLoc = S;
2563 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002564 return Op;
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002565 }
2566
David Blaikie960ea3f2014-06-08 16:18:35 +00002567 static std::unique_ptr<ARMOperand> CreateCoprocNum(unsigned CopVal, SMLoc S) {
2568 auto Op = make_unique<ARMOperand>(k_CoprocNum);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002569 Op->Cop.Val = CopVal;
2570 Op->StartLoc = S;
2571 Op->EndLoc = S;
2572 return Op;
2573 }
2574
David Blaikie960ea3f2014-06-08 16:18:35 +00002575 static std::unique_ptr<ARMOperand> CreateCoprocReg(unsigned CopVal, SMLoc S) {
2576 auto Op = make_unique<ARMOperand>(k_CoprocReg);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002577 Op->Cop.Val = CopVal;
2578 Op->StartLoc = S;
2579 Op->EndLoc = S;
2580 return Op;
2581 }
2582
David Blaikie960ea3f2014-06-08 16:18:35 +00002583 static std::unique_ptr<ARMOperand> CreateCoprocOption(unsigned Val, SMLoc S,
2584 SMLoc E) {
2585 auto Op = make_unique<ARMOperand>(k_CoprocOption);
Jim Grosbach48399582011-10-12 17:34:41 +00002586 Op->Cop.Val = Val;
2587 Op->StartLoc = S;
2588 Op->EndLoc = E;
2589 return Op;
2590 }
2591
David Blaikie960ea3f2014-06-08 16:18:35 +00002592 static std::unique_ptr<ARMOperand> CreateCCOut(unsigned RegNum, SMLoc S) {
2593 auto Op = make_unique<ARMOperand>(k_CCOut);
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002594 Op->Reg.RegNum = RegNum;
2595 Op->StartLoc = S;
2596 Op->EndLoc = S;
2597 return Op;
2598 }
2599
David Blaikie960ea3f2014-06-08 16:18:35 +00002600 static std::unique_ptr<ARMOperand> CreateToken(StringRef Str, SMLoc S) {
2601 auto Op = make_unique<ARMOperand>(k_Token);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002602 Op->Tok.Data = Str.data();
2603 Op->Tok.Length = Str.size();
2604 Op->StartLoc = S;
2605 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002606 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002607 }
2608
David Blaikie960ea3f2014-06-08 16:18:35 +00002609 static std::unique_ptr<ARMOperand> CreateReg(unsigned RegNum, SMLoc S,
2610 SMLoc E) {
2611 auto Op = make_unique<ARMOperand>(k_Register);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002612 Op->Reg.RegNum = RegNum;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002613 Op->StartLoc = S;
2614 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002615 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002616 }
2617
David Blaikie960ea3f2014-06-08 16:18:35 +00002618 static std::unique_ptr<ARMOperand>
2619 CreateShiftedRegister(ARM_AM::ShiftOpc ShTy, unsigned SrcReg,
2620 unsigned ShiftReg, unsigned ShiftImm, SMLoc S,
2621 SMLoc E) {
2622 auto Op = make_unique<ARMOperand>(k_ShiftedRegister);
Jim Grosbachac798e12011-07-25 20:49:51 +00002623 Op->RegShiftedReg.ShiftTy = ShTy;
2624 Op->RegShiftedReg.SrcReg = SrcReg;
2625 Op->RegShiftedReg.ShiftReg = ShiftReg;
2626 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002627 Op->StartLoc = S;
2628 Op->EndLoc = E;
2629 return Op;
2630 }
2631
David Blaikie960ea3f2014-06-08 16:18:35 +00002632 static std::unique_ptr<ARMOperand>
2633 CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy, unsigned SrcReg,
2634 unsigned ShiftImm, SMLoc S, SMLoc E) {
2635 auto Op = make_unique<ARMOperand>(k_ShiftedImmediate);
Jim Grosbachac798e12011-07-25 20:49:51 +00002636 Op->RegShiftedImm.ShiftTy = ShTy;
2637 Op->RegShiftedImm.SrcReg = SrcReg;
2638 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Andersonb595ed02011-07-21 18:54:16 +00002639 Op->StartLoc = S;
2640 Op->EndLoc = E;
2641 return Op;
2642 }
2643
David Blaikie960ea3f2014-06-08 16:18:35 +00002644 static std::unique_ptr<ARMOperand> CreateShifterImm(bool isASR, unsigned Imm,
2645 SMLoc S, SMLoc E) {
2646 auto Op = make_unique<ARMOperand>(k_ShifterImmediate);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002647 Op->ShifterImm.isASR = isASR;
2648 Op->ShifterImm.Imm = Imm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002649 Op->StartLoc = S;
2650 Op->EndLoc = E;
2651 return Op;
2652 }
2653
David Blaikie960ea3f2014-06-08 16:18:35 +00002654 static std::unique_ptr<ARMOperand> CreateRotImm(unsigned Imm, SMLoc S,
2655 SMLoc E) {
2656 auto Op = make_unique<ARMOperand>(k_RotateImmediate);
Jim Grosbach833b9d32011-07-27 20:15:40 +00002657 Op->RotImm.Imm = Imm;
2658 Op->StartLoc = S;
2659 Op->EndLoc = E;
2660 return Op;
2661 }
2662
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00002663 static std::unique_ptr<ARMOperand> CreateModImm(unsigned Bits, unsigned Rot,
2664 SMLoc S, SMLoc E) {
2665 auto Op = make_unique<ARMOperand>(k_ModifiedImmediate);
2666 Op->ModImm.Bits = Bits;
2667 Op->ModImm.Rot = Rot;
2668 Op->StartLoc = S;
2669 Op->EndLoc = E;
2670 return Op;
2671 }
2672
David Blaikie960ea3f2014-06-08 16:18:35 +00002673 static std::unique_ptr<ARMOperand>
2674 CreateBitfield(unsigned LSB, unsigned Width, SMLoc S, SMLoc E) {
2675 auto Op = make_unique<ARMOperand>(k_BitfieldDescriptor);
Jim Grosbach864b6092011-07-28 21:34:26 +00002676 Op->Bitfield.LSB = LSB;
2677 Op->Bitfield.Width = Width;
2678 Op->StartLoc = S;
2679 Op->EndLoc = E;
2680 return Op;
2681 }
2682
David Blaikie960ea3f2014-06-08 16:18:35 +00002683 static std::unique_ptr<ARMOperand>
2684 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned>> &Regs,
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002685 SMLoc StartLoc, SMLoc EndLoc) {
Chad Rosierfa705ee2013-07-01 20:49:23 +00002686 assert (Regs.size() > 0 && "RegList contains no registers?");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002687 KindTy Kind = k_RegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002688
Chad Rosierfa705ee2013-07-01 20:49:23 +00002689 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002690 Kind = k_DPRRegisterList;
Jim Grosbach75461af2011-09-13 22:56:44 +00002691 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Chad Rosierfa705ee2013-07-01 20:49:23 +00002692 contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002693 Kind = k_SPRRegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002694
Chad Rosierfa705ee2013-07-01 20:49:23 +00002695 // Sort based on the register encoding values.
2696 array_pod_sort(Regs.begin(), Regs.end());
2697
David Blaikie960ea3f2014-06-08 16:18:35 +00002698 auto Op = make_unique<ARMOperand>(Kind);
Chad Rosierfa705ee2013-07-01 20:49:23 +00002699 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002700 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Chad Rosierfa705ee2013-07-01 20:49:23 +00002701 Op->Registers.push_back(I->second);
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002702 Op->StartLoc = StartLoc;
2703 Op->EndLoc = EndLoc;
Bill Wendling7cef4472010-11-06 19:56:04 +00002704 return Op;
2705 }
2706
David Blaikie960ea3f2014-06-08 16:18:35 +00002707 static std::unique_ptr<ARMOperand> CreateVectorList(unsigned RegNum,
2708 unsigned Count,
2709 bool isDoubleSpaced,
2710 SMLoc S, SMLoc E) {
2711 auto Op = make_unique<ARMOperand>(k_VectorList);
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002712 Op->VectorList.RegNum = RegNum;
2713 Op->VectorList.Count = Count;
Jim Grosbach2f50e922011-12-15 21:44:33 +00002714 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002715 Op->StartLoc = S;
2716 Op->EndLoc = E;
2717 return Op;
2718 }
2719
David Blaikie960ea3f2014-06-08 16:18:35 +00002720 static std::unique_ptr<ARMOperand>
2721 CreateVectorListAllLanes(unsigned RegNum, unsigned Count, bool isDoubleSpaced,
2722 SMLoc S, SMLoc E) {
2723 auto Op = make_unique<ARMOperand>(k_VectorListAllLanes);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002724 Op->VectorList.RegNum = RegNum;
2725 Op->VectorList.Count = Count;
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002726 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002727 Op->StartLoc = S;
2728 Op->EndLoc = E;
2729 return Op;
2730 }
2731
David Blaikie960ea3f2014-06-08 16:18:35 +00002732 static std::unique_ptr<ARMOperand>
2733 CreateVectorListIndexed(unsigned RegNum, unsigned Count, unsigned Index,
2734 bool isDoubleSpaced, SMLoc S, SMLoc E) {
2735 auto Op = make_unique<ARMOperand>(k_VectorListIndexed);
Jim Grosbach04945c42011-12-02 00:35:16 +00002736 Op->VectorList.RegNum = RegNum;
2737 Op->VectorList.Count = Count;
2738 Op->VectorList.LaneIndex = Index;
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002739 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach04945c42011-12-02 00:35:16 +00002740 Op->StartLoc = S;
2741 Op->EndLoc = E;
2742 return Op;
2743 }
2744
David Blaikie960ea3f2014-06-08 16:18:35 +00002745 static std::unique_ptr<ARMOperand>
2746 CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E, MCContext &Ctx) {
2747 auto Op = make_unique<ARMOperand>(k_VectorIndex);
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002748 Op->VectorIndex.Val = Idx;
2749 Op->StartLoc = S;
2750 Op->EndLoc = E;
2751 return Op;
2752 }
2753
David Blaikie960ea3f2014-06-08 16:18:35 +00002754 static std::unique_ptr<ARMOperand> CreateImm(const MCExpr *Val, SMLoc S,
2755 SMLoc E) {
2756 auto Op = make_unique<ARMOperand>(k_Immediate);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002757 Op->Imm.Val = Val;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002758 Op->StartLoc = S;
2759 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002760 return Op;
Kevin Enderbyf5079942009-10-13 22:19:02 +00002761 }
2762
David Blaikie960ea3f2014-06-08 16:18:35 +00002763 static std::unique_ptr<ARMOperand>
2764 CreateMem(unsigned BaseRegNum, const MCConstantExpr *OffsetImm,
2765 unsigned OffsetRegNum, ARM_AM::ShiftOpc ShiftType,
2766 unsigned ShiftImm, unsigned Alignment, bool isNegative, SMLoc S,
2767 SMLoc E, SMLoc AlignmentLoc = SMLoc()) {
2768 auto Op = make_unique<ARMOperand>(k_Memory);
Jim Grosbach871dff72011-10-11 15:59:20 +00002769 Op->Memory.BaseRegNum = BaseRegNum;
2770 Op->Memory.OffsetImm = OffsetImm;
2771 Op->Memory.OffsetRegNum = OffsetRegNum;
2772 Op->Memory.ShiftType = ShiftType;
2773 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbacha95ec992011-10-11 17:29:55 +00002774 Op->Memory.Alignment = Alignment;
Jim Grosbach871dff72011-10-11 15:59:20 +00002775 Op->Memory.isNegative = isNegative;
Jim Grosbachd3595712011-08-03 23:50:40 +00002776 Op->StartLoc = S;
2777 Op->EndLoc = E;
Kevin Enderby488f20b2014-04-10 20:18:58 +00002778 Op->AlignmentLoc = AlignmentLoc;
Jim Grosbachd3595712011-08-03 23:50:40 +00002779 return Op;
2780 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00002781
David Blaikie960ea3f2014-06-08 16:18:35 +00002782 static std::unique_ptr<ARMOperand>
2783 CreatePostIdxReg(unsigned RegNum, bool isAdd, ARM_AM::ShiftOpc ShiftTy,
2784 unsigned ShiftImm, SMLoc S, SMLoc E) {
2785 auto Op = make_unique<ARMOperand>(k_PostIndexRegister);
Jim Grosbachd3595712011-08-03 23:50:40 +00002786 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +00002787 Op->PostIdxReg.isAdd = isAdd;
2788 Op->PostIdxReg.ShiftTy = ShiftTy;
2789 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002790 Op->StartLoc = S;
2791 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002792 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002793 }
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002794
David Blaikie960ea3f2014-06-08 16:18:35 +00002795 static std::unique_ptr<ARMOperand> CreateMemBarrierOpt(ARM_MB::MemBOpt Opt,
2796 SMLoc S) {
2797 auto Op = make_unique<ARMOperand>(k_MemBarrierOpt);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002798 Op->MBOpt.Val = Opt;
2799 Op->StartLoc = S;
2800 Op->EndLoc = S;
2801 return Op;
2802 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002803
David Blaikie960ea3f2014-06-08 16:18:35 +00002804 static std::unique_ptr<ARMOperand>
2805 CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt, SMLoc S) {
2806 auto Op = make_unique<ARMOperand>(k_InstSyncBarrierOpt);
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002807 Op->ISBOpt.Val = Opt;
2808 Op->StartLoc = S;
2809 Op->EndLoc = S;
2810 return Op;
2811 }
2812
David Blaikie960ea3f2014-06-08 16:18:35 +00002813 static std::unique_ptr<ARMOperand> CreateProcIFlags(ARM_PROC::IFlags IFlags,
2814 SMLoc S) {
2815 auto Op = make_unique<ARMOperand>(k_ProcIFlags);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002816 Op->IFlags.Val = IFlags;
2817 Op->StartLoc = S;
2818 Op->EndLoc = S;
2819 return Op;
2820 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002821
David Blaikie960ea3f2014-06-08 16:18:35 +00002822 static std::unique_ptr<ARMOperand> CreateMSRMask(unsigned MMask, SMLoc S) {
2823 auto Op = make_unique<ARMOperand>(k_MSRMask);
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002824 Op->MMask.Val = MMask;
2825 Op->StartLoc = S;
2826 Op->EndLoc = S;
2827 return Op;
2828 }
Tim Northoveree843ef2014-08-15 10:47:12 +00002829
2830 static std::unique_ptr<ARMOperand> CreateBankedReg(unsigned Reg, SMLoc S) {
2831 auto Op = make_unique<ARMOperand>(k_BankedReg);
2832 Op->BankedReg.Val = Reg;
2833 Op->StartLoc = S;
2834 Op->EndLoc = S;
2835 return Op;
2836 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002837};
2838
2839} // end anonymous namespace.
2840
Jim Grosbach602aa902011-07-13 15:34:57 +00002841void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002842 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002843 case k_CondCode:
Daniel Dunbar2be732a2011-01-10 15:26:21 +00002844 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002845 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002846 case k_CCOut:
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002847 OS << "<ccout " << getReg() << ">";
2848 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002849 case k_ITCondMask: {
Craig Topper42b96d12012-05-24 04:11:15 +00002850 static const char *const MaskStr[] = {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002851 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2852 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2853 };
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002854 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2855 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2856 break;
2857 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002858 case k_CoprocNum:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002859 OS << "<coprocessor number: " << getCoproc() << ">";
2860 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002861 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002862 OS << "<coprocessor register: " << getCoproc() << ">";
2863 break;
Jim Grosbach48399582011-10-12 17:34:41 +00002864 case k_CoprocOption:
2865 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2866 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002867 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002868 OS << "<mask: " << getMSRMask() << ">";
2869 break;
Tim Northoveree843ef2014-08-15 10:47:12 +00002870 case k_BankedReg:
2871 OS << "<banked reg: " << getBankedReg() << ">";
2872 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002873 case k_Immediate:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002874 getImm()->print(OS);
2875 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002876 case k_MemBarrierOpt:
Joey Gouly926d3f52013-09-05 15:35:24 +00002877 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">";
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002878 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002879 case k_InstSyncBarrierOpt:
2880 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2881 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002882 case k_Memory:
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002883 OS << "<memory "
Jim Grosbach871dff72011-10-11 15:59:20 +00002884 << " base:" << Memory.BaseRegNum;
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002885 OS << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002886 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002887 case k_PostIndexRegister:
Jim Grosbachc320c852011-08-05 21:28:30 +00002888 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2889 << PostIdxReg.RegNum;
2890 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2891 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2892 << PostIdxReg.ShiftImm;
2893 OS << ">";
Jim Grosbachd3595712011-08-03 23:50:40 +00002894 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002895 case k_ProcIFlags: {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002896 OS << "<ARM_PROC::";
2897 unsigned IFlags = getProcIFlags();
2898 for (int i=2; i >= 0; --i)
2899 if (IFlags & (1 << i))
2900 OS << ARM_PROC::IFlagsToString(1 << i);
2901 OS << ">";
2902 break;
2903 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002904 case k_Register:
Bill Wendling2063b842010-11-18 23:43:05 +00002905 OS << "<register " << getReg() << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002906 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002907 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002908 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2909 << " #" << ShifterImm.Imm << ">";
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002910 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002911 case k_ShiftedRegister:
Owen Andersonb595ed02011-07-21 18:54:16 +00002912 OS << "<so_reg_reg "
Jim Grosbach01e04392011-11-16 21:46:50 +00002913 << RegShiftedReg.SrcReg << " "
2914 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2915 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002916 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002917 case k_ShiftedImmediate:
Owen Andersonb595ed02011-07-21 18:54:16 +00002918 OS << "<so_reg_imm "
Jim Grosbach01e04392011-11-16 21:46:50 +00002919 << RegShiftedImm.SrcReg << " "
2920 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2921 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Andersonb595ed02011-07-21 18:54:16 +00002922 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002923 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +00002924 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2925 break;
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00002926 case k_ModifiedImmediate:
2927 OS << "<mod_imm #" << ModImm.Bits << ", #"
2928 << ModImm.Rot << ")>";
2929 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002930 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +00002931 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2932 << ", width: " << Bitfield.Width << ">";
2933 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002934 case k_RegisterList:
2935 case k_DPRRegisterList:
2936 case k_SPRRegisterList: {
Bill Wendling7cef4472010-11-06 19:56:04 +00002937 OS << "<register_list ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002938
Bill Wendlingbed94652010-11-09 23:28:44 +00002939 const SmallVectorImpl<unsigned> &RegList = getRegList();
2940 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002941 I = RegList.begin(), E = RegList.end(); I != E; ) {
2942 OS << *I;
2943 if (++I < E) OS << ", ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002944 }
2945
2946 OS << ">";
2947 break;
2948 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002949 case k_VectorList:
2950 OS << "<vector_list " << VectorList.Count << " * "
2951 << VectorList.RegNum << ">";
2952 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002953 case k_VectorListAllLanes:
2954 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2955 << VectorList.RegNum << ">";
2956 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00002957 case k_VectorListIndexed:
2958 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2959 << VectorList.Count << " * " << VectorList.RegNum << ">";
2960 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002961 case k_Token:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002962 OS << "'" << getToken() << "'";
2963 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002964 case k_VectorIndex:
2965 OS << "<vectorindex " << getVectorIndex() << ">";
2966 break;
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002967 }
2968}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002969
2970/// @name Auto-generated Match Functions
2971/// {
2972
2973static unsigned MatchRegisterName(StringRef Name);
2974
2975/// }
2976
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002977bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2978 SMLoc &StartLoc, SMLoc &EndLoc) {
Rafael Espindola961d4692014-11-11 05:18:41 +00002979 const AsmToken &Tok = getParser().getTok();
2980 StartLoc = Tok.getLoc();
2981 EndLoc = Tok.getEndLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002982 RegNo = tryParseRegister();
Roman Divacky36b1b472011-01-27 17:14:22 +00002983
2984 return (RegNo == (unsigned)-1);
2985}
2986
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002987/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattner44e5981c2010-10-30 04:09:10 +00002988/// and if it is a register name the token is eaten and the register number is
2989/// returned. Otherwise return -1.
2990///
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002991int ARMAsmParser::tryParseRegister() {
Rafael Espindola961d4692014-11-11 05:18:41 +00002992 MCAsmParser &Parser = getParser();
Chris Lattner44e5981c2010-10-30 04:09:10 +00002993 const AsmToken &Tok = Parser.getTok();
Jim Grosbachd3595712011-08-03 23:50:40 +00002994 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbach99710a82010-11-01 16:44:21 +00002995
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002996 std::string lowerCase = Tok.getString().lower();
Owen Andersona098d152011-01-13 22:50:36 +00002997 unsigned RegNum = MatchRegisterName(lowerCase);
2998 if (!RegNum) {
2999 RegNum = StringSwitch<unsigned>(lowerCase)
3000 .Case("r13", ARM::SP)
3001 .Case("r14", ARM::LR)
3002 .Case("r15", ARM::PC)
3003 .Case("ip", ARM::R12)
Jim Grosbach4edc7362011-12-08 19:27:38 +00003004 // Additional register name aliases for 'gas' compatibility.
3005 .Case("a1", ARM::R0)
3006 .Case("a2", ARM::R1)
3007 .Case("a3", ARM::R2)
3008 .Case("a4", ARM::R3)
3009 .Case("v1", ARM::R4)
3010 .Case("v2", ARM::R5)
3011 .Case("v3", ARM::R6)
3012 .Case("v4", ARM::R7)
3013 .Case("v5", ARM::R8)
3014 .Case("v6", ARM::R9)
3015 .Case("v7", ARM::R10)
3016 .Case("v8", ARM::R11)
3017 .Case("sb", ARM::R9)
3018 .Case("sl", ARM::R10)
3019 .Case("fp", ARM::R11)
Owen Andersona098d152011-01-13 22:50:36 +00003020 .Default(0);
3021 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00003022 if (!RegNum) {
Jim Grosbachcd22e4a2011-12-20 23:11:00 +00003023 // Check for aliases registered via .req. Canonicalize to lower case.
3024 // That's more consistent since register names are case insensitive, and
3025 // it's how the original entry was passed in from MC/MCParser/AsmParser.
3026 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbachab5830e2011-12-14 02:16:11 +00003027 // If no match, return failure.
3028 if (Entry == RegisterReqs.end())
3029 return -1;
3030 Parser.Lex(); // Eat identifier token.
3031 return Entry->getValue();
3032 }
Bob Wilsonfb0bd042011-02-03 21:46:10 +00003033
Oliver Stannard9e89d8c2014-11-05 12:06:39 +00003034 // Some FPUs only have 16 D registers, so D16-D31 are invalid
3035 if (hasD16() && RegNum >= ARM::D16 && RegNum <= ARM::D31)
3036 return -1;
3037
Chris Lattner44e5981c2010-10-30 04:09:10 +00003038 Parser.Lex(); // Eat identifier token.
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003039
Chris Lattner44e5981c2010-10-30 04:09:10 +00003040 return RegNum;
3041}
Jim Grosbach99710a82010-11-01 16:44:21 +00003042
Jim Grosbachbb24c592011-07-13 18:49:30 +00003043// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
3044// If a recoverable error occurs, return 1. If an irrecoverable error
3045// occurs, return -1. An irrecoverable error is one where tokens have been
3046// consumed in the process of trying to parse the shifter (i.e., when it is
3047// indeed a shifter operand, but malformed).
David Blaikie960ea3f2014-06-08 16:18:35 +00003048int ARMAsmParser::tryParseShiftRegister(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003049 MCAsmParser &Parser = getParser();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003050 SMLoc S = Parser.getTok().getLoc();
3051 const AsmToken &Tok = Parser.getTok();
Kevin Enderby62873712014-02-17 21:45:27 +00003052 if (Tok.isNot(AsmToken::Identifier))
3053 return -1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003054
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003055 std::string lowerCase = Tok.getString().lower();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003056 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbach3b559ff2011-12-07 23:40:58 +00003057 .Case("asl", ARM_AM::lsl)
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003058 .Case("lsl", ARM_AM::lsl)
3059 .Case("lsr", ARM_AM::lsr)
3060 .Case("asr", ARM_AM::asr)
3061 .Case("ror", ARM_AM::ror)
3062 .Case("rrx", ARM_AM::rrx)
3063 .Default(ARM_AM::no_shift);
3064
3065 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbachbb24c592011-07-13 18:49:30 +00003066 return 1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003067
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003068 Parser.Lex(); // Eat the operator.
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003069
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003070 // The source register for the shift has already been added to the
3071 // operand list, so we need to pop it off and combine it into the shifted
3072 // register operand instead.
David Blaikie960ea3f2014-06-08 16:18:35 +00003073 std::unique_ptr<ARMOperand> PrevOp(
3074 (ARMOperand *)Operands.pop_back_val().release());
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003075 if (!PrevOp->isReg())
3076 return Error(PrevOp->getStartLoc(), "shift must be of a register");
3077 int SrcReg = PrevOp->getReg();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003078
3079 SMLoc EndLoc;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003080 int64_t Imm = 0;
3081 int ShiftReg = 0;
3082 if (ShiftTy == ARM_AM::rrx) {
3083 // RRX Doesn't have an explicit shift amount. The encoder expects
3084 // the shift register to be the same as the source register. Seems odd,
3085 // but OK.
3086 ShiftReg = SrcReg;
3087 } else {
3088 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003089 if (Parser.getTok().is(AsmToken::Hash) ||
3090 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003091 Parser.Lex(); // Eat hash.
3092 SMLoc ImmLoc = Parser.getTok().getLoc();
Craig Topper062a2ba2014-04-25 05:30:21 +00003093 const MCExpr *ShiftExpr = nullptr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003094 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00003095 Error(ImmLoc, "invalid immediate shift value");
3096 return -1;
3097 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003098 // The expression must be evaluatable as an immediate.
3099 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbachbb24c592011-07-13 18:49:30 +00003100 if (!CE) {
3101 Error(ImmLoc, "invalid immediate shift value");
3102 return -1;
3103 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003104 // Range check the immediate.
3105 // lsl, ror: 0 <= imm <= 31
3106 // lsr, asr: 0 <= imm <= 32
3107 Imm = CE->getValue();
3108 if (Imm < 0 ||
3109 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
3110 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00003111 Error(ImmLoc, "immediate shift value out of range");
3112 return -1;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003113 }
Jim Grosbach21488b82011-12-22 17:37:00 +00003114 // shift by zero is a nop. Always send it through as lsl.
3115 // ('as' compatibility)
3116 if (Imm == 0)
3117 ShiftTy = ARM_AM::lsl;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003118 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003119 SMLoc L = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003120 EndLoc = Parser.getTok().getEndLoc();
3121 ShiftReg = tryParseRegister();
Jim Grosbachbb24c592011-07-13 18:49:30 +00003122 if (ShiftReg == -1) {
Saleem Abdulrasool6d11b7c2014-05-17 21:49:54 +00003123 Error(L, "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00003124 return -1;
3125 }
3126 } else {
Saleem Abdulrasool6d11b7c2014-05-17 21:49:54 +00003127 Error(Parser.getTok().getLoc(),
3128 "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00003129 return -1;
3130 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003131 }
3132
Owen Andersonb595ed02011-07-21 18:54:16 +00003133 if (ShiftReg && ShiftTy != ARM_AM::rrx)
3134 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachac798e12011-07-25 20:49:51 +00003135 ShiftReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003136 S, EndLoc));
Owen Andersonb595ed02011-07-21 18:54:16 +00003137 else
3138 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003139 S, EndLoc));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003140
Jim Grosbachbb24c592011-07-13 18:49:30 +00003141 return 0;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003142}
3143
3144
Bill Wendling2063b842010-11-18 23:43:05 +00003145/// Try to parse a register name. The token must be an Identifier when called.
3146/// If it's a register, an AsmOperand is created. Another AsmOperand is created
3147/// if there is a "writeback". 'true' if it's not a register.
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00003148///
Kevin Enderby8be42bd2009-10-30 22:55:57 +00003149/// TODO this is likely to change to allow different register types and or to
3150/// parse for a specific register type.
David Blaikie960ea3f2014-06-08 16:18:35 +00003151bool ARMAsmParser::tryParseRegisterWithWriteBack(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003152 MCAsmParser &Parser = getParser();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003153 const AsmToken &RegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003154 int RegNo = tryParseRegister();
Bill Wendlinge18980a2010-11-06 22:36:58 +00003155 if (RegNo == -1)
Bill Wendling2063b842010-11-18 23:43:05 +00003156 return true;
Jim Grosbach99710a82010-11-01 16:44:21 +00003157
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003158 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
3159 RegTok.getEndLoc()));
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00003160
Chris Lattner44e5981c2010-10-30 04:09:10 +00003161 const AsmToken &ExclaimTok = Parser.getTok();
3162 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling2063b842010-11-18 23:43:05 +00003163 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
3164 ExclaimTok.getLoc()));
Chris Lattner44e5981c2010-10-30 04:09:10 +00003165 Parser.Lex(); // Eat exclaim token
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003166 return false;
3167 }
3168
3169 // Also check for an index operand. This is only legal for vector registers,
3170 // but that'll get caught OK in operand matching, so we don't need to
3171 // explicitly filter everything else out here.
3172 if (Parser.getTok().is(AsmToken::LBrac)) {
3173 SMLoc SIdx = Parser.getTok().getLoc();
3174 Parser.Lex(); // Eat left bracket token.
3175
3176 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003177 if (getParser().parseExpression(ImmVal))
Jim Grosbacha2147ce2012-01-31 23:51:09 +00003178 return true;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003179 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachc8f2b782012-01-26 15:56:45 +00003180 if (!MCE)
3181 return TokError("immediate value expected for vector index");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003182
Jim Grosbachc8f2b782012-01-26 15:56:45 +00003183 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003184 return Error(Parser.getTok().getLoc(), "']' expected");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003185
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003186 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003187 Parser.Lex(); // Eat right bracket token.
3188
3189 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
3190 SIdx, E,
3191 getContext()));
Kevin Enderby2207e5f2009-10-07 18:01:35 +00003192 }
3193
Bill Wendling2063b842010-11-18 23:43:05 +00003194 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00003195}
3196
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003197/// MatchCoprocessorOperandName - Try to parse an coprocessor related
Renato Golinac561c32014-06-26 13:10:53 +00003198/// instruction with a symbolic operand name.
3199/// We accept "crN" syntax for GAS compatibility.
3200/// <operand-name> ::= <prefix><number>
3201/// If CoprocOp is 'c', then:
3202/// <prefix> ::= c | cr
3203/// If CoprocOp is 'p', then :
3204/// <prefix> ::= p
3205/// <number> ::= integer in range [0, 15]
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003206static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003207 // Use the same layout as the tablegen'erated register name matcher. Ugly,
3208 // but efficient.
Renato Golinac561c32014-06-26 13:10:53 +00003209 if (Name.size() < 2 || Name[0] != CoprocOp)
3210 return -1;
3211 Name = (Name[1] == 'r') ? Name.drop_front(2) : Name.drop_front();
3212
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003213 switch (Name.size()) {
David Blaikie46a9f012012-01-20 21:51:11 +00003214 default: return -1;
Renato Golinac561c32014-06-26 13:10:53 +00003215 case 1:
3216 switch (Name[0]) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003217 default: return -1;
3218 case '0': return 0;
3219 case '1': return 1;
3220 case '2': return 2;
3221 case '3': return 3;
3222 case '4': return 4;
3223 case '5': return 5;
3224 case '6': return 6;
3225 case '7': return 7;
3226 case '8': return 8;
3227 case '9': return 9;
3228 }
Renato Golinac561c32014-06-26 13:10:53 +00003229 case 2:
3230 if (Name[0] != '1')
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003231 return -1;
Renato Golinac561c32014-06-26 13:10:53 +00003232 switch (Name[1]) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003233 default: return -1;
Renato Golinbc0b0372014-08-04 23:21:56 +00003234 // CP10 and CP11 are VFP/NEON and so vector instructions should be used.
3235 // However, old cores (v5/v6) did use them in that way.
3236 case '0': return 10;
3237 case '1': return 11;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003238 case '2': return 12;
3239 case '3': return 13;
3240 case '4': return 14;
3241 case '5': return 15;
3242 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003243 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003244}
3245
Jim Grosbach3d1eac82011-08-26 21:43:41 +00003246/// parseITCondCode - Try to parse a condition code for an IT instruction.
David Blaikie960ea3f2014-06-08 16:18:35 +00003247ARMAsmParser::OperandMatchResultTy
3248ARMAsmParser::parseITCondCode(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003249 MCAsmParser &Parser = getParser();
Jim Grosbach3d1eac82011-08-26 21:43:41 +00003250 SMLoc S = Parser.getTok().getLoc();
3251 const AsmToken &Tok = Parser.getTok();
3252 if (!Tok.is(AsmToken::Identifier))
3253 return MatchOperand_NoMatch;
Richard Barton82f95ea2012-04-27 17:34:01 +00003254 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach3d1eac82011-08-26 21:43:41 +00003255 .Case("eq", ARMCC::EQ)
3256 .Case("ne", ARMCC::NE)
3257 .Case("hs", ARMCC::HS)
3258 .Case("cs", ARMCC::HS)
3259 .Case("lo", ARMCC::LO)
3260 .Case("cc", ARMCC::LO)
3261 .Case("mi", ARMCC::MI)
3262 .Case("pl", ARMCC::PL)
3263 .Case("vs", ARMCC::VS)
3264 .Case("vc", ARMCC::VC)
3265 .Case("hi", ARMCC::HI)
3266 .Case("ls", ARMCC::LS)
3267 .Case("ge", ARMCC::GE)
3268 .Case("lt", ARMCC::LT)
3269 .Case("gt", ARMCC::GT)
3270 .Case("le", ARMCC::LE)
3271 .Case("al", ARMCC::AL)
3272 .Default(~0U);
3273 if (CC == ~0U)
3274 return MatchOperand_NoMatch;
3275 Parser.Lex(); // Eat the token.
3276
3277 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
3278
3279 return MatchOperand_Success;
3280}
3281
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003282/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003283/// token must be an Identifier when called, and if it is a coprocessor
3284/// number, the token is eaten and the operand is added to the operand list.
David Blaikie960ea3f2014-06-08 16:18:35 +00003285ARMAsmParser::OperandMatchResultTy
3286ARMAsmParser::parseCoprocNumOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003287 MCAsmParser &Parser = getParser();
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003288 SMLoc S = Parser.getTok().getLoc();
3289 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00003290 if (Tok.isNot(AsmToken::Identifier))
3291 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003292
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003293 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003294 if (Num == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00003295 return MatchOperand_NoMatch;
Renato Golinbc0b0372014-08-04 23:21:56 +00003296 // ARMv7 and v8 don't allow cp10/cp11 due to VFP/NEON specific instructions
3297 if ((hasV7Ops() || hasV8Ops()) && (Num == 10 || Num == 11))
3298 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003299
3300 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003301 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003302 return MatchOperand_Success;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003303}
3304
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003305/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003306/// token must be an Identifier when called, and if it is a coprocessor
3307/// number, the token is eaten and the operand is added to the operand list.
David Blaikie960ea3f2014-06-08 16:18:35 +00003308ARMAsmParser::OperandMatchResultTy
3309ARMAsmParser::parseCoprocRegOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003310 MCAsmParser &Parser = getParser();
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003311 SMLoc S = Parser.getTok().getLoc();
3312 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00003313 if (Tok.isNot(AsmToken::Identifier))
3314 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003315
3316 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
3317 if (Reg == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00003318 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003319
3320 Parser.Lex(); // Eat identifier token.
3321 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003322 return MatchOperand_Success;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003323}
3324
Jim Grosbach48399582011-10-12 17:34:41 +00003325/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
3326/// coproc_option : '{' imm0_255 '}'
David Blaikie960ea3f2014-06-08 16:18:35 +00003327ARMAsmParser::OperandMatchResultTy
3328ARMAsmParser::parseCoprocOptionOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003329 MCAsmParser &Parser = getParser();
Jim Grosbach48399582011-10-12 17:34:41 +00003330 SMLoc S = Parser.getTok().getLoc();
3331
3332 // If this isn't a '{', this isn't a coprocessor immediate operand.
3333 if (Parser.getTok().isNot(AsmToken::LCurly))
3334 return MatchOperand_NoMatch;
3335 Parser.Lex(); // Eat the '{'
3336
3337 const MCExpr *Expr;
3338 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003339 if (getParser().parseExpression(Expr)) {
Jim Grosbach48399582011-10-12 17:34:41 +00003340 Error(Loc, "illegal expression");
3341 return MatchOperand_ParseFail;
3342 }
3343 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
3344 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
3345 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
3346 return MatchOperand_ParseFail;
3347 }
3348 int Val = CE->getValue();
3349
3350 // Check for and consume the closing '}'
3351 if (Parser.getTok().isNot(AsmToken::RCurly))
3352 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003353 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach48399582011-10-12 17:34:41 +00003354 Parser.Lex(); // Eat the '}'
3355
3356 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
3357 return MatchOperand_Success;
3358}
3359
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003360// For register list parsing, we need to map from raw GPR register numbering
3361// to the enumeration values. The enumeration values aren't sorted by
3362// register number due to our using "sp", "lr" and "pc" as canonical names.
3363static unsigned getNextRegister(unsigned Reg) {
3364 // If this is a GPR, we need to do it manually, otherwise we can rely
3365 // on the sort ordering of the enumeration since the other reg-classes
3366 // are sane.
3367 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3368 return Reg + 1;
3369 switch(Reg) {
Craig Toppere55c5562012-02-07 02:50:20 +00003370 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003371 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
3372 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
3373 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
3374 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
3375 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
3376 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
3377 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
3378 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
3379 }
3380}
3381
Jim Grosbach85a23432011-11-11 21:27:40 +00003382// Return the low-subreg of a given Q register.
3383static unsigned getDRegFromQReg(unsigned QReg) {
3384 switch (QReg) {
3385 default: llvm_unreachable("expected a Q register!");
3386 case ARM::Q0: return ARM::D0;
3387 case ARM::Q1: return ARM::D2;
3388 case ARM::Q2: return ARM::D4;
3389 case ARM::Q3: return ARM::D6;
3390 case ARM::Q4: return ARM::D8;
3391 case ARM::Q5: return ARM::D10;
3392 case ARM::Q6: return ARM::D12;
3393 case ARM::Q7: return ARM::D14;
3394 case ARM::Q8: return ARM::D16;
Jim Grosbacha92a5d82011-11-15 21:01:30 +00003395 case ARM::Q9: return ARM::D18;
Jim Grosbach85a23432011-11-11 21:27:40 +00003396 case ARM::Q10: return ARM::D20;
3397 case ARM::Q11: return ARM::D22;
3398 case ARM::Q12: return ARM::D24;
3399 case ARM::Q13: return ARM::D26;
3400 case ARM::Q14: return ARM::D28;
3401 case ARM::Q15: return ARM::D30;
3402 }
3403}
3404
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003405/// Parse a register list.
David Blaikie960ea3f2014-06-08 16:18:35 +00003406bool ARMAsmParser::parseRegisterList(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003407 MCAsmParser &Parser = getParser();
Sean Callanan936b0d32010-01-19 21:44:56 +00003408 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00003409 "Token is not a Left Curly Brace");
Bill Wendlinge18980a2010-11-06 22:36:58 +00003410 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003411 Parser.Lex(); // Eat '{' token.
3412 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbya2b99102009-10-09 21:12:28 +00003413
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003414 // Check the first register in the list to see what register class
3415 // this is a list of.
3416 int Reg = tryParseRegister();
3417 if (Reg == -1)
3418 return Error(RegLoc, "register expected");
3419
Jim Grosbach85a23432011-11-11 21:27:40 +00003420 // The reglist instructions have at most 16 registers, so reserve
3421 // space for that many.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003422 int EReg = 0;
3423 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
Jim Grosbach85a23432011-11-11 21:27:40 +00003424
3425 // Allow Q regs and just interpret them as the two D sub-registers.
3426 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3427 Reg = getDRegFromQReg(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003428 EReg = MRI->getEncodingValue(Reg);
3429 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach85a23432011-11-11 21:27:40 +00003430 ++Reg;
3431 }
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00003432 const MCRegisterClass *RC;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003433 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3434 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3435 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3436 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3437 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3438 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3439 else
3440 return Error(RegLoc, "invalid register in register list");
3441
Jim Grosbach85a23432011-11-11 21:27:40 +00003442 // Store the register.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003443 EReg = MRI->getEncodingValue(Reg);
3444 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Kevin Enderbya2b99102009-10-09 21:12:28 +00003445
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003446 // This starts immediately after the first register token in the list,
3447 // so we can see either a comma or a minus (range separator) as a legal
3448 // next token.
3449 while (Parser.getTok().is(AsmToken::Comma) ||
3450 Parser.getTok().is(AsmToken::Minus)) {
3451 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache891fe82011-11-15 23:19:15 +00003452 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003453 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003454 int EndReg = tryParseRegister();
3455 if (EndReg == -1)
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003456 return Error(AfterMinusLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003457 // Allow Q regs and just interpret them as the two D sub-registers.
3458 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3459 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003460 // If the register is the same as the start reg, there's nothing
3461 // more to do.
3462 if (Reg == EndReg)
3463 continue;
3464 // The register must be in the same register class as the first.
3465 if (!RC->contains(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003466 return Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003467 // Ranges must go from low to high.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003468 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003469 return Error(AfterMinusLoc, "bad range in register list");
Kevin Enderbya2b99102009-10-09 21:12:28 +00003470
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003471 // Add all the registers in the range to the register list.
3472 while (Reg != EndReg) {
3473 Reg = getNextRegister(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003474 EReg = MRI->getEncodingValue(Reg);
3475 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003476 }
3477 continue;
3478 }
3479 Parser.Lex(); // Eat the comma.
3480 RegLoc = Parser.getTok().getLoc();
3481 int OldReg = Reg;
Jim Grosbach98bc7972011-12-08 21:34:20 +00003482 const AsmToken RegTok = Parser.getTok();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003483 Reg = tryParseRegister();
3484 if (Reg == -1)
Jim Grosbach3337e392011-09-12 23:36:42 +00003485 return Error(RegLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003486 // Allow Q regs and just interpret them as the two D sub-registers.
3487 bool isQReg = false;
3488 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3489 Reg = getDRegFromQReg(Reg);
3490 isQReg = true;
3491 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003492 // The register must be in the same register class as the first.
3493 if (!RC->contains(Reg))
3494 return Error(RegLoc, "invalid register in register list");
3495 // List must be monotonically increasing.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003496 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbach905686a2012-03-16 20:48:38 +00003497 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3498 Warning(RegLoc, "register list not in ascending order");
3499 else
3500 return Error(RegLoc, "register list not in ascending order");
3501 }
Eric Christopher6ac277c2012-08-09 22:10:21 +00003502 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbach98bc7972011-12-08 21:34:20 +00003503 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3504 ") in register list");
3505 continue;
3506 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003507 // VFP register lists must also be contiguous.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003508 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3509 Reg != OldReg + 1)
3510 return Error(RegLoc, "non-contiguous register range");
Chad Rosierfa705ee2013-07-01 20:49:23 +00003511 EReg = MRI->getEncodingValue(Reg);
3512 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3513 if (isQReg) {
3514 EReg = MRI->getEncodingValue(++Reg);
3515 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3516 }
Bill Wendlinge18980a2010-11-06 22:36:58 +00003517 }
3518
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003519 if (Parser.getTok().isNot(AsmToken::RCurly))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003520 return Error(Parser.getTok().getLoc(), "'}' expected");
3521 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003522 Parser.Lex(); // Eat '}' token.
3523
Jim Grosbach18bf3632011-12-13 21:48:29 +00003524 // Push the register list operand.
Bill Wendling2063b842010-11-18 23:43:05 +00003525 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach18bf3632011-12-13 21:48:29 +00003526
3527 // The ARM system instruction variants for LDM/STM have a '^' token here.
3528 if (Parser.getTok().is(AsmToken::Caret)) {
3529 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3530 Parser.Lex(); // Eat '^' token.
3531 }
3532
Bill Wendling2063b842010-11-18 23:43:05 +00003533 return false;
Kevin Enderbya2b99102009-10-09 21:12:28 +00003534}
3535
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003536// Helper function to parse the lane index for vector lists.
3537ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003538parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003539 MCAsmParser &Parser = getParser();
Jim Grosbach04945c42011-12-02 00:35:16 +00003540 Index = 0; // Always return a defined index value.
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003541 if (Parser.getTok().is(AsmToken::LBrac)) {
3542 Parser.Lex(); // Eat the '['.
3543 if (Parser.getTok().is(AsmToken::RBrac)) {
3544 // "Dn[]" is the 'all lanes' syntax.
3545 LaneKind = AllLanes;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003546 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003547 Parser.Lex(); // Eat the ']'.
3548 return MatchOperand_Success;
3549 }
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003550
3551 // There's an optional '#' token here. Normally there wouldn't be, but
3552 // inline assemble puts one in, and it's friendly to accept that.
3553 if (Parser.getTok().is(AsmToken::Hash))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003554 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003555
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003556 const MCExpr *LaneIndex;
3557 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003558 if (getParser().parseExpression(LaneIndex)) {
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003559 Error(Loc, "illegal expression");
3560 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003561 }
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003562 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3563 if (!CE) {
3564 Error(Loc, "lane index must be empty or an integer");
3565 return MatchOperand_ParseFail;
3566 }
3567 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3568 Error(Parser.getTok().getLoc(), "']' expected");
3569 return MatchOperand_ParseFail;
3570 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003571 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003572 Parser.Lex(); // Eat the ']'.
3573 int64_t Val = CE->getValue();
3574
3575 // FIXME: Make this range check context sensitive for .8, .16, .32.
3576 if (Val < 0 || Val > 7) {
3577 Error(Parser.getTok().getLoc(), "lane index out of range");
3578 return MatchOperand_ParseFail;
3579 }
3580 Index = Val;
3581 LaneKind = IndexedLane;
3582 return MatchOperand_Success;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003583 }
3584 LaneKind = NoLanes;
3585 return MatchOperand_Success;
3586}
3587
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003588// parse a vector register list
David Blaikie960ea3f2014-06-08 16:18:35 +00003589ARMAsmParser::OperandMatchResultTy
3590ARMAsmParser::parseVectorList(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003591 MCAsmParser &Parser = getParser();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003592 VectorLaneTy LaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003593 unsigned LaneIndex;
Jim Grosbach8d579232011-11-15 21:45:55 +00003594 SMLoc S = Parser.getTok().getLoc();
3595 // As an extension (to match gas), support a plain D register or Q register
3596 // (without encosing curly braces) as a single or double entry list,
3597 // respectively.
3598 if (Parser.getTok().is(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003599 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach8d579232011-11-15 21:45:55 +00003600 int Reg = tryParseRegister();
3601 if (Reg == -1)
3602 return MatchOperand_NoMatch;
Jim Grosbach8d579232011-11-15 21:45:55 +00003603 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003604 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003605 if (Res != MatchOperand_Success)
3606 return Res;
3607 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003608 case NoLanes:
Jim Grosbach2f50e922011-12-15 21:44:33 +00003609 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003610 break;
3611 case AllLanes:
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003612 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3613 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003614 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003615 case IndexedLane:
3616 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003617 LaneIndex,
3618 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003619 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003620 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003621 return MatchOperand_Success;
3622 }
3623 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3624 Reg = getDRegFromQReg(Reg);
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003625 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003626 if (Res != MatchOperand_Success)
3627 return Res;
3628 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003629 case NoLanes:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003630 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbach13a292c2012-03-06 22:01:44 +00003631 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003632 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003633 break;
3634 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003635 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3636 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003637 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3638 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003639 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003640 case IndexedLane:
3641 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003642 LaneIndex,
3643 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003644 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003645 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003646 return MatchOperand_Success;
3647 }
3648 Error(S, "vector register expected");
3649 return MatchOperand_ParseFail;
3650 }
3651
3652 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003653 return MatchOperand_NoMatch;
3654
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003655 Parser.Lex(); // Eat '{' token.
3656 SMLoc RegLoc = Parser.getTok().getLoc();
3657
3658 int Reg = tryParseRegister();
3659 if (Reg == -1) {
3660 Error(RegLoc, "register expected");
3661 return MatchOperand_ParseFail;
3662 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003663 unsigned Count = 1;
Jim Grosbachc2f16a32011-12-15 21:54:55 +00003664 int Spacing = 0;
Jim Grosbach080a4992011-10-28 00:06:50 +00003665 unsigned FirstReg = Reg;
3666 // The list is of D registers, but we also allow Q regs and just interpret
3667 // them as the two D sub-registers.
3668 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3669 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003670 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3671 // it's ambiguous with four-register single spaced.
Jim Grosbach080a4992011-10-28 00:06:50 +00003672 ++Reg;
3673 ++Count;
3674 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003675
3676 SMLoc E;
3677 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003678 return MatchOperand_ParseFail;
Jim Grosbach080a4992011-10-28 00:06:50 +00003679
Jim Grosbache891fe82011-11-15 23:19:15 +00003680 while (Parser.getTok().is(AsmToken::Comma) ||
3681 Parser.getTok().is(AsmToken::Minus)) {
3682 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003683 if (!Spacing)
3684 Spacing = 1; // Register range implies a single spaced list.
3685 else if (Spacing == 2) {
3686 Error(Parser.getTok().getLoc(),
3687 "sequential registers in double spaced list");
3688 return MatchOperand_ParseFail;
3689 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003690 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003691 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbache891fe82011-11-15 23:19:15 +00003692 int EndReg = tryParseRegister();
3693 if (EndReg == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003694 Error(AfterMinusLoc, "register expected");
Jim Grosbache891fe82011-11-15 23:19:15 +00003695 return MatchOperand_ParseFail;
3696 }
3697 // Allow Q regs and just interpret them as the two D sub-registers.
3698 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3699 EndReg = getDRegFromQReg(EndReg) + 1;
3700 // If the register is the same as the start reg, there's nothing
3701 // more to do.
3702 if (Reg == EndReg)
3703 continue;
3704 // The register must be in the same register class as the first.
3705 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003706 Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003707 return MatchOperand_ParseFail;
3708 }
3709 // Ranges must go from low to high.
3710 if (Reg > EndReg) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003711 Error(AfterMinusLoc, "bad range in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003712 return MatchOperand_ParseFail;
3713 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003714 // Parse the lane specifier if present.
3715 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003716 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003717 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3718 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003719 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003720 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003721 Error(AfterMinusLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003722 return MatchOperand_ParseFail;
3723 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003724
3725 // Add all the registers in the range to the register list.
3726 Count += EndReg - Reg;
3727 Reg = EndReg;
3728 continue;
3729 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003730 Parser.Lex(); // Eat the comma.
3731 RegLoc = Parser.getTok().getLoc();
3732 int OldReg = Reg;
3733 Reg = tryParseRegister();
3734 if (Reg == -1) {
3735 Error(RegLoc, "register expected");
3736 return MatchOperand_ParseFail;
3737 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003738 // vector register lists must be contiguous.
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003739 // It's OK to use the enumeration values directly here rather, as the
3740 // VFP register classes have the enum sorted properly.
Jim Grosbach080a4992011-10-28 00:06:50 +00003741 //
3742 // The list is of D registers, but we also allow Q regs and just interpret
3743 // them as the two D sub-registers.
3744 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003745 if (!Spacing)
3746 Spacing = 1; // Register range implies a single spaced list.
3747 else if (Spacing == 2) {
3748 Error(RegLoc,
3749 "invalid register in double-spaced list (must be 'D' register')");
3750 return MatchOperand_ParseFail;
3751 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003752 Reg = getDRegFromQReg(Reg);
3753 if (Reg != OldReg + 1) {
3754 Error(RegLoc, "non-contiguous register range");
3755 return MatchOperand_ParseFail;
3756 }
3757 ++Reg;
3758 Count += 2;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003759 // Parse the lane specifier if present.
3760 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003761 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003762 SMLoc LaneLoc = Parser.getTok().getLoc();
3763 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3764 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003765 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003766 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003767 Error(LaneLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003768 return MatchOperand_ParseFail;
3769 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003770 continue;
3771 }
Jim Grosbach2f50e922011-12-15 21:44:33 +00003772 // Normal D register.
3773 // Figure out the register spacing (single or double) of the list if
3774 // we don't know it already.
3775 if (!Spacing)
3776 Spacing = 1 + (Reg == OldReg + 2);
3777
3778 // Just check that it's contiguous and keep going.
3779 if (Reg != OldReg + Spacing) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003780 Error(RegLoc, "non-contiguous register range");
3781 return MatchOperand_ParseFail;
3782 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003783 ++Count;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003784 // Parse the lane specifier if present.
3785 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003786 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003787 SMLoc EndLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003788 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003789 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003790 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003791 Error(EndLoc, "mismatched lane index in register list");
3792 return MatchOperand_ParseFail;
3793 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003794 }
3795
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003796 if (Parser.getTok().isNot(AsmToken::RCurly)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003797 Error(Parser.getTok().getLoc(), "'}' expected");
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003798 return MatchOperand_ParseFail;
3799 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003800 E = Parser.getTok().getEndLoc();
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003801 Parser.Lex(); // Eat '}' token.
3802
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003803 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003804 case NoLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003805 // Two-register operands have been converted to the
Jim Grosbache5307f92012-03-05 21:43:40 +00003806 // composite register classes.
3807 if (Count == 2) {
3808 const MCRegisterClass *RC = (Spacing == 1) ?
3809 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3810 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3811 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3812 }
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003813
Jim Grosbach2f50e922011-12-15 21:44:33 +00003814 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3815 (Spacing == 2), S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003816 break;
3817 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003818 // Two-register operands have been converted to the
3819 // composite register classes.
Jim Grosbached428bc2012-03-06 23:10:38 +00003820 if (Count == 2) {
3821 const MCRegisterClass *RC = (Spacing == 1) ?
3822 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3823 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbach13a292c2012-03-06 22:01:44 +00003824 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3825 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003826 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003827 (Spacing == 2),
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003828 S, E));
3829 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003830 case IndexedLane:
3831 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003832 LaneIndex,
3833 (Spacing == 2),
3834 S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003835 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003836 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003837 return MatchOperand_Success;
3838}
3839
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003840/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
David Blaikie960ea3f2014-06-08 16:18:35 +00003841ARMAsmParser::OperandMatchResultTy
3842ARMAsmParser::parseMemBarrierOptOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003843 MCAsmParser &Parser = getParser();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003844 SMLoc S = Parser.getTok().getLoc();
3845 const AsmToken &Tok = Parser.getTok();
Jiangning Liu288e1af2012-08-02 08:21:27 +00003846 unsigned Opt;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003847
Jiangning Liu288e1af2012-08-02 08:21:27 +00003848 if (Tok.is(AsmToken::Identifier)) {
3849 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003850
Jiangning Liu288e1af2012-08-02 08:21:27 +00003851 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3852 .Case("sy", ARM_MB::SY)
3853 .Case("st", ARM_MB::ST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003854 .Case("ld", ARM_MB::LD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003855 .Case("sh", ARM_MB::ISH)
3856 .Case("ish", ARM_MB::ISH)
3857 .Case("shst", ARM_MB::ISHST)
3858 .Case("ishst", ARM_MB::ISHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003859 .Case("ishld", ARM_MB::ISHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003860 .Case("nsh", ARM_MB::NSH)
3861 .Case("un", ARM_MB::NSH)
3862 .Case("nshst", ARM_MB::NSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003863 .Case("nshld", ARM_MB::NSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003864 .Case("unst", ARM_MB::NSHST)
3865 .Case("osh", ARM_MB::OSH)
3866 .Case("oshst", ARM_MB::OSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003867 .Case("oshld", ARM_MB::OSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003868 .Default(~0U);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003869
Joey Gouly926d3f52013-09-05 15:35:24 +00003870 // ishld, oshld, nshld and ld are only available from ARMv8.
3871 if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD ||
3872 Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD))
3873 Opt = ~0U;
3874
Jiangning Liu288e1af2012-08-02 08:21:27 +00003875 if (Opt == ~0U)
3876 return MatchOperand_NoMatch;
3877
3878 Parser.Lex(); // Eat identifier token.
3879 } else if (Tok.is(AsmToken::Hash) ||
3880 Tok.is(AsmToken::Dollar) ||
3881 Tok.is(AsmToken::Integer)) {
3882 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003883 Parser.Lex(); // Eat '#' or '$'.
Jiangning Liu288e1af2012-08-02 08:21:27 +00003884 SMLoc Loc = Parser.getTok().getLoc();
3885
3886 const MCExpr *MemBarrierID;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003887 if (getParser().parseExpression(MemBarrierID)) {
Jiangning Liu288e1af2012-08-02 08:21:27 +00003888 Error(Loc, "illegal expression");
3889 return MatchOperand_ParseFail;
3890 }
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +00003891
Jiangning Liu288e1af2012-08-02 08:21:27 +00003892 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3893 if (!CE) {
3894 Error(Loc, "constant expression expected");
3895 return MatchOperand_ParseFail;
3896 }
3897
3898 int Val = CE->getValue();
3899 if (Val & ~0xf) {
3900 Error(Loc, "immediate value out of range");
3901 return MatchOperand_ParseFail;
3902 }
3903
3904 Opt = ARM_MB::RESERVED_0 + Val;
3905 } else
3906 return MatchOperand_ParseFail;
3907
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003908 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003909 return MatchOperand_Success;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003910}
3911
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003912/// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
David Blaikie960ea3f2014-06-08 16:18:35 +00003913ARMAsmParser::OperandMatchResultTy
3914ARMAsmParser::parseInstSyncBarrierOptOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003915 MCAsmParser &Parser = getParser();
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003916 SMLoc S = Parser.getTok().getLoc();
3917 const AsmToken &Tok = Parser.getTok();
3918 unsigned Opt;
3919
3920 if (Tok.is(AsmToken::Identifier)) {
3921 StringRef OptStr = Tok.getString();
3922
Benjamin Kramer3e9237a2013-11-09 22:48:13 +00003923 if (OptStr.equals_lower("sy"))
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003924 Opt = ARM_ISB::SY;
3925 else
3926 return MatchOperand_NoMatch;
3927
3928 Parser.Lex(); // Eat identifier token.
3929 } else if (Tok.is(AsmToken::Hash) ||
3930 Tok.is(AsmToken::Dollar) ||
3931 Tok.is(AsmToken::Integer)) {
3932 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003933 Parser.Lex(); // Eat '#' or '$'.
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003934 SMLoc Loc = Parser.getTok().getLoc();
3935
3936 const MCExpr *ISBarrierID;
3937 if (getParser().parseExpression(ISBarrierID)) {
3938 Error(Loc, "illegal expression");
3939 return MatchOperand_ParseFail;
3940 }
3941
3942 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3943 if (!CE) {
3944 Error(Loc, "constant expression expected");
3945 return MatchOperand_ParseFail;
3946 }
3947
3948 int Val = CE->getValue();
3949 if (Val & ~0xf) {
3950 Error(Loc, "immediate value out of range");
3951 return MatchOperand_ParseFail;
3952 }
3953
3954 Opt = ARM_ISB::RESERVED_0 + Val;
3955 } else
3956 return MatchOperand_ParseFail;
3957
3958 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3959 (ARM_ISB::InstSyncBOpt)Opt, S));
3960 return MatchOperand_Success;
3961}
3962
3963
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003964/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
David Blaikie960ea3f2014-06-08 16:18:35 +00003965ARMAsmParser::OperandMatchResultTy
3966ARMAsmParser::parseProcIFlagsOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003967 MCAsmParser &Parser = getParser();
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003968 SMLoc S = Parser.getTok().getLoc();
3969 const AsmToken &Tok = Parser.getTok();
Richard Bartonb0ec3752012-06-14 10:48:04 +00003970 if (!Tok.is(AsmToken::Identifier))
3971 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003972 StringRef IFlagsStr = Tok.getString();
3973
Owen Anderson10c5b122011-10-05 17:16:40 +00003974 // An iflags string of "none" is interpreted to mean that none of the AIF
3975 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003976 unsigned IFlags = 0;
Owen Anderson10c5b122011-10-05 17:16:40 +00003977 if (IFlagsStr != "none") {
3978 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3979 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3980 .Case("a", ARM_PROC::A)
3981 .Case("i", ARM_PROC::I)
3982 .Case("f", ARM_PROC::F)
3983 .Default(~0U);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003984
Owen Anderson10c5b122011-10-05 17:16:40 +00003985 // If some specific iflag is already set, it means that some letter is
3986 // present more than once, this is not acceptable.
3987 if (Flag == ~0U || (IFlags & Flag))
3988 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003989
Owen Anderson10c5b122011-10-05 17:16:40 +00003990 IFlags |= Flag;
3991 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003992 }
3993
3994 Parser.Lex(); // Eat identifier token.
3995 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3996 return MatchOperand_Success;
3997}
3998
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003999/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
David Blaikie960ea3f2014-06-08 16:18:35 +00004000ARMAsmParser::OperandMatchResultTy
4001ARMAsmParser::parseMSRMaskOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004002 MCAsmParser &Parser = getParser();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004003 SMLoc S = Parser.getTok().getLoc();
4004 const AsmToken &Tok = Parser.getTok();
Craig Toppera004b0d2012-10-09 04:55:28 +00004005 if (!Tok.is(AsmToken::Identifier))
4006 return MatchOperand_NoMatch;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004007 StringRef Mask = Tok.getString();
4008
James Molloy21efa7d2011-09-28 14:21:38 +00004009 if (isMClass()) {
4010 // See ARMv6-M 10.1.1
Jim Grosbachd28888d2012-03-15 21:34:14 +00004011 std::string Name = Mask.lower();
4012 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00004013 // Note: in the documentation:
4014 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
4015 // for MSR APSR_nzcvq.
4016 // but we do make it an alias here. This is so to get the "mask encoding"
4017 // bits correct on MSR APSR writes.
4018 //
4019 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
4020 // should really only be allowed when writing a special register. Note
4021 // they get dropped in the MRS instruction reading a special register as
4022 // the SYSm field is only 8 bits.
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00004023 .Case("apsr", 0x800)
4024 .Case("apsr_nzcvq", 0x800)
4025 .Case("apsr_g", 0x400)
4026 .Case("apsr_nzcvqg", 0xc00)
4027 .Case("iapsr", 0x801)
4028 .Case("iapsr_nzcvq", 0x801)
4029 .Case("iapsr_g", 0x401)
4030 .Case("iapsr_nzcvqg", 0xc01)
4031 .Case("eapsr", 0x802)
4032 .Case("eapsr_nzcvq", 0x802)
4033 .Case("eapsr_g", 0x402)
4034 .Case("eapsr_nzcvqg", 0xc02)
4035 .Case("xpsr", 0x803)
4036 .Case("xpsr_nzcvq", 0x803)
4037 .Case("xpsr_g", 0x403)
4038 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderby6c7279e2012-06-15 22:14:44 +00004039 .Case("ipsr", 0x805)
4040 .Case("epsr", 0x806)
4041 .Case("iepsr", 0x807)
4042 .Case("msp", 0x808)
4043 .Case("psp", 0x809)
4044 .Case("primask", 0x810)
4045 .Case("basepri", 0x811)
4046 .Case("basepri_max", 0x812)
4047 .Case("faultmask", 0x813)
4048 .Case("control", 0x814)
James Molloy21efa7d2011-09-28 14:21:38 +00004049 .Default(~0U);
Jim Grosbach3794d822011-12-22 17:17:10 +00004050
James Molloy21efa7d2011-09-28 14:21:38 +00004051 if (FlagsVal == ~0U)
4052 return MatchOperand_NoMatch;
4053
Renato Golin92c816c2014-09-01 11:25:07 +00004054 if (!hasThumb2DSP() && (FlagsVal & 0x400))
4055 // The _g and _nzcvqg versions are only valid if the DSP extension is
4056 // available.
4057 return MatchOperand_NoMatch;
4058
Kevin Enderby6c7279e2012-06-15 22:14:44 +00004059 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloy21efa7d2011-09-28 14:21:38 +00004060 // basepri, basepri_max and faultmask only valid for V7m.
4061 return MatchOperand_NoMatch;
Jim Grosbach3794d822011-12-22 17:17:10 +00004062
James Molloy21efa7d2011-09-28 14:21:38 +00004063 Parser.Lex(); // Eat identifier token.
4064 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
4065 return MatchOperand_Success;
4066 }
4067
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004068 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
4069 size_t Start = 0, Next = Mask.find('_');
4070 StringRef Flags = "";
Benjamin Kramer20baffb2011-11-06 20:37:06 +00004071 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004072 if (Next != StringRef::npos)
4073 Flags = Mask.slice(Next+1, Mask.size());
4074
4075 // FlagsVal contains the complete mask:
4076 // 3-0: Mask
4077 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
4078 unsigned FlagsVal = 0;
4079
4080 if (SpecReg == "apsr") {
4081 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +00004082 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004083 .Case("g", 0x4) // same as CPSR_s
4084 .Case("nzcvqg", 0xc) // same as CPSR_fs
4085 .Default(~0U);
4086
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00004087 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004088 if (!Flags.empty())
4089 return MatchOperand_NoMatch;
4090 else
Jim Grosbach0ecd3952011-09-14 20:03:46 +00004091 FlagsVal = 8; // No flag
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00004092 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004093 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbach3d00eec2012-04-05 03:17:53 +00004094 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
4095 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes54452132011-05-25 00:35:03 +00004096 Flags = "fc";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004097 for (int i = 0, e = Flags.size(); i != e; ++i) {
4098 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
4099 .Case("c", 1)
4100 .Case("x", 2)
4101 .Case("s", 4)
4102 .Case("f", 8)
4103 .Default(~0U);
4104
4105 // If some specific flag is already set, it means that some letter is
4106 // present more than once, this is not acceptable.
4107 if (FlagsVal == ~0U || (FlagsVal & Flag))
4108 return MatchOperand_NoMatch;
4109 FlagsVal |= Flag;
4110 }
4111 } else // No match for special register.
4112 return MatchOperand_NoMatch;
4113
Owen Anderson03a173e2011-10-21 18:43:28 +00004114 // Special register without flags is NOT equivalent to "fc" flags.
4115 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
4116 // two lines would enable gas compatibility at the expense of breaking
4117 // round-tripping.
4118 //
4119 // if (!FlagsVal)
4120 // FlagsVal = 0x9;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004121
4122 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
4123 if (SpecReg == "spsr")
4124 FlagsVal |= 16;
4125
4126 Parser.Lex(); // Eat identifier token.
4127 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
4128 return MatchOperand_Success;
4129}
4130
Tim Northoveree843ef2014-08-15 10:47:12 +00004131/// parseBankedRegOperand - Try to parse a banked register (e.g. "lr_irq") for
4132/// use in the MRS/MSR instructions added to support virtualization.
4133ARMAsmParser::OperandMatchResultTy
4134ARMAsmParser::parseBankedRegOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004135 MCAsmParser &Parser = getParser();
Tim Northoveree843ef2014-08-15 10:47:12 +00004136 SMLoc S = Parser.getTok().getLoc();
4137 const AsmToken &Tok = Parser.getTok();
4138 if (!Tok.is(AsmToken::Identifier))
4139 return MatchOperand_NoMatch;
4140 StringRef RegName = Tok.getString();
4141
4142 // The values here come from B9.2.3 of the ARM ARM, where bits 4-0 are SysM
4143 // and bit 5 is R.
4144 unsigned Encoding = StringSwitch<unsigned>(RegName.lower())
4145 .Case("r8_usr", 0x00)
4146 .Case("r9_usr", 0x01)
4147 .Case("r10_usr", 0x02)
4148 .Case("r11_usr", 0x03)
4149 .Case("r12_usr", 0x04)
4150 .Case("sp_usr", 0x05)
4151 .Case("lr_usr", 0x06)
4152 .Case("r8_fiq", 0x08)
4153 .Case("r9_fiq", 0x09)
4154 .Case("r10_fiq", 0x0a)
4155 .Case("r11_fiq", 0x0b)
4156 .Case("r12_fiq", 0x0c)
4157 .Case("sp_fiq", 0x0d)
4158 .Case("lr_fiq", 0x0e)
4159 .Case("lr_irq", 0x10)
4160 .Case("sp_irq", 0x11)
4161 .Case("lr_svc", 0x12)
4162 .Case("sp_svc", 0x13)
4163 .Case("lr_abt", 0x14)
4164 .Case("sp_abt", 0x15)
4165 .Case("lr_und", 0x16)
4166 .Case("sp_und", 0x17)
4167 .Case("lr_mon", 0x1c)
4168 .Case("sp_mon", 0x1d)
4169 .Case("elr_hyp", 0x1e)
4170 .Case("sp_hyp", 0x1f)
4171 .Case("spsr_fiq", 0x2e)
4172 .Case("spsr_irq", 0x30)
4173 .Case("spsr_svc", 0x32)
4174 .Case("spsr_abt", 0x34)
4175 .Case("spsr_und", 0x36)
4176 .Case("spsr_mon", 0x3c)
4177 .Case("spsr_hyp", 0x3e)
4178 .Default(~0U);
4179
4180 if (Encoding == ~0U)
4181 return MatchOperand_NoMatch;
4182
4183 Parser.Lex(); // Eat identifier token.
4184 Operands.push_back(ARMOperand::CreateBankedReg(Encoding, S));
4185 return MatchOperand_Success;
4186}
4187
David Blaikie960ea3f2014-06-08 16:18:35 +00004188ARMAsmParser::OperandMatchResultTy
4189ARMAsmParser::parsePKHImm(OperandVector &Operands, StringRef Op, int Low,
4190 int High) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004191 MCAsmParser &Parser = getParser();
Jim Grosbach27c1e252011-07-21 17:23:04 +00004192 const AsmToken &Tok = Parser.getTok();
4193 if (Tok.isNot(AsmToken::Identifier)) {
4194 Error(Parser.getTok().getLoc(), Op + " operand expected.");
4195 return MatchOperand_ParseFail;
4196 }
4197 StringRef ShiftName = Tok.getString();
Benjamin Kramer20baffb2011-11-06 20:37:06 +00004198 std::string LowerOp = Op.lower();
4199 std::string UpperOp = Op.upper();
Jim Grosbach27c1e252011-07-21 17:23:04 +00004200 if (ShiftName != LowerOp && ShiftName != UpperOp) {
4201 Error(Parser.getTok().getLoc(), Op + " operand expected.");
4202 return MatchOperand_ParseFail;
4203 }
4204 Parser.Lex(); // Eat shift type token.
4205
4206 // There must be a '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004207 if (Parser.getTok().isNot(AsmToken::Hash) &&
4208 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00004209 Error(Parser.getTok().getLoc(), "'#' expected");
4210 return MatchOperand_ParseFail;
4211 }
4212 Parser.Lex(); // Eat hash token.
4213
4214 const MCExpr *ShiftAmount;
4215 SMLoc Loc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004216 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004217 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00004218 Error(Loc, "illegal expression");
4219 return MatchOperand_ParseFail;
4220 }
4221 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4222 if (!CE) {
4223 Error(Loc, "constant expression expected");
4224 return MatchOperand_ParseFail;
4225 }
4226 int Val = CE->getValue();
4227 if (Val < Low || Val > High) {
4228 Error(Loc, "immediate value out of range");
4229 return MatchOperand_ParseFail;
4230 }
4231
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004232 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
Jim Grosbach27c1e252011-07-21 17:23:04 +00004233
4234 return MatchOperand_Success;
4235}
4236
David Blaikie960ea3f2014-06-08 16:18:35 +00004237ARMAsmParser::OperandMatchResultTy
4238ARMAsmParser::parseSetEndImm(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004239 MCAsmParser &Parser = getParser();
Jim Grosbach0a547702011-07-22 17:44:50 +00004240 const AsmToken &Tok = Parser.getTok();
4241 SMLoc S = Tok.getLoc();
4242 if (Tok.isNot(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004243 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00004244 return MatchOperand_ParseFail;
4245 }
Tim Northover4d141442013-05-31 15:58:45 +00004246 int Val = StringSwitch<int>(Tok.getString().lower())
Jim Grosbach0a547702011-07-22 17:44:50 +00004247 .Case("be", 1)
4248 .Case("le", 0)
4249 .Default(-1);
4250 Parser.Lex(); // Eat the token.
4251
4252 if (Val == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004253 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00004254 return MatchOperand_ParseFail;
4255 }
4256 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
4257 getContext()),
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004258 S, Tok.getEndLoc()));
Jim Grosbach0a547702011-07-22 17:44:50 +00004259 return MatchOperand_Success;
4260}
4261
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004262/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
4263/// instructions. Legal values are:
4264/// lsl #n 'n' in [0,31]
4265/// asr #n 'n' in [1,32]
4266/// n == 32 encoded as n == 0.
David Blaikie960ea3f2014-06-08 16:18:35 +00004267ARMAsmParser::OperandMatchResultTy
4268ARMAsmParser::parseShifterImm(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004269 MCAsmParser &Parser = getParser();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004270 const AsmToken &Tok = Parser.getTok();
4271 SMLoc S = Tok.getLoc();
4272 if (Tok.isNot(AsmToken::Identifier)) {
4273 Error(S, "shift operator 'asr' or 'lsl' expected");
4274 return MatchOperand_ParseFail;
4275 }
4276 StringRef ShiftName = Tok.getString();
4277 bool isASR;
4278 if (ShiftName == "lsl" || ShiftName == "LSL")
4279 isASR = false;
4280 else if (ShiftName == "asr" || ShiftName == "ASR")
4281 isASR = true;
4282 else {
4283 Error(S, "shift operator 'asr' or 'lsl' expected");
4284 return MatchOperand_ParseFail;
4285 }
4286 Parser.Lex(); // Eat the operator.
4287
4288 // A '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004289 if (Parser.getTok().isNot(AsmToken::Hash) &&
4290 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004291 Error(Parser.getTok().getLoc(), "'#' expected");
4292 return MatchOperand_ParseFail;
4293 }
4294 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004295 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004296
4297 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004298 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004299 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004300 Error(ExLoc, "malformed shift expression");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004301 return MatchOperand_ParseFail;
4302 }
4303 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4304 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004305 Error(ExLoc, "shift amount must be an immediate");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004306 return MatchOperand_ParseFail;
4307 }
4308
4309 int64_t Val = CE->getValue();
4310 if (isASR) {
4311 // Shift amount must be in [1,32]
4312 if (Val < 1 || Val > 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004313 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004314 return MatchOperand_ParseFail;
4315 }
Owen Andersonf01e2de2011-09-26 21:06:22 +00004316 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
4317 if (isThumb() && Val == 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004318 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
Owen Andersonf01e2de2011-09-26 21:06:22 +00004319 return MatchOperand_ParseFail;
4320 }
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004321 if (Val == 32) Val = 0;
4322 } else {
4323 // Shift amount must be in [1,32]
4324 if (Val < 0 || Val > 31) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004325 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004326 return MatchOperand_ParseFail;
4327 }
4328 }
4329
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004330 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004331
4332 return MatchOperand_Success;
4333}
4334
Jim Grosbach833b9d32011-07-27 20:15:40 +00004335/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
4336/// of instructions. Legal values are:
4337/// ror #n 'n' in {0, 8, 16, 24}
David Blaikie960ea3f2014-06-08 16:18:35 +00004338ARMAsmParser::OperandMatchResultTy
4339ARMAsmParser::parseRotImm(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004340 MCAsmParser &Parser = getParser();
Jim Grosbach833b9d32011-07-27 20:15:40 +00004341 const AsmToken &Tok = Parser.getTok();
4342 SMLoc S = Tok.getLoc();
Jim Grosbach82213192011-09-19 20:29:33 +00004343 if (Tok.isNot(AsmToken::Identifier))
4344 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00004345 StringRef ShiftName = Tok.getString();
Jim Grosbach82213192011-09-19 20:29:33 +00004346 if (ShiftName != "ror" && ShiftName != "ROR")
4347 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00004348 Parser.Lex(); // Eat the operator.
4349
4350 // A '#' and a rotate amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004351 if (Parser.getTok().isNot(AsmToken::Hash) &&
4352 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00004353 Error(Parser.getTok().getLoc(), "'#' expected");
4354 return MatchOperand_ParseFail;
4355 }
4356 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004357 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach833b9d32011-07-27 20:15:40 +00004358
4359 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004360 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004361 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004362 Error(ExLoc, "malformed rotate expression");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004363 return MatchOperand_ParseFail;
4364 }
4365 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4366 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004367 Error(ExLoc, "rotate amount must be an immediate");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004368 return MatchOperand_ParseFail;
4369 }
4370
4371 int64_t Val = CE->getValue();
4372 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
4373 // normally, zero is represented in asm by omitting the rotate operand
4374 // entirely.
4375 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004376 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004377 return MatchOperand_ParseFail;
4378 }
4379
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004380 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
Jim Grosbach833b9d32011-07-27 20:15:40 +00004381
4382 return MatchOperand_Success;
4383}
4384
David Blaikie960ea3f2014-06-08 16:18:35 +00004385ARMAsmParser::OperandMatchResultTy
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004386ARMAsmParser::parseModImm(OperandVector &Operands) {
4387 MCAsmParser &Parser = getParser();
4388 MCAsmLexer &Lexer = getLexer();
4389 int64_t Imm1, Imm2;
4390
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004391 SMLoc S = Parser.getTok().getLoc();
4392
Asiri Rathnayake13cef352014-12-04 19:34:59 +00004393 // 1) A mod_imm operand can appear in the place of a register name:
4394 // add r0, #mod_imm
4395 // add r0, r0, #mod_imm
4396 // to correctly handle the latter, we bail out as soon as we see an
4397 // identifier.
4398 //
4399 // 2) Similarly, we do not want to parse into complex operands:
4400 // mov r0, #mod_imm
4401 // mov r0, :lower16:(_foo)
4402 if (Parser.getTok().is(AsmToken::Identifier) ||
4403 Parser.getTok().is(AsmToken::Colon))
4404 return MatchOperand_NoMatch;
4405
4406 // Hash (dollar) is optional as per the ARMARM
4407 if (Parser.getTok().is(AsmToken::Hash) ||
4408 Parser.getTok().is(AsmToken::Dollar)) {
4409 // Avoid parsing into complex operands (#:)
4410 if (Lexer.peekTok().is(AsmToken::Colon))
4411 return MatchOperand_NoMatch;
4412
4413 // Eat the hash (dollar)
4414 Parser.Lex();
4415 }
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004416
4417 SMLoc Sx1, Ex1;
4418 Sx1 = Parser.getTok().getLoc();
4419 const MCExpr *Imm1Exp;
4420 if (getParser().parseExpression(Imm1Exp, Ex1)) {
4421 Error(Sx1, "malformed expression");
4422 return MatchOperand_ParseFail;
4423 }
4424
4425 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm1Exp);
4426
4427 if (CE) {
Asiri Rathnayaked33304b2014-12-04 14:49:07 +00004428 // Immediate must fit within 32-bits
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004429 Imm1 = CE->getValue();
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004430 int Enc = ARM_AM::getSOImmVal(Imm1);
4431 if (Enc != -1 && Parser.getTok().is(AsmToken::EndOfStatement)) {
4432 // We have a match!
4433 Operands.push_back(ARMOperand::CreateModImm((Enc & 0xFF),
4434 (Enc & 0xF00) >> 7,
4435 Sx1, Ex1));
4436 return MatchOperand_Success;
4437 }
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004438
Asiri Rathnayaked33304b2014-12-04 14:49:07 +00004439 // We have parsed an immediate which is not for us, fallback to a plain
4440 // immediate. This can happen for instruction aliases. For an example,
4441 // ARMInstrInfo.td defines the alias [mov <-> mvn] which can transform
4442 // a mov (mvn) with a mod_imm_neg/mod_imm_not operand into the opposite
4443 // instruction with a mod_imm operand. The alias is defined such that the
4444 // parser method is shared, that's why we have to do this here.
4445 if (Parser.getTok().is(AsmToken::EndOfStatement)) {
4446 Operands.push_back(ARMOperand::CreateImm(Imm1Exp, Sx1, Ex1));
4447 return MatchOperand_Success;
4448 }
4449 } else {
4450 // Operands like #(l1 - l2) can only be evaluated at a later stage (via an
4451 // MCFixup). Fallback to a plain immediate.
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004452 Operands.push_back(ARMOperand::CreateImm(Imm1Exp, Sx1, Ex1));
4453 return MatchOperand_Success;
4454 }
4455
4456 // From this point onward, we expect the input to be a (#bits, #rot) pair
Asiri Rathnayaked33304b2014-12-04 14:49:07 +00004457 if (Parser.getTok().isNot(AsmToken::Comma)) {
4458 Error(Sx1, "expected modified immediate operand: #[0, 255], #even[0-30]");
4459 return MatchOperand_ParseFail;
4460 }
4461
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004462 if (Imm1 & ~0xFF) {
4463 Error(Sx1, "immediate operand must a number in the range [0, 255]");
4464 return MatchOperand_ParseFail;
4465 }
4466
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004467 // Eat the comma
4468 Parser.Lex();
4469
4470 // Repeat for #rot
4471 SMLoc Sx2, Ex2;
4472 Sx2 = Parser.getTok().getLoc();
4473
Asiri Rathnayake13cef352014-12-04 19:34:59 +00004474 // Eat the optional hash (dollar)
4475 if (Parser.getTok().is(AsmToken::Hash) ||
4476 Parser.getTok().is(AsmToken::Dollar))
4477 Parser.Lex();
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004478
4479 const MCExpr *Imm2Exp;
4480 if (getParser().parseExpression(Imm2Exp, Ex2)) {
4481 Error(Sx2, "malformed expression");
4482 return MatchOperand_ParseFail;
4483 }
4484
4485 CE = dyn_cast<MCConstantExpr>(Imm2Exp);
4486
4487 if (CE) {
4488 Imm2 = CE->getValue();
4489 if (!(Imm2 & ~0x1E)) {
4490 // We have a match!
4491 Operands.push_back(ARMOperand::CreateModImm(Imm1, Imm2, S, Ex2));
4492 return MatchOperand_Success;
4493 }
4494 Error(Sx2, "immediate operand must an even number in the range [0, 30]");
4495 return MatchOperand_ParseFail;
4496 } else {
4497 Error(Sx2, "constant expression expected");
4498 return MatchOperand_ParseFail;
4499 }
4500}
4501
4502ARMAsmParser::OperandMatchResultTy
David Blaikie960ea3f2014-06-08 16:18:35 +00004503ARMAsmParser::parseBitfield(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004504 MCAsmParser &Parser = getParser();
Jim Grosbach864b6092011-07-28 21:34:26 +00004505 SMLoc S = Parser.getTok().getLoc();
4506 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004507 if (Parser.getTok().isNot(AsmToken::Hash) &&
4508 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004509 Error(Parser.getTok().getLoc(), "'#' expected");
4510 return MatchOperand_ParseFail;
4511 }
4512 Parser.Lex(); // Eat hash token.
4513
4514 const MCExpr *LSBExpr;
4515 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004516 if (getParser().parseExpression(LSBExpr)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004517 Error(E, "malformed immediate expression");
4518 return MatchOperand_ParseFail;
4519 }
4520 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
4521 if (!CE) {
4522 Error(E, "'lsb' operand must be an immediate");
4523 return MatchOperand_ParseFail;
4524 }
4525
4526 int64_t LSB = CE->getValue();
4527 // The LSB must be in the range [0,31]
4528 if (LSB < 0 || LSB > 31) {
4529 Error(E, "'lsb' operand must be in the range [0,31]");
4530 return MatchOperand_ParseFail;
4531 }
4532 E = Parser.getTok().getLoc();
4533
4534 // Expect another immediate operand.
4535 if (Parser.getTok().isNot(AsmToken::Comma)) {
4536 Error(Parser.getTok().getLoc(), "too few operands");
4537 return MatchOperand_ParseFail;
4538 }
4539 Parser.Lex(); // Eat hash token.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004540 if (Parser.getTok().isNot(AsmToken::Hash) &&
4541 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004542 Error(Parser.getTok().getLoc(), "'#' expected");
4543 return MatchOperand_ParseFail;
4544 }
4545 Parser.Lex(); // Eat hash token.
4546
4547 const MCExpr *WidthExpr;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004548 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004549 if (getParser().parseExpression(WidthExpr, EndLoc)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004550 Error(E, "malformed immediate expression");
4551 return MatchOperand_ParseFail;
4552 }
4553 CE = dyn_cast<MCConstantExpr>(WidthExpr);
4554 if (!CE) {
4555 Error(E, "'width' operand must be an immediate");
4556 return MatchOperand_ParseFail;
4557 }
4558
4559 int64_t Width = CE->getValue();
4560 // The LSB must be in the range [1,32-lsb]
4561 if (Width < 1 || Width > 32 - LSB) {
4562 Error(E, "'width' operand must be in the range [1,32-lsb]");
4563 return MatchOperand_ParseFail;
4564 }
Jim Grosbach864b6092011-07-28 21:34:26 +00004565
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004566 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
Jim Grosbach864b6092011-07-28 21:34:26 +00004567
4568 return MatchOperand_Success;
4569}
4570
David Blaikie960ea3f2014-06-08 16:18:35 +00004571ARMAsmParser::OperandMatchResultTy
4572ARMAsmParser::parsePostIdxReg(OperandVector &Operands) {
Jim Grosbachd3595712011-08-03 23:50:40 +00004573 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachc320c852011-08-05 21:28:30 +00004574 // postidx_reg := '+' register {, shift}
4575 // | '-' register {, shift}
4576 // | register {, shift}
Jim Grosbachd3595712011-08-03 23:50:40 +00004577
4578 // This method must return MatchOperand_NoMatch without consuming any tokens
4579 // in the case where there is no match, as other alternatives take other
4580 // parse methods.
Rafael Espindola961d4692014-11-11 05:18:41 +00004581 MCAsmParser &Parser = getParser();
Jim Grosbachd3595712011-08-03 23:50:40 +00004582 AsmToken Tok = Parser.getTok();
4583 SMLoc S = Tok.getLoc();
4584 bool haveEaten = false;
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004585 bool isAdd = true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004586 if (Tok.is(AsmToken::Plus)) {
4587 Parser.Lex(); // Eat the '+' token.
4588 haveEaten = true;
4589 } else if (Tok.is(AsmToken::Minus)) {
4590 Parser.Lex(); // Eat the '-' token.
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004591 isAdd = false;
Jim Grosbachd3595712011-08-03 23:50:40 +00004592 haveEaten = true;
4593 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004594
4595 SMLoc E = Parser.getTok().getEndLoc();
4596 int Reg = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004597 if (Reg == -1) {
4598 if (!haveEaten)
4599 return MatchOperand_NoMatch;
4600 Error(Parser.getTok().getLoc(), "register expected");
4601 return MatchOperand_ParseFail;
4602 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004603
Jim Grosbachc320c852011-08-05 21:28:30 +00004604 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
4605 unsigned ShiftImm = 0;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004606 if (Parser.getTok().is(AsmToken::Comma)) {
4607 Parser.Lex(); // Eat the ','.
4608 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4609 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004610
4611 // FIXME: Only approximates end...may include intervening whitespace.
4612 E = Parser.getTok().getLoc();
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004613 }
Jim Grosbachc320c852011-08-05 21:28:30 +00004614
4615 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4616 ShiftImm, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004617
4618 return MatchOperand_Success;
4619}
4620
David Blaikie960ea3f2014-06-08 16:18:35 +00004621ARMAsmParser::OperandMatchResultTy
4622ARMAsmParser::parseAM3Offset(OperandVector &Operands) {
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004623 // Check for a post-index addressing register operand. Specifically:
4624 // am3offset := '+' register
4625 // | '-' register
4626 // | register
4627 // | # imm
4628 // | # + imm
4629 // | # - imm
4630
4631 // This method must return MatchOperand_NoMatch without consuming any tokens
4632 // in the case where there is no match, as other alternatives take other
4633 // parse methods.
Rafael Espindola961d4692014-11-11 05:18:41 +00004634 MCAsmParser &Parser = getParser();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004635 AsmToken Tok = Parser.getTok();
4636 SMLoc S = Tok.getLoc();
4637
4638 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004639 if (Parser.getTok().is(AsmToken::Hash) ||
4640 Parser.getTok().is(AsmToken::Dollar)) {
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004641 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004642 // Explicitly look for a '-', as we need to encode negative zero
4643 // differently.
4644 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4645 const MCExpr *Offset;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004646 SMLoc E;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004647 if (getParser().parseExpression(Offset, E))
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004648 return MatchOperand_ParseFail;
4649 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4650 if (!CE) {
4651 Error(S, "constant expression expected");
4652 return MatchOperand_ParseFail;
4653 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004654 // Negative zero is encoded as the flag value INT32_MIN.
4655 int32_t Val = CE->getValue();
4656 if (isNegative && Val == 0)
4657 Val = INT32_MIN;
4658
4659 Operands.push_back(
4660 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4661
4662 return MatchOperand_Success;
4663 }
4664
4665
4666 bool haveEaten = false;
4667 bool isAdd = true;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004668 if (Tok.is(AsmToken::Plus)) {
4669 Parser.Lex(); // Eat the '+' token.
4670 haveEaten = true;
4671 } else if (Tok.is(AsmToken::Minus)) {
4672 Parser.Lex(); // Eat the '-' token.
4673 isAdd = false;
4674 haveEaten = true;
4675 }
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +00004676
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004677 Tok = Parser.getTok();
4678 int Reg = tryParseRegister();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004679 if (Reg == -1) {
4680 if (!haveEaten)
4681 return MatchOperand_NoMatch;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004682 Error(Tok.getLoc(), "register expected");
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004683 return MatchOperand_ParseFail;
4684 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004685
4686 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004687 0, S, Tok.getEndLoc()));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004688
4689 return MatchOperand_Success;
4690}
4691
Tim Northovereb5e4d52013-07-22 09:06:12 +00004692/// Convert parsed operands to MCInst. Needed here because this instruction
4693/// only has two register operands, but multiplication is commutative so
4694/// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
David Blaikie960ea3f2014-06-08 16:18:35 +00004695void ARMAsmParser::cvtThumbMultiply(MCInst &Inst,
4696 const OperandVector &Operands) {
4697 ((ARMOperand &)*Operands[3]).addRegOperands(Inst, 1);
4698 ((ARMOperand &)*Operands[1]).addCCOutOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004699 // If we have a three-operand form, make sure to set Rn to be the operand
4700 // that isn't the same as Rd.
4701 unsigned RegOp = 4;
4702 if (Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00004703 ((ARMOperand &)*Operands[4]).getReg() ==
4704 ((ARMOperand &)*Operands[3]).getReg())
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004705 RegOp = 5;
David Blaikie960ea3f2014-06-08 16:18:35 +00004706 ((ARMOperand &)*Operands[RegOp]).addRegOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004707 Inst.addOperand(Inst.getOperand(0));
David Blaikie960ea3f2014-06-08 16:18:35 +00004708 ((ARMOperand &)*Operands[2]).addCondCodeOperands(Inst, 2);
Jim Grosbach8e048492011-08-19 22:07:46 +00004709}
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004710
David Blaikie960ea3f2014-06-08 16:18:35 +00004711void ARMAsmParser::cvtThumbBranches(MCInst &Inst,
4712 const OperandVector &Operands) {
Mihai Popaad18d3c2013-08-09 10:38:32 +00004713 int CondOp = -1, ImmOp = -1;
4714 switch(Inst.getOpcode()) {
4715 case ARM::tB:
4716 case ARM::tBcc: CondOp = 1; ImmOp = 2; break;
4717
4718 case ARM::t2B:
4719 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break;
4720
4721 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
4722 }
4723 // first decide whether or not the branch should be conditional
4724 // by looking at it's location relative to an IT block
4725 if(inITBlock()) {
4726 // inside an IT block we cannot have any conditional branches. any
4727 // such instructions needs to be converted to unconditional form
4728 switch(Inst.getOpcode()) {
4729 case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
4730 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
4731 }
4732 } else {
4733 // outside IT blocks we can only have unconditional branches with AL
4734 // condition code or conditional branches with non-AL condition code
David Blaikie960ea3f2014-06-08 16:18:35 +00004735 unsigned Cond = static_cast<ARMOperand &>(*Operands[CondOp]).getCondCode();
Mihai Popaad18d3c2013-08-09 10:38:32 +00004736 switch(Inst.getOpcode()) {
4737 case ARM::tB:
4738 case ARM::tBcc:
4739 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
4740 break;
4741 case ARM::t2B:
4742 case ARM::t2Bcc:
4743 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
4744 break;
4745 }
4746 }
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +00004747
Mihai Popaad18d3c2013-08-09 10:38:32 +00004748 // now decide on encoding size based on branch target range
4749 switch(Inst.getOpcode()) {
4750 // classify tB as either t2B or t1B based on range of immediate operand
4751 case ARM::tB: {
David Blaikie960ea3f2014-06-08 16:18:35 +00004752 ARMOperand &op = static_cast<ARMOperand &>(*Operands[ImmOp]);
4753 if (!op.isSignedOffset<11, 1>() && isThumbTwo())
Mihai Popaad18d3c2013-08-09 10:38:32 +00004754 Inst.setOpcode(ARM::t2B);
4755 break;
4756 }
4757 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
4758 case ARM::tBcc: {
David Blaikie960ea3f2014-06-08 16:18:35 +00004759 ARMOperand &op = static_cast<ARMOperand &>(*Operands[ImmOp]);
4760 if (!op.isSignedOffset<8, 1>() && isThumbTwo())
Mihai Popaad18d3c2013-08-09 10:38:32 +00004761 Inst.setOpcode(ARM::t2Bcc);
4762 break;
4763 }
4764 }
David Blaikie960ea3f2014-06-08 16:18:35 +00004765 ((ARMOperand &)*Operands[ImmOp]).addImmOperands(Inst, 1);
4766 ((ARMOperand &)*Operands[CondOp]).addCondCodeOperands(Inst, 2);
Mihai Popaad18d3c2013-08-09 10:38:32 +00004767}
4768
Bill Wendlinge18980a2010-11-06 22:36:58 +00004769/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004770/// or an error. The first token must be a '[' when called.
David Blaikie960ea3f2014-06-08 16:18:35 +00004771bool ARMAsmParser::parseMemory(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004772 MCAsmParser &Parser = getParser();
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004773 SMLoc S, E;
Sean Callanan936b0d32010-01-19 21:44:56 +00004774 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00004775 "Token is not a Left Bracket");
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004776 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004777 Parser.Lex(); // Eat left bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004778
Sean Callanan936b0d32010-01-19 21:44:56 +00004779 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004780 int BaseRegNum = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004781 if (BaseRegNum == -1)
4782 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004783
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004784 // The next token must either be a comma, a colon or a closing bracket.
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004785 const AsmToken &Tok = Parser.getTok();
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004786 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4787 !Tok.is(AsmToken::RBrac))
Jim Grosbachd3595712011-08-03 23:50:40 +00004788 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004789
Jim Grosbachd3595712011-08-03 23:50:40 +00004790 if (Tok.is(AsmToken::RBrac)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004791 E = Tok.getEndLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004792 Parser.Lex(); // Eat right bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004793
Craig Topper062a2ba2014-04-25 05:30:21 +00004794 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, 0,
4795 ARM_AM::no_shift, 0, 0, false,
4796 S, E));
Jim Grosbach32ff5582010-11-29 23:18:01 +00004797
Jim Grosbach40700e02011-09-19 18:42:21 +00004798 // If there's a pre-indexing writeback marker, '!', just add it as a token
4799 // operand. It's rather odd, but syntactically valid.
4800 if (Parser.getTok().is(AsmToken::Exclaim)) {
4801 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4802 Parser.Lex(); // Eat the '!'.
4803 }
4804
Jim Grosbachd3595712011-08-03 23:50:40 +00004805 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004806 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004807
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004808 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4809 "Lost colon or comma in memory operand?!");
4810 if (Tok.is(AsmToken::Comma)) {
4811 Parser.Lex(); // Eat the comma.
4812 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004813
Jim Grosbacha95ec992011-10-11 17:29:55 +00004814 // If we have a ':', it's an alignment specifier.
4815 if (Parser.getTok().is(AsmToken::Colon)) {
4816 Parser.Lex(); // Eat the ':'.
4817 E = Parser.getTok().getLoc();
Kevin Enderby488f20b2014-04-10 20:18:58 +00004818 SMLoc AlignmentLoc = Tok.getLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004819
4820 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004821 if (getParser().parseExpression(Expr))
Jim Grosbacha95ec992011-10-11 17:29:55 +00004822 return true;
4823
4824 // The expression has to be a constant. Memory references with relocations
4825 // don't come through here, as they use the <label> forms of the relevant
4826 // instructions.
4827 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4828 if (!CE)
4829 return Error (E, "constant expression expected");
4830
4831 unsigned Align = 0;
4832 switch (CE->getValue()) {
4833 default:
Jim Grosbachcef98cd2011-12-19 18:31:43 +00004834 return Error(E,
4835 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4836 case 16: Align = 2; break;
4837 case 32: Align = 4; break;
Jim Grosbacha95ec992011-10-11 17:29:55 +00004838 case 64: Align = 8; break;
4839 case 128: Align = 16; break;
4840 case 256: Align = 32; break;
4841 }
4842
4843 // Now we should have the closing ']'
Jim Grosbacha95ec992011-10-11 17:29:55 +00004844 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004845 return Error(Parser.getTok().getLoc(), "']' expected");
4846 E = Parser.getTok().getEndLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004847 Parser.Lex(); // Eat right bracket token.
4848
4849 // Don't worry about range checking the value here. That's handled by
4850 // the is*() predicates.
Craig Topper062a2ba2014-04-25 05:30:21 +00004851 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004852 ARM_AM::no_shift, 0, Align,
Kevin Enderby488f20b2014-04-10 20:18:58 +00004853 false, S, E, AlignmentLoc));
Jim Grosbacha95ec992011-10-11 17:29:55 +00004854
4855 // If there's a pre-indexing writeback marker, '!', just add it as a token
4856 // operand.
4857 if (Parser.getTok().is(AsmToken::Exclaim)) {
4858 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4859 Parser.Lex(); // Eat the '!'.
4860 }
4861
4862 return false;
4863 }
4864
4865 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach8279c182011-11-15 22:14:41 +00004866 // offset. Be friendly and also accept a plain integer (without a leading
4867 // hash) for gas compatibility.
4868 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004869 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach8279c182011-11-15 22:14:41 +00004870 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004871 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004872 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbachd3595712011-08-03 23:50:40 +00004873 E = Parser.getTok().getLoc();
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004874
Owen Anderson967674d2011-08-29 19:36:44 +00004875 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbachd3595712011-08-03 23:50:40 +00004876 const MCExpr *Offset;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004877 if (getParser().parseExpression(Offset))
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004878 return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004879
4880 // The expression has to be a constant. Memory references with relocations
4881 // don't come through here, as they use the <label> forms of the relevant
4882 // instructions.
4883 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4884 if (!CE)
4885 return Error (E, "constant expression expected");
4886
Owen Anderson967674d2011-08-29 19:36:44 +00004887 // If the constant was #-0, represent it as INT32_MIN.
4888 int32_t Val = CE->getValue();
4889 if (isNegative && Val == 0)
4890 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4891
Jim Grosbachd3595712011-08-03 23:50:40 +00004892 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004893 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004894 return Error(Parser.getTok().getLoc(), "']' expected");
4895 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004896 Parser.Lex(); // Eat right bracket token.
4897
4898 // Don't worry about range checking the value here. That's handled by
4899 // the is*() predicates.
4900 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004901 ARM_AM::no_shift, 0, 0,
4902 false, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004903
4904 // If there's a pre-indexing writeback marker, '!', just add it as a token
4905 // operand.
4906 if (Parser.getTok().is(AsmToken::Exclaim)) {
4907 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4908 Parser.Lex(); // Eat the '!'.
4909 }
4910
4911 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004912 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004913
4914 // The register offset is optionally preceded by a '+' or '-'
4915 bool isNegative = false;
4916 if (Parser.getTok().is(AsmToken::Minus)) {
4917 isNegative = true;
4918 Parser.Lex(); // Eat the '-'.
4919 } else if (Parser.getTok().is(AsmToken::Plus)) {
4920 // Nothing to do.
4921 Parser.Lex(); // Eat the '+'.
4922 }
4923
4924 E = Parser.getTok().getLoc();
4925 int OffsetRegNum = tryParseRegister();
4926 if (OffsetRegNum == -1)
4927 return Error(E, "register expected");
4928
4929 // If there's a shift operator, handle it.
4930 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004931 unsigned ShiftImm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004932 if (Parser.getTok().is(AsmToken::Comma)) {
4933 Parser.Lex(); // Eat the ','.
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004934 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbachd3595712011-08-03 23:50:40 +00004935 return true;
4936 }
4937
4938 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004939 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004940 return Error(Parser.getTok().getLoc(), "']' expected");
4941 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004942 Parser.Lex(); // Eat right bracket token.
4943
Craig Topper062a2ba2014-04-25 05:30:21 +00004944 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, OffsetRegNum,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004945 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbachd3595712011-08-03 23:50:40 +00004946 S, E));
4947
Jim Grosbachc320c852011-08-05 21:28:30 +00004948 // If there's a pre-indexing writeback marker, '!', just add it as a token
4949 // operand.
4950 if (Parser.getTok().is(AsmToken::Exclaim)) {
4951 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4952 Parser.Lex(); // Eat the '!'.
4953 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004954
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004955 return false;
4956}
4957
Jim Grosbachd3595712011-08-03 23:50:40 +00004958/// parseMemRegOffsetShift - one of these two:
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004959/// ( lsl | lsr | asr | ror ) , # shift_amount
4960/// rrx
Jim Grosbachd3595712011-08-03 23:50:40 +00004961/// return true if it parses a shift otherwise it returns false.
4962bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4963 unsigned &Amount) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004964 MCAsmParser &Parser = getParser();
Jim Grosbachd3595712011-08-03 23:50:40 +00004965 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan936b0d32010-01-19 21:44:56 +00004966 const AsmToken &Tok = Parser.getTok();
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004967 if (Tok.isNot(AsmToken::Identifier))
4968 return true;
Benjamin Kramer92d89982010-07-14 22:38:02 +00004969 StringRef ShiftName = Tok.getString();
Jim Grosbach3b559ff2011-12-07 23:40:58 +00004970 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4971 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004972 St = ARM_AM::lsl;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004973 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004974 St = ARM_AM::lsr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004975 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004976 St = ARM_AM::asr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004977 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004978 St = ARM_AM::ror;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004979 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004980 St = ARM_AM::rrx;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004981 else
Jim Grosbachd3595712011-08-03 23:50:40 +00004982 return Error(Loc, "illegal shift operator");
Sean Callanana83fd7d2010-01-19 20:27:46 +00004983 Parser.Lex(); // Eat shift type token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004984
Jim Grosbachd3595712011-08-03 23:50:40 +00004985 // rrx stands alone.
4986 Amount = 0;
4987 if (St != ARM_AM::rrx) {
4988 Loc = Parser.getTok().getLoc();
4989 // A '#' and a shift amount.
4990 const AsmToken &HashTok = Parser.getTok();
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004991 if (HashTok.isNot(AsmToken::Hash) &&
4992 HashTok.isNot(AsmToken::Dollar))
Jim Grosbachd3595712011-08-03 23:50:40 +00004993 return Error(HashTok.getLoc(), "'#' expected");
4994 Parser.Lex(); // Eat hash token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004995
Jim Grosbachd3595712011-08-03 23:50:40 +00004996 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004997 if (getParser().parseExpression(Expr))
Jim Grosbachd3595712011-08-03 23:50:40 +00004998 return true;
4999 // Range check the immediate.
5000 // lsl, ror: 0 <= imm <= 31
5001 // lsr, asr: 0 <= imm <= 32
5002 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
5003 if (!CE)
5004 return Error(Loc, "shift amount must be an immediate");
5005 int64_t Imm = CE->getValue();
5006 if (Imm < 0 ||
5007 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
5008 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
5009 return Error(Loc, "immediate shift value out of range");
Tim Northover0c97e762012-09-22 11:18:12 +00005010 // If <ShiftTy> #0, turn it into a no_shift.
5011 if (Imm == 0)
5012 St = ARM_AM::lsl;
5013 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
5014 if (Imm == 32)
5015 Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00005016 Amount = Imm;
5017 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005018
5019 return false;
5020}
5021
Jim Grosbache7fbce72011-10-03 23:38:36 +00005022/// parseFPImm - A floating point immediate expression operand.
David Blaikie960ea3f2014-06-08 16:18:35 +00005023ARMAsmParser::OperandMatchResultTy
5024ARMAsmParser::parseFPImm(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00005025 MCAsmParser &Parser = getParser();
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005026 // Anything that can accept a floating point constant as an operand
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005027 // needs to go through here, as the regular parseExpression is
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005028 // integer only.
5029 //
5030 // This routine still creates a generic Immediate operand, containing
5031 // a bitcast of the 64-bit floating point value. The various operands
5032 // that accept floats can check whether the value is valid for them
5033 // via the standard is*() predicates.
5034
Jim Grosbache7fbce72011-10-03 23:38:36 +00005035 SMLoc S = Parser.getTok().getLoc();
5036
Jim Grosbachef70e9b2011-12-09 22:25:03 +00005037 if (Parser.getTok().isNot(AsmToken::Hash) &&
5038 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbache7fbce72011-10-03 23:38:36 +00005039 return MatchOperand_NoMatch;
Jim Grosbach741cd732011-10-17 22:26:03 +00005040
5041 // Disambiguate the VMOV forms that can accept an FP immediate.
5042 // vmov.f32 <sreg>, #imm
5043 // vmov.f64 <dreg>, #imm
5044 // vmov.f32 <dreg>, #imm @ vector f32x2
5045 // vmov.f32 <qreg>, #imm @ vector f32x4
5046 //
5047 // There are also the NEON VMOV instructions which expect an
5048 // integer constant. Make sure we don't try to parse an FPImm
5049 // for these:
5050 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
David Blaikie960ea3f2014-06-08 16:18:35 +00005051 ARMOperand &TyOp = static_cast<ARMOperand &>(*Operands[2]);
5052 bool isVmovf = TyOp.isToken() &&
5053 (TyOp.getToken() == ".f32" || TyOp.getToken() == ".f64");
5054 ARMOperand &Mnemonic = static_cast<ARMOperand &>(*Operands[0]);
5055 bool isFconst = Mnemonic.isToken() && (Mnemonic.getToken() == "fconstd" ||
5056 Mnemonic.getToken() == "fconsts");
David Peixottoa872e0e2014-01-07 18:19:23 +00005057 if (!(isVmovf || isFconst))
Jim Grosbach741cd732011-10-17 22:26:03 +00005058 return MatchOperand_NoMatch;
5059
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00005060 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbache7fbce72011-10-03 23:38:36 +00005061
5062 // Handle negation, as that still comes through as a separate token.
5063 bool isNegative = false;
5064 if (Parser.getTok().is(AsmToken::Minus)) {
5065 isNegative = true;
5066 Parser.Lex();
5067 }
5068 const AsmToken &Tok = Parser.getTok();
Jim Grosbach235c8d22012-01-19 02:47:30 +00005069 SMLoc Loc = Tok.getLoc();
David Peixottoa872e0e2014-01-07 18:19:23 +00005070 if (Tok.is(AsmToken::Real) && isVmovf) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005071 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbache7fbce72011-10-03 23:38:36 +00005072 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
5073 // If we had a '-' in front, toggle the sign bit.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005074 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbache7fbce72011-10-03 23:38:36 +00005075 Parser.Lex(); // Eat the token.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005076 Operands.push_back(ARMOperand::CreateImm(
5077 MCConstantExpr::Create(IntVal, getContext()),
5078 S, Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00005079 return MatchOperand_Success;
5080 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005081 // Also handle plain integers. Instructions which allow floating point
5082 // immediates also allow a raw encoded 8-bit value.
David Peixottoa872e0e2014-01-07 18:19:23 +00005083 if (Tok.is(AsmToken::Integer) && isFconst) {
Jim Grosbache7fbce72011-10-03 23:38:36 +00005084 int64_t Val = Tok.getIntVal();
5085 Parser.Lex(); // Eat the token.
5086 if (Val > 255 || Val < 0) {
Jim Grosbach235c8d22012-01-19 02:47:30 +00005087 Error(Loc, "encoded floating point value out of range");
Jim Grosbache7fbce72011-10-03 23:38:36 +00005088 return MatchOperand_ParseFail;
5089 }
David Peixottoa872e0e2014-01-07 18:19:23 +00005090 float RealVal = ARM_AM::getFPImmFloat(Val);
5091 Val = APFloat(RealVal).bitcastToAPInt().getZExtValue();
5092
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005093 Operands.push_back(ARMOperand::CreateImm(
5094 MCConstantExpr::Create(Val, getContext()), S,
5095 Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00005096 return MatchOperand_Success;
5097 }
5098
Jim Grosbach235c8d22012-01-19 02:47:30 +00005099 Error(Loc, "invalid floating point immediate");
Jim Grosbache7fbce72011-10-03 23:38:36 +00005100 return MatchOperand_ParseFail;
5101}
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005102
Kevin Enderby8be42bd2009-10-30 22:55:57 +00005103/// Parse a arm instruction operand. For now this parses the operand regardless
5104/// of the mnemonic.
David Blaikie960ea3f2014-06-08 16:18:35 +00005105bool ARMAsmParser::parseOperand(OperandVector &Operands, StringRef Mnemonic) {
Rafael Espindola961d4692014-11-11 05:18:41 +00005106 MCAsmParser &Parser = getParser();
Sean Callanan7ad0ad02010-04-02 22:27:05 +00005107 SMLoc S, E;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00005108
5109 // Check if the current operand has a custom associated parser, if so, try to
5110 // custom parse the operand, or fallback to the general approach.
Jim Grosbach861e49c2011-02-12 01:34:40 +00005111 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
5112 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00005113 return false;
Jim Grosbach861e49c2011-02-12 01:34:40 +00005114 // If there wasn't a custom match, try the generic matcher below. Otherwise,
5115 // there was a match, but an error occurred, in which case, just return that
5116 // the operand parsing failed.
5117 if (ResTy == MatchOperand_ParseFail)
5118 return true;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00005119
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005120 switch (getLexer().getKind()) {
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005121 default:
5122 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling2063b842010-11-18 23:43:05 +00005123 return true;
Jim Grosbachbb24c592011-07-13 18:49:30 +00005124 case AsmToken::Identifier: {
Chad Rosierb162a5c2013-03-19 23:44:03 +00005125 // If we've seen a branch mnemonic, the next operand must be a label. This
5126 // is true even if the label is a register name. So "br r1" means branch to
5127 // label "r1".
5128 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
5129 if (!ExpectLabel) {
5130 if (!tryParseRegisterWithWriteBack(Operands))
5131 return false;
5132 int Res = tryParseShiftRegister(Operands);
5133 if (Res == 0) // success
5134 return false;
5135 else if (Res == -1) // irrecoverable error
5136 return true;
5137 // If this is VMRS, check for the apsr_nzcv operand.
5138 if (Mnemonic == "vmrs" &&
5139 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
5140 S = Parser.getTok().getLoc();
5141 Parser.Lex();
5142 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
5143 return false;
5144 }
Jim Grosbach4ab23b52011-10-03 21:12:43 +00005145 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00005146
5147 // Fall though for the Identifier case that is not a register or a
5148 // special name.
Jim Grosbachbb24c592011-07-13 18:49:30 +00005149 }
Jim Grosbach4e380352011-10-26 21:14:08 +00005150 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderbyb084be92011-01-13 20:32:36 +00005151 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach5c6b6342011-11-01 22:38:31 +00005152 case AsmToken::String: // quoted label names.
Kevin Enderbyb084be92011-01-13 20:32:36 +00005153 case AsmToken::Dot: { // . as a branch target
Kevin Enderby146dcf22009-10-15 20:48:48 +00005154 // This was not a register so parse other operands that start with an
5155 // identifier (like labels) as expressions and create them as immediates.
5156 const MCExpr *IdVal;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00005157 S = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005158 if (getParser().parseExpression(IdVal))
Bill Wendling2063b842010-11-18 23:43:05 +00005159 return true;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00005160 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling2063b842010-11-18 23:43:05 +00005161 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
5162 return false;
5163 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005164 case AsmToken::LBrac:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005165 return parseMemory(Operands);
Kevin Enderbya2b99102009-10-09 21:12:28 +00005166 case AsmToken::LCurly:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005167 return parseRegisterList(Operands);
Jim Grosbachef70e9b2011-12-09 22:25:03 +00005168 case AsmToken::Dollar:
Owen Andersonf02d98d2011-08-29 17:17:09 +00005169 case AsmToken::Hash: {
Kevin Enderby3a80dac2009-10-13 23:33:38 +00005170 // #42 -> immediate.
Sean Callanan7ad0ad02010-04-02 22:27:05 +00005171 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00005172 Parser.Lex();
Jim Grosbach003607f2012-04-16 21:18:46 +00005173
5174 if (Parser.getTok().isNot(AsmToken::Colon)) {
5175 bool isNegative = Parser.getTok().is(AsmToken::Minus);
5176 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005177 if (getParser().parseExpression(ImmVal))
Jim Grosbach003607f2012-04-16 21:18:46 +00005178 return true;
5179 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
5180 if (CE) {
5181 int32_t Val = CE->getValue();
5182 if (isNegative && Val == 0)
5183 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
5184 }
5185 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
5186 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
Jim Grosbach9be2d712013-02-23 00:52:09 +00005187
5188 // There can be a trailing '!' on operands that we want as a separate
Saleem Abdulrasool83e37702013-12-28 03:07:12 +00005189 // '!' Token operand. Handle that here. For example, the compatibility
Jim Grosbach9be2d712013-02-23 00:52:09 +00005190 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
5191 if (Parser.getTok().is(AsmToken::Exclaim)) {
5192 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
5193 Parser.getTok().getLoc()));
5194 Parser.Lex(); // Eat exclaim token
5195 }
Jim Grosbach003607f2012-04-16 21:18:46 +00005196 return false;
Owen Andersonf02d98d2011-08-29 17:17:09 +00005197 }
Jim Grosbach003607f2012-04-16 21:18:46 +00005198 // w/ a ':' after the '#', it's just like a plain ':'.
5199 // FALLTHROUGH
Owen Andersonf02d98d2011-08-29 17:17:09 +00005200 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00005201 case AsmToken::Colon: {
5202 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng965b3c72011-01-13 07:58:56 +00005203 // FIXME: Check it's an expression prefix,
5204 // e.g. (FOO - :lower16:BAR) isn't legal.
5205 ARMMCExpr::VariantKind RefKind;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005206 if (parsePrefix(RefKind))
Jason W Kim1f7bc072011-01-11 23:53:41 +00005207 return true;
5208
Evan Cheng965b3c72011-01-13 07:58:56 +00005209 const MCExpr *SubExprVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005210 if (getParser().parseExpression(SubExprVal))
Jason W Kim1f7bc072011-01-11 23:53:41 +00005211 return true;
5212
Evan Cheng965b3c72011-01-13 07:58:56 +00005213 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach9659ed92012-09-21 00:26:53 +00005214 getContext());
Jason W Kim1f7bc072011-01-11 23:53:41 +00005215 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng965b3c72011-01-13 07:58:56 +00005216 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim1f7bc072011-01-11 23:53:41 +00005217 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005218 }
David Peixottoe407d092013-12-19 18:12:36 +00005219 case AsmToken::Equal: {
5220 if (Mnemonic != "ldr") // only parse for ldr pseudo (e.g. ldr r0, =val)
5221 return Error(Parser.getTok().getLoc(), "unexpected token in operand");
5222
David Peixottoe407d092013-12-19 18:12:36 +00005223 Parser.Lex(); // Eat '='
5224 const MCExpr *SubExprVal;
5225 if (getParser().parseExpression(SubExprVal))
5226 return true;
5227 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
5228
David Peixottob9b73622014-02-04 17:22:40 +00005229 const MCExpr *CPLoc = getTargetStreamer().addConstantPoolEntry(SubExprVal);
David Peixottoe407d092013-12-19 18:12:36 +00005230 Operands.push_back(ARMOperand::CreateImm(CPLoc, S, E));
5231 return false;
5232 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00005233 }
5234}
5235
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005236// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng965b3c72011-01-13 07:58:56 +00005237// :lower16: and :upper16:.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005238bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Rafael Espindola961d4692014-11-11 05:18:41 +00005239 MCAsmParser &Parser = getParser();
Evan Cheng965b3c72011-01-13 07:58:56 +00005240 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim1f7bc072011-01-11 23:53:41 +00005241
Saleem Abdulrasool435f4562014-01-10 04:38:40 +00005242 // consume an optional '#' (GNU compatibility)
5243 if (getLexer().is(AsmToken::Hash))
5244 Parser.Lex();
5245
Jason W Kim1f7bc072011-01-11 23:53:41 +00005246 // :lower16: and :upper16: modifiers
Jason W Kim93229972011-01-13 00:27:00 +00005247 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim1f7bc072011-01-11 23:53:41 +00005248 Parser.Lex(); // Eat ':'
5249
5250 if (getLexer().isNot(AsmToken::Identifier)) {
5251 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
5252 return true;
5253 }
5254
Saleem Abdulrasoolfaa4f072015-01-13 03:22:49 +00005255 enum {
5256 COFF = (1 << MCObjectFileInfo::IsCOFF),
5257 ELF = (1 << MCObjectFileInfo::IsELF),
5258 MACHO = (1 << MCObjectFileInfo::IsMachO)
5259 };
5260 static const struct PrefixEntry {
5261 const char *Spelling;
5262 ARMMCExpr::VariantKind VariantKind;
5263 uint8_t SupportedFormats;
5264 } PrefixEntries[] = {
5265 { "lower16", ARMMCExpr::VK_ARM_LO16, COFF | ELF | MACHO },
5266 { "upper16", ARMMCExpr::VK_ARM_HI16, COFF | ELF | MACHO },
5267 };
5268
Jason W Kim1f7bc072011-01-11 23:53:41 +00005269 StringRef IDVal = Parser.getTok().getIdentifier();
Saleem Abdulrasoolfaa4f072015-01-13 03:22:49 +00005270
5271 const auto &Prefix =
5272 std::find_if(std::begin(PrefixEntries), std::end(PrefixEntries),
5273 [&IDVal](const PrefixEntry &PE) {
5274 return PE.Spelling == IDVal;
5275 });
5276 if (Prefix == std::end(PrefixEntries)) {
Jason W Kim1f7bc072011-01-11 23:53:41 +00005277 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
5278 return true;
5279 }
Saleem Abdulrasoolfaa4f072015-01-13 03:22:49 +00005280
5281 uint8_t CurrentFormat;
5282 switch (getContext().getObjectFileInfo()->getObjectFileType()) {
5283 case MCObjectFileInfo::IsMachO:
5284 CurrentFormat = MACHO;
5285 break;
5286 case MCObjectFileInfo::IsELF:
5287 CurrentFormat = ELF;
5288 break;
5289 case MCObjectFileInfo::IsCOFF:
5290 CurrentFormat = COFF;
5291 break;
5292 }
5293
5294 if (~Prefix->SupportedFormats & CurrentFormat) {
5295 Error(Parser.getTok().getLoc(),
5296 "cannot represent relocation in the current file format");
5297 return true;
5298 }
5299
5300 RefKind = Prefix->VariantKind;
Jason W Kim1f7bc072011-01-11 23:53:41 +00005301 Parser.Lex();
5302
5303 if (getLexer().isNot(AsmToken::Colon)) {
5304 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
5305 return true;
5306 }
5307 Parser.Lex(); // Eat the last ':'
Saleem Abdulrasoolfaa4f072015-01-13 03:22:49 +00005308
Jason W Kim1f7bc072011-01-11 23:53:41 +00005309 return false;
5310}
5311
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005312/// \brief Given a mnemonic, split out possible predication code and carry
5313/// setting letters to form a canonical mnemonic and flags.
5314//
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005315// FIXME: Would be nice to autogen this.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005316// FIXME: This is a bit of a maze of special cases.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005317StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00005318 unsigned &PredicationCode,
5319 bool &CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005320 unsigned &ProcessorIMod,
5321 StringRef &ITMask) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005322 PredicationCode = ARMCC::AL;
5323 CarrySetting = false;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005324 ProcessorIMod = 0;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005325
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005326 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005327 //
5328 // FIXME: Would be nice to autogen this.
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00005329 if ((Mnemonic == "movs" && isThumb()) ||
5330 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
5331 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
5332 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
5333 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
Richard Barton8d519fe2013-09-05 14:14:19 +00005334 Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00005335 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
5336 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbache16acac2011-12-19 19:43:50 +00005337 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
Joey Gouly2efaa732013-07-06 20:50:18 +00005338 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00005339 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
5340 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
Charlie Turner4d88ae22014-12-01 08:33:28 +00005341 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic == "hvc" ||
5342 Mnemonic.startswith("vsel"))
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005343 return Mnemonic;
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005344
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00005345 // First, split out any predication code. Ignore mnemonics we know aren't
5346 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbach8d114902011-07-20 18:20:31 +00005347 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach0c398b92011-07-27 21:58:11 +00005348 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach3636be32011-08-22 23:55:58 +00005349 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbachf6d5d602011-09-01 18:22:13 +00005350 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00005351 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
5352 .Case("eq", ARMCC::EQ)
5353 .Case("ne", ARMCC::NE)
5354 .Case("hs", ARMCC::HS)
5355 .Case("cs", ARMCC::HS)
5356 .Case("lo", ARMCC::LO)
5357 .Case("cc", ARMCC::LO)
5358 .Case("mi", ARMCC::MI)
5359 .Case("pl", ARMCC::PL)
5360 .Case("vs", ARMCC::VS)
5361 .Case("vc", ARMCC::VC)
5362 .Case("hi", ARMCC::HI)
5363 .Case("ls", ARMCC::LS)
5364 .Case("ge", ARMCC::GE)
5365 .Case("lt", ARMCC::LT)
5366 .Case("gt", ARMCC::GT)
5367 .Case("le", ARMCC::LE)
5368 .Case("al", ARMCC::AL)
5369 .Default(~0U);
5370 if (CC != ~0U) {
5371 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
5372 PredicationCode = CC;
5373 }
Bill Wendling193961b2010-10-29 23:50:21 +00005374 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005375
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005376 // Next, determine if we have a carry setting bit. We explicitly ignore all
5377 // the instructions we know end in 's'.
5378 if (Mnemonic.endswith("s") &&
Jim Grosbachd3e8e292011-08-17 22:49:09 +00005379 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00005380 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
5381 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
5382 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach086d0132011-12-08 00:49:29 +00005383 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach54337b82011-12-10 00:01:02 +00005384 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach92a939a2011-12-19 19:02:41 +00005385 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbachd74560b2012-03-15 20:48:18 +00005386 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
David Peixottoa872e0e2014-01-07 18:19:23 +00005387 Mnemonic == "vfms" || Mnemonic == "vfnms" || Mnemonic == "fconsts" ||
Jim Grosbach51726e22011-07-29 20:26:09 +00005388 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005389 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
5390 CarrySetting = true;
5391 }
5392
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005393 // The "cps" instruction can have a interrupt mode operand which is glued into
5394 // the mnemonic. Check if this is the case, split it and parse the imod op
5395 if (Mnemonic.startswith("cps")) {
5396 // Split out any imod code.
5397 unsigned IMod =
5398 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
5399 .Case("ie", ARM_PROC::IE)
5400 .Case("id", ARM_PROC::ID)
5401 .Default(~0U);
5402 if (IMod != ~0U) {
5403 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
5404 ProcessorIMod = IMod;
5405 }
5406 }
5407
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005408 // The "it" instruction has the condition mask on the end of the mnemonic.
5409 if (Mnemonic.startswith("it")) {
5410 ITMask = Mnemonic.slice(2, Mnemonic.size());
5411 Mnemonic = Mnemonic.slice(0, 2);
5412 }
5413
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005414 return Mnemonic;
5415}
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005416
5417/// \brief Given a canonical mnemonic, determine if the instruction ever allows
5418/// inclusion of carry set or predication code operands.
5419//
5420// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00005421void ARMAsmParser::
Amara Emerson33089092013-09-19 11:59:01 +00005422getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
5423 bool &CanAcceptCarrySet, bool &CanAcceptPredicationCode) {
Daniel Dunbar09264122011-01-11 19:06:29 +00005424 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
5425 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00005426 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00005427 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00005428 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00005429 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00005430 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Chengaca6c822012-04-11 00:13:00 +00005431 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00005432 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00005433 Mnemonic == "mla" || Mnemonic == "smlal" ||
5434 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbar09264122011-01-11 19:06:29 +00005435 CanAcceptCarrySet = true;
Jim Grosbach6c45b752011-09-16 16:39:25 +00005436 } else
Daniel Dunbar09264122011-01-11 19:06:29 +00005437 CanAcceptCarrySet = false;
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005438
Tim Northover2c45a382013-06-26 16:52:40 +00005439 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
5440 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
Saleem Abdulrasool27351f22014-05-14 03:47:39 +00005441 Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic == "udf" ||
5442 Mnemonic.startswith("crc32") || Mnemonic.startswith("cps") ||
5443 Mnemonic.startswith("vsel") ||
Joey Gouly2d0175e2013-07-09 09:59:04 +00005444 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00005445 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
5446 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
Charlie Turner4d88ae22014-12-01 08:33:28 +00005447 Mnemonic == "vrintm" || Mnemonic.startswith("aes") || Mnemonic == "hvc" ||
Amara Emerson33089092013-09-19 11:59:01 +00005448 Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") ||
5449 (FullInst.startswith("vmull") && FullInst.endswith(".p64"))) {
Tim Northover2c45a382013-06-26 16:52:40 +00005450 // These mnemonics are never predicable
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005451 CanAcceptPredicationCode = false;
Tim Northover2c45a382013-06-26 16:52:40 +00005452 } else if (!isThumb()) {
5453 // Some instructions are only predicable in Thumb mode
5454 CanAcceptPredicationCode
5455 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
5456 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
5457 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
5458 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
5459 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
5460 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
5461 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
5462 } else if (isThumbOne()) {
Tim Northoverf86d1f02013-10-07 11:10:47 +00005463 if (hasV6MOps())
5464 CanAcceptPredicationCode = Mnemonic != "movs";
5465 else
5466 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
Jim Grosbach6c45b752011-09-16 16:39:25 +00005467 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005468 CanAcceptPredicationCode = true;
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005469}
5470
Jim Grosbach7283da92011-08-16 21:12:37 +00005471bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
David Blaikie960ea3f2014-06-08 16:18:35 +00005472 OperandVector &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005473 // FIXME: This is all horribly hacky. We really need a better way to deal
5474 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00005475
5476 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
5477 // another does not. Specifically, the MOVW instruction does not. So we
5478 // special case it here and remove the defaulted (non-setting) cc_out
5479 // operand if that's the instruction we're trying to match.
5480 //
5481 // We do this as post-processing of the explicit operands rather than just
5482 // conditionally adding the cc_out in the first place because we need
5483 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00005484 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Asiri Rathnayake52376ac2015-01-06 15:55:09 +00005485 !static_cast<ARMOperand &>(*Operands[4]).isModImm() &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005486 static_cast<ARMOperand &>(*Operands[4]).isImm0_65535Expr() &&
5487 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0)
Jim Grosbach7283da92011-08-16 21:12:37 +00005488 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005489
5490 // Register-register 'add' for thumb does not have a cc_out operand
5491 // when there are only two register operands.
5492 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005493 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5494 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5495 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0)
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005496 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005497 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005498 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
5499 // have to check the immediate range here since Thumb2 has a variant
5500 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005501 if (((isThumb() && Mnemonic == "add") ||
5502 (isThumbTwo() && Mnemonic == "sub")) &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005503 Operands.size() == 6 && static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5504 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5505 static_cast<ARMOperand &>(*Operands[4]).getReg() == ARM::SP &&
5506 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5507 ((Mnemonic == "add" && static_cast<ARMOperand &>(*Operands[5]).isReg()) ||
5508 static_cast<ARMOperand &>(*Operands[5]).isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005509 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005510 // For Thumb2, add/sub immediate does not have a cc_out operand for the
5511 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005512 // selecting via the generic "add" mnemonic, so to know that we
5513 // should remove the cc_out operand, we have to explicitly check that
5514 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005515 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005516 Operands.size() == 6 && static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5517 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5518 static_cast<ARMOperand &>(*Operands[5]).isImm()) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005519 // Nest conditions rather than one big 'if' statement for readability.
5520 //
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005521 // If both registers are low, we're in an IT block, and the immediate is
5522 // in range, we should use encoding T1 instead, which has a cc_out.
5523 if (inITBlock() &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005524 isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) &&
5525 isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) &&
5526 static_cast<ARMOperand &>(*Operands[5]).isImm0_7())
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005527 return false;
Tilmann Schelleref5666f2013-07-03 20:38:01 +00005528 // Check against T3. If the second register is the PC, this is an
5529 // alternate form of ADR, which uses encoding T4, so check for that too.
David Blaikie960ea3f2014-06-08 16:18:35 +00005530 if (static_cast<ARMOperand &>(*Operands[4]).getReg() != ARM::PC &&
5531 static_cast<ARMOperand &>(*Operands[5]).isT2SOImm())
Tilmann Schelleref5666f2013-07-03 20:38:01 +00005532 return false;
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005533
5534 // Otherwise, we use encoding T4, which does not have a cc_out
5535 // operand.
5536 return true;
5537 }
5538
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005539 // The thumb2 multiply instruction doesn't have a CCOut register, so
5540 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
5541 // use the 16-bit encoding or not.
5542 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005543 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5544 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5545 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5546 static_cast<ARMOperand &>(*Operands[5]).isReg() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005547 // If the registers aren't low regs, the destination reg isn't the
5548 // same as one of the source regs, or the cc_out operand is zero
5549 // outside of an IT block, we have to use the 32-bit encoding, so
5550 // remove the cc_out operand.
David Blaikie960ea3f2014-06-08 16:18:35 +00005551 (!isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) ||
5552 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) ||
5553 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[5]).getReg()) ||
5554 !inITBlock() || (static_cast<ARMOperand &>(*Operands[3]).getReg() !=
5555 static_cast<ARMOperand &>(*Operands[5]).getReg() &&
5556 static_cast<ARMOperand &>(*Operands[3]).getReg() !=
5557 static_cast<ARMOperand &>(*Operands[4]).getReg())))
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005558 return true;
5559
Jim Grosbachefa7e952011-11-15 19:55:16 +00005560 // Also check the 'mul' syntax variant that doesn't specify an explicit
5561 // destination register.
5562 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005563 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5564 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5565 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
Jim Grosbachefa7e952011-11-15 19:55:16 +00005566 // If the registers aren't low regs or the cc_out operand is zero
5567 // outside of an IT block, we have to use the 32-bit encoding, so
5568 // remove the cc_out operand.
David Blaikie960ea3f2014-06-08 16:18:35 +00005569 (!isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) ||
5570 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) ||
Jim Grosbachefa7e952011-11-15 19:55:16 +00005571 !inITBlock()))
5572 return true;
5573
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005574
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005575
Jim Grosbach4b701af2011-08-24 21:42:27 +00005576 // Register-register 'add/sub' for thumb does not have a cc_out operand
5577 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
5578 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
5579 // right, this will result in better diagnostics (which operand is off)
5580 // anyway.
5581 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
5582 (Operands.size() == 5 || Operands.size() == 6) &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005583 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5584 static_cast<ARMOperand &>(*Operands[3]).getReg() == ARM::SP &&
5585 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5586 (static_cast<ARMOperand &>(*Operands[4]).isImm() ||
Jim Grosbachdf5a2442012-04-10 17:31:55 +00005587 (Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005588 static_cast<ARMOperand &>(*Operands[5]).isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005589 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005590
Jim Grosbach7283da92011-08-16 21:12:37 +00005591 return false;
5592}
5593
David Blaikie960ea3f2014-06-08 16:18:35 +00005594bool ARMAsmParser::shouldOmitPredicateOperand(StringRef Mnemonic,
5595 OperandVector &Operands) {
Joey Goulye8602552013-07-19 16:34:16 +00005596 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
5597 unsigned RegIdx = 3;
5598 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005599 static_cast<ARMOperand &>(*Operands[2]).getToken() == ".f32") {
5600 if (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
5601 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".f32")
Joey Goulye8602552013-07-19 16:34:16 +00005602 RegIdx = 4;
5603
David Blaikie960ea3f2014-06-08 16:18:35 +00005604 if (static_cast<ARMOperand &>(*Operands[RegIdx]).isReg() &&
5605 (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(
5606 static_cast<ARMOperand &>(*Operands[RegIdx]).getReg()) ||
5607 ARMMCRegisterClasses[ARM::QPRRegClassID].contains(
5608 static_cast<ARMOperand &>(*Operands[RegIdx]).getReg())))
Joey Goulye8602552013-07-19 16:34:16 +00005609 return true;
5610 }
Joey Goulyf520d5e2013-07-19 16:45:16 +00005611 return false;
Joey Goulye8602552013-07-19 16:34:16 +00005612}
5613
Jim Grosbach12952fe2011-11-11 23:08:10 +00005614static bool isDataTypeToken(StringRef Tok) {
5615 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
5616 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
5617 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
5618 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
5619 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
5620 Tok == ".f" || Tok == ".d";
5621}
5622
5623// FIXME: This bit should probably be handled via an explicit match class
5624// in the .td files that matches the suffix instead of having it be
5625// a literal string token the way it is now.
5626static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
5627 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
5628}
Tim Northover26bb14e2014-08-18 11:49:42 +00005629static void applyMnemonicAliases(StringRef &Mnemonic, uint64_t Features,
Chad Rosier9f7a2212013-04-18 22:35:36 +00005630 unsigned VariantID);
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005631
5632static bool RequiresVFPRegListValidation(StringRef Inst,
5633 bool &AcceptSinglePrecisionOnly,
5634 bool &AcceptDoublePrecisionOnly) {
5635 if (Inst.size() < 7)
5636 return false;
5637
5638 if (Inst.startswith("fldm") || Inst.startswith("fstm")) {
5639 StringRef AddressingMode = Inst.substr(4, 2);
5640 if (AddressingMode == "ia" || AddressingMode == "db" ||
5641 AddressingMode == "ea" || AddressingMode == "fd") {
5642 AcceptSinglePrecisionOnly = Inst[6] == 's';
5643 AcceptDoublePrecisionOnly = Inst[6] == 'd' || Inst[6] == 'x';
5644 return true;
5645 }
5646 }
5647
5648 return false;
5649}
5650
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005651/// Parse an arm instruction mnemonic followed by its operands.
Chad Rosierf0e87202012-10-25 20:41:34 +00005652bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
David Blaikie960ea3f2014-06-08 16:18:35 +00005653 SMLoc NameLoc, OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00005654 MCAsmParser &Parser = getParser();
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005655 // FIXME: Can this be done via tablegen in some fashion?
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005656 bool RequireVFPRegisterListCheck;
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005657 bool AcceptSinglePrecisionOnly;
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005658 bool AcceptDoublePrecisionOnly;
5659 RequireVFPRegisterListCheck =
5660 RequiresVFPRegListValidation(Name, AcceptSinglePrecisionOnly,
5661 AcceptDoublePrecisionOnly);
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005662
Jim Grosbach8be2f652011-12-09 23:34:09 +00005663 // Apply mnemonic aliases before doing anything else, as the destination
Saleem Abdulrasoola1937cb2013-12-29 17:58:31 +00005664 // mnemonic may include suffices and we want to handle them normally.
Jim Grosbach8be2f652011-12-09 23:34:09 +00005665 // The generic tblgen'erated code does this later, at the start of
5666 // MatchInstructionImpl(), but that's too late for aliases that include
5667 // any sort of suffix.
Tim Northover26bb14e2014-08-18 11:49:42 +00005668 uint64_t AvailableFeatures = getAvailableFeatures();
Chad Rosier9f7a2212013-04-18 22:35:36 +00005669 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5670 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
Jim Grosbach8be2f652011-12-09 23:34:09 +00005671
Jim Grosbachab5830e2011-12-14 02:16:11 +00005672 // First check for the ARM-specific .req directive.
5673 if (Parser.getTok().is(AsmToken::Identifier) &&
5674 Parser.getTok().getIdentifier() == ".req") {
5675 parseDirectiveReq(Name, NameLoc);
5676 // We always return 'error' for this, as we're done with this
5677 // statement and don't need to match the 'instruction."
5678 return true;
5679 }
5680
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005681 // Create the leading tokens for the mnemonic, split by '.' characters.
5682 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005683 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005684
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005685 // Split out the predication code and carry setting flag from the mnemonic.
5686 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005687 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005688 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005689 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005690 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005691 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005692
Jim Grosbach1c171b12011-08-25 17:23:55 +00005693 // In Thumb1, only the branch (B) instruction can be predicated.
5694 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005695 Parser.eatToEndOfStatement();
Jim Grosbach1c171b12011-08-25 17:23:55 +00005696 return Error(NameLoc, "conditional execution not supported in Thumb1");
5697 }
5698
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005699 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5700
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005701 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5702 // is the mask as it will be for the IT encoding if the conditional
5703 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5704 // where the conditional bit0 is zero, the instruction post-processing
5705 // will adjust the mask accordingly.
5706 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00005707 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5708 if (ITMask.size() > 3) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005709 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005710 return Error(Loc, "too many conditions on IT instruction");
5711 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005712 unsigned Mask = 8;
5713 for (unsigned i = ITMask.size(); i != 0; --i) {
5714 char pos = ITMask[i - 1];
5715 if (pos != 't' && pos != 'e') {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005716 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005717 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005718 }
5719 Mask >>= 1;
5720 if (ITMask[i - 1] == 't')
5721 Mask |= 8;
5722 }
Jim Grosbached16ec42011-08-29 22:24:09 +00005723 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005724 }
5725
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005726 // FIXME: This is all a pretty gross hack. We should automatically handle
5727 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00005728
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005729 // Next, add the CCOut and ConditionCode operands, if needed.
5730 //
5731 // For mnemonics which can ever incorporate a carry setting bit or predication
5732 // code, our matching model involves us always generating CCOut and
5733 // ConditionCode operands to match the mnemonic "as written" and then we let
5734 // the matcher deal with finding the right instruction or generating an
5735 // appropriate error.
5736 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Amara Emerson33089092013-09-19 11:59:01 +00005737 getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005738
Jim Grosbach03a8a162011-07-14 22:04:21 +00005739 // If we had a carry-set on an instruction that can't do that, issue an
5740 // error.
5741 if (!CanAcceptCarrySet && CarrySetting) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005742 Parser.eatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005743 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00005744 "' can not set flags, but 's' suffix specified");
5745 }
Jim Grosbach0a547702011-07-22 17:44:50 +00005746 // If we had a predication code on an instruction that can't do that, issue an
5747 // error.
5748 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005749 Parser.eatToEndOfStatement();
Jim Grosbach0a547702011-07-22 17:44:50 +00005750 return Error(NameLoc, "instruction '" + Mnemonic +
5751 "' is not predicable, but condition code specified");
5752 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00005753
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005754 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00005755 if (CanAcceptCarrySet) {
5756 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005757 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00005758 Loc));
5759 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005760
5761 // Add the predication code operand, if necessary.
5762 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005763 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5764 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005765 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00005766 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005767 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005768
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005769 // Add the processor imod operand, if necessary.
5770 if (ProcessorIMod) {
5771 Operands.push_back(ARMOperand::CreateImm(
5772 MCConstantExpr::Create(ProcessorIMod, getContext()),
5773 NameLoc, NameLoc));
Oliver Stannard1ae8b472014-09-24 14:20:01 +00005774 } else if (Mnemonic == "cps" && isMClass()) {
5775 return Error(NameLoc, "instruction 'cps' requires effect for M-class");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005776 }
5777
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005778 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005779 while (Next != StringRef::npos) {
5780 Start = Next;
5781 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005782 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005783
Jim Grosbach12952fe2011-11-11 23:08:10 +00005784 // Some NEON instructions have an optional datatype suffix that is
5785 // completely ignored. Check for that.
5786 if (isDataTypeToken(ExtraToken) &&
5787 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5788 continue;
5789
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005790 // For for ARM mode generate an error if the .n qualifier is used.
5791 if (ExtraToken == ".n" && !isThumb()) {
5792 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
Saleem Abdulrasoolbdae4b82014-01-12 05:25:44 +00005793 Parser.eatToEndOfStatement();
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005794 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5795 "arm mode");
5796 }
5797
5798 // The .n qualifier is always discarded as that is what the tables
5799 // and matcher expect. In ARM mode the .w qualifier has no effect,
5800 // so discard it to avoid errors that can be caused by the matcher.
5801 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00005802 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5803 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5804 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005805 }
5806
5807 // Read the remaining operands.
5808 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005809 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005810 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005811 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005812 return true;
5813 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005814
5815 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005816 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005817
5818 // Parse and remember the operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005819 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005820 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005821 return true;
5822 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005823 }
5824 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005825
Chris Lattnera2a9d162010-09-11 16:18:25 +00005826 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005827 SMLoc Loc = getLexer().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005828 Parser.eatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005829 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005830 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005831
Chris Lattner91689c12010-09-08 05:10:46 +00005832 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005833
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005834 if (RequireVFPRegisterListCheck) {
David Blaikie960ea3f2014-06-08 16:18:35 +00005835 ARMOperand &Op = static_cast<ARMOperand &>(*Operands.back());
5836 if (AcceptSinglePrecisionOnly && !Op.isSPRRegList())
5837 return Error(Op.getStartLoc(),
Saleem Abdulrasoolaca443c2013-12-29 18:53:16 +00005838 "VFP/Neon single precision register expected");
David Blaikie960ea3f2014-06-08 16:18:35 +00005839 if (AcceptDoublePrecisionOnly && !Op.isDPRRegList())
5840 return Error(Op.getStartLoc(),
Saleem Abdulrasoolaca443c2013-12-29 18:53:16 +00005841 "VFP/Neon double precision register expected");
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005842 }
5843
Jim Grosbach7283da92011-08-16 21:12:37 +00005844 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5845 // do and don't have a cc_out optional-def operand. With some spot-checks
5846 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005847 // parse and adjust accordingly before actually matching. We shouldn't ever
5848 // try to remove a cc_out operand that was explicitly set on the the
5849 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5850 // table driven matcher doesn't fit well with the ARM instruction set.
David Blaikie960ea3f2014-06-08 16:18:35 +00005851 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands))
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005852 Operands.erase(Operands.begin() + 1);
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005853
Joey Goulye8602552013-07-19 16:34:16 +00005854 // Some instructions have the same mnemonic, but don't always
5855 // have a predicate. Distinguish them here and delete the
5856 // predicate if needed.
David Blaikie960ea3f2014-06-08 16:18:35 +00005857 if (shouldOmitPredicateOperand(Mnemonic, Operands))
Joey Goulye8602552013-07-19 16:34:16 +00005858 Operands.erase(Operands.begin() + 1);
Joey Goulye8602552013-07-19 16:34:16 +00005859
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005860 // ARM mode 'blx' need special handling, as the register operand version
5861 // is predicable, but the label operand version is not. So, we can't rely
5862 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005863 // a k_CondCode operand in the list. If we're trying to match the label
5864 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005865 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005866 static_cast<ARMOperand &>(*Operands[2]).isImm())
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005867 Operands.erase(Operands.begin() + 1);
Jim Grosbach8cffa282011-08-11 23:51:13 +00005868
Weiming Zhao8f56f882012-11-16 21:55:34 +00005869 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5870 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5871 // a single GPRPair reg operand is used in the .td file to replace the two
5872 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5873 // expressed as a GPRPair, so we have to manually merge them.
5874 // FIXME: We would really like to be able to tablegen'erate this.
5875 if (!isThumb() && Operands.size() > 4 &&
Joey Goulye6d165c2013-08-27 17:38:16 +00005876 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
5877 Mnemonic == "stlexd")) {
5878 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
Weiming Zhao8f56f882012-11-16 21:55:34 +00005879 unsigned Idx = isLoad ? 2 : 3;
David Blaikie960ea3f2014-06-08 16:18:35 +00005880 ARMOperand &Op1 = static_cast<ARMOperand &>(*Operands[Idx]);
5881 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[Idx + 1]);
Weiming Zhao8f56f882012-11-16 21:55:34 +00005882
5883 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5884 // Adjust only if Op1 and Op2 are GPRs.
David Blaikie960ea3f2014-06-08 16:18:35 +00005885 if (Op1.isReg() && Op2.isReg() && MRC.contains(Op1.getReg()) &&
5886 MRC.contains(Op2.getReg())) {
5887 unsigned Reg1 = Op1.getReg();
5888 unsigned Reg2 = Op2.getReg();
Weiming Zhao8f56f882012-11-16 21:55:34 +00005889 unsigned Rt = MRI->getEncodingValue(Reg1);
5890 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5891
5892 // Rt2 must be Rt + 1 and Rt must be even.
5893 if (Rt + 1 != Rt2 || (Rt & 1)) {
David Blaikie960ea3f2014-06-08 16:18:35 +00005894 Error(Op2.getStartLoc(), isLoad
5895 ? "destination operands must be sequential"
5896 : "source operands must be sequential");
Weiming Zhao8f56f882012-11-16 21:55:34 +00005897 return true;
5898 }
5899 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5900 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
David Blaikie960ea3f2014-06-08 16:18:35 +00005901 Operands[Idx] =
5902 ARMOperand::CreateReg(NewReg, Op1.getStartLoc(), Op2.getEndLoc());
5903 Operands.erase(Operands.begin() + Idx + 1);
Weiming Zhao8f56f882012-11-16 21:55:34 +00005904 }
5905 }
5906
Renato Golin36c626e2014-09-26 16:14:29 +00005907 // If first 2 operands of a 3 operand instruction are the same
5908 // then transform to 2 operand version of the same instruction
5909 // e.g. 'adds r0, r0, #1' transforms to 'adds r0, #1'
5910 // FIXME: We would really like to be able to tablegen'erate this.
5911 if (isThumbOne() && Operands.size() == 6 &&
5912 (Mnemonic == "add" || Mnemonic == "sub" || Mnemonic == "and" ||
5913 Mnemonic == "eor" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
5914 Mnemonic == "asr" || Mnemonic == "adc" || Mnemonic == "sbc" ||
5915 Mnemonic == "ror" || Mnemonic == "orr" || Mnemonic == "bic")) {
5916 ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]);
5917 ARMOperand &Op4 = static_cast<ARMOperand &>(*Operands[4]);
5918 ARMOperand &Op5 = static_cast<ARMOperand &>(*Operands[5]);
5919
5920 // If both registers are the same then remove one of them from
5921 // the operand list.
5922 if (Op3.isReg() && Op4.isReg() && Op3.getReg() == Op4.getReg()) {
5923 // If 3rd operand (variable Op5) is a register and the instruction is adds/sub
5924 // then do not transform as the backend already handles this instruction
5925 // correctly.
5926 if (!Op5.isReg() || !((Mnemonic == "add" && CarrySetting) || Mnemonic == "sub")) {
5927 Operands.erase(Operands.begin() + 3);
5928 if (Mnemonic == "add" && !CarrySetting) {
5929 // Special case for 'add' (not 'adds') instruction must
5930 // remove the CCOut operand as well.
5931 Operands.erase(Operands.begin() + 1);
5932 }
5933 }
5934 }
5935 }
5936
5937 // If instruction is 'add' and first two register operands
5938 // use SP register, then remove one of the SP registers from
5939 // the instruction.
5940 // FIXME: We would really like to be able to tablegen'erate this.
5941 if (isThumbOne() && Operands.size() == 5 && Mnemonic == "add" && !CarrySetting) {
5942 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[2]);
5943 ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]);
5944 if (Op2.isReg() && Op3.isReg() && Op2.getReg() == ARM::SP && Op3.getReg() == ARM::SP) {
5945 Operands.erase(Operands.begin() + 2);
5946 }
5947 }
5948
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +00005949 // GNU Assembler extension (compatibility)
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005950 if ((Mnemonic == "ldrd" || Mnemonic == "strd")) {
David Blaikie960ea3f2014-06-08 16:18:35 +00005951 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[2]);
5952 ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]);
5953 if (Op3.isMem()) {
5954 assert(Op2.isReg() && "expected register argument");
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005955
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005956 unsigned SuperReg = MRI->getMatchingSuperReg(
David Blaikie960ea3f2014-06-08 16:18:35 +00005957 Op2.getReg(), ARM::gsub_0, &MRI->getRegClass(ARM::GPRPairRegClassID));
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005958
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005959 assert(SuperReg && "expected register pair");
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005960
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005961 unsigned PairedReg = MRI->getSubReg(SuperReg, ARM::gsub_1);
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005962
David Blaikie960ea3f2014-06-08 16:18:35 +00005963 Operands.insert(
5964 Operands.begin() + 3,
5965 ARMOperand::CreateReg(PairedReg, Op2.getStartLoc(), Op2.getEndLoc()));
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005966 }
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +00005967 }
5968
Kevin Enderby78f95722013-07-31 21:05:30 +00005969 // FIXME: As said above, this is all a pretty gross hack. This instruction
5970 // does not fit with other "subs" and tblgen.
5971 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5972 // so the Mnemonic is the original name "subs" and delete the predicate
5973 // operand so it will match the table entry.
5974 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005975 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5976 static_cast<ARMOperand &>(*Operands[3]).getReg() == ARM::PC &&
5977 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5978 static_cast<ARMOperand &>(*Operands[4]).getReg() == ARM::LR &&
5979 static_cast<ARMOperand &>(*Operands[5]).isImm()) {
5980 Operands.front() = ARMOperand::CreateToken(Name, NameLoc);
Kevin Enderby78f95722013-07-31 21:05:30 +00005981 Operands.erase(Operands.begin() + 1);
Kevin Enderby78f95722013-07-31 21:05:30 +00005982 }
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005983 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005984}
5985
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005986// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005987
5988// return 'true' if register list contains non-low GPR registers,
5989// 'false' otherwise. If Reg is in the register list or is HiReg, set
5990// 'containsReg' to true.
5991static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5992 unsigned HiReg, bool &containsReg) {
5993 containsReg = false;
5994 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5995 unsigned OpReg = Inst.getOperand(i).getReg();
5996 if (OpReg == Reg)
5997 containsReg = true;
5998 // Anything other than a low register isn't legal here.
5999 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
6000 return true;
6001 }
6002 return false;
6003}
6004
Rafael Espindola5403da42014-12-04 14:10:20 +00006005// Check if the specified regisgter is in the register list of the inst,
Jim Grosbacha31f2232011-09-07 18:05:34 +00006006// starting at the indicated operand number.
Rafael Espindola5403da42014-12-04 14:10:20 +00006007static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
Jim Grosbacha31f2232011-09-07 18:05:34 +00006008 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
6009 unsigned OpReg = Inst.getOperand(i).getReg();
Rafael Espindola5403da42014-12-04 14:10:20 +00006010 if (OpReg == Reg)
6011 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00006012 }
6013 return false;
6014}
6015
Richard Barton8d519fe2013-09-05 14:14:19 +00006016// Return true if instruction has the interesting property of being
6017// allowed in IT blocks, but not being predicable.
6018static bool instIsBreakpoint(const MCInst &Inst) {
6019 return Inst.getOpcode() == ARM::tBKPT ||
6020 Inst.getOpcode() == ARM::BKPT ||
6021 Inst.getOpcode() == ARM::tHLT ||
6022 Inst.getOpcode() == ARM::HLT;
6023
6024}
6025
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006026bool ARMAsmParser::validatetLDMRegList(MCInst Inst,
6027 const OperandVector &Operands,
Jyoti Allur5a139142015-01-14 10:48:16 +00006028 unsigned ListNo, bool IsARPop) {
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006029 const ARMOperand &Op = static_cast<const ARMOperand &>(*Operands[ListNo]);
6030 bool HasWritebackToken = Op.isToken() && Op.getToken() == "!";
6031
6032 bool ListContainsSP = listContainsReg(Inst, ListNo, ARM::SP);
6033 bool ListContainsLR = listContainsReg(Inst, ListNo, ARM::LR);
6034 bool ListContainsPC = listContainsReg(Inst, ListNo, ARM::PC);
6035
Jyoti Allur5a139142015-01-14 10:48:16 +00006036 if (!IsARPop && ListContainsSP)
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006037 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(),
6038 "SP may not be in the register list");
6039 else if (ListContainsPC && ListContainsLR)
6040 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(),
6041 "PC and LR may not be in the register list simultaneously");
6042 else if (inITBlock() && !lastInITBlock() && ListContainsPC)
6043 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(),
6044 "instruction must be outside of IT block or the last "
6045 "instruction in an IT block");
6046 return false;
6047}
6048
6049bool ARMAsmParser::validatetSTMRegList(MCInst Inst,
6050 const OperandVector &Operands,
6051 unsigned ListNo) {
6052 const ARMOperand &Op = static_cast<const ARMOperand &>(*Operands[ListNo]);
6053 bool HasWritebackToken = Op.isToken() && Op.getToken() == "!";
6054
6055 bool ListContainsSP = listContainsReg(Inst, ListNo, ARM::SP);
6056 bool ListContainsPC = listContainsReg(Inst, ListNo, ARM::PC);
6057
6058 if (ListContainsSP && ListContainsPC)
6059 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(),
6060 "SP and PC may not be in the register list");
6061 else if (ListContainsSP)
6062 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(),
6063 "SP may not be in the register list");
6064 else if (ListContainsPC)
6065 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(),
6066 "PC may not be in the register list");
6067 return false;
6068}
6069
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006070// FIXME: We would really like to be able to tablegen'erate this.
David Blaikie960ea3f2014-06-08 16:18:35 +00006071bool ARMAsmParser::validateInstruction(MCInst &Inst,
6072 const OperandVector &Operands) {
Joey Gouly0e76fa72013-09-12 10:28:05 +00006073 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00006074 SMLoc Loc = Operands[0]->getStartLoc();
Mihai Popaad18d3c2013-08-09 10:38:32 +00006075
Jim Grosbached16ec42011-08-29 22:24:09 +00006076 // Check the IT block state first.
Richard Barton8d519fe2013-09-05 14:14:19 +00006077 // NOTE: BKPT and HLT instructions have the interesting property of being
Tilmann Schellerbe904772013-09-30 17:57:30 +00006078 // allowed in IT blocks, but not being predicable. They just always execute.
Richard Barton8d519fe2013-09-05 14:14:19 +00006079 if (inITBlock() && !instIsBreakpoint(Inst)) {
Tilmann Schellerbe904772013-09-30 17:57:30 +00006080 unsigned Bit = 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00006081 if (ITState.FirstCond)
6082 ITState.FirstCond = false;
6083 else
Tilmann Schellerbe904772013-09-30 17:57:30 +00006084 Bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00006085 // The instruction must be predicable.
6086 if (!MCID.isPredicable())
6087 return Error(Loc, "instructions in IT block must be predicable");
6088 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
Tilmann Schellerbe904772013-09-30 17:57:30 +00006089 unsigned ITCond = Bit ? ITState.Cond :
Jim Grosbached16ec42011-08-29 22:24:09 +00006090 ARMCC::getOppositeCondition(ITState.Cond);
6091 if (Cond != ITCond) {
6092 // Find the condition code Operand to get its SMLoc information.
6093 SMLoc CondLoc;
Tilmann Schellerbe904772013-09-30 17:57:30 +00006094 for (unsigned I = 1; I < Operands.size(); ++I)
David Blaikie960ea3f2014-06-08 16:18:35 +00006095 if (static_cast<ARMOperand &>(*Operands[I]).isCondCode())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006096 CondLoc = Operands[I]->getStartLoc();
Jim Grosbached16ec42011-08-29 22:24:09 +00006097 return Error(CondLoc, "incorrect condition in IT block; got '" +
6098 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
6099 "', but expected '" +
6100 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
6101 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00006102 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00006103 } else if (isThumbTwo() && MCID.isPredicable() &&
6104 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Mihai Popaad18d3c2013-08-09 10:38:32 +00006105 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
6106 Inst.getOpcode() != ARM::t2Bcc)
Jim Grosbached16ec42011-08-29 22:24:09 +00006107 return Error(Loc, "predicated instructions must be in IT block");
6108
Tilmann Scheller255722b2013-09-30 16:11:48 +00006109 const unsigned Opcode = Inst.getOpcode();
6110 switch (Opcode) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00006111 case ARM::LDRD:
6112 case ARM::LDRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00006113 case ARM::LDRD_POST: {
Tilmann Scheller255722b2013-09-30 16:11:48 +00006114 const unsigned RtReg = Inst.getOperand(0).getReg();
6115
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00006116 // Rt can't be R14.
6117 if (RtReg == ARM::LR)
6118 return Error(Operands[3]->getStartLoc(),
6119 "Rt can't be R14");
Tilmann Scheller255722b2013-09-30 16:11:48 +00006120
6121 const unsigned Rt = MRI->getEncodingValue(RtReg);
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00006122 // Rt must be even-numbered.
6123 if ((Rt & 1) == 1)
6124 return Error(Operands[3]->getStartLoc(),
6125 "Rt must be even-numbered");
Tilmann Scheller255722b2013-09-30 16:11:48 +00006126
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006127 // Rt2 must be Rt + 1.
Tilmann Scheller255722b2013-09-30 16:11:48 +00006128 const unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006129 if (Rt2 != Rt + 1)
6130 return Error(Operands[3]->getStartLoc(),
6131 "destination operands must be sequential");
Tilmann Scheller255722b2013-09-30 16:11:48 +00006132
6133 if (Opcode == ARM::LDRD_PRE || Opcode == ARM::LDRD_POST) {
6134 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg());
6135 // For addressing modes with writeback, the base register needs to be
6136 // different from the destination registers.
6137 if (Rn == Rt || Rn == Rt2)
6138 return Error(Operands[3]->getStartLoc(),
6139 "base register needs to be different from destination "
6140 "registers");
6141 }
6142
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006143 return false;
6144 }
Tilmann Scheller88c8f162013-09-27 10:30:18 +00006145 case ARM::t2LDRDi8:
6146 case ARM::t2LDRD_PRE:
6147 case ARM::t2LDRD_POST: {
Tilmann Scheller041f7172013-09-27 10:38:11 +00006148 // Rt2 must be different from Rt.
Tilmann Scheller88c8f162013-09-27 10:30:18 +00006149 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
6150 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
6151 if (Rt2 == Rt)
6152 return Error(Operands[3]->getStartLoc(),
6153 "destination operands can't be identical");
6154 return false;
6155 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00006156 case ARM::STRD: {
6157 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00006158 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
6159 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00006160 if (Rt2 != Rt + 1)
6161 return Error(Operands[3]->getStartLoc(),
6162 "source operands must be sequential");
6163 return false;
6164 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00006165 case ARM::STRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00006166 case ARM::STRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006167 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00006168 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
6169 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006170 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00006171 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006172 "source operands must be sequential");
6173 return false;
6174 }
Tilmann Scheller3352a582014-07-23 12:38:17 +00006175 case ARM::STR_PRE_IMM:
6176 case ARM::STR_PRE_REG:
6177 case ARM::STR_POST_IMM:
Tilmann Scheller27272792014-07-23 13:03:47 +00006178 case ARM::STR_POST_REG:
Tilmann Scheller96ef72e2014-07-24 09:55:46 +00006179 case ARM::STRH_PRE:
6180 case ARM::STRH_POST:
Tilmann Scheller27272792014-07-23 13:03:47 +00006181 case ARM::STRB_PRE_IMM:
6182 case ARM::STRB_PRE_REG:
6183 case ARM::STRB_POST_IMM:
6184 case ARM::STRB_POST_REG: {
Tilmann Scheller3352a582014-07-23 12:38:17 +00006185 // Rt must be different from Rn.
6186 const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
6187 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(2).getReg());
6188
6189 if (Rt == Rn)
6190 return Error(Operands[3]->getStartLoc(),
6191 "source register and base register can't be identical");
6192 return false;
6193 }
Tilmann Scheller8ba74302014-08-01 11:08:51 +00006194 case ARM::LDR_PRE_IMM:
6195 case ARM::LDR_PRE_REG:
6196 case ARM::LDR_POST_IMM:
Tilmann Scheller8ff079c2014-08-01 11:33:47 +00006197 case ARM::LDR_POST_REG:
6198 case ARM::LDRH_PRE:
6199 case ARM::LDRH_POST:
6200 case ARM::LDRSH_PRE:
Tilmann Scheller7cc0ed42014-08-01 12:08:04 +00006201 case ARM::LDRSH_POST:
6202 case ARM::LDRB_PRE_IMM:
6203 case ARM::LDRB_PRE_REG:
6204 case ARM::LDRB_POST_IMM:
6205 case ARM::LDRB_POST_REG:
6206 case ARM::LDRSB_PRE:
6207 case ARM::LDRSB_POST: {
Tilmann Scheller8ba74302014-08-01 11:08:51 +00006208 // Rt must be different from Rn.
6209 const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
6210 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(2).getReg());
6211
6212 if (Rt == Rn)
6213 return Error(Operands[3]->getStartLoc(),
6214 "destination register and base register can't be identical");
6215 return false;
6216 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00006217 case ARM::SBFX:
6218 case ARM::UBFX: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00006219 // Width must be in range [1, 32-lsb].
6220 unsigned LSB = Inst.getOperand(2).getImm();
6221 unsigned Widthm1 = Inst.getOperand(3).getImm();
6222 if (Widthm1 >= 32 - LSB)
Jim Grosbach03f56d92011-07-27 21:09:25 +00006223 return Error(Operands[5]->getStartLoc(),
6224 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00006225 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00006226 }
Rafael Espindola5403da42014-12-04 14:10:20 +00006227 // Notionally handles ARM::tLDMIA_UPD too.
6228 case ARM::tLDMIA: {
6229 // If we're parsing Thumb2, the .w variant is available and handles
6230 // most cases that are normally illegal for a Thumb1 LDM instruction.
6231 // We'll make the transformation in processInstruction() if necessary.
6232 //
6233 // Thumb LDM instructions are writeback iff the base register is not
6234 // in the register list.
6235 unsigned Rn = Inst.getOperand(0).getReg();
6236 bool HasWritebackToken =
6237 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
6238 static_cast<ARMOperand &>(*Operands[3]).getToken() == "!");
6239 bool ListContainsBase;
6240 if (checkLowRegisterList(Inst, 3, Rn, 0, ListContainsBase) && !isThumbTwo())
6241 return Error(Operands[3 + HasWritebackToken]->getStartLoc(),
6242 "registers must be in range r0-r7");
6243 // If we should have writeback, then there should be a '!' token.
6244 if (!ListContainsBase && !HasWritebackToken && !isThumbTwo())
6245 return Error(Operands[2]->getStartLoc(),
6246 "writeback operator '!' expected");
6247 // If we should not have writeback, there must not be a '!'. This is
6248 // true even for the 32-bit wide encodings.
6249 if (ListContainsBase && HasWritebackToken)
6250 return Error(Operands[3]->getStartLoc(),
6251 "writeback operator '!' not allowed when base register "
6252 "in register list");
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006253
6254 if (validatetLDMRegList(Inst, Operands, 3))
6255 return true;
Rafael Espindola5403da42014-12-04 14:10:20 +00006256 break;
6257 }
Tim Northover08a86602013-10-22 19:00:39 +00006258 case ARM::LDMIA_UPD:
6259 case ARM::LDMDB_UPD:
6260 case ARM::LDMIB_UPD:
6261 case ARM::LDMDA_UPD:
6262 // ARM variants loading and updating the same register are only officially
6263 // UNPREDICTABLE on v7 upwards. Goodness knows what they did before.
6264 if (!hasV7Ops())
6265 break;
Rafael Espindola5403da42014-12-04 14:10:20 +00006266 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
6267 return Error(Operands.back()->getStartLoc(),
6268 "writeback register not allowed in register list");
6269 break;
Jyoti Allur3b686072014-10-22 10:41:14 +00006270 case ARM::t2LDMIA:
6271 case ARM::t2LDMDB:
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006272 if (validatetLDMRegList(Inst, Operands, 3))
6273 return true;
Rafael Espindola5403da42014-12-04 14:10:20 +00006274 break;
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006275 case ARM::t2STMIA:
6276 case ARM::t2STMDB:
6277 if (validatetSTMRegList(Inst, Operands, 3))
6278 return true;
6279 break;
Tim Northover08a86602013-10-22 19:00:39 +00006280 case ARM::t2LDMIA_UPD:
6281 case ARM::t2LDMDB_UPD:
6282 case ARM::t2STMIA_UPD:
Rafael Espindola5403da42014-12-04 14:10:20 +00006283 case ARM::t2STMDB_UPD: {
6284 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
6285 return Error(Operands.back()->getStartLoc(),
6286 "writeback register not allowed in register list");
6287
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006288 if (Opcode == ARM::t2LDMIA_UPD || Opcode == ARM::t2LDMDB_UPD) {
Saleem Abdulrasool0b5a8522014-12-18 16:16:53 +00006289 if (validatetLDMRegList(Inst, Operands, 3))
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006290 return true;
6291 } else {
Saleem Abdulrasool0b5a8522014-12-18 16:16:53 +00006292 if (validatetSTMRegList(Inst, Operands, 3))
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006293 return true;
6294 }
Rafael Espindola5403da42014-12-04 14:10:20 +00006295 break;
6296 }
Tim Northover8eaf1542013-11-12 21:32:41 +00006297 case ARM::sysLDMIA_UPD:
6298 case ARM::sysLDMDA_UPD:
6299 case ARM::sysLDMDB_UPD:
Rafael Espindola5403da42014-12-04 14:10:20 +00006300 case ARM::sysLDMIB_UPD:
6301 if (!listContainsReg(Inst, 3, ARM::PC))
6302 return Error(Operands[4]->getStartLoc(),
6303 "writeback register only allowed on system LDM "
6304 "if PC in register-list");
Tim Northover8eaf1542013-11-12 21:32:41 +00006305 break;
6306 case ARM::sysSTMIA_UPD:
6307 case ARM::sysSTMDA_UPD:
6308 case ARM::sysSTMDB_UPD:
6309 case ARM::sysSTMIB_UPD:
6310 return Error(Operands[2]->getStartLoc(),
6311 "system STM cannot have writeback register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00006312 case ARM::tMUL: {
6313 // The second source operand must be the same register as the destination
6314 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00006315 //
6316 // In this case, we must directly check the parsed operands because the
6317 // cvtThumbMultiply() function is written in such a way that it guarantees
6318 // this first statement is always true for the new Inst. Essentially, the
6319 // destination is unconditionally copied into the second source operand
6320 // without checking to see if it matches what we actually parsed.
David Blaikie960ea3f2014-06-08 16:18:35 +00006321 if (Operands.size() == 6 && (((ARMOperand &)*Operands[3]).getReg() !=
6322 ((ARMOperand &)*Operands[5]).getReg()) &&
6323 (((ARMOperand &)*Operands[3]).getReg() !=
6324 ((ARMOperand &)*Operands[4]).getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00006325 return Error(Operands[3]->getStartLoc(),
6326 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00006327 }
6328 break;
6329 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00006330 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
6331 // so only issue a diagnostic for thumb1. The instructions will be
6332 // switched to the t2 encodings in processInstruction() if necessary.
Rafael Espindola5403da42014-12-04 14:10:20 +00006333 case ARM::tPOP: {
6334 bool ListContainsBase;
6335 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, ListContainsBase) &&
6336 !isThumbTwo())
6337 return Error(Operands[2]->getStartLoc(),
6338 "registers must be in range r0-r7 or pc");
Jyoti Allur5a139142015-01-14 10:48:16 +00006339 if (validatetLDMRegList(Inst, Operands, 2, !isMClass()))
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006340 return true;
Rafael Espindola5403da42014-12-04 14:10:20 +00006341 break;
6342 }
Jim Grosbach38c59fc2011-08-22 23:17:34 +00006343 case ARM::tPUSH: {
Rafael Espindola5403da42014-12-04 14:10:20 +00006344 bool ListContainsBase;
6345 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, ListContainsBase) &&
6346 !isThumbTwo())
6347 return Error(Operands[2]->getStartLoc(),
6348 "registers must be in range r0-r7 or lr");
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006349 if (validatetSTMRegList(Inst, Operands, 2))
6350 return true;
Jim Grosbach38c59fc2011-08-22 23:17:34 +00006351 break;
6352 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00006353 case ARM::tSTMIA_UPD: {
Rafael Espindola5403da42014-12-04 14:10:20 +00006354 bool ListContainsBase, InvalidLowList;
6355 InvalidLowList = checkLowRegisterList(Inst, 4, Inst.getOperand(0).getReg(),
6356 0, ListContainsBase);
6357 if (InvalidLowList && !isThumbTwo())
6358 return Error(Operands[4]->getStartLoc(),
6359 "registers must be in range r0-r7");
6360
6361 // This would be converted to a 32-bit stm, but that's not valid if the
6362 // writeback register is in the list.
6363 if (InvalidLowList && ListContainsBase)
6364 return Error(Operands[4]->getStartLoc(),
6365 "writeback operator '!' not allowed when base register "
6366 "in register list");
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006367
6368 if (validatetSTMRegList(Inst, Operands, 4))
6369 return true;
Jim Grosbachd80d1692011-08-23 18:15:37 +00006370 break;
6371 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00006372 case ARM::tADDrSP: {
6373 // If the non-SP source operand and the destination operand are not the
6374 // same, we need thumb2 (for the wide encoding), or we have an error.
6375 if (!isThumbTwo() &&
6376 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
6377 return Error(Operands[4]->getStartLoc(),
6378 "source register must be the same as destination");
6379 }
6380 break;
6381 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00006382 // Final range checking for Thumb unconditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00006383 case ARM::tB:
David Blaikie960ea3f2014-06-08 16:18:35 +00006384 if (!(static_cast<ARMOperand &>(*Operands[2])).isSignedOffset<11, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006385 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00006386 break;
6387 case ARM::t2B: {
6388 int op = (Operands[2]->isImm()) ? 2 : 3;
David Blaikie960ea3f2014-06-08 16:18:35 +00006389 if (!static_cast<ARMOperand &>(*Operands[op]).isSignedOffset<24, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006390 return Error(Operands[op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00006391 break;
6392 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00006393 // Final range checking for Thumb conditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00006394 case ARM::tBcc:
David Blaikie960ea3f2014-06-08 16:18:35 +00006395 if (!static_cast<ARMOperand &>(*Operands[2]).isSignedOffset<8, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006396 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00006397 break;
6398 case ARM::t2Bcc: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00006399 int Op = (Operands[2]->isImm()) ? 2 : 3;
David Blaikie960ea3f2014-06-08 16:18:35 +00006400 if (!static_cast<ARMOperand &>(*Operands[Op]).isSignedOffset<20, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006401 return Error(Operands[Op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00006402 break;
6403 }
Kevin Enderbyb7e51f62014-04-18 23:06:39 +00006404 case ARM::MOVi16:
6405 case ARM::t2MOVi16:
6406 case ARM::t2MOVTi16:
6407 {
6408 // We want to avoid misleadingly allowing something like "mov r0, <symbol>"
6409 // especially when we turn it into a movw and the expression <symbol> does
6410 // not have a :lower16: or :upper16 as part of the expression. We don't
6411 // want the behavior of silently truncating, which can be unexpected and
6412 // lead to bugs that are difficult to find since this is an easy mistake
6413 // to make.
6414 int i = (Operands[3]->isImm()) ? 3 : 4;
David Blaikie960ea3f2014-06-08 16:18:35 +00006415 ARMOperand &Op = static_cast<ARMOperand &>(*Operands[i]);
6416 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm());
Kevin Enderbyb7e51f62014-04-18 23:06:39 +00006417 if (CE) break;
David Blaikie960ea3f2014-06-08 16:18:35 +00006418 const MCExpr *E = dyn_cast<MCExpr>(Op.getImm());
Kevin Enderbyb7e51f62014-04-18 23:06:39 +00006419 if (!E) break;
6420 const ARMMCExpr *ARM16Expr = dyn_cast<ARMMCExpr>(E);
6421 if (!ARM16Expr || (ARM16Expr->getKind() != ARMMCExpr::VK_ARM_HI16 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00006422 ARM16Expr->getKind() != ARMMCExpr::VK_ARM_LO16))
6423 return Error(
6424 Op.getStartLoc(),
6425 "immediate expression for mov requires :lower16: or :upper16");
6426 break;
6427 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006428 }
6429
6430 return false;
6431}
6432
Jim Grosbach1a747242012-01-23 23:45:44 +00006433static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00006434 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00006435 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006436 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006437 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
6438 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
6439 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
6440 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
6441 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
6442 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
6443 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
6444 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
6445 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006446
6447 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006448 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
6449 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
6450 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
6451 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
6452 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00006453
Jim Grosbach1e946a42012-01-24 00:43:12 +00006454 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
6455 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
6456 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
6457 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
6458 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00006459
Jim Grosbach1e946a42012-01-24 00:43:12 +00006460 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
6461 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
6462 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
6463 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
6464 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00006465
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006466 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006467 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
6468 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
6469 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
6470 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
6471 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
6472 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
6473 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
6474 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
6475 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
6476 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
6477 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
6478 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
6479 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
6480 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
6481 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006482
Jim Grosbach1a747242012-01-23 23:45:44 +00006483 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00006484 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
6485 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
6486 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
6487 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
6488 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
6489 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
6490 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
6491 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
6492 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
6493 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
6494 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
6495 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
6496 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
6497 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
6498 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
6499 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
6500 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
6501 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00006502
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006503 // VST4LN
6504 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
6505 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
6506 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
6507 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
6508 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
6509 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
6510 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
6511 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
6512 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
6513 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
6514 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
6515 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
6516 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
6517 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
6518 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
6519
Jim Grosbachda70eac2012-01-24 00:58:13 +00006520 // VST4
6521 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
6522 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
6523 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
6524 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
6525 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
6526 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
6527 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
6528 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
6529 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
6530 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
6531 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
6532 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
6533 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
6534 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
6535 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
6536 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
6537 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
6538 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00006539 }
6540}
6541
Jim Grosbach1a747242012-01-23 23:45:44 +00006542static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00006543 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00006544 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006545 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006546 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
6547 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
6548 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
6549 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
6550 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
6551 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
6552 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
6553 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
6554 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006555
6556 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006557 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
6558 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
6559 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
6560 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
6561 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
6562 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
6563 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
6564 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
6565 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
6566 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
6567 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
6568 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
6569 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
6570 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
6571 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006572
Jim Grosbachb78403c2012-01-24 23:47:04 +00006573 // VLD3DUP
6574 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
6575 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
6576 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
6577 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
Kevin Enderbyd88fec32014-04-08 18:00:52 +00006578 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
Jim Grosbachb78403c2012-01-24 23:47:04 +00006579 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
6580 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
6581 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
6582 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
6583 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
6584 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
6585 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
6586 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
6587 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
6588 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
6589 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
6590 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
6591 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
6592
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006593 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006594 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
6595 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
6596 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
6597 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
6598 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
6599 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
6600 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
6601 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
6602 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
6603 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
6604 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
6605 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
6606 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
6607 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
6608 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006609
6610 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00006611 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
6612 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
6613 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
6614 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
6615 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
6616 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
6617 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
6618 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
6619 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
6620 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
6621 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
6622 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
6623 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
6624 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
6625 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
6626 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
6627 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
6628 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00006629
Jim Grosbach14952a02012-01-24 18:37:25 +00006630 // VLD4LN
6631 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
6632 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
6633 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
Kevin Enderby8108f382014-03-26 19:35:40 +00006634 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
Jim Grosbach14952a02012-01-24 18:37:25 +00006635 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
6636 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
6637 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
6638 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
6639 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
6640 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
6641 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
6642 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
6643 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
6644 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
6645 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
6646
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006647 // VLD4DUP
6648 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
6649 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
6650 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
6651 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
6652 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
6653 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
6654 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
6655 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
6656 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
6657 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
6658 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
6659 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
6660 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
6661 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
6662 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
6663 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
6664 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
6665 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
6666
Jim Grosbached561fc2012-01-24 00:43:17 +00006667 // VLD4
6668 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
6669 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
6670 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
6671 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
6672 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
6673 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
6674 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
6675 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
6676 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
6677 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
6678 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
6679 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
6680 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
6681 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
6682 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
6683 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
6684 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
6685 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00006686 }
6687}
6688
David Blaikie960ea3f2014-06-08 16:18:35 +00006689bool ARMAsmParser::processInstruction(MCInst &Inst,
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +00006690 const OperandVector &Operands,
6691 MCStreamer &Out) {
Jim Grosbach8ba76c62011-08-11 17:35:48 +00006692 switch (Inst.getOpcode()) {
Saleem Abdulrasoolfb3950e2014-01-12 04:36:01 +00006693 // Alias for alternate form of 'ldr{,b}t Rt, [Rn], #imm' instruction.
6694 case ARM::LDRT_POST:
6695 case ARM::LDRBT_POST: {
6696 const unsigned Opcode =
6697 (Inst.getOpcode() == ARM::LDRT_POST) ? ARM::LDRT_POST_IMM
6698 : ARM::LDRBT_POST_IMM;
6699 MCInst TmpInst;
6700 TmpInst.setOpcode(Opcode);
6701 TmpInst.addOperand(Inst.getOperand(0));
6702 TmpInst.addOperand(Inst.getOperand(1));
6703 TmpInst.addOperand(Inst.getOperand(1));
6704 TmpInst.addOperand(MCOperand::CreateReg(0));
6705 TmpInst.addOperand(MCOperand::CreateImm(0));
6706 TmpInst.addOperand(Inst.getOperand(2));
6707 TmpInst.addOperand(Inst.getOperand(3));
6708 Inst = TmpInst;
6709 return true;
6710 }
6711 // Alias for alternate form of 'str{,b}t Rt, [Rn], #imm' instruction.
6712 case ARM::STRT_POST:
6713 case ARM::STRBT_POST: {
6714 const unsigned Opcode =
6715 (Inst.getOpcode() == ARM::STRT_POST) ? ARM::STRT_POST_IMM
6716 : ARM::STRBT_POST_IMM;
6717 MCInst TmpInst;
6718 TmpInst.setOpcode(Opcode);
6719 TmpInst.addOperand(Inst.getOperand(1));
6720 TmpInst.addOperand(Inst.getOperand(0));
6721 TmpInst.addOperand(Inst.getOperand(1));
6722 TmpInst.addOperand(MCOperand::CreateReg(0));
6723 TmpInst.addOperand(MCOperand::CreateImm(0));
6724 TmpInst.addOperand(Inst.getOperand(2));
6725 TmpInst.addOperand(Inst.getOperand(3));
6726 Inst = TmpInst;
6727 return true;
6728 }
Jim Grosbache974a6a2012-09-25 00:08:13 +00006729 // Alias for alternate form of 'ADR Rd, #imm' instruction.
6730 case ARM::ADDri: {
6731 if (Inst.getOperand(1).getReg() != ARM::PC ||
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +00006732 Inst.getOperand(5).getReg() != 0 ||
6733 !(Inst.getOperand(2).isExpr() || Inst.getOperand(2).isImm()))
Jim Grosbache974a6a2012-09-25 00:08:13 +00006734 return false;
6735 MCInst TmpInst;
6736 TmpInst.setOpcode(ARM::ADR);
6737 TmpInst.addOperand(Inst.getOperand(0));
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +00006738 if (Inst.getOperand(2).isImm()) {
Asiri Rathnayake7835e9b2014-12-09 13:14:58 +00006739 // Immediate (mod_imm) will be in its encoded form, we must unencode it
6740 // before passing it to the ADR instruction.
6741 unsigned Enc = Inst.getOperand(2).getImm();
6742 TmpInst.addOperand(MCOperand::CreateImm(
6743 ARM_AM::rotr32(Enc & 0xFF, (Enc & 0xF00) >> 7)));
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +00006744 } else {
6745 // Turn PC-relative expression into absolute expression.
6746 // Reading PC provides the start of the current instruction + 8 and
6747 // the transform to adr is biased by that.
6748 MCSymbol *Dot = getContext().CreateTempSymbol();
6749 Out.EmitLabel(Dot);
6750 const MCExpr *OpExpr = Inst.getOperand(2).getExpr();
6751 const MCExpr *InstPC = MCSymbolRefExpr::Create(Dot,
6752 MCSymbolRefExpr::VK_None,
6753 getContext());
6754 const MCExpr *Const8 = MCConstantExpr::Create(8, getContext());
6755 const MCExpr *ReadPC = MCBinaryExpr::CreateAdd(InstPC, Const8,
6756 getContext());
6757 const MCExpr *FixupAddr = MCBinaryExpr::CreateAdd(ReadPC, OpExpr,
6758 getContext());
6759 TmpInst.addOperand(MCOperand::CreateExpr(FixupAddr));
6760 }
Jim Grosbache974a6a2012-09-25 00:08:13 +00006761 TmpInst.addOperand(Inst.getOperand(3));
6762 TmpInst.addOperand(Inst.getOperand(4));
6763 Inst = TmpInst;
6764 return true;
6765 }
Jim Grosbach94298a92012-01-18 22:46:46 +00006766 // Aliases for alternate PC+imm syntax of LDR instructions.
6767 case ARM::t2LDRpcrel:
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00006768 // Select the narrow version if the immediate will fit.
6769 if (Inst.getOperand(1).getImm() > 0 &&
Amaury de la Vieuvilleeac0bad2013-06-18 08:13:05 +00006770 Inst.getOperand(1).getImm() <= 0xff &&
David Blaikie960ea3f2014-06-08 16:18:35 +00006771 !(static_cast<ARMOperand &>(*Operands[2]).isToken() &&
6772 static_cast<ARMOperand &>(*Operands[2]).getToken() == ".w"))
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00006773 Inst.setOpcode(ARM::tLDRpci);
6774 else
6775 Inst.setOpcode(ARM::t2LDRpci);
Jim Grosbach94298a92012-01-18 22:46:46 +00006776 return true;
6777 case ARM::t2LDRBpcrel:
6778 Inst.setOpcode(ARM::t2LDRBpci);
6779 return true;
6780 case ARM::t2LDRHpcrel:
6781 Inst.setOpcode(ARM::t2LDRHpci);
6782 return true;
6783 case ARM::t2LDRSBpcrel:
6784 Inst.setOpcode(ARM::t2LDRSBpci);
6785 return true;
6786 case ARM::t2LDRSHpcrel:
6787 Inst.setOpcode(ARM::t2LDRSHpci);
6788 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006789 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006790 case ARM::VST1LNdWB_register_Asm_8:
6791 case ARM::VST1LNdWB_register_Asm_16:
6792 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006793 MCInst TmpInst;
6794 // Shuffle the operands around so the lane index operand is in the
6795 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006796 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006797 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006798 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6799 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6800 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6801 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6802 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6803 TmpInst.addOperand(Inst.getOperand(1)); // lane
6804 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6805 TmpInst.addOperand(Inst.getOperand(6));
6806 Inst = TmpInst;
6807 return true;
6808 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006809
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006810 case ARM::VST2LNdWB_register_Asm_8:
6811 case ARM::VST2LNdWB_register_Asm_16:
6812 case ARM::VST2LNdWB_register_Asm_32:
6813 case ARM::VST2LNqWB_register_Asm_16:
6814 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006815 MCInst TmpInst;
6816 // Shuffle the operands around so the lane index operand is in the
6817 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006818 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006819 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006820 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6821 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6822 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6823 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6824 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006825 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6826 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006827 TmpInst.addOperand(Inst.getOperand(1)); // lane
6828 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6829 TmpInst.addOperand(Inst.getOperand(6));
6830 Inst = TmpInst;
6831 return true;
6832 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006833
6834 case ARM::VST3LNdWB_register_Asm_8:
6835 case ARM::VST3LNdWB_register_Asm_16:
6836 case ARM::VST3LNdWB_register_Asm_32:
6837 case ARM::VST3LNqWB_register_Asm_16:
6838 case ARM::VST3LNqWB_register_Asm_32: {
6839 MCInst TmpInst;
6840 // Shuffle the operands around so the lane index operand is in the
6841 // right place.
6842 unsigned Spacing;
6843 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6844 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6845 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6846 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6847 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6848 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6849 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6850 Spacing));
6851 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6852 Spacing * 2));
6853 TmpInst.addOperand(Inst.getOperand(1)); // lane
6854 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6855 TmpInst.addOperand(Inst.getOperand(6));
6856 Inst = TmpInst;
6857 return true;
6858 }
6859
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006860 case ARM::VST4LNdWB_register_Asm_8:
6861 case ARM::VST4LNdWB_register_Asm_16:
6862 case ARM::VST4LNdWB_register_Asm_32:
6863 case ARM::VST4LNqWB_register_Asm_16:
6864 case ARM::VST4LNqWB_register_Asm_32: {
6865 MCInst TmpInst;
6866 // Shuffle the operands around so the lane index operand is in the
6867 // right place.
6868 unsigned Spacing;
6869 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6870 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6871 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6872 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6873 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6874 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6875 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6876 Spacing));
6877 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6878 Spacing * 2));
6879 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6880 Spacing * 3));
6881 TmpInst.addOperand(Inst.getOperand(1)); // lane
6882 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6883 TmpInst.addOperand(Inst.getOperand(6));
6884 Inst = TmpInst;
6885 return true;
6886 }
6887
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006888 case ARM::VST1LNdWB_fixed_Asm_8:
6889 case ARM::VST1LNdWB_fixed_Asm_16:
6890 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006891 MCInst TmpInst;
6892 // Shuffle the operands around so the lane index operand is in the
6893 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006894 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006895 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006896 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6897 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6898 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6899 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6900 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6901 TmpInst.addOperand(Inst.getOperand(1)); // lane
6902 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6903 TmpInst.addOperand(Inst.getOperand(5));
6904 Inst = TmpInst;
6905 return true;
6906 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006907
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006908 case ARM::VST2LNdWB_fixed_Asm_8:
6909 case ARM::VST2LNdWB_fixed_Asm_16:
6910 case ARM::VST2LNdWB_fixed_Asm_32:
6911 case ARM::VST2LNqWB_fixed_Asm_16:
6912 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006913 MCInst TmpInst;
6914 // Shuffle the operands around so the lane index operand is in the
6915 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006916 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006917 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006918 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6919 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6920 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6921 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6922 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006923 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6924 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006925 TmpInst.addOperand(Inst.getOperand(1)); // lane
6926 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6927 TmpInst.addOperand(Inst.getOperand(5));
6928 Inst = TmpInst;
6929 return true;
6930 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006931
6932 case ARM::VST3LNdWB_fixed_Asm_8:
6933 case ARM::VST3LNdWB_fixed_Asm_16:
6934 case ARM::VST3LNdWB_fixed_Asm_32:
6935 case ARM::VST3LNqWB_fixed_Asm_16:
6936 case ARM::VST3LNqWB_fixed_Asm_32: {
6937 MCInst TmpInst;
6938 // Shuffle the operands around so the lane index operand is in the
6939 // right place.
6940 unsigned Spacing;
6941 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6942 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6943 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6944 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6945 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6946 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6947 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6948 Spacing));
6949 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6950 Spacing * 2));
6951 TmpInst.addOperand(Inst.getOperand(1)); // lane
6952 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6953 TmpInst.addOperand(Inst.getOperand(5));
6954 Inst = TmpInst;
6955 return true;
6956 }
6957
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006958 case ARM::VST4LNdWB_fixed_Asm_8:
6959 case ARM::VST4LNdWB_fixed_Asm_16:
6960 case ARM::VST4LNdWB_fixed_Asm_32:
6961 case ARM::VST4LNqWB_fixed_Asm_16:
6962 case ARM::VST4LNqWB_fixed_Asm_32: {
6963 MCInst TmpInst;
6964 // Shuffle the operands around so the lane index operand is in the
6965 // right place.
6966 unsigned Spacing;
6967 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6968 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6969 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6970 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6971 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6972 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6973 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6974 Spacing));
6975 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6976 Spacing * 2));
6977 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6978 Spacing * 3));
6979 TmpInst.addOperand(Inst.getOperand(1)); // lane
6980 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6981 TmpInst.addOperand(Inst.getOperand(5));
6982 Inst = TmpInst;
6983 return true;
6984 }
6985
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006986 case ARM::VST1LNdAsm_8:
6987 case ARM::VST1LNdAsm_16:
6988 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006989 MCInst TmpInst;
6990 // Shuffle the operands around so the lane index operand is in the
6991 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006992 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006993 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006994 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6995 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6996 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6997 TmpInst.addOperand(Inst.getOperand(1)); // lane
6998 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6999 TmpInst.addOperand(Inst.getOperand(5));
7000 Inst = TmpInst;
7001 return true;
7002 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007003
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007004 case ARM::VST2LNdAsm_8:
7005 case ARM::VST2LNdAsm_16:
7006 case ARM::VST2LNdAsm_32:
7007 case ARM::VST2LNqAsm_16:
7008 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007009 MCInst TmpInst;
7010 // Shuffle the operands around so the lane index operand is in the
7011 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00007012 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007013 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007014 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7015 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7016 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00007017 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7018 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007019 TmpInst.addOperand(Inst.getOperand(1)); // lane
7020 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7021 TmpInst.addOperand(Inst.getOperand(5));
7022 Inst = TmpInst;
7023 return true;
7024 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00007025
7026 case ARM::VST3LNdAsm_8:
7027 case ARM::VST3LNdAsm_16:
7028 case ARM::VST3LNdAsm_32:
7029 case ARM::VST3LNqAsm_16:
7030 case ARM::VST3LNqAsm_32: {
7031 MCInst TmpInst;
7032 // Shuffle the operands around so the lane index operand is in the
7033 // right place.
7034 unsigned Spacing;
7035 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7036 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7037 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7038 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7039 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7040 Spacing));
7041 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7042 Spacing * 2));
7043 TmpInst.addOperand(Inst.getOperand(1)); // lane
7044 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7045 TmpInst.addOperand(Inst.getOperand(5));
7046 Inst = TmpInst;
7047 return true;
7048 }
7049
Jim Grosbach8e2722c2012-01-24 18:53:13 +00007050 case ARM::VST4LNdAsm_8:
7051 case ARM::VST4LNdAsm_16:
7052 case ARM::VST4LNdAsm_32:
7053 case ARM::VST4LNqAsm_16:
7054 case ARM::VST4LNqAsm_32: {
7055 MCInst TmpInst;
7056 // Shuffle the operands around so the lane index operand is in the
7057 // right place.
7058 unsigned Spacing;
7059 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7060 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7061 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7062 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7063 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7064 Spacing));
7065 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7066 Spacing * 2));
7067 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7068 Spacing * 3));
7069 TmpInst.addOperand(Inst.getOperand(1)); // lane
7070 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7071 TmpInst.addOperand(Inst.getOperand(5));
7072 Inst = TmpInst;
7073 return true;
7074 }
7075
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007076 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007077 case ARM::VLD1LNdWB_register_Asm_8:
7078 case ARM::VLD1LNdWB_register_Asm_16:
7079 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00007080 MCInst TmpInst;
7081 // Shuffle the operands around so the lane index operand is in the
7082 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007083 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007084 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00007085 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7086 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7087 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7088 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7089 TmpInst.addOperand(Inst.getOperand(4)); // Rm
7090 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7091 TmpInst.addOperand(Inst.getOperand(1)); // lane
7092 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
7093 TmpInst.addOperand(Inst.getOperand(6));
7094 Inst = TmpInst;
7095 return true;
7096 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007097
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007098 case ARM::VLD2LNdWB_register_Asm_8:
7099 case ARM::VLD2LNdWB_register_Asm_16:
7100 case ARM::VLD2LNdWB_register_Asm_32:
7101 case ARM::VLD2LNqWB_register_Asm_16:
7102 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007103 MCInst TmpInst;
7104 // Shuffle the operands around so the lane index operand is in the
7105 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007106 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007107 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007108 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007109 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7110 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007111 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7112 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7113 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7114 TmpInst.addOperand(Inst.getOperand(4)); // Rm
7115 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007116 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7117 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007118 TmpInst.addOperand(Inst.getOperand(1)); // lane
7119 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
7120 TmpInst.addOperand(Inst.getOperand(6));
7121 Inst = TmpInst;
7122 return true;
7123 }
7124
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007125 case ARM::VLD3LNdWB_register_Asm_8:
7126 case ARM::VLD3LNdWB_register_Asm_16:
7127 case ARM::VLD3LNdWB_register_Asm_32:
7128 case ARM::VLD3LNqWB_register_Asm_16:
7129 case ARM::VLD3LNqWB_register_Asm_32: {
7130 MCInst TmpInst;
7131 // Shuffle the operands around so the lane index operand is in the
7132 // right place.
7133 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007134 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007135 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7136 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7137 Spacing));
7138 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007139 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007140 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7141 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7142 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7143 TmpInst.addOperand(Inst.getOperand(4)); // Rm
7144 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7145 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7146 Spacing));
7147 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007148 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007149 TmpInst.addOperand(Inst.getOperand(1)); // lane
7150 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
7151 TmpInst.addOperand(Inst.getOperand(6));
7152 Inst = TmpInst;
7153 return true;
7154 }
7155
Jim Grosbach14952a02012-01-24 18:37:25 +00007156 case ARM::VLD4LNdWB_register_Asm_8:
7157 case ARM::VLD4LNdWB_register_Asm_16:
7158 case ARM::VLD4LNdWB_register_Asm_32:
7159 case ARM::VLD4LNqWB_register_Asm_16:
7160 case ARM::VLD4LNqWB_register_Asm_32: {
7161 MCInst TmpInst;
7162 // Shuffle the operands around so the lane index operand is in the
7163 // right place.
7164 unsigned Spacing;
7165 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7166 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7167 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7168 Spacing));
7169 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7170 Spacing * 2));
7171 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7172 Spacing * 3));
7173 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7174 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7175 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7176 TmpInst.addOperand(Inst.getOperand(4)); // Rm
7177 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7178 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7179 Spacing));
7180 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7181 Spacing * 2));
7182 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7183 Spacing * 3));
7184 TmpInst.addOperand(Inst.getOperand(1)); // lane
7185 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
7186 TmpInst.addOperand(Inst.getOperand(6));
7187 Inst = TmpInst;
7188 return true;
7189 }
7190
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007191 case ARM::VLD1LNdWB_fixed_Asm_8:
7192 case ARM::VLD1LNdWB_fixed_Asm_16:
7193 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00007194 MCInst TmpInst;
7195 // Shuffle the operands around so the lane index operand is in the
7196 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007197 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007198 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00007199 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7200 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7201 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7202 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7203 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7204 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7205 TmpInst.addOperand(Inst.getOperand(1)); // lane
7206 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7207 TmpInst.addOperand(Inst.getOperand(5));
7208 Inst = TmpInst;
7209 return true;
7210 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007211
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007212 case ARM::VLD2LNdWB_fixed_Asm_8:
7213 case ARM::VLD2LNdWB_fixed_Asm_16:
7214 case ARM::VLD2LNdWB_fixed_Asm_32:
7215 case ARM::VLD2LNqWB_fixed_Asm_16:
7216 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007217 MCInst TmpInst;
7218 // Shuffle the operands around so the lane index operand is in the
7219 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007220 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007221 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007222 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007223 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7224 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007225 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7226 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7227 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7228 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7229 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007230 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7231 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007232 TmpInst.addOperand(Inst.getOperand(1)); // lane
7233 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7234 TmpInst.addOperand(Inst.getOperand(5));
7235 Inst = TmpInst;
7236 return true;
7237 }
7238
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007239 case ARM::VLD3LNdWB_fixed_Asm_8:
7240 case ARM::VLD3LNdWB_fixed_Asm_16:
7241 case ARM::VLD3LNdWB_fixed_Asm_32:
7242 case ARM::VLD3LNqWB_fixed_Asm_16:
7243 case ARM::VLD3LNqWB_fixed_Asm_32: {
7244 MCInst TmpInst;
7245 // Shuffle the operands around so the lane index operand is in the
7246 // right place.
7247 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007248 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007249 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7250 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7251 Spacing));
7252 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007253 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007254 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7255 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7256 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7257 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7258 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7259 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7260 Spacing));
7261 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007262 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007263 TmpInst.addOperand(Inst.getOperand(1)); // lane
7264 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7265 TmpInst.addOperand(Inst.getOperand(5));
7266 Inst = TmpInst;
7267 return true;
7268 }
7269
Jim Grosbach14952a02012-01-24 18:37:25 +00007270 case ARM::VLD4LNdWB_fixed_Asm_8:
7271 case ARM::VLD4LNdWB_fixed_Asm_16:
7272 case ARM::VLD4LNdWB_fixed_Asm_32:
7273 case ARM::VLD4LNqWB_fixed_Asm_16:
7274 case ARM::VLD4LNqWB_fixed_Asm_32: {
7275 MCInst TmpInst;
7276 // Shuffle the operands around so the lane index operand is in the
7277 // right place.
7278 unsigned Spacing;
7279 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7280 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7281 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7282 Spacing));
7283 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7284 Spacing * 2));
7285 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7286 Spacing * 3));
7287 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7288 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7289 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7290 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7291 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7292 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7293 Spacing));
7294 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7295 Spacing * 2));
7296 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7297 Spacing * 3));
7298 TmpInst.addOperand(Inst.getOperand(1)); // lane
7299 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7300 TmpInst.addOperand(Inst.getOperand(5));
7301 Inst = TmpInst;
7302 return true;
7303 }
7304
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007305 case ARM::VLD1LNdAsm_8:
7306 case ARM::VLD1LNdAsm_16:
7307 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00007308 MCInst TmpInst;
7309 // Shuffle the operands around so the lane index operand is in the
7310 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007311 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007312 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00007313 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7314 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7315 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7316 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7317 TmpInst.addOperand(Inst.getOperand(1)); // lane
7318 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7319 TmpInst.addOperand(Inst.getOperand(5));
7320 Inst = TmpInst;
7321 return true;
7322 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007323
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007324 case ARM::VLD2LNdAsm_8:
7325 case ARM::VLD2LNdAsm_16:
7326 case ARM::VLD2LNdAsm_32:
7327 case ARM::VLD2LNqAsm_16:
7328 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007329 MCInst TmpInst;
7330 // Shuffle the operands around so the lane index operand is in the
7331 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007332 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007333 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007334 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007335 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7336 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007337 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7338 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7339 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007340 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7341 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007342 TmpInst.addOperand(Inst.getOperand(1)); // lane
7343 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7344 TmpInst.addOperand(Inst.getOperand(5));
7345 Inst = TmpInst;
7346 return true;
7347 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007348
7349 case ARM::VLD3LNdAsm_8:
7350 case ARM::VLD3LNdAsm_16:
7351 case ARM::VLD3LNdAsm_32:
7352 case ARM::VLD3LNqAsm_16:
7353 case ARM::VLD3LNqAsm_32: {
7354 MCInst TmpInst;
7355 // Shuffle the operands around so the lane index operand is in the
7356 // right place.
7357 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007358 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007359 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7360 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7361 Spacing));
7362 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007363 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007364 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7365 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7366 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7367 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7368 Spacing));
7369 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007370 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007371 TmpInst.addOperand(Inst.getOperand(1)); // lane
7372 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7373 TmpInst.addOperand(Inst.getOperand(5));
7374 Inst = TmpInst;
7375 return true;
7376 }
7377
Jim Grosbach14952a02012-01-24 18:37:25 +00007378 case ARM::VLD4LNdAsm_8:
7379 case ARM::VLD4LNdAsm_16:
7380 case ARM::VLD4LNdAsm_32:
7381 case ARM::VLD4LNqAsm_16:
7382 case ARM::VLD4LNqAsm_32: {
7383 MCInst TmpInst;
7384 // Shuffle the operands around so the lane index operand is in the
7385 // right place.
7386 unsigned Spacing;
7387 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7388 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7389 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7390 Spacing));
7391 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7392 Spacing * 2));
7393 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7394 Spacing * 3));
7395 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7396 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7397 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7398 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7399 Spacing));
7400 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7401 Spacing * 2));
7402 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7403 Spacing * 3));
7404 TmpInst.addOperand(Inst.getOperand(1)); // lane
7405 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7406 TmpInst.addOperand(Inst.getOperand(5));
7407 Inst = TmpInst;
7408 return true;
7409 }
7410
Jim Grosbachb78403c2012-01-24 23:47:04 +00007411 // VLD3DUP single 3-element structure to all lanes instructions.
7412 case ARM::VLD3DUPdAsm_8:
7413 case ARM::VLD3DUPdAsm_16:
7414 case ARM::VLD3DUPdAsm_32:
7415 case ARM::VLD3DUPqAsm_8:
7416 case ARM::VLD3DUPqAsm_16:
7417 case ARM::VLD3DUPqAsm_32: {
7418 MCInst TmpInst;
7419 unsigned Spacing;
7420 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7421 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7422 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7423 Spacing));
7424 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7425 Spacing * 2));
7426 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7427 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7428 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7429 TmpInst.addOperand(Inst.getOperand(4));
7430 Inst = TmpInst;
7431 return true;
7432 }
7433
7434 case ARM::VLD3DUPdWB_fixed_Asm_8:
7435 case ARM::VLD3DUPdWB_fixed_Asm_16:
7436 case ARM::VLD3DUPdWB_fixed_Asm_32:
7437 case ARM::VLD3DUPqWB_fixed_Asm_8:
7438 case ARM::VLD3DUPqWB_fixed_Asm_16:
7439 case ARM::VLD3DUPqWB_fixed_Asm_32: {
7440 MCInst TmpInst;
7441 unsigned Spacing;
7442 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7443 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7444 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7445 Spacing));
7446 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7447 Spacing * 2));
7448 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7449 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7450 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7451 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7452 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7453 TmpInst.addOperand(Inst.getOperand(4));
7454 Inst = TmpInst;
7455 return true;
7456 }
7457
7458 case ARM::VLD3DUPdWB_register_Asm_8:
7459 case ARM::VLD3DUPdWB_register_Asm_16:
7460 case ARM::VLD3DUPdWB_register_Asm_32:
7461 case ARM::VLD3DUPqWB_register_Asm_8:
7462 case ARM::VLD3DUPqWB_register_Asm_16:
7463 case ARM::VLD3DUPqWB_register_Asm_32: {
7464 MCInst TmpInst;
7465 unsigned Spacing;
7466 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7467 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7468 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7469 Spacing));
7470 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7471 Spacing * 2));
7472 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7473 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7474 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7475 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7476 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7477 TmpInst.addOperand(Inst.getOperand(5));
7478 Inst = TmpInst;
7479 return true;
7480 }
7481
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007482 // VLD3 multiple 3-element structure instructions.
7483 case ARM::VLD3dAsm_8:
7484 case ARM::VLD3dAsm_16:
7485 case ARM::VLD3dAsm_32:
7486 case ARM::VLD3qAsm_8:
7487 case ARM::VLD3qAsm_16:
7488 case ARM::VLD3qAsm_32: {
7489 MCInst TmpInst;
7490 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007491 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007492 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7493 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7494 Spacing));
7495 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7496 Spacing * 2));
7497 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7498 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7499 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7500 TmpInst.addOperand(Inst.getOperand(4));
7501 Inst = TmpInst;
7502 return true;
7503 }
7504
7505 case ARM::VLD3dWB_fixed_Asm_8:
7506 case ARM::VLD3dWB_fixed_Asm_16:
7507 case ARM::VLD3dWB_fixed_Asm_32:
7508 case ARM::VLD3qWB_fixed_Asm_8:
7509 case ARM::VLD3qWB_fixed_Asm_16:
7510 case ARM::VLD3qWB_fixed_Asm_32: {
7511 MCInst TmpInst;
7512 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007513 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007514 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7515 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7516 Spacing));
7517 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7518 Spacing * 2));
7519 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7520 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7521 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7522 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7523 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7524 TmpInst.addOperand(Inst.getOperand(4));
7525 Inst = TmpInst;
7526 return true;
7527 }
7528
7529 case ARM::VLD3dWB_register_Asm_8:
7530 case ARM::VLD3dWB_register_Asm_16:
7531 case ARM::VLD3dWB_register_Asm_32:
7532 case ARM::VLD3qWB_register_Asm_8:
7533 case ARM::VLD3qWB_register_Asm_16:
7534 case ARM::VLD3qWB_register_Asm_32: {
7535 MCInst TmpInst;
7536 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007537 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007538 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7539 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7540 Spacing));
7541 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7542 Spacing * 2));
7543 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7544 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7545 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7546 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7547 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7548 TmpInst.addOperand(Inst.getOperand(5));
7549 Inst = TmpInst;
7550 return true;
7551 }
7552
Jim Grosbach086cbfa2012-01-25 00:01:08 +00007553 // VLD4DUP single 3-element structure to all lanes instructions.
7554 case ARM::VLD4DUPdAsm_8:
7555 case ARM::VLD4DUPdAsm_16:
7556 case ARM::VLD4DUPdAsm_32:
7557 case ARM::VLD4DUPqAsm_8:
7558 case ARM::VLD4DUPqAsm_16:
7559 case ARM::VLD4DUPqAsm_32: {
7560 MCInst TmpInst;
7561 unsigned Spacing;
7562 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7563 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7564 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7565 Spacing));
7566 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7567 Spacing * 2));
7568 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7569 Spacing * 3));
7570 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7571 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7572 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7573 TmpInst.addOperand(Inst.getOperand(4));
7574 Inst = TmpInst;
7575 return true;
7576 }
7577
7578 case ARM::VLD4DUPdWB_fixed_Asm_8:
7579 case ARM::VLD4DUPdWB_fixed_Asm_16:
7580 case ARM::VLD4DUPdWB_fixed_Asm_32:
7581 case ARM::VLD4DUPqWB_fixed_Asm_8:
7582 case ARM::VLD4DUPqWB_fixed_Asm_16:
7583 case ARM::VLD4DUPqWB_fixed_Asm_32: {
7584 MCInst TmpInst;
7585 unsigned Spacing;
7586 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7587 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7588 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7589 Spacing));
7590 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7591 Spacing * 2));
7592 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7593 Spacing * 3));
7594 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7595 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7596 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7597 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7598 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7599 TmpInst.addOperand(Inst.getOperand(4));
7600 Inst = TmpInst;
7601 return true;
7602 }
7603
7604 case ARM::VLD4DUPdWB_register_Asm_8:
7605 case ARM::VLD4DUPdWB_register_Asm_16:
7606 case ARM::VLD4DUPdWB_register_Asm_32:
7607 case ARM::VLD4DUPqWB_register_Asm_8:
7608 case ARM::VLD4DUPqWB_register_Asm_16:
7609 case ARM::VLD4DUPqWB_register_Asm_32: {
7610 MCInst TmpInst;
7611 unsigned Spacing;
7612 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7613 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7614 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7615 Spacing));
7616 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7617 Spacing * 2));
7618 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7619 Spacing * 3));
7620 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7621 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7622 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7623 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7624 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7625 TmpInst.addOperand(Inst.getOperand(5));
7626 Inst = TmpInst;
7627 return true;
7628 }
7629
7630 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00007631 case ARM::VLD4dAsm_8:
7632 case ARM::VLD4dAsm_16:
7633 case ARM::VLD4dAsm_32:
7634 case ARM::VLD4qAsm_8:
7635 case ARM::VLD4qAsm_16:
7636 case ARM::VLD4qAsm_32: {
7637 MCInst TmpInst;
7638 unsigned Spacing;
7639 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7640 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7641 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7642 Spacing));
7643 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7644 Spacing * 2));
7645 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7646 Spacing * 3));
7647 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7648 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7649 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7650 TmpInst.addOperand(Inst.getOperand(4));
7651 Inst = TmpInst;
7652 return true;
7653 }
7654
7655 case ARM::VLD4dWB_fixed_Asm_8:
7656 case ARM::VLD4dWB_fixed_Asm_16:
7657 case ARM::VLD4dWB_fixed_Asm_32:
7658 case ARM::VLD4qWB_fixed_Asm_8:
7659 case ARM::VLD4qWB_fixed_Asm_16:
7660 case ARM::VLD4qWB_fixed_Asm_32: {
7661 MCInst TmpInst;
7662 unsigned Spacing;
7663 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7664 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7665 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7666 Spacing));
7667 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7668 Spacing * 2));
7669 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7670 Spacing * 3));
7671 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7672 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7673 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7674 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7675 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7676 TmpInst.addOperand(Inst.getOperand(4));
7677 Inst = TmpInst;
7678 return true;
7679 }
7680
7681 case ARM::VLD4dWB_register_Asm_8:
7682 case ARM::VLD4dWB_register_Asm_16:
7683 case ARM::VLD4dWB_register_Asm_32:
7684 case ARM::VLD4qWB_register_Asm_8:
7685 case ARM::VLD4qWB_register_Asm_16:
7686 case ARM::VLD4qWB_register_Asm_32: {
7687 MCInst TmpInst;
7688 unsigned Spacing;
7689 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7690 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7691 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7692 Spacing));
7693 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7694 Spacing * 2));
7695 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7696 Spacing * 3));
7697 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7698 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7699 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7700 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7701 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7702 TmpInst.addOperand(Inst.getOperand(5));
7703 Inst = TmpInst;
7704 return true;
7705 }
7706
Jim Grosbach1a747242012-01-23 23:45:44 +00007707 // VST3 multiple 3-element structure instructions.
7708 case ARM::VST3dAsm_8:
7709 case ARM::VST3dAsm_16:
7710 case ARM::VST3dAsm_32:
7711 case ARM::VST3qAsm_8:
7712 case ARM::VST3qAsm_16:
7713 case ARM::VST3qAsm_32: {
7714 MCInst TmpInst;
7715 unsigned Spacing;
7716 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7717 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7718 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7719 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7720 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7721 Spacing));
7722 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7723 Spacing * 2));
7724 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7725 TmpInst.addOperand(Inst.getOperand(4));
7726 Inst = TmpInst;
7727 return true;
7728 }
7729
7730 case ARM::VST3dWB_fixed_Asm_8:
7731 case ARM::VST3dWB_fixed_Asm_16:
7732 case ARM::VST3dWB_fixed_Asm_32:
7733 case ARM::VST3qWB_fixed_Asm_8:
7734 case ARM::VST3qWB_fixed_Asm_16:
7735 case ARM::VST3qWB_fixed_Asm_32: {
7736 MCInst TmpInst;
7737 unsigned Spacing;
7738 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7739 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7740 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7741 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7742 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7743 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7744 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7745 Spacing));
7746 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7747 Spacing * 2));
7748 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7749 TmpInst.addOperand(Inst.getOperand(4));
7750 Inst = TmpInst;
7751 return true;
7752 }
7753
7754 case ARM::VST3dWB_register_Asm_8:
7755 case ARM::VST3dWB_register_Asm_16:
7756 case ARM::VST3dWB_register_Asm_32:
7757 case ARM::VST3qWB_register_Asm_8:
7758 case ARM::VST3qWB_register_Asm_16:
7759 case ARM::VST3qWB_register_Asm_32: {
7760 MCInst TmpInst;
7761 unsigned Spacing;
7762 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7763 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7764 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7765 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7766 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7767 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7768 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7769 Spacing));
7770 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7771 Spacing * 2));
7772 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7773 TmpInst.addOperand(Inst.getOperand(5));
7774 Inst = TmpInst;
7775 return true;
7776 }
7777
Jim Grosbachda70eac2012-01-24 00:58:13 +00007778 // VST4 multiple 3-element structure instructions.
7779 case ARM::VST4dAsm_8:
7780 case ARM::VST4dAsm_16:
7781 case ARM::VST4dAsm_32:
7782 case ARM::VST4qAsm_8:
7783 case ARM::VST4qAsm_16:
7784 case ARM::VST4qAsm_32: {
7785 MCInst TmpInst;
7786 unsigned Spacing;
7787 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7788 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7789 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7790 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7791 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7792 Spacing));
7793 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7794 Spacing * 2));
7795 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7796 Spacing * 3));
7797 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7798 TmpInst.addOperand(Inst.getOperand(4));
7799 Inst = TmpInst;
7800 return true;
7801 }
7802
7803 case ARM::VST4dWB_fixed_Asm_8:
7804 case ARM::VST4dWB_fixed_Asm_16:
7805 case ARM::VST4dWB_fixed_Asm_32:
7806 case ARM::VST4qWB_fixed_Asm_8:
7807 case ARM::VST4qWB_fixed_Asm_16:
7808 case ARM::VST4qWB_fixed_Asm_32: {
7809 MCInst TmpInst;
7810 unsigned Spacing;
7811 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7812 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7813 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7814 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7815 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7816 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7817 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7818 Spacing));
7819 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7820 Spacing * 2));
7821 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7822 Spacing * 3));
7823 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7824 TmpInst.addOperand(Inst.getOperand(4));
7825 Inst = TmpInst;
7826 return true;
7827 }
7828
7829 case ARM::VST4dWB_register_Asm_8:
7830 case ARM::VST4dWB_register_Asm_16:
7831 case ARM::VST4dWB_register_Asm_32:
7832 case ARM::VST4qWB_register_Asm_8:
7833 case ARM::VST4qWB_register_Asm_16:
7834 case ARM::VST4qWB_register_Asm_32: {
7835 MCInst TmpInst;
7836 unsigned Spacing;
7837 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7838 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7839 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7840 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7841 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7842 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7843 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7844 Spacing));
7845 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7846 Spacing * 2));
7847 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7848 Spacing * 3));
7849 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7850 TmpInst.addOperand(Inst.getOperand(5));
7851 Inst = TmpInst;
7852 return true;
7853 }
7854
Jim Grosbachad66de12012-04-11 00:15:16 +00007855 // Handle encoding choice for the shift-immediate instructions.
7856 case ARM::t2LSLri:
7857 case ARM::t2LSRri:
7858 case ARM::t2ASRri: {
7859 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7860 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7861 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
David Blaikie960ea3f2014-06-08 16:18:35 +00007862 !(static_cast<ARMOperand &>(*Operands[3]).isToken() &&
7863 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w")) {
Jim Grosbachad66de12012-04-11 00:15:16 +00007864 unsigned NewOpc;
7865 switch (Inst.getOpcode()) {
7866 default: llvm_unreachable("unexpected opcode");
7867 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
7868 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
7869 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
7870 }
7871 // The Thumb1 operands aren't in the same order. Awesome, eh?
7872 MCInst TmpInst;
7873 TmpInst.setOpcode(NewOpc);
7874 TmpInst.addOperand(Inst.getOperand(0));
7875 TmpInst.addOperand(Inst.getOperand(5));
7876 TmpInst.addOperand(Inst.getOperand(1));
7877 TmpInst.addOperand(Inst.getOperand(2));
7878 TmpInst.addOperand(Inst.getOperand(3));
7879 TmpInst.addOperand(Inst.getOperand(4));
7880 Inst = TmpInst;
7881 return true;
7882 }
7883 return false;
7884 }
7885
Jim Grosbach485e5622011-12-13 22:45:11 +00007886 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00007887 case ARM::t2MOVsr:
7888 case ARM::t2MOVSsr: {
7889 // Which instruction to expand to depends on the CCOut operand and
7890 // whether we're in an IT block if the register operands are low
7891 // registers.
7892 bool isNarrow = false;
7893 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7894 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7895 isARMLowRegister(Inst.getOperand(2).getReg()) &&
7896 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7897 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
7898 isNarrow = true;
7899 MCInst TmpInst;
7900 unsigned newOpc;
7901 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
7902 default: llvm_unreachable("unexpected opcode!");
7903 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
7904 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
7905 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
7906 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
7907 }
7908 TmpInst.setOpcode(newOpc);
7909 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7910 if (isNarrow)
7911 TmpInst.addOperand(MCOperand::CreateReg(
7912 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7913 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7914 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7915 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7916 TmpInst.addOperand(Inst.getOperand(5));
7917 if (!isNarrow)
7918 TmpInst.addOperand(MCOperand::CreateReg(
7919 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7920 Inst = TmpInst;
7921 return true;
7922 }
Jim Grosbach485e5622011-12-13 22:45:11 +00007923 case ARM::t2MOVsi:
7924 case ARM::t2MOVSsi: {
7925 // Which instruction to expand to depends on the CCOut operand and
7926 // whether we're in an IT block if the register operands are low
7927 // registers.
7928 bool isNarrow = false;
7929 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7930 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7931 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
7932 isNarrow = true;
7933 MCInst TmpInst;
7934 unsigned newOpc;
7935 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
7936 default: llvm_unreachable("unexpected opcode!");
7937 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
7938 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
7939 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
7940 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007941 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00007942 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00007943 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
7944 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00007945 TmpInst.setOpcode(newOpc);
7946 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7947 if (isNarrow)
7948 TmpInst.addOperand(MCOperand::CreateReg(
7949 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7950 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007951 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00007952 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00007953 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7954 TmpInst.addOperand(Inst.getOperand(4));
7955 if (!isNarrow)
7956 TmpInst.addOperand(MCOperand::CreateReg(
7957 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7958 Inst = TmpInst;
7959 return true;
7960 }
7961 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00007962 case ARM::ASRr:
7963 case ARM::LSRr:
7964 case ARM::LSLr:
7965 case ARM::RORr: {
7966 ARM_AM::ShiftOpc ShiftTy;
7967 switch(Inst.getOpcode()) {
7968 default: llvm_unreachable("unexpected opcode!");
7969 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7970 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7971 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7972 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7973 }
Jim Grosbachabcac562011-11-16 18:31:45 +00007974 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7975 MCInst TmpInst;
7976 TmpInst.setOpcode(ARM::MOVsr);
7977 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7978 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7979 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7980 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7981 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7982 TmpInst.addOperand(Inst.getOperand(4));
7983 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7984 Inst = TmpInst;
7985 return true;
7986 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00007987 case ARM::ASRi:
7988 case ARM::LSRi:
7989 case ARM::LSLi:
7990 case ARM::RORi: {
7991 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007992 switch(Inst.getOpcode()) {
7993 default: llvm_unreachable("unexpected opcode!");
7994 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7995 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7996 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7997 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7998 }
7999 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00008000 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00008001 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00008002 // A shift by 32 should be encoded as 0 when permitted
8003 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
8004 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00008005 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00008006 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00008007 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00008008 TmpInst.addOperand(Inst.getOperand(0)); // Rd
8009 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00008010 if (Opc == ARM::MOVsi)
8011 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00008012 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
8013 TmpInst.addOperand(Inst.getOperand(4));
8014 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
8015 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00008016 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00008017 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00008018 case ARM::RRXi: {
8019 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
8020 MCInst TmpInst;
8021 TmpInst.setOpcode(ARM::MOVsi);
8022 TmpInst.addOperand(Inst.getOperand(0)); // Rd
8023 TmpInst.addOperand(Inst.getOperand(1)); // Rn
8024 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
8025 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
8026 TmpInst.addOperand(Inst.getOperand(3));
8027 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
8028 Inst = TmpInst;
8029 return true;
8030 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00008031 case ARM::t2LDMIA_UPD: {
8032 // If this is a load of a single register, then we should use
8033 // a post-indexed LDR instruction instead, per the ARM ARM.
8034 if (Inst.getNumOperands() != 5)
8035 return false;
8036 MCInst TmpInst;
8037 TmpInst.setOpcode(ARM::t2LDR_POST);
8038 TmpInst.addOperand(Inst.getOperand(4)); // Rt
8039 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
8040 TmpInst.addOperand(Inst.getOperand(1)); // Rn
8041 TmpInst.addOperand(MCOperand::CreateImm(4));
8042 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
8043 TmpInst.addOperand(Inst.getOperand(3));
8044 Inst = TmpInst;
8045 return true;
8046 }
8047 case ARM::t2STMDB_UPD: {
8048 // If this is a store of a single register, then we should use
8049 // a pre-indexed STR instruction instead, per the ARM ARM.
8050 if (Inst.getNumOperands() != 5)
8051 return false;
8052 MCInst TmpInst;
8053 TmpInst.setOpcode(ARM::t2STR_PRE);
8054 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
8055 TmpInst.addOperand(Inst.getOperand(4)); // Rt
8056 TmpInst.addOperand(Inst.getOperand(1)); // Rn
8057 TmpInst.addOperand(MCOperand::CreateImm(-4));
8058 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
8059 TmpInst.addOperand(Inst.getOperand(3));
8060 Inst = TmpInst;
8061 return true;
8062 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008063 case ARM::LDMIA_UPD:
8064 // If this is a load of a single register via a 'pop', then we should use
8065 // a post-indexed LDR instruction instead, per the ARM ARM.
David Blaikie960ea3f2014-06-08 16:18:35 +00008066 if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "pop" &&
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008067 Inst.getNumOperands() == 5) {
8068 MCInst TmpInst;
8069 TmpInst.setOpcode(ARM::LDR_POST_IMM);
8070 TmpInst.addOperand(Inst.getOperand(4)); // Rt
8071 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
8072 TmpInst.addOperand(Inst.getOperand(1)); // Rn
8073 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
8074 TmpInst.addOperand(MCOperand::CreateImm(4));
8075 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
8076 TmpInst.addOperand(Inst.getOperand(3));
8077 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00008078 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008079 }
8080 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00008081 case ARM::STMDB_UPD:
8082 // If this is a store of a single register via a 'push', then we should use
8083 // a pre-indexed STR instruction instead, per the ARM ARM.
David Blaikie960ea3f2014-06-08 16:18:35 +00008084 if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "push" &&
Jim Grosbach27ad83d2011-08-11 18:07:11 +00008085 Inst.getNumOperands() == 5) {
8086 MCInst TmpInst;
8087 TmpInst.setOpcode(ARM::STR_PRE_IMM);
8088 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
8089 TmpInst.addOperand(Inst.getOperand(4)); // Rt
8090 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
8091 TmpInst.addOperand(MCOperand::CreateImm(-4));
8092 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
8093 TmpInst.addOperand(Inst.getOperand(3));
8094 Inst = TmpInst;
8095 }
8096 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00008097 case ARM::t2ADDri12:
8098 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
8099 // mnemonic was used (not "addw"), encoding T3 is preferred.
David Blaikie960ea3f2014-06-08 16:18:35 +00008100 if (static_cast<ARMOperand &>(*Operands[0]).getToken() != "add" ||
Jim Grosbachec9ba982011-12-05 21:06:26 +00008101 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
8102 break;
8103 Inst.setOpcode(ARM::t2ADDri);
8104 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
8105 break;
8106 case ARM::t2SUBri12:
8107 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
8108 // mnemonic was used (not "subw"), encoding T3 is preferred.
David Blaikie960ea3f2014-06-08 16:18:35 +00008109 if (static_cast<ARMOperand &>(*Operands[0]).getToken() != "sub" ||
Jim Grosbachec9ba982011-12-05 21:06:26 +00008110 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
8111 break;
8112 Inst.setOpcode(ARM::t2SUBri);
8113 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
8114 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00008115 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00008116 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00008117 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
8118 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
8119 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00008120 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00008121 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00008122 return true;
8123 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00008124 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00008125 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00008126 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00008127 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
8128 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
8129 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00008130 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00008131 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00008132 return true;
8133 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00008134 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00008135 case ARM::t2ADDri:
8136 case ARM::t2SUBri: {
8137 // If the destination and first source operand are the same, and
8138 // the flags are compatible with the current IT status, use encoding T2
8139 // instead of T3. For compatibility with the system 'as'. Make sure the
8140 // wide encoding wasn't explicit.
8141 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00008142 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00008143 (unsigned)Inst.getOperand(2).getImm() > 255 ||
8144 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
David Blaikie960ea3f2014-06-08 16:18:35 +00008145 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
8146 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
8147 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w"))
Jim Grosbachdef5e342012-03-30 17:20:40 +00008148 break;
8149 MCInst TmpInst;
8150 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
8151 ARM::tADDi8 : ARM::tSUBi8);
8152 TmpInst.addOperand(Inst.getOperand(0));
8153 TmpInst.addOperand(Inst.getOperand(5));
8154 TmpInst.addOperand(Inst.getOperand(0));
8155 TmpInst.addOperand(Inst.getOperand(2));
8156 TmpInst.addOperand(Inst.getOperand(3));
8157 TmpInst.addOperand(Inst.getOperand(4));
8158 Inst = TmpInst;
8159 return true;
8160 }
Jim Grosbache489bab2011-12-05 22:16:39 +00008161 case ARM::t2ADDrr: {
8162 // If the destination and first source operand are the same, and
8163 // there's no setting of the flags, use encoding T2 instead of T3.
8164 // Note that this is only for ADD, not SUB. This mirrors the system
8165 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
8166 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
8167 Inst.getOperand(5).getReg() != 0 ||
David Blaikie960ea3f2014-06-08 16:18:35 +00008168 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
8169 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00008170 break;
8171 MCInst TmpInst;
8172 TmpInst.setOpcode(ARM::tADDhirr);
8173 TmpInst.addOperand(Inst.getOperand(0));
8174 TmpInst.addOperand(Inst.getOperand(0));
8175 TmpInst.addOperand(Inst.getOperand(2));
8176 TmpInst.addOperand(Inst.getOperand(3));
8177 TmpInst.addOperand(Inst.getOperand(4));
8178 Inst = TmpInst;
8179 return true;
8180 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00008181 case ARM::tADDrSP: {
8182 // If the non-SP source operand and the destination operand are not the
8183 // same, we need to use the 32-bit encoding if it's available.
8184 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
8185 Inst.setOpcode(ARM::t2ADDrr);
8186 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
8187 return true;
8188 }
8189 break;
8190 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00008191 case ARM::tB:
8192 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00008193 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson29cfe6c2011-09-09 21:48:23 +00008194 Inst.setOpcode(ARM::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00008195 return true;
8196 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00008197 break;
8198 case ARM::t2B:
8199 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00008200 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00008201 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00008202 return true;
8203 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00008204 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00008205 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008206 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00008207 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00008208 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00008209 return true;
8210 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00008211 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00008212 case ARM::tBcc:
8213 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00008214 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00008215 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00008216 return true;
8217 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00008218 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00008219 case ARM::tLDMIA: {
8220 // If the register list contains any high registers, or if the writeback
8221 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
8222 // instead if we're in Thumb2. Otherwise, this should have generated
8223 // an error in validateInstruction().
8224 unsigned Rn = Inst.getOperand(0).getReg();
8225 bool hasWritebackToken =
David Blaikie960ea3f2014-06-08 16:18:35 +00008226 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
8227 static_cast<ARMOperand &>(*Operands[3]).getToken() == "!");
Jim Grosbacha31f2232011-09-07 18:05:34 +00008228 bool listContainsBase;
8229 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
8230 (!listContainsBase && !hasWritebackToken) ||
8231 (listContainsBase && hasWritebackToken)) {
8232 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
8233 assert (isThumbTwo());
8234 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
8235 // If we're switching to the updating version, we need to insert
8236 // the writeback tied operand.
8237 if (hasWritebackToken)
8238 Inst.insert(Inst.begin(),
8239 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00008240 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00008241 }
8242 break;
8243 }
Jim Grosbach099c9762011-09-16 20:50:13 +00008244 case ARM::tSTMIA_UPD: {
8245 // If the register list contains any high registers, we need to use
8246 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
8247 // should have generated an error in validateInstruction().
8248 unsigned Rn = Inst.getOperand(0).getReg();
8249 bool listContainsBase;
8250 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
8251 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
8252 assert (isThumbTwo());
8253 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00008254 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00008255 }
8256 break;
8257 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00008258 case ARM::tPOP: {
8259 bool listContainsBase;
8260 // If the register list contains any high registers, we need to use
8261 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
8262 // should have generated an error in validateInstruction().
8263 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00008264 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00008265 assert (isThumbTwo());
8266 Inst.setOpcode(ARM::t2LDMIA_UPD);
8267 // Add the base register and writeback operands.
8268 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
8269 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00008270 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00008271 }
8272 case ARM::tPUSH: {
8273 bool listContainsBase;
8274 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00008275 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00008276 assert (isThumbTwo());
8277 Inst.setOpcode(ARM::t2STMDB_UPD);
8278 // Add the base register and writeback operands.
8279 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
8280 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00008281 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00008282 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00008283 case ARM::t2MOVi: {
8284 // If we can use the 16-bit encoding and the user didn't explicitly
8285 // request the 32-bit variant, transform it here.
8286 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00008287 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00008288 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
David Blaikie960ea3f2014-06-08 16:18:35 +00008289 Inst.getOperand(4).getReg() == ARM::CPSR) ||
8290 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
8291 (!static_cast<ARMOperand &>(*Operands[2]).isToken() ||
8292 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) {
Jim Grosbachb908b7a2011-09-10 00:15:36 +00008293 // The operands aren't in the same order for tMOVi8...
8294 MCInst TmpInst;
8295 TmpInst.setOpcode(ARM::tMOVi8);
8296 TmpInst.addOperand(Inst.getOperand(0));
8297 TmpInst.addOperand(Inst.getOperand(4));
8298 TmpInst.addOperand(Inst.getOperand(1));
8299 TmpInst.addOperand(Inst.getOperand(2));
8300 TmpInst.addOperand(Inst.getOperand(3));
8301 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00008302 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00008303 }
8304 break;
8305 }
8306 case ARM::t2MOVr: {
8307 // If we can use the 16-bit encoding and the user didn't explicitly
8308 // request the 32-bit variant, transform it here.
8309 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
8310 isARMLowRegister(Inst.getOperand(1).getReg()) &&
8311 Inst.getOperand(2).getImm() == ARMCC::AL &&
8312 Inst.getOperand(4).getReg() == ARM::CPSR &&
David Blaikie960ea3f2014-06-08 16:18:35 +00008313 (!static_cast<ARMOperand &>(*Operands[2]).isToken() ||
8314 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) {
Jim Grosbachb908b7a2011-09-10 00:15:36 +00008315 // The operands aren't the same for tMOV[S]r... (no cc_out)
8316 MCInst TmpInst;
8317 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
8318 TmpInst.addOperand(Inst.getOperand(0));
8319 TmpInst.addOperand(Inst.getOperand(1));
8320 TmpInst.addOperand(Inst.getOperand(2));
8321 TmpInst.addOperand(Inst.getOperand(3));
8322 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00008323 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00008324 }
8325 break;
8326 }
Jim Grosbach82213192011-09-19 20:29:33 +00008327 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00008328 case ARM::t2SXTB:
8329 case ARM::t2UXTH:
8330 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00008331 // If we can use the 16-bit encoding and the user didn't explicitly
8332 // request the 32-bit variant, transform it here.
8333 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
8334 isARMLowRegister(Inst.getOperand(1).getReg()) &&
8335 Inst.getOperand(2).getImm() == 0 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00008336 (!static_cast<ARMOperand &>(*Operands[2]).isToken() ||
8337 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00008338 unsigned NewOpc;
8339 switch (Inst.getOpcode()) {
8340 default: llvm_unreachable("Illegal opcode!");
8341 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
8342 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
8343 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
8344 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
8345 }
Jim Grosbach82213192011-09-19 20:29:33 +00008346 // The operands aren't the same for thumb1 (no rotate operand).
8347 MCInst TmpInst;
8348 TmpInst.setOpcode(NewOpc);
8349 TmpInst.addOperand(Inst.getOperand(0));
8350 TmpInst.addOperand(Inst.getOperand(1));
8351 TmpInst.addOperand(Inst.getOperand(3));
8352 TmpInst.addOperand(Inst.getOperand(4));
8353 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00008354 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00008355 }
8356 break;
8357 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00008358 case ARM::MOVsi: {
8359 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00008360 // rrx shifts and asr/lsr of #32 is encoded as 0
8361 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
8362 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00008363 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
8364 // Shifting by zero is accepted as a vanilla 'MOVr'
8365 MCInst TmpInst;
8366 TmpInst.setOpcode(ARM::MOVr);
8367 TmpInst.addOperand(Inst.getOperand(0));
8368 TmpInst.addOperand(Inst.getOperand(1));
8369 TmpInst.addOperand(Inst.getOperand(3));
8370 TmpInst.addOperand(Inst.getOperand(4));
8371 TmpInst.addOperand(Inst.getOperand(5));
8372 Inst = TmpInst;
8373 return true;
8374 }
8375 return false;
8376 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00008377 case ARM::ANDrsi:
8378 case ARM::ORRrsi:
8379 case ARM::EORrsi:
8380 case ARM::BICrsi:
8381 case ARM::SUBrsi:
8382 case ARM::ADDrsi: {
8383 unsigned newOpc;
8384 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
8385 if (SOpc == ARM_AM::rrx) return false;
8386 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00008387 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00008388 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
8389 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
8390 case ARM::EORrsi: newOpc = ARM::EORrr; break;
8391 case ARM::BICrsi: newOpc = ARM::BICrr; break;
8392 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
8393 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
8394 }
8395 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00008396 // The exception is for right shifts, where 0 == 32
8397 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
8398 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00008399 MCInst TmpInst;
8400 TmpInst.setOpcode(newOpc);
8401 TmpInst.addOperand(Inst.getOperand(0));
8402 TmpInst.addOperand(Inst.getOperand(1));
8403 TmpInst.addOperand(Inst.getOperand(2));
8404 TmpInst.addOperand(Inst.getOperand(4));
8405 TmpInst.addOperand(Inst.getOperand(5));
8406 TmpInst.addOperand(Inst.getOperand(6));
8407 Inst = TmpInst;
8408 return true;
8409 }
8410 return false;
8411 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00008412 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008413 case ARM::t2IT: {
8414 // The mask bits for all but the first condition are represented as
8415 // the low bit of the condition code value implies 't'. We currently
8416 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00008417 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008418 MCOperand &MO = Inst.getOperand(1);
8419 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00008420 unsigned OrigMask = Mask;
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +00008421 unsigned TZ = countTrailingZeros(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008422 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008423 assert(Mask && TZ <= 3 && "illegal IT mask value!");
Benjamin Kramer8bad66e2013-05-19 22:01:57 +00008424 Mask ^= (0xE << TZ) & 0xF;
Richard Bartonf435b092012-04-27 08:42:59 +00008425 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008426 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00008427
8428 // Set up the IT block state according to the IT instruction we just
8429 // matched.
8430 assert(!inITBlock() && "nested IT blocks?!");
8431 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
8432 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
8433 ITState.CurPosition = 0;
8434 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008435 break;
8436 }
Richard Bartona39625e2012-07-09 16:12:24 +00008437 case ARM::t2LSLrr:
8438 case ARM::t2LSRrr:
8439 case ARM::t2ASRrr:
8440 case ARM::t2SBCrr:
8441 case ARM::t2RORrr:
8442 case ARM::t2BICrr:
8443 {
Richard Bartond5660372012-07-09 16:14:28 +00008444 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00008445 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
8446 isARMLowRegister(Inst.getOperand(2).getReg())) &&
8447 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00008448 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
David Blaikie960ea3f2014-06-08 16:18:35 +00008449 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
8450 (!static_cast<ARMOperand &>(*Operands[3]).isToken() ||
8451 !static_cast<ARMOperand &>(*Operands[3]).getToken().equals_lower(
8452 ".w"))) {
Richard Bartona39625e2012-07-09 16:12:24 +00008453 unsigned NewOpc;
8454 switch (Inst.getOpcode()) {
8455 default: llvm_unreachable("unexpected opcode");
8456 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
8457 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
8458 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
8459 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
8460 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
8461 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
8462 }
8463 MCInst TmpInst;
8464 TmpInst.setOpcode(NewOpc);
8465 TmpInst.addOperand(Inst.getOperand(0));
8466 TmpInst.addOperand(Inst.getOperand(5));
8467 TmpInst.addOperand(Inst.getOperand(1));
8468 TmpInst.addOperand(Inst.getOperand(2));
8469 TmpInst.addOperand(Inst.getOperand(3));
8470 TmpInst.addOperand(Inst.getOperand(4));
8471 Inst = TmpInst;
8472 return true;
8473 }
8474 return false;
8475 }
8476 case ARM::t2ANDrr:
8477 case ARM::t2EORrr:
8478 case ARM::t2ADCrr:
8479 case ARM::t2ORRrr:
8480 {
Richard Bartond5660372012-07-09 16:14:28 +00008481 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00008482 // These instructions are special in that they are commutable, so shorter encodings
8483 // are available more often.
8484 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
8485 isARMLowRegister(Inst.getOperand(2).getReg())) &&
8486 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
8487 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00008488 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
David Blaikie960ea3f2014-06-08 16:18:35 +00008489 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
8490 (!static_cast<ARMOperand &>(*Operands[3]).isToken() ||
8491 !static_cast<ARMOperand &>(*Operands[3]).getToken().equals_lower(
8492 ".w"))) {
Richard Bartona39625e2012-07-09 16:12:24 +00008493 unsigned NewOpc;
8494 switch (Inst.getOpcode()) {
8495 default: llvm_unreachable("unexpected opcode");
8496 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
8497 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
8498 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
8499 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
8500 }
8501 MCInst TmpInst;
8502 TmpInst.setOpcode(NewOpc);
8503 TmpInst.addOperand(Inst.getOperand(0));
8504 TmpInst.addOperand(Inst.getOperand(5));
8505 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
8506 TmpInst.addOperand(Inst.getOperand(1));
8507 TmpInst.addOperand(Inst.getOperand(2));
8508 } else {
8509 TmpInst.addOperand(Inst.getOperand(2));
8510 TmpInst.addOperand(Inst.getOperand(1));
8511 }
8512 TmpInst.addOperand(Inst.getOperand(3));
8513 TmpInst.addOperand(Inst.getOperand(4));
8514 Inst = TmpInst;
8515 return true;
8516 }
8517 return false;
8518 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008519 }
Jim Grosbachafad0532011-11-10 23:42:14 +00008520 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008521}
8522
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008523unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
8524 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
8525 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008526 unsigned Opc = Inst.getOpcode();
Joey Gouly0e76fa72013-09-12 10:28:05 +00008527 const MCInstrDesc &MCID = MII.get(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008528 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
8529 assert(MCID.hasOptionalDef() &&
8530 "optionally flag setting instruction missing optional def operand");
8531 assert(MCID.NumOperands == Inst.getNumOperands() &&
8532 "operand count mismatch!");
8533 // Find the optional-def operand (cc_out).
8534 unsigned OpNo;
8535 for (OpNo = 0;
8536 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
8537 ++OpNo)
8538 ;
8539 // If we're parsing Thumb1, reject it completely.
8540 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
8541 return Match_MnemonicFail;
8542 // If we're parsing Thumb2, which form is legal depends on whether we're
8543 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00008544 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
8545 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008546 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00008547 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
8548 inITBlock())
8549 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008550 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008551 // Some high-register supporting Thumb1 encodings only allow both registers
8552 // to be from r0-r7 when in Thumb2.
Renato Golin36c626e2014-09-26 16:14:29 +00008553 else if (Opc == ARM::tADDhirr && isThumbOne() && !hasV6MOps() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008554 isARMLowRegister(Inst.getOperand(1).getReg()) &&
8555 isARMLowRegister(Inst.getOperand(2).getReg()))
8556 return Match_RequiresThumb2;
8557 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00008558 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008559 isARMLowRegister(Inst.getOperand(0).getReg()) &&
8560 isARMLowRegister(Inst.getOperand(1).getReg()))
8561 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008562 return Match_Success;
8563}
8564
Benjamin Kramer44a53da2014-04-12 18:45:24 +00008565namespace llvm {
8566template <> inline bool IsCPSRDead<MCInst>(MCInst *Instr) {
Artyom Skrobov1a6cd1d2014-02-26 11:27:28 +00008567 return true; // In an assembly source, no need to second-guess
8568}
Benjamin Kramer44a53da2014-04-12 18:45:24 +00008569}
Artyom Skrobov1a6cd1d2014-02-26 11:27:28 +00008570
Tim Northover26bb14e2014-08-18 11:49:42 +00008571static const char *getSubtargetFeatureName(uint64_t Val);
David Blaikie960ea3f2014-06-08 16:18:35 +00008572bool ARMAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
8573 OperandVector &Operands,
Tim Northover26bb14e2014-08-18 11:49:42 +00008574 MCStreamer &Out, uint64_t &ErrorInfo,
David Blaikie960ea3f2014-06-08 16:18:35 +00008575 bool MatchingInlineAsm) {
Chris Lattner9487de62010-10-28 21:28:01 +00008576 MCInst Inst;
Jim Grosbach120a96a2011-08-15 23:03:29 +00008577 unsigned MatchResult;
Weiming Zhao8f56f882012-11-16 21:55:34 +00008578
Chad Rosier2f480a82012-10-12 22:53:36 +00008579 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
Chad Rosier49963552012-10-13 00:26:04 +00008580 MatchingInlineAsm);
Kevin Enderby3164a342010-12-09 19:19:43 +00008581 switch (MatchResult) {
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008582 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00008583 // Context sensitive operand constraints aren't handled by the matcher,
8584 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008585 if (validateInstruction(Inst, Operands)) {
8586 // Still progress the IT block, otherwise one wrong condition causes
8587 // nasty cascading errors.
8588 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00008589 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008590 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00008591
Amara Emerson52cfb6a2013-10-03 09:31:51 +00008592 { // processInstruction() updates inITBlock state, we need to save it away
8593 bool wasInITBlock = inITBlock();
8594
8595 // Some instructions need post-processing to, for example, tweak which
8596 // encoding is selected. Loop on it while changes happen so the
8597 // individual transformations can chain off each other. E.g.,
8598 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +00008599 while (processInstruction(Inst, Operands, Out))
Amara Emerson52cfb6a2013-10-03 09:31:51 +00008600 ;
8601
8602 // Only after the instruction is fully processed, we can validate it
8603 if (wasInITBlock && hasV8Ops() && isThumb() &&
Weiming Zhao5930ae62014-01-23 19:55:33 +00008604 !isV8EligibleForIT(&Inst)) {
Amara Emerson52cfb6a2013-10-03 09:31:51 +00008605 Warning(IDLoc, "deprecated instruction in IT block");
8606 }
8607 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008608
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008609 // Only move forward at the very end so that everything in validate
8610 // and process gets a consistent answer about whether we're in an IT
8611 // block.
8612 forwardITPosition();
8613
Jim Grosbach82f76d12012-01-25 19:52:01 +00008614 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
8615 // doesn't actually encode.
8616 if (Inst.getOpcode() == ARM::ITasm)
8617 return false;
8618
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00008619 Inst.setLoc(IDLoc);
David Woodhousee6c13e42014-01-28 23:12:42 +00008620 Out.EmitInstruction(Inst, STI);
Chris Lattner9487de62010-10-28 21:28:01 +00008621 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00008622 case Match_MissingFeature: {
8623 assert(ErrorInfo && "Unknown missing feature!");
8624 // Special case the error message for the very common case where only
8625 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
8626 std::string Msg = "instruction requires:";
Tim Northover26bb14e2014-08-18 11:49:42 +00008627 uint64_t Mask = 1;
Jim Grosbach5117ef72012-04-24 22:40:08 +00008628 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
8629 if (ErrorInfo & Mask) {
8630 Msg += " ";
8631 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
8632 }
8633 Mask <<= 1;
8634 }
8635 return Error(IDLoc, Msg);
8636 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008637 case Match_InvalidOperand: {
8638 SMLoc ErrorLoc = IDLoc;
Tim Northover26bb14e2014-08-18 11:49:42 +00008639 if (ErrorInfo != ~0ULL) {
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008640 if (ErrorInfo >= Operands.size())
8641 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00008642
David Blaikie960ea3f2014-06-08 16:18:35 +00008643 ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc();
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008644 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8645 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00008646
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008647 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00008648 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008649 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00008650 return Error(IDLoc, "invalid instruction",
David Blaikie960ea3f2014-06-08 16:18:35 +00008651 ((ARMOperand &)*Operands[0]).getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00008652 case Match_RequiresNotITBlock:
8653 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008654 case Match_RequiresITBlock:
8655 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008656 case Match_RequiresV6:
8657 return Error(IDLoc, "instruction variant requires ARMv6 or later");
8658 case Match_RequiresThumb2:
8659 return Error(IDLoc, "instruction variant requires Thumb2");
Jim Grosbach087affe2012-06-22 23:56:48 +00008660 case Match_ImmRange0_15: {
David Blaikie960ea3f2014-06-08 16:18:35 +00008661 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc();
Jim Grosbach087affe2012-06-22 23:56:48 +00008662 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8663 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
8664 }
Artyom Skrobovfc12e702013-10-23 10:14:40 +00008665 case Match_ImmRange0_239: {
David Blaikie960ea3f2014-06-08 16:18:35 +00008666 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc();
Artyom Skrobovfc12e702013-10-23 10:14:40 +00008667 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8668 return Error(ErrorLoc, "immediate operand must be in the range [0,239]");
8669 }
Kevin Enderby488f20b2014-04-10 20:18:58 +00008670 case Match_AlignedMemoryRequiresNone:
8671 case Match_DupAlignedMemoryRequiresNone:
8672 case Match_AlignedMemoryRequires16:
8673 case Match_DupAlignedMemoryRequires16:
8674 case Match_AlignedMemoryRequires32:
8675 case Match_DupAlignedMemoryRequires32:
8676 case Match_AlignedMemoryRequires64:
8677 case Match_DupAlignedMemoryRequires64:
8678 case Match_AlignedMemoryRequires64or128:
8679 case Match_DupAlignedMemoryRequires64or128:
8680 case Match_AlignedMemoryRequires64or128or256:
8681 {
David Blaikie960ea3f2014-06-08 16:18:35 +00008682 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getAlignmentLoc();
Kevin Enderby488f20b2014-04-10 20:18:58 +00008683 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8684 switch (MatchResult) {
8685 default:
8686 llvm_unreachable("Missing Match_Aligned type");
8687 case Match_AlignedMemoryRequiresNone:
8688 case Match_DupAlignedMemoryRequiresNone:
8689 return Error(ErrorLoc, "alignment must be omitted");
8690 case Match_AlignedMemoryRequires16:
8691 case Match_DupAlignedMemoryRequires16:
8692 return Error(ErrorLoc, "alignment must be 16 or omitted");
8693 case Match_AlignedMemoryRequires32:
8694 case Match_DupAlignedMemoryRequires32:
8695 return Error(ErrorLoc, "alignment must be 32 or omitted");
8696 case Match_AlignedMemoryRequires64:
8697 case Match_DupAlignedMemoryRequires64:
8698 return Error(ErrorLoc, "alignment must be 64 or omitted");
8699 case Match_AlignedMemoryRequires64or128:
8700 case Match_DupAlignedMemoryRequires64or128:
8701 return Error(ErrorLoc, "alignment must be 64, 128 or omitted");
8702 case Match_AlignedMemoryRequires64or128or256:
8703 return Error(ErrorLoc, "alignment must be 64, 128, 256 or omitted");
8704 }
8705 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008706 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00008707
Eric Christopher91d7b902010-10-29 09:26:59 +00008708 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00008709}
8710
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008711/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00008712bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008713 const MCObjectFileInfo::Environment Format =
8714 getContext().getObjectFileInfo()->getObjectFileType();
8715 bool IsMachO = Format == MCObjectFileInfo::IsMachO;
Saleem Abdulrasoolbfdfb142014-09-18 04:28:29 +00008716 bool IsCOFF = Format == MCObjectFileInfo::IsCOFF;
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008717
Kevin Enderbyccab3172009-09-15 00:27:25 +00008718 StringRef IDVal = DirectiveID.getIdentifier();
8719 if (IDVal == ".word")
Saleem Abdulrasool38976512014-02-23 06:22:09 +00008720 return parseLiteralValues(4, DirectiveID.getLoc());
8721 else if (IDVal == ".short" || IDVal == ".hword")
8722 return parseLiteralValues(2, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008723 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008724 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00008725 else if (IDVal == ".arm")
8726 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008727 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008728 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008729 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008730 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008731 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008732 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00008733 else if (IDVal == ".unreq")
8734 return parseDirectiveUnreq(DirectiveID.getLoc());
Logan Chien4ea23b52013-05-10 16:17:24 +00008735 else if (IDVal == ".fnend")
8736 return parseDirectiveFnEnd(DirectiveID.getLoc());
8737 else if (IDVal == ".cantunwind")
8738 return parseDirectiveCantUnwind(DirectiveID.getLoc());
8739 else if (IDVal == ".personality")
8740 return parseDirectivePersonality(DirectiveID.getLoc());
8741 else if (IDVal == ".handlerdata")
8742 return parseDirectiveHandlerData(DirectiveID.getLoc());
8743 else if (IDVal == ".setfp")
8744 return parseDirectiveSetFP(DirectiveID.getLoc());
8745 else if (IDVal == ".pad")
8746 return parseDirectivePad(DirectiveID.getLoc());
8747 else if (IDVal == ".save")
8748 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
8749 else if (IDVal == ".vsave")
8750 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
Saleem Abdulrasool6e6c2392013-12-20 07:21:16 +00008751 else if (IDVal == ".ltorg" || IDVal == ".pool")
David Peixotto80c083a2013-12-19 18:26:07 +00008752 return parseDirectiveLtorg(DirectiveID.getLoc());
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00008753 else if (IDVal == ".even")
8754 return parseDirectiveEven(DirectiveID.getLoc());
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00008755 else if (IDVal == ".personalityindex")
8756 return parseDirectivePersonalityIndex(DirectiveID.getLoc());
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +00008757 else if (IDVal == ".unwind_raw")
8758 return parseDirectiveUnwindRaw(DirectiveID.getLoc());
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00008759 else if (IDVal == ".movsp")
8760 return parseDirectiveMovSP(DirectiveID.getLoc());
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00008761 else if (IDVal == ".arch_extension")
8762 return parseDirectiveArchExtension(DirectiveID.getLoc());
Saleem Abdulrasoolfd6ed1e2014-02-23 17:45:32 +00008763 else if (IDVal == ".align")
8764 return parseDirectiveAlign(DirectiveID.getLoc());
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00008765 else if (IDVal == ".thumb_set")
8766 return parseDirectiveThumbSet(DirectiveID.getLoc());
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008767
Saleem Abdulrasoolbfdfb142014-09-18 04:28:29 +00008768 if (!IsMachO && !IsCOFF) {
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008769 if (IDVal == ".arch")
8770 return parseDirectiveArch(DirectiveID.getLoc());
8771 else if (IDVal == ".cpu")
8772 return parseDirectiveCPU(DirectiveID.getLoc());
8773 else if (IDVal == ".eabi_attribute")
8774 return parseDirectiveEabiAttr(DirectiveID.getLoc());
8775 else if (IDVal == ".fpu")
8776 return parseDirectiveFPU(DirectiveID.getLoc());
8777 else if (IDVal == ".fnstart")
8778 return parseDirectiveFnStart(DirectiveID.getLoc());
8779 else if (IDVal == ".inst")
8780 return parseDirectiveInst(DirectiveID.getLoc());
8781 else if (IDVal == ".inst.n")
8782 return parseDirectiveInst(DirectiveID.getLoc(), 'n');
8783 else if (IDVal == ".inst.w")
8784 return parseDirectiveInst(DirectiveID.getLoc(), 'w');
8785 else if (IDVal == ".object_arch")
8786 return parseDirectiveObjectArch(DirectiveID.getLoc());
8787 else if (IDVal == ".tlsdescseq")
8788 return parseDirectiveTLSDescSeq(DirectiveID.getLoc());
8789 }
8790
Kevin Enderbyccab3172009-09-15 00:27:25 +00008791 return true;
8792}
8793
Saleem Abdulrasool38976512014-02-23 06:22:09 +00008794/// parseLiteralValues
8795/// ::= .hword expression [, expression]*
8796/// ::= .short expression [, expression]*
8797/// ::= .word expression [, expression]*
8798bool ARMAsmParser::parseLiteralValues(unsigned Size, SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008799 MCAsmParser &Parser = getParser();
Kevin Enderbyccab3172009-09-15 00:27:25 +00008800 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8801 for (;;) {
8802 const MCExpr *Value;
Saleem Abdulrasoola9036612014-01-26 22:29:50 +00008803 if (getParser().parseExpression(Value)) {
8804 Parser.eatToEndOfStatement();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008805 return false;
Saleem Abdulrasoola9036612014-01-26 22:29:50 +00008806 }
Kevin Enderbyccab3172009-09-15 00:27:25 +00008807
Eric Christopherbf7bc492013-01-09 03:52:05 +00008808 getParser().getStreamer().EmitValue(Value, Size);
Kevin Enderbyccab3172009-09-15 00:27:25 +00008809
8810 if (getLexer().is(AsmToken::EndOfStatement))
8811 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00008812
Kevin Enderbyccab3172009-09-15 00:27:25 +00008813 // FIXME: Improve diagnostic.
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008814 if (getLexer().isNot(AsmToken::Comma)) {
8815 Error(L, "unexpected token in directive");
8816 return false;
8817 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008818 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00008819 }
8820 }
8821
Sean Callanana83fd7d2010-01-19 20:27:46 +00008822 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00008823 return false;
8824}
8825
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008826/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00008827/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008828bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008829 MCAsmParser &Parser = getParser();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008830 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8831 Error(L, "unexpected token in directive");
8832 return false;
8833 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008834 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008835
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008836 if (!hasThumb()) {
8837 Error(L, "target does not support Thumb mode");
8838 return false;
8839 }
Tim Northovera2292d02013-06-10 23:20:58 +00008840
Jim Grosbach7f882392011-12-07 18:04:19 +00008841 if (!isThumb())
8842 SwitchMode();
Saleem Abdulrasool44419fc2014-03-22 19:26:18 +00008843
Jim Grosbach7f882392011-12-07 18:04:19 +00008844 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
8845 return false;
8846}
8847
8848/// parseDirectiveARM
8849/// ::= .arm
8850bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008851 MCAsmParser &Parser = getParser();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008852 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8853 Error(L, "unexpected token in directive");
8854 return false;
8855 }
Jim Grosbach7f882392011-12-07 18:04:19 +00008856 Parser.Lex();
8857
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008858 if (!hasARM()) {
8859 Error(L, "target does not support ARM mode");
8860 return false;
8861 }
Tim Northovera2292d02013-06-10 23:20:58 +00008862
Jim Grosbach7f882392011-12-07 18:04:19 +00008863 if (isThumb())
8864 SwitchMode();
Saleem Abdulrasool44419fc2014-03-22 19:26:18 +00008865
Jim Grosbach7f882392011-12-07 18:04:19 +00008866 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00008867 return false;
8868}
8869
Tim Northover1744d0a2013-10-25 12:49:50 +00008870void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) {
8871 if (NextSymbolIsThumb) {
8872 getParser().getStreamer().EmitThumbFunc(Symbol);
8873 NextSymbolIsThumb = false;
8874 }
8875}
8876
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008877/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00008878/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008879bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008880 MCAsmParser &Parser = getParser();
Saleem Abdulrasool8c61c6c2014-09-18 03:49:55 +00008881 const auto Format = getContext().getObjectFileInfo()->getObjectFileType();
8882 bool IsMachO = Format == MCObjectFileInfo::IsMachO;
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008883
Jim Grosbach1152cc02011-12-21 22:30:16 +00008884 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008885 // ELF doesn't
Saleem Abdulrasool8c61c6c2014-09-18 03:49:55 +00008886 if (IsMachO) {
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008887 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00008888 if (Tok.isNot(AsmToken::EndOfStatement)) {
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008889 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String)) {
8890 Error(L, "unexpected token in .thumb_func directive");
8891 return false;
8892 }
8893
Tim Northover1744d0a2013-10-25 12:49:50 +00008894 MCSymbol *Func =
8895 getParser().getContext().GetOrCreateSymbol(Tok.getIdentifier());
8896 getParser().getStreamer().EmitThumbFunc(Func);
Jim Grosbach1152cc02011-12-21 22:30:16 +00008897 Parser.Lex(); // Consume the identifier token.
Tim Northover1744d0a2013-10-25 12:49:50 +00008898 return false;
Jim Grosbach1152cc02011-12-21 22:30:16 +00008899 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008900 }
8901
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008902 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Saleem Abdulrasool8c61c6c2014-09-18 03:49:55 +00008903 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8904 Parser.eatToEndOfStatement();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008905 return false;
8906 }
Jim Grosbach1152cc02011-12-21 22:30:16 +00008907
Tim Northover1744d0a2013-10-25 12:49:50 +00008908 NextSymbolIsThumb = true;
Kevin Enderby146dcf22009-10-15 20:48:48 +00008909 return false;
8910}
8911
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008912/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00008913/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008914bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008915 MCAsmParser &Parser = getParser();
Sean Callanan936b0d32010-01-19 21:44:56 +00008916 const AsmToken &Tok = Parser.getTok();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008917 if (Tok.isNot(AsmToken::Identifier)) {
8918 Error(L, "unexpected token in .syntax directive");
8919 return false;
8920 }
8921
Benjamin Kramer92d89982010-07-14 22:38:02 +00008922 StringRef Mode = Tok.getString();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008923 if (Mode == "unified" || Mode == "UNIFIED") {
Sean Callanana83fd7d2010-01-19 20:27:46 +00008924 Parser.Lex();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008925 } else if (Mode == "divided" || Mode == "DIVIDED") {
8926 Error(L, "'.syntax divided' arm asssembly not supported");
8927 return false;
8928 } else {
8929 Error(L, "unrecognized syntax mode in .syntax directive");
8930 return false;
8931 }
Kevin Enderby146dcf22009-10-15 20:48:48 +00008932
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008933 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8934 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8935 return false;
8936 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008937 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008938
8939 // TODO tell the MC streamer the mode
8940 // getParser().getStreamer().Emit???();
8941 return false;
8942}
8943
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008944/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00008945/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008946bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008947 MCAsmParser &Parser = getParser();
Sean Callanan936b0d32010-01-19 21:44:56 +00008948 const AsmToken &Tok = Parser.getTok();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008949 if (Tok.isNot(AsmToken::Integer)) {
8950 Error(L, "unexpected token in .code directive");
8951 return false;
8952 }
Sean Callanan936b0d32010-01-19 21:44:56 +00008953 int64_t Val = Parser.getTok().getIntVal();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008954 if (Val != 16 && Val != 32) {
8955 Error(L, "invalid operand to .code directive");
8956 return false;
8957 }
8958 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008959
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008960 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8961 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8962 return false;
8963 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008964 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008965
Evan Cheng284b4672011-07-08 22:36:29 +00008966 if (Val == 16) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008967 if (!hasThumb()) {
8968 Error(L, "target does not support Thumb mode");
8969 return false;
8970 }
Tim Northovera2292d02013-06-10 23:20:58 +00008971
Jim Grosbachf471ac32011-09-06 18:46:23 +00008972 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00008973 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00008974 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00008975 } else {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008976 if (!hasARM()) {
8977 Error(L, "target does not support ARM mode");
8978 return false;
8979 }
Tim Northovera2292d02013-06-10 23:20:58 +00008980
Jim Grosbachf471ac32011-09-06 18:46:23 +00008981 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00008982 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00008983 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00008984 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00008985
Kevin Enderby146dcf22009-10-15 20:48:48 +00008986 return false;
8987}
8988
Jim Grosbachab5830e2011-12-14 02:16:11 +00008989/// parseDirectiveReq
8990/// ::= name .req registername
8991bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008992 MCAsmParser &Parser = getParser();
Jim Grosbachab5830e2011-12-14 02:16:11 +00008993 Parser.Lex(); // Eat the '.req' token.
8994 unsigned Reg;
8995 SMLoc SRegLoc, ERegLoc;
8996 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008997 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008998 Error(SRegLoc, "register name expected");
8999 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00009000 }
9001
9002 // Shouldn't be anything else.
9003 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00009004 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009005 Error(Parser.getTok().getLoc(), "unexpected input in .req directive.");
9006 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00009007 }
9008
9009 Parser.Lex(); // Consume the EndOfStatement
9010
Frederic Rissb61f01f2015-02-04 03:10:03 +00009011 if (RegisterReqs.insert(std::make_pair(Name, Reg)).first->second != Reg) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009012 Error(SRegLoc, "redefinition of '" + Name + "' does not match original.");
9013 return false;
9014 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00009015
9016 return false;
9017}
9018
9019/// parseDirectiveUneq
9020/// ::= .unreq registername
9021bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009022 MCAsmParser &Parser = getParser();
Jim Grosbachab5830e2011-12-14 02:16:11 +00009023 if (Parser.getTok().isNot(AsmToken::Identifier)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00009024 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009025 Error(L, "unexpected input in .unreq directive.");
9026 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00009027 }
Duncan P. N. Exon Smith29db0eb2014-03-07 16:16:52 +00009028 RegisterReqs.erase(Parser.getTok().getIdentifier().lower());
Jim Grosbachab5830e2011-12-14 02:16:11 +00009029 Parser.Lex(); // Eat the identifier.
9030 return false;
9031}
9032
Jason W Kim135d2442011-12-20 17:38:12 +00009033/// parseDirectiveArch
9034/// ::= .arch token
9035bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
Logan Chien439e8f92013-12-11 17:16:25 +00009036 StringRef Arch = getParser().parseStringToEndOfStatement().trim();
9037
9038 unsigned ID = StringSwitch<unsigned>(Arch)
9039#define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
9040 .Case(NAME, ARM::ID)
Joerg Sonnenbergera13f8b42013-12-26 11:50:28 +00009041#define ARM_ARCH_ALIAS(NAME, ID) \
9042 .Case(NAME, ARM::ID)
Logan Chien439e8f92013-12-11 17:16:25 +00009043#include "MCTargetDesc/ARMArchName.def"
9044 .Default(ARM::INVALID_ARCH);
9045
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009046 if (ID == ARM::INVALID_ARCH) {
9047 Error(L, "Unknown arch name");
9048 return false;
9049 }
Logan Chien439e8f92013-12-11 17:16:25 +00009050
9051 getTargetStreamer().emitArch(ID);
9052 return false;
Jason W Kim135d2442011-12-20 17:38:12 +00009053}
9054
9055/// parseDirectiveEabiAttr
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009056/// ::= .eabi_attribute int, int [, "str"]
9057/// ::= .eabi_attribute Tag_name, int [, "str"]
Jason W Kim135d2442011-12-20 17:38:12 +00009058bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009059 MCAsmParser &Parser = getParser();
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009060 int64_t Tag;
9061 SMLoc TagLoc;
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009062 TagLoc = Parser.getTok().getLoc();
9063 if (Parser.getTok().is(AsmToken::Identifier)) {
9064 StringRef Name = Parser.getTok().getIdentifier();
9065 Tag = ARMBuildAttrs::AttrTypeFromString(Name);
9066 if (Tag == -1) {
9067 Error(TagLoc, "attribute name not recognised: " + Name);
9068 Parser.eatToEndOfStatement();
9069 return false;
9070 }
9071 Parser.Lex();
9072 } else {
9073 const MCExpr *AttrExpr;
9074
9075 TagLoc = Parser.getTok().getLoc();
9076 if (Parser.parseExpression(AttrExpr)) {
9077 Parser.eatToEndOfStatement();
9078 return false;
9079 }
9080
9081 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(AttrExpr);
9082 if (!CE) {
9083 Error(TagLoc, "expected numeric constant");
9084 Parser.eatToEndOfStatement();
9085 return false;
9086 }
9087
9088 Tag = CE->getValue();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009089 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00009090
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009091 if (Parser.getTok().isNot(AsmToken::Comma)) {
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009092 Error(Parser.getTok().getLoc(), "comma expected");
9093 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009094 return false;
9095 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00009096 Parser.Lex(); // skip comma
9097
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009098 StringRef StringValue = "";
9099 bool IsStringValue = false;
Logan Chien8cbb80d2013-10-28 17:51:12 +00009100
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009101 int64_t IntegerValue = 0;
9102 bool IsIntegerValue = false;
9103
9104 if (Tag == ARMBuildAttrs::CPU_raw_name || Tag == ARMBuildAttrs::CPU_name)
9105 IsStringValue = true;
9106 else if (Tag == ARMBuildAttrs::compatibility) {
9107 IsStringValue = true;
9108 IsIntegerValue = true;
Saleem Abdulrasool9dedf642014-01-19 08:25:19 +00009109 } else if (Tag < 32 || Tag % 2 == 0)
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009110 IsIntegerValue = true;
9111 else if (Tag % 2 == 1)
9112 IsStringValue = true;
9113 else
9114 llvm_unreachable("invalid tag type");
9115
9116 if (IsIntegerValue) {
9117 const MCExpr *ValueExpr;
9118 SMLoc ValueExprLoc = Parser.getTok().getLoc();
9119 if (Parser.parseExpression(ValueExpr)) {
9120 Parser.eatToEndOfStatement();
9121 return false;
9122 }
9123
9124 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ValueExpr);
9125 if (!CE) {
9126 Error(ValueExprLoc, "expected numeric constant");
9127 Parser.eatToEndOfStatement();
9128 return false;
9129 }
9130
9131 IntegerValue = CE->getValue();
9132 }
9133
9134 if (Tag == ARMBuildAttrs::compatibility) {
9135 if (Parser.getTok().isNot(AsmToken::Comma))
9136 IsStringValue = false;
Charlie Turner6632d1f2015-01-05 13:26:37 +00009137 if (Parser.getTok().isNot(AsmToken::Comma)) {
9138 Error(Parser.getTok().getLoc(), "comma expected");
9139 Parser.eatToEndOfStatement();
9140 return false;
9141 } else {
9142 Parser.Lex();
9143 }
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009144 }
9145
9146 if (IsStringValue) {
9147 if (Parser.getTok().isNot(AsmToken::String)) {
9148 Error(Parser.getTok().getLoc(), "bad string constant");
9149 Parser.eatToEndOfStatement();
9150 return false;
9151 }
9152
9153 StringValue = Parser.getTok().getStringContents();
9154 Parser.Lex();
9155 }
9156
9157 if (IsIntegerValue && IsStringValue) {
9158 assert(Tag == ARMBuildAttrs::compatibility);
9159 getTargetStreamer().emitIntTextAttribute(Tag, IntegerValue, StringValue);
9160 } else if (IsIntegerValue)
9161 getTargetStreamer().emitAttribute(Tag, IntegerValue);
9162 else if (IsStringValue)
9163 getTargetStreamer().emitTextAttribute(Tag, StringValue);
Logan Chien8cbb80d2013-10-28 17:51:12 +00009164 return false;
9165}
9166
9167/// parseDirectiveCPU
9168/// ::= .cpu str
9169bool ARMAsmParser::parseDirectiveCPU(SMLoc L) {
9170 StringRef CPU = getParser().parseStringToEndOfStatement().trim();
9171 getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name, CPU);
Roman Divacky7e6b5952014-12-02 20:03:22 +00009172
Roman Divackyfdf05602014-12-03 18:39:44 +00009173 if (!STI.isCPUStringValid(CPU)) {
Roman Divacky7e6b5952014-12-02 20:03:22 +00009174 Error(L, "Unknown CPU name");
9175 return false;
9176 }
9177
Roman Divacky6fd64ff2014-12-04 21:39:24 +00009178 // FIXME: This switches the CPU features globally, therefore it might
9179 // happen that code you would not expect to assemble will. For details
9180 // see: http://llvm.org/bugs/show_bug.cgi?id=20757
Roman Divacky7e6b5952014-12-02 20:03:22 +00009181 STI.InitMCProcessorInfo(CPU, "");
9182 STI.InitCPUSchedModel(CPU);
Bradley Smith9f4cd592015-02-04 16:23:24 +00009183 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Roman Divacky7e6b5952014-12-02 20:03:22 +00009184
Logan Chien8cbb80d2013-10-28 17:51:12 +00009185 return false;
9186}
9187
Nico Weberae050bb2014-08-16 05:37:51 +00009188// FIXME: This is duplicated in getARMFPUFeatures() in
9189// tools/clang/lib/Driver/Tools.cpp
9190static const struct {
Saleem Abdulrasool206d1162015-01-30 17:58:25 +00009191 const unsigned ID;
Michael Kuperstein29704e72015-03-24 12:56:59 +00009192 const uint64_t Enabled;
9193 const uint64_t Disabled;
Saleem Abdulrasool206d1162015-01-30 17:58:25 +00009194} FPUs[] = {
Michael Kuperstein29704e72015-03-24 12:56:59 +00009195 {/* ID */ ARM::VFP,
9196 /* Enabled */ ARM::FeatureVFP2,
9197 /* Disabled */ ARM::FeatureNEON},
9198 {/* ID */ ARM::VFPV2,
9199 /* Enabled */ ARM::FeatureVFP2,
9200 /* Disabled */ ARM::FeatureNEON},
9201 {/* ID */ ARM::VFPV3,
9202 /* Enabled */ ARM::FeatureVFP2 | ARM::FeatureVFP3,
9203 /* Disabled */ ARM::FeatureNEON | ARM::FeatureD16},
9204 {/* ID */ ARM::VFPV3_D16,
9205 /* Enable */ ARM::FeatureVFP2 | ARM::FeatureVFP3 | ARM::FeatureD16,
9206 /* Disabled */ ARM::FeatureNEON},
9207 {/* ID */ ARM::VFPV4,
9208 /* Enabled */ ARM::FeatureVFP2 | ARM::FeatureVFP3 | ARM::FeatureVFP4,
9209 /* Disabled */ ARM::FeatureNEON | ARM::FeatureD16},
9210 {/* ID */ ARM::VFPV4_D16,
9211 /* Enabled */ ARM::FeatureVFP2 | ARM::FeatureVFP3 | ARM::FeatureVFP4 |
9212 ARM::FeatureD16,
9213 /* Disabled */ ARM::FeatureNEON},
9214 {/* ID */ ARM::FPV5_D16,
9215 /* Enabled */ ARM::FeatureVFP2 | ARM::FeatureVFP3 | ARM::FeatureVFP4 |
9216 ARM::FeatureFPARMv8 | ARM::FeatureD16,
9217 /* Disabled */ ARM::FeatureNEON | ARM::FeatureCrypto},
9218 {/* ID */ ARM::FP_ARMV8,
9219 /* Enabled */ ARM::FeatureVFP2 | ARM::FeatureVFP3 | ARM::FeatureVFP4 |
9220 ARM::FeatureFPARMv8,
9221 /* Disabled */ ARM::FeatureNEON | ARM::FeatureCrypto | ARM::FeatureD16},
9222 {/* ID */ ARM::NEON,
9223 /* Enabled */ ARM::FeatureVFP2 | ARM::FeatureVFP3 | ARM::FeatureNEON,
9224 /* Disabled */ ARM::FeatureD16},
9225 {/* ID */ ARM::NEON_VFPV4,
9226 /* Enabled */ ARM::FeatureVFP2 | ARM::FeatureVFP3 | ARM::FeatureVFP4 |
9227 ARM::FeatureNEON,
9228 /* Disabled */ ARM::FeatureD16},
9229 {/* ID */ ARM::NEON_FP_ARMV8,
9230 /* Enabled */ ARM::FeatureVFP2 | ARM::FeatureVFP3 | ARM::FeatureVFP4 |
9231 ARM::FeatureFPARMv8 | ARM::FeatureNEON,
9232 /* Disabled */ ARM::FeatureCrypto | ARM::FeatureD16},
9233 {/* ID */ ARM::CRYPTO_NEON_FP_ARMV8,
9234 /* Enabled */ ARM::FeatureVFP2 | ARM::FeatureVFP3 | ARM::FeatureVFP4 |
9235 ARM::FeatureFPARMv8 | ARM::FeatureNEON | ARM::FeatureCrypto,
9236 /* Disabled */ ARM::FeatureD16},
9237 {ARM::SOFTVFP, 0, 0},
Nico Weberae050bb2014-08-16 05:37:51 +00009238};
9239
Logan Chien8cbb80d2013-10-28 17:51:12 +00009240/// parseDirectiveFPU
9241/// ::= .fpu str
9242bool ARMAsmParser::parseDirectiveFPU(SMLoc L) {
Saleem Abdulrasool07b7c032015-01-30 18:42:10 +00009243 SMLoc FPUNameLoc = getTok().getLoc();
Logan Chien8cbb80d2013-10-28 17:51:12 +00009244 StringRef FPU = getParser().parseStringToEndOfStatement().trim();
9245
9246 unsigned ID = StringSwitch<unsigned>(FPU)
9247#define ARM_FPU_NAME(NAME, ID) .Case(NAME, ARM::ID)
9248#include "ARMFPUName.def"
9249 .Default(ARM::INVALID_FPU);
9250
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009251 if (ID == ARM::INVALID_FPU) {
Saleem Abdulrasool07b7c032015-01-30 18:42:10 +00009252 Error(FPUNameLoc, "Unknown FPU name");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009253 return false;
9254 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00009255
Saleem Abdulrasool206d1162015-01-30 17:58:25 +00009256 for (const auto &Entry : FPUs) {
9257 if (Entry.ID != ID)
Nico Weberae050bb2014-08-16 05:37:51 +00009258 continue;
9259
9260 // Need to toggle features that should be on but are off and that
9261 // should off but are on.
Michael Kuperstein29704e72015-03-24 12:56:59 +00009262 uint64_t Toggle = (Entry.Enabled & ~STI.getFeatureBits()) |
9263 (Entry.Disabled & STI.getFeatureBits());
Nico Weberae050bb2014-08-16 05:37:51 +00009264 setAvailableFeatures(ComputeAvailableFeatures(STI.ToggleFeature(Toggle)));
9265 break;
9266 }
9267
Logan Chien8cbb80d2013-10-28 17:51:12 +00009268 getTargetStreamer().emitFPU(ID);
9269 return false;
Jason W Kim135d2442011-12-20 17:38:12 +00009270}
9271
Logan Chien4ea23b52013-05-10 16:17:24 +00009272/// parseDirectiveFnStart
9273/// ::= .fnstart
9274bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009275 if (UC.hasFnStart()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009276 Error(L, ".fnstart starts before the end of previous one");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009277 UC.emitFnStartLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009278 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009279 }
9280
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009281 // Reset the unwind directives parser state
9282 UC.reset();
9283
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009284 getTargetStreamer().emitFnStart();
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009285
9286 UC.recordFnStart(L);
Logan Chien4ea23b52013-05-10 16:17:24 +00009287 return false;
9288}
9289
9290/// parseDirectiveFnEnd
9291/// ::= .fnend
9292bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
9293 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009294 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009295 Error(L, ".fnstart must precede .fnend directive");
9296 return false;
9297 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009298
9299 // Reset the unwind directives parser state
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009300 getTargetStreamer().emitFnEnd();
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009301
9302 UC.reset();
Logan Chien4ea23b52013-05-10 16:17:24 +00009303 return false;
9304}
9305
9306/// parseDirectiveCantUnwind
9307/// ::= .cantunwind
9308bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009309 UC.recordCantUnwind(L);
9310
Logan Chien4ea23b52013-05-10 16:17:24 +00009311 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009312 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009313 Error(L, ".fnstart must precede .cantunwind directive");
9314 return false;
9315 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009316 if (UC.hasHandlerData()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009317 Error(L, ".cantunwind can't be used with .handlerdata directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009318 UC.emitHandlerDataLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009319 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009320 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009321 if (UC.hasPersonality()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009322 Error(L, ".cantunwind can't be used with .personality directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009323 UC.emitPersonalityLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009324 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009325 }
9326
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009327 getTargetStreamer().emitCantUnwind();
Logan Chien4ea23b52013-05-10 16:17:24 +00009328 return false;
9329}
9330
9331/// parseDirectivePersonality
9332/// ::= .personality name
9333bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009334 MCAsmParser &Parser = getParser();
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009335 bool HasExistingPersonality = UC.hasPersonality();
9336
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009337 UC.recordPersonality(L);
9338
Logan Chien4ea23b52013-05-10 16:17:24 +00009339 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009340 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009341 Error(L, ".fnstart must precede .personality directive");
9342 return false;
9343 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009344 if (UC.cantUnwind()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009345 Error(L, ".personality can't be used with .cantunwind directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009346 UC.emitCantUnwindLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009347 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009348 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009349 if (UC.hasHandlerData()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009350 Error(L, ".personality must precede .handlerdata directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009351 UC.emitHandlerDataLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009352 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009353 }
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009354 if (HasExistingPersonality) {
9355 Parser.eatToEndOfStatement();
9356 Error(L, "multiple personality directives");
9357 UC.emitPersonalityLocNotes();
9358 return false;
9359 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009360
9361 // Parse the name of the personality routine
9362 if (Parser.getTok().isNot(AsmToken::Identifier)) {
9363 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009364 Error(L, "unexpected input in .personality directive.");
9365 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009366 }
9367 StringRef Name(Parser.getTok().getIdentifier());
9368 Parser.Lex();
9369
9370 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009371 getTargetStreamer().emitPersonality(PR);
Logan Chien4ea23b52013-05-10 16:17:24 +00009372 return false;
9373}
9374
9375/// parseDirectiveHandlerData
9376/// ::= .handlerdata
9377bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009378 UC.recordHandlerData(L);
9379
Logan Chien4ea23b52013-05-10 16:17:24 +00009380 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009381 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009382 Error(L, ".fnstart must precede .personality directive");
9383 return false;
9384 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009385 if (UC.cantUnwind()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009386 Error(L, ".handlerdata can't be used with .cantunwind directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009387 UC.emitCantUnwindLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009388 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009389 }
9390
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009391 getTargetStreamer().emitHandlerData();
Logan Chien4ea23b52013-05-10 16:17:24 +00009392 return false;
9393}
9394
9395/// parseDirectiveSetFP
9396/// ::= .setfp fpreg, spreg [, offset]
9397bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009398 MCAsmParser &Parser = getParser();
Logan Chien4ea23b52013-05-10 16:17:24 +00009399 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009400 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009401 Error(L, ".fnstart must precede .setfp directive");
9402 return false;
9403 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009404 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009405 Error(L, ".setfp must precede .handlerdata directive");
9406 return false;
9407 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009408
9409 // Parse fpreg
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009410 SMLoc FPRegLoc = Parser.getTok().getLoc();
9411 int FPReg = tryParseRegister();
9412 if (FPReg == -1) {
9413 Error(FPRegLoc, "frame pointer register expected");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009414 return false;
9415 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009416
9417 // Consume comma
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00009418 if (Parser.getTok().isNot(AsmToken::Comma)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009419 Error(Parser.getTok().getLoc(), "comma expected");
9420 return false;
9421 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009422 Parser.Lex(); // skip comma
9423
9424 // Parse spreg
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009425 SMLoc SPRegLoc = Parser.getTok().getLoc();
9426 int SPReg = tryParseRegister();
9427 if (SPReg == -1) {
9428 Error(SPRegLoc, "stack pointer register expected");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009429 return false;
9430 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009431
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009432 if (SPReg != ARM::SP && SPReg != UC.getFPReg()) {
9433 Error(SPRegLoc, "register should be either $sp or the latest fp register");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009434 return false;
9435 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009436
9437 // Update the frame pointer register
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009438 UC.saveFPReg(FPReg);
Logan Chien4ea23b52013-05-10 16:17:24 +00009439
9440 // Parse offset
9441 int64_t Offset = 0;
9442 if (Parser.getTok().is(AsmToken::Comma)) {
9443 Parser.Lex(); // skip comma
9444
9445 if (Parser.getTok().isNot(AsmToken::Hash) &&
9446 Parser.getTok().isNot(AsmToken::Dollar)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009447 Error(Parser.getTok().getLoc(), "'#' expected");
9448 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009449 }
9450 Parser.Lex(); // skip hash token.
9451
9452 const MCExpr *OffsetExpr;
9453 SMLoc ExLoc = Parser.getTok().getLoc();
9454 SMLoc EndLoc;
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009455 if (getParser().parseExpression(OffsetExpr, EndLoc)) {
9456 Error(ExLoc, "malformed setfp offset");
9457 return false;
9458 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009459 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009460 if (!CE) {
9461 Error(ExLoc, "setfp offset must be an immediate");
9462 return false;
9463 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009464
9465 Offset = CE->getValue();
9466 }
9467
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009468 getTargetStreamer().emitSetFP(static_cast<unsigned>(FPReg),
9469 static_cast<unsigned>(SPReg), Offset);
Logan Chien4ea23b52013-05-10 16:17:24 +00009470 return false;
9471}
9472
9473/// parseDirective
9474/// ::= .pad offset
9475bool ARMAsmParser::parseDirectivePad(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009476 MCAsmParser &Parser = getParser();
Logan Chien4ea23b52013-05-10 16:17:24 +00009477 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009478 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009479 Error(L, ".fnstart must precede .pad directive");
9480 return false;
9481 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009482 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009483 Error(L, ".pad must precede .handlerdata directive");
9484 return false;
9485 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009486
9487 // Parse the offset
9488 if (Parser.getTok().isNot(AsmToken::Hash) &&
9489 Parser.getTok().isNot(AsmToken::Dollar)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009490 Error(Parser.getTok().getLoc(), "'#' expected");
9491 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009492 }
9493 Parser.Lex(); // skip hash token.
9494
9495 const MCExpr *OffsetExpr;
9496 SMLoc ExLoc = Parser.getTok().getLoc();
9497 SMLoc EndLoc;
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009498 if (getParser().parseExpression(OffsetExpr, EndLoc)) {
9499 Error(ExLoc, "malformed pad offset");
9500 return false;
9501 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009502 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009503 if (!CE) {
9504 Error(ExLoc, "pad offset must be an immediate");
9505 return false;
9506 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009507
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009508 getTargetStreamer().emitPad(CE->getValue());
Logan Chien4ea23b52013-05-10 16:17:24 +00009509 return false;
9510}
9511
9512/// parseDirectiveRegSave
9513/// ::= .save { registers }
9514/// ::= .vsave { registers }
9515bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
9516 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009517 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009518 Error(L, ".fnstart must precede .save or .vsave directives");
9519 return false;
9520 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009521 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009522 Error(L, ".save or .vsave must precede .handlerdata directive");
9523 return false;
9524 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009525
Benjamin Kramer23632bd2013-08-03 22:16:24 +00009526 // RAII object to make sure parsed operands are deleted.
David Blaikie960ea3f2014-06-08 16:18:35 +00009527 SmallVector<std::unique_ptr<MCParsedAsmOperand>, 1> Operands;
Benjamin Kramer23632bd2013-08-03 22:16:24 +00009528
Logan Chien4ea23b52013-05-10 16:17:24 +00009529 // Parse the register list
David Blaikie960ea3f2014-06-08 16:18:35 +00009530 if (parseRegisterList(Operands))
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00009531 return false;
David Blaikie960ea3f2014-06-08 16:18:35 +00009532 ARMOperand &Op = (ARMOperand &)*Operands[0];
9533 if (!IsVector && !Op.isRegList()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009534 Error(L, ".save expects GPR registers");
9535 return false;
9536 }
David Blaikie960ea3f2014-06-08 16:18:35 +00009537 if (IsVector && !Op.isDPRRegList()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009538 Error(L, ".vsave expects DPR registers");
9539 return false;
9540 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009541
David Blaikie960ea3f2014-06-08 16:18:35 +00009542 getTargetStreamer().emitRegSave(Op.getRegList(), IsVector);
Logan Chien4ea23b52013-05-10 16:17:24 +00009543 return false;
9544}
9545
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009546/// parseDirectiveInst
9547/// ::= .inst opcode [, ...]
9548/// ::= .inst.n opcode [, ...]
9549/// ::= .inst.w opcode [, ...]
9550bool ARMAsmParser::parseDirectiveInst(SMLoc Loc, char Suffix) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009551 MCAsmParser &Parser = getParser();
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009552 int Width;
9553
9554 if (isThumb()) {
9555 switch (Suffix) {
9556 case 'n':
9557 Width = 2;
9558 break;
9559 case 'w':
9560 Width = 4;
9561 break;
9562 default:
9563 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009564 Error(Loc, "cannot determine Thumb instruction size, "
9565 "use inst.n/inst.w instead");
9566 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009567 }
9568 } else {
9569 if (Suffix) {
9570 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009571 Error(Loc, "width suffixes are invalid in ARM mode");
9572 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009573 }
9574 Width = 4;
9575 }
9576
9577 if (getLexer().is(AsmToken::EndOfStatement)) {
9578 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009579 Error(Loc, "expected expression following directive");
9580 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009581 }
9582
9583 for (;;) {
9584 const MCExpr *Expr;
9585
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009586 if (getParser().parseExpression(Expr)) {
9587 Error(Loc, "expected expression");
9588 return false;
9589 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009590
9591 const MCConstantExpr *Value = dyn_cast_or_null<MCConstantExpr>(Expr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009592 if (!Value) {
9593 Error(Loc, "expected constant expression");
9594 return false;
9595 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009596
9597 switch (Width) {
9598 case 2:
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009599 if (Value->getValue() > 0xffff) {
9600 Error(Loc, "inst.n operand is too big, use inst.w instead");
9601 return false;
9602 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009603 break;
9604 case 4:
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009605 if (Value->getValue() > 0xffffffff) {
9606 Error(Loc,
9607 StringRef(Suffix ? "inst.w" : "inst") + " operand is too big");
9608 return false;
9609 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009610 break;
9611 default:
9612 llvm_unreachable("only supported widths are 2 and 4");
9613 }
9614
9615 getTargetStreamer().emitInst(Value->getValue(), Suffix);
9616
9617 if (getLexer().is(AsmToken::EndOfStatement))
9618 break;
9619
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009620 if (getLexer().isNot(AsmToken::Comma)) {
9621 Error(Loc, "unexpected token in directive");
9622 return false;
9623 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009624
9625 Parser.Lex();
9626 }
9627
9628 Parser.Lex();
9629 return false;
9630}
9631
David Peixotto80c083a2013-12-19 18:26:07 +00009632/// parseDirectiveLtorg
Saleem Abdulrasool6e6c2392013-12-20 07:21:16 +00009633/// ::= .ltorg | .pool
David Peixotto80c083a2013-12-19 18:26:07 +00009634bool ARMAsmParser::parseDirectiveLtorg(SMLoc L) {
David Peixottob9b73622014-02-04 17:22:40 +00009635 getTargetStreamer().emitCurrentConstantPool();
David Peixotto80c083a2013-12-19 18:26:07 +00009636 return false;
9637}
9638
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009639bool ARMAsmParser::parseDirectiveEven(SMLoc L) {
9640 const MCSection *Section = getStreamer().getCurrentSection().first;
9641
9642 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9643 TokError("unexpected token in directive");
9644 return false;
9645 }
9646
9647 if (!Section) {
Rafael Espindola7b61ddf2014-10-15 16:12:52 +00009648 getStreamer().InitSections(false);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009649 Section = getStreamer().getCurrentSection().first;
9650 }
9651
Saleem Abdulrasool42b233a2014-03-18 05:26:55 +00009652 assert(Section && "must have section to emit alignment");
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009653 if (Section->UseCodeAlign())
Rafael Espindola7b514962014-02-04 18:34:04 +00009654 getStreamer().EmitCodeAlignment(2);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009655 else
Rafael Espindola7b514962014-02-04 18:34:04 +00009656 getStreamer().EmitValueToAlignment(2);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009657
9658 return false;
9659}
9660
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009661/// parseDirectivePersonalityIndex
9662/// ::= .personalityindex index
9663bool ARMAsmParser::parseDirectivePersonalityIndex(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009664 MCAsmParser &Parser = getParser();
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009665 bool HasExistingPersonality = UC.hasPersonality();
9666
9667 UC.recordPersonalityIndex(L);
9668
9669 if (!UC.hasFnStart()) {
9670 Parser.eatToEndOfStatement();
9671 Error(L, ".fnstart must precede .personalityindex directive");
9672 return false;
9673 }
9674 if (UC.cantUnwind()) {
9675 Parser.eatToEndOfStatement();
9676 Error(L, ".personalityindex cannot be used with .cantunwind");
9677 UC.emitCantUnwindLocNotes();
9678 return false;
9679 }
9680 if (UC.hasHandlerData()) {
9681 Parser.eatToEndOfStatement();
9682 Error(L, ".personalityindex must precede .handlerdata directive");
9683 UC.emitHandlerDataLocNotes();
9684 return false;
9685 }
9686 if (HasExistingPersonality) {
9687 Parser.eatToEndOfStatement();
9688 Error(L, "multiple personality directives");
9689 UC.emitPersonalityLocNotes();
9690 return false;
9691 }
9692
9693 const MCExpr *IndexExpression;
9694 SMLoc IndexLoc = Parser.getTok().getLoc();
9695 if (Parser.parseExpression(IndexExpression)) {
9696 Parser.eatToEndOfStatement();
9697 return false;
9698 }
9699
9700 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(IndexExpression);
9701 if (!CE) {
9702 Parser.eatToEndOfStatement();
9703 Error(IndexLoc, "index must be a constant number");
9704 return false;
9705 }
9706 if (CE->getValue() < 0 ||
9707 CE->getValue() >= ARM::EHABI::NUM_PERSONALITY_INDEX) {
9708 Parser.eatToEndOfStatement();
9709 Error(IndexLoc, "personality routine index should be in range [0-3]");
9710 return false;
9711 }
9712
9713 getTargetStreamer().emitPersonalityIndex(CE->getValue());
9714 return false;
9715}
9716
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +00009717/// parseDirectiveUnwindRaw
9718/// ::= .unwind_raw offset, opcode [, opcode...]
9719bool ARMAsmParser::parseDirectiveUnwindRaw(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009720 MCAsmParser &Parser = getParser();
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +00009721 if (!UC.hasFnStart()) {
9722 Parser.eatToEndOfStatement();
9723 Error(L, ".fnstart must precede .unwind_raw directives");
9724 return false;
9725 }
9726
9727 int64_t StackOffset;
9728
9729 const MCExpr *OffsetExpr;
9730 SMLoc OffsetLoc = getLexer().getLoc();
9731 if (getLexer().is(AsmToken::EndOfStatement) ||
9732 getParser().parseExpression(OffsetExpr)) {
9733 Error(OffsetLoc, "expected expression");
9734 Parser.eatToEndOfStatement();
9735 return false;
9736 }
9737
9738 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
9739 if (!CE) {
9740 Error(OffsetLoc, "offset must be a constant");
9741 Parser.eatToEndOfStatement();
9742 return false;
9743 }
9744
9745 StackOffset = CE->getValue();
9746
9747 if (getLexer().isNot(AsmToken::Comma)) {
9748 Error(getLexer().getLoc(), "expected comma");
9749 Parser.eatToEndOfStatement();
9750 return false;
9751 }
9752 Parser.Lex();
9753
9754 SmallVector<uint8_t, 16> Opcodes;
9755 for (;;) {
9756 const MCExpr *OE;
9757
9758 SMLoc OpcodeLoc = getLexer().getLoc();
9759 if (getLexer().is(AsmToken::EndOfStatement) || Parser.parseExpression(OE)) {
9760 Error(OpcodeLoc, "expected opcode expression");
9761 Parser.eatToEndOfStatement();
9762 return false;
9763 }
9764
9765 const MCConstantExpr *OC = dyn_cast<MCConstantExpr>(OE);
9766 if (!OC) {
9767 Error(OpcodeLoc, "opcode value must be a constant");
9768 Parser.eatToEndOfStatement();
9769 return false;
9770 }
9771
9772 const int64_t Opcode = OC->getValue();
9773 if (Opcode & ~0xff) {
9774 Error(OpcodeLoc, "invalid opcode");
9775 Parser.eatToEndOfStatement();
9776 return false;
9777 }
9778
9779 Opcodes.push_back(uint8_t(Opcode));
9780
9781 if (getLexer().is(AsmToken::EndOfStatement))
9782 break;
9783
9784 if (getLexer().isNot(AsmToken::Comma)) {
9785 Error(getLexer().getLoc(), "unexpected token in directive");
9786 Parser.eatToEndOfStatement();
9787 return false;
9788 }
9789
9790 Parser.Lex();
9791 }
9792
9793 getTargetStreamer().emitUnwindRaw(StackOffset, Opcodes);
9794
9795 Parser.Lex();
9796 return false;
9797}
9798
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +00009799/// parseDirectiveTLSDescSeq
9800/// ::= .tlsdescseq tls-variable
9801bool ARMAsmParser::parseDirectiveTLSDescSeq(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009802 MCAsmParser &Parser = getParser();
9803
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +00009804 if (getLexer().isNot(AsmToken::Identifier)) {
9805 TokError("expected variable after '.tlsdescseq' directive");
9806 Parser.eatToEndOfStatement();
9807 return false;
9808 }
9809
9810 const MCSymbolRefExpr *SRE =
9811 MCSymbolRefExpr::Create(Parser.getTok().getIdentifier(),
9812 MCSymbolRefExpr::VK_ARM_TLSDESCSEQ, getContext());
9813 Lex();
9814
9815 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9816 Error(Parser.getTok().getLoc(), "unexpected token");
9817 Parser.eatToEndOfStatement();
9818 return false;
9819 }
9820
9821 getTargetStreamer().AnnotateTLSDescriptorSequence(SRE);
9822 return false;
9823}
9824
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00009825/// parseDirectiveMovSP
9826/// ::= .movsp reg [, #offset]
9827bool ARMAsmParser::parseDirectiveMovSP(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009828 MCAsmParser &Parser = getParser();
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00009829 if (!UC.hasFnStart()) {
9830 Parser.eatToEndOfStatement();
9831 Error(L, ".fnstart must precede .movsp directives");
9832 return false;
9833 }
9834 if (UC.getFPReg() != ARM::SP) {
9835 Parser.eatToEndOfStatement();
9836 Error(L, "unexpected .movsp directive");
9837 return false;
9838 }
9839
9840 SMLoc SPRegLoc = Parser.getTok().getLoc();
9841 int SPReg = tryParseRegister();
9842 if (SPReg == -1) {
9843 Parser.eatToEndOfStatement();
9844 Error(SPRegLoc, "register expected");
9845 return false;
9846 }
9847
9848 if (SPReg == ARM::SP || SPReg == ARM::PC) {
9849 Parser.eatToEndOfStatement();
9850 Error(SPRegLoc, "sp and pc are not permitted in .movsp directive");
9851 return false;
9852 }
9853
9854 int64_t Offset = 0;
9855 if (Parser.getTok().is(AsmToken::Comma)) {
9856 Parser.Lex();
9857
9858 if (Parser.getTok().isNot(AsmToken::Hash)) {
9859 Error(Parser.getTok().getLoc(), "expected #constant");
9860 Parser.eatToEndOfStatement();
9861 return false;
9862 }
9863 Parser.Lex();
9864
9865 const MCExpr *OffsetExpr;
9866 SMLoc OffsetLoc = Parser.getTok().getLoc();
9867 if (Parser.parseExpression(OffsetExpr)) {
9868 Parser.eatToEndOfStatement();
9869 Error(OffsetLoc, "malformed offset expression");
9870 return false;
9871 }
9872
9873 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
9874 if (!CE) {
9875 Parser.eatToEndOfStatement();
9876 Error(OffsetLoc, "offset must be an immediate constant");
9877 return false;
9878 }
9879
9880 Offset = CE->getValue();
9881 }
9882
9883 getTargetStreamer().emitMovSP(SPReg, Offset);
9884 UC.saveFPReg(SPReg);
9885
9886 return false;
9887}
9888
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +00009889/// parseDirectiveObjectArch
9890/// ::= .object_arch name
9891bool ARMAsmParser::parseDirectiveObjectArch(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009892 MCAsmParser &Parser = getParser();
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +00009893 if (getLexer().isNot(AsmToken::Identifier)) {
9894 Error(getLexer().getLoc(), "unexpected token");
9895 Parser.eatToEndOfStatement();
9896 return false;
9897 }
9898
9899 StringRef Arch = Parser.getTok().getString();
9900 SMLoc ArchLoc = Parser.getTok().getLoc();
9901 getLexer().Lex();
9902
9903 unsigned ID = StringSwitch<unsigned>(Arch)
9904#define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
9905 .Case(NAME, ARM::ID)
9906#define ARM_ARCH_ALIAS(NAME, ID) \
9907 .Case(NAME, ARM::ID)
9908#include "MCTargetDesc/ARMArchName.def"
9909#undef ARM_ARCH_NAME
9910#undef ARM_ARCH_ALIAS
9911 .Default(ARM::INVALID_ARCH);
9912
9913 if (ID == ARM::INVALID_ARCH) {
9914 Error(ArchLoc, "unknown architecture '" + Arch + "'");
9915 Parser.eatToEndOfStatement();
9916 return false;
9917 }
9918
9919 getTargetStreamer().emitObjectArch(ID);
9920
9921 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9922 Error(getLexer().getLoc(), "unexpected token");
9923 Parser.eatToEndOfStatement();
9924 }
9925
9926 return false;
9927}
9928
Saleem Abdulrasoolfd6ed1e2014-02-23 17:45:32 +00009929/// parseDirectiveAlign
9930/// ::= .align
9931bool ARMAsmParser::parseDirectiveAlign(SMLoc L) {
9932 // NOTE: if this is not the end of the statement, fall back to the target
9933 // agnostic handling for this directive which will correctly handle this.
9934 if (getLexer().isNot(AsmToken::EndOfStatement))
9935 return true;
9936
9937 // '.align' is target specifically handled to mean 2**2 byte alignment.
9938 if (getStreamer().getCurrentSection().first->UseCodeAlign())
9939 getStreamer().EmitCodeAlignment(4, 0);
9940 else
9941 getStreamer().EmitValueToAlignment(4, 0, 1, 0);
9942
9943 return false;
9944}
9945
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00009946/// parseDirectiveThumbSet
9947/// ::= .thumb_set name, value
9948bool ARMAsmParser::parseDirectiveThumbSet(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009949 MCAsmParser &Parser = getParser();
9950
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00009951 StringRef Name;
9952 if (Parser.parseIdentifier(Name)) {
9953 TokError("expected identifier after '.thumb_set'");
9954 Parser.eatToEndOfStatement();
9955 return false;
9956 }
9957
9958 if (getLexer().isNot(AsmToken::Comma)) {
9959 TokError("expected comma after name '" + Name + "'");
9960 Parser.eatToEndOfStatement();
9961 return false;
9962 }
9963 Lex();
9964
9965 const MCExpr *Value;
9966 if (Parser.parseExpression(Value)) {
9967 TokError("missing expression");
9968 Parser.eatToEndOfStatement();
9969 return false;
9970 }
9971
9972 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9973 TokError("unexpected token");
9974 Parser.eatToEndOfStatement();
9975 return false;
9976 }
9977 Lex();
9978
9979 MCSymbol *Alias = getContext().GetOrCreateSymbol(Name);
Rafael Espindola466d6632014-04-27 20:23:58 +00009980 getTargetStreamer().emitThumbSet(Alias, Value);
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00009981 return false;
9982}
9983
Kevin Enderby8be42bd2009-10-30 22:55:57 +00009984/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00009985extern "C" void LLVMInitializeARMAsmParser() {
Christian Pirkerdc9ff752014-04-01 15:19:30 +00009986 RegisterMCAsmParser<ARMAsmParser> X(TheARMLETarget);
9987 RegisterMCAsmParser<ARMAsmParser> Y(TheARMBETarget);
9988 RegisterMCAsmParser<ARMAsmParser> A(TheThumbLETarget);
9989 RegisterMCAsmParser<ARMAsmParser> B(TheThumbBETarget);
Kevin Enderbyccab3172009-09-15 00:27:25 +00009990}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00009991
Chris Lattner3e4582a2010-09-06 19:11:01 +00009992#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00009993#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00009994#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00009995#include "ARMGenAsmMatcher.inc"
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009996
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009997static const struct {
9998 const char *Name;
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009999 const unsigned ArchCheck;
Michael Kuperstein29704e72015-03-24 12:56:59 +000010000 const uint64_t Features;
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010001} Extensions[] = {
Michael Kuperstein29704e72015-03-24 12:56:59 +000010002 { "crc", Feature_HasV8, ARM::FeatureCRC },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010003 { "crypto", Feature_HasV8,
Michael Kuperstein29704e72015-03-24 12:56:59 +000010004 ARM::FeatureCrypto | ARM::FeatureNEON | ARM::FeatureFPARMv8 },
10005 { "fp", Feature_HasV8, ARM::FeatureFPARMv8 },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010006 { "idiv", Feature_HasV7 | Feature_IsNotMClass,
Michael Kuperstein29704e72015-03-24 12:56:59 +000010007 ARM::FeatureHWDiv | ARM::FeatureHWDivARM },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010008 // FIXME: iWMMXT not supported
Michael Kuperstein29704e72015-03-24 12:56:59 +000010009 { "iwmmxt", Feature_None, 0 },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010010 // FIXME: iWMMXT2 not supported
Michael Kuperstein29704e72015-03-24 12:56:59 +000010011 { "iwmmxt2", Feature_None, 0 },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010012 // FIXME: Maverick not supported
Michael Kuperstein29704e72015-03-24 12:56:59 +000010013 { "maverick", Feature_None, 0 },
10014 { "mp", Feature_HasV7 | Feature_IsNotMClass, ARM::FeatureMP },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010015 // FIXME: ARMv6-m OS Extensions feature not checked
Michael Kuperstein29704e72015-03-24 12:56:59 +000010016 { "os", Feature_None, 0 },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010017 // FIXME: Also available in ARMv6-K
Michael Kuperstein29704e72015-03-24 12:56:59 +000010018 { "sec", Feature_HasV7, ARM::FeatureTrustZone },
10019 { "simd", Feature_HasV8, ARM::FeatureNEON | ARM::FeatureFPARMv8 },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010020 // FIXME: Only available in A-class, isel not predicated
Michael Kuperstein29704e72015-03-24 12:56:59 +000010021 { "virt", Feature_HasV7, ARM::FeatureVirtualization },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010022 // FIXME: xscale not supported
Michael Kuperstein29704e72015-03-24 12:56:59 +000010023 { "xscale", Feature_None, 0 },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010024};
10025
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010026/// parseDirectiveArchExtension
10027/// ::= .arch_extension [no]feature
10028bool ARMAsmParser::parseDirectiveArchExtension(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +000010029 MCAsmParser &Parser = getParser();
10030
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010031 if (getLexer().isNot(AsmToken::Identifier)) {
10032 Error(getLexer().getLoc(), "unexpected token");
10033 Parser.eatToEndOfStatement();
10034 return false;
10035 }
10036
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +000010037 StringRef Name = Parser.getTok().getString();
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010038 SMLoc ExtLoc = Parser.getTok().getLoc();
10039 getLexer().Lex();
10040
10041 bool EnableFeature = true;
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +000010042 if (Name.startswith_lower("no")) {
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010043 EnableFeature = false;
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +000010044 Name = Name.substr(2);
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010045 }
10046
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +000010047 for (const auto &Extension : Extensions) {
10048 if (Extension.Name != Name)
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010049 continue;
10050
Michael Kuperstein29704e72015-03-24 12:56:59 +000010051 if (!Extension.Features)
Saleem Abdulrasool8988c2a2014-07-27 19:07:09 +000010052 report_fatal_error("unsupported architectural extension: " + Name);
10053
10054 if ((getAvailableFeatures() & Extension.ArchCheck) != Extension.ArchCheck) {
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +000010055 Error(ExtLoc, "architectural extension '" + Name + "' is not "
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010056 "allowed for the current base architecture");
10057 return false;
10058 }
10059
Michael Kuperstein29704e72015-03-24 12:56:59 +000010060 uint64_t ToggleFeatures = EnableFeature
10061 ? (~STI.getFeatureBits() & Extension.Features)
10062 : ( STI.getFeatureBits() & Extension.Features);
Tim Northover26bb14e2014-08-18 11:49:42 +000010063 uint64_t Features =
Saleem Abdulrasool78c44722014-08-17 19:20:38 +000010064 ComputeAvailableFeatures(STI.ToggleFeature(ToggleFeatures));
10065 setAvailableFeatures(Features);
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010066 return false;
10067 }
10068
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +000010069 Error(ExtLoc, "unknown architectural extension: " + Name);
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010070 Parser.eatToEndOfStatement();
10071 return false;
10072}
10073
Jim Grosbach231e7aa2013-02-06 06:00:11 +000010074// Define this matcher function after the auto-generated include so we
10075// have the match class enum definitions.
David Blaikie960ea3f2014-06-08 16:18:35 +000010076unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand &AsmOp,
Jim Grosbach231e7aa2013-02-06 06:00:11 +000010077 unsigned Kind) {
David Blaikie960ea3f2014-06-08 16:18:35 +000010078 ARMOperand &Op = static_cast<ARMOperand &>(AsmOp);
Jim Grosbach231e7aa2013-02-06 06:00:11 +000010079 // If the kind is a token for a literal immediate, check if our asm
10080 // operand matches. This is for InstAliases which have a fixed-value
10081 // immediate in the syntax.
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +000010082 switch (Kind) {
10083 default: break;
10084 case MCK__35_0:
David Blaikie960ea3f2014-06-08 16:18:35 +000010085 if (Op.isImm())
10086 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm()))
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +000010087 if (CE->getValue() == 0)
10088 return Match_Success;
10089 break;
Asiri Rathnayakea0199b92014-12-02 10:53:20 +000010090 case MCK_ModImm:
David Blaikie960ea3f2014-06-08 16:18:35 +000010091 if (Op.isImm()) {
10092 const MCExpr *SOExpr = Op.getImm();
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +000010093 int64_t Value;
10094 if (!SOExpr->EvaluateAsAbsolute(Value))
Stepan Dyatkovskiydf657cc2014-03-29 13:12:40 +000010095 return Match_Success;
Richard Barton3db1d582014-05-01 11:37:44 +000010096 assert((Value >= INT32_MIN && Value <= UINT32_MAX) &&
10097 "expression value must be representable in 32 bits");
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +000010098 }
10099 break;
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +000010100 case MCK_GPRPair:
David Blaikie960ea3f2014-06-08 16:18:35 +000010101 if (Op.isReg() &&
10102 MRI->getRegClass(ARM::GPRRegClassID).contains(Op.getReg()))
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +000010103 return Match_Success;
10104 break;
Jim Grosbach231e7aa2013-02-06 06:00:11 +000010105 }
10106 return Match_InvalidOperand;
10107}