blob: d3b6c78e17c3bc81ef64f90637994d527e060f94 [file] [log] [blame]
Kevin Enderbyccab3172009-09-15 00:27:25 +00001//===-- ARMAsmParser.cpp - Parse ARM assembly to MCInst instructions ------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Logan Chien8cbb80d2013-10-28 17:51:12 +000010#include "ARMBuildAttrs.h"
11#include "ARMFPUName.h"
Amara Emerson52cfb6a2013-10-03 09:31:51 +000012#include "ARMFeatures.h"
Evan Cheng11424442011-07-26 00:24:13 +000013#include "llvm/MC/MCTargetAsmParser.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000014#include "MCTargetDesc/ARMAddressingModes.h"
Logan Chien439e8f92013-12-11 17:16:25 +000015#include "MCTargetDesc/ARMArchName.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000016#include "MCTargetDesc/ARMBaseInfo.h"
17#include "MCTargetDesc/ARMMCExpr.h"
Jim Grosbach5c932b22011-08-22 18:50:36 +000018#include "llvm/ADT/BitVector.h"
David Peixotto52303f62013-12-19 22:41:56 +000019#include "llvm/ADT/MapVector.h"
Benjamin Kramerdebe69f2011-07-08 21:06:23 +000020#include "llvm/ADT/OwningPtr.h"
Evan Cheng11424442011-07-26 00:24:13 +000021#include "llvm/ADT/STLExtras.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000022#include "llvm/ADT/SmallVector.h"
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +000023#include "llvm/ADT/StringExtras.h"
Daniel Dunbar188b47b2010-08-11 06:37:20 +000024#include "llvm/ADT/StringSwitch.h"
Chris Lattner00646cf2010-01-22 01:44:57 +000025#include "llvm/ADT/Twine.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000026#include "llvm/MC/MCAsmInfo.h"
Jack Carter718da0b2013-01-30 02:24:33 +000027#include "llvm/MC/MCAssembler.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000028#include "llvm/MC/MCContext.h"
Jack Carter718da0b2013-01-30 02:24:33 +000029#include "llvm/MC/MCELFStreamer.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000030#include "llvm/MC/MCExpr.h"
31#include "llvm/MC/MCInst.h"
32#include "llvm/MC/MCInstrDesc.h"
Joey Gouly0e76fa72013-09-12 10:28:05 +000033#include "llvm/MC/MCInstrInfo.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000034#include "llvm/MC/MCParser/MCAsmLexer.h"
35#include "llvm/MC/MCParser/MCAsmParser.h"
36#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
37#include "llvm/MC/MCRegisterInfo.h"
38#include "llvm/MC/MCStreamer.h"
39#include "llvm/MC/MCSubtargetInfo.h"
David Peixottoe407d092013-12-19 18:12:36 +000040#include "llvm/MC/MCSymbol.h"
Jack Carter718da0b2013-01-30 02:24:33 +000041#include "llvm/Support/ELF.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000042#include "llvm/Support/MathExtras.h"
43#include "llvm/Support/SourceMgr.h"
44#include "llvm/Support/TargetRegistry.h"
45#include "llvm/Support/raw_ostream.h"
Evan Cheng4d1ca962011-07-08 01:53:10 +000046
Kevin Enderbyccab3172009-09-15 00:27:25 +000047using namespace llvm;
48
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +000049namespace {
Bill Wendlingee7f1f92010-11-06 21:42:12 +000050
51class ARMOperand;
Jim Grosbach624bcc72010-10-29 14:46:02 +000052
Jim Grosbach04945c42011-12-02 00:35:16 +000053enum VectorLaneTy { NoLanes, AllLanes, IndexedLane };
Jim Grosbachcd6f5e72011-11-30 01:09:44 +000054
David Peixottoe407d092013-12-19 18:12:36 +000055// A class to keep track of assembler-generated constant pools that are use to
56// implement the ldr-pseudo.
57class ConstantPool {
58 typedef SmallVector<std::pair<MCSymbol *, const MCExpr *>, 4> EntryVecTy;
59 EntryVecTy Entries;
60
61public:
62 // Initialize a new empty constant pool
63 ConstantPool() { }
64
65 // Add a new entry to the constant pool in the next slot.
66 // \param Value is the new entry to put in the constant pool.
67 //
68 // \returns a MCExpr that references the newly inserted value
69 const MCExpr *addEntry(const MCExpr *Value, MCContext &Context) {
70 MCSymbol *CPEntryLabel = Context.CreateTempSymbol();
71
72 Entries.push_back(std::make_pair(CPEntryLabel, Value));
73 return MCSymbolRefExpr::Create(CPEntryLabel, Context);
74 }
75
76 // Emit the contents of the constant pool using the provided streamer.
David Peixotto52303f62013-12-19 22:41:56 +000077 void emitEntries(MCStreamer &Streamer) {
78 if (Entries.empty())
79 return;
David Peixottoe407d092013-12-19 18:12:36 +000080 Streamer.EmitCodeAlignment(4); // align to 4-byte address
81 Streamer.EmitDataRegion(MCDR_DataRegion);
82 for (EntryVecTy::const_iterator I = Entries.begin(), E = Entries.end();
83 I != E; ++I) {
84 Streamer.EmitLabel(I->first);
85 Streamer.EmitValue(I->second, 4);
86 }
87 Streamer.EmitDataRegion(MCDR_DataRegionEnd);
David Peixotto52303f62013-12-19 22:41:56 +000088 Entries.clear();
89 }
90
91 // Return true if the constant pool is empty
92 bool empty() {
93 return Entries.empty();
David Peixottoe407d092013-12-19 18:12:36 +000094 }
95};
96
97// Map type used to keep track of per-Section constant pools used by the
98// ldr-pseudo opcode. The map associates a section to its constant pool. The
99// constant pool is a vector of (label, value) pairs. When the ldr
100// pseudo is parsed we insert a new (label, value) pair into the constant pool
101// for the current section and add MCSymbolRefExpr to the new label as
102// an opcode to the ldr. After we have parsed all the user input we
103// output the (label, value) pairs in each constant pool at the end of the
104// section.
David Peixotto52303f62013-12-19 22:41:56 +0000105//
106// We use the MapVector for the map type to ensure stable iteration of
107// the sections at the end of the parse. We need to iterate over the
108// sections in a stable order to ensure that we have print the
109// constant pools in a deterministic order when printing an assembly
110// file.
111typedef MapVector<const MCSection *, ConstantPool> ConstantPoolMapTy;
David Peixottoe407d092013-12-19 18:12:36 +0000112
Evan Cheng11424442011-07-26 00:24:13 +0000113class ARMAsmParser : public MCTargetAsmParser {
Evan Cheng91111d22011-07-09 05:47:46 +0000114 MCSubtargetInfo &STI;
Kevin Enderbyccab3172009-09-15 00:27:25 +0000115 MCAsmParser &Parser;
Joey Gouly0e76fa72013-09-12 10:28:05 +0000116 const MCInstrInfo &MII;
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000117 const MCRegisterInfo *MRI;
David Peixottoe407d092013-12-19 18:12:36 +0000118 ConstantPoolMapTy ConstantPools;
119
120 // Assembler created constant pools for ldr pseudo
121 ConstantPool *getConstantPool(const MCSection *Section) {
122 ConstantPoolMapTy::iterator CP = ConstantPools.find(Section);
123 if (CP == ConstantPools.end())
124 return 0;
125
126 return &CP->second;
127 }
128
129 ConstantPool &getOrCreateConstantPool(const MCSection *Section) {
130 return ConstantPools[Section];
131 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000132
Rafael Espindolaa17151a2013-10-08 13:08:17 +0000133 ARMTargetStreamer &getTargetStreamer() {
134 MCTargetStreamer &TS = getParser().getStreamer().getTargetStreamer();
135 return static_cast<ARMTargetStreamer &>(TS);
136 }
137
Logan Chien4ea23b52013-05-10 16:17:24 +0000138 // Unwind directives state
139 SMLoc FnStartLoc;
140 SMLoc CantUnwindLoc;
141 SMLoc PersonalityLoc;
142 SMLoc HandlerDataLoc;
143 int FPReg;
144 void resetUnwindDirectiveParserState() {
145 FnStartLoc = SMLoc();
146 CantUnwindLoc = SMLoc();
147 PersonalityLoc = SMLoc();
148 HandlerDataLoc = SMLoc();
149 FPReg = -1;
150 }
151
Jim Grosbachab5830e2011-12-14 02:16:11 +0000152 // Map of register aliases registers via the .req directive.
153 StringMap<unsigned> RegisterReqs;
154
Tim Northover1744d0a2013-10-25 12:49:50 +0000155 bool NextSymbolIsThumb;
156
Jim Grosbached16ec42011-08-29 22:24:09 +0000157 struct {
158 ARMCC::CondCodes Cond; // Condition for IT block.
159 unsigned Mask:4; // Condition mask for instructions.
160 // Starting at first 1 (from lsb).
161 // '1' condition as indicated in IT.
162 // '0' inverse of condition (else).
163 // Count of instructions in IT block is
164 // 4 - trailingzeroes(mask)
165
166 bool FirstCond; // Explicit flag for when we're parsing the
167 // First instruction in the IT block. It's
168 // implied in the mask, so needs special
169 // handling.
170
171 unsigned CurPosition; // Current position in parsing of IT
172 // block. In range [0,3]. Initialized
173 // according to count of instructions in block.
174 // ~0U if no active IT block.
175 } ITState;
176 bool inITBlock() { return ITState.CurPosition != ~0U;}
Jim Grosbacha0d34d32011-09-02 23:22:08 +0000177 void forwardITPosition() {
178 if (!inITBlock()) return;
179 // Move to the next instruction in the IT block, if there is one. If not,
180 // mark the block as done.
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +0000181 unsigned TZ = countTrailingZeros(ITState.Mask);
Jim Grosbacha0d34d32011-09-02 23:22:08 +0000182 if (++ITState.CurPosition == 5 - TZ)
183 ITState.CurPosition = ~0U; // Done with the IT block after this.
184 }
Jim Grosbached16ec42011-08-29 22:24:09 +0000185
186
Kevin Enderbyccab3172009-09-15 00:27:25 +0000187 MCAsmParser &getParser() const { return Parser; }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000188 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
189
Benjamin Kramer673824b2012-04-15 17:04:27 +0000190 bool Warning(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000191 ArrayRef<SMRange> Ranges = None) {
Benjamin Kramer673824b2012-04-15 17:04:27 +0000192 return Parser.Warning(L, Msg, Ranges);
193 }
194 bool Error(SMLoc L, const Twine &Msg,
Dmitri Gribenko3238fb72013-05-05 00:40:33 +0000195 ArrayRef<SMRange> Ranges = None) {
Benjamin Kramer673824b2012-04-15 17:04:27 +0000196 return Parser.Error(L, Msg, Ranges);
197 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000198
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000199 int tryParseRegister();
200 bool tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbach0d6022d2011-07-26 20:41:24 +0000201 int tryParseShiftRegister(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000202 bool parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbachd3595712011-08-03 23:50:40 +0000203 bool parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000204 bool parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &, StringRef Mnemonic);
205 bool parsePrefix(ARMMCExpr::VariantKind &RefKind);
Jim Grosbachd3595712011-08-03 23:50:40 +0000206 bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType,
207 unsigned &ShiftAmount);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000208 bool parseDirectiveWord(unsigned Size, SMLoc L);
209 bool parseDirectiveThumb(SMLoc L);
Jim Grosbach7f882392011-12-07 18:04:19 +0000210 bool parseDirectiveARM(SMLoc L);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000211 bool parseDirectiveThumbFunc(SMLoc L);
212 bool parseDirectiveCode(SMLoc L);
213 bool parseDirectiveSyntax(SMLoc L);
Jim Grosbachab5830e2011-12-14 02:16:11 +0000214 bool parseDirectiveReq(StringRef Name, SMLoc L);
215 bool parseDirectiveUnreq(SMLoc L);
Jason W Kim135d2442011-12-20 17:38:12 +0000216 bool parseDirectiveArch(SMLoc L);
217 bool parseDirectiveEabiAttr(SMLoc L);
Logan Chien8cbb80d2013-10-28 17:51:12 +0000218 bool parseDirectiveCPU(SMLoc L);
219 bool parseDirectiveFPU(SMLoc L);
Logan Chien4ea23b52013-05-10 16:17:24 +0000220 bool parseDirectiveFnStart(SMLoc L);
221 bool parseDirectiveFnEnd(SMLoc L);
222 bool parseDirectiveCantUnwind(SMLoc L);
223 bool parseDirectivePersonality(SMLoc L);
224 bool parseDirectiveHandlerData(SMLoc L);
225 bool parseDirectiveSetFP(SMLoc L);
226 bool parseDirectivePad(SMLoc L);
227 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +0000228 bool parseDirectiveInst(SMLoc L, char Suffix = '\0');
David Peixotto80c083a2013-12-19 18:26:07 +0000229 bool parseDirectiveLtorg(SMLoc L);
Kevin Enderby146dcf22009-10-15 20:48:48 +0000230
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000231 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000232 bool &CarrySetting, unsigned &ProcessorIMod,
233 StringRef &ITMask);
Amara Emerson33089092013-09-19 11:59:01 +0000234 void getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
235 bool &CanAcceptCarrySet,
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +0000236 bool &CanAcceptPredicationCode);
Jim Grosbach624bcc72010-10-29 14:46:02 +0000237
Evan Cheng4d1ca962011-07-08 01:53:10 +0000238 bool isThumb() const {
239 // FIXME: Can tablegen auto-generate this?
Evan Cheng91111d22011-07-09 05:47:46 +0000240 return (STI.getFeatureBits() & ARM::ModeThumb) != 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000241 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000242 bool isThumbOne() const {
Evan Cheng91111d22011-07-09 05:47:46 +0000243 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000244 }
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000245 bool isThumbTwo() const {
246 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
247 }
Tim Northovera2292d02013-06-10 23:20:58 +0000248 bool hasThumb() const {
249 return STI.getFeatureBits() & ARM::HasV4TOps;
250 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000251 bool hasV6Ops() const {
252 return STI.getFeatureBits() & ARM::HasV6Ops;
253 }
Tim Northoverf86d1f02013-10-07 11:10:47 +0000254 bool hasV6MOps() const {
255 return STI.getFeatureBits() & ARM::HasV6MOps;
256 }
James Molloy21efa7d2011-09-28 14:21:38 +0000257 bool hasV7Ops() const {
258 return STI.getFeatureBits() & ARM::HasV7Ops;
259 }
Joey Goulyb3f550e2013-06-26 16:58:26 +0000260 bool hasV8Ops() const {
261 return STI.getFeatureBits() & ARM::HasV8Ops;
262 }
Tim Northovera2292d02013-06-10 23:20:58 +0000263 bool hasARM() const {
264 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
265 }
266
Evan Cheng284b4672011-07-08 22:36:29 +0000267 void SwitchMode() {
Evan Cheng91111d22011-07-09 05:47:46 +0000268 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
269 setAvailableFeatures(FB);
Evan Cheng284b4672011-07-08 22:36:29 +0000270 }
James Molloy21efa7d2011-09-28 14:21:38 +0000271 bool isMClass() const {
272 return STI.getFeatureBits() & ARM::FeatureMClass;
273 }
Evan Cheng4d1ca962011-07-08 01:53:10 +0000274
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000275 /// @name Auto-generated Match Functions
276 /// {
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +0000277
Chris Lattner3e4582a2010-09-06 19:11:01 +0000278#define GET_ASSEMBLER_HEADER
279#include "ARMGenAsmMatcher.inc"
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000280
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000281 /// }
282
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000283 OperandMatchResultTy parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000284 OperandMatchResultTy parseCoprocNumOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000285 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000286 OperandMatchResultTy parseCoprocRegOperand(
Jim Grosbach861e49c2011-02-12 01:34:40 +0000287 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach48399582011-10-12 17:34:41 +0000288 OperandMatchResultTy parseCoprocOptionOperand(
289 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000290 OperandMatchResultTy parseMemBarrierOptOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000291 SmallVectorImpl<MCParsedAsmOperand*>&);
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000292 OperandMatchResultTy parseInstSyncBarrierOptOperand(
293 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000294 OperandMatchResultTy parseProcIFlagsOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000295 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach2d6ef442011-07-25 20:14:50 +0000296 OperandMatchResultTy parseMSRMaskOperand(
Bruno Cardoso Lopescdd20af2011-02-18 19:49:06 +0000297 SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach27c1e252011-07-21 17:23:04 +0000298 OperandMatchResultTy parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &O,
299 StringRef Op, int Low, int High);
300 OperandMatchResultTy parsePKHLSLImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
301 return parsePKHImm(O, "lsl", 0, 31);
302 }
303 OperandMatchResultTy parsePKHASRImm(SmallVectorImpl<MCParsedAsmOperand*> &O) {
304 return parsePKHImm(O, "asr", 1, 32);
305 }
Jim Grosbach0a547702011-07-22 17:44:50 +0000306 OperandMatchResultTy parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000307 OperandMatchResultTy parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach833b9d32011-07-27 20:15:40 +0000308 OperandMatchResultTy parseRotImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach864b6092011-07-28 21:34:26 +0000309 OperandMatchResultTy parseBitfield(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachd3595712011-08-03 23:50:40 +0000310 OperandMatchResultTy parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbach1d9d5e92011-08-10 21:56:18 +0000311 OperandMatchResultTy parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbache7fbce72011-10-03 23:38:36 +0000312 OperandMatchResultTy parseFPImm(SmallVectorImpl<MCParsedAsmOperand*>&);
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000313 OperandMatchResultTy parseVectorList(SmallVectorImpl<MCParsedAsmOperand*>&);
Jordan Rosee8f1eae2013-01-07 19:00:49 +0000314 OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index,
315 SMLoc &EndLoc);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +0000316
317 // Asm Match Converter Methods
Chad Rosier451ef132012-08-31 22:12:31 +0000318 void cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +0000319 const SmallVectorImpl<MCParsedAsmOperand*> &);
Mihai Popaad18d3c2013-08-09 10:38:32 +0000320 void cvtThumbBranches(MCInst &Inst,
321 const SmallVectorImpl<MCParsedAsmOperand*> &);
322
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000323 bool validateInstruction(MCInst &Inst,
324 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbachafad0532011-11-10 23:42:14 +0000325 bool processInstruction(MCInst &Inst,
Jim Grosbach8ba76c62011-08-11 17:35:48 +0000326 const SmallVectorImpl<MCParsedAsmOperand*> &Ops);
Jim Grosbach7283da92011-08-16 21:12:37 +0000327 bool shouldOmitCCOutOperand(StringRef Mnemonic,
328 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Joey Goulye8602552013-07-19 16:34:16 +0000329 bool shouldOmitPredicateOperand(StringRef Mnemonic,
330 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Kevin Enderbyccab3172009-09-15 00:27:25 +0000331public:
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000332 enum ARMMatchResultTy {
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000333 Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY,
Jim Grosbached16ec42011-08-29 22:24:09 +0000334 Match_RequiresNotITBlock,
Jim Grosbachb7fa2c02011-08-16 22:20:01 +0000335 Match_RequiresV6,
Jim Grosbach087affe2012-06-22 23:56:48 +0000336 Match_RequiresThumb2,
337#define GET_OPERAND_DIAGNOSTIC_TYPES
338#include "ARMGenAsmMatcher.inc"
339
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000340 };
341
Joey Gouly0e76fa72013-09-12 10:28:05 +0000342 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser,
343 const MCInstrInfo &MII)
344 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), MII(MII), FPReg(-1) {
Evan Cheng4d1ca962011-07-08 01:53:10 +0000345 MCAsmParserExtension::Initialize(_Parser);
Evan Cheng284b4672011-07-08 22:36:29 +0000346
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000347 // Cache the MCRegisterInfo.
Bill Wendlingbc07a892013-06-18 07:20:20 +0000348 MRI = getContext().getRegisterInfo();
Jim Grosbachc988e0c2012-03-05 19:33:30 +0000349
Evan Cheng4d1ca962011-07-08 01:53:10 +0000350 // Initialize the set of available features.
Evan Cheng91111d22011-07-09 05:47:46 +0000351 setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits()));
Jim Grosbached16ec42011-08-29 22:24:09 +0000352
353 // Not in an ITBlock to start with.
354 ITState.CurPosition = ~0U;
Tim Northover1744d0a2013-10-25 12:49:50 +0000355
356 NextSymbolIsThumb = false;
Evan Cheng4d1ca962011-07-08 01:53:10 +0000357 }
Kevin Enderbyccab3172009-09-15 00:27:25 +0000358
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000359 // Implementation of the MCTargetAsmParser interface:
360 bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc);
Chad Rosierf0e87202012-10-25 20:41:34 +0000361 bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
362 SMLoc NameLoc,
Jim Grosbachedaa35a2011-07-26 18:25:39 +0000363 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000364 bool ParseDirective(AsmToken DirectiveID);
365
Jim Grosbach231e7aa2013-02-06 06:00:11 +0000366 unsigned validateTargetOperandClass(MCParsedAsmOperand *Op, unsigned Kind);
Jim Grosbach3e941ae2011-08-16 20:45:50 +0000367 unsigned checkTargetMatchPredicate(MCInst &Inst);
368
Chad Rosier49963552012-10-13 00:26:04 +0000369 bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Jim Grosbacheab1c0d2011-07-26 17:10:22 +0000370 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +0000371 MCStreamer &Out, unsigned &ErrorInfo,
372 bool MatchingInlineAsm);
Tim Northover1744d0a2013-10-25 12:49:50 +0000373 void onLabelParsed(MCSymbol *Symbol);
David Peixottoe407d092013-12-19 18:12:36 +0000374 void finishParse();
Kevin Enderbyccab3172009-09-15 00:27:25 +0000375};
Jim Grosbach624bcc72010-10-29 14:46:02 +0000376} // end anonymous namespace
377
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +0000378namespace {
379
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000380/// ARMOperand - Instances of this class represent a parsed ARM machine
Joel Jones54597542013-01-09 22:34:16 +0000381/// operand.
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000382class ARMOperand : public MCParsedAsmOperand {
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000383 enum KindTy {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000384 k_CondCode,
385 k_CCOut,
386 k_ITCondMask,
387 k_CoprocNum,
388 k_CoprocReg,
Jim Grosbach48399582011-10-12 17:34:41 +0000389 k_CoprocOption,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000390 k_Immediate,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000391 k_MemBarrierOpt,
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000392 k_InstSyncBarrierOpt,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000393 k_Memory,
394 k_PostIndexRegister,
395 k_MSRMask,
396 k_ProcIFlags,
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000397 k_VectorIndex,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000398 k_Register,
399 k_RegisterList,
400 k_DPRRegisterList,
401 k_SPRRegisterList,
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000402 k_VectorList,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000403 k_VectorListAllLanes,
Jim Grosbach04945c42011-12-02 00:35:16 +0000404 k_VectorListIndexed,
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000405 k_ShiftedRegister,
406 k_ShiftedImmediate,
407 k_ShifterImmediate,
408 k_RotateImmediate,
409 k_BitfieldDescriptor,
410 k_Token
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000411 } Kind;
412
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000413 SMLoc StartLoc, EndLoc;
Bill Wendling0ab0f672010-11-18 21:50:54 +0000414 SmallVector<unsigned, 8> Registers;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000415
Eric Christopher8996c5d2013-03-15 00:42:55 +0000416 struct CCOp {
417 ARMCC::CondCodes Val;
418 };
419
420 struct CopOp {
421 unsigned Val;
422 };
423
424 struct CoprocOptionOp {
425 unsigned Val;
426 };
427
428 struct ITMaskOp {
429 unsigned Mask:4;
430 };
431
432 struct MBOptOp {
433 ARM_MB::MemBOpt Val;
434 };
435
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000436 struct ISBOptOp {
437 ARM_ISB::InstSyncBOpt Val;
438 };
439
Eric Christopher8996c5d2013-03-15 00:42:55 +0000440 struct IFlagsOp {
441 ARM_PROC::IFlags Val;
442 };
443
444 struct MMaskOp {
445 unsigned Val;
446 };
447
448 struct TokOp {
449 const char *Data;
450 unsigned Length;
451 };
452
453 struct RegOp {
454 unsigned RegNum;
455 };
456
457 // A vector register list is a sequential list of 1 to 4 registers.
458 struct VectorListOp {
459 unsigned RegNum;
460 unsigned Count;
461 unsigned LaneIndex;
462 bool isDoubleSpaced;
463 };
464
465 struct VectorIndexOp {
466 unsigned Val;
467 };
468
469 struct ImmOp {
470 const MCExpr *Val;
471 };
472
473 /// Combined record for all forms of ARM address expressions.
474 struct MemoryOp {
475 unsigned BaseRegNum;
476 // Offset is in OffsetReg or OffsetImm. If both are zero, no offset
477 // was specified.
478 const MCConstantExpr *OffsetImm; // Offset immediate value
479 unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL
480 ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg
481 unsigned ShiftImm; // shift for OffsetReg.
482 unsigned Alignment; // 0 = no alignment specified
483 // n = alignment in bytes (2, 4, 8, 16, or 32)
484 unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit)
485 };
486
487 struct PostIdxRegOp {
488 unsigned RegNum;
489 bool isAdd;
490 ARM_AM::ShiftOpc ShiftTy;
491 unsigned ShiftImm;
492 };
493
494 struct ShifterImmOp {
495 bool isASR;
496 unsigned Imm;
497 };
498
499 struct RegShiftedRegOp {
500 ARM_AM::ShiftOpc ShiftTy;
501 unsigned SrcReg;
502 unsigned ShiftReg;
503 unsigned ShiftImm;
504 };
505
506 struct RegShiftedImmOp {
507 ARM_AM::ShiftOpc ShiftTy;
508 unsigned SrcReg;
509 unsigned ShiftImm;
510 };
511
512 struct RotImmOp {
513 unsigned Imm;
514 };
515
516 struct BitfieldOp {
517 unsigned LSB;
518 unsigned Width;
519 };
520
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000521 union {
Eric Christopher8996c5d2013-03-15 00:42:55 +0000522 struct CCOp CC;
523 struct CopOp Cop;
524 struct CoprocOptionOp CoprocOption;
525 struct MBOptOp MBOpt;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000526 struct ISBOptOp ISBOpt;
Eric Christopher8996c5d2013-03-15 00:42:55 +0000527 struct ITMaskOp ITMask;
528 struct IFlagsOp IFlags;
529 struct MMaskOp MMask;
530 struct TokOp Tok;
531 struct RegOp Reg;
532 struct VectorListOp VectorList;
533 struct VectorIndexOp VectorIndex;
534 struct ImmOp Imm;
535 struct MemoryOp Memory;
536 struct PostIdxRegOp PostIdxReg;
537 struct ShifterImmOp ShifterImm;
538 struct RegShiftedRegOp RegShiftedReg;
539 struct RegShiftedImmOp RegShiftedImm;
540 struct RotImmOp RotImm;
541 struct BitfieldOp Bitfield;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000542 };
Jim Grosbach624bcc72010-10-29 14:46:02 +0000543
Bill Wendlingee7f1f92010-11-06 21:42:12 +0000544 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
545public:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000546 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
547 Kind = o.Kind;
548 StartLoc = o.StartLoc;
549 EndLoc = o.EndLoc;
550 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000551 case k_CondCode:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000552 CC = o.CC;
553 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000554 case k_ITCondMask:
Jim Grosbach3d1eac82011-08-26 21:43:41 +0000555 ITMask = o.ITMask;
556 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000557 case k_Token:
Daniel Dunbard8042b72010-08-11 06:36:53 +0000558 Tok = o.Tok;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000559 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000560 case k_CCOut:
561 case k_Register:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000562 Reg = o.Reg;
563 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000564 case k_RegisterList:
565 case k_DPRRegisterList:
566 case k_SPRRegisterList:
Bill Wendling0ab0f672010-11-18 21:50:54 +0000567 Registers = o.Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000568 break;
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000569 case k_VectorList:
Jim Grosbachcd6f5e72011-11-30 01:09:44 +0000570 case k_VectorListAllLanes:
Jim Grosbach04945c42011-12-02 00:35:16 +0000571 case k_VectorListIndexed:
Jim Grosbachad47cfc2011-10-18 23:02:30 +0000572 VectorList = o.VectorList;
573 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000574 case k_CoprocNum:
575 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000576 Cop = o.Cop;
577 break;
Jim Grosbach48399582011-10-12 17:34:41 +0000578 case k_CoprocOption:
579 CoprocOption = o.CoprocOption;
580 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000581 case k_Immediate:
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000582 Imm = o.Imm;
583 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000584 case k_MemBarrierOpt:
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000585 MBOpt = o.MBOpt;
586 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000587 case k_InstSyncBarrierOpt:
588 ISBOpt = o.ISBOpt;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000589 case k_Memory:
Jim Grosbach871dff72011-10-11 15:59:20 +0000590 Memory = o.Memory;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000591 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000592 case k_PostIndexRegister:
Jim Grosbachd3595712011-08-03 23:50:40 +0000593 PostIdxReg = o.PostIdxReg;
594 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000595 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000596 MMask = o.MMask;
597 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000598 case k_ProcIFlags:
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000599 IFlags = o.IFlags;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000600 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000601 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +0000602 ShifterImm = o.ShifterImm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +0000603 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000604 case k_ShiftedRegister:
Jim Grosbachac798e12011-07-25 20:49:51 +0000605 RegShiftedReg = o.RegShiftedReg;
Jim Grosbach7dcd1352011-07-13 17:50:29 +0000606 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000607 case k_ShiftedImmediate:
Jim Grosbachac798e12011-07-25 20:49:51 +0000608 RegShiftedImm = o.RegShiftedImm;
Owen Andersonb595ed02011-07-21 18:54:16 +0000609 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000610 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +0000611 RotImm = o.RotImm;
612 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000613 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +0000614 Bitfield = o.Bitfield;
615 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000616 case k_VectorIndex:
617 VectorIndex = o.VectorIndex;
618 break;
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000619 }
620 }
Jim Grosbach624bcc72010-10-29 14:46:02 +0000621
Sean Callanan7ad0ad02010-04-02 22:27:05 +0000622 /// getStartLoc - Get the location of the first token of this operand.
623 SMLoc getStartLoc() const { return StartLoc; }
624 /// getEndLoc - Get the location of the last token of this operand.
625 SMLoc getEndLoc() const { return EndLoc; }
Chad Rosier143d0f72012-09-21 20:51:43 +0000626 /// getLocRange - Get the range between the first and last token of this
627 /// operand.
Benjamin Kramer673824b2012-04-15 17:04:27 +0000628 SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); }
629
Daniel Dunbard8042b72010-08-11 06:36:53 +0000630 ARMCC::CondCodes getCondCode() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000631 assert(Kind == k_CondCode && "Invalid access!");
Daniel Dunbard8042b72010-08-11 06:36:53 +0000632 return CC.Val;
633 }
634
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000635 unsigned getCoproc() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000636 assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!");
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +0000637 return Cop.Val;
638 }
639
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000640 StringRef getToken() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000641 assert(Kind == k_Token && "Invalid access!");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000642 return StringRef(Tok.Data, Tok.Length);
643 }
644
645 unsigned getReg() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000646 assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!");
Bill Wendling2cae3272010-11-09 22:44:22 +0000647 return Reg.RegNum;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +0000648 }
649
Bill Wendlingbed94652010-11-09 23:28:44 +0000650 const SmallVectorImpl<unsigned> &getRegList() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000651 assert((Kind == k_RegisterList || Kind == k_DPRRegisterList ||
652 Kind == k_SPRRegisterList) && "Invalid access!");
Bill Wendling0ab0f672010-11-18 21:50:54 +0000653 return Registers;
Bill Wendling7cef4472010-11-06 19:56:04 +0000654 }
655
Kevin Enderbyf5079942009-10-13 22:19:02 +0000656 const MCExpr *getImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000657 assert(isImm() && "Invalid access!");
Kevin Enderbyf5079942009-10-13 22:19:02 +0000658 return Imm.Val;
659 }
660
Jim Grosbachd0637bf2011-10-07 23:56:00 +0000661 unsigned getVectorIndex() const {
662 assert(Kind == k_VectorIndex && "Invalid access!");
663 return VectorIndex.Val;
664 }
665
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000666 ARM_MB::MemBOpt getMemBarrierOpt() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000667 assert(Kind == k_MemBarrierOpt && "Invalid access!");
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +0000668 return MBOpt.Val;
669 }
670
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +0000671 ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const {
672 assert(Kind == k_InstSyncBarrierOpt && "Invalid access!");
673 return ISBOpt.Val;
674 }
675
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000676 ARM_PROC::IFlags getProcIFlags() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000677 assert(Kind == k_ProcIFlags && "Invalid access!");
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +0000678 return IFlags.Val;
679 }
680
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000681 unsigned getMSRMask() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000682 assert(Kind == k_MSRMask && "Invalid access!");
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +0000683 return MMask.Val;
684 }
685
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000686 bool isCoprocNum() const { return Kind == k_CoprocNum; }
687 bool isCoprocReg() const { return Kind == k_CoprocReg; }
Jim Grosbach48399582011-10-12 17:34:41 +0000688 bool isCoprocOption() const { return Kind == k_CoprocOption; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +0000689 bool isCondCode() const { return Kind == k_CondCode; }
690 bool isCCOut() const { return Kind == k_CCOut; }
691 bool isITMask() const { return Kind == k_ITCondMask; }
692 bool isITCondCode() const { return Kind == k_CondCode; }
693 bool isImm() const { return Kind == k_Immediate; }
Mihai Popad36cbaa2013-07-03 09:21:44 +0000694 // checks whether this operand is an unsigned offset which fits is a field
695 // of specified width and scaled by a specific number of bits
696 template<unsigned width, unsigned scale>
697 bool isUnsignedOffset() const {
698 if (!isImm()) return false;
Mihai Popaad18d3c2013-08-09 10:38:32 +0000699 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
Mihai Popad36cbaa2013-07-03 09:21:44 +0000700 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
701 int64_t Val = CE->getValue();
702 int64_t Align = 1LL << scale;
703 int64_t Max = Align * ((1LL << width) - 1);
704 return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max);
705 }
706 return false;
707 }
Mihai Popaad18d3c2013-08-09 10:38:32 +0000708 // checks whether this operand is an signed offset which fits is a field
709 // of specified width and scaled by a specific number of bits
710 template<unsigned width, unsigned scale>
711 bool isSignedOffset() const {
712 if (!isImm()) return false;
713 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
714 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) {
715 int64_t Val = CE->getValue();
716 int64_t Align = 1LL << scale;
717 int64_t Max = Align * ((1LL << (width-1)) - 1);
718 int64_t Min = -Align * (1LL << (width-1));
719 return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max);
720 }
721 return false;
722 }
723
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000724 // checks whether this operand is a memory operand computed as an offset
725 // applied to PC. the offset may have 8 bits of magnitude and is represented
726 // with two bits of shift. textually it may be either [pc, #imm], #imm or
727 // relocable expression...
728 bool isThumbMemPC() const {
729 int64_t Val = 0;
730 if (isImm()) {
731 if (isa<MCSymbolRefExpr>(Imm.Val)) return true;
732 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val);
733 if (!CE) return false;
734 Val = CE->getValue();
735 }
736 else if (isMem()) {
737 if(!Memory.OffsetImm || Memory.OffsetRegNum) return false;
738 if(Memory.BaseRegNum != ARM::PC) return false;
739 Val = Memory.OffsetImm->getValue();
740 }
741 else return false;
Mihai Popad79f00b2013-08-15 15:43:06 +0000742 return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020);
Mihai Popa8a9da5b2013-07-22 15:49:36 +0000743 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +0000744 bool isFPImm() const {
745 if (!isImm()) return false;
746 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
747 if (!CE) return false;
748 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
749 return Val != -1;
750 }
Jim Grosbachea231912011-12-22 22:19:05 +0000751 bool isFBits16() const {
752 if (!isImm()) return false;
753 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
754 if (!CE) return false;
755 int64_t Value = CE->getValue();
756 return Value >= 0 && Value <= 16;
757 }
758 bool isFBits32() const {
759 if (!isImm()) return false;
760 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
761 if (!CE) return false;
762 int64_t Value = CE->getValue();
763 return Value >= 1 && Value <= 32;
764 }
Jim Grosbach7db8d692011-09-08 22:07:06 +0000765 bool isImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000766 if (!isImm()) return false;
Jim Grosbach7db8d692011-09-08 22:07:06 +0000767 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
768 if (!CE) return false;
769 int64_t Value = CE->getValue();
770 return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020;
771 }
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000772 bool isImm0_1020s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000773 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000774 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
775 if (!CE) return false;
776 int64_t Value = CE->getValue();
777 return ((Value & 3) == 0) && Value >= 0 && Value <= 1020;
778 }
779 bool isImm0_508s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000780 if (!isImm()) return false;
Jim Grosbach0a0b3072011-08-24 21:22:15 +0000781 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
782 if (!CE) return false;
783 int64_t Value = CE->getValue();
784 return ((Value & 3) == 0) && Value >= 0 && Value <= 508;
785 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000786 bool isImm0_508s4Neg() const {
787 if (!isImm()) return false;
788 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
789 if (!CE) return false;
790 int64_t Value = -CE->getValue();
791 // explicitly exclude zero. we want that to use the normal 0_508 version.
792 return ((Value & 3) == 0) && Value > 0 && Value <= 508;
793 }
Artyom Skrobovfc12e702013-10-23 10:14:40 +0000794 bool isImm0_239() const {
795 if (!isImm()) return false;
796 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
797 if (!CE) return false;
798 int64_t Value = CE->getValue();
799 return Value >= 0 && Value < 240;
800 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000801 bool isImm0_255() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000802 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +0000803 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
804 if (!CE) return false;
805 int64_t Value = CE->getValue();
806 return Value >= 0 && Value < 256;
807 }
Jim Grosbach930f2f62012-04-05 20:57:13 +0000808 bool isImm0_4095() const {
809 if (!isImm()) return false;
810 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
811 if (!CE) return false;
812 int64_t Value = CE->getValue();
813 return Value >= 0 && Value < 4096;
814 }
815 bool isImm0_4095Neg() const {
816 if (!isImm()) return false;
817 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
818 if (!CE) return false;
819 int64_t Value = -CE->getValue();
820 return Value > 0 && Value < 4096;
821 }
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000822 bool isImm0_1() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000823 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000824 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
825 if (!CE) return false;
826 int64_t Value = CE->getValue();
827 return Value >= 0 && Value < 2;
828 }
829 bool isImm0_3() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000830 if (!isImm()) return false;
Jim Grosbach9dff9f42011-12-02 23:34:39 +0000831 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
832 if (!CE) return false;
833 int64_t Value = CE->getValue();
834 return Value >= 0 && Value < 4;
835 }
Jim Grosbach31756c22011-07-13 22:01:08 +0000836 bool isImm0_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000837 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000838 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
839 if (!CE) return false;
840 int64_t Value = CE->getValue();
841 return Value >= 0 && Value < 8;
842 }
843 bool isImm0_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000844 if (!isImm()) return false;
Jim Grosbach31756c22011-07-13 22:01:08 +0000845 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
846 if (!CE) return false;
847 int64_t Value = CE->getValue();
848 return Value >= 0 && Value < 16;
849 }
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000850 bool isImm0_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000851 if (!isImm()) return false;
Jim Grosbach72e7c4f2011-07-21 23:26:25 +0000852 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
853 if (!CE) return false;
854 int64_t Value = CE->getValue();
855 return Value >= 0 && Value < 32;
856 }
Jim Grosbach00326402011-12-08 01:30:04 +0000857 bool isImm0_63() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000858 if (!isImm()) return false;
Jim Grosbach00326402011-12-08 01:30:04 +0000859 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
860 if (!CE) return false;
861 int64_t Value = CE->getValue();
862 return Value >= 0 && Value < 64;
863 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000864 bool isImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000865 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000866 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
867 if (!CE) return false;
868 int64_t Value = CE->getValue();
869 return Value == 8;
870 }
871 bool isImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000872 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000873 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
874 if (!CE) return false;
875 int64_t Value = CE->getValue();
876 return Value == 16;
877 }
878 bool isImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000879 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000880 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
881 if (!CE) return false;
882 int64_t Value = CE->getValue();
883 return Value == 32;
884 }
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000885 bool isShrImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000886 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000887 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
888 if (!CE) return false;
889 int64_t Value = CE->getValue();
890 return Value > 0 && Value <= 8;
891 }
892 bool isShrImm16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000893 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000894 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
895 if (!CE) return false;
896 int64_t Value = CE->getValue();
897 return Value > 0 && Value <= 16;
898 }
899 bool isShrImm32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000900 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000901 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
902 if (!CE) return false;
903 int64_t Value = CE->getValue();
904 return Value > 0 && Value <= 32;
905 }
906 bool isShrImm64() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000907 if (!isImm()) return false;
Jim Grosbachba7d6ed2011-12-08 22:06:06 +0000908 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
909 if (!CE) return false;
910 int64_t Value = CE->getValue();
911 return Value > 0 && Value <= 64;
912 }
Jim Grosbachd4b82492011-12-07 01:07:24 +0000913 bool isImm1_7() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000914 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000915 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
916 if (!CE) return false;
917 int64_t Value = CE->getValue();
918 return Value > 0 && Value < 8;
919 }
920 bool isImm1_15() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000921 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000922 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
923 if (!CE) return false;
924 int64_t Value = CE->getValue();
925 return Value > 0 && Value < 16;
926 }
927 bool isImm1_31() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000928 if (!isImm()) return false;
Jim Grosbachd4b82492011-12-07 01:07:24 +0000929 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
930 if (!CE) return false;
931 int64_t Value = CE->getValue();
932 return Value > 0 && Value < 32;
933 }
Jim Grosbach475c6db2011-07-25 23:09:14 +0000934 bool isImm1_16() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000935 if (!isImm()) return false;
Jim Grosbach475c6db2011-07-25 23:09:14 +0000936 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
937 if (!CE) return false;
938 int64_t Value = CE->getValue();
939 return Value > 0 && Value < 17;
940 }
Jim Grosbach801e0a32011-07-22 23:16:18 +0000941 bool isImm1_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000942 if (!isImm()) return false;
Jim Grosbach801e0a32011-07-22 23:16:18 +0000943 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
944 if (!CE) return false;
945 int64_t Value = CE->getValue();
946 return Value > 0 && Value < 33;
947 }
Jim Grosbachc14871c2011-11-10 19:18:01 +0000948 bool isImm0_32() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000949 if (!isImm()) return false;
Jim Grosbachc14871c2011-11-10 19:18:01 +0000950 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
951 if (!CE) return false;
952 int64_t Value = CE->getValue();
953 return Value >= 0 && Value < 33;
954 }
Jim Grosbach975b6412011-07-13 20:10:10 +0000955 bool isImm0_65535() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000956 if (!isImm()) return false;
Jim Grosbach975b6412011-07-13 20:10:10 +0000957 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
958 if (!CE) return false;
959 int64_t Value = CE->getValue();
960 return Value >= 0 && Value < 65536;
961 }
Mihai Popaae1112b2013-08-21 13:14:58 +0000962 bool isImm256_65535Expr() const {
963 if (!isImm()) return false;
964 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
965 // If it's not a constant expression, it'll generate a fixup and be
966 // handled later.
967 if (!CE) return true;
968 int64_t Value = CE->getValue();
969 return Value >= 256 && Value < 65536;
970 }
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000971 bool isImm0_65535Expr() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000972 if (!isImm()) return false;
Jim Grosbach7c09e3c2011-07-19 19:13:28 +0000973 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
974 // If it's not a constant expression, it'll generate a fixup and be
975 // handled later.
976 if (!CE) return true;
977 int64_t Value = CE->getValue();
978 return Value >= 0 && Value < 65536;
979 }
Jim Grosbachf1637842011-07-26 16:24:27 +0000980 bool isImm24bit() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000981 if (!isImm()) return false;
Jim Grosbachf1637842011-07-26 16:24:27 +0000982 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
983 if (!CE) return false;
984 int64_t Value = CE->getValue();
985 return Value >= 0 && Value <= 0xffffff;
986 }
Jim Grosbach46dd4132011-08-17 21:51:27 +0000987 bool isImmThumbSR() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000988 if (!isImm()) return false;
Jim Grosbach46dd4132011-08-17 21:51:27 +0000989 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
990 if (!CE) return false;
991 int64_t Value = CE->getValue();
992 return Value > 0 && Value < 33;
993 }
Jim Grosbach27c1e252011-07-21 17:23:04 +0000994 bool isPKHLSLImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +0000995 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +0000996 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
997 if (!CE) return false;
998 int64_t Value = CE->getValue();
999 return Value >= 0 && Value < 32;
1000 }
1001 bool isPKHASRImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001002 if (!isImm()) return false;
Jim Grosbach27c1e252011-07-21 17:23:04 +00001003 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1004 if (!CE) return false;
1005 int64_t Value = CE->getValue();
1006 return Value > 0 && Value <= 32;
1007 }
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001008 bool isAdrLabel() const {
1009 // If we have an immediate that's not a constant, treat it as a label
1010 // reference needing a fixup. If it is a constant, but it can't fit
1011 // into shift immediate encoding, we reject it.
1012 if (isImm() && !isa<MCConstantExpr>(getImm())) return true;
1013 else return (isARMSOImm() || isARMSOImmNeg());
1014 }
Jim Grosbach9720dcf2011-07-19 16:50:30 +00001015 bool isARMSOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001016 if (!isImm()) return false;
Jim Grosbach9720dcf2011-07-19 16:50:30 +00001017 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1018 if (!CE) return false;
1019 int64_t Value = CE->getValue();
1020 return ARM_AM::getSOImmVal(Value) != -1;
1021 }
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001022 bool isARMSOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001023 if (!isImm()) return false;
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001024 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1025 if (!CE) return false;
1026 int64_t Value = CE->getValue();
1027 return ARM_AM::getSOImmVal(~Value) != -1;
1028 }
Jim Grosbach30506252011-12-08 00:31:07 +00001029 bool isARMSOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001030 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +00001031 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1032 if (!CE) return false;
1033 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +00001034 // Only use this when not representable as a plain so_imm.
1035 return ARM_AM::getSOImmVal(Value) == -1 &&
1036 ARM_AM::getSOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +00001037 }
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +00001038 bool isT2SOImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001039 if (!isImm()) return false;
Jim Grosbacha6f7a1e2011-06-27 23:54:06 +00001040 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1041 if (!CE) return false;
1042 int64_t Value = CE->getValue();
1043 return ARM_AM::getT2SOImmVal(Value) != -1;
1044 }
Jim Grosbachb009a872011-10-28 22:36:30 +00001045 bool isT2SOImmNot() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001046 if (!isImm()) return false;
Jim Grosbachb009a872011-10-28 22:36:30 +00001047 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1048 if (!CE) return false;
1049 int64_t Value = CE->getValue();
Mihai Popacf276b22013-08-16 11:55:44 +00001050 return ARM_AM::getT2SOImmVal(Value) == -1 &&
1051 ARM_AM::getT2SOImmVal(~Value) != -1;
Jim Grosbachb009a872011-10-28 22:36:30 +00001052 }
Jim Grosbach30506252011-12-08 00:31:07 +00001053 bool isT2SOImmNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001054 if (!isImm()) return false;
Jim Grosbach30506252011-12-08 00:31:07 +00001055 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1056 if (!CE) return false;
1057 int64_t Value = CE->getValue();
Jim Grosbachfdaab532012-03-30 19:59:02 +00001058 // Only use this when not representable as a plain so_imm.
1059 return ARM_AM::getT2SOImmVal(Value) == -1 &&
1060 ARM_AM::getT2SOImmVal(-Value) != -1;
Jim Grosbach30506252011-12-08 00:31:07 +00001061 }
Jim Grosbach0a547702011-07-22 17:44:50 +00001062 bool isSetEndImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001063 if (!isImm()) return false;
Jim Grosbach0a547702011-07-22 17:44:50 +00001064 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1065 if (!CE) return false;
1066 int64_t Value = CE->getValue();
1067 return Value == 1 || Value == 0;
1068 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001069 bool isReg() const { return Kind == k_Register; }
1070 bool isRegList() const { return Kind == k_RegisterList; }
1071 bool isDPRRegList() const { return Kind == k_DPRRegisterList; }
1072 bool isSPRRegList() const { return Kind == k_SPRRegisterList; }
1073 bool isToken() const { return Kind == k_Token; }
1074 bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; }
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00001075 bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; }
Chad Rosier41099832012-09-11 23:02:35 +00001076 bool isMem() const { return Kind == k_Memory; }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001077 bool isShifterImm() const { return Kind == k_ShifterImmediate; }
1078 bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; }
1079 bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; }
1080 bool isRotImm() const { return Kind == k_RotateImmediate; }
1081 bool isBitfield() const { return Kind == k_BitfieldDescriptor; }
1082 bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; }
Jim Grosbachc320c852011-08-05 21:28:30 +00001083 bool isPostIdxReg() const {
Jim Grosbachee201fa2011-11-14 17:52:47 +00001084 return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift;
Jim Grosbachc320c852011-08-05 21:28:30 +00001085 }
Jim Grosbacha95ec992011-10-11 17:29:55 +00001086 bool isMemNoOffset(bool alignOK = false) const {
Chad Rosier41099832012-09-11 23:02:35 +00001087 if (!isMem())
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001088 return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001089 // No offset of any kind.
Jim Grosbacha95ec992011-10-11 17:29:55 +00001090 return Memory.OffsetRegNum == 0 && Memory.OffsetImm == 0 &&
1091 (alignOK || Memory.Alignment == 0);
1092 }
Jim Grosbach94298a92012-01-18 22:46:46 +00001093 bool isMemPCRelImm12() const {
Chad Rosier41099832012-09-11 23:02:35 +00001094 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach94298a92012-01-18 22:46:46 +00001095 return false;
1096 // Base register must be PC.
1097 if (Memory.BaseRegNum != ARM::PC)
1098 return false;
1099 // Immediate offset in range [-4095, 4095].
1100 if (!Memory.OffsetImm) return true;
1101 int64_t Val = Memory.OffsetImm->getValue();
1102 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
1103 }
Jim Grosbacha95ec992011-10-11 17:29:55 +00001104 bool isAlignedMemory() const {
1105 return isMemNoOffset(true);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001106 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001107 bool isAddrMode2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001108 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001109 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001110 if (Memory.OffsetRegNum) return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00001111 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001112 if (!Memory.OffsetImm) return true;
1113 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbachd3595712011-08-03 23:50:40 +00001114 return Val > -4096 && Val < 4096;
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00001115 }
Jim Grosbachcd17c122011-08-04 23:01:30 +00001116 bool isAM2OffsetImm() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001117 if (!isImm()) return false;
Jim Grosbachcd17c122011-08-04 23:01:30 +00001118 // Immediate offset in range [-4095, 4095].
1119 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1120 if (!CE) return false;
1121 int64_t Val = CE->getValue();
Mihai Popac1d119e2013-06-11 09:48:35 +00001122 return (Val == INT32_MIN) || (Val > -4096 && Val < 4096);
Jim Grosbachcd17c122011-08-04 23:01:30 +00001123 }
Jim Grosbach5b96b802011-08-10 20:29:19 +00001124 bool isAddrMode3() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001125 // If we have an immediate that's not a constant, treat it as a label
1126 // reference needing a fixup. If it is a constant, it's something else
1127 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001128 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001129 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001130 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001131 // No shifts are legal for AM3.
Jim Grosbach871dff72011-10-11 15:59:20 +00001132 if (Memory.ShiftType != ARM_AM::no_shift) return false;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001133 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001134 if (Memory.OffsetRegNum) return true;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001135 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001136 if (!Memory.OffsetImm) return true;
1137 int64_t Val = Memory.OffsetImm->getValue();
Silviu Baranga5a719f92012-05-11 09:10:54 +00001138 // The #-0 offset is encoded as INT32_MIN, and we have to check
1139 // for this too.
1140 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001141 }
1142 bool isAM3Offset() const {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001143 if (Kind != k_Immediate && Kind != k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001144 return false;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001145 if (Kind == k_PostIndexRegister)
Jim Grosbach5b96b802011-08-10 20:29:19 +00001146 return PostIdxReg.ShiftTy == ARM_AM::no_shift;
1147 // Immediate offset in range [-255, 255].
1148 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1149 if (!CE) return false;
1150 int64_t Val = CE->getValue();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001151 // Special case, #-0 is INT32_MIN.
1152 return (Val > -256 && Val < 256) || Val == INT32_MIN;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001153 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001154 bool isAddrMode5() const {
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001155 // If we have an immediate that's not a constant, treat it as a label
1156 // reference needing a fixup. If it is a constant, it's something else
1157 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001158 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001159 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001160 if (!isMem() || Memory.Alignment != 0) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001161 // Check for register offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00001162 if (Memory.OffsetRegNum) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001163 // Immediate offset in range [-1020, 1020] and a multiple of 4.
Jim Grosbach871dff72011-10-11 15:59:20 +00001164 if (!Memory.OffsetImm) return true;
1165 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001166 return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) ||
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00001167 Val == INT32_MIN;
Bill Wendling8d2aa032010-11-08 23:49:57 +00001168 }
Jim Grosbach05541f42011-09-19 22:21:13 +00001169 bool isMemTBB() const {
Chad Rosier41099832012-09-11 23:02:35 +00001170 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001171 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Jim Grosbach05541f42011-09-19 22:21:13 +00001172 return false;
1173 return true;
1174 }
1175 bool isMemTBH() const {
Chad Rosier41099832012-09-11 23:02:35 +00001176 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001177 Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 ||
1178 Memory.Alignment != 0 )
Jim Grosbach05541f42011-09-19 22:21:13 +00001179 return false;
1180 return true;
1181 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001182 bool isMemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001183 if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0)
Bill Wendling092a7bd2010-12-14 03:36:38 +00001184 return false;
Daniel Dunbar7ed45592011-01-18 05:34:11 +00001185 return true;
Bill Wendling092a7bd2010-12-14 03:36:38 +00001186 }
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001187 bool isT2MemRegOffset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001188 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001189 Memory.Alignment != 0)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001190 return false;
1191 // Only lsl #{0, 1, 2, 3} allowed.
Jim Grosbach871dff72011-10-11 15:59:20 +00001192 if (Memory.ShiftType == ARM_AM::no_shift)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001193 return true;
Jim Grosbach871dff72011-10-11 15:59:20 +00001194 if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3)
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00001195 return false;
1196 return true;
1197 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001198 bool isMemThumbRR() const {
1199 // Thumb reg+reg addressing is simple. Just two registers, a base and
1200 // an offset. No shifts, negations or any other complicating factors.
Chad Rosier41099832012-09-11 23:02:35 +00001201 if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001202 Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0)
Bill Wendling811c9362010-11-30 07:44:32 +00001203 return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001204 return isARMLowRegister(Memory.BaseRegNum) &&
1205 (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001206 }
1207 bool isMemThumbRIs4() const {
Chad Rosier41099832012-09-11 23:02:35 +00001208 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001209 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach3fe94e32011-08-19 17:55:24 +00001210 return false;
1211 // Immediate offset, multiple of 4 in range [0, 124].
Jim Grosbach871dff72011-10-11 15:59:20 +00001212 if (!Memory.OffsetImm) return true;
1213 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001214 return Val >= 0 && Val <= 124 && (Val % 4) == 0;
1215 }
Jim Grosbach26d35872011-08-19 18:55:51 +00001216 bool isMemThumbRIs2() const {
Chad Rosier41099832012-09-11 23:02:35 +00001217 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001218 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbach26d35872011-08-19 18:55:51 +00001219 return false;
1220 // Immediate offset, multiple of 4 in range [0, 62].
Jim Grosbach871dff72011-10-11 15:59:20 +00001221 if (!Memory.OffsetImm) return true;
1222 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach26d35872011-08-19 18:55:51 +00001223 return Val >= 0 && Val <= 62 && (Val % 2) == 0;
1224 }
Jim Grosbacha32c7532011-08-19 18:49:59 +00001225 bool isMemThumbRIs1() const {
Chad Rosier41099832012-09-11 23:02:35 +00001226 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001227 !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0)
Jim Grosbacha32c7532011-08-19 18:49:59 +00001228 return false;
1229 // Immediate offset in range [0, 31].
Jim Grosbach871dff72011-10-11 15:59:20 +00001230 if (!Memory.OffsetImm) return true;
1231 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha32c7532011-08-19 18:49:59 +00001232 return Val >= 0 && Val <= 31;
1233 }
Jim Grosbach23983d62011-08-19 18:13:48 +00001234 bool isMemThumbSPI() const {
Chad Rosier41099832012-09-11 23:02:35 +00001235 if (!isMem() || Memory.OffsetRegNum != 0 ||
Jim Grosbacha95ec992011-10-11 17:29:55 +00001236 Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0)
Jim Grosbach23983d62011-08-19 18:13:48 +00001237 return false;
1238 // Immediate offset, multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001239 if (!Memory.OffsetImm) return true;
1240 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach23983d62011-08-19 18:13:48 +00001241 return Val >= 0 && Val <= 1020 && (Val % 4) == 0;
Bill Wendling811c9362010-11-30 07:44:32 +00001242 }
Jim Grosbach7db8d692011-09-08 22:07:06 +00001243 bool isMemImm8s4Offset() const {
Jim Grosbach8648c102011-12-19 23:06:24 +00001244 // If we have an immediate that's not a constant, treat it as a label
1245 // reference needing a fixup. If it is a constant, it's something else
1246 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001247 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach8648c102011-12-19 23:06:24 +00001248 return true;
Chad Rosier41099832012-09-11 23:02:35 +00001249 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach7db8d692011-09-08 22:07:06 +00001250 return false;
1251 // Immediate offset a multiple of 4 in range [-1020, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001252 if (!Memory.OffsetImm) return true;
1253 int64_t Val = Memory.OffsetImm->getValue();
Jiangning Liu6a43bf72012-08-02 08:29:50 +00001254 // Special case, #-0 is INT32_MIN.
1255 return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN;
Jim Grosbach7db8d692011-09-08 22:07:06 +00001256 }
Jim Grosbacha05627e2011-09-09 18:37:27 +00001257 bool isMemImm0_1020s4Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001258 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbacha05627e2011-09-09 18:37:27 +00001259 return false;
1260 // Immediate offset a multiple of 4 in range [0, 1020].
Jim Grosbach871dff72011-10-11 15:59:20 +00001261 if (!Memory.OffsetImm) return true;
1262 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbacha05627e2011-09-09 18:37:27 +00001263 return Val >= 0 && Val <= 1020 && (Val & 3) == 0;
1264 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001265 bool isMemImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001266 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001267 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001268 // Base reg of PC isn't allowed for these encodings.
1269 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001270 // Immediate offset in range [-255, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001271 if (!Memory.OffsetImm) return true;
1272 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson49168402011-09-23 22:25:02 +00001273 return (Val == INT32_MIN) || (Val > -256 && Val < 256);
Jim Grosbachd3595712011-08-03 23:50:40 +00001274 }
Jim Grosbach2392c532011-09-07 23:39:14 +00001275 bool isMemPosImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001276 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach2392c532011-09-07 23:39:14 +00001277 return false;
1278 // Immediate offset in range [0, 255].
Jim Grosbach871dff72011-10-11 15:59:20 +00001279 if (!Memory.OffsetImm) return true;
1280 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach2392c532011-09-07 23:39:14 +00001281 return Val >= 0 && Val < 256;
1282 }
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001283 bool isMemNegImm8Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001284 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001285 return false;
Jim Grosbach94298a92012-01-18 22:46:46 +00001286 // Base reg of PC isn't allowed for these encodings.
1287 if (Memory.BaseRegNum == ARM::PC) return false;
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001288 // Immediate offset in range [-255, -1].
Jim Grosbach175c7d02011-12-06 04:49:29 +00001289 if (!Memory.OffsetImm) return false;
Jim Grosbach871dff72011-10-11 15:59:20 +00001290 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach175c7d02011-12-06 04:49:29 +00001291 return (Val == INT32_MIN) || (Val > -256 && Val < 0);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001292 }
1293 bool isMemUImm12Offset() const {
Chad Rosier41099832012-09-11 23:02:35 +00001294 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001295 return false;
1296 // Immediate offset in range [0, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001297 if (!Memory.OffsetImm) return true;
1298 int64_t Val = Memory.OffsetImm->getValue();
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00001299 return (Val >= 0 && Val < 4096);
1300 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001301 bool isMemImm12Offset() const {
Jim Grosbach95466ce2011-08-08 20:59:31 +00001302 // If we have an immediate that's not a constant, treat it as a label
1303 // reference needing a fixup. If it is a constant, it's something else
1304 // and we reject it.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001305 if (isImm() && !isa<MCConstantExpr>(getImm()))
Jim Grosbach95466ce2011-08-08 20:59:31 +00001306 return true;
1307
Chad Rosier41099832012-09-11 23:02:35 +00001308 if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0)
Jim Grosbachd3595712011-08-03 23:50:40 +00001309 return false;
1310 // Immediate offset in range [-4095, 4095].
Jim Grosbach871dff72011-10-11 15:59:20 +00001311 if (!Memory.OffsetImm) return true;
1312 int64_t Val = Memory.OffsetImm->getValue();
Owen Anderson967674d2011-08-29 19:36:44 +00001313 return (Val > -4096 && Val < 4096) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001314 }
1315 bool isPostIdxImm8() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001316 if (!isImm()) return false;
Jim Grosbachd3595712011-08-03 23:50:40 +00001317 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1318 if (!CE) return false;
1319 int64_t Val = CE->getValue();
Owen Andersonf02d98d2011-08-29 17:17:09 +00001320 return (Val > -256 && Val < 256) || (Val == INT32_MIN);
Jim Grosbachd3595712011-08-03 23:50:40 +00001321 }
Jim Grosbach93981412011-10-11 21:55:36 +00001322 bool isPostIdxImm8s4() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001323 if (!isImm()) return false;
Jim Grosbach93981412011-10-11 21:55:36 +00001324 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1325 if (!CE) return false;
1326 int64_t Val = CE->getValue();
1327 return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) ||
1328 (Val == INT32_MIN);
1329 }
Jim Grosbachd3595712011-08-03 23:50:40 +00001330
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001331 bool isMSRMask() const { return Kind == k_MSRMask; }
1332 bool isProcIFlags() const { return Kind == k_ProcIFlags; }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001333
Jim Grosbach741cd732011-10-17 22:26:03 +00001334 // NEON operands.
Jim Grosbach2f50e922011-12-15 21:44:33 +00001335 bool isSingleSpacedVectorList() const {
1336 return Kind == k_VectorList && !VectorList.isDoubleSpaced;
1337 }
1338 bool isDoubleSpacedVectorList() const {
1339 return Kind == k_VectorList && VectorList.isDoubleSpaced;
1340 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001341 bool isVecListOneD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001342 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00001343 return VectorList.Count == 1;
1344 }
1345
Jim Grosbachc988e0c2012-03-05 19:33:30 +00001346 bool isVecListDPair() const {
1347 if (!isSingleSpacedVectorList()) return false;
1348 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1349 .contains(VectorList.RegNum));
1350 }
1351
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001352 bool isVecListThreeD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001353 if (!isSingleSpacedVectorList()) return false;
Jim Grosbachc4360fe2011-10-21 20:02:19 +00001354 return VectorList.Count == 3;
1355 }
1356
Jim Grosbach846bcff2011-10-21 20:35:01 +00001357 bool isVecListFourD() const {
Jim Grosbach2f50e922011-12-15 21:44:33 +00001358 if (!isSingleSpacedVectorList()) return false;
Jim Grosbach846bcff2011-10-21 20:35:01 +00001359 return VectorList.Count == 4;
1360 }
1361
Jim Grosbache5307f92012-03-05 21:43:40 +00001362 bool isVecListDPairSpaced() const {
Kevin Enderby816ca272012-03-20 17:41:51 +00001363 if (isSingleSpacedVectorList()) return false;
Jim Grosbache5307f92012-03-05 21:43:40 +00001364 return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID]
1365 .contains(VectorList.RegNum));
1366 }
1367
Jim Grosbachac2af3f2012-01-23 23:20:46 +00001368 bool isVecListThreeQ() const {
1369 if (!isDoubleSpacedVectorList()) return false;
1370 return VectorList.Count == 3;
1371 }
1372
Jim Grosbach1e946a42012-01-24 00:43:12 +00001373 bool isVecListFourQ() const {
1374 if (!isDoubleSpacedVectorList()) return false;
1375 return VectorList.Count == 4;
1376 }
1377
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001378 bool isSingleSpacedVectorAllLanes() const {
1379 return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced;
1380 }
1381 bool isDoubleSpacedVectorAllLanes() const {
1382 return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced;
1383 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001384 bool isVecListOneDAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001385 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00001386 return VectorList.Count == 1;
1387 }
1388
Jim Grosbach13a292c2012-03-06 22:01:44 +00001389 bool isVecListDPairAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001390 if (!isSingleSpacedVectorAllLanes()) return false;
Jim Grosbach13a292c2012-03-06 22:01:44 +00001391 return (ARMMCRegisterClasses[ARM::DPairRegClassID]
1392 .contains(VectorList.RegNum));
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001393 }
1394
Jim Grosbached428bc2012-03-06 23:10:38 +00001395 bool isVecListDPairSpacedAllLanes() const {
Jim Grosbachc5af54e2011-12-21 00:38:54 +00001396 if (!isDoubleSpacedVectorAllLanes()) return false;
Jim Grosbach3ecf9762011-11-30 18:21:25 +00001397 return VectorList.Count == 2;
1398 }
1399
Jim Grosbachb78403c2012-01-24 23:47:04 +00001400 bool isVecListThreeDAllLanes() const {
1401 if (!isSingleSpacedVectorAllLanes()) return false;
1402 return VectorList.Count == 3;
1403 }
1404
1405 bool isVecListThreeQAllLanes() const {
1406 if (!isDoubleSpacedVectorAllLanes()) return false;
1407 return VectorList.Count == 3;
1408 }
1409
Jim Grosbach086cbfa2012-01-25 00:01:08 +00001410 bool isVecListFourDAllLanes() const {
1411 if (!isSingleSpacedVectorAllLanes()) return false;
1412 return VectorList.Count == 4;
1413 }
1414
1415 bool isVecListFourQAllLanes() const {
1416 if (!isDoubleSpacedVectorAllLanes()) return false;
1417 return VectorList.Count == 4;
1418 }
1419
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001420 bool isSingleSpacedVectorIndexed() const {
1421 return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced;
1422 }
1423 bool isDoubleSpacedVectorIndexed() const {
1424 return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced;
1425 }
Jim Grosbach04945c42011-12-02 00:35:16 +00001426 bool isVecListOneDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001427 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbach04945c42011-12-02 00:35:16 +00001428 return VectorList.Count == 1 && VectorList.LaneIndex <= 7;
1429 }
1430
Jim Grosbachda511042011-12-14 23:35:06 +00001431 bool isVecListOneDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001432 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001433 return VectorList.Count == 1 && VectorList.LaneIndex <= 3;
1434 }
1435
1436 bool isVecListOneDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001437 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001438 return VectorList.Count == 1 && VectorList.LaneIndex <= 1;
1439 }
1440
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001441 bool isVecListTwoDByteIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001442 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00001443 return VectorList.Count == 2 && VectorList.LaneIndex <= 7;
1444 }
1445
Jim Grosbachda511042011-12-14 23:35:06 +00001446 bool isVecListTwoDHWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001447 if (!isSingleSpacedVectorIndexed()) return false;
1448 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1449 }
1450
1451 bool isVecListTwoQWordIndexed() const {
1452 if (!isDoubleSpacedVectorIndexed()) return false;
1453 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1454 }
1455
1456 bool isVecListTwoQHWordIndexed() const {
1457 if (!isDoubleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001458 return VectorList.Count == 2 && VectorList.LaneIndex <= 3;
1459 }
1460
1461 bool isVecListTwoDWordIndexed() const {
Jim Grosbach75e2ab52011-12-20 19:21:26 +00001462 if (!isSingleSpacedVectorIndexed()) return false;
Jim Grosbachda511042011-12-14 23:35:06 +00001463 return VectorList.Count == 2 && VectorList.LaneIndex <= 1;
1464 }
1465
Jim Grosbacha8b444b2012-01-23 21:53:26 +00001466 bool isVecListThreeDByteIndexed() const {
1467 if (!isSingleSpacedVectorIndexed()) return false;
1468 return VectorList.Count == 3 && VectorList.LaneIndex <= 7;
1469 }
1470
1471 bool isVecListThreeDHWordIndexed() const {
1472 if (!isSingleSpacedVectorIndexed()) return false;
1473 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1474 }
1475
1476 bool isVecListThreeQWordIndexed() const {
1477 if (!isDoubleSpacedVectorIndexed()) return false;
1478 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1479 }
1480
1481 bool isVecListThreeQHWordIndexed() const {
1482 if (!isDoubleSpacedVectorIndexed()) return false;
1483 return VectorList.Count == 3 && VectorList.LaneIndex <= 3;
1484 }
1485
1486 bool isVecListThreeDWordIndexed() const {
1487 if (!isSingleSpacedVectorIndexed()) return false;
1488 return VectorList.Count == 3 && VectorList.LaneIndex <= 1;
1489 }
1490
Jim Grosbach14952a02012-01-24 18:37:25 +00001491 bool isVecListFourDByteIndexed() const {
1492 if (!isSingleSpacedVectorIndexed()) return false;
1493 return VectorList.Count == 4 && VectorList.LaneIndex <= 7;
1494 }
1495
1496 bool isVecListFourDHWordIndexed() const {
1497 if (!isSingleSpacedVectorIndexed()) return false;
1498 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1499 }
1500
1501 bool isVecListFourQWordIndexed() const {
1502 if (!isDoubleSpacedVectorIndexed()) return false;
1503 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1504 }
1505
1506 bool isVecListFourQHWordIndexed() const {
1507 if (!isDoubleSpacedVectorIndexed()) return false;
1508 return VectorList.Count == 4 && VectorList.LaneIndex <= 3;
1509 }
1510
1511 bool isVecListFourDWordIndexed() const {
1512 if (!isSingleSpacedVectorIndexed()) return false;
1513 return VectorList.Count == 4 && VectorList.LaneIndex <= 1;
1514 }
1515
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001516 bool isVectorIndex8() const {
1517 if (Kind != k_VectorIndex) return false;
1518 return VectorIndex.Val < 8;
1519 }
1520 bool isVectorIndex16() const {
1521 if (Kind != k_VectorIndex) return false;
1522 return VectorIndex.Val < 4;
1523 }
1524 bool isVectorIndex32() const {
1525 if (Kind != k_VectorIndex) return false;
1526 return VectorIndex.Val < 2;
1527 }
1528
Jim Grosbach741cd732011-10-17 22:26:03 +00001529 bool isNEONi8splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001530 if (!isImm()) return false;
Jim Grosbach741cd732011-10-17 22:26:03 +00001531 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1532 // Must be a constant.
1533 if (!CE) return false;
1534 int64_t Value = CE->getValue();
1535 // i8 value splatted across 8 bytes. The immediate is just the 8 byte
1536 // value.
Jim Grosbach741cd732011-10-17 22:26:03 +00001537 return Value >= 0 && Value < 256;
1538 }
Jim Grosbachd0637bf2011-10-07 23:56:00 +00001539
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001540 bool isNEONi16splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001541 if (!isImm()) return false;
Jim Grosbachcda32ae2011-10-17 23:09:09 +00001542 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1543 // Must be a constant.
1544 if (!CE) return false;
1545 int64_t Value = CE->getValue();
1546 // i16 value in the range [0,255] or [0x0100, 0xff00]
1547 return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00);
1548 }
1549
Jim Grosbach8211c052011-10-18 00:22:00 +00001550 bool isNEONi32splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001551 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001552 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1553 // Must be a constant.
1554 if (!CE) return false;
1555 int64_t Value = CE->getValue();
1556 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X.
1557 return (Value >= 0 && Value < 256) ||
1558 (Value >= 0x0100 && Value <= 0xff00) ||
1559 (Value >= 0x010000 && Value <= 0xff0000) ||
1560 (Value >= 0x01000000 && Value <= 0xff000000);
1561 }
1562
1563 bool isNEONi32vmov() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001564 if (!isImm()) return false;
Jim Grosbach8211c052011-10-18 00:22:00 +00001565 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1566 // Must be a constant.
1567 if (!CE) return false;
1568 int64_t Value = CE->getValue();
1569 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1570 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1571 return (Value >= 0 && Value < 256) ||
1572 (Value >= 0x0100 && Value <= 0xff00) ||
1573 (Value >= 0x010000 && Value <= 0xff0000) ||
1574 (Value >= 0x01000000 && Value <= 0xff000000) ||
1575 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1576 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1577 }
Jim Grosbach045b6c72011-12-19 23:51:07 +00001578 bool isNEONi32vmovNeg() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001579 if (!isImm()) return false;
Jim Grosbach045b6c72011-12-19 23:51:07 +00001580 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1581 // Must be a constant.
1582 if (!CE) return false;
1583 int64_t Value = ~CE->getValue();
1584 // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X,
1585 // for VMOV/VMVN only, 00Xf or 0Xff are also accepted.
1586 return (Value >= 0 && Value < 256) ||
1587 (Value >= 0x0100 && Value <= 0xff00) ||
1588 (Value >= 0x010000 && Value <= 0xff0000) ||
1589 (Value >= 0x01000000 && Value <= 0xff000000) ||
1590 (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) ||
1591 (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff);
1592 }
Jim Grosbach8211c052011-10-18 00:22:00 +00001593
Jim Grosbache4454e02011-10-18 16:18:11 +00001594 bool isNEONi64splat() const {
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00001595 if (!isImm()) return false;
Jim Grosbache4454e02011-10-18 16:18:11 +00001596 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1597 // Must be a constant.
1598 if (!CE) return false;
1599 uint64_t Value = CE->getValue();
1600 // i64 value with each byte being either 0 or 0xff.
1601 for (unsigned i = 0; i < 8; ++i)
1602 if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false;
1603 return true;
1604 }
1605
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001606 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner5d6f6a02010-10-29 00:27:31 +00001607 // Add as immediates when possible. Null MCExpr = 0.
1608 if (Expr == 0)
1609 Inst.addOperand(MCOperand::CreateImm(0));
1610 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001611 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1612 else
1613 Inst.addOperand(MCOperand::CreateExpr(Expr));
1614 }
1615
Daniel Dunbard8042b72010-08-11 06:36:53 +00001616 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar188b47b2010-08-11 06:37:20 +00001617 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbard8042b72010-08-11 06:36:53 +00001618 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Jim Grosbach968c9272010-12-06 18:30:57 +00001619 unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR;
1620 Inst.addOperand(MCOperand::CreateReg(RegNum));
Daniel Dunbard8042b72010-08-11 06:36:53 +00001621 }
1622
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00001623 void addCoprocNumOperands(MCInst &Inst, unsigned N) const {
1624 assert(N == 1 && "Invalid number of operands!");
1625 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1626 }
1627
Jim Grosbach48399582011-10-12 17:34:41 +00001628 void addCoprocRegOperands(MCInst &Inst, unsigned N) const {
1629 assert(N == 1 && "Invalid number of operands!");
1630 Inst.addOperand(MCOperand::CreateImm(getCoproc()));
1631 }
1632
1633 void addCoprocOptionOperands(MCInst &Inst, unsigned N) const {
1634 assert(N == 1 && "Invalid number of operands!");
1635 Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val));
1636 }
1637
Jim Grosbach3d1eac82011-08-26 21:43:41 +00001638 void addITMaskOperands(MCInst &Inst, unsigned N) const {
1639 assert(N == 1 && "Invalid number of operands!");
1640 Inst.addOperand(MCOperand::CreateImm(ITMask.Mask));
1641 }
1642
1643 void addITCondCodeOperands(MCInst &Inst, unsigned N) const {
1644 assert(N == 1 && "Invalid number of operands!");
1645 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
1646 }
1647
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00001648 void addCCOutOperands(MCInst &Inst, unsigned N) const {
1649 assert(N == 1 && "Invalid number of operands!");
1650 Inst.addOperand(MCOperand::CreateReg(getReg()));
1651 }
1652
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00001653 void addRegOperands(MCInst &Inst, unsigned N) const {
1654 assert(N == 1 && "Invalid number of operands!");
1655 Inst.addOperand(MCOperand::CreateReg(getReg()));
1656 }
1657
Jim Grosbachac798e12011-07-25 20:49:51 +00001658 void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001659 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001660 assert(isRegShiftedReg() &&
Alp Tokerf907b892013-12-05 05:44:44 +00001661 "addRegShiftedRegOperands() on non-RegShiftedReg!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001662 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg));
1663 Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001664 Inst.addOperand(MCOperand::CreateImm(
Jim Grosbachac798e12011-07-25 20:49:51 +00001665 ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm)));
Jim Grosbach7dcd1352011-07-13 17:50:29 +00001666 }
1667
Jim Grosbachac798e12011-07-25 20:49:51 +00001668 void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson04912702011-07-21 23:38:37 +00001669 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00001670 assert(isRegShiftedImm() &&
Alp Tokerf907b892013-12-05 05:44:44 +00001671 "addRegShiftedImmOperands() on non-RegShiftedImm!");
Jim Grosbachac798e12011-07-25 20:49:51 +00001672 Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg));
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001673 // Shift of #32 is encoded as 0 where permitted
1674 unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm);
Owen Andersonb595ed02011-07-21 18:54:16 +00001675 Inst.addOperand(MCOperand::CreateImm(
Richard Bartonba5b0cc2012-04-25 18:00:18 +00001676 ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm)));
Owen Andersonb595ed02011-07-21 18:54:16 +00001677 }
1678
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001679 void addShifterImmOperands(MCInst &Inst, unsigned N) const {
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001680 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00001681 Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) |
1682 ShifterImm.Imm));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00001683 }
1684
Bill Wendling8d2aa032010-11-08 23:49:57 +00001685 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling2cae3272010-11-09 22:44:22 +00001686 assert(N == 1 && "Invalid number of operands!");
Bill Wendlingbed94652010-11-09 23:28:44 +00001687 const SmallVectorImpl<unsigned> &RegList = getRegList();
1688 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00001689 I = RegList.begin(), E = RegList.end(); I != E; ++I)
1690 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling8d2aa032010-11-08 23:49:57 +00001691 }
1692
Bill Wendling9898ac92010-11-17 04:32:08 +00001693 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
1694 addRegListOperands(Inst, N);
1695 }
1696
1697 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
1698 addRegListOperands(Inst, N);
1699 }
1700
Jim Grosbach833b9d32011-07-27 20:15:40 +00001701 void addRotImmOperands(MCInst &Inst, unsigned N) const {
1702 assert(N == 1 && "Invalid number of operands!");
1703 // Encoded as val>>3. The printer handles display as 8, 16, 24.
1704 Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3));
1705 }
1706
Jim Grosbach864b6092011-07-28 21:34:26 +00001707 void addBitfieldOperands(MCInst &Inst, unsigned N) const {
1708 assert(N == 1 && "Invalid number of operands!");
1709 // Munge the lsb/width into a bitfield mask.
1710 unsigned lsb = Bitfield.LSB;
1711 unsigned width = Bitfield.Width;
1712 // Make a 32-bit mask w/ the referenced bits clear and all other bits set.
1713 uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >>
1714 (32 - (lsb + width)));
1715 Inst.addOperand(MCOperand::CreateImm(Mask));
1716 }
1717
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00001718 void addImmOperands(MCInst &Inst, unsigned N) const {
1719 assert(N == 1 && "Invalid number of operands!");
1720 addExpr(Inst, getImm());
1721 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00001722
Jim Grosbachea231912011-12-22 22:19:05 +00001723 void addFBits16Operands(MCInst &Inst, unsigned N) const {
1724 assert(N == 1 && "Invalid number of operands!");
1725 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1726 Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue()));
1727 }
1728
1729 void addFBits32Operands(MCInst &Inst, unsigned N) const {
1730 assert(N == 1 && "Invalid number of operands!");
1731 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1732 Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue()));
1733 }
1734
Jim Grosbache7fbce72011-10-03 23:38:36 +00001735 void addFPImmOperands(MCInst &Inst, unsigned N) const {
1736 assert(N == 1 && "Invalid number of operands!");
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00001737 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1738 int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue()));
1739 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbache7fbce72011-10-03 23:38:36 +00001740 }
1741
Jim Grosbach7db8d692011-09-08 22:07:06 +00001742 void addImm8s4Operands(MCInst &Inst, unsigned N) const {
1743 assert(N == 1 && "Invalid number of operands!");
1744 // FIXME: We really want to scale the value here, but the LDRD/STRD
1745 // instruction don't encode operands that way yet.
1746 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1747 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1748 }
1749
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001750 void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const {
1751 assert(N == 1 && "Invalid number of operands!");
1752 // The immediate is scaled by four in the encoding and is stored
1753 // in the MCInst as such. Lop off the low two bits here.
1754 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1755 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1756 }
1757
Jim Grosbach930f2f62012-04-05 20:57:13 +00001758 void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const {
1759 assert(N == 1 && "Invalid number of operands!");
1760 // The immediate is scaled by four in the encoding and is stored
1761 // in the MCInst as such. Lop off the low two bits here.
1762 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1763 Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4)));
1764 }
1765
Jim Grosbach0a0b3072011-08-24 21:22:15 +00001766 void addImm0_508s4Operands(MCInst &Inst, unsigned N) const {
1767 assert(N == 1 && "Invalid number of operands!");
1768 // The immediate is scaled by four in the encoding and is stored
1769 // in the MCInst as such. Lop off the low two bits here.
1770 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1771 Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4));
1772 }
1773
Jim Grosbach475c6db2011-07-25 23:09:14 +00001774 void addImm1_16Operands(MCInst &Inst, unsigned N) const {
1775 assert(N == 1 && "Invalid number of operands!");
1776 // The constant encodes as the immediate-1, and we store in the instruction
1777 // the bits as encoded, so subtract off one here.
1778 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1779 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1780 }
1781
Jim Grosbach801e0a32011-07-22 23:16:18 +00001782 void addImm1_32Operands(MCInst &Inst, unsigned N) const {
1783 assert(N == 1 && "Invalid number of operands!");
1784 // The constant encodes as the immediate-1, and we store in the instruction
1785 // the bits as encoded, so subtract off one here.
1786 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1787 Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1));
1788 }
1789
Jim Grosbach46dd4132011-08-17 21:51:27 +00001790 void addImmThumbSROperands(MCInst &Inst, unsigned N) const {
1791 assert(N == 1 && "Invalid number of operands!");
1792 // The constant encodes as the immediate, except for 32, which encodes as
1793 // zero.
1794 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1795 unsigned Imm = CE->getValue();
1796 Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm)));
1797 }
1798
Jim Grosbach27c1e252011-07-21 17:23:04 +00001799 void addPKHASRImmOperands(MCInst &Inst, unsigned N) const {
1800 assert(N == 1 && "Invalid number of operands!");
1801 // An ASR value of 32 encodes as 0, so that's how we want to add it to
1802 // the instruction as well.
1803 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1804 int Val = CE->getValue();
1805 Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val));
1806 }
1807
Jim Grosbachb009a872011-10-28 22:36:30 +00001808 void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const {
1809 assert(N == 1 && "Invalid number of operands!");
1810 // The operand is actually a t2_so_imm, but we have its bitwise
1811 // negation in the assembly source, so twiddle it here.
1812 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1813 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1814 }
1815
Jim Grosbach30506252011-12-08 00:31:07 +00001816 void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const {
1817 assert(N == 1 && "Invalid number of operands!");
1818 // The operand is actually a t2_so_imm, but we have its
1819 // negation in the assembly source, so twiddle it here.
1820 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1821 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1822 }
1823
Jim Grosbach930f2f62012-04-05 20:57:13 +00001824 void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const {
1825 assert(N == 1 && "Invalid number of operands!");
1826 // The operand is actually an imm0_4095, but we have its
1827 // negation in the assembly source, so twiddle it here.
1828 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1829 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1830 }
1831
Mihai Popad36cbaa2013-07-03 09:21:44 +00001832 void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const {
1833 if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
1834 Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2));
1835 return;
1836 }
1837
1838 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1839 assert(SR && "Unknown value type!");
1840 Inst.addOperand(MCOperand::CreateExpr(SR));
1841 }
1842
Mihai Popa8a9da5b2013-07-22 15:49:36 +00001843 void addThumbMemPCOperands(MCInst &Inst, unsigned N) const {
1844 assert(N == 1 && "Invalid number of operands!");
1845 if (isImm()) {
1846 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1847 if (CE) {
1848 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
1849 return;
1850 }
1851
1852 const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val);
1853 assert(SR && "Unknown value type!");
1854 Inst.addOperand(MCOperand::CreateExpr(SR));
1855 return;
1856 }
1857
1858 assert(isMem() && "Unknown value type!");
1859 assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!");
1860 Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue()));
1861 }
1862
Jim Grosbach3d785ed2011-10-28 22:50:54 +00001863 void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const {
1864 assert(N == 1 && "Invalid number of operands!");
1865 // The operand is actually a so_imm, but we have its bitwise
1866 // negation in the assembly source, so twiddle it here.
1867 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1868 Inst.addOperand(MCOperand::CreateImm(~CE->getValue()));
1869 }
1870
Jim Grosbach30506252011-12-08 00:31:07 +00001871 void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const {
1872 assert(N == 1 && "Invalid number of operands!");
1873 // The operand is actually a so_imm, but we have its
1874 // negation in the assembly source, so twiddle it here.
1875 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1876 Inst.addOperand(MCOperand::CreateImm(-CE->getValue()));
1877 }
1878
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00001879 void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const {
1880 assert(N == 1 && "Invalid number of operands!");
1881 Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt())));
1882 }
1883
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00001884 void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const {
1885 assert(N == 1 && "Invalid number of operands!");
1886 Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt())));
1887 }
1888
Jim Grosbachd3595712011-08-03 23:50:40 +00001889 void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const {
1890 assert(N == 1 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001891 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Bruno Cardoso Lopesf170f8b2011-03-24 21:04:58 +00001892 }
1893
Jim Grosbach94298a92012-01-18 22:46:46 +00001894 void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const {
1895 assert(N == 1 && "Invalid number of operands!");
1896 int32_t Imm = Memory.OffsetImm->getValue();
Jim Grosbach94298a92012-01-18 22:46:46 +00001897 Inst.addOperand(MCOperand::CreateImm(Imm));
1898 }
1899
Jiangning Liu10dd40e2012-08-02 08:13:13 +00001900 void addAdrLabelOperands(MCInst &Inst, unsigned N) const {
1901 assert(N == 1 && "Invalid number of operands!");
1902 assert(isImm() && "Not an immediate!");
1903
1904 // If we have an immediate that's not a constant, treat it as a label
1905 // reference needing a fixup.
1906 if (!isa<MCConstantExpr>(getImm())) {
1907 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1908 return;
1909 }
1910
1911 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1912 int Val = CE->getValue();
1913 Inst.addOperand(MCOperand::CreateImm(Val));
1914 }
1915
Jim Grosbacha95ec992011-10-11 17:29:55 +00001916 void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const {
1917 assert(N == 2 && "Invalid number of operands!");
1918 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1919 Inst.addOperand(MCOperand::CreateImm(Memory.Alignment));
1920 }
1921
Jim Grosbachd3595712011-08-03 23:50:40 +00001922 void addAddrMode2Operands(MCInst &Inst, unsigned N) const {
1923 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00001924 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1925 if (!Memory.OffsetRegNum) {
Jim Grosbachd3595712011-08-03 23:50:40 +00001926 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1927 // Special case for #-0
1928 if (Val == INT32_MIN) Val = 0;
1929 if (Val < 0) Val = -Val;
1930 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1931 } else {
1932 // For register offset, we encode the shift type and negation flag
1933 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001934 Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
1935 Memory.ShiftImm, Memory.ShiftType);
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001936 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001937 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1938 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00001939 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesab830502011-03-31 23:26:08 +00001940 }
1941
Jim Grosbachcd17c122011-08-04 23:01:30 +00001942 void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const {
1943 assert(N == 2 && "Invalid number of operands!");
1944 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
1945 assert(CE && "non-constant AM2OffsetImm operand!");
1946 int32_t Val = CE->getValue();
1947 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1948 // Special case for #-0
1949 if (Val == INT32_MIN) Val = 0;
1950 if (Val < 0) Val = -Val;
1951 Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift);
1952 Inst.addOperand(MCOperand::CreateReg(0));
1953 Inst.addOperand(MCOperand::CreateImm(Val));
1954 }
1955
Jim Grosbach5b96b802011-08-10 20:29:19 +00001956 void addAddrMode3Operands(MCInst &Inst, unsigned N) const {
1957 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00001958 // If we have an immediate that's not a constant, treat it as a label
1959 // reference needing a fixup. If it is a constant, it's something else
1960 // and we reject it.
1961 if (isImm()) {
1962 Inst.addOperand(MCOperand::CreateExpr(getImm()));
1963 Inst.addOperand(MCOperand::CreateReg(0));
1964 Inst.addOperand(MCOperand::CreateImm(0));
1965 return;
1966 }
1967
Jim Grosbach871dff72011-10-11 15:59:20 +00001968 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
1969 if (!Memory.OffsetRegNum) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001970 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1971 // Special case for #-0
1972 if (Val == INT32_MIN) Val = 0;
1973 if (Val < 0) Val = -Val;
1974 Val = ARM_AM::getAM3Opc(AddSub, Val);
1975 } else {
1976 // For register offset, we encode the shift type and negation flag
1977 // here.
Jim Grosbach871dff72011-10-11 15:59:20 +00001978 Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0);
Jim Grosbach5b96b802011-08-10 20:29:19 +00001979 }
Jim Grosbach871dff72011-10-11 15:59:20 +00001980 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
1981 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach5b96b802011-08-10 20:29:19 +00001982 Inst.addOperand(MCOperand::CreateImm(Val));
1983 }
1984
1985 void addAM3OffsetOperands(MCInst &Inst, unsigned N) const {
1986 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00001987 if (Kind == k_PostIndexRegister) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00001988 int32_t Val =
1989 ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0);
1990 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
1991 Inst.addOperand(MCOperand::CreateImm(Val));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00001992 return;
Jim Grosbach5b96b802011-08-10 20:29:19 +00001993 }
1994
1995 // Constant offset.
1996 const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm());
1997 int32_t Val = CE->getValue();
1998 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
1999 // Special case for #-0
2000 if (Val == INT32_MIN) Val = 0;
2001 if (Val < 0) Val = -Val;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00002002 Val = ARM_AM::getAM3Opc(AddSub, Val);
Jim Grosbach5b96b802011-08-10 20:29:19 +00002003 Inst.addOperand(MCOperand::CreateReg(0));
2004 Inst.addOperand(MCOperand::CreateImm(Val));
2005 }
2006
Jim Grosbachd3595712011-08-03 23:50:40 +00002007 void addAddrMode5Operands(MCInst &Inst, unsigned N) const {
2008 assert(N == 2 && "Invalid number of operands!");
Jim Grosbachfb2f1d62011-11-01 01:24:45 +00002009 // If we have an immediate that's not a constant, treat it as a label
2010 // reference needing a fixup. If it is a constant, it's something else
2011 // and we reject it.
2012 if (isImm()) {
2013 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2014 Inst.addOperand(MCOperand::CreateImm(0));
2015 return;
2016 }
2017
Jim Grosbachd3595712011-08-03 23:50:40 +00002018 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00002019 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002020 ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add;
2021 // Special case for #-0
2022 if (Val == INT32_MIN) Val = 0;
2023 if (Val < 0) Val = -Val;
2024 Val = ARM_AM::getAM5Opc(AddSub, Val);
Jim Grosbach871dff72011-10-11 15:59:20 +00002025 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002026 Inst.addOperand(MCOperand::CreateImm(Val));
Bruno Cardoso Lopesbda36322011-04-04 17:18:19 +00002027 }
2028
Jim Grosbach7db8d692011-09-08 22:07:06 +00002029 void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const {
2030 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach8648c102011-12-19 23:06:24 +00002031 // If we have an immediate that's not a constant, treat it as a label
2032 // reference needing a fixup. If it is a constant, it's something else
2033 // and we reject it.
2034 if (isImm()) {
2035 Inst.addOperand(MCOperand::CreateExpr(getImm()));
2036 Inst.addOperand(MCOperand::CreateImm(0));
2037 return;
2038 }
2039
Jim Grosbach871dff72011-10-11 15:59:20 +00002040 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2041 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach7db8d692011-09-08 22:07:06 +00002042 Inst.addOperand(MCOperand::CreateImm(Val));
2043 }
2044
Jim Grosbacha05627e2011-09-09 18:37:27 +00002045 void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const {
2046 assert(N == 2 && "Invalid number of operands!");
2047 // The lower two bits are always zero and as such are not encoded.
Jim Grosbach871dff72011-10-11 15:59:20 +00002048 int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0;
2049 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha05627e2011-09-09 18:37:27 +00002050 Inst.addOperand(MCOperand::CreateImm(Val));
2051 }
2052
Jim Grosbachd3595712011-08-03 23:50:40 +00002053 void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2054 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002055 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2056 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002057 Inst.addOperand(MCOperand::CreateImm(Val));
Chris Lattner5d6f6a02010-10-29 00:27:31 +00002058 }
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002059
Jim Grosbach2392c532011-09-07 23:39:14 +00002060 void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const {
2061 addMemImm8OffsetOperands(Inst, N);
2062 }
2063
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002064 void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const {
Jim Grosbach2392c532011-09-07 23:39:14 +00002065 addMemImm8OffsetOperands(Inst, N);
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002066 }
2067
2068 void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2069 assert(N == 2 && "Invalid number of operands!");
2070 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00002071 if (isImm()) {
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002072 addExpr(Inst, getImm());
2073 Inst.addOperand(MCOperand::CreateImm(0));
2074 return;
2075 }
2076
2077 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00002078 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2079 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach5bfa8ba2011-09-07 20:58:57 +00002080 Inst.addOperand(MCOperand::CreateImm(Val));
2081 }
2082
Jim Grosbachd3595712011-08-03 23:50:40 +00002083 void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const {
2084 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach95466ce2011-08-08 20:59:31 +00002085 // If this is an immediate, it's a label reference.
Jim Grosbachc4d8d2f2011-12-22 22:02:35 +00002086 if (isImm()) {
Jim Grosbach95466ce2011-08-08 20:59:31 +00002087 addExpr(Inst, getImm());
2088 Inst.addOperand(MCOperand::CreateImm(0));
2089 return;
2090 }
2091
2092 // Otherwise, it's a normal memory reg+offset.
Jim Grosbach871dff72011-10-11 15:59:20 +00002093 int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0;
2094 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002095 Inst.addOperand(MCOperand::CreateImm(Val));
Bill Wendling092a7bd2010-12-14 03:36:38 +00002096 }
Bill Wendling811c9362010-11-30 07:44:32 +00002097
Jim Grosbach05541f42011-09-19 22:21:13 +00002098 void addMemTBBOperands(MCInst &Inst, unsigned N) const {
2099 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002100 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2101 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002102 }
2103
2104 void addMemTBHOperands(MCInst &Inst, unsigned N) const {
2105 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002106 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2107 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbach05541f42011-09-19 22:21:13 +00002108 }
2109
Jim Grosbachd3595712011-08-03 23:50:40 +00002110 void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2111 assert(N == 3 && "Invalid number of operands!");
Jim Grosbachee201fa2011-11-14 17:52:47 +00002112 unsigned Val =
2113 ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add,
2114 Memory.ShiftImm, Memory.ShiftType);
Jim Grosbach871dff72011-10-11 15:59:20 +00002115 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2116 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002117 Inst.addOperand(MCOperand::CreateImm(Val));
2118 }
2119
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002120 void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const {
2121 assert(N == 3 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002122 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2123 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
2124 Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm));
Jim Grosbache0ebc1c2011-09-07 23:10:15 +00002125 }
2126
Jim Grosbachd3595712011-08-03 23:50:40 +00002127 void addMemThumbRROperands(MCInst &Inst, unsigned N) const {
2128 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002129 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
2130 Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum));
Jim Grosbachd3595712011-08-03 23:50:40 +00002131 }
2132
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002133 void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const {
2134 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002135 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2136 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach3fe94e32011-08-19 17:55:24 +00002137 Inst.addOperand(MCOperand::CreateImm(Val));
2138 }
2139
Jim Grosbach26d35872011-08-19 18:55:51 +00002140 void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const {
2141 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002142 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0;
2143 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach26d35872011-08-19 18:55:51 +00002144 Inst.addOperand(MCOperand::CreateImm(Val));
2145 }
2146
Jim Grosbacha32c7532011-08-19 18:49:59 +00002147 void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const {
2148 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002149 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0;
2150 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbacha32c7532011-08-19 18:49:59 +00002151 Inst.addOperand(MCOperand::CreateImm(Val));
2152 }
2153
Jim Grosbach23983d62011-08-19 18:13:48 +00002154 void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const {
2155 assert(N == 2 && "Invalid number of operands!");
Jim Grosbach871dff72011-10-11 15:59:20 +00002156 int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0;
2157 Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum));
Jim Grosbach23983d62011-08-19 18:13:48 +00002158 Inst.addOperand(MCOperand::CreateImm(Val));
2159 }
2160
Jim Grosbachd3595712011-08-03 23:50:40 +00002161 void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const {
2162 assert(N == 1 && "Invalid number of operands!");
2163 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2164 assert(CE && "non-constant post-idx-imm8 operand!");
2165 int Imm = CE->getValue();
2166 bool isAdd = Imm >= 0;
Owen Andersonf02d98d2011-08-29 17:17:09 +00002167 if (Imm == INT32_MIN) Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00002168 Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8;
2169 Inst.addOperand(MCOperand::CreateImm(Imm));
2170 }
2171
Jim Grosbach93981412011-10-11 21:55:36 +00002172 void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const {
2173 assert(N == 1 && "Invalid number of operands!");
2174 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2175 assert(CE && "non-constant post-idx-imm8s4 operand!");
2176 int Imm = CE->getValue();
2177 bool isAdd = Imm >= 0;
2178 if (Imm == INT32_MIN) Imm = 0;
2179 // Immediate is scaled by 4.
2180 Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8;
2181 Inst.addOperand(MCOperand::CreateImm(Imm));
2182 }
2183
Jim Grosbachd3595712011-08-03 23:50:40 +00002184 void addPostIdxRegOperands(MCInst &Inst, unsigned N) const {
2185 assert(N == 2 && "Invalid number of operands!");
2186 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
Jim Grosbachc320c852011-08-05 21:28:30 +00002187 Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd));
2188 }
2189
2190 void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const {
2191 assert(N == 2 && "Invalid number of operands!");
2192 Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum));
2193 // The sign, shift type, and shift amount are encoded in a single operand
2194 // using the AM2 encoding helpers.
2195 ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub;
2196 unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm,
2197 PostIdxReg.ShiftTy);
2198 Inst.addOperand(MCOperand::CreateImm(Imm));
Bill Wendling811c9362010-11-30 07:44:32 +00002199 }
2200
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002201 void addMSRMaskOperands(MCInst &Inst, unsigned N) const {
2202 assert(N == 1 && "Invalid number of operands!");
2203 Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask())));
2204 }
2205
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002206 void addProcIFlagsOperands(MCInst &Inst, unsigned N) const {
2207 assert(N == 1 && "Invalid number of operands!");
2208 Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags())));
2209 }
2210
Jim Grosbach182b6a02011-11-29 23:51:09 +00002211 void addVecListOperands(MCInst &Inst, unsigned N) const {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002212 assert(N == 1 && "Invalid number of operands!");
2213 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2214 }
2215
Jim Grosbach04945c42011-12-02 00:35:16 +00002216 void addVecListIndexedOperands(MCInst &Inst, unsigned N) const {
2217 assert(N == 2 && "Invalid number of operands!");
2218 Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum));
2219 Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex));
2220 }
2221
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002222 void addVectorIndex8Operands(MCInst &Inst, unsigned N) const {
2223 assert(N == 1 && "Invalid number of operands!");
2224 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2225 }
2226
2227 void addVectorIndex16Operands(MCInst &Inst, unsigned N) const {
2228 assert(N == 1 && "Invalid number of operands!");
2229 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2230 }
2231
2232 void addVectorIndex32Operands(MCInst &Inst, unsigned N) const {
2233 assert(N == 1 && "Invalid number of operands!");
2234 Inst.addOperand(MCOperand::CreateImm(getVectorIndex()));
2235 }
2236
Jim Grosbach741cd732011-10-17 22:26:03 +00002237 void addNEONi8splatOperands(MCInst &Inst, unsigned N) const {
2238 assert(N == 1 && "Invalid number of operands!");
2239 // The immediate encodes the type of constant as well as the value.
2240 // Mask in that this is an i8 splat.
2241 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2242 Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00));
2243 }
2244
Jim Grosbachcda32ae2011-10-17 23:09:09 +00002245 void addNEONi16splatOperands(MCInst &Inst, unsigned N) const {
2246 assert(N == 1 && "Invalid number of operands!");
2247 // The immediate encodes the type of constant as well as the value.
2248 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2249 unsigned Value = CE->getValue();
2250 if (Value >= 256)
2251 Value = (Value >> 8) | 0xa00;
2252 else
2253 Value |= 0x800;
2254 Inst.addOperand(MCOperand::CreateImm(Value));
2255 }
2256
Jim Grosbach8211c052011-10-18 00:22:00 +00002257 void addNEONi32splatOperands(MCInst &Inst, unsigned N) const {
2258 assert(N == 1 && "Invalid number of operands!");
2259 // The immediate encodes the type of constant as well as the value.
2260 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2261 unsigned Value = CE->getValue();
2262 if (Value >= 256 && Value <= 0xff00)
2263 Value = (Value >> 8) | 0x200;
2264 else if (Value > 0xffff && Value <= 0xff0000)
2265 Value = (Value >> 16) | 0x400;
2266 else if (Value > 0xffffff)
2267 Value = (Value >> 24) | 0x600;
2268 Inst.addOperand(MCOperand::CreateImm(Value));
2269 }
2270
2271 void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const {
2272 assert(N == 1 && "Invalid number of operands!");
2273 // The immediate encodes the type of constant as well as the value.
2274 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2275 unsigned Value = CE->getValue();
2276 if (Value >= 256 && Value <= 0xffff)
2277 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2278 else if (Value > 0xffff && Value <= 0xffffff)
2279 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2280 else if (Value > 0xffffff)
2281 Value = (Value >> 24) | 0x600;
2282 Inst.addOperand(MCOperand::CreateImm(Value));
2283 }
2284
Jim Grosbach045b6c72011-12-19 23:51:07 +00002285 void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const {
2286 assert(N == 1 && "Invalid number of operands!");
2287 // The immediate encodes the type of constant as well as the value.
2288 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2289 unsigned Value = ~CE->getValue();
2290 if (Value >= 256 && Value <= 0xffff)
2291 Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200);
2292 else if (Value > 0xffff && Value <= 0xffffff)
2293 Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400);
2294 else if (Value > 0xffffff)
2295 Value = (Value >> 24) | 0x600;
2296 Inst.addOperand(MCOperand::CreateImm(Value));
2297 }
2298
Jim Grosbache4454e02011-10-18 16:18:11 +00002299 void addNEONi64splatOperands(MCInst &Inst, unsigned N) const {
2300 assert(N == 1 && "Invalid number of operands!");
2301 // The immediate encodes the type of constant as well as the value.
2302 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
2303 uint64_t Value = CE->getValue();
2304 unsigned Imm = 0;
2305 for (unsigned i = 0; i < 8; ++i, Value >>= 8) {
2306 Imm |= (Value & 1) << i;
2307 }
2308 Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00));
2309 }
2310
Jim Grosbach602aa902011-07-13 15:34:57 +00002311 virtual void print(raw_ostream &OS) const;
Daniel Dunbarebace222010-08-11 06:37:04 +00002312
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002313 static ARMOperand *CreateITMask(unsigned Mask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002314 ARMOperand *Op = new ARMOperand(k_ITCondMask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002315 Op->ITMask.Mask = Mask;
2316 Op->StartLoc = S;
2317 Op->EndLoc = S;
2318 return Op;
2319 }
2320
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002321 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002322 ARMOperand *Op = new ARMOperand(k_CondCode);
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002323 Op->CC.Val = CC;
2324 Op->StartLoc = S;
2325 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002326 return Op;
Daniel Dunbar188b47b2010-08-11 06:37:20 +00002327 }
2328
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002329 static ARMOperand *CreateCoprocNum(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002330 ARMOperand *Op = new ARMOperand(k_CoprocNum);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002331 Op->Cop.Val = CopVal;
2332 Op->StartLoc = S;
2333 Op->EndLoc = S;
2334 return Op;
2335 }
2336
2337 static ARMOperand *CreateCoprocReg(unsigned CopVal, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002338 ARMOperand *Op = new ARMOperand(k_CoprocReg);
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002339 Op->Cop.Val = CopVal;
2340 Op->StartLoc = S;
2341 Op->EndLoc = S;
2342 return Op;
2343 }
2344
Jim Grosbach48399582011-10-12 17:34:41 +00002345 static ARMOperand *CreateCoprocOption(unsigned Val, SMLoc S, SMLoc E) {
2346 ARMOperand *Op = new ARMOperand(k_CoprocOption);
2347 Op->Cop.Val = Val;
2348 Op->StartLoc = S;
2349 Op->EndLoc = E;
2350 return Op;
2351 }
2352
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002353 static ARMOperand *CreateCCOut(unsigned RegNum, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002354 ARMOperand *Op = new ARMOperand(k_CCOut);
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002355 Op->Reg.RegNum = RegNum;
2356 Op->StartLoc = S;
2357 Op->EndLoc = S;
2358 return Op;
2359 }
2360
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002361 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002362 ARMOperand *Op = new ARMOperand(k_Token);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002363 Op->Tok.Data = Str.data();
2364 Op->Tok.Length = Str.size();
2365 Op->StartLoc = S;
2366 Op->EndLoc = S;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002367 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002368 }
2369
Bill Wendling2063b842010-11-18 23:43:05 +00002370 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002371 ARMOperand *Op = new ARMOperand(k_Register);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002372 Op->Reg.RegNum = RegNum;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002373 Op->StartLoc = S;
2374 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002375 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002376 }
2377
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002378 static ARMOperand *CreateShiftedRegister(ARM_AM::ShiftOpc ShTy,
2379 unsigned SrcReg,
2380 unsigned ShiftReg,
2381 unsigned ShiftImm,
2382 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002383 ARMOperand *Op = new ARMOperand(k_ShiftedRegister);
Jim Grosbachac798e12011-07-25 20:49:51 +00002384 Op->RegShiftedReg.ShiftTy = ShTy;
2385 Op->RegShiftedReg.SrcReg = SrcReg;
2386 Op->RegShiftedReg.ShiftReg = ShiftReg;
2387 Op->RegShiftedReg.ShiftImm = ShiftImm;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002388 Op->StartLoc = S;
2389 Op->EndLoc = E;
2390 return Op;
2391 }
2392
Owen Andersonb595ed02011-07-21 18:54:16 +00002393 static ARMOperand *CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy,
2394 unsigned SrcReg,
2395 unsigned ShiftImm,
2396 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002397 ARMOperand *Op = new ARMOperand(k_ShiftedImmediate);
Jim Grosbachac798e12011-07-25 20:49:51 +00002398 Op->RegShiftedImm.ShiftTy = ShTy;
2399 Op->RegShiftedImm.SrcReg = SrcReg;
2400 Op->RegShiftedImm.ShiftImm = ShiftImm;
Owen Andersonb595ed02011-07-21 18:54:16 +00002401 Op->StartLoc = S;
2402 Op->EndLoc = E;
2403 return Op;
2404 }
2405
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002406 static ARMOperand *CreateShifterImm(bool isASR, unsigned Imm,
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002407 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002408 ARMOperand *Op = new ARMOperand(k_ShifterImmediate);
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002409 Op->ShifterImm.isASR = isASR;
2410 Op->ShifterImm.Imm = Imm;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002411 Op->StartLoc = S;
2412 Op->EndLoc = E;
2413 return Op;
2414 }
2415
Jim Grosbach833b9d32011-07-27 20:15:40 +00002416 static ARMOperand *CreateRotImm(unsigned Imm, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002417 ARMOperand *Op = new ARMOperand(k_RotateImmediate);
Jim Grosbach833b9d32011-07-27 20:15:40 +00002418 Op->RotImm.Imm = Imm;
2419 Op->StartLoc = S;
2420 Op->EndLoc = E;
2421 return Op;
2422 }
2423
Jim Grosbach864b6092011-07-28 21:34:26 +00002424 static ARMOperand *CreateBitfield(unsigned LSB, unsigned Width,
2425 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002426 ARMOperand *Op = new ARMOperand(k_BitfieldDescriptor);
Jim Grosbach864b6092011-07-28 21:34:26 +00002427 Op->Bitfield.LSB = LSB;
2428 Op->Bitfield.Width = Width;
2429 Op->StartLoc = S;
2430 Op->EndLoc = E;
2431 return Op;
2432 }
2433
Bill Wendling2cae3272010-11-09 22:44:22 +00002434 static ARMOperand *
Chad Rosierfa705ee2013-07-01 20:49:23 +00002435 CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned> > &Regs,
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002436 SMLoc StartLoc, SMLoc EndLoc) {
Chad Rosierfa705ee2013-07-01 20:49:23 +00002437 assert (Regs.size() > 0 && "RegList contains no registers?");
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002438 KindTy Kind = k_RegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002439
Chad Rosierfa705ee2013-07-01 20:49:23 +00002440 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002441 Kind = k_DPRRegisterList;
Jim Grosbach75461af2011-09-13 22:56:44 +00002442 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].
Chad Rosierfa705ee2013-07-01 20:49:23 +00002443 contains(Regs.front().second))
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002444 Kind = k_SPRRegisterList;
Bill Wendling9898ac92010-11-17 04:32:08 +00002445
Chad Rosierfa705ee2013-07-01 20:49:23 +00002446 // Sort based on the register encoding values.
2447 array_pod_sort(Regs.begin(), Regs.end());
2448
Bill Wendling9898ac92010-11-17 04:32:08 +00002449 ARMOperand *Op = new ARMOperand(Kind);
Chad Rosierfa705ee2013-07-01 20:49:23 +00002450 for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002451 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Chad Rosierfa705ee2013-07-01 20:49:23 +00002452 Op->Registers.push_back(I->second);
Matt Beaumont-Gay55c4cc72010-11-10 00:08:58 +00002453 Op->StartLoc = StartLoc;
2454 Op->EndLoc = EndLoc;
Bill Wendling7cef4472010-11-06 19:56:04 +00002455 return Op;
2456 }
2457
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002458 static ARMOperand *CreateVectorList(unsigned RegNum, unsigned Count,
Jim Grosbach2f50e922011-12-15 21:44:33 +00002459 bool isDoubleSpaced, SMLoc S, SMLoc E) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002460 ARMOperand *Op = new ARMOperand(k_VectorList);
2461 Op->VectorList.RegNum = RegNum;
2462 Op->VectorList.Count = Count;
Jim Grosbach2f50e922011-12-15 21:44:33 +00002463 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002464 Op->StartLoc = S;
2465 Op->EndLoc = E;
2466 return Op;
2467 }
2468
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002469 static ARMOperand *CreateVectorListAllLanes(unsigned RegNum, unsigned Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002470 bool isDoubleSpaced,
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002471 SMLoc S, SMLoc E) {
2472 ARMOperand *Op = new ARMOperand(k_VectorListAllLanes);
2473 Op->VectorList.RegNum = RegNum;
2474 Op->VectorList.Count = Count;
Jim Grosbachc5af54e2011-12-21 00:38:54 +00002475 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002476 Op->StartLoc = S;
2477 Op->EndLoc = E;
2478 return Op;
2479 }
2480
Jim Grosbach04945c42011-12-02 00:35:16 +00002481 static ARMOperand *CreateVectorListIndexed(unsigned RegNum, unsigned Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002482 unsigned Index,
2483 bool isDoubleSpaced,
2484 SMLoc S, SMLoc E) {
Jim Grosbach04945c42011-12-02 00:35:16 +00002485 ARMOperand *Op = new ARMOperand(k_VectorListIndexed);
2486 Op->VectorList.RegNum = RegNum;
2487 Op->VectorList.Count = Count;
2488 Op->VectorList.LaneIndex = Index;
Jim Grosbach75e2ab52011-12-20 19:21:26 +00002489 Op->VectorList.isDoubleSpaced = isDoubleSpaced;
Jim Grosbach04945c42011-12-02 00:35:16 +00002490 Op->StartLoc = S;
2491 Op->EndLoc = E;
2492 return Op;
2493 }
2494
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002495 static ARMOperand *CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E,
2496 MCContext &Ctx) {
2497 ARMOperand *Op = new ARMOperand(k_VectorIndex);
2498 Op->VectorIndex.Val = Idx;
2499 Op->StartLoc = S;
2500 Op->EndLoc = E;
2501 return Op;
2502 }
2503
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002504 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002505 ARMOperand *Op = new ARMOperand(k_Immediate);
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002506 Op->Imm.Val = Val;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002507 Op->StartLoc = S;
2508 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002509 return Op;
Kevin Enderbyf5079942009-10-13 22:19:02 +00002510 }
2511
Jim Grosbachd3595712011-08-03 23:50:40 +00002512 static ARMOperand *CreateMem(unsigned BaseRegNum,
2513 const MCConstantExpr *OffsetImm,
2514 unsigned OffsetRegNum,
2515 ARM_AM::ShiftOpc ShiftType,
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00002516 unsigned ShiftImm,
Jim Grosbacha95ec992011-10-11 17:29:55 +00002517 unsigned Alignment,
Jim Grosbachd3595712011-08-03 23:50:40 +00002518 bool isNegative,
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002519 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002520 ARMOperand *Op = new ARMOperand(k_Memory);
Jim Grosbach871dff72011-10-11 15:59:20 +00002521 Op->Memory.BaseRegNum = BaseRegNum;
2522 Op->Memory.OffsetImm = OffsetImm;
2523 Op->Memory.OffsetRegNum = OffsetRegNum;
2524 Op->Memory.ShiftType = ShiftType;
2525 Op->Memory.ShiftImm = ShiftImm;
Jim Grosbacha95ec992011-10-11 17:29:55 +00002526 Op->Memory.Alignment = Alignment;
Jim Grosbach871dff72011-10-11 15:59:20 +00002527 Op->Memory.isNegative = isNegative;
Jim Grosbachd3595712011-08-03 23:50:40 +00002528 Op->StartLoc = S;
2529 Op->EndLoc = E;
2530 return Op;
2531 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00002532
Jim Grosbachc320c852011-08-05 21:28:30 +00002533 static ARMOperand *CreatePostIdxReg(unsigned RegNum, bool isAdd,
2534 ARM_AM::ShiftOpc ShiftTy,
2535 unsigned ShiftImm,
Jim Grosbachd3595712011-08-03 23:50:40 +00002536 SMLoc S, SMLoc E) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002537 ARMOperand *Op = new ARMOperand(k_PostIndexRegister);
Jim Grosbachd3595712011-08-03 23:50:40 +00002538 Op->PostIdxReg.RegNum = RegNum;
Jim Grosbachc320c852011-08-05 21:28:30 +00002539 Op->PostIdxReg.isAdd = isAdd;
2540 Op->PostIdxReg.ShiftTy = ShiftTy;
2541 Op->PostIdxReg.ShiftImm = ShiftImm;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00002542 Op->StartLoc = S;
2543 Op->EndLoc = E;
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002544 return Op;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002545 }
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002546
2547 static ARMOperand *CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002548 ARMOperand *Op = new ARMOperand(k_MemBarrierOpt);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002549 Op->MBOpt.Val = Opt;
2550 Op->StartLoc = S;
2551 Op->EndLoc = S;
2552 return Op;
2553 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002554
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002555 static ARMOperand *CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt,
2556 SMLoc S) {
2557 ARMOperand *Op = new ARMOperand(k_InstSyncBarrierOpt);
2558 Op->ISBOpt.Val = Opt;
2559 Op->StartLoc = S;
2560 Op->EndLoc = S;
2561 return Op;
2562 }
2563
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002564 static ARMOperand *CreateProcIFlags(ARM_PROC::IFlags IFlags, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002565 ARMOperand *Op = new ARMOperand(k_ProcIFlags);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002566 Op->IFlags.Val = IFlags;
2567 Op->StartLoc = S;
2568 Op->EndLoc = S;
2569 return Op;
2570 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002571
2572 static ARMOperand *CreateMSRMask(unsigned MMask, SMLoc S) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002573 ARMOperand *Op = new ARMOperand(k_MSRMask);
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002574 Op->MMask.Val = MMask;
2575 Op->StartLoc = S;
2576 Op->EndLoc = S;
2577 return Op;
2578 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002579};
2580
2581} // end anonymous namespace.
2582
Jim Grosbach602aa902011-07-13 15:34:57 +00002583void ARMOperand::print(raw_ostream &OS) const {
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002584 switch (Kind) {
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002585 case k_CondCode:
Daniel Dunbar2be732a2011-01-10 15:26:21 +00002586 OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002587 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002588 case k_CCOut:
Jim Grosbach0bfb4d52010-12-06 18:21:12 +00002589 OS << "<ccout " << getReg() << ">";
2590 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002591 case k_ITCondMask: {
Craig Topper42b96d12012-05-24 04:11:15 +00002592 static const char *const MaskStr[] = {
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00002593 "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)",
2594 "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)"
2595 };
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002596 assert((ITMask.Mask & 0xf) == ITMask.Mask);
2597 OS << "<it-mask " << MaskStr[ITMask.Mask] << ">";
2598 break;
2599 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002600 case k_CoprocNum:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002601 OS << "<coprocessor number: " << getCoproc() << ">";
2602 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002603 case k_CoprocReg:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002604 OS << "<coprocessor register: " << getCoproc() << ">";
2605 break;
Jim Grosbach48399582011-10-12 17:34:41 +00002606 case k_CoprocOption:
2607 OS << "<coprocessor option: " << CoprocOption.Val << ">";
2608 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002609 case k_MSRMask:
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00002610 OS << "<mask: " << getMSRMask() << ">";
2611 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002612 case k_Immediate:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002613 getImm()->print(OS);
2614 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002615 case k_MemBarrierOpt:
Joey Gouly926d3f52013-09-05 15:35:24 +00002616 OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">";
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00002617 break;
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00002618 case k_InstSyncBarrierOpt:
2619 OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">";
2620 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002621 case k_Memory:
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002622 OS << "<memory "
Jim Grosbach871dff72011-10-11 15:59:20 +00002623 << " base:" << Memory.BaseRegNum;
Daniel Dunbarbcd8eb02011-01-18 05:55:21 +00002624 OS << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002625 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002626 case k_PostIndexRegister:
Jim Grosbachc320c852011-08-05 21:28:30 +00002627 OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-")
2628 << PostIdxReg.RegNum;
2629 if (PostIdxReg.ShiftTy != ARM_AM::no_shift)
2630 OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " "
2631 << PostIdxReg.ShiftImm;
2632 OS << ">";
Jim Grosbachd3595712011-08-03 23:50:40 +00002633 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002634 case k_ProcIFlags: {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00002635 OS << "<ARM_PROC::";
2636 unsigned IFlags = getProcIFlags();
2637 for (int i=2; i >= 0; --i)
2638 if (IFlags & (1 << i))
2639 OS << ARM_PROC::IFlagsToString(1 << i);
2640 OS << ">";
2641 break;
2642 }
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002643 case k_Register:
Bill Wendling2063b842010-11-18 23:43:05 +00002644 OS << "<register " << getReg() << ">";
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002645 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002646 case k_ShifterImmediate:
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00002647 OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl")
2648 << " #" << ShifterImm.Imm << ">";
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002649 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002650 case k_ShiftedRegister:
Owen Andersonb595ed02011-07-21 18:54:16 +00002651 OS << "<so_reg_reg "
Jim Grosbach01e04392011-11-16 21:46:50 +00002652 << RegShiftedReg.SrcReg << " "
2653 << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy)
2654 << " " << RegShiftedReg.ShiftReg << ">";
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002655 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002656 case k_ShiftedImmediate:
Owen Andersonb595ed02011-07-21 18:54:16 +00002657 OS << "<so_reg_imm "
Jim Grosbach01e04392011-11-16 21:46:50 +00002658 << RegShiftedImm.SrcReg << " "
2659 << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy)
2660 << " #" << RegShiftedImm.ShiftImm << ">";
Owen Andersonb595ed02011-07-21 18:54:16 +00002661 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002662 case k_RotateImmediate:
Jim Grosbach833b9d32011-07-27 20:15:40 +00002663 OS << "<ror " << " #" << (RotImm.Imm * 8) << ">";
2664 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002665 case k_BitfieldDescriptor:
Jim Grosbach864b6092011-07-28 21:34:26 +00002666 OS << "<bitfield " << "lsb: " << Bitfield.LSB
2667 << ", width: " << Bitfield.Width << ">";
2668 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002669 case k_RegisterList:
2670 case k_DPRRegisterList:
2671 case k_SPRRegisterList: {
Bill Wendling7cef4472010-11-06 19:56:04 +00002672 OS << "<register_list ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002673
Bill Wendlingbed94652010-11-09 23:28:44 +00002674 const SmallVectorImpl<unsigned> &RegList = getRegList();
2675 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling2cae3272010-11-09 22:44:22 +00002676 I = RegList.begin(), E = RegList.end(); I != E; ) {
2677 OS << *I;
2678 if (++I < E) OS << ", ";
Bill Wendling7cef4472010-11-06 19:56:04 +00002679 }
2680
2681 OS << ">";
2682 break;
2683 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00002684 case k_VectorList:
2685 OS << "<vector_list " << VectorList.Count << " * "
2686 << VectorList.RegNum << ">";
2687 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00002688 case k_VectorListAllLanes:
2689 OS << "<vector_list(all lanes) " << VectorList.Count << " * "
2690 << VectorList.RegNum << ">";
2691 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00002692 case k_VectorListIndexed:
2693 OS << "<vector_list(lane " << VectorList.LaneIndex << ") "
2694 << VectorList.Count << " * " << VectorList.RegNum << ">";
2695 break;
Jim Grosbach6e5778f2011-10-07 23:24:09 +00002696 case k_Token:
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002697 OS << "'" << getToken() << "'";
2698 break;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002699 case k_VectorIndex:
2700 OS << "<vectorindex " << getVectorIndex() << ">";
2701 break;
Daniel Dunbar4a863e62010-08-11 06:37:12 +00002702 }
2703}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00002704
2705/// @name Auto-generated Match Functions
2706/// {
2707
2708static unsigned MatchRegisterName(StringRef Name);
2709
2710/// }
2711
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002712bool ARMAsmParser::ParseRegister(unsigned &RegNo,
2713 SMLoc &StartLoc, SMLoc &EndLoc) {
Jim Grosbachab5830e2011-12-14 02:16:11 +00002714 StartLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002715 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002716 RegNo = tryParseRegister();
Roman Divacky36b1b472011-01-27 17:14:22 +00002717
2718 return (RegNo == (unsigned)-1);
2719}
2720
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002721/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattner44e5981c2010-10-30 04:09:10 +00002722/// and if it is a register name the token is eaten and the register number is
2723/// returned. Otherwise return -1.
2724///
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002725int ARMAsmParser::tryParseRegister() {
Chris Lattner44e5981c2010-10-30 04:09:10 +00002726 const AsmToken &Tok = Parser.getTok();
Jim Grosbachd3595712011-08-03 23:50:40 +00002727 if (Tok.isNot(AsmToken::Identifier)) return -1;
Jim Grosbach99710a82010-11-01 16:44:21 +00002728
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002729 std::string lowerCase = Tok.getString().lower();
Owen Andersona098d152011-01-13 22:50:36 +00002730 unsigned RegNum = MatchRegisterName(lowerCase);
2731 if (!RegNum) {
2732 RegNum = StringSwitch<unsigned>(lowerCase)
2733 .Case("r13", ARM::SP)
2734 .Case("r14", ARM::LR)
2735 .Case("r15", ARM::PC)
2736 .Case("ip", ARM::R12)
Jim Grosbach4edc7362011-12-08 19:27:38 +00002737 // Additional register name aliases for 'gas' compatibility.
2738 .Case("a1", ARM::R0)
2739 .Case("a2", ARM::R1)
2740 .Case("a3", ARM::R2)
2741 .Case("a4", ARM::R3)
2742 .Case("v1", ARM::R4)
2743 .Case("v2", ARM::R5)
2744 .Case("v3", ARM::R6)
2745 .Case("v4", ARM::R7)
2746 .Case("v5", ARM::R8)
2747 .Case("v6", ARM::R9)
2748 .Case("v7", ARM::R10)
2749 .Case("v8", ARM::R11)
2750 .Case("sb", ARM::R9)
2751 .Case("sl", ARM::R10)
2752 .Case("fp", ARM::R11)
Owen Andersona098d152011-01-13 22:50:36 +00002753 .Default(0);
2754 }
Jim Grosbachab5830e2011-12-14 02:16:11 +00002755 if (!RegNum) {
Jim Grosbachcd22e4a2011-12-20 23:11:00 +00002756 // Check for aliases registered via .req. Canonicalize to lower case.
2757 // That's more consistent since register names are case insensitive, and
2758 // it's how the original entry was passed in from MC/MCParser/AsmParser.
2759 StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase);
Jim Grosbachab5830e2011-12-14 02:16:11 +00002760 // If no match, return failure.
2761 if (Entry == RegisterReqs.end())
2762 return -1;
2763 Parser.Lex(); // Eat identifier token.
2764 return Entry->getValue();
2765 }
Bob Wilsonfb0bd042011-02-03 21:46:10 +00002766
Chris Lattner44e5981c2010-10-30 04:09:10 +00002767 Parser.Lex(); // Eat identifier token.
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002768
Chris Lattner44e5981c2010-10-30 04:09:10 +00002769 return RegNum;
2770}
Jim Grosbach99710a82010-11-01 16:44:21 +00002771
Jim Grosbachbb24c592011-07-13 18:49:30 +00002772// Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0.
2773// If a recoverable error occurs, return 1. If an irrecoverable error
2774// occurs, return -1. An irrecoverable error is one where tokens have been
2775// consumed in the process of trying to parse the shifter (i.e., when it is
2776// indeed a shifter operand, but malformed).
Jim Grosbach0d6022d2011-07-26 20:41:24 +00002777int ARMAsmParser::tryParseShiftRegister(
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002778 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2779 SMLoc S = Parser.getTok().getLoc();
2780 const AsmToken &Tok = Parser.getTok();
2781 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
2782
Benjamin Kramer20baffb2011-11-06 20:37:06 +00002783 std::string lowerCase = Tok.getString().lower();
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002784 ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase)
Jim Grosbach3b559ff2011-12-07 23:40:58 +00002785 .Case("asl", ARM_AM::lsl)
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002786 .Case("lsl", ARM_AM::lsl)
2787 .Case("lsr", ARM_AM::lsr)
2788 .Case("asr", ARM_AM::asr)
2789 .Case("ror", ARM_AM::ror)
2790 .Case("rrx", ARM_AM::rrx)
2791 .Default(ARM_AM::no_shift);
2792
2793 if (ShiftTy == ARM_AM::no_shift)
Jim Grosbachbb24c592011-07-13 18:49:30 +00002794 return 1;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002795
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002796 Parser.Lex(); // Eat the operator.
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002797
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002798 // The source register for the shift has already been added to the
2799 // operand list, so we need to pop it off and combine it into the shifted
2800 // register operand instead.
Benjamin Kramer1757e7a2011-07-14 18:41:22 +00002801 OwningPtr<ARMOperand> PrevOp((ARMOperand*)Operands.pop_back_val());
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002802 if (!PrevOp->isReg())
2803 return Error(PrevOp->getStartLoc(), "shift must be of a register");
2804 int SrcReg = PrevOp->getReg();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002805
2806 SMLoc EndLoc;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002807 int64_t Imm = 0;
2808 int ShiftReg = 0;
2809 if (ShiftTy == ARM_AM::rrx) {
2810 // RRX Doesn't have an explicit shift amount. The encoder expects
2811 // the shift register to be the same as the source register. Seems odd,
2812 // but OK.
2813 ShiftReg = SrcReg;
2814 } else {
2815 // Figure out if this is shifted by a constant or a register (for non-RRX).
Jim Grosbachef70e9b2011-12-09 22:25:03 +00002816 if (Parser.getTok().is(AsmToken::Hash) ||
2817 Parser.getTok().is(AsmToken::Dollar)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002818 Parser.Lex(); // Eat hash.
2819 SMLoc ImmLoc = Parser.getTok().getLoc();
2820 const MCExpr *ShiftExpr = 0;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002821 if (getParser().parseExpression(ShiftExpr, EndLoc)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002822 Error(ImmLoc, "invalid immediate shift value");
2823 return -1;
2824 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002825 // The expression must be evaluatable as an immediate.
2826 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr);
Jim Grosbachbb24c592011-07-13 18:49:30 +00002827 if (!CE) {
2828 Error(ImmLoc, "invalid immediate shift value");
2829 return -1;
2830 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002831 // Range check the immediate.
2832 // lsl, ror: 0 <= imm <= 31
2833 // lsr, asr: 0 <= imm <= 32
2834 Imm = CE->getValue();
2835 if (Imm < 0 ||
2836 ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) ||
2837 ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) {
Jim Grosbachbb24c592011-07-13 18:49:30 +00002838 Error(ImmLoc, "immediate shift value out of range");
2839 return -1;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002840 }
Jim Grosbach21488b82011-12-22 17:37:00 +00002841 // shift by zero is a nop. Always send it through as lsl.
2842 // ('as' compatibility)
2843 if (Imm == 0)
2844 ShiftTy = ARM_AM::lsl;
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002845 } else if (Parser.getTok().is(AsmToken::Identifier)) {
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002846 SMLoc L = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002847 EndLoc = Parser.getTok().getEndLoc();
2848 ShiftReg = tryParseRegister();
Jim Grosbachbb24c592011-07-13 18:49:30 +00002849 if (ShiftReg == -1) {
2850 Error (L, "expected immediate or register in shift operand");
2851 return -1;
2852 }
2853 } else {
2854 Error (Parser.getTok().getLoc(),
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002855 "expected immediate or register in shift operand");
Jim Grosbachbb24c592011-07-13 18:49:30 +00002856 return -1;
2857 }
Jim Grosbach7dcd1352011-07-13 17:50:29 +00002858 }
2859
Owen Andersonb595ed02011-07-21 18:54:16 +00002860 if (ShiftReg && ShiftTy != ARM_AM::rrx)
2861 Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg,
Jim Grosbachac798e12011-07-25 20:49:51 +00002862 ShiftReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002863 S, EndLoc));
Owen Andersonb595ed02011-07-21 18:54:16 +00002864 else
2865 Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002866 S, EndLoc));
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002867
Jim Grosbachbb24c592011-07-13 18:49:30 +00002868 return 0;
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00002869}
2870
2871
Bill Wendling2063b842010-11-18 23:43:05 +00002872/// Try to parse a register name. The token must be an Identifier when called.
2873/// If it's a register, an AsmOperand is created. Another AsmOperand is created
2874/// if there is a "writeback". 'true' if it's not a register.
Chris Lattnerbd7c9fa2010-10-28 17:20:03 +00002875///
Kevin Enderby8be42bd2009-10-30 22:55:57 +00002876/// TODO this is likely to change to allow different register types and or to
2877/// parse for a specific register type.
Bill Wendling2063b842010-11-18 23:43:05 +00002878bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002879tryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002880 const AsmToken &RegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00002881 int RegNo = tryParseRegister();
Bill Wendlinge18980a2010-11-06 22:36:58 +00002882 if (RegNo == -1)
Bill Wendling2063b842010-11-18 23:43:05 +00002883 return true;
Jim Grosbach99710a82010-11-01 16:44:21 +00002884
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002885 Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(),
2886 RegTok.getEndLoc()));
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002887
Chris Lattner44e5981c2010-10-30 04:09:10 +00002888 const AsmToken &ExclaimTok = Parser.getTok();
2889 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling2063b842010-11-18 23:43:05 +00002890 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
2891 ExclaimTok.getLoc()));
Chris Lattner44e5981c2010-10-30 04:09:10 +00002892 Parser.Lex(); // Eat exclaim token
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002893 return false;
2894 }
2895
2896 // Also check for an index operand. This is only legal for vector registers,
2897 // but that'll get caught OK in operand matching, so we don't need to
2898 // explicitly filter everything else out here.
2899 if (Parser.getTok().is(AsmToken::LBrac)) {
2900 SMLoc SIdx = Parser.getTok().getLoc();
2901 Parser.Lex(); // Eat left bracket token.
2902
2903 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00002904 if (getParser().parseExpression(ImmVal))
Jim Grosbacha2147ce2012-01-31 23:51:09 +00002905 return true;
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002906 const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal);
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002907 if (!MCE)
2908 return TokError("immediate value expected for vector index");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002909
Jim Grosbachc8f2b782012-01-26 15:56:45 +00002910 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002911 return Error(Parser.getTok().getLoc(), "']' expected");
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002912
Jordan Rosee8f1eae2013-01-07 19:00:49 +00002913 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbachd0637bf2011-10-07 23:56:00 +00002914 Parser.Lex(); // Eat right bracket token.
2915
2916 Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(),
2917 SIdx, E,
2918 getContext()));
Kevin Enderby2207e5f2009-10-07 18:01:35 +00002919 }
2920
Bill Wendling2063b842010-11-18 23:43:05 +00002921 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00002922}
2923
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002924/// MatchCoprocessorOperandName - Try to parse an coprocessor related
2925/// instruction with a symbolic operand name. Example: "p1", "p7", "c3",
2926/// "c5", ...
2927static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002928 // Use the same layout as the tablegen'erated register name matcher. Ugly,
2929 // but efficient.
2930 switch (Name.size()) {
David Blaikie46a9f012012-01-20 21:51:11 +00002931 default: return -1;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002932 case 2:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002933 if (Name[0] != CoprocOp)
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002934 return -1;
2935 switch (Name[1]) {
2936 default: return -1;
2937 case '0': return 0;
2938 case '1': return 1;
2939 case '2': return 2;
2940 case '3': return 3;
2941 case '4': return 4;
2942 case '5': return 5;
2943 case '6': return 6;
2944 case '7': return 7;
2945 case '8': return 8;
2946 case '9': return 9;
2947 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002948 case 3:
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00002949 if (Name[0] != CoprocOp || Name[1] != '1')
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002950 return -1;
2951 switch (Name[2]) {
2952 default: return -1;
Artyom Skrobov86534432013-11-08 09:16:31 +00002953 // p10 and p11 are invalid for coproc instructions (reserved for FP/NEON)
2954 case '0': return CoprocOp == 'p'? -1: 10;
2955 case '1': return CoprocOp == 'p'? -1: 11;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002956 case '2': return 12;
2957 case '3': return 13;
2958 case '4': return 14;
2959 case '5': return 15;
2960 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002961 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00002962}
2963
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002964/// parseITCondCode - Try to parse a condition code for an IT instruction.
2965ARMAsmParser::OperandMatchResultTy ARMAsmParser::
2966parseITCondCode(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
2967 SMLoc S = Parser.getTok().getLoc();
2968 const AsmToken &Tok = Parser.getTok();
2969 if (!Tok.is(AsmToken::Identifier))
2970 return MatchOperand_NoMatch;
Richard Barton82f95ea2012-04-27 17:34:01 +00002971 unsigned CC = StringSwitch<unsigned>(Tok.getString().lower())
Jim Grosbach3d1eac82011-08-26 21:43:41 +00002972 .Case("eq", ARMCC::EQ)
2973 .Case("ne", ARMCC::NE)
2974 .Case("hs", ARMCC::HS)
2975 .Case("cs", ARMCC::HS)
2976 .Case("lo", ARMCC::LO)
2977 .Case("cc", ARMCC::LO)
2978 .Case("mi", ARMCC::MI)
2979 .Case("pl", ARMCC::PL)
2980 .Case("vs", ARMCC::VS)
2981 .Case("vc", ARMCC::VC)
2982 .Case("hi", ARMCC::HI)
2983 .Case("ls", ARMCC::LS)
2984 .Case("ge", ARMCC::GE)
2985 .Case("lt", ARMCC::LT)
2986 .Case("gt", ARMCC::GT)
2987 .Case("le", ARMCC::LE)
2988 .Case("al", ARMCC::AL)
2989 .Default(~0U);
2990 if (CC == ~0U)
2991 return MatchOperand_NoMatch;
2992 Parser.Lex(); // Eat the token.
2993
2994 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S));
2995
2996 return MatchOperand_Success;
2997}
2998
Jim Grosbach2d6ef442011-07-25 20:14:50 +00002999/// parseCoprocNumOperand - Try to parse an coprocessor number operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003000/// token must be an Identifier when called, and if it is a coprocessor
3001/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003002ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003003parseCoprocNumOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003004 SMLoc S = Parser.getTok().getLoc();
3005 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00003006 if (Tok.isNot(AsmToken::Identifier))
3007 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003008
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003009 int Num = MatchCoprocessorOperandName(Tok.getString(), 'p');
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003010 if (Num == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00003011 return MatchOperand_NoMatch;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003012
3013 Parser.Lex(); // Eat identifier token.
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003014 Operands.push_back(ARMOperand::CreateCoprocNum(Num, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003015 return MatchOperand_Success;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003016}
3017
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003018/// parseCoprocRegOperand - Try to parse an coprocessor register operand. The
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003019/// token must be an Identifier when called, and if it is a coprocessor
3020/// number, the token is eaten and the operand is added to the operand list.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003021ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003022parseCoprocRegOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003023 SMLoc S = Parser.getTok().getLoc();
3024 const AsmToken &Tok = Parser.getTok();
Jim Grosbach54a20ed2011-10-12 20:54:17 +00003025 if (Tok.isNot(AsmToken::Identifier))
3026 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003027
3028 int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c');
3029 if (Reg == -1)
Jim Grosbach861e49c2011-02-12 01:34:40 +00003030 return MatchOperand_NoMatch;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00003031
3032 Parser.Lex(); // Eat identifier token.
3033 Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003034 return MatchOperand_Success;
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00003035}
3036
Jim Grosbach48399582011-10-12 17:34:41 +00003037/// parseCoprocOptionOperand - Try to parse an coprocessor option operand.
3038/// coproc_option : '{' imm0_255 '}'
3039ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3040parseCoprocOptionOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3041 SMLoc S = Parser.getTok().getLoc();
3042
3043 // If this isn't a '{', this isn't a coprocessor immediate operand.
3044 if (Parser.getTok().isNot(AsmToken::LCurly))
3045 return MatchOperand_NoMatch;
3046 Parser.Lex(); // Eat the '{'
3047
3048 const MCExpr *Expr;
3049 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003050 if (getParser().parseExpression(Expr)) {
Jim Grosbach48399582011-10-12 17:34:41 +00003051 Error(Loc, "illegal expression");
3052 return MatchOperand_ParseFail;
3053 }
3054 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
3055 if (!CE || CE->getValue() < 0 || CE->getValue() > 255) {
3056 Error(Loc, "coprocessor option must be an immediate in range [0, 255]");
3057 return MatchOperand_ParseFail;
3058 }
3059 int Val = CE->getValue();
3060
3061 // Check for and consume the closing '}'
3062 if (Parser.getTok().isNot(AsmToken::RCurly))
3063 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003064 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach48399582011-10-12 17:34:41 +00003065 Parser.Lex(); // Eat the '}'
3066
3067 Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E));
3068 return MatchOperand_Success;
3069}
3070
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003071// For register list parsing, we need to map from raw GPR register numbering
3072// to the enumeration values. The enumeration values aren't sorted by
3073// register number due to our using "sp", "lr" and "pc" as canonical names.
3074static unsigned getNextRegister(unsigned Reg) {
3075 // If this is a GPR, we need to do it manually, otherwise we can rely
3076 // on the sort ordering of the enumeration since the other reg-classes
3077 // are sane.
3078 if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3079 return Reg + 1;
3080 switch(Reg) {
Craig Toppere55c5562012-02-07 02:50:20 +00003081 default: llvm_unreachable("Invalid GPR number!");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003082 case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2;
3083 case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4;
3084 case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6;
3085 case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8;
3086 case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10;
3087 case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12;
3088 case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR;
3089 case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0;
3090 }
3091}
3092
Jim Grosbach85a23432011-11-11 21:27:40 +00003093// Return the low-subreg of a given Q register.
3094static unsigned getDRegFromQReg(unsigned QReg) {
3095 switch (QReg) {
3096 default: llvm_unreachable("expected a Q register!");
3097 case ARM::Q0: return ARM::D0;
3098 case ARM::Q1: return ARM::D2;
3099 case ARM::Q2: return ARM::D4;
3100 case ARM::Q3: return ARM::D6;
3101 case ARM::Q4: return ARM::D8;
3102 case ARM::Q5: return ARM::D10;
3103 case ARM::Q6: return ARM::D12;
3104 case ARM::Q7: return ARM::D14;
3105 case ARM::Q8: return ARM::D16;
Jim Grosbacha92a5d82011-11-15 21:01:30 +00003106 case ARM::Q9: return ARM::D18;
Jim Grosbach85a23432011-11-11 21:27:40 +00003107 case ARM::Q10: return ARM::D20;
3108 case ARM::Q11: return ARM::D22;
3109 case ARM::Q12: return ARM::D24;
3110 case ARM::Q13: return ARM::D26;
3111 case ARM::Q14: return ARM::D28;
3112 case ARM::Q15: return ARM::D30;
3113 }
3114}
3115
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003116/// Parse a register list.
Bill Wendling2063b842010-11-18 23:43:05 +00003117bool ARMAsmParser::
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00003118parseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan936b0d32010-01-19 21:44:56 +00003119 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00003120 "Token is not a Left Curly Brace");
Bill Wendlinge18980a2010-11-06 22:36:58 +00003121 SMLoc S = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003122 Parser.Lex(); // Eat '{' token.
3123 SMLoc RegLoc = Parser.getTok().getLoc();
Kevin Enderbya2b99102009-10-09 21:12:28 +00003124
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003125 // Check the first register in the list to see what register class
3126 // this is a list of.
3127 int Reg = tryParseRegister();
3128 if (Reg == -1)
3129 return Error(RegLoc, "register expected");
3130
Jim Grosbach85a23432011-11-11 21:27:40 +00003131 // The reglist instructions have at most 16 registers, so reserve
3132 // space for that many.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003133 int EReg = 0;
3134 SmallVector<std::pair<unsigned, unsigned>, 16> Registers;
Jim Grosbach85a23432011-11-11 21:27:40 +00003135
3136 // Allow Q regs and just interpret them as the two D sub-registers.
3137 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3138 Reg = getDRegFromQReg(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003139 EReg = MRI->getEncodingValue(Reg);
3140 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach85a23432011-11-11 21:27:40 +00003141 ++Reg;
3142 }
Benjamin Kramer0d6d0982011-10-22 16:50:00 +00003143 const MCRegisterClass *RC;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003144 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3145 RC = &ARMMCRegisterClasses[ARM::GPRRegClassID];
3146 else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg))
3147 RC = &ARMMCRegisterClasses[ARM::DPRRegClassID];
3148 else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg))
3149 RC = &ARMMCRegisterClasses[ARM::SPRRegClassID];
3150 else
3151 return Error(RegLoc, "invalid register in register list");
3152
Jim Grosbach85a23432011-11-11 21:27:40 +00003153 // Store the register.
Chad Rosierfa705ee2013-07-01 20:49:23 +00003154 EReg = MRI->getEncodingValue(Reg);
3155 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Kevin Enderbya2b99102009-10-09 21:12:28 +00003156
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003157 // This starts immediately after the first register token in the list,
3158 // so we can see either a comma or a minus (range separator) as a legal
3159 // next token.
3160 while (Parser.getTok().is(AsmToken::Comma) ||
3161 Parser.getTok().is(AsmToken::Minus)) {
3162 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbache891fe82011-11-15 23:19:15 +00003163 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003164 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003165 int EndReg = tryParseRegister();
3166 if (EndReg == -1)
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003167 return Error(AfterMinusLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003168 // Allow Q regs and just interpret them as the two D sub-registers.
3169 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3170 EndReg = getDRegFromQReg(EndReg) + 1;
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003171 // If the register is the same as the start reg, there's nothing
3172 // more to do.
3173 if (Reg == EndReg)
3174 continue;
3175 // The register must be in the same register class as the first.
3176 if (!RC->contains(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003177 return Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003178 // Ranges must go from low to high.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003179 if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003180 return Error(AfterMinusLoc, "bad range in register list");
Kevin Enderbya2b99102009-10-09 21:12:28 +00003181
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003182 // Add all the registers in the range to the register list.
3183 while (Reg != EndReg) {
3184 Reg = getNextRegister(Reg);
Chad Rosierfa705ee2013-07-01 20:49:23 +00003185 EReg = MRI->getEncodingValue(Reg);
3186 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003187 }
3188 continue;
3189 }
3190 Parser.Lex(); // Eat the comma.
3191 RegLoc = Parser.getTok().getLoc();
3192 int OldReg = Reg;
Jim Grosbach98bc7972011-12-08 21:34:20 +00003193 const AsmToken RegTok = Parser.getTok();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003194 Reg = tryParseRegister();
3195 if (Reg == -1)
Jim Grosbach3337e392011-09-12 23:36:42 +00003196 return Error(RegLoc, "register expected");
Jim Grosbach85a23432011-11-11 21:27:40 +00003197 // Allow Q regs and just interpret them as the two D sub-registers.
3198 bool isQReg = false;
3199 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3200 Reg = getDRegFromQReg(Reg);
3201 isQReg = true;
3202 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003203 // The register must be in the same register class as the first.
3204 if (!RC->contains(Reg))
3205 return Error(RegLoc, "invalid register in register list");
3206 // List must be monotonically increasing.
Eric Christopher6ac277c2012-08-09 22:10:21 +00003207 if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) {
Jim Grosbach905686a2012-03-16 20:48:38 +00003208 if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg))
3209 Warning(RegLoc, "register list not in ascending order");
3210 else
3211 return Error(RegLoc, "register list not in ascending order");
3212 }
Eric Christopher6ac277c2012-08-09 22:10:21 +00003213 if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) {
Jim Grosbach98bc7972011-12-08 21:34:20 +00003214 Warning(RegLoc, "duplicated register (" + RegTok.getString() +
3215 ") in register list");
3216 continue;
3217 }
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003218 // VFP register lists must also be contiguous.
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003219 if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] &&
3220 Reg != OldReg + 1)
3221 return Error(RegLoc, "non-contiguous register range");
Chad Rosierfa705ee2013-07-01 20:49:23 +00003222 EReg = MRI->getEncodingValue(Reg);
3223 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3224 if (isQReg) {
3225 EReg = MRI->getEncodingValue(++Reg);
3226 Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg));
3227 }
Bill Wendlinge18980a2010-11-06 22:36:58 +00003228 }
3229
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003230 if (Parser.getTok().isNot(AsmToken::RCurly))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003231 return Error(Parser.getTok().getLoc(), "'}' expected");
3232 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach3ac26b12011-09-14 18:08:35 +00003233 Parser.Lex(); // Eat '}' token.
3234
Jim Grosbach18bf3632011-12-13 21:48:29 +00003235 // Push the register list operand.
Bill Wendling2063b842010-11-18 23:43:05 +00003236 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
Jim Grosbach18bf3632011-12-13 21:48:29 +00003237
3238 // The ARM system instruction variants for LDM/STM have a '^' token here.
3239 if (Parser.getTok().is(AsmToken::Caret)) {
3240 Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc()));
3241 Parser.Lex(); // Eat '^' token.
3242 }
3243
Bill Wendling2063b842010-11-18 23:43:05 +00003244 return false;
Kevin Enderbya2b99102009-10-09 21:12:28 +00003245}
3246
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003247// Helper function to parse the lane index for vector lists.
3248ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003249parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) {
Jim Grosbach04945c42011-12-02 00:35:16 +00003250 Index = 0; // Always return a defined index value.
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003251 if (Parser.getTok().is(AsmToken::LBrac)) {
3252 Parser.Lex(); // Eat the '['.
3253 if (Parser.getTok().is(AsmToken::RBrac)) {
3254 // "Dn[]" is the 'all lanes' syntax.
3255 LaneKind = AllLanes;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003256 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003257 Parser.Lex(); // Eat the ']'.
3258 return MatchOperand_Success;
3259 }
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003260
3261 // There's an optional '#' token here. Normally there wouldn't be, but
3262 // inline assemble puts one in, and it's friendly to accept that.
3263 if (Parser.getTok().is(AsmToken::Hash))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003264 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach67e76ba2012-03-19 20:39:53 +00003265
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003266 const MCExpr *LaneIndex;
3267 SMLoc Loc = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003268 if (getParser().parseExpression(LaneIndex)) {
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003269 Error(Loc, "illegal expression");
3270 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003271 }
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003272 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex);
3273 if (!CE) {
3274 Error(Loc, "lane index must be empty or an integer");
3275 return MatchOperand_ParseFail;
3276 }
3277 if (Parser.getTok().isNot(AsmToken::RBrac)) {
3278 Error(Parser.getTok().getLoc(), "']' expected");
3279 return MatchOperand_ParseFail;
3280 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003281 EndLoc = Parser.getTok().getEndLoc();
Jim Grosbach7de7ab82011-12-21 01:19:23 +00003282 Parser.Lex(); // Eat the ']'.
3283 int64_t Val = CE->getValue();
3284
3285 // FIXME: Make this range check context sensitive for .8, .16, .32.
3286 if (Val < 0 || Val > 7) {
3287 Error(Parser.getTok().getLoc(), "lane index out of range");
3288 return MatchOperand_ParseFail;
3289 }
3290 Index = Val;
3291 LaneKind = IndexedLane;
3292 return MatchOperand_Success;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003293 }
3294 LaneKind = NoLanes;
3295 return MatchOperand_Success;
3296}
3297
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003298// parse a vector register list
3299ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3300parseVectorList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003301 VectorLaneTy LaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003302 unsigned LaneIndex;
Jim Grosbach8d579232011-11-15 21:45:55 +00003303 SMLoc S = Parser.getTok().getLoc();
3304 // As an extension (to match gas), support a plain D register or Q register
3305 // (without encosing curly braces) as a single or double entry list,
3306 // respectively.
3307 if (Parser.getTok().is(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003308 SMLoc E = Parser.getTok().getEndLoc();
Jim Grosbach8d579232011-11-15 21:45:55 +00003309 int Reg = tryParseRegister();
3310 if (Reg == -1)
3311 return MatchOperand_NoMatch;
Jim Grosbach8d579232011-11-15 21:45:55 +00003312 if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003313 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003314 if (Res != MatchOperand_Success)
3315 return Res;
3316 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003317 case NoLanes:
Jim Grosbach2f50e922011-12-15 21:44:33 +00003318 Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003319 break;
3320 case AllLanes:
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003321 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false,
3322 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003323 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003324 case IndexedLane:
3325 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003326 LaneIndex,
3327 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003328 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003329 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003330 return MatchOperand_Success;
3331 }
3332 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3333 Reg = getDRegFromQReg(Reg);
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003334 OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E);
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003335 if (Res != MatchOperand_Success)
3336 return Res;
3337 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003338 case NoLanes:
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003339 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
Jim Grosbach13a292c2012-03-06 22:01:44 +00003340 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003341 Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003342 break;
3343 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003344 Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0,
3345 &ARMMCRegisterClasses[ARM::DPairRegClassID]);
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003346 Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false,
3347 S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003348 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003349 case IndexedLane:
3350 Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003351 LaneIndex,
3352 false, S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003353 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003354 }
Jim Grosbach8d579232011-11-15 21:45:55 +00003355 return MatchOperand_Success;
3356 }
3357 Error(S, "vector register expected");
3358 return MatchOperand_ParseFail;
3359 }
3360
3361 if (Parser.getTok().isNot(AsmToken::LCurly))
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003362 return MatchOperand_NoMatch;
3363
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003364 Parser.Lex(); // Eat '{' token.
3365 SMLoc RegLoc = Parser.getTok().getLoc();
3366
3367 int Reg = tryParseRegister();
3368 if (Reg == -1) {
3369 Error(RegLoc, "register expected");
3370 return MatchOperand_ParseFail;
3371 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003372 unsigned Count = 1;
Jim Grosbachc2f16a32011-12-15 21:54:55 +00003373 int Spacing = 0;
Jim Grosbach080a4992011-10-28 00:06:50 +00003374 unsigned FirstReg = Reg;
3375 // The list is of D registers, but we also allow Q regs and just interpret
3376 // them as the two D sub-registers.
3377 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
3378 FirstReg = Reg = getDRegFromQReg(Reg);
Jim Grosbach2f50e922011-12-15 21:44:33 +00003379 Spacing = 1; // double-spacing requires explicit D registers, otherwise
3380 // it's ambiguous with four-register single spaced.
Jim Grosbach080a4992011-10-28 00:06:50 +00003381 ++Reg;
3382 ++Count;
3383 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003384
3385 SMLoc E;
3386 if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003387 return MatchOperand_ParseFail;
Jim Grosbach080a4992011-10-28 00:06:50 +00003388
Jim Grosbache891fe82011-11-15 23:19:15 +00003389 while (Parser.getTok().is(AsmToken::Comma) ||
3390 Parser.getTok().is(AsmToken::Minus)) {
3391 if (Parser.getTok().is(AsmToken::Minus)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003392 if (!Spacing)
3393 Spacing = 1; // Register range implies a single spaced list.
3394 else if (Spacing == 2) {
3395 Error(Parser.getTok().getLoc(),
3396 "sequential registers in double spaced list");
3397 return MatchOperand_ParseFail;
3398 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003399 Parser.Lex(); // Eat the minus.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003400 SMLoc AfterMinusLoc = Parser.getTok().getLoc();
Jim Grosbache891fe82011-11-15 23:19:15 +00003401 int EndReg = tryParseRegister();
3402 if (EndReg == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003403 Error(AfterMinusLoc, "register expected");
Jim Grosbache891fe82011-11-15 23:19:15 +00003404 return MatchOperand_ParseFail;
3405 }
3406 // Allow Q regs and just interpret them as the two D sub-registers.
3407 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg))
3408 EndReg = getDRegFromQReg(EndReg) + 1;
3409 // If the register is the same as the start reg, there's nothing
3410 // more to do.
3411 if (Reg == EndReg)
3412 continue;
3413 // The register must be in the same register class as the first.
3414 if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003415 Error(AfterMinusLoc, "invalid register in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003416 return MatchOperand_ParseFail;
3417 }
3418 // Ranges must go from low to high.
3419 if (Reg > EndReg) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003420 Error(AfterMinusLoc, "bad range in register list");
Jim Grosbache891fe82011-11-15 23:19:15 +00003421 return MatchOperand_ParseFail;
3422 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003423 // Parse the lane specifier if present.
3424 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003425 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003426 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3427 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003428 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003429 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003430 Error(AfterMinusLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003431 return MatchOperand_ParseFail;
3432 }
Jim Grosbache891fe82011-11-15 23:19:15 +00003433
3434 // Add all the registers in the range to the register list.
3435 Count += EndReg - Reg;
3436 Reg = EndReg;
3437 continue;
3438 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003439 Parser.Lex(); // Eat the comma.
3440 RegLoc = Parser.getTok().getLoc();
3441 int OldReg = Reg;
3442 Reg = tryParseRegister();
3443 if (Reg == -1) {
3444 Error(RegLoc, "register expected");
3445 return MatchOperand_ParseFail;
3446 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003447 // vector register lists must be contiguous.
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003448 // It's OK to use the enumeration values directly here rather, as the
3449 // VFP register classes have the enum sorted properly.
Jim Grosbach080a4992011-10-28 00:06:50 +00003450 //
3451 // The list is of D registers, but we also allow Q regs and just interpret
3452 // them as the two D sub-registers.
3453 if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) {
Jim Grosbach2f50e922011-12-15 21:44:33 +00003454 if (!Spacing)
3455 Spacing = 1; // Register range implies a single spaced list.
3456 else if (Spacing == 2) {
3457 Error(RegLoc,
3458 "invalid register in double-spaced list (must be 'D' register')");
3459 return MatchOperand_ParseFail;
3460 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003461 Reg = getDRegFromQReg(Reg);
3462 if (Reg != OldReg + 1) {
3463 Error(RegLoc, "non-contiguous register range");
3464 return MatchOperand_ParseFail;
3465 }
3466 ++Reg;
3467 Count += 2;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003468 // Parse the lane specifier if present.
3469 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003470 unsigned NextLaneIndex;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003471 SMLoc LaneLoc = Parser.getTok().getLoc();
3472 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) !=
3473 MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003474 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003475 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003476 Error(LaneLoc, "mismatched lane index in register list");
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003477 return MatchOperand_ParseFail;
3478 }
Jim Grosbach080a4992011-10-28 00:06:50 +00003479 continue;
3480 }
Jim Grosbach2f50e922011-12-15 21:44:33 +00003481 // Normal D register.
3482 // Figure out the register spacing (single or double) of the list if
3483 // we don't know it already.
3484 if (!Spacing)
3485 Spacing = 1 + (Reg == OldReg + 2);
3486
3487 // Just check that it's contiguous and keep going.
3488 if (Reg != OldReg + Spacing) {
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003489 Error(RegLoc, "non-contiguous register range");
3490 return MatchOperand_ParseFail;
3491 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003492 ++Count;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003493 // Parse the lane specifier if present.
3494 VectorLaneTy NextLaneKind;
Jim Grosbach04945c42011-12-02 00:35:16 +00003495 unsigned NextLaneIndex;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003496 SMLoc EndLoc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003497 if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success)
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003498 return MatchOperand_ParseFail;
Jim Grosbach04945c42011-12-02 00:35:16 +00003499 if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003500 Error(EndLoc, "mismatched lane index in register list");
3501 return MatchOperand_ParseFail;
3502 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003503 }
3504
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003505 if (Parser.getTok().isNot(AsmToken::RCurly)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003506 Error(Parser.getTok().getLoc(), "'}' expected");
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003507 return MatchOperand_ParseFail;
3508 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003509 E = Parser.getTok().getEndLoc();
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003510 Parser.Lex(); // Eat '}' token.
3511
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003512 switch (LaneKind) {
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003513 case NoLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003514 // Two-register operands have been converted to the
Jim Grosbache5307f92012-03-05 21:43:40 +00003515 // composite register classes.
3516 if (Count == 2) {
3517 const MCRegisterClass *RC = (Spacing == 1) ?
3518 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3519 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
3520 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3521 }
Jim Grosbachc988e0c2012-03-05 19:33:30 +00003522
Jim Grosbach2f50e922011-12-15 21:44:33 +00003523 Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count,
3524 (Spacing == 2), S, E));
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003525 break;
3526 case AllLanes:
Jim Grosbach13a292c2012-03-06 22:01:44 +00003527 // Two-register operands have been converted to the
3528 // composite register classes.
Jim Grosbached428bc2012-03-06 23:10:38 +00003529 if (Count == 2) {
3530 const MCRegisterClass *RC = (Spacing == 1) ?
3531 &ARMMCRegisterClasses[ARM::DPairRegClassID] :
3532 &ARMMCRegisterClasses[ARM::DPairSpcRegClassID];
Jim Grosbach13a292c2012-03-06 22:01:44 +00003533 FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC);
3534 }
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003535 Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count,
Jim Grosbachc5af54e2011-12-21 00:38:54 +00003536 (Spacing == 2),
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003537 S, E));
3538 break;
Jim Grosbach04945c42011-12-02 00:35:16 +00003539 case IndexedLane:
3540 Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count,
Jim Grosbach75e2ab52011-12-20 19:21:26 +00003541 LaneIndex,
3542 (Spacing == 2),
3543 S, E));
Jim Grosbach04945c42011-12-02 00:35:16 +00003544 break;
Jim Grosbachcd6f5e72011-11-30 01:09:44 +00003545 }
Jim Grosbachad47cfc2011-10-18 23:02:30 +00003546 return MatchOperand_Success;
3547}
3548
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003549/// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options.
Jim Grosbach861e49c2011-02-12 01:34:40 +00003550ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003551parseMemBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003552 SMLoc S = Parser.getTok().getLoc();
3553 const AsmToken &Tok = Parser.getTok();
Jiangning Liu288e1af2012-08-02 08:21:27 +00003554 unsigned Opt;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003555
Jiangning Liu288e1af2012-08-02 08:21:27 +00003556 if (Tok.is(AsmToken::Identifier)) {
3557 StringRef OptStr = Tok.getString();
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003558
Jiangning Liu288e1af2012-08-02 08:21:27 +00003559 Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower())
3560 .Case("sy", ARM_MB::SY)
3561 .Case("st", ARM_MB::ST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003562 .Case("ld", ARM_MB::LD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003563 .Case("sh", ARM_MB::ISH)
3564 .Case("ish", ARM_MB::ISH)
3565 .Case("shst", ARM_MB::ISHST)
3566 .Case("ishst", ARM_MB::ISHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003567 .Case("ishld", ARM_MB::ISHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003568 .Case("nsh", ARM_MB::NSH)
3569 .Case("un", ARM_MB::NSH)
3570 .Case("nshst", ARM_MB::NSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003571 .Case("nshld", ARM_MB::NSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003572 .Case("unst", ARM_MB::NSHST)
3573 .Case("osh", ARM_MB::OSH)
3574 .Case("oshst", ARM_MB::OSHST)
Joey Gouly926d3f52013-09-05 15:35:24 +00003575 .Case("oshld", ARM_MB::OSHLD)
Jiangning Liu288e1af2012-08-02 08:21:27 +00003576 .Default(~0U);
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003577
Joey Gouly926d3f52013-09-05 15:35:24 +00003578 // ishld, oshld, nshld and ld are only available from ARMv8.
3579 if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD ||
3580 Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD))
3581 Opt = ~0U;
3582
Jiangning Liu288e1af2012-08-02 08:21:27 +00003583 if (Opt == ~0U)
3584 return MatchOperand_NoMatch;
3585
3586 Parser.Lex(); // Eat identifier token.
3587 } else if (Tok.is(AsmToken::Hash) ||
3588 Tok.is(AsmToken::Dollar) ||
3589 Tok.is(AsmToken::Integer)) {
3590 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003591 Parser.Lex(); // Eat '#' or '$'.
Jiangning Liu288e1af2012-08-02 08:21:27 +00003592 SMLoc Loc = Parser.getTok().getLoc();
3593
3594 const MCExpr *MemBarrierID;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003595 if (getParser().parseExpression(MemBarrierID)) {
Jiangning Liu288e1af2012-08-02 08:21:27 +00003596 Error(Loc, "illegal expression");
3597 return MatchOperand_ParseFail;
3598 }
3599
3600 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID);
3601 if (!CE) {
3602 Error(Loc, "constant expression expected");
3603 return MatchOperand_ParseFail;
3604 }
3605
3606 int Val = CE->getValue();
3607 if (Val & ~0xf) {
3608 Error(Loc, "immediate value out of range");
3609 return MatchOperand_ParseFail;
3610 }
3611
3612 Opt = ARM_MB::RESERVED_0 + Val;
3613 } else
3614 return MatchOperand_ParseFail;
3615
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003616 Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S));
Jim Grosbach861e49c2011-02-12 01:34:40 +00003617 return MatchOperand_Success;
Bruno Cardoso Lopes36dd43f2011-02-07 22:09:15 +00003618}
3619
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003620/// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options.
3621ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3622parseInstSyncBarrierOptOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3623 SMLoc S = Parser.getTok().getLoc();
3624 const AsmToken &Tok = Parser.getTok();
3625 unsigned Opt;
3626
3627 if (Tok.is(AsmToken::Identifier)) {
3628 StringRef OptStr = Tok.getString();
3629
Benjamin Kramer3e9237a2013-11-09 22:48:13 +00003630 if (OptStr.equals_lower("sy"))
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003631 Opt = ARM_ISB::SY;
3632 else
3633 return MatchOperand_NoMatch;
3634
3635 Parser.Lex(); // Eat identifier token.
3636 } else if (Tok.is(AsmToken::Hash) ||
3637 Tok.is(AsmToken::Dollar) ||
3638 Tok.is(AsmToken::Integer)) {
3639 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00003640 Parser.Lex(); // Eat '#' or '$'.
Amaury de la Vieuville43cb13a2013-06-10 14:17:08 +00003641 SMLoc Loc = Parser.getTok().getLoc();
3642
3643 const MCExpr *ISBarrierID;
3644 if (getParser().parseExpression(ISBarrierID)) {
3645 Error(Loc, "illegal expression");
3646 return MatchOperand_ParseFail;
3647 }
3648
3649 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID);
3650 if (!CE) {
3651 Error(Loc, "constant expression expected");
3652 return MatchOperand_ParseFail;
3653 }
3654
3655 int Val = CE->getValue();
3656 if (Val & ~0xf) {
3657 Error(Loc, "immediate value out of range");
3658 return MatchOperand_ParseFail;
3659 }
3660
3661 Opt = ARM_ISB::RESERVED_0 + Val;
3662 } else
3663 return MatchOperand_ParseFail;
3664
3665 Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt(
3666 (ARM_ISB::InstSyncBOpt)Opt, S));
3667 return MatchOperand_Success;
3668}
3669
3670
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003671/// parseProcIFlagsOperand - Try to parse iflags from CPS instruction.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003672ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003673parseProcIFlagsOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003674 SMLoc S = Parser.getTok().getLoc();
3675 const AsmToken &Tok = Parser.getTok();
Richard Bartonb0ec3752012-06-14 10:48:04 +00003676 if (!Tok.is(AsmToken::Identifier))
3677 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003678 StringRef IFlagsStr = Tok.getString();
3679
Owen Anderson10c5b122011-10-05 17:16:40 +00003680 // An iflags string of "none" is interpreted to mean that none of the AIF
3681 // bits are set. Not a terribly useful instruction, but a valid encoding.
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003682 unsigned IFlags = 0;
Owen Anderson10c5b122011-10-05 17:16:40 +00003683 if (IFlagsStr != "none") {
3684 for (int i = 0, e = IFlagsStr.size(); i != e; ++i) {
3685 unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1))
3686 .Case("a", ARM_PROC::A)
3687 .Case("i", ARM_PROC::I)
3688 .Case("f", ARM_PROC::F)
3689 .Default(~0U);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003690
Owen Anderson10c5b122011-10-05 17:16:40 +00003691 // If some specific iflag is already set, it means that some letter is
3692 // present more than once, this is not acceptable.
3693 if (Flag == ~0U || (IFlags & Flag))
3694 return MatchOperand_NoMatch;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003695
Owen Anderson10c5b122011-10-05 17:16:40 +00003696 IFlags |= Flag;
3697 }
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00003698 }
3699
3700 Parser.Lex(); // Eat identifier token.
3701 Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S));
3702 return MatchOperand_Success;
3703}
3704
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003705/// parseMSRMaskOperand - Try to parse mask flags from MSR instruction.
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003706ARMAsmParser::OperandMatchResultTy ARMAsmParser::
Jim Grosbach2d6ef442011-07-25 20:14:50 +00003707parseMSRMaskOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003708 SMLoc S = Parser.getTok().getLoc();
3709 const AsmToken &Tok = Parser.getTok();
Craig Toppera004b0d2012-10-09 04:55:28 +00003710 if (!Tok.is(AsmToken::Identifier))
3711 return MatchOperand_NoMatch;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003712 StringRef Mask = Tok.getString();
3713
James Molloy21efa7d2011-09-28 14:21:38 +00003714 if (isMClass()) {
3715 // See ARMv6-M 10.1.1
Jim Grosbachd28888d2012-03-15 21:34:14 +00003716 std::string Name = Mask.lower();
3717 unsigned FlagsVal = StringSwitch<unsigned>(Name)
Kevin Enderbyf1b225d2012-05-17 22:18:01 +00003718 // Note: in the documentation:
3719 // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias
3720 // for MSR APSR_nzcvq.
3721 // but we do make it an alias here. This is so to get the "mask encoding"
3722 // bits correct on MSR APSR writes.
3723 //
3724 // FIXME: Note the 0xc00 "mask encoding" bits version of the registers
3725 // should really only be allowed when writing a special register. Note
3726 // they get dropped in the MRS instruction reading a special register as
3727 // the SYSm field is only 8 bits.
3728 //
3729 // FIXME: the _g and _nzcvqg versions are only allowed if the processor
3730 // includes the DSP extension but that is not checked.
3731 .Case("apsr", 0x800)
3732 .Case("apsr_nzcvq", 0x800)
3733 .Case("apsr_g", 0x400)
3734 .Case("apsr_nzcvqg", 0xc00)
3735 .Case("iapsr", 0x801)
3736 .Case("iapsr_nzcvq", 0x801)
3737 .Case("iapsr_g", 0x401)
3738 .Case("iapsr_nzcvqg", 0xc01)
3739 .Case("eapsr", 0x802)
3740 .Case("eapsr_nzcvq", 0x802)
3741 .Case("eapsr_g", 0x402)
3742 .Case("eapsr_nzcvqg", 0xc02)
3743 .Case("xpsr", 0x803)
3744 .Case("xpsr_nzcvq", 0x803)
3745 .Case("xpsr_g", 0x403)
3746 .Case("xpsr_nzcvqg", 0xc03)
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003747 .Case("ipsr", 0x805)
3748 .Case("epsr", 0x806)
3749 .Case("iepsr", 0x807)
3750 .Case("msp", 0x808)
3751 .Case("psp", 0x809)
3752 .Case("primask", 0x810)
3753 .Case("basepri", 0x811)
3754 .Case("basepri_max", 0x812)
3755 .Case("faultmask", 0x813)
3756 .Case("control", 0x814)
James Molloy21efa7d2011-09-28 14:21:38 +00003757 .Default(~0U);
Jim Grosbach3794d822011-12-22 17:17:10 +00003758
James Molloy21efa7d2011-09-28 14:21:38 +00003759 if (FlagsVal == ~0U)
3760 return MatchOperand_NoMatch;
3761
Kevin Enderby6c7279e2012-06-15 22:14:44 +00003762 if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813)
James Molloy21efa7d2011-09-28 14:21:38 +00003763 // basepri, basepri_max and faultmask only valid for V7m.
3764 return MatchOperand_NoMatch;
Jim Grosbach3794d822011-12-22 17:17:10 +00003765
James Molloy21efa7d2011-09-28 14:21:38 +00003766 Parser.Lex(); // Eat identifier token.
3767 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3768 return MatchOperand_Success;
3769 }
3770
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003771 // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf"
3772 size_t Start = 0, Next = Mask.find('_');
3773 StringRef Flags = "";
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003774 std::string SpecReg = Mask.slice(Start, Next).lower();
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003775 if (Next != StringRef::npos)
3776 Flags = Mask.slice(Next+1, Mask.size());
3777
3778 // FlagsVal contains the complete mask:
3779 // 3-0: Mask
3780 // 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3781 unsigned FlagsVal = 0;
3782
3783 if (SpecReg == "apsr") {
3784 FlagsVal = StringSwitch<unsigned>(Flags)
Jim Grosbachd25c2cd2011-07-19 22:45:10 +00003785 .Case("nzcvq", 0x8) // same as CPSR_f
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003786 .Case("g", 0x4) // same as CPSR_s
3787 .Case("nzcvqg", 0xc) // same as CPSR_fs
3788 .Default(~0U);
3789
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003790 if (FlagsVal == ~0U) {
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003791 if (!Flags.empty())
3792 return MatchOperand_NoMatch;
3793 else
Jim Grosbach0ecd3952011-09-14 20:03:46 +00003794 FlagsVal = 8; // No flag
Joerg Sonnenberger740467a2011-02-19 00:43:45 +00003795 }
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003796 } else if (SpecReg == "cpsr" || SpecReg == "spsr") {
Jim Grosbach3d00eec2012-04-05 03:17:53 +00003797 // cpsr_all is an alias for cpsr_fc, as is plain cpsr.
3798 if (Flags == "all" || Flags == "")
Bruno Cardoso Lopes54452132011-05-25 00:35:03 +00003799 Flags = "fc";
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003800 for (int i = 0, e = Flags.size(); i != e; ++i) {
3801 unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1))
3802 .Case("c", 1)
3803 .Case("x", 2)
3804 .Case("s", 4)
3805 .Case("f", 8)
3806 .Default(~0U);
3807
3808 // If some specific flag is already set, it means that some letter is
3809 // present more than once, this is not acceptable.
3810 if (FlagsVal == ~0U || (FlagsVal & Flag))
3811 return MatchOperand_NoMatch;
3812 FlagsVal |= Flag;
3813 }
3814 } else // No match for special register.
3815 return MatchOperand_NoMatch;
3816
Owen Anderson03a173e2011-10-21 18:43:28 +00003817 // Special register without flags is NOT equivalent to "fc" flags.
3818 // NOTE: This is a divergence from gas' behavior. Uncommenting the following
3819 // two lines would enable gas compatibility at the expense of breaking
3820 // round-tripping.
3821 //
3822 // if (!FlagsVal)
3823 // FlagsVal = 0x9;
Bruno Cardoso Lopes9cd43972011-02-18 19:45:59 +00003824
3825 // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1)
3826 if (SpecReg == "spsr")
3827 FlagsVal |= 16;
3828
3829 Parser.Lex(); // Eat identifier token.
3830 Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S));
3831 return MatchOperand_Success;
3832}
3833
Jim Grosbach27c1e252011-07-21 17:23:04 +00003834ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3835parsePKHImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands, StringRef Op,
3836 int Low, int High) {
3837 const AsmToken &Tok = Parser.getTok();
3838 if (Tok.isNot(AsmToken::Identifier)) {
3839 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3840 return MatchOperand_ParseFail;
3841 }
3842 StringRef ShiftName = Tok.getString();
Benjamin Kramer20baffb2011-11-06 20:37:06 +00003843 std::string LowerOp = Op.lower();
3844 std::string UpperOp = Op.upper();
Jim Grosbach27c1e252011-07-21 17:23:04 +00003845 if (ShiftName != LowerOp && ShiftName != UpperOp) {
3846 Error(Parser.getTok().getLoc(), Op + " operand expected.");
3847 return MatchOperand_ParseFail;
3848 }
3849 Parser.Lex(); // Eat shift type token.
3850
3851 // There must be a '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003852 if (Parser.getTok().isNot(AsmToken::Hash) &&
3853 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003854 Error(Parser.getTok().getLoc(), "'#' expected");
3855 return MatchOperand_ParseFail;
3856 }
3857 Parser.Lex(); // Eat hash token.
3858
3859 const MCExpr *ShiftAmount;
3860 SMLoc Loc = Parser.getTok().getLoc();
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003861 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003862 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jim Grosbach27c1e252011-07-21 17:23:04 +00003863 Error(Loc, "illegal expression");
3864 return MatchOperand_ParseFail;
3865 }
3866 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3867 if (!CE) {
3868 Error(Loc, "constant expression expected");
3869 return MatchOperand_ParseFail;
3870 }
3871 int Val = CE->getValue();
3872 if (Val < Low || Val > High) {
3873 Error(Loc, "immediate value out of range");
3874 return MatchOperand_ParseFail;
3875 }
3876
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003877 Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc));
Jim Grosbach27c1e252011-07-21 17:23:04 +00003878
3879 return MatchOperand_Success;
3880}
3881
Jim Grosbach0a547702011-07-22 17:44:50 +00003882ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3883parseSetEndImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3884 const AsmToken &Tok = Parser.getTok();
3885 SMLoc S = Tok.getLoc();
3886 if (Tok.isNot(AsmToken::Identifier)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003887 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003888 return MatchOperand_ParseFail;
3889 }
Tim Northover4d141442013-05-31 15:58:45 +00003890 int Val = StringSwitch<int>(Tok.getString().lower())
Jim Grosbach0a547702011-07-22 17:44:50 +00003891 .Case("be", 1)
3892 .Case("le", 0)
3893 .Default(-1);
3894 Parser.Lex(); // Eat the token.
3895
3896 if (Val == -1) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003897 Error(S, "'be' or 'le' operand expected");
Jim Grosbach0a547702011-07-22 17:44:50 +00003898 return MatchOperand_ParseFail;
3899 }
3900 Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val,
3901 getContext()),
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003902 S, Tok.getEndLoc()));
Jim Grosbach0a547702011-07-22 17:44:50 +00003903 return MatchOperand_Success;
3904}
3905
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003906/// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT
3907/// instructions. Legal values are:
3908/// lsl #n 'n' in [0,31]
3909/// asr #n 'n' in [1,32]
3910/// n == 32 encoded as n == 0.
3911ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3912parseShifterImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3913 const AsmToken &Tok = Parser.getTok();
3914 SMLoc S = Tok.getLoc();
3915 if (Tok.isNot(AsmToken::Identifier)) {
3916 Error(S, "shift operator 'asr' or 'lsl' expected");
3917 return MatchOperand_ParseFail;
3918 }
3919 StringRef ShiftName = Tok.getString();
3920 bool isASR;
3921 if (ShiftName == "lsl" || ShiftName == "LSL")
3922 isASR = false;
3923 else if (ShiftName == "asr" || ShiftName == "ASR")
3924 isASR = true;
3925 else {
3926 Error(S, "shift operator 'asr' or 'lsl' expected");
3927 return MatchOperand_ParseFail;
3928 }
3929 Parser.Lex(); // Eat the operator.
3930
3931 // A '#' and a shift amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003932 if (Parser.getTok().isNot(AsmToken::Hash) &&
3933 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003934 Error(Parser.getTok().getLoc(), "'#' expected");
3935 return MatchOperand_ParseFail;
3936 }
3937 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003938 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003939
3940 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003941 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00003942 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003943 Error(ExLoc, "malformed shift expression");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003944 return MatchOperand_ParseFail;
3945 }
3946 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
3947 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003948 Error(ExLoc, "shift amount must be an immediate");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003949 return MatchOperand_ParseFail;
3950 }
3951
3952 int64_t Val = CE->getValue();
3953 if (isASR) {
3954 // Shift amount must be in [1,32]
3955 if (Val < 1 || Val > 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003956 Error(ExLoc, "'asr' shift amount must be in range [1,32]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003957 return MatchOperand_ParseFail;
3958 }
Owen Andersonf01e2de2011-09-26 21:06:22 +00003959 // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode.
3960 if (isThumb() && Val == 32) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003961 Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode");
Owen Andersonf01e2de2011-09-26 21:06:22 +00003962 return MatchOperand_ParseFail;
3963 }
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003964 if (Val == 32) Val = 0;
3965 } else {
3966 // Shift amount must be in [1,32]
3967 if (Val < 0 || Val > 31) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003968 Error(ExLoc, "'lsr' shift amount must be in range [0,31]");
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003969 return MatchOperand_ParseFail;
3970 }
3971 }
3972
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003973 Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc));
Jim Grosbach3a9cbee2011-07-25 22:20:28 +00003974
3975 return MatchOperand_Success;
3976}
3977
Jim Grosbach833b9d32011-07-27 20:15:40 +00003978/// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family
3979/// of instructions. Legal values are:
3980/// ror #n 'n' in {0, 8, 16, 24}
3981ARMAsmParser::OperandMatchResultTy ARMAsmParser::
3982parseRotImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
3983 const AsmToken &Tok = Parser.getTok();
3984 SMLoc S = Tok.getLoc();
Jim Grosbach82213192011-09-19 20:29:33 +00003985 if (Tok.isNot(AsmToken::Identifier))
3986 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003987 StringRef ShiftName = Tok.getString();
Jim Grosbach82213192011-09-19 20:29:33 +00003988 if (ShiftName != "ror" && ShiftName != "ROR")
3989 return MatchOperand_NoMatch;
Jim Grosbach833b9d32011-07-27 20:15:40 +00003990 Parser.Lex(); // Eat the operator.
3991
3992 // A '#' and a rotate amount.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00003993 if (Parser.getTok().isNot(AsmToken::Hash) &&
3994 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach833b9d32011-07-27 20:15:40 +00003995 Error(Parser.getTok().getLoc(), "'#' expected");
3996 return MatchOperand_ParseFail;
3997 }
3998 Parser.Lex(); // Eat hash token.
Jordan Rosee8f1eae2013-01-07 19:00:49 +00003999 SMLoc ExLoc = Parser.getTok().getLoc();
Jim Grosbach833b9d32011-07-27 20:15:40 +00004000
4001 const MCExpr *ShiftAmount;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004002 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004003 if (getParser().parseExpression(ShiftAmount, EndLoc)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004004 Error(ExLoc, "malformed rotate expression");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004005 return MatchOperand_ParseFail;
4006 }
4007 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount);
4008 if (!CE) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004009 Error(ExLoc, "rotate amount must be an immediate");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004010 return MatchOperand_ParseFail;
4011 }
4012
4013 int64_t Val = CE->getValue();
4014 // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension)
4015 // normally, zero is represented in asm by omitting the rotate operand
4016 // entirely.
4017 if (Val != 8 && Val != 16 && Val != 24 && Val != 0) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004018 Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24");
Jim Grosbach833b9d32011-07-27 20:15:40 +00004019 return MatchOperand_ParseFail;
4020 }
4021
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004022 Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc));
Jim Grosbach833b9d32011-07-27 20:15:40 +00004023
4024 return MatchOperand_Success;
4025}
4026
Jim Grosbach864b6092011-07-28 21:34:26 +00004027ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4028parseBitfield(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4029 SMLoc S = Parser.getTok().getLoc();
4030 // The bitfield descriptor is really two operands, the LSB and the width.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004031 if (Parser.getTok().isNot(AsmToken::Hash) &&
4032 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004033 Error(Parser.getTok().getLoc(), "'#' expected");
4034 return MatchOperand_ParseFail;
4035 }
4036 Parser.Lex(); // Eat hash token.
4037
4038 const MCExpr *LSBExpr;
4039 SMLoc E = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004040 if (getParser().parseExpression(LSBExpr)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004041 Error(E, "malformed immediate expression");
4042 return MatchOperand_ParseFail;
4043 }
4044 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr);
4045 if (!CE) {
4046 Error(E, "'lsb' operand must be an immediate");
4047 return MatchOperand_ParseFail;
4048 }
4049
4050 int64_t LSB = CE->getValue();
4051 // The LSB must be in the range [0,31]
4052 if (LSB < 0 || LSB > 31) {
4053 Error(E, "'lsb' operand must be in the range [0,31]");
4054 return MatchOperand_ParseFail;
4055 }
4056 E = Parser.getTok().getLoc();
4057
4058 // Expect another immediate operand.
4059 if (Parser.getTok().isNot(AsmToken::Comma)) {
4060 Error(Parser.getTok().getLoc(), "too few operands");
4061 return MatchOperand_ParseFail;
4062 }
4063 Parser.Lex(); // Eat hash token.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004064 if (Parser.getTok().isNot(AsmToken::Hash) &&
4065 Parser.getTok().isNot(AsmToken::Dollar)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004066 Error(Parser.getTok().getLoc(), "'#' expected");
4067 return MatchOperand_ParseFail;
4068 }
4069 Parser.Lex(); // Eat hash token.
4070
4071 const MCExpr *WidthExpr;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004072 SMLoc EndLoc;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004073 if (getParser().parseExpression(WidthExpr, EndLoc)) {
Jim Grosbach864b6092011-07-28 21:34:26 +00004074 Error(E, "malformed immediate expression");
4075 return MatchOperand_ParseFail;
4076 }
4077 CE = dyn_cast<MCConstantExpr>(WidthExpr);
4078 if (!CE) {
4079 Error(E, "'width' operand must be an immediate");
4080 return MatchOperand_ParseFail;
4081 }
4082
4083 int64_t Width = CE->getValue();
4084 // The LSB must be in the range [1,32-lsb]
4085 if (Width < 1 || Width > 32 - LSB) {
4086 Error(E, "'width' operand must be in the range [1,32-lsb]");
4087 return MatchOperand_ParseFail;
4088 }
Jim Grosbach864b6092011-07-28 21:34:26 +00004089
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004090 Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc));
Jim Grosbach864b6092011-07-28 21:34:26 +00004091
4092 return MatchOperand_Success;
4093}
4094
Jim Grosbachd3595712011-08-03 23:50:40 +00004095ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4096parsePostIdxReg(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4097 // Check for a post-index addressing register operand. Specifically:
Jim Grosbachc320c852011-08-05 21:28:30 +00004098 // postidx_reg := '+' register {, shift}
4099 // | '-' register {, shift}
4100 // | register {, shift}
Jim Grosbachd3595712011-08-03 23:50:40 +00004101
4102 // This method must return MatchOperand_NoMatch without consuming any tokens
4103 // in the case where there is no match, as other alternatives take other
4104 // parse methods.
4105 AsmToken Tok = Parser.getTok();
4106 SMLoc S = Tok.getLoc();
4107 bool haveEaten = false;
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004108 bool isAdd = true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004109 if (Tok.is(AsmToken::Plus)) {
4110 Parser.Lex(); // Eat the '+' token.
4111 haveEaten = true;
4112 } else if (Tok.is(AsmToken::Minus)) {
4113 Parser.Lex(); // Eat the '-' token.
Jim Grosbacha70fbfd52011-08-05 16:11:38 +00004114 isAdd = false;
Jim Grosbachd3595712011-08-03 23:50:40 +00004115 haveEaten = true;
4116 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004117
4118 SMLoc E = Parser.getTok().getEndLoc();
4119 int Reg = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004120 if (Reg == -1) {
4121 if (!haveEaten)
4122 return MatchOperand_NoMatch;
4123 Error(Parser.getTok().getLoc(), "register expected");
4124 return MatchOperand_ParseFail;
4125 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004126
Jim Grosbachc320c852011-08-05 21:28:30 +00004127 ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift;
4128 unsigned ShiftImm = 0;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004129 if (Parser.getTok().is(AsmToken::Comma)) {
4130 Parser.Lex(); // Eat the ','.
4131 if (parseMemRegOffsetShift(ShiftTy, ShiftImm))
4132 return MatchOperand_ParseFail;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004133
4134 // FIXME: Only approximates end...may include intervening whitespace.
4135 E = Parser.getTok().getLoc();
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004136 }
Jim Grosbachc320c852011-08-05 21:28:30 +00004137
4138 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy,
4139 ShiftImm, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004140
4141 return MatchOperand_Success;
4142}
4143
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004144ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4145parseAM3Offset(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4146 // Check for a post-index addressing register operand. Specifically:
4147 // am3offset := '+' register
4148 // | '-' register
4149 // | register
4150 // | # imm
4151 // | # + imm
4152 // | # - imm
4153
4154 // This method must return MatchOperand_NoMatch without consuming any tokens
4155 // in the case where there is no match, as other alternatives take other
4156 // parse methods.
4157 AsmToken Tok = Parser.getTok();
4158 SMLoc S = Tok.getLoc();
4159
4160 // Do immediates first, as we always parse those if we have a '#'.
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004161 if (Parser.getTok().is(AsmToken::Hash) ||
4162 Parser.getTok().is(AsmToken::Dollar)) {
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004163 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004164 // Explicitly look for a '-', as we need to encode negative zero
4165 // differently.
4166 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4167 const MCExpr *Offset;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004168 SMLoc E;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004169 if (getParser().parseExpression(Offset, E))
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004170 return MatchOperand_ParseFail;
4171 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4172 if (!CE) {
4173 Error(S, "constant expression expected");
4174 return MatchOperand_ParseFail;
4175 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004176 // Negative zero is encoded as the flag value INT32_MIN.
4177 int32_t Val = CE->getValue();
4178 if (isNegative && Val == 0)
4179 Val = INT32_MIN;
4180
4181 Operands.push_back(
4182 ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E));
4183
4184 return MatchOperand_Success;
4185 }
4186
4187
4188 bool haveEaten = false;
4189 bool isAdd = true;
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004190 if (Tok.is(AsmToken::Plus)) {
4191 Parser.Lex(); // Eat the '+' token.
4192 haveEaten = true;
4193 } else if (Tok.is(AsmToken::Minus)) {
4194 Parser.Lex(); // Eat the '-' token.
4195 isAdd = false;
4196 haveEaten = true;
4197 }
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004198
4199 Tok = Parser.getTok();
4200 int Reg = tryParseRegister();
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004201 if (Reg == -1) {
4202 if (!haveEaten)
4203 return MatchOperand_NoMatch;
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004204 Error(Tok.getLoc(), "register expected");
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004205 return MatchOperand_ParseFail;
4206 }
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004207
4208 Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift,
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004209 0, S, Tok.getEndLoc()));
Jim Grosbach1d9d5e92011-08-10 21:56:18 +00004210
4211 return MatchOperand_Success;
4212}
4213
Tim Northovereb5e4d52013-07-22 09:06:12 +00004214/// Convert parsed operands to MCInst. Needed here because this instruction
4215/// only has two register operands, but multiplication is commutative so
4216/// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN".
Chad Rosier98cfa102012-08-31 00:03:31 +00004217void ARMAsmParser::
Chad Rosier451ef132012-08-31 22:12:31 +00004218cvtThumbMultiply(MCInst &Inst,
Jim Grosbach8e048492011-08-19 22:07:46 +00004219 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8e048492011-08-19 22:07:46 +00004220 ((ARMOperand*)Operands[3])->addRegOperands(Inst, 1);
4221 ((ARMOperand*)Operands[1])->addCCOutOperands(Inst, 1);
Jim Grosbach5a5ce632011-11-10 22:10:12 +00004222 // If we have a three-operand form, make sure to set Rn to be the operand
4223 // that isn't the same as Rd.
4224 unsigned RegOp = 4;
4225 if (Operands.size() == 6 &&
4226 ((ARMOperand*)Operands[4])->getReg() ==
4227 ((ARMOperand*)Operands[3])->getReg())
4228 RegOp = 5;
4229 ((ARMOperand*)Operands[RegOp])->addRegOperands(Inst, 1);
4230 Inst.addOperand(Inst.getOperand(0));
Jim Grosbach8e048492011-08-19 22:07:46 +00004231 ((ARMOperand*)Operands[2])->addCondCodeOperands(Inst, 2);
Jim Grosbach8e048492011-08-19 22:07:46 +00004232}
Jim Grosbachcd4dd252011-08-10 22:42:16 +00004233
Mihai Popaad18d3c2013-08-09 10:38:32 +00004234void ARMAsmParser::
4235cvtThumbBranches(MCInst &Inst,
4236 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
4237 int CondOp = -1, ImmOp = -1;
4238 switch(Inst.getOpcode()) {
4239 case ARM::tB:
4240 case ARM::tBcc: CondOp = 1; ImmOp = 2; break;
4241
4242 case ARM::t2B:
4243 case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break;
4244
4245 default: llvm_unreachable("Unexpected instruction in cvtThumbBranches");
4246 }
4247 // first decide whether or not the branch should be conditional
4248 // by looking at it's location relative to an IT block
4249 if(inITBlock()) {
4250 // inside an IT block we cannot have any conditional branches. any
4251 // such instructions needs to be converted to unconditional form
4252 switch(Inst.getOpcode()) {
4253 case ARM::tBcc: Inst.setOpcode(ARM::tB); break;
4254 case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break;
4255 }
4256 } else {
4257 // outside IT blocks we can only have unconditional branches with AL
4258 // condition code or conditional branches with non-AL condition code
4259 unsigned Cond = static_cast<ARMOperand*>(Operands[CondOp])->getCondCode();
4260 switch(Inst.getOpcode()) {
4261 case ARM::tB:
4262 case ARM::tBcc:
4263 Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc);
4264 break;
4265 case ARM::t2B:
4266 case ARM::t2Bcc:
4267 Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc);
4268 break;
4269 }
4270 }
4271
4272 // now decide on encoding size based on branch target range
4273 switch(Inst.getOpcode()) {
4274 // classify tB as either t2B or t1B based on range of immediate operand
4275 case ARM::tB: {
4276 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4277 if(!op->isSignedOffset<11, 1>() && isThumbTwo())
4278 Inst.setOpcode(ARM::t2B);
4279 break;
4280 }
4281 // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand
4282 case ARM::tBcc: {
4283 ARMOperand* op = static_cast<ARMOperand*>(Operands[ImmOp]);
4284 if(!op->isSignedOffset<8, 1>() && isThumbTwo())
4285 Inst.setOpcode(ARM::t2Bcc);
4286 break;
4287 }
4288 }
4289 ((ARMOperand*)Operands[ImmOp])->addImmOperands(Inst, 1);
4290 ((ARMOperand*)Operands[CondOp])->addCondCodeOperands(Inst, 2);
4291}
4292
Bill Wendlinge18980a2010-11-06 22:36:58 +00004293/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004294/// or an error. The first token must be a '[' when called.
Bill Wendling2063b842010-11-18 23:43:05 +00004295bool ARMAsmParser::
Jim Grosbachd3595712011-08-03 23:50:40 +00004296parseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004297 SMLoc S, E;
Sean Callanan936b0d32010-01-19 21:44:56 +00004298 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendling4f4bce02010-11-06 10:48:18 +00004299 "Token is not a Left Bracket");
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004300 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004301 Parser.Lex(); // Eat left bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004302
Sean Callanan936b0d32010-01-19 21:44:56 +00004303 const AsmToken &BaseRegTok = Parser.getTok();
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004304 int BaseRegNum = tryParseRegister();
Jim Grosbachd3595712011-08-03 23:50:40 +00004305 if (BaseRegNum == -1)
4306 return Error(BaseRegTok.getLoc(), "register expected");
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004307
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004308 // The next token must either be a comma, a colon or a closing bracket.
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004309 const AsmToken &Tok = Parser.getTok();
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004310 if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) &&
4311 !Tok.is(AsmToken::RBrac))
Jim Grosbachd3595712011-08-03 23:50:40 +00004312 return Error(Tok.getLoc(), "malformed memory operand");
Daniel Dunbar1d5e9542011-01-18 05:34:17 +00004313
Jim Grosbachd3595712011-08-03 23:50:40 +00004314 if (Tok.is(AsmToken::RBrac)) {
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004315 E = Tok.getEndLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004316 Parser.Lex(); // Eat right bracket token.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004317
Jim Grosbachd3595712011-08-03 23:50:40 +00004318 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0, ARM_AM::no_shift,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004319 0, 0, false, S, E));
Jim Grosbach32ff5582010-11-29 23:18:01 +00004320
Jim Grosbach40700e02011-09-19 18:42:21 +00004321 // If there's a pre-indexing writeback marker, '!', just add it as a token
4322 // operand. It's rather odd, but syntactically valid.
4323 if (Parser.getTok().is(AsmToken::Exclaim)) {
4324 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4325 Parser.Lex(); // Eat the '!'.
4326 }
4327
Jim Grosbachd3595712011-08-03 23:50:40 +00004328 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004329 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004330
Kristof Beyls2efb59a2013-02-14 14:46:12 +00004331 assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) &&
4332 "Lost colon or comma in memory operand?!");
4333 if (Tok.is(AsmToken::Comma)) {
4334 Parser.Lex(); // Eat the comma.
4335 }
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004336
Jim Grosbacha95ec992011-10-11 17:29:55 +00004337 // If we have a ':', it's an alignment specifier.
4338 if (Parser.getTok().is(AsmToken::Colon)) {
4339 Parser.Lex(); // Eat the ':'.
4340 E = Parser.getTok().getLoc();
4341
4342 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004343 if (getParser().parseExpression(Expr))
Jim Grosbacha95ec992011-10-11 17:29:55 +00004344 return true;
4345
4346 // The expression has to be a constant. Memory references with relocations
4347 // don't come through here, as they use the <label> forms of the relevant
4348 // instructions.
4349 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4350 if (!CE)
4351 return Error (E, "constant expression expected");
4352
4353 unsigned Align = 0;
4354 switch (CE->getValue()) {
4355 default:
Jim Grosbachcef98cd2011-12-19 18:31:43 +00004356 return Error(E,
4357 "alignment specifier must be 16, 32, 64, 128, or 256 bits");
4358 case 16: Align = 2; break;
4359 case 32: Align = 4; break;
Jim Grosbacha95ec992011-10-11 17:29:55 +00004360 case 64: Align = 8; break;
4361 case 128: Align = 16; break;
4362 case 256: Align = 32; break;
4363 }
4364
4365 // Now we should have the closing ']'
Jim Grosbacha95ec992011-10-11 17:29:55 +00004366 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004367 return Error(Parser.getTok().getLoc(), "']' expected");
4368 E = Parser.getTok().getEndLoc();
Jim Grosbacha95ec992011-10-11 17:29:55 +00004369 Parser.Lex(); // Eat right bracket token.
4370
4371 // Don't worry about range checking the value here. That's handled by
4372 // the is*() predicates.
4373 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, 0,
4374 ARM_AM::no_shift, 0, Align,
4375 false, S, E));
4376
4377 // If there's a pre-indexing writeback marker, '!', just add it as a token
4378 // operand.
4379 if (Parser.getTok().is(AsmToken::Exclaim)) {
4380 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4381 Parser.Lex(); // Eat the '!'.
4382 }
4383
4384 return false;
4385 }
4386
4387 // If we have a '#', it's an immediate offset, else assume it's a register
Jim Grosbach8279c182011-11-15 22:14:41 +00004388 // offset. Be friendly and also accept a plain integer (without a leading
4389 // hash) for gas compatibility.
4390 if (Parser.getTok().is(AsmToken::Hash) ||
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004391 Parser.getTok().is(AsmToken::Dollar) ||
Jim Grosbach8279c182011-11-15 22:14:41 +00004392 Parser.getTok().is(AsmToken::Integer)) {
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004393 if (Parser.getTok().isNot(AsmToken::Integer))
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004394 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbachd3595712011-08-03 23:50:40 +00004395 E = Parser.getTok().getLoc();
Daniel Dunbarf5164f42011-01-18 05:34:24 +00004396
Owen Anderson967674d2011-08-29 19:36:44 +00004397 bool isNegative = getParser().getTok().is(AsmToken::Minus);
Jim Grosbachd3595712011-08-03 23:50:40 +00004398 const MCExpr *Offset;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004399 if (getParser().parseExpression(Offset))
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004400 return true;
Jim Grosbachd3595712011-08-03 23:50:40 +00004401
4402 // The expression has to be a constant. Memory references with relocations
4403 // don't come through here, as they use the <label> forms of the relevant
4404 // instructions.
4405 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset);
4406 if (!CE)
4407 return Error (E, "constant expression expected");
4408
Owen Anderson967674d2011-08-29 19:36:44 +00004409 // If the constant was #-0, represent it as INT32_MIN.
4410 int32_t Val = CE->getValue();
4411 if (isNegative && Val == 0)
4412 CE = MCConstantExpr::Create(INT32_MIN, getContext());
4413
Jim Grosbachd3595712011-08-03 23:50:40 +00004414 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004415 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004416 return Error(Parser.getTok().getLoc(), "']' expected");
4417 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004418 Parser.Lex(); // Eat right bracket token.
4419
4420 // Don't worry about range checking the value here. That's handled by
4421 // the is*() predicates.
4422 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004423 ARM_AM::no_shift, 0, 0,
4424 false, S, E));
Jim Grosbachd3595712011-08-03 23:50:40 +00004425
4426 // If there's a pre-indexing writeback marker, '!', just add it as a token
4427 // operand.
4428 if (Parser.getTok().is(AsmToken::Exclaim)) {
4429 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4430 Parser.Lex(); // Eat the '!'.
4431 }
4432
4433 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004434 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004435
4436 // The register offset is optionally preceded by a '+' or '-'
4437 bool isNegative = false;
4438 if (Parser.getTok().is(AsmToken::Minus)) {
4439 isNegative = true;
4440 Parser.Lex(); // Eat the '-'.
4441 } else if (Parser.getTok().is(AsmToken::Plus)) {
4442 // Nothing to do.
4443 Parser.Lex(); // Eat the '+'.
4444 }
4445
4446 E = Parser.getTok().getLoc();
4447 int OffsetRegNum = tryParseRegister();
4448 if (OffsetRegNum == -1)
4449 return Error(E, "register expected");
4450
4451 // If there's a shift operator, handle it.
4452 ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift;
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004453 unsigned ShiftImm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004454 if (Parser.getTok().is(AsmToken::Comma)) {
4455 Parser.Lex(); // Eat the ','.
Jim Grosbach3d0b3a32011-08-05 22:03:36 +00004456 if (parseMemRegOffsetShift(ShiftType, ShiftImm))
Jim Grosbachd3595712011-08-03 23:50:40 +00004457 return true;
4458 }
4459
4460 // Now we should have the closing ']'
Jim Grosbachd3595712011-08-03 23:50:40 +00004461 if (Parser.getTok().isNot(AsmToken::RBrac))
Jordan Rosee8f1eae2013-01-07 19:00:49 +00004462 return Error(Parser.getTok().getLoc(), "']' expected");
4463 E = Parser.getTok().getEndLoc();
Jim Grosbachd3595712011-08-03 23:50:40 +00004464 Parser.Lex(); // Eat right bracket token.
4465
4466 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, 0, OffsetRegNum,
Jim Grosbacha95ec992011-10-11 17:29:55 +00004467 ShiftType, ShiftImm, 0, isNegative,
Jim Grosbachd3595712011-08-03 23:50:40 +00004468 S, E));
4469
Jim Grosbachc320c852011-08-05 21:28:30 +00004470 // If there's a pre-indexing writeback marker, '!', just add it as a token
4471 // operand.
4472 if (Parser.getTok().is(AsmToken::Exclaim)) {
4473 Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc()));
4474 Parser.Lex(); // Eat the '!'.
4475 }
Jim Grosbachd3595712011-08-03 23:50:40 +00004476
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004477 return false;
4478}
4479
Jim Grosbachd3595712011-08-03 23:50:40 +00004480/// parseMemRegOffsetShift - one of these two:
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004481/// ( lsl | lsr | asr | ror ) , # shift_amount
4482/// rrx
Jim Grosbachd3595712011-08-03 23:50:40 +00004483/// return true if it parses a shift otherwise it returns false.
4484bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St,
4485 unsigned &Amount) {
4486 SMLoc Loc = Parser.getTok().getLoc();
Sean Callanan936b0d32010-01-19 21:44:56 +00004487 const AsmToken &Tok = Parser.getTok();
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004488 if (Tok.isNot(AsmToken::Identifier))
4489 return true;
Benjamin Kramer92d89982010-07-14 22:38:02 +00004490 StringRef ShiftName = Tok.getString();
Jim Grosbach3b559ff2011-12-07 23:40:58 +00004491 if (ShiftName == "lsl" || ShiftName == "LSL" ||
4492 ShiftName == "asl" || ShiftName == "ASL")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004493 St = ARM_AM::lsl;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004494 else if (ShiftName == "lsr" || ShiftName == "LSR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004495 St = ARM_AM::lsr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004496 else if (ShiftName == "asr" || ShiftName == "ASR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004497 St = ARM_AM::asr;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004498 else if (ShiftName == "ror" || ShiftName == "ROR")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004499 St = ARM_AM::ror;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004500 else if (ShiftName == "rrx" || ShiftName == "RRX")
Owen Anderson1d2f5ce2011-03-18 22:50:18 +00004501 St = ARM_AM::rrx;
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004502 else
Jim Grosbachd3595712011-08-03 23:50:40 +00004503 return Error(Loc, "illegal shift operator");
Sean Callanana83fd7d2010-01-19 20:27:46 +00004504 Parser.Lex(); // Eat shift type token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004505
Jim Grosbachd3595712011-08-03 23:50:40 +00004506 // rrx stands alone.
4507 Amount = 0;
4508 if (St != ARM_AM::rrx) {
4509 Loc = Parser.getTok().getLoc();
4510 // A '#' and a shift amount.
4511 const AsmToken &HashTok = Parser.getTok();
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004512 if (HashTok.isNot(AsmToken::Hash) &&
4513 HashTok.isNot(AsmToken::Dollar))
Jim Grosbachd3595712011-08-03 23:50:40 +00004514 return Error(HashTok.getLoc(), "'#' expected");
4515 Parser.Lex(); // Eat hash token.
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004516
Jim Grosbachd3595712011-08-03 23:50:40 +00004517 const MCExpr *Expr;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004518 if (getParser().parseExpression(Expr))
Jim Grosbachd3595712011-08-03 23:50:40 +00004519 return true;
4520 // Range check the immediate.
4521 // lsl, ror: 0 <= imm <= 31
4522 // lsr, asr: 0 <= imm <= 32
4523 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr);
4524 if (!CE)
4525 return Error(Loc, "shift amount must be an immediate");
4526 int64_t Imm = CE->getValue();
4527 if (Imm < 0 ||
4528 ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) ||
4529 ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32))
4530 return Error(Loc, "immediate shift value out of range");
Tim Northover0c97e762012-09-22 11:18:12 +00004531 // If <ShiftTy> #0, turn it into a no_shift.
4532 if (Imm == 0)
4533 St = ARM_AM::lsl;
4534 // For consistency, treat lsr #32 and asr #32 as having immediate value 0.
4535 if (Imm == 32)
4536 Imm = 0;
Jim Grosbachd3595712011-08-03 23:50:40 +00004537 Amount = Imm;
4538 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004539
4540 return false;
4541}
4542
Jim Grosbache7fbce72011-10-03 23:38:36 +00004543/// parseFPImm - A floating point immediate expression operand.
4544ARMAsmParser::OperandMatchResultTy ARMAsmParser::
4545parseFPImm(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004546 // Anything that can accept a floating point constant as an operand
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004547 // needs to go through here, as the regular parseExpression is
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004548 // integer only.
4549 //
4550 // This routine still creates a generic Immediate operand, containing
4551 // a bitcast of the 64-bit floating point value. The various operands
4552 // that accept floats can check whether the value is valid for them
4553 // via the standard is*() predicates.
4554
Jim Grosbache7fbce72011-10-03 23:38:36 +00004555 SMLoc S = Parser.getTok().getLoc();
4556
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004557 if (Parser.getTok().isNot(AsmToken::Hash) &&
4558 Parser.getTok().isNot(AsmToken::Dollar))
Jim Grosbache7fbce72011-10-03 23:38:36 +00004559 return MatchOperand_NoMatch;
Jim Grosbach741cd732011-10-17 22:26:03 +00004560
4561 // Disambiguate the VMOV forms that can accept an FP immediate.
4562 // vmov.f32 <sreg>, #imm
4563 // vmov.f64 <dreg>, #imm
4564 // vmov.f32 <dreg>, #imm @ vector f32x2
4565 // vmov.f32 <qreg>, #imm @ vector f32x4
4566 //
4567 // There are also the NEON VMOV instructions which expect an
4568 // integer constant. Make sure we don't try to parse an FPImm
4569 // for these:
4570 // vmov.i{8|16|32|64} <dreg|qreg>, #imm
4571 ARMOperand *TyOp = static_cast<ARMOperand*>(Operands[2]);
4572 if (!TyOp->isToken() || (TyOp->getToken() != ".f32" &&
4573 TyOp->getToken() != ".f64"))
4574 return MatchOperand_NoMatch;
4575
Amaury de la Vieuvillebac917f2013-06-10 14:17:15 +00004576 Parser.Lex(); // Eat '#' or '$'.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004577
4578 // Handle negation, as that still comes through as a separate token.
4579 bool isNegative = false;
4580 if (Parser.getTok().is(AsmToken::Minus)) {
4581 isNegative = true;
4582 Parser.Lex();
4583 }
4584 const AsmToken &Tok = Parser.getTok();
Jim Grosbach235c8d22012-01-19 02:47:30 +00004585 SMLoc Loc = Tok.getLoc();
Jim Grosbache7fbce72011-10-03 23:38:36 +00004586 if (Tok.is(AsmToken::Real)) {
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004587 APFloat RealVal(APFloat::IEEEsingle, Tok.getString());
Jim Grosbache7fbce72011-10-03 23:38:36 +00004588 uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue();
4589 // If we had a '-' in front, toggle the sign bit.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004590 IntVal ^= (uint64_t)isNegative << 31;
Jim Grosbache7fbce72011-10-03 23:38:36 +00004591 Parser.Lex(); // Eat the token.
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004592 Operands.push_back(ARMOperand::CreateImm(
4593 MCConstantExpr::Create(IntVal, getContext()),
4594 S, Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004595 return MatchOperand_Success;
4596 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004597 // Also handle plain integers. Instructions which allow floating point
4598 // immediates also allow a raw encoded 8-bit value.
Jim Grosbache7fbce72011-10-03 23:38:36 +00004599 if (Tok.is(AsmToken::Integer)) {
4600 int64_t Val = Tok.getIntVal();
4601 Parser.Lex(); // Eat the token.
4602 if (Val > 255 || Val < 0) {
Jim Grosbach235c8d22012-01-19 02:47:30 +00004603 Error(Loc, "encoded floating point value out of range");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004604 return MatchOperand_ParseFail;
4605 }
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004606 double RealVal = ARM_AM::getFPImmFloat(Val);
4607 Val = APFloat(APFloat::IEEEdouble, RealVal).bitcastToAPInt().getZExtValue();
4608 Operands.push_back(ARMOperand::CreateImm(
4609 MCConstantExpr::Create(Val, getContext()), S,
4610 Parser.getTok().getLoc()));
Jim Grosbache7fbce72011-10-03 23:38:36 +00004611 return MatchOperand_Success;
4612 }
4613
Jim Grosbach235c8d22012-01-19 02:47:30 +00004614 Error(Loc, "invalid floating point immediate");
Jim Grosbache7fbce72011-10-03 23:38:36 +00004615 return MatchOperand_ParseFail;
4616}
Jim Grosbacha9d36fb2012-01-20 18:09:51 +00004617
Kevin Enderby8be42bd2009-10-30 22:55:57 +00004618/// Parse a arm instruction operand. For now this parses the operand regardless
4619/// of the mnemonic.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004620bool ARMAsmParser::parseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004621 StringRef Mnemonic) {
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004622 SMLoc S, E;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004623
4624 // Check if the current operand has a custom associated parser, if so, try to
4625 // custom parse the operand, or fallback to the general approach.
Jim Grosbach861e49c2011-02-12 01:34:40 +00004626 OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic);
4627 if (ResTy == MatchOperand_Success)
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004628 return false;
Jim Grosbach861e49c2011-02-12 01:34:40 +00004629 // If there wasn't a custom match, try the generic matcher below. Otherwise,
4630 // there was a match, but an error occurred, in which case, just return that
4631 // the operand parsing failed.
4632 if (ResTy == MatchOperand_ParseFail)
4633 return true;
Bruno Cardoso Lopesc9253b42011-02-07 21:41:25 +00004634
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004635 switch (getLexer().getKind()) {
Bill Wendlingee7f1f92010-11-06 21:42:12 +00004636 default:
4637 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling2063b842010-11-18 23:43:05 +00004638 return true;
Jim Grosbachbb24c592011-07-13 18:49:30 +00004639 case AsmToken::Identifier: {
Chad Rosierb162a5c2013-03-19 23:44:03 +00004640 // If we've seen a branch mnemonic, the next operand must be a label. This
4641 // is true even if the label is a register name. So "br r1" means branch to
4642 // label "r1".
4643 bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl";
4644 if (!ExpectLabel) {
4645 if (!tryParseRegisterWithWriteBack(Operands))
4646 return false;
4647 int Res = tryParseShiftRegister(Operands);
4648 if (Res == 0) // success
4649 return false;
4650 else if (Res == -1) // irrecoverable error
4651 return true;
4652 // If this is VMRS, check for the apsr_nzcv operand.
4653 if (Mnemonic == "vmrs" &&
4654 Parser.getTok().getString().equals_lower("apsr_nzcv")) {
4655 S = Parser.getTok().getLoc();
4656 Parser.Lex();
4657 Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S));
4658 return false;
4659 }
Jim Grosbach4ab23b52011-10-03 21:12:43 +00004660 }
Owen Andersonc3c7f5d2011-01-13 21:46:02 +00004661
4662 // Fall though for the Identifier case that is not a register or a
4663 // special name.
Jim Grosbachbb24c592011-07-13 18:49:30 +00004664 }
Jim Grosbach4e380352011-10-26 21:14:08 +00004665 case AsmToken::LParen: // parenthesized expressions like (_strcmp-4)
Kevin Enderbyb084be92011-01-13 20:32:36 +00004666 case AsmToken::Integer: // things like 1f and 2b as a branch targets
Jim Grosbach5c6b6342011-11-01 22:38:31 +00004667 case AsmToken::String: // quoted label names.
Kevin Enderbyb084be92011-01-13 20:32:36 +00004668 case AsmToken::Dot: { // . as a branch target
Kevin Enderby146dcf22009-10-15 20:48:48 +00004669 // This was not a register so parse other operands that start with an
4670 // identifier (like labels) as expressions and create them as immediates.
4671 const MCExpr *IdVal;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004672 S = Parser.getTok().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004673 if (getParser().parseExpression(IdVal))
Bill Wendling2063b842010-11-18 23:43:05 +00004674 return true;
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004675 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling2063b842010-11-18 23:43:05 +00004676 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
4677 return false;
4678 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004679 case AsmToken::LBrac:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004680 return parseMemory(Operands);
Kevin Enderbya2b99102009-10-09 21:12:28 +00004681 case AsmToken::LCurly:
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004682 return parseRegisterList(Operands);
Jim Grosbachef70e9b2011-12-09 22:25:03 +00004683 case AsmToken::Dollar:
Owen Andersonf02d98d2011-08-29 17:17:09 +00004684 case AsmToken::Hash: {
Kevin Enderby3a80dac2009-10-13 23:33:38 +00004685 // #42 -> immediate.
Sean Callanan7ad0ad02010-04-02 22:27:05 +00004686 S = Parser.getTok().getLoc();
Sean Callanana83fd7d2010-01-19 20:27:46 +00004687 Parser.Lex();
Jim Grosbach003607f2012-04-16 21:18:46 +00004688
4689 if (Parser.getTok().isNot(AsmToken::Colon)) {
4690 bool isNegative = Parser.getTok().is(AsmToken::Minus);
4691 const MCExpr *ImmVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004692 if (getParser().parseExpression(ImmVal))
Jim Grosbach003607f2012-04-16 21:18:46 +00004693 return true;
4694 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal);
4695 if (CE) {
4696 int32_t Val = CE->getValue();
4697 if (isNegative && Val == 0)
4698 ImmVal = MCConstantExpr::Create(INT32_MIN, getContext());
4699 }
4700 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4701 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
Jim Grosbach9be2d712013-02-23 00:52:09 +00004702
4703 // There can be a trailing '!' on operands that we want as a separate
4704 // '!' Token operand. Handle that here. For example, the compatibilty
4705 // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'.
4706 if (Parser.getTok().is(AsmToken::Exclaim)) {
4707 Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(),
4708 Parser.getTok().getLoc()));
4709 Parser.Lex(); // Eat exclaim token
4710 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004711 return false;
Owen Andersonf02d98d2011-08-29 17:17:09 +00004712 }
Jim Grosbach003607f2012-04-16 21:18:46 +00004713 // w/ a ':' after the '#', it's just like a plain ':'.
4714 // FALLTHROUGH
Owen Andersonf02d98d2011-08-29 17:17:09 +00004715 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004716 case AsmToken::Colon: {
4717 // ":lower16:" and ":upper16:" expression prefixes
Evan Cheng965b3c72011-01-13 07:58:56 +00004718 // FIXME: Check it's an expression prefix,
4719 // e.g. (FOO - :lower16:BAR) isn't legal.
4720 ARMMCExpr::VariantKind RefKind;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004721 if (parsePrefix(RefKind))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004722 return true;
4723
Evan Cheng965b3c72011-01-13 07:58:56 +00004724 const MCExpr *SubExprVal;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00004725 if (getParser().parseExpression(SubExprVal))
Jason W Kim1f7bc072011-01-11 23:53:41 +00004726 return true;
4727
Evan Cheng965b3c72011-01-13 07:58:56 +00004728 const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal,
Jim Grosbach9659ed92012-09-21 00:26:53 +00004729 getContext());
Jason W Kim1f7bc072011-01-11 23:53:41 +00004730 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Evan Cheng965b3c72011-01-13 07:58:56 +00004731 Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E));
Jason W Kim1f7bc072011-01-11 23:53:41 +00004732 return false;
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00004733 }
David Peixottoe407d092013-12-19 18:12:36 +00004734 case AsmToken::Equal: {
4735 if (Mnemonic != "ldr") // only parse for ldr pseudo (e.g. ldr r0, =val)
4736 return Error(Parser.getTok().getLoc(), "unexpected token in operand");
4737
4738 const MCSection *Section =
4739 getParser().getStreamer().getCurrentSection().first;
4740 assert(Section);
4741 Parser.Lex(); // Eat '='
4742 const MCExpr *SubExprVal;
4743 if (getParser().parseExpression(SubExprVal))
4744 return true;
4745 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
4746
4747 const MCExpr *CPLoc =
4748 getOrCreateConstantPool(Section).addEntry(SubExprVal, getContext());
4749 Operands.push_back(ARMOperand::CreateImm(CPLoc, S, E));
4750 return false;
4751 }
Jason W Kim1f7bc072011-01-11 23:53:41 +00004752 }
4753}
4754
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004755// parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e.
Evan Cheng965b3c72011-01-13 07:58:56 +00004756// :lower16: and :upper16:.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004757bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
Evan Cheng965b3c72011-01-13 07:58:56 +00004758 RefKind = ARMMCExpr::VK_ARM_None;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004759
4760 // :lower16: and :upper16: modifiers
Jason W Kim93229972011-01-13 00:27:00 +00004761 assert(getLexer().is(AsmToken::Colon) && "expected a :");
Jason W Kim1f7bc072011-01-11 23:53:41 +00004762 Parser.Lex(); // Eat ':'
4763
4764 if (getLexer().isNot(AsmToken::Identifier)) {
4765 Error(Parser.getTok().getLoc(), "expected prefix identifier in operand");
4766 return true;
4767 }
4768
4769 StringRef IDVal = Parser.getTok().getIdentifier();
4770 if (IDVal == "lower16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004771 RefKind = ARMMCExpr::VK_ARM_LO16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004772 } else if (IDVal == "upper16") {
Evan Cheng965b3c72011-01-13 07:58:56 +00004773 RefKind = ARMMCExpr::VK_ARM_HI16;
Jason W Kim1f7bc072011-01-11 23:53:41 +00004774 } else {
4775 Error(Parser.getTok().getLoc(), "unexpected prefix in operand");
4776 return true;
4777 }
4778 Parser.Lex();
4779
4780 if (getLexer().isNot(AsmToken::Colon)) {
4781 Error(Parser.getTok().getLoc(), "unexpected token after prefix");
4782 return true;
4783 }
4784 Parser.Lex(); // Eat the last ':'
4785 return false;
4786}
4787
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004788/// \brief Given a mnemonic, split out possible predication code and carry
4789/// setting letters to form a canonical mnemonic and flags.
4790//
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004791// FIXME: Would be nice to autogen this.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004792// FIXME: This is a bit of a maze of special cases.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00004793StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic,
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004794 unsigned &PredicationCode,
4795 bool &CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004796 unsigned &ProcessorIMod,
4797 StringRef &ITMask) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004798 PredicationCode = ARMCC::AL;
4799 CarrySetting = false;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004800 ProcessorIMod = 0;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004801
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004802 // Ignore some mnemonics we know aren't predicated forms.
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004803 //
4804 // FIXME: Would be nice to autogen this.
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004805 if ((Mnemonic == "movs" && isThumb()) ||
4806 Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" ||
4807 Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" ||
4808 Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" ||
4809 Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" ||
Richard Barton8d519fe2013-09-05 14:14:19 +00004810 Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004811 Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" ||
4812 Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" ||
Jim Grosbache16acac2011-12-19 19:43:50 +00004813 Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" ||
Joey Gouly2efaa732013-07-06 20:50:18 +00004814 Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004815 Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" ||
4816 Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" ||
4817 Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic.startswith("vsel"))
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004818 return Mnemonic;
Daniel Dunbar75d26be2010-08-11 06:37:16 +00004819
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004820 // First, split out any predication code. Ignore mnemonics we know aren't
4821 // predicated but do have a carry-set and so weren't caught above.
Jim Grosbach8d114902011-07-20 18:20:31 +00004822 if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" &&
Jim Grosbach0c398b92011-07-27 21:58:11 +00004823 Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" &&
Jim Grosbach3636be32011-08-22 23:55:58 +00004824 Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" &&
Jim Grosbachf6d5d602011-09-01 18:22:13 +00004825 Mnemonic != "sbcs" && Mnemonic != "rscs") {
Jim Grosbacha9a3f0a2011-07-11 17:09:57 +00004826 unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2))
4827 .Case("eq", ARMCC::EQ)
4828 .Case("ne", ARMCC::NE)
4829 .Case("hs", ARMCC::HS)
4830 .Case("cs", ARMCC::HS)
4831 .Case("lo", ARMCC::LO)
4832 .Case("cc", ARMCC::LO)
4833 .Case("mi", ARMCC::MI)
4834 .Case("pl", ARMCC::PL)
4835 .Case("vs", ARMCC::VS)
4836 .Case("vc", ARMCC::VC)
4837 .Case("hi", ARMCC::HI)
4838 .Case("ls", ARMCC::LS)
4839 .Case("ge", ARMCC::GE)
4840 .Case("lt", ARMCC::LT)
4841 .Case("gt", ARMCC::GT)
4842 .Case("le", ARMCC::LE)
4843 .Case("al", ARMCC::AL)
4844 .Default(~0U);
4845 if (CC != ~0U) {
4846 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2);
4847 PredicationCode = CC;
4848 }
Bill Wendling193961b2010-10-29 23:50:21 +00004849 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00004850
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004851 // Next, determine if we have a carry setting bit. We explicitly ignore all
4852 // the instructions we know end in 's'.
4853 if (Mnemonic.endswith("s") &&
Jim Grosbachd3e8e292011-08-17 22:49:09 +00004854 !(Mnemonic == "cps" || Mnemonic == "mls" ||
Jim Grosbach5cc3b4c2011-07-19 20:10:31 +00004855 Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" ||
4856 Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" ||
4857 Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" ||
Jim Grosbach086d0132011-12-08 00:49:29 +00004858 Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" ||
Jim Grosbach54337b82011-12-10 00:01:02 +00004859 Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" ||
Jim Grosbach92a939a2011-12-19 19:02:41 +00004860 Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" ||
Jim Grosbachd74560b2012-03-15 20:48:18 +00004861 Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004862 Mnemonic == "vfms" || Mnemonic == "vfnms" ||
Jim Grosbach51726e22011-07-29 20:26:09 +00004863 (Mnemonic == "movs" && isThumb()))) {
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004864 Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1);
4865 CarrySetting = true;
4866 }
4867
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00004868 // The "cps" instruction can have a interrupt mode operand which is glued into
4869 // the mnemonic. Check if this is the case, split it and parse the imod op
4870 if (Mnemonic.startswith("cps")) {
4871 // Split out any imod code.
4872 unsigned IMod =
4873 StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2))
4874 .Case("ie", ARM_PROC::IE)
4875 .Case("id", ARM_PROC::ID)
4876 .Default(~0U);
4877 if (IMod != ~0U) {
4878 Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2);
4879 ProcessorIMod = IMod;
4880 }
4881 }
4882
Jim Grosbach3d1eac82011-08-26 21:43:41 +00004883 // The "it" instruction has the condition mask on the end of the mnemonic.
4884 if (Mnemonic.startswith("it")) {
4885 ITMask = Mnemonic.slice(2, Mnemonic.size());
4886 Mnemonic = Mnemonic.slice(0, 2);
4887 }
4888
Daniel Dunbar9d944b32011-01-11 15:59:50 +00004889 return Mnemonic;
4890}
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004891
4892/// \brief Given a canonical mnemonic, determine if the instruction ever allows
4893/// inclusion of carry set or predication code operands.
4894//
4895// FIXME: It would be nice to autogen this.
Bruno Cardoso Lopese6290cc2011-01-18 20:55:11 +00004896void ARMAsmParser::
Amara Emerson33089092013-09-19 11:59:01 +00004897getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst,
4898 bool &CanAcceptCarrySet, bool &CanAcceptPredicationCode) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004899 if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" ||
4900 Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004901 Mnemonic == "add" || Mnemonic == "adc" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004902 Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004903 Mnemonic == "orr" || Mnemonic == "mvn" ||
Daniel Dunbar09264122011-01-11 19:06:29 +00004904 Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004905 Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" ||
Evan Chengaca6c822012-04-11 00:13:00 +00004906 Mnemonic == "vfm" || Mnemonic == "vfnm" ||
Jim Grosbachd73c6452011-09-16 18:05:48 +00004907 (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" ||
Jim Grosbachfc545182011-09-19 23:31:02 +00004908 Mnemonic == "mla" || Mnemonic == "smlal" ||
4909 Mnemonic == "umlal" || Mnemonic == "umull"))) {
Daniel Dunbar09264122011-01-11 19:06:29 +00004910 CanAcceptCarrySet = true;
Jim Grosbach6c45b752011-09-16 16:39:25 +00004911 } else
Daniel Dunbar09264122011-01-11 19:06:29 +00004912 CanAcceptCarrySet = false;
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004913
Tim Northover2c45a382013-06-26 16:52:40 +00004914 if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" ||
4915 Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" ||
Joey Gouly2f8890e2013-09-18 09:45:55 +00004916 Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic.startswith("crc32") ||
Joey Gouly2d0175e2013-07-09 09:59:04 +00004917 Mnemonic.startswith("cps") || Mnemonic.startswith("vsel") ||
4918 Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" ||
Joey Gouly0f12aa22013-07-09 11:26:18 +00004919 Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" ||
4920 Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" ||
Amara Emerson33089092013-09-19 11:59:01 +00004921 Mnemonic == "vrintm" || Mnemonic.startswith("aes") ||
4922 Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") ||
4923 (FullInst.startswith("vmull") && FullInst.endswith(".p64"))) {
Tim Northover2c45a382013-06-26 16:52:40 +00004924 // These mnemonics are never predicable
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004925 CanAcceptPredicationCode = false;
Tim Northover2c45a382013-06-26 16:52:40 +00004926 } else if (!isThumb()) {
4927 // Some instructions are only predicable in Thumb mode
4928 CanAcceptPredicationCode
4929 = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" &&
4930 Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" &&
4931 Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" &&
4932 Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" &&
4933 Mnemonic != "ldc2" && Mnemonic != "ldc2l" &&
4934 Mnemonic != "stc2" && Mnemonic != "stc2l" &&
4935 !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs");
4936 } else if (isThumbOne()) {
Tim Northoverf86d1f02013-10-07 11:10:47 +00004937 if (hasV6MOps())
4938 CanAcceptPredicationCode = Mnemonic != "movs";
4939 else
4940 CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs";
Jim Grosbach6c45b752011-09-16 16:39:25 +00004941 } else
Daniel Dunbar5a384c82011-01-11 15:59:53 +00004942 CanAcceptPredicationCode = true;
Daniel Dunbar876bb0182011-01-10 12:24:52 +00004943}
4944
Jim Grosbach7283da92011-08-16 21:12:37 +00004945bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic,
4946 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004947 // FIXME: This is all horribly hacky. We really need a better way to deal
4948 // with optional operands like this in the matcher table.
Jim Grosbach7283da92011-08-16 21:12:37 +00004949
4950 // The 'mov' mnemonic is special. One variant has a cc_out operand, while
4951 // another does not. Specifically, the MOVW instruction does not. So we
4952 // special case it here and remove the defaulted (non-setting) cc_out
4953 // operand if that's the instruction we're trying to match.
4954 //
4955 // We do this as post-processing of the explicit operands rather than just
4956 // conditionally adding the cc_out in the first place because we need
4957 // to check the type of the parsed immediate operand.
Owen Andersond7791b92011-09-14 22:46:14 +00004958 if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() &&
Jim Grosbach7283da92011-08-16 21:12:37 +00004959 !static_cast<ARMOperand*>(Operands[4])->isARMSOImm() &&
4960 static_cast<ARMOperand*>(Operands[4])->isImm0_65535Expr() &&
4961 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4962 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00004963
4964 // Register-register 'add' for thumb does not have a cc_out operand
4965 // when there are only two register operands.
4966 if (isThumb() && Mnemonic == "add" && Operands.size() == 5 &&
4967 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4968 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4969 static_cast<ARMOperand*>(Operands[1])->getReg() == 0)
4970 return true;
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004971 // Register-register 'add' for thumb does not have a cc_out operand
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004972 // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do
4973 // have to check the immediate range here since Thumb2 has a variant
4974 // that can handle a different range and has a cc_out operand.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004975 if (((isThumb() && Mnemonic == "add") ||
4976 (isThumbTwo() && Mnemonic == "sub")) &&
4977 Operands.size() == 6 &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004978 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4979 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4980 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::SP &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004981 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00004982 ((Mnemonic == "add" &&static_cast<ARMOperand*>(Operands[5])->isReg()) ||
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004983 static_cast<ARMOperand*>(Operands[5])->isImm0_1020s4()))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00004984 return true;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004985 // For Thumb2, add/sub immediate does not have a cc_out operand for the
4986 // imm0_4095 variant. That's the least-preferred variant when
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004987 // selecting via the generic "add" mnemonic, so to know that we
4988 // should remove the cc_out operand, we have to explicitly check that
4989 // it's not one of the other variants. Ugh.
Jim Grosbachd0c435c2011-09-16 22:58:42 +00004990 if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") &&
4991 Operands.size() == 6 &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004992 static_cast<ARMOperand*>(Operands[3])->isReg() &&
4993 static_cast<ARMOperand*>(Operands[4])->isReg() &&
4994 static_cast<ARMOperand*>(Operands[5])->isImm()) {
4995 // Nest conditions rather than one big 'if' statement for readability.
4996 //
Jim Grosbach1d3c1372011-09-01 00:28:52 +00004997 // If both registers are low, we're in an IT block, and the immediate is
4998 // in range, we should use encoding T1 instead, which has a cc_out.
4999 if (inITBlock() &&
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005000 isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) &&
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005001 isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) &&
5002 static_cast<ARMOperand*>(Operands[5])->isImm0_7())
5003 return false;
Tilmann Schelleref5666f2013-07-03 20:38:01 +00005004 // Check against T3. If the second register is the PC, this is an
5005 // alternate form of ADR, which uses encoding T4, so check for that too.
5006 if (static_cast<ARMOperand*>(Operands[4])->getReg() != ARM::PC &&
5007 static_cast<ARMOperand*>(Operands[5])->isT2SOImm())
5008 return false;
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005009
5010 // Otherwise, we use encoding T4, which does not have a cc_out
5011 // operand.
5012 return true;
5013 }
5014
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005015 // The thumb2 multiply instruction doesn't have a CCOut register, so
5016 // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to
5017 // use the 16-bit encoding or not.
5018 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 &&
5019 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5020 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5021 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5022 static_cast<ARMOperand*>(Operands[5])->isReg() &&
5023 // If the registers aren't low regs, the destination reg isn't the
5024 // same as one of the source regs, or the cc_out operand is zero
5025 // outside of an IT block, we have to use the 32-bit encoding, so
5026 // remove the cc_out operand.
5027 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5028 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
Jim Grosbach6efa7b92011-11-15 19:29:45 +00005029 !isARMLowRegister(static_cast<ARMOperand*>(Operands[5])->getReg()) ||
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005030 !inITBlock() ||
5031 (static_cast<ARMOperand*>(Operands[3])->getReg() !=
5032 static_cast<ARMOperand*>(Operands[5])->getReg() &&
5033 static_cast<ARMOperand*>(Operands[3])->getReg() !=
5034 static_cast<ARMOperand*>(Operands[4])->getReg())))
5035 return true;
5036
Jim Grosbachefa7e952011-11-15 19:55:16 +00005037 // Also check the 'mul' syntax variant that doesn't specify an explicit
5038 // destination register.
5039 if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 &&
5040 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5041 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5042 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5043 // If the registers aren't low regs or the cc_out operand is zero
5044 // outside of an IT block, we have to use the 32-bit encoding, so
5045 // remove the cc_out operand.
5046 (!isARMLowRegister(static_cast<ARMOperand*>(Operands[3])->getReg()) ||
5047 !isARMLowRegister(static_cast<ARMOperand*>(Operands[4])->getReg()) ||
5048 !inITBlock()))
5049 return true;
5050
Jim Grosbach9c8b9932011-09-14 21:00:40 +00005051
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005052
Jim Grosbach4b701af2011-08-24 21:42:27 +00005053 // Register-register 'add/sub' for thumb does not have a cc_out operand
5054 // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also
5055 // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't
5056 // right, this will result in better diagnostics (which operand is off)
5057 // anyway.
5058 if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") &&
5059 (Operands.size() == 5 || Operands.size() == 6) &&
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005060 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5061 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::SP &&
Jim Grosbachdf5a2442012-04-10 17:31:55 +00005062 static_cast<ARMOperand*>(Operands[1])->getReg() == 0 &&
5063 (static_cast<ARMOperand*>(Operands[4])->isImm() ||
5064 (Operands.size() == 6 &&
5065 static_cast<ARMOperand*>(Operands[5])->isImm())))
Jim Grosbach0a0b3072011-08-24 21:22:15 +00005066 return true;
Jim Grosbach58ffdcc2011-08-16 21:34:08 +00005067
Jim Grosbach7283da92011-08-16 21:12:37 +00005068 return false;
5069}
5070
Joey Goulye8602552013-07-19 16:34:16 +00005071bool ARMAsmParser::shouldOmitPredicateOperand(
5072 StringRef Mnemonic, SmallVectorImpl<MCParsedAsmOperand *> &Operands) {
5073 // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON
5074 unsigned RegIdx = 3;
5075 if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") &&
5076 static_cast<ARMOperand *>(Operands[2])->getToken() == ".f32") {
5077 if (static_cast<ARMOperand *>(Operands[3])->isToken() &&
5078 static_cast<ARMOperand *>(Operands[3])->getToken() == ".f32")
5079 RegIdx = 4;
5080
5081 if (static_cast<ARMOperand *>(Operands[RegIdx])->isReg() &&
5082 (ARMMCRegisterClasses[ARM::DPRRegClassID]
5083 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg()) ||
5084 ARMMCRegisterClasses[ARM::QPRRegClassID]
5085 .contains(static_cast<ARMOperand *>(Operands[RegIdx])->getReg())))
5086 return true;
5087 }
Joey Goulyf520d5e2013-07-19 16:45:16 +00005088 return false;
Joey Goulye8602552013-07-19 16:34:16 +00005089}
5090
Jim Grosbach12952fe2011-11-11 23:08:10 +00005091static bool isDataTypeToken(StringRef Tok) {
5092 return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" ||
5093 Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" ||
5094 Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" ||
5095 Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" ||
5096 Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" ||
5097 Tok == ".f" || Tok == ".d";
5098}
5099
5100// FIXME: This bit should probably be handled via an explicit match class
5101// in the .td files that matches the suffix instead of having it be
5102// a literal string token the way it is now.
5103static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) {
5104 return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm");
5105}
Chad Rosier9f7a2212013-04-18 22:35:36 +00005106static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features,
5107 unsigned VariantID);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005108/// Parse an arm instruction mnemonic followed by its operands.
Chad Rosierf0e87202012-10-25 20:41:34 +00005109bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
5110 SMLoc NameLoc,
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005111 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Jim Grosbach8be2f652011-12-09 23:34:09 +00005112 // Apply mnemonic aliases before doing anything else, as the destination
5113 // mnemnonic may include suffices and we want to handle them normally.
5114 // The generic tblgen'erated code does this later, at the start of
5115 // MatchInstructionImpl(), but that's too late for aliases that include
5116 // any sort of suffix.
5117 unsigned AvailableFeatures = getAvailableFeatures();
Chad Rosier9f7a2212013-04-18 22:35:36 +00005118 unsigned AssemblerDialect = getParser().getAssemblerDialect();
5119 applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect);
Jim Grosbach8be2f652011-12-09 23:34:09 +00005120
Jim Grosbachab5830e2011-12-14 02:16:11 +00005121 // First check for the ARM-specific .req directive.
5122 if (Parser.getTok().is(AsmToken::Identifier) &&
5123 Parser.getTok().getIdentifier() == ".req") {
5124 parseDirectiveReq(Name, NameLoc);
5125 // We always return 'error' for this, as we're done with this
5126 // statement and don't need to match the 'instruction."
5127 return true;
5128 }
5129
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005130 // Create the leading tokens for the mnemonic, split by '.' characters.
5131 size_t Start = 0, Next = Name.find('.');
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005132 StringRef Mnemonic = Name.slice(Start, Next);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005133
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005134 // Split out the predication code and carry setting flag from the mnemonic.
5135 unsigned PredicationCode;
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005136 unsigned ProcessorIMod;
Daniel Dunbar9d944b32011-01-11 15:59:50 +00005137 bool CarrySetting;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005138 StringRef ITMask;
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005139 Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting,
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005140 ProcessorIMod, ITMask);
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005141
Jim Grosbach1c171b12011-08-25 17:23:55 +00005142 // In Thumb1, only the branch (B) instruction can be predicated.
5143 if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005144 Parser.eatToEndOfStatement();
Jim Grosbach1c171b12011-08-25 17:23:55 +00005145 return Error(NameLoc, "conditional execution not supported in Thumb1");
5146 }
5147
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005148 Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc));
5149
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005150 // Handle the IT instruction ITMask. Convert it to a bitmask. This
5151 // is the mask as it will be for the IT encoding if the conditional
5152 // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case
5153 // where the conditional bit0 is zero, the instruction post-processing
5154 // will adjust the mask accordingly.
5155 if (Mnemonic == "it") {
Jim Grosbached16ec42011-08-29 22:24:09 +00005156 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2);
5157 if (ITMask.size() > 3) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005158 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005159 return Error(Loc, "too many conditions on IT instruction");
5160 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005161 unsigned Mask = 8;
5162 for (unsigned i = ITMask.size(); i != 0; --i) {
5163 char pos = ITMask[i - 1];
5164 if (pos != 't' && pos != 'e') {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005165 Parser.eatToEndOfStatement();
Jim Grosbached16ec42011-08-29 22:24:09 +00005166 return Error(Loc, "illegal IT block condition mask '" + ITMask + "'");
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005167 }
5168 Mask >>= 1;
5169 if (ITMask[i - 1] == 't')
5170 Mask |= 8;
5171 }
Jim Grosbached16ec42011-08-29 22:24:09 +00005172 Operands.push_back(ARMOperand::CreateITMask(Mask, Loc));
Jim Grosbach3d1eac82011-08-26 21:43:41 +00005173 }
5174
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005175 // FIXME: This is all a pretty gross hack. We should automatically handle
5176 // optional operands like this via tblgen.
Bill Wendling219dabd2010-11-21 10:56:05 +00005177
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005178 // Next, add the CCOut and ConditionCode operands, if needed.
5179 //
5180 // For mnemonics which can ever incorporate a carry setting bit or predication
5181 // code, our matching model involves us always generating CCOut and
5182 // ConditionCode operands to match the mnemonic "as written" and then we let
5183 // the matcher deal with finding the right instruction or generating an
5184 // appropriate error.
5185 bool CanAcceptCarrySet, CanAcceptPredicationCode;
Amara Emerson33089092013-09-19 11:59:01 +00005186 getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005187
Jim Grosbach03a8a162011-07-14 22:04:21 +00005188 // If we had a carry-set on an instruction that can't do that, issue an
5189 // error.
5190 if (!CanAcceptCarrySet && CarrySetting) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005191 Parser.eatToEndOfStatement();
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005192 return Error(NameLoc, "instruction '" + Mnemonic +
Jim Grosbach03a8a162011-07-14 22:04:21 +00005193 "' can not set flags, but 's' suffix specified");
5194 }
Jim Grosbach0a547702011-07-22 17:44:50 +00005195 // If we had a predication code on an instruction that can't do that, issue an
5196 // error.
5197 if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005198 Parser.eatToEndOfStatement();
Jim Grosbach0a547702011-07-22 17:44:50 +00005199 return Error(NameLoc, "instruction '" + Mnemonic +
5200 "' is not predicable, but condition code specified");
5201 }
Jim Grosbach03a8a162011-07-14 22:04:21 +00005202
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005203 // Add the carry setting operand, if necessary.
Jim Grosbached16ec42011-08-29 22:24:09 +00005204 if (CanAcceptCarrySet) {
5205 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size());
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005206 Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0,
Jim Grosbached16ec42011-08-29 22:24:09 +00005207 Loc));
5208 }
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005209
5210 // Add the predication code operand, if necessary.
5211 if (CanAcceptPredicationCode) {
Jim Grosbached16ec42011-08-29 22:24:09 +00005212 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() +
5213 CarrySetting);
Daniel Dunbar5a384c82011-01-11 15:59:53 +00005214 Operands.push_back(ARMOperand::CreateCondCode(
Jim Grosbached16ec42011-08-29 22:24:09 +00005215 ARMCC::CondCodes(PredicationCode), Loc));
Daniel Dunbar876bb0182011-01-10 12:24:52 +00005216 }
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005217
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005218 // Add the processor imod operand, if necessary.
5219 if (ProcessorIMod) {
5220 Operands.push_back(ARMOperand::CreateImm(
5221 MCConstantExpr::Create(ProcessorIMod, getContext()),
5222 NameLoc, NameLoc));
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005223 }
5224
Daniel Dunbar188b47b2010-08-11 06:37:20 +00005225 // Add the remaining tokens in the mnemonic.
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005226 while (Next != StringRef::npos) {
5227 Start = Next;
5228 Next = Name.find('.', Start + 1);
Bruno Cardoso Lopes90d1dfe2011-02-14 13:09:44 +00005229 StringRef ExtraToken = Name.slice(Start, Next);
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005230
Jim Grosbach12952fe2011-11-11 23:08:10 +00005231 // Some NEON instructions have an optional datatype suffix that is
5232 // completely ignored. Check for that.
5233 if (isDataTypeToken(ExtraToken) &&
5234 doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken))
5235 continue;
5236
Kevin Enderbyc5d09352013-06-18 20:19:24 +00005237 // For for ARM mode generate an error if the .n qualifier is used.
5238 if (ExtraToken == ".n" && !isThumb()) {
5239 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5240 return Error(Loc, "instruction with .n (narrow) qualifier not allowed in "
5241 "arm mode");
5242 }
5243
5244 // The .n qualifier is always discarded as that is what the tables
5245 // and matcher expect. In ARM mode the .w qualifier has no effect,
5246 // so discard it to avoid errors that can be caused by the matcher.
5247 if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) {
Jim Grosbach39c6e1d2011-09-07 16:06:04 +00005248 SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start);
5249 Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc));
5250 }
Daniel Dunbar75d26be2010-08-11 06:37:16 +00005251 }
5252
5253 // Read the remaining operands.
5254 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005255 // Read the first operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005256 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005257 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005258 return true;
5259 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005260
5261 while (getLexer().is(AsmToken::Comma)) {
Sean Callanana83fd7d2010-01-19 20:27:46 +00005262 Parser.Lex(); // Eat the comma.
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005263
5264 // Parse and remember the operand.
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00005265 if (parseOperand(Operands, Mnemonic)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005266 Parser.eatToEndOfStatement();
Chris Lattnera2a9d162010-09-11 16:18:25 +00005267 return true;
5268 }
Kevin Enderbyfebe39b2009-10-06 22:26:42 +00005269 }
5270 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00005271
Chris Lattnera2a9d162010-09-11 16:18:25 +00005272 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005273 SMLoc Loc = getLexer().getLoc();
Jim Grosbachd2037eb2013-02-20 22:21:35 +00005274 Parser.eatToEndOfStatement();
Jim Grosbachb8d9f512011-10-07 18:27:04 +00005275 return Error(Loc, "unexpected token in argument list");
Chris Lattnera2a9d162010-09-11 16:18:25 +00005276 }
Bill Wendlingee7f1f92010-11-06 21:42:12 +00005277
Chris Lattner91689c12010-09-08 05:10:46 +00005278 Parser.Lex(); // Consume the EndOfStatement
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005279
Jim Grosbach7283da92011-08-16 21:12:37 +00005280 // Some instructions, mostly Thumb, have forms for the same mnemonic that
5281 // do and don't have a cc_out optional-def operand. With some spot-checks
5282 // of the operand list, we can figure out which variant we're trying to
Jim Grosbach1d3c1372011-09-01 00:28:52 +00005283 // parse and adjust accordingly before actually matching. We shouldn't ever
5284 // try to remove a cc_out operand that was explicitly set on the the
5285 // mnemonic, of course (CarrySetting == true). Reason number #317 the
5286 // table driven matcher doesn't fit well with the ARM instruction set.
5287 if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) {
Jim Grosbach7c09e3c2011-07-19 19:13:28 +00005288 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5289 Operands.erase(Operands.begin() + 1);
5290 delete Op;
5291 }
5292
Joey Goulye8602552013-07-19 16:34:16 +00005293 // Some instructions have the same mnemonic, but don't always
5294 // have a predicate. Distinguish them here and delete the
5295 // predicate if needed.
5296 if (shouldOmitPredicateOperand(Mnemonic, Operands)) {
5297 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5298 Operands.erase(Operands.begin() + 1);
5299 delete Op;
5300 }
5301
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005302 // ARM mode 'blx' need special handling, as the register operand version
5303 // is predicable, but the label operand version is not. So, we can't rely
5304 // on the Mnemonic based checking to correctly figure out when to put
Jim Grosbach6e5778f2011-10-07 23:24:09 +00005305 // a k_CondCode operand in the list. If we're trying to match the label
5306 // version, remove the k_CondCode operand here.
Jim Grosbacha03ab0e2011-07-28 21:57:55 +00005307 if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 &&
5308 static_cast<ARMOperand*>(Operands[2])->isImm()) {
5309 ARMOperand *Op = static_cast<ARMOperand*>(Operands[1]);
5310 Operands.erase(Operands.begin() + 1);
5311 delete Op;
5312 }
Jim Grosbach8cffa282011-08-11 23:51:13 +00005313
Weiming Zhao8f56f882012-11-16 21:55:34 +00005314 // Adjust operands of ldrexd/strexd to MCK_GPRPair.
5315 // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
5316 // a single GPRPair reg operand is used in the .td file to replace the two
5317 // GPRs. However, when parsing from asm, the two GRPs cannot be automatically
5318 // expressed as a GPRPair, so we have to manually merge them.
5319 // FIXME: We would really like to be able to tablegen'erate this.
5320 if (!isThumb() && Operands.size() > 4 &&
Joey Goulye6d165c2013-08-27 17:38:16 +00005321 (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" ||
5322 Mnemonic == "stlexd")) {
5323 bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd");
Weiming Zhao8f56f882012-11-16 21:55:34 +00005324 unsigned Idx = isLoad ? 2 : 3;
5325 ARMOperand* Op1 = static_cast<ARMOperand*>(Operands[Idx]);
5326 ARMOperand* Op2 = static_cast<ARMOperand*>(Operands[Idx+1]);
5327
5328 const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID);
5329 // Adjust only if Op1 and Op2 are GPRs.
5330 if (Op1->isReg() && Op2->isReg() && MRC.contains(Op1->getReg()) &&
5331 MRC.contains(Op2->getReg())) {
5332 unsigned Reg1 = Op1->getReg();
5333 unsigned Reg2 = Op2->getReg();
5334 unsigned Rt = MRI->getEncodingValue(Reg1);
5335 unsigned Rt2 = MRI->getEncodingValue(Reg2);
5336
5337 // Rt2 must be Rt + 1 and Rt must be even.
5338 if (Rt + 1 != Rt2 || (Rt & 1)) {
5339 Error(Op2->getStartLoc(), isLoad ?
5340 "destination operands must be sequential" :
5341 "source operands must be sequential");
5342 return true;
5343 }
5344 unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0,
5345 &(MRI->getRegClass(ARM::GPRPairRegClassID)));
5346 Operands.erase(Operands.begin() + Idx, Operands.begin() + Idx + 2);
5347 Operands.insert(Operands.begin() + Idx, ARMOperand::CreateReg(
5348 NewReg, Op1->getStartLoc(), Op2->getEndLoc()));
5349 delete Op1;
5350 delete Op2;
5351 }
5352 }
5353
Kevin Enderby78f95722013-07-31 21:05:30 +00005354 // FIXME: As said above, this is all a pretty gross hack. This instruction
5355 // does not fit with other "subs" and tblgen.
5356 // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction
5357 // so the Mnemonic is the original name "subs" and delete the predicate
5358 // operand so it will match the table entry.
5359 if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 &&
5360 static_cast<ARMOperand*>(Operands[3])->isReg() &&
5361 static_cast<ARMOperand*>(Operands[3])->getReg() == ARM::PC &&
5362 static_cast<ARMOperand*>(Operands[4])->isReg() &&
5363 static_cast<ARMOperand*>(Operands[4])->getReg() == ARM::LR &&
5364 static_cast<ARMOperand*>(Operands[5])->isImm()) {
5365 ARMOperand *Op0 = static_cast<ARMOperand*>(Operands[0]);
5366 Operands.erase(Operands.begin());
5367 delete Op0;
5368 Operands.insert(Operands.begin(), ARMOperand::CreateToken(Name, NameLoc));
5369
5370 ARMOperand *Op1 = static_cast<ARMOperand*>(Operands[1]);
5371 Operands.erase(Operands.begin() + 1);
5372 delete Op1;
5373 }
Chris Lattnerf29c0b62010-01-14 22:21:20 +00005374 return false;
Kevin Enderbyccab3172009-09-15 00:27:25 +00005375}
5376
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005377// Validate context-sensitive operand constraints.
Jim Grosbach169b2be2011-08-23 18:13:04 +00005378
5379// return 'true' if register list contains non-low GPR registers,
5380// 'false' otherwise. If Reg is in the register list or is HiReg, set
5381// 'containsReg' to true.
5382static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg,
5383 unsigned HiReg, bool &containsReg) {
5384 containsReg = false;
5385 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5386 unsigned OpReg = Inst.getOperand(i).getReg();
5387 if (OpReg == Reg)
5388 containsReg = true;
5389 // Anything other than a low register isn't legal here.
5390 if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg))
5391 return true;
5392 }
5393 return false;
5394}
5395
Jim Grosbacha31f2232011-09-07 18:05:34 +00005396// Check if the specified regisgter is in the register list of the inst,
5397// starting at the indicated operand number.
5398static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) {
5399 for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) {
5400 unsigned OpReg = Inst.getOperand(i).getReg();
5401 if (OpReg == Reg)
5402 return true;
5403 }
5404 return false;
5405}
5406
Richard Barton8d519fe2013-09-05 14:14:19 +00005407// Return true if instruction has the interesting property of being
5408// allowed in IT blocks, but not being predicable.
5409static bool instIsBreakpoint(const MCInst &Inst) {
5410 return Inst.getOpcode() == ARM::tBKPT ||
5411 Inst.getOpcode() == ARM::BKPT ||
5412 Inst.getOpcode() == ARM::tHLT ||
5413 Inst.getOpcode() == ARM::HLT;
5414
5415}
5416
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005417// FIXME: We would really like to be able to tablegen'erate this.
5418bool ARMAsmParser::
5419validateInstruction(MCInst &Inst,
5420 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Joey Gouly0e76fa72013-09-12 10:28:05 +00005421 const MCInstrDesc &MCID = MII.get(Inst.getOpcode());
Jim Grosbached16ec42011-08-29 22:24:09 +00005422 SMLoc Loc = Operands[0]->getStartLoc();
Mihai Popaad18d3c2013-08-09 10:38:32 +00005423
Jim Grosbached16ec42011-08-29 22:24:09 +00005424 // Check the IT block state first.
Richard Barton8d519fe2013-09-05 14:14:19 +00005425 // NOTE: BKPT and HLT instructions have the interesting property of being
Tilmann Schellerbe904772013-09-30 17:57:30 +00005426 // allowed in IT blocks, but not being predicable. They just always execute.
Richard Barton8d519fe2013-09-05 14:14:19 +00005427 if (inITBlock() && !instIsBreakpoint(Inst)) {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005428 unsigned Bit = 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005429 if (ITState.FirstCond)
5430 ITState.FirstCond = false;
5431 else
Tilmann Schellerbe904772013-09-30 17:57:30 +00005432 Bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1;
Jim Grosbached16ec42011-08-29 22:24:09 +00005433 // The instruction must be predicable.
5434 if (!MCID.isPredicable())
5435 return Error(Loc, "instructions in IT block must be predicable");
5436 unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm();
Tilmann Schellerbe904772013-09-30 17:57:30 +00005437 unsigned ITCond = Bit ? ITState.Cond :
Jim Grosbached16ec42011-08-29 22:24:09 +00005438 ARMCC::getOppositeCondition(ITState.Cond);
5439 if (Cond != ITCond) {
5440 // Find the condition code Operand to get its SMLoc information.
5441 SMLoc CondLoc;
Tilmann Schellerbe904772013-09-30 17:57:30 +00005442 for (unsigned I = 1; I < Operands.size(); ++I)
5443 if (static_cast<ARMOperand*>(Operands[I])->isCondCode())
5444 CondLoc = Operands[I]->getStartLoc();
Jim Grosbached16ec42011-08-29 22:24:09 +00005445 return Error(CondLoc, "incorrect condition in IT block; got '" +
5446 StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) +
5447 "', but expected '" +
5448 ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'");
5449 }
Jim Grosbachc61fc8f2011-08-31 18:29:05 +00005450 // Check for non-'al' condition codes outside of the IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00005451 } else if (isThumbTwo() && MCID.isPredicable() &&
5452 Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() !=
Mihai Popaad18d3c2013-08-09 10:38:32 +00005453 ARMCC::AL && Inst.getOpcode() != ARM::tBcc &&
5454 Inst.getOpcode() != ARM::t2Bcc)
Jim Grosbached16ec42011-08-29 22:24:09 +00005455 return Error(Loc, "predicated instructions must be in IT block");
5456
Tilmann Scheller255722b2013-09-30 16:11:48 +00005457 const unsigned Opcode = Inst.getOpcode();
5458 switch (Opcode) {
Jim Grosbach5b96b802011-08-10 20:29:19 +00005459 case ARM::LDRD:
5460 case ARM::LDRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005461 case ARM::LDRD_POST: {
Tilmann Scheller255722b2013-09-30 16:11:48 +00005462 const unsigned RtReg = Inst.getOperand(0).getReg();
5463
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00005464 // Rt can't be R14.
5465 if (RtReg == ARM::LR)
5466 return Error(Operands[3]->getStartLoc(),
5467 "Rt can't be R14");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005468
5469 const unsigned Rt = MRI->getEncodingValue(RtReg);
Tilmann Scheller1aebfa02013-09-27 13:28:17 +00005470 // Rt must be even-numbered.
5471 if ((Rt & 1) == 1)
5472 return Error(Operands[3]->getStartLoc(),
5473 "Rt must be even-numbered");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005474
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005475 // Rt2 must be Rt + 1.
Tilmann Scheller255722b2013-09-30 16:11:48 +00005476 const unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005477 if (Rt2 != Rt + 1)
5478 return Error(Operands[3]->getStartLoc(),
5479 "destination operands must be sequential");
Tilmann Scheller255722b2013-09-30 16:11:48 +00005480
5481 if (Opcode == ARM::LDRD_PRE || Opcode == ARM::LDRD_POST) {
5482 const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg());
5483 // For addressing modes with writeback, the base register needs to be
5484 // different from the destination registers.
5485 if (Rn == Rt || Rn == Rt2)
5486 return Error(Operands[3]->getStartLoc(),
5487 "base register needs to be different from destination "
5488 "registers");
5489 }
5490
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005491 return false;
5492 }
Tilmann Scheller88c8f162013-09-27 10:30:18 +00005493 case ARM::t2LDRDi8:
5494 case ARM::t2LDRD_PRE:
5495 case ARM::t2LDRD_POST: {
Tilmann Scheller041f7172013-09-27 10:38:11 +00005496 // Rt2 must be different from Rt.
Tilmann Scheller88c8f162013-09-27 10:30:18 +00005497 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5498 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5499 if (Rt2 == Rt)
5500 return Error(Operands[3]->getStartLoc(),
5501 "destination operands can't be identical");
5502 return false;
5503 }
Jim Grosbacheb09f492011-08-11 20:28:23 +00005504 case ARM::STRD: {
5505 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005506 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg());
5507 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg());
Jim Grosbacheb09f492011-08-11 20:28:23 +00005508 if (Rt2 != Rt + 1)
5509 return Error(Operands[3]->getStartLoc(),
5510 "source operands must be sequential");
5511 return false;
5512 }
Jim Grosbachf7164b22011-08-10 20:49:18 +00005513 case ARM::STRD_PRE:
Weiming Zhao8f56f882012-11-16 21:55:34 +00005514 case ARM::STRD_POST: {
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005515 // Rt2 must be Rt + 1.
Eric Christopher6ac277c2012-08-09 22:10:21 +00005516 unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg());
5517 unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg());
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005518 if (Rt2 != Rt + 1)
Jim Grosbacheb09f492011-08-11 20:28:23 +00005519 return Error(Operands[3]->getStartLoc(),
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005520 "source operands must be sequential");
5521 return false;
5522 }
Jim Grosbach03f56d92011-07-27 21:09:25 +00005523 case ARM::SBFX:
5524 case ARM::UBFX: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005525 // Width must be in range [1, 32-lsb].
5526 unsigned LSB = Inst.getOperand(2).getImm();
5527 unsigned Widthm1 = Inst.getOperand(3).getImm();
5528 if (Widthm1 >= 32 - LSB)
Jim Grosbach03f56d92011-07-27 21:09:25 +00005529 return Error(Operands[5]->getStartLoc(),
5530 "bitfield width must be in range [1,32-lsb]");
Jim Grosbach64610e52011-08-16 21:42:31 +00005531 return false;
Jim Grosbach03f56d92011-07-27 21:09:25 +00005532 }
Tim Northover08a86602013-10-22 19:00:39 +00005533 // Notionally handles ARM::tLDMIA_UPD too.
Jim Grosbach90103cc2011-08-18 21:50:53 +00005534 case ARM::tLDMIA: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005535 // If we're parsing Thumb2, the .w variant is available and handles
Tilmann Schellerbe904772013-09-30 17:57:30 +00005536 // most cases that are normally illegal for a Thumb1 LDM instruction.
5537 // We'll make the transformation in processInstruction() if necessary.
Jim Grosbacha31f2232011-09-07 18:05:34 +00005538 //
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00005539 // Thumb LDM instructions are writeback iff the base register is not
Jim Grosbach90103cc2011-08-18 21:50:53 +00005540 // in the register list.
5541 unsigned Rn = Inst.getOperand(0).getReg();
Tilmann Schellerbe904772013-09-30 17:57:30 +00005542 bool HasWritebackToken =
Jim Grosbach139acd22011-08-22 23:01:07 +00005543 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
5544 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
Tilmann Schellerbe904772013-09-30 17:57:30 +00005545 bool ListContainsBase;
5546 if (checkLowRegisterList(Inst, 3, Rn, 0, ListContainsBase) && !isThumbTwo())
5547 return Error(Operands[3 + HasWritebackToken]->getStartLoc(),
Jim Grosbach169b2be2011-08-23 18:13:04 +00005548 "registers must be in range r0-r7");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005549 // If we should have writeback, then there should be a '!' token.
Tilmann Schellerbe904772013-09-30 17:57:30 +00005550 if (!ListContainsBase && !HasWritebackToken && !isThumbTwo())
Jim Grosbach90103cc2011-08-18 21:50:53 +00005551 return Error(Operands[2]->getStartLoc(),
5552 "writeback operator '!' expected");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005553 // If we should not have writeback, there must not be a '!'. This is
5554 // true even for the 32-bit wide encodings.
Tilmann Schellerbe904772013-09-30 17:57:30 +00005555 if (ListContainsBase && HasWritebackToken)
Jim Grosbach139acd22011-08-22 23:01:07 +00005556 return Error(Operands[3]->getStartLoc(),
5557 "writeback operator '!' not allowed when base register "
5558 "in register list");
Jim Grosbach90103cc2011-08-18 21:50:53 +00005559
5560 break;
5561 }
Tim Northover08a86602013-10-22 19:00:39 +00005562 case ARM::LDMIA_UPD:
5563 case ARM::LDMDB_UPD:
5564 case ARM::LDMIB_UPD:
5565 case ARM::LDMDA_UPD:
5566 // ARM variants loading and updating the same register are only officially
5567 // UNPREDICTABLE on v7 upwards. Goodness knows what they did before.
5568 if (!hasV7Ops())
5569 break;
5570 // Fallthrough
5571 case ARM::t2LDMIA_UPD:
5572 case ARM::t2LDMDB_UPD:
5573 case ARM::t2STMIA_UPD:
5574 case ARM::t2STMDB_UPD: {
Jim Grosbacha31f2232011-09-07 18:05:34 +00005575 if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg()))
Tim Northover741e6ef2013-10-24 09:37:18 +00005576 return Error(Operands.back()->getStartLoc(),
5577 "writeback register not allowed in register list");
Jim Grosbacha31f2232011-09-07 18:05:34 +00005578 break;
5579 }
Tim Northover8eaf1542013-11-12 21:32:41 +00005580 case ARM::sysLDMIA_UPD:
5581 case ARM::sysLDMDA_UPD:
5582 case ARM::sysLDMDB_UPD:
5583 case ARM::sysLDMIB_UPD:
5584 if (!listContainsReg(Inst, 3, ARM::PC))
5585 return Error(Operands[4]->getStartLoc(),
5586 "writeback register only allowed on system LDM "
5587 "if PC in register-list");
5588 break;
5589 case ARM::sysSTMIA_UPD:
5590 case ARM::sysSTMDA_UPD:
5591 case ARM::sysSTMDB_UPD:
5592 case ARM::sysSTMIB_UPD:
5593 return Error(Operands[2]->getStartLoc(),
5594 "system STM cannot have writeback register");
5595 break;
Chad Rosier8513ffb2012-08-30 23:20:38 +00005596 case ARM::tMUL: {
5597 // The second source operand must be the same register as the destination
5598 // operand.
Chad Rosier9d1fc362012-08-31 17:24:10 +00005599 //
5600 // In this case, we must directly check the parsed operands because the
5601 // cvtThumbMultiply() function is written in such a way that it guarantees
5602 // this first statement is always true for the new Inst. Essentially, the
5603 // destination is unconditionally copied into the second source operand
5604 // without checking to see if it matches what we actually parsed.
Chad Rosier8513ffb2012-08-30 23:20:38 +00005605 if (Operands.size() == 6 &&
5606 (((ARMOperand*)Operands[3])->getReg() !=
5607 ((ARMOperand*)Operands[5])->getReg()) &&
5608 (((ARMOperand*)Operands[3])->getReg() !=
5609 ((ARMOperand*)Operands[4])->getReg())) {
Chad Rosierdb482ef2012-08-30 23:22:05 +00005610 return Error(Operands[3]->getStartLoc(),
5611 "destination register must match source register");
Chad Rosier8513ffb2012-08-30 23:20:38 +00005612 }
5613 break;
5614 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005615 // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2,
5616 // so only issue a diagnostic for thumb1. The instructions will be
5617 // switched to the t2 encodings in processInstruction() if necessary.
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005618 case ARM::tPOP: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005619 bool ListContainsBase;
5620 if (checkLowRegisterList(Inst, 2, 0, ARM::PC, ListContainsBase) &&
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005621 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005622 return Error(Operands[2]->getStartLoc(),
5623 "registers must be in range r0-r7 or pc");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005624 break;
5625 }
5626 case ARM::tPUSH: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005627 bool ListContainsBase;
5628 if (checkLowRegisterList(Inst, 2, 0, ARM::LR, ListContainsBase) &&
Jim Grosbach9bded9d2011-11-10 23:17:11 +00005629 !isThumbTwo())
Jim Grosbach169b2be2011-08-23 18:13:04 +00005630 return Error(Operands[2]->getStartLoc(),
5631 "registers must be in range r0-r7 or lr");
Jim Grosbach38c59fc2011-08-22 23:17:34 +00005632 break;
5633 }
Jim Grosbachd80d1692011-08-23 18:15:37 +00005634 case ARM::tSTMIA_UPD: {
Tim Northover08a86602013-10-22 19:00:39 +00005635 bool ListContainsBase, InvalidLowList;
5636 InvalidLowList = checkLowRegisterList(Inst, 4, Inst.getOperand(0).getReg(),
5637 0, ListContainsBase);
5638 if (InvalidLowList && !isThumbTwo())
Jim Grosbachd80d1692011-08-23 18:15:37 +00005639 return Error(Operands[4]->getStartLoc(),
5640 "registers must be in range r0-r7");
Tim Northover08a86602013-10-22 19:00:39 +00005641
5642 // This would be converted to a 32-bit stm, but that's not valid if the
5643 // writeback register is in the list.
5644 if (InvalidLowList && ListContainsBase)
5645 return Error(Operands[4]->getStartLoc(),
5646 "writeback operator '!' not allowed when base register "
5647 "in register list");
Jim Grosbachd80d1692011-08-23 18:15:37 +00005648 break;
5649 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00005650 case ARM::tADDrSP: {
5651 // If the non-SP source operand and the destination operand are not the
5652 // same, we need thumb2 (for the wide encoding), or we have an error.
5653 if (!isThumbTwo() &&
5654 Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
5655 return Error(Operands[4]->getStartLoc(),
5656 "source register must be the same as destination");
5657 }
5658 break;
5659 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00005660 // Final range checking for Thumb unconditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00005661 case ARM::tB:
Tilmann Schellerbe904772013-09-30 17:57:30 +00005662 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<11, 1>())
5663 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005664 break;
5665 case ARM::t2B: {
5666 int op = (Operands[2]->isImm()) ? 2 : 3;
Tilmann Schellerbe904772013-09-30 17:57:30 +00005667 if (!(static_cast<ARMOperand*>(Operands[op]))->isSignedOffset<24, 1>())
5668 return Error(Operands[op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005669 break;
5670 }
Tilmann Schellerbe904772013-09-30 17:57:30 +00005671 // Final range checking for Thumb conditional branch instructions.
Mihai Popaad18d3c2013-08-09 10:38:32 +00005672 case ARM::tBcc:
Tilmann Schellerbe904772013-09-30 17:57:30 +00005673 if (!(static_cast<ARMOperand*>(Operands[2]))->isSignedOffset<8, 1>())
5674 return Error(Operands[2]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005675 break;
5676 case ARM::t2Bcc: {
Tilmann Schellerbe904772013-09-30 17:57:30 +00005677 int Op = (Operands[2]->isImm()) ? 2 : 3;
5678 if (!(static_cast<ARMOperand*>(Operands[Op]))->isSignedOffset<20, 1>())
5679 return Error(Operands[Op]->getStartLoc(), "branch target out of range");
Mihai Popaad18d3c2013-08-09 10:38:32 +00005680 break;
5681 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00005682 }
5683
5684 return false;
5685}
5686
Jim Grosbach1a747242012-01-23 23:45:44 +00005687static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbacheb538222011-12-02 22:34:51 +00005688 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005689 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005690 // VST1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005691 case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5692 case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5693 case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5694 case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD;
5695 case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD;
5696 case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD;
5697 case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8;
5698 case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16;
5699 case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005700
5701 // VST2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005702 case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5703 case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5704 case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5705 case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5706 case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005707
Jim Grosbach1e946a42012-01-24 00:43:12 +00005708 case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD;
5709 case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD;
5710 case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD;
5711 case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD;
5712 case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD;
Jim Grosbach2c590522011-12-20 20:46:29 +00005713
Jim Grosbach1e946a42012-01-24 00:43:12 +00005714 case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8;
5715 case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16;
5716 case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32;
5717 case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16;
5718 case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32;
Jim Grosbach1a747242012-01-23 23:45:44 +00005719
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005720 // VST3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005721 case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5722 case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5723 case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5724 case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD;
5725 case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5726 case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD;
5727 case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD;
5728 case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD;
5729 case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD;
5730 case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD;
5731 case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8;
5732 case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16;
5733 case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32;
5734 case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16;
5735 case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32;
Jim Grosbachd3d36d92012-01-24 00:07:41 +00005736
Jim Grosbach1a747242012-01-23 23:45:44 +00005737 // VST3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005738 case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5739 case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5740 case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5741 case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5742 case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5743 case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5744 case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD;
5745 case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD;
5746 case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD;
5747 case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD;
5748 case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD;
5749 case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD;
5750 case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8;
5751 case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16;
5752 case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32;
5753 case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8;
5754 case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16;
5755 case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32;
Jim Grosbachda70eac2012-01-24 00:58:13 +00005756
Jim Grosbach8e2722c2012-01-24 18:53:13 +00005757 // VST4LN
5758 case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5759 case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5760 case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5761 case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD;
5762 case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5763 case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD;
5764 case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD;
5765 case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD;
5766 case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD;
5767 case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD;
5768 case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8;
5769 case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16;
5770 case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32;
5771 case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16;
5772 case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32;
5773
Jim Grosbachda70eac2012-01-24 00:58:13 +00005774 // VST4
5775 case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5776 case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5777 case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5778 case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5779 case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5780 case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5781 case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD;
5782 case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD;
5783 case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD;
5784 case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD;
5785 case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD;
5786 case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD;
5787 case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8;
5788 case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16;
5789 case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32;
5790 case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8;
5791 case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16;
5792 case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32;
Jim Grosbacheb538222011-12-02 22:34:51 +00005793 }
5794}
5795
Jim Grosbach1a747242012-01-23 23:45:44 +00005796static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) {
Jim Grosbach04945c42011-12-02 00:35:16 +00005797 switch(Opc) {
Craig Toppere55c5562012-02-07 02:50:20 +00005798 default: llvm_unreachable("unexpected opcode!");
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005799 // VLD1LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005800 case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5801 case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5802 case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5803 case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD;
5804 case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD;
5805 case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD;
5806 case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8;
5807 case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16;
5808 case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005809
5810 // VLD2LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005811 case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5812 case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5813 case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5814 case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD;
5815 case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5816 case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD;
5817 case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD;
5818 case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD;
5819 case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD;
5820 case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD;
5821 case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8;
5822 case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16;
5823 case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32;
5824 case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16;
5825 case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32;
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005826
Jim Grosbachb78403c2012-01-24 23:47:04 +00005827 // VLD3DUP
5828 case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5829 case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5830 case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5831 case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD;
5832 case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPq16_UPD;
5833 case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5834 case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD;
5835 case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD;
5836 case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD;
5837 case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD;
5838 case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD;
5839 case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD;
5840 case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8;
5841 case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16;
5842 case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32;
5843 case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8;
5844 case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16;
5845 case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32;
5846
Jim Grosbacha8b444b2012-01-23 21:53:26 +00005847 // VLD3LN
Jim Grosbach1e946a42012-01-24 00:43:12 +00005848 case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5849 case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5850 case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5851 case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD;
5852 case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5853 case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD;
5854 case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD;
5855 case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD;
5856 case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD;
5857 case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD;
5858 case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8;
5859 case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16;
5860 case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32;
5861 case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16;
5862 case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32;
Jim Grosbachac2af3f2012-01-23 23:20:46 +00005863
5864 // VLD3
Jim Grosbach1e946a42012-01-24 00:43:12 +00005865 case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5866 case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5867 case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5868 case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5869 case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5870 case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5871 case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD;
5872 case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD;
5873 case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD;
5874 case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD;
5875 case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD;
5876 case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD;
5877 case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8;
5878 case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16;
5879 case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32;
5880 case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8;
5881 case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16;
5882 case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32;
Jim Grosbached561fc2012-01-24 00:43:17 +00005883
Jim Grosbach14952a02012-01-24 18:37:25 +00005884 // VLD4LN
5885 case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5886 case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5887 case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5888 case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNq16_UPD;
5889 case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5890 case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD;
5891 case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD;
5892 case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD;
5893 case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD;
5894 case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD;
5895 case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8;
5896 case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16;
5897 case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32;
5898 case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16;
5899 case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32;
5900
Jim Grosbach086cbfa2012-01-25 00:01:08 +00005901 // VLD4DUP
5902 case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5903 case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5904 case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5905 case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD;
5906 case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD;
5907 case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5908 case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD;
5909 case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD;
5910 case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD;
5911 case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD;
5912 case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD;
5913 case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD;
5914 case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8;
5915 case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16;
5916 case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32;
5917 case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8;
5918 case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16;
5919 case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32;
5920
Jim Grosbached561fc2012-01-24 00:43:17 +00005921 // VLD4
5922 case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5923 case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5924 case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5925 case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5926 case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5927 case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5928 case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD;
5929 case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD;
5930 case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD;
5931 case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD;
5932 case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD;
5933 case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD;
5934 case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8;
5935 case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16;
5936 case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32;
5937 case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8;
5938 case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16;
5939 case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32;
Jim Grosbach04945c42011-12-02 00:35:16 +00005940 }
5941}
5942
Jim Grosbachafad0532011-11-10 23:42:14 +00005943bool ARMAsmParser::
Jim Grosbach8ba76c62011-08-11 17:35:48 +00005944processInstruction(MCInst &Inst,
5945 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
5946 switch (Inst.getOpcode()) {
Jim Grosbache974a6a2012-09-25 00:08:13 +00005947 // Alias for alternate form of 'ADR Rd, #imm' instruction.
5948 case ARM::ADDri: {
5949 if (Inst.getOperand(1).getReg() != ARM::PC ||
5950 Inst.getOperand(5).getReg() != 0)
5951 return false;
5952 MCInst TmpInst;
5953 TmpInst.setOpcode(ARM::ADR);
5954 TmpInst.addOperand(Inst.getOperand(0));
5955 TmpInst.addOperand(Inst.getOperand(2));
5956 TmpInst.addOperand(Inst.getOperand(3));
5957 TmpInst.addOperand(Inst.getOperand(4));
5958 Inst = TmpInst;
5959 return true;
5960 }
Jim Grosbach94298a92012-01-18 22:46:46 +00005961 // Aliases for alternate PC+imm syntax of LDR instructions.
5962 case ARM::t2LDRpcrel:
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005963 // Select the narrow version if the immediate will fit.
5964 if (Inst.getOperand(1).getImm() > 0 &&
Amaury de la Vieuvilleeac0bad2013-06-18 08:13:05 +00005965 Inst.getOperand(1).getImm() <= 0xff &&
5966 !(static_cast<ARMOperand*>(Operands[2])->isToken() &&
5967 static_cast<ARMOperand*>(Operands[2])->getToken() == ".w"))
Kevin Enderby06aa3eb82012-12-14 23:04:25 +00005968 Inst.setOpcode(ARM::tLDRpci);
5969 else
5970 Inst.setOpcode(ARM::t2LDRpci);
Jim Grosbach94298a92012-01-18 22:46:46 +00005971 return true;
5972 case ARM::t2LDRBpcrel:
5973 Inst.setOpcode(ARM::t2LDRBpci);
5974 return true;
5975 case ARM::t2LDRHpcrel:
5976 Inst.setOpcode(ARM::t2LDRHpci);
5977 return true;
5978 case ARM::t2LDRSBpcrel:
5979 Inst.setOpcode(ARM::t2LDRSBpci);
5980 return true;
5981 case ARM::t2LDRSHpcrel:
5982 Inst.setOpcode(ARM::t2LDRSHpci);
5983 return true;
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00005984 // Handle NEON VST complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00005985 case ARM::VST1LNdWB_register_Asm_8:
5986 case ARM::VST1LNdWB_register_Asm_16:
5987 case ARM::VST1LNdWB_register_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00005988 MCInst TmpInst;
5989 // Shuffle the operands around so the lane index operand is in the
5990 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00005991 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00005992 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00005993 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
5994 TmpInst.addOperand(Inst.getOperand(2)); // Rn
5995 TmpInst.addOperand(Inst.getOperand(3)); // alignment
5996 TmpInst.addOperand(Inst.getOperand(4)); // Rm
5997 TmpInst.addOperand(Inst.getOperand(0)); // Vd
5998 TmpInst.addOperand(Inst.getOperand(1)); // lane
5999 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6000 TmpInst.addOperand(Inst.getOperand(6));
6001 Inst = TmpInst;
6002 return true;
6003 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006004
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006005 case ARM::VST2LNdWB_register_Asm_8:
6006 case ARM::VST2LNdWB_register_Asm_16:
6007 case ARM::VST2LNdWB_register_Asm_32:
6008 case ARM::VST2LNqWB_register_Asm_16:
6009 case ARM::VST2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006010 MCInst TmpInst;
6011 // Shuffle the operands around so the lane index operand is in the
6012 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006013 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006014 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006015 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6016 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6017 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6018 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6019 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006020 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6021 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006022 TmpInst.addOperand(Inst.getOperand(1)); // lane
6023 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6024 TmpInst.addOperand(Inst.getOperand(6));
6025 Inst = TmpInst;
6026 return true;
6027 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006028
6029 case ARM::VST3LNdWB_register_Asm_8:
6030 case ARM::VST3LNdWB_register_Asm_16:
6031 case ARM::VST3LNdWB_register_Asm_32:
6032 case ARM::VST3LNqWB_register_Asm_16:
6033 case ARM::VST3LNqWB_register_Asm_32: {
6034 MCInst TmpInst;
6035 // Shuffle the operands around so the lane index operand is in the
6036 // right place.
6037 unsigned Spacing;
6038 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6039 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6040 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6041 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6042 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6043 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6044 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6045 Spacing));
6046 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6047 Spacing * 2));
6048 TmpInst.addOperand(Inst.getOperand(1)); // lane
6049 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6050 TmpInst.addOperand(Inst.getOperand(6));
6051 Inst = TmpInst;
6052 return true;
6053 }
6054
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006055 case ARM::VST4LNdWB_register_Asm_8:
6056 case ARM::VST4LNdWB_register_Asm_16:
6057 case ARM::VST4LNdWB_register_Asm_32:
6058 case ARM::VST4LNqWB_register_Asm_16:
6059 case ARM::VST4LNqWB_register_Asm_32: {
6060 MCInst TmpInst;
6061 // Shuffle the operands around so the lane index operand is in the
6062 // right place.
6063 unsigned Spacing;
6064 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6065 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6066 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6067 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6068 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6069 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6070 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6071 Spacing));
6072 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6073 Spacing * 2));
6074 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6075 Spacing * 3));
6076 TmpInst.addOperand(Inst.getOperand(1)); // lane
6077 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6078 TmpInst.addOperand(Inst.getOperand(6));
6079 Inst = TmpInst;
6080 return true;
6081 }
6082
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006083 case ARM::VST1LNdWB_fixed_Asm_8:
6084 case ARM::VST1LNdWB_fixed_Asm_16:
6085 case ARM::VST1LNdWB_fixed_Asm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006086 MCInst TmpInst;
6087 // Shuffle the operands around so the lane index operand is in the
6088 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006089 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006090 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006091 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6092 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6093 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6094 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6095 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6096 TmpInst.addOperand(Inst.getOperand(1)); // lane
6097 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6098 TmpInst.addOperand(Inst.getOperand(5));
6099 Inst = TmpInst;
6100 return true;
6101 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006102
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006103 case ARM::VST2LNdWB_fixed_Asm_8:
6104 case ARM::VST2LNdWB_fixed_Asm_16:
6105 case ARM::VST2LNdWB_fixed_Asm_32:
6106 case ARM::VST2LNqWB_fixed_Asm_16:
6107 case ARM::VST2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006108 MCInst TmpInst;
6109 // Shuffle the operands around so the lane index operand is in the
6110 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006111 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006112 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006113 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6114 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6115 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6116 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6117 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006118 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6119 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006120 TmpInst.addOperand(Inst.getOperand(1)); // lane
6121 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6122 TmpInst.addOperand(Inst.getOperand(5));
6123 Inst = TmpInst;
6124 return true;
6125 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006126
6127 case ARM::VST3LNdWB_fixed_Asm_8:
6128 case ARM::VST3LNdWB_fixed_Asm_16:
6129 case ARM::VST3LNdWB_fixed_Asm_32:
6130 case ARM::VST3LNqWB_fixed_Asm_16:
6131 case ARM::VST3LNqWB_fixed_Asm_32: {
6132 MCInst TmpInst;
6133 // Shuffle the operands around so the lane index operand is in the
6134 // right place.
6135 unsigned Spacing;
6136 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6137 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6138 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6139 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6140 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6141 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6142 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6143 Spacing));
6144 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6145 Spacing * 2));
6146 TmpInst.addOperand(Inst.getOperand(1)); // lane
6147 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6148 TmpInst.addOperand(Inst.getOperand(5));
6149 Inst = TmpInst;
6150 return true;
6151 }
6152
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006153 case ARM::VST4LNdWB_fixed_Asm_8:
6154 case ARM::VST4LNdWB_fixed_Asm_16:
6155 case ARM::VST4LNdWB_fixed_Asm_32:
6156 case ARM::VST4LNqWB_fixed_Asm_16:
6157 case ARM::VST4LNqWB_fixed_Asm_32: {
6158 MCInst TmpInst;
6159 // Shuffle the operands around so the lane index operand is in the
6160 // right place.
6161 unsigned Spacing;
6162 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6163 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6164 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6165 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6166 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6167 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6168 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6169 Spacing));
6170 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6171 Spacing * 2));
6172 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6173 Spacing * 3));
6174 TmpInst.addOperand(Inst.getOperand(1)); // lane
6175 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6176 TmpInst.addOperand(Inst.getOperand(5));
6177 Inst = TmpInst;
6178 return true;
6179 }
6180
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006181 case ARM::VST1LNdAsm_8:
6182 case ARM::VST1LNdAsm_16:
6183 case ARM::VST1LNdAsm_32: {
Jim Grosbacheb538222011-12-02 22:34:51 +00006184 MCInst TmpInst;
6185 // Shuffle the operands around so the lane index operand is in the
6186 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006187 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006188 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacheb538222011-12-02 22:34:51 +00006189 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6190 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6191 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6192 TmpInst.addOperand(Inst.getOperand(1)); // lane
6193 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6194 TmpInst.addOperand(Inst.getOperand(5));
6195 Inst = TmpInst;
6196 return true;
6197 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006198
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006199 case ARM::VST2LNdAsm_8:
6200 case ARM::VST2LNdAsm_16:
6201 case ARM::VST2LNdAsm_32:
6202 case ARM::VST2LNqAsm_16:
6203 case ARM::VST2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006204 MCInst TmpInst;
6205 // Shuffle the operands around so the lane index operand is in the
6206 // right place.
Jim Grosbach2c590522011-12-20 20:46:29 +00006207 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006208 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006209 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6210 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6211 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach2c590522011-12-20 20:46:29 +00006212 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6213 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006214 TmpInst.addOperand(Inst.getOperand(1)); // lane
6215 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6216 TmpInst.addOperand(Inst.getOperand(5));
6217 Inst = TmpInst;
6218 return true;
6219 }
Jim Grosbachd3d36d92012-01-24 00:07:41 +00006220
6221 case ARM::VST3LNdAsm_8:
6222 case ARM::VST3LNdAsm_16:
6223 case ARM::VST3LNdAsm_32:
6224 case ARM::VST3LNqAsm_16:
6225 case ARM::VST3LNqAsm_32: {
6226 MCInst TmpInst;
6227 // Shuffle the operands around so the lane index operand is in the
6228 // right place.
6229 unsigned Spacing;
6230 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6231 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6232 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6233 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6234 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6235 Spacing));
6236 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6237 Spacing * 2));
6238 TmpInst.addOperand(Inst.getOperand(1)); // lane
6239 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6240 TmpInst.addOperand(Inst.getOperand(5));
6241 Inst = TmpInst;
6242 return true;
6243 }
6244
Jim Grosbach8e2722c2012-01-24 18:53:13 +00006245 case ARM::VST4LNdAsm_8:
6246 case ARM::VST4LNdAsm_16:
6247 case ARM::VST4LNdAsm_32:
6248 case ARM::VST4LNqAsm_16:
6249 case ARM::VST4LNqAsm_32: {
6250 MCInst TmpInst;
6251 // Shuffle the operands around so the lane index operand is in the
6252 // right place.
6253 unsigned Spacing;
6254 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6255 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6256 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6257 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6258 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6259 Spacing));
6260 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6261 Spacing * 2));
6262 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6263 Spacing * 3));
6264 TmpInst.addOperand(Inst.getOperand(1)); // lane
6265 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6266 TmpInst.addOperand(Inst.getOperand(5));
6267 Inst = TmpInst;
6268 return true;
6269 }
6270
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006271 // Handle NEON VLD complex aliases.
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006272 case ARM::VLD1LNdWB_register_Asm_8:
6273 case ARM::VLD1LNdWB_register_Asm_16:
6274 case ARM::VLD1LNdWB_register_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006275 MCInst TmpInst;
6276 // Shuffle the operands around so the lane index operand is in the
6277 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006278 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006279 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006280 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6281 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6282 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6283 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6284 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6285 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6286 TmpInst.addOperand(Inst.getOperand(1)); // lane
6287 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6288 TmpInst.addOperand(Inst.getOperand(6));
6289 Inst = TmpInst;
6290 return true;
6291 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006292
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006293 case ARM::VLD2LNdWB_register_Asm_8:
6294 case ARM::VLD2LNdWB_register_Asm_16:
6295 case ARM::VLD2LNdWB_register_Asm_32:
6296 case ARM::VLD2LNqWB_register_Asm_16:
6297 case ARM::VLD2LNqWB_register_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006298 MCInst TmpInst;
6299 // Shuffle the operands around so the lane index operand is in the
6300 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006301 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006302 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006303 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006304 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6305 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006306 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6307 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6308 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6309 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6310 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006311 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6312 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006313 TmpInst.addOperand(Inst.getOperand(1)); // lane
6314 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6315 TmpInst.addOperand(Inst.getOperand(6));
6316 Inst = TmpInst;
6317 return true;
6318 }
6319
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006320 case ARM::VLD3LNdWB_register_Asm_8:
6321 case ARM::VLD3LNdWB_register_Asm_16:
6322 case ARM::VLD3LNdWB_register_Asm_32:
6323 case ARM::VLD3LNqWB_register_Asm_16:
6324 case ARM::VLD3LNqWB_register_Asm_32: {
6325 MCInst TmpInst;
6326 // Shuffle the operands around so the lane index operand is in the
6327 // right place.
6328 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006329 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006330 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6331 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6332 Spacing));
6333 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006334 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006335 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6336 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6337 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6338 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6339 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6340 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6341 Spacing));
6342 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006343 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006344 TmpInst.addOperand(Inst.getOperand(1)); // lane
6345 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6346 TmpInst.addOperand(Inst.getOperand(6));
6347 Inst = TmpInst;
6348 return true;
6349 }
6350
Jim Grosbach14952a02012-01-24 18:37:25 +00006351 case ARM::VLD4LNdWB_register_Asm_8:
6352 case ARM::VLD4LNdWB_register_Asm_16:
6353 case ARM::VLD4LNdWB_register_Asm_32:
6354 case ARM::VLD4LNqWB_register_Asm_16:
6355 case ARM::VLD4LNqWB_register_Asm_32: {
6356 MCInst TmpInst;
6357 // Shuffle the operands around so the lane index operand is in the
6358 // right place.
6359 unsigned Spacing;
6360 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6361 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6362 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6363 Spacing));
6364 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6365 Spacing * 2));
6366 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6367 Spacing * 3));
6368 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6369 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6370 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6371 TmpInst.addOperand(Inst.getOperand(4)); // Rm
6372 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6373 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6374 Spacing));
6375 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6376 Spacing * 2));
6377 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6378 Spacing * 3));
6379 TmpInst.addOperand(Inst.getOperand(1)); // lane
6380 TmpInst.addOperand(Inst.getOperand(5)); // CondCode
6381 TmpInst.addOperand(Inst.getOperand(6));
6382 Inst = TmpInst;
6383 return true;
6384 }
6385
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006386 case ARM::VLD1LNdWB_fixed_Asm_8:
6387 case ARM::VLD1LNdWB_fixed_Asm_16:
6388 case ARM::VLD1LNdWB_fixed_Asm_32: {
Jim Grosbachdda976b2011-12-02 22:01:52 +00006389 MCInst TmpInst;
6390 // Shuffle the operands around so the lane index operand is in the
6391 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006392 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006393 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachdda976b2011-12-02 22:01:52 +00006394 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6395 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6396 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6397 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6398 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6399 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6400 TmpInst.addOperand(Inst.getOperand(1)); // lane
6401 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6402 TmpInst.addOperand(Inst.getOperand(5));
6403 Inst = TmpInst;
6404 return true;
6405 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006406
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006407 case ARM::VLD2LNdWB_fixed_Asm_8:
6408 case ARM::VLD2LNdWB_fixed_Asm_16:
6409 case ARM::VLD2LNdWB_fixed_Asm_32:
6410 case ARM::VLD2LNqWB_fixed_Asm_16:
6411 case ARM::VLD2LNqWB_fixed_Asm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006412 MCInst TmpInst;
6413 // Shuffle the operands around so the lane index operand is in the
6414 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006415 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006416 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006417 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006418 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6419 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006420 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6421 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6422 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6423 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6424 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006425 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6426 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006427 TmpInst.addOperand(Inst.getOperand(1)); // lane
6428 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6429 TmpInst.addOperand(Inst.getOperand(5));
6430 Inst = TmpInst;
6431 return true;
6432 }
6433
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006434 case ARM::VLD3LNdWB_fixed_Asm_8:
6435 case ARM::VLD3LNdWB_fixed_Asm_16:
6436 case ARM::VLD3LNdWB_fixed_Asm_32:
6437 case ARM::VLD3LNqWB_fixed_Asm_16:
6438 case ARM::VLD3LNqWB_fixed_Asm_32: {
6439 MCInst TmpInst;
6440 // Shuffle the operands around so the lane index operand is in the
6441 // right place.
6442 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006443 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006444 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6445 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6446 Spacing));
6447 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006448 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006449 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6450 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6451 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6452 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6453 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6454 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6455 Spacing));
6456 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006457 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006458 TmpInst.addOperand(Inst.getOperand(1)); // lane
6459 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6460 TmpInst.addOperand(Inst.getOperand(5));
6461 Inst = TmpInst;
6462 return true;
6463 }
6464
Jim Grosbach14952a02012-01-24 18:37:25 +00006465 case ARM::VLD4LNdWB_fixed_Asm_8:
6466 case ARM::VLD4LNdWB_fixed_Asm_16:
6467 case ARM::VLD4LNdWB_fixed_Asm_32:
6468 case ARM::VLD4LNqWB_fixed_Asm_16:
6469 case ARM::VLD4LNqWB_fixed_Asm_32: {
6470 MCInst TmpInst;
6471 // Shuffle the operands around so the lane index operand is in the
6472 // right place.
6473 unsigned Spacing;
6474 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6475 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6476 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6477 Spacing));
6478 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6479 Spacing * 2));
6480 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6481 Spacing * 3));
6482 TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb
6483 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6484 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6485 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6486 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6487 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6488 Spacing));
6489 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6490 Spacing * 2));
6491 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6492 Spacing * 3));
6493 TmpInst.addOperand(Inst.getOperand(1)); // lane
6494 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6495 TmpInst.addOperand(Inst.getOperand(5));
6496 Inst = TmpInst;
6497 return true;
6498 }
6499
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006500 case ARM::VLD1LNdAsm_8:
6501 case ARM::VLD1LNdAsm_16:
6502 case ARM::VLD1LNdAsm_32: {
Jim Grosbach04945c42011-12-02 00:35:16 +00006503 MCInst TmpInst;
6504 // Shuffle the operands around so the lane index operand is in the
6505 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006506 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006507 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbach04945c42011-12-02 00:35:16 +00006508 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6509 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6510 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6511 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6512 TmpInst.addOperand(Inst.getOperand(1)); // lane
6513 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6514 TmpInst.addOperand(Inst.getOperand(5));
6515 Inst = TmpInst;
6516 return true;
6517 }
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006518
Jim Grosbachd28ef9a2012-01-23 19:39:08 +00006519 case ARM::VLD2LNdAsm_8:
6520 case ARM::VLD2LNdAsm_16:
6521 case ARM::VLD2LNdAsm_32:
6522 case ARM::VLD2LNqAsm_16:
6523 case ARM::VLD2LNqAsm_32: {
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006524 MCInst TmpInst;
6525 // Shuffle the operands around so the lane index operand is in the
6526 // right place.
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006527 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006528 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006529 TmpInst.addOperand(Inst.getOperand(0)); // Vd
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006530 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6531 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006532 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6533 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6534 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
Jim Grosbach75e2ab52011-12-20 19:21:26 +00006535 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6536 Spacing));
Jim Grosbacha8aa30b2011-12-14 23:25:46 +00006537 TmpInst.addOperand(Inst.getOperand(1)); // lane
6538 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6539 TmpInst.addOperand(Inst.getOperand(5));
6540 Inst = TmpInst;
6541 return true;
6542 }
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006543
6544 case ARM::VLD3LNdAsm_8:
6545 case ARM::VLD3LNdAsm_16:
6546 case ARM::VLD3LNdAsm_32:
6547 case ARM::VLD3LNqAsm_16:
6548 case ARM::VLD3LNqAsm_32: {
6549 MCInst TmpInst;
6550 // Shuffle the operands around so the lane index operand is in the
6551 // right place.
6552 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006553 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006554 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6555 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6556 Spacing));
6557 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006558 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006559 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6560 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6561 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6562 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6563 Spacing));
6564 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006565 Spacing * 2));
Jim Grosbacha8b444b2012-01-23 21:53:26 +00006566 TmpInst.addOperand(Inst.getOperand(1)); // lane
6567 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6568 TmpInst.addOperand(Inst.getOperand(5));
6569 Inst = TmpInst;
6570 return true;
6571 }
6572
Jim Grosbach14952a02012-01-24 18:37:25 +00006573 case ARM::VLD4LNdAsm_8:
6574 case ARM::VLD4LNdAsm_16:
6575 case ARM::VLD4LNdAsm_32:
6576 case ARM::VLD4LNqAsm_16:
6577 case ARM::VLD4LNqAsm_32: {
6578 MCInst TmpInst;
6579 // Shuffle the operands around so the lane index operand is in the
6580 // right place.
6581 unsigned Spacing;
6582 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6583 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6584 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6585 Spacing));
6586 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6587 Spacing * 2));
6588 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6589 Spacing * 3));
6590 TmpInst.addOperand(Inst.getOperand(2)); // Rn
6591 TmpInst.addOperand(Inst.getOperand(3)); // alignment
6592 TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd)
6593 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6594 Spacing));
6595 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6596 Spacing * 2));
6597 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6598 Spacing * 3));
6599 TmpInst.addOperand(Inst.getOperand(1)); // lane
6600 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6601 TmpInst.addOperand(Inst.getOperand(5));
6602 Inst = TmpInst;
6603 return true;
6604 }
6605
Jim Grosbachb78403c2012-01-24 23:47:04 +00006606 // VLD3DUP single 3-element structure to all lanes instructions.
6607 case ARM::VLD3DUPdAsm_8:
6608 case ARM::VLD3DUPdAsm_16:
6609 case ARM::VLD3DUPdAsm_32:
6610 case ARM::VLD3DUPqAsm_8:
6611 case ARM::VLD3DUPqAsm_16:
6612 case ARM::VLD3DUPqAsm_32: {
6613 MCInst TmpInst;
6614 unsigned Spacing;
6615 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6616 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6617 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6618 Spacing));
6619 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6620 Spacing * 2));
6621 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6622 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6623 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6624 TmpInst.addOperand(Inst.getOperand(4));
6625 Inst = TmpInst;
6626 return true;
6627 }
6628
6629 case ARM::VLD3DUPdWB_fixed_Asm_8:
6630 case ARM::VLD3DUPdWB_fixed_Asm_16:
6631 case ARM::VLD3DUPdWB_fixed_Asm_32:
6632 case ARM::VLD3DUPqWB_fixed_Asm_8:
6633 case ARM::VLD3DUPqWB_fixed_Asm_16:
6634 case ARM::VLD3DUPqWB_fixed_Asm_32: {
6635 MCInst TmpInst;
6636 unsigned Spacing;
6637 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6638 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6639 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6640 Spacing));
6641 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6642 Spacing * 2));
6643 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6644 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6645 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6646 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6647 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6648 TmpInst.addOperand(Inst.getOperand(4));
6649 Inst = TmpInst;
6650 return true;
6651 }
6652
6653 case ARM::VLD3DUPdWB_register_Asm_8:
6654 case ARM::VLD3DUPdWB_register_Asm_16:
6655 case ARM::VLD3DUPdWB_register_Asm_32:
6656 case ARM::VLD3DUPqWB_register_Asm_8:
6657 case ARM::VLD3DUPqWB_register_Asm_16:
6658 case ARM::VLD3DUPqWB_register_Asm_32: {
6659 MCInst TmpInst;
6660 unsigned Spacing;
6661 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6662 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6663 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6664 Spacing));
6665 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6666 Spacing * 2));
6667 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6668 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6669 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6670 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6671 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6672 TmpInst.addOperand(Inst.getOperand(5));
6673 Inst = TmpInst;
6674 return true;
6675 }
6676
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006677 // VLD3 multiple 3-element structure instructions.
6678 case ARM::VLD3dAsm_8:
6679 case ARM::VLD3dAsm_16:
6680 case ARM::VLD3dAsm_32:
6681 case ARM::VLD3qAsm_8:
6682 case ARM::VLD3qAsm_16:
6683 case ARM::VLD3qAsm_32: {
6684 MCInst TmpInst;
6685 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006686 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006687 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6688 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6689 Spacing));
6690 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6691 Spacing * 2));
6692 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6693 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6694 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6695 TmpInst.addOperand(Inst.getOperand(4));
6696 Inst = TmpInst;
6697 return true;
6698 }
6699
6700 case ARM::VLD3dWB_fixed_Asm_8:
6701 case ARM::VLD3dWB_fixed_Asm_16:
6702 case ARM::VLD3dWB_fixed_Asm_32:
6703 case ARM::VLD3qWB_fixed_Asm_8:
6704 case ARM::VLD3qWB_fixed_Asm_16:
6705 case ARM::VLD3qWB_fixed_Asm_32: {
6706 MCInst TmpInst;
6707 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006708 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006709 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6710 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6711 Spacing));
6712 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6713 Spacing * 2));
6714 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6715 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6716 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6717 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6718 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6719 TmpInst.addOperand(Inst.getOperand(4));
6720 Inst = TmpInst;
6721 return true;
6722 }
6723
6724 case ARM::VLD3dWB_register_Asm_8:
6725 case ARM::VLD3dWB_register_Asm_16:
6726 case ARM::VLD3dWB_register_Asm_32:
6727 case ARM::VLD3qWB_register_Asm_8:
6728 case ARM::VLD3qWB_register_Asm_16:
6729 case ARM::VLD3qWB_register_Asm_32: {
6730 MCInst TmpInst;
6731 unsigned Spacing;
Jim Grosbach1a747242012-01-23 23:45:44 +00006732 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
Jim Grosbachac2af3f2012-01-23 23:20:46 +00006733 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6734 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6735 Spacing));
6736 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6737 Spacing * 2));
6738 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6739 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6740 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6741 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6742 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6743 TmpInst.addOperand(Inst.getOperand(5));
6744 Inst = TmpInst;
6745 return true;
6746 }
6747
Jim Grosbach086cbfa2012-01-25 00:01:08 +00006748 // VLD4DUP single 3-element structure to all lanes instructions.
6749 case ARM::VLD4DUPdAsm_8:
6750 case ARM::VLD4DUPdAsm_16:
6751 case ARM::VLD4DUPdAsm_32:
6752 case ARM::VLD4DUPqAsm_8:
6753 case ARM::VLD4DUPqAsm_16:
6754 case ARM::VLD4DUPqAsm_32: {
6755 MCInst TmpInst;
6756 unsigned Spacing;
6757 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6758 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6759 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6760 Spacing));
6761 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6762 Spacing * 2));
6763 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6764 Spacing * 3));
6765 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6766 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6767 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6768 TmpInst.addOperand(Inst.getOperand(4));
6769 Inst = TmpInst;
6770 return true;
6771 }
6772
6773 case ARM::VLD4DUPdWB_fixed_Asm_8:
6774 case ARM::VLD4DUPdWB_fixed_Asm_16:
6775 case ARM::VLD4DUPdWB_fixed_Asm_32:
6776 case ARM::VLD4DUPqWB_fixed_Asm_8:
6777 case ARM::VLD4DUPqWB_fixed_Asm_16:
6778 case ARM::VLD4DUPqWB_fixed_Asm_32: {
6779 MCInst TmpInst;
6780 unsigned Spacing;
6781 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6782 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6783 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6784 Spacing));
6785 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6786 Spacing * 2));
6787 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6788 Spacing * 3));
6789 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6790 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6791 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6792 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6793 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6794 TmpInst.addOperand(Inst.getOperand(4));
6795 Inst = TmpInst;
6796 return true;
6797 }
6798
6799 case ARM::VLD4DUPdWB_register_Asm_8:
6800 case ARM::VLD4DUPdWB_register_Asm_16:
6801 case ARM::VLD4DUPdWB_register_Asm_32:
6802 case ARM::VLD4DUPqWB_register_Asm_8:
6803 case ARM::VLD4DUPqWB_register_Asm_16:
6804 case ARM::VLD4DUPqWB_register_Asm_32: {
6805 MCInst TmpInst;
6806 unsigned Spacing;
6807 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6808 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6809 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6810 Spacing));
6811 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6812 Spacing * 2));
6813 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6814 Spacing * 3));
6815 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6816 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6817 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6818 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6819 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6820 TmpInst.addOperand(Inst.getOperand(5));
6821 Inst = TmpInst;
6822 return true;
6823 }
6824
6825 // VLD4 multiple 4-element structure instructions.
Jim Grosbached561fc2012-01-24 00:43:17 +00006826 case ARM::VLD4dAsm_8:
6827 case ARM::VLD4dAsm_16:
6828 case ARM::VLD4dAsm_32:
6829 case ARM::VLD4qAsm_8:
6830 case ARM::VLD4qAsm_16:
6831 case ARM::VLD4qAsm_32: {
6832 MCInst TmpInst;
6833 unsigned Spacing;
6834 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6835 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6836 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6837 Spacing));
6838 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6839 Spacing * 2));
6840 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6841 Spacing * 3));
6842 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6843 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6844 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6845 TmpInst.addOperand(Inst.getOperand(4));
6846 Inst = TmpInst;
6847 return true;
6848 }
6849
6850 case ARM::VLD4dWB_fixed_Asm_8:
6851 case ARM::VLD4dWB_fixed_Asm_16:
6852 case ARM::VLD4dWB_fixed_Asm_32:
6853 case ARM::VLD4qWB_fixed_Asm_8:
6854 case ARM::VLD4qWB_fixed_Asm_16:
6855 case ARM::VLD4qWB_fixed_Asm_32: {
6856 MCInst TmpInst;
6857 unsigned Spacing;
6858 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6859 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6860 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6861 Spacing));
6862 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6863 Spacing * 2));
6864 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6865 Spacing * 3));
6866 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6867 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6868 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6869 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6870 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6871 TmpInst.addOperand(Inst.getOperand(4));
6872 Inst = TmpInst;
6873 return true;
6874 }
6875
6876 case ARM::VLD4dWB_register_Asm_8:
6877 case ARM::VLD4dWB_register_Asm_16:
6878 case ARM::VLD4dWB_register_Asm_32:
6879 case ARM::VLD4qWB_register_Asm_8:
6880 case ARM::VLD4qWB_register_Asm_16:
6881 case ARM::VLD4qWB_register_Asm_32: {
6882 MCInst TmpInst;
6883 unsigned Spacing;
6884 TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing));
6885 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6886 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6887 Spacing));
6888 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6889 Spacing * 2));
6890 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6891 Spacing * 3));
6892 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6893 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6894 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6895 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6896 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6897 TmpInst.addOperand(Inst.getOperand(5));
6898 Inst = TmpInst;
6899 return true;
6900 }
6901
Jim Grosbach1a747242012-01-23 23:45:44 +00006902 // VST3 multiple 3-element structure instructions.
6903 case ARM::VST3dAsm_8:
6904 case ARM::VST3dAsm_16:
6905 case ARM::VST3dAsm_32:
6906 case ARM::VST3qAsm_8:
6907 case ARM::VST3qAsm_16:
6908 case ARM::VST3qAsm_32: {
6909 MCInst TmpInst;
6910 unsigned Spacing;
6911 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6912 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6913 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6914 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6915 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6916 Spacing));
6917 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6918 Spacing * 2));
6919 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6920 TmpInst.addOperand(Inst.getOperand(4));
6921 Inst = TmpInst;
6922 return true;
6923 }
6924
6925 case ARM::VST3dWB_fixed_Asm_8:
6926 case ARM::VST3dWB_fixed_Asm_16:
6927 case ARM::VST3dWB_fixed_Asm_32:
6928 case ARM::VST3qWB_fixed_Asm_8:
6929 case ARM::VST3qWB_fixed_Asm_16:
6930 case ARM::VST3qWB_fixed_Asm_32: {
6931 MCInst TmpInst;
6932 unsigned Spacing;
6933 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6934 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6935 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6936 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6937 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
6938 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6939 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6940 Spacing));
6941 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6942 Spacing * 2));
6943 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6944 TmpInst.addOperand(Inst.getOperand(4));
6945 Inst = TmpInst;
6946 return true;
6947 }
6948
6949 case ARM::VST3dWB_register_Asm_8:
6950 case ARM::VST3dWB_register_Asm_16:
6951 case ARM::VST3dWB_register_Asm_32:
6952 case ARM::VST3qWB_register_Asm_8:
6953 case ARM::VST3qWB_register_Asm_16:
6954 case ARM::VST3qWB_register_Asm_32: {
6955 MCInst TmpInst;
6956 unsigned Spacing;
6957 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6958 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6959 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
6960 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6961 TmpInst.addOperand(Inst.getOperand(3)); // Rm
6962 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6963 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6964 Spacing));
6965 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6966 Spacing * 2));
6967 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
6968 TmpInst.addOperand(Inst.getOperand(5));
6969 Inst = TmpInst;
6970 return true;
6971 }
6972
Jim Grosbachda70eac2012-01-24 00:58:13 +00006973 // VST4 multiple 3-element structure instructions.
6974 case ARM::VST4dAsm_8:
6975 case ARM::VST4dAsm_16:
6976 case ARM::VST4dAsm_32:
6977 case ARM::VST4qAsm_8:
6978 case ARM::VST4qAsm_16:
6979 case ARM::VST4qAsm_32: {
6980 MCInst TmpInst;
6981 unsigned Spacing;
6982 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
6983 TmpInst.addOperand(Inst.getOperand(1)); // Rn
6984 TmpInst.addOperand(Inst.getOperand(2)); // alignment
6985 TmpInst.addOperand(Inst.getOperand(0)); // Vd
6986 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6987 Spacing));
6988 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6989 Spacing * 2));
6990 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
6991 Spacing * 3));
6992 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
6993 TmpInst.addOperand(Inst.getOperand(4));
6994 Inst = TmpInst;
6995 return true;
6996 }
6997
6998 case ARM::VST4dWB_fixed_Asm_8:
6999 case ARM::VST4dWB_fixed_Asm_16:
7000 case ARM::VST4dWB_fixed_Asm_32:
7001 case ARM::VST4qWB_fixed_Asm_8:
7002 case ARM::VST4qWB_fixed_Asm_16:
7003 case ARM::VST4qWB_fixed_Asm_32: {
7004 MCInst TmpInst;
7005 unsigned Spacing;
7006 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7007 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7008 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7009 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7010 TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm
7011 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7012 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7013 Spacing));
7014 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7015 Spacing * 2));
7016 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7017 Spacing * 3));
7018 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7019 TmpInst.addOperand(Inst.getOperand(4));
7020 Inst = TmpInst;
7021 return true;
7022 }
7023
7024 case ARM::VST4dWB_register_Asm_8:
7025 case ARM::VST4dWB_register_Asm_16:
7026 case ARM::VST4dWB_register_Asm_32:
7027 case ARM::VST4qWB_register_Asm_8:
7028 case ARM::VST4qWB_register_Asm_16:
7029 case ARM::VST4qWB_register_Asm_32: {
7030 MCInst TmpInst;
7031 unsigned Spacing;
7032 TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing));
7033 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7034 TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn
7035 TmpInst.addOperand(Inst.getOperand(2)); // alignment
7036 TmpInst.addOperand(Inst.getOperand(3)); // Rm
7037 TmpInst.addOperand(Inst.getOperand(0)); // Vd
7038 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7039 Spacing));
7040 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7041 Spacing * 2));
7042 TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() +
7043 Spacing * 3));
7044 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7045 TmpInst.addOperand(Inst.getOperand(5));
7046 Inst = TmpInst;
7047 return true;
7048 }
7049
Jim Grosbachad66de12012-04-11 00:15:16 +00007050 // Handle encoding choice for the shift-immediate instructions.
7051 case ARM::t2LSLri:
7052 case ARM::t2LSRri:
7053 case ARM::t2ASRri: {
7054 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7055 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7056 Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) &&
7057 !(static_cast<ARMOperand*>(Operands[3])->isToken() &&
7058 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w")) {
7059 unsigned NewOpc;
7060 switch (Inst.getOpcode()) {
7061 default: llvm_unreachable("unexpected opcode");
7062 case ARM::t2LSLri: NewOpc = ARM::tLSLri; break;
7063 case ARM::t2LSRri: NewOpc = ARM::tLSRri; break;
7064 case ARM::t2ASRri: NewOpc = ARM::tASRri; break;
7065 }
7066 // The Thumb1 operands aren't in the same order. Awesome, eh?
7067 MCInst TmpInst;
7068 TmpInst.setOpcode(NewOpc);
7069 TmpInst.addOperand(Inst.getOperand(0));
7070 TmpInst.addOperand(Inst.getOperand(5));
7071 TmpInst.addOperand(Inst.getOperand(1));
7072 TmpInst.addOperand(Inst.getOperand(2));
7073 TmpInst.addOperand(Inst.getOperand(3));
7074 TmpInst.addOperand(Inst.getOperand(4));
7075 Inst = TmpInst;
7076 return true;
7077 }
7078 return false;
7079 }
7080
Jim Grosbach485e5622011-12-13 22:45:11 +00007081 // Handle the Thumb2 mode MOV complex aliases.
Jim Grosbachb3ef7132011-12-21 20:54:00 +00007082 case ARM::t2MOVsr:
7083 case ARM::t2MOVSsr: {
7084 // Which instruction to expand to depends on the CCOut operand and
7085 // whether we're in an IT block if the register operands are low
7086 // registers.
7087 bool isNarrow = false;
7088 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7089 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7090 isARMLowRegister(Inst.getOperand(2).getReg()) &&
7091 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
7092 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr))
7093 isNarrow = true;
7094 MCInst TmpInst;
7095 unsigned newOpc;
7096 switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) {
7097 default: llvm_unreachable("unexpected opcode!");
7098 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break;
7099 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break;
7100 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break;
7101 case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break;
7102 }
7103 TmpInst.setOpcode(newOpc);
7104 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7105 if (isNarrow)
7106 TmpInst.addOperand(MCOperand::CreateReg(
7107 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7108 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7109 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7110 TmpInst.addOperand(Inst.getOperand(4)); // CondCode
7111 TmpInst.addOperand(Inst.getOperand(5));
7112 if (!isNarrow)
7113 TmpInst.addOperand(MCOperand::CreateReg(
7114 Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0));
7115 Inst = TmpInst;
7116 return true;
7117 }
Jim Grosbach485e5622011-12-13 22:45:11 +00007118 case ARM::t2MOVsi:
7119 case ARM::t2MOVSsi: {
7120 // Which instruction to expand to depends on the CCOut operand and
7121 // whether we're in an IT block if the register operands are low
7122 // registers.
7123 bool isNarrow = false;
7124 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7125 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7126 inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi))
7127 isNarrow = true;
7128 MCInst TmpInst;
7129 unsigned newOpc;
7130 switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) {
7131 default: llvm_unreachable("unexpected opcode!");
7132 case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break;
7133 case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break;
7134 case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break;
7135 case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break;
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007136 case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break;
Jim Grosbach485e5622011-12-13 22:45:11 +00007137 }
Benjamin Kramerbde91762012-06-02 10:20:22 +00007138 unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm());
7139 if (Amount == 32) Amount = 0;
Jim Grosbach485e5622011-12-13 22:45:11 +00007140 TmpInst.setOpcode(newOpc);
7141 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7142 if (isNarrow)
7143 TmpInst.addOperand(MCOperand::CreateReg(
7144 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7145 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbach8c59bbc2011-12-21 21:04:19 +00007146 if (newOpc != ARM::t2RRX)
Benjamin Kramerbde91762012-06-02 10:20:22 +00007147 TmpInst.addOperand(MCOperand::CreateImm(Amount));
Jim Grosbach485e5622011-12-13 22:45:11 +00007148 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7149 TmpInst.addOperand(Inst.getOperand(4));
7150 if (!isNarrow)
7151 TmpInst.addOperand(MCOperand::CreateReg(
7152 Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0));
7153 Inst = TmpInst;
7154 return true;
7155 }
7156 // Handle the ARM mode MOV complex aliases.
Jim Grosbachabcac562011-11-16 18:31:45 +00007157 case ARM::ASRr:
7158 case ARM::LSRr:
7159 case ARM::LSLr:
7160 case ARM::RORr: {
7161 ARM_AM::ShiftOpc ShiftTy;
7162 switch(Inst.getOpcode()) {
7163 default: llvm_unreachable("unexpected opcode!");
7164 case ARM::ASRr: ShiftTy = ARM_AM::asr; break;
7165 case ARM::LSRr: ShiftTy = ARM_AM::lsr; break;
7166 case ARM::LSLr: ShiftTy = ARM_AM::lsl; break;
7167 case ARM::RORr: ShiftTy = ARM_AM::ror; break;
7168 }
Jim Grosbachabcac562011-11-16 18:31:45 +00007169 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0);
7170 MCInst TmpInst;
7171 TmpInst.setOpcode(ARM::MOVsr);
7172 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7173 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7174 TmpInst.addOperand(Inst.getOperand(2)); // Rm
7175 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7176 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7177 TmpInst.addOperand(Inst.getOperand(4));
7178 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7179 Inst = TmpInst;
7180 return true;
7181 }
Jim Grosbachc14871c2011-11-10 19:18:01 +00007182 case ARM::ASRi:
7183 case ARM::LSRi:
7184 case ARM::LSLi:
7185 case ARM::RORi: {
7186 ARM_AM::ShiftOpc ShiftTy;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007187 switch(Inst.getOpcode()) {
7188 default: llvm_unreachable("unexpected opcode!");
7189 case ARM::ASRi: ShiftTy = ARM_AM::asr; break;
7190 case ARM::LSRi: ShiftTy = ARM_AM::lsr; break;
7191 case ARM::LSLi: ShiftTy = ARM_AM::lsl; break;
7192 case ARM::RORi: ShiftTy = ARM_AM::ror; break;
7193 }
7194 // A shift by zero is a plain MOVr, not a MOVsi.
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007195 unsigned Amt = Inst.getOperand(2).getImm();
Jim Grosbachc14871c2011-11-10 19:18:01 +00007196 unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi;
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007197 // A shift by 32 should be encoded as 0 when permitted
7198 if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr))
7199 Amt = 0;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007200 unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007201 MCInst TmpInst;
Jim Grosbachc14871c2011-11-10 19:18:01 +00007202 TmpInst.setOpcode(Opc);
Jim Grosbach61db5a52011-11-10 16:44:55 +00007203 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7204 TmpInst.addOperand(Inst.getOperand(1)); // Rn
Jim Grosbachc14871c2011-11-10 19:18:01 +00007205 if (Opc == ARM::MOVsi)
7206 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
Jim Grosbach61db5a52011-11-10 16:44:55 +00007207 TmpInst.addOperand(Inst.getOperand(3)); // CondCode
7208 TmpInst.addOperand(Inst.getOperand(4));
7209 TmpInst.addOperand(Inst.getOperand(5)); // cc_out
7210 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007211 return true;
Jim Grosbach61db5a52011-11-10 16:44:55 +00007212 }
Jim Grosbach1a2f9ee2011-11-16 19:05:59 +00007213 case ARM::RRXi: {
7214 unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0);
7215 MCInst TmpInst;
7216 TmpInst.setOpcode(ARM::MOVsi);
7217 TmpInst.addOperand(Inst.getOperand(0)); // Rd
7218 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7219 TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty
7220 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7221 TmpInst.addOperand(Inst.getOperand(3));
7222 TmpInst.addOperand(Inst.getOperand(4)); // cc_out
7223 Inst = TmpInst;
7224 return true;
7225 }
Jim Grosbachd9a9be22011-11-10 23:58:34 +00007226 case ARM::t2LDMIA_UPD: {
7227 // If this is a load of a single register, then we should use
7228 // a post-indexed LDR instruction instead, per the ARM ARM.
7229 if (Inst.getNumOperands() != 5)
7230 return false;
7231 MCInst TmpInst;
7232 TmpInst.setOpcode(ARM::t2LDR_POST);
7233 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7234 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7235 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7236 TmpInst.addOperand(MCOperand::CreateImm(4));
7237 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7238 TmpInst.addOperand(Inst.getOperand(3));
7239 Inst = TmpInst;
7240 return true;
7241 }
7242 case ARM::t2STMDB_UPD: {
7243 // If this is a store of a single register, then we should use
7244 // a pre-indexed STR instruction instead, per the ARM ARM.
7245 if (Inst.getNumOperands() != 5)
7246 return false;
7247 MCInst TmpInst;
7248 TmpInst.setOpcode(ARM::t2STR_PRE);
7249 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7250 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7251 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7252 TmpInst.addOperand(MCOperand::CreateImm(-4));
7253 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7254 TmpInst.addOperand(Inst.getOperand(3));
7255 Inst = TmpInst;
7256 return true;
7257 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007258 case ARM::LDMIA_UPD:
7259 // If this is a load of a single register via a 'pop', then we should use
7260 // a post-indexed LDR instruction instead, per the ARM ARM.
7261 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "pop" &&
7262 Inst.getNumOperands() == 5) {
7263 MCInst TmpInst;
7264 TmpInst.setOpcode(ARM::LDR_POST_IMM);
7265 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7266 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7267 TmpInst.addOperand(Inst.getOperand(1)); // Rn
7268 TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset
7269 TmpInst.addOperand(MCOperand::CreateImm(4));
7270 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7271 TmpInst.addOperand(Inst.getOperand(3));
7272 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007273 return true;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007274 }
7275 break;
Jim Grosbach27ad83d2011-08-11 18:07:11 +00007276 case ARM::STMDB_UPD:
7277 // If this is a store of a single register via a 'push', then we should use
7278 // a pre-indexed STR instruction instead, per the ARM ARM.
7279 if (static_cast<ARMOperand*>(Operands[0])->getToken() == "push" &&
7280 Inst.getNumOperands() == 5) {
7281 MCInst TmpInst;
7282 TmpInst.setOpcode(ARM::STR_PRE_IMM);
7283 TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb
7284 TmpInst.addOperand(Inst.getOperand(4)); // Rt
7285 TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12
7286 TmpInst.addOperand(MCOperand::CreateImm(-4));
7287 TmpInst.addOperand(Inst.getOperand(2)); // CondCode
7288 TmpInst.addOperand(Inst.getOperand(3));
7289 Inst = TmpInst;
7290 }
7291 break;
Jim Grosbachec9ba982011-12-05 21:06:26 +00007292 case ARM::t2ADDri12:
7293 // If the immediate fits for encoding T3 (t2ADDri) and the generic "add"
7294 // mnemonic was used (not "addw"), encoding T3 is preferred.
7295 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "add" ||
7296 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7297 break;
7298 Inst.setOpcode(ARM::t2ADDri);
7299 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7300 break;
7301 case ARM::t2SUBri12:
7302 // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub"
7303 // mnemonic was used (not "subw"), encoding T3 is preferred.
7304 if (static_cast<ARMOperand*>(Operands[0])->getToken() != "sub" ||
7305 ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1)
7306 break;
7307 Inst.setOpcode(ARM::t2SUBri);
7308 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7309 break;
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007310 case ARM::tADDi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007311 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbach6d606fb2011-08-31 17:07:33 +00007312 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7313 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7314 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007315 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007316 Inst.setOpcode(ARM::tADDi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007317 return true;
7318 }
Jim Grosbache9ab47a2011-08-16 23:57:34 +00007319 break;
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007320 case ARM::tSUBi8:
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +00007321 // If the immediate is in the range 0-7, we want tADDi3 iff Rd was
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007322 // explicitly specified. From the ARM ARM: "Encoding T1 is preferred
7323 // to encoding T2 if <Rd> is specified and encoding T2 is preferred
7324 // to encoding T1 if <Rd> is omitted."
Jim Grosbach199ab902012-03-30 16:31:31 +00007325 if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) {
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007326 Inst.setOpcode(ARM::tSUBi3);
Jim Grosbachafad0532011-11-10 23:42:14 +00007327 return true;
7328 }
Jim Grosbachd0c435c2011-09-16 22:58:42 +00007329 break;
Jim Grosbachdef5e342012-03-30 17:20:40 +00007330 case ARM::t2ADDri:
7331 case ARM::t2SUBri: {
7332 // If the destination and first source operand are the same, and
7333 // the flags are compatible with the current IT status, use encoding T2
7334 // instead of T3. For compatibility with the system 'as'. Make sure the
7335 // wide encoding wasn't explicit.
7336 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
Jim Grosbach74005ae2012-03-30 18:39:43 +00007337 !isARMLowRegister(Inst.getOperand(0).getReg()) ||
Jim Grosbachdef5e342012-03-30 17:20:40 +00007338 (unsigned)Inst.getOperand(2).getImm() > 255 ||
7339 ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) ||
7340 (inITBlock() && Inst.getOperand(5).getReg() != 0)) ||
7341 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7342 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
7343 break;
7344 MCInst TmpInst;
7345 TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ?
7346 ARM::tADDi8 : ARM::tSUBi8);
7347 TmpInst.addOperand(Inst.getOperand(0));
7348 TmpInst.addOperand(Inst.getOperand(5));
7349 TmpInst.addOperand(Inst.getOperand(0));
7350 TmpInst.addOperand(Inst.getOperand(2));
7351 TmpInst.addOperand(Inst.getOperand(3));
7352 TmpInst.addOperand(Inst.getOperand(4));
7353 Inst = TmpInst;
7354 return true;
7355 }
Jim Grosbache489bab2011-12-05 22:16:39 +00007356 case ARM::t2ADDrr: {
7357 // If the destination and first source operand are the same, and
7358 // there's no setting of the flags, use encoding T2 instead of T3.
7359 // Note that this is only for ADD, not SUB. This mirrors the system
7360 // 'as' behaviour. Make sure the wide encoding wasn't explicit.
7361 if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() ||
7362 Inst.getOperand(5).getReg() != 0 ||
Jim Grosbachb8c719c2011-12-05 22:27:04 +00007363 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7364 static_cast<ARMOperand*>(Operands[3])->getToken() == ".w"))
Jim Grosbache489bab2011-12-05 22:16:39 +00007365 break;
7366 MCInst TmpInst;
7367 TmpInst.setOpcode(ARM::tADDhirr);
7368 TmpInst.addOperand(Inst.getOperand(0));
7369 TmpInst.addOperand(Inst.getOperand(0));
7370 TmpInst.addOperand(Inst.getOperand(2));
7371 TmpInst.addOperand(Inst.getOperand(3));
7372 TmpInst.addOperand(Inst.getOperand(4));
7373 Inst = TmpInst;
7374 return true;
7375 }
Jim Grosbachc6f32b32012-04-27 23:51:36 +00007376 case ARM::tADDrSP: {
7377 // If the non-SP source operand and the destination operand are not the
7378 // same, we need to use the 32-bit encoding if it's available.
7379 if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) {
7380 Inst.setOpcode(ARM::t2ADDrr);
7381 Inst.addOperand(MCOperand::CreateReg(0)); // cc_out
7382 return true;
7383 }
7384 break;
7385 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007386 case ARM::tB:
7387 // A Thumb conditional branch outside of an IT block is a tBcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007388 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) {
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007389 Inst.setOpcode(ARM::tBcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007390 return true;
7391 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007392 break;
7393 case ARM::t2B:
7394 // A Thumb2 conditional branch outside of an IT block is a t2Bcc.
Jim Grosbachafad0532011-11-10 23:42:14 +00007395 if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007396 Inst.setOpcode(ARM::t2Bcc);
Jim Grosbachafad0532011-11-10 23:42:14 +00007397 return true;
7398 }
Owen Anderson29cfe6c2011-09-09 21:48:23 +00007399 break;
Jim Grosbach99bc8462011-08-31 21:17:31 +00007400 case ARM::t2Bcc:
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007401 // If the conditional is AL or we're in an IT block, we really want t2B.
Jim Grosbachafad0532011-11-10 23:42:14 +00007402 if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) {
Jim Grosbach99bc8462011-08-31 21:17:31 +00007403 Inst.setOpcode(ARM::t2B);
Jim Grosbachafad0532011-11-10 23:42:14 +00007404 return true;
7405 }
Jim Grosbach99bc8462011-08-31 21:17:31 +00007406 break;
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007407 case ARM::tBcc:
7408 // If the conditional is AL, we really want tB.
Jim Grosbachafad0532011-11-10 23:42:14 +00007409 if (Inst.getOperand(1).getImm() == ARMCC::AL) {
Jim Grosbachcbd4ab12011-08-17 22:57:40 +00007410 Inst.setOpcode(ARM::tB);
Jim Grosbachafad0532011-11-10 23:42:14 +00007411 return true;
7412 }
Jim Grosbach6ddb5682011-08-18 16:08:39 +00007413 break;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007414 case ARM::tLDMIA: {
7415 // If the register list contains any high registers, or if the writeback
7416 // doesn't match what tLDMIA can do, we need to use the 32-bit encoding
7417 // instead if we're in Thumb2. Otherwise, this should have generated
7418 // an error in validateInstruction().
7419 unsigned Rn = Inst.getOperand(0).getReg();
7420 bool hasWritebackToken =
7421 (static_cast<ARMOperand*>(Operands[3])->isToken() &&
7422 static_cast<ARMOperand*>(Operands[3])->getToken() == "!");
7423 bool listContainsBase;
7424 if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) ||
7425 (!listContainsBase && !hasWritebackToken) ||
7426 (listContainsBase && hasWritebackToken)) {
7427 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7428 assert (isThumbTwo());
7429 Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA);
7430 // If we're switching to the updating version, we need to insert
7431 // the writeback tied operand.
7432 if (hasWritebackToken)
7433 Inst.insert(Inst.begin(),
7434 MCOperand::CreateReg(Inst.getOperand(0).getReg()));
Jim Grosbachafad0532011-11-10 23:42:14 +00007435 return true;
Jim Grosbacha31f2232011-09-07 18:05:34 +00007436 }
7437 break;
7438 }
Jim Grosbach099c9762011-09-16 20:50:13 +00007439 case ARM::tSTMIA_UPD: {
7440 // If the register list contains any high registers, we need to use
7441 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7442 // should have generated an error in validateInstruction().
7443 unsigned Rn = Inst.getOperand(0).getReg();
7444 bool listContainsBase;
7445 if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) {
7446 // 16-bit encoding isn't sufficient. Switch to the 32-bit version.
7447 assert (isThumbTwo());
7448 Inst.setOpcode(ARM::t2STMIA_UPD);
Jim Grosbachafad0532011-11-10 23:42:14 +00007449 return true;
Jim Grosbach099c9762011-09-16 20:50:13 +00007450 }
7451 break;
7452 }
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007453 case ARM::tPOP: {
7454 bool listContainsBase;
7455 // If the register list contains any high registers, we need to use
7456 // the 32-bit encoding instead if we're in Thumb2. Otherwise, this
7457 // should have generated an error in validateInstruction().
7458 if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007459 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007460 assert (isThumbTwo());
7461 Inst.setOpcode(ARM::t2LDMIA_UPD);
7462 // Add the base register and writeback operands.
7463 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7464 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007465 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007466 }
7467 case ARM::tPUSH: {
7468 bool listContainsBase;
7469 if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase))
Jim Grosbachafad0532011-11-10 23:42:14 +00007470 return false;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007471 assert (isThumbTwo());
7472 Inst.setOpcode(ARM::t2STMDB_UPD);
7473 // Add the base register and writeback operands.
7474 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
7475 Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP));
Jim Grosbachafad0532011-11-10 23:42:14 +00007476 return true;
Jim Grosbach9bded9d2011-11-10 23:17:11 +00007477 }
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007478 case ARM::t2MOVi: {
7479 // If we can use the 16-bit encoding and the user didn't explicitly
7480 // request the 32-bit variant, transform it here.
7481 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
Jim Grosbach199ab902012-03-30 16:31:31 +00007482 (unsigned)Inst.getOperand(1).getImm() <= 255 &&
Jim Grosbach18b8b172011-09-14 19:12:11 +00007483 ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL &&
7484 Inst.getOperand(4).getReg() == ARM::CPSR) ||
7485 (inITBlock() && Inst.getOperand(4).getReg() == 0)) &&
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007486 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7487 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7488 // The operands aren't in the same order for tMOVi8...
7489 MCInst TmpInst;
7490 TmpInst.setOpcode(ARM::tMOVi8);
7491 TmpInst.addOperand(Inst.getOperand(0));
7492 TmpInst.addOperand(Inst.getOperand(4));
7493 TmpInst.addOperand(Inst.getOperand(1));
7494 TmpInst.addOperand(Inst.getOperand(2));
7495 TmpInst.addOperand(Inst.getOperand(3));
7496 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007497 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007498 }
7499 break;
7500 }
7501 case ARM::t2MOVr: {
7502 // If we can use the 16-bit encoding and the user didn't explicitly
7503 // request the 32-bit variant, transform it here.
7504 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7505 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7506 Inst.getOperand(2).getImm() == ARMCC::AL &&
7507 Inst.getOperand(4).getReg() == ARM::CPSR &&
7508 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7509 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
7510 // The operands aren't the same for tMOV[S]r... (no cc_out)
7511 MCInst TmpInst;
7512 TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr);
7513 TmpInst.addOperand(Inst.getOperand(0));
7514 TmpInst.addOperand(Inst.getOperand(1));
7515 TmpInst.addOperand(Inst.getOperand(2));
7516 TmpInst.addOperand(Inst.getOperand(3));
7517 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007518 return true;
Jim Grosbachb908b7a2011-09-10 00:15:36 +00007519 }
7520 break;
7521 }
Jim Grosbach82213192011-09-19 20:29:33 +00007522 case ARM::t2SXTH:
Jim Grosbachb3519802011-09-20 00:46:54 +00007523 case ARM::t2SXTB:
7524 case ARM::t2UXTH:
7525 case ARM::t2UXTB: {
Jim Grosbach82213192011-09-19 20:29:33 +00007526 // If we can use the 16-bit encoding and the user didn't explicitly
7527 // request the 32-bit variant, transform it here.
7528 if (isARMLowRegister(Inst.getOperand(0).getReg()) &&
7529 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7530 Inst.getOperand(2).getImm() == 0 &&
7531 (!static_cast<ARMOperand*>(Operands[2])->isToken() ||
7532 static_cast<ARMOperand*>(Operands[2])->getToken() != ".w")) {
Jim Grosbachb3519802011-09-20 00:46:54 +00007533 unsigned NewOpc;
7534 switch (Inst.getOpcode()) {
7535 default: llvm_unreachable("Illegal opcode!");
7536 case ARM::t2SXTH: NewOpc = ARM::tSXTH; break;
7537 case ARM::t2SXTB: NewOpc = ARM::tSXTB; break;
7538 case ARM::t2UXTH: NewOpc = ARM::tUXTH; break;
7539 case ARM::t2UXTB: NewOpc = ARM::tUXTB; break;
7540 }
Jim Grosbach82213192011-09-19 20:29:33 +00007541 // The operands aren't the same for thumb1 (no rotate operand).
7542 MCInst TmpInst;
7543 TmpInst.setOpcode(NewOpc);
7544 TmpInst.addOperand(Inst.getOperand(0));
7545 TmpInst.addOperand(Inst.getOperand(1));
7546 TmpInst.addOperand(Inst.getOperand(3));
7547 TmpInst.addOperand(Inst.getOperand(4));
7548 Inst = TmpInst;
Jim Grosbachafad0532011-11-10 23:42:14 +00007549 return true;
Jim Grosbach82213192011-09-19 20:29:33 +00007550 }
7551 break;
7552 }
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007553 case ARM::MOVsi: {
7554 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm());
Richard Bartonba5b0cc2012-04-25 18:00:18 +00007555 // rrx shifts and asr/lsr of #32 is encoded as 0
7556 if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr)
7557 return false;
Jim Grosbache2ca9e52011-12-20 00:59:38 +00007558 if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) {
7559 // Shifting by zero is accepted as a vanilla 'MOVr'
7560 MCInst TmpInst;
7561 TmpInst.setOpcode(ARM::MOVr);
7562 TmpInst.addOperand(Inst.getOperand(0));
7563 TmpInst.addOperand(Inst.getOperand(1));
7564 TmpInst.addOperand(Inst.getOperand(3));
7565 TmpInst.addOperand(Inst.getOperand(4));
7566 TmpInst.addOperand(Inst.getOperand(5));
7567 Inst = TmpInst;
7568 return true;
7569 }
7570 return false;
7571 }
Jim Grosbach12ccf452011-12-22 18:04:04 +00007572 case ARM::ANDrsi:
7573 case ARM::ORRrsi:
7574 case ARM::EORrsi:
7575 case ARM::BICrsi:
7576 case ARM::SUBrsi:
7577 case ARM::ADDrsi: {
7578 unsigned newOpc;
7579 ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm());
7580 if (SOpc == ARM_AM::rrx) return false;
7581 switch (Inst.getOpcode()) {
Craig Toppere55c5562012-02-07 02:50:20 +00007582 default: llvm_unreachable("unexpected opcode!");
Jim Grosbach12ccf452011-12-22 18:04:04 +00007583 case ARM::ANDrsi: newOpc = ARM::ANDrr; break;
7584 case ARM::ORRrsi: newOpc = ARM::ORRrr; break;
7585 case ARM::EORrsi: newOpc = ARM::EORrr; break;
7586 case ARM::BICrsi: newOpc = ARM::BICrr; break;
7587 case ARM::SUBrsi: newOpc = ARM::SUBrr; break;
7588 case ARM::ADDrsi: newOpc = ARM::ADDrr; break;
7589 }
7590 // If the shift is by zero, use the non-shifted instruction definition.
Richard Barton35aceb82012-07-09 16:31:14 +00007591 // The exception is for right shifts, where 0 == 32
7592 if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 &&
7593 !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) {
Jim Grosbach12ccf452011-12-22 18:04:04 +00007594 MCInst TmpInst;
7595 TmpInst.setOpcode(newOpc);
7596 TmpInst.addOperand(Inst.getOperand(0));
7597 TmpInst.addOperand(Inst.getOperand(1));
7598 TmpInst.addOperand(Inst.getOperand(2));
7599 TmpInst.addOperand(Inst.getOperand(4));
7600 TmpInst.addOperand(Inst.getOperand(5));
7601 TmpInst.addOperand(Inst.getOperand(6));
7602 Inst = TmpInst;
7603 return true;
7604 }
7605 return false;
7606 }
Jim Grosbach82f76d12012-01-25 19:52:01 +00007607 case ARM::ITasm:
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007608 case ARM::t2IT: {
7609 // The mask bits for all but the first condition are represented as
7610 // the low bit of the condition code value implies 't'. We currently
7611 // always have 1 implies 't', so XOR toggle the bits if the low bit
Richard Bartonf435b092012-04-27 08:42:59 +00007612 // of the condition code is zero.
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007613 MCOperand &MO = Inst.getOperand(1);
7614 unsigned Mask = MO.getImm();
Jim Grosbached16ec42011-08-29 22:24:09 +00007615 unsigned OrigMask = Mask;
Michael J. Spencerdf1ecbd72013-05-24 22:23:49 +00007616 unsigned TZ = countTrailingZeros(Mask);
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007617 if ((Inst.getOperand(0).getImm() & 1) == 0) {
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007618 assert(Mask && TZ <= 3 && "illegal IT mask value!");
Benjamin Kramer8bad66e2013-05-19 22:01:57 +00007619 Mask ^= (0xE << TZ) & 0xF;
Richard Bartonf435b092012-04-27 08:42:59 +00007620 }
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007621 MO.setImm(Mask);
Jim Grosbached16ec42011-08-29 22:24:09 +00007622
7623 // Set up the IT block state according to the IT instruction we just
7624 // matched.
7625 assert(!inITBlock() && "nested IT blocks?!");
7626 ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm());
7627 ITState.Mask = OrigMask; // Use the original mask, not the updated one.
7628 ITState.CurPosition = 0;
7629 ITState.FirstCond = true;
Jim Grosbach3d1eac82011-08-26 21:43:41 +00007630 break;
7631 }
Richard Bartona39625e2012-07-09 16:12:24 +00007632 case ARM::t2LSLrr:
7633 case ARM::t2LSRrr:
7634 case ARM::t2ASRrr:
7635 case ARM::t2SBCrr:
7636 case ARM::t2RORrr:
7637 case ARM::t2BICrr:
7638 {
Richard Bartond5660372012-07-09 16:14:28 +00007639 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007640 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7641 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7642 Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007643 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7644 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007645 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7646 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7647 unsigned NewOpc;
7648 switch (Inst.getOpcode()) {
7649 default: llvm_unreachable("unexpected opcode");
7650 case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break;
7651 case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break;
7652 case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break;
7653 case ARM::t2SBCrr: NewOpc = ARM::tSBC; break;
7654 case ARM::t2RORrr: NewOpc = ARM::tROR; break;
7655 case ARM::t2BICrr: NewOpc = ARM::tBIC; break;
7656 }
7657 MCInst TmpInst;
7658 TmpInst.setOpcode(NewOpc);
7659 TmpInst.addOperand(Inst.getOperand(0));
7660 TmpInst.addOperand(Inst.getOperand(5));
7661 TmpInst.addOperand(Inst.getOperand(1));
7662 TmpInst.addOperand(Inst.getOperand(2));
7663 TmpInst.addOperand(Inst.getOperand(3));
7664 TmpInst.addOperand(Inst.getOperand(4));
7665 Inst = TmpInst;
7666 return true;
7667 }
7668 return false;
7669 }
7670 case ARM::t2ANDrr:
7671 case ARM::t2EORrr:
7672 case ARM::t2ADCrr:
7673 case ARM::t2ORRrr:
7674 {
Richard Bartond5660372012-07-09 16:14:28 +00007675 // Assemblers should use the narrow encodings of these instructions when permissible.
Richard Bartona39625e2012-07-09 16:12:24 +00007676 // These instructions are special in that they are commutable, so shorter encodings
7677 // are available more often.
7678 if ((isARMLowRegister(Inst.getOperand(1).getReg()) &&
7679 isARMLowRegister(Inst.getOperand(2).getReg())) &&
7680 (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() ||
7681 Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) &&
Richard Barton984d0ba2012-07-09 18:30:56 +00007682 ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) ||
7683 (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) &&
Richard Bartona39625e2012-07-09 16:12:24 +00007684 (!static_cast<ARMOperand*>(Operands[3])->isToken() ||
7685 !static_cast<ARMOperand*>(Operands[3])->getToken().equals_lower(".w"))) {
7686 unsigned NewOpc;
7687 switch (Inst.getOpcode()) {
7688 default: llvm_unreachable("unexpected opcode");
7689 case ARM::t2ADCrr: NewOpc = ARM::tADC; break;
7690 case ARM::t2ANDrr: NewOpc = ARM::tAND; break;
7691 case ARM::t2EORrr: NewOpc = ARM::tEOR; break;
7692 case ARM::t2ORRrr: NewOpc = ARM::tORR; break;
7693 }
7694 MCInst TmpInst;
7695 TmpInst.setOpcode(NewOpc);
7696 TmpInst.addOperand(Inst.getOperand(0));
7697 TmpInst.addOperand(Inst.getOperand(5));
7698 if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) {
7699 TmpInst.addOperand(Inst.getOperand(1));
7700 TmpInst.addOperand(Inst.getOperand(2));
7701 } else {
7702 TmpInst.addOperand(Inst.getOperand(2));
7703 TmpInst.addOperand(Inst.getOperand(1));
7704 }
7705 TmpInst.addOperand(Inst.getOperand(3));
7706 TmpInst.addOperand(Inst.getOperand(4));
7707 Inst = TmpInst;
7708 return true;
7709 }
7710 return false;
7711 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007712 }
Jim Grosbachafad0532011-11-10 23:42:14 +00007713 return false;
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007714}
7715
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007716unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
7717 // 16-bit thumb arithmetic instructions either require or preclude the 'S'
7718 // suffix depending on whether they're in an IT block or not.
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007719 unsigned Opc = Inst.getOpcode();
Joey Gouly0e76fa72013-09-12 10:28:05 +00007720 const MCInstrDesc &MCID = MII.get(Opc);
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007721 if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) {
7722 assert(MCID.hasOptionalDef() &&
7723 "optionally flag setting instruction missing optional def operand");
7724 assert(MCID.NumOperands == Inst.getNumOperands() &&
7725 "operand count mismatch!");
7726 // Find the optional-def operand (cc_out).
7727 unsigned OpNo;
7728 for (OpNo = 0;
7729 !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands;
7730 ++OpNo)
7731 ;
7732 // If we're parsing Thumb1, reject it completely.
7733 if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR)
7734 return Match_MnemonicFail;
7735 // If we're parsing Thumb2, which form is legal depends on whether we're
7736 // in an IT block.
Jim Grosbached16ec42011-08-29 22:24:09 +00007737 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR &&
7738 !inITBlock())
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007739 return Match_RequiresITBlock;
Jim Grosbached16ec42011-08-29 22:24:09 +00007740 if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR &&
7741 inITBlock())
7742 return Match_RequiresNotITBlock;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007743 }
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007744 // Some high-register supporting Thumb1 encodings only allow both registers
7745 // to be from r0-r7 when in Thumb2.
7746 else if (Opc == ARM::tADDhirr && isThumbOne() &&
7747 isARMLowRegister(Inst.getOperand(1).getReg()) &&
7748 isARMLowRegister(Inst.getOperand(2).getReg()))
7749 return Match_RequiresThumb2;
7750 // Others only require ARMv6 or later.
Jim Grosbachf86cd372011-08-19 20:46:54 +00007751 else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() &&
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007752 isARMLowRegister(Inst.getOperand(0).getReg()) &&
7753 isARMLowRegister(Inst.getOperand(1).getReg()))
7754 return Match_RequiresV6;
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007755 return Match_Success;
7756}
7757
Jim Grosbach5117ef72012-04-24 22:40:08 +00007758static const char *getSubtargetFeatureName(unsigned Val);
Chris Lattner9487de62010-10-28 21:28:01 +00007759bool ARMAsmParser::
Chad Rosier49963552012-10-13 00:26:04 +00007760MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
Chris Lattner9487de62010-10-28 21:28:01 +00007761 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chad Rosier49963552012-10-13 00:26:04 +00007762 MCStreamer &Out, unsigned &ErrorInfo,
7763 bool MatchingInlineAsm) {
Chris Lattner9487de62010-10-28 21:28:01 +00007764 MCInst Inst;
Jim Grosbach120a96a2011-08-15 23:03:29 +00007765 unsigned MatchResult;
Weiming Zhao8f56f882012-11-16 21:55:34 +00007766
Chad Rosier2f480a82012-10-12 22:53:36 +00007767 MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo,
Chad Rosier49963552012-10-13 00:26:04 +00007768 MatchingInlineAsm);
Kevin Enderby3164a342010-12-09 19:19:43 +00007769 switch (MatchResult) {
Jim Grosbach120a96a2011-08-15 23:03:29 +00007770 default: break;
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007771 case Match_Success:
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007772 // Context sensitive operand constraints aren't handled by the matcher,
7773 // so check them here.
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007774 if (validateInstruction(Inst, Operands)) {
7775 // Still progress the IT block, otherwise one wrong condition causes
7776 // nasty cascading errors.
7777 forwardITPosition();
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007778 return true;
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007779 }
Jim Grosbachedaa35a2011-07-26 18:25:39 +00007780
Amara Emerson52cfb6a2013-10-03 09:31:51 +00007781 { // processInstruction() updates inITBlock state, we need to save it away
7782 bool wasInITBlock = inITBlock();
7783
7784 // Some instructions need post-processing to, for example, tweak which
7785 // encoding is selected. Loop on it while changes happen so the
7786 // individual transformations can chain off each other. E.g.,
7787 // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8)
7788 while (processInstruction(Inst, Operands))
7789 ;
7790
7791 // Only after the instruction is fully processed, we can validate it
7792 if (wasInITBlock && hasV8Ops() && isThumb() &&
7793 !isV8EligibleForIT(&Inst, 2)) {
7794 Warning(IDLoc, "deprecated instruction in IT block");
7795 }
7796 }
Jim Grosbach8ba76c62011-08-11 17:35:48 +00007797
Jim Grosbacha0d34d32011-09-02 23:22:08 +00007798 // Only move forward at the very end so that everything in validate
7799 // and process gets a consistent answer about whether we're in an IT
7800 // block.
7801 forwardITPosition();
7802
Jim Grosbach82f76d12012-01-25 19:52:01 +00007803 // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and
7804 // doesn't actually encode.
7805 if (Inst.getOpcode() == ARM::ITasm)
7806 return false;
7807
Jim Grosbach5e5eabb2012-01-26 23:20:15 +00007808 Inst.setLoc(IDLoc);
Chris Lattner9487de62010-10-28 21:28:01 +00007809 Out.EmitInstruction(Inst);
7810 return false;
Jim Grosbach5117ef72012-04-24 22:40:08 +00007811 case Match_MissingFeature: {
7812 assert(ErrorInfo && "Unknown missing feature!");
7813 // Special case the error message for the very common case where only
7814 // a single subtarget feature is missing (Thumb vs. ARM, e.g.).
7815 std::string Msg = "instruction requires:";
7816 unsigned Mask = 1;
7817 for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) {
7818 if (ErrorInfo & Mask) {
7819 Msg += " ";
7820 Msg += getSubtargetFeatureName(ErrorInfo & Mask);
7821 }
7822 Mask <<= 1;
7823 }
7824 return Error(IDLoc, Msg);
7825 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007826 case Match_InvalidOperand: {
7827 SMLoc ErrorLoc = IDLoc;
7828 if (ErrorInfo != ~0U) {
7829 if (ErrorInfo >= Operands.size())
7830 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach624bcc72010-10-29 14:46:02 +00007831
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007832 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7833 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7834 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007835
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007836 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattner9487de62010-10-28 21:28:01 +00007837 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007838 case Match_MnemonicFail:
Benjamin Kramer673824b2012-04-15 17:04:27 +00007839 return Error(IDLoc, "invalid instruction",
7840 ((ARMOperand*)Operands[0])->getLocRange());
Jim Grosbached16ec42011-08-29 22:24:09 +00007841 case Match_RequiresNotITBlock:
7842 return Error(IDLoc, "flag setting instruction only valid outside IT block");
Jim Grosbach3e941ae2011-08-16 20:45:50 +00007843 case Match_RequiresITBlock:
7844 return Error(IDLoc, "instruction only valid inside IT block");
Jim Grosbachb7fa2c02011-08-16 22:20:01 +00007845 case Match_RequiresV6:
7846 return Error(IDLoc, "instruction variant requires ARMv6 or later");
7847 case Match_RequiresThumb2:
7848 return Error(IDLoc, "instruction variant requires Thumb2");
Jim Grosbach087affe2012-06-22 23:56:48 +00007849 case Match_ImmRange0_15: {
7850 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7851 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7852 return Error(ErrorLoc, "immediate operand must be in the range [0,15]");
7853 }
Artyom Skrobovfc12e702013-10-23 10:14:40 +00007854 case Match_ImmRange0_239: {
7855 SMLoc ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
7856 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
7857 return Error(ErrorLoc, "immediate operand must be in the range [0,239]");
7858 }
Chris Lattnerd27b05e2010-10-28 21:41:58 +00007859 }
Jim Grosbach624bcc72010-10-29 14:46:02 +00007860
Eric Christopher91d7b902010-10-29 09:26:59 +00007861 llvm_unreachable("Implement any new match types added!");
Chris Lattner9487de62010-10-28 21:28:01 +00007862}
7863
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007864/// parseDirective parses the arm specific directives
Kevin Enderbyccab3172009-09-15 00:27:25 +00007865bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
7866 StringRef IDVal = DirectiveID.getIdentifier();
7867 if (IDVal == ".word")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007868 return parseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007869 else if (IDVal == ".thumb")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007870 return parseDirectiveThumb(DirectiveID.getLoc());
Jim Grosbach7f882392011-12-07 18:04:19 +00007871 else if (IDVal == ".arm")
7872 return parseDirectiveARM(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007873 else if (IDVal == ".thumb_func")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007874 return parseDirectiveThumbFunc(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007875 else if (IDVal == ".code")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007876 return parseDirectiveCode(DirectiveID.getLoc());
Kevin Enderby146dcf22009-10-15 20:48:48 +00007877 else if (IDVal == ".syntax")
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007878 return parseDirectiveSyntax(DirectiveID.getLoc());
Jim Grosbachab5830e2011-12-14 02:16:11 +00007879 else if (IDVal == ".unreq")
7880 return parseDirectiveUnreq(DirectiveID.getLoc());
Jason W Kim135d2442011-12-20 17:38:12 +00007881 else if (IDVal == ".arch")
7882 return parseDirectiveArch(DirectiveID.getLoc());
7883 else if (IDVal == ".eabi_attribute")
7884 return parseDirectiveEabiAttr(DirectiveID.getLoc());
Logan Chien8cbb80d2013-10-28 17:51:12 +00007885 else if (IDVal == ".cpu")
7886 return parseDirectiveCPU(DirectiveID.getLoc());
7887 else if (IDVal == ".fpu")
7888 return parseDirectiveFPU(DirectiveID.getLoc());
Logan Chien4ea23b52013-05-10 16:17:24 +00007889 else if (IDVal == ".fnstart")
7890 return parseDirectiveFnStart(DirectiveID.getLoc());
7891 else if (IDVal == ".fnend")
7892 return parseDirectiveFnEnd(DirectiveID.getLoc());
7893 else if (IDVal == ".cantunwind")
7894 return parseDirectiveCantUnwind(DirectiveID.getLoc());
7895 else if (IDVal == ".personality")
7896 return parseDirectivePersonality(DirectiveID.getLoc());
7897 else if (IDVal == ".handlerdata")
7898 return parseDirectiveHandlerData(DirectiveID.getLoc());
7899 else if (IDVal == ".setfp")
7900 return parseDirectiveSetFP(DirectiveID.getLoc());
7901 else if (IDVal == ".pad")
7902 return parseDirectivePad(DirectiveID.getLoc());
7903 else if (IDVal == ".save")
7904 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
7905 else if (IDVal == ".vsave")
7906 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00007907 else if (IDVal == ".inst")
7908 return parseDirectiveInst(DirectiveID.getLoc());
7909 else if (IDVal == ".inst.n")
7910 return parseDirectiveInst(DirectiveID.getLoc(), 'n');
7911 else if (IDVal == ".inst.w")
7912 return parseDirectiveInst(DirectiveID.getLoc(), 'w');
Saleem Abdulrasool6e6c2392013-12-20 07:21:16 +00007913 else if (IDVal == ".ltorg" || IDVal == ".pool")
David Peixotto80c083a2013-12-19 18:26:07 +00007914 return parseDirectiveLtorg(DirectiveID.getLoc());
Kevin Enderbyccab3172009-09-15 00:27:25 +00007915 return true;
7916}
7917
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007918/// parseDirectiveWord
Kevin Enderbyccab3172009-09-15 00:27:25 +00007919/// ::= .word [ expression (, expression)* ]
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007920bool ARMAsmParser::parseDirectiveWord(unsigned Size, SMLoc L) {
Kevin Enderbyccab3172009-09-15 00:27:25 +00007921 if (getLexer().isNot(AsmToken::EndOfStatement)) {
7922 for (;;) {
7923 const MCExpr *Value;
Jim Grosbachd2037eb2013-02-20 22:21:35 +00007924 if (getParser().parseExpression(Value))
Kevin Enderbyccab3172009-09-15 00:27:25 +00007925 return true;
7926
Eric Christopherbf7bc492013-01-09 03:52:05 +00007927 getParser().getStreamer().EmitValue(Value, Size);
Kevin Enderbyccab3172009-09-15 00:27:25 +00007928
7929 if (getLexer().is(AsmToken::EndOfStatement))
7930 break;
Jim Grosbach624bcc72010-10-29 14:46:02 +00007931
Kevin Enderbyccab3172009-09-15 00:27:25 +00007932 // FIXME: Improve diagnostic.
7933 if (getLexer().isNot(AsmToken::Comma))
7934 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007935 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007936 }
7937 }
7938
Sean Callanana83fd7d2010-01-19 20:27:46 +00007939 Parser.Lex();
Kevin Enderbyccab3172009-09-15 00:27:25 +00007940 return false;
7941}
7942
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007943/// parseDirectiveThumb
Kevin Enderby146dcf22009-10-15 20:48:48 +00007944/// ::= .thumb
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007945bool ARMAsmParser::parseDirectiveThumb(SMLoc L) {
Kevin Enderby146dcf22009-10-15 20:48:48 +00007946 if (getLexer().isNot(AsmToken::EndOfStatement))
7947 return Error(L, "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00007948 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00007949
Tim Northovera2292d02013-06-10 23:20:58 +00007950 if (!hasThumb())
7951 return Error(L, "target does not support Thumb mode");
7952
Jim Grosbach7f882392011-12-07 18:04:19 +00007953 if (!isThumb())
7954 SwitchMode();
7955 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
7956 return false;
7957}
7958
7959/// parseDirectiveARM
7960/// ::= .arm
7961bool ARMAsmParser::parseDirectiveARM(SMLoc L) {
7962 if (getLexer().isNot(AsmToken::EndOfStatement))
7963 return Error(L, "unexpected token in directive");
7964 Parser.Lex();
7965
Tim Northovera2292d02013-06-10 23:20:58 +00007966 if (!hasARM())
7967 return Error(L, "target does not support ARM mode");
7968
Jim Grosbach7f882392011-12-07 18:04:19 +00007969 if (isThumb())
7970 SwitchMode();
7971 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Kevin Enderby146dcf22009-10-15 20:48:48 +00007972 return false;
7973}
7974
Tim Northover1744d0a2013-10-25 12:49:50 +00007975void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) {
7976 if (NextSymbolIsThumb) {
7977 getParser().getStreamer().EmitThumbFunc(Symbol);
7978 NextSymbolIsThumb = false;
7979 }
7980}
7981
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007982/// parseDirectiveThumbFunc
Kevin Enderby146dcf22009-10-15 20:48:48 +00007983/// ::= .thumbfunc symbol_name
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00007984bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
Bill Wendlingbc07a892013-06-18 07:20:20 +00007985 const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo();
7986 bool isMachO = MAI->hasSubsectionsViaSymbols();
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007987
Jim Grosbach1152cc02011-12-21 22:30:16 +00007988 // Darwin asm has (optionally) function name after .thumb_func direction
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00007989 // ELF doesn't
7990 if (isMachO) {
7991 const AsmToken &Tok = Parser.getTok();
Jim Grosbach1152cc02011-12-21 22:30:16 +00007992 if (Tok.isNot(AsmToken::EndOfStatement)) {
7993 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
7994 return Error(L, "unexpected token in .thumb_func directive");
Tim Northover1744d0a2013-10-25 12:49:50 +00007995 MCSymbol *Func =
7996 getParser().getContext().GetOrCreateSymbol(Tok.getIdentifier());
7997 getParser().getStreamer().EmitThumbFunc(Func);
Jim Grosbach1152cc02011-12-21 22:30:16 +00007998 Parser.Lex(); // Consume the identifier token.
Tim Northover1744d0a2013-10-25 12:49:50 +00007999 return false;
Jim Grosbach1152cc02011-12-21 22:30:16 +00008000 }
Rafael Espindolae90c1cb2011-05-16 16:17:21 +00008001 }
8002
Jim Grosbach1152cc02011-12-21 22:30:16 +00008003 if (getLexer().isNot(AsmToken::EndOfStatement))
Kevin Enderby146dcf22009-10-15 20:48:48 +00008004 return Error(L, "unexpected token in directive");
Jim Grosbach1152cc02011-12-21 22:30:16 +00008005
Tim Northover1744d0a2013-10-25 12:49:50 +00008006 NextSymbolIsThumb = true;
Kevin Enderby146dcf22009-10-15 20:48:48 +00008007
Kevin Enderby146dcf22009-10-15 20:48:48 +00008008 return false;
8009}
8010
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008011/// parseDirectiveSyntax
Kevin Enderby146dcf22009-10-15 20:48:48 +00008012/// ::= .syntax unified | divided
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008013bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00008014 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008015 if (Tok.isNot(AsmToken::Identifier))
8016 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer92d89982010-07-14 22:38:02 +00008017 StringRef Mode = Tok.getString();
Duncan Sands257eba42010-06-29 13:04:35 +00008018 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callanana83fd7d2010-01-19 20:27:46 +00008019 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00008020 else if (Mode == "divided" || Mode == "DIVIDED")
Kevin Enderbye9f2f0c2011-01-27 23:22:36 +00008021 return Error(L, "'.syntax divided' arm asssembly not supported");
Kevin Enderby146dcf22009-10-15 20:48:48 +00008022 else
8023 return Error(L, "unrecognized syntax mode in .syntax directive");
8024
8025 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00008026 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00008027 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008028
8029 // TODO tell the MC streamer the mode
8030 // getParser().getStreamer().Emit???();
8031 return false;
8032}
8033
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008034/// parseDirectiveCode
Kevin Enderby146dcf22009-10-15 20:48:48 +00008035/// ::= .code 16 | 32
Jim Grosbacheab1c0d2011-07-26 17:10:22 +00008036bool ARMAsmParser::parseDirectiveCode(SMLoc L) {
Sean Callanan936b0d32010-01-19 21:44:56 +00008037 const AsmToken &Tok = Parser.getTok();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008038 if (Tok.isNot(AsmToken::Integer))
8039 return Error(L, "unexpected token in .code directive");
Sean Callanan936b0d32010-01-19 21:44:56 +00008040 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands257eba42010-06-29 13:04:35 +00008041 if (Val == 16)
Sean Callanana83fd7d2010-01-19 20:27:46 +00008042 Parser.Lex();
Duncan Sands257eba42010-06-29 13:04:35 +00008043 else if (Val == 32)
Sean Callanana83fd7d2010-01-19 20:27:46 +00008044 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008045 else
8046 return Error(L, "invalid operand to .code directive");
8047
8048 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan936b0d32010-01-19 21:44:56 +00008049 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callanana83fd7d2010-01-19 20:27:46 +00008050 Parser.Lex();
Kevin Enderby146dcf22009-10-15 20:48:48 +00008051
Evan Cheng284b4672011-07-08 22:36:29 +00008052 if (Val == 16) {
Tim Northovera2292d02013-06-10 23:20:58 +00008053 if (!hasThumb())
8054 return Error(L, "target does not support Thumb mode");
8055
Jim Grosbachf471ac32011-09-06 18:46:23 +00008056 if (!isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00008057 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00008058 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
Evan Cheng284b4672011-07-08 22:36:29 +00008059 } else {
Tim Northovera2292d02013-06-10 23:20:58 +00008060 if (!hasARM())
8061 return Error(L, "target does not support ARM mode");
8062
Jim Grosbachf471ac32011-09-06 18:46:23 +00008063 if (isThumb())
Evan Cheng91111d22011-07-09 05:47:46 +00008064 SwitchMode();
Jim Grosbachf471ac32011-09-06 18:46:23 +00008065 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
Evan Cheng45543ba2011-07-08 22:49:55 +00008066 }
Jim Grosbach2db0ea02010-11-05 22:40:53 +00008067
Kevin Enderby146dcf22009-10-15 20:48:48 +00008068 return false;
8069}
8070
Jim Grosbachab5830e2011-12-14 02:16:11 +00008071/// parseDirectiveReq
8072/// ::= name .req registername
8073bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) {
8074 Parser.Lex(); // Eat the '.req' token.
8075 unsigned Reg;
8076 SMLoc SRegLoc, ERegLoc;
8077 if (ParseRegister(Reg, SRegLoc, ERegLoc)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008078 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00008079 return Error(SRegLoc, "register name expected");
8080 }
8081
8082 // Shouldn't be anything else.
8083 if (Parser.getTok().isNot(AsmToken::EndOfStatement)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008084 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00008085 return Error(Parser.getTok().getLoc(),
8086 "unexpected input in .req directive.");
8087 }
8088
8089 Parser.Lex(); // Consume the EndOfStatement
8090
8091 if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg)
8092 return Error(SRegLoc, "redefinition of '" + Name +
8093 "' does not match original.");
8094
8095 return false;
8096}
8097
8098/// parseDirectiveUneq
8099/// ::= .unreq registername
8100bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) {
8101 if (Parser.getTok().isNot(AsmToken::Identifier)) {
Jim Grosbachd2037eb2013-02-20 22:21:35 +00008102 Parser.eatToEndOfStatement();
Jim Grosbachab5830e2011-12-14 02:16:11 +00008103 return Error(L, "unexpected input in .unreq directive.");
8104 }
8105 RegisterReqs.erase(Parser.getTok().getIdentifier());
8106 Parser.Lex(); // Eat the identifier.
8107 return false;
8108}
8109
Jason W Kim135d2442011-12-20 17:38:12 +00008110/// parseDirectiveArch
8111/// ::= .arch token
8112bool ARMAsmParser::parseDirectiveArch(SMLoc L) {
Logan Chien439e8f92013-12-11 17:16:25 +00008113 StringRef Arch = getParser().parseStringToEndOfStatement().trim();
8114
8115 unsigned ID = StringSwitch<unsigned>(Arch)
8116#define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \
8117 .Case(NAME, ARM::ID)
8118#include "MCTargetDesc/ARMArchName.def"
8119 .Default(ARM::INVALID_ARCH);
8120
8121 if (ID == ARM::INVALID_ARCH)
8122 return Error(L, "Unknown arch name");
8123
8124 getTargetStreamer().emitArch(ID);
8125 return false;
Jason W Kim135d2442011-12-20 17:38:12 +00008126}
8127
8128/// parseDirectiveEabiAttr
8129/// ::= .eabi_attribute int, int
8130bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
Logan Chien8cbb80d2013-10-28 17:51:12 +00008131 if (Parser.getTok().isNot(AsmToken::Integer))
8132 return Error(L, "integer expected");
8133 int64_t Tag = Parser.getTok().getIntVal();
8134 Parser.Lex(); // eat tag integer
8135
8136 if (Parser.getTok().isNot(AsmToken::Comma))
8137 return Error(L, "comma expected");
8138 Parser.Lex(); // skip comma
8139
8140 L = Parser.getTok().getLoc();
8141 if (Parser.getTok().isNot(AsmToken::Integer))
8142 return Error(L, "integer expected");
8143 int64_t Value = Parser.getTok().getIntVal();
8144 Parser.Lex(); // eat value integer
8145
8146 getTargetStreamer().emitAttribute(Tag, Value);
8147 return false;
8148}
8149
8150/// parseDirectiveCPU
8151/// ::= .cpu str
8152bool ARMAsmParser::parseDirectiveCPU(SMLoc L) {
8153 StringRef CPU = getParser().parseStringToEndOfStatement().trim();
8154 getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name, CPU);
8155 return false;
8156}
8157
8158/// parseDirectiveFPU
8159/// ::= .fpu str
8160bool ARMAsmParser::parseDirectiveFPU(SMLoc L) {
8161 StringRef FPU = getParser().parseStringToEndOfStatement().trim();
8162
8163 unsigned ID = StringSwitch<unsigned>(FPU)
8164#define ARM_FPU_NAME(NAME, ID) .Case(NAME, ARM::ID)
8165#include "ARMFPUName.def"
8166 .Default(ARM::INVALID_FPU);
8167
8168 if (ID == ARM::INVALID_FPU)
8169 return Error(L, "Unknown FPU name");
8170
8171 getTargetStreamer().emitFPU(ID);
8172 return false;
Jason W Kim135d2442011-12-20 17:38:12 +00008173}
8174
Logan Chien4ea23b52013-05-10 16:17:24 +00008175/// parseDirectiveFnStart
8176/// ::= .fnstart
8177bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
8178 if (FnStartLoc.isValid()) {
8179 Error(L, ".fnstart starts before the end of previous one");
8180 Error(FnStartLoc, "previous .fnstart starts here");
8181 return true;
8182 }
8183
8184 FnStartLoc = L;
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008185 getTargetStreamer().emitFnStart();
Logan Chien4ea23b52013-05-10 16:17:24 +00008186 return false;
8187}
8188
8189/// parseDirectiveFnEnd
8190/// ::= .fnend
8191bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
8192 // Check the ordering of unwind directives
8193 if (!FnStartLoc.isValid())
8194 return Error(L, ".fnstart must precede .fnend directive");
8195
8196 // Reset the unwind directives parser state
8197 resetUnwindDirectiveParserState();
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008198 getTargetStreamer().emitFnEnd();
Logan Chien4ea23b52013-05-10 16:17:24 +00008199 return false;
8200}
8201
8202/// parseDirectiveCantUnwind
8203/// ::= .cantunwind
8204bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
8205 // Check the ordering of unwind directives
8206 CantUnwindLoc = L;
8207 if (!FnStartLoc.isValid())
8208 return Error(L, ".fnstart must precede .cantunwind directive");
8209 if (HandlerDataLoc.isValid()) {
8210 Error(L, ".cantunwind can't be used with .handlerdata directive");
8211 Error(HandlerDataLoc, ".handlerdata was specified here");
8212 return true;
8213 }
8214 if (PersonalityLoc.isValid()) {
8215 Error(L, ".cantunwind can't be used with .personality directive");
8216 Error(PersonalityLoc, ".personality was specified here");
8217 return true;
8218 }
8219
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008220 getTargetStreamer().emitCantUnwind();
Logan Chien4ea23b52013-05-10 16:17:24 +00008221 return false;
8222}
8223
8224/// parseDirectivePersonality
8225/// ::= .personality name
8226bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
8227 // Check the ordering of unwind directives
8228 PersonalityLoc = L;
8229 if (!FnStartLoc.isValid())
8230 return Error(L, ".fnstart must precede .personality directive");
8231 if (CantUnwindLoc.isValid()) {
8232 Error(L, ".personality can't be used with .cantunwind directive");
8233 Error(CantUnwindLoc, ".cantunwind was specified here");
8234 return true;
8235 }
8236 if (HandlerDataLoc.isValid()) {
8237 Error(L, ".personality must precede .handlerdata directive");
8238 Error(HandlerDataLoc, ".handlerdata was specified here");
8239 return true;
8240 }
8241
8242 // Parse the name of the personality routine
8243 if (Parser.getTok().isNot(AsmToken::Identifier)) {
8244 Parser.eatToEndOfStatement();
8245 return Error(L, "unexpected input in .personality directive.");
8246 }
8247 StringRef Name(Parser.getTok().getIdentifier());
8248 Parser.Lex();
8249
8250 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008251 getTargetStreamer().emitPersonality(PR);
Logan Chien4ea23b52013-05-10 16:17:24 +00008252 return false;
8253}
8254
8255/// parseDirectiveHandlerData
8256/// ::= .handlerdata
8257bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
8258 // Check the ordering of unwind directives
8259 HandlerDataLoc = L;
8260 if (!FnStartLoc.isValid())
8261 return Error(L, ".fnstart must precede .personality directive");
8262 if (CantUnwindLoc.isValid()) {
8263 Error(L, ".handlerdata can't be used with .cantunwind directive");
8264 Error(CantUnwindLoc, ".cantunwind was specified here");
8265 return true;
8266 }
8267
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008268 getTargetStreamer().emitHandlerData();
Logan Chien4ea23b52013-05-10 16:17:24 +00008269 return false;
8270}
8271
8272/// parseDirectiveSetFP
8273/// ::= .setfp fpreg, spreg [, offset]
8274bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
8275 // Check the ordering of unwind directives
8276 if (!FnStartLoc.isValid())
8277 return Error(L, ".fnstart must precede .setfp directive");
8278 if (HandlerDataLoc.isValid())
8279 return Error(L, ".setfp must precede .handlerdata directive");
8280
8281 // Parse fpreg
8282 SMLoc NewFPRegLoc = Parser.getTok().getLoc();
8283 int NewFPReg = tryParseRegister();
8284 if (NewFPReg == -1)
8285 return Error(NewFPRegLoc, "frame pointer register expected");
8286
8287 // Consume comma
8288 if (!Parser.getTok().is(AsmToken::Comma))
8289 return Error(Parser.getTok().getLoc(), "comma expected");
8290 Parser.Lex(); // skip comma
8291
8292 // Parse spreg
8293 SMLoc NewSPRegLoc = Parser.getTok().getLoc();
8294 int NewSPReg = tryParseRegister();
8295 if (NewSPReg == -1)
8296 return Error(NewSPRegLoc, "stack pointer register expected");
8297
8298 if (NewSPReg != ARM::SP && NewSPReg != FPReg)
8299 return Error(NewSPRegLoc,
8300 "register should be either $sp or the latest fp register");
8301
8302 // Update the frame pointer register
8303 FPReg = NewFPReg;
8304
8305 // Parse offset
8306 int64_t Offset = 0;
8307 if (Parser.getTok().is(AsmToken::Comma)) {
8308 Parser.Lex(); // skip comma
8309
8310 if (Parser.getTok().isNot(AsmToken::Hash) &&
8311 Parser.getTok().isNot(AsmToken::Dollar)) {
8312 return Error(Parser.getTok().getLoc(), "'#' expected");
8313 }
8314 Parser.Lex(); // skip hash token.
8315
8316 const MCExpr *OffsetExpr;
8317 SMLoc ExLoc = Parser.getTok().getLoc();
8318 SMLoc EndLoc;
8319 if (getParser().parseExpression(OffsetExpr, EndLoc))
8320 return Error(ExLoc, "malformed setfp offset");
8321 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8322 if (!CE)
8323 return Error(ExLoc, "setfp offset must be an immediate");
8324
8325 Offset = CE->getValue();
8326 }
8327
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008328 getTargetStreamer().emitSetFP(static_cast<unsigned>(NewFPReg),
8329 static_cast<unsigned>(NewSPReg), Offset);
Logan Chien4ea23b52013-05-10 16:17:24 +00008330 return false;
8331}
8332
8333/// parseDirective
8334/// ::= .pad offset
8335bool ARMAsmParser::parseDirectivePad(SMLoc L) {
8336 // Check the ordering of unwind directives
8337 if (!FnStartLoc.isValid())
8338 return Error(L, ".fnstart must precede .pad directive");
8339 if (HandlerDataLoc.isValid())
8340 return Error(L, ".pad must precede .handlerdata directive");
8341
8342 // Parse the offset
8343 if (Parser.getTok().isNot(AsmToken::Hash) &&
8344 Parser.getTok().isNot(AsmToken::Dollar)) {
8345 return Error(Parser.getTok().getLoc(), "'#' expected");
8346 }
8347 Parser.Lex(); // skip hash token.
8348
8349 const MCExpr *OffsetExpr;
8350 SMLoc ExLoc = Parser.getTok().getLoc();
8351 SMLoc EndLoc;
8352 if (getParser().parseExpression(OffsetExpr, EndLoc))
8353 return Error(ExLoc, "malformed pad offset");
8354 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr);
8355 if (!CE)
8356 return Error(ExLoc, "pad offset must be an immediate");
8357
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008358 getTargetStreamer().emitPad(CE->getValue());
Logan Chien4ea23b52013-05-10 16:17:24 +00008359 return false;
8360}
8361
8362/// parseDirectiveRegSave
8363/// ::= .save { registers }
8364/// ::= .vsave { registers }
8365bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
8366 // Check the ordering of unwind directives
8367 if (!FnStartLoc.isValid())
8368 return Error(L, ".fnstart must precede .save or .vsave directives");
8369 if (HandlerDataLoc.isValid())
8370 return Error(L, ".save or .vsave must precede .handlerdata directive");
8371
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008372 // RAII object to make sure parsed operands are deleted.
8373 struct CleanupObject {
8374 SmallVector<MCParsedAsmOperand *, 1> Operands;
8375 ~CleanupObject() {
8376 for (unsigned I = 0, E = Operands.size(); I != E; ++I)
8377 delete Operands[I];
8378 }
8379 } CO;
8380
Logan Chien4ea23b52013-05-10 16:17:24 +00008381 // Parse the register list
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008382 if (parseRegisterList(CO.Operands))
Logan Chien4ea23b52013-05-10 16:17:24 +00008383 return true;
Benjamin Kramer23632bd2013-08-03 22:16:24 +00008384 ARMOperand *Op = (ARMOperand*)CO.Operands[0];
Logan Chien4ea23b52013-05-10 16:17:24 +00008385 if (!IsVector && !Op->isRegList())
8386 return Error(L, ".save expects GPR registers");
8387 if (IsVector && !Op->isDPRRegList())
8388 return Error(L, ".vsave expects DPR registers");
8389
Rafael Espindolaa17151a2013-10-08 13:08:17 +00008390 getTargetStreamer().emitRegSave(Op->getRegList(), IsVector);
Logan Chien4ea23b52013-05-10 16:17:24 +00008391 return false;
8392}
8393
Saleem Abdulrasoolc0da2cb2013-12-19 05:17:58 +00008394/// parseDirectiveInst
8395/// ::= .inst opcode [, ...]
8396/// ::= .inst.n opcode [, ...]
8397/// ::= .inst.w opcode [, ...]
8398bool ARMAsmParser::parseDirectiveInst(SMLoc Loc, char Suffix) {
8399 int Width;
8400
8401 if (isThumb()) {
8402 switch (Suffix) {
8403 case 'n':
8404 Width = 2;
8405 break;
8406 case 'w':
8407 Width = 4;
8408 break;
8409 default:
8410 Parser.eatToEndOfStatement();
8411 return Error(Loc, "cannot determine Thumb instruction size, "
8412 "use inst.n/inst.w instead");
8413 }
8414 } else {
8415 if (Suffix) {
8416 Parser.eatToEndOfStatement();
8417 return Error(Loc, "width suffixes are invalid in ARM mode");
8418 }
8419 Width = 4;
8420 }
8421
8422 if (getLexer().is(AsmToken::EndOfStatement)) {
8423 Parser.eatToEndOfStatement();
8424 return Error(Loc, "expected expression following directive");
8425 }
8426
8427 for (;;) {
8428 const MCExpr *Expr;
8429
8430 if (getParser().parseExpression(Expr))
8431 return Error(Loc, "expected expression");
8432
8433 const MCConstantExpr *Value = dyn_cast_or_null<MCConstantExpr>(Expr);
8434 if (!Value)
8435 return Error(Loc, "expected constant expression");
8436
8437 switch (Width) {
8438 case 2:
8439 if (Value->getValue() > 0xffff)
8440 return Error(Loc, "inst.n operand is too big, use inst.w instead");
8441 break;
8442 case 4:
8443 if (Value->getValue() > 0xffffffff)
8444 return Error(Loc,
8445 StringRef(Suffix ? "inst.w" : "inst") + " operand is too big");
8446 break;
8447 default:
8448 llvm_unreachable("only supported widths are 2 and 4");
8449 }
8450
8451 getTargetStreamer().emitInst(Value->getValue(), Suffix);
8452
8453 if (getLexer().is(AsmToken::EndOfStatement))
8454 break;
8455
8456 if (getLexer().isNot(AsmToken::Comma))
8457 return Error(Loc, "unexpected token in directive");
8458
8459 Parser.Lex();
8460 }
8461
8462 Parser.Lex();
8463 return false;
8464}
8465
David Peixotto80c083a2013-12-19 18:26:07 +00008466/// parseDirectiveLtorg
Saleem Abdulrasool6e6c2392013-12-20 07:21:16 +00008467/// ::= .ltorg | .pool
David Peixotto80c083a2013-12-19 18:26:07 +00008468bool ARMAsmParser::parseDirectiveLtorg(SMLoc L) {
8469 MCStreamer &Streamer = getParser().getStreamer();
8470 const MCSection *Section = Streamer.getCurrentSection().first;
8471
8472 if (ConstantPool *CP = getConstantPool(Section)) {
David Peixotto52303f62013-12-19 22:41:56 +00008473 if (!CP->empty())
8474 CP->emitEntries(Streamer);
David Peixotto80c083a2013-12-19 18:26:07 +00008475 }
8476 return false;
8477}
8478
Kevin Enderby8be42bd2009-10-30 22:55:57 +00008479/// Force static initialization.
Kevin Enderbyccab3172009-09-15 00:27:25 +00008480extern "C" void LLVMInitializeARMAsmParser() {
Evan Cheng11424442011-07-26 00:24:13 +00008481 RegisterMCAsmParser<ARMAsmParser> X(TheARMTarget);
8482 RegisterMCAsmParser<ARMAsmParser> Y(TheThumbTarget);
Kevin Enderbyccab3172009-09-15 00:27:25 +00008483}
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00008484
Chris Lattner3e4582a2010-09-06 19:11:01 +00008485#define GET_REGISTER_MATCHER
Craig Topper3ec7c2a2012-04-25 06:56:34 +00008486#define GET_SUBTARGET_FEATURE_NAME
Chris Lattner3e4582a2010-09-06 19:11:01 +00008487#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar5cd4d0f2010-08-11 05:24:50 +00008488#include "ARMGenAsmMatcher.inc"
Jim Grosbach231e7aa2013-02-06 06:00:11 +00008489
8490// Define this matcher function after the auto-generated include so we
8491// have the match class enum definitions.
8492unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand *AsmOp,
8493 unsigned Kind) {
8494 ARMOperand *Op = static_cast<ARMOperand*>(AsmOp);
8495 // If the kind is a token for a literal immediate, check if our asm
8496 // operand matches. This is for InstAliases which have a fixed-value
8497 // immediate in the syntax.
8498 if (Kind == MCK__35_0 && Op->isImm()) {
8499 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op->getImm());
8500 if (!CE)
8501 return Match_InvalidOperand;
8502 if (CE->getValue() == 0)
8503 return Match_Success;
8504 }
8505 return Match_InvalidOperand;
8506}
David Peixottoe407d092013-12-19 18:12:36 +00008507
8508void ARMAsmParser::finishParse() {
8509 // Dump contents of assembler constant pools.
8510 MCStreamer &Streamer = getParser().getStreamer();
8511 for (ConstantPoolMapTy::iterator CPI = ConstantPools.begin(),
8512 CPE = ConstantPools.end();
8513 CPI != CPE; ++CPI) {
8514 const MCSection *Section = CPI->first;
8515 ConstantPool &CP = CPI->second;
8516
David Peixotto52303f62013-12-19 22:41:56 +00008517 // Dump non-empty assembler constant pools at the end of the section.
8518 if (!CP.empty()) {
8519 Streamer.SwitchSection(Section);
8520 CP.emitEntries(Streamer);
8521 }
David Peixottoe407d092013-12-19 18:12:36 +00008522 }
8523}