blob: 0fa99a94f18c8ce397c2eced836a7809528f3552 [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.
Alexander Kornienkofb37cfa2015-04-14 15:32:58 +00005421void ARMAsmParser::getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
5422 bool &CanAcceptCarrySet,
5423 bool &CanAcceptPredicationCode) {
5424 CanAcceptCarrySet =
5425 Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00005426 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Alexander Kornienkofb37cfa2015-04-14 15:32:58 +00005427 Mnemonic == "add" || Mnemonic == "adc" || Mnemonic == "mul" ||
5428 Mnemonic == "bic" || Mnemonic == "asr" || Mnemonic == "orr" ||
5429 Mnemonic == "mvn" || Mnemonic == "rsb" || Mnemonic == "rsc" ||
5430 Mnemonic == "orn" || Mnemonic == "sbc" || Mnemonic == "eor" ||
5431 Mnemonic == "neg" || Mnemonic == "vfm" || Mnemonic == "vfnm" ||
5432 (!isThumb() &&
5433 (Mnemonic == "smull" || Mnemonic == "mov" || Mnemonic == "mla" ||
5434 Mnemonic == "smlal" || Mnemonic == "umlal" || Mnemonic == "umull"));
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005435
Tim Northover2c45a382013-06-26 16:52:40 +00005436 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
Alexander Kornienkofb37cfa2015-04-14 15:32:58 +00005437 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
Saleem Abdulrasool27351f22014-05-14 03:47:39 +00005438 Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic == "udf" ||
5439 Mnemonic.startswith("crc32") || Mnemonic.startswith("cps") ||
Alexander Kornienkofb37cfa2015-04-14 15:32:58 +00005440 Mnemonic.startswith("vsel") || Mnemonic == "vmaxnm" ||
5441 Mnemonic == "vminnm" || Mnemonic == "vcvta" || Mnemonic == "vcvtn" ||
5442 Mnemonic == "vcvtp" || Mnemonic == "vcvtm" || Mnemonic == "vrinta" ||
5443 Mnemonic == "vrintn" || Mnemonic == "vrintp" || Mnemonic == "vrintm" ||
5444 Mnemonic.startswith("aes") || Mnemonic == "hvc" ||
Amara Emerson33089092013-09-19 11:59:01 +00005445 Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") ||
5446 (FullInst.startswith("vmull") && FullInst.endswith(".p64"))) {
Tim Northover2c45a382013-06-26 16:52:40 +00005447 // These mnemonics are never predicable
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005448 CanAcceptPredicationCode = false;
Tim Northover2c45a382013-06-26 16:52:40 +00005449 } else if (!isThumb()) {
5450 // Some instructions are only predicable in Thumb mode
Alexander Kornienkofb37cfa2015-04-14 15:32:58 +00005451 CanAcceptPredicationCode =
5452 Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
Tim Northover2c45a382013-06-26 16:52:40 +00005453 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
5454 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
5455 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
Alexander Kornienkofb37cfa2015-04-14 15:32:58 +00005456 Mnemonic != "ldc2" && Mnemonic != "ldc2l" && Mnemonic != "stc2" &&
5457 Mnemonic != "stc2l" && !Mnemonic.startswith("rfe") &&
5458 !Mnemonic.startswith("srs");
Tim Northover2c45a382013-06-26 16:52:40 +00005459 } else if (isThumbOne()) {
Tim Northoverf86d1f02013-10-07 11:10:47 +00005460 if (hasV6MOps())
5461 CanAcceptPredicationCode = Mnemonic != "movs";
5462 else
5463 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
Jim Grosbach6c45b752011-09-16 16:39:25 +00005464 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005465 CanAcceptPredicationCode = true;
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005466}
5467
Jim Grosbach7283da92011-08-16 21:12:37 +00005468bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
David Blaikie960ea3f2014-06-08 16:18:35 +00005469 OperandVector &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005470 // FIXME: This is all horribly hacky. We really need a better way to deal
5471 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00005472
5473 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
5474 // another does not. Specifically, the MOVW instruction does not. So we
5475 // special case it here and remove the defaulted (non-setting) cc_out
5476 // operand if that's the instruction we're trying to match.
5477 //
5478 // We do this as post-processing of the explicit operands rather than just
5479 // conditionally adding the cc_out in the first place because we need
5480 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00005481 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Asiri Rathnayake52376ac2015-01-06 15:55:09 +00005482 !static_cast<ARMOperand &>(*Operands[4]).isModImm() &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005483 static_cast<ARMOperand &>(*Operands[4]).isImm0_65535Expr() &&
5484 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0)
Jim Grosbach7283da92011-08-16 21:12:37 +00005485 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005486
5487 // Register-register 'add' for thumb does not have a cc_out operand
5488 // when there are only two register operands.
5489 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005490 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5491 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5492 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0)
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005493 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005494 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005495 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
5496 // have to check the immediate range here since Thumb2 has a variant
5497 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005498 if (((isThumb() && Mnemonic == "add") ||
5499 (isThumbTwo() && Mnemonic == "sub")) &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005500 Operands.size() == 6 && static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5501 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5502 static_cast<ARMOperand &>(*Operands[4]).getReg() == ARM::SP &&
5503 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5504 ((Mnemonic == "add" && static_cast<ARMOperand &>(*Operands[5]).isReg()) ||
5505 static_cast<ARMOperand &>(*Operands[5]).isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005506 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005507 // For Thumb2, add/sub immediate does not have a cc_out operand for the
5508 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005509 // selecting via the generic "add" mnemonic, so to know that we
5510 // should remove the cc_out operand, we have to explicitly check that
5511 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005512 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005513 Operands.size() == 6 && static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5514 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5515 static_cast<ARMOperand &>(*Operands[5]).isImm()) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005516 // Nest conditions rather than one big 'if' statement for readability.
5517 //
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005518 // If both registers are low, we're in an IT block, and the immediate is
5519 // in range, we should use encoding T1 instead, which has a cc_out.
5520 if (inITBlock() &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005521 isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) &&
5522 isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) &&
5523 static_cast<ARMOperand &>(*Operands[5]).isImm0_7())
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005524 return false;
Tilmann Schelleref5666f2013-07-03 20:38:01 +00005525 // Check against T3. If the second register is the PC, this is an
5526 // alternate form of ADR, which uses encoding T4, so check for that too.
David Blaikie960ea3f2014-06-08 16:18:35 +00005527 if (static_cast<ARMOperand &>(*Operands[4]).getReg() != ARM::PC &&
5528 static_cast<ARMOperand &>(*Operands[5]).isT2SOImm())
Tilmann Schelleref5666f2013-07-03 20:38:01 +00005529 return false;
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005530
5531 // Otherwise, we use encoding T4, which does not have a cc_out
5532 // operand.
5533 return true;
5534 }
5535
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005536 // The thumb2 multiply instruction doesn't have a CCOut register, so
5537 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
5538 // use the 16-bit encoding or not.
5539 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005540 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5541 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5542 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5543 static_cast<ARMOperand &>(*Operands[5]).isReg() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005544 // If the registers aren't low regs, the destination reg isn't the
5545 // same as one of the source regs, or the cc_out operand is zero
5546 // outside of an IT block, we have to use the 32-bit encoding, so
5547 // remove the cc_out operand.
David Blaikie960ea3f2014-06-08 16:18:35 +00005548 (!isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) ||
5549 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) ||
5550 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[5]).getReg()) ||
5551 !inITBlock() || (static_cast<ARMOperand &>(*Operands[3]).getReg() !=
5552 static_cast<ARMOperand &>(*Operands[5]).getReg() &&
5553 static_cast<ARMOperand &>(*Operands[3]).getReg() !=
5554 static_cast<ARMOperand &>(*Operands[4]).getReg())))
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005555 return true;
5556
Jim Grosbachefa7e952011-11-15 19:55:16 +00005557 // Also check the 'mul' syntax variant that doesn't specify an explicit
5558 // destination register.
5559 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005560 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5561 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5562 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
Jim Grosbachefa7e952011-11-15 19:55:16 +00005563 // If the registers aren't low regs or the cc_out operand is zero
5564 // outside of an IT block, we have to use the 32-bit encoding, so
5565 // remove the cc_out operand.
David Blaikie960ea3f2014-06-08 16:18:35 +00005566 (!isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) ||
5567 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) ||
Jim Grosbachefa7e952011-11-15 19:55:16 +00005568 !inITBlock()))
5569 return true;
5570
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005571
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005572
Jim Grosbach4b701af2011-08-24 21:42:27 +00005573 // Register-register 'add/sub' for thumb does not have a cc_out operand
5574 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
5575 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
5576 // right, this will result in better diagnostics (which operand is off)
5577 // anyway.
5578 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
5579 (Operands.size() == 5 || Operands.size() == 6) &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005580 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5581 static_cast<ARMOperand &>(*Operands[3]).getReg() == ARM::SP &&
5582 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5583 (static_cast<ARMOperand &>(*Operands[4]).isImm() ||
Jim Grosbachdf5a2442012-04-10 17:31:55 +00005584 (Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005585 static_cast<ARMOperand &>(*Operands[5]).isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005586 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005587
Jim Grosbach7283da92011-08-16 21:12:37 +00005588 return false;
5589}
5590
David Blaikie960ea3f2014-06-08 16:18:35 +00005591bool ARMAsmParser::shouldOmitPredicateOperand(StringRef Mnemonic,
5592 OperandVector &Operands) {
Joey Goulye8602552013-07-19 16:34:16 +00005593 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
5594 unsigned RegIdx = 3;
5595 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005596 static_cast<ARMOperand &>(*Operands[2]).getToken() == ".f32") {
5597 if (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
5598 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".f32")
Joey Goulye8602552013-07-19 16:34:16 +00005599 RegIdx = 4;
5600
David Blaikie960ea3f2014-06-08 16:18:35 +00005601 if (static_cast<ARMOperand &>(*Operands[RegIdx]).isReg() &&
5602 (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(
5603 static_cast<ARMOperand &>(*Operands[RegIdx]).getReg()) ||
5604 ARMMCRegisterClasses[ARM::QPRRegClassID].contains(
5605 static_cast<ARMOperand &>(*Operands[RegIdx]).getReg())))
Joey Goulye8602552013-07-19 16:34:16 +00005606 return true;
5607 }
Joey Goulyf520d5e2013-07-19 16:45:16 +00005608 return false;
Joey Goulye8602552013-07-19 16:34:16 +00005609}
5610
Jim Grosbach12952fe2011-11-11 23:08:10 +00005611static bool isDataTypeToken(StringRef Tok) {
5612 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
5613 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
5614 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
5615 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
5616 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
5617 Tok == ".f" || Tok == ".d";
5618}
5619
5620// FIXME: This bit should probably be handled via an explicit match class
5621// in the .td files that matches the suffix instead of having it be
5622// a literal string token the way it is now.
5623static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
5624 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
5625}
Tim Northover26bb14e2014-08-18 11:49:42 +00005626static void applyMnemonicAliases(StringRef &Mnemonic, uint64_t Features,
Chad Rosier9f7a2212013-04-18 22:35:36 +00005627 unsigned VariantID);
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005628
5629static bool RequiresVFPRegListValidation(StringRef Inst,
5630 bool &AcceptSinglePrecisionOnly,
5631 bool &AcceptDoublePrecisionOnly) {
5632 if (Inst.size() < 7)
5633 return false;
5634
5635 if (Inst.startswith("fldm") || Inst.startswith("fstm")) {
5636 StringRef AddressingMode = Inst.substr(4, 2);
5637 if (AddressingMode == "ia" || AddressingMode == "db" ||
5638 AddressingMode == "ea" || AddressingMode == "fd") {
5639 AcceptSinglePrecisionOnly = Inst[6] == 's';
5640 AcceptDoublePrecisionOnly = Inst[6] == 'd' || Inst[6] == 'x';
5641 return true;
5642 }
5643 }
5644
5645 return false;
5646}
5647
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005648/// Parse an arm instruction mnemonic followed by its operands.
Chad Rosierf0e87202012-10-25 20:41:34 +00005649bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
David Blaikie960ea3f2014-06-08 16:18:35 +00005650 SMLoc NameLoc, OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00005651 MCAsmParser &Parser = getParser();
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005652 // FIXME: Can this be done via tablegen in some fashion?
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005653 bool RequireVFPRegisterListCheck;
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005654 bool AcceptSinglePrecisionOnly;
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005655 bool AcceptDoublePrecisionOnly;
5656 RequireVFPRegisterListCheck =
5657 RequiresVFPRegListValidation(Name, AcceptSinglePrecisionOnly,
5658 AcceptDoublePrecisionOnly);
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005659
Jim Grosbach8be2f652011-12-09 23:34:09 +00005660 // Apply mnemonic aliases before doing anything else, as the destination
Saleem Abdulrasoola1937cb2013-12-29 17:58:31 +00005661 // mnemonic may include suffices and we want to handle them normally.
Jim Grosbach8be2f652011-12-09 23:34:09 +00005662 // The generic tblgen'erated code does this later, at the start of
5663 // MatchInstructionImpl(), but that's too late for aliases that include
5664 // any sort of suffix.
Tim Northover26bb14e2014-08-18 11:49:42 +00005665 uint64_t AvailableFeatures = getAvailableFeatures();
Chad Rosier9f7a2212013-04-18 22:35:36 +00005666 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5667 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
Jim Grosbach8be2f652011-12-09 23:34:09 +00005668
Jim Grosbachab5830e2011-12-14 02:16:11 +00005669 // First check for the ARM-specific .req directive.
5670 if (Parser.getTok().is(AsmToken::Identifier) &&
5671 Parser.getTok().getIdentifier() == ".req") {
5672 parseDirectiveReq(Name, NameLoc);
5673 // We always return 'error' for this, as we're done with this
5674 // statement and don't need to match the 'instruction."
5675 return true;
5676 }
5677
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005678 // Create the leading tokens for the mnemonic, split by '.' characters.
5679 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005680 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005681
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005682 // Split out the predication code and carry setting flag from the mnemonic.
5683 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005684 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005685 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005686 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005687 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005688 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005689
Jim Grosbach1c171b12011-08-25 17:23:55 +00005690 // In Thumb1, only the branch (B) instruction can be predicated.
5691 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005692 Parser.eatToEndOfStatement();
Jim Grosbach1c171b12011-08-25 17:23:55 +00005693 return Error(NameLoc, "conditional execution not supported in Thumb1");
5694 }
5695
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005696 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5697
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005698 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5699 // is the mask as it will be for the IT encoding if the conditional
5700 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5701 // where the conditional bit0 is zero, the instruction post-processing
5702 // will adjust the mask accordingly.
5703 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00005704 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5705 if (ITMask.size() > 3) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005706 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005707 return Error(Loc, "too many conditions on IT instruction");
5708 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005709 unsigned Mask = 8;
5710 for (unsigned i = ITMask.size(); i != 0; --i) {
5711 char pos = ITMask[i - 1];
5712 if (pos != 't' && pos != 'e') {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005713 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005714 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005715 }
5716 Mask >>= 1;
5717 if (ITMask[i - 1] == 't')
5718 Mask |= 8;
5719 }
Jim Grosbached16ec42011-08-29 22:24:09 +00005720 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005721 }
5722
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005723 // FIXME: This is all a pretty gross hack. We should automatically handle
5724 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00005725
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005726 // Next, add the CCOut and ConditionCode operands, if needed.
5727 //
5728 // For mnemonics which can ever incorporate a carry setting bit or predication
5729 // code, our matching model involves us always generating CCOut and
5730 // ConditionCode operands to match the mnemonic "as written" and then we let
5731 // the matcher deal with finding the right instruction or generating an
5732 // appropriate error.
5733 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Amara Emerson33089092013-09-19 11:59:01 +00005734 getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005735
Jim Grosbach03a8a162011-07-14 22:04:21 +00005736 // If we had a carry-set on an instruction that can't do that, issue an
5737 // error.
5738 if (!CanAcceptCarrySet && CarrySetting) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005739 Parser.eatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005740 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00005741 "' can not set flags, but 's' suffix specified");
5742 }
Jim Grosbach0a547702011-07-22 17:44:50 +00005743 // If we had a predication code on an instruction that can't do that, issue an
5744 // error.
5745 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005746 Parser.eatToEndOfStatement();
Jim Grosbach0a547702011-07-22 17:44:50 +00005747 return Error(NameLoc, "instruction '" + Mnemonic +
5748 "' is not predicable, but condition code specified");
5749 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00005750
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005751 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00005752 if (CanAcceptCarrySet) {
5753 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005754 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00005755 Loc));
5756 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005757
5758 // Add the predication code operand, if necessary.
5759 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005760 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5761 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005762 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00005763 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005764 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005765
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005766 // Add the processor imod operand, if necessary.
5767 if (ProcessorIMod) {
5768 Operands.push_back(ARMOperand::CreateImm(
5769 MCConstantExpr::Create(ProcessorIMod, getContext()),
5770 NameLoc, NameLoc));
Oliver Stannard1ae8b472014-09-24 14:20:01 +00005771 } else if (Mnemonic == "cps" && isMClass()) {
5772 return Error(NameLoc, "instruction 'cps' requires effect for M-class");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005773 }
5774
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005775 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005776 while (Next != StringRef::npos) {
5777 Start = Next;
5778 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005779 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005780
Jim Grosbach12952fe2011-11-11 23:08:10 +00005781 // Some NEON instructions have an optional datatype suffix that is
5782 // completely ignored. Check for that.
5783 if (isDataTypeToken(ExtraToken) &&
5784 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5785 continue;
5786
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005787 // For for ARM mode generate an error if the .n qualifier is used.
5788 if (ExtraToken == ".n" && !isThumb()) {
5789 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
Saleem Abdulrasoolbdae4b82014-01-12 05:25:44 +00005790 Parser.eatToEndOfStatement();
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005791 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5792 "arm mode");
5793 }
5794
5795 // The .n qualifier is always discarded as that is what the tables
5796 // and matcher expect. In ARM mode the .w qualifier has no effect,
5797 // so discard it to avoid errors that can be caused by the matcher.
5798 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00005799 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5800 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5801 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005802 }
5803
5804 // Read the remaining operands.
5805 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005806 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005807 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005808 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005809 return true;
5810 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005811
5812 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005813 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005814
5815 // Parse and remember the operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005816 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005817 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005818 return true;
5819 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005820 }
5821 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005822
Chris Lattnera2a9d162010-09-11 16:18:25 +00005823 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005824 SMLoc Loc = getLexer().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005825 Parser.eatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005826 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005827 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005828
Chris Lattner91689c12010-09-08 05:10:46 +00005829 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005830
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005831 if (RequireVFPRegisterListCheck) {
David Blaikie960ea3f2014-06-08 16:18:35 +00005832 ARMOperand &Op = static_cast<ARMOperand &>(*Operands.back());
5833 if (AcceptSinglePrecisionOnly && !Op.isSPRRegList())
5834 return Error(Op.getStartLoc(),
Saleem Abdulrasoolaca443c2013-12-29 18:53:16 +00005835 "VFP/Neon single precision register expected");
David Blaikie960ea3f2014-06-08 16:18:35 +00005836 if (AcceptDoublePrecisionOnly && !Op.isDPRRegList())
5837 return Error(Op.getStartLoc(),
Saleem Abdulrasoolaca443c2013-12-29 18:53:16 +00005838 "VFP/Neon double precision register expected");
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005839 }
5840
Jim Grosbach7283da92011-08-16 21:12:37 +00005841 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5842 // do and don't have a cc_out optional-def operand. With some spot-checks
5843 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005844 // parse and adjust accordingly before actually matching. We shouldn't ever
5845 // try to remove a cc_out operand that was explicitly set on the the
5846 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5847 // table driven matcher doesn't fit well with the ARM instruction set.
David Blaikie960ea3f2014-06-08 16:18:35 +00005848 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands))
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005849 Operands.erase(Operands.begin() + 1);
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005850
Joey Goulye8602552013-07-19 16:34:16 +00005851 // Some instructions have the same mnemonic, but don't always
5852 // have a predicate. Distinguish them here and delete the
5853 // predicate if needed.
David Blaikie960ea3f2014-06-08 16:18:35 +00005854 if (shouldOmitPredicateOperand(Mnemonic, Operands))
Joey Goulye8602552013-07-19 16:34:16 +00005855 Operands.erase(Operands.begin() + 1);
Joey Goulye8602552013-07-19 16:34:16 +00005856
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005857 // ARM mode 'blx' need special handling, as the register operand version
5858 // is predicable, but the label operand version is not. So, we can't rely
5859 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005860 // a k_CondCode operand in the list. If we're trying to match the label
5861 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005862 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005863 static_cast<ARMOperand &>(*Operands[2]).isImm())
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005864 Operands.erase(Operands.begin() + 1);
Jim Grosbach8cffa282011-08-11 23:51:13 +00005865
Weiming Zhao8f56f882012-11-16 21:55:34 +00005866 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5867 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5868 // a single GPRPair reg operand is used in the .td file to replace the two
5869 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5870 // expressed as a GPRPair, so we have to manually merge them.
5871 // FIXME: We would really like to be able to tablegen'erate this.
5872 if (!isThumb() && Operands.size() > 4 &&
Joey Goulye6d165c2013-08-27 17:38:16 +00005873 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
5874 Mnemonic == "stlexd")) {
5875 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
Weiming Zhao8f56f882012-11-16 21:55:34 +00005876 unsigned Idx = isLoad ? 2 : 3;
David Blaikie960ea3f2014-06-08 16:18:35 +00005877 ARMOperand &Op1 = static_cast<ARMOperand &>(*Operands[Idx]);
5878 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[Idx + 1]);
Weiming Zhao8f56f882012-11-16 21:55:34 +00005879
5880 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5881 // Adjust only if Op1 and Op2 are GPRs.
David Blaikie960ea3f2014-06-08 16:18:35 +00005882 if (Op1.isReg() && Op2.isReg() && MRC.contains(Op1.getReg()) &&
5883 MRC.contains(Op2.getReg())) {
5884 unsigned Reg1 = Op1.getReg();
5885 unsigned Reg2 = Op2.getReg();
Weiming Zhao8f56f882012-11-16 21:55:34 +00005886 unsigned Rt = MRI->getEncodingValue(Reg1);
5887 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5888
5889 // Rt2 must be Rt + 1 and Rt must be even.
5890 if (Rt + 1 != Rt2 || (Rt & 1)) {
David Blaikie960ea3f2014-06-08 16:18:35 +00005891 Error(Op2.getStartLoc(), isLoad
5892 ? "destination operands must be sequential"
5893 : "source operands must be sequential");
Weiming Zhao8f56f882012-11-16 21:55:34 +00005894 return true;
5895 }
5896 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5897 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
David Blaikie960ea3f2014-06-08 16:18:35 +00005898 Operands[Idx] =
5899 ARMOperand::CreateReg(NewReg, Op1.getStartLoc(), Op2.getEndLoc());
5900 Operands.erase(Operands.begin() + Idx + 1);
Weiming Zhao8f56f882012-11-16 21:55:34 +00005901 }
5902 }
5903
Renato Golin36c626e2014-09-26 16:14:29 +00005904 // If first 2 operands of a 3 operand instruction are the same
5905 // then transform to 2 operand version of the same instruction
5906 // e.g. 'adds r0, r0, #1' transforms to 'adds r0, #1'
5907 // FIXME: We would really like to be able to tablegen'erate this.
5908 if (isThumbOne() && Operands.size() == 6 &&
5909 (Mnemonic == "add" || Mnemonic == "sub" || Mnemonic == "and" ||
5910 Mnemonic == "eor" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
5911 Mnemonic == "asr" || Mnemonic == "adc" || Mnemonic == "sbc" ||
5912 Mnemonic == "ror" || Mnemonic == "orr" || Mnemonic == "bic")) {
5913 ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]);
5914 ARMOperand &Op4 = static_cast<ARMOperand &>(*Operands[4]);
5915 ARMOperand &Op5 = static_cast<ARMOperand &>(*Operands[5]);
5916
5917 // If both registers are the same then remove one of them from
5918 // the operand list.
5919 if (Op3.isReg() && Op4.isReg() && Op3.getReg() == Op4.getReg()) {
5920 // If 3rd operand (variable Op5) is a register and the instruction is adds/sub
5921 // then do not transform as the backend already handles this instruction
5922 // correctly.
5923 if (!Op5.isReg() || !((Mnemonic == "add" && CarrySetting) || Mnemonic == "sub")) {
5924 Operands.erase(Operands.begin() + 3);
5925 if (Mnemonic == "add" && !CarrySetting) {
5926 // Special case for 'add' (not 'adds') instruction must
5927 // remove the CCOut operand as well.
5928 Operands.erase(Operands.begin() + 1);
5929 }
5930 }
5931 }
5932 }
5933
5934 // If instruction is 'add' and first two register operands
5935 // use SP register, then remove one of the SP registers from
5936 // the instruction.
5937 // FIXME: We would really like to be able to tablegen'erate this.
5938 if (isThumbOne() && Operands.size() == 5 && Mnemonic == "add" && !CarrySetting) {
5939 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[2]);
5940 ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]);
5941 if (Op2.isReg() && Op3.isReg() && Op2.getReg() == ARM::SP && Op3.getReg() == ARM::SP) {
5942 Operands.erase(Operands.begin() + 2);
5943 }
5944 }
5945
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +00005946 // GNU Assembler extension (compatibility)
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005947 if ((Mnemonic == "ldrd" || Mnemonic == "strd")) {
David Blaikie960ea3f2014-06-08 16:18:35 +00005948 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[2]);
5949 ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]);
5950 if (Op3.isMem()) {
5951 assert(Op2.isReg() && "expected register argument");
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005952
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005953 unsigned SuperReg = MRI->getMatchingSuperReg(
David Blaikie960ea3f2014-06-08 16:18:35 +00005954 Op2.getReg(), ARM::gsub_0, &MRI->getRegClass(ARM::GPRPairRegClassID));
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005955
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005956 assert(SuperReg && "expected register pair");
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005957
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005958 unsigned PairedReg = MRI->getSubReg(SuperReg, ARM::gsub_1);
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005959
David Blaikie960ea3f2014-06-08 16:18:35 +00005960 Operands.insert(
5961 Operands.begin() + 3,
5962 ARMOperand::CreateReg(PairedReg, Op2.getStartLoc(), Op2.getEndLoc()));
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005963 }
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +00005964 }
5965
Kevin Enderby78f95722013-07-31 21:05:30 +00005966 // FIXME: As said above, this is all a pretty gross hack. This instruction
5967 // does not fit with other "subs" and tblgen.
5968 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5969 // so the Mnemonic is the original name "subs" and delete the predicate
5970 // operand so it will match the table entry.
5971 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005972 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5973 static_cast<ARMOperand &>(*Operands[3]).getReg() == ARM::PC &&
5974 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5975 static_cast<ARMOperand &>(*Operands[4]).getReg() == ARM::LR &&
5976 static_cast<ARMOperand &>(*Operands[5]).isImm()) {
5977 Operands.front() = ARMOperand::CreateToken(Name, NameLoc);
Kevin Enderby78f95722013-07-31 21:05:30 +00005978 Operands.erase(Operands.begin() + 1);
Kevin Enderby78f95722013-07-31 21:05:30 +00005979 }
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005980 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005981}
5982
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005983// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005984
5985// return 'true' if register list contains non-low GPR registers,
5986// 'false' otherwise. If Reg is in the register list or is HiReg, set
5987// 'containsReg' to true.
5988static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5989 unsigned HiReg, bool &containsReg) {
5990 containsReg = false;
5991 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5992 unsigned OpReg = Inst.getOperand(i).getReg();
5993 if (OpReg == Reg)
5994 containsReg = true;
5995 // Anything other than a low register isn't legal here.
5996 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5997 return true;
5998 }
5999 return false;
6000}
6001
Rafael Espindola5403da42014-12-04 14:10:20 +00006002// Check if the specified regisgter is in the register list of the inst,
Jim Grosbacha31f2232011-09-07 18:05:34 +00006003// starting at the indicated operand number.
Rafael Espindola5403da42014-12-04 14:10:20 +00006004static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
Jim Grosbacha31f2232011-09-07 18:05:34 +00006005 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
6006 unsigned OpReg = Inst.getOperand(i).getReg();
Rafael Espindola5403da42014-12-04 14:10:20 +00006007 if (OpReg == Reg)
6008 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00006009 }
6010 return false;
6011}
6012
Richard Barton8d519fe2013-09-05 14:14:19 +00006013// Return true if instruction has the interesting property of being
6014// allowed in IT blocks, but not being predicable.
6015static bool instIsBreakpoint(const MCInst &Inst) {
6016 return Inst.getOpcode() == ARM::tBKPT ||
6017 Inst.getOpcode() == ARM::BKPT ||
6018 Inst.getOpcode() == ARM::tHLT ||
6019 Inst.getOpcode() == ARM::HLT;
6020
6021}
6022
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006023bool ARMAsmParser::validatetLDMRegList(MCInst Inst,
6024 const OperandVector &Operands,
Jyoti Allur5a139142015-01-14 10:48:16 +00006025 unsigned ListNo, bool IsARPop) {
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006026 const ARMOperand &Op = static_cast<const ARMOperand &>(*Operands[ListNo]);
6027 bool HasWritebackToken = Op.isToken() && Op.getToken() == "!";
6028
6029 bool ListContainsSP = listContainsReg(Inst, ListNo, ARM::SP);
6030 bool ListContainsLR = listContainsReg(Inst, ListNo, ARM::LR);
6031 bool ListContainsPC = listContainsReg(Inst, ListNo, ARM::PC);
6032
Jyoti Allur5a139142015-01-14 10:48:16 +00006033 if (!IsARPop && ListContainsSP)
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006034 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(),
6035 "SP may not be in the register list");
6036 else if (ListContainsPC && ListContainsLR)
6037 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(),
6038 "PC and LR may not be in the register list simultaneously");
6039 else if (inITBlock() && !lastInITBlock() && ListContainsPC)
6040 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(),
6041 "instruction must be outside of IT block or the last "
6042 "instruction in an IT block");
6043 return false;
6044}
6045
6046bool ARMAsmParser::validatetSTMRegList(MCInst Inst,
6047 const OperandVector &Operands,
6048 unsigned ListNo) {
6049 const ARMOperand &Op = static_cast<const ARMOperand &>(*Operands[ListNo]);
6050 bool HasWritebackToken = Op.isToken() && Op.getToken() == "!";
6051
6052 bool ListContainsSP = listContainsReg(Inst, ListNo, ARM::SP);
6053 bool ListContainsPC = listContainsReg(Inst, ListNo, ARM::PC);
6054
6055 if (ListContainsSP && ListContainsPC)
6056 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(),
6057 "SP and PC may not be in the register list");
6058 else if (ListContainsSP)
6059 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(),
6060 "SP may not be in the register list");
6061 else if (ListContainsPC)
6062 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(),
6063 "PC may not be in the register list");
6064 return false;
6065}
6066
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006067// FIXME: We would really like to be able to tablegen'erate this.
David Blaikie960ea3f2014-06-08 16:18:35 +00006068bool ARMAsmParser::validateInstruction(MCInst &Inst,
6069 const OperandVector &Operands) {
Joey Gouly0e76fa72013-09-12 10:28:05 +00006070 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00006071 SMLoc Loc = Operands[0]->getStartLoc();
Mihai Popaad18d3c2013-08-09 10:38:32 +00006072
Jim Grosbached16ec42011-08-29 22:24:09 +00006073 // Check the IT block state first.
Richard Barton8d519fe2013-09-05 14:14:19 +00006074 // NOTE: BKPT and HLT instructions have the interesting property of being
Tilmann Schellerbe904772013-09-30 17:57:30 +00006075 // allowed in IT blocks, but not being predicable. They just always execute.
Richard Barton8d519fe2013-09-05 14:14:19 +00006076 if (inITBlock() && !instIsBreakpoint(Inst)) {
Tilmann Schellerbe904772013-09-30 17:57:30 +00006077 unsigned Bit = 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00006078 if (ITState.FirstCond)
6079 ITState.FirstCond = false;
6080 else
Tilmann Schellerbe904772013-09-30 17:57:30 +00006081 Bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00006082 // The instruction must be predicable.
6083 if (!MCID.isPredicable())
6084 return Error(Loc, "instructions in IT block must be predicable");
6085 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
Tilmann Schellerbe904772013-09-30 17:57:30 +00006086 unsigned ITCond = Bit ? ITState.Cond :
Jim Grosbached16ec42011-08-29 22:24:09 +00006087 ARMCC::getOppositeCondition(ITState.Cond);
6088 if (Cond != ITCond) {
6089 // Find the condition code Operand to get its SMLoc information.
6090 SMLoc CondLoc;
Tilmann Schellerbe904772013-09-30 17:57:30 +00006091 for (unsigned I = 1; I < Operands.size(); ++I)
David Blaikie960ea3f2014-06-08 16:18:35 +00006092 if (static_cast<ARMOperand &>(*Operands[I]).isCondCode())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006093 CondLoc = Operands[I]->getStartLoc();
Jim Grosbached16ec42011-08-29 22:24:09 +00006094 return Error(CondLoc, "incorrect condition in IT block; got '" +
6095 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
6096 "', but expected '" +
6097 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
6098 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00006099 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00006100 } else if (isThumbTwo() && MCID.isPredicable() &&
6101 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Mihai Popaad18d3c2013-08-09 10:38:32 +00006102 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
6103 Inst.getOpcode() != ARM::t2Bcc)
Jim Grosbached16ec42011-08-29 22:24:09 +00006104 return Error(Loc, "predicated instructions must be in IT block");
6105
Tilmann Scheller255722b2013-09-30 16:11:48 +00006106 const unsigned Opcode = Inst.getOpcode();
6107 switch (Opcode) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00006108 case ARM::LDRD:
6109 case ARM::LDRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00006110 case ARM::LDRD_POST: {
Tilmann Scheller255722b2013-09-30 16:11:48 +00006111 const unsigned RtReg = Inst.getOperand(0).getReg();
6112
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00006113 // Rt can't be R14.
6114 if (RtReg == ARM::LR)
6115 return Error(Operands[3]->getStartLoc(),
6116 "Rt can't be R14");
Tilmann Scheller255722b2013-09-30 16:11:48 +00006117
6118 const unsigned Rt = MRI->getEncodingValue(RtReg);
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00006119 // Rt must be even-numbered.
6120 if ((Rt & 1) == 1)
6121 return Error(Operands[3]->getStartLoc(),
6122 "Rt must be even-numbered");
Tilmann Scheller255722b2013-09-30 16:11:48 +00006123
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006124 // Rt2 must be Rt + 1.
Tilmann Scheller255722b2013-09-30 16:11:48 +00006125 const unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006126 if (Rt2 != Rt + 1)
6127 return Error(Operands[3]->getStartLoc(),
6128 "destination operands must be sequential");
Tilmann Scheller255722b2013-09-30 16:11:48 +00006129
6130 if (Opcode == ARM::LDRD_PRE || Opcode == ARM::LDRD_POST) {
6131 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg());
6132 // For addressing modes with writeback, the base register needs to be
6133 // different from the destination registers.
6134 if (Rn == Rt || Rn == Rt2)
6135 return Error(Operands[3]->getStartLoc(),
6136 "base register needs to be different from destination "
6137 "registers");
6138 }
6139
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006140 return false;
6141 }
Tilmann Scheller88c8f162013-09-27 10:30:18 +00006142 case ARM::t2LDRDi8:
6143 case ARM::t2LDRD_PRE:
6144 case ARM::t2LDRD_POST: {
Tilmann Scheller041f7172013-09-27 10:38:11 +00006145 // Rt2 must be different from Rt.
Tilmann Scheller88c8f162013-09-27 10:30:18 +00006146 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
6147 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
6148 if (Rt2 == Rt)
6149 return Error(Operands[3]->getStartLoc(),
6150 "destination operands can't be identical");
6151 return false;
6152 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00006153 case ARM::STRD: {
6154 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00006155 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
6156 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00006157 if (Rt2 != Rt + 1)
6158 return Error(Operands[3]->getStartLoc(),
6159 "source operands must be sequential");
6160 return false;
6161 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00006162 case ARM::STRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00006163 case ARM::STRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006164 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00006165 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
6166 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006167 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00006168 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006169 "source operands must be sequential");
6170 return false;
6171 }
Tilmann Scheller3352a582014-07-23 12:38:17 +00006172 case ARM::STR_PRE_IMM:
6173 case ARM::STR_PRE_REG:
6174 case ARM::STR_POST_IMM:
Tilmann Scheller27272792014-07-23 13:03:47 +00006175 case ARM::STR_POST_REG:
Tilmann Scheller96ef72e2014-07-24 09:55:46 +00006176 case ARM::STRH_PRE:
6177 case ARM::STRH_POST:
Tilmann Scheller27272792014-07-23 13:03:47 +00006178 case ARM::STRB_PRE_IMM:
6179 case ARM::STRB_PRE_REG:
6180 case ARM::STRB_POST_IMM:
6181 case ARM::STRB_POST_REG: {
Tilmann Scheller3352a582014-07-23 12:38:17 +00006182 // Rt must be different from Rn.
6183 const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
6184 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(2).getReg());
6185
6186 if (Rt == Rn)
6187 return Error(Operands[3]->getStartLoc(),
6188 "source register and base register can't be identical");
6189 return false;
6190 }
Tilmann Scheller8ba74302014-08-01 11:08:51 +00006191 case ARM::LDR_PRE_IMM:
6192 case ARM::LDR_PRE_REG:
6193 case ARM::LDR_POST_IMM:
Tilmann Scheller8ff079c2014-08-01 11:33:47 +00006194 case ARM::LDR_POST_REG:
6195 case ARM::LDRH_PRE:
6196 case ARM::LDRH_POST:
6197 case ARM::LDRSH_PRE:
Tilmann Scheller7cc0ed42014-08-01 12:08:04 +00006198 case ARM::LDRSH_POST:
6199 case ARM::LDRB_PRE_IMM:
6200 case ARM::LDRB_PRE_REG:
6201 case ARM::LDRB_POST_IMM:
6202 case ARM::LDRB_POST_REG:
6203 case ARM::LDRSB_PRE:
6204 case ARM::LDRSB_POST: {
Tilmann Scheller8ba74302014-08-01 11:08:51 +00006205 // Rt must be different from Rn.
6206 const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
6207 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(2).getReg());
6208
6209 if (Rt == Rn)
6210 return Error(Operands[3]->getStartLoc(),
6211 "destination register and base register can't be identical");
6212 return false;
6213 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00006214 case ARM::SBFX:
6215 case ARM::UBFX: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00006216 // Width must be in range [1, 32-lsb].
6217 unsigned LSB = Inst.getOperand(2).getImm();
6218 unsigned Widthm1 = Inst.getOperand(3).getImm();
6219 if (Widthm1 >= 32 - LSB)
Jim Grosbach03f56d92011-07-27 21:09:25 +00006220 return Error(Operands[5]->getStartLoc(),
6221 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00006222 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00006223 }
Rafael Espindola5403da42014-12-04 14:10:20 +00006224 // Notionally handles ARM::tLDMIA_UPD too.
6225 case ARM::tLDMIA: {
6226 // If we're parsing Thumb2, the .w variant is available and handles
6227 // most cases that are normally illegal for a Thumb1 LDM instruction.
6228 // We'll make the transformation in processInstruction() if necessary.
6229 //
6230 // Thumb LDM instructions are writeback iff the base register is not
6231 // in the register list.
6232 unsigned Rn = Inst.getOperand(0).getReg();
6233 bool HasWritebackToken =
6234 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
6235 static_cast<ARMOperand &>(*Operands[3]).getToken() == "!");
6236 bool ListContainsBase;
6237 if (checkLowRegisterList(Inst, 3, Rn, 0, ListContainsBase) && !isThumbTwo())
6238 return Error(Operands[3 + HasWritebackToken]->getStartLoc(),
6239 "registers must be in range r0-r7");
6240 // If we should have writeback, then there should be a '!' token.
6241 if (!ListContainsBase && !HasWritebackToken && !isThumbTwo())
6242 return Error(Operands[2]->getStartLoc(),
6243 "writeback operator '!' expected");
6244 // If we should not have writeback, there must not be a '!'. This is
6245 // true even for the 32-bit wide encodings.
6246 if (ListContainsBase && HasWritebackToken)
6247 return Error(Operands[3]->getStartLoc(),
6248 "writeback operator '!' not allowed when base register "
6249 "in register list");
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006250
6251 if (validatetLDMRegList(Inst, Operands, 3))
6252 return true;
Rafael Espindola5403da42014-12-04 14:10:20 +00006253 break;
6254 }
Tim Northover08a86602013-10-22 19:00:39 +00006255 case ARM::LDMIA_UPD:
6256 case ARM::LDMDB_UPD:
6257 case ARM::LDMIB_UPD:
6258 case ARM::LDMDA_UPD:
6259 // ARM variants loading and updating the same register are only officially
6260 // UNPREDICTABLE on v7 upwards. Goodness knows what they did before.
6261 if (!hasV7Ops())
6262 break;
Rafael Espindola5403da42014-12-04 14:10:20 +00006263 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
6264 return Error(Operands.back()->getStartLoc(),
6265 "writeback register not allowed in register list");
6266 break;
Jyoti Allur3b686072014-10-22 10:41:14 +00006267 case ARM::t2LDMIA:
6268 case ARM::t2LDMDB:
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006269 if (validatetLDMRegList(Inst, Operands, 3))
6270 return true;
Rafael Espindola5403da42014-12-04 14:10:20 +00006271 break;
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006272 case ARM::t2STMIA:
6273 case ARM::t2STMDB:
6274 if (validatetSTMRegList(Inst, Operands, 3))
6275 return true;
6276 break;
Tim Northover08a86602013-10-22 19:00:39 +00006277 case ARM::t2LDMIA_UPD:
6278 case ARM::t2LDMDB_UPD:
6279 case ARM::t2STMIA_UPD:
Rafael Espindola5403da42014-12-04 14:10:20 +00006280 case ARM::t2STMDB_UPD: {
6281 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
6282 return Error(Operands.back()->getStartLoc(),
6283 "writeback register not allowed in register list");
6284
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006285 if (Opcode == ARM::t2LDMIA_UPD || Opcode == ARM::t2LDMDB_UPD) {
Saleem Abdulrasool0b5a8522014-12-18 16:16:53 +00006286 if (validatetLDMRegList(Inst, Operands, 3))
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006287 return true;
6288 } else {
Saleem Abdulrasool0b5a8522014-12-18 16:16:53 +00006289 if (validatetSTMRegList(Inst, Operands, 3))
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006290 return true;
6291 }
Rafael Espindola5403da42014-12-04 14:10:20 +00006292 break;
6293 }
Tim Northover8eaf1542013-11-12 21:32:41 +00006294 case ARM::sysLDMIA_UPD:
6295 case ARM::sysLDMDA_UPD:
6296 case ARM::sysLDMDB_UPD:
Rafael Espindola5403da42014-12-04 14:10:20 +00006297 case ARM::sysLDMIB_UPD:
6298 if (!listContainsReg(Inst, 3, ARM::PC))
6299 return Error(Operands[4]->getStartLoc(),
6300 "writeback register only allowed on system LDM "
6301 "if PC in register-list");
Tim Northover8eaf1542013-11-12 21:32:41 +00006302 break;
6303 case ARM::sysSTMIA_UPD:
6304 case ARM::sysSTMDA_UPD:
6305 case ARM::sysSTMDB_UPD:
6306 case ARM::sysSTMIB_UPD:
6307 return Error(Operands[2]->getStartLoc(),
6308 "system STM cannot have writeback register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00006309 case ARM::tMUL: {
6310 // The second source operand must be the same register as the destination
6311 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00006312 //
6313 // In this case, we must directly check the parsed operands because the
6314 // cvtThumbMultiply() function is written in such a way that it guarantees
6315 // this first statement is always true for the new Inst. Essentially, the
6316 // destination is unconditionally copied into the second source operand
6317 // without checking to see if it matches what we actually parsed.
David Blaikie960ea3f2014-06-08 16:18:35 +00006318 if (Operands.size() == 6 && (((ARMOperand &)*Operands[3]).getReg() !=
6319 ((ARMOperand &)*Operands[5]).getReg()) &&
6320 (((ARMOperand &)*Operands[3]).getReg() !=
6321 ((ARMOperand &)*Operands[4]).getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00006322 return Error(Operands[3]->getStartLoc(),
6323 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00006324 }
6325 break;
6326 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00006327 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
6328 // so only issue a diagnostic for thumb1. The instructions will be
6329 // switched to the t2 encodings in processInstruction() if necessary.
Rafael Espindola5403da42014-12-04 14:10:20 +00006330 case ARM::tPOP: {
6331 bool ListContainsBase;
6332 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, ListContainsBase) &&
6333 !isThumbTwo())
6334 return Error(Operands[2]->getStartLoc(),
6335 "registers must be in range r0-r7 or pc");
Jyoti Allur5a139142015-01-14 10:48:16 +00006336 if (validatetLDMRegList(Inst, Operands, 2, !isMClass()))
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006337 return true;
Rafael Espindola5403da42014-12-04 14:10:20 +00006338 break;
6339 }
Jim Grosbach38c59fc2011-08-22 23:17:34 +00006340 case ARM::tPUSH: {
Rafael Espindola5403da42014-12-04 14:10:20 +00006341 bool ListContainsBase;
6342 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, ListContainsBase) &&
6343 !isThumbTwo())
6344 return Error(Operands[2]->getStartLoc(),
6345 "registers must be in range r0-r7 or lr");
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006346 if (validatetSTMRegList(Inst, Operands, 2))
6347 return true;
Jim Grosbach38c59fc2011-08-22 23:17:34 +00006348 break;
6349 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00006350 case ARM::tSTMIA_UPD: {
Rafael Espindola5403da42014-12-04 14:10:20 +00006351 bool ListContainsBase, InvalidLowList;
6352 InvalidLowList = checkLowRegisterList(Inst, 4, Inst.getOperand(0).getReg(),
6353 0, ListContainsBase);
6354 if (InvalidLowList && !isThumbTwo())
6355 return Error(Operands[4]->getStartLoc(),
6356 "registers must be in range r0-r7");
6357
6358 // This would be converted to a 32-bit stm, but that's not valid if the
6359 // writeback register is in the list.
6360 if (InvalidLowList && ListContainsBase)
6361 return Error(Operands[4]->getStartLoc(),
6362 "writeback operator '!' not allowed when base register "
6363 "in register list");
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006364
6365 if (validatetSTMRegList(Inst, Operands, 4))
6366 return true;
Jim Grosbachd80d1692011-08-23 18:15:37 +00006367 break;
6368 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00006369 case ARM::tADDrSP: {
6370 // If the non-SP source operand and the destination operand are not the
6371 // same, we need thumb2 (for the wide encoding), or we have an error.
6372 if (!isThumbTwo() &&
6373 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
6374 return Error(Operands[4]->getStartLoc(),
6375 "source register must be the same as destination");
6376 }
6377 break;
6378 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00006379 // Final range checking for Thumb unconditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00006380 case ARM::tB:
David Blaikie960ea3f2014-06-08 16:18:35 +00006381 if (!(static_cast<ARMOperand &>(*Operands[2])).isSignedOffset<11, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006382 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00006383 break;
6384 case ARM::t2B: {
6385 int op = (Operands[2]->isImm()) ? 2 : 3;
David Blaikie960ea3f2014-06-08 16:18:35 +00006386 if (!static_cast<ARMOperand &>(*Operands[op]).isSignedOffset<24, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006387 return Error(Operands[op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00006388 break;
6389 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00006390 // Final range checking for Thumb conditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00006391 case ARM::tBcc:
David Blaikie960ea3f2014-06-08 16:18:35 +00006392 if (!static_cast<ARMOperand &>(*Operands[2]).isSignedOffset<8, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006393 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00006394 break;
6395 case ARM::t2Bcc: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00006396 int Op = (Operands[2]->isImm()) ? 2 : 3;
David Blaikie960ea3f2014-06-08 16:18:35 +00006397 if (!static_cast<ARMOperand &>(*Operands[Op]).isSignedOffset<20, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006398 return Error(Operands[Op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00006399 break;
6400 }
Kevin Enderbyb7e51f62014-04-18 23:06:39 +00006401 case ARM::MOVi16:
6402 case ARM::t2MOVi16:
6403 case ARM::t2MOVTi16:
6404 {
6405 // We want to avoid misleadingly allowing something like "mov r0, <symbol>"
6406 // especially when we turn it into a movw and the expression <symbol> does
6407 // not have a :lower16: or :upper16 as part of the expression. We don't
6408 // want the behavior of silently truncating, which can be unexpected and
6409 // lead to bugs that are difficult to find since this is an easy mistake
6410 // to make.
6411 int i = (Operands[3]->isImm()) ? 3 : 4;
David Blaikie960ea3f2014-06-08 16:18:35 +00006412 ARMOperand &Op = static_cast<ARMOperand &>(*Operands[i]);
6413 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm());
Kevin Enderbyb7e51f62014-04-18 23:06:39 +00006414 if (CE) break;
David Blaikie960ea3f2014-06-08 16:18:35 +00006415 const MCExpr *E = dyn_cast<MCExpr>(Op.getImm());
Kevin Enderbyb7e51f62014-04-18 23:06:39 +00006416 if (!E) break;
6417 const ARMMCExpr *ARM16Expr = dyn_cast<ARMMCExpr>(E);
6418 if (!ARM16Expr || (ARM16Expr->getKind() != ARMMCExpr::VK_ARM_HI16 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00006419 ARM16Expr->getKind() != ARMMCExpr::VK_ARM_LO16))
6420 return Error(
6421 Op.getStartLoc(),
6422 "immediate expression for mov requires :lower16: or :upper16");
6423 break;
6424 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006425 }
6426
6427 return false;
6428}
6429
Jim Grosbach1a747242012-01-23 23:45:44 +00006430static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00006431 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00006432 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006433 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006434 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
6435 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
6436 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
6437 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
6438 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
6439 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
6440 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
6441 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
6442 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006443
6444 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006445 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
6446 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
6447 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
6448 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
6449 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00006450
Jim Grosbach1e946a42012-01-24 00:43:12 +00006451 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
6452 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
6453 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
6454 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
6455 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00006456
Jim Grosbach1e946a42012-01-24 00:43:12 +00006457 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
6458 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
6459 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
6460 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
6461 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00006462
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006463 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006464 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
6465 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
6466 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
6467 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
6468 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
6469 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
6470 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
6471 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
6472 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
6473 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
6474 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
6475 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
6476 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
6477 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
6478 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006479
Jim Grosbach1a747242012-01-23 23:45:44 +00006480 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00006481 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
6482 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
6483 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
6484 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
6485 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
6486 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
6487 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
6488 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
6489 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
6490 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
6491 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
6492 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
6493 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
6494 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
6495 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
6496 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
6497 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
6498 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00006499
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006500 // VST4LN
6501 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
6502 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
6503 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
6504 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
6505 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
6506 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
6507 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
6508 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
6509 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
6510 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
6511 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
6512 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
6513 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
6514 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
6515 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
6516
Jim Grosbachda70eac2012-01-24 00:58:13 +00006517 // VST4
6518 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
6519 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
6520 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
6521 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
6522 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
6523 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
6524 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
6525 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
6526 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
6527 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
6528 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
6529 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
6530 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
6531 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
6532 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
6533 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
6534 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
6535 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00006536 }
6537}
6538
Jim Grosbach1a747242012-01-23 23:45:44 +00006539static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00006540 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00006541 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006542 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006543 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
6544 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
6545 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
6546 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
6547 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
6548 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
6549 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
6550 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
6551 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006552
6553 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006554 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
6555 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
6556 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
6557 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
6558 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
6559 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
6560 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
6561 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
6562 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
6563 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
6564 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
6565 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
6566 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
6567 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
6568 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006569
Jim Grosbachb78403c2012-01-24 23:47:04 +00006570 // VLD3DUP
6571 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
6572 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
6573 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
6574 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
Kevin Enderbyd88fec32014-04-08 18:00:52 +00006575 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
Jim Grosbachb78403c2012-01-24 23:47:04 +00006576 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
6577 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
6578 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
6579 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
6580 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
6581 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
6582 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
6583 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
6584 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
6585 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
6586 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
6587 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
6588 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
6589
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006590 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006591 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
6592 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
6593 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
6594 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
6595 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
6596 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
6597 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
6598 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
6599 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
6600 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
6601 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
6602 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
6603 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
6604 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
6605 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006606
6607 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00006608 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
6609 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
6610 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
6611 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
6612 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
6613 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
6614 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
6615 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
6616 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
6617 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
6618 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
6619 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
6620 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
6621 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
6622 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
6623 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
6624 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
6625 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00006626
Jim Grosbach14952a02012-01-24 18:37:25 +00006627 // VLD4LN
6628 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
6629 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
6630 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
Kevin Enderby8108f382014-03-26 19:35:40 +00006631 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
Jim Grosbach14952a02012-01-24 18:37:25 +00006632 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
6633 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
6634 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
6635 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
6636 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
6637 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
6638 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
6639 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
6640 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
6641 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
6642 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
6643
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006644 // VLD4DUP
6645 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
6646 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
6647 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
6648 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
6649 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
6650 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
6651 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
6652 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
6653 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
6654 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
6655 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
6656 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
6657 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
6658 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
6659 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
6660 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
6661 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
6662 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
6663
Jim Grosbached561fc2012-01-24 00:43:17 +00006664 // VLD4
6665 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
6666 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
6667 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
6668 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
6669 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
6670 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
6671 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
6672 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
6673 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
6674 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
6675 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
6676 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
6677 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
6678 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
6679 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
6680 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
6681 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
6682 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00006683 }
6684}
6685
David Blaikie960ea3f2014-06-08 16:18:35 +00006686bool ARMAsmParser::processInstruction(MCInst &Inst,
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +00006687 const OperandVector &Operands,
6688 MCStreamer &Out) {
Jim Grosbach8ba76c62011-08-11 17:35:48 +00006689 switch (Inst.getOpcode()) {
Saleem Abdulrasoolfb3950e2014-01-12 04:36:01 +00006690 // Alias for alternate form of 'ldr{,b}t Rt, [Rn], #imm' instruction.
6691 case ARM::LDRT_POST:
6692 case ARM::LDRBT_POST: {
6693 const unsigned Opcode =
6694 (Inst.getOpcode() == ARM::LDRT_POST) ? ARM::LDRT_POST_IMM
6695 : ARM::LDRBT_POST_IMM;
6696 MCInst TmpInst;
6697 TmpInst.setOpcode(Opcode);
6698 TmpInst.addOperand(Inst.getOperand(0));
6699 TmpInst.addOperand(Inst.getOperand(1));
6700 TmpInst.addOperand(Inst.getOperand(1));
6701 TmpInst.addOperand(MCOperand::CreateReg(0));
6702 TmpInst.addOperand(MCOperand::CreateImm(0));
6703 TmpInst.addOperand(Inst.getOperand(2));
6704 TmpInst.addOperand(Inst.getOperand(3));
6705 Inst = TmpInst;
6706 return true;
6707 }
6708 // Alias for alternate form of 'str{,b}t Rt, [Rn], #imm' instruction.
6709 case ARM::STRT_POST:
6710 case ARM::STRBT_POST: {
6711 const unsigned Opcode =
6712 (Inst.getOpcode() == ARM::STRT_POST) ? ARM::STRT_POST_IMM
6713 : ARM::STRBT_POST_IMM;
6714 MCInst TmpInst;
6715 TmpInst.setOpcode(Opcode);
6716 TmpInst.addOperand(Inst.getOperand(1));
6717 TmpInst.addOperand(Inst.getOperand(0));
6718 TmpInst.addOperand(Inst.getOperand(1));
6719 TmpInst.addOperand(MCOperand::CreateReg(0));
6720 TmpInst.addOperand(MCOperand::CreateImm(0));
6721 TmpInst.addOperand(Inst.getOperand(2));
6722 TmpInst.addOperand(Inst.getOperand(3));
6723 Inst = TmpInst;
6724 return true;
6725 }
Jim Grosbache974a6a2012-09-25 00:08:13 +00006726 // Alias for alternate form of 'ADR Rd, #imm' instruction.
6727 case ARM::ADDri: {
6728 if (Inst.getOperand(1).getReg() != ARM::PC ||
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +00006729 Inst.getOperand(5).getReg() != 0 ||
6730 !(Inst.getOperand(2).isExpr() || Inst.getOperand(2).isImm()))
Jim Grosbache974a6a2012-09-25 00:08:13 +00006731 return false;
6732 MCInst TmpInst;
6733 TmpInst.setOpcode(ARM::ADR);
6734 TmpInst.addOperand(Inst.getOperand(0));
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +00006735 if (Inst.getOperand(2).isImm()) {
Asiri Rathnayake7835e9b2014-12-09 13:14:58 +00006736 // Immediate (mod_imm) will be in its encoded form, we must unencode it
6737 // before passing it to the ADR instruction.
6738 unsigned Enc = Inst.getOperand(2).getImm();
6739 TmpInst.addOperand(MCOperand::CreateImm(
6740 ARM_AM::rotr32(Enc & 0xFF, (Enc & 0xF00) >> 7)));
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +00006741 } else {
6742 // Turn PC-relative expression into absolute expression.
6743 // Reading PC provides the start of the current instruction + 8 and
6744 // the transform to adr is biased by that.
6745 MCSymbol *Dot = getContext().CreateTempSymbol();
6746 Out.EmitLabel(Dot);
6747 const MCExpr *OpExpr = Inst.getOperand(2).getExpr();
6748 const MCExpr *InstPC = MCSymbolRefExpr::Create(Dot,
6749 MCSymbolRefExpr::VK_None,
6750 getContext());
6751 const MCExpr *Const8 = MCConstantExpr::Create(8, getContext());
6752 const MCExpr *ReadPC = MCBinaryExpr::CreateAdd(InstPC, Const8,
6753 getContext());
6754 const MCExpr *FixupAddr = MCBinaryExpr::CreateAdd(ReadPC, OpExpr,
6755 getContext());
6756 TmpInst.addOperand(MCOperand::CreateExpr(FixupAddr));
6757 }
Jim Grosbache974a6a2012-09-25 00:08:13 +00006758 TmpInst.addOperand(Inst.getOperand(3));
6759 TmpInst.addOperand(Inst.getOperand(4));
6760 Inst = TmpInst;
6761 return true;
6762 }
Jim Grosbach94298a92012-01-18 22:46:46 +00006763 // Aliases for alternate PC+imm syntax of LDR instructions.
6764 case ARM::t2LDRpcrel:
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00006765 // Select the narrow version if the immediate will fit.
6766 if (Inst.getOperand(1).getImm() > 0 &&
Amaury de la Vieuvilleeac0bad2013-06-18 08:13:05 +00006767 Inst.getOperand(1).getImm() <= 0xff &&
David Blaikie960ea3f2014-06-08 16:18:35 +00006768 !(static_cast<ARMOperand &>(*Operands[2]).isToken() &&
6769 static_cast<ARMOperand &>(*Operands[2]).getToken() == ".w"))
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00006770 Inst.setOpcode(ARM::tLDRpci);
6771 else
6772 Inst.setOpcode(ARM::t2LDRpci);
Jim Grosbach94298a92012-01-18 22:46:46 +00006773 return true;
6774 case ARM::t2LDRBpcrel:
6775 Inst.setOpcode(ARM::t2LDRBpci);
6776 return true;
6777 case ARM::t2LDRHpcrel:
6778 Inst.setOpcode(ARM::t2LDRHpci);
6779 return true;
6780 case ARM::t2LDRSBpcrel:
6781 Inst.setOpcode(ARM::t2LDRSBpci);
6782 return true;
6783 case ARM::t2LDRSHpcrel:
6784 Inst.setOpcode(ARM::t2LDRSHpci);
6785 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006786 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006787 case ARM::VST1LNdWB_register_Asm_8:
6788 case ARM::VST1LNdWB_register_Asm_16:
6789 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006790 MCInst TmpInst;
6791 // Shuffle the operands around so the lane index operand is in the
6792 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006793 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006794 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006795 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6796 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6797 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6798 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6799 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6800 TmpInst.addOperand(Inst.getOperand(1)); // lane
6801 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6802 TmpInst.addOperand(Inst.getOperand(6));
6803 Inst = TmpInst;
6804 return true;
6805 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006806
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006807 case ARM::VST2LNdWB_register_Asm_8:
6808 case ARM::VST2LNdWB_register_Asm_16:
6809 case ARM::VST2LNdWB_register_Asm_32:
6810 case ARM::VST2LNqWB_register_Asm_16:
6811 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006812 MCInst TmpInst;
6813 // Shuffle the operands around so the lane index operand is in the
6814 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006815 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006816 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006817 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6818 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6819 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6820 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6821 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006822 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6823 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006824 TmpInst.addOperand(Inst.getOperand(1)); // lane
6825 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6826 TmpInst.addOperand(Inst.getOperand(6));
6827 Inst = TmpInst;
6828 return true;
6829 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006830
6831 case ARM::VST3LNdWB_register_Asm_8:
6832 case ARM::VST3LNdWB_register_Asm_16:
6833 case ARM::VST3LNdWB_register_Asm_32:
6834 case ARM::VST3LNqWB_register_Asm_16:
6835 case ARM::VST3LNqWB_register_Asm_32: {
6836 MCInst TmpInst;
6837 // Shuffle the operands around so the lane index operand is in the
6838 // right place.
6839 unsigned Spacing;
6840 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6841 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6842 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6843 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6844 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6845 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6846 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6847 Spacing));
6848 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6849 Spacing * 2));
6850 TmpInst.addOperand(Inst.getOperand(1)); // lane
6851 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6852 TmpInst.addOperand(Inst.getOperand(6));
6853 Inst = TmpInst;
6854 return true;
6855 }
6856
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006857 case ARM::VST4LNdWB_register_Asm_8:
6858 case ARM::VST4LNdWB_register_Asm_16:
6859 case ARM::VST4LNdWB_register_Asm_32:
6860 case ARM::VST4LNqWB_register_Asm_16:
6861 case ARM::VST4LNqWB_register_Asm_32: {
6862 MCInst TmpInst;
6863 // Shuffle the operands around so the lane index operand is in the
6864 // right place.
6865 unsigned Spacing;
6866 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6867 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6868 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6869 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6870 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6871 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6872 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6873 Spacing));
6874 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6875 Spacing * 2));
6876 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6877 Spacing * 3));
6878 TmpInst.addOperand(Inst.getOperand(1)); // lane
6879 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6880 TmpInst.addOperand(Inst.getOperand(6));
6881 Inst = TmpInst;
6882 return true;
6883 }
6884
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006885 case ARM::VST1LNdWB_fixed_Asm_8:
6886 case ARM::VST1LNdWB_fixed_Asm_16:
6887 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006888 MCInst TmpInst;
6889 // Shuffle the operands around so the lane index operand is in the
6890 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006891 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006892 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006893 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6894 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6895 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6896 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6897 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6898 TmpInst.addOperand(Inst.getOperand(1)); // lane
6899 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6900 TmpInst.addOperand(Inst.getOperand(5));
6901 Inst = TmpInst;
6902 return true;
6903 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006904
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006905 case ARM::VST2LNdWB_fixed_Asm_8:
6906 case ARM::VST2LNdWB_fixed_Asm_16:
6907 case ARM::VST2LNdWB_fixed_Asm_32:
6908 case ARM::VST2LNqWB_fixed_Asm_16:
6909 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006910 MCInst TmpInst;
6911 // Shuffle the operands around so the lane index operand is in the
6912 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006913 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006914 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006915 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6916 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6917 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6918 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6919 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006920 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6921 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006922 TmpInst.addOperand(Inst.getOperand(1)); // lane
6923 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6924 TmpInst.addOperand(Inst.getOperand(5));
6925 Inst = TmpInst;
6926 return true;
6927 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006928
6929 case ARM::VST3LNdWB_fixed_Asm_8:
6930 case ARM::VST3LNdWB_fixed_Asm_16:
6931 case ARM::VST3LNdWB_fixed_Asm_32:
6932 case ARM::VST3LNqWB_fixed_Asm_16:
6933 case ARM::VST3LNqWB_fixed_Asm_32: {
6934 MCInst TmpInst;
6935 // Shuffle the operands around so the lane index operand is in the
6936 // right place.
6937 unsigned Spacing;
6938 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6939 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6940 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6941 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6942 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6943 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6944 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6945 Spacing));
6946 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6947 Spacing * 2));
6948 TmpInst.addOperand(Inst.getOperand(1)); // lane
6949 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6950 TmpInst.addOperand(Inst.getOperand(5));
6951 Inst = TmpInst;
6952 return true;
6953 }
6954
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006955 case ARM::VST4LNdWB_fixed_Asm_8:
6956 case ARM::VST4LNdWB_fixed_Asm_16:
6957 case ARM::VST4LNdWB_fixed_Asm_32:
6958 case ARM::VST4LNqWB_fixed_Asm_16:
6959 case ARM::VST4LNqWB_fixed_Asm_32: {
6960 MCInst TmpInst;
6961 // Shuffle the operands around so the lane index operand is in the
6962 // right place.
6963 unsigned Spacing;
6964 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6965 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6966 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6967 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6968 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6969 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6970 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6971 Spacing));
6972 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6973 Spacing * 2));
6974 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6975 Spacing * 3));
6976 TmpInst.addOperand(Inst.getOperand(1)); // lane
6977 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6978 TmpInst.addOperand(Inst.getOperand(5));
6979 Inst = TmpInst;
6980 return true;
6981 }
6982
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006983 case ARM::VST1LNdAsm_8:
6984 case ARM::VST1LNdAsm_16:
6985 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006986 MCInst TmpInst;
6987 // Shuffle the operands around so the lane index operand is in the
6988 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006989 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006990 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006991 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6992 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6993 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6994 TmpInst.addOperand(Inst.getOperand(1)); // lane
6995 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6996 TmpInst.addOperand(Inst.getOperand(5));
6997 Inst = TmpInst;
6998 return true;
6999 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007000
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007001 case ARM::VST2LNdAsm_8:
7002 case ARM::VST2LNdAsm_16:
7003 case ARM::VST2LNdAsm_32:
7004 case ARM::VST2LNqAsm_16:
7005 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007006 MCInst TmpInst;
7007 // Shuffle the operands around so the lane index operand is in the
7008 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00007009 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007010 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007011 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7012 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7013 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00007014 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7015 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007016 TmpInst.addOperand(Inst.getOperand(1)); // lane
7017 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7018 TmpInst.addOperand(Inst.getOperand(5));
7019 Inst = TmpInst;
7020 return true;
7021 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00007022
7023 case ARM::VST3LNdAsm_8:
7024 case ARM::VST3LNdAsm_16:
7025 case ARM::VST3LNdAsm_32:
7026 case ARM::VST3LNqAsm_16:
7027 case ARM::VST3LNqAsm_32: {
7028 MCInst TmpInst;
7029 // Shuffle the operands around so the lane index operand is in the
7030 // right place.
7031 unsigned Spacing;
7032 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7033 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7034 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7035 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7036 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7037 Spacing));
7038 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7039 Spacing * 2));
7040 TmpInst.addOperand(Inst.getOperand(1)); // lane
7041 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7042 TmpInst.addOperand(Inst.getOperand(5));
7043 Inst = TmpInst;
7044 return true;
7045 }
7046
Jim Grosbach8e2722c2012-01-24 18:53:13 +00007047 case ARM::VST4LNdAsm_8:
7048 case ARM::VST4LNdAsm_16:
7049 case ARM::VST4LNdAsm_32:
7050 case ARM::VST4LNqAsm_16:
7051 case ARM::VST4LNqAsm_32: {
7052 MCInst TmpInst;
7053 // Shuffle the operands around so the lane index operand is in the
7054 // right place.
7055 unsigned Spacing;
7056 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7057 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7058 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7059 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7060 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7061 Spacing));
7062 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7063 Spacing * 2));
7064 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7065 Spacing * 3));
7066 TmpInst.addOperand(Inst.getOperand(1)); // lane
7067 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7068 TmpInst.addOperand(Inst.getOperand(5));
7069 Inst = TmpInst;
7070 return true;
7071 }
7072
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007073 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007074 case ARM::VLD1LNdWB_register_Asm_8:
7075 case ARM::VLD1LNdWB_register_Asm_16:
7076 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00007077 MCInst TmpInst;
7078 // Shuffle the operands around so the lane index operand is in the
7079 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007080 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007081 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00007082 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7083 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7084 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7085 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7086 TmpInst.addOperand(Inst.getOperand(4)); // Rm
7087 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7088 TmpInst.addOperand(Inst.getOperand(1)); // lane
7089 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
7090 TmpInst.addOperand(Inst.getOperand(6));
7091 Inst = TmpInst;
7092 return true;
7093 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007094
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007095 case ARM::VLD2LNdWB_register_Asm_8:
7096 case ARM::VLD2LNdWB_register_Asm_16:
7097 case ARM::VLD2LNdWB_register_Asm_32:
7098 case ARM::VLD2LNqWB_register_Asm_16:
7099 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007100 MCInst TmpInst;
7101 // Shuffle the operands around so the lane index operand is in the
7102 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007103 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007104 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007105 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007106 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7107 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007108 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7109 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7110 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7111 TmpInst.addOperand(Inst.getOperand(4)); // Rm
7112 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007113 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7114 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007115 TmpInst.addOperand(Inst.getOperand(1)); // lane
7116 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
7117 TmpInst.addOperand(Inst.getOperand(6));
7118 Inst = TmpInst;
7119 return true;
7120 }
7121
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007122 case ARM::VLD3LNdWB_register_Asm_8:
7123 case ARM::VLD3LNdWB_register_Asm_16:
7124 case ARM::VLD3LNdWB_register_Asm_32:
7125 case ARM::VLD3LNqWB_register_Asm_16:
7126 case ARM::VLD3LNqWB_register_Asm_32: {
7127 MCInst TmpInst;
7128 // Shuffle the operands around so the lane index operand is in the
7129 // right place.
7130 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007131 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007132 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7133 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7134 Spacing));
7135 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007136 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007137 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7138 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7139 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7140 TmpInst.addOperand(Inst.getOperand(4)); // Rm
7141 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7142 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7143 Spacing));
7144 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007145 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007146 TmpInst.addOperand(Inst.getOperand(1)); // lane
7147 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
7148 TmpInst.addOperand(Inst.getOperand(6));
7149 Inst = TmpInst;
7150 return true;
7151 }
7152
Jim Grosbach14952a02012-01-24 18:37:25 +00007153 case ARM::VLD4LNdWB_register_Asm_8:
7154 case ARM::VLD4LNdWB_register_Asm_16:
7155 case ARM::VLD4LNdWB_register_Asm_32:
7156 case ARM::VLD4LNqWB_register_Asm_16:
7157 case ARM::VLD4LNqWB_register_Asm_32: {
7158 MCInst TmpInst;
7159 // Shuffle the operands around so the lane index operand is in the
7160 // right place.
7161 unsigned Spacing;
7162 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7163 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7164 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7165 Spacing));
7166 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7167 Spacing * 2));
7168 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7169 Spacing * 3));
7170 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7171 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7172 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7173 TmpInst.addOperand(Inst.getOperand(4)); // Rm
7174 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7175 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7176 Spacing));
7177 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7178 Spacing * 2));
7179 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7180 Spacing * 3));
7181 TmpInst.addOperand(Inst.getOperand(1)); // lane
7182 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
7183 TmpInst.addOperand(Inst.getOperand(6));
7184 Inst = TmpInst;
7185 return true;
7186 }
7187
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007188 case ARM::VLD1LNdWB_fixed_Asm_8:
7189 case ARM::VLD1LNdWB_fixed_Asm_16:
7190 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00007191 MCInst TmpInst;
7192 // Shuffle the operands around so the lane index operand is in the
7193 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007194 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007195 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00007196 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7197 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7198 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7199 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7200 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7201 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7202 TmpInst.addOperand(Inst.getOperand(1)); // lane
7203 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7204 TmpInst.addOperand(Inst.getOperand(5));
7205 Inst = TmpInst;
7206 return true;
7207 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007208
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007209 case ARM::VLD2LNdWB_fixed_Asm_8:
7210 case ARM::VLD2LNdWB_fixed_Asm_16:
7211 case ARM::VLD2LNdWB_fixed_Asm_32:
7212 case ARM::VLD2LNqWB_fixed_Asm_16:
7213 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007214 MCInst TmpInst;
7215 // Shuffle the operands around so the lane index operand is in the
7216 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007217 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007218 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007219 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007220 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7221 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007222 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7223 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7224 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7225 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7226 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007227 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7228 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007229 TmpInst.addOperand(Inst.getOperand(1)); // lane
7230 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7231 TmpInst.addOperand(Inst.getOperand(5));
7232 Inst = TmpInst;
7233 return true;
7234 }
7235
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007236 case ARM::VLD3LNdWB_fixed_Asm_8:
7237 case ARM::VLD3LNdWB_fixed_Asm_16:
7238 case ARM::VLD3LNdWB_fixed_Asm_32:
7239 case ARM::VLD3LNqWB_fixed_Asm_16:
7240 case ARM::VLD3LNqWB_fixed_Asm_32: {
7241 MCInst TmpInst;
7242 // Shuffle the operands around so the lane index operand is in the
7243 // right place.
7244 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007245 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007246 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7247 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7248 Spacing));
7249 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007250 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007251 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7252 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7253 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7254 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7255 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7256 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7257 Spacing));
7258 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007259 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007260 TmpInst.addOperand(Inst.getOperand(1)); // lane
7261 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7262 TmpInst.addOperand(Inst.getOperand(5));
7263 Inst = TmpInst;
7264 return true;
7265 }
7266
Jim Grosbach14952a02012-01-24 18:37:25 +00007267 case ARM::VLD4LNdWB_fixed_Asm_8:
7268 case ARM::VLD4LNdWB_fixed_Asm_16:
7269 case ARM::VLD4LNdWB_fixed_Asm_32:
7270 case ARM::VLD4LNqWB_fixed_Asm_16:
7271 case ARM::VLD4LNqWB_fixed_Asm_32: {
7272 MCInst TmpInst;
7273 // Shuffle the operands around so the lane index operand is in the
7274 // right place.
7275 unsigned Spacing;
7276 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7277 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7278 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7279 Spacing));
7280 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7281 Spacing * 2));
7282 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7283 Spacing * 3));
7284 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7285 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7286 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7287 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7288 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7289 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7290 Spacing));
7291 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7292 Spacing * 2));
7293 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7294 Spacing * 3));
7295 TmpInst.addOperand(Inst.getOperand(1)); // lane
7296 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7297 TmpInst.addOperand(Inst.getOperand(5));
7298 Inst = TmpInst;
7299 return true;
7300 }
7301
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007302 case ARM::VLD1LNdAsm_8:
7303 case ARM::VLD1LNdAsm_16:
7304 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00007305 MCInst TmpInst;
7306 // Shuffle the operands around so the lane index operand is in the
7307 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007308 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007309 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00007310 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7311 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7312 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7313 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7314 TmpInst.addOperand(Inst.getOperand(1)); // lane
7315 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7316 TmpInst.addOperand(Inst.getOperand(5));
7317 Inst = TmpInst;
7318 return true;
7319 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007320
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007321 case ARM::VLD2LNdAsm_8:
7322 case ARM::VLD2LNdAsm_16:
7323 case ARM::VLD2LNdAsm_32:
7324 case ARM::VLD2LNqAsm_16:
7325 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007326 MCInst TmpInst;
7327 // Shuffle the operands around so the lane index operand is in the
7328 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007329 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007330 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007331 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007332 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7333 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007334 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7335 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7336 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007337 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7338 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007339 TmpInst.addOperand(Inst.getOperand(1)); // lane
7340 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7341 TmpInst.addOperand(Inst.getOperand(5));
7342 Inst = TmpInst;
7343 return true;
7344 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007345
7346 case ARM::VLD3LNdAsm_8:
7347 case ARM::VLD3LNdAsm_16:
7348 case ARM::VLD3LNdAsm_32:
7349 case ARM::VLD3LNqAsm_16:
7350 case ARM::VLD3LNqAsm_32: {
7351 MCInst TmpInst;
7352 // Shuffle the operands around so the lane index operand is in the
7353 // right place.
7354 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007355 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007356 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7357 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7358 Spacing));
7359 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007360 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007361 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7362 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7363 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7364 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7365 Spacing));
7366 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007367 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007368 TmpInst.addOperand(Inst.getOperand(1)); // lane
7369 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7370 TmpInst.addOperand(Inst.getOperand(5));
7371 Inst = TmpInst;
7372 return true;
7373 }
7374
Jim Grosbach14952a02012-01-24 18:37:25 +00007375 case ARM::VLD4LNdAsm_8:
7376 case ARM::VLD4LNdAsm_16:
7377 case ARM::VLD4LNdAsm_32:
7378 case ARM::VLD4LNqAsm_16:
7379 case ARM::VLD4LNqAsm_32: {
7380 MCInst TmpInst;
7381 // Shuffle the operands around so the lane index operand is in the
7382 // right place.
7383 unsigned Spacing;
7384 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7385 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7386 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7387 Spacing));
7388 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7389 Spacing * 2));
7390 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7391 Spacing * 3));
7392 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7393 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7394 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7395 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7396 Spacing));
7397 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7398 Spacing * 2));
7399 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7400 Spacing * 3));
7401 TmpInst.addOperand(Inst.getOperand(1)); // lane
7402 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7403 TmpInst.addOperand(Inst.getOperand(5));
7404 Inst = TmpInst;
7405 return true;
7406 }
7407
Jim Grosbachb78403c2012-01-24 23:47:04 +00007408 // VLD3DUP single 3-element structure to all lanes instructions.
7409 case ARM::VLD3DUPdAsm_8:
7410 case ARM::VLD3DUPdAsm_16:
7411 case ARM::VLD3DUPdAsm_32:
7412 case ARM::VLD3DUPqAsm_8:
7413 case ARM::VLD3DUPqAsm_16:
7414 case ARM::VLD3DUPqAsm_32: {
7415 MCInst TmpInst;
7416 unsigned Spacing;
7417 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7418 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7419 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7420 Spacing));
7421 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7422 Spacing * 2));
7423 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7424 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7425 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7426 TmpInst.addOperand(Inst.getOperand(4));
7427 Inst = TmpInst;
7428 return true;
7429 }
7430
7431 case ARM::VLD3DUPdWB_fixed_Asm_8:
7432 case ARM::VLD3DUPdWB_fixed_Asm_16:
7433 case ARM::VLD3DUPdWB_fixed_Asm_32:
7434 case ARM::VLD3DUPqWB_fixed_Asm_8:
7435 case ARM::VLD3DUPqWB_fixed_Asm_16:
7436 case ARM::VLD3DUPqWB_fixed_Asm_32: {
7437 MCInst TmpInst;
7438 unsigned Spacing;
7439 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7440 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7441 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7442 Spacing));
7443 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7444 Spacing * 2));
7445 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7446 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7447 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7448 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7449 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7450 TmpInst.addOperand(Inst.getOperand(4));
7451 Inst = TmpInst;
7452 return true;
7453 }
7454
7455 case ARM::VLD3DUPdWB_register_Asm_8:
7456 case ARM::VLD3DUPdWB_register_Asm_16:
7457 case ARM::VLD3DUPdWB_register_Asm_32:
7458 case ARM::VLD3DUPqWB_register_Asm_8:
7459 case ARM::VLD3DUPqWB_register_Asm_16:
7460 case ARM::VLD3DUPqWB_register_Asm_32: {
7461 MCInst TmpInst;
7462 unsigned Spacing;
7463 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7464 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7465 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7466 Spacing));
7467 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7468 Spacing * 2));
7469 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7470 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7471 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7472 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7473 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7474 TmpInst.addOperand(Inst.getOperand(5));
7475 Inst = TmpInst;
7476 return true;
7477 }
7478
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007479 // VLD3 multiple 3-element structure instructions.
7480 case ARM::VLD3dAsm_8:
7481 case ARM::VLD3dAsm_16:
7482 case ARM::VLD3dAsm_32:
7483 case ARM::VLD3qAsm_8:
7484 case ARM::VLD3qAsm_16:
7485 case ARM::VLD3qAsm_32: {
7486 MCInst TmpInst;
7487 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007488 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007489 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7490 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7491 Spacing));
7492 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7493 Spacing * 2));
7494 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7495 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7496 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7497 TmpInst.addOperand(Inst.getOperand(4));
7498 Inst = TmpInst;
7499 return true;
7500 }
7501
7502 case ARM::VLD3dWB_fixed_Asm_8:
7503 case ARM::VLD3dWB_fixed_Asm_16:
7504 case ARM::VLD3dWB_fixed_Asm_32:
7505 case ARM::VLD3qWB_fixed_Asm_8:
7506 case ARM::VLD3qWB_fixed_Asm_16:
7507 case ARM::VLD3qWB_fixed_Asm_32: {
7508 MCInst TmpInst;
7509 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007510 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007511 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7512 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7513 Spacing));
7514 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7515 Spacing * 2));
7516 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7517 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7518 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7519 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7520 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7521 TmpInst.addOperand(Inst.getOperand(4));
7522 Inst = TmpInst;
7523 return true;
7524 }
7525
7526 case ARM::VLD3dWB_register_Asm_8:
7527 case ARM::VLD3dWB_register_Asm_16:
7528 case ARM::VLD3dWB_register_Asm_32:
7529 case ARM::VLD3qWB_register_Asm_8:
7530 case ARM::VLD3qWB_register_Asm_16:
7531 case ARM::VLD3qWB_register_Asm_32: {
7532 MCInst TmpInst;
7533 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007534 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007535 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7536 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7537 Spacing));
7538 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7539 Spacing * 2));
7540 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7541 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7542 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7543 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7544 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7545 TmpInst.addOperand(Inst.getOperand(5));
7546 Inst = TmpInst;
7547 return true;
7548 }
7549
Jim Grosbach086cbfa2012-01-25 00:01:08 +00007550 // VLD4DUP single 3-element structure to all lanes instructions.
7551 case ARM::VLD4DUPdAsm_8:
7552 case ARM::VLD4DUPdAsm_16:
7553 case ARM::VLD4DUPdAsm_32:
7554 case ARM::VLD4DUPqAsm_8:
7555 case ARM::VLD4DUPqAsm_16:
7556 case ARM::VLD4DUPqAsm_32: {
7557 MCInst TmpInst;
7558 unsigned Spacing;
7559 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7560 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7561 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7562 Spacing));
7563 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7564 Spacing * 2));
7565 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7566 Spacing * 3));
7567 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7568 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7569 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7570 TmpInst.addOperand(Inst.getOperand(4));
7571 Inst = TmpInst;
7572 return true;
7573 }
7574
7575 case ARM::VLD4DUPdWB_fixed_Asm_8:
7576 case ARM::VLD4DUPdWB_fixed_Asm_16:
7577 case ARM::VLD4DUPdWB_fixed_Asm_32:
7578 case ARM::VLD4DUPqWB_fixed_Asm_8:
7579 case ARM::VLD4DUPqWB_fixed_Asm_16:
7580 case ARM::VLD4DUPqWB_fixed_Asm_32: {
7581 MCInst TmpInst;
7582 unsigned Spacing;
7583 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7584 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7585 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7586 Spacing));
7587 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7588 Spacing * 2));
7589 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7590 Spacing * 3));
7591 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7592 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7593 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7594 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7595 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7596 TmpInst.addOperand(Inst.getOperand(4));
7597 Inst = TmpInst;
7598 return true;
7599 }
7600
7601 case ARM::VLD4DUPdWB_register_Asm_8:
7602 case ARM::VLD4DUPdWB_register_Asm_16:
7603 case ARM::VLD4DUPdWB_register_Asm_32:
7604 case ARM::VLD4DUPqWB_register_Asm_8:
7605 case ARM::VLD4DUPqWB_register_Asm_16:
7606 case ARM::VLD4DUPqWB_register_Asm_32: {
7607 MCInst TmpInst;
7608 unsigned Spacing;
7609 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7610 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7611 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7612 Spacing));
7613 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7614 Spacing * 2));
7615 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7616 Spacing * 3));
7617 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7618 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7619 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7620 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7621 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7622 TmpInst.addOperand(Inst.getOperand(5));
7623 Inst = TmpInst;
7624 return true;
7625 }
7626
7627 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00007628 case ARM::VLD4dAsm_8:
7629 case ARM::VLD4dAsm_16:
7630 case ARM::VLD4dAsm_32:
7631 case ARM::VLD4qAsm_8:
7632 case ARM::VLD4qAsm_16:
7633 case ARM::VLD4qAsm_32: {
7634 MCInst TmpInst;
7635 unsigned Spacing;
7636 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7637 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7638 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7639 Spacing));
7640 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7641 Spacing * 2));
7642 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7643 Spacing * 3));
7644 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7645 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7646 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7647 TmpInst.addOperand(Inst.getOperand(4));
7648 Inst = TmpInst;
7649 return true;
7650 }
7651
7652 case ARM::VLD4dWB_fixed_Asm_8:
7653 case ARM::VLD4dWB_fixed_Asm_16:
7654 case ARM::VLD4dWB_fixed_Asm_32:
7655 case ARM::VLD4qWB_fixed_Asm_8:
7656 case ARM::VLD4qWB_fixed_Asm_16:
7657 case ARM::VLD4qWB_fixed_Asm_32: {
7658 MCInst TmpInst;
7659 unsigned Spacing;
7660 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7661 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7662 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7663 Spacing));
7664 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7665 Spacing * 2));
7666 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7667 Spacing * 3));
7668 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7669 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7670 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7671 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7672 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7673 TmpInst.addOperand(Inst.getOperand(4));
7674 Inst = TmpInst;
7675 return true;
7676 }
7677
7678 case ARM::VLD4dWB_register_Asm_8:
7679 case ARM::VLD4dWB_register_Asm_16:
7680 case ARM::VLD4dWB_register_Asm_32:
7681 case ARM::VLD4qWB_register_Asm_8:
7682 case ARM::VLD4qWB_register_Asm_16:
7683 case ARM::VLD4qWB_register_Asm_32: {
7684 MCInst TmpInst;
7685 unsigned Spacing;
7686 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7687 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7688 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7689 Spacing));
7690 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7691 Spacing * 2));
7692 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7693 Spacing * 3));
7694 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7695 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7696 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7697 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7698 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7699 TmpInst.addOperand(Inst.getOperand(5));
7700 Inst = TmpInst;
7701 return true;
7702 }
7703
Jim Grosbach1a747242012-01-23 23:45:44 +00007704 // VST3 multiple 3-element structure instructions.
7705 case ARM::VST3dAsm_8:
7706 case ARM::VST3dAsm_16:
7707 case ARM::VST3dAsm_32:
7708 case ARM::VST3qAsm_8:
7709 case ARM::VST3qAsm_16:
7710 case ARM::VST3qAsm_32: {
7711 MCInst TmpInst;
7712 unsigned Spacing;
7713 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7714 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7715 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7716 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7717 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7718 Spacing));
7719 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7720 Spacing * 2));
7721 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7722 TmpInst.addOperand(Inst.getOperand(4));
7723 Inst = TmpInst;
7724 return true;
7725 }
7726
7727 case ARM::VST3dWB_fixed_Asm_8:
7728 case ARM::VST3dWB_fixed_Asm_16:
7729 case ARM::VST3dWB_fixed_Asm_32:
7730 case ARM::VST3qWB_fixed_Asm_8:
7731 case ARM::VST3qWB_fixed_Asm_16:
7732 case ARM::VST3qWB_fixed_Asm_32: {
7733 MCInst TmpInst;
7734 unsigned Spacing;
7735 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7736 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7737 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7738 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7739 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7740 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7741 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7742 Spacing));
7743 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7744 Spacing * 2));
7745 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7746 TmpInst.addOperand(Inst.getOperand(4));
7747 Inst = TmpInst;
7748 return true;
7749 }
7750
7751 case ARM::VST3dWB_register_Asm_8:
7752 case ARM::VST3dWB_register_Asm_16:
7753 case ARM::VST3dWB_register_Asm_32:
7754 case ARM::VST3qWB_register_Asm_8:
7755 case ARM::VST3qWB_register_Asm_16:
7756 case ARM::VST3qWB_register_Asm_32: {
7757 MCInst TmpInst;
7758 unsigned Spacing;
7759 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7760 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7761 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7762 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7763 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7764 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7765 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7766 Spacing));
7767 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7768 Spacing * 2));
7769 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7770 TmpInst.addOperand(Inst.getOperand(5));
7771 Inst = TmpInst;
7772 return true;
7773 }
7774
Jim Grosbachda70eac2012-01-24 00:58:13 +00007775 // VST4 multiple 3-element structure instructions.
7776 case ARM::VST4dAsm_8:
7777 case ARM::VST4dAsm_16:
7778 case ARM::VST4dAsm_32:
7779 case ARM::VST4qAsm_8:
7780 case ARM::VST4qAsm_16:
7781 case ARM::VST4qAsm_32: {
7782 MCInst TmpInst;
7783 unsigned Spacing;
7784 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7785 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7786 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7787 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7788 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7789 Spacing));
7790 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7791 Spacing * 2));
7792 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7793 Spacing * 3));
7794 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7795 TmpInst.addOperand(Inst.getOperand(4));
7796 Inst = TmpInst;
7797 return true;
7798 }
7799
7800 case ARM::VST4dWB_fixed_Asm_8:
7801 case ARM::VST4dWB_fixed_Asm_16:
7802 case ARM::VST4dWB_fixed_Asm_32:
7803 case ARM::VST4qWB_fixed_Asm_8:
7804 case ARM::VST4qWB_fixed_Asm_16:
7805 case ARM::VST4qWB_fixed_Asm_32: {
7806 MCInst TmpInst;
7807 unsigned Spacing;
7808 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7809 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7810 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7811 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7812 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7813 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7814 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7815 Spacing));
7816 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7817 Spacing * 2));
7818 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7819 Spacing * 3));
7820 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7821 TmpInst.addOperand(Inst.getOperand(4));
7822 Inst = TmpInst;
7823 return true;
7824 }
7825
7826 case ARM::VST4dWB_register_Asm_8:
7827 case ARM::VST4dWB_register_Asm_16:
7828 case ARM::VST4dWB_register_Asm_32:
7829 case ARM::VST4qWB_register_Asm_8:
7830 case ARM::VST4qWB_register_Asm_16:
7831 case ARM::VST4qWB_register_Asm_32: {
7832 MCInst TmpInst;
7833 unsigned Spacing;
7834 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7835 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7836 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7837 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7838 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7839 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7840 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7841 Spacing));
7842 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7843 Spacing * 2));
7844 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7845 Spacing * 3));
7846 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7847 TmpInst.addOperand(Inst.getOperand(5));
7848 Inst = TmpInst;
7849 return true;
7850 }
7851
Jim Grosbachad66de12012-04-11 00:15:16 +00007852 // Handle encoding choice for the shift-immediate instructions.
7853 case ARM::t2LSLri:
7854 case ARM::t2LSRri:
7855 case ARM::t2ASRri: {
7856 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7857 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7858 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
David Blaikie960ea3f2014-06-08 16:18:35 +00007859 !(static_cast<ARMOperand &>(*Operands[3]).isToken() &&
7860 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w")) {
Jim Grosbachad66de12012-04-11 00:15:16 +00007861 unsigned NewOpc;
7862 switch (Inst.getOpcode()) {
7863 default: llvm_unreachable("unexpected opcode");
7864 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
7865 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
7866 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
7867 }
7868 // The Thumb1 operands aren't in the same order. Awesome, eh?
7869 MCInst TmpInst;
7870 TmpInst.setOpcode(NewOpc);
7871 TmpInst.addOperand(Inst.getOperand(0));
7872 TmpInst.addOperand(Inst.getOperand(5));
7873 TmpInst.addOperand(Inst.getOperand(1));
7874 TmpInst.addOperand(Inst.getOperand(2));
7875 TmpInst.addOperand(Inst.getOperand(3));
7876 TmpInst.addOperand(Inst.getOperand(4));
7877 Inst = TmpInst;
7878 return true;
7879 }
7880 return false;
7881 }
7882
Jim Grosbach485e5622011-12-13 22:45:11 +00007883 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00007884 case ARM::t2MOVsr:
7885 case ARM::t2MOVSsr: {
7886 // Which instruction to expand to depends on the CCOut operand and
7887 // whether we're in an IT block if the register operands are low
7888 // registers.
7889 bool isNarrow = false;
7890 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7891 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7892 isARMLowRegister(Inst.getOperand(2).getReg()) &&
7893 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7894 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
7895 isNarrow = true;
7896 MCInst TmpInst;
7897 unsigned newOpc;
7898 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
7899 default: llvm_unreachable("unexpected opcode!");
7900 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
7901 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
7902 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
7903 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
7904 }
7905 TmpInst.setOpcode(newOpc);
7906 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7907 if (isNarrow)
7908 TmpInst.addOperand(MCOperand::CreateReg(
7909 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7910 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7911 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7912 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7913 TmpInst.addOperand(Inst.getOperand(5));
7914 if (!isNarrow)
7915 TmpInst.addOperand(MCOperand::CreateReg(
7916 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7917 Inst = TmpInst;
7918 return true;
7919 }
Jim Grosbach485e5622011-12-13 22:45:11 +00007920 case ARM::t2MOVsi:
7921 case ARM::t2MOVSsi: {
7922 // Which instruction to expand to depends on the CCOut operand and
7923 // whether we're in an IT block if the register operands are low
7924 // registers.
7925 bool isNarrow = false;
7926 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7927 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7928 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
7929 isNarrow = true;
7930 MCInst TmpInst;
7931 unsigned newOpc;
7932 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
7933 default: llvm_unreachable("unexpected opcode!");
7934 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
7935 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
7936 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
7937 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007938 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00007939 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00007940 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
7941 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00007942 TmpInst.setOpcode(newOpc);
7943 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7944 if (isNarrow)
7945 TmpInst.addOperand(MCOperand::CreateReg(
7946 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7947 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007948 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00007949 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00007950 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7951 TmpInst.addOperand(Inst.getOperand(4));
7952 if (!isNarrow)
7953 TmpInst.addOperand(MCOperand::CreateReg(
7954 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7955 Inst = TmpInst;
7956 return true;
7957 }
7958 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00007959 case ARM::ASRr:
7960 case ARM::LSRr:
7961 case ARM::LSLr:
7962 case ARM::RORr: {
7963 ARM_AM::ShiftOpc ShiftTy;
7964 switch(Inst.getOpcode()) {
7965 default: llvm_unreachable("unexpected opcode!");
7966 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7967 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7968 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7969 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7970 }
Jim Grosbachabcac562011-11-16 18:31:45 +00007971 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7972 MCInst TmpInst;
7973 TmpInst.setOpcode(ARM::MOVsr);
7974 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7975 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7976 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7977 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7978 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7979 TmpInst.addOperand(Inst.getOperand(4));
7980 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7981 Inst = TmpInst;
7982 return true;
7983 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00007984 case ARM::ASRi:
7985 case ARM::LSRi:
7986 case ARM::LSLi:
7987 case ARM::RORi: {
7988 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007989 switch(Inst.getOpcode()) {
7990 default: llvm_unreachable("unexpected opcode!");
7991 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7992 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7993 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7994 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7995 }
7996 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007997 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00007998 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007999 // A shift by 32 should be encoded as 0 when permitted
8000 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
8001 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00008002 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00008003 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00008004 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00008005 TmpInst.addOperand(Inst.getOperand(0)); // Rd
8006 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00008007 if (Opc == ARM::MOVsi)
8008 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00008009 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
8010 TmpInst.addOperand(Inst.getOperand(4));
8011 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
8012 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00008013 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00008014 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00008015 case ARM::RRXi: {
8016 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
8017 MCInst TmpInst;
8018 TmpInst.setOpcode(ARM::MOVsi);
8019 TmpInst.addOperand(Inst.getOperand(0)); // Rd
8020 TmpInst.addOperand(Inst.getOperand(1)); // Rn
8021 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
8022 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
8023 TmpInst.addOperand(Inst.getOperand(3));
8024 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
8025 Inst = TmpInst;
8026 return true;
8027 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00008028 case ARM::t2LDMIA_UPD: {
8029 // If this is a load of a single register, then we should use
8030 // a post-indexed LDR instruction instead, per the ARM ARM.
8031 if (Inst.getNumOperands() != 5)
8032 return false;
8033 MCInst TmpInst;
8034 TmpInst.setOpcode(ARM::t2LDR_POST);
8035 TmpInst.addOperand(Inst.getOperand(4)); // Rt
8036 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
8037 TmpInst.addOperand(Inst.getOperand(1)); // Rn
8038 TmpInst.addOperand(MCOperand::CreateImm(4));
8039 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
8040 TmpInst.addOperand(Inst.getOperand(3));
8041 Inst = TmpInst;
8042 return true;
8043 }
8044 case ARM::t2STMDB_UPD: {
8045 // If this is a store of a single register, then we should use
8046 // a pre-indexed STR instruction instead, per the ARM ARM.
8047 if (Inst.getNumOperands() != 5)
8048 return false;
8049 MCInst TmpInst;
8050 TmpInst.setOpcode(ARM::t2STR_PRE);
8051 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
8052 TmpInst.addOperand(Inst.getOperand(4)); // Rt
8053 TmpInst.addOperand(Inst.getOperand(1)); // Rn
8054 TmpInst.addOperand(MCOperand::CreateImm(-4));
8055 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
8056 TmpInst.addOperand(Inst.getOperand(3));
8057 Inst = TmpInst;
8058 return true;
8059 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008060 case ARM::LDMIA_UPD:
8061 // If this is a load of a single register via a 'pop', then we should use
8062 // a post-indexed LDR instruction instead, per the ARM ARM.
David Blaikie960ea3f2014-06-08 16:18:35 +00008063 if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "pop" &&
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008064 Inst.getNumOperands() == 5) {
8065 MCInst TmpInst;
8066 TmpInst.setOpcode(ARM::LDR_POST_IMM);
8067 TmpInst.addOperand(Inst.getOperand(4)); // Rt
8068 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
8069 TmpInst.addOperand(Inst.getOperand(1)); // Rn
8070 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
8071 TmpInst.addOperand(MCOperand::CreateImm(4));
8072 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
8073 TmpInst.addOperand(Inst.getOperand(3));
8074 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00008075 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008076 }
8077 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00008078 case ARM::STMDB_UPD:
8079 // If this is a store of a single register via a 'push', then we should use
8080 // a pre-indexed STR instruction instead, per the ARM ARM.
David Blaikie960ea3f2014-06-08 16:18:35 +00008081 if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "push" &&
Jim Grosbach27ad83d2011-08-11 18:07:11 +00008082 Inst.getNumOperands() == 5) {
8083 MCInst TmpInst;
8084 TmpInst.setOpcode(ARM::STR_PRE_IMM);
8085 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
8086 TmpInst.addOperand(Inst.getOperand(4)); // Rt
8087 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
8088 TmpInst.addOperand(MCOperand::CreateImm(-4));
8089 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
8090 TmpInst.addOperand(Inst.getOperand(3));
8091 Inst = TmpInst;
8092 }
8093 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00008094 case ARM::t2ADDri12:
8095 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
8096 // mnemonic was used (not "addw"), encoding T3 is preferred.
David Blaikie960ea3f2014-06-08 16:18:35 +00008097 if (static_cast<ARMOperand &>(*Operands[0]).getToken() != "add" ||
Jim Grosbachec9ba982011-12-05 21:06:26 +00008098 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
8099 break;
8100 Inst.setOpcode(ARM::t2ADDri);
8101 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
8102 break;
8103 case ARM::t2SUBri12:
8104 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
8105 // mnemonic was used (not "subw"), encoding T3 is preferred.
David Blaikie960ea3f2014-06-08 16:18:35 +00008106 if (static_cast<ARMOperand &>(*Operands[0]).getToken() != "sub" ||
Jim Grosbachec9ba982011-12-05 21:06:26 +00008107 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
8108 break;
8109 Inst.setOpcode(ARM::t2SUBri);
8110 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
8111 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00008112 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00008113 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00008114 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
8115 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
8116 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00008117 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00008118 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00008119 return true;
8120 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00008121 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00008122 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00008123 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00008124 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
8125 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
8126 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00008127 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00008128 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00008129 return true;
8130 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00008131 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00008132 case ARM::t2ADDri:
8133 case ARM::t2SUBri: {
8134 // If the destination and first source operand are the same, and
8135 // the flags are compatible with the current IT status, use encoding T2
8136 // instead of T3. For compatibility with the system 'as'. Make sure the
8137 // wide encoding wasn't explicit.
8138 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00008139 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00008140 (unsigned)Inst.getOperand(2).getImm() > 255 ||
8141 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
David Blaikie960ea3f2014-06-08 16:18:35 +00008142 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
8143 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
8144 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w"))
Jim Grosbachdef5e342012-03-30 17:20:40 +00008145 break;
8146 MCInst TmpInst;
8147 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
8148 ARM::tADDi8 : ARM::tSUBi8);
8149 TmpInst.addOperand(Inst.getOperand(0));
8150 TmpInst.addOperand(Inst.getOperand(5));
8151 TmpInst.addOperand(Inst.getOperand(0));
8152 TmpInst.addOperand(Inst.getOperand(2));
8153 TmpInst.addOperand(Inst.getOperand(3));
8154 TmpInst.addOperand(Inst.getOperand(4));
8155 Inst = TmpInst;
8156 return true;
8157 }
Jim Grosbache489bab2011-12-05 22:16:39 +00008158 case ARM::t2ADDrr: {
8159 // If the destination and first source operand are the same, and
8160 // there's no setting of the flags, use encoding T2 instead of T3.
8161 // Note that this is only for ADD, not SUB. This mirrors the system
8162 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
8163 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
8164 Inst.getOperand(5).getReg() != 0 ||
David Blaikie960ea3f2014-06-08 16:18:35 +00008165 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
8166 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00008167 break;
8168 MCInst TmpInst;
8169 TmpInst.setOpcode(ARM::tADDhirr);
8170 TmpInst.addOperand(Inst.getOperand(0));
8171 TmpInst.addOperand(Inst.getOperand(0));
8172 TmpInst.addOperand(Inst.getOperand(2));
8173 TmpInst.addOperand(Inst.getOperand(3));
8174 TmpInst.addOperand(Inst.getOperand(4));
8175 Inst = TmpInst;
8176 return true;
8177 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00008178 case ARM::tADDrSP: {
8179 // If the non-SP source operand and the destination operand are not the
8180 // same, we need to use the 32-bit encoding if it's available.
8181 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
8182 Inst.setOpcode(ARM::t2ADDrr);
8183 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
8184 return true;
8185 }
8186 break;
8187 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00008188 case ARM::tB:
8189 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00008190 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson29cfe6c2011-09-09 21:48:23 +00008191 Inst.setOpcode(ARM::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00008192 return true;
8193 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00008194 break;
8195 case ARM::t2B:
8196 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00008197 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00008198 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00008199 return true;
8200 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00008201 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00008202 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008203 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00008204 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00008205 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00008206 return true;
8207 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00008208 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00008209 case ARM::tBcc:
8210 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00008211 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00008212 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00008213 return true;
8214 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00008215 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00008216 case ARM::tLDMIA: {
8217 // If the register list contains any high registers, or if the writeback
8218 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
8219 // instead if we're in Thumb2. Otherwise, this should have generated
8220 // an error in validateInstruction().
8221 unsigned Rn = Inst.getOperand(0).getReg();
8222 bool hasWritebackToken =
David Blaikie960ea3f2014-06-08 16:18:35 +00008223 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
8224 static_cast<ARMOperand &>(*Operands[3]).getToken() == "!");
Jim Grosbacha31f2232011-09-07 18:05:34 +00008225 bool listContainsBase;
8226 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
8227 (!listContainsBase && !hasWritebackToken) ||
8228 (listContainsBase && hasWritebackToken)) {
8229 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
8230 assert (isThumbTwo());
8231 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
8232 // If we're switching to the updating version, we need to insert
8233 // the writeback tied operand.
8234 if (hasWritebackToken)
8235 Inst.insert(Inst.begin(),
8236 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00008237 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00008238 }
8239 break;
8240 }
Jim Grosbach099c9762011-09-16 20:50:13 +00008241 case ARM::tSTMIA_UPD: {
8242 // If the register list contains any high registers, we need to use
8243 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
8244 // should have generated an error in validateInstruction().
8245 unsigned Rn = Inst.getOperand(0).getReg();
8246 bool listContainsBase;
8247 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
8248 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
8249 assert (isThumbTwo());
8250 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00008251 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00008252 }
8253 break;
8254 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00008255 case ARM::tPOP: {
8256 bool listContainsBase;
8257 // If the register list contains any high registers, we need to use
8258 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
8259 // should have generated an error in validateInstruction().
8260 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00008261 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00008262 assert (isThumbTwo());
8263 Inst.setOpcode(ARM::t2LDMIA_UPD);
8264 // Add the base register and writeback operands.
8265 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
8266 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00008267 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00008268 }
8269 case ARM::tPUSH: {
8270 bool listContainsBase;
8271 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00008272 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00008273 assert (isThumbTwo());
8274 Inst.setOpcode(ARM::t2STMDB_UPD);
8275 // Add the base register and writeback operands.
8276 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
8277 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00008278 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00008279 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00008280 case ARM::t2MOVi: {
8281 // If we can use the 16-bit encoding and the user didn't explicitly
8282 // request the 32-bit variant, transform it here.
8283 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00008284 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00008285 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
David Blaikie960ea3f2014-06-08 16:18:35 +00008286 Inst.getOperand(4).getReg() == ARM::CPSR) ||
8287 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
8288 (!static_cast<ARMOperand &>(*Operands[2]).isToken() ||
8289 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) {
Jim Grosbachb908b7a2011-09-10 00:15:36 +00008290 // The operands aren't in the same order for tMOVi8...
8291 MCInst TmpInst;
8292 TmpInst.setOpcode(ARM::tMOVi8);
8293 TmpInst.addOperand(Inst.getOperand(0));
8294 TmpInst.addOperand(Inst.getOperand(4));
8295 TmpInst.addOperand(Inst.getOperand(1));
8296 TmpInst.addOperand(Inst.getOperand(2));
8297 TmpInst.addOperand(Inst.getOperand(3));
8298 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00008299 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00008300 }
8301 break;
8302 }
8303 case ARM::t2MOVr: {
8304 // If we can use the 16-bit encoding and the user didn't explicitly
8305 // request the 32-bit variant, transform it here.
8306 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
8307 isARMLowRegister(Inst.getOperand(1).getReg()) &&
8308 Inst.getOperand(2).getImm() == ARMCC::AL &&
8309 Inst.getOperand(4).getReg() == ARM::CPSR &&
David Blaikie960ea3f2014-06-08 16:18:35 +00008310 (!static_cast<ARMOperand &>(*Operands[2]).isToken() ||
8311 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) {
Jim Grosbachb908b7a2011-09-10 00:15:36 +00008312 // The operands aren't the same for tMOV[S]r... (no cc_out)
8313 MCInst TmpInst;
8314 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
8315 TmpInst.addOperand(Inst.getOperand(0));
8316 TmpInst.addOperand(Inst.getOperand(1));
8317 TmpInst.addOperand(Inst.getOperand(2));
8318 TmpInst.addOperand(Inst.getOperand(3));
8319 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00008320 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00008321 }
8322 break;
8323 }
Jim Grosbach82213192011-09-19 20:29:33 +00008324 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00008325 case ARM::t2SXTB:
8326 case ARM::t2UXTH:
8327 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00008328 // If we can use the 16-bit encoding and the user didn't explicitly
8329 // request the 32-bit variant, transform it here.
8330 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
8331 isARMLowRegister(Inst.getOperand(1).getReg()) &&
8332 Inst.getOperand(2).getImm() == 0 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00008333 (!static_cast<ARMOperand &>(*Operands[2]).isToken() ||
8334 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00008335 unsigned NewOpc;
8336 switch (Inst.getOpcode()) {
8337 default: llvm_unreachable("Illegal opcode!");
8338 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
8339 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
8340 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
8341 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
8342 }
Jim Grosbach82213192011-09-19 20:29:33 +00008343 // The operands aren't the same for thumb1 (no rotate operand).
8344 MCInst TmpInst;
8345 TmpInst.setOpcode(NewOpc);
8346 TmpInst.addOperand(Inst.getOperand(0));
8347 TmpInst.addOperand(Inst.getOperand(1));
8348 TmpInst.addOperand(Inst.getOperand(3));
8349 TmpInst.addOperand(Inst.getOperand(4));
8350 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00008351 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00008352 }
8353 break;
8354 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00008355 case ARM::MOVsi: {
8356 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00008357 // rrx shifts and asr/lsr of #32 is encoded as 0
8358 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
8359 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00008360 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
8361 // Shifting by zero is accepted as a vanilla 'MOVr'
8362 MCInst TmpInst;
8363 TmpInst.setOpcode(ARM::MOVr);
8364 TmpInst.addOperand(Inst.getOperand(0));
8365 TmpInst.addOperand(Inst.getOperand(1));
8366 TmpInst.addOperand(Inst.getOperand(3));
8367 TmpInst.addOperand(Inst.getOperand(4));
8368 TmpInst.addOperand(Inst.getOperand(5));
8369 Inst = TmpInst;
8370 return true;
8371 }
8372 return false;
8373 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00008374 case ARM::ANDrsi:
8375 case ARM::ORRrsi:
8376 case ARM::EORrsi:
8377 case ARM::BICrsi:
8378 case ARM::SUBrsi:
8379 case ARM::ADDrsi: {
8380 unsigned newOpc;
8381 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
8382 if (SOpc == ARM_AM::rrx) return false;
8383 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00008384 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00008385 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
8386 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
8387 case ARM::EORrsi: newOpc = ARM::EORrr; break;
8388 case ARM::BICrsi: newOpc = ARM::BICrr; break;
8389 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
8390 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
8391 }
8392 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00008393 // The exception is for right shifts, where 0 == 32
8394 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
8395 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00008396 MCInst TmpInst;
8397 TmpInst.setOpcode(newOpc);
8398 TmpInst.addOperand(Inst.getOperand(0));
8399 TmpInst.addOperand(Inst.getOperand(1));
8400 TmpInst.addOperand(Inst.getOperand(2));
8401 TmpInst.addOperand(Inst.getOperand(4));
8402 TmpInst.addOperand(Inst.getOperand(5));
8403 TmpInst.addOperand(Inst.getOperand(6));
8404 Inst = TmpInst;
8405 return true;
8406 }
8407 return false;
8408 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00008409 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008410 case ARM::t2IT: {
8411 // The mask bits for all but the first condition are represented as
8412 // the low bit of the condition code value implies 't'. We currently
8413 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00008414 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008415 MCOperand &MO = Inst.getOperand(1);
8416 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00008417 unsigned OrigMask = Mask;
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +00008418 unsigned TZ = countTrailingZeros(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008419 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008420 assert(Mask && TZ <= 3 && "illegal IT mask value!");
Benjamin Kramer8bad66e2013-05-19 22:01:57 +00008421 Mask ^= (0xE << TZ) & 0xF;
Richard Bartonf435b092012-04-27 08:42:59 +00008422 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008423 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00008424
8425 // Set up the IT block state according to the IT instruction we just
8426 // matched.
8427 assert(!inITBlock() && "nested IT blocks?!");
8428 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
8429 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
8430 ITState.CurPosition = 0;
8431 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008432 break;
8433 }
Richard Bartona39625e2012-07-09 16:12:24 +00008434 case ARM::t2LSLrr:
8435 case ARM::t2LSRrr:
8436 case ARM::t2ASRrr:
8437 case ARM::t2SBCrr:
8438 case ARM::t2RORrr:
8439 case ARM::t2BICrr:
8440 {
Richard Bartond5660372012-07-09 16:14:28 +00008441 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00008442 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
8443 isARMLowRegister(Inst.getOperand(2).getReg())) &&
8444 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00008445 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
David Blaikie960ea3f2014-06-08 16:18:35 +00008446 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
8447 (!static_cast<ARMOperand &>(*Operands[3]).isToken() ||
8448 !static_cast<ARMOperand &>(*Operands[3]).getToken().equals_lower(
8449 ".w"))) {
Richard Bartona39625e2012-07-09 16:12:24 +00008450 unsigned NewOpc;
8451 switch (Inst.getOpcode()) {
8452 default: llvm_unreachable("unexpected opcode");
8453 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
8454 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
8455 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
8456 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
8457 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
8458 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
8459 }
8460 MCInst TmpInst;
8461 TmpInst.setOpcode(NewOpc);
8462 TmpInst.addOperand(Inst.getOperand(0));
8463 TmpInst.addOperand(Inst.getOperand(5));
8464 TmpInst.addOperand(Inst.getOperand(1));
8465 TmpInst.addOperand(Inst.getOperand(2));
8466 TmpInst.addOperand(Inst.getOperand(3));
8467 TmpInst.addOperand(Inst.getOperand(4));
8468 Inst = TmpInst;
8469 return true;
8470 }
8471 return false;
8472 }
8473 case ARM::t2ANDrr:
8474 case ARM::t2EORrr:
8475 case ARM::t2ADCrr:
8476 case ARM::t2ORRrr:
8477 {
Richard Bartond5660372012-07-09 16:14:28 +00008478 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00008479 // These instructions are special in that they are commutable, so shorter encodings
8480 // are available more often.
8481 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
8482 isARMLowRegister(Inst.getOperand(2).getReg())) &&
8483 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
8484 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00008485 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
David Blaikie960ea3f2014-06-08 16:18:35 +00008486 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
8487 (!static_cast<ARMOperand &>(*Operands[3]).isToken() ||
8488 !static_cast<ARMOperand &>(*Operands[3]).getToken().equals_lower(
8489 ".w"))) {
Richard Bartona39625e2012-07-09 16:12:24 +00008490 unsigned NewOpc;
8491 switch (Inst.getOpcode()) {
8492 default: llvm_unreachable("unexpected opcode");
8493 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
8494 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
8495 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
8496 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
8497 }
8498 MCInst TmpInst;
8499 TmpInst.setOpcode(NewOpc);
8500 TmpInst.addOperand(Inst.getOperand(0));
8501 TmpInst.addOperand(Inst.getOperand(5));
8502 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
8503 TmpInst.addOperand(Inst.getOperand(1));
8504 TmpInst.addOperand(Inst.getOperand(2));
8505 } else {
8506 TmpInst.addOperand(Inst.getOperand(2));
8507 TmpInst.addOperand(Inst.getOperand(1));
8508 }
8509 TmpInst.addOperand(Inst.getOperand(3));
8510 TmpInst.addOperand(Inst.getOperand(4));
8511 Inst = TmpInst;
8512 return true;
8513 }
8514 return false;
8515 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008516 }
Jim Grosbachafad0532011-11-10 23:42:14 +00008517 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008518}
8519
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008520unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
8521 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
8522 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008523 unsigned Opc = Inst.getOpcode();
Joey Gouly0e76fa72013-09-12 10:28:05 +00008524 const MCInstrDesc &MCID = MII.get(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008525 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
8526 assert(MCID.hasOptionalDef() &&
8527 "optionally flag setting instruction missing optional def operand");
8528 assert(MCID.NumOperands == Inst.getNumOperands() &&
8529 "operand count mismatch!");
8530 // Find the optional-def operand (cc_out).
8531 unsigned OpNo;
8532 for (OpNo = 0;
8533 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
8534 ++OpNo)
8535 ;
8536 // If we're parsing Thumb1, reject it completely.
8537 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
8538 return Match_MnemonicFail;
8539 // If we're parsing Thumb2, which form is legal depends on whether we're
8540 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00008541 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
8542 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008543 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00008544 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
8545 inITBlock())
8546 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008547 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008548 // Some high-register supporting Thumb1 encodings only allow both registers
8549 // to be from r0-r7 when in Thumb2.
Renato Golin36c626e2014-09-26 16:14:29 +00008550 else if (Opc == ARM::tADDhirr && isThumbOne() && !hasV6MOps() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008551 isARMLowRegister(Inst.getOperand(1).getReg()) &&
8552 isARMLowRegister(Inst.getOperand(2).getReg()))
8553 return Match_RequiresThumb2;
8554 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00008555 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008556 isARMLowRegister(Inst.getOperand(0).getReg()) &&
8557 isARMLowRegister(Inst.getOperand(1).getReg()))
8558 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008559 return Match_Success;
8560}
8561
Benjamin Kramer44a53da2014-04-12 18:45:24 +00008562namespace llvm {
8563template <> inline bool IsCPSRDead<MCInst>(MCInst *Instr) {
Artyom Skrobov1a6cd1d2014-02-26 11:27:28 +00008564 return true; // In an assembly source, no need to second-guess
8565}
Benjamin Kramer44a53da2014-04-12 18:45:24 +00008566}
Artyom Skrobov1a6cd1d2014-02-26 11:27:28 +00008567
Tim Northover26bb14e2014-08-18 11:49:42 +00008568static const char *getSubtargetFeatureName(uint64_t Val);
David Blaikie960ea3f2014-06-08 16:18:35 +00008569bool ARMAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
8570 OperandVector &Operands,
Tim Northover26bb14e2014-08-18 11:49:42 +00008571 MCStreamer &Out, uint64_t &ErrorInfo,
David Blaikie960ea3f2014-06-08 16:18:35 +00008572 bool MatchingInlineAsm) {
Chris Lattner9487de62010-10-28 21:28:01 +00008573 MCInst Inst;
Jim Grosbach120a96a2011-08-15 23:03:29 +00008574 unsigned MatchResult;
Weiming Zhao8f56f882012-11-16 21:55:34 +00008575
Chad Rosier2f480a82012-10-12 22:53:36 +00008576 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
Chad Rosier49963552012-10-13 00:26:04 +00008577 MatchingInlineAsm);
Kevin Enderby3164a342010-12-09 19:19:43 +00008578 switch (MatchResult) {
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008579 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00008580 // Context sensitive operand constraints aren't handled by the matcher,
8581 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008582 if (validateInstruction(Inst, Operands)) {
8583 // Still progress the IT block, otherwise one wrong condition causes
8584 // nasty cascading errors.
8585 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00008586 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008587 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00008588
Amara Emerson52cfb6a2013-10-03 09:31:51 +00008589 { // processInstruction() updates inITBlock state, we need to save it away
8590 bool wasInITBlock = inITBlock();
8591
8592 // Some instructions need post-processing to, for example, tweak which
8593 // encoding is selected. Loop on it while changes happen so the
8594 // individual transformations can chain off each other. E.g.,
8595 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +00008596 while (processInstruction(Inst, Operands, Out))
Amara Emerson52cfb6a2013-10-03 09:31:51 +00008597 ;
8598
8599 // Only after the instruction is fully processed, we can validate it
8600 if (wasInITBlock && hasV8Ops() && isThumb() &&
Weiming Zhao5930ae62014-01-23 19:55:33 +00008601 !isV8EligibleForIT(&Inst)) {
Amara Emerson52cfb6a2013-10-03 09:31:51 +00008602 Warning(IDLoc, "deprecated instruction in IT block");
8603 }
8604 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008605
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008606 // Only move forward at the very end so that everything in validate
8607 // and process gets a consistent answer about whether we're in an IT
8608 // block.
8609 forwardITPosition();
8610
Jim Grosbach82f76d12012-01-25 19:52:01 +00008611 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
8612 // doesn't actually encode.
8613 if (Inst.getOpcode() == ARM::ITasm)
8614 return false;
8615
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00008616 Inst.setLoc(IDLoc);
David Woodhousee6c13e42014-01-28 23:12:42 +00008617 Out.EmitInstruction(Inst, STI);
Chris Lattner9487de62010-10-28 21:28:01 +00008618 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00008619 case Match_MissingFeature: {
8620 assert(ErrorInfo && "Unknown missing feature!");
8621 // Special case the error message for the very common case where only
8622 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
8623 std::string Msg = "instruction requires:";
Tim Northover26bb14e2014-08-18 11:49:42 +00008624 uint64_t Mask = 1;
Jim Grosbach5117ef72012-04-24 22:40:08 +00008625 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
8626 if (ErrorInfo & Mask) {
8627 Msg += " ";
8628 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
8629 }
8630 Mask <<= 1;
8631 }
8632 return Error(IDLoc, Msg);
8633 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008634 case Match_InvalidOperand: {
8635 SMLoc ErrorLoc = IDLoc;
Tim Northover26bb14e2014-08-18 11:49:42 +00008636 if (ErrorInfo != ~0ULL) {
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008637 if (ErrorInfo >= Operands.size())
8638 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00008639
David Blaikie960ea3f2014-06-08 16:18:35 +00008640 ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc();
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008641 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8642 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00008643
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008644 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00008645 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008646 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00008647 return Error(IDLoc, "invalid instruction",
David Blaikie960ea3f2014-06-08 16:18:35 +00008648 ((ARMOperand &)*Operands[0]).getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00008649 case Match_RequiresNotITBlock:
8650 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008651 case Match_RequiresITBlock:
8652 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008653 case Match_RequiresV6:
8654 return Error(IDLoc, "instruction variant requires ARMv6 or later");
8655 case Match_RequiresThumb2:
8656 return Error(IDLoc, "instruction variant requires Thumb2");
Jim Grosbach087affe2012-06-22 23:56:48 +00008657 case Match_ImmRange0_15: {
David Blaikie960ea3f2014-06-08 16:18:35 +00008658 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc();
Jim Grosbach087affe2012-06-22 23:56:48 +00008659 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8660 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
8661 }
Artyom Skrobovfc12e702013-10-23 10:14:40 +00008662 case Match_ImmRange0_239: {
David Blaikie960ea3f2014-06-08 16:18:35 +00008663 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc();
Artyom Skrobovfc12e702013-10-23 10:14:40 +00008664 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8665 return Error(ErrorLoc, "immediate operand must be in the range [0,239]");
8666 }
Kevin Enderby488f20b2014-04-10 20:18:58 +00008667 case Match_AlignedMemoryRequiresNone:
8668 case Match_DupAlignedMemoryRequiresNone:
8669 case Match_AlignedMemoryRequires16:
8670 case Match_DupAlignedMemoryRequires16:
8671 case Match_AlignedMemoryRequires32:
8672 case Match_DupAlignedMemoryRequires32:
8673 case Match_AlignedMemoryRequires64:
8674 case Match_DupAlignedMemoryRequires64:
8675 case Match_AlignedMemoryRequires64or128:
8676 case Match_DupAlignedMemoryRequires64or128:
8677 case Match_AlignedMemoryRequires64or128or256:
8678 {
David Blaikie960ea3f2014-06-08 16:18:35 +00008679 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getAlignmentLoc();
Kevin Enderby488f20b2014-04-10 20:18:58 +00008680 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8681 switch (MatchResult) {
8682 default:
8683 llvm_unreachable("Missing Match_Aligned type");
8684 case Match_AlignedMemoryRequiresNone:
8685 case Match_DupAlignedMemoryRequiresNone:
8686 return Error(ErrorLoc, "alignment must be omitted");
8687 case Match_AlignedMemoryRequires16:
8688 case Match_DupAlignedMemoryRequires16:
8689 return Error(ErrorLoc, "alignment must be 16 or omitted");
8690 case Match_AlignedMemoryRequires32:
8691 case Match_DupAlignedMemoryRequires32:
8692 return Error(ErrorLoc, "alignment must be 32 or omitted");
8693 case Match_AlignedMemoryRequires64:
8694 case Match_DupAlignedMemoryRequires64:
8695 return Error(ErrorLoc, "alignment must be 64 or omitted");
8696 case Match_AlignedMemoryRequires64or128:
8697 case Match_DupAlignedMemoryRequires64or128:
8698 return Error(ErrorLoc, "alignment must be 64, 128 or omitted");
8699 case Match_AlignedMemoryRequires64or128or256:
8700 return Error(ErrorLoc, "alignment must be 64, 128, 256 or omitted");
8701 }
8702 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008703 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00008704
Eric Christopher91d7b902010-10-29 09:26:59 +00008705 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00008706}
8707
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008708/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00008709bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008710 const MCObjectFileInfo::Environment Format =
8711 getContext().getObjectFileInfo()->getObjectFileType();
8712 bool IsMachO = Format == MCObjectFileInfo::IsMachO;
Saleem Abdulrasoolbfdfb142014-09-18 04:28:29 +00008713 bool IsCOFF = Format == MCObjectFileInfo::IsCOFF;
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008714
Kevin Enderbyccab3172009-09-15 00:27:25 +00008715 StringRef IDVal = DirectiveID.getIdentifier();
8716 if (IDVal == ".word")
Saleem Abdulrasool38976512014-02-23 06:22:09 +00008717 return parseLiteralValues(4, DirectiveID.getLoc());
8718 else if (IDVal == ".short" || IDVal == ".hword")
8719 return parseLiteralValues(2, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008720 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008721 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00008722 else if (IDVal == ".arm")
8723 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008724 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008725 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008726 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008727 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008728 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008729 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00008730 else if (IDVal == ".unreq")
8731 return parseDirectiveUnreq(DirectiveID.getLoc());
Logan Chien4ea23b52013-05-10 16:17:24 +00008732 else if (IDVal == ".fnend")
8733 return parseDirectiveFnEnd(DirectiveID.getLoc());
8734 else if (IDVal == ".cantunwind")
8735 return parseDirectiveCantUnwind(DirectiveID.getLoc());
8736 else if (IDVal == ".personality")
8737 return parseDirectivePersonality(DirectiveID.getLoc());
8738 else if (IDVal == ".handlerdata")
8739 return parseDirectiveHandlerData(DirectiveID.getLoc());
8740 else if (IDVal == ".setfp")
8741 return parseDirectiveSetFP(DirectiveID.getLoc());
8742 else if (IDVal == ".pad")
8743 return parseDirectivePad(DirectiveID.getLoc());
8744 else if (IDVal == ".save")
8745 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
8746 else if (IDVal == ".vsave")
8747 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
Saleem Abdulrasool6e6c2392013-12-20 07:21:16 +00008748 else if (IDVal == ".ltorg" || IDVal == ".pool")
David Peixotto80c083a2013-12-19 18:26:07 +00008749 return parseDirectiveLtorg(DirectiveID.getLoc());
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00008750 else if (IDVal == ".even")
8751 return parseDirectiveEven(DirectiveID.getLoc());
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00008752 else if (IDVal == ".personalityindex")
8753 return parseDirectivePersonalityIndex(DirectiveID.getLoc());
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +00008754 else if (IDVal == ".unwind_raw")
8755 return parseDirectiveUnwindRaw(DirectiveID.getLoc());
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00008756 else if (IDVal == ".movsp")
8757 return parseDirectiveMovSP(DirectiveID.getLoc());
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00008758 else if (IDVal == ".arch_extension")
8759 return parseDirectiveArchExtension(DirectiveID.getLoc());
Saleem Abdulrasoolfd6ed1e2014-02-23 17:45:32 +00008760 else if (IDVal == ".align")
8761 return parseDirectiveAlign(DirectiveID.getLoc());
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00008762 else if (IDVal == ".thumb_set")
8763 return parseDirectiveThumbSet(DirectiveID.getLoc());
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008764
Saleem Abdulrasoolbfdfb142014-09-18 04:28:29 +00008765 if (!IsMachO && !IsCOFF) {
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008766 if (IDVal == ".arch")
8767 return parseDirectiveArch(DirectiveID.getLoc());
8768 else if (IDVal == ".cpu")
8769 return parseDirectiveCPU(DirectiveID.getLoc());
8770 else if (IDVal == ".eabi_attribute")
8771 return parseDirectiveEabiAttr(DirectiveID.getLoc());
8772 else if (IDVal == ".fpu")
8773 return parseDirectiveFPU(DirectiveID.getLoc());
8774 else if (IDVal == ".fnstart")
8775 return parseDirectiveFnStart(DirectiveID.getLoc());
8776 else if (IDVal == ".inst")
8777 return parseDirectiveInst(DirectiveID.getLoc());
8778 else if (IDVal == ".inst.n")
8779 return parseDirectiveInst(DirectiveID.getLoc(), 'n');
8780 else if (IDVal == ".inst.w")
8781 return parseDirectiveInst(DirectiveID.getLoc(), 'w');
8782 else if (IDVal == ".object_arch")
8783 return parseDirectiveObjectArch(DirectiveID.getLoc());
8784 else if (IDVal == ".tlsdescseq")
8785 return parseDirectiveTLSDescSeq(DirectiveID.getLoc());
8786 }
8787
Kevin Enderbyccab3172009-09-15 00:27:25 +00008788 return true;
8789}
8790
Saleem Abdulrasool38976512014-02-23 06:22:09 +00008791/// parseLiteralValues
8792/// ::= .hword expression [, expression]*
8793/// ::= .short expression [, expression]*
8794/// ::= .word expression [, expression]*
8795bool ARMAsmParser::parseLiteralValues(unsigned Size, SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008796 MCAsmParser &Parser = getParser();
Kevin Enderbyccab3172009-09-15 00:27:25 +00008797 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8798 for (;;) {
8799 const MCExpr *Value;
Saleem Abdulrasoola9036612014-01-26 22:29:50 +00008800 if (getParser().parseExpression(Value)) {
8801 Parser.eatToEndOfStatement();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008802 return false;
Saleem Abdulrasoola9036612014-01-26 22:29:50 +00008803 }
Kevin Enderbyccab3172009-09-15 00:27:25 +00008804
Eric Christopherbf7bc492013-01-09 03:52:05 +00008805 getParser().getStreamer().EmitValue(Value, Size);
Kevin Enderbyccab3172009-09-15 00:27:25 +00008806
8807 if (getLexer().is(AsmToken::EndOfStatement))
8808 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00008809
Kevin Enderbyccab3172009-09-15 00:27:25 +00008810 // FIXME: Improve diagnostic.
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008811 if (getLexer().isNot(AsmToken::Comma)) {
8812 Error(L, "unexpected token in directive");
8813 return false;
8814 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008815 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00008816 }
8817 }
8818
Sean Callanana83fd7d2010-01-19 20:27:46 +00008819 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00008820 return false;
8821}
8822
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008823/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00008824/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008825bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008826 MCAsmParser &Parser = getParser();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008827 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8828 Error(L, "unexpected token in directive");
8829 return false;
8830 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008831 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008832
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008833 if (!hasThumb()) {
8834 Error(L, "target does not support Thumb mode");
8835 return false;
8836 }
Tim Northovera2292d02013-06-10 23:20:58 +00008837
Jim Grosbach7f882392011-12-07 18:04:19 +00008838 if (!isThumb())
8839 SwitchMode();
Saleem Abdulrasool44419fc2014-03-22 19:26:18 +00008840
Jim Grosbach7f882392011-12-07 18:04:19 +00008841 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
8842 return false;
8843}
8844
8845/// parseDirectiveARM
8846/// ::= .arm
8847bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008848 MCAsmParser &Parser = getParser();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008849 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8850 Error(L, "unexpected token in directive");
8851 return false;
8852 }
Jim Grosbach7f882392011-12-07 18:04:19 +00008853 Parser.Lex();
8854
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008855 if (!hasARM()) {
8856 Error(L, "target does not support ARM mode");
8857 return false;
8858 }
Tim Northovera2292d02013-06-10 23:20:58 +00008859
Jim Grosbach7f882392011-12-07 18:04:19 +00008860 if (isThumb())
8861 SwitchMode();
Saleem Abdulrasool44419fc2014-03-22 19:26:18 +00008862
Jim Grosbach7f882392011-12-07 18:04:19 +00008863 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00008864 return false;
8865}
8866
Tim Northover1744d0a2013-10-25 12:49:50 +00008867void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) {
8868 if (NextSymbolIsThumb) {
8869 getParser().getStreamer().EmitThumbFunc(Symbol);
8870 NextSymbolIsThumb = false;
8871 }
8872}
8873
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008874/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00008875/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008876bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008877 MCAsmParser &Parser = getParser();
Saleem Abdulrasool8c61c6c2014-09-18 03:49:55 +00008878 const auto Format = getContext().getObjectFileInfo()->getObjectFileType();
8879 bool IsMachO = Format == MCObjectFileInfo::IsMachO;
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008880
Jim Grosbach1152cc02011-12-21 22:30:16 +00008881 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008882 // ELF doesn't
Saleem Abdulrasool8c61c6c2014-09-18 03:49:55 +00008883 if (IsMachO) {
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008884 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00008885 if (Tok.isNot(AsmToken::EndOfStatement)) {
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008886 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String)) {
8887 Error(L, "unexpected token in .thumb_func directive");
8888 return false;
8889 }
8890
Tim Northover1744d0a2013-10-25 12:49:50 +00008891 MCSymbol *Func =
8892 getParser().getContext().GetOrCreateSymbol(Tok.getIdentifier());
8893 getParser().getStreamer().EmitThumbFunc(Func);
Jim Grosbach1152cc02011-12-21 22:30:16 +00008894 Parser.Lex(); // Consume the identifier token.
Tim Northover1744d0a2013-10-25 12:49:50 +00008895 return false;
Jim Grosbach1152cc02011-12-21 22:30:16 +00008896 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008897 }
8898
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008899 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Saleem Abdulrasool8c61c6c2014-09-18 03:49:55 +00008900 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8901 Parser.eatToEndOfStatement();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008902 return false;
8903 }
Jim Grosbach1152cc02011-12-21 22:30:16 +00008904
Tim Northover1744d0a2013-10-25 12:49:50 +00008905 NextSymbolIsThumb = true;
Kevin Enderby146dcf22009-10-15 20:48:48 +00008906 return false;
8907}
8908
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008909/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00008910/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008911bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008912 MCAsmParser &Parser = getParser();
Sean Callanan936b0d32010-01-19 21:44:56 +00008913 const AsmToken &Tok = Parser.getTok();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008914 if (Tok.isNot(AsmToken::Identifier)) {
8915 Error(L, "unexpected token in .syntax directive");
8916 return false;
8917 }
8918
Benjamin Kramer92d89982010-07-14 22:38:02 +00008919 StringRef Mode = Tok.getString();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008920 if (Mode == "unified" || Mode == "UNIFIED") {
Sean Callanana83fd7d2010-01-19 20:27:46 +00008921 Parser.Lex();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008922 } else if (Mode == "divided" || Mode == "DIVIDED") {
8923 Error(L, "'.syntax divided' arm asssembly not supported");
8924 return false;
8925 } else {
8926 Error(L, "unrecognized syntax mode in .syntax directive");
8927 return false;
8928 }
Kevin Enderby146dcf22009-10-15 20:48:48 +00008929
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008930 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8931 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8932 return false;
8933 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008934 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008935
8936 // TODO tell the MC streamer the mode
8937 // getParser().getStreamer().Emit???();
8938 return false;
8939}
8940
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008941/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00008942/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008943bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008944 MCAsmParser &Parser = getParser();
Sean Callanan936b0d32010-01-19 21:44:56 +00008945 const AsmToken &Tok = Parser.getTok();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008946 if (Tok.isNot(AsmToken::Integer)) {
8947 Error(L, "unexpected token in .code directive");
8948 return false;
8949 }
Sean Callanan936b0d32010-01-19 21:44:56 +00008950 int64_t Val = Parser.getTok().getIntVal();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008951 if (Val != 16 && Val != 32) {
8952 Error(L, "invalid operand to .code directive");
8953 return false;
8954 }
8955 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008956
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008957 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8958 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8959 return false;
8960 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008961 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008962
Evan Cheng284b4672011-07-08 22:36:29 +00008963 if (Val == 16) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008964 if (!hasThumb()) {
8965 Error(L, "target does not support Thumb mode");
8966 return false;
8967 }
Tim Northovera2292d02013-06-10 23:20:58 +00008968
Jim Grosbachf471ac32011-09-06 18:46:23 +00008969 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00008970 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00008971 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00008972 } else {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008973 if (!hasARM()) {
8974 Error(L, "target does not support ARM mode");
8975 return false;
8976 }
Tim Northovera2292d02013-06-10 23:20:58 +00008977
Jim Grosbachf471ac32011-09-06 18:46:23 +00008978 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00008979 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00008980 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00008981 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00008982
Kevin Enderby146dcf22009-10-15 20:48:48 +00008983 return false;
8984}
8985
Jim Grosbachab5830e2011-12-14 02:16:11 +00008986/// parseDirectiveReq
8987/// ::= name .req registername
8988bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008989 MCAsmParser &Parser = getParser();
Jim Grosbachab5830e2011-12-14 02:16:11 +00008990 Parser.Lex(); // Eat the '.req' token.
8991 unsigned Reg;
8992 SMLoc SRegLoc, ERegLoc;
8993 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008994 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008995 Error(SRegLoc, "register name expected");
8996 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00008997 }
8998
8999 // Shouldn't be anything else.
9000 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00009001 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009002 Error(Parser.getTok().getLoc(), "unexpected input in .req directive.");
9003 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00009004 }
9005
9006 Parser.Lex(); // Consume the EndOfStatement
9007
Frederic Rissb61f01f2015-02-04 03:10:03 +00009008 if (RegisterReqs.insert(std::make_pair(Name, Reg)).first->second != Reg) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009009 Error(SRegLoc, "redefinition of '" + Name + "' does not match original.");
9010 return false;
9011 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00009012
9013 return false;
9014}
9015
9016/// parseDirectiveUneq
9017/// ::= .unreq registername
9018bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009019 MCAsmParser &Parser = getParser();
Jim Grosbachab5830e2011-12-14 02:16:11 +00009020 if (Parser.getTok().isNot(AsmToken::Identifier)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00009021 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009022 Error(L, "unexpected input in .unreq directive.");
9023 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00009024 }
Duncan P. N. Exon Smith29db0eb2014-03-07 16:16:52 +00009025 RegisterReqs.erase(Parser.getTok().getIdentifier().lower());
Jim Grosbachab5830e2011-12-14 02:16:11 +00009026 Parser.Lex(); // Eat the identifier.
9027 return false;
9028}
9029
Jason W Kim135d2442011-12-20 17:38:12 +00009030/// parseDirectiveArch
9031/// ::= .arch token
9032bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
Logan Chien439e8f92013-12-11 17:16:25 +00009033 StringRef Arch = getParser().parseStringToEndOfStatement().trim();
9034
9035 unsigned ID = StringSwitch<unsigned>(Arch)
9036#define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
9037 .Case(NAME, ARM::ID)
Joerg Sonnenbergera13f8b42013-12-26 11:50:28 +00009038#define ARM_ARCH_ALIAS(NAME, ID) \
9039 .Case(NAME, ARM::ID)
Logan Chien439e8f92013-12-11 17:16:25 +00009040#include "MCTargetDesc/ARMArchName.def"
9041 .Default(ARM::INVALID_ARCH);
9042
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009043 if (ID == ARM::INVALID_ARCH) {
9044 Error(L, "Unknown arch name");
9045 return false;
9046 }
Logan Chien439e8f92013-12-11 17:16:25 +00009047
9048 getTargetStreamer().emitArch(ID);
9049 return false;
Jason W Kim135d2442011-12-20 17:38:12 +00009050}
9051
9052/// parseDirectiveEabiAttr
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009053/// ::= .eabi_attribute int, int [, "str"]
9054/// ::= .eabi_attribute Tag_name, int [, "str"]
Jason W Kim135d2442011-12-20 17:38:12 +00009055bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009056 MCAsmParser &Parser = getParser();
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009057 int64_t Tag;
9058 SMLoc TagLoc;
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009059 TagLoc = Parser.getTok().getLoc();
9060 if (Parser.getTok().is(AsmToken::Identifier)) {
9061 StringRef Name = Parser.getTok().getIdentifier();
9062 Tag = ARMBuildAttrs::AttrTypeFromString(Name);
9063 if (Tag == -1) {
9064 Error(TagLoc, "attribute name not recognised: " + Name);
9065 Parser.eatToEndOfStatement();
9066 return false;
9067 }
9068 Parser.Lex();
9069 } else {
9070 const MCExpr *AttrExpr;
9071
9072 TagLoc = Parser.getTok().getLoc();
9073 if (Parser.parseExpression(AttrExpr)) {
9074 Parser.eatToEndOfStatement();
9075 return false;
9076 }
9077
9078 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(AttrExpr);
9079 if (!CE) {
9080 Error(TagLoc, "expected numeric constant");
9081 Parser.eatToEndOfStatement();
9082 return false;
9083 }
9084
9085 Tag = CE->getValue();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009086 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00009087
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009088 if (Parser.getTok().isNot(AsmToken::Comma)) {
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009089 Error(Parser.getTok().getLoc(), "comma expected");
9090 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009091 return false;
9092 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00009093 Parser.Lex(); // skip comma
9094
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009095 StringRef StringValue = "";
9096 bool IsStringValue = false;
Logan Chien8cbb80d2013-10-28 17:51:12 +00009097
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009098 int64_t IntegerValue = 0;
9099 bool IsIntegerValue = false;
9100
9101 if (Tag == ARMBuildAttrs::CPU_raw_name || Tag == ARMBuildAttrs::CPU_name)
9102 IsStringValue = true;
9103 else if (Tag == ARMBuildAttrs::compatibility) {
9104 IsStringValue = true;
9105 IsIntegerValue = true;
Saleem Abdulrasool9dedf642014-01-19 08:25:19 +00009106 } else if (Tag < 32 || Tag % 2 == 0)
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009107 IsIntegerValue = true;
9108 else if (Tag % 2 == 1)
9109 IsStringValue = true;
9110 else
9111 llvm_unreachable("invalid tag type");
9112
9113 if (IsIntegerValue) {
9114 const MCExpr *ValueExpr;
9115 SMLoc ValueExprLoc = Parser.getTok().getLoc();
9116 if (Parser.parseExpression(ValueExpr)) {
9117 Parser.eatToEndOfStatement();
9118 return false;
9119 }
9120
9121 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ValueExpr);
9122 if (!CE) {
9123 Error(ValueExprLoc, "expected numeric constant");
9124 Parser.eatToEndOfStatement();
9125 return false;
9126 }
9127
9128 IntegerValue = CE->getValue();
9129 }
9130
9131 if (Tag == ARMBuildAttrs::compatibility) {
9132 if (Parser.getTok().isNot(AsmToken::Comma))
9133 IsStringValue = false;
Charlie Turner6632d1f2015-01-05 13:26:37 +00009134 if (Parser.getTok().isNot(AsmToken::Comma)) {
9135 Error(Parser.getTok().getLoc(), "comma expected");
9136 Parser.eatToEndOfStatement();
9137 return false;
9138 } else {
9139 Parser.Lex();
9140 }
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009141 }
9142
9143 if (IsStringValue) {
9144 if (Parser.getTok().isNot(AsmToken::String)) {
9145 Error(Parser.getTok().getLoc(), "bad string constant");
9146 Parser.eatToEndOfStatement();
9147 return false;
9148 }
9149
9150 StringValue = Parser.getTok().getStringContents();
9151 Parser.Lex();
9152 }
9153
9154 if (IsIntegerValue && IsStringValue) {
9155 assert(Tag == ARMBuildAttrs::compatibility);
9156 getTargetStreamer().emitIntTextAttribute(Tag, IntegerValue, StringValue);
9157 } else if (IsIntegerValue)
9158 getTargetStreamer().emitAttribute(Tag, IntegerValue);
9159 else if (IsStringValue)
9160 getTargetStreamer().emitTextAttribute(Tag, StringValue);
Logan Chien8cbb80d2013-10-28 17:51:12 +00009161 return false;
9162}
9163
9164/// parseDirectiveCPU
9165/// ::= .cpu str
9166bool ARMAsmParser::parseDirectiveCPU(SMLoc L) {
9167 StringRef CPU = getParser().parseStringToEndOfStatement().trim();
9168 getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name, CPU);
Roman Divacky7e6b5952014-12-02 20:03:22 +00009169
Roman Divackyfdf05602014-12-03 18:39:44 +00009170 if (!STI.isCPUStringValid(CPU)) {
Roman Divacky7e6b5952014-12-02 20:03:22 +00009171 Error(L, "Unknown CPU name");
9172 return false;
9173 }
9174
Roman Divacky6fd64ff2014-12-04 21:39:24 +00009175 // FIXME: This switches the CPU features globally, therefore it might
9176 // happen that code you would not expect to assemble will. For details
9177 // see: http://llvm.org/bugs/show_bug.cgi?id=20757
Roman Divacky7e6b5952014-12-02 20:03:22 +00009178 STI.InitMCProcessorInfo(CPU, "");
9179 STI.InitCPUSchedModel(CPU);
Bradley Smith9f4cd592015-02-04 16:23:24 +00009180 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Roman Divacky7e6b5952014-12-02 20:03:22 +00009181
Logan Chien8cbb80d2013-10-28 17:51:12 +00009182 return false;
9183}
9184
Nico Weberae050bb2014-08-16 05:37:51 +00009185// FIXME: This is duplicated in getARMFPUFeatures() in
9186// tools/clang/lib/Driver/Tools.cpp
9187static const struct {
Saleem Abdulrasool206d1162015-01-30 17:58:25 +00009188 const unsigned ID;
Michael Kuperstein29704e72015-03-24 12:56:59 +00009189 const uint64_t Enabled;
9190 const uint64_t Disabled;
Saleem Abdulrasool206d1162015-01-30 17:58:25 +00009191} FPUs[] = {
Michael Kuperstein29704e72015-03-24 12:56:59 +00009192 {/* ID */ ARM::VFP,
9193 /* Enabled */ ARM::FeatureVFP2,
9194 /* Disabled */ ARM::FeatureNEON},
9195 {/* ID */ ARM::VFPV2,
9196 /* Enabled */ ARM::FeatureVFP2,
9197 /* Disabled */ ARM::FeatureNEON},
9198 {/* ID */ ARM::VFPV3,
9199 /* Enabled */ ARM::FeatureVFP2 | ARM::FeatureVFP3,
9200 /* Disabled */ ARM::FeatureNEON | ARM::FeatureD16},
9201 {/* ID */ ARM::VFPV3_D16,
9202 /* Enable */ ARM::FeatureVFP2 | ARM::FeatureVFP3 | ARM::FeatureD16,
9203 /* Disabled */ ARM::FeatureNEON},
9204 {/* ID */ ARM::VFPV4,
9205 /* Enabled */ ARM::FeatureVFP2 | ARM::FeatureVFP3 | ARM::FeatureVFP4,
9206 /* Disabled */ ARM::FeatureNEON | ARM::FeatureD16},
9207 {/* ID */ ARM::VFPV4_D16,
9208 /* Enabled */ ARM::FeatureVFP2 | ARM::FeatureVFP3 | ARM::FeatureVFP4 |
9209 ARM::FeatureD16,
9210 /* Disabled */ ARM::FeatureNEON},
9211 {/* ID */ ARM::FPV5_D16,
9212 /* Enabled */ ARM::FeatureVFP2 | ARM::FeatureVFP3 | ARM::FeatureVFP4 |
9213 ARM::FeatureFPARMv8 | ARM::FeatureD16,
9214 /* Disabled */ ARM::FeatureNEON | ARM::FeatureCrypto},
9215 {/* ID */ ARM::FP_ARMV8,
9216 /* Enabled */ ARM::FeatureVFP2 | ARM::FeatureVFP3 | ARM::FeatureVFP4 |
9217 ARM::FeatureFPARMv8,
9218 /* Disabled */ ARM::FeatureNEON | ARM::FeatureCrypto | ARM::FeatureD16},
9219 {/* ID */ ARM::NEON,
9220 /* Enabled */ ARM::FeatureVFP2 | ARM::FeatureVFP3 | ARM::FeatureNEON,
9221 /* Disabled */ ARM::FeatureD16},
9222 {/* ID */ ARM::NEON_VFPV4,
9223 /* Enabled */ ARM::FeatureVFP2 | ARM::FeatureVFP3 | ARM::FeatureVFP4 |
9224 ARM::FeatureNEON,
9225 /* Disabled */ ARM::FeatureD16},
9226 {/* ID */ ARM::NEON_FP_ARMV8,
9227 /* Enabled */ ARM::FeatureVFP2 | ARM::FeatureVFP3 | ARM::FeatureVFP4 |
9228 ARM::FeatureFPARMv8 | ARM::FeatureNEON,
9229 /* Disabled */ ARM::FeatureCrypto | ARM::FeatureD16},
9230 {/* ID */ ARM::CRYPTO_NEON_FP_ARMV8,
9231 /* Enabled */ ARM::FeatureVFP2 | ARM::FeatureVFP3 | ARM::FeatureVFP4 |
9232 ARM::FeatureFPARMv8 | ARM::FeatureNEON | ARM::FeatureCrypto,
9233 /* Disabled */ ARM::FeatureD16},
9234 {ARM::SOFTVFP, 0, 0},
Nico Weberae050bb2014-08-16 05:37:51 +00009235};
9236
Logan Chien8cbb80d2013-10-28 17:51:12 +00009237/// parseDirectiveFPU
9238/// ::= .fpu str
9239bool ARMAsmParser::parseDirectiveFPU(SMLoc L) {
Saleem Abdulrasool07b7c032015-01-30 18:42:10 +00009240 SMLoc FPUNameLoc = getTok().getLoc();
Logan Chien8cbb80d2013-10-28 17:51:12 +00009241 StringRef FPU = getParser().parseStringToEndOfStatement().trim();
9242
9243 unsigned ID = StringSwitch<unsigned>(FPU)
9244#define ARM_FPU_NAME(NAME, ID) .Case(NAME, ARM::ID)
9245#include "ARMFPUName.def"
9246 .Default(ARM::INVALID_FPU);
9247
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009248 if (ID == ARM::INVALID_FPU) {
Saleem Abdulrasool07b7c032015-01-30 18:42:10 +00009249 Error(FPUNameLoc, "Unknown FPU name");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009250 return false;
9251 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00009252
Saleem Abdulrasool206d1162015-01-30 17:58:25 +00009253 for (const auto &Entry : FPUs) {
9254 if (Entry.ID != ID)
Nico Weberae050bb2014-08-16 05:37:51 +00009255 continue;
9256
9257 // Need to toggle features that should be on but are off and that
9258 // should off but are on.
Michael Kuperstein29704e72015-03-24 12:56:59 +00009259 uint64_t Toggle = (Entry.Enabled & ~STI.getFeatureBits()) |
9260 (Entry.Disabled & STI.getFeatureBits());
Nico Weberae050bb2014-08-16 05:37:51 +00009261 setAvailableFeatures(ComputeAvailableFeatures(STI.ToggleFeature(Toggle)));
9262 break;
9263 }
9264
Logan Chien8cbb80d2013-10-28 17:51:12 +00009265 getTargetStreamer().emitFPU(ID);
9266 return false;
Jason W Kim135d2442011-12-20 17:38:12 +00009267}
9268
Logan Chien4ea23b52013-05-10 16:17:24 +00009269/// parseDirectiveFnStart
9270/// ::= .fnstart
9271bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009272 if (UC.hasFnStart()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009273 Error(L, ".fnstart starts before the end of previous one");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009274 UC.emitFnStartLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009275 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009276 }
9277
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009278 // Reset the unwind directives parser state
9279 UC.reset();
9280
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009281 getTargetStreamer().emitFnStart();
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009282
9283 UC.recordFnStart(L);
Logan Chien4ea23b52013-05-10 16:17:24 +00009284 return false;
9285}
9286
9287/// parseDirectiveFnEnd
9288/// ::= .fnend
9289bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
9290 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009291 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009292 Error(L, ".fnstart must precede .fnend directive");
9293 return false;
9294 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009295
9296 // Reset the unwind directives parser state
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009297 getTargetStreamer().emitFnEnd();
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009298
9299 UC.reset();
Logan Chien4ea23b52013-05-10 16:17:24 +00009300 return false;
9301}
9302
9303/// parseDirectiveCantUnwind
9304/// ::= .cantunwind
9305bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009306 UC.recordCantUnwind(L);
9307
Logan Chien4ea23b52013-05-10 16:17:24 +00009308 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009309 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009310 Error(L, ".fnstart must precede .cantunwind directive");
9311 return false;
9312 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009313 if (UC.hasHandlerData()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009314 Error(L, ".cantunwind can't be used with .handlerdata directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009315 UC.emitHandlerDataLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009316 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009317 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009318 if (UC.hasPersonality()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009319 Error(L, ".cantunwind can't be used with .personality directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009320 UC.emitPersonalityLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009321 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009322 }
9323
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009324 getTargetStreamer().emitCantUnwind();
Logan Chien4ea23b52013-05-10 16:17:24 +00009325 return false;
9326}
9327
9328/// parseDirectivePersonality
9329/// ::= .personality name
9330bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009331 MCAsmParser &Parser = getParser();
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009332 bool HasExistingPersonality = UC.hasPersonality();
9333
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009334 UC.recordPersonality(L);
9335
Logan Chien4ea23b52013-05-10 16:17:24 +00009336 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009337 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009338 Error(L, ".fnstart must precede .personality directive");
9339 return false;
9340 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009341 if (UC.cantUnwind()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009342 Error(L, ".personality can't be used with .cantunwind directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009343 UC.emitCantUnwindLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009344 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009345 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009346 if (UC.hasHandlerData()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009347 Error(L, ".personality must precede .handlerdata directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009348 UC.emitHandlerDataLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009349 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009350 }
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009351 if (HasExistingPersonality) {
9352 Parser.eatToEndOfStatement();
9353 Error(L, "multiple personality directives");
9354 UC.emitPersonalityLocNotes();
9355 return false;
9356 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009357
9358 // Parse the name of the personality routine
9359 if (Parser.getTok().isNot(AsmToken::Identifier)) {
9360 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009361 Error(L, "unexpected input in .personality directive.");
9362 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009363 }
9364 StringRef Name(Parser.getTok().getIdentifier());
9365 Parser.Lex();
9366
9367 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009368 getTargetStreamer().emitPersonality(PR);
Logan Chien4ea23b52013-05-10 16:17:24 +00009369 return false;
9370}
9371
9372/// parseDirectiveHandlerData
9373/// ::= .handlerdata
9374bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009375 UC.recordHandlerData(L);
9376
Logan Chien4ea23b52013-05-10 16:17:24 +00009377 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009378 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009379 Error(L, ".fnstart must precede .personality directive");
9380 return false;
9381 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009382 if (UC.cantUnwind()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009383 Error(L, ".handlerdata can't be used with .cantunwind directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009384 UC.emitCantUnwindLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009385 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009386 }
9387
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009388 getTargetStreamer().emitHandlerData();
Logan Chien4ea23b52013-05-10 16:17:24 +00009389 return false;
9390}
9391
9392/// parseDirectiveSetFP
9393/// ::= .setfp fpreg, spreg [, offset]
9394bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009395 MCAsmParser &Parser = getParser();
Logan Chien4ea23b52013-05-10 16:17:24 +00009396 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009397 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009398 Error(L, ".fnstart must precede .setfp directive");
9399 return false;
9400 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009401 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009402 Error(L, ".setfp must precede .handlerdata directive");
9403 return false;
9404 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009405
9406 // Parse fpreg
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009407 SMLoc FPRegLoc = Parser.getTok().getLoc();
9408 int FPReg = tryParseRegister();
9409 if (FPReg == -1) {
9410 Error(FPRegLoc, "frame pointer register expected");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009411 return false;
9412 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009413
9414 // Consume comma
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00009415 if (Parser.getTok().isNot(AsmToken::Comma)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009416 Error(Parser.getTok().getLoc(), "comma expected");
9417 return false;
9418 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009419 Parser.Lex(); // skip comma
9420
9421 // Parse spreg
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009422 SMLoc SPRegLoc = Parser.getTok().getLoc();
9423 int SPReg = tryParseRegister();
9424 if (SPReg == -1) {
9425 Error(SPRegLoc, "stack pointer register expected");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009426 return false;
9427 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009428
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009429 if (SPReg != ARM::SP && SPReg != UC.getFPReg()) {
9430 Error(SPRegLoc, "register should be either $sp or the latest fp register");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009431 return false;
9432 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009433
9434 // Update the frame pointer register
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009435 UC.saveFPReg(FPReg);
Logan Chien4ea23b52013-05-10 16:17:24 +00009436
9437 // Parse offset
9438 int64_t Offset = 0;
9439 if (Parser.getTok().is(AsmToken::Comma)) {
9440 Parser.Lex(); // skip comma
9441
9442 if (Parser.getTok().isNot(AsmToken::Hash) &&
9443 Parser.getTok().isNot(AsmToken::Dollar)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009444 Error(Parser.getTok().getLoc(), "'#' expected");
9445 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009446 }
9447 Parser.Lex(); // skip hash token.
9448
9449 const MCExpr *OffsetExpr;
9450 SMLoc ExLoc = Parser.getTok().getLoc();
9451 SMLoc EndLoc;
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009452 if (getParser().parseExpression(OffsetExpr, EndLoc)) {
9453 Error(ExLoc, "malformed setfp offset");
9454 return false;
9455 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009456 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009457 if (!CE) {
9458 Error(ExLoc, "setfp offset must be an immediate");
9459 return false;
9460 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009461
9462 Offset = CE->getValue();
9463 }
9464
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009465 getTargetStreamer().emitSetFP(static_cast<unsigned>(FPReg),
9466 static_cast<unsigned>(SPReg), Offset);
Logan Chien4ea23b52013-05-10 16:17:24 +00009467 return false;
9468}
9469
9470/// parseDirective
9471/// ::= .pad offset
9472bool ARMAsmParser::parseDirectivePad(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009473 MCAsmParser &Parser = getParser();
Logan Chien4ea23b52013-05-10 16:17:24 +00009474 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009475 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009476 Error(L, ".fnstart must precede .pad directive");
9477 return false;
9478 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009479 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009480 Error(L, ".pad must precede .handlerdata directive");
9481 return false;
9482 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009483
9484 // Parse the offset
9485 if (Parser.getTok().isNot(AsmToken::Hash) &&
9486 Parser.getTok().isNot(AsmToken::Dollar)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009487 Error(Parser.getTok().getLoc(), "'#' expected");
9488 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009489 }
9490 Parser.Lex(); // skip hash token.
9491
9492 const MCExpr *OffsetExpr;
9493 SMLoc ExLoc = Parser.getTok().getLoc();
9494 SMLoc EndLoc;
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009495 if (getParser().parseExpression(OffsetExpr, EndLoc)) {
9496 Error(ExLoc, "malformed pad offset");
9497 return false;
9498 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009499 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009500 if (!CE) {
9501 Error(ExLoc, "pad offset must be an immediate");
9502 return false;
9503 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009504
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009505 getTargetStreamer().emitPad(CE->getValue());
Logan Chien4ea23b52013-05-10 16:17:24 +00009506 return false;
9507}
9508
9509/// parseDirectiveRegSave
9510/// ::= .save { registers }
9511/// ::= .vsave { registers }
9512bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
9513 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009514 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009515 Error(L, ".fnstart must precede .save or .vsave directives");
9516 return false;
9517 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009518 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009519 Error(L, ".save or .vsave must precede .handlerdata directive");
9520 return false;
9521 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009522
Benjamin Kramer23632bd2013-08-03 22:16:24 +00009523 // RAII object to make sure parsed operands are deleted.
David Blaikie960ea3f2014-06-08 16:18:35 +00009524 SmallVector<std::unique_ptr<MCParsedAsmOperand>, 1> Operands;
Benjamin Kramer23632bd2013-08-03 22:16:24 +00009525
Logan Chien4ea23b52013-05-10 16:17:24 +00009526 // Parse the register list
David Blaikie960ea3f2014-06-08 16:18:35 +00009527 if (parseRegisterList(Operands))
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00009528 return false;
David Blaikie960ea3f2014-06-08 16:18:35 +00009529 ARMOperand &Op = (ARMOperand &)*Operands[0];
9530 if (!IsVector && !Op.isRegList()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009531 Error(L, ".save expects GPR registers");
9532 return false;
9533 }
David Blaikie960ea3f2014-06-08 16:18:35 +00009534 if (IsVector && !Op.isDPRRegList()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009535 Error(L, ".vsave expects DPR registers");
9536 return false;
9537 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009538
David Blaikie960ea3f2014-06-08 16:18:35 +00009539 getTargetStreamer().emitRegSave(Op.getRegList(), IsVector);
Logan Chien4ea23b52013-05-10 16:17:24 +00009540 return false;
9541}
9542
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009543/// parseDirectiveInst
9544/// ::= .inst opcode [, ...]
9545/// ::= .inst.n opcode [, ...]
9546/// ::= .inst.w opcode [, ...]
9547bool ARMAsmParser::parseDirectiveInst(SMLoc Loc, char Suffix) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009548 MCAsmParser &Parser = getParser();
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009549 int Width;
9550
9551 if (isThumb()) {
9552 switch (Suffix) {
9553 case 'n':
9554 Width = 2;
9555 break;
9556 case 'w':
9557 Width = 4;
9558 break;
9559 default:
9560 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009561 Error(Loc, "cannot determine Thumb instruction size, "
9562 "use inst.n/inst.w instead");
9563 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009564 }
9565 } else {
9566 if (Suffix) {
9567 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009568 Error(Loc, "width suffixes are invalid in ARM mode");
9569 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009570 }
9571 Width = 4;
9572 }
9573
9574 if (getLexer().is(AsmToken::EndOfStatement)) {
9575 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009576 Error(Loc, "expected expression following directive");
9577 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009578 }
9579
9580 for (;;) {
9581 const MCExpr *Expr;
9582
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009583 if (getParser().parseExpression(Expr)) {
9584 Error(Loc, "expected expression");
9585 return false;
9586 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009587
9588 const MCConstantExpr *Value = dyn_cast_or_null<MCConstantExpr>(Expr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009589 if (!Value) {
9590 Error(Loc, "expected constant expression");
9591 return false;
9592 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009593
9594 switch (Width) {
9595 case 2:
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009596 if (Value->getValue() > 0xffff) {
9597 Error(Loc, "inst.n operand is too big, use inst.w instead");
9598 return false;
9599 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009600 break;
9601 case 4:
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009602 if (Value->getValue() > 0xffffffff) {
9603 Error(Loc,
9604 StringRef(Suffix ? "inst.w" : "inst") + " operand is too big");
9605 return false;
9606 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009607 break;
9608 default:
9609 llvm_unreachable("only supported widths are 2 and 4");
9610 }
9611
9612 getTargetStreamer().emitInst(Value->getValue(), Suffix);
9613
9614 if (getLexer().is(AsmToken::EndOfStatement))
9615 break;
9616
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009617 if (getLexer().isNot(AsmToken::Comma)) {
9618 Error(Loc, "unexpected token in directive");
9619 return false;
9620 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009621
9622 Parser.Lex();
9623 }
9624
9625 Parser.Lex();
9626 return false;
9627}
9628
David Peixotto80c083a2013-12-19 18:26:07 +00009629/// parseDirectiveLtorg
Saleem Abdulrasool6e6c2392013-12-20 07:21:16 +00009630/// ::= .ltorg | .pool
David Peixotto80c083a2013-12-19 18:26:07 +00009631bool ARMAsmParser::parseDirectiveLtorg(SMLoc L) {
David Peixottob9b73622014-02-04 17:22:40 +00009632 getTargetStreamer().emitCurrentConstantPool();
David Peixotto80c083a2013-12-19 18:26:07 +00009633 return false;
9634}
9635
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009636bool ARMAsmParser::parseDirectiveEven(SMLoc L) {
9637 const MCSection *Section = getStreamer().getCurrentSection().first;
9638
9639 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9640 TokError("unexpected token in directive");
9641 return false;
9642 }
9643
9644 if (!Section) {
Rafael Espindola7b61ddf2014-10-15 16:12:52 +00009645 getStreamer().InitSections(false);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009646 Section = getStreamer().getCurrentSection().first;
9647 }
9648
Saleem Abdulrasool42b233a2014-03-18 05:26:55 +00009649 assert(Section && "must have section to emit alignment");
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009650 if (Section->UseCodeAlign())
Rafael Espindola7b514962014-02-04 18:34:04 +00009651 getStreamer().EmitCodeAlignment(2);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009652 else
Rafael Espindola7b514962014-02-04 18:34:04 +00009653 getStreamer().EmitValueToAlignment(2);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009654
9655 return false;
9656}
9657
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009658/// parseDirectivePersonalityIndex
9659/// ::= .personalityindex index
9660bool ARMAsmParser::parseDirectivePersonalityIndex(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009661 MCAsmParser &Parser = getParser();
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009662 bool HasExistingPersonality = UC.hasPersonality();
9663
9664 UC.recordPersonalityIndex(L);
9665
9666 if (!UC.hasFnStart()) {
9667 Parser.eatToEndOfStatement();
9668 Error(L, ".fnstart must precede .personalityindex directive");
9669 return false;
9670 }
9671 if (UC.cantUnwind()) {
9672 Parser.eatToEndOfStatement();
9673 Error(L, ".personalityindex cannot be used with .cantunwind");
9674 UC.emitCantUnwindLocNotes();
9675 return false;
9676 }
9677 if (UC.hasHandlerData()) {
9678 Parser.eatToEndOfStatement();
9679 Error(L, ".personalityindex must precede .handlerdata directive");
9680 UC.emitHandlerDataLocNotes();
9681 return false;
9682 }
9683 if (HasExistingPersonality) {
9684 Parser.eatToEndOfStatement();
9685 Error(L, "multiple personality directives");
9686 UC.emitPersonalityLocNotes();
9687 return false;
9688 }
9689
9690 const MCExpr *IndexExpression;
9691 SMLoc IndexLoc = Parser.getTok().getLoc();
9692 if (Parser.parseExpression(IndexExpression)) {
9693 Parser.eatToEndOfStatement();
9694 return false;
9695 }
9696
9697 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(IndexExpression);
9698 if (!CE) {
9699 Parser.eatToEndOfStatement();
9700 Error(IndexLoc, "index must be a constant number");
9701 return false;
9702 }
9703 if (CE->getValue() < 0 ||
9704 CE->getValue() >= ARM::EHABI::NUM_PERSONALITY_INDEX) {
9705 Parser.eatToEndOfStatement();
9706 Error(IndexLoc, "personality routine index should be in range [0-3]");
9707 return false;
9708 }
9709
9710 getTargetStreamer().emitPersonalityIndex(CE->getValue());
9711 return false;
9712}
9713
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +00009714/// parseDirectiveUnwindRaw
9715/// ::= .unwind_raw offset, opcode [, opcode...]
9716bool ARMAsmParser::parseDirectiveUnwindRaw(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009717 MCAsmParser &Parser = getParser();
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +00009718 if (!UC.hasFnStart()) {
9719 Parser.eatToEndOfStatement();
9720 Error(L, ".fnstart must precede .unwind_raw directives");
9721 return false;
9722 }
9723
9724 int64_t StackOffset;
9725
9726 const MCExpr *OffsetExpr;
9727 SMLoc OffsetLoc = getLexer().getLoc();
9728 if (getLexer().is(AsmToken::EndOfStatement) ||
9729 getParser().parseExpression(OffsetExpr)) {
9730 Error(OffsetLoc, "expected expression");
9731 Parser.eatToEndOfStatement();
9732 return false;
9733 }
9734
9735 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
9736 if (!CE) {
9737 Error(OffsetLoc, "offset must be a constant");
9738 Parser.eatToEndOfStatement();
9739 return false;
9740 }
9741
9742 StackOffset = CE->getValue();
9743
9744 if (getLexer().isNot(AsmToken::Comma)) {
9745 Error(getLexer().getLoc(), "expected comma");
9746 Parser.eatToEndOfStatement();
9747 return false;
9748 }
9749 Parser.Lex();
9750
9751 SmallVector<uint8_t, 16> Opcodes;
9752 for (;;) {
9753 const MCExpr *OE;
9754
9755 SMLoc OpcodeLoc = getLexer().getLoc();
9756 if (getLexer().is(AsmToken::EndOfStatement) || Parser.parseExpression(OE)) {
9757 Error(OpcodeLoc, "expected opcode expression");
9758 Parser.eatToEndOfStatement();
9759 return false;
9760 }
9761
9762 const MCConstantExpr *OC = dyn_cast<MCConstantExpr>(OE);
9763 if (!OC) {
9764 Error(OpcodeLoc, "opcode value must be a constant");
9765 Parser.eatToEndOfStatement();
9766 return false;
9767 }
9768
9769 const int64_t Opcode = OC->getValue();
9770 if (Opcode & ~0xff) {
9771 Error(OpcodeLoc, "invalid opcode");
9772 Parser.eatToEndOfStatement();
9773 return false;
9774 }
9775
9776 Opcodes.push_back(uint8_t(Opcode));
9777
9778 if (getLexer().is(AsmToken::EndOfStatement))
9779 break;
9780
9781 if (getLexer().isNot(AsmToken::Comma)) {
9782 Error(getLexer().getLoc(), "unexpected token in directive");
9783 Parser.eatToEndOfStatement();
9784 return false;
9785 }
9786
9787 Parser.Lex();
9788 }
9789
9790 getTargetStreamer().emitUnwindRaw(StackOffset, Opcodes);
9791
9792 Parser.Lex();
9793 return false;
9794}
9795
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +00009796/// parseDirectiveTLSDescSeq
9797/// ::= .tlsdescseq tls-variable
9798bool ARMAsmParser::parseDirectiveTLSDescSeq(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009799 MCAsmParser &Parser = getParser();
9800
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +00009801 if (getLexer().isNot(AsmToken::Identifier)) {
9802 TokError("expected variable after '.tlsdescseq' directive");
9803 Parser.eatToEndOfStatement();
9804 return false;
9805 }
9806
9807 const MCSymbolRefExpr *SRE =
9808 MCSymbolRefExpr::Create(Parser.getTok().getIdentifier(),
9809 MCSymbolRefExpr::VK_ARM_TLSDESCSEQ, getContext());
9810 Lex();
9811
9812 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9813 Error(Parser.getTok().getLoc(), "unexpected token");
9814 Parser.eatToEndOfStatement();
9815 return false;
9816 }
9817
9818 getTargetStreamer().AnnotateTLSDescriptorSequence(SRE);
9819 return false;
9820}
9821
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00009822/// parseDirectiveMovSP
9823/// ::= .movsp reg [, #offset]
9824bool ARMAsmParser::parseDirectiveMovSP(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009825 MCAsmParser &Parser = getParser();
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00009826 if (!UC.hasFnStart()) {
9827 Parser.eatToEndOfStatement();
9828 Error(L, ".fnstart must precede .movsp directives");
9829 return false;
9830 }
9831 if (UC.getFPReg() != ARM::SP) {
9832 Parser.eatToEndOfStatement();
9833 Error(L, "unexpected .movsp directive");
9834 return false;
9835 }
9836
9837 SMLoc SPRegLoc = Parser.getTok().getLoc();
9838 int SPReg = tryParseRegister();
9839 if (SPReg == -1) {
9840 Parser.eatToEndOfStatement();
9841 Error(SPRegLoc, "register expected");
9842 return false;
9843 }
9844
9845 if (SPReg == ARM::SP || SPReg == ARM::PC) {
9846 Parser.eatToEndOfStatement();
9847 Error(SPRegLoc, "sp and pc are not permitted in .movsp directive");
9848 return false;
9849 }
9850
9851 int64_t Offset = 0;
9852 if (Parser.getTok().is(AsmToken::Comma)) {
9853 Parser.Lex();
9854
9855 if (Parser.getTok().isNot(AsmToken::Hash)) {
9856 Error(Parser.getTok().getLoc(), "expected #constant");
9857 Parser.eatToEndOfStatement();
9858 return false;
9859 }
9860 Parser.Lex();
9861
9862 const MCExpr *OffsetExpr;
9863 SMLoc OffsetLoc = Parser.getTok().getLoc();
9864 if (Parser.parseExpression(OffsetExpr)) {
9865 Parser.eatToEndOfStatement();
9866 Error(OffsetLoc, "malformed offset expression");
9867 return false;
9868 }
9869
9870 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
9871 if (!CE) {
9872 Parser.eatToEndOfStatement();
9873 Error(OffsetLoc, "offset must be an immediate constant");
9874 return false;
9875 }
9876
9877 Offset = CE->getValue();
9878 }
9879
9880 getTargetStreamer().emitMovSP(SPReg, Offset);
9881 UC.saveFPReg(SPReg);
9882
9883 return false;
9884}
9885
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +00009886/// parseDirectiveObjectArch
9887/// ::= .object_arch name
9888bool ARMAsmParser::parseDirectiveObjectArch(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009889 MCAsmParser &Parser = getParser();
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +00009890 if (getLexer().isNot(AsmToken::Identifier)) {
9891 Error(getLexer().getLoc(), "unexpected token");
9892 Parser.eatToEndOfStatement();
9893 return false;
9894 }
9895
9896 StringRef Arch = Parser.getTok().getString();
9897 SMLoc ArchLoc = Parser.getTok().getLoc();
9898 getLexer().Lex();
9899
9900 unsigned ID = StringSwitch<unsigned>(Arch)
9901#define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
9902 .Case(NAME, ARM::ID)
9903#define ARM_ARCH_ALIAS(NAME, ID) \
9904 .Case(NAME, ARM::ID)
9905#include "MCTargetDesc/ARMArchName.def"
9906#undef ARM_ARCH_NAME
9907#undef ARM_ARCH_ALIAS
9908 .Default(ARM::INVALID_ARCH);
9909
9910 if (ID == ARM::INVALID_ARCH) {
9911 Error(ArchLoc, "unknown architecture '" + Arch + "'");
9912 Parser.eatToEndOfStatement();
9913 return false;
9914 }
9915
9916 getTargetStreamer().emitObjectArch(ID);
9917
9918 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9919 Error(getLexer().getLoc(), "unexpected token");
9920 Parser.eatToEndOfStatement();
9921 }
9922
9923 return false;
9924}
9925
Saleem Abdulrasoolfd6ed1e2014-02-23 17:45:32 +00009926/// parseDirectiveAlign
9927/// ::= .align
9928bool ARMAsmParser::parseDirectiveAlign(SMLoc L) {
9929 // NOTE: if this is not the end of the statement, fall back to the target
9930 // agnostic handling for this directive which will correctly handle this.
9931 if (getLexer().isNot(AsmToken::EndOfStatement))
9932 return true;
9933
9934 // '.align' is target specifically handled to mean 2**2 byte alignment.
9935 if (getStreamer().getCurrentSection().first->UseCodeAlign())
9936 getStreamer().EmitCodeAlignment(4, 0);
9937 else
9938 getStreamer().EmitValueToAlignment(4, 0, 1, 0);
9939
9940 return false;
9941}
9942
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00009943/// parseDirectiveThumbSet
9944/// ::= .thumb_set name, value
9945bool ARMAsmParser::parseDirectiveThumbSet(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009946 MCAsmParser &Parser = getParser();
9947
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00009948 StringRef Name;
9949 if (Parser.parseIdentifier(Name)) {
9950 TokError("expected identifier after '.thumb_set'");
9951 Parser.eatToEndOfStatement();
9952 return false;
9953 }
9954
9955 if (getLexer().isNot(AsmToken::Comma)) {
9956 TokError("expected comma after name '" + Name + "'");
9957 Parser.eatToEndOfStatement();
9958 return false;
9959 }
9960 Lex();
9961
9962 const MCExpr *Value;
9963 if (Parser.parseExpression(Value)) {
9964 TokError("missing expression");
9965 Parser.eatToEndOfStatement();
9966 return false;
9967 }
9968
9969 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9970 TokError("unexpected token");
9971 Parser.eatToEndOfStatement();
9972 return false;
9973 }
9974 Lex();
9975
9976 MCSymbol *Alias = getContext().GetOrCreateSymbol(Name);
Rafael Espindola466d6632014-04-27 20:23:58 +00009977 getTargetStreamer().emitThumbSet(Alias, Value);
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00009978 return false;
9979}
9980
Kevin Enderby8be42bd2009-10-30 22:55:57 +00009981/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00009982extern "C" void LLVMInitializeARMAsmParser() {
Christian Pirkerdc9ff752014-04-01 15:19:30 +00009983 RegisterMCAsmParser<ARMAsmParser> X(TheARMLETarget);
9984 RegisterMCAsmParser<ARMAsmParser> Y(TheARMBETarget);
9985 RegisterMCAsmParser<ARMAsmParser> A(TheThumbLETarget);
9986 RegisterMCAsmParser<ARMAsmParser> B(TheThumbBETarget);
Kevin Enderbyccab3172009-09-15 00:27:25 +00009987}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00009988
Chris Lattner3e4582a2010-09-06 19:11:01 +00009989#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00009990#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00009991#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00009992#include "ARMGenAsmMatcher.inc"
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009993
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009994static const struct {
9995 const char *Name;
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009996 const unsigned ArchCheck;
Michael Kuperstein29704e72015-03-24 12:56:59 +00009997 const uint64_t Features;
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009998} Extensions[] = {
Michael Kuperstein29704e72015-03-24 12:56:59 +00009999 { "crc", Feature_HasV8, ARM::FeatureCRC },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010000 { "crypto", Feature_HasV8,
Michael Kuperstein29704e72015-03-24 12:56:59 +000010001 ARM::FeatureCrypto | ARM::FeatureNEON | ARM::FeatureFPARMv8 },
10002 { "fp", Feature_HasV8, ARM::FeatureFPARMv8 },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010003 { "idiv", Feature_HasV7 | Feature_IsNotMClass,
Michael Kuperstein29704e72015-03-24 12:56:59 +000010004 ARM::FeatureHWDiv | ARM::FeatureHWDivARM },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010005 // FIXME: iWMMXT not supported
Michael Kuperstein29704e72015-03-24 12:56:59 +000010006 { "iwmmxt", Feature_None, 0 },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010007 // FIXME: iWMMXT2 not supported
Michael Kuperstein29704e72015-03-24 12:56:59 +000010008 { "iwmmxt2", Feature_None, 0 },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010009 // FIXME: Maverick not supported
Michael Kuperstein29704e72015-03-24 12:56:59 +000010010 { "maverick", Feature_None, 0 },
10011 { "mp", Feature_HasV7 | Feature_IsNotMClass, ARM::FeatureMP },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010012 // FIXME: ARMv6-m OS Extensions feature not checked
Michael Kuperstein29704e72015-03-24 12:56:59 +000010013 { "os", Feature_None, 0 },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010014 // FIXME: Also available in ARMv6-K
Michael Kuperstein29704e72015-03-24 12:56:59 +000010015 { "sec", Feature_HasV7, ARM::FeatureTrustZone },
10016 { "simd", Feature_HasV8, ARM::FeatureNEON | ARM::FeatureFPARMv8 },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010017 // FIXME: Only available in A-class, isel not predicated
Michael Kuperstein29704e72015-03-24 12:56:59 +000010018 { "virt", Feature_HasV7, ARM::FeatureVirtualization },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010019 // FIXME: xscale not supported
Michael Kuperstein29704e72015-03-24 12:56:59 +000010020 { "xscale", Feature_None, 0 },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010021};
10022
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010023/// parseDirectiveArchExtension
10024/// ::= .arch_extension [no]feature
10025bool ARMAsmParser::parseDirectiveArchExtension(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +000010026 MCAsmParser &Parser = getParser();
10027
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010028 if (getLexer().isNot(AsmToken::Identifier)) {
10029 Error(getLexer().getLoc(), "unexpected token");
10030 Parser.eatToEndOfStatement();
10031 return false;
10032 }
10033
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +000010034 StringRef Name = Parser.getTok().getString();
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010035 SMLoc ExtLoc = Parser.getTok().getLoc();
10036 getLexer().Lex();
10037
10038 bool EnableFeature = true;
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +000010039 if (Name.startswith_lower("no")) {
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010040 EnableFeature = false;
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +000010041 Name = Name.substr(2);
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010042 }
10043
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +000010044 for (const auto &Extension : Extensions) {
10045 if (Extension.Name != Name)
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010046 continue;
10047
Michael Kuperstein29704e72015-03-24 12:56:59 +000010048 if (!Extension.Features)
Saleem Abdulrasool8988c2a2014-07-27 19:07:09 +000010049 report_fatal_error("unsupported architectural extension: " + Name);
10050
10051 if ((getAvailableFeatures() & Extension.ArchCheck) != Extension.ArchCheck) {
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +000010052 Error(ExtLoc, "architectural extension '" + Name + "' is not "
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010053 "allowed for the current base architecture");
10054 return false;
10055 }
10056
Michael Kuperstein29704e72015-03-24 12:56:59 +000010057 uint64_t ToggleFeatures = EnableFeature
10058 ? (~STI.getFeatureBits() & Extension.Features)
10059 : ( STI.getFeatureBits() & Extension.Features);
Tim Northover26bb14e2014-08-18 11:49:42 +000010060 uint64_t Features =
Saleem Abdulrasool78c44722014-08-17 19:20:38 +000010061 ComputeAvailableFeatures(STI.ToggleFeature(ToggleFeatures));
10062 setAvailableFeatures(Features);
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010063 return false;
10064 }
10065
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +000010066 Error(ExtLoc, "unknown architectural extension: " + Name);
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010067 Parser.eatToEndOfStatement();
10068 return false;
10069}
10070
Jim Grosbach231e7aa2013-02-06 06:00:11 +000010071// Define this matcher function after the auto-generated include so we
10072// have the match class enum definitions.
David Blaikie960ea3f2014-06-08 16:18:35 +000010073unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand &AsmOp,
Jim Grosbach231e7aa2013-02-06 06:00:11 +000010074 unsigned Kind) {
David Blaikie960ea3f2014-06-08 16:18:35 +000010075 ARMOperand &Op = static_cast<ARMOperand &>(AsmOp);
Jim Grosbach231e7aa2013-02-06 06:00:11 +000010076 // If the kind is a token for a literal immediate, check if our asm
10077 // operand matches. This is for InstAliases which have a fixed-value
10078 // immediate in the syntax.
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +000010079 switch (Kind) {
10080 default: break;
10081 case MCK__35_0:
David Blaikie960ea3f2014-06-08 16:18:35 +000010082 if (Op.isImm())
10083 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm()))
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +000010084 if (CE->getValue() == 0)
10085 return Match_Success;
10086 break;
Asiri Rathnayakea0199b92014-12-02 10:53:20 +000010087 case MCK_ModImm:
David Blaikie960ea3f2014-06-08 16:18:35 +000010088 if (Op.isImm()) {
10089 const MCExpr *SOExpr = Op.getImm();
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +000010090 int64_t Value;
10091 if (!SOExpr->EvaluateAsAbsolute(Value))
Stepan Dyatkovskiydf657cc2014-03-29 13:12:40 +000010092 return Match_Success;
Richard Barton3db1d582014-05-01 11:37:44 +000010093 assert((Value >= INT32_MIN && Value <= UINT32_MAX) &&
10094 "expression value must be representable in 32 bits");
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +000010095 }
10096 break;
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +000010097 case MCK_GPRPair:
David Blaikie960ea3f2014-06-08 16:18:35 +000010098 if (Op.isReg() &&
10099 MRI->getRegClass(ARM::GPRRegClassID).contains(Op.getReg()))
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +000010100 return Match_Success;
10101 break;
Jim Grosbach231e7aa2013-02-06 06:00:11 +000010102 }
10103 return Match_InvalidOperand;
10104}