blob: 7c09c7caa1982e18fe53536abcb13ab691a29631 [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
Amara Emerson52cfb6a2013-10-03 09:31:51 +000010#include "ARMFeatures.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000011#include "MCTargetDesc/ARMAddressingModes.h"
12#include "MCTargetDesc/ARMBaseInfo.h"
13#include "MCTargetDesc/ARMMCExpr.h"
Evan Cheng11424442011-07-26 00:24:13 +000014#include "llvm/ADT/STLExtras.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000015#include "llvm/ADT/SmallVector.h"
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +000016#include "llvm/ADT/StringExtras.h"
Daniel Dunbar188b47b2010-08-11 06:37:20 +000017#include "llvm/ADT/StringSwitch.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000018#include "llvm/ADT/Twine.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000019#include "llvm/MC/MCAsmInfo.h"
Jack Carter718da0b2013-01-30 02:24:33 +000020#include "llvm/MC/MCAssembler.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000021#include "llvm/MC/MCContext.h"
Tim Northoverd6a729b2014-01-06 14:28:05 +000022#include "llvm/MC/MCDisassembler.h"
Jack Carter718da0b2013-01-30 02:24:33 +000023#include "llvm/MC/MCELFStreamer.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000024#include "llvm/MC/MCExpr.h"
25#include "llvm/MC/MCInst.h"
26#include "llvm/MC/MCInstrDesc.h"
Joey Gouly0e76fa72013-09-12 10:28:05 +000027#include "llvm/MC/MCInstrInfo.h"
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +000028#include "llvm/MC/MCObjectFileInfo.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000029#include "llvm/MC/MCParser/MCAsmLexer.h"
30#include "llvm/MC/MCParser/MCAsmParser.h"
31#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
32#include "llvm/MC/MCRegisterInfo.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000033#include "llvm/MC/MCSection.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000034#include "llvm/MC/MCStreamer.h"
35#include "llvm/MC/MCSubtargetInfo.h"
David Peixottoe407d092013-12-19 18:12:36 +000036#include "llvm/MC/MCSymbol.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000037#include "llvm/MC/MCTargetAsmParser.h"
Saleem Abdulrasool278a9f42014-01-19 08:25:27 +000038#include "llvm/Support/ARMBuildAttributes.h"
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +000039#include "llvm/Support/ARMEHABI.h"
Renato Golinf5f373f2015-05-08 21:04:27 +000040#include "llvm/Support/TargetParser.h"
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +000041#include "llvm/Support/COFF.h"
Tim Northoverd6a729b2014-01-06 14:28:05 +000042#include "llvm/Support/Debug.h"
Jack Carter718da0b2013-01-30 02:24:33 +000043#include "llvm/Support/ELF.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000044#include "llvm/Support/MathExtras.h"
45#include "llvm/Support/SourceMgr.h"
46#include "llvm/Support/TargetRegistry.h"
47#include "llvm/Support/raw_ostream.h"
Evan Cheng4d1ca962011-07-08 01:53:10 +000048
Kevin Enderbyccab3172009-09-15 00:27:25 +000049using namespace llvm;
50
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +000051namespace {
Bill Wendlingee7f1f92010-11-06 21:42:12 +000052
53class ARMOperand;
Jim Grosbach624bcc72010-10-29 14:46:02 +000054
Jim Grosbach04945c42011-12-02 00:35:16 +000055enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
Jim Grosbachcd6f5e72011-11-30 01:09:44 +000056
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000057class UnwindContext {
58 MCAsmParser &Parser;
59
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +000060 typedef SmallVector<SMLoc, 4> Locs;
61
62 Locs FnStartLocs;
63 Locs CantUnwindLocs;
64 Locs PersonalityLocs;
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +000065 Locs PersonalityIndexLocs;
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +000066 Locs HandlerDataLocs;
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000067 int FPReg;
68
69public:
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +000070 UnwindContext(MCAsmParser &P) : Parser(P), FPReg(ARM::SP) {}
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000071
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +000072 bool hasFnStart() const { return !FnStartLocs.empty(); }
73 bool cantUnwind() const { return !CantUnwindLocs.empty(); }
74 bool hasHandlerData() const { return !HandlerDataLocs.empty(); }
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +000075 bool hasPersonality() const {
76 return !(PersonalityLocs.empty() && PersonalityIndexLocs.empty());
77 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000078
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +000079 void recordFnStart(SMLoc L) { FnStartLocs.push_back(L); }
80 void recordCantUnwind(SMLoc L) { CantUnwindLocs.push_back(L); }
81 void recordPersonality(SMLoc L) { PersonalityLocs.push_back(L); }
82 void recordHandlerData(SMLoc L) { HandlerDataLocs.push_back(L); }
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +000083 void recordPersonalityIndex(SMLoc L) { PersonalityIndexLocs.push_back(L); }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000084
85 void saveFPReg(int Reg) { FPReg = Reg; }
86 int getFPReg() const { return FPReg; }
87
88 void emitFnStartLocNotes() const {
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +000089 for (Locs::const_iterator FI = FnStartLocs.begin(), FE = FnStartLocs.end();
90 FI != FE; ++FI)
91 Parser.Note(*FI, ".fnstart was specified here");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000092 }
93 void emitCantUnwindLocNotes() const {
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +000094 for (Locs::const_iterator UI = CantUnwindLocs.begin(),
95 UE = CantUnwindLocs.end(); UI != UE; ++UI)
96 Parser.Note(*UI, ".cantunwind was specified here");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +000097 }
98 void emitHandlerDataLocNotes() const {
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +000099 for (Locs::const_iterator HI = HandlerDataLocs.begin(),
100 HE = HandlerDataLocs.end(); HI != HE; ++HI)
101 Parser.Note(*HI, ".handlerdata was specified here");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +0000102 }
103 void emitPersonalityLocNotes() const {
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +0000104 for (Locs::const_iterator PI = PersonalityLocs.begin(),
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +0000105 PE = PersonalityLocs.end(),
106 PII = PersonalityIndexLocs.begin(),
107 PIE = PersonalityIndexLocs.end();
108 PI != PE || PII != PIE;) {
109 if (PI != PE && (PII == PIE || PI->getPointer() < PII->getPointer()))
110 Parser.Note(*PI++, ".personality was specified here");
111 else if (PII != PIE && (PI == PE || PII->getPointer() < PI->getPointer()))
112 Parser.Note(*PII++, ".personalityindex was specified here");
113 else
114 llvm_unreachable(".personality and .personalityindex cannot be "
115 "at the same location");
116 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +0000117 }
118
119 void reset() {
Saleem Abdulrasool4cb063c2014-01-07 02:29:00 +0000120 FnStartLocs = Locs();
121 CantUnwindLocs = Locs();
122 PersonalityLocs = Locs();
123 HandlerDataLocs = Locs();
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +0000124 PersonalityIndexLocs = Locs();
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +0000125 FPReg = ARM::SP;
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +0000126 }
127};
128
Evan Cheng11424442011-07-26 00:24:13 +0000129class ARMAsmParser : public MCTargetAsmParser {
Evan Cheng91111d22011-07-09 05:47:46 +0000130 MCSubtargetInfo &STI;
Joey Gouly0e76fa72013-09-12 10:28:05 +0000131 const MCInstrInfo &MII;
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000132 const MCRegisterInfo *MRI;
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +0000133 UnwindContext UC;
David Peixottoe407d092013-12-19 18:12:36 +0000134
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000135 ARMTargetStreamer &getTargetStreamer() {
Saleem Abdulrasoolbfdfb142014-09-18 04:28:29 +0000136 assert(getParser().getStreamer().getTargetStreamer() &&
137 "do not have a target streamer");
Rafael Espindola4a1a3602014-01-14 01:21:46 +0000138 MCTargetStreamer &TS = *getParser().getStreamer().getTargetStreamer();
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000139 return static_cast<ARMTargetStreamer &>(TS);
140 }
141
Jim Grosbachab5830e2011-12-14 02:16:11 +0000142 // Map of register aliases registers via the .req directive.
143 StringMap<unsigned> RegisterReqs;
144
Tim Northover1744d0a2013-10-25 12:49:50 +0000145 bool NextSymbolIsThumb;
146
Jim Grosbached16ec42011-08-29 22:24:09 +0000147 struct {
148 ARMCC::CondCodes Cond; // Condition for IT block.
149 unsigned Mask:4; // Condition mask for instructions.
150 // Starting at first 1 (from lsb).
151 // '1' condition as indicated in IT.
152 // '0' inverse of condition (else).
153 // Count of instructions in IT block is
154 // 4 - trailingzeroes(mask)
155
156 bool FirstCond; // Explicit flag for when we're parsing the
157 // First instruction in the IT block. It's
158 // implied in the mask, so needs special
159 // handling.
160
161 unsigned CurPosition; // Current position in parsing of IT
162 // block. In range [0,3]. Initialized
163 // according to count of instructions in block.
164 // ~0U if no active IT block.
165 } ITState;
Saleem Abdulrasool3a239172014-12-18 05:24:38 +0000166 bool inITBlock() { return ITState.CurPosition != ~0U; }
167 bool lastInITBlock() {
168 return ITState.CurPosition == 4 - countTrailingZeros(ITState.Mask);
169 }
Jim Grosbacha0d34d32011-09-02 23:22:08 +0000170 void forwardITPosition() {
171 if (!inITBlock()) return;
172 // Move to the next instruction in the IT block, if there is one. If not,
173 // mark the block as done.
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +0000174 unsigned TZ = countTrailingZeros(ITState.Mask);
Jim Grosbacha0d34d32011-09-02 23:22:08 +0000175 if (++ITState.CurPosition == 5 - TZ)
176 ITState.CurPosition = ~0U; // Done with the IT block after this.
177 }
Jim Grosbached16ec42011-08-29 22:24:09 +0000178
Saleem Abdulrasool69c7caf2014-01-07 02:28:31 +0000179 void Note(SMLoc L, const Twine &Msg, ArrayRef<SMRange> Ranges = None) {
Rafael Espindola961d4692014-11-11 05:18:41 +0000180 return getParser().Note(L, Msg, Ranges);
Saleem Abdulrasool69c7caf2014-01-07 02:28:31 +0000181 }
Benjamin Kramer673824b2012-04-15 17:04:27 +0000182 bool Warning(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000183 ArrayRef<SMRange> Ranges = None) {
Rafael Espindola961d4692014-11-11 05:18:41 +0000184 return getParser().Warning(L, Msg, Ranges);
Benjamin Kramer673824b2012-04-15 17:04:27 +0000185 }
186 bool Error(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000187 ArrayRef<SMRange> Ranges = None) {
Rafael Espindola961d4692014-11-11 05:18:41 +0000188 return getParser().Error(L, Msg, Ranges);
Benjamin Kramer673824b2012-04-15 17:04:27 +0000189 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000190
Saleem Abdulrasool3a239172014-12-18 05:24:38 +0000191 bool validatetLDMRegList(MCInst Inst, const OperandVector &Operands,
Jyoti Allur5a139142015-01-14 10:48:16 +0000192 unsigned ListNo, bool IsARPop = false);
Saleem Abdulrasool3a239172014-12-18 05:24:38 +0000193 bool validatetSTMRegList(MCInst Inst, const OperandVector &Operands,
194 unsigned ListNo);
195
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000196 int tryParseRegister();
David Blaikie960ea3f2014-06-08 16:18:35 +0000197 bool tryParseRegisterWithWriteBack(OperandVector &);
198 int tryParseShiftRegister(OperandVector &);
199 bool parseRegisterList(OperandVector &);
200 bool parseMemory(OperandVector &);
201 bool parseOperand(OperandVector &, StringRef Mnemonic);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000202 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
Jim Grosbachd3595712011-08-03 23:50:40 +0000203 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
204 unsigned &ShiftAmount);
Saleem Abdulrasool38976512014-02-23 06:22:09 +0000205 bool parseLiteralValues(unsigned Size, SMLoc L);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000206 bool parseDirectiveThumb(SMLoc L);
Jim Grosbach7f882392011-12-07 18:04:19 +0000207 bool parseDirectiveARM(SMLoc L);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000208 bool parseDirectiveThumbFunc(SMLoc L);
209 bool parseDirectiveCode(SMLoc L);
210 bool parseDirectiveSyntax(SMLoc L);
Jim Grosbachab5830e2011-12-14 02:16:11 +0000211 bool parseDirectiveReq(StringRef Name, SMLoc L);
212 bool parseDirectiveUnreq(SMLoc L);
Jason W Kim135d2442011-12-20 17:38:12 +0000213 bool parseDirectiveArch(SMLoc L);
214 bool parseDirectiveEabiAttr(SMLoc L);
Logan Chien8cbb80d2013-10-28 17:51:12 +0000215 bool parseDirectiveCPU(SMLoc L);
216 bool parseDirectiveFPU(SMLoc L);
Logan Chien4ea23b52013-05-10 16:17:24 +0000217 bool parseDirectiveFnStart(SMLoc L);
218 bool parseDirectiveFnEnd(SMLoc L);
219 bool parseDirectiveCantUnwind(SMLoc L);
220 bool parseDirectivePersonality(SMLoc L);
221 bool parseDirectiveHandlerData(SMLoc L);
222 bool parseDirectiveSetFP(SMLoc L);
223 bool parseDirectivePad(SMLoc L);
224 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +0000225 bool parseDirectiveInst(SMLoc L, char Suffix = '\0');
David Peixotto80c083a2013-12-19 18:26:07 +0000226 bool parseDirectiveLtorg(SMLoc L);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +0000227 bool parseDirectiveEven(SMLoc L);
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +0000228 bool parseDirectivePersonalityIndex(SMLoc L);
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +0000229 bool parseDirectiveUnwindRaw(SMLoc L);
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +0000230 bool parseDirectiveTLSDescSeq(SMLoc L);
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +0000231 bool parseDirectiveMovSP(SMLoc L);
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +0000232 bool parseDirectiveObjectArch(SMLoc L);
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +0000233 bool parseDirectiveArchExtension(SMLoc L);
Saleem Abdulrasoolfd6ed1e2014-02-23 17:45:32 +0000234 bool parseDirectiveAlign(SMLoc L);
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +0000235 bool parseDirectiveThumbSet(SMLoc L);
Kevin Enderby146dcf22009-10-15 20:48:48 +0000236
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000237 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000238 bool &CarrySetting, unsigned &ProcessorIMod,
239 StringRef &ITMask);
Amara Emerson33089092013-09-19 11:59:01 +0000240 void getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
241 bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +0000242 bool &CanAcceptPredicationCode);
Jim Grosbach624bcc72010-10-29 14:46:02 +0000243
Evan Cheng4d1ca962011-07-08 01:53:10 +0000244 bool isThumb() const {
245 // FIXME: Can tablegen auto-generate this?
Michael Kupersteinaba4a342015-05-13 08:27:08 +0000246 return STI.getFeatureBits()[ARM::ModeThumb];
Evan Cheng4d1ca962011-07-08 01:53:10 +0000247 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000248 bool isThumbOne() const {
Michael Kupersteinaba4a342015-05-13 08:27:08 +0000249 return isThumb() && !STI.getFeatureBits()[ARM::FeatureThumb2];
Evan Cheng4d1ca962011-07-08 01:53:10 +0000250 }
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000251 bool isThumbTwo() const {
Michael Kupersteinaba4a342015-05-13 08:27:08 +0000252 return isThumb() && STI.getFeatureBits()[ARM::FeatureThumb2];
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000253 }
Tim Northovera2292d02013-06-10 23:20:58 +0000254 bool hasThumb() const {
Michael Kupersteinaba4a342015-05-13 08:27:08 +0000255 return STI.getFeatureBits()[ARM::HasV4TOps];
Tim Northovera2292d02013-06-10 23:20:58 +0000256 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000257 bool hasV6Ops() const {
Michael Kupersteinaba4a342015-05-13 08:27:08 +0000258 return STI.getFeatureBits()[ARM::HasV6Ops];
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000259 }
Tim Northoverf86d1f02013-10-07 11:10:47 +0000260 bool hasV6MOps() const {
Michael Kupersteinaba4a342015-05-13 08:27:08 +0000261 return STI.getFeatureBits()[ARM::HasV6MOps];
Tim Northoverf86d1f02013-10-07 11:10:47 +0000262 }
James Molloy21efa7d2011-09-28 14:21:38 +0000263 bool hasV7Ops() const {
Michael Kupersteinaba4a342015-05-13 08:27:08 +0000264 return STI.getFeatureBits()[ARM::HasV7Ops];
James Molloy21efa7d2011-09-28 14:21:38 +0000265 }
Joey Goulyb3f550e2013-06-26 16:58:26 +0000266 bool hasV8Ops() const {
Michael Kupersteinaba4a342015-05-13 08:27:08 +0000267 return STI.getFeatureBits()[ARM::HasV8Ops];
Joey Goulyb3f550e2013-06-26 16:58:26 +0000268 }
Tim Northovera2292d02013-06-10 23:20:58 +0000269 bool hasARM() const {
Michael Kupersteinaba4a342015-05-13 08:27:08 +0000270 return !STI.getFeatureBits()[ARM::FeatureNoARM];
Tim Northovera2292d02013-06-10 23:20:58 +0000271 }
Renato Golin92c816c2014-09-01 11:25:07 +0000272 bool hasThumb2DSP() const {
Michael Kupersteinaba4a342015-05-13 08:27:08 +0000273 return STI.getFeatureBits()[ARM::FeatureDSPThumb2];
Renato Golin92c816c2014-09-01 11:25:07 +0000274 }
Oliver Stannard9e89d8c2014-11-05 12:06:39 +0000275 bool hasD16() const {
Michael Kupersteinaba4a342015-05-13 08:27:08 +0000276 return STI.getFeatureBits()[ARM::FeatureD16];
Oliver Stannard9e89d8c2014-11-05 12:06:39 +0000277 }
Vladimir Sukharev2afdb322015-04-01 14:54:56 +0000278 bool hasV8_1aOps() const {
Michael Kupersteinaba4a342015-05-13 08:27:08 +0000279 return STI.getFeatureBits()[ARM::HasV8_1aOps];
Vladimir Sukharevc632cda2015-03-26 17:05:54 +0000280 }
Tim Northovera2292d02013-06-10 23:20:58 +0000281
Evan Cheng284b4672011-07-08 22:36:29 +0000282 void SwitchMode() {
Tim Northover26bb14e2014-08-18 11:49:42 +0000283 uint64_t FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
Evan Cheng91111d22011-07-09 05:47:46 +0000284 setAvailableFeatures(FB);
Evan Cheng284b4672011-07-08 22:36:29 +0000285 }
James Molloy21efa7d2011-09-28 14:21:38 +0000286 bool isMClass() const {
Michael Kupersteinaba4a342015-05-13 08:27:08 +0000287 return STI.getFeatureBits()[ARM::FeatureMClass];
James Molloy21efa7d2011-09-28 14:21:38 +0000288 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000289
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000290 /// @name Auto-generated Match Functions
291 /// {
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +0000292
Chris Lattner3e4582a2010-09-06 19:11:01 +0000293#define GET_ASSEMBLER_HEADER
294#include "ARMGenAsmMatcher.inc"
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000295
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000296 /// }
297
David Blaikie960ea3f2014-06-08 16:18:35 +0000298 OperandMatchResultTy parseITCondCode(OperandVector &);
299 OperandMatchResultTy parseCoprocNumOperand(OperandVector &);
300 OperandMatchResultTy parseCoprocRegOperand(OperandVector &);
301 OperandMatchResultTy parseCoprocOptionOperand(OperandVector &);
302 OperandMatchResultTy parseMemBarrierOptOperand(OperandVector &);
303 OperandMatchResultTy parseInstSyncBarrierOptOperand(OperandVector &);
304 OperandMatchResultTy parseProcIFlagsOperand(OperandVector &);
305 OperandMatchResultTy parseMSRMaskOperand(OperandVector &);
Tim Northoveree843ef2014-08-15 10:47:12 +0000306 OperandMatchResultTy parseBankedRegOperand(OperandVector &);
David Blaikie960ea3f2014-06-08 16:18:35 +0000307 OperandMatchResultTy parsePKHImm(OperandVector &O, StringRef Op, int Low,
308 int High);
309 OperandMatchResultTy parsePKHLSLImm(OperandVector &O) {
Jim Grosbach27c1e252011-07-21 17:23:04 +0000310 return parsePKHImm(O, "lsl", 0, 31);
311 }
David Blaikie960ea3f2014-06-08 16:18:35 +0000312 OperandMatchResultTy parsePKHASRImm(OperandVector &O) {
Jim Grosbach27c1e252011-07-21 17:23:04 +0000313 return parsePKHImm(O, "asr", 1, 32);
314 }
David Blaikie960ea3f2014-06-08 16:18:35 +0000315 OperandMatchResultTy parseSetEndImm(OperandVector &);
316 OperandMatchResultTy parseShifterImm(OperandVector &);
317 OperandMatchResultTy parseRotImm(OperandVector &);
Asiri Rathnayakea0199b92014-12-02 10:53:20 +0000318 OperandMatchResultTy parseModImm(OperandVector &);
David Blaikie960ea3f2014-06-08 16:18:35 +0000319 OperandMatchResultTy parseBitfield(OperandVector &);
320 OperandMatchResultTy parsePostIdxReg(OperandVector &);
321 OperandMatchResultTy parseAM3Offset(OperandVector &);
322 OperandMatchResultTy parseFPImm(OperandVector &);
323 OperandMatchResultTy parseVectorList(OperandVector &);
Jordan Rosee8f1eae2013-01-07 19:00:49 +0000324 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
325 SMLoc &EndLoc);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000326
327 // Asm Match Converter Methods
David Blaikie960ea3f2014-06-08 16:18:35 +0000328 void cvtThumbMultiply(MCInst &Inst, const OperandVector &);
329 void cvtThumbBranches(MCInst &Inst, const OperandVector &);
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +0000330
David Blaikie960ea3f2014-06-08 16:18:35 +0000331 bool validateInstruction(MCInst &Inst, const OperandVector &Ops);
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +0000332 bool processInstruction(MCInst &Inst, const OperandVector &Ops, MCStreamer &Out);
David Blaikie960ea3f2014-06-08 16:18:35 +0000333 bool shouldOmitCCOutOperand(StringRef Mnemonic, OperandVector &Operands);
334 bool shouldOmitPredicateOperand(StringRef Mnemonic, OperandVector &Operands);
335
Kevin Enderbyccab3172009-09-15 00:27:25 +0000336public:
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000337 enum ARMMatchResultTy {
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000338 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbached16ec42011-08-29 22:24:09 +0000339 Match_RequiresNotITBlock,
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000340 Match_RequiresV6,
Jim Grosbach087affe2012-06-22 23:56:48 +0000341 Match_RequiresThumb2,
342#define GET_OPERAND_DIAGNOSTIC_TYPES
343#include "ARMGenAsmMatcher.inc"
344
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000345 };
346
David Blaikie9f380a32015-03-16 18:06:57 +0000347 ARMAsmParser(MCSubtargetInfo &STI, MCAsmParser &Parser,
Rafael Espindola961d4692014-11-11 05:18:41 +0000348 const MCInstrInfo &MII, const MCTargetOptions &Options)
David Blaikie9f380a32015-03-16 18:06:57 +0000349 : STI(STI), MII(MII), UC(Parser) {
350 MCAsmParserExtension::Initialize(Parser);
Evan Cheng284b4672011-07-08 22:36:29 +0000351
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000352 // Cache the MCRegisterInfo.
Bill Wendlingbc07a892013-06-18 07:20:20 +0000353 MRI = getContext().getRegisterInfo();
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000354
Evan Cheng4d1ca962011-07-08 01:53:10 +0000355 // Initialize the set of available features.
Evan Cheng91111d22011-07-09 05:47:46 +0000356 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbached16ec42011-08-29 22:24:09 +0000357
358 // Not in an ITBlock to start with.
359 ITState.CurPosition = ~0U;
Tim Northover1744d0a2013-10-25 12:49:50 +0000360
361 NextSymbolIsThumb = false;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000362 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000363
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000364 // Implementation of the MCTargetAsmParser interface:
Craig Topperca7e3e52014-03-10 03:19:03 +0000365 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc) override;
David Blaikie960ea3f2014-06-08 16:18:35 +0000366 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
367 SMLoc NameLoc, OperandVector &Operands) override;
Craig Topperca7e3e52014-03-10 03:19:03 +0000368 bool ParseDirective(AsmToken DirectiveID) override;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000369
David Blaikie960ea3f2014-06-08 16:18:35 +0000370 unsigned validateTargetOperandClass(MCParsedAsmOperand &Op,
Craig Topperca7e3e52014-03-10 03:19:03 +0000371 unsigned Kind) override;
372 unsigned checkTargetMatchPredicate(MCInst &Inst) override;
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000373
Chad Rosier49963552012-10-13 00:26:04 +0000374 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
David Blaikie960ea3f2014-06-08 16:18:35 +0000375 OperandVector &Operands, MCStreamer &Out,
Tim Northover26bb14e2014-08-18 11:49:42 +0000376 uint64_t &ErrorInfo,
Craig Topperca7e3e52014-03-10 03:19:03 +0000377 bool MatchingInlineAsm) override;
378 void onLabelParsed(MCSymbol *Symbol) override;
Kevin Enderbyccab3172009-09-15 00:27:25 +0000379};
Jim Grosbach624bcc72010-10-29 14:46:02 +0000380} // end anonymous namespace
381
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +0000382namespace {
383
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000384/// ARMOperand - Instances of this class represent a parsed ARM machine
Joel Jones54597542013-01-09 22:34:16 +0000385/// operand.
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000386class ARMOperand : public MCParsedAsmOperand {
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000387 enum KindTy {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000388 k_CondCode,
389 k_CCOut,
390 k_ITCondMask,
391 k_CoprocNum,
392 k_CoprocReg,
Jim Grosbach48399582011-10-12 17:34:41 +0000393 k_CoprocOption,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000394 k_Immediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000395 k_MemBarrierOpt,
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000396 k_InstSyncBarrierOpt,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000397 k_Memory,
398 k_PostIndexRegister,
399 k_MSRMask,
Tim Northoveree843ef2014-08-15 10:47:12 +0000400 k_BankedReg,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000401 k_ProcIFlags,
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000402 k_VectorIndex,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000403 k_Register,
404 k_RegisterList,
405 k_DPRRegisterList,
406 k_SPRRegisterList,
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000407 k_VectorList,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000408 k_VectorListAllLanes,
Jim Grosbach04945c42011-12-02 00:35:16 +0000409 k_VectorListIndexed,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000410 k_ShiftedRegister,
411 k_ShiftedImmediate,
412 k_ShifterImmediate,
413 k_RotateImmediate,
Asiri Rathnayakea0199b92014-12-02 10:53:20 +0000414 k_ModifiedImmediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000415 k_BitfieldDescriptor,
416 k_Token
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000417 } Kind;
418
Kevin Enderby488f20b2014-04-10 20:18:58 +0000419 SMLoc StartLoc, EndLoc, AlignmentLoc;
Bill Wendling0ab0f672010-11-18 21:50:54 +0000420 SmallVector<unsigned, 8> Registers;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000421
Eric Christopher8996c5d2013-03-15 00:42:55 +0000422 struct CCOp {
423 ARMCC::CondCodes Val;
424 };
425
426 struct CopOp {
427 unsigned Val;
428 };
429
430 struct CoprocOptionOp {
431 unsigned Val;
432 };
433
434 struct ITMaskOp {
435 unsigned Mask:4;
436 };
437
438 struct MBOptOp {
439 ARM_MB::MemBOpt Val;
440 };
441
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000442 struct ISBOptOp {
443 ARM_ISB::InstSyncBOpt Val;
444 };
445
Eric Christopher8996c5d2013-03-15 00:42:55 +0000446 struct IFlagsOp {
447 ARM_PROC::IFlags Val;
448 };
449
450 struct MMaskOp {
451 unsigned Val;
452 };
453
Tim Northoveree843ef2014-08-15 10:47:12 +0000454 struct BankedRegOp {
455 unsigned Val;
456 };
457
Eric Christopher8996c5d2013-03-15 00:42:55 +0000458 struct TokOp {
459 const char *Data;
460 unsigned Length;
461 };
462
463 struct RegOp {
464 unsigned RegNum;
465 };
466
467 // A vector register list is a sequential list of 1 to 4 registers.
468 struct VectorListOp {
469 unsigned RegNum;
470 unsigned Count;
471 unsigned LaneIndex;
472 bool isDoubleSpaced;
473 };
474
475 struct VectorIndexOp {
476 unsigned Val;
477 };
478
479 struct ImmOp {
480 const MCExpr *Val;
481 };
482
483 /// Combined record for all forms of ARM address expressions.
484 struct MemoryOp {
485 unsigned BaseRegNum;
486 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
487 // was specified.
488 const MCConstantExpr *OffsetImm; // Offset immediate value
489 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
490 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
491 unsigned ShiftImm; // shift for OffsetReg.
492 unsigned Alignment; // 0 = no alignment specified
493 // n = alignment in bytes (2, 4, 8, 16, or 32)
494 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
495 };
496
497 struct PostIdxRegOp {
498 unsigned RegNum;
499 bool isAdd;
500 ARM_AM::ShiftOpc ShiftTy;
501 unsigned ShiftImm;
502 };
503
504 struct ShifterImmOp {
505 bool isASR;
506 unsigned Imm;
507 };
508
509 struct RegShiftedRegOp {
510 ARM_AM::ShiftOpc ShiftTy;
511 unsigned SrcReg;
512 unsigned ShiftReg;
513 unsigned ShiftImm;
514 };
515
516 struct RegShiftedImmOp {
517 ARM_AM::ShiftOpc ShiftTy;
518 unsigned SrcReg;
519 unsigned ShiftImm;
520 };
521
522 struct RotImmOp {
523 unsigned Imm;
524 };
525
Asiri Rathnayakea0199b92014-12-02 10:53:20 +0000526 struct ModImmOp {
527 unsigned Bits;
528 unsigned Rot;
529 };
530
Eric Christopher8996c5d2013-03-15 00:42:55 +0000531 struct BitfieldOp {
532 unsigned LSB;
533 unsigned Width;
534 };
535
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000536 union {
Eric Christopher8996c5d2013-03-15 00:42:55 +0000537 struct CCOp CC;
538 struct CopOp Cop;
539 struct CoprocOptionOp CoprocOption;
540 struct MBOptOp MBOpt;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000541 struct ISBOptOp ISBOpt;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000542 struct ITMaskOp ITMask;
543 struct IFlagsOp IFlags;
544 struct MMaskOp MMask;
Tim Northoveree843ef2014-08-15 10:47:12 +0000545 struct BankedRegOp BankedReg;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000546 struct TokOp Tok;
547 struct RegOp Reg;
548 struct VectorListOp VectorList;
549 struct VectorIndexOp VectorIndex;
550 struct ImmOp Imm;
551 struct MemoryOp Memory;
552 struct PostIdxRegOp PostIdxReg;
553 struct ShifterImmOp ShifterImm;
554 struct RegShiftedRegOp RegShiftedReg;
555 struct RegShiftedImmOp RegShiftedImm;
556 struct RotImmOp RotImm;
Asiri Rathnayakea0199b92014-12-02 10:53:20 +0000557 struct ModImmOp ModImm;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000558 struct BitfieldOp Bitfield;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000559 };
Jim Grosbach624bcc72010-10-29 14:46:02 +0000560
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000561public:
David Blaikie960ea3f2014-06-08 16:18:35 +0000562 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000563 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
564 Kind = o.Kind;
565 StartLoc = o.StartLoc;
566 EndLoc = o.EndLoc;
567 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000568 case k_CondCode:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000569 CC = o.CC;
570 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000571 case k_ITCondMask:
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000572 ITMask = o.ITMask;
573 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000574 case k_Token:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000575 Tok = o.Tok;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000576 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000577 case k_CCOut:
578 case k_Register:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000579 Reg = o.Reg;
580 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000581 case k_RegisterList:
582 case k_DPRRegisterList:
583 case k_SPRRegisterList:
Bill Wendling0ab0f672010-11-18 21:50:54 +0000584 Registers = o.Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000585 break;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000586 case k_VectorList:
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000587 case k_VectorListAllLanes:
Jim Grosbach04945c42011-12-02 00:35:16 +0000588 case k_VectorListIndexed:
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000589 VectorList = o.VectorList;
590 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000591 case k_CoprocNum:
592 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000593 Cop = o.Cop;
594 break;
Jim Grosbach48399582011-10-12 17:34:41 +0000595 case k_CoprocOption:
596 CoprocOption = o.CoprocOption;
597 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000598 case k_Immediate:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000599 Imm = o.Imm;
600 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000601 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000602 MBOpt = o.MBOpt;
603 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000604 case k_InstSyncBarrierOpt:
605 ISBOpt = o.ISBOpt;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000606 case k_Memory:
Jim Grosbach871dff72011-10-11 15:59:20 +0000607 Memory = o.Memory;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000608 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000609 case k_PostIndexRegister:
Jim Grosbachd3595712011-08-03 23:50:40 +0000610 PostIdxReg = o.PostIdxReg;
611 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000612 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000613 MMask = o.MMask;
614 break;
Tim Northoveree843ef2014-08-15 10:47:12 +0000615 case k_BankedReg:
616 BankedReg = o.BankedReg;
617 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000618 case k_ProcIFlags:
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000619 IFlags = o.IFlags;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000620 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000621 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000622 ShifterImm = o.ShifterImm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000623 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000624 case k_ShiftedRegister:
Jim Grosbachac798e12011-07-25 20:49:51 +0000625 RegShiftedReg = o.RegShiftedReg;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000626 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000627 case k_ShiftedImmediate:
Jim Grosbachac798e12011-07-25 20:49:51 +0000628 RegShiftedImm = o.RegShiftedImm;
Owen Andersonb595ed02011-07-21 18:54:16 +0000629 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000630 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +0000631 RotImm = o.RotImm;
632 break;
Asiri Rathnayakea0199b92014-12-02 10:53:20 +0000633 case k_ModifiedImmediate:
634 ModImm = o.ModImm;
635 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000636 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +0000637 Bitfield = o.Bitfield;
638 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000639 case k_VectorIndex:
640 VectorIndex = o.VectorIndex;
641 break;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000642 }
643 }
Jim Grosbach624bcc72010-10-29 14:46:02 +0000644
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000645 /// getStartLoc - Get the location of the first token of this operand.
Craig Topperca7e3e52014-03-10 03:19:03 +0000646 SMLoc getStartLoc() const override { return StartLoc; }
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000647 /// getEndLoc - Get the location of the last token of this operand.
Craig Topperca7e3e52014-03-10 03:19:03 +0000648 SMLoc getEndLoc() const override { return EndLoc; }
Chad Rosier143d0f72012-09-21 20:51:43 +0000649 /// getLocRange - Get the range between the first and last token of this
650 /// operand.
Benjamin Kramer673824b2012-04-15 17:04:27 +0000651 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
652
Kevin Enderby488f20b2014-04-10 20:18:58 +0000653 /// getAlignmentLoc - Get the location of the Alignment token of this operand.
654 SMLoc getAlignmentLoc() const {
655 assert(Kind == k_Memory && "Invalid access!");
656 return AlignmentLoc;
657 }
658
Daniel Dunbard8042b72010-08-11 06:36:53 +0000659 ARMCC::CondCodes getCondCode() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000660 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbard8042b72010-08-11 06:36:53 +0000661 return CC.Val;
662 }
663
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000664 unsigned getCoproc() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000665 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000666 return Cop.Val;
667 }
668
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000669 StringRef getToken() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000670 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000671 return StringRef(Tok.Data, Tok.Length);
672 }
673
Craig Topperca7e3e52014-03-10 03:19:03 +0000674 unsigned getReg() const override {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000675 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling2cae3272010-11-09 22:44:22 +0000676 return Reg.RegNum;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000677 }
678
Bill Wendlingbed94652010-11-09 23:28:44 +0000679 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000680 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
681 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling0ab0f672010-11-18 21:50:54 +0000682 return Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000683 }
684
Kevin Enderbyf5079942009-10-13 22:19:02 +0000685 const MCExpr *getImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000686 assert(isImm() && "Invalid access!");
Kevin Enderbyf5079942009-10-13 22:19:02 +0000687 return Imm.Val;
688 }
689
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000690 unsigned getVectorIndex() const {
691 assert(Kind == k_VectorIndex && "Invalid access!");
692 return VectorIndex.Val;
693 }
694
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000695 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000696 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000697 return MBOpt.Val;
698 }
699
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000700 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
701 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
702 return ISBOpt.Val;
703 }
704
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000705 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000706 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000707 return IFlags.Val;
708 }
709
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000710 unsigned getMSRMask() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000711 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000712 return MMask.Val;
713 }
714
Tim Northoveree843ef2014-08-15 10:47:12 +0000715 unsigned getBankedReg() const {
716 assert(Kind == k_BankedReg && "Invalid access!");
717 return BankedReg.Val;
718 }
719
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000720 bool isCoprocNum() const { return Kind == k_CoprocNum; }
721 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach48399582011-10-12 17:34:41 +0000722 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000723 bool isCondCode() const { return Kind == k_CondCode; }
724 bool isCCOut() const { return Kind == k_CCOut; }
725 bool isITMask() const { return Kind == k_ITCondMask; }
726 bool isITCondCode() const { return Kind == k_CondCode; }
Craig Topperca7e3e52014-03-10 03:19:03 +0000727 bool isImm() const override { return Kind == k_Immediate; }
Mihai Popad36cbaa2013-07-03 09:21:44 +0000728 // checks whether this operand is an unsigned offset which fits is a field
729 // of specified width and scaled by a specific number of bits
730 template<unsigned width, unsigned scale>
731 bool isUnsignedOffset() const {
732 if (!isImm()) return false;
Mihai Popaad18d3c2013-08-09 10:38:32 +0000733 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
Mihai Popad36cbaa2013-07-03 09:21:44 +0000734 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
735 int64_t Val = CE->getValue();
736 int64_t Align = 1LL << scale;
737 int64_t Max = Align * ((1LL << width) - 1);
738 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
739 }
740 return false;
741 }
Mihai Popaad18d3c2013-08-09 10:38:32 +0000742 // checks whether this operand is an signed offset which fits is a field
743 // of specified width and scaled by a specific number of bits
744 template<unsigned width, unsigned scale>
745 bool isSignedOffset() const {
746 if (!isImm()) return false;
747 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
748 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
749 int64_t Val = CE->getValue();
750 int64_t Align = 1LL << scale;
751 int64_t Max = Align * ((1LL << (width-1)) - 1);
752 int64_t Min = -Align * (1LL << (width-1));
753 return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max);
754 }
755 return false;
756 }
757
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000758 // checks whether this operand is a memory operand computed as an offset
759 // applied to PC. the offset may have 8 bits of magnitude and is represented
760 // with two bits of shift. textually it may be either [pc, #imm], #imm or
761 // relocable expression...
762 bool isThumbMemPC() const {
763 int64_t Val = 0;
764 if (isImm()) {
765 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
766 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val);
767 if (!CE) return false;
768 Val = CE->getValue();
769 }
770 else if (isMem()) {
771 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false;
772 if(Memory.BaseRegNum != ARM::PC) return false;
773 Val = Memory.OffsetImm->getValue();
774 }
775 else return false;
Mihai Popad79f00b2013-08-15 15:43:06 +0000776 return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020);
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000777 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +0000778 bool isFPImm() const {
779 if (!isImm()) return false;
780 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
781 if (!CE) return false;
782 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
783 return Val != -1;
784 }
Jim Grosbachea231912011-12-22 22:19:05 +0000785 bool isFBits16() const {
786 if (!isImm()) return false;
787 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
788 if (!CE) return false;
789 int64_t Value = CE->getValue();
790 return Value >= 0 && Value <= 16;
791 }
792 bool isFBits32() const {
793 if (!isImm()) return false;
794 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
795 if (!CE) return false;
796 int64_t Value = CE->getValue();
797 return Value >= 1 && Value <= 32;
798 }
Jim Grosbach7db8d692011-09-08 22:07:06 +0000799 bool isImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000800 if (!isImm()) return false;
Jim Grosbach7db8d692011-09-08 22:07:06 +0000801 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
802 if (!CE) return false;
803 int64_t Value = CE->getValue();
804 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
805 }
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000806 bool isImm0_1020s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000807 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000808 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
809 if (!CE) return false;
810 int64_t Value = CE->getValue();
811 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
812 }
813 bool isImm0_508s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000814 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000815 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
816 if (!CE) return false;
817 int64_t Value = CE->getValue();
818 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
819 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000820 bool isImm0_508s4Neg() const {
821 if (!isImm()) return false;
822 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
823 if (!CE) return false;
824 int64_t Value = -CE->getValue();
825 // explicitly exclude zero. we want that to use the normal 0_508 version.
826 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
827 }
Artyom Skrobovfc12e702013-10-23 10:14:40 +0000828 bool isImm0_239() const {
829 if (!isImm()) return false;
830 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
831 if (!CE) return false;
832 int64_t Value = CE->getValue();
833 return Value >= 0 && Value < 240;
834 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000835 bool isImm0_255() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000836 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000837 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
838 if (!CE) return false;
839 int64_t Value = CE->getValue();
840 return Value >= 0 && Value < 256;
841 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000842 bool isImm0_4095() const {
843 if (!isImm()) return false;
844 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
845 if (!CE) return false;
846 int64_t Value = CE->getValue();
847 return Value >= 0 && Value < 4096;
848 }
849 bool isImm0_4095Neg() const {
850 if (!isImm()) return false;
851 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
852 if (!CE) return false;
853 int64_t Value = -CE->getValue();
854 return Value > 0 && Value < 4096;
855 }
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000856 bool isImm0_1() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000857 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000858 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
859 if (!CE) return false;
860 int64_t Value = CE->getValue();
861 return Value >= 0 && Value < 2;
862 }
863 bool isImm0_3() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000864 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000865 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
866 if (!CE) return false;
867 int64_t Value = CE->getValue();
868 return Value >= 0 && Value < 4;
869 }
Jim Grosbach31756c22011-07-13 22:01:08 +0000870 bool isImm0_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000871 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000872 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
873 if (!CE) return false;
874 int64_t Value = CE->getValue();
875 return Value >= 0 && Value < 8;
876 }
877 bool isImm0_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000878 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000879 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
880 if (!CE) return false;
881 int64_t Value = CE->getValue();
882 return Value >= 0 && Value < 16;
883 }
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000884 bool isImm0_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000885 if (!isImm()) return false;
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000886 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
887 if (!CE) return false;
888 int64_t Value = CE->getValue();
889 return Value >= 0 && Value < 32;
890 }
Jim Grosbach00326402011-12-08 01:30:04 +0000891 bool isImm0_63() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000892 if (!isImm()) return false;
Jim Grosbach00326402011-12-08 01:30:04 +0000893 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
894 if (!CE) return false;
895 int64_t Value = CE->getValue();
896 return Value >= 0 && Value < 64;
897 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000898 bool isImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000899 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000900 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
901 if (!CE) return false;
902 int64_t Value = CE->getValue();
903 return Value == 8;
904 }
905 bool isImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000906 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000907 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
908 if (!CE) return false;
909 int64_t Value = CE->getValue();
910 return Value == 16;
911 }
912 bool isImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000913 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000914 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
915 if (!CE) return false;
916 int64_t Value = CE->getValue();
917 return Value == 32;
918 }
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000919 bool isShrImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000920 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000921 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
922 if (!CE) return false;
923 int64_t Value = CE->getValue();
924 return Value > 0 && Value <= 8;
925 }
926 bool isShrImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000927 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000928 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
929 if (!CE) return false;
930 int64_t Value = CE->getValue();
931 return Value > 0 && Value <= 16;
932 }
933 bool isShrImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000934 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000935 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
936 if (!CE) return false;
937 int64_t Value = CE->getValue();
938 return Value > 0 && Value <= 32;
939 }
940 bool isShrImm64() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000941 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000942 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
943 if (!CE) return false;
944 int64_t Value = CE->getValue();
945 return Value > 0 && Value <= 64;
946 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000947 bool isImm1_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000948 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000949 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
950 if (!CE) return false;
951 int64_t Value = CE->getValue();
952 return Value > 0 && Value < 8;
953 }
954 bool isImm1_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000955 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000956 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
957 if (!CE) return false;
958 int64_t Value = CE->getValue();
959 return Value > 0 && Value < 16;
960 }
961 bool isImm1_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000962 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000963 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
964 if (!CE) return false;
965 int64_t Value = CE->getValue();
966 return Value > 0 && Value < 32;
967 }
Jim Grosbach475c6db2011-07-25 23:09:14 +0000968 bool isImm1_16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000969 if (!isImm()) return false;
Jim Grosbach475c6db2011-07-25 23:09:14 +0000970 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
971 if (!CE) return false;
972 int64_t Value = CE->getValue();
973 return Value > 0 && Value < 17;
974 }
Jim Grosbach801e0a32011-07-22 23:16:18 +0000975 bool isImm1_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000976 if (!isImm()) return false;
Jim Grosbach801e0a32011-07-22 23:16:18 +0000977 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
978 if (!CE) return false;
979 int64_t Value = CE->getValue();
980 return Value > 0 && Value < 33;
981 }
Jim Grosbachc14871c2011-11-10 19:18:01 +0000982 bool isImm0_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000983 if (!isImm()) return false;
Jim Grosbachc14871c2011-11-10 19:18:01 +0000984 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
985 if (!CE) return false;
986 int64_t Value = CE->getValue();
987 return Value >= 0 && Value < 33;
988 }
Jim Grosbach975b6412011-07-13 20:10:10 +0000989 bool isImm0_65535() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000990 if (!isImm()) return false;
Jim Grosbach975b6412011-07-13 20:10:10 +0000991 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
992 if (!CE) return false;
993 int64_t Value = CE->getValue();
994 return Value >= 0 && Value < 65536;
995 }
Mihai Popaae1112b2013-08-21 13:14:58 +0000996 bool isImm256_65535Expr() const {
997 if (!isImm()) return false;
998 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
999 // If it's not a constant expression, it'll generate a fixup and be
1000 // handled later.
1001 if (!CE) return true;
1002 int64_t Value = CE->getValue();
1003 return Value >= 256 && Value < 65536;
1004 }
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00001005 bool isImm0_65535Expr() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001006 if (!isImm()) return false;
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00001007 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1008 // If it's not a constant expression, it'll generate a fixup and be
1009 // handled later.
1010 if (!CE) return true;
1011 int64_t Value = CE->getValue();
1012 return Value >= 0 && Value < 65536;
1013 }
Jim Grosbachf1637842011-07-26 16:24:27 +00001014 bool isImm24bit() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001015 if (!isImm()) return false;
Jim Grosbachf1637842011-07-26 16:24:27 +00001016 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1017 if (!CE) return false;
1018 int64_t Value = CE->getValue();
1019 return Value >= 0 && Value <= 0xffffff;
1020 }
Jim Grosbach46dd4132011-08-17 21:51:27 +00001021 bool isImmThumbSR() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001022 if (!isImm()) return false;
Jim Grosbach46dd4132011-08-17 21:51:27 +00001023 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1024 if (!CE) return false;
1025 int64_t Value = CE->getValue();
1026 return Value > 0 && Value < 33;
1027 }
Jim Grosbach27c1e252011-07-21 17:23:04 +00001028 bool isPKHLSLImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001029 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +00001030 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1031 if (!CE) return false;
1032 int64_t Value = CE->getValue();
1033 return Value >= 0 && Value < 32;
1034 }
1035 bool isPKHASRImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001036 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +00001037 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1038 if (!CE) return false;
1039 int64_t Value = CE->getValue();
1040 return Value > 0 && Value <= 32;
1041 }
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001042 bool isAdrLabel() const {
1043 // If we have an immediate that's not a constant, treat it as a label
Asiri Rathnayake52376ac2015-01-06 15:55:09 +00001044 // reference needing a fixup.
1045 if (isImm() && !isa<MCConstantExpr>(getImm()))
1046 return true;
1047
1048 // If it is a constant, it must fit into a modified immediate encoding.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001049 if (!isImm()) return false;
Jim Grosbach9720dcf2011-07-19 16:50:30 +00001050 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1051 if (!CE) return false;
1052 int64_t Value = CE->getValue();
Asiri Rathnayake52376ac2015-01-06 15:55:09 +00001053 return (ARM_AM::getSOImmVal(Value) != -1 ||
Asiri Rathnayake77436f82015-01-07 11:22:58 +00001054 ARM_AM::getSOImmVal(-Value) != -1);;
Jim Grosbach30506252011-12-08 00:31:07 +00001055 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +00001056 bool isT2SOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001057 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +00001058 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1059 if (!CE) return false;
1060 int64_t Value = CE->getValue();
1061 return ARM_AM::getT2SOImmVal(Value) != -1;
1062 }
Jim Grosbachb009a872011-10-28 22:36:30 +00001063 bool isT2SOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001064 if (!isImm()) return false;
Jim Grosbachb009a872011-10-28 22:36:30 +00001065 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1066 if (!CE) return false;
1067 int64_t Value = CE->getValue();
Mihai Popacf276b22013-08-16 11:55:44 +00001068 return ARM_AM::getT2SOImmVal(Value) == -1 &&
1069 ARM_AM::getT2SOImmVal(~Value) != -1;
Jim Grosbachb009a872011-10-28 22:36:30 +00001070 }
Jim Grosbach30506252011-12-08 00:31:07 +00001071 bool isT2SOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001072 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +00001073 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1074 if (!CE) return false;
1075 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +00001076 // Only use this when not representable as a plain so_imm.
1077 return ARM_AM::getT2SOImmVal(Value) == -1 &&
1078 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +00001079 }
Jim Grosbach0a547702011-07-22 17:44:50 +00001080 bool isSetEndImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001081 if (!isImm()) return false;
Jim Grosbach0a547702011-07-22 17:44:50 +00001082 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1083 if (!CE) return false;
1084 int64_t Value = CE->getValue();
1085 return Value == 1 || Value == 0;
1086 }
Craig Topperca7e3e52014-03-10 03:19:03 +00001087 bool isReg() const override { return Kind == k_Register; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001088 bool isRegList() const { return Kind == k_RegisterList; }
1089 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
1090 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
Craig Topperca7e3e52014-03-10 03:19:03 +00001091 bool isToken() const override { return Kind == k_Token; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001092 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00001093 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
Craig Topperca7e3e52014-03-10 03:19:03 +00001094 bool isMem() const override { return Kind == k_Memory; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001095 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
1096 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
1097 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
1098 bool isRotImm() const { return Kind == k_RotateImmediate; }
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00001099 bool isModImm() const { return Kind == k_ModifiedImmediate; }
1100 bool isModImmNot() const {
1101 if (!isImm()) return false;
1102 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1103 if (!CE) return false;
1104 int64_t Value = CE->getValue();
1105 return ARM_AM::getSOImmVal(~Value) != -1;
1106 }
1107 bool isModImmNeg() const {
1108 if (!isImm()) return false;
1109 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1110 if (!CE) return false;
1111 int64_t Value = CE->getValue();
1112 return ARM_AM::getSOImmVal(Value) == -1 &&
1113 ARM_AM::getSOImmVal(-Value) != -1;
1114 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001115 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
1116 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachc320c852011-08-05 21:28:30 +00001117 bool isPostIdxReg() const {
Jim Grosbachee201fa2011-11-14 17:52:47 +00001118 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachc320c852011-08-05 21:28:30 +00001119 }
Kevin Enderby488f20b2014-04-10 20:18:58 +00001120 bool isMemNoOffset(bool alignOK = false, unsigned Alignment = 0) const {
Chad Rosier41099832012-09-11 23:02:35 +00001121 if (!isMem())
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001122 return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001123 // No offset of any kind.
Craig Topper062a2ba2014-04-25 05:30:21 +00001124 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == nullptr &&
Kevin Enderby488f20b2014-04-10 20:18:58 +00001125 (alignOK || Memory.Alignment == Alignment);
Jim Grosbacha95ec992011-10-11 17:29:55 +00001126 }
Jim Grosbach94298a92012-01-18 22:46:46 +00001127 bool isMemPCRelImm12() const {
Chad Rosier41099832012-09-11 23:02:35 +00001128 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach94298a92012-01-18 22:46:46 +00001129 return false;
1130 // Base register must be PC.
1131 if (Memory.BaseRegNum != ARM::PC)
1132 return false;
1133 // Immediate offset in range [-4095, 4095].
1134 if (!Memory.OffsetImm) return true;
1135 int64_t Val = Memory.OffsetImm->getValue();
1136 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1137 }
Jim Grosbacha95ec992011-10-11 17:29:55 +00001138 bool isAlignedMemory() const {
1139 return isMemNoOffset(true);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001140 }
Kevin Enderby488f20b2014-04-10 20:18:58 +00001141 bool isAlignedMemoryNone() const {
1142 return isMemNoOffset(false, 0);
1143 }
1144 bool isDupAlignedMemoryNone() const {
1145 return isMemNoOffset(false, 0);
1146 }
1147 bool isAlignedMemory16() const {
1148 if (isMemNoOffset(false, 2)) // alignment in bytes for 16-bits is 2.
1149 return true;
1150 return isMemNoOffset(false, 0);
1151 }
1152 bool isDupAlignedMemory16() const {
1153 if (isMemNoOffset(false, 2)) // alignment in bytes for 16-bits is 2.
1154 return true;
1155 return isMemNoOffset(false, 0);
1156 }
1157 bool isAlignedMemory32() const {
1158 if (isMemNoOffset(false, 4)) // alignment in bytes for 32-bits is 4.
1159 return true;
1160 return isMemNoOffset(false, 0);
1161 }
1162 bool isDupAlignedMemory32() const {
1163 if (isMemNoOffset(false, 4)) // alignment in bytes for 32-bits is 4.
1164 return true;
1165 return isMemNoOffset(false, 0);
1166 }
1167 bool isAlignedMemory64() const {
1168 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1169 return true;
1170 return isMemNoOffset(false, 0);
1171 }
1172 bool isDupAlignedMemory64() const {
1173 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1174 return true;
1175 return isMemNoOffset(false, 0);
1176 }
1177 bool isAlignedMemory64or128() const {
1178 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1179 return true;
1180 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
1181 return true;
1182 return isMemNoOffset(false, 0);
1183 }
1184 bool isDupAlignedMemory64or128() const {
1185 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1186 return true;
1187 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
1188 return true;
1189 return isMemNoOffset(false, 0);
1190 }
1191 bool isAlignedMemory64or128or256() const {
1192 if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8.
1193 return true;
1194 if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16.
1195 return true;
1196 if (isMemNoOffset(false, 32)) // alignment in bytes for 256-bits is 32.
1197 return true;
1198 return isMemNoOffset(false, 0);
1199 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001200 bool isAddrMode2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001201 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001202 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001203 if (Memory.OffsetRegNum) return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00001204 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001205 if (!Memory.OffsetImm) return true;
1206 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachd3595712011-08-03 23:50:40 +00001207 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001208 }
Jim Grosbachcd17c122011-08-04 23:01:30 +00001209 bool isAM2OffsetImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001210 if (!isImm()) return false;
Jim Grosbachcd17c122011-08-04 23:01:30 +00001211 // Immediate offset in range [-4095, 4095].
1212 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1213 if (!CE) return false;
1214 int64_t Val = CE->getValue();
Mihai Popac1d119e2013-06-11 09:48:35 +00001215 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
Jim Grosbachcd17c122011-08-04 23:01:30 +00001216 }
Jim Grosbach5b96b802011-08-10 20:29:19 +00001217 bool isAddrMode3() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001218 // If we have an immediate that's not a constant, treat it as a label
1219 // reference needing a fixup. If it is a constant, it's something else
1220 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001221 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001222 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001223 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001224 // No shifts are legal for AM3.
Jim Grosbach871dff72011-10-11 15:59:20 +00001225 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001226 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001227 if (Memory.OffsetRegNum) return true;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001228 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001229 if (!Memory.OffsetImm) return true;
1230 int64_t Val = Memory.OffsetImm->getValue();
Silviu Baranga5a719f92012-05-11 09:10:54 +00001231 // The #-0 offset is encoded as INT32_MIN, and we have to check
1232 // for this too.
1233 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001234 }
1235 bool isAM3Offset() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001236 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001237 return false;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001238 if (Kind == k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001239 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1240 // Immediate offset in range [-255, 255].
1241 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1242 if (!CE) return false;
1243 int64_t Val = CE->getValue();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001244 // Special case, #-0 is INT32_MIN.
1245 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001246 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001247 bool isAddrMode5() const {
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001248 // If we have an immediate that's not a constant, treat it as a label
1249 // reference needing a fixup. If it is a constant, it's something else
1250 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001251 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001252 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001253 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001254 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001255 if (Memory.OffsetRegNum) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001256 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbach871dff72011-10-11 15:59:20 +00001257 if (!Memory.OffsetImm) return true;
1258 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001259 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001260 Val == INT32_MIN;
Bill Wendling8d2aa032010-11-08 23:49:57 +00001261 }
Jim Grosbach05541f42011-09-19 22:21:13 +00001262 bool isMemTBB() const {
Chad Rosier41099832012-09-11 23:02:35 +00001263 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001264 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach05541f42011-09-19 22:21:13 +00001265 return false;
1266 return true;
1267 }
1268 bool isMemTBH() const {
Chad Rosier41099832012-09-11 23:02:35 +00001269 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001270 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1271 Memory.Alignment != 0 )
Jim Grosbach05541f42011-09-19 22:21:13 +00001272 return false;
1273 return true;
1274 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001275 bool isMemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001276 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendling092a7bd2010-12-14 03:36:38 +00001277 return false;
Daniel Dunbar7ed45592011-01-18 05:34:11 +00001278 return true;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001279 }
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001280 bool isT2MemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001281 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001282 Memory.Alignment != 0)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001283 return false;
1284 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbach871dff72011-10-11 15:59:20 +00001285 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001286 return true;
Jim Grosbach871dff72011-10-11 15:59:20 +00001287 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001288 return false;
1289 return true;
1290 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001291 bool isMemThumbRR() const {
1292 // Thumb reg+reg addressing is simple. Just two registers, a base and
1293 // an offset. No shifts, negations or any other complicating factors.
Chad Rosier41099832012-09-11 23:02:35 +00001294 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001295 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendling811c9362010-11-30 07:44:32 +00001296 return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001297 return isARMLowRegister(Memory.BaseRegNum) &&
1298 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001299 }
1300 bool isMemThumbRIs4() const {
Chad Rosier41099832012-09-11 23:02:35 +00001301 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001302 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001303 return false;
1304 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbach871dff72011-10-11 15:59:20 +00001305 if (!Memory.OffsetImm) return true;
1306 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001307 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1308 }
Jim Grosbach26d35872011-08-19 18:55:51 +00001309 bool isMemThumbRIs2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001310 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001311 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach26d35872011-08-19 18:55:51 +00001312 return false;
1313 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbach871dff72011-10-11 15:59:20 +00001314 if (!Memory.OffsetImm) return true;
1315 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach26d35872011-08-19 18:55:51 +00001316 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1317 }
Jim Grosbacha32c7532011-08-19 18:49:59 +00001318 bool isMemThumbRIs1() const {
Chad Rosier41099832012-09-11 23:02:35 +00001319 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001320 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbacha32c7532011-08-19 18:49:59 +00001321 return false;
1322 // Immediate offset in range [0, 31].
Jim Grosbach871dff72011-10-11 15:59:20 +00001323 if (!Memory.OffsetImm) return true;
1324 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha32c7532011-08-19 18:49:59 +00001325 return Val >= 0 && Val <= 31;
1326 }
Jim Grosbach23983d62011-08-19 18:13:48 +00001327 bool isMemThumbSPI() const {
Chad Rosier41099832012-09-11 23:02:35 +00001328 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001329 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbach23983d62011-08-19 18:13:48 +00001330 return false;
1331 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001332 if (!Memory.OffsetImm) return true;
1333 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001334 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendling811c9362010-11-30 07:44:32 +00001335 }
Jim Grosbach7db8d692011-09-08 22:07:06 +00001336 bool isMemImm8s4Offset() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001337 // If we have an immediate that's not a constant, treat it as a label
1338 // reference needing a fixup. If it is a constant, it's something else
1339 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001340 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001341 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001342 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7db8d692011-09-08 22:07:06 +00001343 return false;
1344 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001345 if (!Memory.OffsetImm) return true;
1346 int64_t Val = Memory.OffsetImm->getValue();
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001347 // Special case, #-0 is INT32_MIN.
1348 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
Jim Grosbach7db8d692011-09-08 22:07:06 +00001349 }
Jim Grosbacha05627e2011-09-09 18:37:27 +00001350 bool isMemImm0_1020s4Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001351 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha05627e2011-09-09 18:37:27 +00001352 return false;
1353 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001354 if (!Memory.OffsetImm) return true;
1355 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha05627e2011-09-09 18:37:27 +00001356 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1357 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001358 bool isMemImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001359 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001360 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001361 // Base reg of PC isn't allowed for these encodings.
1362 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001363 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001364 if (!Memory.OffsetImm) return true;
1365 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson49168402011-09-23 22:25:02 +00001366 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbachd3595712011-08-03 23:50:40 +00001367 }
Jim Grosbach2392c532011-09-07 23:39:14 +00001368 bool isMemPosImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001369 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach2392c532011-09-07 23:39:14 +00001370 return false;
1371 // Immediate offset in range [0, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001372 if (!Memory.OffsetImm) return true;
1373 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach2392c532011-09-07 23:39:14 +00001374 return Val >= 0 && Val < 256;
1375 }
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001376 bool isMemNegImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001377 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001378 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001379 // Base reg of PC isn't allowed for these encodings.
1380 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001381 // Immediate offset in range [-255, -1].
Jim Grosbach175c7d02011-12-06 04:49:29 +00001382 if (!Memory.OffsetImm) return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001383 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach175c7d02011-12-06 04:49:29 +00001384 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001385 }
1386 bool isMemUImm12Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001387 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001388 return false;
1389 // Immediate offset in range [0, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001390 if (!Memory.OffsetImm) return true;
1391 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001392 return (Val >= 0 && Val < 4096);
1393 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001394 bool isMemImm12Offset() const {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001395 // If we have an immediate that's not a constant, treat it as a label
1396 // reference needing a fixup. If it is a constant, it's something else
1397 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001398 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach95466ce2011-08-08 20:59:31 +00001399 return true;
1400
Chad Rosier41099832012-09-11 23:02:35 +00001401 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001402 return false;
1403 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001404 if (!Memory.OffsetImm) return true;
1405 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001406 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001407 }
1408 bool isPostIdxImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001409 if (!isImm()) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001410 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1411 if (!CE) return false;
1412 int64_t Val = CE->getValue();
Owen Andersonf02d98d2011-08-29 17:17:09 +00001413 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001414 }
Jim Grosbach93981412011-10-11 21:55:36 +00001415 bool isPostIdxImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001416 if (!isImm()) return false;
Jim Grosbach93981412011-10-11 21:55:36 +00001417 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1418 if (!CE) return false;
1419 int64_t Val = CE->getValue();
1420 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1421 (Val == INT32_MIN);
1422 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001423
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001424 bool isMSRMask() const { return Kind == k_MSRMask; }
Tim Northoveree843ef2014-08-15 10:47:12 +00001425 bool isBankedReg() const { return Kind == k_BankedReg; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001426 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001427
Jim Grosbach741cd732011-10-17 22:26:03 +00001428 // NEON operands.
Jim Grosbach2f50e922011-12-15 21:44:33 +00001429 bool isSingleSpacedVectorList() const {
1430 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1431 }
1432 bool isDoubleSpacedVectorList() const {
1433 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1434 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001435 bool isVecListOneD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001436 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001437 return VectorList.Count == 1;
1438 }
1439
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001440 bool isVecListDPair() const {
1441 if (!isSingleSpacedVectorList()) return false;
1442 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1443 .contains(VectorList.RegNum));
1444 }
1445
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001446 bool isVecListThreeD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001447 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001448 return VectorList.Count == 3;
1449 }
1450
Jim Grosbach846bcff2011-10-21 20:35:01 +00001451 bool isVecListFourD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001452 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach846bcff2011-10-21 20:35:01 +00001453 return VectorList.Count == 4;
1454 }
1455
Jim Grosbache5307f92012-03-05 21:43:40 +00001456 bool isVecListDPairSpaced() const {
Kevin Enderby56113982014-03-26 21:54:11 +00001457 if (Kind != k_VectorList) return false;
Kevin Enderby816ca272012-03-20 17:41:51 +00001458 if (isSingleSpacedVectorList()) return false;
Jim Grosbache5307f92012-03-05 21:43:40 +00001459 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1460 .contains(VectorList.RegNum));
1461 }
1462
Jim Grosbachac2af3f2012-01-23 23:20:46 +00001463 bool isVecListThreeQ() const {
1464 if (!isDoubleSpacedVectorList()) return false;
1465 return VectorList.Count == 3;
1466 }
1467
Jim Grosbach1e946a42012-01-24 00:43:12 +00001468 bool isVecListFourQ() const {
1469 if (!isDoubleSpacedVectorList()) return false;
1470 return VectorList.Count == 4;
1471 }
1472
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001473 bool isSingleSpacedVectorAllLanes() const {
1474 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1475 }
1476 bool isDoubleSpacedVectorAllLanes() const {
1477 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1478 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001479 bool isVecListOneDAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001480 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001481 return VectorList.Count == 1;
1482 }
1483
Jim Grosbach13a292c2012-03-06 22:01:44 +00001484 bool isVecListDPairAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001485 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach13a292c2012-03-06 22:01:44 +00001486 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1487 .contains(VectorList.RegNum));
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001488 }
1489
Jim Grosbached428bc2012-03-06 23:10:38 +00001490 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001491 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001492 return VectorList.Count == 2;
1493 }
1494
Jim Grosbachb78403c2012-01-24 23:47:04 +00001495 bool isVecListThreeDAllLanes() const {
1496 if (!isSingleSpacedVectorAllLanes()) return false;
1497 return VectorList.Count == 3;
1498 }
1499
1500 bool isVecListThreeQAllLanes() const {
1501 if (!isDoubleSpacedVectorAllLanes()) return false;
1502 return VectorList.Count == 3;
1503 }
1504
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001505 bool isVecListFourDAllLanes() const {
1506 if (!isSingleSpacedVectorAllLanes()) return false;
1507 return VectorList.Count == 4;
1508 }
1509
1510 bool isVecListFourQAllLanes() const {
1511 if (!isDoubleSpacedVectorAllLanes()) return false;
1512 return VectorList.Count == 4;
1513 }
1514
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001515 bool isSingleSpacedVectorIndexed() const {
1516 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1517 }
1518 bool isDoubleSpacedVectorIndexed() const {
1519 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1520 }
Jim Grosbach04945c42011-12-02 00:35:16 +00001521 bool isVecListOneDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001522 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach04945c42011-12-02 00:35:16 +00001523 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1524 }
1525
Jim Grosbachda511042011-12-14 23:35:06 +00001526 bool isVecListOneDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001527 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001528 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1529 }
1530
1531 bool isVecListOneDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001532 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001533 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1534 }
1535
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001536 bool isVecListTwoDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001537 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001538 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1539 }
1540
Jim Grosbachda511042011-12-14 23:35:06 +00001541 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001542 if (!isSingleSpacedVectorIndexed()) return false;
1543 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1544 }
1545
1546 bool isVecListTwoQWordIndexed() const {
1547 if (!isDoubleSpacedVectorIndexed()) return false;
1548 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1549 }
1550
1551 bool isVecListTwoQHWordIndexed() const {
1552 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001553 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1554 }
1555
1556 bool isVecListTwoDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001557 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001558 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1559 }
1560
Jim Grosbacha8b444b2012-01-23 21:53:26 +00001561 bool isVecListThreeDByteIndexed() const {
1562 if (!isSingleSpacedVectorIndexed()) return false;
1563 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1564 }
1565
1566 bool isVecListThreeDHWordIndexed() const {
1567 if (!isSingleSpacedVectorIndexed()) return false;
1568 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1569 }
1570
1571 bool isVecListThreeQWordIndexed() const {
1572 if (!isDoubleSpacedVectorIndexed()) return false;
1573 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1574 }
1575
1576 bool isVecListThreeQHWordIndexed() const {
1577 if (!isDoubleSpacedVectorIndexed()) return false;
1578 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1579 }
1580
1581 bool isVecListThreeDWordIndexed() const {
1582 if (!isSingleSpacedVectorIndexed()) return false;
1583 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1584 }
1585
Jim Grosbach14952a02012-01-24 18:37:25 +00001586 bool isVecListFourDByteIndexed() const {
1587 if (!isSingleSpacedVectorIndexed()) return false;
1588 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1589 }
1590
1591 bool isVecListFourDHWordIndexed() const {
1592 if (!isSingleSpacedVectorIndexed()) return false;
1593 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1594 }
1595
1596 bool isVecListFourQWordIndexed() const {
1597 if (!isDoubleSpacedVectorIndexed()) return false;
1598 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1599 }
1600
1601 bool isVecListFourQHWordIndexed() const {
1602 if (!isDoubleSpacedVectorIndexed()) return false;
1603 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1604 }
1605
1606 bool isVecListFourDWordIndexed() const {
1607 if (!isSingleSpacedVectorIndexed()) return false;
1608 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1609 }
1610
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001611 bool isVectorIndex8() const {
1612 if (Kind != k_VectorIndex) return false;
1613 return VectorIndex.Val < 8;
1614 }
1615 bool isVectorIndex16() const {
1616 if (Kind != k_VectorIndex) return false;
1617 return VectorIndex.Val < 4;
1618 }
1619 bool isVectorIndex32() const {
1620 if (Kind != k_VectorIndex) return false;
1621 return VectorIndex.Val < 2;
1622 }
1623
Jim Grosbach741cd732011-10-17 22:26:03 +00001624 bool isNEONi8splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001625 if (!isImm()) return false;
Jim Grosbach741cd732011-10-17 22:26:03 +00001626 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1627 // Must be a constant.
1628 if (!CE) return false;
1629 int64_t Value = CE->getValue();
1630 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1631 // value.
Jim Grosbach741cd732011-10-17 22:26:03 +00001632 return Value >= 0 && Value < 256;
1633 }
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001634
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001635 bool isNEONi16splat() const {
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00001636 if (isNEONByteReplicate(2))
1637 return false; // Leave that for bytes replication and forbid by default.
1638 if (!isImm())
1639 return false;
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001640 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1641 // Must be a constant.
1642 if (!CE) return false;
Renato Golinf5dd1da2014-09-25 11:31:24 +00001643 unsigned Value = CE->getValue();
1644 return ARM_AM::isNEONi16splat(Value);
1645 }
1646
1647 bool isNEONi16splatNot() const {
1648 if (!isImm())
1649 return false;
1650 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1651 // Must be a constant.
1652 if (!CE) return false;
1653 unsigned Value = CE->getValue();
1654 return ARM_AM::isNEONi16splat(~Value & 0xffff);
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001655 }
1656
Jim Grosbach8211c052011-10-18 00:22:00 +00001657 bool isNEONi32splat() const {
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00001658 if (isNEONByteReplicate(4))
1659 return false; // Leave that for bytes replication and forbid by default.
1660 if (!isImm())
1661 return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001662 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1663 // Must be a constant.
1664 if (!CE) return false;
Renato Golinf5dd1da2014-09-25 11:31:24 +00001665 unsigned Value = CE->getValue();
1666 return ARM_AM::isNEONi32splat(Value);
1667 }
1668
1669 bool isNEONi32splatNot() const {
1670 if (!isImm())
1671 return false;
1672 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1673 // Must be a constant.
1674 if (!CE) return false;
1675 unsigned Value = CE->getValue();
1676 return ARM_AM::isNEONi32splat(~Value);
Jim Grosbach8211c052011-10-18 00:22:00 +00001677 }
1678
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00001679 bool isNEONByteReplicate(unsigned NumBytes) const {
1680 if (!isImm())
1681 return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001682 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1683 // Must be a constant.
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00001684 if (!CE)
1685 return false;
1686 int64_t Value = CE->getValue();
1687 if (!Value)
1688 return false; // Don't bother with zero.
1689
1690 unsigned char B = Value & 0xff;
1691 for (unsigned i = 1; i < NumBytes; ++i) {
1692 Value >>= 8;
1693 if ((Value & 0xff) != B)
1694 return false;
1695 }
1696 return true;
1697 }
1698 bool isNEONi16ByteReplicate() const { return isNEONByteReplicate(2); }
1699 bool isNEONi32ByteReplicate() const { return isNEONByteReplicate(4); }
1700 bool isNEONi32vmov() const {
1701 if (isNEONByteReplicate(4))
1702 return false; // Let it to be classified as byte-replicate case.
1703 if (!isImm())
1704 return false;
1705 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1706 // Must be a constant.
1707 if (!CE)
1708 return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001709 int64_t Value = CE->getValue();
1710 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1711 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
Renato Golinf5dd1da2014-09-25 11:31:24 +00001712 // FIXME: This is probably wrong and a copy and paste from previous example
Jim Grosbach8211c052011-10-18 00:22:00 +00001713 return (Value >= 0 && Value < 256) ||
1714 (Value >= 0x0100 && Value <= 0xff00) ||
1715 (Value >= 0x010000 && Value <= 0xff0000) ||
1716 (Value >= 0x01000000 && Value <= 0xff000000) ||
1717 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1718 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1719 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00001720 bool isNEONi32vmovNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001721 if (!isImm()) return false;
Jim Grosbach045b6c72011-12-19 23:51:07 +00001722 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1723 // Must be a constant.
1724 if (!CE) return false;
1725 int64_t Value = ~CE->getValue();
1726 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1727 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
Renato Golinf5dd1da2014-09-25 11:31:24 +00001728 // FIXME: This is probably wrong and a copy and paste from previous example
Jim Grosbach045b6c72011-12-19 23:51:07 +00001729 return (Value >= 0 && Value < 256) ||
1730 (Value >= 0x0100 && Value <= 0xff00) ||
1731 (Value >= 0x010000 && Value <= 0xff0000) ||
1732 (Value >= 0x01000000 && Value <= 0xff000000) ||
1733 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1734 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1735 }
Jim Grosbach8211c052011-10-18 00:22:00 +00001736
Jim Grosbache4454e02011-10-18 16:18:11 +00001737 bool isNEONi64splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001738 if (!isImm()) return false;
Jim Grosbache4454e02011-10-18 16:18:11 +00001739 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1740 // Must be a constant.
1741 if (!CE) return false;
1742 uint64_t Value = CE->getValue();
1743 // i64 value with each byte being either 0 or 0xff.
1744 for (unsigned i = 0; i < 8; ++i)
1745 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1746 return true;
1747 }
1748
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001749 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001750 // Add as immediates when possible. Null MCExpr = 0.
Craig Topper062a2ba2014-04-25 05:30:21 +00001751 if (!Expr)
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001752 Inst.addOperand(MCOperand::CreateImm(0));
1753 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001754 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1755 else
1756 Inst.addOperand(MCOperand::CreateExpr(Expr));
1757 }
1758
Daniel Dunbard8042b72010-08-11 06:36:53 +00001759 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar188b47b2010-08-11 06:37:20 +00001760 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbard8042b72010-08-11 06:36:53 +00001761 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach968c9272010-12-06 18:30:57 +00001762 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1763 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbard8042b72010-08-11 06:36:53 +00001764 }
1765
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00001766 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1767 assert(N == 1 && "Invalid number of operands!");
1768 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1769 }
1770
Jim Grosbach48399582011-10-12 17:34:41 +00001771 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1772 assert(N == 1 && "Invalid number of operands!");
1773 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1774 }
1775
1776 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1777 assert(N == 1 && "Invalid number of operands!");
1778 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1779 }
1780
Jim Grosbach3d1eac82011-08-26 21:43:41 +00001781 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1782 assert(N == 1 && "Invalid number of operands!");
1783 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1784 }
1785
1786 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1787 assert(N == 1 && "Invalid number of operands!");
1788 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1789 }
1790
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00001791 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1792 assert(N == 1 && "Invalid number of operands!");
1793 Inst.addOperand(MCOperand::CreateReg(getReg()));
1794 }
1795
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00001796 void addRegOperands(MCInst &Inst, unsigned N) const {
1797 assert(N == 1 && "Invalid number of operands!");
1798 Inst.addOperand(MCOperand::CreateReg(getReg()));
1799 }
1800
Jim Grosbachac798e12011-07-25 20:49:51 +00001801 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001802 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001803 assert(isRegShiftedReg() &&
Alp Tokerf907b892013-12-05 05:44:44 +00001804 "addRegShiftedRegOperands() on non-RegShiftedReg!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001805 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1806 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001807 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachac798e12011-07-25 20:49:51 +00001808 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001809 }
1810
Jim Grosbachac798e12011-07-25 20:49:51 +00001811 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson04912702011-07-21 23:38:37 +00001812 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001813 assert(isRegShiftedImm() &&
Alp Tokerf907b892013-12-05 05:44:44 +00001814 "addRegShiftedImmOperands() on non-RegShiftedImm!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001815 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001816 // Shift of #32 is encoded as 0 where permitted
1817 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Andersonb595ed02011-07-21 18:54:16 +00001818 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001819 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Andersonb595ed02011-07-21 18:54:16 +00001820 }
1821
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001822 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001823 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001824 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1825 ShifterImm.Imm));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001826 }
1827
Bill Wendling8d2aa032010-11-08 23:49:57 +00001828 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling2cae3272010-11-09 22:44:22 +00001829 assert(N == 1 && "Invalid number of operands!");
Bill Wendlingbed94652010-11-09 23:28:44 +00001830 const SmallVectorImpl<unsigned> &RegList = getRegList();
1831 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00001832 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1833 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling8d2aa032010-11-08 23:49:57 +00001834 }
1835
Bill Wendling9898ac92010-11-17 04:32:08 +00001836 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1837 addRegListOperands(Inst, N);
1838 }
1839
1840 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1841 addRegListOperands(Inst, N);
1842 }
1843
Jim Grosbach833b9d32011-07-27 20:15:40 +00001844 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1845 assert(N == 1 && "Invalid number of operands!");
1846 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1847 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1848 }
1849
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00001850 void addModImmOperands(MCInst &Inst, unsigned N) const {
1851 assert(N == 1 && "Invalid number of operands!");
1852
1853 // Support for fixups (MCFixup)
1854 if (isImm())
1855 return addImmOperands(Inst, N);
1856
Asiri Rathnayake7835e9b2014-12-09 13:14:58 +00001857 Inst.addOperand(MCOperand::CreateImm(ModImm.Bits | (ModImm.Rot << 7)));
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00001858 }
1859
1860 void addModImmNotOperands(MCInst &Inst, unsigned N) const {
1861 assert(N == 1 && "Invalid number of operands!");
1862 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1863 uint32_t Enc = ARM_AM::getSOImmVal(~CE->getValue());
1864 Inst.addOperand(MCOperand::CreateImm(Enc));
1865 }
1866
1867 void addModImmNegOperands(MCInst &Inst, unsigned N) const {
1868 assert(N == 1 && "Invalid number of operands!");
1869 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1870 uint32_t Enc = ARM_AM::getSOImmVal(-CE->getValue());
1871 Inst.addOperand(MCOperand::CreateImm(Enc));
1872 }
1873
Jim Grosbach864b6092011-07-28 21:34:26 +00001874 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1875 assert(N == 1 && "Invalid number of operands!");
1876 // Munge the lsb/width into a bitfield mask.
1877 unsigned lsb = Bitfield.LSB;
1878 unsigned width = Bitfield.Width;
1879 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1880 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1881 (32 - (lsb + width)));
1882 Inst.addOperand(MCOperand::CreateImm(Mask));
1883 }
1884
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001885 void addImmOperands(MCInst &Inst, unsigned N) const {
1886 assert(N == 1 && "Invalid number of operands!");
1887 addExpr(Inst, getImm());
1888 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00001889
Jim Grosbachea231912011-12-22 22:19:05 +00001890 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1891 assert(N == 1 && "Invalid number of operands!");
1892 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1893 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1894 }
1895
1896 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1897 assert(N == 1 && "Invalid number of operands!");
1898 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1899 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1900 }
1901
Jim Grosbache7fbce72011-10-03 23:38:36 +00001902 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1903 assert(N == 1 && "Invalid number of operands!");
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00001904 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1905 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1906 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbache7fbce72011-10-03 23:38:36 +00001907 }
1908
Jim Grosbach7db8d692011-09-08 22:07:06 +00001909 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1910 assert(N == 1 && "Invalid number of operands!");
1911 // FIXME: We really want to scale the value here, but the LDRD/STRD
1912 // instruction don't encode operands that way yet.
1913 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1914 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1915 }
1916
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001917 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1918 assert(N == 1 && "Invalid number of operands!");
1919 // The immediate is scaled by four in the encoding and is stored
1920 // in the MCInst as such. Lop off the low two bits here.
1921 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1922 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1923 }
1924
Jim Grosbach930f2f62012-04-05 20:57:13 +00001925 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1926 assert(N == 1 && "Invalid number of operands!");
1927 // The immediate is scaled by four in the encoding and is stored
1928 // in the MCInst as such. Lop off the low two bits here.
1929 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1930 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1931 }
1932
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001933 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1934 assert(N == 1 && "Invalid number of operands!");
1935 // The immediate is scaled by four in the encoding and is stored
1936 // in the MCInst as such. Lop off the low two bits here.
1937 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1938 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1939 }
1940
Jim Grosbach475c6db2011-07-25 23:09:14 +00001941 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1942 assert(N == 1 && "Invalid number of operands!");
1943 // The constant encodes as the immediate-1, and we store in the instruction
1944 // the bits as encoded, so subtract off one here.
1945 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1946 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1947 }
1948
Jim Grosbach801e0a32011-07-22 23:16:18 +00001949 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1950 assert(N == 1 && "Invalid number of operands!");
1951 // The constant encodes as the immediate-1, and we store in the instruction
1952 // the bits as encoded, so subtract off one here.
1953 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1954 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1955 }
1956
Jim Grosbach46dd4132011-08-17 21:51:27 +00001957 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1958 assert(N == 1 && "Invalid number of operands!");
1959 // The constant encodes as the immediate, except for 32, which encodes as
1960 // zero.
1961 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1962 unsigned Imm = CE->getValue();
1963 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1964 }
1965
Jim Grosbach27c1e252011-07-21 17:23:04 +00001966 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1967 assert(N == 1 && "Invalid number of operands!");
1968 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1969 // the instruction as well.
1970 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1971 int Val = CE->getValue();
1972 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1973 }
1974
Jim Grosbachb009a872011-10-28 22:36:30 +00001975 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1976 assert(N == 1 && "Invalid number of operands!");
1977 // The operand is actually a t2_so_imm, but we have its bitwise
1978 // negation in the assembly source, so twiddle it here.
1979 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1980 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1981 }
1982
Jim Grosbach30506252011-12-08 00:31:07 +00001983 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1984 assert(N == 1 && "Invalid number of operands!");
1985 // The operand is actually a t2_so_imm, but we have its
1986 // negation in the assembly source, so twiddle it here.
1987 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1988 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1989 }
1990
Jim Grosbach930f2f62012-04-05 20:57:13 +00001991 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1992 assert(N == 1 && "Invalid number of operands!");
1993 // The operand is actually an imm0_4095, but we have its
1994 // negation in the assembly source, so twiddle it here.
1995 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1996 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1997 }
1998
Mihai Popad36cbaa2013-07-03 09:21:44 +00001999 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
2000 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
2001 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
2002 return;
2003 }
2004
2005 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
2006 assert(SR && "Unknown value type!");
2007 Inst.addOperand(MCOperand::CreateExpr(SR));
2008 }
2009
Mihai Popa8a9da5b2013-07-22 15:49:36 +00002010 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
2011 assert(N == 1 && "Invalid number of operands!");
2012 if (isImm()) {
2013 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2014 if (CE) {
2015 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
2016 return;
2017 }
2018
2019 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
2020 assert(SR && "Unknown value type!");
2021 Inst.addOperand(MCOperand::CreateExpr(SR));
2022 return;
2023 }
2024
2025 assert(isMem() && "Unknown value type!");
2026 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
2027 Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue()));
2028 }
2029
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002030 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
2031 assert(N == 1 && "Invalid number of operands!");
2032 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
2033 }
2034
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002035 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
2036 assert(N == 1 && "Invalid number of operands!");
2037 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
2038 }
2039
Jim Grosbachd3595712011-08-03 23:50:40 +00002040 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
2041 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002042 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +00002043 }
2044
Jim Grosbach94298a92012-01-18 22:46:46 +00002045 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
2046 assert(N == 1 && "Invalid number of operands!");
2047 int32_t Imm = Memory.OffsetImm->getValue();
Jim Grosbach94298a92012-01-18 22:46:46 +00002048 Inst.addOperand(MCOperand::CreateImm(Imm));
2049 }
2050
Jiangning Liu10dd40e2012-08-02 08:13:13 +00002051 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
2052 assert(N == 1 && "Invalid number of operands!");
2053 assert(isImm() && "Not an immediate!");
2054
2055 // If we have an immediate that's not a constant, treat it as a label
2056 // reference needing a fixup.
2057 if (!isa<MCConstantExpr>(getImm())) {
2058 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2059 return;
2060 }
2061
2062 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2063 int Val = CE->getValue();
2064 Inst.addOperand(MCOperand::CreateImm(Val));
2065 }
2066
Jim Grosbacha95ec992011-10-11 17:29:55 +00002067 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
2068 assert(N == 2 && "Invalid number of operands!");
2069 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2070 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
2071 }
2072
Kevin Enderby488f20b2014-04-10 20:18:58 +00002073 void addDupAlignedMemoryNoneOperands(MCInst &Inst, unsigned N) const {
2074 addAlignedMemoryOperands(Inst, N);
2075 }
2076
2077 void addAlignedMemoryNoneOperands(MCInst &Inst, unsigned N) const {
2078 addAlignedMemoryOperands(Inst, N);
2079 }
2080
2081 void addAlignedMemory16Operands(MCInst &Inst, unsigned N) const {
2082 addAlignedMemoryOperands(Inst, N);
2083 }
2084
2085 void addDupAlignedMemory16Operands(MCInst &Inst, unsigned N) const {
2086 addAlignedMemoryOperands(Inst, N);
2087 }
2088
2089 void addAlignedMemory32Operands(MCInst &Inst, unsigned N) const {
2090 addAlignedMemoryOperands(Inst, N);
2091 }
2092
2093 void addDupAlignedMemory32Operands(MCInst &Inst, unsigned N) const {
2094 addAlignedMemoryOperands(Inst, N);
2095 }
2096
2097 void addAlignedMemory64Operands(MCInst &Inst, unsigned N) const {
2098 addAlignedMemoryOperands(Inst, N);
2099 }
2100
2101 void addDupAlignedMemory64Operands(MCInst &Inst, unsigned N) const {
2102 addAlignedMemoryOperands(Inst, N);
2103 }
2104
2105 void addAlignedMemory64or128Operands(MCInst &Inst, unsigned N) const {
2106 addAlignedMemoryOperands(Inst, N);
2107 }
2108
2109 void addDupAlignedMemory64or128Operands(MCInst &Inst, unsigned N) const {
2110 addAlignedMemoryOperands(Inst, N);
2111 }
2112
2113 void addAlignedMemory64or128or256Operands(MCInst &Inst, unsigned N) const {
2114 addAlignedMemoryOperands(Inst, N);
2115 }
2116
Jim Grosbachd3595712011-08-03 23:50:40 +00002117 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
2118 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002119 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2120 if (!Memory.OffsetRegNum) {
Jim Grosbachd3595712011-08-03 23:50:40 +00002121 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2122 // Special case for #-0
2123 if (Val == INT32_MIN) Val = 0;
2124 if (Val < 0) Val = -Val;
2125 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
2126 } else {
2127 // For register offset, we encode the shift type and negation flag
2128 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00002129 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2130 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00002131 }
Jim Grosbach871dff72011-10-11 15:59:20 +00002132 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2133 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002134 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00002135 }
2136
Jim Grosbachcd17c122011-08-04 23:01:30 +00002137 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
2138 assert(N == 2 && "Invalid number of operands!");
2139 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2140 assert(CE && "non-constant AM2OffsetImm operand!");
2141 int32_t Val = CE->getValue();
2142 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2143 // Special case for #-0
2144 if (Val == INT32_MIN) Val = 0;
2145 if (Val < 0) Val = -Val;
2146 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
2147 Inst.addOperand(MCOperand::CreateReg(0));
2148 Inst.addOperand(MCOperand::CreateImm(Val));
2149 }
2150
Jim Grosbach5b96b802011-08-10 20:29:19 +00002151 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
2152 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00002153 // If we have an immediate that's not a constant, treat it as a label
2154 // reference needing a fixup. If it is a constant, it's something else
2155 // and we reject it.
2156 if (isImm()) {
2157 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2158 Inst.addOperand(MCOperand::CreateReg(0));
2159 Inst.addOperand(MCOperand::CreateImm(0));
2160 return;
2161 }
2162
Jim Grosbach871dff72011-10-11 15:59:20 +00002163 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2164 if (!Memory.OffsetRegNum) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00002165 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2166 // Special case for #-0
2167 if (Val == INT32_MIN) Val = 0;
2168 if (Val < 0) Val = -Val;
2169 Val = ARM_AM::getAM3Opc(AddSub, Val);
2170 } else {
2171 // For register offset, we encode the shift type and negation flag
2172 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00002173 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach5b96b802011-08-10 20:29:19 +00002174 }
Jim Grosbach871dff72011-10-11 15:59:20 +00002175 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2176 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach5b96b802011-08-10 20:29:19 +00002177 Inst.addOperand(MCOperand::CreateImm(Val));
2178 }
2179
2180 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
2181 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002182 if (Kind == k_PostIndexRegister) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00002183 int32_t Val =
2184 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
2185 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2186 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00002187 return;
Jim Grosbach5b96b802011-08-10 20:29:19 +00002188 }
2189
2190 // Constant offset.
2191 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
2192 int32_t Val = CE->getValue();
2193 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2194 // Special case for #-0
2195 if (Val == INT32_MIN) Val = 0;
2196 if (Val < 0) Val = -Val;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00002197 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach5b96b802011-08-10 20:29:19 +00002198 Inst.addOperand(MCOperand::CreateReg(0));
2199 Inst.addOperand(MCOperand::CreateImm(Val));
2200 }
2201
Jim Grosbachd3595712011-08-03 23:50:40 +00002202 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
2203 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00002204 // If we have an immediate that's not a constant, treat it as a label
2205 // reference needing a fixup. If it is a constant, it's something else
2206 // and we reject it.
2207 if (isImm()) {
2208 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2209 Inst.addOperand(MCOperand::CreateImm(0));
2210 return;
2211 }
2212
Jim Grosbachd3595712011-08-03 23:50:40 +00002213 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00002214 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002215 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2216 // Special case for #-0
2217 if (Val == INT32_MIN) Val = 0;
2218 if (Val < 0) Val = -Val;
2219 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbach871dff72011-10-11 15:59:20 +00002220 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002221 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00002222 }
2223
Jim Grosbach7db8d692011-09-08 22:07:06 +00002224 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
2225 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00002226 // If we have an immediate that's not a constant, treat it as a label
2227 // reference needing a fixup. If it is a constant, it's something else
2228 // and we reject it.
2229 if (isImm()) {
2230 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2231 Inst.addOperand(MCOperand::CreateImm(0));
2232 return;
2233 }
2234
Jim Grosbach871dff72011-10-11 15:59:20 +00002235 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2236 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7db8d692011-09-08 22:07:06 +00002237 Inst.addOperand(MCOperand::CreateImm(Val));
2238 }
2239
Jim Grosbacha05627e2011-09-09 18:37:27 +00002240 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
2241 assert(N == 2 && "Invalid number of operands!");
2242 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00002243 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
2244 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha05627e2011-09-09 18:37:27 +00002245 Inst.addOperand(MCOperand::CreateImm(Val));
2246 }
2247
Jim Grosbachd3595712011-08-03 23:50:40 +00002248 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2249 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002250 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2251 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002252 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner5d6f6a02010-10-29 00:27:31 +00002253 }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002254
Jim Grosbach2392c532011-09-07 23:39:14 +00002255 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2256 addMemImm8OffsetOperands(Inst, N);
2257 }
2258
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002259 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach2392c532011-09-07 23:39:14 +00002260 addMemImm8OffsetOperands(Inst, N);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002261 }
2262
2263 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2264 assert(N == 2 && "Invalid number of operands!");
2265 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00002266 if (isImm()) {
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002267 addExpr(Inst, getImm());
2268 Inst.addOperand(MCOperand::CreateImm(0));
2269 return;
2270 }
2271
2272 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00002273 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2274 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002275 Inst.addOperand(MCOperand::CreateImm(Val));
2276 }
2277
Jim Grosbachd3595712011-08-03 23:50:40 +00002278 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2279 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach95466ce2011-08-08 20:59:31 +00002280 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00002281 if (isImm()) {
Jim Grosbach95466ce2011-08-08 20:59:31 +00002282 addExpr(Inst, getImm());
2283 Inst.addOperand(MCOperand::CreateImm(0));
2284 return;
2285 }
2286
2287 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00002288 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2289 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002290 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendling092a7bd2010-12-14 03:36:38 +00002291 }
Bill Wendling811c9362010-11-30 07:44:32 +00002292
Jim Grosbach05541f42011-09-19 22:21:13 +00002293 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
2294 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002295 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2296 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002297 }
2298
2299 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
2300 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002301 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2302 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002303 }
2304
Jim Grosbachd3595712011-08-03 23:50:40 +00002305 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2306 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00002307 unsigned Val =
2308 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2309 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbach871dff72011-10-11 15:59:20 +00002310 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2311 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002312 Inst.addOperand(MCOperand::CreateImm(Val));
2313 }
2314
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002315 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2316 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002317 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2318 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2319 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002320 }
2321
Jim Grosbachd3595712011-08-03 23:50:40 +00002322 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2323 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002324 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2325 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002326 }
2327
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002328 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2329 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002330 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2331 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002332 Inst.addOperand(MCOperand::CreateImm(Val));
2333 }
2334
Jim Grosbach26d35872011-08-19 18:55:51 +00002335 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2336 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002337 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2338 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach26d35872011-08-19 18:55:51 +00002339 Inst.addOperand(MCOperand::CreateImm(Val));
2340 }
2341
Jim Grosbacha32c7532011-08-19 18:49:59 +00002342 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2343 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002344 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2345 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha32c7532011-08-19 18:49:59 +00002346 Inst.addOperand(MCOperand::CreateImm(Val));
2347 }
2348
Jim Grosbach23983d62011-08-19 18:13:48 +00002349 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2350 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002351 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2352 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach23983d62011-08-19 18:13:48 +00002353 Inst.addOperand(MCOperand::CreateImm(Val));
2354 }
2355
Jim Grosbachd3595712011-08-03 23:50:40 +00002356 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2357 assert(N == 1 && "Invalid number of operands!");
2358 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2359 assert(CE && "non-constant post-idx-imm8 operand!");
2360 int Imm = CE->getValue();
2361 bool isAdd = Imm >= 0;
Owen Andersonf02d98d2011-08-29 17:17:09 +00002362 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002363 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2364 Inst.addOperand(MCOperand::CreateImm(Imm));
2365 }
2366
Jim Grosbach93981412011-10-11 21:55:36 +00002367 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2368 assert(N == 1 && "Invalid number of operands!");
2369 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2370 assert(CE && "non-constant post-idx-imm8s4 operand!");
2371 int Imm = CE->getValue();
2372 bool isAdd = Imm >= 0;
2373 if (Imm == INT32_MIN) Imm = 0;
2374 // Immediate is scaled by 4.
2375 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2376 Inst.addOperand(MCOperand::CreateImm(Imm));
2377 }
2378
Jim Grosbachd3595712011-08-03 23:50:40 +00002379 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2380 assert(N == 2 && "Invalid number of operands!");
2381 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachc320c852011-08-05 21:28:30 +00002382 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2383 }
2384
2385 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2386 assert(N == 2 && "Invalid number of operands!");
2387 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2388 // The sign, shift type, and shift amount are encoded in a single operand
2389 // using the AM2 encoding helpers.
2390 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2391 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2392 PostIdxReg.ShiftTy);
2393 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendling811c9362010-11-30 07:44:32 +00002394 }
2395
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002396 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2397 assert(N == 1 && "Invalid number of operands!");
2398 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2399 }
2400
Tim Northoveree843ef2014-08-15 10:47:12 +00002401 void addBankedRegOperands(MCInst &Inst, unsigned N) const {
2402 assert(N == 1 && "Invalid number of operands!");
2403 Inst.addOperand(MCOperand::CreateImm(unsigned(getBankedReg())));
2404 }
2405
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002406 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2407 assert(N == 1 && "Invalid number of operands!");
2408 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2409 }
2410
Jim Grosbach182b6a02011-11-29 23:51:09 +00002411 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002412 assert(N == 1 && "Invalid number of operands!");
2413 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2414 }
2415
Jim Grosbach04945c42011-12-02 00:35:16 +00002416 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2417 assert(N == 2 && "Invalid number of operands!");
2418 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2419 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2420 }
2421
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002422 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2423 assert(N == 1 && "Invalid number of operands!");
2424 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2425 }
2426
2427 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2428 assert(N == 1 && "Invalid number of operands!");
2429 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2430 }
2431
2432 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2433 assert(N == 1 && "Invalid number of operands!");
2434 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2435 }
2436
Jim Grosbach741cd732011-10-17 22:26:03 +00002437 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2438 assert(N == 1 && "Invalid number of operands!");
2439 // The immediate encodes the type of constant as well as the value.
2440 // Mask in that this is an i8 splat.
2441 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2442 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2443 }
2444
Jim Grosbachcda32ae2011-10-17 23:09:09 +00002445 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2446 assert(N == 1 && "Invalid number of operands!");
2447 // The immediate encodes the type of constant as well as the value.
2448 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2449 unsigned Value = CE->getValue();
Renato Golinf5dd1da2014-09-25 11:31:24 +00002450 Value = ARM_AM::encodeNEONi16splat(Value);
2451 Inst.addOperand(MCOperand::CreateImm(Value));
2452 }
2453
2454 void addNEONi16splatNotOperands(MCInst &Inst, unsigned N) const {
2455 assert(N == 1 && "Invalid number of operands!");
2456 // The immediate encodes the type of constant as well as the value.
2457 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2458 unsigned Value = CE->getValue();
2459 Value = ARM_AM::encodeNEONi16splat(~Value & 0xffff);
Jim Grosbachcda32ae2011-10-17 23:09:09 +00002460 Inst.addOperand(MCOperand::CreateImm(Value));
2461 }
2462
Jim Grosbach8211c052011-10-18 00:22:00 +00002463 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2464 assert(N == 1 && "Invalid number of operands!");
2465 // The immediate encodes the type of constant as well as the value.
2466 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2467 unsigned Value = CE->getValue();
Renato Golinf5dd1da2014-09-25 11:31:24 +00002468 Value = ARM_AM::encodeNEONi32splat(Value);
2469 Inst.addOperand(MCOperand::CreateImm(Value));
2470 }
2471
2472 void addNEONi32splatNotOperands(MCInst &Inst, unsigned N) const {
2473 assert(N == 1 && "Invalid number of operands!");
2474 // The immediate encodes the type of constant as well as the value.
2475 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2476 unsigned Value = CE->getValue();
2477 Value = ARM_AM::encodeNEONi32splat(~Value);
Jim Grosbach8211c052011-10-18 00:22:00 +00002478 Inst.addOperand(MCOperand::CreateImm(Value));
2479 }
2480
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00002481 void addNEONinvByteReplicateOperands(MCInst &Inst, unsigned N) const {
2482 assert(N == 1 && "Invalid number of operands!");
2483 // The immediate encodes the type of constant as well as the value.
2484 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2485 unsigned Value = CE->getValue();
2486 assert((Inst.getOpcode() == ARM::VMOVv8i8 ||
2487 Inst.getOpcode() == ARM::VMOVv16i8) &&
2488 "All vmvn instructions that wants to replicate non-zero byte "
2489 "always must be replaced with VMOVv8i8 or VMOVv16i8.");
2490 unsigned B = ((~Value) & 0xff);
2491 B |= 0xe00; // cmode = 0b1110
2492 Inst.addOperand(MCOperand::CreateImm(B));
2493 }
Jim Grosbach8211c052011-10-18 00:22:00 +00002494 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2495 assert(N == 1 && "Invalid number of operands!");
2496 // The immediate encodes the type of constant as well as the value.
2497 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2498 unsigned Value = CE->getValue();
2499 if (Value >= 256 && Value <= 0xffff)
2500 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2501 else if (Value > 0xffff && Value <= 0xffffff)
2502 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2503 else if (Value > 0xffffff)
2504 Value = (Value >> 24) | 0x600;
2505 Inst.addOperand(MCOperand::CreateImm(Value));
2506 }
2507
Stepan Dyatkovskiy00dcc0f2014-04-24 06:03:01 +00002508 void addNEONvmovByteReplicateOperands(MCInst &Inst, unsigned N) const {
2509 assert(N == 1 && "Invalid number of operands!");
2510 // The immediate encodes the type of constant as well as the value.
2511 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2512 unsigned Value = CE->getValue();
2513 assert((Inst.getOpcode() == ARM::VMOVv8i8 ||
2514 Inst.getOpcode() == ARM::VMOVv16i8) &&
2515 "All instructions that wants to replicate non-zero byte "
2516 "always must be replaced with VMOVv8i8 or VMOVv16i8.");
2517 unsigned B = Value & 0xff;
2518 B |= 0xe00; // cmode = 0b1110
2519 Inst.addOperand(MCOperand::CreateImm(B));
2520 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00002521 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2522 assert(N == 1 && "Invalid number of operands!");
2523 // The immediate encodes the type of constant as well as the value.
2524 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2525 unsigned Value = ~CE->getValue();
2526 if (Value >= 256 && Value <= 0xffff)
2527 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2528 else if (Value > 0xffff && Value <= 0xffffff)
2529 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2530 else if (Value > 0xffffff)
2531 Value = (Value >> 24) | 0x600;
2532 Inst.addOperand(MCOperand::CreateImm(Value));
2533 }
2534
Jim Grosbache4454e02011-10-18 16:18:11 +00002535 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2536 assert(N == 1 && "Invalid number of operands!");
2537 // The immediate encodes the type of constant as well as the value.
2538 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2539 uint64_t Value = CE->getValue();
2540 unsigned Imm = 0;
2541 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2542 Imm |= (Value & 1) << i;
2543 }
2544 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2545 }
2546
Craig Topperca7e3e52014-03-10 03:19:03 +00002547 void print(raw_ostream &OS) const override;
Daniel Dunbarebace222010-08-11 06:37:04 +00002548
David Blaikie960ea3f2014-06-08 16:18:35 +00002549 static std::unique_ptr<ARMOperand> CreateITMask(unsigned Mask, SMLoc S) {
2550 auto Op = make_unique<ARMOperand>(k_ITCondMask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002551 Op->ITMask.Mask = Mask;
2552 Op->StartLoc = S;
2553 Op->EndLoc = S;
2554 return Op;
2555 }
2556
David Blaikie960ea3f2014-06-08 16:18:35 +00002557 static std::unique_ptr<ARMOperand> CreateCondCode(ARMCC::CondCodes CC,
2558 SMLoc S) {
2559 auto Op = make_unique<ARMOperand>(k_CondCode);
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002560 Op->CC.Val = CC;
2561 Op->StartLoc = S;
2562 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002563 return Op;
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002564 }
2565
David Blaikie960ea3f2014-06-08 16:18:35 +00002566 static std::unique_ptr<ARMOperand> CreateCoprocNum(unsigned CopVal, SMLoc S) {
2567 auto Op = make_unique<ARMOperand>(k_CoprocNum);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002568 Op->Cop.Val = CopVal;
2569 Op->StartLoc = S;
2570 Op->EndLoc = S;
2571 return Op;
2572 }
2573
David Blaikie960ea3f2014-06-08 16:18:35 +00002574 static std::unique_ptr<ARMOperand> CreateCoprocReg(unsigned CopVal, SMLoc S) {
2575 auto Op = make_unique<ARMOperand>(k_CoprocReg);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002576 Op->Cop.Val = CopVal;
2577 Op->StartLoc = S;
2578 Op->EndLoc = S;
2579 return Op;
2580 }
2581
David Blaikie960ea3f2014-06-08 16:18:35 +00002582 static std::unique_ptr<ARMOperand> CreateCoprocOption(unsigned Val, SMLoc S,
2583 SMLoc E) {
2584 auto Op = make_unique<ARMOperand>(k_CoprocOption);
Jim Grosbach48399582011-10-12 17:34:41 +00002585 Op->Cop.Val = Val;
2586 Op->StartLoc = S;
2587 Op->EndLoc = E;
2588 return Op;
2589 }
2590
David Blaikie960ea3f2014-06-08 16:18:35 +00002591 static std::unique_ptr<ARMOperand> CreateCCOut(unsigned RegNum, SMLoc S) {
2592 auto Op = make_unique<ARMOperand>(k_CCOut);
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002593 Op->Reg.RegNum = RegNum;
2594 Op->StartLoc = S;
2595 Op->EndLoc = S;
2596 return Op;
2597 }
2598
David Blaikie960ea3f2014-06-08 16:18:35 +00002599 static std::unique_ptr<ARMOperand> CreateToken(StringRef Str, SMLoc S) {
2600 auto Op = make_unique<ARMOperand>(k_Token);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002601 Op->Tok.Data = Str.data();
2602 Op->Tok.Length = Str.size();
2603 Op->StartLoc = S;
2604 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002605 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002606 }
2607
David Blaikie960ea3f2014-06-08 16:18:35 +00002608 static std::unique_ptr<ARMOperand> CreateReg(unsigned RegNum, SMLoc S,
2609 SMLoc E) {
2610 auto Op = make_unique<ARMOperand>(k_Register);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002611 Op->Reg.RegNum = RegNum;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002612 Op->StartLoc = S;
2613 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002614 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002615 }
2616
David Blaikie960ea3f2014-06-08 16:18:35 +00002617 static std::unique_ptr<ARMOperand>
2618 CreateShiftedRegister(ARM_AM::ShiftOpc ShTy, unsigned SrcReg,
2619 unsigned ShiftReg, unsigned ShiftImm, SMLoc S,
2620 SMLoc E) {
2621 auto Op = make_unique<ARMOperand>(k_ShiftedRegister);
Jim Grosbachac798e12011-07-25 20:49:51 +00002622 Op->RegShiftedReg.ShiftTy = ShTy;
2623 Op->RegShiftedReg.SrcReg = SrcReg;
2624 Op->RegShiftedReg.ShiftReg = ShiftReg;
2625 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002626 Op->StartLoc = S;
2627 Op->EndLoc = E;
2628 return Op;
2629 }
2630
David Blaikie960ea3f2014-06-08 16:18:35 +00002631 static std::unique_ptr<ARMOperand>
2632 CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy, unsigned SrcReg,
2633 unsigned ShiftImm, SMLoc S, SMLoc E) {
2634 auto Op = make_unique<ARMOperand>(k_ShiftedImmediate);
Jim Grosbachac798e12011-07-25 20:49:51 +00002635 Op->RegShiftedImm.ShiftTy = ShTy;
2636 Op->RegShiftedImm.SrcReg = SrcReg;
2637 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Andersonb595ed02011-07-21 18:54:16 +00002638 Op->StartLoc = S;
2639 Op->EndLoc = E;
2640 return Op;
2641 }
2642
David Blaikie960ea3f2014-06-08 16:18:35 +00002643 static std::unique_ptr<ARMOperand> CreateShifterImm(bool isASR, unsigned Imm,
2644 SMLoc S, SMLoc E) {
2645 auto Op = make_unique<ARMOperand>(k_ShifterImmediate);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002646 Op->ShifterImm.isASR = isASR;
2647 Op->ShifterImm.Imm = Imm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002648 Op->StartLoc = S;
2649 Op->EndLoc = E;
2650 return Op;
2651 }
2652
David Blaikie960ea3f2014-06-08 16:18:35 +00002653 static std::unique_ptr<ARMOperand> CreateRotImm(unsigned Imm, SMLoc S,
2654 SMLoc E) {
2655 auto Op = make_unique<ARMOperand>(k_RotateImmediate);
Jim Grosbach833b9d32011-07-27 20:15:40 +00002656 Op->RotImm.Imm = Imm;
2657 Op->StartLoc = S;
2658 Op->EndLoc = E;
2659 return Op;
2660 }
2661
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00002662 static std::unique_ptr<ARMOperand> CreateModImm(unsigned Bits, unsigned Rot,
2663 SMLoc S, SMLoc E) {
2664 auto Op = make_unique<ARMOperand>(k_ModifiedImmediate);
2665 Op->ModImm.Bits = Bits;
2666 Op->ModImm.Rot = Rot;
2667 Op->StartLoc = S;
2668 Op->EndLoc = E;
2669 return Op;
2670 }
2671
David Blaikie960ea3f2014-06-08 16:18:35 +00002672 static std::unique_ptr<ARMOperand>
2673 CreateBitfield(unsigned LSB, unsigned Width, SMLoc S, SMLoc E) {
2674 auto Op = make_unique<ARMOperand>(k_BitfieldDescriptor);
Jim Grosbach864b6092011-07-28 21:34:26 +00002675 Op->Bitfield.LSB = LSB;
2676 Op->Bitfield.Width = Width;
2677 Op->StartLoc = S;
2678 Op->EndLoc = E;
2679 return Op;
2680 }
2681
David Blaikie960ea3f2014-06-08 16:18:35 +00002682 static std::unique_ptr<ARMOperand>
2683 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned>> &Regs,
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002684 SMLoc StartLoc, SMLoc EndLoc) {
Chad Rosierfa705ee2013-07-01 20:49:23 +00002685 assert (Regs.size() > 0 && "RegList contains no registers?");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002686 KindTy Kind = k_RegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002687
Chad Rosierfa705ee2013-07-01 20:49:23 +00002688 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002689 Kind = k_DPRRegisterList;
Jim Grosbach75461af2011-09-13 22:56:44 +00002690 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Chad Rosierfa705ee2013-07-01 20:49:23 +00002691 contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002692 Kind = k_SPRRegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002693
Chad Rosierfa705ee2013-07-01 20:49:23 +00002694 // Sort based on the register encoding values.
2695 array_pod_sort(Regs.begin(), Regs.end());
2696
David Blaikie960ea3f2014-06-08 16:18:35 +00002697 auto Op = make_unique<ARMOperand>(Kind);
Chad Rosierfa705ee2013-07-01 20:49:23 +00002698 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002699 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Chad Rosierfa705ee2013-07-01 20:49:23 +00002700 Op->Registers.push_back(I->second);
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002701 Op->StartLoc = StartLoc;
2702 Op->EndLoc = EndLoc;
Bill Wendling7cef4472010-11-06 19:56:04 +00002703 return Op;
2704 }
2705
David Blaikie960ea3f2014-06-08 16:18:35 +00002706 static std::unique_ptr<ARMOperand> CreateVectorList(unsigned RegNum,
2707 unsigned Count,
2708 bool isDoubleSpaced,
2709 SMLoc S, SMLoc E) {
2710 auto Op = make_unique<ARMOperand>(k_VectorList);
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002711 Op->VectorList.RegNum = RegNum;
2712 Op->VectorList.Count = Count;
Jim Grosbach2f50e922011-12-15 21:44:33 +00002713 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002714 Op->StartLoc = S;
2715 Op->EndLoc = E;
2716 return Op;
2717 }
2718
David Blaikie960ea3f2014-06-08 16:18:35 +00002719 static std::unique_ptr<ARMOperand>
2720 CreateVectorListAllLanes(unsigned RegNum, unsigned Count, bool isDoubleSpaced,
2721 SMLoc S, SMLoc E) {
2722 auto Op = make_unique<ARMOperand>(k_VectorListAllLanes);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002723 Op->VectorList.RegNum = RegNum;
2724 Op->VectorList.Count = Count;
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002725 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002726 Op->StartLoc = S;
2727 Op->EndLoc = E;
2728 return Op;
2729 }
2730
David Blaikie960ea3f2014-06-08 16:18:35 +00002731 static std::unique_ptr<ARMOperand>
2732 CreateVectorListIndexed(unsigned RegNum, unsigned Count, unsigned Index,
2733 bool isDoubleSpaced, SMLoc S, SMLoc E) {
2734 auto Op = make_unique<ARMOperand>(k_VectorListIndexed);
Jim Grosbach04945c42011-12-02 00:35:16 +00002735 Op->VectorList.RegNum = RegNum;
2736 Op->VectorList.Count = Count;
2737 Op->VectorList.LaneIndex = Index;
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002738 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach04945c42011-12-02 00:35:16 +00002739 Op->StartLoc = S;
2740 Op->EndLoc = E;
2741 return Op;
2742 }
2743
David Blaikie960ea3f2014-06-08 16:18:35 +00002744 static std::unique_ptr<ARMOperand>
2745 CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E, MCContext &Ctx) {
2746 auto Op = make_unique<ARMOperand>(k_VectorIndex);
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002747 Op->VectorIndex.Val = Idx;
2748 Op->StartLoc = S;
2749 Op->EndLoc = E;
2750 return Op;
2751 }
2752
David Blaikie960ea3f2014-06-08 16:18:35 +00002753 static std::unique_ptr<ARMOperand> CreateImm(const MCExpr *Val, SMLoc S,
2754 SMLoc E) {
2755 auto Op = make_unique<ARMOperand>(k_Immediate);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002756 Op->Imm.Val = Val;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002757 Op->StartLoc = S;
2758 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002759 return Op;
Kevin Enderbyf5079942009-10-13 22:19:02 +00002760 }
2761
David Blaikie960ea3f2014-06-08 16:18:35 +00002762 static std::unique_ptr<ARMOperand>
2763 CreateMem(unsigned BaseRegNum, const MCConstantExpr *OffsetImm,
2764 unsigned OffsetRegNum, ARM_AM::ShiftOpc ShiftType,
2765 unsigned ShiftImm, unsigned Alignment, bool isNegative, SMLoc S,
2766 SMLoc E, SMLoc AlignmentLoc = SMLoc()) {
2767 auto Op = make_unique<ARMOperand>(k_Memory);
Jim Grosbach871dff72011-10-11 15:59:20 +00002768 Op->Memory.BaseRegNum = BaseRegNum;
2769 Op->Memory.OffsetImm = OffsetImm;
2770 Op->Memory.OffsetRegNum = OffsetRegNum;
2771 Op->Memory.ShiftType = ShiftType;
2772 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbacha95ec992011-10-11 17:29:55 +00002773 Op->Memory.Alignment = Alignment;
Jim Grosbach871dff72011-10-11 15:59:20 +00002774 Op->Memory.isNegative = isNegative;
Jim Grosbachd3595712011-08-03 23:50:40 +00002775 Op->StartLoc = S;
2776 Op->EndLoc = E;
Kevin Enderby488f20b2014-04-10 20:18:58 +00002777 Op->AlignmentLoc = AlignmentLoc;
Jim Grosbachd3595712011-08-03 23:50:40 +00002778 return Op;
2779 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00002780
David Blaikie960ea3f2014-06-08 16:18:35 +00002781 static std::unique_ptr<ARMOperand>
2782 CreatePostIdxReg(unsigned RegNum, bool isAdd, ARM_AM::ShiftOpc ShiftTy,
2783 unsigned ShiftImm, SMLoc S, SMLoc E) {
2784 auto Op = make_unique<ARMOperand>(k_PostIndexRegister);
Jim Grosbachd3595712011-08-03 23:50:40 +00002785 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +00002786 Op->PostIdxReg.isAdd = isAdd;
2787 Op->PostIdxReg.ShiftTy = ShiftTy;
2788 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002789 Op->StartLoc = S;
2790 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002791 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002792 }
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002793
David Blaikie960ea3f2014-06-08 16:18:35 +00002794 static std::unique_ptr<ARMOperand> CreateMemBarrierOpt(ARM_MB::MemBOpt Opt,
2795 SMLoc S) {
2796 auto Op = make_unique<ARMOperand>(k_MemBarrierOpt);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002797 Op->MBOpt.Val = Opt;
2798 Op->StartLoc = S;
2799 Op->EndLoc = S;
2800 return Op;
2801 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002802
David Blaikie960ea3f2014-06-08 16:18:35 +00002803 static std::unique_ptr<ARMOperand>
2804 CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt, SMLoc S) {
2805 auto Op = make_unique<ARMOperand>(k_InstSyncBarrierOpt);
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002806 Op->ISBOpt.Val = Opt;
2807 Op->StartLoc = S;
2808 Op->EndLoc = S;
2809 return Op;
2810 }
2811
David Blaikie960ea3f2014-06-08 16:18:35 +00002812 static std::unique_ptr<ARMOperand> CreateProcIFlags(ARM_PROC::IFlags IFlags,
2813 SMLoc S) {
2814 auto Op = make_unique<ARMOperand>(k_ProcIFlags);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002815 Op->IFlags.Val = IFlags;
2816 Op->StartLoc = S;
2817 Op->EndLoc = S;
2818 return Op;
2819 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002820
David Blaikie960ea3f2014-06-08 16:18:35 +00002821 static std::unique_ptr<ARMOperand> CreateMSRMask(unsigned MMask, SMLoc S) {
2822 auto Op = make_unique<ARMOperand>(k_MSRMask);
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002823 Op->MMask.Val = MMask;
2824 Op->StartLoc = S;
2825 Op->EndLoc = S;
2826 return Op;
2827 }
Tim Northoveree843ef2014-08-15 10:47:12 +00002828
2829 static std::unique_ptr<ARMOperand> CreateBankedReg(unsigned Reg, SMLoc S) {
2830 auto Op = make_unique<ARMOperand>(k_BankedReg);
2831 Op->BankedReg.Val = Reg;
2832 Op->StartLoc = S;
2833 Op->EndLoc = S;
2834 return Op;
2835 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002836};
2837
2838} // end anonymous namespace.
2839
Jim Grosbach602aa902011-07-13 15:34:57 +00002840void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002841 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002842 case k_CondCode:
Daniel Dunbar2be732a2011-01-10 15:26:21 +00002843 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002844 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002845 case k_CCOut:
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002846 OS << "<ccout " << getReg() << ">";
2847 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002848 case k_ITCondMask: {
Craig Topper42b96d12012-05-24 04:11:15 +00002849 static const char *const MaskStr[] = {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002850 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2851 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2852 };
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002853 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2854 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2855 break;
2856 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002857 case k_CoprocNum:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002858 OS << "<coprocessor number: " << getCoproc() << ">";
2859 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002860 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002861 OS << "<coprocessor register: " << getCoproc() << ">";
2862 break;
Jim Grosbach48399582011-10-12 17:34:41 +00002863 case k_CoprocOption:
2864 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2865 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002866 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002867 OS << "<mask: " << getMSRMask() << ">";
2868 break;
Tim Northoveree843ef2014-08-15 10:47:12 +00002869 case k_BankedReg:
2870 OS << "<banked reg: " << getBankedReg() << ">";
2871 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002872 case k_Immediate:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002873 getImm()->print(OS);
2874 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002875 case k_MemBarrierOpt:
Joey Gouly926d3f52013-09-05 15:35:24 +00002876 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">";
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002877 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002878 case k_InstSyncBarrierOpt:
2879 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2880 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002881 case k_Memory:
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002882 OS << "<memory "
Jim Grosbach871dff72011-10-11 15:59:20 +00002883 << " base:" << Memory.BaseRegNum;
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002884 OS << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002885 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002886 case k_PostIndexRegister:
Jim Grosbachc320c852011-08-05 21:28:30 +00002887 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2888 << PostIdxReg.RegNum;
2889 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2890 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2891 << PostIdxReg.ShiftImm;
2892 OS << ">";
Jim Grosbachd3595712011-08-03 23:50:40 +00002893 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002894 case k_ProcIFlags: {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002895 OS << "<ARM_PROC::";
2896 unsigned IFlags = getProcIFlags();
2897 for (int i=2; i >= 0; --i)
2898 if (IFlags & (1 << i))
2899 OS << ARM_PROC::IFlagsToString(1 << i);
2900 OS << ">";
2901 break;
2902 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002903 case k_Register:
Bill Wendling2063b842010-11-18 23:43:05 +00002904 OS << "<register " << getReg() << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002905 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002906 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002907 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2908 << " #" << ShifterImm.Imm << ">";
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002909 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002910 case k_ShiftedRegister:
Owen Andersonb595ed02011-07-21 18:54:16 +00002911 OS << "<so_reg_reg "
Jim Grosbach01e04392011-11-16 21:46:50 +00002912 << RegShiftedReg.SrcReg << " "
2913 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2914 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002915 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002916 case k_ShiftedImmediate:
Owen Andersonb595ed02011-07-21 18:54:16 +00002917 OS << "<so_reg_imm "
Jim Grosbach01e04392011-11-16 21:46:50 +00002918 << RegShiftedImm.SrcReg << " "
2919 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2920 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Andersonb595ed02011-07-21 18:54:16 +00002921 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002922 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +00002923 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2924 break;
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00002925 case k_ModifiedImmediate:
2926 OS << "<mod_imm #" << ModImm.Bits << ", #"
2927 << ModImm.Rot << ")>";
2928 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002929 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +00002930 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2931 << ", width: " << Bitfield.Width << ">";
2932 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002933 case k_RegisterList:
2934 case k_DPRRegisterList:
2935 case k_SPRRegisterList: {
Bill Wendling7cef4472010-11-06 19:56:04 +00002936 OS << "<register_list ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002937
Bill Wendlingbed94652010-11-09 23:28:44 +00002938 const SmallVectorImpl<unsigned> &RegList = getRegList();
2939 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002940 I = RegList.begin(), E = RegList.end(); I != E; ) {
2941 OS << *I;
2942 if (++I < E) OS << ", ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002943 }
2944
2945 OS << ">";
2946 break;
2947 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002948 case k_VectorList:
2949 OS << "<vector_list " << VectorList.Count << " * "
2950 << VectorList.RegNum << ">";
2951 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002952 case k_VectorListAllLanes:
2953 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2954 << VectorList.RegNum << ">";
2955 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00002956 case k_VectorListIndexed:
2957 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2958 << VectorList.Count << " * " << VectorList.RegNum << ">";
2959 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002960 case k_Token:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002961 OS << "'" << getToken() << "'";
2962 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002963 case k_VectorIndex:
2964 OS << "<vectorindex " << getVectorIndex() << ">";
2965 break;
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002966 }
2967}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002968
2969/// @name Auto-generated Match Functions
2970/// {
2971
2972static unsigned MatchRegisterName(StringRef Name);
2973
2974/// }
2975
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002976bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2977 SMLoc &StartLoc, SMLoc &EndLoc) {
Rafael Espindola961d4692014-11-11 05:18:41 +00002978 const AsmToken &Tok = getParser().getTok();
2979 StartLoc = Tok.getLoc();
2980 EndLoc = Tok.getEndLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002981 RegNo = tryParseRegister();
Roman Divacky36b1b472011-01-27 17:14:22 +00002982
2983 return (RegNo == (unsigned)-1);
2984}
2985
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002986/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattner44e5981c2010-10-30 04:09:10 +00002987/// and if it is a register name the token is eaten and the register number is
2988/// returned. Otherwise return -1.
2989///
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002990int ARMAsmParser::tryParseRegister() {
Rafael Espindola961d4692014-11-11 05:18:41 +00002991 MCAsmParser &Parser = getParser();
Chris Lattner44e5981c2010-10-30 04:09:10 +00002992 const AsmToken &Tok = Parser.getTok();
Jim Grosbachd3595712011-08-03 23:50:40 +00002993 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbach99710a82010-11-01 16:44:21 +00002994
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002995 std::string lowerCase = Tok.getString().lower();
Owen Andersona098d152011-01-13 22:50:36 +00002996 unsigned RegNum = MatchRegisterName(lowerCase);
2997 if (!RegNum) {
2998 RegNum = StringSwitch<unsigned>(lowerCase)
2999 .Case("r13", ARM::SP)
3000 .Case("r14", ARM::LR)
3001 .Case("r15", ARM::PC)
3002 .Case("ip", ARM::R12)
Jim Grosbach4edc7362011-12-08 19:27:38 +00003003 // Additional register name aliases for 'gas' compatibility.
3004 .Case("a1", ARM::R0)
3005 .Case("a2", ARM::R1)
3006 .Case("a3", ARM::R2)
3007 .Case("a4", ARM::R3)
3008 .Case("v1", ARM::R4)
3009 .Case("v2", ARM::R5)
3010 .Case("v3", ARM::R6)
3011 .Case("v4", ARM::R7)
3012 .Case("v5", ARM::R8)
3013 .Case("v6", ARM::R9)
3014 .Case("v7", ARM::R10)
3015 .Case("v8", ARM::R11)
3016 .Case("sb", ARM::R9)
3017 .Case("sl", ARM::R10)
3018 .Case("fp", ARM::R11)
Owen Andersona098d152011-01-13 22:50:36 +00003019 .Default(0);
3020 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00003021 if (!RegNum) {
Jim Grosbachcd22e4a2011-12-20 23:11:00 +00003022 // Check for aliases registered via .req. Canonicalize to lower case.
3023 // That's more consistent since register names are case insensitive, and
3024 // it's how the original entry was passed in from MC/MCParser/AsmParser.
3025 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbachab5830e2011-12-14 02:16:11 +00003026 // If no match, return failure.
3027 if (Entry == RegisterReqs.end())
3028 return -1;
3029 Parser.Lex(); // Eat identifier token.
3030 return Entry->getValue();
3031 }
Bob Wilsonfb0bd042011-02-03 21:46:10 +00003032
Oliver Stannard9e89d8c2014-11-05 12:06:39 +00003033 // Some FPUs only have 16 D registers, so D16-D31 are invalid
3034 if (hasD16() && RegNum >= ARM::D16 && RegNum <= ARM::D31)
3035 return -1;
3036
Chris Lattner44e5981c2010-10-30 04:09:10 +00003037 Parser.Lex(); // Eat identifier token.
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003038
Chris Lattner44e5981c2010-10-30 04:09:10 +00003039 return RegNum;
3040}
Jim Grosbach99710a82010-11-01 16:44:21 +00003041
Jim Grosbachbb24c592011-07-13 18:49:30 +00003042// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
3043// If a recoverable error occurs, return 1. If an irrecoverable error
3044// occurs, return -1. An irrecoverable error is one where tokens have been
3045// consumed in the process of trying to parse the shifter (i.e., when it is
3046// indeed a shifter operand, but malformed).
David Blaikie960ea3f2014-06-08 16:18:35 +00003047int ARMAsmParser::tryParseShiftRegister(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003048 MCAsmParser &Parser = getParser();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003049 SMLoc S = Parser.getTok().getLoc();
3050 const AsmToken &Tok = Parser.getTok();
Kevin Enderby62873712014-02-17 21:45:27 +00003051 if (Tok.isNot(AsmToken::Identifier))
3052 return -1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003053
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003054 std::string lowerCase = Tok.getString().lower();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003055 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbach3b559ff2011-12-07 23:40:58 +00003056 .Case("asl", ARM_AM::lsl)
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003057 .Case("lsl", ARM_AM::lsl)
3058 .Case("lsr", ARM_AM::lsr)
3059 .Case("asr", ARM_AM::asr)
3060 .Case("ror", ARM_AM::ror)
3061 .Case("rrx", ARM_AM::rrx)
3062 .Default(ARM_AM::no_shift);
3063
3064 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbachbb24c592011-07-13 18:49:30 +00003065 return 1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003066
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003067 Parser.Lex(); // Eat the operator.
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003068
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003069 // The source register for the shift has already been added to the
3070 // operand list, so we need to pop it off and combine it into the shifted
3071 // register operand instead.
David Blaikie960ea3f2014-06-08 16:18:35 +00003072 std::unique_ptr<ARMOperand> PrevOp(
3073 (ARMOperand *)Operands.pop_back_val().release());
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003074 if (!PrevOp->isReg())
3075 return Error(PrevOp->getStartLoc(), "shift must be of a register");
3076 int SrcReg = PrevOp->getReg();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003077
3078 SMLoc EndLoc;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003079 int64_t Imm = 0;
3080 int ShiftReg = 0;
3081 if (ShiftTy == ARM_AM::rrx) {
3082 // RRX Doesn't have an explicit shift amount. The encoder expects
3083 // the shift register to be the same as the source register. Seems odd,
3084 // but OK.
3085 ShiftReg = SrcReg;
3086 } else {
3087 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003088 if (Parser.getTok().is(AsmToken::Hash) ||
3089 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003090 Parser.Lex(); // Eat hash.
3091 SMLoc ImmLoc = Parser.getTok().getLoc();
Craig Topper062a2ba2014-04-25 05:30:21 +00003092 const MCExpr *ShiftExpr = nullptr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003093 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00003094 Error(ImmLoc, "invalid immediate shift value");
3095 return -1;
3096 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003097 // The expression must be evaluatable as an immediate.
3098 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbachbb24c592011-07-13 18:49:30 +00003099 if (!CE) {
3100 Error(ImmLoc, "invalid immediate shift value");
3101 return -1;
3102 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003103 // Range check the immediate.
3104 // lsl, ror: 0 <= imm <= 31
3105 // lsr, asr: 0 <= imm <= 32
3106 Imm = CE->getValue();
3107 if (Imm < 0 ||
3108 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
3109 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00003110 Error(ImmLoc, "immediate shift value out of range");
3111 return -1;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003112 }
Jim Grosbach21488b82011-12-22 17:37:00 +00003113 // shift by zero is a nop. Always send it through as lsl.
3114 // ('as' compatibility)
3115 if (Imm == 0)
3116 ShiftTy = ARM_AM::lsl;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003117 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003118 SMLoc L = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003119 EndLoc = Parser.getTok().getEndLoc();
3120 ShiftReg = tryParseRegister();
Jim Grosbachbb24c592011-07-13 18:49:30 +00003121 if (ShiftReg == -1) {
Saleem Abdulrasool6d11b7c2014-05-17 21:49:54 +00003122 Error(L, "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00003123 return -1;
3124 }
3125 } else {
Saleem Abdulrasool6d11b7c2014-05-17 21:49:54 +00003126 Error(Parser.getTok().getLoc(),
3127 "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00003128 return -1;
3129 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00003130 }
3131
Owen Andersonb595ed02011-07-21 18:54:16 +00003132 if (ShiftReg && ShiftTy != ARM_AM::rrx)
3133 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachac798e12011-07-25 20:49:51 +00003134 ShiftReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003135 S, EndLoc));
Owen Andersonb595ed02011-07-21 18:54:16 +00003136 else
3137 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003138 S, EndLoc));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003139
Jim Grosbachbb24c592011-07-13 18:49:30 +00003140 return 0;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00003141}
3142
3143
Bill Wendling2063b842010-11-18 23:43:05 +00003144/// Try to parse a register name. The token must be an Identifier when called.
3145/// If it's a register, an AsmOperand is created. Another AsmOperand is created
3146/// if there is a "writeback". 'true' if it's not a register.
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00003147///
Kevin Enderby8be42bd2009-10-30 22:55:57 +00003148/// TODO this is likely to change to allow different register types and or to
3149/// parse for a specific register type.
David Blaikie960ea3f2014-06-08 16:18:35 +00003150bool ARMAsmParser::tryParseRegisterWithWriteBack(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003151 MCAsmParser &Parser = getParser();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003152 const AsmToken &RegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003153 int RegNo = tryParseRegister();
Bill Wendlinge18980a2010-11-06 22:36:58 +00003154 if (RegNo == -1)
Bill Wendling2063b842010-11-18 23:43:05 +00003155 return true;
Jim Grosbach99710a82010-11-01 16:44:21 +00003156
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003157 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
3158 RegTok.getEndLoc()));
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00003159
Chris Lattner44e5981c2010-10-30 04:09:10 +00003160 const AsmToken &ExclaimTok = Parser.getTok();
3161 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling2063b842010-11-18 23:43:05 +00003162 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
3163 ExclaimTok.getLoc()));
Chris Lattner44e5981c2010-10-30 04:09:10 +00003164 Parser.Lex(); // Eat exclaim token
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003165 return false;
3166 }
3167
3168 // Also check for an index operand. This is only legal for vector registers,
3169 // but that'll get caught OK in operand matching, so we don't need to
3170 // explicitly filter everything else out here.
3171 if (Parser.getTok().is(AsmToken::LBrac)) {
3172 SMLoc SIdx = Parser.getTok().getLoc();
3173 Parser.Lex(); // Eat left bracket token.
3174
3175 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003176 if (getParser().parseExpression(ImmVal))
Jim Grosbacha2147ce2012-01-31 23:51:09 +00003177 return true;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003178 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachc8f2b782012-01-26 15:56:45 +00003179 if (!MCE)
3180 return TokError("immediate value expected for vector index");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003181
Jim Grosbachc8f2b782012-01-26 15:56:45 +00003182 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003183 return Error(Parser.getTok().getLoc(), "']' expected");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003184
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003185 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbachd0637bf2011-10-07 23:56:00 +00003186 Parser.Lex(); // Eat right bracket token.
3187
3188 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
3189 SIdx, E,
3190 getContext()));
Kevin Enderby2207e5f2009-10-07 18:01:35 +00003191 }
3192
Bill Wendling2063b842010-11-18 23:43:05 +00003193 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00003194}
3195
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003196/// MatchCoprocessorOperandName - Try to parse an coprocessor related
Renato Golinac561c32014-06-26 13:10:53 +00003197/// instruction with a symbolic operand name.
3198/// We accept "crN" syntax for GAS compatibility.
3199/// <operand-name> ::= <prefix><number>
3200/// If CoprocOp is 'c', then:
3201/// <prefix> ::= c | cr
3202/// If CoprocOp is 'p', then :
3203/// <prefix> ::= p
3204/// <number> ::= integer in range [0, 15]
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003205static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003206 // Use the same layout as the tablegen'erated register name matcher. Ugly,
3207 // but efficient.
Renato Golinac561c32014-06-26 13:10:53 +00003208 if (Name.size() < 2 || Name[0] != CoprocOp)
3209 return -1;
3210 Name = (Name[1] == 'r') ? Name.drop_front(2) : Name.drop_front();
3211
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003212 switch (Name.size()) {
David Blaikie46a9f012012-01-20 21:51:11 +00003213 default: return -1;
Renato Golinac561c32014-06-26 13:10:53 +00003214 case 1:
3215 switch (Name[0]) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003216 default: return -1;
3217 case '0': return 0;
3218 case '1': return 1;
3219 case '2': return 2;
3220 case '3': return 3;
3221 case '4': return 4;
3222 case '5': return 5;
3223 case '6': return 6;
3224 case '7': return 7;
3225 case '8': return 8;
3226 case '9': return 9;
3227 }
Renato Golinac561c32014-06-26 13:10:53 +00003228 case 2:
3229 if (Name[0] != '1')
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003230 return -1;
Renato Golinac561c32014-06-26 13:10:53 +00003231 switch (Name[1]) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003232 default: return -1;
Renato Golinbc0b0372014-08-04 23:21:56 +00003233 // CP10 and CP11 are VFP/NEON and so vector instructions should be used.
3234 // However, old cores (v5/v6) did use them in that way.
3235 case '0': return 10;
3236 case '1': return 11;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003237 case '2': return 12;
3238 case '3': return 13;
3239 case '4': return 14;
3240 case '5': return 15;
3241 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003242 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003243}
3244
Jim Grosbach3d1eac82011-08-26 21:43:41 +00003245/// parseITCondCode - Try to parse a condition code for an IT instruction.
David Blaikie960ea3f2014-06-08 16:18:35 +00003246ARMAsmParser::OperandMatchResultTy
3247ARMAsmParser::parseITCondCode(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003248 MCAsmParser &Parser = getParser();
Jim Grosbach3d1eac82011-08-26 21:43:41 +00003249 SMLoc S = Parser.getTok().getLoc();
3250 const AsmToken &Tok = Parser.getTok();
3251 if (!Tok.is(AsmToken::Identifier))
3252 return MatchOperand_NoMatch;
Richard Barton82f95ea2012-04-27 17:34:01 +00003253 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach3d1eac82011-08-26 21:43:41 +00003254 .Case("eq", ARMCC::EQ)
3255 .Case("ne", ARMCC::NE)
3256 .Case("hs", ARMCC::HS)
3257 .Case("cs", ARMCC::HS)
3258 .Case("lo", ARMCC::LO)
3259 .Case("cc", ARMCC::LO)
3260 .Case("mi", ARMCC::MI)
3261 .Case("pl", ARMCC::PL)
3262 .Case("vs", ARMCC::VS)
3263 .Case("vc", ARMCC::VC)
3264 .Case("hi", ARMCC::HI)
3265 .Case("ls", ARMCC::LS)
3266 .Case("ge", ARMCC::GE)
3267 .Case("lt", ARMCC::LT)
3268 .Case("gt", ARMCC::GT)
3269 .Case("le", ARMCC::LE)
3270 .Case("al", ARMCC::AL)
3271 .Default(~0U);
3272 if (CC == ~0U)
3273 return MatchOperand_NoMatch;
3274 Parser.Lex(); // Eat the token.
3275
3276 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
3277
3278 return MatchOperand_Success;
3279}
3280
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003281/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003282/// token must be an Identifier when called, and if it is a coprocessor
3283/// number, the token is eaten and the operand is added to the operand list.
David Blaikie960ea3f2014-06-08 16:18:35 +00003284ARMAsmParser::OperandMatchResultTy
3285ARMAsmParser::parseCoprocNumOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003286 MCAsmParser &Parser = getParser();
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003287 SMLoc S = Parser.getTok().getLoc();
3288 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00003289 if (Tok.isNot(AsmToken::Identifier))
3290 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003291
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003292 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003293 if (Num == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00003294 return MatchOperand_NoMatch;
Renato Golinbc0b0372014-08-04 23:21:56 +00003295 // ARMv7 and v8 don't allow cp10/cp11 due to VFP/NEON specific instructions
3296 if ((hasV7Ops() || hasV8Ops()) && (Num == 10 || Num == 11))
3297 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003298
3299 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003300 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003301 return MatchOperand_Success;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003302}
3303
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003304/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003305/// token must be an Identifier when called, and if it is a coprocessor
3306/// number, the token is eaten and the operand is added to the operand list.
David Blaikie960ea3f2014-06-08 16:18:35 +00003307ARMAsmParser::OperandMatchResultTy
3308ARMAsmParser::parseCoprocRegOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003309 MCAsmParser &Parser = getParser();
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003310 SMLoc S = Parser.getTok().getLoc();
3311 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00003312 if (Tok.isNot(AsmToken::Identifier))
3313 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003314
3315 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
3316 if (Reg == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00003317 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003318
3319 Parser.Lex(); // Eat identifier token.
3320 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003321 return MatchOperand_Success;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003322}
3323
Jim Grosbach48399582011-10-12 17:34:41 +00003324/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
3325/// coproc_option : '{' imm0_255 '}'
David Blaikie960ea3f2014-06-08 16:18:35 +00003326ARMAsmParser::OperandMatchResultTy
3327ARMAsmParser::parseCoprocOptionOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003328 MCAsmParser &Parser = getParser();
Jim Grosbach48399582011-10-12 17:34:41 +00003329 SMLoc S = Parser.getTok().getLoc();
3330
3331 // If this isn't a '{', this isn't a coprocessor immediate operand.
3332 if (Parser.getTok().isNot(AsmToken::LCurly))
3333 return MatchOperand_NoMatch;
3334 Parser.Lex(); // Eat the '{'
3335
3336 const MCExpr *Expr;
3337 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003338 if (getParser().parseExpression(Expr)) {
Jim Grosbach48399582011-10-12 17:34:41 +00003339 Error(Loc, "illegal expression");
3340 return MatchOperand_ParseFail;
3341 }
3342 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
3343 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
3344 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
3345 return MatchOperand_ParseFail;
3346 }
3347 int Val = CE->getValue();
3348
3349 // Check for and consume the closing '}'
3350 if (Parser.getTok().isNot(AsmToken::RCurly))
3351 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003352 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach48399582011-10-12 17:34:41 +00003353 Parser.Lex(); // Eat the '}'
3354
3355 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
3356 return MatchOperand_Success;
3357}
3358
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003359// For register list parsing, we need to map from raw GPR register numbering
3360// to the enumeration values. The enumeration values aren't sorted by
3361// register number due to our using "sp", "lr" and "pc" as canonical names.
3362static unsigned getNextRegister(unsigned Reg) {
3363 // If this is a GPR, we need to do it manually, otherwise we can rely
3364 // on the sort ordering of the enumeration since the other reg-classes
3365 // are sane.
3366 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3367 return Reg + 1;
3368 switch(Reg) {
Craig Toppere55c5562012-02-07 02:50:20 +00003369 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003370 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
3371 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
3372 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
3373 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
3374 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
3375 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
3376 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
3377 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
3378 }
3379}
3380
Jim Grosbach85a23432011-11-11 21:27:40 +00003381// Return the low-subreg of a given Q register.
3382static unsigned getDRegFromQReg(unsigned QReg) {
3383 switch (QReg) {
3384 default: llvm_unreachable("expected a Q register!");
3385 case ARM::Q0: return ARM::D0;
3386 case ARM::Q1: return ARM::D2;
3387 case ARM::Q2: return ARM::D4;
3388 case ARM::Q3: return ARM::D6;
3389 case ARM::Q4: return ARM::D8;
3390 case ARM::Q5: return ARM::D10;
3391 case ARM::Q6: return ARM::D12;
3392 case ARM::Q7: return ARM::D14;
3393 case ARM::Q8: return ARM::D16;
Jim Grosbacha92a5d82011-11-15 21:01:30 +00003394 case ARM::Q9: return ARM::D18;
Jim Grosbach85a23432011-11-11 21:27:40 +00003395 case ARM::Q10: return ARM::D20;
3396 case ARM::Q11: return ARM::D22;
3397 case ARM::Q12: return ARM::D24;
3398 case ARM::Q13: return ARM::D26;
3399 case ARM::Q14: return ARM::D28;
3400 case ARM::Q15: return ARM::D30;
3401 }
3402}
3403
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003404/// Parse a register list.
David Blaikie960ea3f2014-06-08 16:18:35 +00003405bool ARMAsmParser::parseRegisterList(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003406 MCAsmParser &Parser = getParser();
Sean Callanan936b0d32010-01-19 21:44:56 +00003407 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00003408 "Token is not a Left Curly Brace");
Bill Wendlinge18980a2010-11-06 22:36:58 +00003409 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003410 Parser.Lex(); // Eat '{' token.
3411 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbya2b99102009-10-09 21:12:28 +00003412
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003413 // Check the first register in the list to see what register class
3414 // this is a list of.
3415 int Reg = tryParseRegister();
3416 if (Reg == -1)
3417 return Error(RegLoc, "register expected");
3418
Jim Grosbach85a23432011-11-11 21:27:40 +00003419 // The reglist instructions have at most 16 registers, so reserve
3420 // space for that many.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003421 int EReg = 0;
3422 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
Jim Grosbach85a23432011-11-11 21:27:40 +00003423
3424 // Allow Q regs and just interpret them as the two D sub-registers.
3425 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3426 Reg = getDRegFromQReg(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003427 EReg = MRI->getEncodingValue(Reg);
3428 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach85a23432011-11-11 21:27:40 +00003429 ++Reg;
3430 }
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00003431 const MCRegisterClass *RC;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003432 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3433 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3434 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3435 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3436 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3437 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3438 else
3439 return Error(RegLoc, "invalid register in register list");
3440
Jim Grosbach85a23432011-11-11 21:27:40 +00003441 // Store the register.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003442 EReg = MRI->getEncodingValue(Reg);
3443 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Kevin Enderbya2b99102009-10-09 21:12:28 +00003444
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003445 // This starts immediately after the first register token in the list,
3446 // so we can see either a comma or a minus (range separator) as a legal
3447 // next token.
3448 while (Parser.getTok().is(AsmToken::Comma) ||
3449 Parser.getTok().is(AsmToken::Minus)) {
3450 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache891fe82011-11-15 23:19:15 +00003451 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003452 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003453 int EndReg = tryParseRegister();
3454 if (EndReg == -1)
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003455 return Error(AfterMinusLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003456 // Allow Q regs and just interpret them as the two D sub-registers.
3457 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3458 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003459 // If the register is the same as the start reg, there's nothing
3460 // more to do.
3461 if (Reg == EndReg)
3462 continue;
3463 // The register must be in the same register class as the first.
3464 if (!RC->contains(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003465 return Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003466 // Ranges must go from low to high.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003467 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003468 return Error(AfterMinusLoc, "bad range in register list");
Kevin Enderbya2b99102009-10-09 21:12:28 +00003469
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003470 // Add all the registers in the range to the register list.
3471 while (Reg != EndReg) {
3472 Reg = getNextRegister(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003473 EReg = MRI->getEncodingValue(Reg);
3474 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003475 }
3476 continue;
3477 }
3478 Parser.Lex(); // Eat the comma.
3479 RegLoc = Parser.getTok().getLoc();
3480 int OldReg = Reg;
Jim Grosbach98bc7972011-12-08 21:34:20 +00003481 const AsmToken RegTok = Parser.getTok();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003482 Reg = tryParseRegister();
3483 if (Reg == -1)
Jim Grosbach3337e392011-09-12 23:36:42 +00003484 return Error(RegLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003485 // Allow Q regs and just interpret them as the two D sub-registers.
3486 bool isQReg = false;
3487 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3488 Reg = getDRegFromQReg(Reg);
3489 isQReg = true;
3490 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003491 // The register must be in the same register class as the first.
3492 if (!RC->contains(Reg))
3493 return Error(RegLoc, "invalid register in register list");
3494 // List must be monotonically increasing.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003495 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbach905686a2012-03-16 20:48:38 +00003496 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3497 Warning(RegLoc, "register list not in ascending order");
3498 else
3499 return Error(RegLoc, "register list not in ascending order");
3500 }
Eric Christopher6ac277c2012-08-09 22:10:21 +00003501 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbach98bc7972011-12-08 21:34:20 +00003502 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3503 ") in register list");
3504 continue;
3505 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003506 // VFP register lists must also be contiguous.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003507 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3508 Reg != OldReg + 1)
3509 return Error(RegLoc, "non-contiguous register range");
Chad Rosierfa705ee2013-07-01 20:49:23 +00003510 EReg = MRI->getEncodingValue(Reg);
3511 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3512 if (isQReg) {
3513 EReg = MRI->getEncodingValue(++Reg);
3514 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3515 }
Bill Wendlinge18980a2010-11-06 22:36:58 +00003516 }
3517
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003518 if (Parser.getTok().isNot(AsmToken::RCurly))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003519 return Error(Parser.getTok().getLoc(), "'}' expected");
3520 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003521 Parser.Lex(); // Eat '}' token.
3522
Jim Grosbach18bf3632011-12-13 21:48:29 +00003523 // Push the register list operand.
Bill Wendling2063b842010-11-18 23:43:05 +00003524 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach18bf3632011-12-13 21:48:29 +00003525
3526 // The ARM system instruction variants for LDM/STM have a '^' token here.
3527 if (Parser.getTok().is(AsmToken::Caret)) {
3528 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3529 Parser.Lex(); // Eat '^' token.
3530 }
3531
Bill Wendling2063b842010-11-18 23:43:05 +00003532 return false;
Kevin Enderbya2b99102009-10-09 21:12:28 +00003533}
3534
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003535// Helper function to parse the lane index for vector lists.
3536ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003537parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003538 MCAsmParser &Parser = getParser();
Jim Grosbach04945c42011-12-02 00:35:16 +00003539 Index = 0; // Always return a defined index value.
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003540 if (Parser.getTok().is(AsmToken::LBrac)) {
3541 Parser.Lex(); // Eat the '['.
3542 if (Parser.getTok().is(AsmToken::RBrac)) {
3543 // "Dn[]" is the 'all lanes' syntax.
3544 LaneKind = AllLanes;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003545 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003546 Parser.Lex(); // Eat the ']'.
3547 return MatchOperand_Success;
3548 }
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003549
3550 // There's an optional '#' token here. Normally there wouldn't be, but
3551 // inline assemble puts one in, and it's friendly to accept that.
3552 if (Parser.getTok().is(AsmToken::Hash))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003553 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003554
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003555 const MCExpr *LaneIndex;
3556 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003557 if (getParser().parseExpression(LaneIndex)) {
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003558 Error(Loc, "illegal expression");
3559 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003560 }
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003561 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3562 if (!CE) {
3563 Error(Loc, "lane index must be empty or an integer");
3564 return MatchOperand_ParseFail;
3565 }
3566 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3567 Error(Parser.getTok().getLoc(), "']' expected");
3568 return MatchOperand_ParseFail;
3569 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003570 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003571 Parser.Lex(); // Eat the ']'.
3572 int64_t Val = CE->getValue();
3573
3574 // FIXME: Make this range check context sensitive for .8, .16, .32.
3575 if (Val < 0 || Val > 7) {
3576 Error(Parser.getTok().getLoc(), "lane index out of range");
3577 return MatchOperand_ParseFail;
3578 }
3579 Index = Val;
3580 LaneKind = IndexedLane;
3581 return MatchOperand_Success;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003582 }
3583 LaneKind = NoLanes;
3584 return MatchOperand_Success;
3585}
3586
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003587// parse a vector register list
David Blaikie960ea3f2014-06-08 16:18:35 +00003588ARMAsmParser::OperandMatchResultTy
3589ARMAsmParser::parseVectorList(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003590 MCAsmParser &Parser = getParser();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003591 VectorLaneTy LaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003592 unsigned LaneIndex;
Jim Grosbach8d579232011-11-15 21:45:55 +00003593 SMLoc S = Parser.getTok().getLoc();
3594 // As an extension (to match gas), support a plain D register or Q register
3595 // (without encosing curly braces) as a single or double entry list,
3596 // respectively.
3597 if (Parser.getTok().is(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003598 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach8d579232011-11-15 21:45:55 +00003599 int Reg = tryParseRegister();
3600 if (Reg == -1)
3601 return MatchOperand_NoMatch;
Jim Grosbach8d579232011-11-15 21:45:55 +00003602 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003603 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003604 if (Res != MatchOperand_Success)
3605 return Res;
3606 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003607 case NoLanes:
Jim Grosbach2f50e922011-12-15 21:44:33 +00003608 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003609 break;
3610 case AllLanes:
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003611 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3612 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003613 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003614 case IndexedLane:
3615 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003616 LaneIndex,
3617 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003618 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003619 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003620 return MatchOperand_Success;
3621 }
3622 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3623 Reg = getDRegFromQReg(Reg);
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003624 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003625 if (Res != MatchOperand_Success)
3626 return Res;
3627 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003628 case NoLanes:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003629 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbach13a292c2012-03-06 22:01:44 +00003630 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003631 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003632 break;
3633 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003634 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3635 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003636 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3637 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003638 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003639 case IndexedLane:
3640 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003641 LaneIndex,
3642 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003643 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003644 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003645 return MatchOperand_Success;
3646 }
3647 Error(S, "vector register expected");
3648 return MatchOperand_ParseFail;
3649 }
3650
3651 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003652 return MatchOperand_NoMatch;
3653
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003654 Parser.Lex(); // Eat '{' token.
3655 SMLoc RegLoc = Parser.getTok().getLoc();
3656
3657 int Reg = tryParseRegister();
3658 if (Reg == -1) {
3659 Error(RegLoc, "register expected");
3660 return MatchOperand_ParseFail;
3661 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003662 unsigned Count = 1;
Jim Grosbachc2f16a32011-12-15 21:54:55 +00003663 int Spacing = 0;
Jim Grosbach080a4992011-10-28 00:06:50 +00003664 unsigned FirstReg = Reg;
3665 // The list is of D registers, but we also allow Q regs and just interpret
3666 // them as the two D sub-registers.
3667 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3668 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003669 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3670 // it's ambiguous with four-register single spaced.
Jim Grosbach080a4992011-10-28 00:06:50 +00003671 ++Reg;
3672 ++Count;
3673 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003674
3675 SMLoc E;
3676 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003677 return MatchOperand_ParseFail;
Jim Grosbach080a4992011-10-28 00:06:50 +00003678
Jim Grosbache891fe82011-11-15 23:19:15 +00003679 while (Parser.getTok().is(AsmToken::Comma) ||
3680 Parser.getTok().is(AsmToken::Minus)) {
3681 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003682 if (!Spacing)
3683 Spacing = 1; // Register range implies a single spaced list.
3684 else if (Spacing == 2) {
3685 Error(Parser.getTok().getLoc(),
3686 "sequential registers in double spaced list");
3687 return MatchOperand_ParseFail;
3688 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003689 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003690 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbache891fe82011-11-15 23:19:15 +00003691 int EndReg = tryParseRegister();
3692 if (EndReg == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003693 Error(AfterMinusLoc, "register expected");
Jim Grosbache891fe82011-11-15 23:19:15 +00003694 return MatchOperand_ParseFail;
3695 }
3696 // Allow Q regs and just interpret them as the two D sub-registers.
3697 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3698 EndReg = getDRegFromQReg(EndReg) + 1;
3699 // If the register is the same as the start reg, there's nothing
3700 // more to do.
3701 if (Reg == EndReg)
3702 continue;
3703 // The register must be in the same register class as the first.
3704 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003705 Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003706 return MatchOperand_ParseFail;
3707 }
3708 // Ranges must go from low to high.
3709 if (Reg > EndReg) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003710 Error(AfterMinusLoc, "bad range in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003711 return MatchOperand_ParseFail;
3712 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003713 // Parse the lane specifier if present.
3714 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003715 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003716 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3717 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003718 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003719 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003720 Error(AfterMinusLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003721 return MatchOperand_ParseFail;
3722 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003723
3724 // Add all the registers in the range to the register list.
3725 Count += EndReg - Reg;
3726 Reg = EndReg;
3727 continue;
3728 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003729 Parser.Lex(); // Eat the comma.
3730 RegLoc = Parser.getTok().getLoc();
3731 int OldReg = Reg;
3732 Reg = tryParseRegister();
3733 if (Reg == -1) {
3734 Error(RegLoc, "register expected");
3735 return MatchOperand_ParseFail;
3736 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003737 // vector register lists must be contiguous.
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003738 // It's OK to use the enumeration values directly here rather, as the
3739 // VFP register classes have the enum sorted properly.
Jim Grosbach080a4992011-10-28 00:06:50 +00003740 //
3741 // The list is of D registers, but we also allow Q regs and just interpret
3742 // them as the two D sub-registers.
3743 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003744 if (!Spacing)
3745 Spacing = 1; // Register range implies a single spaced list.
3746 else if (Spacing == 2) {
3747 Error(RegLoc,
3748 "invalid register in double-spaced list (must be 'D' register')");
3749 return MatchOperand_ParseFail;
3750 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003751 Reg = getDRegFromQReg(Reg);
3752 if (Reg != OldReg + 1) {
3753 Error(RegLoc, "non-contiguous register range");
3754 return MatchOperand_ParseFail;
3755 }
3756 ++Reg;
3757 Count += 2;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003758 // Parse the lane specifier if present.
3759 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003760 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003761 SMLoc LaneLoc = Parser.getTok().getLoc();
3762 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3763 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003764 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003765 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003766 Error(LaneLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003767 return MatchOperand_ParseFail;
3768 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003769 continue;
3770 }
Jim Grosbach2f50e922011-12-15 21:44:33 +00003771 // Normal D register.
3772 // Figure out the register spacing (single or double) of the list if
3773 // we don't know it already.
3774 if (!Spacing)
3775 Spacing = 1 + (Reg == OldReg + 2);
3776
3777 // Just check that it's contiguous and keep going.
3778 if (Reg != OldReg + Spacing) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003779 Error(RegLoc, "non-contiguous register range");
3780 return MatchOperand_ParseFail;
3781 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003782 ++Count;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003783 // Parse the lane specifier if present.
3784 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003785 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003786 SMLoc EndLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003787 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003788 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003789 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003790 Error(EndLoc, "mismatched lane index in register list");
3791 return MatchOperand_ParseFail;
3792 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003793 }
3794
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003795 if (Parser.getTok().isNot(AsmToken::RCurly)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003796 Error(Parser.getTok().getLoc(), "'}' expected");
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003797 return MatchOperand_ParseFail;
3798 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003799 E = Parser.getTok().getEndLoc();
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003800 Parser.Lex(); // Eat '}' token.
3801
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003802 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003803 case NoLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003804 // Two-register operands have been converted to the
Jim Grosbache5307f92012-03-05 21:43:40 +00003805 // composite register classes.
3806 if (Count == 2) {
3807 const MCRegisterClass *RC = (Spacing == 1) ?
3808 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3809 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3810 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3811 }
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003812
Jim Grosbach2f50e922011-12-15 21:44:33 +00003813 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3814 (Spacing == 2), S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003815 break;
3816 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003817 // Two-register operands have been converted to the
3818 // composite register classes.
Jim Grosbached428bc2012-03-06 23:10:38 +00003819 if (Count == 2) {
3820 const MCRegisterClass *RC = (Spacing == 1) ?
3821 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3822 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbach13a292c2012-03-06 22:01:44 +00003823 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3824 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003825 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003826 (Spacing == 2),
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003827 S, E));
3828 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003829 case IndexedLane:
3830 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003831 LaneIndex,
3832 (Spacing == 2),
3833 S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003834 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003835 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003836 return MatchOperand_Success;
3837}
3838
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003839/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
David Blaikie960ea3f2014-06-08 16:18:35 +00003840ARMAsmParser::OperandMatchResultTy
3841ARMAsmParser::parseMemBarrierOptOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003842 MCAsmParser &Parser = getParser();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003843 SMLoc S = Parser.getTok().getLoc();
3844 const AsmToken &Tok = Parser.getTok();
Jiangning Liu288e1af2012-08-02 08:21:27 +00003845 unsigned Opt;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003846
Jiangning Liu288e1af2012-08-02 08:21:27 +00003847 if (Tok.is(AsmToken::Identifier)) {
3848 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003849
Jiangning Liu288e1af2012-08-02 08:21:27 +00003850 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3851 .Case("sy", ARM_MB::SY)
3852 .Case("st", ARM_MB::ST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003853 .Case("ld", ARM_MB::LD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003854 .Case("sh", ARM_MB::ISH)
3855 .Case("ish", ARM_MB::ISH)
3856 .Case("shst", ARM_MB::ISHST)
3857 .Case("ishst", ARM_MB::ISHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003858 .Case("ishld", ARM_MB::ISHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003859 .Case("nsh", ARM_MB::NSH)
3860 .Case("un", ARM_MB::NSH)
3861 .Case("nshst", ARM_MB::NSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003862 .Case("nshld", ARM_MB::NSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003863 .Case("unst", ARM_MB::NSHST)
3864 .Case("osh", ARM_MB::OSH)
3865 .Case("oshst", ARM_MB::OSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003866 .Case("oshld", ARM_MB::OSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003867 .Default(~0U);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003868
Joey Gouly926d3f52013-09-05 15:35:24 +00003869 // ishld, oshld, nshld and ld are only available from ARMv8.
3870 if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD ||
3871 Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD))
3872 Opt = ~0U;
3873
Jiangning Liu288e1af2012-08-02 08:21:27 +00003874 if (Opt == ~0U)
3875 return MatchOperand_NoMatch;
3876
3877 Parser.Lex(); // Eat identifier token.
3878 } else if (Tok.is(AsmToken::Hash) ||
3879 Tok.is(AsmToken::Dollar) ||
3880 Tok.is(AsmToken::Integer)) {
3881 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003882 Parser.Lex(); // Eat '#' or '$'.
Jiangning Liu288e1af2012-08-02 08:21:27 +00003883 SMLoc Loc = Parser.getTok().getLoc();
3884
3885 const MCExpr *MemBarrierID;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003886 if (getParser().parseExpression(MemBarrierID)) {
Jiangning Liu288e1af2012-08-02 08:21:27 +00003887 Error(Loc, "illegal expression");
3888 return MatchOperand_ParseFail;
3889 }
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +00003890
Jiangning Liu288e1af2012-08-02 08:21:27 +00003891 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3892 if (!CE) {
3893 Error(Loc, "constant expression expected");
3894 return MatchOperand_ParseFail;
3895 }
3896
3897 int Val = CE->getValue();
3898 if (Val & ~0xf) {
3899 Error(Loc, "immediate value out of range");
3900 return MatchOperand_ParseFail;
3901 }
3902
3903 Opt = ARM_MB::RESERVED_0 + Val;
3904 } else
3905 return MatchOperand_ParseFail;
3906
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003907 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003908 return MatchOperand_Success;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003909}
3910
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003911/// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
David Blaikie960ea3f2014-06-08 16:18:35 +00003912ARMAsmParser::OperandMatchResultTy
3913ARMAsmParser::parseInstSyncBarrierOptOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003914 MCAsmParser &Parser = getParser();
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003915 SMLoc S = Parser.getTok().getLoc();
3916 const AsmToken &Tok = Parser.getTok();
3917 unsigned Opt;
3918
3919 if (Tok.is(AsmToken::Identifier)) {
3920 StringRef OptStr = Tok.getString();
3921
Benjamin Kramer3e9237a2013-11-09 22:48:13 +00003922 if (OptStr.equals_lower("sy"))
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003923 Opt = ARM_ISB::SY;
3924 else
3925 return MatchOperand_NoMatch;
3926
3927 Parser.Lex(); // Eat identifier token.
3928 } else if (Tok.is(AsmToken::Hash) ||
3929 Tok.is(AsmToken::Dollar) ||
3930 Tok.is(AsmToken::Integer)) {
3931 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003932 Parser.Lex(); // Eat '#' or '$'.
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003933 SMLoc Loc = Parser.getTok().getLoc();
3934
3935 const MCExpr *ISBarrierID;
3936 if (getParser().parseExpression(ISBarrierID)) {
3937 Error(Loc, "illegal expression");
3938 return MatchOperand_ParseFail;
3939 }
3940
3941 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3942 if (!CE) {
3943 Error(Loc, "constant expression expected");
3944 return MatchOperand_ParseFail;
3945 }
3946
3947 int Val = CE->getValue();
3948 if (Val & ~0xf) {
3949 Error(Loc, "immediate value out of range");
3950 return MatchOperand_ParseFail;
3951 }
3952
3953 Opt = ARM_ISB::RESERVED_0 + Val;
3954 } else
3955 return MatchOperand_ParseFail;
3956
3957 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3958 (ARM_ISB::InstSyncBOpt)Opt, S));
3959 return MatchOperand_Success;
3960}
3961
3962
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003963/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
David Blaikie960ea3f2014-06-08 16:18:35 +00003964ARMAsmParser::OperandMatchResultTy
3965ARMAsmParser::parseProcIFlagsOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00003966 MCAsmParser &Parser = getParser();
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003967 SMLoc S = Parser.getTok().getLoc();
3968 const AsmToken &Tok = Parser.getTok();
Richard Bartonb0ec3752012-06-14 10:48:04 +00003969 if (!Tok.is(AsmToken::Identifier))
3970 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003971 StringRef IFlagsStr = Tok.getString();
3972
Owen Anderson10c5b122011-10-05 17:16:40 +00003973 // An iflags string of "none" is interpreted to mean that none of the AIF
3974 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003975 unsigned IFlags = 0;
Owen Anderson10c5b122011-10-05 17:16:40 +00003976 if (IFlagsStr != "none") {
3977 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3978 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3979 .Case("a", ARM_PROC::A)
3980 .Case("i", ARM_PROC::I)
3981 .Case("f", ARM_PROC::F)
3982 .Default(~0U);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003983
Owen Anderson10c5b122011-10-05 17:16:40 +00003984 // If some specific iflag is already set, it means that some letter is
3985 // present more than once, this is not acceptable.
3986 if (Flag == ~0U || (IFlags & Flag))
3987 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003988
Owen Anderson10c5b122011-10-05 17:16:40 +00003989 IFlags |= Flag;
3990 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003991 }
3992
3993 Parser.Lex(); // Eat identifier token.
3994 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3995 return MatchOperand_Success;
3996}
3997
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003998/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
David Blaikie960ea3f2014-06-08 16:18:35 +00003999ARMAsmParser::OperandMatchResultTy
4000ARMAsmParser::parseMSRMaskOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004001 MCAsmParser &Parser = getParser();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004002 SMLoc S = Parser.getTok().getLoc();
4003 const AsmToken &Tok = Parser.getTok();
Craig Toppera004b0d2012-10-09 04:55:28 +00004004 if (!Tok.is(AsmToken::Identifier))
4005 return MatchOperand_NoMatch;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004006 StringRef Mask = Tok.getString();
4007
James Molloy21efa7d2011-09-28 14:21:38 +00004008 if (isMClass()) {
4009 // See ARMv6-M 10.1.1
Jim Grosbachd28888d2012-03-15 21:34:14 +00004010 std::string Name = Mask.lower();
4011 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00004012 // Note: in the documentation:
4013 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
4014 // for MSR APSR_nzcvq.
4015 // but we do make it an alias here. This is so to get the "mask encoding"
4016 // bits correct on MSR APSR writes.
4017 //
4018 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
4019 // should really only be allowed when writing a special register. Note
4020 // they get dropped in the MRS instruction reading a special register as
4021 // the SYSm field is only 8 bits.
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00004022 .Case("apsr", 0x800)
4023 .Case("apsr_nzcvq", 0x800)
4024 .Case("apsr_g", 0x400)
4025 .Case("apsr_nzcvqg", 0xc00)
4026 .Case("iapsr", 0x801)
4027 .Case("iapsr_nzcvq", 0x801)
4028 .Case("iapsr_g", 0x401)
4029 .Case("iapsr_nzcvqg", 0xc01)
4030 .Case("eapsr", 0x802)
4031 .Case("eapsr_nzcvq", 0x802)
4032 .Case("eapsr_g", 0x402)
4033 .Case("eapsr_nzcvqg", 0xc02)
4034 .Case("xpsr", 0x803)
4035 .Case("xpsr_nzcvq", 0x803)
4036 .Case("xpsr_g", 0x403)
4037 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderby6c7279e2012-06-15 22:14:44 +00004038 .Case("ipsr", 0x805)
4039 .Case("epsr", 0x806)
4040 .Case("iepsr", 0x807)
4041 .Case("msp", 0x808)
4042 .Case("psp", 0x809)
4043 .Case("primask", 0x810)
4044 .Case("basepri", 0x811)
4045 .Case("basepri_max", 0x812)
4046 .Case("faultmask", 0x813)
4047 .Case("control", 0x814)
James Molloy21efa7d2011-09-28 14:21:38 +00004048 .Default(~0U);
Jim Grosbach3794d822011-12-22 17:17:10 +00004049
James Molloy21efa7d2011-09-28 14:21:38 +00004050 if (FlagsVal == ~0U)
4051 return MatchOperand_NoMatch;
4052
Renato Golin92c816c2014-09-01 11:25:07 +00004053 if (!hasThumb2DSP() && (FlagsVal & 0x400))
4054 // The _g and _nzcvqg versions are only valid if the DSP extension is
4055 // available.
4056 return MatchOperand_NoMatch;
4057
Kevin Enderby6c7279e2012-06-15 22:14:44 +00004058 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloy21efa7d2011-09-28 14:21:38 +00004059 // basepri, basepri_max and faultmask only valid for V7m.
4060 return MatchOperand_NoMatch;
Jim Grosbach3794d822011-12-22 17:17:10 +00004061
James Molloy21efa7d2011-09-28 14:21:38 +00004062 Parser.Lex(); // Eat identifier token.
4063 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
4064 return MatchOperand_Success;
4065 }
4066
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004067 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
4068 size_t Start = 0, Next = Mask.find('_');
4069 StringRef Flags = "";
Benjamin Kramer20baffb2011-11-06 20:37:06 +00004070 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004071 if (Next != StringRef::npos)
4072 Flags = Mask.slice(Next+1, Mask.size());
4073
4074 // FlagsVal contains the complete mask:
4075 // 3-0: Mask
4076 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
4077 unsigned FlagsVal = 0;
4078
4079 if (SpecReg == "apsr") {
4080 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +00004081 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004082 .Case("g", 0x4) // same as CPSR_s
4083 .Case("nzcvqg", 0xc) // same as CPSR_fs
4084 .Default(~0U);
4085
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00004086 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004087 if (!Flags.empty())
4088 return MatchOperand_NoMatch;
4089 else
Jim Grosbach0ecd3952011-09-14 20:03:46 +00004090 FlagsVal = 8; // No flag
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00004091 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004092 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbach3d00eec2012-04-05 03:17:53 +00004093 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
4094 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes54452132011-05-25 00:35:03 +00004095 Flags = "fc";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004096 for (int i = 0, e = Flags.size(); i != e; ++i) {
4097 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
4098 .Case("c", 1)
4099 .Case("x", 2)
4100 .Case("s", 4)
4101 .Case("f", 8)
4102 .Default(~0U);
4103
4104 // If some specific flag is already set, it means that some letter is
4105 // present more than once, this is not acceptable.
4106 if (FlagsVal == ~0U || (FlagsVal & Flag))
4107 return MatchOperand_NoMatch;
4108 FlagsVal |= Flag;
4109 }
4110 } else // No match for special register.
4111 return MatchOperand_NoMatch;
4112
Owen Anderson03a173e2011-10-21 18:43:28 +00004113 // Special register without flags is NOT equivalent to "fc" flags.
4114 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
4115 // two lines would enable gas compatibility at the expense of breaking
4116 // round-tripping.
4117 //
4118 // if (!FlagsVal)
4119 // FlagsVal = 0x9;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00004120
4121 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
4122 if (SpecReg == "spsr")
4123 FlagsVal |= 16;
4124
4125 Parser.Lex(); // Eat identifier token.
4126 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
4127 return MatchOperand_Success;
4128}
4129
Tim Northoveree843ef2014-08-15 10:47:12 +00004130/// parseBankedRegOperand - Try to parse a banked register (e.g. "lr_irq") for
4131/// use in the MRS/MSR instructions added to support virtualization.
4132ARMAsmParser::OperandMatchResultTy
4133ARMAsmParser::parseBankedRegOperand(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004134 MCAsmParser &Parser = getParser();
Tim Northoveree843ef2014-08-15 10:47:12 +00004135 SMLoc S = Parser.getTok().getLoc();
4136 const AsmToken &Tok = Parser.getTok();
4137 if (!Tok.is(AsmToken::Identifier))
4138 return MatchOperand_NoMatch;
4139 StringRef RegName = Tok.getString();
4140
4141 // The values here come from B9.2.3 of the ARM ARM, where bits 4-0 are SysM
4142 // and bit 5 is R.
4143 unsigned Encoding = StringSwitch<unsigned>(RegName.lower())
4144 .Case("r8_usr", 0x00)
4145 .Case("r9_usr", 0x01)
4146 .Case("r10_usr", 0x02)
4147 .Case("r11_usr", 0x03)
4148 .Case("r12_usr", 0x04)
4149 .Case("sp_usr", 0x05)
4150 .Case("lr_usr", 0x06)
4151 .Case("r8_fiq", 0x08)
4152 .Case("r9_fiq", 0x09)
4153 .Case("r10_fiq", 0x0a)
4154 .Case("r11_fiq", 0x0b)
4155 .Case("r12_fiq", 0x0c)
4156 .Case("sp_fiq", 0x0d)
4157 .Case("lr_fiq", 0x0e)
4158 .Case("lr_irq", 0x10)
4159 .Case("sp_irq", 0x11)
4160 .Case("lr_svc", 0x12)
4161 .Case("sp_svc", 0x13)
4162 .Case("lr_abt", 0x14)
4163 .Case("sp_abt", 0x15)
4164 .Case("lr_und", 0x16)
4165 .Case("sp_und", 0x17)
4166 .Case("lr_mon", 0x1c)
4167 .Case("sp_mon", 0x1d)
4168 .Case("elr_hyp", 0x1e)
4169 .Case("sp_hyp", 0x1f)
4170 .Case("spsr_fiq", 0x2e)
4171 .Case("spsr_irq", 0x30)
4172 .Case("spsr_svc", 0x32)
4173 .Case("spsr_abt", 0x34)
4174 .Case("spsr_und", 0x36)
4175 .Case("spsr_mon", 0x3c)
4176 .Case("spsr_hyp", 0x3e)
4177 .Default(~0U);
4178
4179 if (Encoding == ~0U)
4180 return MatchOperand_NoMatch;
4181
4182 Parser.Lex(); // Eat identifier token.
4183 Operands.push_back(ARMOperand::CreateBankedReg(Encoding, S));
4184 return MatchOperand_Success;
4185}
4186
David Blaikie960ea3f2014-06-08 16:18:35 +00004187ARMAsmParser::OperandMatchResultTy
4188ARMAsmParser::parsePKHImm(OperandVector &Operands, StringRef Op, int Low,
4189 int High) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004190 MCAsmParser &Parser = getParser();
Jim Grosbach27c1e252011-07-21 17:23:04 +00004191 const AsmToken &Tok = Parser.getTok();
4192 if (Tok.isNot(AsmToken::Identifier)) {
4193 Error(Parser.getTok().getLoc(), Op + " operand expected.");
4194 return MatchOperand_ParseFail;
4195 }
4196 StringRef ShiftName = Tok.getString();
Benjamin Kramer20baffb2011-11-06 20:37:06 +00004197 std::string LowerOp = Op.lower();
4198 std::string UpperOp = Op.upper();
Jim Grosbach27c1e252011-07-21 17:23:04 +00004199 if (ShiftName != LowerOp && ShiftName != UpperOp) {
4200 Error(Parser.getTok().getLoc(), Op + " operand expected.");
4201 return MatchOperand_ParseFail;
4202 }
4203 Parser.Lex(); // Eat shift type token.
4204
4205 // There must be a '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004206 if (Parser.getTok().isNot(AsmToken::Hash) &&
4207 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00004208 Error(Parser.getTok().getLoc(), "'#' expected");
4209 return MatchOperand_ParseFail;
4210 }
4211 Parser.Lex(); // Eat hash token.
4212
4213 const MCExpr *ShiftAmount;
4214 SMLoc Loc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004215 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004216 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00004217 Error(Loc, "illegal expression");
4218 return MatchOperand_ParseFail;
4219 }
4220 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4221 if (!CE) {
4222 Error(Loc, "constant expression expected");
4223 return MatchOperand_ParseFail;
4224 }
4225 int Val = CE->getValue();
4226 if (Val < Low || Val > High) {
4227 Error(Loc, "immediate value out of range");
4228 return MatchOperand_ParseFail;
4229 }
4230
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004231 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
Jim Grosbach27c1e252011-07-21 17:23:04 +00004232
4233 return MatchOperand_Success;
4234}
4235
David Blaikie960ea3f2014-06-08 16:18:35 +00004236ARMAsmParser::OperandMatchResultTy
4237ARMAsmParser::parseSetEndImm(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004238 MCAsmParser &Parser = getParser();
Jim Grosbach0a547702011-07-22 17:44:50 +00004239 const AsmToken &Tok = Parser.getTok();
4240 SMLoc S = Tok.getLoc();
4241 if (Tok.isNot(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004242 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00004243 return MatchOperand_ParseFail;
4244 }
Tim Northover4d141442013-05-31 15:58:45 +00004245 int Val = StringSwitch<int>(Tok.getString().lower())
Jim Grosbach0a547702011-07-22 17:44:50 +00004246 .Case("be", 1)
4247 .Case("le", 0)
4248 .Default(-1);
4249 Parser.Lex(); // Eat the token.
4250
4251 if (Val == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004252 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00004253 return MatchOperand_ParseFail;
4254 }
4255 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
4256 getContext()),
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004257 S, Tok.getEndLoc()));
Jim Grosbach0a547702011-07-22 17:44:50 +00004258 return MatchOperand_Success;
4259}
4260
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004261/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
4262/// instructions. Legal values are:
4263/// lsl #n 'n' in [0,31]
4264/// asr #n 'n' in [1,32]
4265/// n == 32 encoded as n == 0.
David Blaikie960ea3f2014-06-08 16:18:35 +00004266ARMAsmParser::OperandMatchResultTy
4267ARMAsmParser::parseShifterImm(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004268 MCAsmParser &Parser = getParser();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004269 const AsmToken &Tok = Parser.getTok();
4270 SMLoc S = Tok.getLoc();
4271 if (Tok.isNot(AsmToken::Identifier)) {
4272 Error(S, "shift operator 'asr' or 'lsl' expected");
4273 return MatchOperand_ParseFail;
4274 }
4275 StringRef ShiftName = Tok.getString();
4276 bool isASR;
4277 if (ShiftName == "lsl" || ShiftName == "LSL")
4278 isASR = false;
4279 else if (ShiftName == "asr" || ShiftName == "ASR")
4280 isASR = true;
4281 else {
4282 Error(S, "shift operator 'asr' or 'lsl' expected");
4283 return MatchOperand_ParseFail;
4284 }
4285 Parser.Lex(); // Eat the operator.
4286
4287 // A '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004288 if (Parser.getTok().isNot(AsmToken::Hash) &&
4289 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004290 Error(Parser.getTok().getLoc(), "'#' expected");
4291 return MatchOperand_ParseFail;
4292 }
4293 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004294 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004295
4296 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004297 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004298 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004299 Error(ExLoc, "malformed shift expression");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004300 return MatchOperand_ParseFail;
4301 }
4302 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4303 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004304 Error(ExLoc, "shift amount must be an immediate");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004305 return MatchOperand_ParseFail;
4306 }
4307
4308 int64_t Val = CE->getValue();
4309 if (isASR) {
4310 // Shift amount must be in [1,32]
4311 if (Val < 1 || Val > 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004312 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004313 return MatchOperand_ParseFail;
4314 }
Owen Andersonf01e2de2011-09-26 21:06:22 +00004315 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
4316 if (isThumb() && Val == 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004317 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
Owen Andersonf01e2de2011-09-26 21:06:22 +00004318 return MatchOperand_ParseFail;
4319 }
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004320 if (Val == 32) Val = 0;
4321 } else {
4322 // Shift amount must be in [1,32]
4323 if (Val < 0 || Val > 31) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004324 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004325 return MatchOperand_ParseFail;
4326 }
4327 }
4328
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004329 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00004330
4331 return MatchOperand_Success;
4332}
4333
Jim Grosbach833b9d32011-07-27 20:15:40 +00004334/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
4335/// of instructions. Legal values are:
4336/// ror #n 'n' in {0, 8, 16, 24}
David Blaikie960ea3f2014-06-08 16:18:35 +00004337ARMAsmParser::OperandMatchResultTy
4338ARMAsmParser::parseRotImm(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004339 MCAsmParser &Parser = getParser();
Jim Grosbach833b9d32011-07-27 20:15:40 +00004340 const AsmToken &Tok = Parser.getTok();
4341 SMLoc S = Tok.getLoc();
Jim Grosbach82213192011-09-19 20:29:33 +00004342 if (Tok.isNot(AsmToken::Identifier))
4343 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00004344 StringRef ShiftName = Tok.getString();
Jim Grosbach82213192011-09-19 20:29:33 +00004345 if (ShiftName != "ror" && ShiftName != "ROR")
4346 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00004347 Parser.Lex(); // Eat the operator.
4348
4349 // A '#' and a rotate amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004350 if (Parser.getTok().isNot(AsmToken::Hash) &&
4351 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00004352 Error(Parser.getTok().getLoc(), "'#' expected");
4353 return MatchOperand_ParseFail;
4354 }
4355 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004356 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach833b9d32011-07-27 20:15:40 +00004357
4358 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004359 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004360 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004361 Error(ExLoc, "malformed rotate expression");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004362 return MatchOperand_ParseFail;
4363 }
4364 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4365 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004366 Error(ExLoc, "rotate amount must be an immediate");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004367 return MatchOperand_ParseFail;
4368 }
4369
4370 int64_t Val = CE->getValue();
4371 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
4372 // normally, zero is represented in asm by omitting the rotate operand
4373 // entirely.
4374 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004375 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004376 return MatchOperand_ParseFail;
4377 }
4378
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004379 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
Jim Grosbach833b9d32011-07-27 20:15:40 +00004380
4381 return MatchOperand_Success;
4382}
4383
David Blaikie960ea3f2014-06-08 16:18:35 +00004384ARMAsmParser::OperandMatchResultTy
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004385ARMAsmParser::parseModImm(OperandVector &Operands) {
4386 MCAsmParser &Parser = getParser();
4387 MCAsmLexer &Lexer = getLexer();
4388 int64_t Imm1, Imm2;
4389
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004390 SMLoc S = Parser.getTok().getLoc();
4391
Asiri Rathnayake13cef352014-12-04 19:34:59 +00004392 // 1) A mod_imm operand can appear in the place of a register name:
4393 // add r0, #mod_imm
4394 // add r0, r0, #mod_imm
4395 // to correctly handle the latter, we bail out as soon as we see an
4396 // identifier.
4397 //
4398 // 2) Similarly, we do not want to parse into complex operands:
4399 // mov r0, #mod_imm
4400 // mov r0, :lower16:(_foo)
4401 if (Parser.getTok().is(AsmToken::Identifier) ||
4402 Parser.getTok().is(AsmToken::Colon))
4403 return MatchOperand_NoMatch;
4404
4405 // Hash (dollar) is optional as per the ARMARM
4406 if (Parser.getTok().is(AsmToken::Hash) ||
4407 Parser.getTok().is(AsmToken::Dollar)) {
4408 // Avoid parsing into complex operands (#:)
4409 if (Lexer.peekTok().is(AsmToken::Colon))
4410 return MatchOperand_NoMatch;
4411
4412 // Eat the hash (dollar)
4413 Parser.Lex();
4414 }
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004415
4416 SMLoc Sx1, Ex1;
4417 Sx1 = Parser.getTok().getLoc();
4418 const MCExpr *Imm1Exp;
4419 if (getParser().parseExpression(Imm1Exp, Ex1)) {
4420 Error(Sx1, "malformed expression");
4421 return MatchOperand_ParseFail;
4422 }
4423
4424 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm1Exp);
4425
4426 if (CE) {
Asiri Rathnayaked33304b2014-12-04 14:49:07 +00004427 // Immediate must fit within 32-bits
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004428 Imm1 = CE->getValue();
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004429 int Enc = ARM_AM::getSOImmVal(Imm1);
4430 if (Enc != -1 && Parser.getTok().is(AsmToken::EndOfStatement)) {
4431 // We have a match!
4432 Operands.push_back(ARMOperand::CreateModImm((Enc & 0xFF),
4433 (Enc & 0xF00) >> 7,
4434 Sx1, Ex1));
4435 return MatchOperand_Success;
4436 }
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004437
Asiri Rathnayaked33304b2014-12-04 14:49:07 +00004438 // We have parsed an immediate which is not for us, fallback to a plain
4439 // immediate. This can happen for instruction aliases. For an example,
4440 // ARMInstrInfo.td defines the alias [mov <-> mvn] which can transform
4441 // a mov (mvn) with a mod_imm_neg/mod_imm_not operand into the opposite
4442 // instruction with a mod_imm operand. The alias is defined such that the
4443 // parser method is shared, that's why we have to do this here.
4444 if (Parser.getTok().is(AsmToken::EndOfStatement)) {
4445 Operands.push_back(ARMOperand::CreateImm(Imm1Exp, Sx1, Ex1));
4446 return MatchOperand_Success;
4447 }
4448 } else {
4449 // Operands like #(l1 - l2) can only be evaluated at a later stage (via an
4450 // MCFixup). Fallback to a plain immediate.
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004451 Operands.push_back(ARMOperand::CreateImm(Imm1Exp, Sx1, Ex1));
4452 return MatchOperand_Success;
4453 }
4454
4455 // From this point onward, we expect the input to be a (#bits, #rot) pair
Asiri Rathnayaked33304b2014-12-04 14:49:07 +00004456 if (Parser.getTok().isNot(AsmToken::Comma)) {
4457 Error(Sx1, "expected modified immediate operand: #[0, 255], #even[0-30]");
4458 return MatchOperand_ParseFail;
4459 }
4460
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004461 if (Imm1 & ~0xFF) {
4462 Error(Sx1, "immediate operand must a number in the range [0, 255]");
4463 return MatchOperand_ParseFail;
4464 }
4465
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004466 // Eat the comma
4467 Parser.Lex();
4468
4469 // Repeat for #rot
4470 SMLoc Sx2, Ex2;
4471 Sx2 = Parser.getTok().getLoc();
4472
Asiri Rathnayake13cef352014-12-04 19:34:59 +00004473 // Eat the optional hash (dollar)
4474 if (Parser.getTok().is(AsmToken::Hash) ||
4475 Parser.getTok().is(AsmToken::Dollar))
4476 Parser.Lex();
Asiri Rathnayakea0199b92014-12-02 10:53:20 +00004477
4478 const MCExpr *Imm2Exp;
4479 if (getParser().parseExpression(Imm2Exp, Ex2)) {
4480 Error(Sx2, "malformed expression");
4481 return MatchOperand_ParseFail;
4482 }
4483
4484 CE = dyn_cast<MCConstantExpr>(Imm2Exp);
4485
4486 if (CE) {
4487 Imm2 = CE->getValue();
4488 if (!(Imm2 & ~0x1E)) {
4489 // We have a match!
4490 Operands.push_back(ARMOperand::CreateModImm(Imm1, Imm2, S, Ex2));
4491 return MatchOperand_Success;
4492 }
4493 Error(Sx2, "immediate operand must an even number in the range [0, 30]");
4494 return MatchOperand_ParseFail;
4495 } else {
4496 Error(Sx2, "constant expression expected");
4497 return MatchOperand_ParseFail;
4498 }
4499}
4500
4501ARMAsmParser::OperandMatchResultTy
David Blaikie960ea3f2014-06-08 16:18:35 +00004502ARMAsmParser::parseBitfield(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004503 MCAsmParser &Parser = getParser();
Jim Grosbach864b6092011-07-28 21:34:26 +00004504 SMLoc S = Parser.getTok().getLoc();
4505 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004506 if (Parser.getTok().isNot(AsmToken::Hash) &&
4507 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004508 Error(Parser.getTok().getLoc(), "'#' expected");
4509 return MatchOperand_ParseFail;
4510 }
4511 Parser.Lex(); // Eat hash token.
4512
4513 const MCExpr *LSBExpr;
4514 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004515 if (getParser().parseExpression(LSBExpr)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004516 Error(E, "malformed immediate expression");
4517 return MatchOperand_ParseFail;
4518 }
4519 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
4520 if (!CE) {
4521 Error(E, "'lsb' operand must be an immediate");
4522 return MatchOperand_ParseFail;
4523 }
4524
4525 int64_t LSB = CE->getValue();
4526 // The LSB must be in the range [0,31]
4527 if (LSB < 0 || LSB > 31) {
4528 Error(E, "'lsb' operand must be in the range [0,31]");
4529 return MatchOperand_ParseFail;
4530 }
4531 E = Parser.getTok().getLoc();
4532
4533 // Expect another immediate operand.
4534 if (Parser.getTok().isNot(AsmToken::Comma)) {
4535 Error(Parser.getTok().getLoc(), "too few operands");
4536 return MatchOperand_ParseFail;
4537 }
4538 Parser.Lex(); // Eat hash token.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004539 if (Parser.getTok().isNot(AsmToken::Hash) &&
4540 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004541 Error(Parser.getTok().getLoc(), "'#' expected");
4542 return MatchOperand_ParseFail;
4543 }
4544 Parser.Lex(); // Eat hash token.
4545
4546 const MCExpr *WidthExpr;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004547 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004548 if (getParser().parseExpression(WidthExpr, EndLoc)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004549 Error(E, "malformed immediate expression");
4550 return MatchOperand_ParseFail;
4551 }
4552 CE = dyn_cast<MCConstantExpr>(WidthExpr);
4553 if (!CE) {
4554 Error(E, "'width' operand must be an immediate");
4555 return MatchOperand_ParseFail;
4556 }
4557
4558 int64_t Width = CE->getValue();
4559 // The LSB must be in the range [1,32-lsb]
4560 if (Width < 1 || Width > 32 - LSB) {
4561 Error(E, "'width' operand must be in the range [1,32-lsb]");
4562 return MatchOperand_ParseFail;
4563 }
Jim Grosbach864b6092011-07-28 21:34:26 +00004564
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004565 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
Jim Grosbach864b6092011-07-28 21:34:26 +00004566
4567 return MatchOperand_Success;
4568}
4569
David Blaikie960ea3f2014-06-08 16:18:35 +00004570ARMAsmParser::OperandMatchResultTy
4571ARMAsmParser::parsePostIdxReg(OperandVector &Operands) {
Jim Grosbachd3595712011-08-03 23:50:40 +00004572 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachc320c852011-08-05 21:28:30 +00004573 // postidx_reg := '+' register {, shift}
4574 // | '-' register {, shift}
4575 // | register {, shift}
Jim Grosbachd3595712011-08-03 23:50:40 +00004576
4577 // This method must return MatchOperand_NoMatch without consuming any tokens
4578 // in the case where there is no match, as other alternatives take other
4579 // parse methods.
Rafael Espindola961d4692014-11-11 05:18:41 +00004580 MCAsmParser &Parser = getParser();
Jim Grosbachd3595712011-08-03 23:50:40 +00004581 AsmToken Tok = Parser.getTok();
4582 SMLoc S = Tok.getLoc();
4583 bool haveEaten = false;
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004584 bool isAdd = true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004585 if (Tok.is(AsmToken::Plus)) {
4586 Parser.Lex(); // Eat the '+' token.
4587 haveEaten = true;
4588 } else if (Tok.is(AsmToken::Minus)) {
4589 Parser.Lex(); // Eat the '-' token.
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004590 isAdd = false;
Jim Grosbachd3595712011-08-03 23:50:40 +00004591 haveEaten = true;
4592 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004593
4594 SMLoc E = Parser.getTok().getEndLoc();
4595 int Reg = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004596 if (Reg == -1) {
4597 if (!haveEaten)
4598 return MatchOperand_NoMatch;
4599 Error(Parser.getTok().getLoc(), "register expected");
4600 return MatchOperand_ParseFail;
4601 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004602
Jim Grosbachc320c852011-08-05 21:28:30 +00004603 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
4604 unsigned ShiftImm = 0;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004605 if (Parser.getTok().is(AsmToken::Comma)) {
4606 Parser.Lex(); // Eat the ','.
4607 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4608 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004609
4610 // FIXME: Only approximates end...may include intervening whitespace.
4611 E = Parser.getTok().getLoc();
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004612 }
Jim Grosbachc320c852011-08-05 21:28:30 +00004613
4614 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4615 ShiftImm, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004616
4617 return MatchOperand_Success;
4618}
4619
David Blaikie960ea3f2014-06-08 16:18:35 +00004620ARMAsmParser::OperandMatchResultTy
4621ARMAsmParser::parseAM3Offset(OperandVector &Operands) {
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004622 // Check for a post-index addressing register operand. Specifically:
4623 // am3offset := '+' register
4624 // | '-' register
4625 // | register
4626 // | # imm
4627 // | # + imm
4628 // | # - imm
4629
4630 // This method must return MatchOperand_NoMatch without consuming any tokens
4631 // in the case where there is no match, as other alternatives take other
4632 // parse methods.
Rafael Espindola961d4692014-11-11 05:18:41 +00004633 MCAsmParser &Parser = getParser();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004634 AsmToken Tok = Parser.getTok();
4635 SMLoc S = Tok.getLoc();
4636
4637 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004638 if (Parser.getTok().is(AsmToken::Hash) ||
4639 Parser.getTok().is(AsmToken::Dollar)) {
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004640 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004641 // Explicitly look for a '-', as we need to encode negative zero
4642 // differently.
4643 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4644 const MCExpr *Offset;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004645 SMLoc E;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004646 if (getParser().parseExpression(Offset, E))
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004647 return MatchOperand_ParseFail;
4648 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4649 if (!CE) {
4650 Error(S, "constant expression expected");
4651 return MatchOperand_ParseFail;
4652 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004653 // Negative zero is encoded as the flag value INT32_MIN.
4654 int32_t Val = CE->getValue();
4655 if (isNegative && Val == 0)
4656 Val = INT32_MIN;
4657
4658 Operands.push_back(
4659 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4660
4661 return MatchOperand_Success;
4662 }
4663
4664
4665 bool haveEaten = false;
4666 bool isAdd = true;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004667 if (Tok.is(AsmToken::Plus)) {
4668 Parser.Lex(); // Eat the '+' token.
4669 haveEaten = true;
4670 } else if (Tok.is(AsmToken::Minus)) {
4671 Parser.Lex(); // Eat the '-' token.
4672 isAdd = false;
4673 haveEaten = true;
4674 }
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +00004675
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004676 Tok = Parser.getTok();
4677 int Reg = tryParseRegister();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004678 if (Reg == -1) {
4679 if (!haveEaten)
4680 return MatchOperand_NoMatch;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004681 Error(Tok.getLoc(), "register expected");
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004682 return MatchOperand_ParseFail;
4683 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004684
4685 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004686 0, S, Tok.getEndLoc()));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004687
4688 return MatchOperand_Success;
4689}
4690
Tim Northovereb5e4d52013-07-22 09:06:12 +00004691/// Convert parsed operands to MCInst. Needed here because this instruction
4692/// only has two register operands, but multiplication is commutative so
4693/// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
David Blaikie960ea3f2014-06-08 16:18:35 +00004694void ARMAsmParser::cvtThumbMultiply(MCInst &Inst,
4695 const OperandVector &Operands) {
4696 ((ARMOperand &)*Operands[3]).addRegOperands(Inst, 1);
4697 ((ARMOperand &)*Operands[1]).addCCOutOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004698 // If we have a three-operand form, make sure to set Rn to be the operand
4699 // that isn't the same as Rd.
4700 unsigned RegOp = 4;
4701 if (Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00004702 ((ARMOperand &)*Operands[4]).getReg() ==
4703 ((ARMOperand &)*Operands[3]).getReg())
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004704 RegOp = 5;
David Blaikie960ea3f2014-06-08 16:18:35 +00004705 ((ARMOperand &)*Operands[RegOp]).addRegOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004706 Inst.addOperand(Inst.getOperand(0));
David Blaikie960ea3f2014-06-08 16:18:35 +00004707 ((ARMOperand &)*Operands[2]).addCondCodeOperands(Inst, 2);
Jim Grosbach8e048492011-08-19 22:07:46 +00004708}
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004709
David Blaikie960ea3f2014-06-08 16:18:35 +00004710void ARMAsmParser::cvtThumbBranches(MCInst &Inst,
4711 const OperandVector &Operands) {
Mihai Popaad18d3c2013-08-09 10:38:32 +00004712 int CondOp = -1, ImmOp = -1;
4713 switch(Inst.getOpcode()) {
4714 case ARM::tB:
4715 case ARM::tBcc: CondOp = 1; ImmOp = 2; break;
4716
4717 case ARM::t2B:
4718 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break;
4719
4720 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
4721 }
4722 // first decide whether or not the branch should be conditional
4723 // by looking at it's location relative to an IT block
4724 if(inITBlock()) {
4725 // inside an IT block we cannot have any conditional branches. any
4726 // such instructions needs to be converted to unconditional form
4727 switch(Inst.getOpcode()) {
4728 case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
4729 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
4730 }
4731 } else {
4732 // outside IT blocks we can only have unconditional branches with AL
4733 // condition code or conditional branches with non-AL condition code
David Blaikie960ea3f2014-06-08 16:18:35 +00004734 unsigned Cond = static_cast<ARMOperand &>(*Operands[CondOp]).getCondCode();
Mihai Popaad18d3c2013-08-09 10:38:32 +00004735 switch(Inst.getOpcode()) {
4736 case ARM::tB:
4737 case ARM::tBcc:
4738 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
4739 break;
4740 case ARM::t2B:
4741 case ARM::t2Bcc:
4742 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
4743 break;
4744 }
4745 }
Saleem Abdulrasool4ab6e732014-02-23 17:45:36 +00004746
Mihai Popaad18d3c2013-08-09 10:38:32 +00004747 // now decide on encoding size based on branch target range
4748 switch(Inst.getOpcode()) {
4749 // classify tB as either t2B or t1B based on range of immediate operand
4750 case ARM::tB: {
David Blaikie960ea3f2014-06-08 16:18:35 +00004751 ARMOperand &op = static_cast<ARMOperand &>(*Operands[ImmOp]);
4752 if (!op.isSignedOffset<11, 1>() && isThumbTwo())
Mihai Popaad18d3c2013-08-09 10:38:32 +00004753 Inst.setOpcode(ARM::t2B);
4754 break;
4755 }
4756 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
4757 case ARM::tBcc: {
David Blaikie960ea3f2014-06-08 16:18:35 +00004758 ARMOperand &op = static_cast<ARMOperand &>(*Operands[ImmOp]);
4759 if (!op.isSignedOffset<8, 1>() && isThumbTwo())
Mihai Popaad18d3c2013-08-09 10:38:32 +00004760 Inst.setOpcode(ARM::t2Bcc);
4761 break;
4762 }
4763 }
David Blaikie960ea3f2014-06-08 16:18:35 +00004764 ((ARMOperand &)*Operands[ImmOp]).addImmOperands(Inst, 1);
4765 ((ARMOperand &)*Operands[CondOp]).addCondCodeOperands(Inst, 2);
Mihai Popaad18d3c2013-08-09 10:38:32 +00004766}
4767
Bill Wendlinge18980a2010-11-06 22:36:58 +00004768/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004769/// or an error. The first token must be a '[' when called.
David Blaikie960ea3f2014-06-08 16:18:35 +00004770bool ARMAsmParser::parseMemory(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004771 MCAsmParser &Parser = getParser();
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004772 SMLoc S, E;
Sean Callanan936b0d32010-01-19 21:44:56 +00004773 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00004774 "Token is not a Left Bracket");
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004775 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004776 Parser.Lex(); // Eat left bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004777
Sean Callanan936b0d32010-01-19 21:44:56 +00004778 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004779 int BaseRegNum = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004780 if (BaseRegNum == -1)
4781 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004782
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004783 // The next token must either be a comma, a colon or a closing bracket.
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004784 const AsmToken &Tok = Parser.getTok();
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004785 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4786 !Tok.is(AsmToken::RBrac))
Jim Grosbachd3595712011-08-03 23:50:40 +00004787 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004788
Jim Grosbachd3595712011-08-03 23:50:40 +00004789 if (Tok.is(AsmToken::RBrac)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004790 E = Tok.getEndLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004791 Parser.Lex(); // Eat right bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004792
Craig Topper062a2ba2014-04-25 05:30:21 +00004793 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, 0,
4794 ARM_AM::no_shift, 0, 0, false,
4795 S, E));
Jim Grosbach32ff5582010-11-29 23:18:01 +00004796
Jim Grosbach40700e02011-09-19 18:42:21 +00004797 // If there's a pre-indexing writeback marker, '!', just add it as a token
4798 // operand. It's rather odd, but syntactically valid.
4799 if (Parser.getTok().is(AsmToken::Exclaim)) {
4800 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4801 Parser.Lex(); // Eat the '!'.
4802 }
4803
Jim Grosbachd3595712011-08-03 23:50:40 +00004804 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004805 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004806
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004807 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4808 "Lost colon or comma in memory operand?!");
4809 if (Tok.is(AsmToken::Comma)) {
4810 Parser.Lex(); // Eat the comma.
4811 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004812
Jim Grosbacha95ec992011-10-11 17:29:55 +00004813 // If we have a ':', it's an alignment specifier.
4814 if (Parser.getTok().is(AsmToken::Colon)) {
4815 Parser.Lex(); // Eat the ':'.
4816 E = Parser.getTok().getLoc();
Kevin Enderby488f20b2014-04-10 20:18:58 +00004817 SMLoc AlignmentLoc = Tok.getLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004818
4819 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004820 if (getParser().parseExpression(Expr))
Jim Grosbacha95ec992011-10-11 17:29:55 +00004821 return true;
4822
4823 // The expression has to be a constant. Memory references with relocations
4824 // don't come through here, as they use the <label> forms of the relevant
4825 // instructions.
4826 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4827 if (!CE)
4828 return Error (E, "constant expression expected");
4829
4830 unsigned Align = 0;
4831 switch (CE->getValue()) {
4832 default:
Jim Grosbachcef98cd2011-12-19 18:31:43 +00004833 return Error(E,
4834 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4835 case 16: Align = 2; break;
4836 case 32: Align = 4; break;
Jim Grosbacha95ec992011-10-11 17:29:55 +00004837 case 64: Align = 8; break;
4838 case 128: Align = 16; break;
4839 case 256: Align = 32; break;
4840 }
4841
4842 // Now we should have the closing ']'
Jim Grosbacha95ec992011-10-11 17:29:55 +00004843 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004844 return Error(Parser.getTok().getLoc(), "']' expected");
4845 E = Parser.getTok().getEndLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004846 Parser.Lex(); // Eat right bracket token.
4847
4848 // Don't worry about range checking the value here. That's handled by
4849 // the is*() predicates.
Craig Topper062a2ba2014-04-25 05:30:21 +00004850 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004851 ARM_AM::no_shift, 0, Align,
Kevin Enderby488f20b2014-04-10 20:18:58 +00004852 false, S, E, AlignmentLoc));
Jim Grosbacha95ec992011-10-11 17:29:55 +00004853
4854 // If there's a pre-indexing writeback marker, '!', just add it as a token
4855 // operand.
4856 if (Parser.getTok().is(AsmToken::Exclaim)) {
4857 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4858 Parser.Lex(); // Eat the '!'.
4859 }
4860
4861 return false;
4862 }
4863
4864 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach8279c182011-11-15 22:14:41 +00004865 // offset. Be friendly and also accept a plain integer (without a leading
4866 // hash) for gas compatibility.
4867 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004868 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach8279c182011-11-15 22:14:41 +00004869 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004870 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004871 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbachd3595712011-08-03 23:50:40 +00004872 E = Parser.getTok().getLoc();
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004873
Owen Anderson967674d2011-08-29 19:36:44 +00004874 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbachd3595712011-08-03 23:50:40 +00004875 const MCExpr *Offset;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004876 if (getParser().parseExpression(Offset))
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004877 return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004878
4879 // The expression has to be a constant. Memory references with relocations
4880 // don't come through here, as they use the <label> forms of the relevant
4881 // instructions.
4882 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4883 if (!CE)
4884 return Error (E, "constant expression expected");
4885
Owen Anderson967674d2011-08-29 19:36:44 +00004886 // If the constant was #-0, represent it as INT32_MIN.
4887 int32_t Val = CE->getValue();
4888 if (isNegative && Val == 0)
4889 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4890
Jim Grosbachd3595712011-08-03 23:50:40 +00004891 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004892 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004893 return Error(Parser.getTok().getLoc(), "']' expected");
4894 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004895 Parser.Lex(); // Eat right bracket token.
4896
4897 // Don't worry about range checking the value here. That's handled by
4898 // the is*() predicates.
4899 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004900 ARM_AM::no_shift, 0, 0,
4901 false, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004902
4903 // If there's a pre-indexing writeback marker, '!', just add it as a token
4904 // operand.
4905 if (Parser.getTok().is(AsmToken::Exclaim)) {
4906 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4907 Parser.Lex(); // Eat the '!'.
4908 }
4909
4910 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004911 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004912
4913 // The register offset is optionally preceded by a '+' or '-'
4914 bool isNegative = false;
4915 if (Parser.getTok().is(AsmToken::Minus)) {
4916 isNegative = true;
4917 Parser.Lex(); // Eat the '-'.
4918 } else if (Parser.getTok().is(AsmToken::Plus)) {
4919 // Nothing to do.
4920 Parser.Lex(); // Eat the '+'.
4921 }
4922
4923 E = Parser.getTok().getLoc();
4924 int OffsetRegNum = tryParseRegister();
4925 if (OffsetRegNum == -1)
4926 return Error(E, "register expected");
4927
4928 // If there's a shift operator, handle it.
4929 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004930 unsigned ShiftImm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004931 if (Parser.getTok().is(AsmToken::Comma)) {
4932 Parser.Lex(); // Eat the ','.
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004933 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbachd3595712011-08-03 23:50:40 +00004934 return true;
4935 }
4936
4937 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004938 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004939 return Error(Parser.getTok().getLoc(), "']' expected");
4940 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004941 Parser.Lex(); // Eat right bracket token.
4942
Craig Topper062a2ba2014-04-25 05:30:21 +00004943 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, OffsetRegNum,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004944 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbachd3595712011-08-03 23:50:40 +00004945 S, E));
4946
Jim Grosbachc320c852011-08-05 21:28:30 +00004947 // If there's a pre-indexing writeback marker, '!', just add it as a token
4948 // operand.
4949 if (Parser.getTok().is(AsmToken::Exclaim)) {
4950 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4951 Parser.Lex(); // Eat the '!'.
4952 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004953
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004954 return false;
4955}
4956
Jim Grosbachd3595712011-08-03 23:50:40 +00004957/// parseMemRegOffsetShift - one of these two:
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004958/// ( lsl | lsr | asr | ror ) , # shift_amount
4959/// rrx
Jim Grosbachd3595712011-08-03 23:50:40 +00004960/// return true if it parses a shift otherwise it returns false.
4961bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4962 unsigned &Amount) {
Rafael Espindola961d4692014-11-11 05:18:41 +00004963 MCAsmParser &Parser = getParser();
Jim Grosbachd3595712011-08-03 23:50:40 +00004964 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan936b0d32010-01-19 21:44:56 +00004965 const AsmToken &Tok = Parser.getTok();
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004966 if (Tok.isNot(AsmToken::Identifier))
4967 return true;
Benjamin Kramer92d89982010-07-14 22:38:02 +00004968 StringRef ShiftName = Tok.getString();
Jim Grosbach3b559ff2011-12-07 23:40:58 +00004969 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4970 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004971 St = ARM_AM::lsl;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004972 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004973 St = ARM_AM::lsr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004974 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004975 St = ARM_AM::asr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004976 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004977 St = ARM_AM::ror;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004978 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004979 St = ARM_AM::rrx;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004980 else
Jim Grosbachd3595712011-08-03 23:50:40 +00004981 return Error(Loc, "illegal shift operator");
Sean Callanana83fd7d2010-01-19 20:27:46 +00004982 Parser.Lex(); // Eat shift type token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004983
Jim Grosbachd3595712011-08-03 23:50:40 +00004984 // rrx stands alone.
4985 Amount = 0;
4986 if (St != ARM_AM::rrx) {
4987 Loc = Parser.getTok().getLoc();
4988 // A '#' and a shift amount.
4989 const AsmToken &HashTok = Parser.getTok();
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004990 if (HashTok.isNot(AsmToken::Hash) &&
4991 HashTok.isNot(AsmToken::Dollar))
Jim Grosbachd3595712011-08-03 23:50:40 +00004992 return Error(HashTok.getLoc(), "'#' expected");
4993 Parser.Lex(); // Eat hash token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004994
Jim Grosbachd3595712011-08-03 23:50:40 +00004995 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004996 if (getParser().parseExpression(Expr))
Jim Grosbachd3595712011-08-03 23:50:40 +00004997 return true;
4998 // Range check the immediate.
4999 // lsl, ror: 0 <= imm <= 31
5000 // lsr, asr: 0 <= imm <= 32
5001 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
5002 if (!CE)
5003 return Error(Loc, "shift amount must be an immediate");
5004 int64_t Imm = CE->getValue();
5005 if (Imm < 0 ||
5006 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
5007 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
5008 return Error(Loc, "immediate shift value out of range");
Tim Northover0c97e762012-09-22 11:18:12 +00005009 // If <ShiftTy> #0, turn it into a no_shift.
5010 if (Imm == 0)
5011 St = ARM_AM::lsl;
5012 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
5013 if (Imm == 32)
5014 Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00005015 Amount = Imm;
5016 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005017
5018 return false;
5019}
5020
Jim Grosbache7fbce72011-10-03 23:38:36 +00005021/// parseFPImm - A floating point immediate expression operand.
David Blaikie960ea3f2014-06-08 16:18:35 +00005022ARMAsmParser::OperandMatchResultTy
5023ARMAsmParser::parseFPImm(OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00005024 MCAsmParser &Parser = getParser();
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005025 // Anything that can accept a floating point constant as an operand
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005026 // needs to go through here, as the regular parseExpression is
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005027 // integer only.
5028 //
5029 // This routine still creates a generic Immediate operand, containing
5030 // a bitcast of the 64-bit floating point value. The various operands
5031 // that accept floats can check whether the value is valid for them
5032 // via the standard is*() predicates.
5033
Jim Grosbache7fbce72011-10-03 23:38:36 +00005034 SMLoc S = Parser.getTok().getLoc();
5035
Jim Grosbachef70e9b2011-12-09 22:25:03 +00005036 if (Parser.getTok().isNot(AsmToken::Hash) &&
5037 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbache7fbce72011-10-03 23:38:36 +00005038 return MatchOperand_NoMatch;
Jim Grosbach741cd732011-10-17 22:26:03 +00005039
5040 // Disambiguate the VMOV forms that can accept an FP immediate.
5041 // vmov.f32 <sreg>, #imm
5042 // vmov.f64 <dreg>, #imm
5043 // vmov.f32 <dreg>, #imm @ vector f32x2
5044 // vmov.f32 <qreg>, #imm @ vector f32x4
5045 //
5046 // There are also the NEON VMOV instructions which expect an
5047 // integer constant. Make sure we don't try to parse an FPImm
5048 // for these:
5049 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
David Blaikie960ea3f2014-06-08 16:18:35 +00005050 ARMOperand &TyOp = static_cast<ARMOperand &>(*Operands[2]);
5051 bool isVmovf = TyOp.isToken() &&
5052 (TyOp.getToken() == ".f32" || TyOp.getToken() == ".f64");
5053 ARMOperand &Mnemonic = static_cast<ARMOperand &>(*Operands[0]);
5054 bool isFconst = Mnemonic.isToken() && (Mnemonic.getToken() == "fconstd" ||
5055 Mnemonic.getToken() == "fconsts");
David Peixottoa872e0e2014-01-07 18:19:23 +00005056 if (!(isVmovf || isFconst))
Jim Grosbach741cd732011-10-17 22:26:03 +00005057 return MatchOperand_NoMatch;
5058
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00005059 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbache7fbce72011-10-03 23:38:36 +00005060
5061 // Handle negation, as that still comes through as a separate token.
5062 bool isNegative = false;
5063 if (Parser.getTok().is(AsmToken::Minus)) {
5064 isNegative = true;
5065 Parser.Lex();
5066 }
5067 const AsmToken &Tok = Parser.getTok();
Jim Grosbach235c8d22012-01-19 02:47:30 +00005068 SMLoc Loc = Tok.getLoc();
David Peixottoa872e0e2014-01-07 18:19:23 +00005069 if (Tok.is(AsmToken::Real) && isVmovf) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005070 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbache7fbce72011-10-03 23:38:36 +00005071 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
5072 // If we had a '-' in front, toggle the sign bit.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005073 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbache7fbce72011-10-03 23:38:36 +00005074 Parser.Lex(); // Eat the token.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005075 Operands.push_back(ARMOperand::CreateImm(
5076 MCConstantExpr::Create(IntVal, getContext()),
5077 S, Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00005078 return MatchOperand_Success;
5079 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005080 // Also handle plain integers. Instructions which allow floating point
5081 // immediates also allow a raw encoded 8-bit value.
David Peixottoa872e0e2014-01-07 18:19:23 +00005082 if (Tok.is(AsmToken::Integer) && isFconst) {
Jim Grosbache7fbce72011-10-03 23:38:36 +00005083 int64_t Val = Tok.getIntVal();
5084 Parser.Lex(); // Eat the token.
5085 if (Val > 255 || Val < 0) {
Jim Grosbach235c8d22012-01-19 02:47:30 +00005086 Error(Loc, "encoded floating point value out of range");
Jim Grosbache7fbce72011-10-03 23:38:36 +00005087 return MatchOperand_ParseFail;
5088 }
David Peixottoa872e0e2014-01-07 18:19:23 +00005089 float RealVal = ARM_AM::getFPImmFloat(Val);
5090 Val = APFloat(RealVal).bitcastToAPInt().getZExtValue();
5091
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005092 Operands.push_back(ARMOperand::CreateImm(
5093 MCConstantExpr::Create(Val, getContext()), S,
5094 Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00005095 return MatchOperand_Success;
5096 }
5097
Jim Grosbach235c8d22012-01-19 02:47:30 +00005098 Error(Loc, "invalid floating point immediate");
Jim Grosbache7fbce72011-10-03 23:38:36 +00005099 return MatchOperand_ParseFail;
5100}
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00005101
Kevin Enderby8be42bd2009-10-30 22:55:57 +00005102/// Parse a arm instruction operand. For now this parses the operand regardless
5103/// of the mnemonic.
David Blaikie960ea3f2014-06-08 16:18:35 +00005104bool ARMAsmParser::parseOperand(OperandVector &Operands, StringRef Mnemonic) {
Rafael Espindola961d4692014-11-11 05:18:41 +00005105 MCAsmParser &Parser = getParser();
Sean Callanan7ad0ad02010-04-02 22:27:05 +00005106 SMLoc S, E;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00005107
5108 // Check if the current operand has a custom associated parser, if so, try to
5109 // custom parse the operand, or fallback to the general approach.
Jim Grosbach861e49c2011-02-12 01:34:40 +00005110 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
5111 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00005112 return false;
Jim Grosbach861e49c2011-02-12 01:34:40 +00005113 // If there wasn't a custom match, try the generic matcher below. Otherwise,
5114 // there was a match, but an error occurred, in which case, just return that
5115 // the operand parsing failed.
5116 if (ResTy == MatchOperand_ParseFail)
5117 return true;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00005118
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005119 switch (getLexer().getKind()) {
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005120 default:
5121 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling2063b842010-11-18 23:43:05 +00005122 return true;
Jim Grosbachbb24c592011-07-13 18:49:30 +00005123 case AsmToken::Identifier: {
Chad Rosierb162a5c2013-03-19 23:44:03 +00005124 // If we've seen a branch mnemonic, the next operand must be a label. This
5125 // is true even if the label is a register name. So "br r1" means branch to
5126 // label "r1".
5127 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
5128 if (!ExpectLabel) {
5129 if (!tryParseRegisterWithWriteBack(Operands))
5130 return false;
5131 int Res = tryParseShiftRegister(Operands);
5132 if (Res == 0) // success
5133 return false;
5134 else if (Res == -1) // irrecoverable error
5135 return true;
5136 // If this is VMRS, check for the apsr_nzcv operand.
5137 if (Mnemonic == "vmrs" &&
5138 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
5139 S = Parser.getTok().getLoc();
5140 Parser.Lex();
5141 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
5142 return false;
5143 }
Jim Grosbach4ab23b52011-10-03 21:12:43 +00005144 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00005145
5146 // Fall though for the Identifier case that is not a register or a
5147 // special name.
Jim Grosbachbb24c592011-07-13 18:49:30 +00005148 }
Jim Grosbach4e380352011-10-26 21:14:08 +00005149 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderbyb084be92011-01-13 20:32:36 +00005150 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach5c6b6342011-11-01 22:38:31 +00005151 case AsmToken::String: // quoted label names.
Kevin Enderbyb084be92011-01-13 20:32:36 +00005152 case AsmToken::Dot: { // . as a branch target
Kevin Enderby146dcf22009-10-15 20:48:48 +00005153 // This was not a register so parse other operands that start with an
5154 // identifier (like labels) as expressions and create them as immediates.
5155 const MCExpr *IdVal;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00005156 S = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005157 if (getParser().parseExpression(IdVal))
Bill Wendling2063b842010-11-18 23:43:05 +00005158 return true;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00005159 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling2063b842010-11-18 23:43:05 +00005160 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
5161 return false;
5162 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005163 case AsmToken::LBrac:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005164 return parseMemory(Operands);
Kevin Enderbya2b99102009-10-09 21:12:28 +00005165 case AsmToken::LCurly:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005166 return parseRegisterList(Operands);
Jim Grosbachef70e9b2011-12-09 22:25:03 +00005167 case AsmToken::Dollar:
Owen Andersonf02d98d2011-08-29 17:17:09 +00005168 case AsmToken::Hash: {
Kevin Enderby3a80dac2009-10-13 23:33:38 +00005169 // #42 -> immediate.
Sean Callanan7ad0ad02010-04-02 22:27:05 +00005170 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00005171 Parser.Lex();
Jim Grosbach003607f2012-04-16 21:18:46 +00005172
5173 if (Parser.getTok().isNot(AsmToken::Colon)) {
5174 bool isNegative = Parser.getTok().is(AsmToken::Minus);
5175 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005176 if (getParser().parseExpression(ImmVal))
Jim Grosbach003607f2012-04-16 21:18:46 +00005177 return true;
5178 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
5179 if (CE) {
5180 int32_t Val = CE->getValue();
5181 if (isNegative && Val == 0)
5182 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
5183 }
5184 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
5185 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
Jim Grosbach9be2d712013-02-23 00:52:09 +00005186
5187 // There can be a trailing '!' on operands that we want as a separate
Saleem Abdulrasool83e37702013-12-28 03:07:12 +00005188 // '!' Token operand. Handle that here. For example, the compatibility
Jim Grosbach9be2d712013-02-23 00:52:09 +00005189 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
5190 if (Parser.getTok().is(AsmToken::Exclaim)) {
5191 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
5192 Parser.getTok().getLoc()));
5193 Parser.Lex(); // Eat exclaim token
5194 }
Jim Grosbach003607f2012-04-16 21:18:46 +00005195 return false;
Owen Andersonf02d98d2011-08-29 17:17:09 +00005196 }
Jim Grosbach003607f2012-04-16 21:18:46 +00005197 // w/ a ':' after the '#', it's just like a plain ':'.
5198 // FALLTHROUGH
Owen Andersonf02d98d2011-08-29 17:17:09 +00005199 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00005200 case AsmToken::Colon: {
5201 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng965b3c72011-01-13 07:58:56 +00005202 // FIXME: Check it's an expression prefix,
5203 // e.g. (FOO - :lower16:BAR) isn't legal.
5204 ARMMCExpr::VariantKind RefKind;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005205 if (parsePrefix(RefKind))
Jason W Kim1f7bc072011-01-11 23:53:41 +00005206 return true;
5207
Evan Cheng965b3c72011-01-13 07:58:56 +00005208 const MCExpr *SubExprVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005209 if (getParser().parseExpression(SubExprVal))
Jason W Kim1f7bc072011-01-11 23:53:41 +00005210 return true;
5211
Evan Cheng965b3c72011-01-13 07:58:56 +00005212 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach9659ed92012-09-21 00:26:53 +00005213 getContext());
Jason W Kim1f7bc072011-01-11 23:53:41 +00005214 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng965b3c72011-01-13 07:58:56 +00005215 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim1f7bc072011-01-11 23:53:41 +00005216 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005217 }
David Peixottoe407d092013-12-19 18:12:36 +00005218 case AsmToken::Equal: {
5219 if (Mnemonic != "ldr") // only parse for ldr pseudo (e.g. ldr r0, =val)
5220 return Error(Parser.getTok().getLoc(), "unexpected token in operand");
5221
David Peixottoe407d092013-12-19 18:12:36 +00005222 Parser.Lex(); // Eat '='
5223 const MCExpr *SubExprVal;
5224 if (getParser().parseExpression(SubExprVal))
5225 return true;
5226 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
5227
David Peixottob9b73622014-02-04 17:22:40 +00005228 const MCExpr *CPLoc = getTargetStreamer().addConstantPoolEntry(SubExprVal);
David Peixottoe407d092013-12-19 18:12:36 +00005229 Operands.push_back(ARMOperand::CreateImm(CPLoc, S, E));
5230 return false;
5231 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00005232 }
5233}
5234
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005235// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng965b3c72011-01-13 07:58:56 +00005236// :lower16: and :upper16:.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005237bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Rafael Espindola961d4692014-11-11 05:18:41 +00005238 MCAsmParser &Parser = getParser();
Evan Cheng965b3c72011-01-13 07:58:56 +00005239 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim1f7bc072011-01-11 23:53:41 +00005240
Saleem Abdulrasool435f4562014-01-10 04:38:40 +00005241 // consume an optional '#' (GNU compatibility)
5242 if (getLexer().is(AsmToken::Hash))
5243 Parser.Lex();
5244
Jason W Kim1f7bc072011-01-11 23:53:41 +00005245 // :lower16: and :upper16: modifiers
Jason W Kim93229972011-01-13 00:27:00 +00005246 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim1f7bc072011-01-11 23:53:41 +00005247 Parser.Lex(); // Eat ':'
5248
5249 if (getLexer().isNot(AsmToken::Identifier)) {
5250 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
5251 return true;
5252 }
5253
Saleem Abdulrasoolfaa4f072015-01-13 03:22:49 +00005254 enum {
5255 COFF = (1 << MCObjectFileInfo::IsCOFF),
5256 ELF = (1 << MCObjectFileInfo::IsELF),
5257 MACHO = (1 << MCObjectFileInfo::IsMachO)
5258 };
5259 static const struct PrefixEntry {
5260 const char *Spelling;
5261 ARMMCExpr::VariantKind VariantKind;
5262 uint8_t SupportedFormats;
5263 } PrefixEntries[] = {
5264 { "lower16", ARMMCExpr::VK_ARM_LO16, COFF | ELF | MACHO },
5265 { "upper16", ARMMCExpr::VK_ARM_HI16, COFF | ELF | MACHO },
5266 };
5267
Jason W Kim1f7bc072011-01-11 23:53:41 +00005268 StringRef IDVal = Parser.getTok().getIdentifier();
Saleem Abdulrasoolfaa4f072015-01-13 03:22:49 +00005269
5270 const auto &Prefix =
5271 std::find_if(std::begin(PrefixEntries), std::end(PrefixEntries),
5272 [&IDVal](const PrefixEntry &PE) {
5273 return PE.Spelling == IDVal;
5274 });
5275 if (Prefix == std::end(PrefixEntries)) {
Jason W Kim1f7bc072011-01-11 23:53:41 +00005276 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
5277 return true;
5278 }
Saleem Abdulrasoolfaa4f072015-01-13 03:22:49 +00005279
5280 uint8_t CurrentFormat;
5281 switch (getContext().getObjectFileInfo()->getObjectFileType()) {
5282 case MCObjectFileInfo::IsMachO:
5283 CurrentFormat = MACHO;
5284 break;
5285 case MCObjectFileInfo::IsELF:
5286 CurrentFormat = ELF;
5287 break;
5288 case MCObjectFileInfo::IsCOFF:
5289 CurrentFormat = COFF;
5290 break;
5291 }
5292
5293 if (~Prefix->SupportedFormats & CurrentFormat) {
5294 Error(Parser.getTok().getLoc(),
5295 "cannot represent relocation in the current file format");
5296 return true;
5297 }
5298
5299 RefKind = Prefix->VariantKind;
Jason W Kim1f7bc072011-01-11 23:53:41 +00005300 Parser.Lex();
5301
5302 if (getLexer().isNot(AsmToken::Colon)) {
5303 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
5304 return true;
5305 }
5306 Parser.Lex(); // Eat the last ':'
Saleem Abdulrasoolfaa4f072015-01-13 03:22:49 +00005307
Jason W Kim1f7bc072011-01-11 23:53:41 +00005308 return false;
5309}
5310
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005311/// \brief Given a mnemonic, split out possible predication code and carry
5312/// setting letters to form a canonical mnemonic and flags.
5313//
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005314// FIXME: Would be nice to autogen this.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005315// FIXME: This is a bit of a maze of special cases.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005316StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00005317 unsigned &PredicationCode,
5318 bool &CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005319 unsigned &ProcessorIMod,
5320 StringRef &ITMask) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005321 PredicationCode = ARMCC::AL;
5322 CarrySetting = false;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005323 ProcessorIMod = 0;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005324
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005325 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005326 //
5327 // FIXME: Would be nice to autogen this.
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00005328 if ((Mnemonic == "movs" && isThumb()) ||
5329 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
5330 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
5331 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
5332 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
Richard Barton8d519fe2013-09-05 14:14:19 +00005333 Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00005334 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
5335 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbache16acac2011-12-19 19:43:50 +00005336 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
Joey Gouly2efaa732013-07-06 20:50:18 +00005337 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00005338 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
5339 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
Charlie Turner4d88ae22014-12-01 08:33:28 +00005340 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic == "hvc" ||
5341 Mnemonic.startswith("vsel"))
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005342 return Mnemonic;
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005343
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00005344 // First, split out any predication code. Ignore mnemonics we know aren't
5345 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbach8d114902011-07-20 18:20:31 +00005346 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach0c398b92011-07-27 21:58:11 +00005347 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach3636be32011-08-22 23:55:58 +00005348 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbachf6d5d602011-09-01 18:22:13 +00005349 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00005350 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
5351 .Case("eq", ARMCC::EQ)
5352 .Case("ne", ARMCC::NE)
5353 .Case("hs", ARMCC::HS)
5354 .Case("cs", ARMCC::HS)
5355 .Case("lo", ARMCC::LO)
5356 .Case("cc", ARMCC::LO)
5357 .Case("mi", ARMCC::MI)
5358 .Case("pl", ARMCC::PL)
5359 .Case("vs", ARMCC::VS)
5360 .Case("vc", ARMCC::VC)
5361 .Case("hi", ARMCC::HI)
5362 .Case("ls", ARMCC::LS)
5363 .Case("ge", ARMCC::GE)
5364 .Case("lt", ARMCC::LT)
5365 .Case("gt", ARMCC::GT)
5366 .Case("le", ARMCC::LE)
5367 .Case("al", ARMCC::AL)
5368 .Default(~0U);
5369 if (CC != ~0U) {
5370 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
5371 PredicationCode = CC;
5372 }
Bill Wendling193961b2010-10-29 23:50:21 +00005373 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005374
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005375 // Next, determine if we have a carry setting bit. We explicitly ignore all
5376 // the instructions we know end in 's'.
5377 if (Mnemonic.endswith("s") &&
Jim Grosbachd3e8e292011-08-17 22:49:09 +00005378 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00005379 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
5380 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
5381 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach086d0132011-12-08 00:49:29 +00005382 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach54337b82011-12-10 00:01:02 +00005383 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach92a939a2011-12-19 19:02:41 +00005384 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbachd74560b2012-03-15 20:48:18 +00005385 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
David Peixottoa872e0e2014-01-07 18:19:23 +00005386 Mnemonic == "vfms" || Mnemonic == "vfnms" || Mnemonic == "fconsts" ||
Jim Grosbach51726e22011-07-29 20:26:09 +00005387 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005388 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
5389 CarrySetting = true;
5390 }
5391
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005392 // The "cps" instruction can have a interrupt mode operand which is glued into
5393 // the mnemonic. Check if this is the case, split it and parse the imod op
5394 if (Mnemonic.startswith("cps")) {
5395 // Split out any imod code.
5396 unsigned IMod =
5397 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
5398 .Case("ie", ARM_PROC::IE)
5399 .Case("id", ARM_PROC::ID)
5400 .Default(~0U);
5401 if (IMod != ~0U) {
5402 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
5403 ProcessorIMod = IMod;
5404 }
5405 }
5406
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005407 // The "it" instruction has the condition mask on the end of the mnemonic.
5408 if (Mnemonic.startswith("it")) {
5409 ITMask = Mnemonic.slice(2, Mnemonic.size());
5410 Mnemonic = Mnemonic.slice(0, 2);
5411 }
5412
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005413 return Mnemonic;
5414}
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005415
5416/// \brief Given a canonical mnemonic, determine if the instruction ever allows
5417/// inclusion of carry set or predication code operands.
5418//
5419// FIXME: It would be nice to autogen this.
Alexander Kornienkofb37cfa2015-04-14 15:32:58 +00005420void ARMAsmParser::getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
5421 bool &CanAcceptCarrySet,
5422 bool &CanAcceptPredicationCode) {
5423 CanAcceptCarrySet =
5424 Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00005425 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Alexander Kornienkofb37cfa2015-04-14 15:32:58 +00005426 Mnemonic == "add" || Mnemonic == "adc" || Mnemonic == "mul" ||
5427 Mnemonic == "bic" || Mnemonic == "asr" || Mnemonic == "orr" ||
5428 Mnemonic == "mvn" || Mnemonic == "rsb" || Mnemonic == "rsc" ||
5429 Mnemonic == "orn" || Mnemonic == "sbc" || Mnemonic == "eor" ||
5430 Mnemonic == "neg" || Mnemonic == "vfm" || Mnemonic == "vfnm" ||
5431 (!isThumb() &&
5432 (Mnemonic == "smull" || Mnemonic == "mov" || Mnemonic == "mla" ||
5433 Mnemonic == "smlal" || Mnemonic == "umlal" || Mnemonic == "umull"));
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005434
Tim Northover2c45a382013-06-26 16:52:40 +00005435 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
Alexander Kornienkofb37cfa2015-04-14 15:32:58 +00005436 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
Saleem Abdulrasool27351f22014-05-14 03:47:39 +00005437 Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic == "udf" ||
5438 Mnemonic.startswith("crc32") || Mnemonic.startswith("cps") ||
Alexander Kornienkofb37cfa2015-04-14 15:32:58 +00005439 Mnemonic.startswith("vsel") || Mnemonic == "vmaxnm" ||
5440 Mnemonic == "vminnm" || Mnemonic == "vcvta" || Mnemonic == "vcvtn" ||
5441 Mnemonic == "vcvtp" || Mnemonic == "vcvtm" || Mnemonic == "vrinta" ||
5442 Mnemonic == "vrintn" || Mnemonic == "vrintp" || Mnemonic == "vrintm" ||
Vladimir Sukharev0e0f8d22015-04-16 11:34:25 +00005443 Mnemonic.startswith("aes") || Mnemonic == "hvc" || Mnemonic == "setpan" ||
Amara Emerson33089092013-09-19 11:59:01 +00005444 Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") ||
5445 (FullInst.startswith("vmull") && FullInst.endswith(".p64"))) {
Tim Northover2c45a382013-06-26 16:52:40 +00005446 // These mnemonics are never predicable
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005447 CanAcceptPredicationCode = false;
Tim Northover2c45a382013-06-26 16:52:40 +00005448 } else if (!isThumb()) {
5449 // Some instructions are only predicable in Thumb mode
Alexander Kornienkofb37cfa2015-04-14 15:32:58 +00005450 CanAcceptPredicationCode =
5451 Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
Tim Northover2c45a382013-06-26 16:52:40 +00005452 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
5453 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
5454 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
Alexander Kornienkofb37cfa2015-04-14 15:32:58 +00005455 Mnemonic != "ldc2" && Mnemonic != "ldc2l" && Mnemonic != "stc2" &&
5456 Mnemonic != "stc2l" && !Mnemonic.startswith("rfe") &&
5457 !Mnemonic.startswith("srs");
Tim Northover2c45a382013-06-26 16:52:40 +00005458 } else if (isThumbOne()) {
Tim Northoverf86d1f02013-10-07 11:10:47 +00005459 if (hasV6MOps())
5460 CanAcceptPredicationCode = Mnemonic != "movs";
5461 else
5462 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
Jim Grosbach6c45b752011-09-16 16:39:25 +00005463 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005464 CanAcceptPredicationCode = true;
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005465}
5466
Jim Grosbach7283da92011-08-16 21:12:37 +00005467bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
David Blaikie960ea3f2014-06-08 16:18:35 +00005468 OperandVector &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005469 // FIXME: This is all horribly hacky. We really need a better way to deal
5470 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00005471
5472 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
5473 // another does not. Specifically, the MOVW instruction does not. So we
5474 // special case it here and remove the defaulted (non-setting) cc_out
5475 // operand if that's the instruction we're trying to match.
5476 //
5477 // We do this as post-processing of the explicit operands rather than just
5478 // conditionally adding the cc_out in the first place because we need
5479 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00005480 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Asiri Rathnayake52376ac2015-01-06 15:55:09 +00005481 !static_cast<ARMOperand &>(*Operands[4]).isModImm() &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005482 static_cast<ARMOperand &>(*Operands[4]).isImm0_65535Expr() &&
5483 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0)
Jim Grosbach7283da92011-08-16 21:12:37 +00005484 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005485
5486 // Register-register 'add' for thumb does not have a cc_out operand
5487 // when there are only two register operands.
5488 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005489 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5490 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5491 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0)
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005492 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005493 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005494 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
5495 // have to check the immediate range here since Thumb2 has a variant
5496 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005497 if (((isThumb() && Mnemonic == "add") ||
5498 (isThumbTwo() && Mnemonic == "sub")) &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005499 Operands.size() == 6 && static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5500 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5501 static_cast<ARMOperand &>(*Operands[4]).getReg() == ARM::SP &&
5502 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5503 ((Mnemonic == "add" && static_cast<ARMOperand &>(*Operands[5]).isReg()) ||
5504 static_cast<ARMOperand &>(*Operands[5]).isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005505 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005506 // For Thumb2, add/sub immediate does not have a cc_out operand for the
5507 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005508 // selecting via the generic "add" mnemonic, so to know that we
5509 // should remove the cc_out operand, we have to explicitly check that
5510 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00005511 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005512 Operands.size() == 6 && static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5513 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5514 static_cast<ARMOperand &>(*Operands[5]).isImm()) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005515 // Nest conditions rather than one big 'if' statement for readability.
5516 //
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005517 // If both registers are low, we're in an IT block, and the immediate is
5518 // in range, we should use encoding T1 instead, which has a cc_out.
5519 if (inITBlock() &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005520 isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) &&
5521 isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) &&
5522 static_cast<ARMOperand &>(*Operands[5]).isImm0_7())
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005523 return false;
Tilmann Schelleref5666f2013-07-03 20:38:01 +00005524 // Check against T3. If the second register is the PC, this is an
5525 // alternate form of ADR, which uses encoding T4, so check for that too.
David Blaikie960ea3f2014-06-08 16:18:35 +00005526 if (static_cast<ARMOperand &>(*Operands[4]).getReg() != ARM::PC &&
5527 static_cast<ARMOperand &>(*Operands[5]).isT2SOImm())
Tilmann Schelleref5666f2013-07-03 20:38:01 +00005528 return false;
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005529
5530 // Otherwise, we use encoding T4, which does not have a cc_out
5531 // operand.
5532 return true;
5533 }
5534
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005535 // The thumb2 multiply instruction doesn't have a CCOut register, so
5536 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
5537 // use the 16-bit encoding or not.
5538 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005539 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5540 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5541 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5542 static_cast<ARMOperand &>(*Operands[5]).isReg() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005543 // If the registers aren't low regs, the destination reg isn't the
5544 // same as one of the source regs, or the cc_out operand is zero
5545 // outside of an IT block, we have to use the 32-bit encoding, so
5546 // remove the cc_out operand.
David Blaikie960ea3f2014-06-08 16:18:35 +00005547 (!isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) ||
5548 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) ||
5549 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[5]).getReg()) ||
5550 !inITBlock() || (static_cast<ARMOperand &>(*Operands[3]).getReg() !=
5551 static_cast<ARMOperand &>(*Operands[5]).getReg() &&
5552 static_cast<ARMOperand &>(*Operands[3]).getReg() !=
5553 static_cast<ARMOperand &>(*Operands[4]).getReg())))
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005554 return true;
5555
Jim Grosbachefa7e952011-11-15 19:55:16 +00005556 // Also check the 'mul' syntax variant that doesn't specify an explicit
5557 // destination register.
5558 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005559 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5560 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5561 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
Jim Grosbachefa7e952011-11-15 19:55:16 +00005562 // If the registers aren't low regs or the cc_out operand is zero
5563 // outside of an IT block, we have to use the 32-bit encoding, so
5564 // remove the cc_out operand.
David Blaikie960ea3f2014-06-08 16:18:35 +00005565 (!isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) ||
5566 !isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) ||
Jim Grosbachefa7e952011-11-15 19:55:16 +00005567 !inITBlock()))
5568 return true;
5569
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005570
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005571
Jim Grosbach4b701af2011-08-24 21:42:27 +00005572 // Register-register 'add/sub' for thumb does not have a cc_out operand
5573 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
5574 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
5575 // right, this will result in better diagnostics (which operand is off)
5576 // anyway.
5577 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
5578 (Operands.size() == 5 || Operands.size() == 6) &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005579 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5580 static_cast<ARMOperand &>(*Operands[3]).getReg() == ARM::SP &&
5581 static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 &&
5582 (static_cast<ARMOperand &>(*Operands[4]).isImm() ||
Jim Grosbachdf5a2442012-04-10 17:31:55 +00005583 (Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005584 static_cast<ARMOperand &>(*Operands[5]).isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005585 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005586
Jim Grosbach7283da92011-08-16 21:12:37 +00005587 return false;
5588}
5589
David Blaikie960ea3f2014-06-08 16:18:35 +00005590bool ARMAsmParser::shouldOmitPredicateOperand(StringRef Mnemonic,
5591 OperandVector &Operands) {
Joey Goulye8602552013-07-19 16:34:16 +00005592 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
5593 unsigned RegIdx = 3;
5594 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005595 static_cast<ARMOperand &>(*Operands[2]).getToken() == ".f32") {
5596 if (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
5597 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".f32")
Joey Goulye8602552013-07-19 16:34:16 +00005598 RegIdx = 4;
5599
David Blaikie960ea3f2014-06-08 16:18:35 +00005600 if (static_cast<ARMOperand &>(*Operands[RegIdx]).isReg() &&
5601 (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(
5602 static_cast<ARMOperand &>(*Operands[RegIdx]).getReg()) ||
5603 ARMMCRegisterClasses[ARM::QPRRegClassID].contains(
5604 static_cast<ARMOperand &>(*Operands[RegIdx]).getReg())))
Joey Goulye8602552013-07-19 16:34:16 +00005605 return true;
5606 }
Joey Goulyf520d5e2013-07-19 16:45:16 +00005607 return false;
Joey Goulye8602552013-07-19 16:34:16 +00005608}
5609
Jim Grosbach12952fe2011-11-11 23:08:10 +00005610static bool isDataTypeToken(StringRef Tok) {
5611 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
5612 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
5613 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
5614 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
5615 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
5616 Tok == ".f" || Tok == ".d";
5617}
5618
5619// FIXME: This bit should probably be handled via an explicit match class
5620// in the .td files that matches the suffix instead of having it be
5621// a literal string token the way it is now.
5622static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
5623 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
5624}
Tim Northover26bb14e2014-08-18 11:49:42 +00005625static void applyMnemonicAliases(StringRef &Mnemonic, uint64_t Features,
Chad Rosier9f7a2212013-04-18 22:35:36 +00005626 unsigned VariantID);
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005627
5628static bool RequiresVFPRegListValidation(StringRef Inst,
5629 bool &AcceptSinglePrecisionOnly,
5630 bool &AcceptDoublePrecisionOnly) {
5631 if (Inst.size() < 7)
5632 return false;
5633
5634 if (Inst.startswith("fldm") || Inst.startswith("fstm")) {
5635 StringRef AddressingMode = Inst.substr(4, 2);
5636 if (AddressingMode == "ia" || AddressingMode == "db" ||
5637 AddressingMode == "ea" || AddressingMode == "fd") {
5638 AcceptSinglePrecisionOnly = Inst[6] == 's';
5639 AcceptDoublePrecisionOnly = Inst[6] == 'd' || Inst[6] == 'x';
5640 return true;
5641 }
5642 }
5643
5644 return false;
5645}
5646
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005647/// Parse an arm instruction mnemonic followed by its operands.
Chad Rosierf0e87202012-10-25 20:41:34 +00005648bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
David Blaikie960ea3f2014-06-08 16:18:35 +00005649 SMLoc NameLoc, OperandVector &Operands) {
Rafael Espindola961d4692014-11-11 05:18:41 +00005650 MCAsmParser &Parser = getParser();
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005651 // FIXME: Can this be done via tablegen in some fashion?
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005652 bool RequireVFPRegisterListCheck;
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005653 bool AcceptSinglePrecisionOnly;
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005654 bool AcceptDoublePrecisionOnly;
5655 RequireVFPRegisterListCheck =
5656 RequiresVFPRegListValidation(Name, AcceptSinglePrecisionOnly,
5657 AcceptDoublePrecisionOnly);
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005658
Jim Grosbach8be2f652011-12-09 23:34:09 +00005659 // Apply mnemonic aliases before doing anything else, as the destination
Saleem Abdulrasoola1937cb2013-12-29 17:58:31 +00005660 // mnemonic may include suffices and we want to handle them normally.
Jim Grosbach8be2f652011-12-09 23:34:09 +00005661 // The generic tblgen'erated code does this later, at the start of
5662 // MatchInstructionImpl(), but that's too late for aliases that include
5663 // any sort of suffix.
Tim Northover26bb14e2014-08-18 11:49:42 +00005664 uint64_t AvailableFeatures = getAvailableFeatures();
Chad Rosier9f7a2212013-04-18 22:35:36 +00005665 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5666 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
Jim Grosbach8be2f652011-12-09 23:34:09 +00005667
Jim Grosbachab5830e2011-12-14 02:16:11 +00005668 // First check for the ARM-specific .req directive.
5669 if (Parser.getTok().is(AsmToken::Identifier) &&
5670 Parser.getTok().getIdentifier() == ".req") {
5671 parseDirectiveReq(Name, NameLoc);
5672 // We always return 'error' for this, as we're done with this
5673 // statement and don't need to match the 'instruction."
5674 return true;
5675 }
5676
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005677 // Create the leading tokens for the mnemonic, split by '.' characters.
5678 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005679 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005680
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005681 // Split out the predication code and carry setting flag from the mnemonic.
5682 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005683 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005684 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005685 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005686 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005687 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005688
Jim Grosbach1c171b12011-08-25 17:23:55 +00005689 // In Thumb1, only the branch (B) instruction can be predicated.
5690 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005691 Parser.eatToEndOfStatement();
Jim Grosbach1c171b12011-08-25 17:23:55 +00005692 return Error(NameLoc, "conditional execution not supported in Thumb1");
5693 }
5694
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005695 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5696
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005697 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5698 // is the mask as it will be for the IT encoding if the conditional
5699 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5700 // where the conditional bit0 is zero, the instruction post-processing
5701 // will adjust the mask accordingly.
5702 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00005703 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5704 if (ITMask.size() > 3) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005705 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005706 return Error(Loc, "too many conditions on IT instruction");
5707 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005708 unsigned Mask = 8;
5709 for (unsigned i = ITMask.size(); i != 0; --i) {
5710 char pos = ITMask[i - 1];
5711 if (pos != 't' && pos != 'e') {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005712 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005713 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005714 }
5715 Mask >>= 1;
5716 if (ITMask[i - 1] == 't')
5717 Mask |= 8;
5718 }
Jim Grosbached16ec42011-08-29 22:24:09 +00005719 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005720 }
5721
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005722 // FIXME: This is all a pretty gross hack. We should automatically handle
5723 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00005724
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005725 // Next, add the CCOut and ConditionCode operands, if needed.
5726 //
5727 // For mnemonics which can ever incorporate a carry setting bit or predication
5728 // code, our matching model involves us always generating CCOut and
5729 // ConditionCode operands to match the mnemonic "as written" and then we let
5730 // the matcher deal with finding the right instruction or generating an
5731 // appropriate error.
5732 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Amara Emerson33089092013-09-19 11:59:01 +00005733 getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005734
Jim Grosbach03a8a162011-07-14 22:04:21 +00005735 // If we had a carry-set on an instruction that can't do that, issue an
5736 // error.
5737 if (!CanAcceptCarrySet && CarrySetting) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005738 Parser.eatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005739 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00005740 "' can not set flags, but 's' suffix specified");
5741 }
Jim Grosbach0a547702011-07-22 17:44:50 +00005742 // If we had a predication code on an instruction that can't do that, issue an
5743 // error.
5744 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005745 Parser.eatToEndOfStatement();
Jim Grosbach0a547702011-07-22 17:44:50 +00005746 return Error(NameLoc, "instruction '" + Mnemonic +
5747 "' is not predicable, but condition code specified");
5748 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00005749
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005750 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00005751 if (CanAcceptCarrySet) {
5752 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005753 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00005754 Loc));
5755 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005756
5757 // Add the predication code operand, if necessary.
5758 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005759 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5760 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005761 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00005762 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005763 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005764
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005765 // Add the processor imod operand, if necessary.
5766 if (ProcessorIMod) {
5767 Operands.push_back(ARMOperand::CreateImm(
5768 MCConstantExpr::Create(ProcessorIMod, getContext()),
5769 NameLoc, NameLoc));
Oliver Stannard1ae8b472014-09-24 14:20:01 +00005770 } else if (Mnemonic == "cps" && isMClass()) {
5771 return Error(NameLoc, "instruction 'cps' requires effect for M-class");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005772 }
5773
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005774 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005775 while (Next != StringRef::npos) {
5776 Start = Next;
5777 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005778 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005779
Jim Grosbach12952fe2011-11-11 23:08:10 +00005780 // Some NEON instructions have an optional datatype suffix that is
5781 // completely ignored. Check for that.
5782 if (isDataTypeToken(ExtraToken) &&
5783 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5784 continue;
5785
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005786 // For for ARM mode generate an error if the .n qualifier is used.
5787 if (ExtraToken == ".n" && !isThumb()) {
5788 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
Saleem Abdulrasoolbdae4b82014-01-12 05:25:44 +00005789 Parser.eatToEndOfStatement();
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005790 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5791 "arm mode");
5792 }
5793
5794 // The .n qualifier is always discarded as that is what the tables
5795 // and matcher expect. In ARM mode the .w qualifier has no effect,
5796 // so discard it to avoid errors that can be caused by the matcher.
5797 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00005798 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5799 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5800 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005801 }
5802
5803 // Read the remaining operands.
5804 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005805 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005806 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005807 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005808 return true;
5809 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005810
5811 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005812 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005813
5814 // Parse and remember the operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005815 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005816 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005817 return true;
5818 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005819 }
5820 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005821
Chris Lattnera2a9d162010-09-11 16:18:25 +00005822 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005823 SMLoc Loc = getLexer().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005824 Parser.eatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005825 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005826 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005827
Chris Lattner91689c12010-09-08 05:10:46 +00005828 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005829
Saleem Abdulrasoole3a9dc12013-12-30 18:38:01 +00005830 if (RequireVFPRegisterListCheck) {
David Blaikie960ea3f2014-06-08 16:18:35 +00005831 ARMOperand &Op = static_cast<ARMOperand &>(*Operands.back());
5832 if (AcceptSinglePrecisionOnly && !Op.isSPRRegList())
5833 return Error(Op.getStartLoc(),
Saleem Abdulrasoolaca443c2013-12-29 18:53:16 +00005834 "VFP/Neon single precision register expected");
David Blaikie960ea3f2014-06-08 16:18:35 +00005835 if (AcceptDoublePrecisionOnly && !Op.isDPRRegList())
5836 return Error(Op.getStartLoc(),
Saleem Abdulrasoolaca443c2013-12-29 18:53:16 +00005837 "VFP/Neon double precision register expected");
Saleem Abdulrasool4da9c6e2013-12-29 17:58:35 +00005838 }
5839
Jim Grosbach7283da92011-08-16 21:12:37 +00005840 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5841 // do and don't have a cc_out optional-def operand. With some spot-checks
5842 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005843 // parse and adjust accordingly before actually matching. We shouldn't ever
5844 // try to remove a cc_out operand that was explicitly set on the the
5845 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5846 // table driven matcher doesn't fit well with the ARM instruction set.
David Blaikie960ea3f2014-06-08 16:18:35 +00005847 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands))
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005848 Operands.erase(Operands.begin() + 1);
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005849
Joey Goulye8602552013-07-19 16:34:16 +00005850 // Some instructions have the same mnemonic, but don't always
5851 // have a predicate. Distinguish them here and delete the
5852 // predicate if needed.
David Blaikie960ea3f2014-06-08 16:18:35 +00005853 if (shouldOmitPredicateOperand(Mnemonic, Operands))
Joey Goulye8602552013-07-19 16:34:16 +00005854 Operands.erase(Operands.begin() + 1);
Joey Goulye8602552013-07-19 16:34:16 +00005855
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005856 // ARM mode 'blx' need special handling, as the register operand version
5857 // is predicable, but the label operand version is not. So, we can't rely
5858 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005859 // a k_CondCode operand in the list. If we're trying to match the label
5860 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005861 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005862 static_cast<ARMOperand &>(*Operands[2]).isImm())
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005863 Operands.erase(Operands.begin() + 1);
Jim Grosbach8cffa282011-08-11 23:51:13 +00005864
Weiming Zhao8f56f882012-11-16 21:55:34 +00005865 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5866 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5867 // a single GPRPair reg operand is used in the .td file to replace the two
5868 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5869 // expressed as a GPRPair, so we have to manually merge them.
5870 // FIXME: We would really like to be able to tablegen'erate this.
5871 if (!isThumb() && Operands.size() > 4 &&
Joey Goulye6d165c2013-08-27 17:38:16 +00005872 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
5873 Mnemonic == "stlexd")) {
5874 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
Weiming Zhao8f56f882012-11-16 21:55:34 +00005875 unsigned Idx = isLoad ? 2 : 3;
David Blaikie960ea3f2014-06-08 16:18:35 +00005876 ARMOperand &Op1 = static_cast<ARMOperand &>(*Operands[Idx]);
5877 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[Idx + 1]);
Weiming Zhao8f56f882012-11-16 21:55:34 +00005878
5879 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5880 // Adjust only if Op1 and Op2 are GPRs.
David Blaikie960ea3f2014-06-08 16:18:35 +00005881 if (Op1.isReg() && Op2.isReg() && MRC.contains(Op1.getReg()) &&
5882 MRC.contains(Op2.getReg())) {
5883 unsigned Reg1 = Op1.getReg();
5884 unsigned Reg2 = Op2.getReg();
Weiming Zhao8f56f882012-11-16 21:55:34 +00005885 unsigned Rt = MRI->getEncodingValue(Reg1);
5886 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5887
5888 // Rt2 must be Rt + 1 and Rt must be even.
5889 if (Rt + 1 != Rt2 || (Rt & 1)) {
David Blaikie960ea3f2014-06-08 16:18:35 +00005890 Error(Op2.getStartLoc(), isLoad
5891 ? "destination operands must be sequential"
5892 : "source operands must be sequential");
Weiming Zhao8f56f882012-11-16 21:55:34 +00005893 return true;
5894 }
5895 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5896 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
David Blaikie960ea3f2014-06-08 16:18:35 +00005897 Operands[Idx] =
5898 ARMOperand::CreateReg(NewReg, Op1.getStartLoc(), Op2.getEndLoc());
5899 Operands.erase(Operands.begin() + Idx + 1);
Weiming Zhao8f56f882012-11-16 21:55:34 +00005900 }
5901 }
5902
Renato Golin36c626e2014-09-26 16:14:29 +00005903 // If first 2 operands of a 3 operand instruction are the same
5904 // then transform to 2 operand version of the same instruction
5905 // e.g. 'adds r0, r0, #1' transforms to 'adds r0, #1'
5906 // FIXME: We would really like to be able to tablegen'erate this.
5907 if (isThumbOne() && Operands.size() == 6 &&
5908 (Mnemonic == "add" || Mnemonic == "sub" || Mnemonic == "and" ||
5909 Mnemonic == "eor" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
5910 Mnemonic == "asr" || Mnemonic == "adc" || Mnemonic == "sbc" ||
5911 Mnemonic == "ror" || Mnemonic == "orr" || Mnemonic == "bic")) {
5912 ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]);
5913 ARMOperand &Op4 = static_cast<ARMOperand &>(*Operands[4]);
5914 ARMOperand &Op5 = static_cast<ARMOperand &>(*Operands[5]);
5915
5916 // If both registers are the same then remove one of them from
5917 // the operand list.
5918 if (Op3.isReg() && Op4.isReg() && Op3.getReg() == Op4.getReg()) {
5919 // If 3rd operand (variable Op5) is a register and the instruction is adds/sub
5920 // then do not transform as the backend already handles this instruction
5921 // correctly.
5922 if (!Op5.isReg() || !((Mnemonic == "add" && CarrySetting) || Mnemonic == "sub")) {
5923 Operands.erase(Operands.begin() + 3);
5924 if (Mnemonic == "add" && !CarrySetting) {
5925 // Special case for 'add' (not 'adds') instruction must
5926 // remove the CCOut operand as well.
5927 Operands.erase(Operands.begin() + 1);
5928 }
5929 }
5930 }
5931 }
5932
5933 // If instruction is 'add' and first two register operands
5934 // use SP register, then remove one of the SP registers from
5935 // the instruction.
5936 // FIXME: We would really like to be able to tablegen'erate this.
5937 if (isThumbOne() && Operands.size() == 5 && Mnemonic == "add" && !CarrySetting) {
5938 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[2]);
5939 ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]);
5940 if (Op2.isReg() && Op3.isReg() && Op2.getReg() == ARM::SP && Op3.getReg() == ARM::SP) {
5941 Operands.erase(Operands.begin() + 2);
5942 }
5943 }
5944
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +00005945 // GNU Assembler extension (compatibility)
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005946 if ((Mnemonic == "ldrd" || Mnemonic == "strd")) {
David Blaikie960ea3f2014-06-08 16:18:35 +00005947 ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[2]);
5948 ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]);
5949 if (Op3.isMem()) {
5950 assert(Op2.isReg() && "expected register argument");
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005951
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005952 unsigned SuperReg = MRI->getMatchingSuperReg(
David Blaikie960ea3f2014-06-08 16:18:35 +00005953 Op2.getReg(), ARM::gsub_0, &MRI->getRegClass(ARM::GPRPairRegClassID));
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005954
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005955 assert(SuperReg && "expected register pair");
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005956
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005957 unsigned PairedReg = MRI->getSubReg(SuperReg, ARM::gsub_1);
Stepan Dyatkovskiy6207a4d2014-04-03 11:29:15 +00005958
David Blaikie960ea3f2014-06-08 16:18:35 +00005959 Operands.insert(
5960 Operands.begin() + 3,
5961 ARMOperand::CreateReg(PairedReg, Op2.getStartLoc(), Op2.getEndLoc()));
Stepan Dyatkovskiy3f1fa3d2014-04-04 10:17:56 +00005962 }
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +00005963 }
5964
Kevin Enderby78f95722013-07-31 21:05:30 +00005965 // FIXME: As said above, this is all a pretty gross hack. This instruction
5966 // does not fit with other "subs" and tblgen.
5967 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5968 // so the Mnemonic is the original name "subs" and delete the predicate
5969 // operand so it will match the table entry.
5970 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00005971 static_cast<ARMOperand &>(*Operands[3]).isReg() &&
5972 static_cast<ARMOperand &>(*Operands[3]).getReg() == ARM::PC &&
5973 static_cast<ARMOperand &>(*Operands[4]).isReg() &&
5974 static_cast<ARMOperand &>(*Operands[4]).getReg() == ARM::LR &&
5975 static_cast<ARMOperand &>(*Operands[5]).isImm()) {
5976 Operands.front() = ARMOperand::CreateToken(Name, NameLoc);
Kevin Enderby78f95722013-07-31 21:05:30 +00005977 Operands.erase(Operands.begin() + 1);
Kevin Enderby78f95722013-07-31 21:05:30 +00005978 }
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005979 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005980}
5981
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005982// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005983
5984// return 'true' if register list contains non-low GPR registers,
5985// 'false' otherwise. If Reg is in the register list or is HiReg, set
5986// 'containsReg' to true.
5987static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5988 unsigned HiReg, bool &containsReg) {
5989 containsReg = false;
5990 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5991 unsigned OpReg = Inst.getOperand(i).getReg();
5992 if (OpReg == Reg)
5993 containsReg = true;
5994 // Anything other than a low register isn't legal here.
5995 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5996 return true;
5997 }
5998 return false;
5999}
6000
Rafael Espindola5403da42014-12-04 14:10:20 +00006001// Check if the specified regisgter is in the register list of the inst,
Jim Grosbacha31f2232011-09-07 18:05:34 +00006002// starting at the indicated operand number.
Rafael Espindola5403da42014-12-04 14:10:20 +00006003static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
Jim Grosbacha31f2232011-09-07 18:05:34 +00006004 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
6005 unsigned OpReg = Inst.getOperand(i).getReg();
Rafael Espindola5403da42014-12-04 14:10:20 +00006006 if (OpReg == Reg)
6007 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00006008 }
6009 return false;
6010}
6011
Richard Barton8d519fe2013-09-05 14:14:19 +00006012// Return true if instruction has the interesting property of being
6013// allowed in IT blocks, but not being predicable.
6014static bool instIsBreakpoint(const MCInst &Inst) {
6015 return Inst.getOpcode() == ARM::tBKPT ||
6016 Inst.getOpcode() == ARM::BKPT ||
6017 Inst.getOpcode() == ARM::tHLT ||
6018 Inst.getOpcode() == ARM::HLT;
6019
6020}
6021
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006022bool ARMAsmParser::validatetLDMRegList(MCInst Inst,
6023 const OperandVector &Operands,
Jyoti Allur5a139142015-01-14 10:48:16 +00006024 unsigned ListNo, bool IsARPop) {
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006025 const ARMOperand &Op = static_cast<const ARMOperand &>(*Operands[ListNo]);
6026 bool HasWritebackToken = Op.isToken() && Op.getToken() == "!";
6027
6028 bool ListContainsSP = listContainsReg(Inst, ListNo, ARM::SP);
6029 bool ListContainsLR = listContainsReg(Inst, ListNo, ARM::LR);
6030 bool ListContainsPC = listContainsReg(Inst, ListNo, ARM::PC);
6031
Jyoti Allur5a139142015-01-14 10:48:16 +00006032 if (!IsARPop && ListContainsSP)
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006033 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(),
6034 "SP may not be in the register list");
6035 else if (ListContainsPC && ListContainsLR)
6036 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(),
6037 "PC and LR may not be in the register list simultaneously");
6038 else if (inITBlock() && !lastInITBlock() && ListContainsPC)
6039 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(),
6040 "instruction must be outside of IT block or the last "
6041 "instruction in an IT block");
6042 return false;
6043}
6044
6045bool ARMAsmParser::validatetSTMRegList(MCInst Inst,
6046 const OperandVector &Operands,
6047 unsigned ListNo) {
6048 const ARMOperand &Op = static_cast<const ARMOperand &>(*Operands[ListNo]);
6049 bool HasWritebackToken = Op.isToken() && Op.getToken() == "!";
6050
6051 bool ListContainsSP = listContainsReg(Inst, ListNo, ARM::SP);
6052 bool ListContainsPC = listContainsReg(Inst, ListNo, ARM::PC);
6053
6054 if (ListContainsSP && ListContainsPC)
6055 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(),
6056 "SP and PC may not be in the register list");
6057 else if (ListContainsSP)
6058 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(),
6059 "SP may not be in the register list");
6060 else if (ListContainsPC)
6061 return Error(Operands[ListNo + HasWritebackToken]->getStartLoc(),
6062 "PC may not be in the register list");
6063 return false;
6064}
6065
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006066// FIXME: We would really like to be able to tablegen'erate this.
David Blaikie960ea3f2014-06-08 16:18:35 +00006067bool ARMAsmParser::validateInstruction(MCInst &Inst,
6068 const OperandVector &Operands) {
Joey Gouly0e76fa72013-09-12 10:28:05 +00006069 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00006070 SMLoc Loc = Operands[0]->getStartLoc();
Mihai Popaad18d3c2013-08-09 10:38:32 +00006071
Jim Grosbached16ec42011-08-29 22:24:09 +00006072 // Check the IT block state first.
Richard Barton8d519fe2013-09-05 14:14:19 +00006073 // NOTE: BKPT and HLT instructions have the interesting property of being
Tilmann Schellerbe904772013-09-30 17:57:30 +00006074 // allowed in IT blocks, but not being predicable. They just always execute.
Richard Barton8d519fe2013-09-05 14:14:19 +00006075 if (inITBlock() && !instIsBreakpoint(Inst)) {
Tilmann Schellerbe904772013-09-30 17:57:30 +00006076 unsigned Bit = 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00006077 if (ITState.FirstCond)
6078 ITState.FirstCond = false;
6079 else
Tilmann Schellerbe904772013-09-30 17:57:30 +00006080 Bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00006081 // The instruction must be predicable.
6082 if (!MCID.isPredicable())
6083 return Error(Loc, "instructions in IT block must be predicable");
6084 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
Tilmann Schellerbe904772013-09-30 17:57:30 +00006085 unsigned ITCond = Bit ? ITState.Cond :
Jim Grosbached16ec42011-08-29 22:24:09 +00006086 ARMCC::getOppositeCondition(ITState.Cond);
6087 if (Cond != ITCond) {
6088 // Find the condition code Operand to get its SMLoc information.
6089 SMLoc CondLoc;
Tilmann Schellerbe904772013-09-30 17:57:30 +00006090 for (unsigned I = 1; I < Operands.size(); ++I)
David Blaikie960ea3f2014-06-08 16:18:35 +00006091 if (static_cast<ARMOperand &>(*Operands[I]).isCondCode())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006092 CondLoc = Operands[I]->getStartLoc();
Jim Grosbached16ec42011-08-29 22:24:09 +00006093 return Error(CondLoc, "incorrect condition in IT block; got '" +
6094 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
6095 "', but expected '" +
6096 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
6097 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00006098 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00006099 } else if (isThumbTwo() && MCID.isPredicable() &&
6100 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Mihai Popaad18d3c2013-08-09 10:38:32 +00006101 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
6102 Inst.getOpcode() != ARM::t2Bcc)
Jim Grosbached16ec42011-08-29 22:24:09 +00006103 return Error(Loc, "predicated instructions must be in IT block");
6104
Tilmann Scheller255722b2013-09-30 16:11:48 +00006105 const unsigned Opcode = Inst.getOpcode();
6106 switch (Opcode) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00006107 case ARM::LDRD:
6108 case ARM::LDRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00006109 case ARM::LDRD_POST: {
Tilmann Scheller255722b2013-09-30 16:11:48 +00006110 const unsigned RtReg = Inst.getOperand(0).getReg();
6111
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00006112 // Rt can't be R14.
6113 if (RtReg == ARM::LR)
6114 return Error(Operands[3]->getStartLoc(),
6115 "Rt can't be R14");
Tilmann Scheller255722b2013-09-30 16:11:48 +00006116
6117 const unsigned Rt = MRI->getEncodingValue(RtReg);
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00006118 // Rt must be even-numbered.
6119 if ((Rt & 1) == 1)
6120 return Error(Operands[3]->getStartLoc(),
6121 "Rt must be even-numbered");
Tilmann Scheller255722b2013-09-30 16:11:48 +00006122
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006123 // Rt2 must be Rt + 1.
Tilmann Scheller255722b2013-09-30 16:11:48 +00006124 const unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006125 if (Rt2 != Rt + 1)
6126 return Error(Operands[3]->getStartLoc(),
6127 "destination operands must be sequential");
Tilmann Scheller255722b2013-09-30 16:11:48 +00006128
6129 if (Opcode == ARM::LDRD_PRE || Opcode == ARM::LDRD_POST) {
6130 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg());
6131 // For addressing modes with writeback, the base register needs to be
6132 // different from the destination registers.
6133 if (Rn == Rt || Rn == Rt2)
6134 return Error(Operands[3]->getStartLoc(),
6135 "base register needs to be different from destination "
6136 "registers");
6137 }
6138
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006139 return false;
6140 }
Tilmann Scheller88c8f162013-09-27 10:30:18 +00006141 case ARM::t2LDRDi8:
6142 case ARM::t2LDRD_PRE:
6143 case ARM::t2LDRD_POST: {
Tilmann Scheller041f7172013-09-27 10:38:11 +00006144 // Rt2 must be different from Rt.
Tilmann Scheller88c8f162013-09-27 10:30:18 +00006145 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
6146 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
6147 if (Rt2 == Rt)
6148 return Error(Operands[3]->getStartLoc(),
6149 "destination operands can't be identical");
6150 return false;
6151 }
Charlie Turner6f13d0c2015-04-15 17:28:23 +00006152 case ARM::t2BXJ: {
6153 const unsigned RmReg = Inst.getOperand(0).getReg();
6154 // Rm = SP is no longer unpredictable in v8-A
6155 if (RmReg == ARM::SP && !hasV8Ops())
6156 return Error(Operands[2]->getStartLoc(),
6157 "r13 (SP) is an unpredictable operand to BXJ");
6158 return false;
6159 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00006160 case ARM::STRD: {
6161 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00006162 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
6163 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00006164 if (Rt2 != Rt + 1)
6165 return Error(Operands[3]->getStartLoc(),
6166 "source operands must be sequential");
6167 return false;
6168 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00006169 case ARM::STRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00006170 case ARM::STRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006171 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00006172 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
6173 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006174 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00006175 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006176 "source operands must be sequential");
6177 return false;
6178 }
Tilmann Scheller3352a582014-07-23 12:38:17 +00006179 case ARM::STR_PRE_IMM:
6180 case ARM::STR_PRE_REG:
6181 case ARM::STR_POST_IMM:
Tilmann Scheller27272792014-07-23 13:03:47 +00006182 case ARM::STR_POST_REG:
Tilmann Scheller96ef72e2014-07-24 09:55:46 +00006183 case ARM::STRH_PRE:
6184 case ARM::STRH_POST:
Tilmann Scheller27272792014-07-23 13:03:47 +00006185 case ARM::STRB_PRE_IMM:
6186 case ARM::STRB_PRE_REG:
6187 case ARM::STRB_POST_IMM:
6188 case ARM::STRB_POST_REG: {
Tilmann Scheller3352a582014-07-23 12:38:17 +00006189 // Rt must be different from Rn.
6190 const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
6191 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(2).getReg());
6192
6193 if (Rt == Rn)
6194 return Error(Operands[3]->getStartLoc(),
6195 "source register and base register can't be identical");
6196 return false;
6197 }
Tilmann Scheller8ba74302014-08-01 11:08:51 +00006198 case ARM::LDR_PRE_IMM:
6199 case ARM::LDR_PRE_REG:
6200 case ARM::LDR_POST_IMM:
Tilmann Scheller8ff079c2014-08-01 11:33:47 +00006201 case ARM::LDR_POST_REG:
6202 case ARM::LDRH_PRE:
6203 case ARM::LDRH_POST:
6204 case ARM::LDRSH_PRE:
Tilmann Scheller7cc0ed42014-08-01 12:08:04 +00006205 case ARM::LDRSH_POST:
6206 case ARM::LDRB_PRE_IMM:
6207 case ARM::LDRB_PRE_REG:
6208 case ARM::LDRB_POST_IMM:
6209 case ARM::LDRB_POST_REG:
6210 case ARM::LDRSB_PRE:
6211 case ARM::LDRSB_POST: {
Tilmann Scheller8ba74302014-08-01 11:08:51 +00006212 // Rt must be different from Rn.
6213 const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
6214 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(2).getReg());
6215
6216 if (Rt == Rn)
6217 return Error(Operands[3]->getStartLoc(),
6218 "destination register and base register can't be identical");
6219 return false;
6220 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00006221 case ARM::SBFX:
6222 case ARM::UBFX: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00006223 // Width must be in range [1, 32-lsb].
6224 unsigned LSB = Inst.getOperand(2).getImm();
6225 unsigned Widthm1 = Inst.getOperand(3).getImm();
6226 if (Widthm1 >= 32 - LSB)
Jim Grosbach03f56d92011-07-27 21:09:25 +00006227 return Error(Operands[5]->getStartLoc(),
6228 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00006229 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00006230 }
Rafael Espindola5403da42014-12-04 14:10:20 +00006231 // Notionally handles ARM::tLDMIA_UPD too.
6232 case ARM::tLDMIA: {
6233 // If we're parsing Thumb2, the .w variant is available and handles
6234 // most cases that are normally illegal for a Thumb1 LDM instruction.
6235 // We'll make the transformation in processInstruction() if necessary.
6236 //
6237 // Thumb LDM instructions are writeback iff the base register is not
6238 // in the register list.
6239 unsigned Rn = Inst.getOperand(0).getReg();
6240 bool HasWritebackToken =
6241 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
6242 static_cast<ARMOperand &>(*Operands[3]).getToken() == "!");
6243 bool ListContainsBase;
6244 if (checkLowRegisterList(Inst, 3, Rn, 0, ListContainsBase) && !isThumbTwo())
6245 return Error(Operands[3 + HasWritebackToken]->getStartLoc(),
6246 "registers must be in range r0-r7");
6247 // If we should have writeback, then there should be a '!' token.
6248 if (!ListContainsBase && !HasWritebackToken && !isThumbTwo())
6249 return Error(Operands[2]->getStartLoc(),
6250 "writeback operator '!' expected");
6251 // If we should not have writeback, there must not be a '!'. This is
6252 // true even for the 32-bit wide encodings.
6253 if (ListContainsBase && HasWritebackToken)
6254 return Error(Operands[3]->getStartLoc(),
6255 "writeback operator '!' not allowed when base register "
6256 "in register list");
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006257
6258 if (validatetLDMRegList(Inst, Operands, 3))
6259 return true;
Rafael Espindola5403da42014-12-04 14:10:20 +00006260 break;
6261 }
Tim Northover08a86602013-10-22 19:00:39 +00006262 case ARM::LDMIA_UPD:
6263 case ARM::LDMDB_UPD:
6264 case ARM::LDMIB_UPD:
6265 case ARM::LDMDA_UPD:
6266 // ARM variants loading and updating the same register are only officially
6267 // UNPREDICTABLE on v7 upwards. Goodness knows what they did before.
6268 if (!hasV7Ops())
6269 break;
Rafael Espindola5403da42014-12-04 14:10:20 +00006270 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
6271 return Error(Operands.back()->getStartLoc(),
6272 "writeback register not allowed in register list");
6273 break;
Jyoti Allur3b686072014-10-22 10:41:14 +00006274 case ARM::t2LDMIA:
6275 case ARM::t2LDMDB:
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006276 if (validatetLDMRegList(Inst, Operands, 3))
6277 return true;
Rafael Espindola5403da42014-12-04 14:10:20 +00006278 break;
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006279 case ARM::t2STMIA:
6280 case ARM::t2STMDB:
6281 if (validatetSTMRegList(Inst, Operands, 3))
6282 return true;
6283 break;
Tim Northover08a86602013-10-22 19:00:39 +00006284 case ARM::t2LDMIA_UPD:
6285 case ARM::t2LDMDB_UPD:
6286 case ARM::t2STMIA_UPD:
Rafael Espindola5403da42014-12-04 14:10:20 +00006287 case ARM::t2STMDB_UPD: {
6288 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
6289 return Error(Operands.back()->getStartLoc(),
6290 "writeback register not allowed in register list");
6291
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006292 if (Opcode == ARM::t2LDMIA_UPD || Opcode == ARM::t2LDMDB_UPD) {
Saleem Abdulrasool0b5a8522014-12-18 16:16:53 +00006293 if (validatetLDMRegList(Inst, Operands, 3))
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006294 return true;
6295 } else {
Saleem Abdulrasool0b5a8522014-12-18 16:16:53 +00006296 if (validatetSTMRegList(Inst, Operands, 3))
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006297 return true;
6298 }
Rafael Espindola5403da42014-12-04 14:10:20 +00006299 break;
6300 }
Tim Northover8eaf1542013-11-12 21:32:41 +00006301 case ARM::sysLDMIA_UPD:
6302 case ARM::sysLDMDA_UPD:
6303 case ARM::sysLDMDB_UPD:
Rafael Espindola5403da42014-12-04 14:10:20 +00006304 case ARM::sysLDMIB_UPD:
6305 if (!listContainsReg(Inst, 3, ARM::PC))
6306 return Error(Operands[4]->getStartLoc(),
6307 "writeback register only allowed on system LDM "
6308 "if PC in register-list");
Tim Northover8eaf1542013-11-12 21:32:41 +00006309 break;
6310 case ARM::sysSTMIA_UPD:
6311 case ARM::sysSTMDA_UPD:
6312 case ARM::sysSTMDB_UPD:
6313 case ARM::sysSTMIB_UPD:
6314 return Error(Operands[2]->getStartLoc(),
6315 "system STM cannot have writeback register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00006316 case ARM::tMUL: {
6317 // The second source operand must be the same register as the destination
6318 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00006319 //
6320 // In this case, we must directly check the parsed operands because the
6321 // cvtThumbMultiply() function is written in such a way that it guarantees
6322 // this first statement is always true for the new Inst. Essentially, the
6323 // destination is unconditionally copied into the second source operand
6324 // without checking to see if it matches what we actually parsed.
David Blaikie960ea3f2014-06-08 16:18:35 +00006325 if (Operands.size() == 6 && (((ARMOperand &)*Operands[3]).getReg() !=
6326 ((ARMOperand &)*Operands[5]).getReg()) &&
6327 (((ARMOperand &)*Operands[3]).getReg() !=
6328 ((ARMOperand &)*Operands[4]).getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00006329 return Error(Operands[3]->getStartLoc(),
6330 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00006331 }
6332 break;
6333 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00006334 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
6335 // so only issue a diagnostic for thumb1. The instructions will be
6336 // switched to the t2 encodings in processInstruction() if necessary.
Rafael Espindola5403da42014-12-04 14:10:20 +00006337 case ARM::tPOP: {
6338 bool ListContainsBase;
6339 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, ListContainsBase) &&
6340 !isThumbTwo())
6341 return Error(Operands[2]->getStartLoc(),
6342 "registers must be in range r0-r7 or pc");
Jyoti Allur5a139142015-01-14 10:48:16 +00006343 if (validatetLDMRegList(Inst, Operands, 2, !isMClass()))
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006344 return true;
Rafael Espindola5403da42014-12-04 14:10:20 +00006345 break;
6346 }
Jim Grosbach38c59fc2011-08-22 23:17:34 +00006347 case ARM::tPUSH: {
Rafael Espindola5403da42014-12-04 14:10:20 +00006348 bool ListContainsBase;
6349 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, ListContainsBase) &&
6350 !isThumbTwo())
6351 return Error(Operands[2]->getStartLoc(),
6352 "registers must be in range r0-r7 or lr");
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006353 if (validatetSTMRegList(Inst, Operands, 2))
6354 return true;
Jim Grosbach38c59fc2011-08-22 23:17:34 +00006355 break;
6356 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00006357 case ARM::tSTMIA_UPD: {
Rafael Espindola5403da42014-12-04 14:10:20 +00006358 bool ListContainsBase, InvalidLowList;
6359 InvalidLowList = checkLowRegisterList(Inst, 4, Inst.getOperand(0).getReg(),
6360 0, ListContainsBase);
6361 if (InvalidLowList && !isThumbTwo())
6362 return Error(Operands[4]->getStartLoc(),
6363 "registers must be in range r0-r7");
6364
6365 // This would be converted to a 32-bit stm, but that's not valid if the
6366 // writeback register is in the list.
6367 if (InvalidLowList && ListContainsBase)
6368 return Error(Operands[4]->getStartLoc(),
6369 "writeback operator '!' not allowed when base register "
6370 "in register list");
Saleem Abdulrasool3a239172014-12-18 05:24:38 +00006371
6372 if (validatetSTMRegList(Inst, Operands, 4))
6373 return true;
Jim Grosbachd80d1692011-08-23 18:15:37 +00006374 break;
6375 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00006376 case ARM::tADDrSP: {
6377 // If the non-SP source operand and the destination operand are not the
6378 // same, we need thumb2 (for the wide encoding), or we have an error.
6379 if (!isThumbTwo() &&
6380 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
6381 return Error(Operands[4]->getStartLoc(),
6382 "source register must be the same as destination");
6383 }
6384 break;
6385 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00006386 // Final range checking for Thumb unconditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00006387 case ARM::tB:
David Blaikie960ea3f2014-06-08 16:18:35 +00006388 if (!(static_cast<ARMOperand &>(*Operands[2])).isSignedOffset<11, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006389 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00006390 break;
6391 case ARM::t2B: {
6392 int op = (Operands[2]->isImm()) ? 2 : 3;
David Blaikie960ea3f2014-06-08 16:18:35 +00006393 if (!static_cast<ARMOperand &>(*Operands[op]).isSignedOffset<24, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006394 return Error(Operands[op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00006395 break;
6396 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00006397 // Final range checking for Thumb conditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00006398 case ARM::tBcc:
David Blaikie960ea3f2014-06-08 16:18:35 +00006399 if (!static_cast<ARMOperand &>(*Operands[2]).isSignedOffset<8, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006400 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00006401 break;
6402 case ARM::t2Bcc: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00006403 int Op = (Operands[2]->isImm()) ? 2 : 3;
David Blaikie960ea3f2014-06-08 16:18:35 +00006404 if (!static_cast<ARMOperand &>(*Operands[Op]).isSignedOffset<20, 1>())
Tilmann Schellerbe904772013-09-30 17:57:30 +00006405 return Error(Operands[Op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00006406 break;
6407 }
Kevin Enderbyb7e51f62014-04-18 23:06:39 +00006408 case ARM::MOVi16:
6409 case ARM::t2MOVi16:
6410 case ARM::t2MOVTi16:
6411 {
6412 // We want to avoid misleadingly allowing something like "mov r0, <symbol>"
6413 // especially when we turn it into a movw and the expression <symbol> does
6414 // not have a :lower16: or :upper16 as part of the expression. We don't
6415 // want the behavior of silently truncating, which can be unexpected and
6416 // lead to bugs that are difficult to find since this is an easy mistake
6417 // to make.
6418 int i = (Operands[3]->isImm()) ? 3 : 4;
David Blaikie960ea3f2014-06-08 16:18:35 +00006419 ARMOperand &Op = static_cast<ARMOperand &>(*Operands[i]);
6420 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm());
Kevin Enderbyb7e51f62014-04-18 23:06:39 +00006421 if (CE) break;
David Blaikie960ea3f2014-06-08 16:18:35 +00006422 const MCExpr *E = dyn_cast<MCExpr>(Op.getImm());
Kevin Enderbyb7e51f62014-04-18 23:06:39 +00006423 if (!E) break;
6424 const ARMMCExpr *ARM16Expr = dyn_cast<ARMMCExpr>(E);
6425 if (!ARM16Expr || (ARM16Expr->getKind() != ARMMCExpr::VK_ARM_HI16 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00006426 ARM16Expr->getKind() != ARMMCExpr::VK_ARM_LO16))
6427 return Error(
6428 Op.getStartLoc(),
6429 "immediate expression for mov requires :lower16: or :upper16");
6430 break;
6431 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00006432 }
6433
6434 return false;
6435}
6436
Jim Grosbach1a747242012-01-23 23:45:44 +00006437static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00006438 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00006439 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006440 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006441 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
6442 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
6443 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
6444 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
6445 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
6446 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
6447 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
6448 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
6449 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006450
6451 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006452 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
6453 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
6454 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
6455 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
6456 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00006457
Jim Grosbach1e946a42012-01-24 00:43:12 +00006458 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
6459 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
6460 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
6461 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
6462 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00006463
Jim Grosbach1e946a42012-01-24 00:43:12 +00006464 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
6465 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
6466 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
6467 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
6468 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00006469
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006470 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006471 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
6472 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
6473 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
6474 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
6475 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
6476 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
6477 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
6478 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
6479 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
6480 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
6481 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
6482 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
6483 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
6484 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
6485 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006486
Jim Grosbach1a747242012-01-23 23:45:44 +00006487 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00006488 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
6489 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
6490 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
6491 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
6492 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
6493 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
6494 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
6495 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
6496 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
6497 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
6498 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
6499 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
6500 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
6501 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
6502 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
6503 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
6504 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
6505 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00006506
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006507 // VST4LN
6508 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
6509 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
6510 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
6511 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
6512 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
6513 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
6514 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
6515 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
6516 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
6517 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
6518 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
6519 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
6520 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
6521 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
6522 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
6523
Jim Grosbachda70eac2012-01-24 00:58:13 +00006524 // VST4
6525 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
6526 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
6527 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
6528 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
6529 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
6530 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
6531 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
6532 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
6533 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
6534 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
6535 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
6536 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
6537 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
6538 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
6539 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
6540 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
6541 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
6542 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00006543 }
6544}
6545
Jim Grosbach1a747242012-01-23 23:45:44 +00006546static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00006547 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00006548 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006549 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006550 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
6551 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
6552 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
6553 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
6554 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
6555 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
6556 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
6557 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
6558 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006559
6560 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006561 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
6562 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
6563 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
6564 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
6565 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
6566 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
6567 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
6568 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
6569 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
6570 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
6571 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
6572 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
6573 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
6574 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
6575 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006576
Jim Grosbachb78403c2012-01-24 23:47:04 +00006577 // VLD3DUP
6578 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
6579 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
6580 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
6581 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
Kevin Enderbyd88fec32014-04-08 18:00:52 +00006582 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
Jim Grosbachb78403c2012-01-24 23:47:04 +00006583 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
6584 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
6585 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
6586 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
6587 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
6588 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
6589 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
6590 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
6591 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
6592 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
6593 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
6594 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
6595 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
6596
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006597 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00006598 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
6599 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
6600 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
6601 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
6602 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
6603 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
6604 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
6605 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
6606 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
6607 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
6608 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
6609 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
6610 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
6611 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
6612 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006613
6614 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00006615 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
6616 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
6617 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
6618 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
6619 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
6620 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
6621 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
6622 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
6623 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
6624 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
6625 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
6626 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
6627 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
6628 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
6629 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
6630 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
6631 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
6632 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00006633
Jim Grosbach14952a02012-01-24 18:37:25 +00006634 // VLD4LN
6635 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
6636 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
6637 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
Kevin Enderby8108f382014-03-26 19:35:40 +00006638 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
Jim Grosbach14952a02012-01-24 18:37:25 +00006639 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
6640 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
6641 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
6642 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
6643 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
6644 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
6645 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
6646 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
6647 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
6648 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
6649 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
6650
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006651 // VLD4DUP
6652 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
6653 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
6654 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
6655 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
6656 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
6657 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
6658 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
6659 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
6660 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
6661 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
6662 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
6663 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
6664 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
6665 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
6666 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
6667 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
6668 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
6669 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
6670
Jim Grosbached561fc2012-01-24 00:43:17 +00006671 // VLD4
6672 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
6673 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
6674 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
6675 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
6676 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
6677 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
6678 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
6679 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
6680 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
6681 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
6682 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
6683 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
6684 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
6685 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
6686 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
6687 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
6688 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
6689 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00006690 }
6691}
6692
David Blaikie960ea3f2014-06-08 16:18:35 +00006693bool ARMAsmParser::processInstruction(MCInst &Inst,
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +00006694 const OperandVector &Operands,
6695 MCStreamer &Out) {
Jim Grosbach8ba76c62011-08-11 17:35:48 +00006696 switch (Inst.getOpcode()) {
Saleem Abdulrasoolfb3950e2014-01-12 04:36:01 +00006697 // Alias for alternate form of 'ldr{,b}t Rt, [Rn], #imm' instruction.
6698 case ARM::LDRT_POST:
6699 case ARM::LDRBT_POST: {
6700 const unsigned Opcode =
6701 (Inst.getOpcode() == ARM::LDRT_POST) ? ARM::LDRT_POST_IMM
6702 : ARM::LDRBT_POST_IMM;
6703 MCInst TmpInst;
6704 TmpInst.setOpcode(Opcode);
6705 TmpInst.addOperand(Inst.getOperand(0));
6706 TmpInst.addOperand(Inst.getOperand(1));
6707 TmpInst.addOperand(Inst.getOperand(1));
6708 TmpInst.addOperand(MCOperand::CreateReg(0));
6709 TmpInst.addOperand(MCOperand::CreateImm(0));
6710 TmpInst.addOperand(Inst.getOperand(2));
6711 TmpInst.addOperand(Inst.getOperand(3));
6712 Inst = TmpInst;
6713 return true;
6714 }
6715 // Alias for alternate form of 'str{,b}t Rt, [Rn], #imm' instruction.
6716 case ARM::STRT_POST:
6717 case ARM::STRBT_POST: {
6718 const unsigned Opcode =
6719 (Inst.getOpcode() == ARM::STRT_POST) ? ARM::STRT_POST_IMM
6720 : ARM::STRBT_POST_IMM;
6721 MCInst TmpInst;
6722 TmpInst.setOpcode(Opcode);
6723 TmpInst.addOperand(Inst.getOperand(1));
6724 TmpInst.addOperand(Inst.getOperand(0));
6725 TmpInst.addOperand(Inst.getOperand(1));
6726 TmpInst.addOperand(MCOperand::CreateReg(0));
6727 TmpInst.addOperand(MCOperand::CreateImm(0));
6728 TmpInst.addOperand(Inst.getOperand(2));
6729 TmpInst.addOperand(Inst.getOperand(3));
6730 Inst = TmpInst;
6731 return true;
6732 }
Jim Grosbache974a6a2012-09-25 00:08:13 +00006733 // Alias for alternate form of 'ADR Rd, #imm' instruction.
6734 case ARM::ADDri: {
6735 if (Inst.getOperand(1).getReg() != ARM::PC ||
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +00006736 Inst.getOperand(5).getReg() != 0 ||
6737 !(Inst.getOperand(2).isExpr() || Inst.getOperand(2).isImm()))
Jim Grosbache974a6a2012-09-25 00:08:13 +00006738 return false;
6739 MCInst TmpInst;
6740 TmpInst.setOpcode(ARM::ADR);
6741 TmpInst.addOperand(Inst.getOperand(0));
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +00006742 if (Inst.getOperand(2).isImm()) {
Asiri Rathnayake7835e9b2014-12-09 13:14:58 +00006743 // Immediate (mod_imm) will be in its encoded form, we must unencode it
6744 // before passing it to the ADR instruction.
6745 unsigned Enc = Inst.getOperand(2).getImm();
6746 TmpInst.addOperand(MCOperand::CreateImm(
6747 ARM_AM::rotr32(Enc & 0xFF, (Enc & 0xF00) >> 7)));
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +00006748 } else {
6749 // Turn PC-relative expression into absolute expression.
6750 // Reading PC provides the start of the current instruction + 8 and
6751 // the transform to adr is biased by that.
6752 MCSymbol *Dot = getContext().CreateTempSymbol();
6753 Out.EmitLabel(Dot);
6754 const MCExpr *OpExpr = Inst.getOperand(2).getExpr();
6755 const MCExpr *InstPC = MCSymbolRefExpr::Create(Dot,
6756 MCSymbolRefExpr::VK_None,
6757 getContext());
6758 const MCExpr *Const8 = MCConstantExpr::Create(8, getContext());
6759 const MCExpr *ReadPC = MCBinaryExpr::CreateAdd(InstPC, Const8,
6760 getContext());
6761 const MCExpr *FixupAddr = MCBinaryExpr::CreateAdd(ReadPC, OpExpr,
6762 getContext());
6763 TmpInst.addOperand(MCOperand::CreateExpr(FixupAddr));
6764 }
Jim Grosbache974a6a2012-09-25 00:08:13 +00006765 TmpInst.addOperand(Inst.getOperand(3));
6766 TmpInst.addOperand(Inst.getOperand(4));
6767 Inst = TmpInst;
6768 return true;
6769 }
Jim Grosbach94298a92012-01-18 22:46:46 +00006770 // Aliases for alternate PC+imm syntax of LDR instructions.
6771 case ARM::t2LDRpcrel:
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00006772 // Select the narrow version if the immediate will fit.
6773 if (Inst.getOperand(1).getImm() > 0 &&
Amaury de la Vieuvilleeac0bad2013-06-18 08:13:05 +00006774 Inst.getOperand(1).getImm() <= 0xff &&
David Blaikie960ea3f2014-06-08 16:18:35 +00006775 !(static_cast<ARMOperand &>(*Operands[2]).isToken() &&
6776 static_cast<ARMOperand &>(*Operands[2]).getToken() == ".w"))
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00006777 Inst.setOpcode(ARM::tLDRpci);
6778 else
6779 Inst.setOpcode(ARM::t2LDRpci);
Jim Grosbach94298a92012-01-18 22:46:46 +00006780 return true;
6781 case ARM::t2LDRBpcrel:
6782 Inst.setOpcode(ARM::t2LDRBpci);
6783 return true;
6784 case ARM::t2LDRHpcrel:
6785 Inst.setOpcode(ARM::t2LDRHpci);
6786 return true;
6787 case ARM::t2LDRSBpcrel:
6788 Inst.setOpcode(ARM::t2LDRSBpci);
6789 return true;
6790 case ARM::t2LDRSHpcrel:
6791 Inst.setOpcode(ARM::t2LDRSHpci);
6792 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006793 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006794 case ARM::VST1LNdWB_register_Asm_8:
6795 case ARM::VST1LNdWB_register_Asm_16:
6796 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006797 MCInst TmpInst;
6798 // Shuffle the operands around so the lane index operand is in the
6799 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006800 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006801 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006802 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6803 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6804 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6805 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6806 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6807 TmpInst.addOperand(Inst.getOperand(1)); // lane
6808 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6809 TmpInst.addOperand(Inst.getOperand(6));
6810 Inst = TmpInst;
6811 return true;
6812 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006813
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006814 case ARM::VST2LNdWB_register_Asm_8:
6815 case ARM::VST2LNdWB_register_Asm_16:
6816 case ARM::VST2LNdWB_register_Asm_32:
6817 case ARM::VST2LNqWB_register_Asm_16:
6818 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006819 MCInst TmpInst;
6820 // Shuffle the operands around so the lane index operand is in the
6821 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006822 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006823 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006824 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6825 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6826 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6827 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6828 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006829 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6830 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006831 TmpInst.addOperand(Inst.getOperand(1)); // lane
6832 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6833 TmpInst.addOperand(Inst.getOperand(6));
6834 Inst = TmpInst;
6835 return true;
6836 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006837
6838 case ARM::VST3LNdWB_register_Asm_8:
6839 case ARM::VST3LNdWB_register_Asm_16:
6840 case ARM::VST3LNdWB_register_Asm_32:
6841 case ARM::VST3LNqWB_register_Asm_16:
6842 case ARM::VST3LNqWB_register_Asm_32: {
6843 MCInst TmpInst;
6844 // Shuffle the operands around so the lane index operand is in the
6845 // right place.
6846 unsigned Spacing;
6847 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6848 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6849 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6850 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6851 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6852 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6853 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6854 Spacing));
6855 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6856 Spacing * 2));
6857 TmpInst.addOperand(Inst.getOperand(1)); // lane
6858 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6859 TmpInst.addOperand(Inst.getOperand(6));
6860 Inst = TmpInst;
6861 return true;
6862 }
6863
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006864 case ARM::VST4LNdWB_register_Asm_8:
6865 case ARM::VST4LNdWB_register_Asm_16:
6866 case ARM::VST4LNdWB_register_Asm_32:
6867 case ARM::VST4LNqWB_register_Asm_16:
6868 case ARM::VST4LNqWB_register_Asm_32: {
6869 MCInst TmpInst;
6870 // Shuffle the operands around so the lane index operand is in the
6871 // right place.
6872 unsigned Spacing;
6873 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6874 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6875 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6876 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6877 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6878 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6879 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6880 Spacing));
6881 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6882 Spacing * 2));
6883 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6884 Spacing * 3));
6885 TmpInst.addOperand(Inst.getOperand(1)); // lane
6886 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6887 TmpInst.addOperand(Inst.getOperand(6));
6888 Inst = TmpInst;
6889 return true;
6890 }
6891
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006892 case ARM::VST1LNdWB_fixed_Asm_8:
6893 case ARM::VST1LNdWB_fixed_Asm_16:
6894 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006895 MCInst TmpInst;
6896 // Shuffle the operands around so the lane index operand is in the
6897 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006898 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006899 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006900 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6901 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6902 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6903 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6904 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6905 TmpInst.addOperand(Inst.getOperand(1)); // lane
6906 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6907 TmpInst.addOperand(Inst.getOperand(5));
6908 Inst = TmpInst;
6909 return true;
6910 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006911
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006912 case ARM::VST2LNdWB_fixed_Asm_8:
6913 case ARM::VST2LNdWB_fixed_Asm_16:
6914 case ARM::VST2LNdWB_fixed_Asm_32:
6915 case ARM::VST2LNqWB_fixed_Asm_16:
6916 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006917 MCInst TmpInst;
6918 // Shuffle the operands around so the lane index operand is in the
6919 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006920 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006921 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006922 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6923 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6924 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6925 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6926 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006927 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6928 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006929 TmpInst.addOperand(Inst.getOperand(1)); // lane
6930 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6931 TmpInst.addOperand(Inst.getOperand(5));
6932 Inst = TmpInst;
6933 return true;
6934 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006935
6936 case ARM::VST3LNdWB_fixed_Asm_8:
6937 case ARM::VST3LNdWB_fixed_Asm_16:
6938 case ARM::VST3LNdWB_fixed_Asm_32:
6939 case ARM::VST3LNqWB_fixed_Asm_16:
6940 case ARM::VST3LNqWB_fixed_Asm_32: {
6941 MCInst TmpInst;
6942 // Shuffle the operands around so the lane index operand is in the
6943 // right place.
6944 unsigned Spacing;
6945 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6946 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6947 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6948 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6949 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6950 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6951 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6952 Spacing));
6953 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6954 Spacing * 2));
6955 TmpInst.addOperand(Inst.getOperand(1)); // lane
6956 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6957 TmpInst.addOperand(Inst.getOperand(5));
6958 Inst = TmpInst;
6959 return true;
6960 }
6961
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006962 case ARM::VST4LNdWB_fixed_Asm_8:
6963 case ARM::VST4LNdWB_fixed_Asm_16:
6964 case ARM::VST4LNdWB_fixed_Asm_32:
6965 case ARM::VST4LNqWB_fixed_Asm_16:
6966 case ARM::VST4LNqWB_fixed_Asm_32: {
6967 MCInst TmpInst;
6968 // Shuffle the operands around so the lane index operand is in the
6969 // right place.
6970 unsigned Spacing;
6971 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6972 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6973 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6974 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6975 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6976 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6977 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6978 Spacing));
6979 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6980 Spacing * 2));
6981 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6982 Spacing * 3));
6983 TmpInst.addOperand(Inst.getOperand(1)); // lane
6984 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6985 TmpInst.addOperand(Inst.getOperand(5));
6986 Inst = TmpInst;
6987 return true;
6988 }
6989
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006990 case ARM::VST1LNdAsm_8:
6991 case ARM::VST1LNdAsm_16:
6992 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006993 MCInst TmpInst;
6994 // Shuffle the operands around so the lane index operand is in the
6995 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006996 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006997 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006998 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6999 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7000 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7001 TmpInst.addOperand(Inst.getOperand(1)); // lane
7002 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7003 TmpInst.addOperand(Inst.getOperand(5));
7004 Inst = TmpInst;
7005 return true;
7006 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007007
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007008 case ARM::VST2LNdAsm_8:
7009 case ARM::VST2LNdAsm_16:
7010 case ARM::VST2LNdAsm_32:
7011 case ARM::VST2LNqAsm_16:
7012 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007013 MCInst TmpInst;
7014 // Shuffle the operands around so the lane index operand is in the
7015 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00007016 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007017 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007018 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7019 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7020 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00007021 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7022 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007023 TmpInst.addOperand(Inst.getOperand(1)); // lane
7024 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7025 TmpInst.addOperand(Inst.getOperand(5));
7026 Inst = TmpInst;
7027 return true;
7028 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00007029
7030 case ARM::VST3LNdAsm_8:
7031 case ARM::VST3LNdAsm_16:
7032 case ARM::VST3LNdAsm_32:
7033 case ARM::VST3LNqAsm_16:
7034 case ARM::VST3LNqAsm_32: {
7035 MCInst TmpInst;
7036 // Shuffle the operands around so the lane index operand is in the
7037 // right place.
7038 unsigned Spacing;
7039 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7040 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7041 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7042 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7043 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7044 Spacing));
7045 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7046 Spacing * 2));
7047 TmpInst.addOperand(Inst.getOperand(1)); // lane
7048 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7049 TmpInst.addOperand(Inst.getOperand(5));
7050 Inst = TmpInst;
7051 return true;
7052 }
7053
Jim Grosbach8e2722c2012-01-24 18:53:13 +00007054 case ARM::VST4LNdAsm_8:
7055 case ARM::VST4LNdAsm_16:
7056 case ARM::VST4LNdAsm_32:
7057 case ARM::VST4LNqAsm_16:
7058 case ARM::VST4LNqAsm_32: {
7059 MCInst TmpInst;
7060 // Shuffle the operands around so the lane index operand is in the
7061 // right place.
7062 unsigned Spacing;
7063 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7064 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7065 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7066 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7067 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7068 Spacing));
7069 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7070 Spacing * 2));
7071 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7072 Spacing * 3));
7073 TmpInst.addOperand(Inst.getOperand(1)); // lane
7074 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7075 TmpInst.addOperand(Inst.getOperand(5));
7076 Inst = TmpInst;
7077 return true;
7078 }
7079
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007080 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007081 case ARM::VLD1LNdWB_register_Asm_8:
7082 case ARM::VLD1LNdWB_register_Asm_16:
7083 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00007084 MCInst TmpInst;
7085 // Shuffle the operands around so the lane index operand is in the
7086 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007087 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007088 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00007089 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7090 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7091 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7092 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7093 TmpInst.addOperand(Inst.getOperand(4)); // Rm
7094 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7095 TmpInst.addOperand(Inst.getOperand(1)); // lane
7096 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
7097 TmpInst.addOperand(Inst.getOperand(6));
7098 Inst = TmpInst;
7099 return true;
7100 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007101
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007102 case ARM::VLD2LNdWB_register_Asm_8:
7103 case ARM::VLD2LNdWB_register_Asm_16:
7104 case ARM::VLD2LNdWB_register_Asm_32:
7105 case ARM::VLD2LNqWB_register_Asm_16:
7106 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007107 MCInst TmpInst;
7108 // Shuffle the operands around so the lane index operand is in the
7109 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007110 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007111 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007112 TmpInst.addOperand(Inst.getOperand(0)); // 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(2)); // Rn_wb
7116 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7117 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7118 TmpInst.addOperand(Inst.getOperand(4)); // Rm
7119 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007120 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7121 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007122 TmpInst.addOperand(Inst.getOperand(1)); // lane
7123 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
7124 TmpInst.addOperand(Inst.getOperand(6));
7125 Inst = TmpInst;
7126 return true;
7127 }
7128
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007129 case ARM::VLD3LNdWB_register_Asm_8:
7130 case ARM::VLD3LNdWB_register_Asm_16:
7131 case ARM::VLD3LNdWB_register_Asm_32:
7132 case ARM::VLD3LNqWB_register_Asm_16:
7133 case ARM::VLD3LNqWB_register_Asm_32: {
7134 MCInst TmpInst;
7135 // Shuffle the operands around so the lane index operand is in the
7136 // right place.
7137 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007138 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007139 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7140 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7141 Spacing));
7142 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007143 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007144 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7145 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7146 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7147 TmpInst.addOperand(Inst.getOperand(4)); // Rm
7148 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7149 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7150 Spacing));
7151 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007152 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007153 TmpInst.addOperand(Inst.getOperand(1)); // lane
7154 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
7155 TmpInst.addOperand(Inst.getOperand(6));
7156 Inst = TmpInst;
7157 return true;
7158 }
7159
Jim Grosbach14952a02012-01-24 18:37:25 +00007160 case ARM::VLD4LNdWB_register_Asm_8:
7161 case ARM::VLD4LNdWB_register_Asm_16:
7162 case ARM::VLD4LNdWB_register_Asm_32:
7163 case ARM::VLD4LNqWB_register_Asm_16:
7164 case ARM::VLD4LNqWB_register_Asm_32: {
7165 MCInst TmpInst;
7166 // Shuffle the operands around so the lane index operand is in the
7167 // right place.
7168 unsigned Spacing;
7169 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7170 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7171 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7172 Spacing));
7173 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7174 Spacing * 2));
7175 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7176 Spacing * 3));
7177 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7178 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7179 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7180 TmpInst.addOperand(Inst.getOperand(4)); // Rm
7181 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7182 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7183 Spacing));
7184 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7185 Spacing * 2));
7186 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7187 Spacing * 3));
7188 TmpInst.addOperand(Inst.getOperand(1)); // lane
7189 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
7190 TmpInst.addOperand(Inst.getOperand(6));
7191 Inst = TmpInst;
7192 return true;
7193 }
7194
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007195 case ARM::VLD1LNdWB_fixed_Asm_8:
7196 case ARM::VLD1LNdWB_fixed_Asm_16:
7197 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00007198 MCInst TmpInst;
7199 // Shuffle the operands around so the lane index operand is in the
7200 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007201 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007202 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00007203 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7204 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7205 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7206 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7207 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7208 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7209 TmpInst.addOperand(Inst.getOperand(1)); // lane
7210 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7211 TmpInst.addOperand(Inst.getOperand(5));
7212 Inst = TmpInst;
7213 return true;
7214 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007215
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007216 case ARM::VLD2LNdWB_fixed_Asm_8:
7217 case ARM::VLD2LNdWB_fixed_Asm_16:
7218 case ARM::VLD2LNdWB_fixed_Asm_32:
7219 case ARM::VLD2LNqWB_fixed_Asm_16:
7220 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007221 MCInst TmpInst;
7222 // Shuffle the operands around so the lane index operand is in the
7223 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007224 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007225 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007226 TmpInst.addOperand(Inst.getOperand(0)); // 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(2)); // Rn_wb
7230 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7231 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7232 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7233 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007234 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7235 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007236 TmpInst.addOperand(Inst.getOperand(1)); // lane
7237 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7238 TmpInst.addOperand(Inst.getOperand(5));
7239 Inst = TmpInst;
7240 return true;
7241 }
7242
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007243 case ARM::VLD3LNdWB_fixed_Asm_8:
7244 case ARM::VLD3LNdWB_fixed_Asm_16:
7245 case ARM::VLD3LNdWB_fixed_Asm_32:
7246 case ARM::VLD3LNqWB_fixed_Asm_16:
7247 case ARM::VLD3LNqWB_fixed_Asm_32: {
7248 MCInst TmpInst;
7249 // Shuffle the operands around so the lane index operand is in the
7250 // right place.
7251 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007252 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007253 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7254 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7255 Spacing));
7256 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007257 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007258 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7259 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7260 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7261 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7262 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7263 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7264 Spacing));
7265 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007266 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007267 TmpInst.addOperand(Inst.getOperand(1)); // lane
7268 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7269 TmpInst.addOperand(Inst.getOperand(5));
7270 Inst = TmpInst;
7271 return true;
7272 }
7273
Jim Grosbach14952a02012-01-24 18:37:25 +00007274 case ARM::VLD4LNdWB_fixed_Asm_8:
7275 case ARM::VLD4LNdWB_fixed_Asm_16:
7276 case ARM::VLD4LNdWB_fixed_Asm_32:
7277 case ARM::VLD4LNqWB_fixed_Asm_16:
7278 case ARM::VLD4LNqWB_fixed_Asm_32: {
7279 MCInst TmpInst;
7280 // Shuffle the operands around so the lane index operand is in the
7281 // right place.
7282 unsigned Spacing;
7283 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7284 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7285 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7286 Spacing));
7287 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7288 Spacing * 2));
7289 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7290 Spacing * 3));
7291 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
7292 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7293 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7294 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7295 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7296 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7297 Spacing));
7298 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7299 Spacing * 2));
7300 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7301 Spacing * 3));
7302 TmpInst.addOperand(Inst.getOperand(1)); // lane
7303 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7304 TmpInst.addOperand(Inst.getOperand(5));
7305 Inst = TmpInst;
7306 return true;
7307 }
7308
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007309 case ARM::VLD1LNdAsm_8:
7310 case ARM::VLD1LNdAsm_16:
7311 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00007312 MCInst TmpInst;
7313 // Shuffle the operands around so the lane index operand is in the
7314 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007315 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007316 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00007317 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7318 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7319 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7320 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7321 TmpInst.addOperand(Inst.getOperand(1)); // lane
7322 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7323 TmpInst.addOperand(Inst.getOperand(5));
7324 Inst = TmpInst;
7325 return true;
7326 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007327
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00007328 case ARM::VLD2LNdAsm_8:
7329 case ARM::VLD2LNdAsm_16:
7330 case ARM::VLD2LNdAsm_32:
7331 case ARM::VLD2LNqAsm_16:
7332 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007333 MCInst TmpInst;
7334 // Shuffle the operands around so the lane index operand is in the
7335 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007336 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007337 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007338 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007339 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7340 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007341 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7342 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7343 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00007344 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7345 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00007346 TmpInst.addOperand(Inst.getOperand(1)); // lane
7347 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7348 TmpInst.addOperand(Inst.getOperand(5));
7349 Inst = TmpInst;
7350 return true;
7351 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007352
7353 case ARM::VLD3LNdAsm_8:
7354 case ARM::VLD3LNdAsm_16:
7355 case ARM::VLD3LNdAsm_32:
7356 case ARM::VLD3LNqAsm_16:
7357 case ARM::VLD3LNqAsm_32: {
7358 MCInst TmpInst;
7359 // Shuffle the operands around so the lane index operand is in the
7360 // right place.
7361 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007362 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007363 TmpInst.addOperand(Inst.getOperand(0)); // 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(2)); // Rn
7369 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7370 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7371 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7372 Spacing));
7373 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007374 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00007375 TmpInst.addOperand(Inst.getOperand(1)); // lane
7376 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7377 TmpInst.addOperand(Inst.getOperand(5));
7378 Inst = TmpInst;
7379 return true;
7380 }
7381
Jim Grosbach14952a02012-01-24 18:37:25 +00007382 case ARM::VLD4LNdAsm_8:
7383 case ARM::VLD4LNdAsm_16:
7384 case ARM::VLD4LNdAsm_32:
7385 case ARM::VLD4LNqAsm_16:
7386 case ARM::VLD4LNqAsm_32: {
7387 MCInst TmpInst;
7388 // Shuffle the operands around so the lane index operand is in the
7389 // right place.
7390 unsigned Spacing;
7391 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7392 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7393 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7394 Spacing));
7395 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7396 Spacing * 2));
7397 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7398 Spacing * 3));
7399 TmpInst.addOperand(Inst.getOperand(2)); // Rn
7400 TmpInst.addOperand(Inst.getOperand(3)); // alignment
7401 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
7402 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7403 Spacing));
7404 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7405 Spacing * 2));
7406 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7407 Spacing * 3));
7408 TmpInst.addOperand(Inst.getOperand(1)); // lane
7409 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7410 TmpInst.addOperand(Inst.getOperand(5));
7411 Inst = TmpInst;
7412 return true;
7413 }
7414
Jim Grosbachb78403c2012-01-24 23:47:04 +00007415 // VLD3DUP single 3-element structure to all lanes instructions.
7416 case ARM::VLD3DUPdAsm_8:
7417 case ARM::VLD3DUPdAsm_16:
7418 case ARM::VLD3DUPdAsm_32:
7419 case ARM::VLD3DUPqAsm_8:
7420 case ARM::VLD3DUPqAsm_16:
7421 case ARM::VLD3DUPqAsm_32: {
7422 MCInst TmpInst;
7423 unsigned Spacing;
7424 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7425 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7426 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7427 Spacing));
7428 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7429 Spacing * 2));
7430 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7431 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7432 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7433 TmpInst.addOperand(Inst.getOperand(4));
7434 Inst = TmpInst;
7435 return true;
7436 }
7437
7438 case ARM::VLD3DUPdWB_fixed_Asm_8:
7439 case ARM::VLD3DUPdWB_fixed_Asm_16:
7440 case ARM::VLD3DUPdWB_fixed_Asm_32:
7441 case ARM::VLD3DUPqWB_fixed_Asm_8:
7442 case ARM::VLD3DUPqWB_fixed_Asm_16:
7443 case ARM::VLD3DUPqWB_fixed_Asm_32: {
7444 MCInst TmpInst;
7445 unsigned Spacing;
7446 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7447 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7448 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7449 Spacing));
7450 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7451 Spacing * 2));
7452 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7453 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7454 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7455 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7456 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7457 TmpInst.addOperand(Inst.getOperand(4));
7458 Inst = TmpInst;
7459 return true;
7460 }
7461
7462 case ARM::VLD3DUPdWB_register_Asm_8:
7463 case ARM::VLD3DUPdWB_register_Asm_16:
7464 case ARM::VLD3DUPdWB_register_Asm_32:
7465 case ARM::VLD3DUPqWB_register_Asm_8:
7466 case ARM::VLD3DUPqWB_register_Asm_16:
7467 case ARM::VLD3DUPqWB_register_Asm_32: {
7468 MCInst TmpInst;
7469 unsigned Spacing;
7470 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7471 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7472 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7473 Spacing));
7474 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7475 Spacing * 2));
7476 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7477 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7478 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7479 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7480 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7481 TmpInst.addOperand(Inst.getOperand(5));
7482 Inst = TmpInst;
7483 return true;
7484 }
7485
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007486 // VLD3 multiple 3-element structure instructions.
7487 case ARM::VLD3dAsm_8:
7488 case ARM::VLD3dAsm_16:
7489 case ARM::VLD3dAsm_32:
7490 case ARM::VLD3qAsm_8:
7491 case ARM::VLD3qAsm_16:
7492 case ARM::VLD3qAsm_32: {
7493 MCInst TmpInst;
7494 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007495 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007496 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7497 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7498 Spacing));
7499 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7500 Spacing * 2));
7501 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7502 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7503 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7504 TmpInst.addOperand(Inst.getOperand(4));
7505 Inst = TmpInst;
7506 return true;
7507 }
7508
7509 case ARM::VLD3dWB_fixed_Asm_8:
7510 case ARM::VLD3dWB_fixed_Asm_16:
7511 case ARM::VLD3dWB_fixed_Asm_32:
7512 case ARM::VLD3qWB_fixed_Asm_8:
7513 case ARM::VLD3qWB_fixed_Asm_16:
7514 case ARM::VLD3qWB_fixed_Asm_32: {
7515 MCInst TmpInst;
7516 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007517 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007518 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7519 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7520 Spacing));
7521 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7522 Spacing * 2));
7523 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7524 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7525 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7526 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7527 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7528 TmpInst.addOperand(Inst.getOperand(4));
7529 Inst = TmpInst;
7530 return true;
7531 }
7532
7533 case ARM::VLD3dWB_register_Asm_8:
7534 case ARM::VLD3dWB_register_Asm_16:
7535 case ARM::VLD3dWB_register_Asm_32:
7536 case ARM::VLD3qWB_register_Asm_8:
7537 case ARM::VLD3qWB_register_Asm_16:
7538 case ARM::VLD3qWB_register_Asm_32: {
7539 MCInst TmpInst;
7540 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00007541 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00007542 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7543 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7544 Spacing));
7545 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7546 Spacing * 2));
7547 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7548 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7549 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7550 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7551 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7552 TmpInst.addOperand(Inst.getOperand(5));
7553 Inst = TmpInst;
7554 return true;
7555 }
7556
Jim Grosbach086cbfa2012-01-25 00:01:08 +00007557 // VLD4DUP single 3-element structure to all lanes instructions.
7558 case ARM::VLD4DUPdAsm_8:
7559 case ARM::VLD4DUPdAsm_16:
7560 case ARM::VLD4DUPdAsm_32:
7561 case ARM::VLD4DUPqAsm_8:
7562 case ARM::VLD4DUPqAsm_16:
7563 case ARM::VLD4DUPqAsm_32: {
7564 MCInst TmpInst;
7565 unsigned Spacing;
7566 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7567 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7568 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7569 Spacing));
7570 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7571 Spacing * 2));
7572 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7573 Spacing * 3));
7574 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7575 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7576 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7577 TmpInst.addOperand(Inst.getOperand(4));
7578 Inst = TmpInst;
7579 return true;
7580 }
7581
7582 case ARM::VLD4DUPdWB_fixed_Asm_8:
7583 case ARM::VLD4DUPdWB_fixed_Asm_16:
7584 case ARM::VLD4DUPdWB_fixed_Asm_32:
7585 case ARM::VLD4DUPqWB_fixed_Asm_8:
7586 case ARM::VLD4DUPqWB_fixed_Asm_16:
7587 case ARM::VLD4DUPqWB_fixed_Asm_32: {
7588 MCInst TmpInst;
7589 unsigned Spacing;
7590 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7591 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7592 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7593 Spacing));
7594 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7595 Spacing * 2));
7596 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7597 Spacing * 3));
7598 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7599 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7600 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7601 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7602 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7603 TmpInst.addOperand(Inst.getOperand(4));
7604 Inst = TmpInst;
7605 return true;
7606 }
7607
7608 case ARM::VLD4DUPdWB_register_Asm_8:
7609 case ARM::VLD4DUPdWB_register_Asm_16:
7610 case ARM::VLD4DUPdWB_register_Asm_32:
7611 case ARM::VLD4DUPqWB_register_Asm_8:
7612 case ARM::VLD4DUPqWB_register_Asm_16:
7613 case ARM::VLD4DUPqWB_register_Asm_32: {
7614 MCInst TmpInst;
7615 unsigned Spacing;
7616 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7617 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7618 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7619 Spacing));
7620 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7621 Spacing * 2));
7622 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7623 Spacing * 3));
7624 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7625 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7626 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7627 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7628 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7629 TmpInst.addOperand(Inst.getOperand(5));
7630 Inst = TmpInst;
7631 return true;
7632 }
7633
7634 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00007635 case ARM::VLD4dAsm_8:
7636 case ARM::VLD4dAsm_16:
7637 case ARM::VLD4dAsm_32:
7638 case ARM::VLD4qAsm_8:
7639 case ARM::VLD4qAsm_16:
7640 case ARM::VLD4qAsm_32: {
7641 MCInst TmpInst;
7642 unsigned Spacing;
7643 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7644 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7645 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7646 Spacing));
7647 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7648 Spacing * 2));
7649 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7650 Spacing * 3));
7651 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7652 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7653 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7654 TmpInst.addOperand(Inst.getOperand(4));
7655 Inst = TmpInst;
7656 return true;
7657 }
7658
7659 case ARM::VLD4dWB_fixed_Asm_8:
7660 case ARM::VLD4dWB_fixed_Asm_16:
7661 case ARM::VLD4dWB_fixed_Asm_32:
7662 case ARM::VLD4qWB_fixed_Asm_8:
7663 case ARM::VLD4qWB_fixed_Asm_16:
7664 case ARM::VLD4qWB_fixed_Asm_32: {
7665 MCInst TmpInst;
7666 unsigned Spacing;
7667 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7668 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7669 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7670 Spacing));
7671 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7672 Spacing * 2));
7673 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7674 Spacing * 3));
7675 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7676 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7677 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7678 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7679 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7680 TmpInst.addOperand(Inst.getOperand(4));
7681 Inst = TmpInst;
7682 return true;
7683 }
7684
7685 case ARM::VLD4dWB_register_Asm_8:
7686 case ARM::VLD4dWB_register_Asm_16:
7687 case ARM::VLD4dWB_register_Asm_32:
7688 case ARM::VLD4qWB_register_Asm_8:
7689 case ARM::VLD4qWB_register_Asm_16:
7690 case ARM::VLD4qWB_register_Asm_32: {
7691 MCInst TmpInst;
7692 unsigned Spacing;
7693 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
7694 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7695 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7696 Spacing));
7697 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7698 Spacing * 2));
7699 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7700 Spacing * 3));
7701 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7702 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7703 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7704 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7705 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7706 TmpInst.addOperand(Inst.getOperand(5));
7707 Inst = TmpInst;
7708 return true;
7709 }
7710
Jim Grosbach1a747242012-01-23 23:45:44 +00007711 // VST3 multiple 3-element structure instructions.
7712 case ARM::VST3dAsm_8:
7713 case ARM::VST3dAsm_16:
7714 case ARM::VST3dAsm_32:
7715 case ARM::VST3qAsm_8:
7716 case ARM::VST3qAsm_16:
7717 case ARM::VST3qAsm_32: {
7718 MCInst TmpInst;
7719 unsigned Spacing;
7720 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7721 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7722 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7723 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7724 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7725 Spacing));
7726 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7727 Spacing * 2));
7728 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7729 TmpInst.addOperand(Inst.getOperand(4));
7730 Inst = TmpInst;
7731 return true;
7732 }
7733
7734 case ARM::VST3dWB_fixed_Asm_8:
7735 case ARM::VST3dWB_fixed_Asm_16:
7736 case ARM::VST3dWB_fixed_Asm_32:
7737 case ARM::VST3qWB_fixed_Asm_8:
7738 case ARM::VST3qWB_fixed_Asm_16:
7739 case ARM::VST3qWB_fixed_Asm_32: {
7740 MCInst TmpInst;
7741 unsigned Spacing;
7742 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7743 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7744 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7745 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7746 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7747 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7748 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7749 Spacing));
7750 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7751 Spacing * 2));
7752 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7753 TmpInst.addOperand(Inst.getOperand(4));
7754 Inst = TmpInst;
7755 return true;
7756 }
7757
7758 case ARM::VST3dWB_register_Asm_8:
7759 case ARM::VST3dWB_register_Asm_16:
7760 case ARM::VST3dWB_register_Asm_32:
7761 case ARM::VST3qWB_register_Asm_8:
7762 case ARM::VST3qWB_register_Asm_16:
7763 case ARM::VST3qWB_register_Asm_32: {
7764 MCInst TmpInst;
7765 unsigned Spacing;
7766 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7767 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7768 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7769 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7770 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7771 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7772 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7773 Spacing));
7774 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7775 Spacing * 2));
7776 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7777 TmpInst.addOperand(Inst.getOperand(5));
7778 Inst = TmpInst;
7779 return true;
7780 }
7781
Jim Grosbachda70eac2012-01-24 00:58:13 +00007782 // VST4 multiple 3-element structure instructions.
7783 case ARM::VST4dAsm_8:
7784 case ARM::VST4dAsm_16:
7785 case ARM::VST4dAsm_32:
7786 case ARM::VST4qAsm_8:
7787 case ARM::VST4qAsm_16:
7788 case ARM::VST4qAsm_32: {
7789 MCInst TmpInst;
7790 unsigned Spacing;
7791 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7792 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7793 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7794 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7795 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7796 Spacing));
7797 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7798 Spacing * 2));
7799 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7800 Spacing * 3));
7801 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7802 TmpInst.addOperand(Inst.getOperand(4));
7803 Inst = TmpInst;
7804 return true;
7805 }
7806
7807 case ARM::VST4dWB_fixed_Asm_8:
7808 case ARM::VST4dWB_fixed_Asm_16:
7809 case ARM::VST4dWB_fixed_Asm_32:
7810 case ARM::VST4qWB_fixed_Asm_8:
7811 case ARM::VST4qWB_fixed_Asm_16:
7812 case ARM::VST4qWB_fixed_Asm_32: {
7813 MCInst TmpInst;
7814 unsigned Spacing;
7815 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7816 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7817 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7818 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7819 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7820 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7821 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7822 Spacing));
7823 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7824 Spacing * 2));
7825 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7826 Spacing * 3));
7827 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7828 TmpInst.addOperand(Inst.getOperand(4));
7829 Inst = TmpInst;
7830 return true;
7831 }
7832
7833 case ARM::VST4dWB_register_Asm_8:
7834 case ARM::VST4dWB_register_Asm_16:
7835 case ARM::VST4dWB_register_Asm_32:
7836 case ARM::VST4qWB_register_Asm_8:
7837 case ARM::VST4qWB_register_Asm_16:
7838 case ARM::VST4qWB_register_Asm_32: {
7839 MCInst TmpInst;
7840 unsigned Spacing;
7841 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7842 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7843 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7844 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7845 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7846 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7847 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7848 Spacing));
7849 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7850 Spacing * 2));
7851 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7852 Spacing * 3));
7853 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7854 TmpInst.addOperand(Inst.getOperand(5));
7855 Inst = TmpInst;
7856 return true;
7857 }
7858
Jim Grosbachad66de12012-04-11 00:15:16 +00007859 // Handle encoding choice for the shift-immediate instructions.
7860 case ARM::t2LSLri:
7861 case ARM::t2LSRri:
7862 case ARM::t2ASRri: {
7863 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7864 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7865 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
David Blaikie960ea3f2014-06-08 16:18:35 +00007866 !(static_cast<ARMOperand &>(*Operands[3]).isToken() &&
7867 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w")) {
Jim Grosbachad66de12012-04-11 00:15:16 +00007868 unsigned NewOpc;
7869 switch (Inst.getOpcode()) {
7870 default: llvm_unreachable("unexpected opcode");
7871 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
7872 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
7873 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
7874 }
7875 // The Thumb1 operands aren't in the same order. Awesome, eh?
7876 MCInst TmpInst;
7877 TmpInst.setOpcode(NewOpc);
7878 TmpInst.addOperand(Inst.getOperand(0));
7879 TmpInst.addOperand(Inst.getOperand(5));
7880 TmpInst.addOperand(Inst.getOperand(1));
7881 TmpInst.addOperand(Inst.getOperand(2));
7882 TmpInst.addOperand(Inst.getOperand(3));
7883 TmpInst.addOperand(Inst.getOperand(4));
7884 Inst = TmpInst;
7885 return true;
7886 }
7887 return false;
7888 }
7889
Jim Grosbach485e5622011-12-13 22:45:11 +00007890 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00007891 case ARM::t2MOVsr:
7892 case ARM::t2MOVSsr: {
7893 // Which instruction to expand to depends on the CCOut operand and
7894 // whether we're in an IT block if the register operands are low
7895 // registers.
7896 bool isNarrow = false;
7897 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7898 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7899 isARMLowRegister(Inst.getOperand(2).getReg()) &&
7900 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7901 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
7902 isNarrow = true;
7903 MCInst TmpInst;
7904 unsigned newOpc;
7905 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
7906 default: llvm_unreachable("unexpected opcode!");
7907 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
7908 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
7909 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
7910 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
7911 }
7912 TmpInst.setOpcode(newOpc);
7913 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7914 if (isNarrow)
7915 TmpInst.addOperand(MCOperand::CreateReg(
7916 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7917 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7918 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7919 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7920 TmpInst.addOperand(Inst.getOperand(5));
7921 if (!isNarrow)
7922 TmpInst.addOperand(MCOperand::CreateReg(
7923 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7924 Inst = TmpInst;
7925 return true;
7926 }
Jim Grosbach485e5622011-12-13 22:45:11 +00007927 case ARM::t2MOVsi:
7928 case ARM::t2MOVSsi: {
7929 // Which instruction to expand to depends on the CCOut operand and
7930 // whether we're in an IT block if the register operands are low
7931 // registers.
7932 bool isNarrow = false;
7933 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7934 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7935 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
7936 isNarrow = true;
7937 MCInst TmpInst;
7938 unsigned newOpc;
7939 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
7940 default: llvm_unreachable("unexpected opcode!");
7941 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
7942 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
7943 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
7944 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007945 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00007946 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00007947 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
7948 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00007949 TmpInst.setOpcode(newOpc);
7950 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7951 if (isNarrow)
7952 TmpInst.addOperand(MCOperand::CreateReg(
7953 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7954 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007955 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00007956 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00007957 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7958 TmpInst.addOperand(Inst.getOperand(4));
7959 if (!isNarrow)
7960 TmpInst.addOperand(MCOperand::CreateReg(
7961 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7962 Inst = TmpInst;
7963 return true;
7964 }
7965 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00007966 case ARM::ASRr:
7967 case ARM::LSRr:
7968 case ARM::LSLr:
7969 case ARM::RORr: {
7970 ARM_AM::ShiftOpc ShiftTy;
7971 switch(Inst.getOpcode()) {
7972 default: llvm_unreachable("unexpected opcode!");
7973 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7974 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7975 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7976 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7977 }
Jim Grosbachabcac562011-11-16 18:31:45 +00007978 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7979 MCInst TmpInst;
7980 TmpInst.setOpcode(ARM::MOVsr);
7981 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7982 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7983 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7984 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7985 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7986 TmpInst.addOperand(Inst.getOperand(4));
7987 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7988 Inst = TmpInst;
7989 return true;
7990 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00007991 case ARM::ASRi:
7992 case ARM::LSRi:
7993 case ARM::LSLi:
7994 case ARM::RORi: {
7995 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007996 switch(Inst.getOpcode()) {
7997 default: llvm_unreachable("unexpected opcode!");
7998 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7999 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
8000 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
8001 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
8002 }
8003 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00008004 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00008005 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00008006 // A shift by 32 should be encoded as 0 when permitted
8007 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
8008 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00008009 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00008010 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00008011 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00008012 TmpInst.addOperand(Inst.getOperand(0)); // Rd
8013 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00008014 if (Opc == ARM::MOVsi)
8015 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00008016 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
8017 TmpInst.addOperand(Inst.getOperand(4));
8018 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
8019 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00008020 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00008021 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00008022 case ARM::RRXi: {
8023 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
8024 MCInst TmpInst;
8025 TmpInst.setOpcode(ARM::MOVsi);
8026 TmpInst.addOperand(Inst.getOperand(0)); // Rd
8027 TmpInst.addOperand(Inst.getOperand(1)); // Rn
8028 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
8029 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
8030 TmpInst.addOperand(Inst.getOperand(3));
8031 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
8032 Inst = TmpInst;
8033 return true;
8034 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00008035 case ARM::t2LDMIA_UPD: {
8036 // If this is a load of a single register, then we should use
8037 // a post-indexed LDR instruction instead, per the ARM ARM.
8038 if (Inst.getNumOperands() != 5)
8039 return false;
8040 MCInst TmpInst;
8041 TmpInst.setOpcode(ARM::t2LDR_POST);
8042 TmpInst.addOperand(Inst.getOperand(4)); // Rt
8043 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
8044 TmpInst.addOperand(Inst.getOperand(1)); // Rn
8045 TmpInst.addOperand(MCOperand::CreateImm(4));
8046 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
8047 TmpInst.addOperand(Inst.getOperand(3));
8048 Inst = TmpInst;
8049 return true;
8050 }
8051 case ARM::t2STMDB_UPD: {
8052 // If this is a store of a single register, then we should use
8053 // a pre-indexed STR instruction instead, per the ARM ARM.
8054 if (Inst.getNumOperands() != 5)
8055 return false;
8056 MCInst TmpInst;
8057 TmpInst.setOpcode(ARM::t2STR_PRE);
8058 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
8059 TmpInst.addOperand(Inst.getOperand(4)); // Rt
8060 TmpInst.addOperand(Inst.getOperand(1)); // Rn
8061 TmpInst.addOperand(MCOperand::CreateImm(-4));
8062 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
8063 TmpInst.addOperand(Inst.getOperand(3));
8064 Inst = TmpInst;
8065 return true;
8066 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008067 case ARM::LDMIA_UPD:
8068 // If this is a load of a single register via a 'pop', then we should use
8069 // a post-indexed LDR instruction instead, per the ARM ARM.
David Blaikie960ea3f2014-06-08 16:18:35 +00008070 if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "pop" &&
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008071 Inst.getNumOperands() == 5) {
8072 MCInst TmpInst;
8073 TmpInst.setOpcode(ARM::LDR_POST_IMM);
8074 TmpInst.addOperand(Inst.getOperand(4)); // Rt
8075 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
8076 TmpInst.addOperand(Inst.getOperand(1)); // Rn
8077 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
8078 TmpInst.addOperand(MCOperand::CreateImm(4));
8079 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
8080 TmpInst.addOperand(Inst.getOperand(3));
8081 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00008082 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008083 }
8084 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00008085 case ARM::STMDB_UPD:
8086 // If this is a store of a single register via a 'push', then we should use
8087 // a pre-indexed STR instruction instead, per the ARM ARM.
David Blaikie960ea3f2014-06-08 16:18:35 +00008088 if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "push" &&
Jim Grosbach27ad83d2011-08-11 18:07:11 +00008089 Inst.getNumOperands() == 5) {
8090 MCInst TmpInst;
8091 TmpInst.setOpcode(ARM::STR_PRE_IMM);
8092 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
8093 TmpInst.addOperand(Inst.getOperand(4)); // Rt
8094 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
8095 TmpInst.addOperand(MCOperand::CreateImm(-4));
8096 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
8097 TmpInst.addOperand(Inst.getOperand(3));
8098 Inst = TmpInst;
8099 }
8100 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00008101 case ARM::t2ADDri12:
8102 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
8103 // mnemonic was used (not "addw"), encoding T3 is preferred.
David Blaikie960ea3f2014-06-08 16:18:35 +00008104 if (static_cast<ARMOperand &>(*Operands[0]).getToken() != "add" ||
Jim Grosbachec9ba982011-12-05 21:06:26 +00008105 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
8106 break;
8107 Inst.setOpcode(ARM::t2ADDri);
8108 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
8109 break;
8110 case ARM::t2SUBri12:
8111 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
8112 // mnemonic was used (not "subw"), encoding T3 is preferred.
David Blaikie960ea3f2014-06-08 16:18:35 +00008113 if (static_cast<ARMOperand &>(*Operands[0]).getToken() != "sub" ||
Jim Grosbachec9ba982011-12-05 21:06:26 +00008114 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
8115 break;
8116 Inst.setOpcode(ARM::t2SUBri);
8117 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
8118 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00008119 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00008120 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00008121 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
8122 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
8123 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00008124 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00008125 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00008126 return true;
8127 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00008128 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00008129 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00008130 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00008131 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
8132 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
8133 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00008134 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00008135 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00008136 return true;
8137 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00008138 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00008139 case ARM::t2ADDri:
8140 case ARM::t2SUBri: {
8141 // If the destination and first source operand are the same, and
8142 // the flags are compatible with the current IT status, use encoding T2
8143 // instead of T3. For compatibility with the system 'as'. Make sure the
8144 // wide encoding wasn't explicit.
8145 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00008146 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00008147 (unsigned)Inst.getOperand(2).getImm() > 255 ||
8148 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
David Blaikie960ea3f2014-06-08 16:18:35 +00008149 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
8150 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
8151 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w"))
Jim Grosbachdef5e342012-03-30 17:20:40 +00008152 break;
8153 MCInst TmpInst;
8154 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
8155 ARM::tADDi8 : ARM::tSUBi8);
8156 TmpInst.addOperand(Inst.getOperand(0));
8157 TmpInst.addOperand(Inst.getOperand(5));
8158 TmpInst.addOperand(Inst.getOperand(0));
8159 TmpInst.addOperand(Inst.getOperand(2));
8160 TmpInst.addOperand(Inst.getOperand(3));
8161 TmpInst.addOperand(Inst.getOperand(4));
8162 Inst = TmpInst;
8163 return true;
8164 }
Jim Grosbache489bab2011-12-05 22:16:39 +00008165 case ARM::t2ADDrr: {
8166 // If the destination and first source operand are the same, and
8167 // there's no setting of the flags, use encoding T2 instead of T3.
8168 // Note that this is only for ADD, not SUB. This mirrors the system
8169 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
8170 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
8171 Inst.getOperand(5).getReg() != 0 ||
David Blaikie960ea3f2014-06-08 16:18:35 +00008172 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
8173 static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00008174 break;
8175 MCInst TmpInst;
8176 TmpInst.setOpcode(ARM::tADDhirr);
8177 TmpInst.addOperand(Inst.getOperand(0));
8178 TmpInst.addOperand(Inst.getOperand(0));
8179 TmpInst.addOperand(Inst.getOperand(2));
8180 TmpInst.addOperand(Inst.getOperand(3));
8181 TmpInst.addOperand(Inst.getOperand(4));
8182 Inst = TmpInst;
8183 return true;
8184 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00008185 case ARM::tADDrSP: {
8186 // If the non-SP source operand and the destination operand are not the
8187 // same, we need to use the 32-bit encoding if it's available.
8188 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
8189 Inst.setOpcode(ARM::t2ADDrr);
8190 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
8191 return true;
8192 }
8193 break;
8194 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00008195 case ARM::tB:
8196 // A Thumb conditional branch outside of an IT block is a tBcc.
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::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00008199 return true;
8200 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00008201 break;
8202 case ARM::t2B:
8203 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00008204 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00008205 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00008206 return true;
8207 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00008208 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00008209 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008210 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00008211 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00008212 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00008213 return true;
8214 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00008215 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00008216 case ARM::tBcc:
8217 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00008218 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00008219 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00008220 return true;
8221 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00008222 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00008223 case ARM::tLDMIA: {
8224 // If the register list contains any high registers, or if the writeback
8225 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
8226 // instead if we're in Thumb2. Otherwise, this should have generated
8227 // an error in validateInstruction().
8228 unsigned Rn = Inst.getOperand(0).getReg();
8229 bool hasWritebackToken =
David Blaikie960ea3f2014-06-08 16:18:35 +00008230 (static_cast<ARMOperand &>(*Operands[3]).isToken() &&
8231 static_cast<ARMOperand &>(*Operands[3]).getToken() == "!");
Jim Grosbacha31f2232011-09-07 18:05:34 +00008232 bool listContainsBase;
8233 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
8234 (!listContainsBase && !hasWritebackToken) ||
8235 (listContainsBase && hasWritebackToken)) {
8236 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
8237 assert (isThumbTwo());
8238 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
8239 // If we're switching to the updating version, we need to insert
8240 // the writeback tied operand.
8241 if (hasWritebackToken)
8242 Inst.insert(Inst.begin(),
8243 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00008244 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00008245 }
8246 break;
8247 }
Jim Grosbach099c9762011-09-16 20:50:13 +00008248 case ARM::tSTMIA_UPD: {
8249 // If the register list contains any high registers, we need to use
8250 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
8251 // should have generated an error in validateInstruction().
8252 unsigned Rn = Inst.getOperand(0).getReg();
8253 bool listContainsBase;
8254 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
8255 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
8256 assert (isThumbTwo());
8257 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00008258 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00008259 }
8260 break;
8261 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00008262 case ARM::tPOP: {
8263 bool listContainsBase;
8264 // If the register list contains any high registers, we need to use
8265 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
8266 // should have generated an error in validateInstruction().
8267 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00008268 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00008269 assert (isThumbTwo());
8270 Inst.setOpcode(ARM::t2LDMIA_UPD);
8271 // Add the base register and writeback operands.
8272 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
8273 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00008274 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00008275 }
8276 case ARM::tPUSH: {
8277 bool listContainsBase;
8278 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00008279 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00008280 assert (isThumbTwo());
8281 Inst.setOpcode(ARM::t2STMDB_UPD);
8282 // Add the base register and writeback operands.
8283 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
8284 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00008285 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00008286 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00008287 case ARM::t2MOVi: {
8288 // If we can use the 16-bit encoding and the user didn't explicitly
8289 // request the 32-bit variant, transform it here.
8290 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00008291 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00008292 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
David Blaikie960ea3f2014-06-08 16:18:35 +00008293 Inst.getOperand(4).getReg() == ARM::CPSR) ||
8294 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
8295 (!static_cast<ARMOperand &>(*Operands[2]).isToken() ||
8296 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) {
Jim Grosbachb908b7a2011-09-10 00:15:36 +00008297 // The operands aren't in the same order for tMOVi8...
8298 MCInst TmpInst;
8299 TmpInst.setOpcode(ARM::tMOVi8);
8300 TmpInst.addOperand(Inst.getOperand(0));
8301 TmpInst.addOperand(Inst.getOperand(4));
8302 TmpInst.addOperand(Inst.getOperand(1));
8303 TmpInst.addOperand(Inst.getOperand(2));
8304 TmpInst.addOperand(Inst.getOperand(3));
8305 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00008306 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00008307 }
8308 break;
8309 }
8310 case ARM::t2MOVr: {
8311 // If we can use the 16-bit encoding and the user didn't explicitly
8312 // request the 32-bit variant, transform it here.
8313 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
8314 isARMLowRegister(Inst.getOperand(1).getReg()) &&
8315 Inst.getOperand(2).getImm() == ARMCC::AL &&
8316 Inst.getOperand(4).getReg() == ARM::CPSR &&
David Blaikie960ea3f2014-06-08 16:18:35 +00008317 (!static_cast<ARMOperand &>(*Operands[2]).isToken() ||
8318 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) {
Jim Grosbachb908b7a2011-09-10 00:15:36 +00008319 // The operands aren't the same for tMOV[S]r... (no cc_out)
8320 MCInst TmpInst;
8321 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
8322 TmpInst.addOperand(Inst.getOperand(0));
8323 TmpInst.addOperand(Inst.getOperand(1));
8324 TmpInst.addOperand(Inst.getOperand(2));
8325 TmpInst.addOperand(Inst.getOperand(3));
8326 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00008327 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00008328 }
8329 break;
8330 }
Jim Grosbach82213192011-09-19 20:29:33 +00008331 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00008332 case ARM::t2SXTB:
8333 case ARM::t2UXTH:
8334 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00008335 // If we can use the 16-bit encoding and the user didn't explicitly
8336 // request the 32-bit variant, transform it here.
8337 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
8338 isARMLowRegister(Inst.getOperand(1).getReg()) &&
8339 Inst.getOperand(2).getImm() == 0 &&
David Blaikie960ea3f2014-06-08 16:18:35 +00008340 (!static_cast<ARMOperand &>(*Operands[2]).isToken() ||
8341 static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00008342 unsigned NewOpc;
8343 switch (Inst.getOpcode()) {
8344 default: llvm_unreachable("Illegal opcode!");
8345 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
8346 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
8347 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
8348 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
8349 }
Jim Grosbach82213192011-09-19 20:29:33 +00008350 // The operands aren't the same for thumb1 (no rotate operand).
8351 MCInst TmpInst;
8352 TmpInst.setOpcode(NewOpc);
8353 TmpInst.addOperand(Inst.getOperand(0));
8354 TmpInst.addOperand(Inst.getOperand(1));
8355 TmpInst.addOperand(Inst.getOperand(3));
8356 TmpInst.addOperand(Inst.getOperand(4));
8357 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00008358 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00008359 }
8360 break;
8361 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00008362 case ARM::MOVsi: {
8363 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00008364 // rrx shifts and asr/lsr of #32 is encoded as 0
8365 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
8366 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00008367 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
8368 // Shifting by zero is accepted as a vanilla 'MOVr'
8369 MCInst TmpInst;
8370 TmpInst.setOpcode(ARM::MOVr);
8371 TmpInst.addOperand(Inst.getOperand(0));
8372 TmpInst.addOperand(Inst.getOperand(1));
8373 TmpInst.addOperand(Inst.getOperand(3));
8374 TmpInst.addOperand(Inst.getOperand(4));
8375 TmpInst.addOperand(Inst.getOperand(5));
8376 Inst = TmpInst;
8377 return true;
8378 }
8379 return false;
8380 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00008381 case ARM::ANDrsi:
8382 case ARM::ORRrsi:
8383 case ARM::EORrsi:
8384 case ARM::BICrsi:
8385 case ARM::SUBrsi:
8386 case ARM::ADDrsi: {
8387 unsigned newOpc;
8388 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
8389 if (SOpc == ARM_AM::rrx) return false;
8390 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00008391 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00008392 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
8393 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
8394 case ARM::EORrsi: newOpc = ARM::EORrr; break;
8395 case ARM::BICrsi: newOpc = ARM::BICrr; break;
8396 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
8397 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
8398 }
8399 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00008400 // The exception is for right shifts, where 0 == 32
8401 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
8402 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00008403 MCInst TmpInst;
8404 TmpInst.setOpcode(newOpc);
8405 TmpInst.addOperand(Inst.getOperand(0));
8406 TmpInst.addOperand(Inst.getOperand(1));
8407 TmpInst.addOperand(Inst.getOperand(2));
8408 TmpInst.addOperand(Inst.getOperand(4));
8409 TmpInst.addOperand(Inst.getOperand(5));
8410 TmpInst.addOperand(Inst.getOperand(6));
8411 Inst = TmpInst;
8412 return true;
8413 }
8414 return false;
8415 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00008416 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008417 case ARM::t2IT: {
8418 // The mask bits for all but the first condition are represented as
8419 // the low bit of the condition code value implies 't'. We currently
8420 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00008421 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008422 MCOperand &MO = Inst.getOperand(1);
8423 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00008424 unsigned OrigMask = Mask;
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +00008425 unsigned TZ = countTrailingZeros(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008426 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008427 assert(Mask && TZ <= 3 && "illegal IT mask value!");
Benjamin Kramer8bad66e2013-05-19 22:01:57 +00008428 Mask ^= (0xE << TZ) & 0xF;
Richard Bartonf435b092012-04-27 08:42:59 +00008429 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008430 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00008431
8432 // Set up the IT block state according to the IT instruction we just
8433 // matched.
8434 assert(!inITBlock() && "nested IT blocks?!");
8435 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
8436 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
8437 ITState.CurPosition = 0;
8438 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00008439 break;
8440 }
Richard Bartona39625e2012-07-09 16:12:24 +00008441 case ARM::t2LSLrr:
8442 case ARM::t2LSRrr:
8443 case ARM::t2ASRrr:
8444 case ARM::t2SBCrr:
8445 case ARM::t2RORrr:
8446 case ARM::t2BICrr:
8447 {
Richard Bartond5660372012-07-09 16:14:28 +00008448 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00008449 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
8450 isARMLowRegister(Inst.getOperand(2).getReg())) &&
8451 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00008452 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
David Blaikie960ea3f2014-06-08 16:18:35 +00008453 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
8454 (!static_cast<ARMOperand &>(*Operands[3]).isToken() ||
8455 !static_cast<ARMOperand &>(*Operands[3]).getToken().equals_lower(
8456 ".w"))) {
Richard Bartona39625e2012-07-09 16:12:24 +00008457 unsigned NewOpc;
8458 switch (Inst.getOpcode()) {
8459 default: llvm_unreachable("unexpected opcode");
8460 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
8461 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
8462 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
8463 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
8464 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
8465 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
8466 }
8467 MCInst TmpInst;
8468 TmpInst.setOpcode(NewOpc);
8469 TmpInst.addOperand(Inst.getOperand(0));
8470 TmpInst.addOperand(Inst.getOperand(5));
8471 TmpInst.addOperand(Inst.getOperand(1));
8472 TmpInst.addOperand(Inst.getOperand(2));
8473 TmpInst.addOperand(Inst.getOperand(3));
8474 TmpInst.addOperand(Inst.getOperand(4));
8475 Inst = TmpInst;
8476 return true;
8477 }
8478 return false;
8479 }
8480 case ARM::t2ANDrr:
8481 case ARM::t2EORrr:
8482 case ARM::t2ADCrr:
8483 case ARM::t2ORRrr:
8484 {
Richard Bartond5660372012-07-09 16:14:28 +00008485 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00008486 // These instructions are special in that they are commutable, so shorter encodings
8487 // are available more often.
8488 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
8489 isARMLowRegister(Inst.getOperand(2).getReg())) &&
8490 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
8491 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00008492 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
David Blaikie960ea3f2014-06-08 16:18:35 +00008493 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
8494 (!static_cast<ARMOperand &>(*Operands[3]).isToken() ||
8495 !static_cast<ARMOperand &>(*Operands[3]).getToken().equals_lower(
8496 ".w"))) {
Richard Bartona39625e2012-07-09 16:12:24 +00008497 unsigned NewOpc;
8498 switch (Inst.getOpcode()) {
8499 default: llvm_unreachable("unexpected opcode");
8500 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
8501 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
8502 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
8503 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
8504 }
8505 MCInst TmpInst;
8506 TmpInst.setOpcode(NewOpc);
8507 TmpInst.addOperand(Inst.getOperand(0));
8508 TmpInst.addOperand(Inst.getOperand(5));
8509 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
8510 TmpInst.addOperand(Inst.getOperand(1));
8511 TmpInst.addOperand(Inst.getOperand(2));
8512 } else {
8513 TmpInst.addOperand(Inst.getOperand(2));
8514 TmpInst.addOperand(Inst.getOperand(1));
8515 }
8516 TmpInst.addOperand(Inst.getOperand(3));
8517 TmpInst.addOperand(Inst.getOperand(4));
8518 Inst = TmpInst;
8519 return true;
8520 }
8521 return false;
8522 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008523 }
Jim Grosbachafad0532011-11-10 23:42:14 +00008524 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008525}
8526
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008527unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
8528 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
8529 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008530 unsigned Opc = Inst.getOpcode();
Joey Gouly0e76fa72013-09-12 10:28:05 +00008531 const MCInstrDesc &MCID = MII.get(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008532 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
8533 assert(MCID.hasOptionalDef() &&
8534 "optionally flag setting instruction missing optional def operand");
8535 assert(MCID.NumOperands == Inst.getNumOperands() &&
8536 "operand count mismatch!");
8537 // Find the optional-def operand (cc_out).
8538 unsigned OpNo;
8539 for (OpNo = 0;
8540 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
8541 ++OpNo)
8542 ;
8543 // If we're parsing Thumb1, reject it completely.
8544 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
8545 return Match_MnemonicFail;
8546 // If we're parsing Thumb2, which form is legal depends on whether we're
8547 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00008548 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
8549 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008550 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00008551 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
8552 inITBlock())
8553 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008554 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008555 // Some high-register supporting Thumb1 encodings only allow both registers
8556 // to be from r0-r7 when in Thumb2.
Renato Golin36c626e2014-09-26 16:14:29 +00008557 else if (Opc == ARM::tADDhirr && isThumbOne() && !hasV6MOps() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008558 isARMLowRegister(Inst.getOperand(1).getReg()) &&
8559 isARMLowRegister(Inst.getOperand(2).getReg()))
8560 return Match_RequiresThumb2;
8561 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00008562 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008563 isARMLowRegister(Inst.getOperand(0).getReg()) &&
8564 isARMLowRegister(Inst.getOperand(1).getReg()))
8565 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008566 return Match_Success;
8567}
8568
Benjamin Kramer44a53da2014-04-12 18:45:24 +00008569namespace llvm {
8570template <> inline bool IsCPSRDead<MCInst>(MCInst *Instr) {
Artyom Skrobov1a6cd1d2014-02-26 11:27:28 +00008571 return true; // In an assembly source, no need to second-guess
8572}
Benjamin Kramer44a53da2014-04-12 18:45:24 +00008573}
Artyom Skrobov1a6cd1d2014-02-26 11:27:28 +00008574
Tim Northover26bb14e2014-08-18 11:49:42 +00008575static const char *getSubtargetFeatureName(uint64_t Val);
David Blaikie960ea3f2014-06-08 16:18:35 +00008576bool ARMAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
8577 OperandVector &Operands,
Tim Northover26bb14e2014-08-18 11:49:42 +00008578 MCStreamer &Out, uint64_t &ErrorInfo,
David Blaikie960ea3f2014-06-08 16:18:35 +00008579 bool MatchingInlineAsm) {
Chris Lattner9487de62010-10-28 21:28:01 +00008580 MCInst Inst;
Jim Grosbach120a96a2011-08-15 23:03:29 +00008581 unsigned MatchResult;
Weiming Zhao8f56f882012-11-16 21:55:34 +00008582
Chad Rosier2f480a82012-10-12 22:53:36 +00008583 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
Chad Rosier49963552012-10-13 00:26:04 +00008584 MatchingInlineAsm);
Kevin Enderby3164a342010-12-09 19:19:43 +00008585 switch (MatchResult) {
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008586 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00008587 // Context sensitive operand constraints aren't handled by the matcher,
8588 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008589 if (validateInstruction(Inst, Operands)) {
8590 // Still progress the IT block, otherwise one wrong condition causes
8591 // nasty cascading errors.
8592 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00008593 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008594 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00008595
Amara Emerson52cfb6a2013-10-03 09:31:51 +00008596 { // processInstruction() updates inITBlock state, we need to save it away
8597 bool wasInITBlock = inITBlock();
8598
8599 // Some instructions need post-processing to, for example, tweak which
8600 // encoding is selected. Loop on it while changes happen so the
8601 // individual transformations can chain off each other. E.g.,
8602 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
Joerg Sonnenberger02b13a82014-11-21 22:39:34 +00008603 while (processInstruction(Inst, Operands, Out))
Amara Emerson52cfb6a2013-10-03 09:31:51 +00008604 ;
8605
8606 // Only after the instruction is fully processed, we can validate it
8607 if (wasInITBlock && hasV8Ops() && isThumb() &&
Weiming Zhao5930ae62014-01-23 19:55:33 +00008608 !isV8EligibleForIT(&Inst)) {
Amara Emerson52cfb6a2013-10-03 09:31:51 +00008609 Warning(IDLoc, "deprecated instruction in IT block");
8610 }
8611 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00008612
Jim Grosbacha0d34d32011-09-02 23:22:08 +00008613 // Only move forward at the very end so that everything in validate
8614 // and process gets a consistent answer about whether we're in an IT
8615 // block.
8616 forwardITPosition();
8617
Jim Grosbach82f76d12012-01-25 19:52:01 +00008618 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
8619 // doesn't actually encode.
8620 if (Inst.getOpcode() == ARM::ITasm)
8621 return false;
8622
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00008623 Inst.setLoc(IDLoc);
David Woodhousee6c13e42014-01-28 23:12:42 +00008624 Out.EmitInstruction(Inst, STI);
Chris Lattner9487de62010-10-28 21:28:01 +00008625 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00008626 case Match_MissingFeature: {
8627 assert(ErrorInfo && "Unknown missing feature!");
8628 // Special case the error message for the very common case where only
8629 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
8630 std::string Msg = "instruction requires:";
Tim Northover26bb14e2014-08-18 11:49:42 +00008631 uint64_t Mask = 1;
Jim Grosbach5117ef72012-04-24 22:40:08 +00008632 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
8633 if (ErrorInfo & Mask) {
8634 Msg += " ";
8635 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
8636 }
8637 Mask <<= 1;
8638 }
8639 return Error(IDLoc, Msg);
8640 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008641 case Match_InvalidOperand: {
8642 SMLoc ErrorLoc = IDLoc;
Tim Northover26bb14e2014-08-18 11:49:42 +00008643 if (ErrorInfo != ~0ULL) {
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008644 if (ErrorInfo >= Operands.size())
8645 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00008646
David Blaikie960ea3f2014-06-08 16:18:35 +00008647 ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc();
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008648 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8649 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00008650
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008651 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00008652 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008653 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00008654 return Error(IDLoc, "invalid instruction",
David Blaikie960ea3f2014-06-08 16:18:35 +00008655 ((ARMOperand &)*Operands[0]).getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00008656 case Match_RequiresNotITBlock:
8657 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00008658 case Match_RequiresITBlock:
8659 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00008660 case Match_RequiresV6:
8661 return Error(IDLoc, "instruction variant requires ARMv6 or later");
8662 case Match_RequiresThumb2:
8663 return Error(IDLoc, "instruction variant requires Thumb2");
Jim Grosbach087affe2012-06-22 23:56:48 +00008664 case Match_ImmRange0_15: {
David Blaikie960ea3f2014-06-08 16:18:35 +00008665 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc();
Jim Grosbach087affe2012-06-22 23:56:48 +00008666 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8667 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
8668 }
Artyom Skrobovfc12e702013-10-23 10:14:40 +00008669 case Match_ImmRange0_239: {
David Blaikie960ea3f2014-06-08 16:18:35 +00008670 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc();
Artyom Skrobovfc12e702013-10-23 10:14:40 +00008671 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8672 return Error(ErrorLoc, "immediate operand must be in the range [0,239]");
8673 }
Kevin Enderby488f20b2014-04-10 20:18:58 +00008674 case Match_AlignedMemoryRequiresNone:
8675 case Match_DupAlignedMemoryRequiresNone:
8676 case Match_AlignedMemoryRequires16:
8677 case Match_DupAlignedMemoryRequires16:
8678 case Match_AlignedMemoryRequires32:
8679 case Match_DupAlignedMemoryRequires32:
8680 case Match_AlignedMemoryRequires64:
8681 case Match_DupAlignedMemoryRequires64:
8682 case Match_AlignedMemoryRequires64or128:
8683 case Match_DupAlignedMemoryRequires64or128:
8684 case Match_AlignedMemoryRequires64or128or256:
8685 {
David Blaikie960ea3f2014-06-08 16:18:35 +00008686 SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getAlignmentLoc();
Kevin Enderby488f20b2014-04-10 20:18:58 +00008687 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
8688 switch (MatchResult) {
8689 default:
8690 llvm_unreachable("Missing Match_Aligned type");
8691 case Match_AlignedMemoryRequiresNone:
8692 case Match_DupAlignedMemoryRequiresNone:
8693 return Error(ErrorLoc, "alignment must be omitted");
8694 case Match_AlignedMemoryRequires16:
8695 case Match_DupAlignedMemoryRequires16:
8696 return Error(ErrorLoc, "alignment must be 16 or omitted");
8697 case Match_AlignedMemoryRequires32:
8698 case Match_DupAlignedMemoryRequires32:
8699 return Error(ErrorLoc, "alignment must be 32 or omitted");
8700 case Match_AlignedMemoryRequires64:
8701 case Match_DupAlignedMemoryRequires64:
8702 return Error(ErrorLoc, "alignment must be 64 or omitted");
8703 case Match_AlignedMemoryRequires64or128:
8704 case Match_DupAlignedMemoryRequires64or128:
8705 return Error(ErrorLoc, "alignment must be 64, 128 or omitted");
8706 case Match_AlignedMemoryRequires64or128or256:
8707 return Error(ErrorLoc, "alignment must be 64, 128, 256 or omitted");
8708 }
8709 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00008710 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00008711
Eric Christopher91d7b902010-10-29 09:26:59 +00008712 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00008713}
8714
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008715/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00008716bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008717 const MCObjectFileInfo::Environment Format =
8718 getContext().getObjectFileInfo()->getObjectFileType();
8719 bool IsMachO = Format == MCObjectFileInfo::IsMachO;
Saleem Abdulrasoolbfdfb142014-09-18 04:28:29 +00008720 bool IsCOFF = Format == MCObjectFileInfo::IsCOFF;
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008721
Kevin Enderbyccab3172009-09-15 00:27:25 +00008722 StringRef IDVal = DirectiveID.getIdentifier();
8723 if (IDVal == ".word")
Saleem Abdulrasool38976512014-02-23 06:22:09 +00008724 return parseLiteralValues(4, DirectiveID.getLoc());
8725 else if (IDVal == ".short" || IDVal == ".hword")
8726 return parseLiteralValues(2, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008727 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008728 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00008729 else if (IDVal == ".arm")
8730 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008731 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008732 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008733 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008734 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00008735 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008736 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00008737 else if (IDVal == ".unreq")
8738 return parseDirectiveUnreq(DirectiveID.getLoc());
Logan Chien4ea23b52013-05-10 16:17:24 +00008739 else if (IDVal == ".fnend")
8740 return parseDirectiveFnEnd(DirectiveID.getLoc());
8741 else if (IDVal == ".cantunwind")
8742 return parseDirectiveCantUnwind(DirectiveID.getLoc());
8743 else if (IDVal == ".personality")
8744 return parseDirectivePersonality(DirectiveID.getLoc());
8745 else if (IDVal == ".handlerdata")
8746 return parseDirectiveHandlerData(DirectiveID.getLoc());
8747 else if (IDVal == ".setfp")
8748 return parseDirectiveSetFP(DirectiveID.getLoc());
8749 else if (IDVal == ".pad")
8750 return parseDirectivePad(DirectiveID.getLoc());
8751 else if (IDVal == ".save")
8752 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
8753 else if (IDVal == ".vsave")
8754 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
Saleem Abdulrasool6e6c2392013-12-20 07:21:16 +00008755 else if (IDVal == ".ltorg" || IDVal == ".pool")
David Peixotto80c083a2013-12-19 18:26:07 +00008756 return parseDirectiveLtorg(DirectiveID.getLoc());
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00008757 else if (IDVal == ".even")
8758 return parseDirectiveEven(DirectiveID.getLoc());
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00008759 else if (IDVal == ".personalityindex")
8760 return parseDirectivePersonalityIndex(DirectiveID.getLoc());
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +00008761 else if (IDVal == ".unwind_raw")
8762 return parseDirectiveUnwindRaw(DirectiveID.getLoc());
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00008763 else if (IDVal == ".movsp")
8764 return parseDirectiveMovSP(DirectiveID.getLoc());
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00008765 else if (IDVal == ".arch_extension")
8766 return parseDirectiveArchExtension(DirectiveID.getLoc());
Saleem Abdulrasoolfd6ed1e2014-02-23 17:45:32 +00008767 else if (IDVal == ".align")
8768 return parseDirectiveAlign(DirectiveID.getLoc());
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00008769 else if (IDVal == ".thumb_set")
8770 return parseDirectiveThumbSet(DirectiveID.getLoc());
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008771
Saleem Abdulrasoolbfdfb142014-09-18 04:28:29 +00008772 if (!IsMachO && !IsCOFF) {
Saleem Abdulrasooldd979e62014-04-05 22:09:51 +00008773 if (IDVal == ".arch")
8774 return parseDirectiveArch(DirectiveID.getLoc());
8775 else if (IDVal == ".cpu")
8776 return parseDirectiveCPU(DirectiveID.getLoc());
8777 else if (IDVal == ".eabi_attribute")
8778 return parseDirectiveEabiAttr(DirectiveID.getLoc());
8779 else if (IDVal == ".fpu")
8780 return parseDirectiveFPU(DirectiveID.getLoc());
8781 else if (IDVal == ".fnstart")
8782 return parseDirectiveFnStart(DirectiveID.getLoc());
8783 else if (IDVal == ".inst")
8784 return parseDirectiveInst(DirectiveID.getLoc());
8785 else if (IDVal == ".inst.n")
8786 return parseDirectiveInst(DirectiveID.getLoc(), 'n');
8787 else if (IDVal == ".inst.w")
8788 return parseDirectiveInst(DirectiveID.getLoc(), 'w');
8789 else if (IDVal == ".object_arch")
8790 return parseDirectiveObjectArch(DirectiveID.getLoc());
8791 else if (IDVal == ".tlsdescseq")
8792 return parseDirectiveTLSDescSeq(DirectiveID.getLoc());
8793 }
8794
Kevin Enderbyccab3172009-09-15 00:27:25 +00008795 return true;
8796}
8797
Saleem Abdulrasool38976512014-02-23 06:22:09 +00008798/// parseLiteralValues
8799/// ::= .hword expression [, expression]*
8800/// ::= .short expression [, expression]*
8801/// ::= .word expression [, expression]*
8802bool ARMAsmParser::parseLiteralValues(unsigned Size, SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008803 MCAsmParser &Parser = getParser();
Kevin Enderbyccab3172009-09-15 00:27:25 +00008804 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8805 for (;;) {
8806 const MCExpr *Value;
Saleem Abdulrasoola9036612014-01-26 22:29:50 +00008807 if (getParser().parseExpression(Value)) {
8808 Parser.eatToEndOfStatement();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008809 return false;
Saleem Abdulrasoola9036612014-01-26 22:29:50 +00008810 }
Kevin Enderbyccab3172009-09-15 00:27:25 +00008811
Eric Christopherbf7bc492013-01-09 03:52:05 +00008812 getParser().getStreamer().EmitValue(Value, Size);
Kevin Enderbyccab3172009-09-15 00:27:25 +00008813
8814 if (getLexer().is(AsmToken::EndOfStatement))
8815 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00008816
Kevin Enderbyccab3172009-09-15 00:27:25 +00008817 // FIXME: Improve diagnostic.
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008818 if (getLexer().isNot(AsmToken::Comma)) {
8819 Error(L, "unexpected token in directive");
8820 return false;
8821 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008822 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00008823 }
8824 }
8825
Sean Callanana83fd7d2010-01-19 20:27:46 +00008826 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00008827 return false;
8828}
8829
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008830/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00008831/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008832bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008833 MCAsmParser &Parser = getParser();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008834 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8835 Error(L, "unexpected token in directive");
8836 return false;
8837 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008838 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008839
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008840 if (!hasThumb()) {
8841 Error(L, "target does not support Thumb mode");
8842 return false;
8843 }
Tim Northovera2292d02013-06-10 23:20:58 +00008844
Jim Grosbach7f882392011-12-07 18:04:19 +00008845 if (!isThumb())
8846 SwitchMode();
Saleem Abdulrasool44419fc2014-03-22 19:26:18 +00008847
Jim Grosbach7f882392011-12-07 18:04:19 +00008848 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
8849 return false;
8850}
8851
8852/// parseDirectiveARM
8853/// ::= .arm
8854bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008855 MCAsmParser &Parser = getParser();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008856 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8857 Error(L, "unexpected token in directive");
8858 return false;
8859 }
Jim Grosbach7f882392011-12-07 18:04:19 +00008860 Parser.Lex();
8861
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008862 if (!hasARM()) {
8863 Error(L, "target does not support ARM mode");
8864 return false;
8865 }
Tim Northovera2292d02013-06-10 23:20:58 +00008866
Jim Grosbach7f882392011-12-07 18:04:19 +00008867 if (isThumb())
8868 SwitchMode();
Saleem Abdulrasool44419fc2014-03-22 19:26:18 +00008869
Jim Grosbach7f882392011-12-07 18:04:19 +00008870 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00008871 return false;
8872}
8873
Tim Northover1744d0a2013-10-25 12:49:50 +00008874void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) {
8875 if (NextSymbolIsThumb) {
8876 getParser().getStreamer().EmitThumbFunc(Symbol);
8877 NextSymbolIsThumb = false;
8878 }
8879}
8880
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008881/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00008882/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008883bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008884 MCAsmParser &Parser = getParser();
Saleem Abdulrasool8c61c6c2014-09-18 03:49:55 +00008885 const auto Format = getContext().getObjectFileInfo()->getObjectFileType();
8886 bool IsMachO = Format == MCObjectFileInfo::IsMachO;
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008887
Jim Grosbach1152cc02011-12-21 22:30:16 +00008888 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008889 // ELF doesn't
Saleem Abdulrasool8c61c6c2014-09-18 03:49:55 +00008890 if (IsMachO) {
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008891 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00008892 if (Tok.isNot(AsmToken::EndOfStatement)) {
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008893 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String)) {
8894 Error(L, "unexpected token in .thumb_func directive");
8895 return false;
8896 }
8897
Tim Northover1744d0a2013-10-25 12:49:50 +00008898 MCSymbol *Func =
8899 getParser().getContext().GetOrCreateSymbol(Tok.getIdentifier());
8900 getParser().getStreamer().EmitThumbFunc(Func);
Jim Grosbach1152cc02011-12-21 22:30:16 +00008901 Parser.Lex(); // Consume the identifier token.
Tim Northover1744d0a2013-10-25 12:49:50 +00008902 return false;
Jim Grosbach1152cc02011-12-21 22:30:16 +00008903 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008904 }
8905
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008906 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Saleem Abdulrasool8c61c6c2014-09-18 03:49:55 +00008907 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8908 Parser.eatToEndOfStatement();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008909 return false;
8910 }
Jim Grosbach1152cc02011-12-21 22:30:16 +00008911
Tim Northover1744d0a2013-10-25 12:49:50 +00008912 NextSymbolIsThumb = true;
Kevin Enderby146dcf22009-10-15 20:48:48 +00008913 return false;
8914}
8915
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008916/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00008917/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008918bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008919 MCAsmParser &Parser = getParser();
Sean Callanan936b0d32010-01-19 21:44:56 +00008920 const AsmToken &Tok = Parser.getTok();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008921 if (Tok.isNot(AsmToken::Identifier)) {
8922 Error(L, "unexpected token in .syntax directive");
8923 return false;
8924 }
8925
Benjamin Kramer92d89982010-07-14 22:38:02 +00008926 StringRef Mode = Tok.getString();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008927 if (Mode == "unified" || Mode == "UNIFIED") {
Sean Callanana83fd7d2010-01-19 20:27:46 +00008928 Parser.Lex();
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00008929 } else if (Mode == "divided" || Mode == "DIVIDED") {
8930 Error(L, "'.syntax divided' arm asssembly not supported");
8931 return false;
8932 } else {
8933 Error(L, "unrecognized syntax mode in .syntax directive");
8934 return false;
8935 }
Kevin Enderby146dcf22009-10-15 20:48:48 +00008936
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008937 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8938 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8939 return false;
8940 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008941 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008942
8943 // TODO tell the MC streamer the mode
8944 // getParser().getStreamer().Emit???();
8945 return false;
8946}
8947
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008948/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00008949/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008950bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008951 MCAsmParser &Parser = getParser();
Sean Callanan936b0d32010-01-19 21:44:56 +00008952 const AsmToken &Tok = Parser.getTok();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008953 if (Tok.isNot(AsmToken::Integer)) {
8954 Error(L, "unexpected token in .code directive");
8955 return false;
8956 }
Sean Callanan936b0d32010-01-19 21:44:56 +00008957 int64_t Val = Parser.getTok().getIntVal();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008958 if (Val != 16 && Val != 32) {
8959 Error(L, "invalid operand to .code directive");
8960 return false;
8961 }
8962 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008963
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008964 if (getLexer().isNot(AsmToken::EndOfStatement)) {
8965 Error(Parser.getTok().getLoc(), "unexpected token in directive");
8966 return false;
8967 }
Sean Callanana83fd7d2010-01-19 20:27:46 +00008968 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008969
Evan Cheng284b4672011-07-08 22:36:29 +00008970 if (Val == 16) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008971 if (!hasThumb()) {
8972 Error(L, "target does not support Thumb mode");
8973 return false;
8974 }
Tim Northovera2292d02013-06-10 23:20:58 +00008975
Jim Grosbachf471ac32011-09-06 18:46:23 +00008976 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00008977 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00008978 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00008979 } else {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00008980 if (!hasARM()) {
8981 Error(L, "target does not support ARM mode");
8982 return false;
8983 }
Tim Northovera2292d02013-06-10 23:20:58 +00008984
Jim Grosbachf471ac32011-09-06 18:46:23 +00008985 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00008986 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00008987 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00008988 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00008989
Kevin Enderby146dcf22009-10-15 20:48:48 +00008990 return false;
8991}
8992
Jim Grosbachab5830e2011-12-14 02:16:11 +00008993/// parseDirectiveReq
8994/// ::= name .req registername
8995bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00008996 MCAsmParser &Parser = getParser();
Jim Grosbachab5830e2011-12-14 02:16:11 +00008997 Parser.Lex(); // Eat the '.req' token.
8998 unsigned Reg;
8999 SMLoc SRegLoc, ERegLoc;
9000 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00009001 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009002 Error(SRegLoc, "register name expected");
9003 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00009004 }
9005
9006 // Shouldn't be anything else.
9007 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00009008 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009009 Error(Parser.getTok().getLoc(), "unexpected input in .req directive.");
9010 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00009011 }
9012
9013 Parser.Lex(); // Consume the EndOfStatement
9014
Frederic Rissb61f01f2015-02-04 03:10:03 +00009015 if (RegisterReqs.insert(std::make_pair(Name, Reg)).first->second != Reg) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009016 Error(SRegLoc, "redefinition of '" + Name + "' does not match original.");
9017 return false;
9018 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00009019
9020 return false;
9021}
9022
9023/// parseDirectiveUneq
9024/// ::= .unreq registername
9025bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009026 MCAsmParser &Parser = getParser();
Jim Grosbachab5830e2011-12-14 02:16:11 +00009027 if (Parser.getTok().isNot(AsmToken::Identifier)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00009028 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009029 Error(L, "unexpected input in .unreq directive.");
9030 return false;
Jim Grosbachab5830e2011-12-14 02:16:11 +00009031 }
Duncan P. N. Exon Smith29db0eb2014-03-07 16:16:52 +00009032 RegisterReqs.erase(Parser.getTok().getIdentifier().lower());
Jim Grosbachab5830e2011-12-14 02:16:11 +00009033 Parser.Lex(); // Eat the identifier.
9034 return false;
9035}
9036
Jason W Kim135d2442011-12-20 17:38:12 +00009037/// parseDirectiveArch
9038/// ::= .arch token
9039bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
Logan Chien439e8f92013-12-11 17:16:25 +00009040 StringRef Arch = getParser().parseStringToEndOfStatement().trim();
9041
Renato Golinf5f373f2015-05-08 21:04:27 +00009042 unsigned ID = ARMTargetParser::parseArch(Arch);
Logan Chien439e8f92013-12-11 17:16:25 +00009043
Renato Golin35de35d2015-05-12 10:33:58 +00009044 if (ID == ARM::AK_INVALID) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009045 Error(L, "Unknown arch name");
9046 return false;
9047 }
Logan Chien439e8f92013-12-11 17:16:25 +00009048
9049 getTargetStreamer().emitArch(ID);
9050 return false;
Jason W Kim135d2442011-12-20 17:38:12 +00009051}
9052
9053/// parseDirectiveEabiAttr
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009054/// ::= .eabi_attribute int, int [, "str"]
9055/// ::= .eabi_attribute Tag_name, int [, "str"]
Jason W Kim135d2442011-12-20 17:38:12 +00009056bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009057 MCAsmParser &Parser = getParser();
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009058 int64_t Tag;
9059 SMLoc TagLoc;
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009060 TagLoc = Parser.getTok().getLoc();
9061 if (Parser.getTok().is(AsmToken::Identifier)) {
9062 StringRef Name = Parser.getTok().getIdentifier();
9063 Tag = ARMBuildAttrs::AttrTypeFromString(Name);
9064 if (Tag == -1) {
9065 Error(TagLoc, "attribute name not recognised: " + Name);
9066 Parser.eatToEndOfStatement();
9067 return false;
9068 }
9069 Parser.Lex();
9070 } else {
9071 const MCExpr *AttrExpr;
9072
9073 TagLoc = Parser.getTok().getLoc();
9074 if (Parser.parseExpression(AttrExpr)) {
9075 Parser.eatToEndOfStatement();
9076 return false;
9077 }
9078
9079 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(AttrExpr);
9080 if (!CE) {
9081 Error(TagLoc, "expected numeric constant");
9082 Parser.eatToEndOfStatement();
9083 return false;
9084 }
9085
9086 Tag = CE->getValue();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009087 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00009088
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009089 if (Parser.getTok().isNot(AsmToken::Comma)) {
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009090 Error(Parser.getTok().getLoc(), "comma expected");
9091 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009092 return false;
9093 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00009094 Parser.Lex(); // skip comma
9095
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009096 StringRef StringValue = "";
9097 bool IsStringValue = false;
Logan Chien8cbb80d2013-10-28 17:51:12 +00009098
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009099 int64_t IntegerValue = 0;
9100 bool IsIntegerValue = false;
9101
9102 if (Tag == ARMBuildAttrs::CPU_raw_name || Tag == ARMBuildAttrs::CPU_name)
9103 IsStringValue = true;
9104 else if (Tag == ARMBuildAttrs::compatibility) {
9105 IsStringValue = true;
9106 IsIntegerValue = true;
Saleem Abdulrasool9dedf642014-01-19 08:25:19 +00009107 } else if (Tag < 32 || Tag % 2 == 0)
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009108 IsIntegerValue = true;
9109 else if (Tag % 2 == 1)
9110 IsStringValue = true;
9111 else
9112 llvm_unreachable("invalid tag type");
9113
9114 if (IsIntegerValue) {
9115 const MCExpr *ValueExpr;
9116 SMLoc ValueExprLoc = Parser.getTok().getLoc();
9117 if (Parser.parseExpression(ValueExpr)) {
9118 Parser.eatToEndOfStatement();
9119 return false;
9120 }
9121
9122 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ValueExpr);
9123 if (!CE) {
9124 Error(ValueExprLoc, "expected numeric constant");
9125 Parser.eatToEndOfStatement();
9126 return false;
9127 }
9128
9129 IntegerValue = CE->getValue();
9130 }
9131
9132 if (Tag == ARMBuildAttrs::compatibility) {
9133 if (Parser.getTok().isNot(AsmToken::Comma))
9134 IsStringValue = false;
Charlie Turner6632d1f2015-01-05 13:26:37 +00009135 if (Parser.getTok().isNot(AsmToken::Comma)) {
9136 Error(Parser.getTok().getLoc(), "comma expected");
9137 Parser.eatToEndOfStatement();
9138 return false;
9139 } else {
9140 Parser.Lex();
9141 }
Saleem Abdulrasool87ccd362014-01-07 02:28:42 +00009142 }
9143
9144 if (IsStringValue) {
9145 if (Parser.getTok().isNot(AsmToken::String)) {
9146 Error(Parser.getTok().getLoc(), "bad string constant");
9147 Parser.eatToEndOfStatement();
9148 return false;
9149 }
9150
9151 StringValue = Parser.getTok().getStringContents();
9152 Parser.Lex();
9153 }
9154
9155 if (IsIntegerValue && IsStringValue) {
9156 assert(Tag == ARMBuildAttrs::compatibility);
9157 getTargetStreamer().emitIntTextAttribute(Tag, IntegerValue, StringValue);
9158 } else if (IsIntegerValue)
9159 getTargetStreamer().emitAttribute(Tag, IntegerValue);
9160 else if (IsStringValue)
9161 getTargetStreamer().emitTextAttribute(Tag, StringValue);
Logan Chien8cbb80d2013-10-28 17:51:12 +00009162 return false;
9163}
9164
9165/// parseDirectiveCPU
9166/// ::= .cpu str
9167bool ARMAsmParser::parseDirectiveCPU(SMLoc L) {
9168 StringRef CPU = getParser().parseStringToEndOfStatement().trim();
9169 getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name, CPU);
Roman Divacky7e6b5952014-12-02 20:03:22 +00009170
Roman Divackyfdf05602014-12-03 18:39:44 +00009171 if (!STI.isCPUStringValid(CPU)) {
Roman Divacky7e6b5952014-12-02 20:03:22 +00009172 Error(L, "Unknown CPU name");
9173 return false;
9174 }
9175
Roman Divacky6fd64ff2014-12-04 21:39:24 +00009176 // FIXME: This switches the CPU features globally, therefore it might
9177 // happen that code you would not expect to assemble will. For details
9178 // see: http://llvm.org/bugs/show_bug.cgi?id=20757
Roman Divacky7e6b5952014-12-02 20:03:22 +00009179 STI.InitMCProcessorInfo(CPU, "");
9180 STI.InitCPUSchedModel(CPU);
Bradley Smith9f4cd592015-02-04 16:23:24 +00009181 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Roman Divacky7e6b5952014-12-02 20:03:22 +00009182
Logan Chien8cbb80d2013-10-28 17:51:12 +00009183 return false;
9184}
9185
Nico Weberae050bb2014-08-16 05:37:51 +00009186// FIXME: This is duplicated in getARMFPUFeatures() in
9187// tools/clang/lib/Driver/Tools.cpp
9188static const struct {
Saleem Abdulrasool206d1162015-01-30 17:58:25 +00009189 const unsigned ID;
Michael Kupersteinaba4a342015-05-13 08:27:08 +00009190 const FeatureBitset Enabled;
9191 const FeatureBitset Disabled;
Saleem Abdulrasool206d1162015-01-30 17:58:25 +00009192} FPUs[] = {
Michael Kupersteinaba4a342015-05-13 08:27:08 +00009193 {/* ID */ ARM::FK_VFP,
9194 /* Enabled */ {ARM::FeatureVFP2},
9195 /* Disabled */ {ARM::FeatureNEON}},
9196 {/* ID */ ARM::FK_VFPV2,
9197 /* Enabled */ {ARM::FeatureVFP2},
9198 /* Disabled */ {ARM::FeatureNEON}},
9199 {/* ID */ ARM::FK_VFPV3,
9200 /* Enabled */ {ARM::FeatureVFP2, ARM::FeatureVFP3},
9201 /* Disabled */ {ARM::FeatureNEON, ARM::FeatureD16}},
9202 {/* ID */ ARM::FK_VFPV3_D16,
9203 /* Enabled */ {ARM::FeatureVFP2, ARM::FeatureVFP3, ARM::FeatureD16},
9204 /* Disabled */ {ARM::FeatureNEON}},
9205 {/* ID */ ARM::FK_VFPV4,
9206 /* Enabled */ {ARM::FeatureVFP2, ARM::FeatureVFP3, ARM::FeatureVFP4},
9207 /* Disabled */ {ARM::FeatureNEON, ARM::FeatureD16}},
9208 {/* ID */ ARM::FK_VFPV4_D16,
9209 /* Enabled */ {ARM::FeatureVFP2, ARM::FeatureVFP3, ARM::FeatureVFP4,
9210 ARM::FeatureD16},
9211 /* Disabled */ {ARM::FeatureNEON}},
9212 {/* ID */ ARM::FK_FPV5_D16,
9213 /* Enabled */ {ARM::FeatureVFP2, ARM::FeatureVFP3, ARM::FeatureVFP4,
9214 ARM::FeatureFPARMv8, ARM::FeatureD16},
9215 /* Disabled */ {ARM::FeatureNEON, ARM::FeatureCrypto}},
9216 {/* ID */ ARM::FK_FP_ARMV8,
9217 /* Enabled */ {ARM::FeatureVFP2, ARM::FeatureVFP3, ARM::FeatureVFP4,
9218 ARM::FeatureFPARMv8},
9219 /* Disabled */ {ARM::FeatureNEON, ARM::FeatureCrypto, ARM::FeatureD16}},
9220 {/* ID */ ARM::FK_NEON,
9221 /* Enabled */ {ARM::FeatureVFP2, ARM::FeatureVFP3, ARM::FeatureNEON},
9222 /* Disabled */ {ARM::FeatureD16}},
9223 {/* ID */ ARM::FK_NEON_VFPV4,
9224 /* Enabled */ {ARM::FeatureVFP2, ARM::FeatureVFP3, ARM::FeatureVFP4,
9225 ARM::FeatureNEON},
9226 /* Disabled */ {ARM::FeatureD16}},
9227 {/* ID */ ARM::FK_NEON_FP_ARMV8,
9228 /* Enabled */ {ARM::FeatureVFP2, ARM::FeatureVFP3, ARM::FeatureVFP4,
9229 ARM::FeatureFPARMv8, ARM::FeatureNEON},
9230 /* Disabled */ {ARM::FeatureCrypto, ARM::FeatureD16}},
Renato Golin35de35d2015-05-12 10:33:58 +00009231 {/* ID */ ARM::FK_CRYPTO_NEON_FP_ARMV8,
Michael Kupersteinaba4a342015-05-13 08:27:08 +00009232 /* Enabled */ {ARM::FeatureVFP2, ARM::FeatureVFP3, ARM::FeatureVFP4,
9233 ARM::FeatureFPARMv8, ARM::FeatureNEON,
9234 ARM::FeatureCrypto},
9235 /* Disabled */ {ARM::FeatureD16}},
9236 {ARM::FK_SOFTVFP, {}, {}},
Nico Weberae050bb2014-08-16 05:37:51 +00009237};
9238
Logan Chien8cbb80d2013-10-28 17:51:12 +00009239/// parseDirectiveFPU
9240/// ::= .fpu str
9241bool ARMAsmParser::parseDirectiveFPU(SMLoc L) {
Saleem Abdulrasool07b7c032015-01-30 18:42:10 +00009242 SMLoc FPUNameLoc = getTok().getLoc();
Logan Chien8cbb80d2013-10-28 17:51:12 +00009243 StringRef FPU = getParser().parseStringToEndOfStatement().trim();
9244
Renato Golinf5f373f2015-05-08 21:04:27 +00009245 unsigned ID = ARMTargetParser::parseFPU(FPU);
Logan Chien8cbb80d2013-10-28 17:51:12 +00009246
Renato Golin35de35d2015-05-12 10:33:58 +00009247 if (ID == ARM::FK_INVALID) {
Saleem Abdulrasool07b7c032015-01-30 18:42:10 +00009248 Error(FPUNameLoc, "Unknown FPU name");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009249 return false;
9250 }
Logan Chien8cbb80d2013-10-28 17:51:12 +00009251
Saleem Abdulrasool206d1162015-01-30 17:58:25 +00009252 for (const auto &Entry : FPUs) {
9253 if (Entry.ID != ID)
Nico Weberae050bb2014-08-16 05:37:51 +00009254 continue;
9255
9256 // Need to toggle features that should be on but are off and that
9257 // should off but are on.
Michael Kupersteinaba4a342015-05-13 08:27:08 +00009258 FeatureBitset Toggle = (Entry.Enabled & ~STI.getFeatureBits()) |
9259 (Entry.Disabled & STI.getFeatureBits());
Nico Weberae050bb2014-08-16 05:37:51 +00009260 setAvailableFeatures(ComputeAvailableFeatures(STI.ToggleFeature(Toggle)));
9261 break;
9262 }
9263
Logan Chien8cbb80d2013-10-28 17:51:12 +00009264 getTargetStreamer().emitFPU(ID);
9265 return false;
Jason W Kim135d2442011-12-20 17:38:12 +00009266}
9267
Logan Chien4ea23b52013-05-10 16:17:24 +00009268/// parseDirectiveFnStart
9269/// ::= .fnstart
9270bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009271 if (UC.hasFnStart()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009272 Error(L, ".fnstart starts before the end of previous one");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009273 UC.emitFnStartLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009274 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009275 }
9276
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009277 // Reset the unwind directives parser state
9278 UC.reset();
9279
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009280 getTargetStreamer().emitFnStart();
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009281
9282 UC.recordFnStart(L);
Logan Chien4ea23b52013-05-10 16:17:24 +00009283 return false;
9284}
9285
9286/// parseDirectiveFnEnd
9287/// ::= .fnend
9288bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
9289 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009290 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009291 Error(L, ".fnstart must precede .fnend directive");
9292 return false;
9293 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009294
9295 // Reset the unwind directives parser state
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009296 getTargetStreamer().emitFnEnd();
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009297
9298 UC.reset();
Logan Chien4ea23b52013-05-10 16:17:24 +00009299 return false;
9300}
9301
9302/// parseDirectiveCantUnwind
9303/// ::= .cantunwind
9304bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009305 UC.recordCantUnwind(L);
9306
Logan Chien4ea23b52013-05-10 16:17:24 +00009307 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009308 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009309 Error(L, ".fnstart must precede .cantunwind directive");
9310 return false;
9311 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009312 if (UC.hasHandlerData()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009313 Error(L, ".cantunwind can't be used with .handlerdata directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009314 UC.emitHandlerDataLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009315 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009316 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009317 if (UC.hasPersonality()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009318 Error(L, ".cantunwind can't be used with .personality directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009319 UC.emitPersonalityLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009320 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009321 }
9322
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009323 getTargetStreamer().emitCantUnwind();
Logan Chien4ea23b52013-05-10 16:17:24 +00009324 return false;
9325}
9326
9327/// parseDirectivePersonality
9328/// ::= .personality name
9329bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009330 MCAsmParser &Parser = getParser();
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009331 bool HasExistingPersonality = UC.hasPersonality();
9332
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009333 UC.recordPersonality(L);
9334
Logan Chien4ea23b52013-05-10 16:17:24 +00009335 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009336 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009337 Error(L, ".fnstart must precede .personality directive");
9338 return false;
9339 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009340 if (UC.cantUnwind()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009341 Error(L, ".personality can't be used with .cantunwind directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009342 UC.emitCantUnwindLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009343 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009344 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009345 if (UC.hasHandlerData()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009346 Error(L, ".personality must precede .handlerdata directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009347 UC.emitHandlerDataLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009348 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009349 }
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009350 if (HasExistingPersonality) {
9351 Parser.eatToEndOfStatement();
9352 Error(L, "multiple personality directives");
9353 UC.emitPersonalityLocNotes();
9354 return false;
9355 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009356
9357 // Parse the name of the personality routine
9358 if (Parser.getTok().isNot(AsmToken::Identifier)) {
9359 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009360 Error(L, "unexpected input in .personality directive.");
9361 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009362 }
9363 StringRef Name(Parser.getTok().getIdentifier());
9364 Parser.Lex();
9365
9366 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009367 getTargetStreamer().emitPersonality(PR);
Logan Chien4ea23b52013-05-10 16:17:24 +00009368 return false;
9369}
9370
9371/// parseDirectiveHandlerData
9372/// ::= .handlerdata
9373bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009374 UC.recordHandlerData(L);
9375
Logan Chien4ea23b52013-05-10 16:17:24 +00009376 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009377 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009378 Error(L, ".fnstart must precede .personality directive");
9379 return false;
9380 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009381 if (UC.cantUnwind()) {
Logan Chien4ea23b52013-05-10 16:17:24 +00009382 Error(L, ".handlerdata can't be used with .cantunwind directive");
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009383 UC.emitCantUnwindLocNotes();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009384 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009385 }
9386
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009387 getTargetStreamer().emitHandlerData();
Logan Chien4ea23b52013-05-10 16:17:24 +00009388 return false;
9389}
9390
9391/// parseDirectiveSetFP
9392/// ::= .setfp fpreg, spreg [, offset]
9393bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009394 MCAsmParser &Parser = getParser();
Logan Chien4ea23b52013-05-10 16:17:24 +00009395 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009396 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009397 Error(L, ".fnstart must precede .setfp directive");
9398 return false;
9399 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009400 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009401 Error(L, ".setfp must precede .handlerdata directive");
9402 return false;
9403 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009404
9405 // Parse fpreg
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009406 SMLoc FPRegLoc = Parser.getTok().getLoc();
9407 int FPReg = tryParseRegister();
9408 if (FPReg == -1) {
9409 Error(FPRegLoc, "frame pointer register expected");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009410 return false;
9411 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009412
9413 // Consume comma
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00009414 if (Parser.getTok().isNot(AsmToken::Comma)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009415 Error(Parser.getTok().getLoc(), "comma expected");
9416 return false;
9417 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009418 Parser.Lex(); // skip comma
9419
9420 // Parse spreg
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009421 SMLoc SPRegLoc = Parser.getTok().getLoc();
9422 int SPReg = tryParseRegister();
9423 if (SPReg == -1) {
9424 Error(SPRegLoc, "stack pointer register expected");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009425 return false;
9426 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009427
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009428 if (SPReg != ARM::SP && SPReg != UC.getFPReg()) {
9429 Error(SPRegLoc, "register should be either $sp or the latest fp register");
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009430 return false;
9431 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009432
9433 // Update the frame pointer register
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009434 UC.saveFPReg(FPReg);
Logan Chien4ea23b52013-05-10 16:17:24 +00009435
9436 // Parse offset
9437 int64_t Offset = 0;
9438 if (Parser.getTok().is(AsmToken::Comma)) {
9439 Parser.Lex(); // skip comma
9440
9441 if (Parser.getTok().isNot(AsmToken::Hash) &&
9442 Parser.getTok().isNot(AsmToken::Dollar)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009443 Error(Parser.getTok().getLoc(), "'#' expected");
9444 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009445 }
9446 Parser.Lex(); // skip hash token.
9447
9448 const MCExpr *OffsetExpr;
9449 SMLoc ExLoc = Parser.getTok().getLoc();
9450 SMLoc EndLoc;
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009451 if (getParser().parseExpression(OffsetExpr, EndLoc)) {
9452 Error(ExLoc, "malformed setfp offset");
9453 return false;
9454 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009455 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009456 if (!CE) {
9457 Error(ExLoc, "setfp offset must be an immediate");
9458 return false;
9459 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009460
9461 Offset = CE->getValue();
9462 }
9463
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009464 getTargetStreamer().emitSetFP(static_cast<unsigned>(FPReg),
9465 static_cast<unsigned>(SPReg), Offset);
Logan Chien4ea23b52013-05-10 16:17:24 +00009466 return false;
9467}
9468
9469/// parseDirective
9470/// ::= .pad offset
9471bool ARMAsmParser::parseDirectivePad(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009472 MCAsmParser &Parser = getParser();
Logan Chien4ea23b52013-05-10 16:17:24 +00009473 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009474 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009475 Error(L, ".fnstart must precede .pad directive");
9476 return false;
9477 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009478 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009479 Error(L, ".pad must precede .handlerdata directive");
9480 return false;
9481 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009482
9483 // Parse the offset
9484 if (Parser.getTok().isNot(AsmToken::Hash) &&
9485 Parser.getTok().isNot(AsmToken::Dollar)) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009486 Error(Parser.getTok().getLoc(), "'#' expected");
9487 return false;
Logan Chien4ea23b52013-05-10 16:17:24 +00009488 }
9489 Parser.Lex(); // skip hash token.
9490
9491 const MCExpr *OffsetExpr;
9492 SMLoc ExLoc = Parser.getTok().getLoc();
9493 SMLoc EndLoc;
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009494 if (getParser().parseExpression(OffsetExpr, EndLoc)) {
9495 Error(ExLoc, "malformed pad offset");
9496 return false;
9497 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009498 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009499 if (!CE) {
9500 Error(ExLoc, "pad offset must be an immediate");
9501 return false;
9502 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009503
Rafael Espindolaa17151a2013-10-08 13:08:17 +00009504 getTargetStreamer().emitPad(CE->getValue());
Logan Chien4ea23b52013-05-10 16:17:24 +00009505 return false;
9506}
9507
9508/// parseDirectiveRegSave
9509/// ::= .save { registers }
9510/// ::= .vsave { registers }
9511bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
9512 // Check the ordering of unwind directives
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009513 if (!UC.hasFnStart()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009514 Error(L, ".fnstart must precede .save or .vsave directives");
9515 return false;
9516 }
Saleem Abdulrasoolc493d142014-01-07 02:28:55 +00009517 if (UC.hasHandlerData()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009518 Error(L, ".save or .vsave must precede .handlerdata directive");
9519 return false;
9520 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009521
Benjamin Kramer23632bd2013-08-03 22:16:24 +00009522 // RAII object to make sure parsed operands are deleted.
David Blaikie960ea3f2014-06-08 16:18:35 +00009523 SmallVector<std::unique_ptr<MCParsedAsmOperand>, 1> Operands;
Benjamin Kramer23632bd2013-08-03 22:16:24 +00009524
Logan Chien4ea23b52013-05-10 16:17:24 +00009525 // Parse the register list
David Blaikie960ea3f2014-06-08 16:18:35 +00009526 if (parseRegisterList(Operands))
Saleem Abdulrasoola6505ca2014-01-13 01:15:39 +00009527 return false;
David Blaikie960ea3f2014-06-08 16:18:35 +00009528 ARMOperand &Op = (ARMOperand &)*Operands[0];
9529 if (!IsVector && !Op.isRegList()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009530 Error(L, ".save expects GPR registers");
9531 return false;
9532 }
David Blaikie960ea3f2014-06-08 16:18:35 +00009533 if (IsVector && !Op.isDPRRegList()) {
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009534 Error(L, ".vsave expects DPR registers");
9535 return false;
9536 }
Logan Chien4ea23b52013-05-10 16:17:24 +00009537
David Blaikie960ea3f2014-06-08 16:18:35 +00009538 getTargetStreamer().emitRegSave(Op.getRegList(), IsVector);
Logan Chien4ea23b52013-05-10 16:17:24 +00009539 return false;
9540}
9541
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009542/// parseDirectiveInst
9543/// ::= .inst opcode [, ...]
9544/// ::= .inst.n opcode [, ...]
9545/// ::= .inst.w opcode [, ...]
9546bool ARMAsmParser::parseDirectiveInst(SMLoc Loc, char Suffix) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009547 MCAsmParser &Parser = getParser();
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009548 int Width;
9549
9550 if (isThumb()) {
9551 switch (Suffix) {
9552 case 'n':
9553 Width = 2;
9554 break;
9555 case 'w':
9556 Width = 4;
9557 break;
9558 default:
9559 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009560 Error(Loc, "cannot determine Thumb instruction size, "
9561 "use inst.n/inst.w instead");
9562 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009563 }
9564 } else {
9565 if (Suffix) {
9566 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009567 Error(Loc, "width suffixes are invalid in ARM mode");
9568 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009569 }
9570 Width = 4;
9571 }
9572
9573 if (getLexer().is(AsmToken::EndOfStatement)) {
9574 Parser.eatToEndOfStatement();
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009575 Error(Loc, "expected expression following directive");
9576 return false;
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009577 }
9578
9579 for (;;) {
9580 const MCExpr *Expr;
9581
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009582 if (getParser().parseExpression(Expr)) {
9583 Error(Loc, "expected expression");
9584 return false;
9585 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009586
9587 const MCConstantExpr *Value = dyn_cast_or_null<MCConstantExpr>(Expr);
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009588 if (!Value) {
9589 Error(Loc, "expected constant expression");
9590 return false;
9591 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009592
9593 switch (Width) {
9594 case 2:
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009595 if (Value->getValue() > 0xffff) {
9596 Error(Loc, "inst.n operand is too big, use inst.w instead");
9597 return false;
9598 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009599 break;
9600 case 4:
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009601 if (Value->getValue() > 0xffffffff) {
9602 Error(Loc,
9603 StringRef(Suffix ? "inst.w" : "inst") + " operand is too big");
9604 return false;
9605 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009606 break;
9607 default:
9608 llvm_unreachable("only supported widths are 2 and 4");
9609 }
9610
9611 getTargetStreamer().emitInst(Value->getValue(), Suffix);
9612
9613 if (getLexer().is(AsmToken::EndOfStatement))
9614 break;
9615
Saleem Abdulrasool0c4b1022013-12-28 22:47:53 +00009616 if (getLexer().isNot(AsmToken::Comma)) {
9617 Error(Loc, "unexpected token in directive");
9618 return false;
9619 }
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00009620
9621 Parser.Lex();
9622 }
9623
9624 Parser.Lex();
9625 return false;
9626}
9627
David Peixotto80c083a2013-12-19 18:26:07 +00009628/// parseDirectiveLtorg
Saleem Abdulrasool6e6c2392013-12-20 07:21:16 +00009629/// ::= .ltorg | .pool
David Peixotto80c083a2013-12-19 18:26:07 +00009630bool ARMAsmParser::parseDirectiveLtorg(SMLoc L) {
David Peixottob9b73622014-02-04 17:22:40 +00009631 getTargetStreamer().emitCurrentConstantPool();
David Peixotto80c083a2013-12-19 18:26:07 +00009632 return false;
9633}
9634
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009635bool ARMAsmParser::parseDirectiveEven(SMLoc L) {
9636 const MCSection *Section = getStreamer().getCurrentSection().first;
9637
9638 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9639 TokError("unexpected token in directive");
9640 return false;
9641 }
9642
9643 if (!Section) {
Rafael Espindola7b61ddf2014-10-15 16:12:52 +00009644 getStreamer().InitSections(false);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009645 Section = getStreamer().getCurrentSection().first;
9646 }
9647
Saleem Abdulrasool42b233a2014-03-18 05:26:55 +00009648 assert(Section && "must have section to emit alignment");
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009649 if (Section->UseCodeAlign())
Rafael Espindola7b514962014-02-04 18:34:04 +00009650 getStreamer().EmitCodeAlignment(2);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009651 else
Rafael Espindola7b514962014-02-04 18:34:04 +00009652 getStreamer().EmitValueToAlignment(2);
Saleem Abdulrasoola5549682013-12-26 01:52:28 +00009653
9654 return false;
9655}
9656
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009657/// parseDirectivePersonalityIndex
9658/// ::= .personalityindex index
9659bool ARMAsmParser::parseDirectivePersonalityIndex(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009660 MCAsmParser &Parser = getParser();
Saleem Abdulrasool662f5c12014-01-21 02:33:02 +00009661 bool HasExistingPersonality = UC.hasPersonality();
9662
9663 UC.recordPersonalityIndex(L);
9664
9665 if (!UC.hasFnStart()) {
9666 Parser.eatToEndOfStatement();
9667 Error(L, ".fnstart must precede .personalityindex directive");
9668 return false;
9669 }
9670 if (UC.cantUnwind()) {
9671 Parser.eatToEndOfStatement();
9672 Error(L, ".personalityindex cannot be used with .cantunwind");
9673 UC.emitCantUnwindLocNotes();
9674 return false;
9675 }
9676 if (UC.hasHandlerData()) {
9677 Parser.eatToEndOfStatement();
9678 Error(L, ".personalityindex must precede .handlerdata directive");
9679 UC.emitHandlerDataLocNotes();
9680 return false;
9681 }
9682 if (HasExistingPersonality) {
9683 Parser.eatToEndOfStatement();
9684 Error(L, "multiple personality directives");
9685 UC.emitPersonalityLocNotes();
9686 return false;
9687 }
9688
9689 const MCExpr *IndexExpression;
9690 SMLoc IndexLoc = Parser.getTok().getLoc();
9691 if (Parser.parseExpression(IndexExpression)) {
9692 Parser.eatToEndOfStatement();
9693 return false;
9694 }
9695
9696 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(IndexExpression);
9697 if (!CE) {
9698 Parser.eatToEndOfStatement();
9699 Error(IndexLoc, "index must be a constant number");
9700 return false;
9701 }
9702 if (CE->getValue() < 0 ||
9703 CE->getValue() >= ARM::EHABI::NUM_PERSONALITY_INDEX) {
9704 Parser.eatToEndOfStatement();
9705 Error(IndexLoc, "personality routine index should be in range [0-3]");
9706 return false;
9707 }
9708
9709 getTargetStreamer().emitPersonalityIndex(CE->getValue());
9710 return false;
9711}
9712
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +00009713/// parseDirectiveUnwindRaw
9714/// ::= .unwind_raw offset, opcode [, opcode...]
9715bool ARMAsmParser::parseDirectiveUnwindRaw(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009716 MCAsmParser &Parser = getParser();
Saleem Abdulrasoold9f08602014-01-21 02:33:10 +00009717 if (!UC.hasFnStart()) {
9718 Parser.eatToEndOfStatement();
9719 Error(L, ".fnstart must precede .unwind_raw directives");
9720 return false;
9721 }
9722
9723 int64_t StackOffset;
9724
9725 const MCExpr *OffsetExpr;
9726 SMLoc OffsetLoc = getLexer().getLoc();
9727 if (getLexer().is(AsmToken::EndOfStatement) ||
9728 getParser().parseExpression(OffsetExpr)) {
9729 Error(OffsetLoc, "expected expression");
9730 Parser.eatToEndOfStatement();
9731 return false;
9732 }
9733
9734 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
9735 if (!CE) {
9736 Error(OffsetLoc, "offset must be a constant");
9737 Parser.eatToEndOfStatement();
9738 return false;
9739 }
9740
9741 StackOffset = CE->getValue();
9742
9743 if (getLexer().isNot(AsmToken::Comma)) {
9744 Error(getLexer().getLoc(), "expected comma");
9745 Parser.eatToEndOfStatement();
9746 return false;
9747 }
9748 Parser.Lex();
9749
9750 SmallVector<uint8_t, 16> Opcodes;
9751 for (;;) {
9752 const MCExpr *OE;
9753
9754 SMLoc OpcodeLoc = getLexer().getLoc();
9755 if (getLexer().is(AsmToken::EndOfStatement) || Parser.parseExpression(OE)) {
9756 Error(OpcodeLoc, "expected opcode expression");
9757 Parser.eatToEndOfStatement();
9758 return false;
9759 }
9760
9761 const MCConstantExpr *OC = dyn_cast<MCConstantExpr>(OE);
9762 if (!OC) {
9763 Error(OpcodeLoc, "opcode value must be a constant");
9764 Parser.eatToEndOfStatement();
9765 return false;
9766 }
9767
9768 const int64_t Opcode = OC->getValue();
9769 if (Opcode & ~0xff) {
9770 Error(OpcodeLoc, "invalid opcode");
9771 Parser.eatToEndOfStatement();
9772 return false;
9773 }
9774
9775 Opcodes.push_back(uint8_t(Opcode));
9776
9777 if (getLexer().is(AsmToken::EndOfStatement))
9778 break;
9779
9780 if (getLexer().isNot(AsmToken::Comma)) {
9781 Error(getLexer().getLoc(), "unexpected token in directive");
9782 Parser.eatToEndOfStatement();
9783 return false;
9784 }
9785
9786 Parser.Lex();
9787 }
9788
9789 getTargetStreamer().emitUnwindRaw(StackOffset, Opcodes);
9790
9791 Parser.Lex();
9792 return false;
9793}
9794
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +00009795/// parseDirectiveTLSDescSeq
9796/// ::= .tlsdescseq tls-variable
9797bool ARMAsmParser::parseDirectiveTLSDescSeq(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009798 MCAsmParser &Parser = getParser();
9799
Saleem Abdulrasool56e06e82014-01-30 04:02:47 +00009800 if (getLexer().isNot(AsmToken::Identifier)) {
9801 TokError("expected variable after '.tlsdescseq' directive");
9802 Parser.eatToEndOfStatement();
9803 return false;
9804 }
9805
9806 const MCSymbolRefExpr *SRE =
9807 MCSymbolRefExpr::Create(Parser.getTok().getIdentifier(),
9808 MCSymbolRefExpr::VK_ARM_TLSDESCSEQ, getContext());
9809 Lex();
9810
9811 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9812 Error(Parser.getTok().getLoc(), "unexpected token");
9813 Parser.eatToEndOfStatement();
9814 return false;
9815 }
9816
9817 getTargetStreamer().AnnotateTLSDescriptorSequence(SRE);
9818 return false;
9819}
9820
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00009821/// parseDirectiveMovSP
9822/// ::= .movsp reg [, #offset]
9823bool ARMAsmParser::parseDirectiveMovSP(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009824 MCAsmParser &Parser = getParser();
Saleem Abdulrasool5d962d32014-01-30 04:46:24 +00009825 if (!UC.hasFnStart()) {
9826 Parser.eatToEndOfStatement();
9827 Error(L, ".fnstart must precede .movsp directives");
9828 return false;
9829 }
9830 if (UC.getFPReg() != ARM::SP) {
9831 Parser.eatToEndOfStatement();
9832 Error(L, "unexpected .movsp directive");
9833 return false;
9834 }
9835
9836 SMLoc SPRegLoc = Parser.getTok().getLoc();
9837 int SPReg = tryParseRegister();
9838 if (SPReg == -1) {
9839 Parser.eatToEndOfStatement();
9840 Error(SPRegLoc, "register expected");
9841 return false;
9842 }
9843
9844 if (SPReg == ARM::SP || SPReg == ARM::PC) {
9845 Parser.eatToEndOfStatement();
9846 Error(SPRegLoc, "sp and pc are not permitted in .movsp directive");
9847 return false;
9848 }
9849
9850 int64_t Offset = 0;
9851 if (Parser.getTok().is(AsmToken::Comma)) {
9852 Parser.Lex();
9853
9854 if (Parser.getTok().isNot(AsmToken::Hash)) {
9855 Error(Parser.getTok().getLoc(), "expected #constant");
9856 Parser.eatToEndOfStatement();
9857 return false;
9858 }
9859 Parser.Lex();
9860
9861 const MCExpr *OffsetExpr;
9862 SMLoc OffsetLoc = Parser.getTok().getLoc();
9863 if (Parser.parseExpression(OffsetExpr)) {
9864 Parser.eatToEndOfStatement();
9865 Error(OffsetLoc, "malformed offset expression");
9866 return false;
9867 }
9868
9869 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
9870 if (!CE) {
9871 Parser.eatToEndOfStatement();
9872 Error(OffsetLoc, "offset must be an immediate constant");
9873 return false;
9874 }
9875
9876 Offset = CE->getValue();
9877 }
9878
9879 getTargetStreamer().emitMovSP(SPReg, Offset);
9880 UC.saveFPReg(SPReg);
9881
9882 return false;
9883}
9884
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +00009885/// parseDirectiveObjectArch
9886/// ::= .object_arch name
9887bool ARMAsmParser::parseDirectiveObjectArch(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009888 MCAsmParser &Parser = getParser();
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +00009889 if (getLexer().isNot(AsmToken::Identifier)) {
9890 Error(getLexer().getLoc(), "unexpected token");
9891 Parser.eatToEndOfStatement();
9892 return false;
9893 }
9894
9895 StringRef Arch = Parser.getTok().getString();
9896 SMLoc ArchLoc = Parser.getTok().getLoc();
9897 getLexer().Lex();
9898
Renato Golinf5f373f2015-05-08 21:04:27 +00009899 unsigned ID = ARMTargetParser::parseArch(Arch);
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +00009900
Renato Golin35de35d2015-05-12 10:33:58 +00009901 if (ID == ARM::AK_INVALID) {
Saleem Abdulrasool4c4789b2014-01-30 04:46:41 +00009902 Error(ArchLoc, "unknown architecture '" + Arch + "'");
9903 Parser.eatToEndOfStatement();
9904 return false;
9905 }
9906
9907 getTargetStreamer().emitObjectArch(ID);
9908
9909 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9910 Error(getLexer().getLoc(), "unexpected token");
9911 Parser.eatToEndOfStatement();
9912 }
9913
9914 return false;
9915}
9916
Saleem Abdulrasoolfd6ed1e2014-02-23 17:45:32 +00009917/// parseDirectiveAlign
9918/// ::= .align
9919bool ARMAsmParser::parseDirectiveAlign(SMLoc L) {
9920 // NOTE: if this is not the end of the statement, fall back to the target
9921 // agnostic handling for this directive which will correctly handle this.
9922 if (getLexer().isNot(AsmToken::EndOfStatement))
9923 return true;
9924
9925 // '.align' is target specifically handled to mean 2**2 byte alignment.
9926 if (getStreamer().getCurrentSection().first->UseCodeAlign())
9927 getStreamer().EmitCodeAlignment(4, 0);
9928 else
9929 getStreamer().EmitValueToAlignment(4, 0, 1, 0);
9930
9931 return false;
9932}
9933
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00009934/// parseDirectiveThumbSet
9935/// ::= .thumb_set name, value
9936bool ARMAsmParser::parseDirectiveThumbSet(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +00009937 MCAsmParser &Parser = getParser();
9938
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00009939 StringRef Name;
9940 if (Parser.parseIdentifier(Name)) {
9941 TokError("expected identifier after '.thumb_set'");
9942 Parser.eatToEndOfStatement();
9943 return false;
9944 }
9945
9946 if (getLexer().isNot(AsmToken::Comma)) {
9947 TokError("expected comma after name '" + Name + "'");
9948 Parser.eatToEndOfStatement();
9949 return false;
9950 }
9951 Lex();
9952
9953 const MCExpr *Value;
9954 if (Parser.parseExpression(Value)) {
9955 TokError("missing expression");
9956 Parser.eatToEndOfStatement();
9957 return false;
9958 }
9959
9960 if (getLexer().isNot(AsmToken::EndOfStatement)) {
9961 TokError("unexpected token");
9962 Parser.eatToEndOfStatement();
9963 return false;
9964 }
9965 Lex();
9966
9967 MCSymbol *Alias = getContext().GetOrCreateSymbol(Name);
Rafael Espindola466d6632014-04-27 20:23:58 +00009968 getTargetStreamer().emitThumbSet(Alias, Value);
Saleem Abdulrasool39f773f2014-03-20 06:05:33 +00009969 return false;
9970}
9971
Kevin Enderby8be42bd2009-10-30 22:55:57 +00009972/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00009973extern "C" void LLVMInitializeARMAsmParser() {
Christian Pirkerdc9ff752014-04-01 15:19:30 +00009974 RegisterMCAsmParser<ARMAsmParser> X(TheARMLETarget);
9975 RegisterMCAsmParser<ARMAsmParser> Y(TheARMBETarget);
9976 RegisterMCAsmParser<ARMAsmParser> A(TheThumbLETarget);
9977 RegisterMCAsmParser<ARMAsmParser> B(TheThumbBETarget);
Kevin Enderbyccab3172009-09-15 00:27:25 +00009978}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00009979
Chris Lattner3e4582a2010-09-06 19:11:01 +00009980#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00009981#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00009982#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00009983#include "ARMGenAsmMatcher.inc"
Jim Grosbach231e7aa2013-02-06 06:00:11 +00009984
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +00009985static const struct {
9986 const char *Name;
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009987 const unsigned ArchCheck;
Michael Kupersteinaba4a342015-05-13 08:27:08 +00009988 const FeatureBitset Features;
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009989} Extensions[] = {
Michael Kupersteinaba4a342015-05-13 08:27:08 +00009990 { "crc", Feature_HasV8, {ARM::FeatureCRC} },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009991 { "crypto", Feature_HasV8,
Michael Kupersteinaba4a342015-05-13 08:27:08 +00009992 {ARM::FeatureCrypto, ARM::FeatureNEON, ARM::FeatureFPARMv8} },
9993 { "fp", Feature_HasV8, {ARM::FeatureFPARMv8} },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009994 { "idiv", Feature_HasV7 | Feature_IsNotMClass,
Michael Kupersteinaba4a342015-05-13 08:27:08 +00009995 {ARM::FeatureHWDiv, ARM::FeatureHWDivARM} },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009996 // FIXME: iWMMXT not supported
Michael Kupersteinaba4a342015-05-13 08:27:08 +00009997 { "iwmmxt", Feature_None, {} },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +00009998 // FIXME: iWMMXT2 not supported
Michael Kupersteinaba4a342015-05-13 08:27:08 +00009999 { "iwmmxt2", Feature_None, {} },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010000 // FIXME: Maverick not supported
Michael Kupersteinaba4a342015-05-13 08:27:08 +000010001 { "maverick", Feature_None, {} },
10002 { "mp", Feature_HasV7 | Feature_IsNotMClass, {ARM::FeatureMP} },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010003 // FIXME: ARMv6-m OS Extensions feature not checked
Michael Kupersteinaba4a342015-05-13 08:27:08 +000010004 { "os", Feature_None, {} },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010005 // FIXME: Also available in ARMv6-K
Michael Kupersteinaba4a342015-05-13 08:27:08 +000010006 { "sec", Feature_HasV7, {ARM::FeatureTrustZone} },
10007 { "simd", Feature_HasV8, {ARM::FeatureNEON, ARM::FeatureFPARMv8} },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010008 // FIXME: Only available in A-class, isel not predicated
Michael Kupersteinaba4a342015-05-13 08:27:08 +000010009 { "virt", Feature_HasV7, {ARM::FeatureVirtualization} },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010010 // FIXME: xscale not supported
Michael Kupersteinaba4a342015-05-13 08:27:08 +000010011 { "xscale", Feature_None, {} },
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010012};
10013
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010014/// parseDirectiveArchExtension
10015/// ::= .arch_extension [no]feature
10016bool ARMAsmParser::parseDirectiveArchExtension(SMLoc L) {
Rafael Espindola961d4692014-11-11 05:18:41 +000010017 MCAsmParser &Parser = getParser();
10018
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010019 if (getLexer().isNot(AsmToken::Identifier)) {
10020 Error(getLexer().getLoc(), "unexpected token");
10021 Parser.eatToEndOfStatement();
10022 return false;
10023 }
10024
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +000010025 StringRef Name = Parser.getTok().getString();
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010026 SMLoc ExtLoc = Parser.getTok().getLoc();
10027 getLexer().Lex();
10028
10029 bool EnableFeature = true;
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +000010030 if (Name.startswith_lower("no")) {
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010031 EnableFeature = false;
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +000010032 Name = Name.substr(2);
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010033 }
10034
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +000010035 for (const auto &Extension : Extensions) {
10036 if (Extension.Name != Name)
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010037 continue;
10038
Michael Kupersteinaba4a342015-05-13 08:27:08 +000010039 if (Extension.Features.none())
Saleem Abdulrasool8988c2a2014-07-27 19:07:09 +000010040 report_fatal_error("unsupported architectural extension: " + Name);
10041
10042 if ((getAvailableFeatures() & Extension.ArchCheck) != Extension.ArchCheck) {
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +000010043 Error(ExtLoc, "architectural extension '" + Name + "' is not "
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010044 "allowed for the current base architecture");
10045 return false;
10046 }
10047
Michael Kupersteinaba4a342015-05-13 08:27:08 +000010048 FeatureBitset ToggleFeatures = EnableFeature
10049 ? (~STI.getFeatureBits() & Extension.Features)
10050 : ( STI.getFeatureBits() & Extension.Features);
10051
Tim Northover26bb14e2014-08-18 11:49:42 +000010052 uint64_t Features =
Saleem Abdulrasool78c44722014-08-17 19:20:38 +000010053 ComputeAvailableFeatures(STI.ToggleFeature(ToggleFeatures));
10054 setAvailableFeatures(Features);
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010055 return false;
10056 }
10057
Saleem Abdulrasool45cf67b2014-07-27 19:07:05 +000010058 Error(ExtLoc, "unknown architectural extension: " + Name);
Saleem Abdulrasool49480bf2014-02-16 00:16:41 +000010059 Parser.eatToEndOfStatement();
10060 return false;
10061}
10062
Jim Grosbach231e7aa2013-02-06 06:00:11 +000010063// Define this matcher function after the auto-generated include so we
10064// have the match class enum definitions.
David Blaikie960ea3f2014-06-08 16:18:35 +000010065unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand &AsmOp,
Jim Grosbach231e7aa2013-02-06 06:00:11 +000010066 unsigned Kind) {
David Blaikie960ea3f2014-06-08 16:18:35 +000010067 ARMOperand &Op = static_cast<ARMOperand &>(AsmOp);
Jim Grosbach231e7aa2013-02-06 06:00:11 +000010068 // If the kind is a token for a literal immediate, check if our asm
10069 // operand matches. This is for InstAliases which have a fixed-value
10070 // immediate in the syntax.
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +000010071 switch (Kind) {
10072 default: break;
10073 case MCK__35_0:
David Blaikie960ea3f2014-06-08 16:18:35 +000010074 if (Op.isImm())
10075 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm()))
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +000010076 if (CE->getValue() == 0)
10077 return Match_Success;
10078 break;
Asiri Rathnayakea0199b92014-12-02 10:53:20 +000010079 case MCK_ModImm:
David Blaikie960ea3f2014-06-08 16:18:35 +000010080 if (Op.isImm()) {
10081 const MCExpr *SOExpr = Op.getImm();
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +000010082 int64_t Value;
10083 if (!SOExpr->EvaluateAsAbsolute(Value))
Stepan Dyatkovskiydf657cc2014-03-29 13:12:40 +000010084 return Match_Success;
Richard Barton3db1d582014-05-01 11:37:44 +000010085 assert((Value >= INT32_MIN && Value <= UINT32_MAX) &&
10086 "expression value must be representable in 32 bits");
Saleem Abdulrasoold88affb2014-01-08 03:28:14 +000010087 }
10088 break;
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +000010089 case MCK_GPRPair:
David Blaikie960ea3f2014-06-08 16:18:35 +000010090 if (Op.isReg() &&
10091 MRI->getRegClass(ARM::GPRRegClassID).contains(Op.getReg()))
Saleem Abdulrasoole6e6d712014-01-10 04:38:35 +000010092 return Match_Success;
10093 break;
Jim Grosbach231e7aa2013-02-06 06:00:11 +000010094 }
10095 return Match_InvalidOperand;
10096}