Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 1 | //===-- 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 Chien | 8cbb80d | 2013-10-28 17:51:12 +0000 | [diff] [blame] | 10 | #include "ARMFPUName.h" |
Amara Emerson | 52cfb6a | 2013-10-03 09:31:51 +0000 | [diff] [blame] | 11 | #include "ARMFeatures.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 12 | #include "MCTargetDesc/ARMAddressingModes.h" |
Logan Chien | 439e8f9 | 2013-12-11 17:16:25 +0000 | [diff] [blame] | 13 | #include "MCTargetDesc/ARMArchName.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 14 | #include "MCTargetDesc/ARMBaseInfo.h" |
| 15 | #include "MCTargetDesc/ARMMCExpr.h" |
Evan Cheng | 1142444 | 2011-07-26 00:24:13 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/STLExtras.h" |
Chris Lattner | 00646cf | 2010-01-22 01:44:57 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/SmallVector.h" |
Saleem Abdulrasool | c0da2cb | 2013-12-19 05:17:58 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/StringExtras.h" |
Daniel Dunbar | 188b47b | 2010-08-11 06:37:20 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/StringSwitch.h" |
Chris Lattner | 00646cf | 2010-01-22 01:44:57 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/Twine.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 21 | #include "llvm/MC/MCAsmInfo.h" |
Jack Carter | 718da0b | 2013-01-30 02:24:33 +0000 | [diff] [blame] | 22 | #include "llvm/MC/MCAssembler.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 23 | #include "llvm/MC/MCContext.h" |
Tim Northover | d6a729b | 2014-01-06 14:28:05 +0000 | [diff] [blame] | 24 | #include "llvm/MC/MCDisassembler.h" |
Jack Carter | 718da0b | 2013-01-30 02:24:33 +0000 | [diff] [blame] | 25 | #include "llvm/MC/MCELFStreamer.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 26 | #include "llvm/MC/MCExpr.h" |
| 27 | #include "llvm/MC/MCInst.h" |
| 28 | #include "llvm/MC/MCInstrDesc.h" |
Joey Gouly | 0e76fa7 | 2013-09-12 10:28:05 +0000 | [diff] [blame] | 29 | #include "llvm/MC/MCInstrInfo.h" |
Saleem Abdulrasool | 39f773f | 2014-03-20 06:05:33 +0000 | [diff] [blame] | 30 | #include "llvm/MC/MCObjectFileInfo.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 31 | #include "llvm/MC/MCParser/MCAsmLexer.h" |
| 32 | #include "llvm/MC/MCParser/MCAsmParser.h" |
| 33 | #include "llvm/MC/MCParser/MCParsedAsmOperand.h" |
| 34 | #include "llvm/MC/MCRegisterInfo.h" |
Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 35 | #include "llvm/MC/MCSection.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 36 | #include "llvm/MC/MCStreamer.h" |
| 37 | #include "llvm/MC/MCSubtargetInfo.h" |
David Peixotto | e407d09 | 2013-12-19 18:12:36 +0000 | [diff] [blame] | 38 | #include "llvm/MC/MCSymbol.h" |
Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 39 | #include "llvm/MC/MCTargetAsmParser.h" |
Saleem Abdulrasool | 278a9f4 | 2014-01-19 08:25:27 +0000 | [diff] [blame] | 40 | #include "llvm/Support/ARMBuildAttributes.h" |
Saleem Abdulrasool | 662f5c1 | 2014-01-21 02:33:02 +0000 | [diff] [blame] | 41 | #include "llvm/Support/ARMEHABI.h" |
Saleem Abdulrasool | 39f773f | 2014-03-20 06:05:33 +0000 | [diff] [blame] | 42 | #include "llvm/Support/COFF.h" |
Tim Northover | d6a729b | 2014-01-06 14:28:05 +0000 | [diff] [blame] | 43 | #include "llvm/Support/Debug.h" |
Jack Carter | 718da0b | 2013-01-30 02:24:33 +0000 | [diff] [blame] | 44 | #include "llvm/Support/ELF.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 45 | #include "llvm/Support/MathExtras.h" |
| 46 | #include "llvm/Support/SourceMgr.h" |
| 47 | #include "llvm/Support/TargetRegistry.h" |
| 48 | #include "llvm/Support/raw_ostream.h" |
Evan Cheng | 4d1ca96 | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 49 | |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 50 | using namespace llvm; |
| 51 | |
Chris Lattner | bd7c9fa | 2010-10-28 17:20:03 +0000 | [diff] [blame] | 52 | namespace { |
Bill Wendling | ee7f1f9 | 2010-11-06 21:42:12 +0000 | [diff] [blame] | 53 | |
| 54 | class ARMOperand; |
Jim Grosbach | 624bcc7 | 2010-10-29 14:46:02 +0000 | [diff] [blame] | 55 | |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 56 | enum VectorLaneTy { NoLanes, AllLanes, IndexedLane }; |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 57 | |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 58 | class UnwindContext { |
| 59 | MCAsmParser &Parser; |
| 60 | |
Saleem Abdulrasool | 4cb063c | 2014-01-07 02:29:00 +0000 | [diff] [blame] | 61 | typedef SmallVector<SMLoc, 4> Locs; |
| 62 | |
| 63 | Locs FnStartLocs; |
| 64 | Locs CantUnwindLocs; |
| 65 | Locs PersonalityLocs; |
Saleem Abdulrasool | 662f5c1 | 2014-01-21 02:33:02 +0000 | [diff] [blame] | 66 | Locs PersonalityIndexLocs; |
Saleem Abdulrasool | 4cb063c | 2014-01-07 02:29:00 +0000 | [diff] [blame] | 67 | Locs HandlerDataLocs; |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 68 | int FPReg; |
| 69 | |
| 70 | public: |
Saleem Abdulrasool | 5d962d3 | 2014-01-30 04:46:24 +0000 | [diff] [blame] | 71 | UnwindContext(MCAsmParser &P) : Parser(P), FPReg(ARM::SP) {} |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 72 | |
Saleem Abdulrasool | 4cb063c | 2014-01-07 02:29:00 +0000 | [diff] [blame] | 73 | bool hasFnStart() const { return !FnStartLocs.empty(); } |
| 74 | bool cantUnwind() const { return !CantUnwindLocs.empty(); } |
| 75 | bool hasHandlerData() const { return !HandlerDataLocs.empty(); } |
Saleem Abdulrasool | 662f5c1 | 2014-01-21 02:33:02 +0000 | [diff] [blame] | 76 | bool hasPersonality() const { |
| 77 | return !(PersonalityLocs.empty() && PersonalityIndexLocs.empty()); |
| 78 | } |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 79 | |
Saleem Abdulrasool | 4cb063c | 2014-01-07 02:29:00 +0000 | [diff] [blame] | 80 | void recordFnStart(SMLoc L) { FnStartLocs.push_back(L); } |
| 81 | void recordCantUnwind(SMLoc L) { CantUnwindLocs.push_back(L); } |
| 82 | void recordPersonality(SMLoc L) { PersonalityLocs.push_back(L); } |
| 83 | void recordHandlerData(SMLoc L) { HandlerDataLocs.push_back(L); } |
Saleem Abdulrasool | 662f5c1 | 2014-01-21 02:33:02 +0000 | [diff] [blame] | 84 | void recordPersonalityIndex(SMLoc L) { PersonalityIndexLocs.push_back(L); } |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 85 | |
| 86 | void saveFPReg(int Reg) { FPReg = Reg; } |
| 87 | int getFPReg() const { return FPReg; } |
| 88 | |
| 89 | void emitFnStartLocNotes() const { |
Saleem Abdulrasool | 4cb063c | 2014-01-07 02:29:00 +0000 | [diff] [blame] | 90 | for (Locs::const_iterator FI = FnStartLocs.begin(), FE = FnStartLocs.end(); |
| 91 | FI != FE; ++FI) |
| 92 | Parser.Note(*FI, ".fnstart was specified here"); |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 93 | } |
| 94 | void emitCantUnwindLocNotes() const { |
Saleem Abdulrasool | 4cb063c | 2014-01-07 02:29:00 +0000 | [diff] [blame] | 95 | for (Locs::const_iterator UI = CantUnwindLocs.begin(), |
| 96 | UE = CantUnwindLocs.end(); UI != UE; ++UI) |
| 97 | Parser.Note(*UI, ".cantunwind was specified here"); |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 98 | } |
| 99 | void emitHandlerDataLocNotes() const { |
Saleem Abdulrasool | 4cb063c | 2014-01-07 02:29:00 +0000 | [diff] [blame] | 100 | for (Locs::const_iterator HI = HandlerDataLocs.begin(), |
| 101 | HE = HandlerDataLocs.end(); HI != HE; ++HI) |
| 102 | Parser.Note(*HI, ".handlerdata was specified here"); |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 103 | } |
| 104 | void emitPersonalityLocNotes() const { |
Saleem Abdulrasool | 4cb063c | 2014-01-07 02:29:00 +0000 | [diff] [blame] | 105 | for (Locs::const_iterator PI = PersonalityLocs.begin(), |
Saleem Abdulrasool | 662f5c1 | 2014-01-21 02:33:02 +0000 | [diff] [blame] | 106 | PE = PersonalityLocs.end(), |
| 107 | PII = PersonalityIndexLocs.begin(), |
| 108 | PIE = PersonalityIndexLocs.end(); |
| 109 | PI != PE || PII != PIE;) { |
| 110 | if (PI != PE && (PII == PIE || PI->getPointer() < PII->getPointer())) |
| 111 | Parser.Note(*PI++, ".personality was specified here"); |
| 112 | else if (PII != PIE && (PI == PE || PII->getPointer() < PI->getPointer())) |
| 113 | Parser.Note(*PII++, ".personalityindex was specified here"); |
| 114 | else |
| 115 | llvm_unreachable(".personality and .personalityindex cannot be " |
| 116 | "at the same location"); |
| 117 | } |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | void reset() { |
Saleem Abdulrasool | 4cb063c | 2014-01-07 02:29:00 +0000 | [diff] [blame] | 121 | FnStartLocs = Locs(); |
| 122 | CantUnwindLocs = Locs(); |
| 123 | PersonalityLocs = Locs(); |
| 124 | HandlerDataLocs = Locs(); |
Saleem Abdulrasool | 662f5c1 | 2014-01-21 02:33:02 +0000 | [diff] [blame] | 125 | PersonalityIndexLocs = Locs(); |
Saleem Abdulrasool | 5d962d3 | 2014-01-30 04:46:24 +0000 | [diff] [blame] | 126 | FPReg = ARM::SP; |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 127 | } |
| 128 | }; |
| 129 | |
Evan Cheng | 1142444 | 2011-07-26 00:24:13 +0000 | [diff] [blame] | 130 | class ARMAsmParser : public MCTargetAsmParser { |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 131 | MCSubtargetInfo &STI; |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 132 | MCAsmParser &Parser; |
Joey Gouly | 0e76fa7 | 2013-09-12 10:28:05 +0000 | [diff] [blame] | 133 | const MCInstrInfo &MII; |
Jim Grosbach | c988e0c | 2012-03-05 19:33:30 +0000 | [diff] [blame] | 134 | const MCRegisterInfo *MRI; |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 135 | UnwindContext UC; |
David Peixotto | e407d09 | 2013-12-19 18:12:36 +0000 | [diff] [blame] | 136 | |
Rafael Espindola | a17151a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 137 | ARMTargetStreamer &getTargetStreamer() { |
Rafael Espindola | 4a1a360 | 2014-01-14 01:21:46 +0000 | [diff] [blame] | 138 | MCTargetStreamer &TS = *getParser().getStreamer().getTargetStreamer(); |
Rafael Espindola | a17151a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 139 | return static_cast<ARMTargetStreamer &>(TS); |
| 140 | } |
| 141 | |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 142 | // Map of register aliases registers via the .req directive. |
| 143 | StringMap<unsigned> RegisterReqs; |
| 144 | |
Tim Northover | 1744d0a | 2013-10-25 12:49:50 +0000 | [diff] [blame] | 145 | bool NextSymbolIsThumb; |
| 146 | |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 147 | struct { |
| 148 | ARMCC::CondCodes Cond; // Condition for IT block. |
| 149 | unsigned Mask:4; // Condition mask for instructions. |
| 150 | // Starting at first 1 (from lsb). |
| 151 | // '1' condition as indicated in IT. |
| 152 | // '0' inverse of condition (else). |
| 153 | // Count of instructions in IT block is |
| 154 | // 4 - trailingzeroes(mask) |
| 155 | |
| 156 | bool FirstCond; // Explicit flag for when we're parsing the |
| 157 | // First instruction in the IT block. It's |
| 158 | // implied in the mask, so needs special |
| 159 | // handling. |
| 160 | |
| 161 | unsigned CurPosition; // Current position in parsing of IT |
| 162 | // block. In range [0,3]. Initialized |
| 163 | // according to count of instructions in block. |
| 164 | // ~0U if no active IT block. |
| 165 | } ITState; |
| 166 | bool inITBlock() { return ITState.CurPosition != ~0U;} |
Jim Grosbach | a0d34d3 | 2011-09-02 23:22:08 +0000 | [diff] [blame] | 167 | void forwardITPosition() { |
| 168 | if (!inITBlock()) return; |
| 169 | // Move to the next instruction in the IT block, if there is one. If not, |
| 170 | // mark the block as done. |
Michael J. Spencer | df1ecbd7 | 2013-05-24 22:23:49 +0000 | [diff] [blame] | 171 | unsigned TZ = countTrailingZeros(ITState.Mask); |
Jim Grosbach | a0d34d3 | 2011-09-02 23:22:08 +0000 | [diff] [blame] | 172 | if (++ITState.CurPosition == 5 - TZ) |
| 173 | ITState.CurPosition = ~0U; // Done with the IT block after this. |
| 174 | } |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 175 | |
| 176 | |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 177 | MCAsmParser &getParser() const { return Parser; } |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 178 | MCAsmLexer &getLexer() const { return Parser.getLexer(); } |
| 179 | |
Saleem Abdulrasool | 69c7caf | 2014-01-07 02:28:31 +0000 | [diff] [blame] | 180 | void Note(SMLoc L, const Twine &Msg, ArrayRef<SMRange> Ranges = None) { |
| 181 | return Parser.Note(L, Msg, Ranges); |
| 182 | } |
Benjamin Kramer | 673824b | 2012-04-15 17:04:27 +0000 | [diff] [blame] | 183 | bool Warning(SMLoc L, const Twine &Msg, |
Dmitri Gribenko | 3238fb7 | 2013-05-05 00:40:33 +0000 | [diff] [blame] | 184 | ArrayRef<SMRange> Ranges = None) { |
Benjamin Kramer | 673824b | 2012-04-15 17:04:27 +0000 | [diff] [blame] | 185 | return Parser.Warning(L, Msg, Ranges); |
| 186 | } |
| 187 | bool Error(SMLoc L, const Twine &Msg, |
Dmitri Gribenko | 3238fb7 | 2013-05-05 00:40:33 +0000 | [diff] [blame] | 188 | ArrayRef<SMRange> Ranges = None) { |
Benjamin Kramer | 673824b | 2012-04-15 17:04:27 +0000 | [diff] [blame] | 189 | return Parser.Error(L, Msg, Ranges); |
| 190 | } |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 191 | |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 192 | int tryParseRegister(); |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 193 | bool tryParseRegisterWithWriteBack(OperandVector &); |
| 194 | int tryParseShiftRegister(OperandVector &); |
| 195 | bool parseRegisterList(OperandVector &); |
| 196 | bool parseMemory(OperandVector &); |
| 197 | bool parseOperand(OperandVector &, StringRef Mnemonic); |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 198 | bool parsePrefix(ARMMCExpr::VariantKind &RefKind); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 199 | bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType, |
| 200 | unsigned &ShiftAmount); |
Saleem Abdulrasool | 3897651 | 2014-02-23 06:22:09 +0000 | [diff] [blame] | 201 | bool parseLiteralValues(unsigned Size, SMLoc L); |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 202 | bool parseDirectiveThumb(SMLoc L); |
Jim Grosbach | 7f88239 | 2011-12-07 18:04:19 +0000 | [diff] [blame] | 203 | bool parseDirectiveARM(SMLoc L); |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 204 | bool parseDirectiveThumbFunc(SMLoc L); |
| 205 | bool parseDirectiveCode(SMLoc L); |
| 206 | bool parseDirectiveSyntax(SMLoc L); |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 207 | bool parseDirectiveReq(StringRef Name, SMLoc L); |
| 208 | bool parseDirectiveUnreq(SMLoc L); |
Jason W Kim | 135d244 | 2011-12-20 17:38:12 +0000 | [diff] [blame] | 209 | bool parseDirectiveArch(SMLoc L); |
| 210 | bool parseDirectiveEabiAttr(SMLoc L); |
Logan Chien | 8cbb80d | 2013-10-28 17:51:12 +0000 | [diff] [blame] | 211 | bool parseDirectiveCPU(SMLoc L); |
| 212 | bool parseDirectiveFPU(SMLoc L); |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 213 | bool parseDirectiveFnStart(SMLoc L); |
| 214 | bool parseDirectiveFnEnd(SMLoc L); |
| 215 | bool parseDirectiveCantUnwind(SMLoc L); |
| 216 | bool parseDirectivePersonality(SMLoc L); |
| 217 | bool parseDirectiveHandlerData(SMLoc L); |
| 218 | bool parseDirectiveSetFP(SMLoc L); |
| 219 | bool parseDirectivePad(SMLoc L); |
| 220 | bool parseDirectiveRegSave(SMLoc L, bool IsVector); |
Saleem Abdulrasool | c0da2cb | 2013-12-19 05:17:58 +0000 | [diff] [blame] | 221 | bool parseDirectiveInst(SMLoc L, char Suffix = '\0'); |
David Peixotto | 80c083a | 2013-12-19 18:26:07 +0000 | [diff] [blame] | 222 | bool parseDirectiveLtorg(SMLoc L); |
Saleem Abdulrasool | a554968 | 2013-12-26 01:52:28 +0000 | [diff] [blame] | 223 | bool parseDirectiveEven(SMLoc L); |
Saleem Abdulrasool | 662f5c1 | 2014-01-21 02:33:02 +0000 | [diff] [blame] | 224 | bool parseDirectivePersonalityIndex(SMLoc L); |
Saleem Abdulrasool | d9f0860 | 2014-01-21 02:33:10 +0000 | [diff] [blame] | 225 | bool parseDirectiveUnwindRaw(SMLoc L); |
Saleem Abdulrasool | 56e06e8 | 2014-01-30 04:02:47 +0000 | [diff] [blame] | 226 | bool parseDirectiveTLSDescSeq(SMLoc L); |
Saleem Abdulrasool | 5d962d3 | 2014-01-30 04:46:24 +0000 | [diff] [blame] | 227 | bool parseDirectiveMovSP(SMLoc L); |
Saleem Abdulrasool | 4c4789b | 2014-01-30 04:46:41 +0000 | [diff] [blame] | 228 | bool parseDirectiveObjectArch(SMLoc L); |
Saleem Abdulrasool | 49480bf | 2014-02-16 00:16:41 +0000 | [diff] [blame] | 229 | bool parseDirectiveArchExtension(SMLoc L); |
Saleem Abdulrasool | fd6ed1e | 2014-02-23 17:45:32 +0000 | [diff] [blame] | 230 | bool parseDirectiveAlign(SMLoc L); |
Saleem Abdulrasool | 39f773f | 2014-03-20 06:05:33 +0000 | [diff] [blame] | 231 | bool parseDirectiveThumbSet(SMLoc L); |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 232 | |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 233 | StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode, |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 234 | bool &CarrySetting, unsigned &ProcessorIMod, |
| 235 | StringRef &ITMask); |
Amara Emerson | 3308909 | 2013-09-19 11:59:01 +0000 | [diff] [blame] | 236 | void getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst, |
| 237 | bool &CanAcceptCarrySet, |
Bruno Cardoso Lopes | e6290cc | 2011-01-18 20:55:11 +0000 | [diff] [blame] | 238 | bool &CanAcceptPredicationCode); |
Jim Grosbach | 624bcc7 | 2010-10-29 14:46:02 +0000 | [diff] [blame] | 239 | |
Evan Cheng | 4d1ca96 | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 240 | bool isThumb() const { |
| 241 | // FIXME: Can tablegen auto-generate this? |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 242 | return (STI.getFeatureBits() & ARM::ModeThumb) != 0; |
Evan Cheng | 4d1ca96 | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 243 | } |
Evan Cheng | 4d1ca96 | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 244 | bool isThumbOne() const { |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 245 | return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0; |
Evan Cheng | 4d1ca96 | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 246 | } |
Jim Grosbach | 3e941ae | 2011-08-16 20:45:50 +0000 | [diff] [blame] | 247 | bool isThumbTwo() const { |
| 248 | return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2); |
| 249 | } |
Tim Northover | a2292d0 | 2013-06-10 23:20:58 +0000 | [diff] [blame] | 250 | bool hasThumb() const { |
| 251 | return STI.getFeatureBits() & ARM::HasV4TOps; |
| 252 | } |
Jim Grosbach | b7fa2c0 | 2011-08-16 22:20:01 +0000 | [diff] [blame] | 253 | bool hasV6Ops() const { |
| 254 | return STI.getFeatureBits() & ARM::HasV6Ops; |
| 255 | } |
Tim Northover | f86d1f0 | 2013-10-07 11:10:47 +0000 | [diff] [blame] | 256 | bool hasV6MOps() const { |
| 257 | return STI.getFeatureBits() & ARM::HasV6MOps; |
| 258 | } |
James Molloy | 21efa7d | 2011-09-28 14:21:38 +0000 | [diff] [blame] | 259 | bool hasV7Ops() const { |
| 260 | return STI.getFeatureBits() & ARM::HasV7Ops; |
| 261 | } |
Joey Gouly | b3f550e | 2013-06-26 16:58:26 +0000 | [diff] [blame] | 262 | bool hasV8Ops() const { |
| 263 | return STI.getFeatureBits() & ARM::HasV8Ops; |
| 264 | } |
Tim Northover | a2292d0 | 2013-06-10 23:20:58 +0000 | [diff] [blame] | 265 | bool hasARM() const { |
| 266 | return !(STI.getFeatureBits() & ARM::FeatureNoARM); |
| 267 | } |
| 268 | |
Evan Cheng | 284b467 | 2011-07-08 22:36:29 +0000 | [diff] [blame] | 269 | void SwitchMode() { |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 270 | unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb)); |
| 271 | setAvailableFeatures(FB); |
Evan Cheng | 284b467 | 2011-07-08 22:36:29 +0000 | [diff] [blame] | 272 | } |
James Molloy | 21efa7d | 2011-09-28 14:21:38 +0000 | [diff] [blame] | 273 | bool isMClass() const { |
| 274 | return STI.getFeatureBits() & ARM::FeatureMClass; |
| 275 | } |
Evan Cheng | 4d1ca96 | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 276 | |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 277 | /// @name Auto-generated Match Functions |
| 278 | /// { |
Daniel Dunbar | 5cd4d0f | 2010-08-11 05:24:50 +0000 | [diff] [blame] | 279 | |
Chris Lattner | 3e4582a | 2010-09-06 19:11:01 +0000 | [diff] [blame] | 280 | #define GET_ASSEMBLER_HEADER |
| 281 | #include "ARMGenAsmMatcher.inc" |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 282 | |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 283 | /// } |
| 284 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 285 | OperandMatchResultTy parseITCondCode(OperandVector &); |
| 286 | OperandMatchResultTy parseCoprocNumOperand(OperandVector &); |
| 287 | OperandMatchResultTy parseCoprocRegOperand(OperandVector &); |
| 288 | OperandMatchResultTy parseCoprocOptionOperand(OperandVector &); |
| 289 | OperandMatchResultTy parseMemBarrierOptOperand(OperandVector &); |
| 290 | OperandMatchResultTy parseInstSyncBarrierOptOperand(OperandVector &); |
| 291 | OperandMatchResultTy parseProcIFlagsOperand(OperandVector &); |
| 292 | OperandMatchResultTy parseMSRMaskOperand(OperandVector &); |
| 293 | OperandMatchResultTy parsePKHImm(OperandVector &O, StringRef Op, int Low, |
| 294 | int High); |
| 295 | OperandMatchResultTy parsePKHLSLImm(OperandVector &O) { |
Jim Grosbach | 27c1e25 | 2011-07-21 17:23:04 +0000 | [diff] [blame] | 296 | return parsePKHImm(O, "lsl", 0, 31); |
| 297 | } |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 298 | OperandMatchResultTy parsePKHASRImm(OperandVector &O) { |
Jim Grosbach | 27c1e25 | 2011-07-21 17:23:04 +0000 | [diff] [blame] | 299 | return parsePKHImm(O, "asr", 1, 32); |
| 300 | } |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 301 | OperandMatchResultTy parseSetEndImm(OperandVector &); |
| 302 | OperandMatchResultTy parseShifterImm(OperandVector &); |
| 303 | OperandMatchResultTy parseRotImm(OperandVector &); |
| 304 | OperandMatchResultTy parseBitfield(OperandVector &); |
| 305 | OperandMatchResultTy parsePostIdxReg(OperandVector &); |
| 306 | OperandMatchResultTy parseAM3Offset(OperandVector &); |
| 307 | OperandMatchResultTy parseFPImm(OperandVector &); |
| 308 | OperandMatchResultTy parseVectorList(OperandVector &); |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 309 | OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, |
| 310 | SMLoc &EndLoc); |
Bruno Cardoso Lopes | ab83050 | 2011-03-31 23:26:08 +0000 | [diff] [blame] | 311 | |
| 312 | // Asm Match Converter Methods |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 313 | void cvtThumbMultiply(MCInst &Inst, const OperandVector &); |
| 314 | void cvtThumbBranches(MCInst &Inst, const OperandVector &); |
Saleem Abdulrasool | 4ab6e73 | 2014-02-23 17:45:36 +0000 | [diff] [blame] | 315 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 316 | bool validateInstruction(MCInst &Inst, const OperandVector &Ops); |
| 317 | bool processInstruction(MCInst &Inst, const OperandVector &Ops); |
| 318 | bool shouldOmitCCOutOperand(StringRef Mnemonic, OperandVector &Operands); |
| 319 | bool shouldOmitPredicateOperand(StringRef Mnemonic, OperandVector &Operands); |
| 320 | |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 321 | public: |
Jim Grosbach | 3e941ae | 2011-08-16 20:45:50 +0000 | [diff] [blame] | 322 | enum ARMMatchResultTy { |
Jim Grosbach | b7fa2c0 | 2011-08-16 22:20:01 +0000 | [diff] [blame] | 323 | Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY, |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 324 | Match_RequiresNotITBlock, |
Jim Grosbach | b7fa2c0 | 2011-08-16 22:20:01 +0000 | [diff] [blame] | 325 | Match_RequiresV6, |
Jim Grosbach | 087affe | 2012-06-22 23:56:48 +0000 | [diff] [blame] | 326 | Match_RequiresThumb2, |
| 327 | #define GET_OPERAND_DIAGNOSTIC_TYPES |
| 328 | #include "ARMGenAsmMatcher.inc" |
| 329 | |
Jim Grosbach | 3e941ae | 2011-08-16 20:45:50 +0000 | [diff] [blame] | 330 | }; |
| 331 | |
Joey Gouly | 0e76fa7 | 2013-09-12 10:28:05 +0000 | [diff] [blame] | 332 | ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser, |
Evgeniy Stepanov | 0a951b7 | 2014-04-23 11:16:03 +0000 | [diff] [blame] | 333 | const MCInstrInfo &MII, |
| 334 | const MCTargetOptions &Options) |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 335 | : MCTargetAsmParser(), STI(_STI), Parser(_Parser), MII(MII), UC(_Parser) { |
Evan Cheng | 4d1ca96 | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 336 | MCAsmParserExtension::Initialize(_Parser); |
Evan Cheng | 284b467 | 2011-07-08 22:36:29 +0000 | [diff] [blame] | 337 | |
Jim Grosbach | c988e0c | 2012-03-05 19:33:30 +0000 | [diff] [blame] | 338 | // Cache the MCRegisterInfo. |
Bill Wendling | bc07a89 | 2013-06-18 07:20:20 +0000 | [diff] [blame] | 339 | MRI = getContext().getRegisterInfo(); |
Jim Grosbach | c988e0c | 2012-03-05 19:33:30 +0000 | [diff] [blame] | 340 | |
Evan Cheng | 4d1ca96 | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 341 | // Initialize the set of available features. |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 342 | setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits())); |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 343 | |
| 344 | // Not in an ITBlock to start with. |
| 345 | ITState.CurPosition = ~0U; |
Tim Northover | 1744d0a | 2013-10-25 12:49:50 +0000 | [diff] [blame] | 346 | |
| 347 | NextSymbolIsThumb = false; |
Evan Cheng | 4d1ca96 | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 348 | } |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 349 | |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 350 | // Implementation of the MCTargetAsmParser interface: |
Craig Topper | ca7e3e5 | 2014-03-10 03:19:03 +0000 | [diff] [blame] | 351 | bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc) override; |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 352 | bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name, |
| 353 | SMLoc NameLoc, OperandVector &Operands) override; |
Craig Topper | ca7e3e5 | 2014-03-10 03:19:03 +0000 | [diff] [blame] | 354 | bool ParseDirective(AsmToken DirectiveID) override; |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 355 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 356 | unsigned validateTargetOperandClass(MCParsedAsmOperand &Op, |
Craig Topper | ca7e3e5 | 2014-03-10 03:19:03 +0000 | [diff] [blame] | 357 | unsigned Kind) override; |
| 358 | unsigned checkTargetMatchPredicate(MCInst &Inst) override; |
Jim Grosbach | 3e941ae | 2011-08-16 20:45:50 +0000 | [diff] [blame] | 359 | |
Chad Rosier | 4996355 | 2012-10-13 00:26:04 +0000 | [diff] [blame] | 360 | bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode, |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 361 | OperandVector &Operands, MCStreamer &Out, |
| 362 | unsigned &ErrorInfo, |
Craig Topper | ca7e3e5 | 2014-03-10 03:19:03 +0000 | [diff] [blame] | 363 | bool MatchingInlineAsm) override; |
| 364 | void onLabelParsed(MCSymbol *Symbol) override; |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 365 | }; |
Jim Grosbach | 624bcc7 | 2010-10-29 14:46:02 +0000 | [diff] [blame] | 366 | } // end anonymous namespace |
| 367 | |
Chris Lattner | bd7c9fa | 2010-10-28 17:20:03 +0000 | [diff] [blame] | 368 | namespace { |
| 369 | |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 370 | /// ARMOperand - Instances of this class represent a parsed ARM machine |
Joel Jones | 5459754 | 2013-01-09 22:34:16 +0000 | [diff] [blame] | 371 | /// operand. |
Bill Wendling | ee7f1f9 | 2010-11-06 21:42:12 +0000 | [diff] [blame] | 372 | class ARMOperand : public MCParsedAsmOperand { |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 373 | enum KindTy { |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 374 | k_CondCode, |
| 375 | k_CCOut, |
| 376 | k_ITCondMask, |
| 377 | k_CoprocNum, |
| 378 | k_CoprocReg, |
Jim Grosbach | 4839958 | 2011-10-12 17:34:41 +0000 | [diff] [blame] | 379 | k_CoprocOption, |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 380 | k_Immediate, |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 381 | k_MemBarrierOpt, |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 382 | k_InstSyncBarrierOpt, |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 383 | k_Memory, |
| 384 | k_PostIndexRegister, |
| 385 | k_MSRMask, |
| 386 | k_ProcIFlags, |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 387 | k_VectorIndex, |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 388 | k_Register, |
| 389 | k_RegisterList, |
| 390 | k_DPRRegisterList, |
| 391 | k_SPRRegisterList, |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 392 | k_VectorList, |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 393 | k_VectorListAllLanes, |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 394 | k_VectorListIndexed, |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 395 | k_ShiftedRegister, |
| 396 | k_ShiftedImmediate, |
| 397 | k_ShifterImmediate, |
| 398 | k_RotateImmediate, |
| 399 | k_BitfieldDescriptor, |
| 400 | k_Token |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 401 | } Kind; |
| 402 | |
Kevin Enderby | 488f20b | 2014-04-10 20:18:58 +0000 | [diff] [blame] | 403 | SMLoc StartLoc, EndLoc, AlignmentLoc; |
Bill Wendling | 0ab0f67 | 2010-11-18 21:50:54 +0000 | [diff] [blame] | 404 | SmallVector<unsigned, 8> Registers; |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 405 | |
Eric Christopher | 8996c5d | 2013-03-15 00:42:55 +0000 | [diff] [blame] | 406 | struct CCOp { |
| 407 | ARMCC::CondCodes Val; |
| 408 | }; |
| 409 | |
| 410 | struct CopOp { |
| 411 | unsigned Val; |
| 412 | }; |
| 413 | |
| 414 | struct CoprocOptionOp { |
| 415 | unsigned Val; |
| 416 | }; |
| 417 | |
| 418 | struct ITMaskOp { |
| 419 | unsigned Mask:4; |
| 420 | }; |
| 421 | |
| 422 | struct MBOptOp { |
| 423 | ARM_MB::MemBOpt Val; |
| 424 | }; |
| 425 | |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 426 | struct ISBOptOp { |
| 427 | ARM_ISB::InstSyncBOpt Val; |
| 428 | }; |
| 429 | |
Eric Christopher | 8996c5d | 2013-03-15 00:42:55 +0000 | [diff] [blame] | 430 | struct IFlagsOp { |
| 431 | ARM_PROC::IFlags Val; |
| 432 | }; |
| 433 | |
| 434 | struct MMaskOp { |
| 435 | unsigned Val; |
| 436 | }; |
| 437 | |
| 438 | struct TokOp { |
| 439 | const char *Data; |
| 440 | unsigned Length; |
| 441 | }; |
| 442 | |
| 443 | struct RegOp { |
| 444 | unsigned RegNum; |
| 445 | }; |
| 446 | |
| 447 | // A vector register list is a sequential list of 1 to 4 registers. |
| 448 | struct VectorListOp { |
| 449 | unsigned RegNum; |
| 450 | unsigned Count; |
| 451 | unsigned LaneIndex; |
| 452 | bool isDoubleSpaced; |
| 453 | }; |
| 454 | |
| 455 | struct VectorIndexOp { |
| 456 | unsigned Val; |
| 457 | }; |
| 458 | |
| 459 | struct ImmOp { |
| 460 | const MCExpr *Val; |
| 461 | }; |
| 462 | |
| 463 | /// Combined record for all forms of ARM address expressions. |
| 464 | struct MemoryOp { |
| 465 | unsigned BaseRegNum; |
| 466 | // Offset is in OffsetReg or OffsetImm. If both are zero, no offset |
| 467 | // was specified. |
| 468 | const MCConstantExpr *OffsetImm; // Offset immediate value |
| 469 | unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL |
| 470 | ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg |
| 471 | unsigned ShiftImm; // shift for OffsetReg. |
| 472 | unsigned Alignment; // 0 = no alignment specified |
| 473 | // n = alignment in bytes (2, 4, 8, 16, or 32) |
| 474 | unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit) |
| 475 | }; |
| 476 | |
| 477 | struct PostIdxRegOp { |
| 478 | unsigned RegNum; |
| 479 | bool isAdd; |
| 480 | ARM_AM::ShiftOpc ShiftTy; |
| 481 | unsigned ShiftImm; |
| 482 | }; |
| 483 | |
| 484 | struct ShifterImmOp { |
| 485 | bool isASR; |
| 486 | unsigned Imm; |
| 487 | }; |
| 488 | |
| 489 | struct RegShiftedRegOp { |
| 490 | ARM_AM::ShiftOpc ShiftTy; |
| 491 | unsigned SrcReg; |
| 492 | unsigned ShiftReg; |
| 493 | unsigned ShiftImm; |
| 494 | }; |
| 495 | |
| 496 | struct RegShiftedImmOp { |
| 497 | ARM_AM::ShiftOpc ShiftTy; |
| 498 | unsigned SrcReg; |
| 499 | unsigned ShiftImm; |
| 500 | }; |
| 501 | |
| 502 | struct RotImmOp { |
| 503 | unsigned Imm; |
| 504 | }; |
| 505 | |
| 506 | struct BitfieldOp { |
| 507 | unsigned LSB; |
| 508 | unsigned Width; |
| 509 | }; |
| 510 | |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 511 | union { |
Eric Christopher | 8996c5d | 2013-03-15 00:42:55 +0000 | [diff] [blame] | 512 | struct CCOp CC; |
| 513 | struct CopOp Cop; |
| 514 | struct CoprocOptionOp CoprocOption; |
| 515 | struct MBOptOp MBOpt; |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 516 | struct ISBOptOp ISBOpt; |
Eric Christopher | 8996c5d | 2013-03-15 00:42:55 +0000 | [diff] [blame] | 517 | struct ITMaskOp ITMask; |
| 518 | struct IFlagsOp IFlags; |
| 519 | struct MMaskOp MMask; |
| 520 | struct TokOp Tok; |
| 521 | struct RegOp Reg; |
| 522 | struct VectorListOp VectorList; |
| 523 | struct VectorIndexOp VectorIndex; |
| 524 | struct ImmOp Imm; |
| 525 | struct MemoryOp Memory; |
| 526 | struct PostIdxRegOp PostIdxReg; |
| 527 | struct ShifterImmOp ShifterImm; |
| 528 | struct RegShiftedRegOp RegShiftedReg; |
| 529 | struct RegShiftedImmOp RegShiftedImm; |
| 530 | struct RotImmOp RotImm; |
| 531 | struct BitfieldOp Bitfield; |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 532 | }; |
Jim Grosbach | 624bcc7 | 2010-10-29 14:46:02 +0000 | [diff] [blame] | 533 | |
Bill Wendling | ee7f1f9 | 2010-11-06 21:42:12 +0000 | [diff] [blame] | 534 | public: |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 535 | ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {} |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 536 | ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() { |
| 537 | Kind = o.Kind; |
| 538 | StartLoc = o.StartLoc; |
| 539 | EndLoc = o.EndLoc; |
| 540 | switch (Kind) { |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 541 | case k_CondCode: |
Daniel Dunbar | d8042b7 | 2010-08-11 06:36:53 +0000 | [diff] [blame] | 542 | CC = o.CC; |
| 543 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 544 | case k_ITCondMask: |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 545 | ITMask = o.ITMask; |
| 546 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 547 | case k_Token: |
Daniel Dunbar | d8042b7 | 2010-08-11 06:36:53 +0000 | [diff] [blame] | 548 | Tok = o.Tok; |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 549 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 550 | case k_CCOut: |
| 551 | case k_Register: |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 552 | Reg = o.Reg; |
| 553 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 554 | case k_RegisterList: |
| 555 | case k_DPRRegisterList: |
| 556 | case k_SPRRegisterList: |
Bill Wendling | 0ab0f67 | 2010-11-18 21:50:54 +0000 | [diff] [blame] | 557 | Registers = o.Registers; |
Bill Wendling | 7cef447 | 2010-11-06 19:56:04 +0000 | [diff] [blame] | 558 | break; |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 559 | case k_VectorList: |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 560 | case k_VectorListAllLanes: |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 561 | case k_VectorListIndexed: |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 562 | VectorList = o.VectorList; |
| 563 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 564 | case k_CoprocNum: |
| 565 | case k_CoprocReg: |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 566 | Cop = o.Cop; |
| 567 | break; |
Jim Grosbach | 4839958 | 2011-10-12 17:34:41 +0000 | [diff] [blame] | 568 | case k_CoprocOption: |
| 569 | CoprocOption = o.CoprocOption; |
| 570 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 571 | case k_Immediate: |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 572 | Imm = o.Imm; |
| 573 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 574 | case k_MemBarrierOpt: |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 575 | MBOpt = o.MBOpt; |
| 576 | break; |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 577 | case k_InstSyncBarrierOpt: |
| 578 | ISBOpt = o.ISBOpt; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 579 | case k_Memory: |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 580 | Memory = o.Memory; |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 581 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 582 | case k_PostIndexRegister: |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 583 | PostIdxReg = o.PostIdxReg; |
| 584 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 585 | case k_MSRMask: |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 586 | MMask = o.MMask; |
| 587 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 588 | case k_ProcIFlags: |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 589 | IFlags = o.IFlags; |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 590 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 591 | case k_ShifterImmediate: |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 592 | ShifterImm = o.ShifterImm; |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 593 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 594 | case k_ShiftedRegister: |
Jim Grosbach | ac798e1 | 2011-07-25 20:49:51 +0000 | [diff] [blame] | 595 | RegShiftedReg = o.RegShiftedReg; |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 596 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 597 | case k_ShiftedImmediate: |
Jim Grosbach | ac798e1 | 2011-07-25 20:49:51 +0000 | [diff] [blame] | 598 | RegShiftedImm = o.RegShiftedImm; |
Owen Anderson | b595ed0 | 2011-07-21 18:54:16 +0000 | [diff] [blame] | 599 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 600 | case k_RotateImmediate: |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 601 | RotImm = o.RotImm; |
| 602 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 603 | case k_BitfieldDescriptor: |
Jim Grosbach | 864b609 | 2011-07-28 21:34:26 +0000 | [diff] [blame] | 604 | Bitfield = o.Bitfield; |
| 605 | break; |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 606 | case k_VectorIndex: |
| 607 | VectorIndex = o.VectorIndex; |
| 608 | break; |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 609 | } |
| 610 | } |
Jim Grosbach | 624bcc7 | 2010-10-29 14:46:02 +0000 | [diff] [blame] | 611 | |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 612 | /// getStartLoc - Get the location of the first token of this operand. |
Craig Topper | ca7e3e5 | 2014-03-10 03:19:03 +0000 | [diff] [blame] | 613 | SMLoc getStartLoc() const override { return StartLoc; } |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 614 | /// getEndLoc - Get the location of the last token of this operand. |
Craig Topper | ca7e3e5 | 2014-03-10 03:19:03 +0000 | [diff] [blame] | 615 | SMLoc getEndLoc() const override { return EndLoc; } |
Chad Rosier | 143d0f7 | 2012-09-21 20:51:43 +0000 | [diff] [blame] | 616 | /// getLocRange - Get the range between the first and last token of this |
| 617 | /// operand. |
Benjamin Kramer | 673824b | 2012-04-15 17:04:27 +0000 | [diff] [blame] | 618 | SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); } |
| 619 | |
Kevin Enderby | 488f20b | 2014-04-10 20:18:58 +0000 | [diff] [blame] | 620 | /// getAlignmentLoc - Get the location of the Alignment token of this operand. |
| 621 | SMLoc getAlignmentLoc() const { |
| 622 | assert(Kind == k_Memory && "Invalid access!"); |
| 623 | return AlignmentLoc; |
| 624 | } |
| 625 | |
Daniel Dunbar | d8042b7 | 2010-08-11 06:36:53 +0000 | [diff] [blame] | 626 | ARMCC::CondCodes getCondCode() const { |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 627 | assert(Kind == k_CondCode && "Invalid access!"); |
Daniel Dunbar | d8042b7 | 2010-08-11 06:36:53 +0000 | [diff] [blame] | 628 | return CC.Val; |
| 629 | } |
| 630 | |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 631 | unsigned getCoproc() const { |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 632 | assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!"); |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 633 | return Cop.Val; |
| 634 | } |
| 635 | |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 636 | StringRef getToken() const { |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 637 | assert(Kind == k_Token && "Invalid access!"); |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 638 | return StringRef(Tok.Data, Tok.Length); |
| 639 | } |
| 640 | |
Craig Topper | ca7e3e5 | 2014-03-10 03:19:03 +0000 | [diff] [blame] | 641 | unsigned getReg() const override { |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 642 | assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!"); |
Bill Wendling | 2cae327 | 2010-11-09 22:44:22 +0000 | [diff] [blame] | 643 | return Reg.RegNum; |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 644 | } |
| 645 | |
Bill Wendling | bed9465 | 2010-11-09 23:28:44 +0000 | [diff] [blame] | 646 | const SmallVectorImpl<unsigned> &getRegList() const { |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 647 | assert((Kind == k_RegisterList || Kind == k_DPRRegisterList || |
| 648 | Kind == k_SPRRegisterList) && "Invalid access!"); |
Bill Wendling | 0ab0f67 | 2010-11-18 21:50:54 +0000 | [diff] [blame] | 649 | return Registers; |
Bill Wendling | 7cef447 | 2010-11-06 19:56:04 +0000 | [diff] [blame] | 650 | } |
| 651 | |
Kevin Enderby | f507994 | 2009-10-13 22:19:02 +0000 | [diff] [blame] | 652 | const MCExpr *getImm() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 653 | assert(isImm() && "Invalid access!"); |
Kevin Enderby | f507994 | 2009-10-13 22:19:02 +0000 | [diff] [blame] | 654 | return Imm.Val; |
| 655 | } |
| 656 | |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 657 | unsigned getVectorIndex() const { |
| 658 | assert(Kind == k_VectorIndex && "Invalid access!"); |
| 659 | return VectorIndex.Val; |
| 660 | } |
| 661 | |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 662 | ARM_MB::MemBOpt getMemBarrierOpt() const { |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 663 | assert(Kind == k_MemBarrierOpt && "Invalid access!"); |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 664 | return MBOpt.Val; |
| 665 | } |
| 666 | |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 667 | ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const { |
| 668 | assert(Kind == k_InstSyncBarrierOpt && "Invalid access!"); |
| 669 | return ISBOpt.Val; |
| 670 | } |
| 671 | |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 672 | ARM_PROC::IFlags getProcIFlags() const { |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 673 | assert(Kind == k_ProcIFlags && "Invalid access!"); |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 674 | return IFlags.Val; |
| 675 | } |
| 676 | |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 677 | unsigned getMSRMask() const { |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 678 | assert(Kind == k_MSRMask && "Invalid access!"); |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 679 | return MMask.Val; |
| 680 | } |
| 681 | |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 682 | bool isCoprocNum() const { return Kind == k_CoprocNum; } |
| 683 | bool isCoprocReg() const { return Kind == k_CoprocReg; } |
Jim Grosbach | 4839958 | 2011-10-12 17:34:41 +0000 | [diff] [blame] | 684 | bool isCoprocOption() const { return Kind == k_CoprocOption; } |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 685 | bool isCondCode() const { return Kind == k_CondCode; } |
| 686 | bool isCCOut() const { return Kind == k_CCOut; } |
| 687 | bool isITMask() const { return Kind == k_ITCondMask; } |
| 688 | bool isITCondCode() const { return Kind == k_CondCode; } |
Craig Topper | ca7e3e5 | 2014-03-10 03:19:03 +0000 | [diff] [blame] | 689 | bool isImm() const override { return Kind == k_Immediate; } |
Mihai Popa | d36cbaa | 2013-07-03 09:21:44 +0000 | [diff] [blame] | 690 | // checks whether this operand is an unsigned offset which fits is a field |
| 691 | // of specified width and scaled by a specific number of bits |
| 692 | template<unsigned width, unsigned scale> |
| 693 | bool isUnsignedOffset() const { |
| 694 | if (!isImm()) return false; |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 695 | if (isa<MCSymbolRefExpr>(Imm.Val)) return true; |
Mihai Popa | d36cbaa | 2013-07-03 09:21:44 +0000 | [diff] [blame] | 696 | if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) { |
| 697 | int64_t Val = CE->getValue(); |
| 698 | int64_t Align = 1LL << scale; |
| 699 | int64_t Max = Align * ((1LL << width) - 1); |
| 700 | return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max); |
| 701 | } |
| 702 | return false; |
| 703 | } |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 704 | // checks whether this operand is an signed offset which fits is a field |
| 705 | // of specified width and scaled by a specific number of bits |
| 706 | template<unsigned width, unsigned scale> |
| 707 | bool isSignedOffset() const { |
| 708 | if (!isImm()) return false; |
| 709 | if (isa<MCSymbolRefExpr>(Imm.Val)) return true; |
| 710 | if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) { |
| 711 | int64_t Val = CE->getValue(); |
| 712 | int64_t Align = 1LL << scale; |
| 713 | int64_t Max = Align * ((1LL << (width-1)) - 1); |
| 714 | int64_t Min = -Align * (1LL << (width-1)); |
| 715 | return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max); |
| 716 | } |
| 717 | return false; |
| 718 | } |
| 719 | |
Mihai Popa | 8a9da5b | 2013-07-22 15:49:36 +0000 | [diff] [blame] | 720 | // checks whether this operand is a memory operand computed as an offset |
| 721 | // applied to PC. the offset may have 8 bits of magnitude and is represented |
| 722 | // with two bits of shift. textually it may be either [pc, #imm], #imm or |
| 723 | // relocable expression... |
| 724 | bool isThumbMemPC() const { |
| 725 | int64_t Val = 0; |
| 726 | if (isImm()) { |
| 727 | if (isa<MCSymbolRefExpr>(Imm.Val)) return true; |
| 728 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val); |
| 729 | if (!CE) return false; |
| 730 | Val = CE->getValue(); |
| 731 | } |
| 732 | else if (isMem()) { |
| 733 | if(!Memory.OffsetImm || Memory.OffsetRegNum) return false; |
| 734 | if(Memory.BaseRegNum != ARM::PC) return false; |
| 735 | Val = Memory.OffsetImm->getValue(); |
| 736 | } |
| 737 | else return false; |
Mihai Popa | d79f00b | 2013-08-15 15:43:06 +0000 | [diff] [blame] | 738 | return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020); |
Mihai Popa | 8a9da5b | 2013-07-22 15:49:36 +0000 | [diff] [blame] | 739 | } |
Jim Grosbach | a9d36fb | 2012-01-20 18:09:51 +0000 | [diff] [blame] | 740 | bool isFPImm() const { |
| 741 | if (!isImm()) return false; |
| 742 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 743 | if (!CE) return false; |
| 744 | int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue())); |
| 745 | return Val != -1; |
| 746 | } |
Jim Grosbach | ea23191 | 2011-12-22 22:19:05 +0000 | [diff] [blame] | 747 | bool isFBits16() const { |
| 748 | if (!isImm()) return false; |
| 749 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 750 | if (!CE) return false; |
| 751 | int64_t Value = CE->getValue(); |
| 752 | return Value >= 0 && Value <= 16; |
| 753 | } |
| 754 | bool isFBits32() const { |
| 755 | if (!isImm()) return false; |
| 756 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 757 | if (!CE) return false; |
| 758 | int64_t Value = CE->getValue(); |
| 759 | return Value >= 1 && Value <= 32; |
| 760 | } |
Jim Grosbach | 7db8d69 | 2011-09-08 22:07:06 +0000 | [diff] [blame] | 761 | bool isImm8s4() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 762 | if (!isImm()) return false; |
Jim Grosbach | 7db8d69 | 2011-09-08 22:07:06 +0000 | [diff] [blame] | 763 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 764 | if (!CE) return false; |
| 765 | int64_t Value = CE->getValue(); |
| 766 | return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020; |
| 767 | } |
Jim Grosbach | 0a0b307 | 2011-08-24 21:22:15 +0000 | [diff] [blame] | 768 | bool isImm0_1020s4() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 769 | if (!isImm()) return false; |
Jim Grosbach | 0a0b307 | 2011-08-24 21:22:15 +0000 | [diff] [blame] | 770 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 771 | if (!CE) return false; |
| 772 | int64_t Value = CE->getValue(); |
| 773 | return ((Value & 3) == 0) && Value >= 0 && Value <= 1020; |
| 774 | } |
| 775 | bool isImm0_508s4() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 776 | if (!isImm()) return false; |
Jim Grosbach | 0a0b307 | 2011-08-24 21:22:15 +0000 | [diff] [blame] | 777 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 778 | if (!CE) return false; |
| 779 | int64_t Value = CE->getValue(); |
| 780 | return ((Value & 3) == 0) && Value >= 0 && Value <= 508; |
| 781 | } |
Jim Grosbach | 930f2f6 | 2012-04-05 20:57:13 +0000 | [diff] [blame] | 782 | bool isImm0_508s4Neg() const { |
| 783 | if (!isImm()) return false; |
| 784 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 785 | if (!CE) return false; |
| 786 | int64_t Value = -CE->getValue(); |
| 787 | // explicitly exclude zero. we want that to use the normal 0_508 version. |
| 788 | return ((Value & 3) == 0) && Value > 0 && Value <= 508; |
| 789 | } |
Artyom Skrobov | fc12e70 | 2013-10-23 10:14:40 +0000 | [diff] [blame] | 790 | bool isImm0_239() const { |
| 791 | if (!isImm()) return false; |
| 792 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 793 | if (!CE) return false; |
| 794 | int64_t Value = CE->getValue(); |
| 795 | return Value >= 0 && Value < 240; |
| 796 | } |
Jim Grosbach | a6f7a1e | 2011-06-27 23:54:06 +0000 | [diff] [blame] | 797 | bool isImm0_255() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 798 | if (!isImm()) return false; |
Jim Grosbach | a6f7a1e | 2011-06-27 23:54:06 +0000 | [diff] [blame] | 799 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 800 | if (!CE) return false; |
| 801 | int64_t Value = CE->getValue(); |
| 802 | return Value >= 0 && Value < 256; |
| 803 | } |
Jim Grosbach | 930f2f6 | 2012-04-05 20:57:13 +0000 | [diff] [blame] | 804 | bool isImm0_4095() const { |
| 805 | if (!isImm()) return false; |
| 806 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 807 | if (!CE) return false; |
| 808 | int64_t Value = CE->getValue(); |
| 809 | return Value >= 0 && Value < 4096; |
| 810 | } |
| 811 | bool isImm0_4095Neg() const { |
| 812 | if (!isImm()) return false; |
| 813 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 814 | if (!CE) return false; |
| 815 | int64_t Value = -CE->getValue(); |
| 816 | return Value > 0 && Value < 4096; |
| 817 | } |
Jim Grosbach | 9dff9f4 | 2011-12-02 23:34:39 +0000 | [diff] [blame] | 818 | bool isImm0_1() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 819 | if (!isImm()) return false; |
Jim Grosbach | 9dff9f4 | 2011-12-02 23:34:39 +0000 | [diff] [blame] | 820 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 821 | if (!CE) return false; |
| 822 | int64_t Value = CE->getValue(); |
| 823 | return Value >= 0 && Value < 2; |
| 824 | } |
| 825 | bool isImm0_3() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 826 | if (!isImm()) return false; |
Jim Grosbach | 9dff9f4 | 2011-12-02 23:34:39 +0000 | [diff] [blame] | 827 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 828 | if (!CE) return false; |
| 829 | int64_t Value = CE->getValue(); |
| 830 | return Value >= 0 && Value < 4; |
| 831 | } |
Jim Grosbach | 31756c2 | 2011-07-13 22:01:08 +0000 | [diff] [blame] | 832 | bool isImm0_7() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 833 | if (!isImm()) return false; |
Jim Grosbach | 31756c2 | 2011-07-13 22:01:08 +0000 | [diff] [blame] | 834 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 835 | if (!CE) return false; |
| 836 | int64_t Value = CE->getValue(); |
| 837 | return Value >= 0 && Value < 8; |
| 838 | } |
| 839 | bool isImm0_15() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 840 | if (!isImm()) return false; |
Jim Grosbach | 31756c2 | 2011-07-13 22:01:08 +0000 | [diff] [blame] | 841 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 842 | if (!CE) return false; |
| 843 | int64_t Value = CE->getValue(); |
| 844 | return Value >= 0 && Value < 16; |
| 845 | } |
Jim Grosbach | 72e7c4f | 2011-07-21 23:26:25 +0000 | [diff] [blame] | 846 | bool isImm0_31() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 847 | if (!isImm()) return false; |
Jim Grosbach | 72e7c4f | 2011-07-21 23:26:25 +0000 | [diff] [blame] | 848 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 849 | if (!CE) return false; |
| 850 | int64_t Value = CE->getValue(); |
| 851 | return Value >= 0 && Value < 32; |
| 852 | } |
Jim Grosbach | 0032640 | 2011-12-08 01:30:04 +0000 | [diff] [blame] | 853 | bool isImm0_63() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 854 | if (!isImm()) return false; |
Jim Grosbach | 0032640 | 2011-12-08 01:30:04 +0000 | [diff] [blame] | 855 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 856 | if (!CE) return false; |
| 857 | int64_t Value = CE->getValue(); |
| 858 | return Value >= 0 && Value < 64; |
| 859 | } |
Jim Grosbach | d4b8249 | 2011-12-07 01:07:24 +0000 | [diff] [blame] | 860 | bool isImm8() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 861 | if (!isImm()) return false; |
Jim Grosbach | d4b8249 | 2011-12-07 01:07:24 +0000 | [diff] [blame] | 862 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 863 | if (!CE) return false; |
| 864 | int64_t Value = CE->getValue(); |
| 865 | return Value == 8; |
| 866 | } |
| 867 | bool isImm16() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 868 | if (!isImm()) return false; |
Jim Grosbach | d4b8249 | 2011-12-07 01:07:24 +0000 | [diff] [blame] | 869 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 870 | if (!CE) return false; |
| 871 | int64_t Value = CE->getValue(); |
| 872 | return Value == 16; |
| 873 | } |
| 874 | bool isImm32() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 875 | if (!isImm()) return false; |
Jim Grosbach | d4b8249 | 2011-12-07 01:07:24 +0000 | [diff] [blame] | 876 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 877 | if (!CE) return false; |
| 878 | int64_t Value = CE->getValue(); |
| 879 | return Value == 32; |
| 880 | } |
Jim Grosbach | ba7d6ed | 2011-12-08 22:06:06 +0000 | [diff] [blame] | 881 | bool isShrImm8() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 882 | if (!isImm()) return false; |
Jim Grosbach | ba7d6ed | 2011-12-08 22:06:06 +0000 | [diff] [blame] | 883 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 884 | if (!CE) return false; |
| 885 | int64_t Value = CE->getValue(); |
| 886 | return Value > 0 && Value <= 8; |
| 887 | } |
| 888 | bool isShrImm16() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 889 | if (!isImm()) return false; |
Jim Grosbach | ba7d6ed | 2011-12-08 22:06:06 +0000 | [diff] [blame] | 890 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 891 | if (!CE) return false; |
| 892 | int64_t Value = CE->getValue(); |
| 893 | return Value > 0 && Value <= 16; |
| 894 | } |
| 895 | bool isShrImm32() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 896 | if (!isImm()) return false; |
Jim Grosbach | ba7d6ed | 2011-12-08 22:06:06 +0000 | [diff] [blame] | 897 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 898 | if (!CE) return false; |
| 899 | int64_t Value = CE->getValue(); |
| 900 | return Value > 0 && Value <= 32; |
| 901 | } |
| 902 | bool isShrImm64() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 903 | if (!isImm()) return false; |
Jim Grosbach | ba7d6ed | 2011-12-08 22:06:06 +0000 | [diff] [blame] | 904 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 905 | if (!CE) return false; |
| 906 | int64_t Value = CE->getValue(); |
| 907 | return Value > 0 && Value <= 64; |
| 908 | } |
Jim Grosbach | d4b8249 | 2011-12-07 01:07:24 +0000 | [diff] [blame] | 909 | bool isImm1_7() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 910 | if (!isImm()) return false; |
Jim Grosbach | d4b8249 | 2011-12-07 01:07:24 +0000 | [diff] [blame] | 911 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 912 | if (!CE) return false; |
| 913 | int64_t Value = CE->getValue(); |
| 914 | return Value > 0 && Value < 8; |
| 915 | } |
| 916 | bool isImm1_15() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 917 | if (!isImm()) return false; |
Jim Grosbach | d4b8249 | 2011-12-07 01:07:24 +0000 | [diff] [blame] | 918 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 919 | if (!CE) return false; |
| 920 | int64_t Value = CE->getValue(); |
| 921 | return Value > 0 && Value < 16; |
| 922 | } |
| 923 | bool isImm1_31() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 924 | if (!isImm()) return false; |
Jim Grosbach | d4b8249 | 2011-12-07 01:07:24 +0000 | [diff] [blame] | 925 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 926 | if (!CE) return false; |
| 927 | int64_t Value = CE->getValue(); |
| 928 | return Value > 0 && Value < 32; |
| 929 | } |
Jim Grosbach | 475c6db | 2011-07-25 23:09:14 +0000 | [diff] [blame] | 930 | bool isImm1_16() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 931 | if (!isImm()) return false; |
Jim Grosbach | 475c6db | 2011-07-25 23:09:14 +0000 | [diff] [blame] | 932 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 933 | if (!CE) return false; |
| 934 | int64_t Value = CE->getValue(); |
| 935 | return Value > 0 && Value < 17; |
| 936 | } |
Jim Grosbach | 801e0a3 | 2011-07-22 23:16:18 +0000 | [diff] [blame] | 937 | bool isImm1_32() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 938 | if (!isImm()) return false; |
Jim Grosbach | 801e0a3 | 2011-07-22 23:16:18 +0000 | [diff] [blame] | 939 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 940 | if (!CE) return false; |
| 941 | int64_t Value = CE->getValue(); |
| 942 | return Value > 0 && Value < 33; |
| 943 | } |
Jim Grosbach | c14871c | 2011-11-10 19:18:01 +0000 | [diff] [blame] | 944 | bool isImm0_32() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 945 | if (!isImm()) return false; |
Jim Grosbach | c14871c | 2011-11-10 19:18:01 +0000 | [diff] [blame] | 946 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 947 | if (!CE) return false; |
| 948 | int64_t Value = CE->getValue(); |
| 949 | return Value >= 0 && Value < 33; |
| 950 | } |
Jim Grosbach | 975b641 | 2011-07-13 20:10:10 +0000 | [diff] [blame] | 951 | bool isImm0_65535() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 952 | if (!isImm()) return false; |
Jim Grosbach | 975b641 | 2011-07-13 20:10:10 +0000 | [diff] [blame] | 953 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 954 | if (!CE) return false; |
| 955 | int64_t Value = CE->getValue(); |
| 956 | return Value >= 0 && Value < 65536; |
| 957 | } |
Mihai Popa | ae1112b | 2013-08-21 13:14:58 +0000 | [diff] [blame] | 958 | bool isImm256_65535Expr() const { |
| 959 | if (!isImm()) return false; |
| 960 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 961 | // If it's not a constant expression, it'll generate a fixup and be |
| 962 | // handled later. |
| 963 | if (!CE) return true; |
| 964 | int64_t Value = CE->getValue(); |
| 965 | return Value >= 256 && Value < 65536; |
| 966 | } |
Jim Grosbach | 7c09e3c | 2011-07-19 19:13:28 +0000 | [diff] [blame] | 967 | bool isImm0_65535Expr() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 968 | if (!isImm()) return false; |
Jim Grosbach | 7c09e3c | 2011-07-19 19:13:28 +0000 | [diff] [blame] | 969 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 970 | // If it's not a constant expression, it'll generate a fixup and be |
| 971 | // handled later. |
| 972 | if (!CE) return true; |
| 973 | int64_t Value = CE->getValue(); |
| 974 | return Value >= 0 && Value < 65536; |
| 975 | } |
Jim Grosbach | f163784 | 2011-07-26 16:24:27 +0000 | [diff] [blame] | 976 | bool isImm24bit() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 977 | if (!isImm()) return false; |
Jim Grosbach | f163784 | 2011-07-26 16:24:27 +0000 | [diff] [blame] | 978 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 979 | if (!CE) return false; |
| 980 | int64_t Value = CE->getValue(); |
| 981 | return Value >= 0 && Value <= 0xffffff; |
| 982 | } |
Jim Grosbach | 46dd413 | 2011-08-17 21:51:27 +0000 | [diff] [blame] | 983 | bool isImmThumbSR() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 984 | if (!isImm()) return false; |
Jim Grosbach | 46dd413 | 2011-08-17 21:51:27 +0000 | [diff] [blame] | 985 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 986 | if (!CE) return false; |
| 987 | int64_t Value = CE->getValue(); |
| 988 | return Value > 0 && Value < 33; |
| 989 | } |
Jim Grosbach | 27c1e25 | 2011-07-21 17:23:04 +0000 | [diff] [blame] | 990 | bool isPKHLSLImm() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 991 | if (!isImm()) return false; |
Jim Grosbach | 27c1e25 | 2011-07-21 17:23:04 +0000 | [diff] [blame] | 992 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 993 | if (!CE) return false; |
| 994 | int64_t Value = CE->getValue(); |
| 995 | return Value >= 0 && Value < 32; |
| 996 | } |
| 997 | bool isPKHASRImm() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 998 | if (!isImm()) return false; |
Jim Grosbach | 27c1e25 | 2011-07-21 17:23:04 +0000 | [diff] [blame] | 999 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1000 | if (!CE) return false; |
| 1001 | int64_t Value = CE->getValue(); |
| 1002 | return Value > 0 && Value <= 32; |
| 1003 | } |
Jiangning Liu | 10dd40e | 2012-08-02 08:13:13 +0000 | [diff] [blame] | 1004 | bool isAdrLabel() const { |
| 1005 | // If we have an immediate that's not a constant, treat it as a label |
| 1006 | // reference needing a fixup. If it is a constant, but it can't fit |
| 1007 | // into shift immediate encoding, we reject it. |
| 1008 | if (isImm() && !isa<MCConstantExpr>(getImm())) return true; |
| 1009 | else return (isARMSOImm() || isARMSOImmNeg()); |
| 1010 | } |
Jim Grosbach | 9720dcf | 2011-07-19 16:50:30 +0000 | [diff] [blame] | 1011 | bool isARMSOImm() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1012 | if (!isImm()) return false; |
Jim Grosbach | 9720dcf | 2011-07-19 16:50:30 +0000 | [diff] [blame] | 1013 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1014 | if (!CE) return false; |
| 1015 | int64_t Value = CE->getValue(); |
| 1016 | return ARM_AM::getSOImmVal(Value) != -1; |
| 1017 | } |
Jim Grosbach | 3d785ed | 2011-10-28 22:50:54 +0000 | [diff] [blame] | 1018 | bool isARMSOImmNot() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1019 | if (!isImm()) return false; |
Jim Grosbach | 3d785ed | 2011-10-28 22:50:54 +0000 | [diff] [blame] | 1020 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1021 | if (!CE) return false; |
| 1022 | int64_t Value = CE->getValue(); |
| 1023 | return ARM_AM::getSOImmVal(~Value) != -1; |
| 1024 | } |
Jim Grosbach | 3050625 | 2011-12-08 00:31:07 +0000 | [diff] [blame] | 1025 | bool isARMSOImmNeg() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1026 | if (!isImm()) return false; |
Jim Grosbach | 3050625 | 2011-12-08 00:31:07 +0000 | [diff] [blame] | 1027 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1028 | if (!CE) return false; |
| 1029 | int64_t Value = CE->getValue(); |
Jim Grosbach | fdaab53 | 2012-03-30 19:59:02 +0000 | [diff] [blame] | 1030 | // Only use this when not representable as a plain so_imm. |
| 1031 | return ARM_AM::getSOImmVal(Value) == -1 && |
| 1032 | ARM_AM::getSOImmVal(-Value) != -1; |
Jim Grosbach | 3050625 | 2011-12-08 00:31:07 +0000 | [diff] [blame] | 1033 | } |
Jim Grosbach | a6f7a1e | 2011-06-27 23:54:06 +0000 | [diff] [blame] | 1034 | bool isT2SOImm() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1035 | if (!isImm()) return false; |
Jim Grosbach | a6f7a1e | 2011-06-27 23:54:06 +0000 | [diff] [blame] | 1036 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1037 | if (!CE) return false; |
| 1038 | int64_t Value = CE->getValue(); |
| 1039 | return ARM_AM::getT2SOImmVal(Value) != -1; |
| 1040 | } |
Jim Grosbach | b009a87 | 2011-10-28 22:36:30 +0000 | [diff] [blame] | 1041 | bool isT2SOImmNot() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1042 | if (!isImm()) return false; |
Jim Grosbach | b009a87 | 2011-10-28 22:36:30 +0000 | [diff] [blame] | 1043 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1044 | if (!CE) return false; |
| 1045 | int64_t Value = CE->getValue(); |
Mihai Popa | cf276b2 | 2013-08-16 11:55:44 +0000 | [diff] [blame] | 1046 | return ARM_AM::getT2SOImmVal(Value) == -1 && |
| 1047 | ARM_AM::getT2SOImmVal(~Value) != -1; |
Jim Grosbach | b009a87 | 2011-10-28 22:36:30 +0000 | [diff] [blame] | 1048 | } |
Jim Grosbach | 3050625 | 2011-12-08 00:31:07 +0000 | [diff] [blame] | 1049 | bool isT2SOImmNeg() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1050 | if (!isImm()) return false; |
Jim Grosbach | 3050625 | 2011-12-08 00:31:07 +0000 | [diff] [blame] | 1051 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1052 | if (!CE) return false; |
| 1053 | int64_t Value = CE->getValue(); |
Jim Grosbach | fdaab53 | 2012-03-30 19:59:02 +0000 | [diff] [blame] | 1054 | // Only use this when not representable as a plain so_imm. |
| 1055 | return ARM_AM::getT2SOImmVal(Value) == -1 && |
| 1056 | ARM_AM::getT2SOImmVal(-Value) != -1; |
Jim Grosbach | 3050625 | 2011-12-08 00:31:07 +0000 | [diff] [blame] | 1057 | } |
Jim Grosbach | 0a54770 | 2011-07-22 17:44:50 +0000 | [diff] [blame] | 1058 | bool isSetEndImm() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1059 | if (!isImm()) return false; |
Jim Grosbach | 0a54770 | 2011-07-22 17:44:50 +0000 | [diff] [blame] | 1060 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1061 | if (!CE) return false; |
| 1062 | int64_t Value = CE->getValue(); |
| 1063 | return Value == 1 || Value == 0; |
| 1064 | } |
Craig Topper | ca7e3e5 | 2014-03-10 03:19:03 +0000 | [diff] [blame] | 1065 | bool isReg() const override { return Kind == k_Register; } |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 1066 | bool isRegList() const { return Kind == k_RegisterList; } |
| 1067 | bool isDPRRegList() const { return Kind == k_DPRRegisterList; } |
| 1068 | bool isSPRRegList() const { return Kind == k_SPRRegisterList; } |
Craig Topper | ca7e3e5 | 2014-03-10 03:19:03 +0000 | [diff] [blame] | 1069 | bool isToken() const override { return Kind == k_Token; } |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 1070 | bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; } |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 1071 | bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; } |
Craig Topper | ca7e3e5 | 2014-03-10 03:19:03 +0000 | [diff] [blame] | 1072 | bool isMem() const override { return Kind == k_Memory; } |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 1073 | bool isShifterImm() const { return Kind == k_ShifterImmediate; } |
| 1074 | bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; } |
| 1075 | bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; } |
| 1076 | bool isRotImm() const { return Kind == k_RotateImmediate; } |
| 1077 | bool isBitfield() const { return Kind == k_BitfieldDescriptor; } |
| 1078 | bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; } |
Jim Grosbach | c320c85 | 2011-08-05 21:28:30 +0000 | [diff] [blame] | 1079 | bool isPostIdxReg() const { |
Jim Grosbach | ee201fa | 2011-11-14 17:52:47 +0000 | [diff] [blame] | 1080 | return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift; |
Jim Grosbach | c320c85 | 2011-08-05 21:28:30 +0000 | [diff] [blame] | 1081 | } |
Kevin Enderby | 488f20b | 2014-04-10 20:18:58 +0000 | [diff] [blame] | 1082 | bool isMemNoOffset(bool alignOK = false, unsigned Alignment = 0) const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1083 | if (!isMem()) |
Bruno Cardoso Lopes | ab83050 | 2011-03-31 23:26:08 +0000 | [diff] [blame] | 1084 | return false; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1085 | // No offset of any kind. |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1086 | return Memory.OffsetRegNum == 0 && Memory.OffsetImm == nullptr && |
Kevin Enderby | 488f20b | 2014-04-10 20:18:58 +0000 | [diff] [blame] | 1087 | (alignOK || Memory.Alignment == Alignment); |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 1088 | } |
Jim Grosbach | 94298a9 | 2012-01-18 22:46:46 +0000 | [diff] [blame] | 1089 | bool isMemPCRelImm12() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1090 | if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) |
Jim Grosbach | 94298a9 | 2012-01-18 22:46:46 +0000 | [diff] [blame] | 1091 | return false; |
| 1092 | // Base register must be PC. |
| 1093 | if (Memory.BaseRegNum != ARM::PC) |
| 1094 | return false; |
| 1095 | // Immediate offset in range [-4095, 4095]. |
| 1096 | if (!Memory.OffsetImm) return true; |
| 1097 | int64_t Val = Memory.OffsetImm->getValue(); |
| 1098 | return (Val > -4096 && Val < 4096) || (Val == INT32_MIN); |
| 1099 | } |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 1100 | bool isAlignedMemory() const { |
| 1101 | return isMemNoOffset(true); |
Bruno Cardoso Lopes | ab83050 | 2011-03-31 23:26:08 +0000 | [diff] [blame] | 1102 | } |
Kevin Enderby | 488f20b | 2014-04-10 20:18:58 +0000 | [diff] [blame] | 1103 | bool isAlignedMemoryNone() const { |
| 1104 | return isMemNoOffset(false, 0); |
| 1105 | } |
| 1106 | bool isDupAlignedMemoryNone() const { |
| 1107 | return isMemNoOffset(false, 0); |
| 1108 | } |
| 1109 | bool isAlignedMemory16() const { |
| 1110 | if (isMemNoOffset(false, 2)) // alignment in bytes for 16-bits is 2. |
| 1111 | return true; |
| 1112 | return isMemNoOffset(false, 0); |
| 1113 | } |
| 1114 | bool isDupAlignedMemory16() const { |
| 1115 | if (isMemNoOffset(false, 2)) // alignment in bytes for 16-bits is 2. |
| 1116 | return true; |
| 1117 | return isMemNoOffset(false, 0); |
| 1118 | } |
| 1119 | bool isAlignedMemory32() const { |
| 1120 | if (isMemNoOffset(false, 4)) // alignment in bytes for 32-bits is 4. |
| 1121 | return true; |
| 1122 | return isMemNoOffset(false, 0); |
| 1123 | } |
| 1124 | bool isDupAlignedMemory32() const { |
| 1125 | if (isMemNoOffset(false, 4)) // alignment in bytes for 32-bits is 4. |
| 1126 | return true; |
| 1127 | return isMemNoOffset(false, 0); |
| 1128 | } |
| 1129 | bool isAlignedMemory64() const { |
| 1130 | if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8. |
| 1131 | return true; |
| 1132 | return isMemNoOffset(false, 0); |
| 1133 | } |
| 1134 | bool isDupAlignedMemory64() const { |
| 1135 | if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8. |
| 1136 | return true; |
| 1137 | return isMemNoOffset(false, 0); |
| 1138 | } |
| 1139 | bool isAlignedMemory64or128() const { |
| 1140 | if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8. |
| 1141 | return true; |
| 1142 | if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16. |
| 1143 | return true; |
| 1144 | return isMemNoOffset(false, 0); |
| 1145 | } |
| 1146 | bool isDupAlignedMemory64or128() const { |
| 1147 | if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8. |
| 1148 | return true; |
| 1149 | if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16. |
| 1150 | return true; |
| 1151 | return isMemNoOffset(false, 0); |
| 1152 | } |
| 1153 | bool isAlignedMemory64or128or256() const { |
| 1154 | if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8. |
| 1155 | return true; |
| 1156 | if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16. |
| 1157 | return true; |
| 1158 | if (isMemNoOffset(false, 32)) // alignment in bytes for 256-bits is 32. |
| 1159 | return true; |
| 1160 | return isMemNoOffset(false, 0); |
| 1161 | } |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1162 | bool isAddrMode2() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1163 | if (!isMem() || Memory.Alignment != 0) return false; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1164 | // Check for register offset. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1165 | if (Memory.OffsetRegNum) return true; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1166 | // Immediate offset in range [-4095, 4095]. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1167 | if (!Memory.OffsetImm) return true; |
| 1168 | int64_t Val = Memory.OffsetImm->getValue(); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1169 | return Val > -4096 && Val < 4096; |
Bruno Cardoso Lopes | bda3632 | 2011-04-04 17:18:19 +0000 | [diff] [blame] | 1170 | } |
Jim Grosbach | cd17c12 | 2011-08-04 23:01:30 +0000 | [diff] [blame] | 1171 | bool isAM2OffsetImm() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1172 | if (!isImm()) return false; |
Jim Grosbach | cd17c12 | 2011-08-04 23:01:30 +0000 | [diff] [blame] | 1173 | // Immediate offset in range [-4095, 4095]. |
| 1174 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1175 | if (!CE) return false; |
| 1176 | int64_t Val = CE->getValue(); |
Mihai Popa | c1d119e | 2013-06-11 09:48:35 +0000 | [diff] [blame] | 1177 | return (Val == INT32_MIN) || (Val > -4096 && Val < 4096); |
Jim Grosbach | cd17c12 | 2011-08-04 23:01:30 +0000 | [diff] [blame] | 1178 | } |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 1179 | bool isAddrMode3() const { |
Jim Grosbach | 8648c10 | 2011-12-19 23:06:24 +0000 | [diff] [blame] | 1180 | // If we have an immediate that's not a constant, treat it as a label |
| 1181 | // reference needing a fixup. If it is a constant, it's something else |
| 1182 | // and we reject it. |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1183 | if (isImm() && !isa<MCConstantExpr>(getImm())) |
Jim Grosbach | 8648c10 | 2011-12-19 23:06:24 +0000 | [diff] [blame] | 1184 | return true; |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1185 | if (!isMem() || Memory.Alignment != 0) return false; |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 1186 | // No shifts are legal for AM3. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1187 | if (Memory.ShiftType != ARM_AM::no_shift) return false; |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 1188 | // Check for register offset. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1189 | if (Memory.OffsetRegNum) return true; |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 1190 | // Immediate offset in range [-255, 255]. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1191 | if (!Memory.OffsetImm) return true; |
| 1192 | int64_t Val = Memory.OffsetImm->getValue(); |
Silviu Baranga | 5a719f9 | 2012-05-11 09:10:54 +0000 | [diff] [blame] | 1193 | // The #-0 offset is encoded as INT32_MIN, and we have to check |
| 1194 | // for this too. |
| 1195 | return (Val > -256 && Val < 256) || Val == INT32_MIN; |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 1196 | } |
| 1197 | bool isAM3Offset() const { |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 1198 | if (Kind != k_Immediate && Kind != k_PostIndexRegister) |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 1199 | return false; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 1200 | if (Kind == k_PostIndexRegister) |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 1201 | return PostIdxReg.ShiftTy == ARM_AM::no_shift; |
| 1202 | // Immediate offset in range [-255, 255]. |
| 1203 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1204 | if (!CE) return false; |
| 1205 | int64_t Val = CE->getValue(); |
Jim Grosbach | 1d9d5e9 | 2011-08-10 21:56:18 +0000 | [diff] [blame] | 1206 | // Special case, #-0 is INT32_MIN. |
| 1207 | return (Val > -256 && Val < 256) || Val == INT32_MIN; |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 1208 | } |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1209 | bool isAddrMode5() const { |
Jim Grosbach | fb2f1d6 | 2011-11-01 01:24:45 +0000 | [diff] [blame] | 1210 | // If we have an immediate that's not a constant, treat it as a label |
| 1211 | // reference needing a fixup. If it is a constant, it's something else |
| 1212 | // and we reject it. |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1213 | if (isImm() && !isa<MCConstantExpr>(getImm())) |
Jim Grosbach | fb2f1d6 | 2011-11-01 01:24:45 +0000 | [diff] [blame] | 1214 | return true; |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1215 | if (!isMem() || Memory.Alignment != 0) return false; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1216 | // Check for register offset. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1217 | if (Memory.OffsetRegNum) return false; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1218 | // Immediate offset in range [-1020, 1020] and a multiple of 4. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1219 | if (!Memory.OffsetImm) return true; |
| 1220 | int64_t Val = Memory.OffsetImm->getValue(); |
Owen Anderson | 967674d | 2011-08-29 19:36:44 +0000 | [diff] [blame] | 1221 | return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) || |
Jim Grosbach | fb2f1d6 | 2011-11-01 01:24:45 +0000 | [diff] [blame] | 1222 | Val == INT32_MIN; |
Bill Wendling | 8d2aa03 | 2010-11-08 23:49:57 +0000 | [diff] [blame] | 1223 | } |
Jim Grosbach | 05541f4 | 2011-09-19 22:21:13 +0000 | [diff] [blame] | 1224 | bool isMemTBB() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1225 | if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative || |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 1226 | Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0) |
Jim Grosbach | 05541f4 | 2011-09-19 22:21:13 +0000 | [diff] [blame] | 1227 | return false; |
| 1228 | return true; |
| 1229 | } |
| 1230 | bool isMemTBH() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1231 | if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative || |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 1232 | Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 || |
| 1233 | Memory.Alignment != 0 ) |
Jim Grosbach | 05541f4 | 2011-09-19 22:21:13 +0000 | [diff] [blame] | 1234 | return false; |
| 1235 | return true; |
| 1236 | } |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1237 | bool isMemRegOffset() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1238 | if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0) |
Bill Wendling | 092a7bd | 2010-12-14 03:36:38 +0000 | [diff] [blame] | 1239 | return false; |
Daniel Dunbar | 7ed4559 | 2011-01-18 05:34:11 +0000 | [diff] [blame] | 1240 | return true; |
Bill Wendling | 092a7bd | 2010-12-14 03:36:38 +0000 | [diff] [blame] | 1241 | } |
Jim Grosbach | e0ebc1c | 2011-09-07 23:10:15 +0000 | [diff] [blame] | 1242 | bool isT2MemRegOffset() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1243 | if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative || |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 1244 | Memory.Alignment != 0) |
Jim Grosbach | e0ebc1c | 2011-09-07 23:10:15 +0000 | [diff] [blame] | 1245 | return false; |
| 1246 | // Only lsl #{0, 1, 2, 3} allowed. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1247 | if (Memory.ShiftType == ARM_AM::no_shift) |
Jim Grosbach | e0ebc1c | 2011-09-07 23:10:15 +0000 | [diff] [blame] | 1248 | return true; |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1249 | if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3) |
Jim Grosbach | e0ebc1c | 2011-09-07 23:10:15 +0000 | [diff] [blame] | 1250 | return false; |
| 1251 | return true; |
| 1252 | } |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1253 | bool isMemThumbRR() const { |
| 1254 | // Thumb reg+reg addressing is simple. Just two registers, a base and |
| 1255 | // an offset. No shifts, negations or any other complicating factors. |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1256 | if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative || |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 1257 | Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0) |
Bill Wendling | 811c936 | 2010-11-30 07:44:32 +0000 | [diff] [blame] | 1258 | return false; |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1259 | return isARMLowRegister(Memory.BaseRegNum) && |
| 1260 | (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum)); |
Jim Grosbach | 3fe94e3 | 2011-08-19 17:55:24 +0000 | [diff] [blame] | 1261 | } |
| 1262 | bool isMemThumbRIs4() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1263 | if (!isMem() || Memory.OffsetRegNum != 0 || |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 1264 | !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0) |
Jim Grosbach | 3fe94e3 | 2011-08-19 17:55:24 +0000 | [diff] [blame] | 1265 | return false; |
| 1266 | // Immediate offset, multiple of 4 in range [0, 124]. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1267 | if (!Memory.OffsetImm) return true; |
| 1268 | int64_t Val = Memory.OffsetImm->getValue(); |
Jim Grosbach | 23983d6 | 2011-08-19 18:13:48 +0000 | [diff] [blame] | 1269 | return Val >= 0 && Val <= 124 && (Val % 4) == 0; |
| 1270 | } |
Jim Grosbach | 26d3587 | 2011-08-19 18:55:51 +0000 | [diff] [blame] | 1271 | bool isMemThumbRIs2() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1272 | if (!isMem() || Memory.OffsetRegNum != 0 || |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 1273 | !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0) |
Jim Grosbach | 26d3587 | 2011-08-19 18:55:51 +0000 | [diff] [blame] | 1274 | return false; |
| 1275 | // Immediate offset, multiple of 4 in range [0, 62]. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1276 | if (!Memory.OffsetImm) return true; |
| 1277 | int64_t Val = Memory.OffsetImm->getValue(); |
Jim Grosbach | 26d3587 | 2011-08-19 18:55:51 +0000 | [diff] [blame] | 1278 | return Val >= 0 && Val <= 62 && (Val % 2) == 0; |
| 1279 | } |
Jim Grosbach | a32c753 | 2011-08-19 18:49:59 +0000 | [diff] [blame] | 1280 | bool isMemThumbRIs1() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1281 | if (!isMem() || Memory.OffsetRegNum != 0 || |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 1282 | !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0) |
Jim Grosbach | a32c753 | 2011-08-19 18:49:59 +0000 | [diff] [blame] | 1283 | return false; |
| 1284 | // Immediate offset in range [0, 31]. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1285 | if (!Memory.OffsetImm) return true; |
| 1286 | int64_t Val = Memory.OffsetImm->getValue(); |
Jim Grosbach | a32c753 | 2011-08-19 18:49:59 +0000 | [diff] [blame] | 1287 | return Val >= 0 && Val <= 31; |
| 1288 | } |
Jim Grosbach | 23983d6 | 2011-08-19 18:13:48 +0000 | [diff] [blame] | 1289 | bool isMemThumbSPI() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1290 | if (!isMem() || Memory.OffsetRegNum != 0 || |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 1291 | Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0) |
Jim Grosbach | 23983d6 | 2011-08-19 18:13:48 +0000 | [diff] [blame] | 1292 | return false; |
| 1293 | // Immediate offset, multiple of 4 in range [0, 1020]. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1294 | if (!Memory.OffsetImm) return true; |
| 1295 | int64_t Val = Memory.OffsetImm->getValue(); |
Jim Grosbach | 23983d6 | 2011-08-19 18:13:48 +0000 | [diff] [blame] | 1296 | return Val >= 0 && Val <= 1020 && (Val % 4) == 0; |
Bill Wendling | 811c936 | 2010-11-30 07:44:32 +0000 | [diff] [blame] | 1297 | } |
Jim Grosbach | 7db8d69 | 2011-09-08 22:07:06 +0000 | [diff] [blame] | 1298 | bool isMemImm8s4Offset() const { |
Jim Grosbach | 8648c10 | 2011-12-19 23:06:24 +0000 | [diff] [blame] | 1299 | // If we have an immediate that's not a constant, treat it as a label |
| 1300 | // reference needing a fixup. If it is a constant, it's something else |
| 1301 | // and we reject it. |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1302 | if (isImm() && !isa<MCConstantExpr>(getImm())) |
Jim Grosbach | 8648c10 | 2011-12-19 23:06:24 +0000 | [diff] [blame] | 1303 | return true; |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1304 | if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) |
Jim Grosbach | 7db8d69 | 2011-09-08 22:07:06 +0000 | [diff] [blame] | 1305 | return false; |
| 1306 | // Immediate offset a multiple of 4 in range [-1020, 1020]. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1307 | if (!Memory.OffsetImm) return true; |
| 1308 | int64_t Val = Memory.OffsetImm->getValue(); |
Jiangning Liu | 6a43bf7 | 2012-08-02 08:29:50 +0000 | [diff] [blame] | 1309 | // Special case, #-0 is INT32_MIN. |
| 1310 | return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN; |
Jim Grosbach | 7db8d69 | 2011-09-08 22:07:06 +0000 | [diff] [blame] | 1311 | } |
Jim Grosbach | a05627e | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 1312 | bool isMemImm0_1020s4Offset() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1313 | if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) |
Jim Grosbach | a05627e | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 1314 | return false; |
| 1315 | // Immediate offset a multiple of 4 in range [0, 1020]. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1316 | if (!Memory.OffsetImm) return true; |
| 1317 | int64_t Val = Memory.OffsetImm->getValue(); |
Jim Grosbach | a05627e | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 1318 | return Val >= 0 && Val <= 1020 && (Val & 3) == 0; |
| 1319 | } |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1320 | bool isMemImm8Offset() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1321 | if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1322 | return false; |
Jim Grosbach | 94298a9 | 2012-01-18 22:46:46 +0000 | [diff] [blame] | 1323 | // Base reg of PC isn't allowed for these encodings. |
| 1324 | if (Memory.BaseRegNum == ARM::PC) return false; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1325 | // Immediate offset in range [-255, 255]. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1326 | if (!Memory.OffsetImm) return true; |
| 1327 | int64_t Val = Memory.OffsetImm->getValue(); |
Owen Anderson | 4916840 | 2011-09-23 22:25:02 +0000 | [diff] [blame] | 1328 | return (Val == INT32_MIN) || (Val > -256 && Val < 256); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1329 | } |
Jim Grosbach | 2392c53 | 2011-09-07 23:39:14 +0000 | [diff] [blame] | 1330 | bool isMemPosImm8Offset() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1331 | if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) |
Jim Grosbach | 2392c53 | 2011-09-07 23:39:14 +0000 | [diff] [blame] | 1332 | return false; |
| 1333 | // Immediate offset in range [0, 255]. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1334 | if (!Memory.OffsetImm) return true; |
| 1335 | int64_t Val = Memory.OffsetImm->getValue(); |
Jim Grosbach | 2392c53 | 2011-09-07 23:39:14 +0000 | [diff] [blame] | 1336 | return Val >= 0 && Val < 256; |
| 1337 | } |
Jim Grosbach | 5bfa8ba | 2011-09-07 20:58:57 +0000 | [diff] [blame] | 1338 | bool isMemNegImm8Offset() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1339 | if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) |
Jim Grosbach | 5bfa8ba | 2011-09-07 20:58:57 +0000 | [diff] [blame] | 1340 | return false; |
Jim Grosbach | 94298a9 | 2012-01-18 22:46:46 +0000 | [diff] [blame] | 1341 | // Base reg of PC isn't allowed for these encodings. |
| 1342 | if (Memory.BaseRegNum == ARM::PC) return false; |
Jim Grosbach | 5bfa8ba | 2011-09-07 20:58:57 +0000 | [diff] [blame] | 1343 | // Immediate offset in range [-255, -1]. |
Jim Grosbach | 175c7d0 | 2011-12-06 04:49:29 +0000 | [diff] [blame] | 1344 | if (!Memory.OffsetImm) return false; |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1345 | int64_t Val = Memory.OffsetImm->getValue(); |
Jim Grosbach | 175c7d0 | 2011-12-06 04:49:29 +0000 | [diff] [blame] | 1346 | return (Val == INT32_MIN) || (Val > -256 && Val < 0); |
Jim Grosbach | 5bfa8ba | 2011-09-07 20:58:57 +0000 | [diff] [blame] | 1347 | } |
| 1348 | bool isMemUImm12Offset() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1349 | if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) |
Jim Grosbach | 5bfa8ba | 2011-09-07 20:58:57 +0000 | [diff] [blame] | 1350 | return false; |
| 1351 | // Immediate offset in range [0, 4095]. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1352 | if (!Memory.OffsetImm) return true; |
| 1353 | int64_t Val = Memory.OffsetImm->getValue(); |
Jim Grosbach | 5bfa8ba | 2011-09-07 20:58:57 +0000 | [diff] [blame] | 1354 | return (Val >= 0 && Val < 4096); |
| 1355 | } |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1356 | bool isMemImm12Offset() const { |
Jim Grosbach | 95466ce | 2011-08-08 20:59:31 +0000 | [diff] [blame] | 1357 | // If we have an immediate that's not a constant, treat it as a label |
| 1358 | // reference needing a fixup. If it is a constant, it's something else |
| 1359 | // and we reject it. |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1360 | if (isImm() && !isa<MCConstantExpr>(getImm())) |
Jim Grosbach | 95466ce | 2011-08-08 20:59:31 +0000 | [diff] [blame] | 1361 | return true; |
| 1362 | |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1363 | if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1364 | return false; |
| 1365 | // Immediate offset in range [-4095, 4095]. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1366 | if (!Memory.OffsetImm) return true; |
| 1367 | int64_t Val = Memory.OffsetImm->getValue(); |
Owen Anderson | 967674d | 2011-08-29 19:36:44 +0000 | [diff] [blame] | 1368 | return (Val > -4096 && Val < 4096) || (Val == INT32_MIN); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1369 | } |
| 1370 | bool isPostIdxImm8() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1371 | if (!isImm()) return false; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1372 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1373 | if (!CE) return false; |
| 1374 | int64_t Val = CE->getValue(); |
Owen Anderson | f02d98d | 2011-08-29 17:17:09 +0000 | [diff] [blame] | 1375 | return (Val > -256 && Val < 256) || (Val == INT32_MIN); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1376 | } |
Jim Grosbach | 9398141 | 2011-10-11 21:55:36 +0000 | [diff] [blame] | 1377 | bool isPostIdxImm8s4() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1378 | if (!isImm()) return false; |
Jim Grosbach | 9398141 | 2011-10-11 21:55:36 +0000 | [diff] [blame] | 1379 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1380 | if (!CE) return false; |
| 1381 | int64_t Val = CE->getValue(); |
| 1382 | return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) || |
| 1383 | (Val == INT32_MIN); |
| 1384 | } |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1385 | |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 1386 | bool isMSRMask() const { return Kind == k_MSRMask; } |
| 1387 | bool isProcIFlags() const { return Kind == k_ProcIFlags; } |
Daniel Dunbar | 5cd4d0f | 2010-08-11 05:24:50 +0000 | [diff] [blame] | 1388 | |
Jim Grosbach | 741cd73 | 2011-10-17 22:26:03 +0000 | [diff] [blame] | 1389 | // NEON operands. |
Jim Grosbach | 2f50e92 | 2011-12-15 21:44:33 +0000 | [diff] [blame] | 1390 | bool isSingleSpacedVectorList() const { |
| 1391 | return Kind == k_VectorList && !VectorList.isDoubleSpaced; |
| 1392 | } |
| 1393 | bool isDoubleSpacedVectorList() const { |
| 1394 | return Kind == k_VectorList && VectorList.isDoubleSpaced; |
| 1395 | } |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 1396 | bool isVecListOneD() const { |
Jim Grosbach | 2f50e92 | 2011-12-15 21:44:33 +0000 | [diff] [blame] | 1397 | if (!isSingleSpacedVectorList()) return false; |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 1398 | return VectorList.Count == 1; |
| 1399 | } |
| 1400 | |
Jim Grosbach | c988e0c | 2012-03-05 19:33:30 +0000 | [diff] [blame] | 1401 | bool isVecListDPair() const { |
| 1402 | if (!isSingleSpacedVectorList()) return false; |
| 1403 | return (ARMMCRegisterClasses[ARM::DPairRegClassID] |
| 1404 | .contains(VectorList.RegNum)); |
| 1405 | } |
| 1406 | |
Jim Grosbach | c4360fe | 2011-10-21 20:02:19 +0000 | [diff] [blame] | 1407 | bool isVecListThreeD() const { |
Jim Grosbach | 2f50e92 | 2011-12-15 21:44:33 +0000 | [diff] [blame] | 1408 | if (!isSingleSpacedVectorList()) return false; |
Jim Grosbach | c4360fe | 2011-10-21 20:02:19 +0000 | [diff] [blame] | 1409 | return VectorList.Count == 3; |
| 1410 | } |
| 1411 | |
Jim Grosbach | 846bcff | 2011-10-21 20:35:01 +0000 | [diff] [blame] | 1412 | bool isVecListFourD() const { |
Jim Grosbach | 2f50e92 | 2011-12-15 21:44:33 +0000 | [diff] [blame] | 1413 | if (!isSingleSpacedVectorList()) return false; |
Jim Grosbach | 846bcff | 2011-10-21 20:35:01 +0000 | [diff] [blame] | 1414 | return VectorList.Count == 4; |
| 1415 | } |
| 1416 | |
Jim Grosbach | e5307f9 | 2012-03-05 21:43:40 +0000 | [diff] [blame] | 1417 | bool isVecListDPairSpaced() const { |
Kevin Enderby | 5611398 | 2014-03-26 21:54:11 +0000 | [diff] [blame] | 1418 | if (Kind != k_VectorList) return false; |
Kevin Enderby | 816ca27 | 2012-03-20 17:41:51 +0000 | [diff] [blame] | 1419 | if (isSingleSpacedVectorList()) return false; |
Jim Grosbach | e5307f9 | 2012-03-05 21:43:40 +0000 | [diff] [blame] | 1420 | return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID] |
| 1421 | .contains(VectorList.RegNum)); |
| 1422 | } |
| 1423 | |
Jim Grosbach | ac2af3f | 2012-01-23 23:20:46 +0000 | [diff] [blame] | 1424 | bool isVecListThreeQ() const { |
| 1425 | if (!isDoubleSpacedVectorList()) return false; |
| 1426 | return VectorList.Count == 3; |
| 1427 | } |
| 1428 | |
Jim Grosbach | 1e946a4 | 2012-01-24 00:43:12 +0000 | [diff] [blame] | 1429 | bool isVecListFourQ() const { |
| 1430 | if (!isDoubleSpacedVectorList()) return false; |
| 1431 | return VectorList.Count == 4; |
| 1432 | } |
| 1433 | |
Jim Grosbach | c5af54e | 2011-12-21 00:38:54 +0000 | [diff] [blame] | 1434 | bool isSingleSpacedVectorAllLanes() const { |
| 1435 | return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced; |
| 1436 | } |
| 1437 | bool isDoubleSpacedVectorAllLanes() const { |
| 1438 | return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced; |
| 1439 | } |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 1440 | bool isVecListOneDAllLanes() const { |
Jim Grosbach | c5af54e | 2011-12-21 00:38:54 +0000 | [diff] [blame] | 1441 | if (!isSingleSpacedVectorAllLanes()) return false; |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 1442 | return VectorList.Count == 1; |
| 1443 | } |
| 1444 | |
Jim Grosbach | 13a292c | 2012-03-06 22:01:44 +0000 | [diff] [blame] | 1445 | bool isVecListDPairAllLanes() const { |
Jim Grosbach | c5af54e | 2011-12-21 00:38:54 +0000 | [diff] [blame] | 1446 | if (!isSingleSpacedVectorAllLanes()) return false; |
Jim Grosbach | 13a292c | 2012-03-06 22:01:44 +0000 | [diff] [blame] | 1447 | return (ARMMCRegisterClasses[ARM::DPairRegClassID] |
| 1448 | .contains(VectorList.RegNum)); |
Jim Grosbach | c5af54e | 2011-12-21 00:38:54 +0000 | [diff] [blame] | 1449 | } |
| 1450 | |
Jim Grosbach | ed428bc | 2012-03-06 23:10:38 +0000 | [diff] [blame] | 1451 | bool isVecListDPairSpacedAllLanes() const { |
Jim Grosbach | c5af54e | 2011-12-21 00:38:54 +0000 | [diff] [blame] | 1452 | if (!isDoubleSpacedVectorAllLanes()) return false; |
Jim Grosbach | 3ecf976 | 2011-11-30 18:21:25 +0000 | [diff] [blame] | 1453 | return VectorList.Count == 2; |
| 1454 | } |
| 1455 | |
Jim Grosbach | b78403c | 2012-01-24 23:47:04 +0000 | [diff] [blame] | 1456 | bool isVecListThreeDAllLanes() const { |
| 1457 | if (!isSingleSpacedVectorAllLanes()) return false; |
| 1458 | return VectorList.Count == 3; |
| 1459 | } |
| 1460 | |
| 1461 | bool isVecListThreeQAllLanes() const { |
| 1462 | if (!isDoubleSpacedVectorAllLanes()) return false; |
| 1463 | return VectorList.Count == 3; |
| 1464 | } |
| 1465 | |
Jim Grosbach | 086cbfa | 2012-01-25 00:01:08 +0000 | [diff] [blame] | 1466 | bool isVecListFourDAllLanes() const { |
| 1467 | if (!isSingleSpacedVectorAllLanes()) return false; |
| 1468 | return VectorList.Count == 4; |
| 1469 | } |
| 1470 | |
| 1471 | bool isVecListFourQAllLanes() const { |
| 1472 | if (!isDoubleSpacedVectorAllLanes()) return false; |
| 1473 | return VectorList.Count == 4; |
| 1474 | } |
| 1475 | |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 1476 | bool isSingleSpacedVectorIndexed() const { |
| 1477 | return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced; |
| 1478 | } |
| 1479 | bool isDoubleSpacedVectorIndexed() const { |
| 1480 | return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced; |
| 1481 | } |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 1482 | bool isVecListOneDByteIndexed() const { |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 1483 | if (!isSingleSpacedVectorIndexed()) return false; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 1484 | return VectorList.Count == 1 && VectorList.LaneIndex <= 7; |
| 1485 | } |
| 1486 | |
Jim Grosbach | da51104 | 2011-12-14 23:35:06 +0000 | [diff] [blame] | 1487 | bool isVecListOneDHWordIndexed() const { |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 1488 | if (!isSingleSpacedVectorIndexed()) return false; |
Jim Grosbach | da51104 | 2011-12-14 23:35:06 +0000 | [diff] [blame] | 1489 | return VectorList.Count == 1 && VectorList.LaneIndex <= 3; |
| 1490 | } |
| 1491 | |
| 1492 | bool isVecListOneDWordIndexed() const { |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 1493 | if (!isSingleSpacedVectorIndexed()) return false; |
Jim Grosbach | da51104 | 2011-12-14 23:35:06 +0000 | [diff] [blame] | 1494 | return VectorList.Count == 1 && VectorList.LaneIndex <= 1; |
| 1495 | } |
| 1496 | |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 1497 | bool isVecListTwoDByteIndexed() const { |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 1498 | if (!isSingleSpacedVectorIndexed()) return false; |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 1499 | return VectorList.Count == 2 && VectorList.LaneIndex <= 7; |
| 1500 | } |
| 1501 | |
Jim Grosbach | da51104 | 2011-12-14 23:35:06 +0000 | [diff] [blame] | 1502 | bool isVecListTwoDHWordIndexed() const { |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 1503 | if (!isSingleSpacedVectorIndexed()) return false; |
| 1504 | return VectorList.Count == 2 && VectorList.LaneIndex <= 3; |
| 1505 | } |
| 1506 | |
| 1507 | bool isVecListTwoQWordIndexed() const { |
| 1508 | if (!isDoubleSpacedVectorIndexed()) return false; |
| 1509 | return VectorList.Count == 2 && VectorList.LaneIndex <= 1; |
| 1510 | } |
| 1511 | |
| 1512 | bool isVecListTwoQHWordIndexed() const { |
| 1513 | if (!isDoubleSpacedVectorIndexed()) return false; |
Jim Grosbach | da51104 | 2011-12-14 23:35:06 +0000 | [diff] [blame] | 1514 | return VectorList.Count == 2 && VectorList.LaneIndex <= 3; |
| 1515 | } |
| 1516 | |
| 1517 | bool isVecListTwoDWordIndexed() const { |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 1518 | if (!isSingleSpacedVectorIndexed()) return false; |
Jim Grosbach | da51104 | 2011-12-14 23:35:06 +0000 | [diff] [blame] | 1519 | return VectorList.Count == 2 && VectorList.LaneIndex <= 1; |
| 1520 | } |
| 1521 | |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 1522 | bool isVecListThreeDByteIndexed() const { |
| 1523 | if (!isSingleSpacedVectorIndexed()) return false; |
| 1524 | return VectorList.Count == 3 && VectorList.LaneIndex <= 7; |
| 1525 | } |
| 1526 | |
| 1527 | bool isVecListThreeDHWordIndexed() const { |
| 1528 | if (!isSingleSpacedVectorIndexed()) return false; |
| 1529 | return VectorList.Count == 3 && VectorList.LaneIndex <= 3; |
| 1530 | } |
| 1531 | |
| 1532 | bool isVecListThreeQWordIndexed() const { |
| 1533 | if (!isDoubleSpacedVectorIndexed()) return false; |
| 1534 | return VectorList.Count == 3 && VectorList.LaneIndex <= 1; |
| 1535 | } |
| 1536 | |
| 1537 | bool isVecListThreeQHWordIndexed() const { |
| 1538 | if (!isDoubleSpacedVectorIndexed()) return false; |
| 1539 | return VectorList.Count == 3 && VectorList.LaneIndex <= 3; |
| 1540 | } |
| 1541 | |
| 1542 | bool isVecListThreeDWordIndexed() const { |
| 1543 | if (!isSingleSpacedVectorIndexed()) return false; |
| 1544 | return VectorList.Count == 3 && VectorList.LaneIndex <= 1; |
| 1545 | } |
| 1546 | |
Jim Grosbach | 14952a0 | 2012-01-24 18:37:25 +0000 | [diff] [blame] | 1547 | bool isVecListFourDByteIndexed() const { |
| 1548 | if (!isSingleSpacedVectorIndexed()) return false; |
| 1549 | return VectorList.Count == 4 && VectorList.LaneIndex <= 7; |
| 1550 | } |
| 1551 | |
| 1552 | bool isVecListFourDHWordIndexed() const { |
| 1553 | if (!isSingleSpacedVectorIndexed()) return false; |
| 1554 | return VectorList.Count == 4 && VectorList.LaneIndex <= 3; |
| 1555 | } |
| 1556 | |
| 1557 | bool isVecListFourQWordIndexed() const { |
| 1558 | if (!isDoubleSpacedVectorIndexed()) return false; |
| 1559 | return VectorList.Count == 4 && VectorList.LaneIndex <= 1; |
| 1560 | } |
| 1561 | |
| 1562 | bool isVecListFourQHWordIndexed() const { |
| 1563 | if (!isDoubleSpacedVectorIndexed()) return false; |
| 1564 | return VectorList.Count == 4 && VectorList.LaneIndex <= 3; |
| 1565 | } |
| 1566 | |
| 1567 | bool isVecListFourDWordIndexed() const { |
| 1568 | if (!isSingleSpacedVectorIndexed()) return false; |
| 1569 | return VectorList.Count == 4 && VectorList.LaneIndex <= 1; |
| 1570 | } |
| 1571 | |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 1572 | bool isVectorIndex8() const { |
| 1573 | if (Kind != k_VectorIndex) return false; |
| 1574 | return VectorIndex.Val < 8; |
| 1575 | } |
| 1576 | bool isVectorIndex16() const { |
| 1577 | if (Kind != k_VectorIndex) return false; |
| 1578 | return VectorIndex.Val < 4; |
| 1579 | } |
| 1580 | bool isVectorIndex32() const { |
| 1581 | if (Kind != k_VectorIndex) return false; |
| 1582 | return VectorIndex.Val < 2; |
| 1583 | } |
| 1584 | |
Jim Grosbach | 741cd73 | 2011-10-17 22:26:03 +0000 | [diff] [blame] | 1585 | bool isNEONi8splat() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1586 | if (!isImm()) return false; |
Jim Grosbach | 741cd73 | 2011-10-17 22:26:03 +0000 | [diff] [blame] | 1587 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1588 | // Must be a constant. |
| 1589 | if (!CE) return false; |
| 1590 | int64_t Value = CE->getValue(); |
| 1591 | // i8 value splatted across 8 bytes. The immediate is just the 8 byte |
| 1592 | // value. |
Jim Grosbach | 741cd73 | 2011-10-17 22:26:03 +0000 | [diff] [blame] | 1593 | return Value >= 0 && Value < 256; |
| 1594 | } |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 1595 | |
Jim Grosbach | cda32ae | 2011-10-17 23:09:09 +0000 | [diff] [blame] | 1596 | bool isNEONi16splat() const { |
Stepan Dyatkovskiy | 00dcc0f | 2014-04-24 06:03:01 +0000 | [diff] [blame] | 1597 | if (isNEONByteReplicate(2)) |
| 1598 | return false; // Leave that for bytes replication and forbid by default. |
| 1599 | if (!isImm()) |
| 1600 | return false; |
Jim Grosbach | cda32ae | 2011-10-17 23:09:09 +0000 | [diff] [blame] | 1601 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1602 | // Must be a constant. |
| 1603 | if (!CE) return false; |
| 1604 | int64_t Value = CE->getValue(); |
| 1605 | // i16 value in the range [0,255] or [0x0100, 0xff00] |
| 1606 | return (Value >= 0 && Value < 256) || (Value >= 0x0100 && Value <= 0xff00); |
| 1607 | } |
| 1608 | |
Jim Grosbach | 8211c05 | 2011-10-18 00:22:00 +0000 | [diff] [blame] | 1609 | bool isNEONi32splat() const { |
Stepan Dyatkovskiy | 00dcc0f | 2014-04-24 06:03:01 +0000 | [diff] [blame] | 1610 | if (isNEONByteReplicate(4)) |
| 1611 | return false; // Leave that for bytes replication and forbid by default. |
| 1612 | if (!isImm()) |
| 1613 | return false; |
Jim Grosbach | 8211c05 | 2011-10-18 00:22:00 +0000 | [diff] [blame] | 1614 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1615 | // Must be a constant. |
| 1616 | if (!CE) return false; |
| 1617 | int64_t Value = CE->getValue(); |
| 1618 | // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X. |
| 1619 | return (Value >= 0 && Value < 256) || |
| 1620 | (Value >= 0x0100 && Value <= 0xff00) || |
| 1621 | (Value >= 0x010000 && Value <= 0xff0000) || |
| 1622 | (Value >= 0x01000000 && Value <= 0xff000000); |
| 1623 | } |
| 1624 | |
Stepan Dyatkovskiy | 00dcc0f | 2014-04-24 06:03:01 +0000 | [diff] [blame] | 1625 | bool isNEONByteReplicate(unsigned NumBytes) const { |
| 1626 | if (!isImm()) |
| 1627 | return false; |
Jim Grosbach | 8211c05 | 2011-10-18 00:22:00 +0000 | [diff] [blame] | 1628 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1629 | // Must be a constant. |
Stepan Dyatkovskiy | 00dcc0f | 2014-04-24 06:03:01 +0000 | [diff] [blame] | 1630 | if (!CE) |
| 1631 | return false; |
| 1632 | int64_t Value = CE->getValue(); |
| 1633 | if (!Value) |
| 1634 | return false; // Don't bother with zero. |
| 1635 | |
| 1636 | unsigned char B = Value & 0xff; |
| 1637 | for (unsigned i = 1; i < NumBytes; ++i) { |
| 1638 | Value >>= 8; |
| 1639 | if ((Value & 0xff) != B) |
| 1640 | return false; |
| 1641 | } |
| 1642 | return true; |
| 1643 | } |
| 1644 | bool isNEONi16ByteReplicate() const { return isNEONByteReplicate(2); } |
| 1645 | bool isNEONi32ByteReplicate() const { return isNEONByteReplicate(4); } |
| 1646 | bool isNEONi32vmov() const { |
| 1647 | if (isNEONByteReplicate(4)) |
| 1648 | return false; // Let it to be classified as byte-replicate case. |
| 1649 | if (!isImm()) |
| 1650 | return false; |
| 1651 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1652 | // Must be a constant. |
| 1653 | if (!CE) |
| 1654 | return false; |
Jim Grosbach | 8211c05 | 2011-10-18 00:22:00 +0000 | [diff] [blame] | 1655 | int64_t Value = CE->getValue(); |
| 1656 | // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X, |
| 1657 | // for VMOV/VMVN only, 00Xf or 0Xff are also accepted. |
| 1658 | return (Value >= 0 && Value < 256) || |
| 1659 | (Value >= 0x0100 && Value <= 0xff00) || |
| 1660 | (Value >= 0x010000 && Value <= 0xff0000) || |
| 1661 | (Value >= 0x01000000 && Value <= 0xff000000) || |
| 1662 | (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) || |
| 1663 | (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff); |
| 1664 | } |
Jim Grosbach | 045b6c7 | 2011-12-19 23:51:07 +0000 | [diff] [blame] | 1665 | bool isNEONi32vmovNeg() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1666 | if (!isImm()) return false; |
Jim Grosbach | 045b6c7 | 2011-12-19 23:51:07 +0000 | [diff] [blame] | 1667 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1668 | // Must be a constant. |
| 1669 | if (!CE) return false; |
| 1670 | int64_t Value = ~CE->getValue(); |
| 1671 | // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X, |
| 1672 | // for VMOV/VMVN only, 00Xf or 0Xff are also accepted. |
| 1673 | return (Value >= 0 && Value < 256) || |
| 1674 | (Value >= 0x0100 && Value <= 0xff00) || |
| 1675 | (Value >= 0x010000 && Value <= 0xff0000) || |
| 1676 | (Value >= 0x01000000 && Value <= 0xff000000) || |
| 1677 | (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) || |
| 1678 | (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff); |
| 1679 | } |
Jim Grosbach | 8211c05 | 2011-10-18 00:22:00 +0000 | [diff] [blame] | 1680 | |
Jim Grosbach | e4454e0 | 2011-10-18 16:18:11 +0000 | [diff] [blame] | 1681 | bool isNEONi64splat() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1682 | if (!isImm()) return false; |
Jim Grosbach | e4454e0 | 2011-10-18 16:18:11 +0000 | [diff] [blame] | 1683 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1684 | // Must be a constant. |
| 1685 | if (!CE) return false; |
| 1686 | uint64_t Value = CE->getValue(); |
| 1687 | // i64 value with each byte being either 0 or 0xff. |
| 1688 | for (unsigned i = 0; i < 8; ++i) |
| 1689 | if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false; |
| 1690 | return true; |
| 1691 | } |
| 1692 | |
Daniel Dunbar | 5cd4d0f | 2010-08-11 05:24:50 +0000 | [diff] [blame] | 1693 | void addExpr(MCInst &Inst, const MCExpr *Expr) const { |
Chris Lattner | 5d6f6a0 | 2010-10-29 00:27:31 +0000 | [diff] [blame] | 1694 | // Add as immediates when possible. Null MCExpr = 0. |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1695 | if (!Expr) |
Chris Lattner | 5d6f6a0 | 2010-10-29 00:27:31 +0000 | [diff] [blame] | 1696 | Inst.addOperand(MCOperand::CreateImm(0)); |
| 1697 | else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr)) |
Daniel Dunbar | 5cd4d0f | 2010-08-11 05:24:50 +0000 | [diff] [blame] | 1698 | Inst.addOperand(MCOperand::CreateImm(CE->getValue())); |
| 1699 | else |
| 1700 | Inst.addOperand(MCOperand::CreateExpr(Expr)); |
| 1701 | } |
| 1702 | |
Daniel Dunbar | d8042b7 | 2010-08-11 06:36:53 +0000 | [diff] [blame] | 1703 | void addCondCodeOperands(MCInst &Inst, unsigned N) const { |
Daniel Dunbar | 188b47b | 2010-08-11 06:37:20 +0000 | [diff] [blame] | 1704 | assert(N == 2 && "Invalid number of operands!"); |
Daniel Dunbar | d8042b7 | 2010-08-11 06:36:53 +0000 | [diff] [blame] | 1705 | Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode()))); |
Jim Grosbach | 968c927 | 2010-12-06 18:30:57 +0000 | [diff] [blame] | 1706 | unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR; |
| 1707 | Inst.addOperand(MCOperand::CreateReg(RegNum)); |
Daniel Dunbar | d8042b7 | 2010-08-11 06:36:53 +0000 | [diff] [blame] | 1708 | } |
| 1709 | |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 1710 | void addCoprocNumOperands(MCInst &Inst, unsigned N) const { |
| 1711 | assert(N == 1 && "Invalid number of operands!"); |
| 1712 | Inst.addOperand(MCOperand::CreateImm(getCoproc())); |
| 1713 | } |
| 1714 | |
Jim Grosbach | 4839958 | 2011-10-12 17:34:41 +0000 | [diff] [blame] | 1715 | void addCoprocRegOperands(MCInst &Inst, unsigned N) const { |
| 1716 | assert(N == 1 && "Invalid number of operands!"); |
| 1717 | Inst.addOperand(MCOperand::CreateImm(getCoproc())); |
| 1718 | } |
| 1719 | |
| 1720 | void addCoprocOptionOperands(MCInst &Inst, unsigned N) const { |
| 1721 | assert(N == 1 && "Invalid number of operands!"); |
| 1722 | Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val)); |
| 1723 | } |
| 1724 | |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 1725 | void addITMaskOperands(MCInst &Inst, unsigned N) const { |
| 1726 | assert(N == 1 && "Invalid number of operands!"); |
| 1727 | Inst.addOperand(MCOperand::CreateImm(ITMask.Mask)); |
| 1728 | } |
| 1729 | |
| 1730 | void addITCondCodeOperands(MCInst &Inst, unsigned N) const { |
| 1731 | assert(N == 1 && "Invalid number of operands!"); |
| 1732 | Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode()))); |
| 1733 | } |
| 1734 | |
Jim Grosbach | 0bfb4d5 | 2010-12-06 18:21:12 +0000 | [diff] [blame] | 1735 | void addCCOutOperands(MCInst &Inst, unsigned N) const { |
| 1736 | assert(N == 1 && "Invalid number of operands!"); |
| 1737 | Inst.addOperand(MCOperand::CreateReg(getReg())); |
| 1738 | } |
| 1739 | |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 1740 | void addRegOperands(MCInst &Inst, unsigned N) const { |
| 1741 | assert(N == 1 && "Invalid number of operands!"); |
| 1742 | Inst.addOperand(MCOperand::CreateReg(getReg())); |
| 1743 | } |
| 1744 | |
Jim Grosbach | ac798e1 | 2011-07-25 20:49:51 +0000 | [diff] [blame] | 1745 | void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const { |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 1746 | assert(N == 3 && "Invalid number of operands!"); |
Jim Grosbach | ee201fa | 2011-11-14 17:52:47 +0000 | [diff] [blame] | 1747 | assert(isRegShiftedReg() && |
Alp Toker | f907b89 | 2013-12-05 05:44:44 +0000 | [diff] [blame] | 1748 | "addRegShiftedRegOperands() on non-RegShiftedReg!"); |
Jim Grosbach | ac798e1 | 2011-07-25 20:49:51 +0000 | [diff] [blame] | 1749 | Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg)); |
| 1750 | Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg)); |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 1751 | Inst.addOperand(MCOperand::CreateImm( |
Jim Grosbach | ac798e1 | 2011-07-25 20:49:51 +0000 | [diff] [blame] | 1752 | ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm))); |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 1753 | } |
| 1754 | |
Jim Grosbach | ac798e1 | 2011-07-25 20:49:51 +0000 | [diff] [blame] | 1755 | void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const { |
Owen Anderson | 0491270 | 2011-07-21 23:38:37 +0000 | [diff] [blame] | 1756 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | ee201fa | 2011-11-14 17:52:47 +0000 | [diff] [blame] | 1757 | assert(isRegShiftedImm() && |
Alp Toker | f907b89 | 2013-12-05 05:44:44 +0000 | [diff] [blame] | 1758 | "addRegShiftedImmOperands() on non-RegShiftedImm!"); |
Jim Grosbach | ac798e1 | 2011-07-25 20:49:51 +0000 | [diff] [blame] | 1759 | Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg)); |
Richard Barton | ba5b0cc | 2012-04-25 18:00:18 +0000 | [diff] [blame] | 1760 | // Shift of #32 is encoded as 0 where permitted |
| 1761 | unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm); |
Owen Anderson | b595ed0 | 2011-07-21 18:54:16 +0000 | [diff] [blame] | 1762 | Inst.addOperand(MCOperand::CreateImm( |
Richard Barton | ba5b0cc | 2012-04-25 18:00:18 +0000 | [diff] [blame] | 1763 | ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm))); |
Owen Anderson | b595ed0 | 2011-07-21 18:54:16 +0000 | [diff] [blame] | 1764 | } |
| 1765 | |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 1766 | void addShifterImmOperands(MCInst &Inst, unsigned N) const { |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 1767 | assert(N == 1 && "Invalid number of operands!"); |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 1768 | Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) | |
| 1769 | ShifterImm.Imm)); |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 1770 | } |
| 1771 | |
Bill Wendling | 8d2aa03 | 2010-11-08 23:49:57 +0000 | [diff] [blame] | 1772 | void addRegListOperands(MCInst &Inst, unsigned N) const { |
Bill Wendling | 2cae327 | 2010-11-09 22:44:22 +0000 | [diff] [blame] | 1773 | assert(N == 1 && "Invalid number of operands!"); |
Bill Wendling | bed9465 | 2010-11-09 23:28:44 +0000 | [diff] [blame] | 1774 | const SmallVectorImpl<unsigned> &RegList = getRegList(); |
| 1775 | for (SmallVectorImpl<unsigned>::const_iterator |
Bill Wendling | 2cae327 | 2010-11-09 22:44:22 +0000 | [diff] [blame] | 1776 | I = RegList.begin(), E = RegList.end(); I != E; ++I) |
| 1777 | Inst.addOperand(MCOperand::CreateReg(*I)); |
Bill Wendling | 8d2aa03 | 2010-11-08 23:49:57 +0000 | [diff] [blame] | 1778 | } |
| 1779 | |
Bill Wendling | 9898ac9 | 2010-11-17 04:32:08 +0000 | [diff] [blame] | 1780 | void addDPRRegListOperands(MCInst &Inst, unsigned N) const { |
| 1781 | addRegListOperands(Inst, N); |
| 1782 | } |
| 1783 | |
| 1784 | void addSPRRegListOperands(MCInst &Inst, unsigned N) const { |
| 1785 | addRegListOperands(Inst, N); |
| 1786 | } |
| 1787 | |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 1788 | void addRotImmOperands(MCInst &Inst, unsigned N) const { |
| 1789 | assert(N == 1 && "Invalid number of operands!"); |
| 1790 | // Encoded as val>>3. The printer handles display as 8, 16, 24. |
| 1791 | Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3)); |
| 1792 | } |
| 1793 | |
Jim Grosbach | 864b609 | 2011-07-28 21:34:26 +0000 | [diff] [blame] | 1794 | void addBitfieldOperands(MCInst &Inst, unsigned N) const { |
| 1795 | assert(N == 1 && "Invalid number of operands!"); |
| 1796 | // Munge the lsb/width into a bitfield mask. |
| 1797 | unsigned lsb = Bitfield.LSB; |
| 1798 | unsigned width = Bitfield.Width; |
| 1799 | // Make a 32-bit mask w/ the referenced bits clear and all other bits set. |
| 1800 | uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >> |
| 1801 | (32 - (lsb + width))); |
| 1802 | Inst.addOperand(MCOperand::CreateImm(Mask)); |
| 1803 | } |
| 1804 | |
Daniel Dunbar | 5cd4d0f | 2010-08-11 05:24:50 +0000 | [diff] [blame] | 1805 | void addImmOperands(MCInst &Inst, unsigned N) const { |
| 1806 | assert(N == 1 && "Invalid number of operands!"); |
| 1807 | addExpr(Inst, getImm()); |
| 1808 | } |
Jim Grosbach | 624bcc7 | 2010-10-29 14:46:02 +0000 | [diff] [blame] | 1809 | |
Jim Grosbach | ea23191 | 2011-12-22 22:19:05 +0000 | [diff] [blame] | 1810 | void addFBits16Operands(MCInst &Inst, unsigned N) const { |
| 1811 | assert(N == 1 && "Invalid number of operands!"); |
| 1812 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1813 | Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue())); |
| 1814 | } |
| 1815 | |
| 1816 | void addFBits32Operands(MCInst &Inst, unsigned N) const { |
| 1817 | assert(N == 1 && "Invalid number of operands!"); |
| 1818 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1819 | Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue())); |
| 1820 | } |
| 1821 | |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 1822 | void addFPImmOperands(MCInst &Inst, unsigned N) const { |
| 1823 | assert(N == 1 && "Invalid number of operands!"); |
Jim Grosbach | a9d36fb | 2012-01-20 18:09:51 +0000 | [diff] [blame] | 1824 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1825 | int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue())); |
| 1826 | Inst.addOperand(MCOperand::CreateImm(Val)); |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 1827 | } |
| 1828 | |
Jim Grosbach | 7db8d69 | 2011-09-08 22:07:06 +0000 | [diff] [blame] | 1829 | void addImm8s4Operands(MCInst &Inst, unsigned N) const { |
| 1830 | assert(N == 1 && "Invalid number of operands!"); |
| 1831 | // FIXME: We really want to scale the value here, but the LDRD/STRD |
| 1832 | // instruction don't encode operands that way yet. |
| 1833 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1834 | Inst.addOperand(MCOperand::CreateImm(CE->getValue())); |
| 1835 | } |
| 1836 | |
Jim Grosbach | 0a0b307 | 2011-08-24 21:22:15 +0000 | [diff] [blame] | 1837 | void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const { |
| 1838 | assert(N == 1 && "Invalid number of operands!"); |
| 1839 | // The immediate is scaled by four in the encoding and is stored |
| 1840 | // in the MCInst as such. Lop off the low two bits here. |
| 1841 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1842 | Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4)); |
| 1843 | } |
| 1844 | |
Jim Grosbach | 930f2f6 | 2012-04-05 20:57:13 +0000 | [diff] [blame] | 1845 | void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const { |
| 1846 | assert(N == 1 && "Invalid number of operands!"); |
| 1847 | // The immediate is scaled by four in the encoding and is stored |
| 1848 | // in the MCInst as such. Lop off the low two bits here. |
| 1849 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1850 | Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4))); |
| 1851 | } |
| 1852 | |
Jim Grosbach | 0a0b307 | 2011-08-24 21:22:15 +0000 | [diff] [blame] | 1853 | void addImm0_508s4Operands(MCInst &Inst, unsigned N) const { |
| 1854 | assert(N == 1 && "Invalid number of operands!"); |
| 1855 | // The immediate is scaled by four in the encoding and is stored |
| 1856 | // in the MCInst as such. Lop off the low two bits here. |
| 1857 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1858 | Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4)); |
| 1859 | } |
| 1860 | |
Jim Grosbach | 475c6db | 2011-07-25 23:09:14 +0000 | [diff] [blame] | 1861 | void addImm1_16Operands(MCInst &Inst, unsigned N) const { |
| 1862 | assert(N == 1 && "Invalid number of operands!"); |
| 1863 | // The constant encodes as the immediate-1, and we store in the instruction |
| 1864 | // the bits as encoded, so subtract off one here. |
| 1865 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1866 | Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1)); |
| 1867 | } |
| 1868 | |
Jim Grosbach | 801e0a3 | 2011-07-22 23:16:18 +0000 | [diff] [blame] | 1869 | void addImm1_32Operands(MCInst &Inst, unsigned N) const { |
| 1870 | assert(N == 1 && "Invalid number of operands!"); |
| 1871 | // The constant encodes as the immediate-1, and we store in the instruction |
| 1872 | // the bits as encoded, so subtract off one here. |
| 1873 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1874 | Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1)); |
| 1875 | } |
| 1876 | |
Jim Grosbach | 46dd413 | 2011-08-17 21:51:27 +0000 | [diff] [blame] | 1877 | void addImmThumbSROperands(MCInst &Inst, unsigned N) const { |
| 1878 | assert(N == 1 && "Invalid number of operands!"); |
| 1879 | // The constant encodes as the immediate, except for 32, which encodes as |
| 1880 | // zero. |
| 1881 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1882 | unsigned Imm = CE->getValue(); |
| 1883 | Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm))); |
| 1884 | } |
| 1885 | |
Jim Grosbach | 27c1e25 | 2011-07-21 17:23:04 +0000 | [diff] [blame] | 1886 | void addPKHASRImmOperands(MCInst &Inst, unsigned N) const { |
| 1887 | assert(N == 1 && "Invalid number of operands!"); |
| 1888 | // An ASR value of 32 encodes as 0, so that's how we want to add it to |
| 1889 | // the instruction as well. |
| 1890 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1891 | int Val = CE->getValue(); |
| 1892 | Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val)); |
| 1893 | } |
| 1894 | |
Jim Grosbach | b009a87 | 2011-10-28 22:36:30 +0000 | [diff] [blame] | 1895 | void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const { |
| 1896 | assert(N == 1 && "Invalid number of operands!"); |
| 1897 | // The operand is actually a t2_so_imm, but we have its bitwise |
| 1898 | // negation in the assembly source, so twiddle it here. |
| 1899 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1900 | Inst.addOperand(MCOperand::CreateImm(~CE->getValue())); |
| 1901 | } |
| 1902 | |
Jim Grosbach | 3050625 | 2011-12-08 00:31:07 +0000 | [diff] [blame] | 1903 | void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const { |
| 1904 | assert(N == 1 && "Invalid number of operands!"); |
| 1905 | // The operand is actually a t2_so_imm, but we have its |
| 1906 | // negation in the assembly source, so twiddle it here. |
| 1907 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1908 | Inst.addOperand(MCOperand::CreateImm(-CE->getValue())); |
| 1909 | } |
| 1910 | |
Jim Grosbach | 930f2f6 | 2012-04-05 20:57:13 +0000 | [diff] [blame] | 1911 | void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const { |
| 1912 | assert(N == 1 && "Invalid number of operands!"); |
| 1913 | // The operand is actually an imm0_4095, but we have its |
| 1914 | // negation in the assembly source, so twiddle it here. |
| 1915 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1916 | Inst.addOperand(MCOperand::CreateImm(-CE->getValue())); |
| 1917 | } |
| 1918 | |
Mihai Popa | d36cbaa | 2013-07-03 09:21:44 +0000 | [diff] [blame] | 1919 | void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const { |
| 1920 | if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) { |
| 1921 | Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2)); |
| 1922 | return; |
| 1923 | } |
| 1924 | |
| 1925 | const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val); |
| 1926 | assert(SR && "Unknown value type!"); |
| 1927 | Inst.addOperand(MCOperand::CreateExpr(SR)); |
| 1928 | } |
| 1929 | |
Mihai Popa | 8a9da5b | 2013-07-22 15:49:36 +0000 | [diff] [blame] | 1930 | void addThumbMemPCOperands(MCInst &Inst, unsigned N) const { |
| 1931 | assert(N == 1 && "Invalid number of operands!"); |
| 1932 | if (isImm()) { |
| 1933 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1934 | if (CE) { |
| 1935 | Inst.addOperand(MCOperand::CreateImm(CE->getValue())); |
| 1936 | return; |
| 1937 | } |
| 1938 | |
| 1939 | const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val); |
| 1940 | assert(SR && "Unknown value type!"); |
| 1941 | Inst.addOperand(MCOperand::CreateExpr(SR)); |
| 1942 | return; |
| 1943 | } |
| 1944 | |
| 1945 | assert(isMem() && "Unknown value type!"); |
| 1946 | assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!"); |
| 1947 | Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue())); |
| 1948 | } |
| 1949 | |
Jim Grosbach | 3d785ed | 2011-10-28 22:50:54 +0000 | [diff] [blame] | 1950 | void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const { |
| 1951 | assert(N == 1 && "Invalid number of operands!"); |
| 1952 | // The operand is actually a so_imm, but we have its bitwise |
| 1953 | // negation in the assembly source, so twiddle it here. |
| 1954 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1955 | Inst.addOperand(MCOperand::CreateImm(~CE->getValue())); |
| 1956 | } |
| 1957 | |
Jim Grosbach | 3050625 | 2011-12-08 00:31:07 +0000 | [diff] [blame] | 1958 | void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const { |
| 1959 | assert(N == 1 && "Invalid number of operands!"); |
| 1960 | // The operand is actually a so_imm, but we have its |
| 1961 | // negation in the assembly source, so twiddle it here. |
| 1962 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1963 | Inst.addOperand(MCOperand::CreateImm(-CE->getValue())); |
| 1964 | } |
| 1965 | |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 1966 | void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const { |
| 1967 | assert(N == 1 && "Invalid number of operands!"); |
| 1968 | Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt()))); |
| 1969 | } |
| 1970 | |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 1971 | void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const { |
| 1972 | assert(N == 1 && "Invalid number of operands!"); |
| 1973 | Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt()))); |
| 1974 | } |
| 1975 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1976 | void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const { |
| 1977 | assert(N == 1 && "Invalid number of operands!"); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1978 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
Bruno Cardoso Lopes | f170f8b | 2011-03-24 21:04:58 +0000 | [diff] [blame] | 1979 | } |
| 1980 | |
Jim Grosbach | 94298a9 | 2012-01-18 22:46:46 +0000 | [diff] [blame] | 1981 | void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const { |
| 1982 | assert(N == 1 && "Invalid number of operands!"); |
| 1983 | int32_t Imm = Memory.OffsetImm->getValue(); |
Jim Grosbach | 94298a9 | 2012-01-18 22:46:46 +0000 | [diff] [blame] | 1984 | Inst.addOperand(MCOperand::CreateImm(Imm)); |
| 1985 | } |
| 1986 | |
Jiangning Liu | 10dd40e | 2012-08-02 08:13:13 +0000 | [diff] [blame] | 1987 | void addAdrLabelOperands(MCInst &Inst, unsigned N) const { |
| 1988 | assert(N == 1 && "Invalid number of operands!"); |
| 1989 | assert(isImm() && "Not an immediate!"); |
| 1990 | |
| 1991 | // If we have an immediate that's not a constant, treat it as a label |
| 1992 | // reference needing a fixup. |
| 1993 | if (!isa<MCConstantExpr>(getImm())) { |
| 1994 | Inst.addOperand(MCOperand::CreateExpr(getImm())); |
| 1995 | return; |
| 1996 | } |
| 1997 | |
| 1998 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1999 | int Val = CE->getValue(); |
| 2000 | Inst.addOperand(MCOperand::CreateImm(Val)); |
| 2001 | } |
| 2002 | |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 2003 | void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const { |
| 2004 | assert(N == 2 && "Invalid number of operands!"); |
| 2005 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
| 2006 | Inst.addOperand(MCOperand::CreateImm(Memory.Alignment)); |
| 2007 | } |
| 2008 | |
Kevin Enderby | 488f20b | 2014-04-10 20:18:58 +0000 | [diff] [blame] | 2009 | void addDupAlignedMemoryNoneOperands(MCInst &Inst, unsigned N) const { |
| 2010 | addAlignedMemoryOperands(Inst, N); |
| 2011 | } |
| 2012 | |
| 2013 | void addAlignedMemoryNoneOperands(MCInst &Inst, unsigned N) const { |
| 2014 | addAlignedMemoryOperands(Inst, N); |
| 2015 | } |
| 2016 | |
| 2017 | void addAlignedMemory16Operands(MCInst &Inst, unsigned N) const { |
| 2018 | addAlignedMemoryOperands(Inst, N); |
| 2019 | } |
| 2020 | |
| 2021 | void addDupAlignedMemory16Operands(MCInst &Inst, unsigned N) const { |
| 2022 | addAlignedMemoryOperands(Inst, N); |
| 2023 | } |
| 2024 | |
| 2025 | void addAlignedMemory32Operands(MCInst &Inst, unsigned N) const { |
| 2026 | addAlignedMemoryOperands(Inst, N); |
| 2027 | } |
| 2028 | |
| 2029 | void addDupAlignedMemory32Operands(MCInst &Inst, unsigned N) const { |
| 2030 | addAlignedMemoryOperands(Inst, N); |
| 2031 | } |
| 2032 | |
| 2033 | void addAlignedMemory64Operands(MCInst &Inst, unsigned N) const { |
| 2034 | addAlignedMemoryOperands(Inst, N); |
| 2035 | } |
| 2036 | |
| 2037 | void addDupAlignedMemory64Operands(MCInst &Inst, unsigned N) const { |
| 2038 | addAlignedMemoryOperands(Inst, N); |
| 2039 | } |
| 2040 | |
| 2041 | void addAlignedMemory64or128Operands(MCInst &Inst, unsigned N) const { |
| 2042 | addAlignedMemoryOperands(Inst, N); |
| 2043 | } |
| 2044 | |
| 2045 | void addDupAlignedMemory64or128Operands(MCInst &Inst, unsigned N) const { |
| 2046 | addAlignedMemoryOperands(Inst, N); |
| 2047 | } |
| 2048 | |
| 2049 | void addAlignedMemory64or128or256Operands(MCInst &Inst, unsigned N) const { |
| 2050 | addAlignedMemoryOperands(Inst, N); |
| 2051 | } |
| 2052 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2053 | void addAddrMode2Operands(MCInst &Inst, unsigned N) const { |
| 2054 | assert(N == 3 && "Invalid number of operands!"); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2055 | int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0; |
| 2056 | if (!Memory.OffsetRegNum) { |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2057 | ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add; |
| 2058 | // Special case for #-0 |
| 2059 | if (Val == INT32_MIN) Val = 0; |
| 2060 | if (Val < 0) Val = -Val; |
| 2061 | Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift); |
| 2062 | } else { |
| 2063 | // For register offset, we encode the shift type and negation flag |
| 2064 | // here. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2065 | Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, |
| 2066 | Memory.ShiftImm, Memory.ShiftType); |
Bruno Cardoso Lopes | ab83050 | 2011-03-31 23:26:08 +0000 | [diff] [blame] | 2067 | } |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2068 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
| 2069 | Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum)); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2070 | Inst.addOperand(MCOperand::CreateImm(Val)); |
Bruno Cardoso Lopes | ab83050 | 2011-03-31 23:26:08 +0000 | [diff] [blame] | 2071 | } |
| 2072 | |
Jim Grosbach | cd17c12 | 2011-08-04 23:01:30 +0000 | [diff] [blame] | 2073 | void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const { |
| 2074 | assert(N == 2 && "Invalid number of operands!"); |
| 2075 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2076 | assert(CE && "non-constant AM2OffsetImm operand!"); |
| 2077 | int32_t Val = CE->getValue(); |
| 2078 | ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add; |
| 2079 | // Special case for #-0 |
| 2080 | if (Val == INT32_MIN) Val = 0; |
| 2081 | if (Val < 0) Val = -Val; |
| 2082 | Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift); |
| 2083 | Inst.addOperand(MCOperand::CreateReg(0)); |
| 2084 | Inst.addOperand(MCOperand::CreateImm(Val)); |
| 2085 | } |
| 2086 | |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 2087 | void addAddrMode3Operands(MCInst &Inst, unsigned N) const { |
| 2088 | assert(N == 3 && "Invalid number of operands!"); |
Jim Grosbach | 8648c10 | 2011-12-19 23:06:24 +0000 | [diff] [blame] | 2089 | // If we have an immediate that's not a constant, treat it as a label |
| 2090 | // reference needing a fixup. If it is a constant, it's something else |
| 2091 | // and we reject it. |
| 2092 | if (isImm()) { |
| 2093 | Inst.addOperand(MCOperand::CreateExpr(getImm())); |
| 2094 | Inst.addOperand(MCOperand::CreateReg(0)); |
| 2095 | Inst.addOperand(MCOperand::CreateImm(0)); |
| 2096 | return; |
| 2097 | } |
| 2098 | |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2099 | int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0; |
| 2100 | if (!Memory.OffsetRegNum) { |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 2101 | ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add; |
| 2102 | // Special case for #-0 |
| 2103 | if (Val == INT32_MIN) Val = 0; |
| 2104 | if (Val < 0) Val = -Val; |
| 2105 | Val = ARM_AM::getAM3Opc(AddSub, Val); |
| 2106 | } else { |
| 2107 | // For register offset, we encode the shift type and negation flag |
| 2108 | // here. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2109 | Val = ARM_AM::getAM3Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, 0); |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 2110 | } |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2111 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
| 2112 | Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum)); |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 2113 | Inst.addOperand(MCOperand::CreateImm(Val)); |
| 2114 | } |
| 2115 | |
| 2116 | void addAM3OffsetOperands(MCInst &Inst, unsigned N) const { |
| 2117 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2118 | if (Kind == k_PostIndexRegister) { |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 2119 | int32_t Val = |
| 2120 | ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0); |
| 2121 | Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum)); |
| 2122 | Inst.addOperand(MCOperand::CreateImm(Val)); |
Jim Grosbach | 1d9d5e9 | 2011-08-10 21:56:18 +0000 | [diff] [blame] | 2123 | return; |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 2124 | } |
| 2125 | |
| 2126 | // Constant offset. |
| 2127 | const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm()); |
| 2128 | int32_t Val = CE->getValue(); |
| 2129 | ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add; |
| 2130 | // Special case for #-0 |
| 2131 | if (Val == INT32_MIN) Val = 0; |
| 2132 | if (Val < 0) Val = -Val; |
Jim Grosbach | 1d9d5e9 | 2011-08-10 21:56:18 +0000 | [diff] [blame] | 2133 | Val = ARM_AM::getAM3Opc(AddSub, Val); |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 2134 | Inst.addOperand(MCOperand::CreateReg(0)); |
| 2135 | Inst.addOperand(MCOperand::CreateImm(Val)); |
| 2136 | } |
| 2137 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2138 | void addAddrMode5Operands(MCInst &Inst, unsigned N) const { |
| 2139 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | fb2f1d6 | 2011-11-01 01:24:45 +0000 | [diff] [blame] | 2140 | // If we have an immediate that's not a constant, treat it as a label |
| 2141 | // reference needing a fixup. If it is a constant, it's something else |
| 2142 | // and we reject it. |
| 2143 | if (isImm()) { |
| 2144 | Inst.addOperand(MCOperand::CreateExpr(getImm())); |
| 2145 | Inst.addOperand(MCOperand::CreateImm(0)); |
| 2146 | return; |
| 2147 | } |
| 2148 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2149 | // The lower two bits are always zero and as such are not encoded. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2150 | int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2151 | ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add; |
| 2152 | // Special case for #-0 |
| 2153 | if (Val == INT32_MIN) Val = 0; |
| 2154 | if (Val < 0) Val = -Val; |
| 2155 | Val = ARM_AM::getAM5Opc(AddSub, Val); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2156 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2157 | Inst.addOperand(MCOperand::CreateImm(Val)); |
Bruno Cardoso Lopes | bda3632 | 2011-04-04 17:18:19 +0000 | [diff] [blame] | 2158 | } |
| 2159 | |
Jim Grosbach | 7db8d69 | 2011-09-08 22:07:06 +0000 | [diff] [blame] | 2160 | void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const { |
| 2161 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | 8648c10 | 2011-12-19 23:06:24 +0000 | [diff] [blame] | 2162 | // If we have an immediate that's not a constant, treat it as a label |
| 2163 | // reference needing a fixup. If it is a constant, it's something else |
| 2164 | // and we reject it. |
| 2165 | if (isImm()) { |
| 2166 | Inst.addOperand(MCOperand::CreateExpr(getImm())); |
| 2167 | Inst.addOperand(MCOperand::CreateImm(0)); |
| 2168 | return; |
| 2169 | } |
| 2170 | |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2171 | int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0; |
| 2172 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
Jim Grosbach | 7db8d69 | 2011-09-08 22:07:06 +0000 | [diff] [blame] | 2173 | Inst.addOperand(MCOperand::CreateImm(Val)); |
| 2174 | } |
| 2175 | |
Jim Grosbach | a05627e | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 2176 | void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const { |
| 2177 | assert(N == 2 && "Invalid number of operands!"); |
| 2178 | // The lower two bits are always zero and as such are not encoded. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2179 | int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0; |
| 2180 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
Jim Grosbach | a05627e | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 2181 | Inst.addOperand(MCOperand::CreateImm(Val)); |
| 2182 | } |
| 2183 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2184 | void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const { |
| 2185 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2186 | int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0; |
| 2187 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2188 | Inst.addOperand(MCOperand::CreateImm(Val)); |
Chris Lattner | 5d6f6a0 | 2010-10-29 00:27:31 +0000 | [diff] [blame] | 2189 | } |
Daniel Dunbar | 5cd4d0f | 2010-08-11 05:24:50 +0000 | [diff] [blame] | 2190 | |
Jim Grosbach | 2392c53 | 2011-09-07 23:39:14 +0000 | [diff] [blame] | 2191 | void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const { |
| 2192 | addMemImm8OffsetOperands(Inst, N); |
| 2193 | } |
| 2194 | |
Jim Grosbach | 5bfa8ba | 2011-09-07 20:58:57 +0000 | [diff] [blame] | 2195 | void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const { |
Jim Grosbach | 2392c53 | 2011-09-07 23:39:14 +0000 | [diff] [blame] | 2196 | addMemImm8OffsetOperands(Inst, N); |
Jim Grosbach | 5bfa8ba | 2011-09-07 20:58:57 +0000 | [diff] [blame] | 2197 | } |
| 2198 | |
| 2199 | void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const { |
| 2200 | assert(N == 2 && "Invalid number of operands!"); |
| 2201 | // If this is an immediate, it's a label reference. |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 2202 | if (isImm()) { |
Jim Grosbach | 5bfa8ba | 2011-09-07 20:58:57 +0000 | [diff] [blame] | 2203 | addExpr(Inst, getImm()); |
| 2204 | Inst.addOperand(MCOperand::CreateImm(0)); |
| 2205 | return; |
| 2206 | } |
| 2207 | |
| 2208 | // Otherwise, it's a normal memory reg+offset. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2209 | int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0; |
| 2210 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
Jim Grosbach | 5bfa8ba | 2011-09-07 20:58:57 +0000 | [diff] [blame] | 2211 | Inst.addOperand(MCOperand::CreateImm(Val)); |
| 2212 | } |
| 2213 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2214 | void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const { |
| 2215 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | 95466ce | 2011-08-08 20:59:31 +0000 | [diff] [blame] | 2216 | // If this is an immediate, it's a label reference. |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 2217 | if (isImm()) { |
Jim Grosbach | 95466ce | 2011-08-08 20:59:31 +0000 | [diff] [blame] | 2218 | addExpr(Inst, getImm()); |
| 2219 | Inst.addOperand(MCOperand::CreateImm(0)); |
| 2220 | return; |
| 2221 | } |
| 2222 | |
| 2223 | // Otherwise, it's a normal memory reg+offset. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2224 | int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0; |
| 2225 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2226 | Inst.addOperand(MCOperand::CreateImm(Val)); |
Bill Wendling | 092a7bd | 2010-12-14 03:36:38 +0000 | [diff] [blame] | 2227 | } |
Bill Wendling | 811c936 | 2010-11-30 07:44:32 +0000 | [diff] [blame] | 2228 | |
Jim Grosbach | 05541f4 | 2011-09-19 22:21:13 +0000 | [diff] [blame] | 2229 | void addMemTBBOperands(MCInst &Inst, unsigned N) const { |
| 2230 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2231 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
| 2232 | Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum)); |
Jim Grosbach | 05541f4 | 2011-09-19 22:21:13 +0000 | [diff] [blame] | 2233 | } |
| 2234 | |
| 2235 | void addMemTBHOperands(MCInst &Inst, unsigned N) const { |
| 2236 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2237 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
| 2238 | Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum)); |
Jim Grosbach | 05541f4 | 2011-09-19 22:21:13 +0000 | [diff] [blame] | 2239 | } |
| 2240 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2241 | void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const { |
| 2242 | assert(N == 3 && "Invalid number of operands!"); |
Jim Grosbach | ee201fa | 2011-11-14 17:52:47 +0000 | [diff] [blame] | 2243 | unsigned Val = |
| 2244 | ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, |
| 2245 | Memory.ShiftImm, Memory.ShiftType); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2246 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
| 2247 | Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum)); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2248 | Inst.addOperand(MCOperand::CreateImm(Val)); |
| 2249 | } |
| 2250 | |
Jim Grosbach | e0ebc1c | 2011-09-07 23:10:15 +0000 | [diff] [blame] | 2251 | void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const { |
| 2252 | assert(N == 3 && "Invalid number of operands!"); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2253 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
| 2254 | Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum)); |
| 2255 | Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm)); |
Jim Grosbach | e0ebc1c | 2011-09-07 23:10:15 +0000 | [diff] [blame] | 2256 | } |
| 2257 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2258 | void addMemThumbRROperands(MCInst &Inst, unsigned N) const { |
| 2259 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2260 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
| 2261 | Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum)); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2262 | } |
| 2263 | |
Jim Grosbach | 3fe94e3 | 2011-08-19 17:55:24 +0000 | [diff] [blame] | 2264 | void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const { |
| 2265 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2266 | int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0; |
| 2267 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
Jim Grosbach | 3fe94e3 | 2011-08-19 17:55:24 +0000 | [diff] [blame] | 2268 | Inst.addOperand(MCOperand::CreateImm(Val)); |
| 2269 | } |
| 2270 | |
Jim Grosbach | 26d3587 | 2011-08-19 18:55:51 +0000 | [diff] [blame] | 2271 | void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const { |
| 2272 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2273 | int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0; |
| 2274 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
Jim Grosbach | 26d3587 | 2011-08-19 18:55:51 +0000 | [diff] [blame] | 2275 | Inst.addOperand(MCOperand::CreateImm(Val)); |
| 2276 | } |
| 2277 | |
Jim Grosbach | a32c753 | 2011-08-19 18:49:59 +0000 | [diff] [blame] | 2278 | void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const { |
| 2279 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2280 | int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0; |
| 2281 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
Jim Grosbach | a32c753 | 2011-08-19 18:49:59 +0000 | [diff] [blame] | 2282 | Inst.addOperand(MCOperand::CreateImm(Val)); |
| 2283 | } |
| 2284 | |
Jim Grosbach | 23983d6 | 2011-08-19 18:13:48 +0000 | [diff] [blame] | 2285 | void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const { |
| 2286 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2287 | int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0; |
| 2288 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
Jim Grosbach | 23983d6 | 2011-08-19 18:13:48 +0000 | [diff] [blame] | 2289 | Inst.addOperand(MCOperand::CreateImm(Val)); |
| 2290 | } |
| 2291 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2292 | void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const { |
| 2293 | assert(N == 1 && "Invalid number of operands!"); |
| 2294 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2295 | assert(CE && "non-constant post-idx-imm8 operand!"); |
| 2296 | int Imm = CE->getValue(); |
| 2297 | bool isAdd = Imm >= 0; |
Owen Anderson | f02d98d | 2011-08-29 17:17:09 +0000 | [diff] [blame] | 2298 | if (Imm == INT32_MIN) Imm = 0; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2299 | Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8; |
| 2300 | Inst.addOperand(MCOperand::CreateImm(Imm)); |
| 2301 | } |
| 2302 | |
Jim Grosbach | 9398141 | 2011-10-11 21:55:36 +0000 | [diff] [blame] | 2303 | void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const { |
| 2304 | assert(N == 1 && "Invalid number of operands!"); |
| 2305 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2306 | assert(CE && "non-constant post-idx-imm8s4 operand!"); |
| 2307 | int Imm = CE->getValue(); |
| 2308 | bool isAdd = Imm >= 0; |
| 2309 | if (Imm == INT32_MIN) Imm = 0; |
| 2310 | // Immediate is scaled by 4. |
| 2311 | Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8; |
| 2312 | Inst.addOperand(MCOperand::CreateImm(Imm)); |
| 2313 | } |
| 2314 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2315 | void addPostIdxRegOperands(MCInst &Inst, unsigned N) const { |
| 2316 | assert(N == 2 && "Invalid number of operands!"); |
| 2317 | Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum)); |
Jim Grosbach | c320c85 | 2011-08-05 21:28:30 +0000 | [diff] [blame] | 2318 | Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd)); |
| 2319 | } |
| 2320 | |
| 2321 | void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const { |
| 2322 | assert(N == 2 && "Invalid number of operands!"); |
| 2323 | Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum)); |
| 2324 | // The sign, shift type, and shift amount are encoded in a single operand |
| 2325 | // using the AM2 encoding helpers. |
| 2326 | ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub; |
| 2327 | unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm, |
| 2328 | PostIdxReg.ShiftTy); |
| 2329 | Inst.addOperand(MCOperand::CreateImm(Imm)); |
Bill Wendling | 811c936 | 2010-11-30 07:44:32 +0000 | [diff] [blame] | 2330 | } |
| 2331 | |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 2332 | void addMSRMaskOperands(MCInst &Inst, unsigned N) const { |
| 2333 | assert(N == 1 && "Invalid number of operands!"); |
| 2334 | Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask()))); |
| 2335 | } |
| 2336 | |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 2337 | void addProcIFlagsOperands(MCInst &Inst, unsigned N) const { |
| 2338 | assert(N == 1 && "Invalid number of operands!"); |
| 2339 | Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags()))); |
| 2340 | } |
| 2341 | |
Jim Grosbach | 182b6a0 | 2011-11-29 23:51:09 +0000 | [diff] [blame] | 2342 | void addVecListOperands(MCInst &Inst, unsigned N) const { |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 2343 | assert(N == 1 && "Invalid number of operands!"); |
| 2344 | Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum)); |
| 2345 | } |
| 2346 | |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 2347 | void addVecListIndexedOperands(MCInst &Inst, unsigned N) const { |
| 2348 | assert(N == 2 && "Invalid number of operands!"); |
| 2349 | Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum)); |
| 2350 | Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex)); |
| 2351 | } |
| 2352 | |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 2353 | void addVectorIndex8Operands(MCInst &Inst, unsigned N) const { |
| 2354 | assert(N == 1 && "Invalid number of operands!"); |
| 2355 | Inst.addOperand(MCOperand::CreateImm(getVectorIndex())); |
| 2356 | } |
| 2357 | |
| 2358 | void addVectorIndex16Operands(MCInst &Inst, unsigned N) const { |
| 2359 | assert(N == 1 && "Invalid number of operands!"); |
| 2360 | Inst.addOperand(MCOperand::CreateImm(getVectorIndex())); |
| 2361 | } |
| 2362 | |
| 2363 | void addVectorIndex32Operands(MCInst &Inst, unsigned N) const { |
| 2364 | assert(N == 1 && "Invalid number of operands!"); |
| 2365 | Inst.addOperand(MCOperand::CreateImm(getVectorIndex())); |
| 2366 | } |
| 2367 | |
Jim Grosbach | 741cd73 | 2011-10-17 22:26:03 +0000 | [diff] [blame] | 2368 | void addNEONi8splatOperands(MCInst &Inst, unsigned N) const { |
| 2369 | assert(N == 1 && "Invalid number of operands!"); |
| 2370 | // The immediate encodes the type of constant as well as the value. |
| 2371 | // Mask in that this is an i8 splat. |
| 2372 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2373 | Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00)); |
| 2374 | } |
| 2375 | |
Jim Grosbach | cda32ae | 2011-10-17 23:09:09 +0000 | [diff] [blame] | 2376 | void addNEONi16splatOperands(MCInst &Inst, unsigned N) const { |
| 2377 | assert(N == 1 && "Invalid number of operands!"); |
| 2378 | // The immediate encodes the type of constant as well as the value. |
| 2379 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2380 | unsigned Value = CE->getValue(); |
| 2381 | if (Value >= 256) |
| 2382 | Value = (Value >> 8) | 0xa00; |
| 2383 | else |
| 2384 | Value |= 0x800; |
| 2385 | Inst.addOperand(MCOperand::CreateImm(Value)); |
| 2386 | } |
| 2387 | |
Jim Grosbach | 8211c05 | 2011-10-18 00:22:00 +0000 | [diff] [blame] | 2388 | void addNEONi32splatOperands(MCInst &Inst, unsigned N) const { |
| 2389 | assert(N == 1 && "Invalid number of operands!"); |
| 2390 | // The immediate encodes the type of constant as well as the value. |
| 2391 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2392 | unsigned Value = CE->getValue(); |
| 2393 | if (Value >= 256 && Value <= 0xff00) |
| 2394 | Value = (Value >> 8) | 0x200; |
| 2395 | else if (Value > 0xffff && Value <= 0xff0000) |
| 2396 | Value = (Value >> 16) | 0x400; |
| 2397 | else if (Value > 0xffffff) |
| 2398 | Value = (Value >> 24) | 0x600; |
| 2399 | Inst.addOperand(MCOperand::CreateImm(Value)); |
| 2400 | } |
| 2401 | |
Stepan Dyatkovskiy | 00dcc0f | 2014-04-24 06:03:01 +0000 | [diff] [blame] | 2402 | void addNEONinvByteReplicateOperands(MCInst &Inst, unsigned N) const { |
| 2403 | assert(N == 1 && "Invalid number of operands!"); |
| 2404 | // The immediate encodes the type of constant as well as the value. |
| 2405 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2406 | unsigned Value = CE->getValue(); |
| 2407 | assert((Inst.getOpcode() == ARM::VMOVv8i8 || |
| 2408 | Inst.getOpcode() == ARM::VMOVv16i8) && |
| 2409 | "All vmvn instructions that wants to replicate non-zero byte " |
| 2410 | "always must be replaced with VMOVv8i8 or VMOVv16i8."); |
| 2411 | unsigned B = ((~Value) & 0xff); |
| 2412 | B |= 0xe00; // cmode = 0b1110 |
| 2413 | Inst.addOperand(MCOperand::CreateImm(B)); |
| 2414 | } |
Jim Grosbach | 8211c05 | 2011-10-18 00:22:00 +0000 | [diff] [blame] | 2415 | void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const { |
| 2416 | assert(N == 1 && "Invalid number of operands!"); |
| 2417 | // The immediate encodes the type of constant as well as the value. |
| 2418 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2419 | unsigned Value = CE->getValue(); |
| 2420 | if (Value >= 256 && Value <= 0xffff) |
| 2421 | Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200); |
| 2422 | else if (Value > 0xffff && Value <= 0xffffff) |
| 2423 | Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400); |
| 2424 | else if (Value > 0xffffff) |
| 2425 | Value = (Value >> 24) | 0x600; |
| 2426 | Inst.addOperand(MCOperand::CreateImm(Value)); |
| 2427 | } |
| 2428 | |
Stepan Dyatkovskiy | 00dcc0f | 2014-04-24 06:03:01 +0000 | [diff] [blame] | 2429 | void addNEONvmovByteReplicateOperands(MCInst &Inst, unsigned N) const { |
| 2430 | assert(N == 1 && "Invalid number of operands!"); |
| 2431 | // The immediate encodes the type of constant as well as the value. |
| 2432 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2433 | unsigned Value = CE->getValue(); |
| 2434 | assert((Inst.getOpcode() == ARM::VMOVv8i8 || |
| 2435 | Inst.getOpcode() == ARM::VMOVv16i8) && |
| 2436 | "All instructions that wants to replicate non-zero byte " |
| 2437 | "always must be replaced with VMOVv8i8 or VMOVv16i8."); |
| 2438 | unsigned B = Value & 0xff; |
| 2439 | B |= 0xe00; // cmode = 0b1110 |
| 2440 | Inst.addOperand(MCOperand::CreateImm(B)); |
| 2441 | } |
Jim Grosbach | 045b6c7 | 2011-12-19 23:51:07 +0000 | [diff] [blame] | 2442 | void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const { |
| 2443 | assert(N == 1 && "Invalid number of operands!"); |
| 2444 | // The immediate encodes the type of constant as well as the value. |
| 2445 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2446 | unsigned Value = ~CE->getValue(); |
| 2447 | if (Value >= 256 && Value <= 0xffff) |
| 2448 | Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200); |
| 2449 | else if (Value > 0xffff && Value <= 0xffffff) |
| 2450 | Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400); |
| 2451 | else if (Value > 0xffffff) |
| 2452 | Value = (Value >> 24) | 0x600; |
| 2453 | Inst.addOperand(MCOperand::CreateImm(Value)); |
| 2454 | } |
| 2455 | |
Jim Grosbach | e4454e0 | 2011-10-18 16:18:11 +0000 | [diff] [blame] | 2456 | void addNEONi64splatOperands(MCInst &Inst, unsigned N) const { |
| 2457 | assert(N == 1 && "Invalid number of operands!"); |
| 2458 | // The immediate encodes the type of constant as well as the value. |
| 2459 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2460 | uint64_t Value = CE->getValue(); |
| 2461 | unsigned Imm = 0; |
| 2462 | for (unsigned i = 0; i < 8; ++i, Value >>= 8) { |
| 2463 | Imm |= (Value & 1) << i; |
| 2464 | } |
| 2465 | Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00)); |
| 2466 | } |
| 2467 | |
Craig Topper | ca7e3e5 | 2014-03-10 03:19:03 +0000 | [diff] [blame] | 2468 | void print(raw_ostream &OS) const override; |
Daniel Dunbar | ebace22 | 2010-08-11 06:37:04 +0000 | [diff] [blame] | 2469 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2470 | static std::unique_ptr<ARMOperand> CreateITMask(unsigned Mask, SMLoc S) { |
| 2471 | auto Op = make_unique<ARMOperand>(k_ITCondMask); |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 2472 | Op->ITMask.Mask = Mask; |
| 2473 | Op->StartLoc = S; |
| 2474 | Op->EndLoc = S; |
| 2475 | return Op; |
| 2476 | } |
| 2477 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2478 | static std::unique_ptr<ARMOperand> CreateCondCode(ARMCC::CondCodes CC, |
| 2479 | SMLoc S) { |
| 2480 | auto Op = make_unique<ARMOperand>(k_CondCode); |
Daniel Dunbar | 188b47b | 2010-08-11 06:37:20 +0000 | [diff] [blame] | 2481 | Op->CC.Val = CC; |
| 2482 | Op->StartLoc = S; |
| 2483 | Op->EndLoc = S; |
Chris Lattner | bd7c9fa | 2010-10-28 17:20:03 +0000 | [diff] [blame] | 2484 | return Op; |
Daniel Dunbar | 188b47b | 2010-08-11 06:37:20 +0000 | [diff] [blame] | 2485 | } |
| 2486 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2487 | static std::unique_ptr<ARMOperand> CreateCoprocNum(unsigned CopVal, SMLoc S) { |
| 2488 | auto Op = make_unique<ARMOperand>(k_CoprocNum); |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 2489 | Op->Cop.Val = CopVal; |
| 2490 | Op->StartLoc = S; |
| 2491 | Op->EndLoc = S; |
| 2492 | return Op; |
| 2493 | } |
| 2494 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2495 | static std::unique_ptr<ARMOperand> CreateCoprocReg(unsigned CopVal, SMLoc S) { |
| 2496 | auto Op = make_unique<ARMOperand>(k_CoprocReg); |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 2497 | Op->Cop.Val = CopVal; |
| 2498 | Op->StartLoc = S; |
| 2499 | Op->EndLoc = S; |
| 2500 | return Op; |
| 2501 | } |
| 2502 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2503 | static std::unique_ptr<ARMOperand> CreateCoprocOption(unsigned Val, SMLoc S, |
| 2504 | SMLoc E) { |
| 2505 | auto Op = make_unique<ARMOperand>(k_CoprocOption); |
Jim Grosbach | 4839958 | 2011-10-12 17:34:41 +0000 | [diff] [blame] | 2506 | Op->Cop.Val = Val; |
| 2507 | Op->StartLoc = S; |
| 2508 | Op->EndLoc = E; |
| 2509 | return Op; |
| 2510 | } |
| 2511 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2512 | static std::unique_ptr<ARMOperand> CreateCCOut(unsigned RegNum, SMLoc S) { |
| 2513 | auto Op = make_unique<ARMOperand>(k_CCOut); |
Jim Grosbach | 0bfb4d5 | 2010-12-06 18:21:12 +0000 | [diff] [blame] | 2514 | Op->Reg.RegNum = RegNum; |
| 2515 | Op->StartLoc = S; |
| 2516 | Op->EndLoc = S; |
| 2517 | return Op; |
| 2518 | } |
| 2519 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2520 | static std::unique_ptr<ARMOperand> CreateToken(StringRef Str, SMLoc S) { |
| 2521 | auto Op = make_unique<ARMOperand>(k_Token); |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 2522 | Op->Tok.Data = Str.data(); |
| 2523 | Op->Tok.Length = Str.size(); |
| 2524 | Op->StartLoc = S; |
| 2525 | Op->EndLoc = S; |
Chris Lattner | bd7c9fa | 2010-10-28 17:20:03 +0000 | [diff] [blame] | 2526 | return Op; |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 2527 | } |
| 2528 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2529 | static std::unique_ptr<ARMOperand> CreateReg(unsigned RegNum, SMLoc S, |
| 2530 | SMLoc E) { |
| 2531 | auto Op = make_unique<ARMOperand>(k_Register); |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 2532 | Op->Reg.RegNum = RegNum; |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 2533 | Op->StartLoc = S; |
| 2534 | Op->EndLoc = E; |
Chris Lattner | bd7c9fa | 2010-10-28 17:20:03 +0000 | [diff] [blame] | 2535 | return Op; |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 2536 | } |
| 2537 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2538 | static std::unique_ptr<ARMOperand> |
| 2539 | CreateShiftedRegister(ARM_AM::ShiftOpc ShTy, unsigned SrcReg, |
| 2540 | unsigned ShiftReg, unsigned ShiftImm, SMLoc S, |
| 2541 | SMLoc E) { |
| 2542 | auto Op = make_unique<ARMOperand>(k_ShiftedRegister); |
Jim Grosbach | ac798e1 | 2011-07-25 20:49:51 +0000 | [diff] [blame] | 2543 | Op->RegShiftedReg.ShiftTy = ShTy; |
| 2544 | Op->RegShiftedReg.SrcReg = SrcReg; |
| 2545 | Op->RegShiftedReg.ShiftReg = ShiftReg; |
| 2546 | Op->RegShiftedReg.ShiftImm = ShiftImm; |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 2547 | Op->StartLoc = S; |
| 2548 | Op->EndLoc = E; |
| 2549 | return Op; |
| 2550 | } |
| 2551 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2552 | static std::unique_ptr<ARMOperand> |
| 2553 | CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy, unsigned SrcReg, |
| 2554 | unsigned ShiftImm, SMLoc S, SMLoc E) { |
| 2555 | auto Op = make_unique<ARMOperand>(k_ShiftedImmediate); |
Jim Grosbach | ac798e1 | 2011-07-25 20:49:51 +0000 | [diff] [blame] | 2556 | Op->RegShiftedImm.ShiftTy = ShTy; |
| 2557 | Op->RegShiftedImm.SrcReg = SrcReg; |
| 2558 | Op->RegShiftedImm.ShiftImm = ShiftImm; |
Owen Anderson | b595ed0 | 2011-07-21 18:54:16 +0000 | [diff] [blame] | 2559 | Op->StartLoc = S; |
| 2560 | Op->EndLoc = E; |
| 2561 | return Op; |
| 2562 | } |
| 2563 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2564 | static std::unique_ptr<ARMOperand> CreateShifterImm(bool isASR, unsigned Imm, |
| 2565 | SMLoc S, SMLoc E) { |
| 2566 | auto Op = make_unique<ARMOperand>(k_ShifterImmediate); |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 2567 | Op->ShifterImm.isASR = isASR; |
| 2568 | Op->ShifterImm.Imm = Imm; |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 2569 | Op->StartLoc = S; |
| 2570 | Op->EndLoc = E; |
| 2571 | return Op; |
| 2572 | } |
| 2573 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2574 | static std::unique_ptr<ARMOperand> CreateRotImm(unsigned Imm, SMLoc S, |
| 2575 | SMLoc E) { |
| 2576 | auto Op = make_unique<ARMOperand>(k_RotateImmediate); |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 2577 | Op->RotImm.Imm = Imm; |
| 2578 | Op->StartLoc = S; |
| 2579 | Op->EndLoc = E; |
| 2580 | return Op; |
| 2581 | } |
| 2582 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2583 | static std::unique_ptr<ARMOperand> |
| 2584 | CreateBitfield(unsigned LSB, unsigned Width, SMLoc S, SMLoc E) { |
| 2585 | auto Op = make_unique<ARMOperand>(k_BitfieldDescriptor); |
Jim Grosbach | 864b609 | 2011-07-28 21:34:26 +0000 | [diff] [blame] | 2586 | Op->Bitfield.LSB = LSB; |
| 2587 | Op->Bitfield.Width = Width; |
| 2588 | Op->StartLoc = S; |
| 2589 | Op->EndLoc = E; |
| 2590 | return Op; |
| 2591 | } |
| 2592 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2593 | static std::unique_ptr<ARMOperand> |
| 2594 | CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned>> &Regs, |
Matt Beaumont-Gay | 55c4cc7 | 2010-11-10 00:08:58 +0000 | [diff] [blame] | 2595 | SMLoc StartLoc, SMLoc EndLoc) { |
Chad Rosier | fa705ee | 2013-07-01 20:49:23 +0000 | [diff] [blame] | 2596 | assert (Regs.size() > 0 && "RegList contains no registers?"); |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2597 | KindTy Kind = k_RegisterList; |
Bill Wendling | 9898ac9 | 2010-11-17 04:32:08 +0000 | [diff] [blame] | 2598 | |
Chad Rosier | fa705ee | 2013-07-01 20:49:23 +0000 | [diff] [blame] | 2599 | if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second)) |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2600 | Kind = k_DPRRegisterList; |
Jim Grosbach | 75461af | 2011-09-13 22:56:44 +0000 | [diff] [blame] | 2601 | else if (ARMMCRegisterClasses[ARM::SPRRegClassID]. |
Chad Rosier | fa705ee | 2013-07-01 20:49:23 +0000 | [diff] [blame] | 2602 | contains(Regs.front().second)) |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2603 | Kind = k_SPRRegisterList; |
Bill Wendling | 9898ac9 | 2010-11-17 04:32:08 +0000 | [diff] [blame] | 2604 | |
Chad Rosier | fa705ee | 2013-07-01 20:49:23 +0000 | [diff] [blame] | 2605 | // Sort based on the register encoding values. |
| 2606 | array_pod_sort(Regs.begin(), Regs.end()); |
| 2607 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2608 | auto Op = make_unique<ARMOperand>(Kind); |
Chad Rosier | fa705ee | 2013-07-01 20:49:23 +0000 | [diff] [blame] | 2609 | for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator |
Bill Wendling | 2cae327 | 2010-11-09 22:44:22 +0000 | [diff] [blame] | 2610 | I = Regs.begin(), E = Regs.end(); I != E; ++I) |
Chad Rosier | fa705ee | 2013-07-01 20:49:23 +0000 | [diff] [blame] | 2611 | Op->Registers.push_back(I->second); |
Matt Beaumont-Gay | 55c4cc7 | 2010-11-10 00:08:58 +0000 | [diff] [blame] | 2612 | Op->StartLoc = StartLoc; |
| 2613 | Op->EndLoc = EndLoc; |
Bill Wendling | 7cef447 | 2010-11-06 19:56:04 +0000 | [diff] [blame] | 2614 | return Op; |
| 2615 | } |
| 2616 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2617 | static std::unique_ptr<ARMOperand> CreateVectorList(unsigned RegNum, |
| 2618 | unsigned Count, |
| 2619 | bool isDoubleSpaced, |
| 2620 | SMLoc S, SMLoc E) { |
| 2621 | auto Op = make_unique<ARMOperand>(k_VectorList); |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 2622 | Op->VectorList.RegNum = RegNum; |
| 2623 | Op->VectorList.Count = Count; |
Jim Grosbach | 2f50e92 | 2011-12-15 21:44:33 +0000 | [diff] [blame] | 2624 | Op->VectorList.isDoubleSpaced = isDoubleSpaced; |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 2625 | Op->StartLoc = S; |
| 2626 | Op->EndLoc = E; |
| 2627 | return Op; |
| 2628 | } |
| 2629 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2630 | static std::unique_ptr<ARMOperand> |
| 2631 | CreateVectorListAllLanes(unsigned RegNum, unsigned Count, bool isDoubleSpaced, |
| 2632 | SMLoc S, SMLoc E) { |
| 2633 | auto Op = make_unique<ARMOperand>(k_VectorListAllLanes); |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 2634 | Op->VectorList.RegNum = RegNum; |
| 2635 | Op->VectorList.Count = Count; |
Jim Grosbach | c5af54e | 2011-12-21 00:38:54 +0000 | [diff] [blame] | 2636 | Op->VectorList.isDoubleSpaced = isDoubleSpaced; |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 2637 | Op->StartLoc = S; |
| 2638 | Op->EndLoc = E; |
| 2639 | return Op; |
| 2640 | } |
| 2641 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2642 | static std::unique_ptr<ARMOperand> |
| 2643 | CreateVectorListIndexed(unsigned RegNum, unsigned Count, unsigned Index, |
| 2644 | bool isDoubleSpaced, SMLoc S, SMLoc E) { |
| 2645 | auto Op = make_unique<ARMOperand>(k_VectorListIndexed); |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 2646 | Op->VectorList.RegNum = RegNum; |
| 2647 | Op->VectorList.Count = Count; |
| 2648 | Op->VectorList.LaneIndex = Index; |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 2649 | Op->VectorList.isDoubleSpaced = isDoubleSpaced; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 2650 | Op->StartLoc = S; |
| 2651 | Op->EndLoc = E; |
| 2652 | return Op; |
| 2653 | } |
| 2654 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2655 | static std::unique_ptr<ARMOperand> |
| 2656 | CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E, MCContext &Ctx) { |
| 2657 | auto Op = make_unique<ARMOperand>(k_VectorIndex); |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 2658 | Op->VectorIndex.Val = Idx; |
| 2659 | Op->StartLoc = S; |
| 2660 | Op->EndLoc = E; |
| 2661 | return Op; |
| 2662 | } |
| 2663 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2664 | static std::unique_ptr<ARMOperand> CreateImm(const MCExpr *Val, SMLoc S, |
| 2665 | SMLoc E) { |
| 2666 | auto Op = make_unique<ARMOperand>(k_Immediate); |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 2667 | Op->Imm.Val = Val; |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 2668 | Op->StartLoc = S; |
| 2669 | Op->EndLoc = E; |
Chris Lattner | bd7c9fa | 2010-10-28 17:20:03 +0000 | [diff] [blame] | 2670 | return Op; |
Kevin Enderby | f507994 | 2009-10-13 22:19:02 +0000 | [diff] [blame] | 2671 | } |
| 2672 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2673 | static std::unique_ptr<ARMOperand> |
| 2674 | CreateMem(unsigned BaseRegNum, const MCConstantExpr *OffsetImm, |
| 2675 | unsigned OffsetRegNum, ARM_AM::ShiftOpc ShiftType, |
| 2676 | unsigned ShiftImm, unsigned Alignment, bool isNegative, SMLoc S, |
| 2677 | SMLoc E, SMLoc AlignmentLoc = SMLoc()) { |
| 2678 | auto Op = make_unique<ARMOperand>(k_Memory); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2679 | Op->Memory.BaseRegNum = BaseRegNum; |
| 2680 | Op->Memory.OffsetImm = OffsetImm; |
| 2681 | Op->Memory.OffsetRegNum = OffsetRegNum; |
| 2682 | Op->Memory.ShiftType = ShiftType; |
| 2683 | Op->Memory.ShiftImm = ShiftImm; |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 2684 | Op->Memory.Alignment = Alignment; |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2685 | Op->Memory.isNegative = isNegative; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2686 | Op->StartLoc = S; |
| 2687 | Op->EndLoc = E; |
Kevin Enderby | 488f20b | 2014-04-10 20:18:58 +0000 | [diff] [blame] | 2688 | Op->AlignmentLoc = AlignmentLoc; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2689 | return Op; |
| 2690 | } |
Jim Grosbach | 624bcc7 | 2010-10-29 14:46:02 +0000 | [diff] [blame] | 2691 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2692 | static std::unique_ptr<ARMOperand> |
| 2693 | CreatePostIdxReg(unsigned RegNum, bool isAdd, ARM_AM::ShiftOpc ShiftTy, |
| 2694 | unsigned ShiftImm, SMLoc S, SMLoc E) { |
| 2695 | auto Op = make_unique<ARMOperand>(k_PostIndexRegister); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2696 | Op->PostIdxReg.RegNum = RegNum; |
Jim Grosbach | c320c85 | 2011-08-05 21:28:30 +0000 | [diff] [blame] | 2697 | Op->PostIdxReg.isAdd = isAdd; |
| 2698 | Op->PostIdxReg.ShiftTy = ShiftTy; |
| 2699 | Op->PostIdxReg.ShiftImm = ShiftImm; |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 2700 | Op->StartLoc = S; |
| 2701 | Op->EndLoc = E; |
Chris Lattner | bd7c9fa | 2010-10-28 17:20:03 +0000 | [diff] [blame] | 2702 | return Op; |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 2703 | } |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 2704 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2705 | static std::unique_ptr<ARMOperand> CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, |
| 2706 | SMLoc S) { |
| 2707 | auto Op = make_unique<ARMOperand>(k_MemBarrierOpt); |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 2708 | Op->MBOpt.Val = Opt; |
| 2709 | Op->StartLoc = S; |
| 2710 | Op->EndLoc = S; |
| 2711 | return Op; |
| 2712 | } |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 2713 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2714 | static std::unique_ptr<ARMOperand> |
| 2715 | CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt, SMLoc S) { |
| 2716 | auto Op = make_unique<ARMOperand>(k_InstSyncBarrierOpt); |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 2717 | Op->ISBOpt.Val = Opt; |
| 2718 | Op->StartLoc = S; |
| 2719 | Op->EndLoc = S; |
| 2720 | return Op; |
| 2721 | } |
| 2722 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2723 | static std::unique_ptr<ARMOperand> CreateProcIFlags(ARM_PROC::IFlags IFlags, |
| 2724 | SMLoc S) { |
| 2725 | auto Op = make_unique<ARMOperand>(k_ProcIFlags); |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 2726 | Op->IFlags.Val = IFlags; |
| 2727 | Op->StartLoc = S; |
| 2728 | Op->EndLoc = S; |
| 2729 | return Op; |
| 2730 | } |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 2731 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2732 | static std::unique_ptr<ARMOperand> CreateMSRMask(unsigned MMask, SMLoc S) { |
| 2733 | auto Op = make_unique<ARMOperand>(k_MSRMask); |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 2734 | Op->MMask.Val = MMask; |
| 2735 | Op->StartLoc = S; |
| 2736 | Op->EndLoc = S; |
| 2737 | return Op; |
| 2738 | } |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 2739 | }; |
| 2740 | |
| 2741 | } // end anonymous namespace. |
| 2742 | |
Jim Grosbach | 602aa90 | 2011-07-13 15:34:57 +0000 | [diff] [blame] | 2743 | void ARMOperand::print(raw_ostream &OS) const { |
Daniel Dunbar | 4a863e6 | 2010-08-11 06:37:12 +0000 | [diff] [blame] | 2744 | switch (Kind) { |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2745 | case k_CondCode: |
Daniel Dunbar | 2be732a | 2011-01-10 15:26:21 +0000 | [diff] [blame] | 2746 | OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">"; |
Daniel Dunbar | 4a863e6 | 2010-08-11 06:37:12 +0000 | [diff] [blame] | 2747 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2748 | case k_CCOut: |
Jim Grosbach | 0bfb4d5 | 2010-12-06 18:21:12 +0000 | [diff] [blame] | 2749 | OS << "<ccout " << getReg() << ">"; |
| 2750 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2751 | case k_ITCondMask: { |
Craig Topper | 42b96d1 | 2012-05-24 04:11:15 +0000 | [diff] [blame] | 2752 | static const char *const MaskStr[] = { |
Benjamin Kramer | 0d6d098 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 2753 | "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)", |
| 2754 | "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)" |
| 2755 | }; |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 2756 | assert((ITMask.Mask & 0xf) == ITMask.Mask); |
| 2757 | OS << "<it-mask " << MaskStr[ITMask.Mask] << ">"; |
| 2758 | break; |
| 2759 | } |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2760 | case k_CoprocNum: |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 2761 | OS << "<coprocessor number: " << getCoproc() << ">"; |
| 2762 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2763 | case k_CoprocReg: |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 2764 | OS << "<coprocessor register: " << getCoproc() << ">"; |
| 2765 | break; |
Jim Grosbach | 4839958 | 2011-10-12 17:34:41 +0000 | [diff] [blame] | 2766 | case k_CoprocOption: |
| 2767 | OS << "<coprocessor option: " << CoprocOption.Val << ">"; |
| 2768 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2769 | case k_MSRMask: |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 2770 | OS << "<mask: " << getMSRMask() << ">"; |
| 2771 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2772 | case k_Immediate: |
Daniel Dunbar | 4a863e6 | 2010-08-11 06:37:12 +0000 | [diff] [blame] | 2773 | getImm()->print(OS); |
| 2774 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2775 | case k_MemBarrierOpt: |
Joey Gouly | 926d3f5 | 2013-09-05 15:35:24 +0000 | [diff] [blame] | 2776 | OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">"; |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 2777 | break; |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 2778 | case k_InstSyncBarrierOpt: |
| 2779 | OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">"; |
| 2780 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2781 | case k_Memory: |
Daniel Dunbar | bcd8eb0 | 2011-01-18 05:55:21 +0000 | [diff] [blame] | 2782 | OS << "<memory " |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2783 | << " base:" << Memory.BaseRegNum; |
Daniel Dunbar | bcd8eb0 | 2011-01-18 05:55:21 +0000 | [diff] [blame] | 2784 | OS << ">"; |
Daniel Dunbar | 4a863e6 | 2010-08-11 06:37:12 +0000 | [diff] [blame] | 2785 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2786 | case k_PostIndexRegister: |
Jim Grosbach | c320c85 | 2011-08-05 21:28:30 +0000 | [diff] [blame] | 2787 | OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-") |
| 2788 | << PostIdxReg.RegNum; |
| 2789 | if (PostIdxReg.ShiftTy != ARM_AM::no_shift) |
| 2790 | OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " " |
| 2791 | << PostIdxReg.ShiftImm; |
| 2792 | OS << ">"; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2793 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2794 | case k_ProcIFlags: { |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 2795 | OS << "<ARM_PROC::"; |
| 2796 | unsigned IFlags = getProcIFlags(); |
| 2797 | for (int i=2; i >= 0; --i) |
| 2798 | if (IFlags & (1 << i)) |
| 2799 | OS << ARM_PROC::IFlagsToString(1 << i); |
| 2800 | OS << ">"; |
| 2801 | break; |
| 2802 | } |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2803 | case k_Register: |
Bill Wendling | 2063b84 | 2010-11-18 23:43:05 +0000 | [diff] [blame] | 2804 | OS << "<register " << getReg() << ">"; |
Daniel Dunbar | 4a863e6 | 2010-08-11 06:37:12 +0000 | [diff] [blame] | 2805 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2806 | case k_ShifterImmediate: |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 2807 | OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl") |
| 2808 | << " #" << ShifterImm.Imm << ">"; |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 2809 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2810 | case k_ShiftedRegister: |
Owen Anderson | b595ed0 | 2011-07-21 18:54:16 +0000 | [diff] [blame] | 2811 | OS << "<so_reg_reg " |
Jim Grosbach | 01e0439 | 2011-11-16 21:46:50 +0000 | [diff] [blame] | 2812 | << RegShiftedReg.SrcReg << " " |
| 2813 | << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy) |
| 2814 | << " " << RegShiftedReg.ShiftReg << ">"; |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 2815 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2816 | case k_ShiftedImmediate: |
Owen Anderson | b595ed0 | 2011-07-21 18:54:16 +0000 | [diff] [blame] | 2817 | OS << "<so_reg_imm " |
Jim Grosbach | 01e0439 | 2011-11-16 21:46:50 +0000 | [diff] [blame] | 2818 | << RegShiftedImm.SrcReg << " " |
| 2819 | << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy) |
| 2820 | << " #" << RegShiftedImm.ShiftImm << ">"; |
Owen Anderson | b595ed0 | 2011-07-21 18:54:16 +0000 | [diff] [blame] | 2821 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2822 | case k_RotateImmediate: |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 2823 | OS << "<ror " << " #" << (RotImm.Imm * 8) << ">"; |
| 2824 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2825 | case k_BitfieldDescriptor: |
Jim Grosbach | 864b609 | 2011-07-28 21:34:26 +0000 | [diff] [blame] | 2826 | OS << "<bitfield " << "lsb: " << Bitfield.LSB |
| 2827 | << ", width: " << Bitfield.Width << ">"; |
| 2828 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2829 | case k_RegisterList: |
| 2830 | case k_DPRRegisterList: |
| 2831 | case k_SPRRegisterList: { |
Bill Wendling | 7cef447 | 2010-11-06 19:56:04 +0000 | [diff] [blame] | 2832 | OS << "<register_list "; |
Bill Wendling | 7cef447 | 2010-11-06 19:56:04 +0000 | [diff] [blame] | 2833 | |
Bill Wendling | bed9465 | 2010-11-09 23:28:44 +0000 | [diff] [blame] | 2834 | const SmallVectorImpl<unsigned> &RegList = getRegList(); |
| 2835 | for (SmallVectorImpl<unsigned>::const_iterator |
Bill Wendling | 2cae327 | 2010-11-09 22:44:22 +0000 | [diff] [blame] | 2836 | I = RegList.begin(), E = RegList.end(); I != E; ) { |
| 2837 | OS << *I; |
| 2838 | if (++I < E) OS << ", "; |
Bill Wendling | 7cef447 | 2010-11-06 19:56:04 +0000 | [diff] [blame] | 2839 | } |
| 2840 | |
| 2841 | OS << ">"; |
| 2842 | break; |
| 2843 | } |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 2844 | case k_VectorList: |
| 2845 | OS << "<vector_list " << VectorList.Count << " * " |
| 2846 | << VectorList.RegNum << ">"; |
| 2847 | break; |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 2848 | case k_VectorListAllLanes: |
| 2849 | OS << "<vector_list(all lanes) " << VectorList.Count << " * " |
| 2850 | << VectorList.RegNum << ">"; |
| 2851 | break; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 2852 | case k_VectorListIndexed: |
| 2853 | OS << "<vector_list(lane " << VectorList.LaneIndex << ") " |
| 2854 | << VectorList.Count << " * " << VectorList.RegNum << ">"; |
| 2855 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2856 | case k_Token: |
Daniel Dunbar | 4a863e6 | 2010-08-11 06:37:12 +0000 | [diff] [blame] | 2857 | OS << "'" << getToken() << "'"; |
| 2858 | break; |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 2859 | case k_VectorIndex: |
| 2860 | OS << "<vectorindex " << getVectorIndex() << ">"; |
| 2861 | break; |
Daniel Dunbar | 4a863e6 | 2010-08-11 06:37:12 +0000 | [diff] [blame] | 2862 | } |
| 2863 | } |
Daniel Dunbar | 5cd4d0f | 2010-08-11 05:24:50 +0000 | [diff] [blame] | 2864 | |
| 2865 | /// @name Auto-generated Match Functions |
| 2866 | /// { |
| 2867 | |
| 2868 | static unsigned MatchRegisterName(StringRef Name); |
| 2869 | |
| 2870 | /// } |
| 2871 | |
Bob Wilson | fb0bd04 | 2011-02-03 21:46:10 +0000 | [diff] [blame] | 2872 | bool ARMAsmParser::ParseRegister(unsigned &RegNo, |
| 2873 | SMLoc &StartLoc, SMLoc &EndLoc) { |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 2874 | StartLoc = Parser.getTok().getLoc(); |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 2875 | EndLoc = Parser.getTok().getEndLoc(); |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 2876 | RegNo = tryParseRegister(); |
Roman Divacky | 36b1b47 | 2011-01-27 17:14:22 +0000 | [diff] [blame] | 2877 | |
| 2878 | return (RegNo == (unsigned)-1); |
| 2879 | } |
| 2880 | |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 2881 | /// Try to parse a register name. The token must be an Identifier when called, |
Chris Lattner | 44e5981c | 2010-10-30 04:09:10 +0000 | [diff] [blame] | 2882 | /// and if it is a register name the token is eaten and the register number is |
| 2883 | /// returned. Otherwise return -1. |
| 2884 | /// |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 2885 | int ARMAsmParser::tryParseRegister() { |
Chris Lattner | 44e5981c | 2010-10-30 04:09:10 +0000 | [diff] [blame] | 2886 | const AsmToken &Tok = Parser.getTok(); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2887 | if (Tok.isNot(AsmToken::Identifier)) return -1; |
Jim Grosbach | 99710a8 | 2010-11-01 16:44:21 +0000 | [diff] [blame] | 2888 | |
Benjamin Kramer | 20baffb | 2011-11-06 20:37:06 +0000 | [diff] [blame] | 2889 | std::string lowerCase = Tok.getString().lower(); |
Owen Anderson | a098d15 | 2011-01-13 22:50:36 +0000 | [diff] [blame] | 2890 | unsigned RegNum = MatchRegisterName(lowerCase); |
| 2891 | if (!RegNum) { |
| 2892 | RegNum = StringSwitch<unsigned>(lowerCase) |
| 2893 | .Case("r13", ARM::SP) |
| 2894 | .Case("r14", ARM::LR) |
| 2895 | .Case("r15", ARM::PC) |
| 2896 | .Case("ip", ARM::R12) |
Jim Grosbach | 4edc736 | 2011-12-08 19:27:38 +0000 | [diff] [blame] | 2897 | // Additional register name aliases for 'gas' compatibility. |
| 2898 | .Case("a1", ARM::R0) |
| 2899 | .Case("a2", ARM::R1) |
| 2900 | .Case("a3", ARM::R2) |
| 2901 | .Case("a4", ARM::R3) |
| 2902 | .Case("v1", ARM::R4) |
| 2903 | .Case("v2", ARM::R5) |
| 2904 | .Case("v3", ARM::R6) |
| 2905 | .Case("v4", ARM::R7) |
| 2906 | .Case("v5", ARM::R8) |
| 2907 | .Case("v6", ARM::R9) |
| 2908 | .Case("v7", ARM::R10) |
| 2909 | .Case("v8", ARM::R11) |
| 2910 | .Case("sb", ARM::R9) |
| 2911 | .Case("sl", ARM::R10) |
| 2912 | .Case("fp", ARM::R11) |
Owen Anderson | a098d15 | 2011-01-13 22:50:36 +0000 | [diff] [blame] | 2913 | .Default(0); |
| 2914 | } |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 2915 | if (!RegNum) { |
Jim Grosbach | cd22e4a | 2011-12-20 23:11:00 +0000 | [diff] [blame] | 2916 | // Check for aliases registered via .req. Canonicalize to lower case. |
| 2917 | // That's more consistent since register names are case insensitive, and |
| 2918 | // it's how the original entry was passed in from MC/MCParser/AsmParser. |
| 2919 | StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase); |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 2920 | // If no match, return failure. |
| 2921 | if (Entry == RegisterReqs.end()) |
| 2922 | return -1; |
| 2923 | Parser.Lex(); // Eat identifier token. |
| 2924 | return Entry->getValue(); |
| 2925 | } |
Bob Wilson | fb0bd04 | 2011-02-03 21:46:10 +0000 | [diff] [blame] | 2926 | |
Chris Lattner | 44e5981c | 2010-10-30 04:09:10 +0000 | [diff] [blame] | 2927 | Parser.Lex(); // Eat identifier token. |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 2928 | |
Chris Lattner | 44e5981c | 2010-10-30 04:09:10 +0000 | [diff] [blame] | 2929 | return RegNum; |
| 2930 | } |
Jim Grosbach | 99710a8 | 2010-11-01 16:44:21 +0000 | [diff] [blame] | 2931 | |
Jim Grosbach | bb24c59 | 2011-07-13 18:49:30 +0000 | [diff] [blame] | 2932 | // Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0. |
| 2933 | // If a recoverable error occurs, return 1. If an irrecoverable error |
| 2934 | // occurs, return -1. An irrecoverable error is one where tokens have been |
| 2935 | // consumed in the process of trying to parse the shifter (i.e., when it is |
| 2936 | // indeed a shifter operand, but malformed). |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2937 | int ARMAsmParser::tryParseShiftRegister(OperandVector &Operands) { |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 2938 | SMLoc S = Parser.getTok().getLoc(); |
| 2939 | const AsmToken &Tok = Parser.getTok(); |
Kevin Enderby | 6287371 | 2014-02-17 21:45:27 +0000 | [diff] [blame] | 2940 | if (Tok.isNot(AsmToken::Identifier)) |
| 2941 | return -1; |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 2942 | |
Benjamin Kramer | 20baffb | 2011-11-06 20:37:06 +0000 | [diff] [blame] | 2943 | std::string lowerCase = Tok.getString().lower(); |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 2944 | ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase) |
Jim Grosbach | 3b559ff | 2011-12-07 23:40:58 +0000 | [diff] [blame] | 2945 | .Case("asl", ARM_AM::lsl) |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 2946 | .Case("lsl", ARM_AM::lsl) |
| 2947 | .Case("lsr", ARM_AM::lsr) |
| 2948 | .Case("asr", ARM_AM::asr) |
| 2949 | .Case("ror", ARM_AM::ror) |
| 2950 | .Case("rrx", ARM_AM::rrx) |
| 2951 | .Default(ARM_AM::no_shift); |
| 2952 | |
| 2953 | if (ShiftTy == ARM_AM::no_shift) |
Jim Grosbach | bb24c59 | 2011-07-13 18:49:30 +0000 | [diff] [blame] | 2954 | return 1; |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 2955 | |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 2956 | Parser.Lex(); // Eat the operator. |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 2957 | |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 2958 | // The source register for the shift has already been added to the |
| 2959 | // operand list, so we need to pop it off and combine it into the shifted |
| 2960 | // register operand instead. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2961 | std::unique_ptr<ARMOperand> PrevOp( |
| 2962 | (ARMOperand *)Operands.pop_back_val().release()); |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 2963 | if (!PrevOp->isReg()) |
| 2964 | return Error(PrevOp->getStartLoc(), "shift must be of a register"); |
| 2965 | int SrcReg = PrevOp->getReg(); |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 2966 | |
| 2967 | SMLoc EndLoc; |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 2968 | int64_t Imm = 0; |
| 2969 | int ShiftReg = 0; |
| 2970 | if (ShiftTy == ARM_AM::rrx) { |
| 2971 | // RRX Doesn't have an explicit shift amount. The encoder expects |
| 2972 | // the shift register to be the same as the source register. Seems odd, |
| 2973 | // but OK. |
| 2974 | ShiftReg = SrcReg; |
| 2975 | } else { |
| 2976 | // Figure out if this is shifted by a constant or a register (for non-RRX). |
Jim Grosbach | ef70e9b | 2011-12-09 22:25:03 +0000 | [diff] [blame] | 2977 | if (Parser.getTok().is(AsmToken::Hash) || |
| 2978 | Parser.getTok().is(AsmToken::Dollar)) { |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 2979 | Parser.Lex(); // Eat hash. |
| 2980 | SMLoc ImmLoc = Parser.getTok().getLoc(); |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 2981 | const MCExpr *ShiftExpr = nullptr; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 2982 | if (getParser().parseExpression(ShiftExpr, EndLoc)) { |
Jim Grosbach | bb24c59 | 2011-07-13 18:49:30 +0000 | [diff] [blame] | 2983 | Error(ImmLoc, "invalid immediate shift value"); |
| 2984 | return -1; |
| 2985 | } |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 2986 | // The expression must be evaluatable as an immediate. |
| 2987 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr); |
Jim Grosbach | bb24c59 | 2011-07-13 18:49:30 +0000 | [diff] [blame] | 2988 | if (!CE) { |
| 2989 | Error(ImmLoc, "invalid immediate shift value"); |
| 2990 | return -1; |
| 2991 | } |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 2992 | // Range check the immediate. |
| 2993 | // lsl, ror: 0 <= imm <= 31 |
| 2994 | // lsr, asr: 0 <= imm <= 32 |
| 2995 | Imm = CE->getValue(); |
| 2996 | if (Imm < 0 || |
| 2997 | ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) || |
| 2998 | ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) { |
Jim Grosbach | bb24c59 | 2011-07-13 18:49:30 +0000 | [diff] [blame] | 2999 | Error(ImmLoc, "immediate shift value out of range"); |
| 3000 | return -1; |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 3001 | } |
Jim Grosbach | 21488b8 | 2011-12-22 17:37:00 +0000 | [diff] [blame] | 3002 | // shift by zero is a nop. Always send it through as lsl. |
| 3003 | // ('as' compatibility) |
| 3004 | if (Imm == 0) |
| 3005 | ShiftTy = ARM_AM::lsl; |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 3006 | } else if (Parser.getTok().is(AsmToken::Identifier)) { |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 3007 | SMLoc L = Parser.getTok().getLoc(); |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3008 | EndLoc = Parser.getTok().getEndLoc(); |
| 3009 | ShiftReg = tryParseRegister(); |
Jim Grosbach | bb24c59 | 2011-07-13 18:49:30 +0000 | [diff] [blame] | 3010 | if (ShiftReg == -1) { |
Saleem Abdulrasool | 6d11b7c | 2014-05-17 21:49:54 +0000 | [diff] [blame] | 3011 | Error(L, "expected immediate or register in shift operand"); |
Jim Grosbach | bb24c59 | 2011-07-13 18:49:30 +0000 | [diff] [blame] | 3012 | return -1; |
| 3013 | } |
| 3014 | } else { |
Saleem Abdulrasool | 6d11b7c | 2014-05-17 21:49:54 +0000 | [diff] [blame] | 3015 | Error(Parser.getTok().getLoc(), |
| 3016 | "expected immediate or register in shift operand"); |
Jim Grosbach | bb24c59 | 2011-07-13 18:49:30 +0000 | [diff] [blame] | 3017 | return -1; |
| 3018 | } |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 3019 | } |
| 3020 | |
Owen Anderson | b595ed0 | 2011-07-21 18:54:16 +0000 | [diff] [blame] | 3021 | if (ShiftReg && ShiftTy != ARM_AM::rrx) |
| 3022 | Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg, |
Jim Grosbach | ac798e1 | 2011-07-25 20:49:51 +0000 | [diff] [blame] | 3023 | ShiftReg, Imm, |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3024 | S, EndLoc)); |
Owen Anderson | b595ed0 | 2011-07-21 18:54:16 +0000 | [diff] [blame] | 3025 | else |
| 3026 | Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm, |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3027 | S, EndLoc)); |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 3028 | |
Jim Grosbach | bb24c59 | 2011-07-13 18:49:30 +0000 | [diff] [blame] | 3029 | return 0; |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 3030 | } |
| 3031 | |
| 3032 | |
Bill Wendling | 2063b84 | 2010-11-18 23:43:05 +0000 | [diff] [blame] | 3033 | /// Try to parse a register name. The token must be an Identifier when called. |
| 3034 | /// If it's a register, an AsmOperand is created. Another AsmOperand is created |
| 3035 | /// if there is a "writeback". 'true' if it's not a register. |
Chris Lattner | bd7c9fa | 2010-10-28 17:20:03 +0000 | [diff] [blame] | 3036 | /// |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 3037 | /// TODO this is likely to change to allow different register types and or to |
| 3038 | /// parse for a specific register type. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 3039 | bool ARMAsmParser::tryParseRegisterWithWriteBack(OperandVector &Operands) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3040 | const AsmToken &RegTok = Parser.getTok(); |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 3041 | int RegNo = tryParseRegister(); |
Bill Wendling | e18980a | 2010-11-06 22:36:58 +0000 | [diff] [blame] | 3042 | if (RegNo == -1) |
Bill Wendling | 2063b84 | 2010-11-18 23:43:05 +0000 | [diff] [blame] | 3043 | return true; |
Jim Grosbach | 99710a8 | 2010-11-01 16:44:21 +0000 | [diff] [blame] | 3044 | |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3045 | Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(), |
| 3046 | RegTok.getEndLoc())); |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 3047 | |
Chris Lattner | 44e5981c | 2010-10-30 04:09:10 +0000 | [diff] [blame] | 3048 | const AsmToken &ExclaimTok = Parser.getTok(); |
| 3049 | if (ExclaimTok.is(AsmToken::Exclaim)) { |
Bill Wendling | 2063b84 | 2010-11-18 23:43:05 +0000 | [diff] [blame] | 3050 | Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(), |
| 3051 | ExclaimTok.getLoc())); |
Chris Lattner | 44e5981c | 2010-10-30 04:09:10 +0000 | [diff] [blame] | 3052 | Parser.Lex(); // Eat exclaim token |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 3053 | return false; |
| 3054 | } |
| 3055 | |
| 3056 | // Also check for an index operand. This is only legal for vector registers, |
| 3057 | // but that'll get caught OK in operand matching, so we don't need to |
| 3058 | // explicitly filter everything else out here. |
| 3059 | if (Parser.getTok().is(AsmToken::LBrac)) { |
| 3060 | SMLoc SIdx = Parser.getTok().getLoc(); |
| 3061 | Parser.Lex(); // Eat left bracket token. |
| 3062 | |
| 3063 | const MCExpr *ImmVal; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 3064 | if (getParser().parseExpression(ImmVal)) |
Jim Grosbach | a2147ce | 2012-01-31 23:51:09 +0000 | [diff] [blame] | 3065 | return true; |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 3066 | const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal); |
Jim Grosbach | c8f2b78 | 2012-01-26 15:56:45 +0000 | [diff] [blame] | 3067 | if (!MCE) |
| 3068 | return TokError("immediate value expected for vector index"); |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 3069 | |
Jim Grosbach | c8f2b78 | 2012-01-26 15:56:45 +0000 | [diff] [blame] | 3070 | if (Parser.getTok().isNot(AsmToken::RBrac)) |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3071 | return Error(Parser.getTok().getLoc(), "']' expected"); |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 3072 | |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3073 | SMLoc E = Parser.getTok().getEndLoc(); |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 3074 | Parser.Lex(); // Eat right bracket token. |
| 3075 | |
| 3076 | Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(), |
| 3077 | SIdx, E, |
| 3078 | getContext())); |
Kevin Enderby | 2207e5f | 2009-10-07 18:01:35 +0000 | [diff] [blame] | 3079 | } |
| 3080 | |
Bill Wendling | 2063b84 | 2010-11-18 23:43:05 +0000 | [diff] [blame] | 3081 | return false; |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 3082 | } |
| 3083 | |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 3084 | /// MatchCoprocessorOperandName - Try to parse an coprocessor related |
Renato Golin | ac561c3 | 2014-06-26 13:10:53 +0000 | [diff] [blame] | 3085 | /// instruction with a symbolic operand name. |
| 3086 | /// We accept "crN" syntax for GAS compatibility. |
| 3087 | /// <operand-name> ::= <prefix><number> |
| 3088 | /// If CoprocOp is 'c', then: |
| 3089 | /// <prefix> ::= c | cr |
| 3090 | /// If CoprocOp is 'p', then : |
| 3091 | /// <prefix> ::= p |
| 3092 | /// <number> ::= integer in range [0, 15] |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 3093 | static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) { |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3094 | // Use the same layout as the tablegen'erated register name matcher. Ugly, |
| 3095 | // but efficient. |
Renato Golin | ac561c3 | 2014-06-26 13:10:53 +0000 | [diff] [blame] | 3096 | if (Name.size() < 2 || Name[0] != CoprocOp) |
| 3097 | return -1; |
| 3098 | Name = (Name[1] == 'r') ? Name.drop_front(2) : Name.drop_front(); |
| 3099 | |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3100 | switch (Name.size()) { |
David Blaikie | 46a9f01 | 2012-01-20 21:51:11 +0000 | [diff] [blame] | 3101 | default: return -1; |
Renato Golin | ac561c3 | 2014-06-26 13:10:53 +0000 | [diff] [blame] | 3102 | case 1: |
| 3103 | switch (Name[0]) { |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3104 | default: return -1; |
| 3105 | case '0': return 0; |
| 3106 | case '1': return 1; |
| 3107 | case '2': return 2; |
| 3108 | case '3': return 3; |
| 3109 | case '4': return 4; |
| 3110 | case '5': return 5; |
| 3111 | case '6': return 6; |
| 3112 | case '7': return 7; |
| 3113 | case '8': return 8; |
| 3114 | case '9': return 9; |
| 3115 | } |
Renato Golin | ac561c3 | 2014-06-26 13:10:53 +0000 | [diff] [blame] | 3116 | case 2: |
| 3117 | if (Name[0] != '1') |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3118 | return -1; |
Renato Golin | ac561c3 | 2014-06-26 13:10:53 +0000 | [diff] [blame] | 3119 | switch (Name[1]) { |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3120 | default: return -1; |
Renato Golin | bc0b037 | 2014-08-04 23:21:56 +0000 | [diff] [blame^] | 3121 | // CP10 and CP11 are VFP/NEON and so vector instructions should be used. |
| 3122 | // However, old cores (v5/v6) did use them in that way. |
| 3123 | case '0': return 10; |
| 3124 | case '1': return 11; |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3125 | case '2': return 12; |
| 3126 | case '3': return 13; |
| 3127 | case '4': return 14; |
| 3128 | case '5': return 15; |
| 3129 | } |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3130 | } |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3131 | } |
| 3132 | |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 3133 | /// parseITCondCode - Try to parse a condition code for an IT instruction. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 3134 | ARMAsmParser::OperandMatchResultTy |
| 3135 | ARMAsmParser::parseITCondCode(OperandVector &Operands) { |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 3136 | SMLoc S = Parser.getTok().getLoc(); |
| 3137 | const AsmToken &Tok = Parser.getTok(); |
| 3138 | if (!Tok.is(AsmToken::Identifier)) |
| 3139 | return MatchOperand_NoMatch; |
Richard Barton | 82f95ea | 2012-04-27 17:34:01 +0000 | [diff] [blame] | 3140 | unsigned CC = StringSwitch<unsigned>(Tok.getString().lower()) |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 3141 | .Case("eq", ARMCC::EQ) |
| 3142 | .Case("ne", ARMCC::NE) |
| 3143 | .Case("hs", ARMCC::HS) |
| 3144 | .Case("cs", ARMCC::HS) |
| 3145 | .Case("lo", ARMCC::LO) |
| 3146 | .Case("cc", ARMCC::LO) |
| 3147 | .Case("mi", ARMCC::MI) |
| 3148 | .Case("pl", ARMCC::PL) |
| 3149 | .Case("vs", ARMCC::VS) |
| 3150 | .Case("vc", ARMCC::VC) |
| 3151 | .Case("hi", ARMCC::HI) |
| 3152 | .Case("ls", ARMCC::LS) |
| 3153 | .Case("ge", ARMCC::GE) |
| 3154 | .Case("lt", ARMCC::LT) |
| 3155 | .Case("gt", ARMCC::GT) |
| 3156 | .Case("le", ARMCC::LE) |
| 3157 | .Case("al", ARMCC::AL) |
| 3158 | .Default(~0U); |
| 3159 | if (CC == ~0U) |
| 3160 | return MatchOperand_NoMatch; |
| 3161 | Parser.Lex(); // Eat the token. |
| 3162 | |
| 3163 | Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S)); |
| 3164 | |
| 3165 | return MatchOperand_Success; |
| 3166 | } |
| 3167 | |
Jim Grosbach | 2d6ef44 | 2011-07-25 20:14:50 +0000 | [diff] [blame] | 3168 | /// parseCoprocNumOperand - Try to parse an coprocessor number operand. The |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 3169 | /// token must be an Identifier when called, and if it is a coprocessor |
| 3170 | /// number, the token is eaten and the operand is added to the operand list. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 3171 | ARMAsmParser::OperandMatchResultTy |
| 3172 | ARMAsmParser::parseCoprocNumOperand(OperandVector &Operands) { |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3173 | SMLoc S = Parser.getTok().getLoc(); |
| 3174 | const AsmToken &Tok = Parser.getTok(); |
Jim Grosbach | 54a20ed | 2011-10-12 20:54:17 +0000 | [diff] [blame] | 3175 | if (Tok.isNot(AsmToken::Identifier)) |
| 3176 | return MatchOperand_NoMatch; |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3177 | |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 3178 | int Num = MatchCoprocessorOperandName(Tok.getString(), 'p'); |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3179 | if (Num == -1) |
Jim Grosbach | 861e49c | 2011-02-12 01:34:40 +0000 | [diff] [blame] | 3180 | return MatchOperand_NoMatch; |
Renato Golin | bc0b037 | 2014-08-04 23:21:56 +0000 | [diff] [blame^] | 3181 | // ARMv7 and v8 don't allow cp10/cp11 due to VFP/NEON specific instructions |
| 3182 | if ((hasV7Ops() || hasV8Ops()) && (Num == 10 || Num == 11)) |
| 3183 | return MatchOperand_NoMatch; |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3184 | |
| 3185 | Parser.Lex(); // Eat identifier token. |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 3186 | Operands.push_back(ARMOperand::CreateCoprocNum(Num, S)); |
Jim Grosbach | 861e49c | 2011-02-12 01:34:40 +0000 | [diff] [blame] | 3187 | return MatchOperand_Success; |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 3188 | } |
| 3189 | |
Jim Grosbach | 2d6ef44 | 2011-07-25 20:14:50 +0000 | [diff] [blame] | 3190 | /// parseCoprocRegOperand - Try to parse an coprocessor register operand. The |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 3191 | /// token must be an Identifier when called, and if it is a coprocessor |
| 3192 | /// number, the token is eaten and the operand is added to the operand list. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 3193 | ARMAsmParser::OperandMatchResultTy |
| 3194 | ARMAsmParser::parseCoprocRegOperand(OperandVector &Operands) { |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 3195 | SMLoc S = Parser.getTok().getLoc(); |
| 3196 | const AsmToken &Tok = Parser.getTok(); |
Jim Grosbach | 54a20ed | 2011-10-12 20:54:17 +0000 | [diff] [blame] | 3197 | if (Tok.isNot(AsmToken::Identifier)) |
| 3198 | return MatchOperand_NoMatch; |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 3199 | |
| 3200 | int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c'); |
| 3201 | if (Reg == -1) |
Jim Grosbach | 861e49c | 2011-02-12 01:34:40 +0000 | [diff] [blame] | 3202 | return MatchOperand_NoMatch; |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 3203 | |
| 3204 | Parser.Lex(); // Eat identifier token. |
| 3205 | Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S)); |
Jim Grosbach | 861e49c | 2011-02-12 01:34:40 +0000 | [diff] [blame] | 3206 | return MatchOperand_Success; |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3207 | } |
| 3208 | |
Jim Grosbach | 4839958 | 2011-10-12 17:34:41 +0000 | [diff] [blame] | 3209 | /// parseCoprocOptionOperand - Try to parse an coprocessor option operand. |
| 3210 | /// coproc_option : '{' imm0_255 '}' |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 3211 | ARMAsmParser::OperandMatchResultTy |
| 3212 | ARMAsmParser::parseCoprocOptionOperand(OperandVector &Operands) { |
Jim Grosbach | 4839958 | 2011-10-12 17:34:41 +0000 | [diff] [blame] | 3213 | SMLoc S = Parser.getTok().getLoc(); |
| 3214 | |
| 3215 | // If this isn't a '{', this isn't a coprocessor immediate operand. |
| 3216 | if (Parser.getTok().isNot(AsmToken::LCurly)) |
| 3217 | return MatchOperand_NoMatch; |
| 3218 | Parser.Lex(); // Eat the '{' |
| 3219 | |
| 3220 | const MCExpr *Expr; |
| 3221 | SMLoc Loc = Parser.getTok().getLoc(); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 3222 | if (getParser().parseExpression(Expr)) { |
Jim Grosbach | 4839958 | 2011-10-12 17:34:41 +0000 | [diff] [blame] | 3223 | Error(Loc, "illegal expression"); |
| 3224 | return MatchOperand_ParseFail; |
| 3225 | } |
| 3226 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr); |
| 3227 | if (!CE || CE->getValue() < 0 || CE->getValue() > 255) { |
| 3228 | Error(Loc, "coprocessor option must be an immediate in range [0, 255]"); |
| 3229 | return MatchOperand_ParseFail; |
| 3230 | } |
| 3231 | int Val = CE->getValue(); |
| 3232 | |
| 3233 | // Check for and consume the closing '}' |
| 3234 | if (Parser.getTok().isNot(AsmToken::RCurly)) |
| 3235 | return MatchOperand_ParseFail; |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3236 | SMLoc E = Parser.getTok().getEndLoc(); |
Jim Grosbach | 4839958 | 2011-10-12 17:34:41 +0000 | [diff] [blame] | 3237 | Parser.Lex(); // Eat the '}' |
| 3238 | |
| 3239 | Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E)); |
| 3240 | return MatchOperand_Success; |
| 3241 | } |
| 3242 | |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3243 | // For register list parsing, we need to map from raw GPR register numbering |
| 3244 | // to the enumeration values. The enumeration values aren't sorted by |
| 3245 | // register number due to our using "sp", "lr" and "pc" as canonical names. |
| 3246 | static unsigned getNextRegister(unsigned Reg) { |
| 3247 | // If this is a GPR, we need to do it manually, otherwise we can rely |
| 3248 | // on the sort ordering of the enumeration since the other reg-classes |
| 3249 | // are sane. |
| 3250 | if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg)) |
| 3251 | return Reg + 1; |
| 3252 | switch(Reg) { |
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 3253 | default: llvm_unreachable("Invalid GPR number!"); |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3254 | case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2; |
| 3255 | case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4; |
| 3256 | case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6; |
| 3257 | case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8; |
| 3258 | case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10; |
| 3259 | case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12; |
| 3260 | case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR; |
| 3261 | case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0; |
| 3262 | } |
| 3263 | } |
| 3264 | |
Jim Grosbach | 85a2343 | 2011-11-11 21:27:40 +0000 | [diff] [blame] | 3265 | // Return the low-subreg of a given Q register. |
| 3266 | static unsigned getDRegFromQReg(unsigned QReg) { |
| 3267 | switch (QReg) { |
| 3268 | default: llvm_unreachable("expected a Q register!"); |
| 3269 | case ARM::Q0: return ARM::D0; |
| 3270 | case ARM::Q1: return ARM::D2; |
| 3271 | case ARM::Q2: return ARM::D4; |
| 3272 | case ARM::Q3: return ARM::D6; |
| 3273 | case ARM::Q4: return ARM::D8; |
| 3274 | case ARM::Q5: return ARM::D10; |
| 3275 | case ARM::Q6: return ARM::D12; |
| 3276 | case ARM::Q7: return ARM::D14; |
| 3277 | case ARM::Q8: return ARM::D16; |
Jim Grosbach | a92a5d8 | 2011-11-15 21:01:30 +0000 | [diff] [blame] | 3278 | case ARM::Q9: return ARM::D18; |
Jim Grosbach | 85a2343 | 2011-11-11 21:27:40 +0000 | [diff] [blame] | 3279 | case ARM::Q10: return ARM::D20; |
| 3280 | case ARM::Q11: return ARM::D22; |
| 3281 | case ARM::Q12: return ARM::D24; |
| 3282 | case ARM::Q13: return ARM::D26; |
| 3283 | case ARM::Q14: return ARM::D28; |
| 3284 | case ARM::Q15: return ARM::D30; |
| 3285 | } |
| 3286 | } |
| 3287 | |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3288 | /// Parse a register list. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 3289 | bool ARMAsmParser::parseRegisterList(OperandVector &Operands) { |
Sean Callanan | 936b0d3 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 3290 | assert(Parser.getTok().is(AsmToken::LCurly) && |
Bill Wendling | 4f4bce0 | 2010-11-06 10:48:18 +0000 | [diff] [blame] | 3291 | "Token is not a Left Curly Brace"); |
Bill Wendling | e18980a | 2010-11-06 22:36:58 +0000 | [diff] [blame] | 3292 | SMLoc S = Parser.getTok().getLoc(); |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3293 | Parser.Lex(); // Eat '{' token. |
| 3294 | SMLoc RegLoc = Parser.getTok().getLoc(); |
Kevin Enderby | a2b9910 | 2009-10-09 21:12:28 +0000 | [diff] [blame] | 3295 | |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3296 | // Check the first register in the list to see what register class |
| 3297 | // this is a list of. |
| 3298 | int Reg = tryParseRegister(); |
| 3299 | if (Reg == -1) |
| 3300 | return Error(RegLoc, "register expected"); |
| 3301 | |
Jim Grosbach | 85a2343 | 2011-11-11 21:27:40 +0000 | [diff] [blame] | 3302 | // The reglist instructions have at most 16 registers, so reserve |
| 3303 | // space for that many. |
Chad Rosier | fa705ee | 2013-07-01 20:49:23 +0000 | [diff] [blame] | 3304 | int EReg = 0; |
| 3305 | SmallVector<std::pair<unsigned, unsigned>, 16> Registers; |
Jim Grosbach | 85a2343 | 2011-11-11 21:27:40 +0000 | [diff] [blame] | 3306 | |
| 3307 | // Allow Q regs and just interpret them as the two D sub-registers. |
| 3308 | if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) { |
| 3309 | Reg = getDRegFromQReg(Reg); |
Chad Rosier | fa705ee | 2013-07-01 20:49:23 +0000 | [diff] [blame] | 3310 | EReg = MRI->getEncodingValue(Reg); |
| 3311 | Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg)); |
Jim Grosbach | 85a2343 | 2011-11-11 21:27:40 +0000 | [diff] [blame] | 3312 | ++Reg; |
| 3313 | } |
Benjamin Kramer | 0d6d098 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 3314 | const MCRegisterClass *RC; |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3315 | if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg)) |
| 3316 | RC = &ARMMCRegisterClasses[ARM::GPRRegClassID]; |
| 3317 | else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) |
| 3318 | RC = &ARMMCRegisterClasses[ARM::DPRRegClassID]; |
| 3319 | else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg)) |
| 3320 | RC = &ARMMCRegisterClasses[ARM::SPRRegClassID]; |
| 3321 | else |
| 3322 | return Error(RegLoc, "invalid register in register list"); |
| 3323 | |
Jim Grosbach | 85a2343 | 2011-11-11 21:27:40 +0000 | [diff] [blame] | 3324 | // Store the register. |
Chad Rosier | fa705ee | 2013-07-01 20:49:23 +0000 | [diff] [blame] | 3325 | EReg = MRI->getEncodingValue(Reg); |
| 3326 | Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg)); |
Kevin Enderby | a2b9910 | 2009-10-09 21:12:28 +0000 | [diff] [blame] | 3327 | |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3328 | // This starts immediately after the first register token in the list, |
| 3329 | // so we can see either a comma or a minus (range separator) as a legal |
| 3330 | // next token. |
| 3331 | while (Parser.getTok().is(AsmToken::Comma) || |
| 3332 | Parser.getTok().is(AsmToken::Minus)) { |
| 3333 | if (Parser.getTok().is(AsmToken::Minus)) { |
Jim Grosbach | e891fe8 | 2011-11-15 23:19:15 +0000 | [diff] [blame] | 3334 | Parser.Lex(); // Eat the minus. |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3335 | SMLoc AfterMinusLoc = Parser.getTok().getLoc(); |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3336 | int EndReg = tryParseRegister(); |
| 3337 | if (EndReg == -1) |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3338 | return Error(AfterMinusLoc, "register expected"); |
Jim Grosbach | 85a2343 | 2011-11-11 21:27:40 +0000 | [diff] [blame] | 3339 | // Allow Q regs and just interpret them as the two D sub-registers. |
| 3340 | if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg)) |
| 3341 | EndReg = getDRegFromQReg(EndReg) + 1; |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3342 | // If the register is the same as the start reg, there's nothing |
| 3343 | // more to do. |
| 3344 | if (Reg == EndReg) |
| 3345 | continue; |
| 3346 | // The register must be in the same register class as the first. |
| 3347 | if (!RC->contains(EndReg)) |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3348 | return Error(AfterMinusLoc, "invalid register in register list"); |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3349 | // Ranges must go from low to high. |
Eric Christopher | 6ac277c | 2012-08-09 22:10:21 +0000 | [diff] [blame] | 3350 | if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg)) |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3351 | return Error(AfterMinusLoc, "bad range in register list"); |
Kevin Enderby | a2b9910 | 2009-10-09 21:12:28 +0000 | [diff] [blame] | 3352 | |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3353 | // Add all the registers in the range to the register list. |
| 3354 | while (Reg != EndReg) { |
| 3355 | Reg = getNextRegister(Reg); |
Chad Rosier | fa705ee | 2013-07-01 20:49:23 +0000 | [diff] [blame] | 3356 | EReg = MRI->getEncodingValue(Reg); |
| 3357 | Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg)); |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3358 | } |
| 3359 | continue; |
| 3360 | } |
| 3361 | Parser.Lex(); // Eat the comma. |
| 3362 | RegLoc = Parser.getTok().getLoc(); |
| 3363 | int OldReg = Reg; |
Jim Grosbach | 98bc797 | 2011-12-08 21:34:20 +0000 | [diff] [blame] | 3364 | const AsmToken RegTok = Parser.getTok(); |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3365 | Reg = tryParseRegister(); |
| 3366 | if (Reg == -1) |
Jim Grosbach | 3337e39 | 2011-09-12 23:36:42 +0000 | [diff] [blame] | 3367 | return Error(RegLoc, "register expected"); |
Jim Grosbach | 85a2343 | 2011-11-11 21:27:40 +0000 | [diff] [blame] | 3368 | // Allow Q regs and just interpret them as the two D sub-registers. |
| 3369 | bool isQReg = false; |
| 3370 | if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) { |
| 3371 | Reg = getDRegFromQReg(Reg); |
| 3372 | isQReg = true; |
| 3373 | } |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3374 | // The register must be in the same register class as the first. |
| 3375 | if (!RC->contains(Reg)) |
| 3376 | return Error(RegLoc, "invalid register in register list"); |
| 3377 | // List must be monotonically increasing. |
Eric Christopher | 6ac277c | 2012-08-09 22:10:21 +0000 | [diff] [blame] | 3378 | if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) { |
Jim Grosbach | 905686a | 2012-03-16 20:48:38 +0000 | [diff] [blame] | 3379 | if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg)) |
| 3380 | Warning(RegLoc, "register list not in ascending order"); |
| 3381 | else |
| 3382 | return Error(RegLoc, "register list not in ascending order"); |
| 3383 | } |
Eric Christopher | 6ac277c | 2012-08-09 22:10:21 +0000 | [diff] [blame] | 3384 | if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) { |
Jim Grosbach | 98bc797 | 2011-12-08 21:34:20 +0000 | [diff] [blame] | 3385 | Warning(RegLoc, "duplicated register (" + RegTok.getString() + |
| 3386 | ") in register list"); |
| 3387 | continue; |
| 3388 | } |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3389 | // VFP register lists must also be contiguous. |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3390 | if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] && |
| 3391 | Reg != OldReg + 1) |
| 3392 | return Error(RegLoc, "non-contiguous register range"); |
Chad Rosier | fa705ee | 2013-07-01 20:49:23 +0000 | [diff] [blame] | 3393 | EReg = MRI->getEncodingValue(Reg); |
| 3394 | Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg)); |
| 3395 | if (isQReg) { |
| 3396 | EReg = MRI->getEncodingValue(++Reg); |
| 3397 | Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg)); |
| 3398 | } |
Bill Wendling | e18980a | 2010-11-06 22:36:58 +0000 | [diff] [blame] | 3399 | } |
| 3400 | |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3401 | if (Parser.getTok().isNot(AsmToken::RCurly)) |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3402 | return Error(Parser.getTok().getLoc(), "'}' expected"); |
| 3403 | SMLoc E = Parser.getTok().getEndLoc(); |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3404 | Parser.Lex(); // Eat '}' token. |
| 3405 | |
Jim Grosbach | 18bf363 | 2011-12-13 21:48:29 +0000 | [diff] [blame] | 3406 | // Push the register list operand. |
Bill Wendling | 2063b84 | 2010-11-18 23:43:05 +0000 | [diff] [blame] | 3407 | Operands.push_back(ARMOperand::CreateRegList(Registers, S, E)); |
Jim Grosbach | 18bf363 | 2011-12-13 21:48:29 +0000 | [diff] [blame] | 3408 | |
| 3409 | // The ARM system instruction variants for LDM/STM have a '^' token here. |
| 3410 | if (Parser.getTok().is(AsmToken::Caret)) { |
| 3411 | Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc())); |
| 3412 | Parser.Lex(); // Eat '^' token. |
| 3413 | } |
| 3414 | |
Bill Wendling | 2063b84 | 2010-11-18 23:43:05 +0000 | [diff] [blame] | 3415 | return false; |
Kevin Enderby | a2b9910 | 2009-10-09 21:12:28 +0000 | [diff] [blame] | 3416 | } |
| 3417 | |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3418 | // Helper function to parse the lane index for vector lists. |
| 3419 | ARMAsmParser::OperandMatchResultTy ARMAsmParser:: |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3420 | parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) { |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3421 | Index = 0; // Always return a defined index value. |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3422 | if (Parser.getTok().is(AsmToken::LBrac)) { |
| 3423 | Parser.Lex(); // Eat the '['. |
| 3424 | if (Parser.getTok().is(AsmToken::RBrac)) { |
| 3425 | // "Dn[]" is the 'all lanes' syntax. |
| 3426 | LaneKind = AllLanes; |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3427 | EndLoc = Parser.getTok().getEndLoc(); |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3428 | Parser.Lex(); // Eat the ']'. |
| 3429 | return MatchOperand_Success; |
| 3430 | } |
Jim Grosbach | 67e76ba | 2012-03-19 20:39:53 +0000 | [diff] [blame] | 3431 | |
| 3432 | // There's an optional '#' token here. Normally there wouldn't be, but |
| 3433 | // inline assemble puts one in, and it's friendly to accept that. |
| 3434 | if (Parser.getTok().is(AsmToken::Hash)) |
Amaury de la Vieuville | bac917f | 2013-06-10 14:17:15 +0000 | [diff] [blame] | 3435 | Parser.Lex(); // Eat '#' or '$'. |
Jim Grosbach | 67e76ba | 2012-03-19 20:39:53 +0000 | [diff] [blame] | 3436 | |
Jim Grosbach | 7de7ab8 | 2011-12-21 01:19:23 +0000 | [diff] [blame] | 3437 | const MCExpr *LaneIndex; |
| 3438 | SMLoc Loc = Parser.getTok().getLoc(); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 3439 | if (getParser().parseExpression(LaneIndex)) { |
Jim Grosbach | 7de7ab8 | 2011-12-21 01:19:23 +0000 | [diff] [blame] | 3440 | Error(Loc, "illegal expression"); |
| 3441 | return MatchOperand_ParseFail; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3442 | } |
Jim Grosbach | 7de7ab8 | 2011-12-21 01:19:23 +0000 | [diff] [blame] | 3443 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex); |
| 3444 | if (!CE) { |
| 3445 | Error(Loc, "lane index must be empty or an integer"); |
| 3446 | return MatchOperand_ParseFail; |
| 3447 | } |
| 3448 | if (Parser.getTok().isNot(AsmToken::RBrac)) { |
| 3449 | Error(Parser.getTok().getLoc(), "']' expected"); |
| 3450 | return MatchOperand_ParseFail; |
| 3451 | } |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3452 | EndLoc = Parser.getTok().getEndLoc(); |
Jim Grosbach | 7de7ab8 | 2011-12-21 01:19:23 +0000 | [diff] [blame] | 3453 | Parser.Lex(); // Eat the ']'. |
| 3454 | int64_t Val = CE->getValue(); |
| 3455 | |
| 3456 | // FIXME: Make this range check context sensitive for .8, .16, .32. |
| 3457 | if (Val < 0 || Val > 7) { |
| 3458 | Error(Parser.getTok().getLoc(), "lane index out of range"); |
| 3459 | return MatchOperand_ParseFail; |
| 3460 | } |
| 3461 | Index = Val; |
| 3462 | LaneKind = IndexedLane; |
| 3463 | return MatchOperand_Success; |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3464 | } |
| 3465 | LaneKind = NoLanes; |
| 3466 | return MatchOperand_Success; |
| 3467 | } |
| 3468 | |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3469 | // parse a vector register list |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 3470 | ARMAsmParser::OperandMatchResultTy |
| 3471 | ARMAsmParser::parseVectorList(OperandVector &Operands) { |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3472 | VectorLaneTy LaneKind; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3473 | unsigned LaneIndex; |
Jim Grosbach | 8d57923 | 2011-11-15 21:45:55 +0000 | [diff] [blame] | 3474 | SMLoc S = Parser.getTok().getLoc(); |
| 3475 | // As an extension (to match gas), support a plain D register or Q register |
| 3476 | // (without encosing curly braces) as a single or double entry list, |
| 3477 | // respectively. |
| 3478 | if (Parser.getTok().is(AsmToken::Identifier)) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3479 | SMLoc E = Parser.getTok().getEndLoc(); |
Jim Grosbach | 8d57923 | 2011-11-15 21:45:55 +0000 | [diff] [blame] | 3480 | int Reg = tryParseRegister(); |
| 3481 | if (Reg == -1) |
| 3482 | return MatchOperand_NoMatch; |
Jim Grosbach | 8d57923 | 2011-11-15 21:45:55 +0000 | [diff] [blame] | 3483 | if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3484 | OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E); |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3485 | if (Res != MatchOperand_Success) |
| 3486 | return Res; |
| 3487 | switch (LaneKind) { |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3488 | case NoLanes: |
Jim Grosbach | 2f50e92 | 2011-12-15 21:44:33 +0000 | [diff] [blame] | 3489 | Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E)); |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3490 | break; |
| 3491 | case AllLanes: |
Jim Grosbach | c5af54e | 2011-12-21 00:38:54 +0000 | [diff] [blame] | 3492 | Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false, |
| 3493 | S, E)); |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3494 | break; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3495 | case IndexedLane: |
| 3496 | Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1, |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 3497 | LaneIndex, |
| 3498 | false, S, E)); |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3499 | break; |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3500 | } |
Jim Grosbach | 8d57923 | 2011-11-15 21:45:55 +0000 | [diff] [blame] | 3501 | return MatchOperand_Success; |
| 3502 | } |
| 3503 | if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) { |
| 3504 | Reg = getDRegFromQReg(Reg); |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3505 | OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E); |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3506 | if (Res != MatchOperand_Success) |
| 3507 | return Res; |
| 3508 | switch (LaneKind) { |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3509 | case NoLanes: |
Jim Grosbach | c988e0c | 2012-03-05 19:33:30 +0000 | [diff] [blame] | 3510 | Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0, |
Jim Grosbach | 13a292c | 2012-03-06 22:01:44 +0000 | [diff] [blame] | 3511 | &ARMMCRegisterClasses[ARM::DPairRegClassID]); |
Jim Grosbach | 2f50e92 | 2011-12-15 21:44:33 +0000 | [diff] [blame] | 3512 | Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E)); |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3513 | break; |
| 3514 | case AllLanes: |
Jim Grosbach | 13a292c | 2012-03-06 22:01:44 +0000 | [diff] [blame] | 3515 | Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0, |
| 3516 | &ARMMCRegisterClasses[ARM::DPairRegClassID]); |
Jim Grosbach | c5af54e | 2011-12-21 00:38:54 +0000 | [diff] [blame] | 3517 | Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false, |
| 3518 | S, E)); |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3519 | break; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3520 | case IndexedLane: |
| 3521 | Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2, |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 3522 | LaneIndex, |
| 3523 | false, S, E)); |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3524 | break; |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3525 | } |
Jim Grosbach | 8d57923 | 2011-11-15 21:45:55 +0000 | [diff] [blame] | 3526 | return MatchOperand_Success; |
| 3527 | } |
| 3528 | Error(S, "vector register expected"); |
| 3529 | return MatchOperand_ParseFail; |
| 3530 | } |
| 3531 | |
| 3532 | if (Parser.getTok().isNot(AsmToken::LCurly)) |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3533 | return MatchOperand_NoMatch; |
| 3534 | |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3535 | Parser.Lex(); // Eat '{' token. |
| 3536 | SMLoc RegLoc = Parser.getTok().getLoc(); |
| 3537 | |
| 3538 | int Reg = tryParseRegister(); |
| 3539 | if (Reg == -1) { |
| 3540 | Error(RegLoc, "register expected"); |
| 3541 | return MatchOperand_ParseFail; |
| 3542 | } |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3543 | unsigned Count = 1; |
Jim Grosbach | c2f16a3 | 2011-12-15 21:54:55 +0000 | [diff] [blame] | 3544 | int Spacing = 0; |
Jim Grosbach | 080a499 | 2011-10-28 00:06:50 +0000 | [diff] [blame] | 3545 | unsigned FirstReg = Reg; |
| 3546 | // The list is of D registers, but we also allow Q regs and just interpret |
| 3547 | // them as the two D sub-registers. |
| 3548 | if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) { |
| 3549 | FirstReg = Reg = getDRegFromQReg(Reg); |
Jim Grosbach | 2f50e92 | 2011-12-15 21:44:33 +0000 | [diff] [blame] | 3550 | Spacing = 1; // double-spacing requires explicit D registers, otherwise |
| 3551 | // it's ambiguous with four-register single spaced. |
Jim Grosbach | 080a499 | 2011-10-28 00:06:50 +0000 | [diff] [blame] | 3552 | ++Reg; |
| 3553 | ++Count; |
| 3554 | } |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3555 | |
| 3556 | SMLoc E; |
| 3557 | if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success) |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3558 | return MatchOperand_ParseFail; |
Jim Grosbach | 080a499 | 2011-10-28 00:06:50 +0000 | [diff] [blame] | 3559 | |
Jim Grosbach | e891fe8 | 2011-11-15 23:19:15 +0000 | [diff] [blame] | 3560 | while (Parser.getTok().is(AsmToken::Comma) || |
| 3561 | Parser.getTok().is(AsmToken::Minus)) { |
| 3562 | if (Parser.getTok().is(AsmToken::Minus)) { |
Jim Grosbach | 2f50e92 | 2011-12-15 21:44:33 +0000 | [diff] [blame] | 3563 | if (!Spacing) |
| 3564 | Spacing = 1; // Register range implies a single spaced list. |
| 3565 | else if (Spacing == 2) { |
| 3566 | Error(Parser.getTok().getLoc(), |
| 3567 | "sequential registers in double spaced list"); |
| 3568 | return MatchOperand_ParseFail; |
| 3569 | } |
Jim Grosbach | e891fe8 | 2011-11-15 23:19:15 +0000 | [diff] [blame] | 3570 | Parser.Lex(); // Eat the minus. |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3571 | SMLoc AfterMinusLoc = Parser.getTok().getLoc(); |
Jim Grosbach | e891fe8 | 2011-11-15 23:19:15 +0000 | [diff] [blame] | 3572 | int EndReg = tryParseRegister(); |
| 3573 | if (EndReg == -1) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3574 | Error(AfterMinusLoc, "register expected"); |
Jim Grosbach | e891fe8 | 2011-11-15 23:19:15 +0000 | [diff] [blame] | 3575 | return MatchOperand_ParseFail; |
| 3576 | } |
| 3577 | // Allow Q regs and just interpret them as the two D sub-registers. |
| 3578 | if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg)) |
| 3579 | EndReg = getDRegFromQReg(EndReg) + 1; |
| 3580 | // If the register is the same as the start reg, there's nothing |
| 3581 | // more to do. |
| 3582 | if (Reg == EndReg) |
| 3583 | continue; |
| 3584 | // The register must be in the same register class as the first. |
| 3585 | if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3586 | Error(AfterMinusLoc, "invalid register in register list"); |
Jim Grosbach | e891fe8 | 2011-11-15 23:19:15 +0000 | [diff] [blame] | 3587 | return MatchOperand_ParseFail; |
| 3588 | } |
| 3589 | // Ranges must go from low to high. |
| 3590 | if (Reg > EndReg) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3591 | Error(AfterMinusLoc, "bad range in register list"); |
Jim Grosbach | e891fe8 | 2011-11-15 23:19:15 +0000 | [diff] [blame] | 3592 | return MatchOperand_ParseFail; |
| 3593 | } |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3594 | // Parse the lane specifier if present. |
| 3595 | VectorLaneTy NextLaneKind; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3596 | unsigned NextLaneIndex; |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3597 | if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != |
| 3598 | MatchOperand_Success) |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3599 | return MatchOperand_ParseFail; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3600 | if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3601 | Error(AfterMinusLoc, "mismatched lane index in register list"); |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3602 | return MatchOperand_ParseFail; |
| 3603 | } |
Jim Grosbach | e891fe8 | 2011-11-15 23:19:15 +0000 | [diff] [blame] | 3604 | |
| 3605 | // Add all the registers in the range to the register list. |
| 3606 | Count += EndReg - Reg; |
| 3607 | Reg = EndReg; |
| 3608 | continue; |
| 3609 | } |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3610 | Parser.Lex(); // Eat the comma. |
| 3611 | RegLoc = Parser.getTok().getLoc(); |
| 3612 | int OldReg = Reg; |
| 3613 | Reg = tryParseRegister(); |
| 3614 | if (Reg == -1) { |
| 3615 | Error(RegLoc, "register expected"); |
| 3616 | return MatchOperand_ParseFail; |
| 3617 | } |
Jim Grosbach | 080a499 | 2011-10-28 00:06:50 +0000 | [diff] [blame] | 3618 | // vector register lists must be contiguous. |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3619 | // It's OK to use the enumeration values directly here rather, as the |
| 3620 | // VFP register classes have the enum sorted properly. |
Jim Grosbach | 080a499 | 2011-10-28 00:06:50 +0000 | [diff] [blame] | 3621 | // |
| 3622 | // The list is of D registers, but we also allow Q regs and just interpret |
| 3623 | // them as the two D sub-registers. |
| 3624 | if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) { |
Jim Grosbach | 2f50e92 | 2011-12-15 21:44:33 +0000 | [diff] [blame] | 3625 | if (!Spacing) |
| 3626 | Spacing = 1; // Register range implies a single spaced list. |
| 3627 | else if (Spacing == 2) { |
| 3628 | Error(RegLoc, |
| 3629 | "invalid register in double-spaced list (must be 'D' register')"); |
| 3630 | return MatchOperand_ParseFail; |
| 3631 | } |
Jim Grosbach | 080a499 | 2011-10-28 00:06:50 +0000 | [diff] [blame] | 3632 | Reg = getDRegFromQReg(Reg); |
| 3633 | if (Reg != OldReg + 1) { |
| 3634 | Error(RegLoc, "non-contiguous register range"); |
| 3635 | return MatchOperand_ParseFail; |
| 3636 | } |
| 3637 | ++Reg; |
| 3638 | Count += 2; |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3639 | // Parse the lane specifier if present. |
| 3640 | VectorLaneTy NextLaneKind; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3641 | unsigned NextLaneIndex; |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3642 | SMLoc LaneLoc = Parser.getTok().getLoc(); |
| 3643 | if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != |
| 3644 | MatchOperand_Success) |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3645 | return MatchOperand_ParseFail; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3646 | if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3647 | Error(LaneLoc, "mismatched lane index in register list"); |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3648 | return MatchOperand_ParseFail; |
| 3649 | } |
Jim Grosbach | 080a499 | 2011-10-28 00:06:50 +0000 | [diff] [blame] | 3650 | continue; |
| 3651 | } |
Jim Grosbach | 2f50e92 | 2011-12-15 21:44:33 +0000 | [diff] [blame] | 3652 | // Normal D register. |
| 3653 | // Figure out the register spacing (single or double) of the list if |
| 3654 | // we don't know it already. |
| 3655 | if (!Spacing) |
| 3656 | Spacing = 1 + (Reg == OldReg + 2); |
| 3657 | |
| 3658 | // Just check that it's contiguous and keep going. |
| 3659 | if (Reg != OldReg + Spacing) { |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3660 | Error(RegLoc, "non-contiguous register range"); |
| 3661 | return MatchOperand_ParseFail; |
| 3662 | } |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3663 | ++Count; |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3664 | // Parse the lane specifier if present. |
| 3665 | VectorLaneTy NextLaneKind; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3666 | unsigned NextLaneIndex; |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3667 | SMLoc EndLoc = Parser.getTok().getLoc(); |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3668 | if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success) |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3669 | return MatchOperand_ParseFail; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3670 | if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) { |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3671 | Error(EndLoc, "mismatched lane index in register list"); |
| 3672 | return MatchOperand_ParseFail; |
| 3673 | } |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3674 | } |
| 3675 | |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3676 | if (Parser.getTok().isNot(AsmToken::RCurly)) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3677 | Error(Parser.getTok().getLoc(), "'}' expected"); |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3678 | return MatchOperand_ParseFail; |
| 3679 | } |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3680 | E = Parser.getTok().getEndLoc(); |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3681 | Parser.Lex(); // Eat '}' token. |
| 3682 | |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3683 | switch (LaneKind) { |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3684 | case NoLanes: |
Jim Grosbach | 13a292c | 2012-03-06 22:01:44 +0000 | [diff] [blame] | 3685 | // Two-register operands have been converted to the |
Jim Grosbach | e5307f9 | 2012-03-05 21:43:40 +0000 | [diff] [blame] | 3686 | // composite register classes. |
| 3687 | if (Count == 2) { |
| 3688 | const MCRegisterClass *RC = (Spacing == 1) ? |
| 3689 | &ARMMCRegisterClasses[ARM::DPairRegClassID] : |
| 3690 | &ARMMCRegisterClasses[ARM::DPairSpcRegClassID]; |
| 3691 | FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC); |
| 3692 | } |
Jim Grosbach | c988e0c | 2012-03-05 19:33:30 +0000 | [diff] [blame] | 3693 | |
Jim Grosbach | 2f50e92 | 2011-12-15 21:44:33 +0000 | [diff] [blame] | 3694 | Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count, |
| 3695 | (Spacing == 2), S, E)); |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3696 | break; |
| 3697 | case AllLanes: |
Jim Grosbach | 13a292c | 2012-03-06 22:01:44 +0000 | [diff] [blame] | 3698 | // Two-register operands have been converted to the |
| 3699 | // composite register classes. |
Jim Grosbach | ed428bc | 2012-03-06 23:10:38 +0000 | [diff] [blame] | 3700 | if (Count == 2) { |
| 3701 | const MCRegisterClass *RC = (Spacing == 1) ? |
| 3702 | &ARMMCRegisterClasses[ARM::DPairRegClassID] : |
| 3703 | &ARMMCRegisterClasses[ARM::DPairSpcRegClassID]; |
Jim Grosbach | 13a292c | 2012-03-06 22:01:44 +0000 | [diff] [blame] | 3704 | FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC); |
| 3705 | } |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3706 | Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count, |
Jim Grosbach | c5af54e | 2011-12-21 00:38:54 +0000 | [diff] [blame] | 3707 | (Spacing == 2), |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3708 | S, E)); |
| 3709 | break; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3710 | case IndexedLane: |
| 3711 | Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count, |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 3712 | LaneIndex, |
| 3713 | (Spacing == 2), |
| 3714 | S, E)); |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3715 | break; |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3716 | } |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3717 | return MatchOperand_Success; |
| 3718 | } |
| 3719 | |
Jim Grosbach | 2d6ef44 | 2011-07-25 20:14:50 +0000 | [diff] [blame] | 3720 | /// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 3721 | ARMAsmParser::OperandMatchResultTy |
| 3722 | ARMAsmParser::parseMemBarrierOptOperand(OperandVector &Operands) { |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 3723 | SMLoc S = Parser.getTok().getLoc(); |
| 3724 | const AsmToken &Tok = Parser.getTok(); |
Jiangning Liu | 288e1af | 2012-08-02 08:21:27 +0000 | [diff] [blame] | 3725 | unsigned Opt; |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 3726 | |
Jiangning Liu | 288e1af | 2012-08-02 08:21:27 +0000 | [diff] [blame] | 3727 | if (Tok.is(AsmToken::Identifier)) { |
| 3728 | StringRef OptStr = Tok.getString(); |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 3729 | |
Jiangning Liu | 288e1af | 2012-08-02 08:21:27 +0000 | [diff] [blame] | 3730 | Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower()) |
| 3731 | .Case("sy", ARM_MB::SY) |
| 3732 | .Case("st", ARM_MB::ST) |
Joey Gouly | 926d3f5 | 2013-09-05 15:35:24 +0000 | [diff] [blame] | 3733 | .Case("ld", ARM_MB::LD) |
Jiangning Liu | 288e1af | 2012-08-02 08:21:27 +0000 | [diff] [blame] | 3734 | .Case("sh", ARM_MB::ISH) |
| 3735 | .Case("ish", ARM_MB::ISH) |
| 3736 | .Case("shst", ARM_MB::ISHST) |
| 3737 | .Case("ishst", ARM_MB::ISHST) |
Joey Gouly | 926d3f5 | 2013-09-05 15:35:24 +0000 | [diff] [blame] | 3738 | .Case("ishld", ARM_MB::ISHLD) |
Jiangning Liu | 288e1af | 2012-08-02 08:21:27 +0000 | [diff] [blame] | 3739 | .Case("nsh", ARM_MB::NSH) |
| 3740 | .Case("un", ARM_MB::NSH) |
| 3741 | .Case("nshst", ARM_MB::NSHST) |
Joey Gouly | 926d3f5 | 2013-09-05 15:35:24 +0000 | [diff] [blame] | 3742 | .Case("nshld", ARM_MB::NSHLD) |
Jiangning Liu | 288e1af | 2012-08-02 08:21:27 +0000 | [diff] [blame] | 3743 | .Case("unst", ARM_MB::NSHST) |
| 3744 | .Case("osh", ARM_MB::OSH) |
| 3745 | .Case("oshst", ARM_MB::OSHST) |
Joey Gouly | 926d3f5 | 2013-09-05 15:35:24 +0000 | [diff] [blame] | 3746 | .Case("oshld", ARM_MB::OSHLD) |
Jiangning Liu | 288e1af | 2012-08-02 08:21:27 +0000 | [diff] [blame] | 3747 | .Default(~0U); |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 3748 | |
Joey Gouly | 926d3f5 | 2013-09-05 15:35:24 +0000 | [diff] [blame] | 3749 | // ishld, oshld, nshld and ld are only available from ARMv8. |
| 3750 | if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD || |
| 3751 | Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD)) |
| 3752 | Opt = ~0U; |
| 3753 | |
Jiangning Liu | 288e1af | 2012-08-02 08:21:27 +0000 | [diff] [blame] | 3754 | if (Opt == ~0U) |
| 3755 | return MatchOperand_NoMatch; |
| 3756 | |
| 3757 | Parser.Lex(); // Eat identifier token. |
| 3758 | } else if (Tok.is(AsmToken::Hash) || |
| 3759 | Tok.is(AsmToken::Dollar) || |
| 3760 | Tok.is(AsmToken::Integer)) { |
| 3761 | if (Parser.getTok().isNot(AsmToken::Integer)) |
Amaury de la Vieuville | bac917f | 2013-06-10 14:17:15 +0000 | [diff] [blame] | 3762 | Parser.Lex(); // Eat '#' or '$'. |
Jiangning Liu | 288e1af | 2012-08-02 08:21:27 +0000 | [diff] [blame] | 3763 | SMLoc Loc = Parser.getTok().getLoc(); |
| 3764 | |
| 3765 | const MCExpr *MemBarrierID; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 3766 | if (getParser().parseExpression(MemBarrierID)) { |
Jiangning Liu | 288e1af | 2012-08-02 08:21:27 +0000 | [diff] [blame] | 3767 | Error(Loc, "illegal expression"); |
| 3768 | return MatchOperand_ParseFail; |
| 3769 | } |
Saleem Abdulrasool | 4ab6e73 | 2014-02-23 17:45:36 +0000 | [diff] [blame] | 3770 | |
Jiangning Liu | 288e1af | 2012-08-02 08:21:27 +0000 | [diff] [blame] | 3771 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID); |
| 3772 | if (!CE) { |
| 3773 | Error(Loc, "constant expression expected"); |
| 3774 | return MatchOperand_ParseFail; |
| 3775 | } |
| 3776 | |
| 3777 | int Val = CE->getValue(); |
| 3778 | if (Val & ~0xf) { |
| 3779 | Error(Loc, "immediate value out of range"); |
| 3780 | return MatchOperand_ParseFail; |
| 3781 | } |
| 3782 | |
| 3783 | Opt = ARM_MB::RESERVED_0 + Val; |
| 3784 | } else |
| 3785 | return MatchOperand_ParseFail; |
| 3786 | |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 3787 | Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S)); |
Jim Grosbach | 861e49c | 2011-02-12 01:34:40 +0000 | [diff] [blame] | 3788 | return MatchOperand_Success; |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 3789 | } |
| 3790 | |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 3791 | /// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 3792 | ARMAsmParser::OperandMatchResultTy |
| 3793 | ARMAsmParser::parseInstSyncBarrierOptOperand(OperandVector &Operands) { |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 3794 | SMLoc S = Parser.getTok().getLoc(); |
| 3795 | const AsmToken &Tok = Parser.getTok(); |
| 3796 | unsigned Opt; |
| 3797 | |
| 3798 | if (Tok.is(AsmToken::Identifier)) { |
| 3799 | StringRef OptStr = Tok.getString(); |
| 3800 | |
Benjamin Kramer | 3e9237a | 2013-11-09 22:48:13 +0000 | [diff] [blame] | 3801 | if (OptStr.equals_lower("sy")) |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 3802 | Opt = ARM_ISB::SY; |
| 3803 | else |
| 3804 | return MatchOperand_NoMatch; |
| 3805 | |
| 3806 | Parser.Lex(); // Eat identifier token. |
| 3807 | } else if (Tok.is(AsmToken::Hash) || |
| 3808 | Tok.is(AsmToken::Dollar) || |
| 3809 | Tok.is(AsmToken::Integer)) { |
| 3810 | if (Parser.getTok().isNot(AsmToken::Integer)) |
Amaury de la Vieuville | bac917f | 2013-06-10 14:17:15 +0000 | [diff] [blame] | 3811 | Parser.Lex(); // Eat '#' or '$'. |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 3812 | SMLoc Loc = Parser.getTok().getLoc(); |
| 3813 | |
| 3814 | const MCExpr *ISBarrierID; |
| 3815 | if (getParser().parseExpression(ISBarrierID)) { |
| 3816 | Error(Loc, "illegal expression"); |
| 3817 | return MatchOperand_ParseFail; |
| 3818 | } |
| 3819 | |
| 3820 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID); |
| 3821 | if (!CE) { |
| 3822 | Error(Loc, "constant expression expected"); |
| 3823 | return MatchOperand_ParseFail; |
| 3824 | } |
| 3825 | |
| 3826 | int Val = CE->getValue(); |
| 3827 | if (Val & ~0xf) { |
| 3828 | Error(Loc, "immediate value out of range"); |
| 3829 | return MatchOperand_ParseFail; |
| 3830 | } |
| 3831 | |
| 3832 | Opt = ARM_ISB::RESERVED_0 + Val; |
| 3833 | } else |
| 3834 | return MatchOperand_ParseFail; |
| 3835 | |
| 3836 | Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt( |
| 3837 | (ARM_ISB::InstSyncBOpt)Opt, S)); |
| 3838 | return MatchOperand_Success; |
| 3839 | } |
| 3840 | |
| 3841 | |
Jim Grosbach | 2d6ef44 | 2011-07-25 20:14:50 +0000 | [diff] [blame] | 3842 | /// parseProcIFlagsOperand - Try to parse iflags from CPS instruction. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 3843 | ARMAsmParser::OperandMatchResultTy |
| 3844 | ARMAsmParser::parseProcIFlagsOperand(OperandVector &Operands) { |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 3845 | SMLoc S = Parser.getTok().getLoc(); |
| 3846 | const AsmToken &Tok = Parser.getTok(); |
Richard Barton | b0ec375 | 2012-06-14 10:48:04 +0000 | [diff] [blame] | 3847 | if (!Tok.is(AsmToken::Identifier)) |
| 3848 | return MatchOperand_NoMatch; |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 3849 | StringRef IFlagsStr = Tok.getString(); |
| 3850 | |
Owen Anderson | 10c5b12 | 2011-10-05 17:16:40 +0000 | [diff] [blame] | 3851 | // An iflags string of "none" is interpreted to mean that none of the AIF |
| 3852 | // bits are set. Not a terribly useful instruction, but a valid encoding. |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 3853 | unsigned IFlags = 0; |
Owen Anderson | 10c5b12 | 2011-10-05 17:16:40 +0000 | [diff] [blame] | 3854 | if (IFlagsStr != "none") { |
| 3855 | for (int i = 0, e = IFlagsStr.size(); i != e; ++i) { |
| 3856 | unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1)) |
| 3857 | .Case("a", ARM_PROC::A) |
| 3858 | .Case("i", ARM_PROC::I) |
| 3859 | .Case("f", ARM_PROC::F) |
| 3860 | .Default(~0U); |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 3861 | |
Owen Anderson | 10c5b12 | 2011-10-05 17:16:40 +0000 | [diff] [blame] | 3862 | // If some specific iflag is already set, it means that some letter is |
| 3863 | // present more than once, this is not acceptable. |
| 3864 | if (Flag == ~0U || (IFlags & Flag)) |
| 3865 | return MatchOperand_NoMatch; |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 3866 | |
Owen Anderson | 10c5b12 | 2011-10-05 17:16:40 +0000 | [diff] [blame] | 3867 | IFlags |= Flag; |
| 3868 | } |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 3869 | } |
| 3870 | |
| 3871 | Parser.Lex(); // Eat identifier token. |
| 3872 | Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S)); |
| 3873 | return MatchOperand_Success; |
| 3874 | } |
| 3875 | |
Jim Grosbach | 2d6ef44 | 2011-07-25 20:14:50 +0000 | [diff] [blame] | 3876 | /// parseMSRMaskOperand - Try to parse mask flags from MSR instruction. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 3877 | ARMAsmParser::OperandMatchResultTy |
| 3878 | ARMAsmParser::parseMSRMaskOperand(OperandVector &Operands) { |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 3879 | SMLoc S = Parser.getTok().getLoc(); |
| 3880 | const AsmToken &Tok = Parser.getTok(); |
Craig Topper | a004b0d | 2012-10-09 04:55:28 +0000 | [diff] [blame] | 3881 | if (!Tok.is(AsmToken::Identifier)) |
| 3882 | return MatchOperand_NoMatch; |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 3883 | StringRef Mask = Tok.getString(); |
| 3884 | |
James Molloy | 21efa7d | 2011-09-28 14:21:38 +0000 | [diff] [blame] | 3885 | if (isMClass()) { |
| 3886 | // See ARMv6-M 10.1.1 |
Jim Grosbach | d28888d | 2012-03-15 21:34:14 +0000 | [diff] [blame] | 3887 | std::string Name = Mask.lower(); |
| 3888 | unsigned FlagsVal = StringSwitch<unsigned>(Name) |
Kevin Enderby | f1b225d | 2012-05-17 22:18:01 +0000 | [diff] [blame] | 3889 | // Note: in the documentation: |
| 3890 | // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias |
| 3891 | // for MSR APSR_nzcvq. |
| 3892 | // but we do make it an alias here. This is so to get the "mask encoding" |
| 3893 | // bits correct on MSR APSR writes. |
| 3894 | // |
| 3895 | // FIXME: Note the 0xc00 "mask encoding" bits version of the registers |
| 3896 | // should really only be allowed when writing a special register. Note |
| 3897 | // they get dropped in the MRS instruction reading a special register as |
| 3898 | // the SYSm field is only 8 bits. |
| 3899 | // |
| 3900 | // FIXME: the _g and _nzcvqg versions are only allowed if the processor |
| 3901 | // includes the DSP extension but that is not checked. |
| 3902 | .Case("apsr", 0x800) |
| 3903 | .Case("apsr_nzcvq", 0x800) |
| 3904 | .Case("apsr_g", 0x400) |
| 3905 | .Case("apsr_nzcvqg", 0xc00) |
| 3906 | .Case("iapsr", 0x801) |
| 3907 | .Case("iapsr_nzcvq", 0x801) |
| 3908 | .Case("iapsr_g", 0x401) |
| 3909 | .Case("iapsr_nzcvqg", 0xc01) |
| 3910 | .Case("eapsr", 0x802) |
| 3911 | .Case("eapsr_nzcvq", 0x802) |
| 3912 | .Case("eapsr_g", 0x402) |
| 3913 | .Case("eapsr_nzcvqg", 0xc02) |
| 3914 | .Case("xpsr", 0x803) |
| 3915 | .Case("xpsr_nzcvq", 0x803) |
| 3916 | .Case("xpsr_g", 0x403) |
| 3917 | .Case("xpsr_nzcvqg", 0xc03) |
Kevin Enderby | 6c7279e | 2012-06-15 22:14:44 +0000 | [diff] [blame] | 3918 | .Case("ipsr", 0x805) |
| 3919 | .Case("epsr", 0x806) |
| 3920 | .Case("iepsr", 0x807) |
| 3921 | .Case("msp", 0x808) |
| 3922 | .Case("psp", 0x809) |
| 3923 | .Case("primask", 0x810) |
| 3924 | .Case("basepri", 0x811) |
| 3925 | .Case("basepri_max", 0x812) |
| 3926 | .Case("faultmask", 0x813) |
| 3927 | .Case("control", 0x814) |
James Molloy | 21efa7d | 2011-09-28 14:21:38 +0000 | [diff] [blame] | 3928 | .Default(~0U); |
Jim Grosbach | 3794d82 | 2011-12-22 17:17:10 +0000 | [diff] [blame] | 3929 | |
James Molloy | 21efa7d | 2011-09-28 14:21:38 +0000 | [diff] [blame] | 3930 | if (FlagsVal == ~0U) |
| 3931 | return MatchOperand_NoMatch; |
| 3932 | |
Kevin Enderby | 6c7279e | 2012-06-15 22:14:44 +0000 | [diff] [blame] | 3933 | if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813) |
James Molloy | 21efa7d | 2011-09-28 14:21:38 +0000 | [diff] [blame] | 3934 | // basepri, basepri_max and faultmask only valid for V7m. |
| 3935 | return MatchOperand_NoMatch; |
Jim Grosbach | 3794d82 | 2011-12-22 17:17:10 +0000 | [diff] [blame] | 3936 | |
James Molloy | 21efa7d | 2011-09-28 14:21:38 +0000 | [diff] [blame] | 3937 | Parser.Lex(); // Eat identifier token. |
| 3938 | Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S)); |
| 3939 | return MatchOperand_Success; |
| 3940 | } |
| 3941 | |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 3942 | // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf" |
| 3943 | size_t Start = 0, Next = Mask.find('_'); |
| 3944 | StringRef Flags = ""; |
Benjamin Kramer | 20baffb | 2011-11-06 20:37:06 +0000 | [diff] [blame] | 3945 | std::string SpecReg = Mask.slice(Start, Next).lower(); |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 3946 | if (Next != StringRef::npos) |
| 3947 | Flags = Mask.slice(Next+1, Mask.size()); |
| 3948 | |
| 3949 | // FlagsVal contains the complete mask: |
| 3950 | // 3-0: Mask |
| 3951 | // 4: Special Reg (cpsr, apsr => 0; spsr => 1) |
| 3952 | unsigned FlagsVal = 0; |
| 3953 | |
| 3954 | if (SpecReg == "apsr") { |
| 3955 | FlagsVal = StringSwitch<unsigned>(Flags) |
Jim Grosbach | d25c2cd | 2011-07-19 22:45:10 +0000 | [diff] [blame] | 3956 | .Case("nzcvq", 0x8) // same as CPSR_f |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 3957 | .Case("g", 0x4) // same as CPSR_s |
| 3958 | .Case("nzcvqg", 0xc) // same as CPSR_fs |
| 3959 | .Default(~0U); |
| 3960 | |
Joerg Sonnenberger | 740467a | 2011-02-19 00:43:45 +0000 | [diff] [blame] | 3961 | if (FlagsVal == ~0U) { |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 3962 | if (!Flags.empty()) |
| 3963 | return MatchOperand_NoMatch; |
| 3964 | else |
Jim Grosbach | 0ecd395 | 2011-09-14 20:03:46 +0000 | [diff] [blame] | 3965 | FlagsVal = 8; // No flag |
Joerg Sonnenberger | 740467a | 2011-02-19 00:43:45 +0000 | [diff] [blame] | 3966 | } |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 3967 | } else if (SpecReg == "cpsr" || SpecReg == "spsr") { |
Jim Grosbach | 3d00eec | 2012-04-05 03:17:53 +0000 | [diff] [blame] | 3968 | // cpsr_all is an alias for cpsr_fc, as is plain cpsr. |
| 3969 | if (Flags == "all" || Flags == "") |
Bruno Cardoso Lopes | 5445213 | 2011-05-25 00:35:03 +0000 | [diff] [blame] | 3970 | Flags = "fc"; |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 3971 | for (int i = 0, e = Flags.size(); i != e; ++i) { |
| 3972 | unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1)) |
| 3973 | .Case("c", 1) |
| 3974 | .Case("x", 2) |
| 3975 | .Case("s", 4) |
| 3976 | .Case("f", 8) |
| 3977 | .Default(~0U); |
| 3978 | |
| 3979 | // If some specific flag is already set, it means that some letter is |
| 3980 | // present more than once, this is not acceptable. |
| 3981 | if (FlagsVal == ~0U || (FlagsVal & Flag)) |
| 3982 | return MatchOperand_NoMatch; |
| 3983 | FlagsVal |= Flag; |
| 3984 | } |
| 3985 | } else // No match for special register. |
| 3986 | return MatchOperand_NoMatch; |
| 3987 | |
Owen Anderson | 03a173e | 2011-10-21 18:43:28 +0000 | [diff] [blame] | 3988 | // Special register without flags is NOT equivalent to "fc" flags. |
| 3989 | // NOTE: This is a divergence from gas' behavior. Uncommenting the following |
| 3990 | // two lines would enable gas compatibility at the expense of breaking |
| 3991 | // round-tripping. |
| 3992 | // |
| 3993 | // if (!FlagsVal) |
| 3994 | // FlagsVal = 0x9; |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 3995 | |
| 3996 | // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1) |
| 3997 | if (SpecReg == "spsr") |
| 3998 | FlagsVal |= 16; |
| 3999 | |
| 4000 | Parser.Lex(); // Eat identifier token. |
| 4001 | Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S)); |
| 4002 | return MatchOperand_Success; |
| 4003 | } |
| 4004 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4005 | ARMAsmParser::OperandMatchResultTy |
| 4006 | ARMAsmParser::parsePKHImm(OperandVector &Operands, StringRef Op, int Low, |
| 4007 | int High) { |
Jim Grosbach | 27c1e25 | 2011-07-21 17:23:04 +0000 | [diff] [blame] | 4008 | const AsmToken &Tok = Parser.getTok(); |
| 4009 | if (Tok.isNot(AsmToken::Identifier)) { |
| 4010 | Error(Parser.getTok().getLoc(), Op + " operand expected."); |
| 4011 | return MatchOperand_ParseFail; |
| 4012 | } |
| 4013 | StringRef ShiftName = Tok.getString(); |
Benjamin Kramer | 20baffb | 2011-11-06 20:37:06 +0000 | [diff] [blame] | 4014 | std::string LowerOp = Op.lower(); |
| 4015 | std::string UpperOp = Op.upper(); |
Jim Grosbach | 27c1e25 | 2011-07-21 17:23:04 +0000 | [diff] [blame] | 4016 | if (ShiftName != LowerOp && ShiftName != UpperOp) { |
| 4017 | Error(Parser.getTok().getLoc(), Op + " operand expected."); |
| 4018 | return MatchOperand_ParseFail; |
| 4019 | } |
| 4020 | Parser.Lex(); // Eat shift type token. |
| 4021 | |
| 4022 | // There must be a '#' and a shift amount. |
Jim Grosbach | ef70e9b | 2011-12-09 22:25:03 +0000 | [diff] [blame] | 4023 | if (Parser.getTok().isNot(AsmToken::Hash) && |
| 4024 | Parser.getTok().isNot(AsmToken::Dollar)) { |
Jim Grosbach | 27c1e25 | 2011-07-21 17:23:04 +0000 | [diff] [blame] | 4025 | Error(Parser.getTok().getLoc(), "'#' expected"); |
| 4026 | return MatchOperand_ParseFail; |
| 4027 | } |
| 4028 | Parser.Lex(); // Eat hash token. |
| 4029 | |
| 4030 | const MCExpr *ShiftAmount; |
| 4031 | SMLoc Loc = Parser.getTok().getLoc(); |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4032 | SMLoc EndLoc; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 4033 | if (getParser().parseExpression(ShiftAmount, EndLoc)) { |
Jim Grosbach | 27c1e25 | 2011-07-21 17:23:04 +0000 | [diff] [blame] | 4034 | Error(Loc, "illegal expression"); |
| 4035 | return MatchOperand_ParseFail; |
| 4036 | } |
| 4037 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount); |
| 4038 | if (!CE) { |
| 4039 | Error(Loc, "constant expression expected"); |
| 4040 | return MatchOperand_ParseFail; |
| 4041 | } |
| 4042 | int Val = CE->getValue(); |
| 4043 | if (Val < Low || Val > High) { |
| 4044 | Error(Loc, "immediate value out of range"); |
| 4045 | return MatchOperand_ParseFail; |
| 4046 | } |
| 4047 | |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4048 | Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc)); |
Jim Grosbach | 27c1e25 | 2011-07-21 17:23:04 +0000 | [diff] [blame] | 4049 | |
| 4050 | return MatchOperand_Success; |
| 4051 | } |
| 4052 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4053 | ARMAsmParser::OperandMatchResultTy |
| 4054 | ARMAsmParser::parseSetEndImm(OperandVector &Operands) { |
Jim Grosbach | 0a54770 | 2011-07-22 17:44:50 +0000 | [diff] [blame] | 4055 | const AsmToken &Tok = Parser.getTok(); |
| 4056 | SMLoc S = Tok.getLoc(); |
| 4057 | if (Tok.isNot(AsmToken::Identifier)) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4058 | Error(S, "'be' or 'le' operand expected"); |
Jim Grosbach | 0a54770 | 2011-07-22 17:44:50 +0000 | [diff] [blame] | 4059 | return MatchOperand_ParseFail; |
| 4060 | } |
Tim Northover | 4d14144 | 2013-05-31 15:58:45 +0000 | [diff] [blame] | 4061 | int Val = StringSwitch<int>(Tok.getString().lower()) |
Jim Grosbach | 0a54770 | 2011-07-22 17:44:50 +0000 | [diff] [blame] | 4062 | .Case("be", 1) |
| 4063 | .Case("le", 0) |
| 4064 | .Default(-1); |
| 4065 | Parser.Lex(); // Eat the token. |
| 4066 | |
| 4067 | if (Val == -1) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4068 | Error(S, "'be' or 'le' operand expected"); |
Jim Grosbach | 0a54770 | 2011-07-22 17:44:50 +0000 | [diff] [blame] | 4069 | return MatchOperand_ParseFail; |
| 4070 | } |
| 4071 | Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val, |
| 4072 | getContext()), |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4073 | S, Tok.getEndLoc())); |
Jim Grosbach | 0a54770 | 2011-07-22 17:44:50 +0000 | [diff] [blame] | 4074 | return MatchOperand_Success; |
| 4075 | } |
| 4076 | |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 4077 | /// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT |
| 4078 | /// instructions. Legal values are: |
| 4079 | /// lsl #n 'n' in [0,31] |
| 4080 | /// asr #n 'n' in [1,32] |
| 4081 | /// n == 32 encoded as n == 0. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4082 | ARMAsmParser::OperandMatchResultTy |
| 4083 | ARMAsmParser::parseShifterImm(OperandVector &Operands) { |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 4084 | const AsmToken &Tok = Parser.getTok(); |
| 4085 | SMLoc S = Tok.getLoc(); |
| 4086 | if (Tok.isNot(AsmToken::Identifier)) { |
| 4087 | Error(S, "shift operator 'asr' or 'lsl' expected"); |
| 4088 | return MatchOperand_ParseFail; |
| 4089 | } |
| 4090 | StringRef ShiftName = Tok.getString(); |
| 4091 | bool isASR; |
| 4092 | if (ShiftName == "lsl" || ShiftName == "LSL") |
| 4093 | isASR = false; |
| 4094 | else if (ShiftName == "asr" || ShiftName == "ASR") |
| 4095 | isASR = true; |
| 4096 | else { |
| 4097 | Error(S, "shift operator 'asr' or 'lsl' expected"); |
| 4098 | return MatchOperand_ParseFail; |
| 4099 | } |
| 4100 | Parser.Lex(); // Eat the operator. |
| 4101 | |
| 4102 | // A '#' and a shift amount. |
Jim Grosbach | ef70e9b | 2011-12-09 22:25:03 +0000 | [diff] [blame] | 4103 | if (Parser.getTok().isNot(AsmToken::Hash) && |
| 4104 | Parser.getTok().isNot(AsmToken::Dollar)) { |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 4105 | Error(Parser.getTok().getLoc(), "'#' expected"); |
| 4106 | return MatchOperand_ParseFail; |
| 4107 | } |
| 4108 | Parser.Lex(); // Eat hash token. |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4109 | SMLoc ExLoc = Parser.getTok().getLoc(); |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 4110 | |
| 4111 | const MCExpr *ShiftAmount; |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4112 | SMLoc EndLoc; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 4113 | if (getParser().parseExpression(ShiftAmount, EndLoc)) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4114 | Error(ExLoc, "malformed shift expression"); |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 4115 | return MatchOperand_ParseFail; |
| 4116 | } |
| 4117 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount); |
| 4118 | if (!CE) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4119 | Error(ExLoc, "shift amount must be an immediate"); |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 4120 | return MatchOperand_ParseFail; |
| 4121 | } |
| 4122 | |
| 4123 | int64_t Val = CE->getValue(); |
| 4124 | if (isASR) { |
| 4125 | // Shift amount must be in [1,32] |
| 4126 | if (Val < 1 || Val > 32) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4127 | Error(ExLoc, "'asr' shift amount must be in range [1,32]"); |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 4128 | return MatchOperand_ParseFail; |
| 4129 | } |
Owen Anderson | f01e2de | 2011-09-26 21:06:22 +0000 | [diff] [blame] | 4130 | // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode. |
| 4131 | if (isThumb() && Val == 32) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4132 | Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode"); |
Owen Anderson | f01e2de | 2011-09-26 21:06:22 +0000 | [diff] [blame] | 4133 | return MatchOperand_ParseFail; |
| 4134 | } |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 4135 | if (Val == 32) Val = 0; |
| 4136 | } else { |
| 4137 | // Shift amount must be in [1,32] |
| 4138 | if (Val < 0 || Val > 31) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4139 | Error(ExLoc, "'lsr' shift amount must be in range [0,31]"); |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 4140 | return MatchOperand_ParseFail; |
| 4141 | } |
| 4142 | } |
| 4143 | |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4144 | Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc)); |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 4145 | |
| 4146 | return MatchOperand_Success; |
| 4147 | } |
| 4148 | |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 4149 | /// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family |
| 4150 | /// of instructions. Legal values are: |
| 4151 | /// ror #n 'n' in {0, 8, 16, 24} |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4152 | ARMAsmParser::OperandMatchResultTy |
| 4153 | ARMAsmParser::parseRotImm(OperandVector &Operands) { |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 4154 | const AsmToken &Tok = Parser.getTok(); |
| 4155 | SMLoc S = Tok.getLoc(); |
Jim Grosbach | 8221319 | 2011-09-19 20:29:33 +0000 | [diff] [blame] | 4156 | if (Tok.isNot(AsmToken::Identifier)) |
| 4157 | return MatchOperand_NoMatch; |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 4158 | StringRef ShiftName = Tok.getString(); |
Jim Grosbach | 8221319 | 2011-09-19 20:29:33 +0000 | [diff] [blame] | 4159 | if (ShiftName != "ror" && ShiftName != "ROR") |
| 4160 | return MatchOperand_NoMatch; |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 4161 | Parser.Lex(); // Eat the operator. |
| 4162 | |
| 4163 | // A '#' and a rotate amount. |
Jim Grosbach | ef70e9b | 2011-12-09 22:25:03 +0000 | [diff] [blame] | 4164 | if (Parser.getTok().isNot(AsmToken::Hash) && |
| 4165 | Parser.getTok().isNot(AsmToken::Dollar)) { |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 4166 | Error(Parser.getTok().getLoc(), "'#' expected"); |
| 4167 | return MatchOperand_ParseFail; |
| 4168 | } |
| 4169 | Parser.Lex(); // Eat hash token. |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4170 | SMLoc ExLoc = Parser.getTok().getLoc(); |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 4171 | |
| 4172 | const MCExpr *ShiftAmount; |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4173 | SMLoc EndLoc; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 4174 | if (getParser().parseExpression(ShiftAmount, EndLoc)) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4175 | Error(ExLoc, "malformed rotate expression"); |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 4176 | return MatchOperand_ParseFail; |
| 4177 | } |
| 4178 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount); |
| 4179 | if (!CE) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4180 | Error(ExLoc, "rotate amount must be an immediate"); |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 4181 | return MatchOperand_ParseFail; |
| 4182 | } |
| 4183 | |
| 4184 | int64_t Val = CE->getValue(); |
| 4185 | // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension) |
| 4186 | // normally, zero is represented in asm by omitting the rotate operand |
| 4187 | // entirely. |
| 4188 | if (Val != 8 && Val != 16 && Val != 24 && Val != 0) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4189 | Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24"); |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 4190 | return MatchOperand_ParseFail; |
| 4191 | } |
| 4192 | |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4193 | Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc)); |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 4194 | |
| 4195 | return MatchOperand_Success; |
| 4196 | } |
| 4197 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4198 | ARMAsmParser::OperandMatchResultTy |
| 4199 | ARMAsmParser::parseBitfield(OperandVector &Operands) { |
Jim Grosbach | 864b609 | 2011-07-28 21:34:26 +0000 | [diff] [blame] | 4200 | SMLoc S = Parser.getTok().getLoc(); |
| 4201 | // The bitfield descriptor is really two operands, the LSB and the width. |
Jim Grosbach | ef70e9b | 2011-12-09 22:25:03 +0000 | [diff] [blame] | 4202 | if (Parser.getTok().isNot(AsmToken::Hash) && |
| 4203 | Parser.getTok().isNot(AsmToken::Dollar)) { |
Jim Grosbach | 864b609 | 2011-07-28 21:34:26 +0000 | [diff] [blame] | 4204 | Error(Parser.getTok().getLoc(), "'#' expected"); |
| 4205 | return MatchOperand_ParseFail; |
| 4206 | } |
| 4207 | Parser.Lex(); // Eat hash token. |
| 4208 | |
| 4209 | const MCExpr *LSBExpr; |
| 4210 | SMLoc E = Parser.getTok().getLoc(); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 4211 | if (getParser().parseExpression(LSBExpr)) { |
Jim Grosbach | 864b609 | 2011-07-28 21:34:26 +0000 | [diff] [blame] | 4212 | Error(E, "malformed immediate expression"); |
| 4213 | return MatchOperand_ParseFail; |
| 4214 | } |
| 4215 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr); |
| 4216 | if (!CE) { |
| 4217 | Error(E, "'lsb' operand must be an immediate"); |
| 4218 | return MatchOperand_ParseFail; |
| 4219 | } |
| 4220 | |
| 4221 | int64_t LSB = CE->getValue(); |
| 4222 | // The LSB must be in the range [0,31] |
| 4223 | if (LSB < 0 || LSB > 31) { |
| 4224 | Error(E, "'lsb' operand must be in the range [0,31]"); |
| 4225 | return MatchOperand_ParseFail; |
| 4226 | } |
| 4227 | E = Parser.getTok().getLoc(); |
| 4228 | |
| 4229 | // Expect another immediate operand. |
| 4230 | if (Parser.getTok().isNot(AsmToken::Comma)) { |
| 4231 | Error(Parser.getTok().getLoc(), "too few operands"); |
| 4232 | return MatchOperand_ParseFail; |
| 4233 | } |
| 4234 | Parser.Lex(); // Eat hash token. |
Jim Grosbach | ef70e9b | 2011-12-09 22:25:03 +0000 | [diff] [blame] | 4235 | if (Parser.getTok().isNot(AsmToken::Hash) && |
| 4236 | Parser.getTok().isNot(AsmToken::Dollar)) { |
Jim Grosbach | 864b609 | 2011-07-28 21:34:26 +0000 | [diff] [blame] | 4237 | Error(Parser.getTok().getLoc(), "'#' expected"); |
| 4238 | return MatchOperand_ParseFail; |
| 4239 | } |
| 4240 | Parser.Lex(); // Eat hash token. |
| 4241 | |
| 4242 | const MCExpr *WidthExpr; |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4243 | SMLoc EndLoc; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 4244 | if (getParser().parseExpression(WidthExpr, EndLoc)) { |
Jim Grosbach | 864b609 | 2011-07-28 21:34:26 +0000 | [diff] [blame] | 4245 | Error(E, "malformed immediate expression"); |
| 4246 | return MatchOperand_ParseFail; |
| 4247 | } |
| 4248 | CE = dyn_cast<MCConstantExpr>(WidthExpr); |
| 4249 | if (!CE) { |
| 4250 | Error(E, "'width' operand must be an immediate"); |
| 4251 | return MatchOperand_ParseFail; |
| 4252 | } |
| 4253 | |
| 4254 | int64_t Width = CE->getValue(); |
| 4255 | // The LSB must be in the range [1,32-lsb] |
| 4256 | if (Width < 1 || Width > 32 - LSB) { |
| 4257 | Error(E, "'width' operand must be in the range [1,32-lsb]"); |
| 4258 | return MatchOperand_ParseFail; |
| 4259 | } |
Jim Grosbach | 864b609 | 2011-07-28 21:34:26 +0000 | [diff] [blame] | 4260 | |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4261 | Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc)); |
Jim Grosbach | 864b609 | 2011-07-28 21:34:26 +0000 | [diff] [blame] | 4262 | |
| 4263 | return MatchOperand_Success; |
| 4264 | } |
| 4265 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4266 | ARMAsmParser::OperandMatchResultTy |
| 4267 | ARMAsmParser::parsePostIdxReg(OperandVector &Operands) { |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4268 | // Check for a post-index addressing register operand. Specifically: |
Jim Grosbach | c320c85 | 2011-08-05 21:28:30 +0000 | [diff] [blame] | 4269 | // postidx_reg := '+' register {, shift} |
| 4270 | // | '-' register {, shift} |
| 4271 | // | register {, shift} |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4272 | |
| 4273 | // This method must return MatchOperand_NoMatch without consuming any tokens |
| 4274 | // in the case where there is no match, as other alternatives take other |
| 4275 | // parse methods. |
| 4276 | AsmToken Tok = Parser.getTok(); |
| 4277 | SMLoc S = Tok.getLoc(); |
| 4278 | bool haveEaten = false; |
Jim Grosbach | a70fbfd5 | 2011-08-05 16:11:38 +0000 | [diff] [blame] | 4279 | bool isAdd = true; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4280 | if (Tok.is(AsmToken::Plus)) { |
| 4281 | Parser.Lex(); // Eat the '+' token. |
| 4282 | haveEaten = true; |
| 4283 | } else if (Tok.is(AsmToken::Minus)) { |
| 4284 | Parser.Lex(); // Eat the '-' token. |
Jim Grosbach | a70fbfd5 | 2011-08-05 16:11:38 +0000 | [diff] [blame] | 4285 | isAdd = false; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4286 | haveEaten = true; |
| 4287 | } |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4288 | |
| 4289 | SMLoc E = Parser.getTok().getEndLoc(); |
| 4290 | int Reg = tryParseRegister(); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4291 | if (Reg == -1) { |
| 4292 | if (!haveEaten) |
| 4293 | return MatchOperand_NoMatch; |
| 4294 | Error(Parser.getTok().getLoc(), "register expected"); |
| 4295 | return MatchOperand_ParseFail; |
| 4296 | } |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4297 | |
Jim Grosbach | c320c85 | 2011-08-05 21:28:30 +0000 | [diff] [blame] | 4298 | ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift; |
| 4299 | unsigned ShiftImm = 0; |
Jim Grosbach | 3d0b3a3 | 2011-08-05 22:03:36 +0000 | [diff] [blame] | 4300 | if (Parser.getTok().is(AsmToken::Comma)) { |
| 4301 | Parser.Lex(); // Eat the ','. |
| 4302 | if (parseMemRegOffsetShift(ShiftTy, ShiftImm)) |
| 4303 | return MatchOperand_ParseFail; |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4304 | |
| 4305 | // FIXME: Only approximates end...may include intervening whitespace. |
| 4306 | E = Parser.getTok().getLoc(); |
Jim Grosbach | 3d0b3a3 | 2011-08-05 22:03:36 +0000 | [diff] [blame] | 4307 | } |
Jim Grosbach | c320c85 | 2011-08-05 21:28:30 +0000 | [diff] [blame] | 4308 | |
| 4309 | Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy, |
| 4310 | ShiftImm, S, E)); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4311 | |
| 4312 | return MatchOperand_Success; |
| 4313 | } |
| 4314 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4315 | ARMAsmParser::OperandMatchResultTy |
| 4316 | ARMAsmParser::parseAM3Offset(OperandVector &Operands) { |
Jim Grosbach | 1d9d5e9 | 2011-08-10 21:56:18 +0000 | [diff] [blame] | 4317 | // Check for a post-index addressing register operand. Specifically: |
| 4318 | // am3offset := '+' register |
| 4319 | // | '-' register |
| 4320 | // | register |
| 4321 | // | # imm |
| 4322 | // | # + imm |
| 4323 | // | # - imm |
| 4324 | |
| 4325 | // This method must return MatchOperand_NoMatch without consuming any tokens |
| 4326 | // in the case where there is no match, as other alternatives take other |
| 4327 | // parse methods. |
| 4328 | AsmToken Tok = Parser.getTok(); |
| 4329 | SMLoc S = Tok.getLoc(); |
| 4330 | |
| 4331 | // Do immediates first, as we always parse those if we have a '#'. |
Jim Grosbach | ef70e9b | 2011-12-09 22:25:03 +0000 | [diff] [blame] | 4332 | if (Parser.getTok().is(AsmToken::Hash) || |
| 4333 | Parser.getTok().is(AsmToken::Dollar)) { |
Amaury de la Vieuville | bac917f | 2013-06-10 14:17:15 +0000 | [diff] [blame] | 4334 | Parser.Lex(); // Eat '#' or '$'. |
Jim Grosbach | 1d9d5e9 | 2011-08-10 21:56:18 +0000 | [diff] [blame] | 4335 | // Explicitly look for a '-', as we need to encode negative zero |
| 4336 | // differently. |
| 4337 | bool isNegative = Parser.getTok().is(AsmToken::Minus); |
| 4338 | const MCExpr *Offset; |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4339 | SMLoc E; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 4340 | if (getParser().parseExpression(Offset, E)) |
Jim Grosbach | 1d9d5e9 | 2011-08-10 21:56:18 +0000 | [diff] [blame] | 4341 | return MatchOperand_ParseFail; |
| 4342 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset); |
| 4343 | if (!CE) { |
| 4344 | Error(S, "constant expression expected"); |
| 4345 | return MatchOperand_ParseFail; |
| 4346 | } |
Jim Grosbach | 1d9d5e9 | 2011-08-10 21:56:18 +0000 | [diff] [blame] | 4347 | // Negative zero is encoded as the flag value INT32_MIN. |
| 4348 | int32_t Val = CE->getValue(); |
| 4349 | if (isNegative && Val == 0) |
| 4350 | Val = INT32_MIN; |
| 4351 | |
| 4352 | Operands.push_back( |
| 4353 | ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E)); |
| 4354 | |
| 4355 | return MatchOperand_Success; |
| 4356 | } |
| 4357 | |
| 4358 | |
| 4359 | bool haveEaten = false; |
| 4360 | bool isAdd = true; |
Jim Grosbach | 1d9d5e9 | 2011-08-10 21:56:18 +0000 | [diff] [blame] | 4361 | if (Tok.is(AsmToken::Plus)) { |
| 4362 | Parser.Lex(); // Eat the '+' token. |
| 4363 | haveEaten = true; |
| 4364 | } else if (Tok.is(AsmToken::Minus)) { |
| 4365 | Parser.Lex(); // Eat the '-' token. |
| 4366 | isAdd = false; |
| 4367 | haveEaten = true; |
| 4368 | } |
Saleem Abdulrasool | 4ab6e73 | 2014-02-23 17:45:36 +0000 | [diff] [blame] | 4369 | |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4370 | Tok = Parser.getTok(); |
| 4371 | int Reg = tryParseRegister(); |
Jim Grosbach | 1d9d5e9 | 2011-08-10 21:56:18 +0000 | [diff] [blame] | 4372 | if (Reg == -1) { |
| 4373 | if (!haveEaten) |
| 4374 | return MatchOperand_NoMatch; |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4375 | Error(Tok.getLoc(), "register expected"); |
Jim Grosbach | 1d9d5e9 | 2011-08-10 21:56:18 +0000 | [diff] [blame] | 4376 | return MatchOperand_ParseFail; |
| 4377 | } |
Jim Grosbach | 1d9d5e9 | 2011-08-10 21:56:18 +0000 | [diff] [blame] | 4378 | |
| 4379 | Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift, |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4380 | 0, S, Tok.getEndLoc())); |
Jim Grosbach | 1d9d5e9 | 2011-08-10 21:56:18 +0000 | [diff] [blame] | 4381 | |
| 4382 | return MatchOperand_Success; |
| 4383 | } |
| 4384 | |
Tim Northover | eb5e4d5 | 2013-07-22 09:06:12 +0000 | [diff] [blame] | 4385 | /// Convert parsed operands to MCInst. Needed here because this instruction |
| 4386 | /// only has two register operands, but multiplication is commutative so |
| 4387 | /// assemblers should accept both "mul rD, rN, rD" and "mul rD, rD, rN". |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4388 | void ARMAsmParser::cvtThumbMultiply(MCInst &Inst, |
| 4389 | const OperandVector &Operands) { |
| 4390 | ((ARMOperand &)*Operands[3]).addRegOperands(Inst, 1); |
| 4391 | ((ARMOperand &)*Operands[1]).addCCOutOperands(Inst, 1); |
Jim Grosbach | 5a5ce63 | 2011-11-10 22:10:12 +0000 | [diff] [blame] | 4392 | // If we have a three-operand form, make sure to set Rn to be the operand |
| 4393 | // that isn't the same as Rd. |
| 4394 | unsigned RegOp = 4; |
| 4395 | if (Operands.size() == 6 && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4396 | ((ARMOperand &)*Operands[4]).getReg() == |
| 4397 | ((ARMOperand &)*Operands[3]).getReg()) |
Jim Grosbach | 5a5ce63 | 2011-11-10 22:10:12 +0000 | [diff] [blame] | 4398 | RegOp = 5; |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4399 | ((ARMOperand &)*Operands[RegOp]).addRegOperands(Inst, 1); |
Jim Grosbach | 5a5ce63 | 2011-11-10 22:10:12 +0000 | [diff] [blame] | 4400 | Inst.addOperand(Inst.getOperand(0)); |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4401 | ((ARMOperand &)*Operands[2]).addCondCodeOperands(Inst, 2); |
Jim Grosbach | 8e04849 | 2011-08-19 22:07:46 +0000 | [diff] [blame] | 4402 | } |
Jim Grosbach | cd4dd25 | 2011-08-10 22:42:16 +0000 | [diff] [blame] | 4403 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4404 | void ARMAsmParser::cvtThumbBranches(MCInst &Inst, |
| 4405 | const OperandVector &Operands) { |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 4406 | int CondOp = -1, ImmOp = -1; |
| 4407 | switch(Inst.getOpcode()) { |
| 4408 | case ARM::tB: |
| 4409 | case ARM::tBcc: CondOp = 1; ImmOp = 2; break; |
| 4410 | |
| 4411 | case ARM::t2B: |
| 4412 | case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break; |
| 4413 | |
| 4414 | default: llvm_unreachable("Unexpected instruction in cvtThumbBranches"); |
| 4415 | } |
| 4416 | // first decide whether or not the branch should be conditional |
| 4417 | // by looking at it's location relative to an IT block |
| 4418 | if(inITBlock()) { |
| 4419 | // inside an IT block we cannot have any conditional branches. any |
| 4420 | // such instructions needs to be converted to unconditional form |
| 4421 | switch(Inst.getOpcode()) { |
| 4422 | case ARM::tBcc: Inst.setOpcode(ARM::tB); break; |
| 4423 | case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break; |
| 4424 | } |
| 4425 | } else { |
| 4426 | // outside IT blocks we can only have unconditional branches with AL |
| 4427 | // condition code or conditional branches with non-AL condition code |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4428 | unsigned Cond = static_cast<ARMOperand &>(*Operands[CondOp]).getCondCode(); |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 4429 | switch(Inst.getOpcode()) { |
| 4430 | case ARM::tB: |
| 4431 | case ARM::tBcc: |
| 4432 | Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc); |
| 4433 | break; |
| 4434 | case ARM::t2B: |
| 4435 | case ARM::t2Bcc: |
| 4436 | Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc); |
| 4437 | break; |
| 4438 | } |
| 4439 | } |
Saleem Abdulrasool | 4ab6e73 | 2014-02-23 17:45:36 +0000 | [diff] [blame] | 4440 | |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 4441 | // now decide on encoding size based on branch target range |
| 4442 | switch(Inst.getOpcode()) { |
| 4443 | // classify tB as either t2B or t1B based on range of immediate operand |
| 4444 | case ARM::tB: { |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4445 | ARMOperand &op = static_cast<ARMOperand &>(*Operands[ImmOp]); |
| 4446 | if (!op.isSignedOffset<11, 1>() && isThumbTwo()) |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 4447 | Inst.setOpcode(ARM::t2B); |
| 4448 | break; |
| 4449 | } |
| 4450 | // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand |
| 4451 | case ARM::tBcc: { |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4452 | ARMOperand &op = static_cast<ARMOperand &>(*Operands[ImmOp]); |
| 4453 | if (!op.isSignedOffset<8, 1>() && isThumbTwo()) |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 4454 | Inst.setOpcode(ARM::t2Bcc); |
| 4455 | break; |
| 4456 | } |
| 4457 | } |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4458 | ((ARMOperand &)*Operands[ImmOp]).addImmOperands(Inst, 1); |
| 4459 | ((ARMOperand &)*Operands[CondOp]).addCondCodeOperands(Inst, 2); |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 4460 | } |
| 4461 | |
Bill Wendling | e18980a | 2010-11-06 22:36:58 +0000 | [diff] [blame] | 4462 | /// Parse an ARM memory expression, return false if successful else return true |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 4463 | /// or an error. The first token must be a '[' when called. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4464 | bool ARMAsmParser::parseMemory(OperandVector &Operands) { |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 4465 | SMLoc S, E; |
Sean Callanan | 936b0d3 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 4466 | assert(Parser.getTok().is(AsmToken::LBrac) && |
Bill Wendling | 4f4bce0 | 2010-11-06 10:48:18 +0000 | [diff] [blame] | 4467 | "Token is not a Left Bracket"); |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 4468 | S = Parser.getTok().getLoc(); |
Sean Callanan | a83fd7d | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 4469 | Parser.Lex(); // Eat left bracket token. |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 4470 | |
Sean Callanan | 936b0d3 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 4471 | const AsmToken &BaseRegTok = Parser.getTok(); |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 4472 | int BaseRegNum = tryParseRegister(); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4473 | if (BaseRegNum == -1) |
| 4474 | return Error(BaseRegTok.getLoc(), "register expected"); |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 4475 | |
Kristof Beyls | 2efb59a | 2013-02-14 14:46:12 +0000 | [diff] [blame] | 4476 | // The next token must either be a comma, a colon or a closing bracket. |
Daniel Dunbar | 1d5e954 | 2011-01-18 05:34:17 +0000 | [diff] [blame] | 4477 | const AsmToken &Tok = Parser.getTok(); |
Kristof Beyls | 2efb59a | 2013-02-14 14:46:12 +0000 | [diff] [blame] | 4478 | if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) && |
| 4479 | !Tok.is(AsmToken::RBrac)) |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4480 | return Error(Tok.getLoc(), "malformed memory operand"); |
Daniel Dunbar | 1d5e954 | 2011-01-18 05:34:17 +0000 | [diff] [blame] | 4481 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4482 | if (Tok.is(AsmToken::RBrac)) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4483 | E = Tok.getEndLoc(); |
Sean Callanan | a83fd7d | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 4484 | Parser.Lex(); // Eat right bracket token. |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 4485 | |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 4486 | Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, 0, |
| 4487 | ARM_AM::no_shift, 0, 0, false, |
| 4488 | S, E)); |
Jim Grosbach | 32ff558 | 2010-11-29 23:18:01 +0000 | [diff] [blame] | 4489 | |
Jim Grosbach | 40700e0 | 2011-09-19 18:42:21 +0000 | [diff] [blame] | 4490 | // If there's a pre-indexing writeback marker, '!', just add it as a token |
| 4491 | // operand. It's rather odd, but syntactically valid. |
| 4492 | if (Parser.getTok().is(AsmToken::Exclaim)) { |
| 4493 | Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc())); |
| 4494 | Parser.Lex(); // Eat the '!'. |
| 4495 | } |
| 4496 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4497 | return false; |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 4498 | } |
Daniel Dunbar | f5164f4 | 2011-01-18 05:34:24 +0000 | [diff] [blame] | 4499 | |
Kristof Beyls | 2efb59a | 2013-02-14 14:46:12 +0000 | [diff] [blame] | 4500 | assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) && |
| 4501 | "Lost colon or comma in memory operand?!"); |
| 4502 | if (Tok.is(AsmToken::Comma)) { |
| 4503 | Parser.Lex(); // Eat the comma. |
| 4504 | } |
Daniel Dunbar | f5164f4 | 2011-01-18 05:34:24 +0000 | [diff] [blame] | 4505 | |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 4506 | // If we have a ':', it's an alignment specifier. |
| 4507 | if (Parser.getTok().is(AsmToken::Colon)) { |
| 4508 | Parser.Lex(); // Eat the ':'. |
| 4509 | E = Parser.getTok().getLoc(); |
Kevin Enderby | 488f20b | 2014-04-10 20:18:58 +0000 | [diff] [blame] | 4510 | SMLoc AlignmentLoc = Tok.getLoc(); |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 4511 | |
| 4512 | const MCExpr *Expr; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 4513 | if (getParser().parseExpression(Expr)) |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 4514 | return true; |
| 4515 | |
| 4516 | // The expression has to be a constant. Memory references with relocations |
| 4517 | // don't come through here, as they use the <label> forms of the relevant |
| 4518 | // instructions. |
| 4519 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr); |
| 4520 | if (!CE) |
| 4521 | return Error (E, "constant expression expected"); |
| 4522 | |
| 4523 | unsigned Align = 0; |
| 4524 | switch (CE->getValue()) { |
| 4525 | default: |
Jim Grosbach | cef98cd | 2011-12-19 18:31:43 +0000 | [diff] [blame] | 4526 | return Error(E, |
| 4527 | "alignment specifier must be 16, 32, 64, 128, or 256 bits"); |
| 4528 | case 16: Align = 2; break; |
| 4529 | case 32: Align = 4; break; |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 4530 | case 64: Align = 8; break; |
| 4531 | case 128: Align = 16; break; |
| 4532 | case 256: Align = 32; break; |
| 4533 | } |
| 4534 | |
| 4535 | // Now we should have the closing ']' |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 4536 | if (Parser.getTok().isNot(AsmToken::RBrac)) |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4537 | return Error(Parser.getTok().getLoc(), "']' expected"); |
| 4538 | E = Parser.getTok().getEndLoc(); |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 4539 | Parser.Lex(); // Eat right bracket token. |
| 4540 | |
| 4541 | // Don't worry about range checking the value here. That's handled by |
| 4542 | // the is*() predicates. |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 4543 | Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, 0, |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 4544 | ARM_AM::no_shift, 0, Align, |
Kevin Enderby | 488f20b | 2014-04-10 20:18:58 +0000 | [diff] [blame] | 4545 | false, S, E, AlignmentLoc)); |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 4546 | |
| 4547 | // If there's a pre-indexing writeback marker, '!', just add it as a token |
| 4548 | // operand. |
| 4549 | if (Parser.getTok().is(AsmToken::Exclaim)) { |
| 4550 | Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc())); |
| 4551 | Parser.Lex(); // Eat the '!'. |
| 4552 | } |
| 4553 | |
| 4554 | return false; |
| 4555 | } |
| 4556 | |
| 4557 | // If we have a '#', it's an immediate offset, else assume it's a register |
Jim Grosbach | 8279c18 | 2011-11-15 22:14:41 +0000 | [diff] [blame] | 4558 | // offset. Be friendly and also accept a plain integer (without a leading |
| 4559 | // hash) for gas compatibility. |
| 4560 | if (Parser.getTok().is(AsmToken::Hash) || |
Jim Grosbach | ef70e9b | 2011-12-09 22:25:03 +0000 | [diff] [blame] | 4561 | Parser.getTok().is(AsmToken::Dollar) || |
Jim Grosbach | 8279c18 | 2011-11-15 22:14:41 +0000 | [diff] [blame] | 4562 | Parser.getTok().is(AsmToken::Integer)) { |
Jim Grosbach | ef70e9b | 2011-12-09 22:25:03 +0000 | [diff] [blame] | 4563 | if (Parser.getTok().isNot(AsmToken::Integer)) |
Amaury de la Vieuville | bac917f | 2013-06-10 14:17:15 +0000 | [diff] [blame] | 4564 | Parser.Lex(); // Eat '#' or '$'. |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4565 | E = Parser.getTok().getLoc(); |
Daniel Dunbar | f5164f4 | 2011-01-18 05:34:24 +0000 | [diff] [blame] | 4566 | |
Owen Anderson | 967674d | 2011-08-29 19:36:44 +0000 | [diff] [blame] | 4567 | bool isNegative = getParser().getTok().is(AsmToken::Minus); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4568 | const MCExpr *Offset; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 4569 | if (getParser().parseExpression(Offset)) |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 4570 | return true; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4571 | |
| 4572 | // The expression has to be a constant. Memory references with relocations |
| 4573 | // don't come through here, as they use the <label> forms of the relevant |
| 4574 | // instructions. |
| 4575 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset); |
| 4576 | if (!CE) |
| 4577 | return Error (E, "constant expression expected"); |
| 4578 | |
Owen Anderson | 967674d | 2011-08-29 19:36:44 +0000 | [diff] [blame] | 4579 | // If the constant was #-0, represent it as INT32_MIN. |
| 4580 | int32_t Val = CE->getValue(); |
| 4581 | if (isNegative && Val == 0) |
| 4582 | CE = MCConstantExpr::Create(INT32_MIN, getContext()); |
| 4583 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4584 | // Now we should have the closing ']' |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4585 | if (Parser.getTok().isNot(AsmToken::RBrac)) |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4586 | return Error(Parser.getTok().getLoc(), "']' expected"); |
| 4587 | E = Parser.getTok().getEndLoc(); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4588 | Parser.Lex(); // Eat right bracket token. |
| 4589 | |
| 4590 | // Don't worry about range checking the value here. That's handled by |
| 4591 | // the is*() predicates. |
| 4592 | Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0, |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 4593 | ARM_AM::no_shift, 0, 0, |
| 4594 | false, S, E)); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4595 | |
| 4596 | // If there's a pre-indexing writeback marker, '!', just add it as a token |
| 4597 | // operand. |
| 4598 | if (Parser.getTok().is(AsmToken::Exclaim)) { |
| 4599 | Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc())); |
| 4600 | Parser.Lex(); // Eat the '!'. |
| 4601 | } |
| 4602 | |
| 4603 | return false; |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 4604 | } |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4605 | |
| 4606 | // The register offset is optionally preceded by a '+' or '-' |
| 4607 | bool isNegative = false; |
| 4608 | if (Parser.getTok().is(AsmToken::Minus)) { |
| 4609 | isNegative = true; |
| 4610 | Parser.Lex(); // Eat the '-'. |
| 4611 | } else if (Parser.getTok().is(AsmToken::Plus)) { |
| 4612 | // Nothing to do. |
| 4613 | Parser.Lex(); // Eat the '+'. |
| 4614 | } |
| 4615 | |
| 4616 | E = Parser.getTok().getLoc(); |
| 4617 | int OffsetRegNum = tryParseRegister(); |
| 4618 | if (OffsetRegNum == -1) |
| 4619 | return Error(E, "register expected"); |
| 4620 | |
| 4621 | // If there's a shift operator, handle it. |
| 4622 | ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift; |
Jim Grosbach | 3d0b3a3 | 2011-08-05 22:03:36 +0000 | [diff] [blame] | 4623 | unsigned ShiftImm = 0; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4624 | if (Parser.getTok().is(AsmToken::Comma)) { |
| 4625 | Parser.Lex(); // Eat the ','. |
Jim Grosbach | 3d0b3a3 | 2011-08-05 22:03:36 +0000 | [diff] [blame] | 4626 | if (parseMemRegOffsetShift(ShiftType, ShiftImm)) |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4627 | return true; |
| 4628 | } |
| 4629 | |
| 4630 | // Now we should have the closing ']' |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4631 | if (Parser.getTok().isNot(AsmToken::RBrac)) |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4632 | return Error(Parser.getTok().getLoc(), "']' expected"); |
| 4633 | E = Parser.getTok().getEndLoc(); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4634 | Parser.Lex(); // Eat right bracket token. |
| 4635 | |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 4636 | Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, OffsetRegNum, |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 4637 | ShiftType, ShiftImm, 0, isNegative, |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4638 | S, E)); |
| 4639 | |
Jim Grosbach | c320c85 | 2011-08-05 21:28:30 +0000 | [diff] [blame] | 4640 | // If there's a pre-indexing writeback marker, '!', just add it as a token |
| 4641 | // operand. |
| 4642 | if (Parser.getTok().is(AsmToken::Exclaim)) { |
| 4643 | Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc())); |
| 4644 | Parser.Lex(); // Eat the '!'. |
| 4645 | } |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4646 | |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 4647 | return false; |
| 4648 | } |
| 4649 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4650 | /// parseMemRegOffsetShift - one of these two: |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 4651 | /// ( lsl | lsr | asr | ror ) , # shift_amount |
| 4652 | /// rrx |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4653 | /// return true if it parses a shift otherwise it returns false. |
| 4654 | bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St, |
| 4655 | unsigned &Amount) { |
| 4656 | SMLoc Loc = Parser.getTok().getLoc(); |
Sean Callanan | 936b0d3 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 4657 | const AsmToken &Tok = Parser.getTok(); |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 4658 | if (Tok.isNot(AsmToken::Identifier)) |
| 4659 | return true; |
Benjamin Kramer | 92d8998 | 2010-07-14 22:38:02 +0000 | [diff] [blame] | 4660 | StringRef ShiftName = Tok.getString(); |
Jim Grosbach | 3b559ff | 2011-12-07 23:40:58 +0000 | [diff] [blame] | 4661 | if (ShiftName == "lsl" || ShiftName == "LSL" || |
| 4662 | ShiftName == "asl" || ShiftName == "ASL") |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 4663 | St = ARM_AM::lsl; |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 4664 | else if (ShiftName == "lsr" || ShiftName == "LSR") |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 4665 | St = ARM_AM::lsr; |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 4666 | else if (ShiftName == "asr" || ShiftName == "ASR") |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 4667 | St = ARM_AM::asr; |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 4668 | else if (ShiftName == "ror" || ShiftName == "ROR") |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 4669 | St = ARM_AM::ror; |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 4670 | else if (ShiftName == "rrx" || ShiftName == "RRX") |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 4671 | St = ARM_AM::rrx; |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 4672 | else |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4673 | return Error(Loc, "illegal shift operator"); |
Sean Callanan | a83fd7d | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 4674 | Parser.Lex(); // Eat shift type token. |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 4675 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4676 | // rrx stands alone. |
| 4677 | Amount = 0; |
| 4678 | if (St != ARM_AM::rrx) { |
| 4679 | Loc = Parser.getTok().getLoc(); |
| 4680 | // A '#' and a shift amount. |
| 4681 | const AsmToken &HashTok = Parser.getTok(); |
Jim Grosbach | ef70e9b | 2011-12-09 22:25:03 +0000 | [diff] [blame] | 4682 | if (HashTok.isNot(AsmToken::Hash) && |
| 4683 | HashTok.isNot(AsmToken::Dollar)) |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4684 | return Error(HashTok.getLoc(), "'#' expected"); |
| 4685 | Parser.Lex(); // Eat hash token. |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 4686 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4687 | const MCExpr *Expr; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 4688 | if (getParser().parseExpression(Expr)) |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4689 | return true; |
| 4690 | // Range check the immediate. |
| 4691 | // lsl, ror: 0 <= imm <= 31 |
| 4692 | // lsr, asr: 0 <= imm <= 32 |
| 4693 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr); |
| 4694 | if (!CE) |
| 4695 | return Error(Loc, "shift amount must be an immediate"); |
| 4696 | int64_t Imm = CE->getValue(); |
| 4697 | if (Imm < 0 || |
| 4698 | ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) || |
| 4699 | ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32)) |
| 4700 | return Error(Loc, "immediate shift value out of range"); |
Tim Northover | 0c97e76 | 2012-09-22 11:18:12 +0000 | [diff] [blame] | 4701 | // If <ShiftTy> #0, turn it into a no_shift. |
| 4702 | if (Imm == 0) |
| 4703 | St = ARM_AM::lsl; |
| 4704 | // For consistency, treat lsr #32 and asr #32 as having immediate value 0. |
| 4705 | if (Imm == 32) |
| 4706 | Imm = 0; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4707 | Amount = Imm; |
| 4708 | } |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 4709 | |
| 4710 | return false; |
| 4711 | } |
| 4712 | |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 4713 | /// parseFPImm - A floating point immediate expression operand. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4714 | ARMAsmParser::OperandMatchResultTy |
| 4715 | ARMAsmParser::parseFPImm(OperandVector &Operands) { |
Jim Grosbach | a9d36fb | 2012-01-20 18:09:51 +0000 | [diff] [blame] | 4716 | // Anything that can accept a floating point constant as an operand |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 4717 | // needs to go through here, as the regular parseExpression is |
Jim Grosbach | a9d36fb | 2012-01-20 18:09:51 +0000 | [diff] [blame] | 4718 | // integer only. |
| 4719 | // |
| 4720 | // This routine still creates a generic Immediate operand, containing |
| 4721 | // a bitcast of the 64-bit floating point value. The various operands |
| 4722 | // that accept floats can check whether the value is valid for them |
| 4723 | // via the standard is*() predicates. |
| 4724 | |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 4725 | SMLoc S = Parser.getTok().getLoc(); |
| 4726 | |
Jim Grosbach | ef70e9b | 2011-12-09 22:25:03 +0000 | [diff] [blame] | 4727 | if (Parser.getTok().isNot(AsmToken::Hash) && |
| 4728 | Parser.getTok().isNot(AsmToken::Dollar)) |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 4729 | return MatchOperand_NoMatch; |
Jim Grosbach | 741cd73 | 2011-10-17 22:26:03 +0000 | [diff] [blame] | 4730 | |
| 4731 | // Disambiguate the VMOV forms that can accept an FP immediate. |
| 4732 | // vmov.f32 <sreg>, #imm |
| 4733 | // vmov.f64 <dreg>, #imm |
| 4734 | // vmov.f32 <dreg>, #imm @ vector f32x2 |
| 4735 | // vmov.f32 <qreg>, #imm @ vector f32x4 |
| 4736 | // |
| 4737 | // There are also the NEON VMOV instructions which expect an |
| 4738 | // integer constant. Make sure we don't try to parse an FPImm |
| 4739 | // for these: |
| 4740 | // vmov.i{8|16|32|64} <dreg|qreg>, #imm |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4741 | ARMOperand &TyOp = static_cast<ARMOperand &>(*Operands[2]); |
| 4742 | bool isVmovf = TyOp.isToken() && |
| 4743 | (TyOp.getToken() == ".f32" || TyOp.getToken() == ".f64"); |
| 4744 | ARMOperand &Mnemonic = static_cast<ARMOperand &>(*Operands[0]); |
| 4745 | bool isFconst = Mnemonic.isToken() && (Mnemonic.getToken() == "fconstd" || |
| 4746 | Mnemonic.getToken() == "fconsts"); |
David Peixotto | a872e0e | 2014-01-07 18:19:23 +0000 | [diff] [blame] | 4747 | if (!(isVmovf || isFconst)) |
Jim Grosbach | 741cd73 | 2011-10-17 22:26:03 +0000 | [diff] [blame] | 4748 | return MatchOperand_NoMatch; |
| 4749 | |
Amaury de la Vieuville | bac917f | 2013-06-10 14:17:15 +0000 | [diff] [blame] | 4750 | Parser.Lex(); // Eat '#' or '$'. |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 4751 | |
| 4752 | // Handle negation, as that still comes through as a separate token. |
| 4753 | bool isNegative = false; |
| 4754 | if (Parser.getTok().is(AsmToken::Minus)) { |
| 4755 | isNegative = true; |
| 4756 | Parser.Lex(); |
| 4757 | } |
| 4758 | const AsmToken &Tok = Parser.getTok(); |
Jim Grosbach | 235c8d2 | 2012-01-19 02:47:30 +0000 | [diff] [blame] | 4759 | SMLoc Loc = Tok.getLoc(); |
David Peixotto | a872e0e | 2014-01-07 18:19:23 +0000 | [diff] [blame] | 4760 | if (Tok.is(AsmToken::Real) && isVmovf) { |
Jim Grosbach | a9d36fb | 2012-01-20 18:09:51 +0000 | [diff] [blame] | 4761 | APFloat RealVal(APFloat::IEEEsingle, Tok.getString()); |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 4762 | uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue(); |
| 4763 | // If we had a '-' in front, toggle the sign bit. |
Jim Grosbach | a9d36fb | 2012-01-20 18:09:51 +0000 | [diff] [blame] | 4764 | IntVal ^= (uint64_t)isNegative << 31; |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 4765 | Parser.Lex(); // Eat the token. |
Jim Grosbach | a9d36fb | 2012-01-20 18:09:51 +0000 | [diff] [blame] | 4766 | Operands.push_back(ARMOperand::CreateImm( |
| 4767 | MCConstantExpr::Create(IntVal, getContext()), |
| 4768 | S, Parser.getTok().getLoc())); |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 4769 | return MatchOperand_Success; |
| 4770 | } |
Jim Grosbach | a9d36fb | 2012-01-20 18:09:51 +0000 | [diff] [blame] | 4771 | // Also handle plain integers. Instructions which allow floating point |
| 4772 | // immediates also allow a raw encoded 8-bit value. |
David Peixotto | a872e0e | 2014-01-07 18:19:23 +0000 | [diff] [blame] | 4773 | if (Tok.is(AsmToken::Integer) && isFconst) { |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 4774 | int64_t Val = Tok.getIntVal(); |
| 4775 | Parser.Lex(); // Eat the token. |
| 4776 | if (Val > 255 || Val < 0) { |
Jim Grosbach | 235c8d2 | 2012-01-19 02:47:30 +0000 | [diff] [blame] | 4777 | Error(Loc, "encoded floating point value out of range"); |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 4778 | return MatchOperand_ParseFail; |
| 4779 | } |
David Peixotto | a872e0e | 2014-01-07 18:19:23 +0000 | [diff] [blame] | 4780 | float RealVal = ARM_AM::getFPImmFloat(Val); |
| 4781 | Val = APFloat(RealVal).bitcastToAPInt().getZExtValue(); |
| 4782 | |
Jim Grosbach | a9d36fb | 2012-01-20 18:09:51 +0000 | [diff] [blame] | 4783 | Operands.push_back(ARMOperand::CreateImm( |
| 4784 | MCConstantExpr::Create(Val, getContext()), S, |
| 4785 | Parser.getTok().getLoc())); |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 4786 | return MatchOperand_Success; |
| 4787 | } |
| 4788 | |
Jim Grosbach | 235c8d2 | 2012-01-19 02:47:30 +0000 | [diff] [blame] | 4789 | Error(Loc, "invalid floating point immediate"); |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 4790 | return MatchOperand_ParseFail; |
| 4791 | } |
Jim Grosbach | a9d36fb | 2012-01-20 18:09:51 +0000 | [diff] [blame] | 4792 | |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 4793 | /// Parse a arm instruction operand. For now this parses the operand regardless |
| 4794 | /// of the mnemonic. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4795 | bool ARMAsmParser::parseOperand(OperandVector &Operands, StringRef Mnemonic) { |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 4796 | SMLoc S, E; |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 4797 | |
| 4798 | // Check if the current operand has a custom associated parser, if so, try to |
| 4799 | // custom parse the operand, or fallback to the general approach. |
Jim Grosbach | 861e49c | 2011-02-12 01:34:40 +0000 | [diff] [blame] | 4800 | OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic); |
| 4801 | if (ResTy == MatchOperand_Success) |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 4802 | return false; |
Jim Grosbach | 861e49c | 2011-02-12 01:34:40 +0000 | [diff] [blame] | 4803 | // If there wasn't a custom match, try the generic matcher below. Otherwise, |
| 4804 | // there was a match, but an error occurred, in which case, just return that |
| 4805 | // the operand parsing failed. |
| 4806 | if (ResTy == MatchOperand_ParseFail) |
| 4807 | return true; |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 4808 | |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 4809 | switch (getLexer().getKind()) { |
Bill Wendling | ee7f1f9 | 2010-11-06 21:42:12 +0000 | [diff] [blame] | 4810 | default: |
| 4811 | Error(Parser.getTok().getLoc(), "unexpected token in operand"); |
Bill Wendling | 2063b84 | 2010-11-18 23:43:05 +0000 | [diff] [blame] | 4812 | return true; |
Jim Grosbach | bb24c59 | 2011-07-13 18:49:30 +0000 | [diff] [blame] | 4813 | case AsmToken::Identifier: { |
Chad Rosier | b162a5c | 2013-03-19 23:44:03 +0000 | [diff] [blame] | 4814 | // If we've seen a branch mnemonic, the next operand must be a label. This |
| 4815 | // is true even if the label is a register name. So "br r1" means branch to |
| 4816 | // label "r1". |
| 4817 | bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl"; |
| 4818 | if (!ExpectLabel) { |
| 4819 | if (!tryParseRegisterWithWriteBack(Operands)) |
| 4820 | return false; |
| 4821 | int Res = tryParseShiftRegister(Operands); |
| 4822 | if (Res == 0) // success |
| 4823 | return false; |
| 4824 | else if (Res == -1) // irrecoverable error |
| 4825 | return true; |
| 4826 | // If this is VMRS, check for the apsr_nzcv operand. |
| 4827 | if (Mnemonic == "vmrs" && |
| 4828 | Parser.getTok().getString().equals_lower("apsr_nzcv")) { |
| 4829 | S = Parser.getTok().getLoc(); |
| 4830 | Parser.Lex(); |
| 4831 | Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S)); |
| 4832 | return false; |
| 4833 | } |
Jim Grosbach | 4ab23b5 | 2011-10-03 21:12:43 +0000 | [diff] [blame] | 4834 | } |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 4835 | |
| 4836 | // Fall though for the Identifier case that is not a register or a |
| 4837 | // special name. |
Jim Grosbach | bb24c59 | 2011-07-13 18:49:30 +0000 | [diff] [blame] | 4838 | } |
Jim Grosbach | 4e38035 | 2011-10-26 21:14:08 +0000 | [diff] [blame] | 4839 | case AsmToken::LParen: // parenthesized expressions like (_strcmp-4) |
Kevin Enderby | b084be9 | 2011-01-13 20:32:36 +0000 | [diff] [blame] | 4840 | case AsmToken::Integer: // things like 1f and 2b as a branch targets |
Jim Grosbach | 5c6b634 | 2011-11-01 22:38:31 +0000 | [diff] [blame] | 4841 | case AsmToken::String: // quoted label names. |
Kevin Enderby | b084be9 | 2011-01-13 20:32:36 +0000 | [diff] [blame] | 4842 | case AsmToken::Dot: { // . as a branch target |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 4843 | // This was not a register so parse other operands that start with an |
| 4844 | // identifier (like labels) as expressions and create them as immediates. |
| 4845 | const MCExpr *IdVal; |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 4846 | S = Parser.getTok().getLoc(); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 4847 | if (getParser().parseExpression(IdVal)) |
Bill Wendling | 2063b84 | 2010-11-18 23:43:05 +0000 | [diff] [blame] | 4848 | return true; |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 4849 | E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1); |
Bill Wendling | 2063b84 | 2010-11-18 23:43:05 +0000 | [diff] [blame] | 4850 | Operands.push_back(ARMOperand::CreateImm(IdVal, S, E)); |
| 4851 | return false; |
| 4852 | } |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 4853 | case AsmToken::LBrac: |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 4854 | return parseMemory(Operands); |
Kevin Enderby | a2b9910 | 2009-10-09 21:12:28 +0000 | [diff] [blame] | 4855 | case AsmToken::LCurly: |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 4856 | return parseRegisterList(Operands); |
Jim Grosbach | ef70e9b | 2011-12-09 22:25:03 +0000 | [diff] [blame] | 4857 | case AsmToken::Dollar: |
Owen Anderson | f02d98d | 2011-08-29 17:17:09 +0000 | [diff] [blame] | 4858 | case AsmToken::Hash: { |
Kevin Enderby | 3a80dac | 2009-10-13 23:33:38 +0000 | [diff] [blame] | 4859 | // #42 -> immediate. |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 4860 | S = Parser.getTok().getLoc(); |
Sean Callanan | a83fd7d | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 4861 | Parser.Lex(); |
Jim Grosbach | 003607f | 2012-04-16 21:18:46 +0000 | [diff] [blame] | 4862 | |
| 4863 | if (Parser.getTok().isNot(AsmToken::Colon)) { |
| 4864 | bool isNegative = Parser.getTok().is(AsmToken::Minus); |
| 4865 | const MCExpr *ImmVal; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 4866 | if (getParser().parseExpression(ImmVal)) |
Jim Grosbach | 003607f | 2012-04-16 21:18:46 +0000 | [diff] [blame] | 4867 | return true; |
| 4868 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal); |
| 4869 | if (CE) { |
| 4870 | int32_t Val = CE->getValue(); |
| 4871 | if (isNegative && Val == 0) |
| 4872 | ImmVal = MCConstantExpr::Create(INT32_MIN, getContext()); |
| 4873 | } |
| 4874 | E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1); |
| 4875 | Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E)); |
Jim Grosbach | 9be2d71 | 2013-02-23 00:52:09 +0000 | [diff] [blame] | 4876 | |
| 4877 | // There can be a trailing '!' on operands that we want as a separate |
Saleem Abdulrasool | 83e3770 | 2013-12-28 03:07:12 +0000 | [diff] [blame] | 4878 | // '!' Token operand. Handle that here. For example, the compatibility |
Jim Grosbach | 9be2d71 | 2013-02-23 00:52:09 +0000 | [diff] [blame] | 4879 | // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'. |
| 4880 | if (Parser.getTok().is(AsmToken::Exclaim)) { |
| 4881 | Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(), |
| 4882 | Parser.getTok().getLoc())); |
| 4883 | Parser.Lex(); // Eat exclaim token |
| 4884 | } |
Jim Grosbach | 003607f | 2012-04-16 21:18:46 +0000 | [diff] [blame] | 4885 | return false; |
Owen Anderson | f02d98d | 2011-08-29 17:17:09 +0000 | [diff] [blame] | 4886 | } |
Jim Grosbach | 003607f | 2012-04-16 21:18:46 +0000 | [diff] [blame] | 4887 | // w/ a ':' after the '#', it's just like a plain ':'. |
| 4888 | // FALLTHROUGH |
Owen Anderson | f02d98d | 2011-08-29 17:17:09 +0000 | [diff] [blame] | 4889 | } |
Jason W Kim | 1f7bc07 | 2011-01-11 23:53:41 +0000 | [diff] [blame] | 4890 | case AsmToken::Colon: { |
| 4891 | // ":lower16:" and ":upper16:" expression prefixes |
Evan Cheng | 965b3c7 | 2011-01-13 07:58:56 +0000 | [diff] [blame] | 4892 | // FIXME: Check it's an expression prefix, |
| 4893 | // e.g. (FOO - :lower16:BAR) isn't legal. |
| 4894 | ARMMCExpr::VariantKind RefKind; |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 4895 | if (parsePrefix(RefKind)) |
Jason W Kim | 1f7bc07 | 2011-01-11 23:53:41 +0000 | [diff] [blame] | 4896 | return true; |
| 4897 | |
Evan Cheng | 965b3c7 | 2011-01-13 07:58:56 +0000 | [diff] [blame] | 4898 | const MCExpr *SubExprVal; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 4899 | if (getParser().parseExpression(SubExprVal)) |
Jason W Kim | 1f7bc07 | 2011-01-11 23:53:41 +0000 | [diff] [blame] | 4900 | return true; |
| 4901 | |
Evan Cheng | 965b3c7 | 2011-01-13 07:58:56 +0000 | [diff] [blame] | 4902 | const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal, |
Jim Grosbach | 9659ed9 | 2012-09-21 00:26:53 +0000 | [diff] [blame] | 4903 | getContext()); |
Jason W Kim | 1f7bc07 | 2011-01-11 23:53:41 +0000 | [diff] [blame] | 4904 | E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1); |
Evan Cheng | 965b3c7 | 2011-01-13 07:58:56 +0000 | [diff] [blame] | 4905 | Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E)); |
Jason W Kim | 1f7bc07 | 2011-01-11 23:53:41 +0000 | [diff] [blame] | 4906 | return false; |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 4907 | } |
David Peixotto | e407d09 | 2013-12-19 18:12:36 +0000 | [diff] [blame] | 4908 | case AsmToken::Equal: { |
| 4909 | if (Mnemonic != "ldr") // only parse for ldr pseudo (e.g. ldr r0, =val) |
| 4910 | return Error(Parser.getTok().getLoc(), "unexpected token in operand"); |
| 4911 | |
David Peixotto | e407d09 | 2013-12-19 18:12:36 +0000 | [diff] [blame] | 4912 | Parser.Lex(); // Eat '=' |
| 4913 | const MCExpr *SubExprVal; |
| 4914 | if (getParser().parseExpression(SubExprVal)) |
| 4915 | return true; |
| 4916 | E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1); |
| 4917 | |
David Peixotto | b9b7362 | 2014-02-04 17:22:40 +0000 | [diff] [blame] | 4918 | const MCExpr *CPLoc = getTargetStreamer().addConstantPoolEntry(SubExprVal); |
David Peixotto | e407d09 | 2013-12-19 18:12:36 +0000 | [diff] [blame] | 4919 | Operands.push_back(ARMOperand::CreateImm(CPLoc, S, E)); |
| 4920 | return false; |
| 4921 | } |
Jason W Kim | 1f7bc07 | 2011-01-11 23:53:41 +0000 | [diff] [blame] | 4922 | } |
| 4923 | } |
| 4924 | |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 4925 | // parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e. |
Evan Cheng | 965b3c7 | 2011-01-13 07:58:56 +0000 | [diff] [blame] | 4926 | // :lower16: and :upper16:. |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 4927 | bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) { |
Evan Cheng | 965b3c7 | 2011-01-13 07:58:56 +0000 | [diff] [blame] | 4928 | RefKind = ARMMCExpr::VK_ARM_None; |
Jason W Kim | 1f7bc07 | 2011-01-11 23:53:41 +0000 | [diff] [blame] | 4929 | |
Saleem Abdulrasool | 435f456 | 2014-01-10 04:38:40 +0000 | [diff] [blame] | 4930 | // consume an optional '#' (GNU compatibility) |
| 4931 | if (getLexer().is(AsmToken::Hash)) |
| 4932 | Parser.Lex(); |
| 4933 | |
Jason W Kim | 1f7bc07 | 2011-01-11 23:53:41 +0000 | [diff] [blame] | 4934 | // :lower16: and :upper16: modifiers |
Jason W Kim | 9322997 | 2011-01-13 00:27:00 +0000 | [diff] [blame] | 4935 | assert(getLexer().is(AsmToken::Colon) && "expected a :"); |
Jason W Kim | 1f7bc07 | 2011-01-11 23:53:41 +0000 | [diff] [blame] | 4936 | Parser.Lex(); // Eat ':' |
| 4937 | |
| 4938 | if (getLexer().isNot(AsmToken::Identifier)) { |
| 4939 | Error(Parser.getTok().getLoc(), "expected prefix identifier in operand"); |
| 4940 | return true; |
| 4941 | } |
| 4942 | |
| 4943 | StringRef IDVal = Parser.getTok().getIdentifier(); |
| 4944 | if (IDVal == "lower16") { |
Evan Cheng | 965b3c7 | 2011-01-13 07:58:56 +0000 | [diff] [blame] | 4945 | RefKind = ARMMCExpr::VK_ARM_LO16; |
Jason W Kim | 1f7bc07 | 2011-01-11 23:53:41 +0000 | [diff] [blame] | 4946 | } else if (IDVal == "upper16") { |
Evan Cheng | 965b3c7 | 2011-01-13 07:58:56 +0000 | [diff] [blame] | 4947 | RefKind = ARMMCExpr::VK_ARM_HI16; |
Jason W Kim | 1f7bc07 | 2011-01-11 23:53:41 +0000 | [diff] [blame] | 4948 | } else { |
| 4949 | Error(Parser.getTok().getLoc(), "unexpected prefix in operand"); |
| 4950 | return true; |
| 4951 | } |
| 4952 | Parser.Lex(); |
| 4953 | |
| 4954 | if (getLexer().isNot(AsmToken::Colon)) { |
| 4955 | Error(Parser.getTok().getLoc(), "unexpected token after prefix"); |
| 4956 | return true; |
| 4957 | } |
| 4958 | Parser.Lex(); // Eat the last ':' |
| 4959 | return false; |
| 4960 | } |
| 4961 | |
Daniel Dunbar | 9d944b3 | 2011-01-11 15:59:50 +0000 | [diff] [blame] | 4962 | /// \brief Given a mnemonic, split out possible predication code and carry |
| 4963 | /// setting letters to form a canonical mnemonic and flags. |
| 4964 | // |
Daniel Dunbar | 876bb018 | 2011-01-10 12:24:52 +0000 | [diff] [blame] | 4965 | // FIXME: Would be nice to autogen this. |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 4966 | // FIXME: This is a bit of a maze of special cases. |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 4967 | StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic, |
Jim Grosbach | 5cc3b4c | 2011-07-19 20:10:31 +0000 | [diff] [blame] | 4968 | unsigned &PredicationCode, |
| 4969 | bool &CarrySetting, |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 4970 | unsigned &ProcessorIMod, |
| 4971 | StringRef &ITMask) { |
Daniel Dunbar | 9d944b3 | 2011-01-11 15:59:50 +0000 | [diff] [blame] | 4972 | PredicationCode = ARMCC::AL; |
| 4973 | CarrySetting = false; |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 4974 | ProcessorIMod = 0; |
Daniel Dunbar | 9d944b3 | 2011-01-11 15:59:50 +0000 | [diff] [blame] | 4975 | |
Daniel Dunbar | 876bb018 | 2011-01-10 12:24:52 +0000 | [diff] [blame] | 4976 | // Ignore some mnemonics we know aren't predicated forms. |
Daniel Dunbar | 9d944b3 | 2011-01-11 15:59:50 +0000 | [diff] [blame] | 4977 | // |
| 4978 | // FIXME: Would be nice to autogen this. |
Jim Grosbach | 5cc3b4c | 2011-07-19 20:10:31 +0000 | [diff] [blame] | 4979 | if ((Mnemonic == "movs" && isThumb()) || |
| 4980 | Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" || |
| 4981 | Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" || |
| 4982 | Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" || |
| 4983 | Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" || |
Richard Barton | 8d519fe | 2013-09-05 14:14:19 +0000 | [diff] [blame] | 4984 | Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" || |
Jim Grosbach | 5cc3b4c | 2011-07-19 20:10:31 +0000 | [diff] [blame] | 4985 | Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" || |
| 4986 | Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" || |
Jim Grosbach | e16acac | 2011-12-19 19:43:50 +0000 | [diff] [blame] | 4987 | Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" || |
Joey Gouly | 2efaa73 | 2013-07-06 20:50:18 +0000 | [diff] [blame] | 4988 | Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || |
Joey Gouly | 0f12aa2 | 2013-07-09 11:26:18 +0000 | [diff] [blame] | 4989 | Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || |
| 4990 | Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" || |
| 4991 | Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic.startswith("vsel")) |
Daniel Dunbar | 9d944b3 | 2011-01-11 15:59:50 +0000 | [diff] [blame] | 4992 | return Mnemonic; |
Daniel Dunbar | 75d26be | 2010-08-11 06:37:16 +0000 | [diff] [blame] | 4993 | |
Jim Grosbach | a9a3f0a | 2011-07-11 17:09:57 +0000 | [diff] [blame] | 4994 | // First, split out any predication code. Ignore mnemonics we know aren't |
| 4995 | // predicated but do have a carry-set and so weren't caught above. |
Jim Grosbach | 8d11490 | 2011-07-20 18:20:31 +0000 | [diff] [blame] | 4996 | if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" && |
Jim Grosbach | 0c398b9 | 2011-07-27 21:58:11 +0000 | [diff] [blame] | 4997 | Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" && |
Jim Grosbach | 3636be3 | 2011-08-22 23:55:58 +0000 | [diff] [blame] | 4998 | Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" && |
Jim Grosbach | f6d5d60 | 2011-09-01 18:22:13 +0000 | [diff] [blame] | 4999 | Mnemonic != "sbcs" && Mnemonic != "rscs") { |
Jim Grosbach | a9a3f0a | 2011-07-11 17:09:57 +0000 | [diff] [blame] | 5000 | unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2)) |
| 5001 | .Case("eq", ARMCC::EQ) |
| 5002 | .Case("ne", ARMCC::NE) |
| 5003 | .Case("hs", ARMCC::HS) |
| 5004 | .Case("cs", ARMCC::HS) |
| 5005 | .Case("lo", ARMCC::LO) |
| 5006 | .Case("cc", ARMCC::LO) |
| 5007 | .Case("mi", ARMCC::MI) |
| 5008 | .Case("pl", ARMCC::PL) |
| 5009 | .Case("vs", ARMCC::VS) |
| 5010 | .Case("vc", ARMCC::VC) |
| 5011 | .Case("hi", ARMCC::HI) |
| 5012 | .Case("ls", ARMCC::LS) |
| 5013 | .Case("ge", ARMCC::GE) |
| 5014 | .Case("lt", ARMCC::LT) |
| 5015 | .Case("gt", ARMCC::GT) |
| 5016 | .Case("le", ARMCC::LE) |
| 5017 | .Case("al", ARMCC::AL) |
| 5018 | .Default(~0U); |
| 5019 | if (CC != ~0U) { |
| 5020 | Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2); |
| 5021 | PredicationCode = CC; |
| 5022 | } |
Bill Wendling | 193961b | 2010-10-29 23:50:21 +0000 | [diff] [blame] | 5023 | } |
Daniel Dunbar | 188b47b | 2010-08-11 06:37:20 +0000 | [diff] [blame] | 5024 | |
Daniel Dunbar | 9d944b3 | 2011-01-11 15:59:50 +0000 | [diff] [blame] | 5025 | // Next, determine if we have a carry setting bit. We explicitly ignore all |
| 5026 | // the instructions we know end in 's'. |
| 5027 | if (Mnemonic.endswith("s") && |
Jim Grosbach | d3e8e29 | 2011-08-17 22:49:09 +0000 | [diff] [blame] | 5028 | !(Mnemonic == "cps" || Mnemonic == "mls" || |
Jim Grosbach | 5cc3b4c | 2011-07-19 20:10:31 +0000 | [diff] [blame] | 5029 | Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" || |
| 5030 | Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" || |
| 5031 | Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" || |
Jim Grosbach | 086d013 | 2011-12-08 00:49:29 +0000 | [diff] [blame] | 5032 | Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" || |
Jim Grosbach | 54337b8 | 2011-12-10 00:01:02 +0000 | [diff] [blame] | 5033 | Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" || |
Jim Grosbach | 92a939a | 2011-12-19 19:02:41 +0000 | [diff] [blame] | 5034 | Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" || |
Jim Grosbach | d74560b | 2012-03-15 20:48:18 +0000 | [diff] [blame] | 5035 | Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" || |
David Peixotto | a872e0e | 2014-01-07 18:19:23 +0000 | [diff] [blame] | 5036 | Mnemonic == "vfms" || Mnemonic == "vfnms" || Mnemonic == "fconsts" || |
Jim Grosbach | 51726e2 | 2011-07-29 20:26:09 +0000 | [diff] [blame] | 5037 | (Mnemonic == "movs" && isThumb()))) { |
Daniel Dunbar | 9d944b3 | 2011-01-11 15:59:50 +0000 | [diff] [blame] | 5038 | Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1); |
| 5039 | CarrySetting = true; |
| 5040 | } |
| 5041 | |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 5042 | // The "cps" instruction can have a interrupt mode operand which is glued into |
| 5043 | // the mnemonic. Check if this is the case, split it and parse the imod op |
| 5044 | if (Mnemonic.startswith("cps")) { |
| 5045 | // Split out any imod code. |
| 5046 | unsigned IMod = |
| 5047 | StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2)) |
| 5048 | .Case("ie", ARM_PROC::IE) |
| 5049 | .Case("id", ARM_PROC::ID) |
| 5050 | .Default(~0U); |
| 5051 | if (IMod != ~0U) { |
| 5052 | Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2); |
| 5053 | ProcessorIMod = IMod; |
| 5054 | } |
| 5055 | } |
| 5056 | |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 5057 | // The "it" instruction has the condition mask on the end of the mnemonic. |
| 5058 | if (Mnemonic.startswith("it")) { |
| 5059 | ITMask = Mnemonic.slice(2, Mnemonic.size()); |
| 5060 | Mnemonic = Mnemonic.slice(0, 2); |
| 5061 | } |
| 5062 | |
Daniel Dunbar | 9d944b3 | 2011-01-11 15:59:50 +0000 | [diff] [blame] | 5063 | return Mnemonic; |
| 5064 | } |
Daniel Dunbar | 5a384c8 | 2011-01-11 15:59:53 +0000 | [diff] [blame] | 5065 | |
| 5066 | /// \brief Given a canonical mnemonic, determine if the instruction ever allows |
| 5067 | /// inclusion of carry set or predication code operands. |
| 5068 | // |
| 5069 | // FIXME: It would be nice to autogen this. |
Bruno Cardoso Lopes | e6290cc | 2011-01-18 20:55:11 +0000 | [diff] [blame] | 5070 | void ARMAsmParser:: |
Amara Emerson | 3308909 | 2013-09-19 11:59:01 +0000 | [diff] [blame] | 5071 | getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst, |
| 5072 | bool &CanAcceptCarrySet, bool &CanAcceptPredicationCode) { |
Daniel Dunbar | 0926412 | 2011-01-11 19:06:29 +0000 | [diff] [blame] | 5073 | if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" || |
| 5074 | Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" || |
Jim Grosbach | d73c645 | 2011-09-16 18:05:48 +0000 | [diff] [blame] | 5075 | Mnemonic == "add" || Mnemonic == "adc" || |
Daniel Dunbar | 0926412 | 2011-01-11 19:06:29 +0000 | [diff] [blame] | 5076 | Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" || |
Jim Grosbach | fc54518 | 2011-09-19 23:31:02 +0000 | [diff] [blame] | 5077 | Mnemonic == "orr" || Mnemonic == "mvn" || |
Daniel Dunbar | 0926412 | 2011-01-11 19:06:29 +0000 | [diff] [blame] | 5078 | Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" || |
Jim Grosbach | fc54518 | 2011-09-19 23:31:02 +0000 | [diff] [blame] | 5079 | Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" || |
Evan Cheng | aca6c82 | 2012-04-11 00:13:00 +0000 | [diff] [blame] | 5080 | Mnemonic == "vfm" || Mnemonic == "vfnm" || |
Jim Grosbach | d73c645 | 2011-09-16 18:05:48 +0000 | [diff] [blame] | 5081 | (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" || |
Jim Grosbach | fc54518 | 2011-09-19 23:31:02 +0000 | [diff] [blame] | 5082 | Mnemonic == "mla" || Mnemonic == "smlal" || |
| 5083 | Mnemonic == "umlal" || Mnemonic == "umull"))) { |
Daniel Dunbar | 0926412 | 2011-01-11 19:06:29 +0000 | [diff] [blame] | 5084 | CanAcceptCarrySet = true; |
Jim Grosbach | 6c45b75 | 2011-09-16 16:39:25 +0000 | [diff] [blame] | 5085 | } else |
Daniel Dunbar | 0926412 | 2011-01-11 19:06:29 +0000 | [diff] [blame] | 5086 | CanAcceptCarrySet = false; |
Daniel Dunbar | 5a384c8 | 2011-01-11 15:59:53 +0000 | [diff] [blame] | 5087 | |
Tim Northover | 2c45a38 | 2013-06-26 16:52:40 +0000 | [diff] [blame] | 5088 | if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" || |
| 5089 | Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" || |
Saleem Abdulrasool | 27351f2 | 2014-05-14 03:47:39 +0000 | [diff] [blame] | 5090 | Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic == "udf" || |
| 5091 | Mnemonic.startswith("crc32") || Mnemonic.startswith("cps") || |
| 5092 | Mnemonic.startswith("vsel") || |
Joey Gouly | 2d0175e | 2013-07-09 09:59:04 +0000 | [diff] [blame] | 5093 | Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" || |
Joey Gouly | 0f12aa2 | 2013-07-09 11:26:18 +0000 | [diff] [blame] | 5094 | Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" || |
| 5095 | Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" || |
Amara Emerson | 3308909 | 2013-09-19 11:59:01 +0000 | [diff] [blame] | 5096 | Mnemonic == "vrintm" || Mnemonic.startswith("aes") || |
| 5097 | Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") || |
| 5098 | (FullInst.startswith("vmull") && FullInst.endswith(".p64"))) { |
Tim Northover | 2c45a38 | 2013-06-26 16:52:40 +0000 | [diff] [blame] | 5099 | // These mnemonics are never predicable |
Daniel Dunbar | 5a384c8 | 2011-01-11 15:59:53 +0000 | [diff] [blame] | 5100 | CanAcceptPredicationCode = false; |
Tim Northover | 2c45a38 | 2013-06-26 16:52:40 +0000 | [diff] [blame] | 5101 | } else if (!isThumb()) { |
| 5102 | // Some instructions are only predicable in Thumb mode |
| 5103 | CanAcceptPredicationCode |
| 5104 | = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" && |
| 5105 | Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" && |
| 5106 | Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" && |
| 5107 | Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" && |
| 5108 | Mnemonic != "ldc2" && Mnemonic != "ldc2l" && |
| 5109 | Mnemonic != "stc2" && Mnemonic != "stc2l" && |
| 5110 | !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs"); |
| 5111 | } else if (isThumbOne()) { |
Tim Northover | f86d1f0 | 2013-10-07 11:10:47 +0000 | [diff] [blame] | 5112 | if (hasV6MOps()) |
| 5113 | CanAcceptPredicationCode = Mnemonic != "movs"; |
| 5114 | else |
| 5115 | CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs"; |
Jim Grosbach | 6c45b75 | 2011-09-16 16:39:25 +0000 | [diff] [blame] | 5116 | } else |
Daniel Dunbar | 5a384c8 | 2011-01-11 15:59:53 +0000 | [diff] [blame] | 5117 | CanAcceptPredicationCode = true; |
Daniel Dunbar | 876bb018 | 2011-01-10 12:24:52 +0000 | [diff] [blame] | 5118 | } |
| 5119 | |
Jim Grosbach | 7283da9 | 2011-08-16 21:12:37 +0000 | [diff] [blame] | 5120 | bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic, |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5121 | OperandVector &Operands) { |
Jim Grosbach | 1d3c137 | 2011-09-01 00:28:52 +0000 | [diff] [blame] | 5122 | // FIXME: This is all horribly hacky. We really need a better way to deal |
| 5123 | // with optional operands like this in the matcher table. |
Jim Grosbach | 7283da9 | 2011-08-16 21:12:37 +0000 | [diff] [blame] | 5124 | |
| 5125 | // The 'mov' mnemonic is special. One variant has a cc_out operand, while |
| 5126 | // another does not. Specifically, the MOVW instruction does not. So we |
| 5127 | // special case it here and remove the defaulted (non-setting) cc_out |
| 5128 | // operand if that's the instruction we're trying to match. |
| 5129 | // |
| 5130 | // We do this as post-processing of the explicit operands rather than just |
| 5131 | // conditionally adding the cc_out in the first place because we need |
| 5132 | // to check the type of the parsed immediate operand. |
Owen Anderson | d7791b9 | 2011-09-14 22:46:14 +0000 | [diff] [blame] | 5133 | if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5134 | !static_cast<ARMOperand &>(*Operands[4]).isARMSOImm() && |
| 5135 | static_cast<ARMOperand &>(*Operands[4]).isImm0_65535Expr() && |
| 5136 | static_cast<ARMOperand &>(*Operands[1]).getReg() == 0) |
Jim Grosbach | 7283da9 | 2011-08-16 21:12:37 +0000 | [diff] [blame] | 5137 | return true; |
Jim Grosbach | 58ffdcc | 2011-08-16 21:34:08 +0000 | [diff] [blame] | 5138 | |
| 5139 | // Register-register 'add' for thumb does not have a cc_out operand |
| 5140 | // when there are only two register operands. |
| 5141 | if (isThumb() && Mnemonic == "add" && Operands.size() == 5 && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5142 | static_cast<ARMOperand &>(*Operands[3]).isReg() && |
| 5143 | static_cast<ARMOperand &>(*Operands[4]).isReg() && |
| 5144 | static_cast<ARMOperand &>(*Operands[1]).getReg() == 0) |
Jim Grosbach | 58ffdcc | 2011-08-16 21:34:08 +0000 | [diff] [blame] | 5145 | return true; |
Jim Grosbach | 0a0b307 | 2011-08-24 21:22:15 +0000 | [diff] [blame] | 5146 | // Register-register 'add' for thumb does not have a cc_out operand |
Jim Grosbach | 1d3c137 | 2011-09-01 00:28:52 +0000 | [diff] [blame] | 5147 | // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do |
| 5148 | // have to check the immediate range here since Thumb2 has a variant |
| 5149 | // that can handle a different range and has a cc_out operand. |
Jim Grosbach | d0c435c | 2011-09-16 22:58:42 +0000 | [diff] [blame] | 5150 | if (((isThumb() && Mnemonic == "add") || |
| 5151 | (isThumbTwo() && Mnemonic == "sub")) && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5152 | Operands.size() == 6 && static_cast<ARMOperand &>(*Operands[3]).isReg() && |
| 5153 | static_cast<ARMOperand &>(*Operands[4]).isReg() && |
| 5154 | static_cast<ARMOperand &>(*Operands[4]).getReg() == ARM::SP && |
| 5155 | static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 && |
| 5156 | ((Mnemonic == "add" && static_cast<ARMOperand &>(*Operands[5]).isReg()) || |
| 5157 | static_cast<ARMOperand &>(*Operands[5]).isImm0_1020s4())) |
Jim Grosbach | 0a0b307 | 2011-08-24 21:22:15 +0000 | [diff] [blame] | 5158 | return true; |
Jim Grosbach | d0c435c | 2011-09-16 22:58:42 +0000 | [diff] [blame] | 5159 | // For Thumb2, add/sub immediate does not have a cc_out operand for the |
| 5160 | // imm0_4095 variant. That's the least-preferred variant when |
Jim Grosbach | 1d3c137 | 2011-09-01 00:28:52 +0000 | [diff] [blame] | 5161 | // selecting via the generic "add" mnemonic, so to know that we |
| 5162 | // should remove the cc_out operand, we have to explicitly check that |
| 5163 | // it's not one of the other variants. Ugh. |
Jim Grosbach | d0c435c | 2011-09-16 22:58:42 +0000 | [diff] [blame] | 5164 | if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5165 | Operands.size() == 6 && static_cast<ARMOperand &>(*Operands[3]).isReg() && |
| 5166 | static_cast<ARMOperand &>(*Operands[4]).isReg() && |
| 5167 | static_cast<ARMOperand &>(*Operands[5]).isImm()) { |
Jim Grosbach | 1d3c137 | 2011-09-01 00:28:52 +0000 | [diff] [blame] | 5168 | // Nest conditions rather than one big 'if' statement for readability. |
| 5169 | // |
Jim Grosbach | 1d3c137 | 2011-09-01 00:28:52 +0000 | [diff] [blame] | 5170 | // If both registers are low, we're in an IT block, and the immediate is |
| 5171 | // in range, we should use encoding T1 instead, which has a cc_out. |
| 5172 | if (inITBlock() && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5173 | isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) && |
| 5174 | isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) && |
| 5175 | static_cast<ARMOperand &>(*Operands[5]).isImm0_7()) |
Jim Grosbach | 1d3c137 | 2011-09-01 00:28:52 +0000 | [diff] [blame] | 5176 | return false; |
Tilmann Scheller | ef5666f | 2013-07-03 20:38:01 +0000 | [diff] [blame] | 5177 | // Check against T3. If the second register is the PC, this is an |
| 5178 | // alternate form of ADR, which uses encoding T4, so check for that too. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5179 | if (static_cast<ARMOperand &>(*Operands[4]).getReg() != ARM::PC && |
| 5180 | static_cast<ARMOperand &>(*Operands[5]).isT2SOImm()) |
Tilmann Scheller | ef5666f | 2013-07-03 20:38:01 +0000 | [diff] [blame] | 5181 | return false; |
Jim Grosbach | 1d3c137 | 2011-09-01 00:28:52 +0000 | [diff] [blame] | 5182 | |
| 5183 | // Otherwise, we use encoding T4, which does not have a cc_out |
| 5184 | // operand. |
| 5185 | return true; |
| 5186 | } |
| 5187 | |
Jim Grosbach | 9c8b993 | 2011-09-14 21:00:40 +0000 | [diff] [blame] | 5188 | // The thumb2 multiply instruction doesn't have a CCOut register, so |
| 5189 | // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to |
| 5190 | // use the 16-bit encoding or not. |
| 5191 | if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5192 | static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 && |
| 5193 | static_cast<ARMOperand &>(*Operands[3]).isReg() && |
| 5194 | static_cast<ARMOperand &>(*Operands[4]).isReg() && |
| 5195 | static_cast<ARMOperand &>(*Operands[5]).isReg() && |
Jim Grosbach | 9c8b993 | 2011-09-14 21:00:40 +0000 | [diff] [blame] | 5196 | // If the registers aren't low regs, the destination reg isn't the |
| 5197 | // same as one of the source regs, or the cc_out operand is zero |
| 5198 | // outside of an IT block, we have to use the 32-bit encoding, so |
| 5199 | // remove the cc_out operand. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5200 | (!isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) || |
| 5201 | !isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) || |
| 5202 | !isARMLowRegister(static_cast<ARMOperand &>(*Operands[5]).getReg()) || |
| 5203 | !inITBlock() || (static_cast<ARMOperand &>(*Operands[3]).getReg() != |
| 5204 | static_cast<ARMOperand &>(*Operands[5]).getReg() && |
| 5205 | static_cast<ARMOperand &>(*Operands[3]).getReg() != |
| 5206 | static_cast<ARMOperand &>(*Operands[4]).getReg()))) |
Jim Grosbach | 9c8b993 | 2011-09-14 21:00:40 +0000 | [diff] [blame] | 5207 | return true; |
| 5208 | |
Jim Grosbach | efa7e95 | 2011-11-15 19:55:16 +0000 | [diff] [blame] | 5209 | // Also check the 'mul' syntax variant that doesn't specify an explicit |
| 5210 | // destination register. |
| 5211 | if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5212 | static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 && |
| 5213 | static_cast<ARMOperand &>(*Operands[3]).isReg() && |
| 5214 | static_cast<ARMOperand &>(*Operands[4]).isReg() && |
Jim Grosbach | efa7e95 | 2011-11-15 19:55:16 +0000 | [diff] [blame] | 5215 | // If the registers aren't low regs or the cc_out operand is zero |
| 5216 | // outside of an IT block, we have to use the 32-bit encoding, so |
| 5217 | // remove the cc_out operand. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5218 | (!isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) || |
| 5219 | !isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) || |
Jim Grosbach | efa7e95 | 2011-11-15 19:55:16 +0000 | [diff] [blame] | 5220 | !inITBlock())) |
| 5221 | return true; |
| 5222 | |
Jim Grosbach | 9c8b993 | 2011-09-14 21:00:40 +0000 | [diff] [blame] | 5223 | |
Jim Grosbach | 1d3c137 | 2011-09-01 00:28:52 +0000 | [diff] [blame] | 5224 | |
Jim Grosbach | 4b701af | 2011-08-24 21:42:27 +0000 | [diff] [blame] | 5225 | // Register-register 'add/sub' for thumb does not have a cc_out operand |
| 5226 | // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also |
| 5227 | // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't |
| 5228 | // right, this will result in better diagnostics (which operand is off) |
| 5229 | // anyway. |
| 5230 | if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") && |
| 5231 | (Operands.size() == 5 || Operands.size() == 6) && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5232 | static_cast<ARMOperand &>(*Operands[3]).isReg() && |
| 5233 | static_cast<ARMOperand &>(*Operands[3]).getReg() == ARM::SP && |
| 5234 | static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 && |
| 5235 | (static_cast<ARMOperand &>(*Operands[4]).isImm() || |
Jim Grosbach | df5a244 | 2012-04-10 17:31:55 +0000 | [diff] [blame] | 5236 | (Operands.size() == 6 && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5237 | static_cast<ARMOperand &>(*Operands[5]).isImm()))) |
Jim Grosbach | 0a0b307 | 2011-08-24 21:22:15 +0000 | [diff] [blame] | 5238 | return true; |
Jim Grosbach | 58ffdcc | 2011-08-16 21:34:08 +0000 | [diff] [blame] | 5239 | |
Jim Grosbach | 7283da9 | 2011-08-16 21:12:37 +0000 | [diff] [blame] | 5240 | return false; |
| 5241 | } |
| 5242 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5243 | bool ARMAsmParser::shouldOmitPredicateOperand(StringRef Mnemonic, |
| 5244 | OperandVector &Operands) { |
Joey Gouly | e860255 | 2013-07-19 16:34:16 +0000 | [diff] [blame] | 5245 | // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON |
| 5246 | unsigned RegIdx = 3; |
| 5247 | if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5248 | static_cast<ARMOperand &>(*Operands[2]).getToken() == ".f32") { |
| 5249 | if (static_cast<ARMOperand &>(*Operands[3]).isToken() && |
| 5250 | static_cast<ARMOperand &>(*Operands[3]).getToken() == ".f32") |
Joey Gouly | e860255 | 2013-07-19 16:34:16 +0000 | [diff] [blame] | 5251 | RegIdx = 4; |
| 5252 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5253 | if (static_cast<ARMOperand &>(*Operands[RegIdx]).isReg() && |
| 5254 | (ARMMCRegisterClasses[ARM::DPRRegClassID].contains( |
| 5255 | static_cast<ARMOperand &>(*Operands[RegIdx]).getReg()) || |
| 5256 | ARMMCRegisterClasses[ARM::QPRRegClassID].contains( |
| 5257 | static_cast<ARMOperand &>(*Operands[RegIdx]).getReg()))) |
Joey Gouly | e860255 | 2013-07-19 16:34:16 +0000 | [diff] [blame] | 5258 | return true; |
| 5259 | } |
Joey Gouly | f520d5e | 2013-07-19 16:45:16 +0000 | [diff] [blame] | 5260 | return false; |
Joey Gouly | e860255 | 2013-07-19 16:34:16 +0000 | [diff] [blame] | 5261 | } |
| 5262 | |
Jim Grosbach | 12952fe | 2011-11-11 23:08:10 +0000 | [diff] [blame] | 5263 | static bool isDataTypeToken(StringRef Tok) { |
| 5264 | return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" || |
| 5265 | Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" || |
| 5266 | Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" || |
| 5267 | Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" || |
| 5268 | Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" || |
| 5269 | Tok == ".f" || Tok == ".d"; |
| 5270 | } |
| 5271 | |
| 5272 | // FIXME: This bit should probably be handled via an explicit match class |
| 5273 | // in the .td files that matches the suffix instead of having it be |
| 5274 | // a literal string token the way it is now. |
| 5275 | static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) { |
| 5276 | return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm"); |
| 5277 | } |
Chad Rosier | 9f7a221 | 2013-04-18 22:35:36 +0000 | [diff] [blame] | 5278 | static void applyMnemonicAliases(StringRef &Mnemonic, unsigned Features, |
| 5279 | unsigned VariantID); |
Saleem Abdulrasool | e3a9dc1 | 2013-12-30 18:38:01 +0000 | [diff] [blame] | 5280 | |
| 5281 | static bool RequiresVFPRegListValidation(StringRef Inst, |
| 5282 | bool &AcceptSinglePrecisionOnly, |
| 5283 | bool &AcceptDoublePrecisionOnly) { |
| 5284 | if (Inst.size() < 7) |
| 5285 | return false; |
| 5286 | |
| 5287 | if (Inst.startswith("fldm") || Inst.startswith("fstm")) { |
| 5288 | StringRef AddressingMode = Inst.substr(4, 2); |
| 5289 | if (AddressingMode == "ia" || AddressingMode == "db" || |
| 5290 | AddressingMode == "ea" || AddressingMode == "fd") { |
| 5291 | AcceptSinglePrecisionOnly = Inst[6] == 's'; |
| 5292 | AcceptDoublePrecisionOnly = Inst[6] == 'd' || Inst[6] == 'x'; |
| 5293 | return true; |
| 5294 | } |
| 5295 | } |
| 5296 | |
| 5297 | return false; |
| 5298 | } |
| 5299 | |
Daniel Dunbar | 876bb018 | 2011-01-10 12:24:52 +0000 | [diff] [blame] | 5300 | /// Parse an arm instruction mnemonic followed by its operands. |
Chad Rosier | f0e8720 | 2012-10-25 20:41:34 +0000 | [diff] [blame] | 5301 | bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name, |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5302 | SMLoc NameLoc, OperandVector &Operands) { |
Saleem Abdulrasool | 4da9c6e | 2013-12-29 17:58:35 +0000 | [diff] [blame] | 5303 | // FIXME: Can this be done via tablegen in some fashion? |
Saleem Abdulrasool | e3a9dc1 | 2013-12-30 18:38:01 +0000 | [diff] [blame] | 5304 | bool RequireVFPRegisterListCheck; |
Saleem Abdulrasool | 4da9c6e | 2013-12-29 17:58:35 +0000 | [diff] [blame] | 5305 | bool AcceptSinglePrecisionOnly; |
Saleem Abdulrasool | e3a9dc1 | 2013-12-30 18:38:01 +0000 | [diff] [blame] | 5306 | bool AcceptDoublePrecisionOnly; |
| 5307 | RequireVFPRegisterListCheck = |
| 5308 | RequiresVFPRegListValidation(Name, AcceptSinglePrecisionOnly, |
| 5309 | AcceptDoublePrecisionOnly); |
Saleem Abdulrasool | 4da9c6e | 2013-12-29 17:58:35 +0000 | [diff] [blame] | 5310 | |
Jim Grosbach | 8be2f65 | 2011-12-09 23:34:09 +0000 | [diff] [blame] | 5311 | // Apply mnemonic aliases before doing anything else, as the destination |
Saleem Abdulrasool | a1937cb | 2013-12-29 17:58:31 +0000 | [diff] [blame] | 5312 | // mnemonic may include suffices and we want to handle them normally. |
Jim Grosbach | 8be2f65 | 2011-12-09 23:34:09 +0000 | [diff] [blame] | 5313 | // The generic tblgen'erated code does this later, at the start of |
| 5314 | // MatchInstructionImpl(), but that's too late for aliases that include |
| 5315 | // any sort of suffix. |
| 5316 | unsigned AvailableFeatures = getAvailableFeatures(); |
Chad Rosier | 9f7a221 | 2013-04-18 22:35:36 +0000 | [diff] [blame] | 5317 | unsigned AssemblerDialect = getParser().getAssemblerDialect(); |
| 5318 | applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect); |
Jim Grosbach | 8be2f65 | 2011-12-09 23:34:09 +0000 | [diff] [blame] | 5319 | |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 5320 | // First check for the ARM-specific .req directive. |
| 5321 | if (Parser.getTok().is(AsmToken::Identifier) && |
| 5322 | Parser.getTok().getIdentifier() == ".req") { |
| 5323 | parseDirectiveReq(Name, NameLoc); |
| 5324 | // We always return 'error' for this, as we're done with this |
| 5325 | // statement and don't need to match the 'instruction." |
| 5326 | return true; |
| 5327 | } |
| 5328 | |
Daniel Dunbar | 876bb018 | 2011-01-10 12:24:52 +0000 | [diff] [blame] | 5329 | // Create the leading tokens for the mnemonic, split by '.' characters. |
| 5330 | size_t Start = 0, Next = Name.find('.'); |
Jim Grosbach | 7c09e3c | 2011-07-19 19:13:28 +0000 | [diff] [blame] | 5331 | StringRef Mnemonic = Name.slice(Start, Next); |
Daniel Dunbar | 876bb018 | 2011-01-10 12:24:52 +0000 | [diff] [blame] | 5332 | |
Daniel Dunbar | 9d944b3 | 2011-01-11 15:59:50 +0000 | [diff] [blame] | 5333 | // Split out the predication code and carry setting flag from the mnemonic. |
| 5334 | unsigned PredicationCode; |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 5335 | unsigned ProcessorIMod; |
Daniel Dunbar | 9d944b3 | 2011-01-11 15:59:50 +0000 | [diff] [blame] | 5336 | bool CarrySetting; |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 5337 | StringRef ITMask; |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 5338 | Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting, |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 5339 | ProcessorIMod, ITMask); |
Daniel Dunbar | 876bb018 | 2011-01-10 12:24:52 +0000 | [diff] [blame] | 5340 | |
Jim Grosbach | 1c171b1 | 2011-08-25 17:23:55 +0000 | [diff] [blame] | 5341 | // In Thumb1, only the branch (B) instruction can be predicated. |
| 5342 | if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") { |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 5343 | Parser.eatToEndOfStatement(); |
Jim Grosbach | 1c171b1 | 2011-08-25 17:23:55 +0000 | [diff] [blame] | 5344 | return Error(NameLoc, "conditional execution not supported in Thumb1"); |
| 5345 | } |
| 5346 | |
Jim Grosbach | 7c09e3c | 2011-07-19 19:13:28 +0000 | [diff] [blame] | 5347 | Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc)); |
| 5348 | |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 5349 | // Handle the IT instruction ITMask. Convert it to a bitmask. This |
| 5350 | // is the mask as it will be for the IT encoding if the conditional |
| 5351 | // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case |
| 5352 | // where the conditional bit0 is zero, the instruction post-processing |
| 5353 | // will adjust the mask accordingly. |
| 5354 | if (Mnemonic == "it") { |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5355 | SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2); |
| 5356 | if (ITMask.size() > 3) { |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 5357 | Parser.eatToEndOfStatement(); |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5358 | return Error(Loc, "too many conditions on IT instruction"); |
| 5359 | } |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 5360 | unsigned Mask = 8; |
| 5361 | for (unsigned i = ITMask.size(); i != 0; --i) { |
| 5362 | char pos = ITMask[i - 1]; |
| 5363 | if (pos != 't' && pos != 'e') { |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 5364 | Parser.eatToEndOfStatement(); |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5365 | return Error(Loc, "illegal IT block condition mask '" + ITMask + "'"); |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 5366 | } |
| 5367 | Mask >>= 1; |
| 5368 | if (ITMask[i - 1] == 't') |
| 5369 | Mask |= 8; |
| 5370 | } |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5371 | Operands.push_back(ARMOperand::CreateITMask(Mask, Loc)); |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 5372 | } |
| 5373 | |
Jim Grosbach | 7c09e3c | 2011-07-19 19:13:28 +0000 | [diff] [blame] | 5374 | // FIXME: This is all a pretty gross hack. We should automatically handle |
| 5375 | // optional operands like this via tblgen. |
Bill Wendling | 219dabd | 2010-11-21 10:56:05 +0000 | [diff] [blame] | 5376 | |
Daniel Dunbar | 5a384c8 | 2011-01-11 15:59:53 +0000 | [diff] [blame] | 5377 | // Next, add the CCOut and ConditionCode operands, if needed. |
| 5378 | // |
| 5379 | // For mnemonics which can ever incorporate a carry setting bit or predication |
| 5380 | // code, our matching model involves us always generating CCOut and |
| 5381 | // ConditionCode operands to match the mnemonic "as written" and then we let |
| 5382 | // the matcher deal with finding the right instruction or generating an |
| 5383 | // appropriate error. |
| 5384 | bool CanAcceptCarrySet, CanAcceptPredicationCode; |
Amara Emerson | 3308909 | 2013-09-19 11:59:01 +0000 | [diff] [blame] | 5385 | getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode); |
Daniel Dunbar | 5a384c8 | 2011-01-11 15:59:53 +0000 | [diff] [blame] | 5386 | |
Jim Grosbach | 03a8a16 | 2011-07-14 22:04:21 +0000 | [diff] [blame] | 5387 | // If we had a carry-set on an instruction that can't do that, issue an |
| 5388 | // error. |
| 5389 | if (!CanAcceptCarrySet && CarrySetting) { |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 5390 | Parser.eatToEndOfStatement(); |
Jim Grosbach | 7c09e3c | 2011-07-19 19:13:28 +0000 | [diff] [blame] | 5391 | return Error(NameLoc, "instruction '" + Mnemonic + |
Jim Grosbach | 03a8a16 | 2011-07-14 22:04:21 +0000 | [diff] [blame] | 5392 | "' can not set flags, but 's' suffix specified"); |
| 5393 | } |
Jim Grosbach | 0a54770 | 2011-07-22 17:44:50 +0000 | [diff] [blame] | 5394 | // If we had a predication code on an instruction that can't do that, issue an |
| 5395 | // error. |
| 5396 | if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) { |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 5397 | Parser.eatToEndOfStatement(); |
Jim Grosbach | 0a54770 | 2011-07-22 17:44:50 +0000 | [diff] [blame] | 5398 | return Error(NameLoc, "instruction '" + Mnemonic + |
| 5399 | "' is not predicable, but condition code specified"); |
| 5400 | } |
Jim Grosbach | 03a8a16 | 2011-07-14 22:04:21 +0000 | [diff] [blame] | 5401 | |
Daniel Dunbar | 5a384c8 | 2011-01-11 15:59:53 +0000 | [diff] [blame] | 5402 | // Add the carry setting operand, if necessary. |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5403 | if (CanAcceptCarrySet) { |
| 5404 | SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size()); |
Daniel Dunbar | 5a384c8 | 2011-01-11 15:59:53 +0000 | [diff] [blame] | 5405 | Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0, |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5406 | Loc)); |
| 5407 | } |
Daniel Dunbar | 5a384c8 | 2011-01-11 15:59:53 +0000 | [diff] [blame] | 5408 | |
| 5409 | // Add the predication code operand, if necessary. |
| 5410 | if (CanAcceptPredicationCode) { |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5411 | SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() + |
| 5412 | CarrySetting); |
Daniel Dunbar | 5a384c8 | 2011-01-11 15:59:53 +0000 | [diff] [blame] | 5413 | Operands.push_back(ARMOperand::CreateCondCode( |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5414 | ARMCC::CondCodes(PredicationCode), Loc)); |
Daniel Dunbar | 876bb018 | 2011-01-10 12:24:52 +0000 | [diff] [blame] | 5415 | } |
Daniel Dunbar | 188b47b | 2010-08-11 06:37:20 +0000 | [diff] [blame] | 5416 | |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 5417 | // Add the processor imod operand, if necessary. |
| 5418 | if (ProcessorIMod) { |
| 5419 | Operands.push_back(ARMOperand::CreateImm( |
| 5420 | MCConstantExpr::Create(ProcessorIMod, getContext()), |
| 5421 | NameLoc, NameLoc)); |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 5422 | } |
| 5423 | |
Daniel Dunbar | 188b47b | 2010-08-11 06:37:20 +0000 | [diff] [blame] | 5424 | // Add the remaining tokens in the mnemonic. |
Daniel Dunbar | 75d26be | 2010-08-11 06:37:16 +0000 | [diff] [blame] | 5425 | while (Next != StringRef::npos) { |
| 5426 | Start = Next; |
| 5427 | Next = Name.find('.', Start + 1); |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 5428 | StringRef ExtraToken = Name.slice(Start, Next); |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 5429 | |
Jim Grosbach | 12952fe | 2011-11-11 23:08:10 +0000 | [diff] [blame] | 5430 | // Some NEON instructions have an optional datatype suffix that is |
| 5431 | // completely ignored. Check for that. |
| 5432 | if (isDataTypeToken(ExtraToken) && |
| 5433 | doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken)) |
| 5434 | continue; |
| 5435 | |
Kevin Enderby | c5d0935 | 2013-06-18 20:19:24 +0000 | [diff] [blame] | 5436 | // For for ARM mode generate an error if the .n qualifier is used. |
| 5437 | if (ExtraToken == ".n" && !isThumb()) { |
| 5438 | SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start); |
Saleem Abdulrasool | bdae4b8 | 2014-01-12 05:25:44 +0000 | [diff] [blame] | 5439 | Parser.eatToEndOfStatement(); |
Kevin Enderby | c5d0935 | 2013-06-18 20:19:24 +0000 | [diff] [blame] | 5440 | return Error(Loc, "instruction with .n (narrow) qualifier not allowed in " |
| 5441 | "arm mode"); |
| 5442 | } |
| 5443 | |
| 5444 | // The .n qualifier is always discarded as that is what the tables |
| 5445 | // and matcher expect. In ARM mode the .w qualifier has no effect, |
| 5446 | // so discard it to avoid errors that can be caused by the matcher. |
| 5447 | if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) { |
Jim Grosbach | 39c6e1d | 2011-09-07 16:06:04 +0000 | [diff] [blame] | 5448 | SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start); |
| 5449 | Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc)); |
| 5450 | } |
Daniel Dunbar | 75d26be | 2010-08-11 06:37:16 +0000 | [diff] [blame] | 5451 | } |
| 5452 | |
| 5453 | // Read the remaining operands. |
| 5454 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 5455 | // Read the first operand. |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 5456 | if (parseOperand(Operands, Mnemonic)) { |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 5457 | Parser.eatToEndOfStatement(); |
Chris Lattner | a2a9d16 | 2010-09-11 16:18:25 +0000 | [diff] [blame] | 5458 | return true; |
| 5459 | } |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 5460 | |
| 5461 | while (getLexer().is(AsmToken::Comma)) { |
Sean Callanan | a83fd7d | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 5462 | Parser.Lex(); // Eat the comma. |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 5463 | |
| 5464 | // Parse and remember the operand. |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 5465 | if (parseOperand(Operands, Mnemonic)) { |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 5466 | Parser.eatToEndOfStatement(); |
Chris Lattner | a2a9d16 | 2010-09-11 16:18:25 +0000 | [diff] [blame] | 5467 | return true; |
| 5468 | } |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 5469 | } |
| 5470 | } |
Jim Grosbach | 624bcc7 | 2010-10-29 14:46:02 +0000 | [diff] [blame] | 5471 | |
Chris Lattner | a2a9d16 | 2010-09-11 16:18:25 +0000 | [diff] [blame] | 5472 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
Jim Grosbach | b8d9f51 | 2011-10-07 18:27:04 +0000 | [diff] [blame] | 5473 | SMLoc Loc = getLexer().getLoc(); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 5474 | Parser.eatToEndOfStatement(); |
Jim Grosbach | b8d9f51 | 2011-10-07 18:27:04 +0000 | [diff] [blame] | 5475 | return Error(Loc, "unexpected token in argument list"); |
Chris Lattner | a2a9d16 | 2010-09-11 16:18:25 +0000 | [diff] [blame] | 5476 | } |
Bill Wendling | ee7f1f9 | 2010-11-06 21:42:12 +0000 | [diff] [blame] | 5477 | |
Chris Lattner | 91689c1 | 2010-09-08 05:10:46 +0000 | [diff] [blame] | 5478 | Parser.Lex(); // Consume the EndOfStatement |
Jim Grosbach | 7c09e3c | 2011-07-19 19:13:28 +0000 | [diff] [blame] | 5479 | |
Saleem Abdulrasool | e3a9dc1 | 2013-12-30 18:38:01 +0000 | [diff] [blame] | 5480 | if (RequireVFPRegisterListCheck) { |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5481 | ARMOperand &Op = static_cast<ARMOperand &>(*Operands.back()); |
| 5482 | if (AcceptSinglePrecisionOnly && !Op.isSPRRegList()) |
| 5483 | return Error(Op.getStartLoc(), |
Saleem Abdulrasool | aca443c | 2013-12-29 18:53:16 +0000 | [diff] [blame] | 5484 | "VFP/Neon single precision register expected"); |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5485 | if (AcceptDoublePrecisionOnly && !Op.isDPRRegList()) |
| 5486 | return Error(Op.getStartLoc(), |
Saleem Abdulrasool | aca443c | 2013-12-29 18:53:16 +0000 | [diff] [blame] | 5487 | "VFP/Neon double precision register expected"); |
Saleem Abdulrasool | 4da9c6e | 2013-12-29 17:58:35 +0000 | [diff] [blame] | 5488 | } |
| 5489 | |
Jim Grosbach | 7283da9 | 2011-08-16 21:12:37 +0000 | [diff] [blame] | 5490 | // Some instructions, mostly Thumb, have forms for the same mnemonic that |
| 5491 | // do and don't have a cc_out optional-def operand. With some spot-checks |
| 5492 | // of the operand list, we can figure out which variant we're trying to |
Jim Grosbach | 1d3c137 | 2011-09-01 00:28:52 +0000 | [diff] [blame] | 5493 | // parse and adjust accordingly before actually matching. We shouldn't ever |
| 5494 | // try to remove a cc_out operand that was explicitly set on the the |
| 5495 | // mnemonic, of course (CarrySetting == true). Reason number #317 the |
| 5496 | // table driven matcher doesn't fit well with the ARM instruction set. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5497 | if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) |
Jim Grosbach | 7c09e3c | 2011-07-19 19:13:28 +0000 | [diff] [blame] | 5498 | Operands.erase(Operands.begin() + 1); |
Jim Grosbach | 7c09e3c | 2011-07-19 19:13:28 +0000 | [diff] [blame] | 5499 | |
Joey Gouly | e860255 | 2013-07-19 16:34:16 +0000 | [diff] [blame] | 5500 | // Some instructions have the same mnemonic, but don't always |
| 5501 | // have a predicate. Distinguish them here and delete the |
| 5502 | // predicate if needed. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5503 | if (shouldOmitPredicateOperand(Mnemonic, Operands)) |
Joey Gouly | e860255 | 2013-07-19 16:34:16 +0000 | [diff] [blame] | 5504 | Operands.erase(Operands.begin() + 1); |
Joey Gouly | e860255 | 2013-07-19 16:34:16 +0000 | [diff] [blame] | 5505 | |
Jim Grosbach | a03ab0e | 2011-07-28 21:57:55 +0000 | [diff] [blame] | 5506 | // ARM mode 'blx' need special handling, as the register operand version |
| 5507 | // is predicable, but the label operand version is not. So, we can't rely |
| 5508 | // on the Mnemonic based checking to correctly figure out when to put |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 5509 | // a k_CondCode operand in the list. If we're trying to match the label |
| 5510 | // version, remove the k_CondCode operand here. |
Jim Grosbach | a03ab0e | 2011-07-28 21:57:55 +0000 | [diff] [blame] | 5511 | if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5512 | static_cast<ARMOperand &>(*Operands[2]).isImm()) |
Jim Grosbach | a03ab0e | 2011-07-28 21:57:55 +0000 | [diff] [blame] | 5513 | Operands.erase(Operands.begin() + 1); |
Jim Grosbach | 8cffa28 | 2011-08-11 23:51:13 +0000 | [diff] [blame] | 5514 | |
Weiming Zhao | 8f56f88 | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 5515 | // Adjust operands of ldrexd/strexd to MCK_GPRPair. |
| 5516 | // ldrexd/strexd require even/odd GPR pair. To enforce this constraint, |
| 5517 | // a single GPRPair reg operand is used in the .td file to replace the two |
| 5518 | // GPRs. However, when parsing from asm, the two GRPs cannot be automatically |
| 5519 | // expressed as a GPRPair, so we have to manually merge them. |
| 5520 | // FIXME: We would really like to be able to tablegen'erate this. |
| 5521 | if (!isThumb() && Operands.size() > 4 && |
Joey Gouly | e6d165c | 2013-08-27 17:38:16 +0000 | [diff] [blame] | 5522 | (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" || |
| 5523 | Mnemonic == "stlexd")) { |
| 5524 | bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd"); |
Weiming Zhao | 8f56f88 | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 5525 | unsigned Idx = isLoad ? 2 : 3; |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5526 | ARMOperand &Op1 = static_cast<ARMOperand &>(*Operands[Idx]); |
| 5527 | ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[Idx + 1]); |
Weiming Zhao | 8f56f88 | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 5528 | |
| 5529 | const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID); |
| 5530 | // Adjust only if Op1 and Op2 are GPRs. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5531 | if (Op1.isReg() && Op2.isReg() && MRC.contains(Op1.getReg()) && |
| 5532 | MRC.contains(Op2.getReg())) { |
| 5533 | unsigned Reg1 = Op1.getReg(); |
| 5534 | unsigned Reg2 = Op2.getReg(); |
Weiming Zhao | 8f56f88 | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 5535 | unsigned Rt = MRI->getEncodingValue(Reg1); |
| 5536 | unsigned Rt2 = MRI->getEncodingValue(Reg2); |
| 5537 | |
| 5538 | // Rt2 must be Rt + 1 and Rt must be even. |
| 5539 | if (Rt + 1 != Rt2 || (Rt & 1)) { |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5540 | Error(Op2.getStartLoc(), isLoad |
| 5541 | ? "destination operands must be sequential" |
| 5542 | : "source operands must be sequential"); |
Weiming Zhao | 8f56f88 | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 5543 | return true; |
| 5544 | } |
| 5545 | unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0, |
| 5546 | &(MRI->getRegClass(ARM::GPRPairRegClassID))); |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5547 | Operands[Idx] = |
| 5548 | ARMOperand::CreateReg(NewReg, Op1.getStartLoc(), Op2.getEndLoc()); |
| 5549 | Operands.erase(Operands.begin() + Idx + 1); |
Weiming Zhao | 8f56f88 | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 5550 | } |
| 5551 | } |
| 5552 | |
Saleem Abdulrasool | e6e6d71 | 2014-01-10 04:38:35 +0000 | [diff] [blame] | 5553 | // GNU Assembler extension (compatibility) |
Stepan Dyatkovskiy | 3f1fa3d | 2014-04-04 10:17:56 +0000 | [diff] [blame] | 5554 | if ((Mnemonic == "ldrd" || Mnemonic == "strd")) { |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5555 | ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[2]); |
| 5556 | ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]); |
| 5557 | if (Op3.isMem()) { |
| 5558 | assert(Op2.isReg() && "expected register argument"); |
Stepan Dyatkovskiy | 6207a4d | 2014-04-03 11:29:15 +0000 | [diff] [blame] | 5559 | |
Stepan Dyatkovskiy | 3f1fa3d | 2014-04-04 10:17:56 +0000 | [diff] [blame] | 5560 | unsigned SuperReg = MRI->getMatchingSuperReg( |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5561 | Op2.getReg(), ARM::gsub_0, &MRI->getRegClass(ARM::GPRPairRegClassID)); |
Stepan Dyatkovskiy | 6207a4d | 2014-04-03 11:29:15 +0000 | [diff] [blame] | 5562 | |
Stepan Dyatkovskiy | 3f1fa3d | 2014-04-04 10:17:56 +0000 | [diff] [blame] | 5563 | assert(SuperReg && "expected register pair"); |
Stepan Dyatkovskiy | 6207a4d | 2014-04-03 11:29:15 +0000 | [diff] [blame] | 5564 | |
Stepan Dyatkovskiy | 3f1fa3d | 2014-04-04 10:17:56 +0000 | [diff] [blame] | 5565 | unsigned PairedReg = MRI->getSubReg(SuperReg, ARM::gsub_1); |
Stepan Dyatkovskiy | 6207a4d | 2014-04-03 11:29:15 +0000 | [diff] [blame] | 5566 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5567 | Operands.insert( |
| 5568 | Operands.begin() + 3, |
| 5569 | ARMOperand::CreateReg(PairedReg, Op2.getStartLoc(), Op2.getEndLoc())); |
Stepan Dyatkovskiy | 3f1fa3d | 2014-04-04 10:17:56 +0000 | [diff] [blame] | 5570 | } |
Saleem Abdulrasool | e6e6d71 | 2014-01-10 04:38:35 +0000 | [diff] [blame] | 5571 | } |
| 5572 | |
Kevin Enderby | 78f9572 | 2013-07-31 21:05:30 +0000 | [diff] [blame] | 5573 | // FIXME: As said above, this is all a pretty gross hack. This instruction |
| 5574 | // does not fit with other "subs" and tblgen. |
| 5575 | // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction |
| 5576 | // so the Mnemonic is the original name "subs" and delete the predicate |
| 5577 | // operand so it will match the table entry. |
| 5578 | if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5579 | static_cast<ARMOperand &>(*Operands[3]).isReg() && |
| 5580 | static_cast<ARMOperand &>(*Operands[3]).getReg() == ARM::PC && |
| 5581 | static_cast<ARMOperand &>(*Operands[4]).isReg() && |
| 5582 | static_cast<ARMOperand &>(*Operands[4]).getReg() == ARM::LR && |
| 5583 | static_cast<ARMOperand &>(*Operands[5]).isImm()) { |
| 5584 | Operands.front() = ARMOperand::CreateToken(Name, NameLoc); |
Kevin Enderby | 78f9572 | 2013-07-31 21:05:30 +0000 | [diff] [blame] | 5585 | Operands.erase(Operands.begin() + 1); |
Kevin Enderby | 78f9572 | 2013-07-31 21:05:30 +0000 | [diff] [blame] | 5586 | } |
Chris Lattner | f29c0b6 | 2010-01-14 22:21:20 +0000 | [diff] [blame] | 5587 | return false; |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 5588 | } |
| 5589 | |
Jim Grosbach | edaa35a | 2011-07-26 18:25:39 +0000 | [diff] [blame] | 5590 | // Validate context-sensitive operand constraints. |
Jim Grosbach | 169b2be | 2011-08-23 18:13:04 +0000 | [diff] [blame] | 5591 | |
| 5592 | // return 'true' if register list contains non-low GPR registers, |
| 5593 | // 'false' otherwise. If Reg is in the register list or is HiReg, set |
| 5594 | // 'containsReg' to true. |
| 5595 | static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg, |
| 5596 | unsigned HiReg, bool &containsReg) { |
| 5597 | containsReg = false; |
| 5598 | for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) { |
| 5599 | unsigned OpReg = Inst.getOperand(i).getReg(); |
| 5600 | if (OpReg == Reg) |
| 5601 | containsReg = true; |
| 5602 | // Anything other than a low register isn't legal here. |
| 5603 | if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg)) |
| 5604 | return true; |
| 5605 | } |
| 5606 | return false; |
| 5607 | } |
| 5608 | |
Jim Grosbach | a31f223 | 2011-09-07 18:05:34 +0000 | [diff] [blame] | 5609 | // Check if the specified regisgter is in the register list of the inst, |
| 5610 | // starting at the indicated operand number. |
| 5611 | static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) { |
| 5612 | for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) { |
| 5613 | unsigned OpReg = Inst.getOperand(i).getReg(); |
| 5614 | if (OpReg == Reg) |
| 5615 | return true; |
| 5616 | } |
| 5617 | return false; |
| 5618 | } |
| 5619 | |
Richard Barton | 8d519fe | 2013-09-05 14:14:19 +0000 | [diff] [blame] | 5620 | // Return true if instruction has the interesting property of being |
| 5621 | // allowed in IT blocks, but not being predicable. |
| 5622 | static bool instIsBreakpoint(const MCInst &Inst) { |
| 5623 | return Inst.getOpcode() == ARM::tBKPT || |
| 5624 | Inst.getOpcode() == ARM::BKPT || |
| 5625 | Inst.getOpcode() == ARM::tHLT || |
| 5626 | Inst.getOpcode() == ARM::HLT; |
| 5627 | |
| 5628 | } |
| 5629 | |
Jim Grosbach | edaa35a | 2011-07-26 18:25:39 +0000 | [diff] [blame] | 5630 | // FIXME: We would really like to be able to tablegen'erate this. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5631 | bool ARMAsmParser::validateInstruction(MCInst &Inst, |
| 5632 | const OperandVector &Operands) { |
Joey Gouly | 0e76fa7 | 2013-09-12 10:28:05 +0000 | [diff] [blame] | 5633 | const MCInstrDesc &MCID = MII.get(Inst.getOpcode()); |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5634 | SMLoc Loc = Operands[0]->getStartLoc(); |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 5635 | |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5636 | // Check the IT block state first. |
Richard Barton | 8d519fe | 2013-09-05 14:14:19 +0000 | [diff] [blame] | 5637 | // NOTE: BKPT and HLT instructions have the interesting property of being |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 5638 | // allowed in IT blocks, but not being predicable. They just always execute. |
Richard Barton | 8d519fe | 2013-09-05 14:14:19 +0000 | [diff] [blame] | 5639 | if (inITBlock() && !instIsBreakpoint(Inst)) { |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 5640 | unsigned Bit = 1; |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5641 | if (ITState.FirstCond) |
| 5642 | ITState.FirstCond = false; |
| 5643 | else |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 5644 | Bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1; |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5645 | // The instruction must be predicable. |
| 5646 | if (!MCID.isPredicable()) |
| 5647 | return Error(Loc, "instructions in IT block must be predicable"); |
| 5648 | unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm(); |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 5649 | unsigned ITCond = Bit ? ITState.Cond : |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5650 | ARMCC::getOppositeCondition(ITState.Cond); |
| 5651 | if (Cond != ITCond) { |
| 5652 | // Find the condition code Operand to get its SMLoc information. |
| 5653 | SMLoc CondLoc; |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 5654 | for (unsigned I = 1; I < Operands.size(); ++I) |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5655 | if (static_cast<ARMOperand &>(*Operands[I]).isCondCode()) |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 5656 | CondLoc = Operands[I]->getStartLoc(); |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5657 | return Error(CondLoc, "incorrect condition in IT block; got '" + |
| 5658 | StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) + |
| 5659 | "', but expected '" + |
| 5660 | ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'"); |
| 5661 | } |
Jim Grosbach | c61fc8f | 2011-08-31 18:29:05 +0000 | [diff] [blame] | 5662 | // Check for non-'al' condition codes outside of the IT block. |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5663 | } else if (isThumbTwo() && MCID.isPredicable() && |
| 5664 | Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() != |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 5665 | ARMCC::AL && Inst.getOpcode() != ARM::tBcc && |
| 5666 | Inst.getOpcode() != ARM::t2Bcc) |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5667 | return Error(Loc, "predicated instructions must be in IT block"); |
| 5668 | |
Tilmann Scheller | 255722b | 2013-09-30 16:11:48 +0000 | [diff] [blame] | 5669 | const unsigned Opcode = Inst.getOpcode(); |
| 5670 | switch (Opcode) { |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 5671 | case ARM::LDRD: |
| 5672 | case ARM::LDRD_PRE: |
Weiming Zhao | 8f56f88 | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 5673 | case ARM::LDRD_POST: { |
Tilmann Scheller | 255722b | 2013-09-30 16:11:48 +0000 | [diff] [blame] | 5674 | const unsigned RtReg = Inst.getOperand(0).getReg(); |
| 5675 | |
Tilmann Scheller | 1aebfa0 | 2013-09-27 13:28:17 +0000 | [diff] [blame] | 5676 | // Rt can't be R14. |
| 5677 | if (RtReg == ARM::LR) |
| 5678 | return Error(Operands[3]->getStartLoc(), |
| 5679 | "Rt can't be R14"); |
Tilmann Scheller | 255722b | 2013-09-30 16:11:48 +0000 | [diff] [blame] | 5680 | |
| 5681 | const unsigned Rt = MRI->getEncodingValue(RtReg); |
Tilmann Scheller | 1aebfa0 | 2013-09-27 13:28:17 +0000 | [diff] [blame] | 5682 | // Rt must be even-numbered. |
| 5683 | if ((Rt & 1) == 1) |
| 5684 | return Error(Operands[3]->getStartLoc(), |
| 5685 | "Rt must be even-numbered"); |
Tilmann Scheller | 255722b | 2013-09-30 16:11:48 +0000 | [diff] [blame] | 5686 | |
Jim Grosbach | edaa35a | 2011-07-26 18:25:39 +0000 | [diff] [blame] | 5687 | // Rt2 must be Rt + 1. |
Tilmann Scheller | 255722b | 2013-09-30 16:11:48 +0000 | [diff] [blame] | 5688 | const unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg()); |
Jim Grosbach | edaa35a | 2011-07-26 18:25:39 +0000 | [diff] [blame] | 5689 | if (Rt2 != Rt + 1) |
| 5690 | return Error(Operands[3]->getStartLoc(), |
| 5691 | "destination operands must be sequential"); |
Tilmann Scheller | 255722b | 2013-09-30 16:11:48 +0000 | [diff] [blame] | 5692 | |
| 5693 | if (Opcode == ARM::LDRD_PRE || Opcode == ARM::LDRD_POST) { |
| 5694 | const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg()); |
| 5695 | // For addressing modes with writeback, the base register needs to be |
| 5696 | // different from the destination registers. |
| 5697 | if (Rn == Rt || Rn == Rt2) |
| 5698 | return Error(Operands[3]->getStartLoc(), |
| 5699 | "base register needs to be different from destination " |
| 5700 | "registers"); |
| 5701 | } |
| 5702 | |
Jim Grosbach | edaa35a | 2011-07-26 18:25:39 +0000 | [diff] [blame] | 5703 | return false; |
| 5704 | } |
Tilmann Scheller | 88c8f16 | 2013-09-27 10:30:18 +0000 | [diff] [blame] | 5705 | case ARM::t2LDRDi8: |
| 5706 | case ARM::t2LDRD_PRE: |
| 5707 | case ARM::t2LDRD_POST: { |
Tilmann Scheller | 041f717 | 2013-09-27 10:38:11 +0000 | [diff] [blame] | 5708 | // Rt2 must be different from Rt. |
Tilmann Scheller | 88c8f16 | 2013-09-27 10:30:18 +0000 | [diff] [blame] | 5709 | unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg()); |
| 5710 | unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg()); |
| 5711 | if (Rt2 == Rt) |
| 5712 | return Error(Operands[3]->getStartLoc(), |
| 5713 | "destination operands can't be identical"); |
| 5714 | return false; |
| 5715 | } |
Jim Grosbach | eb09f49 | 2011-08-11 20:28:23 +0000 | [diff] [blame] | 5716 | case ARM::STRD: { |
| 5717 | // Rt2 must be Rt + 1. |
Eric Christopher | 6ac277c | 2012-08-09 22:10:21 +0000 | [diff] [blame] | 5718 | unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg()); |
| 5719 | unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg()); |
Jim Grosbach | eb09f49 | 2011-08-11 20:28:23 +0000 | [diff] [blame] | 5720 | if (Rt2 != Rt + 1) |
| 5721 | return Error(Operands[3]->getStartLoc(), |
| 5722 | "source operands must be sequential"); |
| 5723 | return false; |
| 5724 | } |
Jim Grosbach | f7164b2 | 2011-08-10 20:49:18 +0000 | [diff] [blame] | 5725 | case ARM::STRD_PRE: |
Weiming Zhao | 8f56f88 | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 5726 | case ARM::STRD_POST: { |
Jim Grosbach | edaa35a | 2011-07-26 18:25:39 +0000 | [diff] [blame] | 5727 | // Rt2 must be Rt + 1. |
Eric Christopher | 6ac277c | 2012-08-09 22:10:21 +0000 | [diff] [blame] | 5728 | unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg()); |
| 5729 | unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg()); |
Jim Grosbach | edaa35a | 2011-07-26 18:25:39 +0000 | [diff] [blame] | 5730 | if (Rt2 != Rt + 1) |
Jim Grosbach | eb09f49 | 2011-08-11 20:28:23 +0000 | [diff] [blame] | 5731 | return Error(Operands[3]->getStartLoc(), |
Jim Grosbach | edaa35a | 2011-07-26 18:25:39 +0000 | [diff] [blame] | 5732 | "source operands must be sequential"); |
| 5733 | return false; |
| 5734 | } |
Tilmann Scheller | 3352a58 | 2014-07-23 12:38:17 +0000 | [diff] [blame] | 5735 | case ARM::STR_PRE_IMM: |
| 5736 | case ARM::STR_PRE_REG: |
| 5737 | case ARM::STR_POST_IMM: |
Tilmann Scheller | 2727279 | 2014-07-23 13:03:47 +0000 | [diff] [blame] | 5738 | case ARM::STR_POST_REG: |
Tilmann Scheller | 96ef72e | 2014-07-24 09:55:46 +0000 | [diff] [blame] | 5739 | case ARM::STRH_PRE: |
| 5740 | case ARM::STRH_POST: |
Tilmann Scheller | 2727279 | 2014-07-23 13:03:47 +0000 | [diff] [blame] | 5741 | case ARM::STRB_PRE_IMM: |
| 5742 | case ARM::STRB_PRE_REG: |
| 5743 | case ARM::STRB_POST_IMM: |
| 5744 | case ARM::STRB_POST_REG: { |
Tilmann Scheller | 3352a58 | 2014-07-23 12:38:17 +0000 | [diff] [blame] | 5745 | // Rt must be different from Rn. |
| 5746 | const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg()); |
| 5747 | const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(2).getReg()); |
| 5748 | |
| 5749 | if (Rt == Rn) |
| 5750 | return Error(Operands[3]->getStartLoc(), |
| 5751 | "source register and base register can't be identical"); |
| 5752 | return false; |
| 5753 | } |
Tilmann Scheller | 8ba7430 | 2014-08-01 11:08:51 +0000 | [diff] [blame] | 5754 | case ARM::LDR_PRE_IMM: |
| 5755 | case ARM::LDR_PRE_REG: |
| 5756 | case ARM::LDR_POST_IMM: |
Tilmann Scheller | 8ff079c | 2014-08-01 11:33:47 +0000 | [diff] [blame] | 5757 | case ARM::LDR_POST_REG: |
| 5758 | case ARM::LDRH_PRE: |
| 5759 | case ARM::LDRH_POST: |
| 5760 | case ARM::LDRSH_PRE: |
Tilmann Scheller | 7cc0ed4 | 2014-08-01 12:08:04 +0000 | [diff] [blame] | 5761 | case ARM::LDRSH_POST: |
| 5762 | case ARM::LDRB_PRE_IMM: |
| 5763 | case ARM::LDRB_PRE_REG: |
| 5764 | case ARM::LDRB_POST_IMM: |
| 5765 | case ARM::LDRB_POST_REG: |
| 5766 | case ARM::LDRSB_PRE: |
| 5767 | case ARM::LDRSB_POST: { |
Tilmann Scheller | 8ba7430 | 2014-08-01 11:08:51 +0000 | [diff] [blame] | 5768 | // Rt must be different from Rn. |
| 5769 | const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg()); |
| 5770 | const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(2).getReg()); |
| 5771 | |
| 5772 | if (Rt == Rn) |
| 5773 | return Error(Operands[3]->getStartLoc(), |
| 5774 | "destination register and base register can't be identical"); |
| 5775 | return false; |
| 5776 | } |
Jim Grosbach | 03f56d9 | 2011-07-27 21:09:25 +0000 | [diff] [blame] | 5777 | case ARM::SBFX: |
| 5778 | case ARM::UBFX: { |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 5779 | // Width must be in range [1, 32-lsb]. |
| 5780 | unsigned LSB = Inst.getOperand(2).getImm(); |
| 5781 | unsigned Widthm1 = Inst.getOperand(3).getImm(); |
| 5782 | if (Widthm1 >= 32 - LSB) |
Jim Grosbach | 03f56d9 | 2011-07-27 21:09:25 +0000 | [diff] [blame] | 5783 | return Error(Operands[5]->getStartLoc(), |
| 5784 | "bitfield width must be in range [1,32-lsb]"); |
Jim Grosbach | 64610e5 | 2011-08-16 21:42:31 +0000 | [diff] [blame] | 5785 | return false; |
Jim Grosbach | 03f56d9 | 2011-07-27 21:09:25 +0000 | [diff] [blame] | 5786 | } |
Tim Northover | 08a8660 | 2013-10-22 19:00:39 +0000 | [diff] [blame] | 5787 | // Notionally handles ARM::tLDMIA_UPD too. |
Jim Grosbach | 90103cc | 2011-08-18 21:50:53 +0000 | [diff] [blame] | 5788 | case ARM::tLDMIA: { |
Jim Grosbach | a31f223 | 2011-09-07 18:05:34 +0000 | [diff] [blame] | 5789 | // If we're parsing Thumb2, the .w variant is available and handles |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 5790 | // most cases that are normally illegal for a Thumb1 LDM instruction. |
| 5791 | // We'll make the transformation in processInstruction() if necessary. |
Jim Grosbach | a31f223 | 2011-09-07 18:05:34 +0000 | [diff] [blame] | 5792 | // |
Sylvestre Ledru | 91ce36c | 2012-09-27 10:14:43 +0000 | [diff] [blame] | 5793 | // Thumb LDM instructions are writeback iff the base register is not |
Jim Grosbach | 90103cc | 2011-08-18 21:50:53 +0000 | [diff] [blame] | 5794 | // in the register list. |
| 5795 | unsigned Rn = Inst.getOperand(0).getReg(); |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 5796 | bool HasWritebackToken = |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5797 | (static_cast<ARMOperand &>(*Operands[3]).isToken() && |
| 5798 | static_cast<ARMOperand &>(*Operands[3]).getToken() == "!"); |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 5799 | bool ListContainsBase; |
| 5800 | if (checkLowRegisterList(Inst, 3, Rn, 0, ListContainsBase) && !isThumbTwo()) |
| 5801 | return Error(Operands[3 + HasWritebackToken]->getStartLoc(), |
Jim Grosbach | 169b2be | 2011-08-23 18:13:04 +0000 | [diff] [blame] | 5802 | "registers must be in range r0-r7"); |
Jim Grosbach | 90103cc | 2011-08-18 21:50:53 +0000 | [diff] [blame] | 5803 | // If we should have writeback, then there should be a '!' token. |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 5804 | if (!ListContainsBase && !HasWritebackToken && !isThumbTwo()) |
Jim Grosbach | 90103cc | 2011-08-18 21:50:53 +0000 | [diff] [blame] | 5805 | return Error(Operands[2]->getStartLoc(), |
| 5806 | "writeback operator '!' expected"); |
Jim Grosbach | a31f223 | 2011-09-07 18:05:34 +0000 | [diff] [blame] | 5807 | // If we should not have writeback, there must not be a '!'. This is |
| 5808 | // true even for the 32-bit wide encodings. |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 5809 | if (ListContainsBase && HasWritebackToken) |
Jim Grosbach | 139acd2 | 2011-08-22 23:01:07 +0000 | [diff] [blame] | 5810 | return Error(Operands[3]->getStartLoc(), |
| 5811 | "writeback operator '!' not allowed when base register " |
| 5812 | "in register list"); |
Jim Grosbach | 90103cc | 2011-08-18 21:50:53 +0000 | [diff] [blame] | 5813 | |
| 5814 | break; |
| 5815 | } |
Tim Northover | 08a8660 | 2013-10-22 19:00:39 +0000 | [diff] [blame] | 5816 | case ARM::LDMIA_UPD: |
| 5817 | case ARM::LDMDB_UPD: |
| 5818 | case ARM::LDMIB_UPD: |
| 5819 | case ARM::LDMDA_UPD: |
| 5820 | // ARM variants loading and updating the same register are only officially |
| 5821 | // UNPREDICTABLE on v7 upwards. Goodness knows what they did before. |
| 5822 | if (!hasV7Ops()) |
| 5823 | break; |
| 5824 | // Fallthrough |
| 5825 | case ARM::t2LDMIA_UPD: |
| 5826 | case ARM::t2LDMDB_UPD: |
| 5827 | case ARM::t2STMIA_UPD: |
| 5828 | case ARM::t2STMDB_UPD: { |
Jim Grosbach | a31f223 | 2011-09-07 18:05:34 +0000 | [diff] [blame] | 5829 | if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg())) |
Tim Northover | 741e6ef | 2013-10-24 09:37:18 +0000 | [diff] [blame] | 5830 | return Error(Operands.back()->getStartLoc(), |
| 5831 | "writeback register not allowed in register list"); |
Jim Grosbach | a31f223 | 2011-09-07 18:05:34 +0000 | [diff] [blame] | 5832 | break; |
| 5833 | } |
Tim Northover | 8eaf154 | 2013-11-12 21:32:41 +0000 | [diff] [blame] | 5834 | case ARM::sysLDMIA_UPD: |
| 5835 | case ARM::sysLDMDA_UPD: |
| 5836 | case ARM::sysLDMDB_UPD: |
| 5837 | case ARM::sysLDMIB_UPD: |
| 5838 | if (!listContainsReg(Inst, 3, ARM::PC)) |
| 5839 | return Error(Operands[4]->getStartLoc(), |
| 5840 | "writeback register only allowed on system LDM " |
| 5841 | "if PC in register-list"); |
| 5842 | break; |
| 5843 | case ARM::sysSTMIA_UPD: |
| 5844 | case ARM::sysSTMDA_UPD: |
| 5845 | case ARM::sysSTMDB_UPD: |
| 5846 | case ARM::sysSTMIB_UPD: |
| 5847 | return Error(Operands[2]->getStartLoc(), |
| 5848 | "system STM cannot have writeback register"); |
Chad Rosier | 8513ffb | 2012-08-30 23:20:38 +0000 | [diff] [blame] | 5849 | case ARM::tMUL: { |
| 5850 | // The second source operand must be the same register as the destination |
| 5851 | // operand. |
Chad Rosier | 9d1fc36 | 2012-08-31 17:24:10 +0000 | [diff] [blame] | 5852 | // |
| 5853 | // In this case, we must directly check the parsed operands because the |
| 5854 | // cvtThumbMultiply() function is written in such a way that it guarantees |
| 5855 | // this first statement is always true for the new Inst. Essentially, the |
| 5856 | // destination is unconditionally copied into the second source operand |
| 5857 | // without checking to see if it matches what we actually parsed. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5858 | if (Operands.size() == 6 && (((ARMOperand &)*Operands[3]).getReg() != |
| 5859 | ((ARMOperand &)*Operands[5]).getReg()) && |
| 5860 | (((ARMOperand &)*Operands[3]).getReg() != |
| 5861 | ((ARMOperand &)*Operands[4]).getReg())) { |
Chad Rosier | db482ef | 2012-08-30 23:22:05 +0000 | [diff] [blame] | 5862 | return Error(Operands[3]->getStartLoc(), |
| 5863 | "destination register must match source register"); |
Chad Rosier | 8513ffb | 2012-08-30 23:20:38 +0000 | [diff] [blame] | 5864 | } |
| 5865 | break; |
| 5866 | } |
Jim Grosbach | 9bded9d | 2011-11-10 23:17:11 +0000 | [diff] [blame] | 5867 | // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2, |
| 5868 | // so only issue a diagnostic for thumb1. The instructions will be |
| 5869 | // switched to the t2 encodings in processInstruction() if necessary. |
Jim Grosbach | 38c59fc | 2011-08-22 23:17:34 +0000 | [diff] [blame] | 5870 | case ARM::tPOP: { |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 5871 | bool ListContainsBase; |
| 5872 | if (checkLowRegisterList(Inst, 2, 0, ARM::PC, ListContainsBase) && |
Jim Grosbach | 9bded9d | 2011-11-10 23:17:11 +0000 | [diff] [blame] | 5873 | !isThumbTwo()) |
Jim Grosbach | 169b2be | 2011-08-23 18:13:04 +0000 | [diff] [blame] | 5874 | return Error(Operands[2]->getStartLoc(), |
| 5875 | "registers must be in range r0-r7 or pc"); |
Jim Grosbach | 38c59fc | 2011-08-22 23:17:34 +0000 | [diff] [blame] | 5876 | break; |
| 5877 | } |
| 5878 | case ARM::tPUSH: { |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 5879 | bool ListContainsBase; |
| 5880 | if (checkLowRegisterList(Inst, 2, 0, ARM::LR, ListContainsBase) && |
Jim Grosbach | 9bded9d | 2011-11-10 23:17:11 +0000 | [diff] [blame] | 5881 | !isThumbTwo()) |
Jim Grosbach | 169b2be | 2011-08-23 18:13:04 +0000 | [diff] [blame] | 5882 | return Error(Operands[2]->getStartLoc(), |
| 5883 | "registers must be in range r0-r7 or lr"); |
Jim Grosbach | 38c59fc | 2011-08-22 23:17:34 +0000 | [diff] [blame] | 5884 | break; |
| 5885 | } |
Jim Grosbach | d80d169 | 2011-08-23 18:15:37 +0000 | [diff] [blame] | 5886 | case ARM::tSTMIA_UPD: { |
Tim Northover | 08a8660 | 2013-10-22 19:00:39 +0000 | [diff] [blame] | 5887 | bool ListContainsBase, InvalidLowList; |
| 5888 | InvalidLowList = checkLowRegisterList(Inst, 4, Inst.getOperand(0).getReg(), |
| 5889 | 0, ListContainsBase); |
| 5890 | if (InvalidLowList && !isThumbTwo()) |
Jim Grosbach | d80d169 | 2011-08-23 18:15:37 +0000 | [diff] [blame] | 5891 | return Error(Operands[4]->getStartLoc(), |
| 5892 | "registers must be in range r0-r7"); |
Tim Northover | 08a8660 | 2013-10-22 19:00:39 +0000 | [diff] [blame] | 5893 | |
| 5894 | // This would be converted to a 32-bit stm, but that's not valid if the |
| 5895 | // writeback register is in the list. |
| 5896 | if (InvalidLowList && ListContainsBase) |
| 5897 | return Error(Operands[4]->getStartLoc(), |
| 5898 | "writeback operator '!' not allowed when base register " |
| 5899 | "in register list"); |
Jim Grosbach | d80d169 | 2011-08-23 18:15:37 +0000 | [diff] [blame] | 5900 | break; |
| 5901 | } |
Jim Grosbach | c6f32b3 | 2012-04-27 23:51:36 +0000 | [diff] [blame] | 5902 | case ARM::tADDrSP: { |
| 5903 | // If the non-SP source operand and the destination operand are not the |
| 5904 | // same, we need thumb2 (for the wide encoding), or we have an error. |
| 5905 | if (!isThumbTwo() && |
| 5906 | Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) { |
| 5907 | return Error(Operands[4]->getStartLoc(), |
| 5908 | "source register must be the same as destination"); |
| 5909 | } |
| 5910 | break; |
| 5911 | } |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 5912 | // Final range checking for Thumb unconditional branch instructions. |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 5913 | case ARM::tB: |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5914 | if (!(static_cast<ARMOperand &>(*Operands[2])).isSignedOffset<11, 1>()) |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 5915 | return Error(Operands[2]->getStartLoc(), "branch target out of range"); |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 5916 | break; |
| 5917 | case ARM::t2B: { |
| 5918 | int op = (Operands[2]->isImm()) ? 2 : 3; |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5919 | if (!static_cast<ARMOperand &>(*Operands[op]).isSignedOffset<24, 1>()) |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 5920 | return Error(Operands[op]->getStartLoc(), "branch target out of range"); |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 5921 | break; |
| 5922 | } |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 5923 | // Final range checking for Thumb conditional branch instructions. |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 5924 | case ARM::tBcc: |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5925 | if (!static_cast<ARMOperand &>(*Operands[2]).isSignedOffset<8, 1>()) |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 5926 | return Error(Operands[2]->getStartLoc(), "branch target out of range"); |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 5927 | break; |
| 5928 | case ARM::t2Bcc: { |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 5929 | int Op = (Operands[2]->isImm()) ? 2 : 3; |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5930 | if (!static_cast<ARMOperand &>(*Operands[Op]).isSignedOffset<20, 1>()) |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 5931 | return Error(Operands[Op]->getStartLoc(), "branch target out of range"); |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 5932 | break; |
| 5933 | } |
Kevin Enderby | b7e51f6 | 2014-04-18 23:06:39 +0000 | [diff] [blame] | 5934 | case ARM::MOVi16: |
| 5935 | case ARM::t2MOVi16: |
| 5936 | case ARM::t2MOVTi16: |
| 5937 | { |
| 5938 | // We want to avoid misleadingly allowing something like "mov r0, <symbol>" |
| 5939 | // especially when we turn it into a movw and the expression <symbol> does |
| 5940 | // not have a :lower16: or :upper16 as part of the expression. We don't |
| 5941 | // want the behavior of silently truncating, which can be unexpected and |
| 5942 | // lead to bugs that are difficult to find since this is an easy mistake |
| 5943 | // to make. |
| 5944 | int i = (Operands[3]->isImm()) ? 3 : 4; |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5945 | ARMOperand &Op = static_cast<ARMOperand &>(*Operands[i]); |
| 5946 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm()); |
Kevin Enderby | b7e51f6 | 2014-04-18 23:06:39 +0000 | [diff] [blame] | 5947 | if (CE) break; |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5948 | const MCExpr *E = dyn_cast<MCExpr>(Op.getImm()); |
Kevin Enderby | b7e51f6 | 2014-04-18 23:06:39 +0000 | [diff] [blame] | 5949 | if (!E) break; |
| 5950 | const ARMMCExpr *ARM16Expr = dyn_cast<ARMMCExpr>(E); |
| 5951 | if (!ARM16Expr || (ARM16Expr->getKind() != ARMMCExpr::VK_ARM_HI16 && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5952 | ARM16Expr->getKind() != ARMMCExpr::VK_ARM_LO16)) |
| 5953 | return Error( |
| 5954 | Op.getStartLoc(), |
| 5955 | "immediate expression for mov requires :lower16: or :upper16"); |
| 5956 | break; |
| 5957 | } |
Jim Grosbach | edaa35a | 2011-07-26 18:25:39 +0000 | [diff] [blame] | 5958 | } |
| 5959 | |
| 5960 | return false; |
| 5961 | } |
| 5962 | |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 5963 | static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) { |
Jim Grosbach | eb53822 | 2011-12-02 22:34:51 +0000 | [diff] [blame] | 5964 | switch(Opc) { |
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 5965 | default: llvm_unreachable("unexpected opcode!"); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 5966 | // VST1LN |
Jim Grosbach | 1e946a4 | 2012-01-24 00:43:12 +0000 | [diff] [blame] | 5967 | case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD; |
| 5968 | case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD; |
| 5969 | case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD; |
| 5970 | case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD; |
| 5971 | case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD; |
| 5972 | case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD; |
| 5973 | case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8; |
| 5974 | case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16; |
| 5975 | case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32; |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 5976 | |
| 5977 | // VST2LN |
Jim Grosbach | 1e946a4 | 2012-01-24 00:43:12 +0000 | [diff] [blame] | 5978 | case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD; |
| 5979 | case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD; |
| 5980 | case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD; |
| 5981 | case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD; |
| 5982 | case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD; |
Jim Grosbach | 2c59052 | 2011-12-20 20:46:29 +0000 | [diff] [blame] | 5983 | |
Jim Grosbach | 1e946a4 | 2012-01-24 00:43:12 +0000 | [diff] [blame] | 5984 | case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD; |
| 5985 | case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD; |
| 5986 | case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD; |
| 5987 | case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD; |
| 5988 | case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD; |
Jim Grosbach | 2c59052 | 2011-12-20 20:46:29 +0000 | [diff] [blame] | 5989 | |
Jim Grosbach | 1e946a4 | 2012-01-24 00:43:12 +0000 | [diff] [blame] | 5990 | case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8; |
| 5991 | case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16; |
| 5992 | case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32; |
| 5993 | case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16; |
| 5994 | case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 5995 | |
Jim Grosbach | d3d36d9 | 2012-01-24 00:07:41 +0000 | [diff] [blame] | 5996 | // VST3LN |
Jim Grosbach | 1e946a4 | 2012-01-24 00:43:12 +0000 | [diff] [blame] | 5997 | case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD; |
| 5998 | case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD; |
| 5999 | case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD; |
| 6000 | case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD; |
| 6001 | case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD; |
| 6002 | case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD; |
| 6003 | case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD; |
| 6004 | case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD; |
| 6005 | case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD; |
| 6006 | case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD; |
| 6007 | case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8; |
| 6008 | case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16; |
| 6009 | case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32; |
| 6010 | case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16; |
| 6011 | case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32; |
Jim Grosbach | d3d36d9 | 2012-01-24 00:07:41 +0000 | [diff] [blame] | 6012 | |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6013 | // VST3 |
Jim Grosbach | 1e946a4 | 2012-01-24 00:43:12 +0000 | [diff] [blame] | 6014 | case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD; |
| 6015 | case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD; |
| 6016 | case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD; |
| 6017 | case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD; |
| 6018 | case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD; |
| 6019 | case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD; |
| 6020 | case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD; |
| 6021 | case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD; |
| 6022 | case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD; |
| 6023 | case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD; |
| 6024 | case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD; |
| 6025 | case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD; |
| 6026 | case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8; |
| 6027 | case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16; |
| 6028 | case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32; |
| 6029 | case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8; |
| 6030 | case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16; |
| 6031 | case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32; |
Jim Grosbach | da70eac | 2012-01-24 00:58:13 +0000 | [diff] [blame] | 6032 | |
Jim Grosbach | 8e2722c | 2012-01-24 18:53:13 +0000 | [diff] [blame] | 6033 | // VST4LN |
| 6034 | case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD; |
| 6035 | case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD; |
| 6036 | case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD; |
| 6037 | case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD; |
| 6038 | case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD; |
| 6039 | case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD; |
| 6040 | case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD; |
| 6041 | case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD; |
| 6042 | case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD; |
| 6043 | case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD; |
| 6044 | case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8; |
| 6045 | case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16; |
| 6046 | case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32; |
| 6047 | case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16; |
| 6048 | case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32; |
| 6049 | |
Jim Grosbach | da70eac | 2012-01-24 00:58:13 +0000 | [diff] [blame] | 6050 | // VST4 |
| 6051 | case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD; |
| 6052 | case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD; |
| 6053 | case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD; |
| 6054 | case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD; |
| 6055 | case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD; |
| 6056 | case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD; |
| 6057 | case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD; |
| 6058 | case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD; |
| 6059 | case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD; |
| 6060 | case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD; |
| 6061 | case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD; |
| 6062 | case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD; |
| 6063 | case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8; |
| 6064 | case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16; |
| 6065 | case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32; |
| 6066 | case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8; |
| 6067 | case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16; |
| 6068 | case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32; |
Jim Grosbach | eb53822 | 2011-12-02 22:34:51 +0000 | [diff] [blame] | 6069 | } |
| 6070 | } |
| 6071 | |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6072 | static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) { |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 6073 | switch(Opc) { |
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 6074 | default: llvm_unreachable("unexpected opcode!"); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6075 | // VLD1LN |
Jim Grosbach | 1e946a4 | 2012-01-24 00:43:12 +0000 | [diff] [blame] | 6076 | case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD; |
| 6077 | case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD; |
| 6078 | case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD; |
| 6079 | case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD; |
| 6080 | case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD; |
| 6081 | case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD; |
| 6082 | case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8; |
| 6083 | case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16; |
| 6084 | case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32; |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6085 | |
| 6086 | // VLD2LN |
Jim Grosbach | 1e946a4 | 2012-01-24 00:43:12 +0000 | [diff] [blame] | 6087 | case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD; |
| 6088 | case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD; |
| 6089 | case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD; |
| 6090 | case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD; |
| 6091 | case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD; |
| 6092 | case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD; |
| 6093 | case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD; |
| 6094 | case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD; |
| 6095 | case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD; |
| 6096 | case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD; |
| 6097 | case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8; |
| 6098 | case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16; |
| 6099 | case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32; |
| 6100 | case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16; |
| 6101 | case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32; |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 6102 | |
Jim Grosbach | b78403c | 2012-01-24 23:47:04 +0000 | [diff] [blame] | 6103 | // VLD3DUP |
| 6104 | case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD; |
| 6105 | case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD; |
| 6106 | case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD; |
| 6107 | case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD; |
Kevin Enderby | d88fec3 | 2014-04-08 18:00:52 +0000 | [diff] [blame] | 6108 | case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD; |
Jim Grosbach | b78403c | 2012-01-24 23:47:04 +0000 | [diff] [blame] | 6109 | case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD; |
| 6110 | case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD; |
| 6111 | case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD; |
| 6112 | case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD; |
| 6113 | case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD; |
| 6114 | case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD; |
| 6115 | case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD; |
| 6116 | case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8; |
| 6117 | case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16; |
| 6118 | case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32; |
| 6119 | case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8; |
| 6120 | case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16; |
| 6121 | case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32; |
| 6122 | |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 6123 | // VLD3LN |
Jim Grosbach | 1e946a4 | 2012-01-24 00:43:12 +0000 | [diff] [blame] | 6124 | case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD; |
| 6125 | case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD; |
| 6126 | case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD; |
| 6127 | case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD; |
| 6128 | case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD; |
| 6129 | case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD; |
| 6130 | case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD; |
| 6131 | case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD; |
| 6132 | case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD; |
| 6133 | case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD; |
| 6134 | case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8; |
| 6135 | case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16; |
| 6136 | case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32; |
| 6137 | case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16; |
| 6138 | case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32; |
Jim Grosbach | ac2af3f | 2012-01-23 23:20:46 +0000 | [diff] [blame] | 6139 | |
| 6140 | // VLD3 |
Jim Grosbach | 1e946a4 | 2012-01-24 00:43:12 +0000 | [diff] [blame] | 6141 | case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD; |
| 6142 | case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD; |
| 6143 | case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD; |
| 6144 | case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD; |
| 6145 | case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD; |
| 6146 | case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD; |
| 6147 | case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD; |
| 6148 | case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD; |
| 6149 | case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD; |
| 6150 | case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD; |
| 6151 | case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD; |
| 6152 | case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD; |
| 6153 | case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8; |
| 6154 | case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16; |
| 6155 | case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32; |
| 6156 | case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8; |
| 6157 | case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16; |
| 6158 | case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32; |
Jim Grosbach | ed561fc | 2012-01-24 00:43:17 +0000 | [diff] [blame] | 6159 | |
Jim Grosbach | 14952a0 | 2012-01-24 18:37:25 +0000 | [diff] [blame] | 6160 | // VLD4LN |
| 6161 | case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD; |
| 6162 | case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD; |
| 6163 | case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD; |
Kevin Enderby | 8108f38 | 2014-03-26 19:35:40 +0000 | [diff] [blame] | 6164 | case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD; |
Jim Grosbach | 14952a0 | 2012-01-24 18:37:25 +0000 | [diff] [blame] | 6165 | case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD; |
| 6166 | case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD; |
| 6167 | case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD; |
| 6168 | case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD; |
| 6169 | case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD; |
| 6170 | case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD; |
| 6171 | case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8; |
| 6172 | case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16; |
| 6173 | case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32; |
| 6174 | case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16; |
| 6175 | case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32; |
| 6176 | |
Jim Grosbach | 086cbfa | 2012-01-25 00:01:08 +0000 | [diff] [blame] | 6177 | // VLD4DUP |
| 6178 | case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD; |
| 6179 | case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD; |
| 6180 | case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD; |
| 6181 | case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD; |
| 6182 | case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD; |
| 6183 | case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD; |
| 6184 | case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD; |
| 6185 | case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD; |
| 6186 | case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD; |
| 6187 | case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD; |
| 6188 | case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD; |
| 6189 | case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD; |
| 6190 | case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8; |
| 6191 | case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16; |
| 6192 | case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32; |
| 6193 | case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8; |
| 6194 | case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16; |
| 6195 | case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32; |
| 6196 | |
Jim Grosbach | ed561fc | 2012-01-24 00:43:17 +0000 | [diff] [blame] | 6197 | // VLD4 |
| 6198 | case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD; |
| 6199 | case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD; |
| 6200 | case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD; |
| 6201 | case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD; |
| 6202 | case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD; |
| 6203 | case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD; |
| 6204 | case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD; |
| 6205 | case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD; |
| 6206 | case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD; |
| 6207 | case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD; |
| 6208 | case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD; |
| 6209 | case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD; |
| 6210 | case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8; |
| 6211 | case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16; |
| 6212 | case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32; |
| 6213 | case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8; |
| 6214 | case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16; |
| 6215 | case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 6216 | } |
| 6217 | } |
| 6218 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 6219 | bool ARMAsmParser::processInstruction(MCInst &Inst, |
| 6220 | const OperandVector &Operands) { |
Jim Grosbach | 8ba76c6 | 2011-08-11 17:35:48 +0000 | [diff] [blame] | 6221 | switch (Inst.getOpcode()) { |
Saleem Abdulrasool | fb3950e | 2014-01-12 04:36:01 +0000 | [diff] [blame] | 6222 | // Alias for alternate form of 'ldr{,b}t Rt, [Rn], #imm' instruction. |
| 6223 | case ARM::LDRT_POST: |
| 6224 | case ARM::LDRBT_POST: { |
| 6225 | const unsigned Opcode = |
| 6226 | (Inst.getOpcode() == ARM::LDRT_POST) ? ARM::LDRT_POST_IMM |
| 6227 | : ARM::LDRBT_POST_IMM; |
| 6228 | MCInst TmpInst; |
| 6229 | TmpInst.setOpcode(Opcode); |
| 6230 | TmpInst.addOperand(Inst.getOperand(0)); |
| 6231 | TmpInst.addOperand(Inst.getOperand(1)); |
| 6232 | TmpInst.addOperand(Inst.getOperand(1)); |
| 6233 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 6234 | TmpInst.addOperand(MCOperand::CreateImm(0)); |
| 6235 | TmpInst.addOperand(Inst.getOperand(2)); |
| 6236 | TmpInst.addOperand(Inst.getOperand(3)); |
| 6237 | Inst = TmpInst; |
| 6238 | return true; |
| 6239 | } |
| 6240 | // Alias for alternate form of 'str{,b}t Rt, [Rn], #imm' instruction. |
| 6241 | case ARM::STRT_POST: |
| 6242 | case ARM::STRBT_POST: { |
| 6243 | const unsigned Opcode = |
| 6244 | (Inst.getOpcode() == ARM::STRT_POST) ? ARM::STRT_POST_IMM |
| 6245 | : ARM::STRBT_POST_IMM; |
| 6246 | MCInst TmpInst; |
| 6247 | TmpInst.setOpcode(Opcode); |
| 6248 | TmpInst.addOperand(Inst.getOperand(1)); |
| 6249 | TmpInst.addOperand(Inst.getOperand(0)); |
| 6250 | TmpInst.addOperand(Inst.getOperand(1)); |
| 6251 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 6252 | TmpInst.addOperand(MCOperand::CreateImm(0)); |
| 6253 | TmpInst.addOperand(Inst.getOperand(2)); |
| 6254 | TmpInst.addOperand(Inst.getOperand(3)); |
| 6255 | Inst = TmpInst; |
| 6256 | return true; |
| 6257 | } |
Jim Grosbach | e974a6a | 2012-09-25 00:08:13 +0000 | [diff] [blame] | 6258 | // Alias for alternate form of 'ADR Rd, #imm' instruction. |
| 6259 | case ARM::ADDri: { |
| 6260 | if (Inst.getOperand(1).getReg() != ARM::PC || |
| 6261 | Inst.getOperand(5).getReg() != 0) |
| 6262 | return false; |
| 6263 | MCInst TmpInst; |
| 6264 | TmpInst.setOpcode(ARM::ADR); |
| 6265 | TmpInst.addOperand(Inst.getOperand(0)); |
| 6266 | TmpInst.addOperand(Inst.getOperand(2)); |
| 6267 | TmpInst.addOperand(Inst.getOperand(3)); |
| 6268 | TmpInst.addOperand(Inst.getOperand(4)); |
| 6269 | Inst = TmpInst; |
| 6270 | return true; |
| 6271 | } |
Jim Grosbach | 94298a9 | 2012-01-18 22:46:46 +0000 | [diff] [blame] | 6272 | // Aliases for alternate PC+imm syntax of LDR instructions. |
| 6273 | case ARM::t2LDRpcrel: |
Kevin Enderby | 06aa3eb8 | 2012-12-14 23:04:25 +0000 | [diff] [blame] | 6274 | // Select the narrow version if the immediate will fit. |
| 6275 | if (Inst.getOperand(1).getImm() > 0 && |
Amaury de la Vieuville | eac0bad | 2013-06-18 08:13:05 +0000 | [diff] [blame] | 6276 | Inst.getOperand(1).getImm() <= 0xff && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 6277 | !(static_cast<ARMOperand &>(*Operands[2]).isToken() && |
| 6278 | static_cast<ARMOperand &>(*Operands[2]).getToken() == ".w")) |
Kevin Enderby | 06aa3eb8 | 2012-12-14 23:04:25 +0000 | [diff] [blame] | 6279 | Inst.setOpcode(ARM::tLDRpci); |
| 6280 | else |
| 6281 | Inst.setOpcode(ARM::t2LDRpci); |
Jim Grosbach | 94298a9 | 2012-01-18 22:46:46 +0000 | [diff] [blame] | 6282 | return true; |
| 6283 | case ARM::t2LDRBpcrel: |
| 6284 | Inst.setOpcode(ARM::t2LDRBpci); |
| 6285 | return true; |
| 6286 | case ARM::t2LDRHpcrel: |
| 6287 | Inst.setOpcode(ARM::t2LDRHpci); |
| 6288 | return true; |
| 6289 | case ARM::t2LDRSBpcrel: |
| 6290 | Inst.setOpcode(ARM::t2LDRSBpci); |
| 6291 | return true; |
| 6292 | case ARM::t2LDRSHpcrel: |
| 6293 | Inst.setOpcode(ARM::t2LDRSHpci); |
| 6294 | return true; |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6295 | // Handle NEON VST complex aliases. |
Jim Grosbach | d28ef9a | 2012-01-23 19:39:08 +0000 | [diff] [blame] | 6296 | case ARM::VST1LNdWB_register_Asm_8: |
| 6297 | case ARM::VST1LNdWB_register_Asm_16: |
| 6298 | case ARM::VST1LNdWB_register_Asm_32: { |
Jim Grosbach | eb53822 | 2011-12-02 22:34:51 +0000 | [diff] [blame] | 6299 | MCInst TmpInst; |
| 6300 | // Shuffle the operands around so the lane index operand is in the |
| 6301 | // right place. |
Jim Grosbach | 2c59052 | 2011-12-20 20:46:29 +0000 | [diff] [blame] | 6302 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6303 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | eb53822 | 2011-12-02 22:34:51 +0000 | [diff] [blame] | 6304 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6305 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6306 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6307 | TmpInst.addOperand(Inst.getOperand(4)); // Rm |
| 6308 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6309 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6310 | TmpInst.addOperand(Inst.getOperand(5)); // CondCode |
| 6311 | TmpInst.addOperand(Inst.getOperand(6)); |
| 6312 | Inst = TmpInst; |
| 6313 | return true; |
| 6314 | } |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6315 | |
Jim Grosbach | d28ef9a | 2012-01-23 19:39:08 +0000 | [diff] [blame] | 6316 | case ARM::VST2LNdWB_register_Asm_8: |
| 6317 | case ARM::VST2LNdWB_register_Asm_16: |
| 6318 | case ARM::VST2LNdWB_register_Asm_32: |
| 6319 | case ARM::VST2LNqWB_register_Asm_16: |
| 6320 | case ARM::VST2LNqWB_register_Asm_32: { |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6321 | MCInst TmpInst; |
| 6322 | // Shuffle the operands around so the lane index operand is in the |
| 6323 | // right place. |
Jim Grosbach | 2c59052 | 2011-12-20 20:46:29 +0000 | [diff] [blame] | 6324 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6325 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6326 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6327 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6328 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6329 | TmpInst.addOperand(Inst.getOperand(4)); // Rm |
| 6330 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
Jim Grosbach | 2c59052 | 2011-12-20 20:46:29 +0000 | [diff] [blame] | 6331 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6332 | Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6333 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6334 | TmpInst.addOperand(Inst.getOperand(5)); // CondCode |
| 6335 | TmpInst.addOperand(Inst.getOperand(6)); |
| 6336 | Inst = TmpInst; |
| 6337 | return true; |
| 6338 | } |
Jim Grosbach | d3d36d9 | 2012-01-24 00:07:41 +0000 | [diff] [blame] | 6339 | |
| 6340 | case ARM::VST3LNdWB_register_Asm_8: |
| 6341 | case ARM::VST3LNdWB_register_Asm_16: |
| 6342 | case ARM::VST3LNdWB_register_Asm_32: |
| 6343 | case ARM::VST3LNqWB_register_Asm_16: |
| 6344 | case ARM::VST3LNqWB_register_Asm_32: { |
| 6345 | MCInst TmpInst; |
| 6346 | // Shuffle the operands around so the lane index operand is in the |
| 6347 | // right place. |
| 6348 | unsigned Spacing; |
| 6349 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
| 6350 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6351 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6352 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6353 | TmpInst.addOperand(Inst.getOperand(4)); // Rm |
| 6354 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6355 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6356 | Spacing)); |
| 6357 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6358 | Spacing * 2)); |
| 6359 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6360 | TmpInst.addOperand(Inst.getOperand(5)); // CondCode |
| 6361 | TmpInst.addOperand(Inst.getOperand(6)); |
| 6362 | Inst = TmpInst; |
| 6363 | return true; |
| 6364 | } |
| 6365 | |
Jim Grosbach | 8e2722c | 2012-01-24 18:53:13 +0000 | [diff] [blame] | 6366 | case ARM::VST4LNdWB_register_Asm_8: |
| 6367 | case ARM::VST4LNdWB_register_Asm_16: |
| 6368 | case ARM::VST4LNdWB_register_Asm_32: |
| 6369 | case ARM::VST4LNqWB_register_Asm_16: |
| 6370 | case ARM::VST4LNqWB_register_Asm_32: { |
| 6371 | MCInst TmpInst; |
| 6372 | // Shuffle the operands around so the lane index operand is in the |
| 6373 | // right place. |
| 6374 | unsigned Spacing; |
| 6375 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
| 6376 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6377 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6378 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6379 | TmpInst.addOperand(Inst.getOperand(4)); // Rm |
| 6380 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6381 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6382 | Spacing)); |
| 6383 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6384 | Spacing * 2)); |
| 6385 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6386 | Spacing * 3)); |
| 6387 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6388 | TmpInst.addOperand(Inst.getOperand(5)); // CondCode |
| 6389 | TmpInst.addOperand(Inst.getOperand(6)); |
| 6390 | Inst = TmpInst; |
| 6391 | return true; |
| 6392 | } |
| 6393 | |
Jim Grosbach | d28ef9a | 2012-01-23 19:39:08 +0000 | [diff] [blame] | 6394 | case ARM::VST1LNdWB_fixed_Asm_8: |
| 6395 | case ARM::VST1LNdWB_fixed_Asm_16: |
| 6396 | case ARM::VST1LNdWB_fixed_Asm_32: { |
Jim Grosbach | eb53822 | 2011-12-02 22:34:51 +0000 | [diff] [blame] | 6397 | MCInst TmpInst; |
| 6398 | // Shuffle the operands around so the lane index operand is in the |
| 6399 | // right place. |
Jim Grosbach | 2c59052 | 2011-12-20 20:46:29 +0000 | [diff] [blame] | 6400 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6401 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | eb53822 | 2011-12-02 22:34:51 +0000 | [diff] [blame] | 6402 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6403 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6404 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6405 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 6406 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6407 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6408 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 6409 | TmpInst.addOperand(Inst.getOperand(5)); |
| 6410 | Inst = TmpInst; |
| 6411 | return true; |
| 6412 | } |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6413 | |
Jim Grosbach | d28ef9a | 2012-01-23 19:39:08 +0000 | [diff] [blame] | 6414 | case ARM::VST2LNdWB_fixed_Asm_8: |
| 6415 | case ARM::VST2LNdWB_fixed_Asm_16: |
| 6416 | case ARM::VST2LNdWB_fixed_Asm_32: |
| 6417 | case ARM::VST2LNqWB_fixed_Asm_16: |
| 6418 | case ARM::VST2LNqWB_fixed_Asm_32: { |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6419 | MCInst TmpInst; |
| 6420 | // Shuffle the operands around so the lane index operand is in the |
| 6421 | // right place. |
Jim Grosbach | 2c59052 | 2011-12-20 20:46:29 +0000 | [diff] [blame] | 6422 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6423 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6424 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6425 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6426 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6427 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 6428 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
Jim Grosbach | 2c59052 | 2011-12-20 20:46:29 +0000 | [diff] [blame] | 6429 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6430 | Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6431 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6432 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 6433 | TmpInst.addOperand(Inst.getOperand(5)); |
| 6434 | Inst = TmpInst; |
| 6435 | return true; |
| 6436 | } |
Jim Grosbach | d3d36d9 | 2012-01-24 00:07:41 +0000 | [diff] [blame] | 6437 | |
| 6438 | case ARM::VST3LNdWB_fixed_Asm_8: |
| 6439 | case ARM::VST3LNdWB_fixed_Asm_16: |
| 6440 | case ARM::VST3LNdWB_fixed_Asm_32: |
| 6441 | case ARM::VST3LNqWB_fixed_Asm_16: |
| 6442 | case ARM::VST3LNqWB_fixed_Asm_32: { |
| 6443 | MCInst TmpInst; |
| 6444 | // Shuffle the operands around so the lane index operand is in the |
| 6445 | // right place. |
| 6446 | unsigned Spacing; |
| 6447 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
| 6448 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6449 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6450 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6451 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 6452 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6453 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6454 | Spacing)); |
| 6455 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6456 | Spacing * 2)); |
| 6457 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6458 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 6459 | TmpInst.addOperand(Inst.getOperand(5)); |
| 6460 | Inst = TmpInst; |
| 6461 | return true; |
| 6462 | } |
| 6463 | |
Jim Grosbach | 8e2722c | 2012-01-24 18:53:13 +0000 | [diff] [blame] | 6464 | case ARM::VST4LNdWB_fixed_Asm_8: |
| 6465 | case ARM::VST4LNdWB_fixed_Asm_16: |
| 6466 | case ARM::VST4LNdWB_fixed_Asm_32: |
| 6467 | case ARM::VST4LNqWB_fixed_Asm_16: |
| 6468 | case ARM::VST4LNqWB_fixed_Asm_32: { |
| 6469 | MCInst TmpInst; |
| 6470 | // Shuffle the operands around so the lane index operand is in the |
| 6471 | // right place. |
| 6472 | unsigned Spacing; |
| 6473 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
| 6474 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6475 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6476 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6477 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 6478 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6479 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6480 | Spacing)); |
| 6481 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6482 | Spacing * 2)); |
| 6483 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6484 | Spacing * 3)); |
| 6485 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6486 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 6487 | TmpInst.addOperand(Inst.getOperand(5)); |
| 6488 | Inst = TmpInst; |
| 6489 | return true; |
| 6490 | } |
| 6491 | |
Jim Grosbach | d28ef9a | 2012-01-23 19:39:08 +0000 | [diff] [blame] | 6492 | case ARM::VST1LNdAsm_8: |
| 6493 | case ARM::VST1LNdAsm_16: |
| 6494 | case ARM::VST1LNdAsm_32: { |
Jim Grosbach | eb53822 | 2011-12-02 22:34:51 +0000 | [diff] [blame] | 6495 | MCInst TmpInst; |
| 6496 | // Shuffle the operands around so the lane index operand is in the |
| 6497 | // right place. |
Jim Grosbach | 2c59052 | 2011-12-20 20:46:29 +0000 | [diff] [blame] | 6498 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6499 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | eb53822 | 2011-12-02 22:34:51 +0000 | [diff] [blame] | 6500 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6501 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6502 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6503 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6504 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 6505 | TmpInst.addOperand(Inst.getOperand(5)); |
| 6506 | Inst = TmpInst; |
| 6507 | return true; |
| 6508 | } |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6509 | |
Jim Grosbach | d28ef9a | 2012-01-23 19:39:08 +0000 | [diff] [blame] | 6510 | case ARM::VST2LNdAsm_8: |
| 6511 | case ARM::VST2LNdAsm_16: |
| 6512 | case ARM::VST2LNdAsm_32: |
| 6513 | case ARM::VST2LNqAsm_16: |
| 6514 | case ARM::VST2LNqAsm_32: { |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6515 | MCInst TmpInst; |
| 6516 | // Shuffle the operands around so the lane index operand is in the |
| 6517 | // right place. |
Jim Grosbach | 2c59052 | 2011-12-20 20:46:29 +0000 | [diff] [blame] | 6518 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6519 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6520 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6521 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6522 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
Jim Grosbach | 2c59052 | 2011-12-20 20:46:29 +0000 | [diff] [blame] | 6523 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6524 | Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6525 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6526 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 6527 | TmpInst.addOperand(Inst.getOperand(5)); |
| 6528 | Inst = TmpInst; |
| 6529 | return true; |
| 6530 | } |
Jim Grosbach | d3d36d9 | 2012-01-24 00:07:41 +0000 | [diff] [blame] | 6531 | |
| 6532 | case ARM::VST3LNdAsm_8: |
| 6533 | case ARM::VST3LNdAsm_16: |
| 6534 | case ARM::VST3LNdAsm_32: |
| 6535 | case ARM::VST3LNqAsm_16: |
| 6536 | case ARM::VST3LNqAsm_32: { |
| 6537 | MCInst TmpInst; |
| 6538 | // Shuffle the operands around so the lane index operand is in the |
| 6539 | // right place. |
| 6540 | unsigned Spacing; |
| 6541 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
| 6542 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6543 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6544 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6545 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6546 | Spacing)); |
| 6547 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6548 | Spacing * 2)); |
| 6549 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6550 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 6551 | TmpInst.addOperand(Inst.getOperand(5)); |
| 6552 | Inst = TmpInst; |
| 6553 | return true; |
| 6554 | } |
| 6555 | |
Jim Grosbach | 8e2722c | 2012-01-24 18:53:13 +0000 | [diff] [blame] | 6556 | case ARM::VST4LNdAsm_8: |
| 6557 | case ARM::VST4LNdAsm_16: |
| 6558 | case ARM::VST4LNdAsm_32: |
| 6559 | case ARM::VST4LNqAsm_16: |
| 6560 | case ARM::VST4LNqAsm_32: { |
| 6561 | MCInst TmpInst; |
| 6562 | // Shuffle the operands around so the lane index operand is in the |
| 6563 | // right place. |
| 6564 | unsigned Spacing; |
| 6565 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
| 6566 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6567 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6568 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6569 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6570 | Spacing)); |
| 6571 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6572 | Spacing * 2)); |
| 6573 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6574 | Spacing * 3)); |
| 6575 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6576 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 6577 | TmpInst.addOperand(Inst.getOperand(5)); |
| 6578 | Inst = TmpInst; |
| 6579 | return true; |
| 6580 | } |
| 6581 | |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6582 | // Handle NEON VLD complex aliases. |
Jim Grosbach | d28ef9a | 2012-01-23 19:39:08 +0000 | [diff] [blame] | 6583 | case ARM::VLD1LNdWB_register_Asm_8: |
| 6584 | case ARM::VLD1LNdWB_register_Asm_16: |
| 6585 | case ARM::VLD1LNdWB_register_Asm_32: { |
Jim Grosbach | dda976b | 2011-12-02 22:01:52 +0000 | [diff] [blame] | 6586 | MCInst TmpInst; |
| 6587 | // Shuffle the operands around so the lane index operand is in the |
| 6588 | // right place. |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 6589 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6590 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | dda976b | 2011-12-02 22:01:52 +0000 | [diff] [blame] | 6591 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6592 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6593 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6594 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6595 | TmpInst.addOperand(Inst.getOperand(4)); // Rm |
| 6596 | TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) |
| 6597 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6598 | TmpInst.addOperand(Inst.getOperand(5)); // CondCode |
| 6599 | TmpInst.addOperand(Inst.getOperand(6)); |
| 6600 | Inst = TmpInst; |
| 6601 | return true; |
| 6602 | } |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6603 | |
Jim Grosbach | d28ef9a | 2012-01-23 19:39:08 +0000 | [diff] [blame] | 6604 | case ARM::VLD2LNdWB_register_Asm_8: |
| 6605 | case ARM::VLD2LNdWB_register_Asm_16: |
| 6606 | case ARM::VLD2LNdWB_register_Asm_32: |
| 6607 | case ARM::VLD2LNqWB_register_Asm_16: |
| 6608 | case ARM::VLD2LNqWB_register_Asm_32: { |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6609 | MCInst TmpInst; |
| 6610 | // Shuffle the operands around so the lane index operand is in the |
| 6611 | // right place. |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 6612 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6613 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6614 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 6615 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6616 | Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6617 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6618 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6619 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6620 | TmpInst.addOperand(Inst.getOperand(4)); // Rm |
| 6621 | TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 6622 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6623 | Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6624 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6625 | TmpInst.addOperand(Inst.getOperand(5)); // CondCode |
| 6626 | TmpInst.addOperand(Inst.getOperand(6)); |
| 6627 | Inst = TmpInst; |
| 6628 | return true; |
| 6629 | } |
| 6630 | |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 6631 | case ARM::VLD3LNdWB_register_Asm_8: |
| 6632 | case ARM::VLD3LNdWB_register_Asm_16: |
| 6633 | case ARM::VLD3LNdWB_register_Asm_32: |
| 6634 | case ARM::VLD3LNqWB_register_Asm_16: |
| 6635 | case ARM::VLD3LNqWB_register_Asm_32: { |
| 6636 | MCInst TmpInst; |
| 6637 | // Shuffle the operands around so the lane index operand is in the |
| 6638 | // right place. |
| 6639 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6640 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 6641 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6642 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6643 | Spacing)); |
| 6644 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
Jim Grosbach | ac2af3f | 2012-01-23 23:20:46 +0000 | [diff] [blame] | 6645 | Spacing * 2)); |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 6646 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6647 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6648 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6649 | TmpInst.addOperand(Inst.getOperand(4)); // Rm |
| 6650 | TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) |
| 6651 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6652 | Spacing)); |
| 6653 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
Jim Grosbach | ac2af3f | 2012-01-23 23:20:46 +0000 | [diff] [blame] | 6654 | Spacing * 2)); |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 6655 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6656 | TmpInst.addOperand(Inst.getOperand(5)); // CondCode |
| 6657 | TmpInst.addOperand(Inst.getOperand(6)); |
| 6658 | Inst = TmpInst; |
| 6659 | return true; |
| 6660 | } |
| 6661 | |
Jim Grosbach | 14952a0 | 2012-01-24 18:37:25 +0000 | [diff] [blame] | 6662 | case ARM::VLD4LNdWB_register_Asm_8: |
| 6663 | case ARM::VLD4LNdWB_register_Asm_16: |
| 6664 | case ARM::VLD4LNdWB_register_Asm_32: |
| 6665 | case ARM::VLD4LNqWB_register_Asm_16: |
| 6666 | case ARM::VLD4LNqWB_register_Asm_32: { |
| 6667 | MCInst TmpInst; |
| 6668 | // Shuffle the operands around so the lane index operand is in the |
| 6669 | // right place. |
| 6670 | unsigned Spacing; |
| 6671 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
| 6672 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6673 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6674 | Spacing)); |
| 6675 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6676 | Spacing * 2)); |
| 6677 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6678 | Spacing * 3)); |
| 6679 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6680 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6681 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6682 | TmpInst.addOperand(Inst.getOperand(4)); // Rm |
| 6683 | TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) |
| 6684 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6685 | Spacing)); |
| 6686 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6687 | Spacing * 2)); |
| 6688 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6689 | Spacing * 3)); |
| 6690 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6691 | TmpInst.addOperand(Inst.getOperand(5)); // CondCode |
| 6692 | TmpInst.addOperand(Inst.getOperand(6)); |
| 6693 | Inst = TmpInst; |
| 6694 | return true; |
| 6695 | } |
| 6696 | |
Jim Grosbach | d28ef9a | 2012-01-23 19:39:08 +0000 | [diff] [blame] | 6697 | case ARM::VLD1LNdWB_fixed_Asm_8: |
| 6698 | case ARM::VLD1LNdWB_fixed_Asm_16: |
| 6699 | case ARM::VLD1LNdWB_fixed_Asm_32: { |
Jim Grosbach | dda976b | 2011-12-02 22:01:52 +0000 | [diff] [blame] | 6700 | MCInst TmpInst; |
| 6701 | // Shuffle the operands around so the lane index operand is in the |
| 6702 | // right place. |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 6703 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6704 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | dda976b | 2011-12-02 22:01:52 +0000 | [diff] [blame] | 6705 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6706 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6707 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6708 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6709 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 6710 | TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) |
| 6711 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6712 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 6713 | TmpInst.addOperand(Inst.getOperand(5)); |
| 6714 | Inst = TmpInst; |
| 6715 | return true; |
| 6716 | } |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6717 | |
Jim Grosbach | d28ef9a | 2012-01-23 19:39:08 +0000 | [diff] [blame] | 6718 | case ARM::VLD2LNdWB_fixed_Asm_8: |
| 6719 | case ARM::VLD2LNdWB_fixed_Asm_16: |
| 6720 | case ARM::VLD2LNdWB_fixed_Asm_32: |
| 6721 | case ARM::VLD2LNqWB_fixed_Asm_16: |
| 6722 | case ARM::VLD2LNqWB_fixed_Asm_32: { |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6723 | MCInst TmpInst; |
| 6724 | // Shuffle the operands around so the lane index operand is in the |
| 6725 | // right place. |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 6726 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6727 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6728 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 6729 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6730 | Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6731 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6732 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6733 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6734 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 6735 | TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 6736 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6737 | Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6738 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6739 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 6740 | TmpInst.addOperand(Inst.getOperand(5)); |
| 6741 | Inst = TmpInst; |
| 6742 | return true; |
| 6743 | } |
| 6744 | |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 6745 | case ARM::VLD3LNdWB_fixed_Asm_8: |
| 6746 | case ARM::VLD3LNdWB_fixed_Asm_16: |
| 6747 | case ARM::VLD3LNdWB_fixed_Asm_32: |
| 6748 | case ARM::VLD3LNqWB_fixed_Asm_16: |
| 6749 | case ARM::VLD3LNqWB_fixed_Asm_32: { |
| 6750 | MCInst TmpInst; |
| 6751 | // Shuffle the operands around so the lane index operand is in the |
| 6752 | // right place. |
| 6753 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6754 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 6755 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6756 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6757 | Spacing)); |
| 6758 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
Jim Grosbach | ac2af3f | 2012-01-23 23:20:46 +0000 | [diff] [blame] | 6759 | Spacing * 2)); |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 6760 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6761 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6762 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6763 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 6764 | TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) |
| 6765 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6766 | Spacing)); |
| 6767 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
Jim Grosbach | ac2af3f | 2012-01-23 23:20:46 +0000 | [diff] [blame] | 6768 | Spacing * 2)); |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 6769 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6770 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 6771 | TmpInst.addOperand(Inst.getOperand(5)); |
| 6772 | Inst = TmpInst; |
| 6773 | return true; |
| 6774 | } |
| 6775 | |
Jim Grosbach | 14952a0 | 2012-01-24 18:37:25 +0000 | [diff] [blame] | 6776 | case ARM::VLD4LNdWB_fixed_Asm_8: |
| 6777 | case ARM::VLD4LNdWB_fixed_Asm_16: |
| 6778 | case ARM::VLD4LNdWB_fixed_Asm_32: |
| 6779 | case ARM::VLD4LNqWB_fixed_Asm_16: |
| 6780 | case ARM::VLD4LNqWB_fixed_Asm_32: { |
| 6781 | MCInst TmpInst; |
| 6782 | // Shuffle the operands around so the lane index operand is in the |
| 6783 | // right place. |
| 6784 | unsigned Spacing; |
| 6785 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
| 6786 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6787 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6788 | Spacing)); |
| 6789 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6790 | Spacing * 2)); |
| 6791 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6792 | Spacing * 3)); |
| 6793 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6794 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6795 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6796 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 6797 | TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) |
| 6798 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6799 | Spacing)); |
| 6800 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6801 | Spacing * 2)); |
| 6802 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6803 | Spacing * 3)); |
| 6804 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6805 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 6806 | TmpInst.addOperand(Inst.getOperand(5)); |
| 6807 | Inst = TmpInst; |
| 6808 | return true; |
| 6809 | } |
| 6810 | |
Jim Grosbach | d28ef9a | 2012-01-23 19:39:08 +0000 | [diff] [blame] | 6811 | case ARM::VLD1LNdAsm_8: |
| 6812 | case ARM::VLD1LNdAsm_16: |
| 6813 | case ARM::VLD1LNdAsm_32: { |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 6814 | MCInst TmpInst; |
| 6815 | // Shuffle the operands around so the lane index operand is in the |
| 6816 | // right place. |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 6817 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6818 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 6819 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6820 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6821 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6822 | TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) |
| 6823 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6824 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 6825 | TmpInst.addOperand(Inst.getOperand(5)); |
| 6826 | Inst = TmpInst; |
| 6827 | return true; |
| 6828 | } |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6829 | |
Jim Grosbach | d28ef9a | 2012-01-23 19:39:08 +0000 | [diff] [blame] | 6830 | case ARM::VLD2LNdAsm_8: |
| 6831 | case ARM::VLD2LNdAsm_16: |
| 6832 | case ARM::VLD2LNdAsm_32: |
| 6833 | case ARM::VLD2LNqAsm_16: |
| 6834 | case ARM::VLD2LNqAsm_32: { |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6835 | MCInst TmpInst; |
| 6836 | // Shuffle the operands around so the lane index operand is in the |
| 6837 | // right place. |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 6838 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6839 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6840 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 6841 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6842 | Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6843 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6844 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6845 | TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 6846 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6847 | Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6848 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6849 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 6850 | TmpInst.addOperand(Inst.getOperand(5)); |
| 6851 | Inst = TmpInst; |
| 6852 | return true; |
| 6853 | } |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 6854 | |
| 6855 | case ARM::VLD3LNdAsm_8: |
| 6856 | case ARM::VLD3LNdAsm_16: |
| 6857 | case ARM::VLD3LNdAsm_32: |
| 6858 | case ARM::VLD3LNqAsm_16: |
| 6859 | case ARM::VLD3LNqAsm_32: { |
| 6860 | MCInst TmpInst; |
| 6861 | // Shuffle the operands around so the lane index operand is in the |
| 6862 | // right place. |
| 6863 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6864 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 6865 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6866 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6867 | Spacing)); |
| 6868 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
Jim Grosbach | ac2af3f | 2012-01-23 23:20:46 +0000 | [diff] [blame] | 6869 | Spacing * 2)); |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 6870 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6871 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6872 | TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) |
| 6873 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6874 | Spacing)); |
| 6875 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
Jim Grosbach | ac2af3f | 2012-01-23 23:20:46 +0000 | [diff] [blame] | 6876 | Spacing * 2)); |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 6877 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6878 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 6879 | TmpInst.addOperand(Inst.getOperand(5)); |
| 6880 | Inst = TmpInst; |
| 6881 | return true; |
| 6882 | } |
| 6883 | |
Jim Grosbach | 14952a0 | 2012-01-24 18:37:25 +0000 | [diff] [blame] | 6884 | case ARM::VLD4LNdAsm_8: |
| 6885 | case ARM::VLD4LNdAsm_16: |
| 6886 | case ARM::VLD4LNdAsm_32: |
| 6887 | case ARM::VLD4LNqAsm_16: |
| 6888 | case ARM::VLD4LNqAsm_32: { |
| 6889 | MCInst TmpInst; |
| 6890 | // Shuffle the operands around so the lane index operand is in the |
| 6891 | // right place. |
| 6892 | unsigned Spacing; |
| 6893 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
| 6894 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6895 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6896 | Spacing)); |
| 6897 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6898 | Spacing * 2)); |
| 6899 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6900 | Spacing * 3)); |
| 6901 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6902 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6903 | TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) |
| 6904 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6905 | Spacing)); |
| 6906 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6907 | Spacing * 2)); |
| 6908 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6909 | Spacing * 3)); |
| 6910 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6911 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 6912 | TmpInst.addOperand(Inst.getOperand(5)); |
| 6913 | Inst = TmpInst; |
| 6914 | return true; |
| 6915 | } |
| 6916 | |
Jim Grosbach | b78403c | 2012-01-24 23:47:04 +0000 | [diff] [blame] | 6917 | // VLD3DUP single 3-element structure to all lanes instructions. |
| 6918 | case ARM::VLD3DUPdAsm_8: |
| 6919 | case ARM::VLD3DUPdAsm_16: |
| 6920 | case ARM::VLD3DUPdAsm_32: |
| 6921 | case ARM::VLD3DUPqAsm_8: |
| 6922 | case ARM::VLD3DUPqAsm_16: |
| 6923 | case ARM::VLD3DUPqAsm_32: { |
| 6924 | MCInst TmpInst; |
| 6925 | unsigned Spacing; |
| 6926 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
| 6927 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6928 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6929 | Spacing)); |
| 6930 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6931 | Spacing * 2)); |
| 6932 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 6933 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 6934 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 6935 | TmpInst.addOperand(Inst.getOperand(4)); |
| 6936 | Inst = TmpInst; |
| 6937 | return true; |
| 6938 | } |
| 6939 | |
| 6940 | case ARM::VLD3DUPdWB_fixed_Asm_8: |
| 6941 | case ARM::VLD3DUPdWB_fixed_Asm_16: |
| 6942 | case ARM::VLD3DUPdWB_fixed_Asm_32: |
| 6943 | case ARM::VLD3DUPqWB_fixed_Asm_8: |
| 6944 | case ARM::VLD3DUPqWB_fixed_Asm_16: |
| 6945 | case ARM::VLD3DUPqWB_fixed_Asm_32: { |
| 6946 | MCInst TmpInst; |
| 6947 | unsigned Spacing; |
| 6948 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
| 6949 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6950 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6951 | Spacing)); |
| 6952 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6953 | Spacing * 2)); |
| 6954 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 6955 | TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn |
| 6956 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 6957 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 6958 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 6959 | TmpInst.addOperand(Inst.getOperand(4)); |
| 6960 | Inst = TmpInst; |
| 6961 | return true; |
| 6962 | } |
| 6963 | |
| 6964 | case ARM::VLD3DUPdWB_register_Asm_8: |
| 6965 | case ARM::VLD3DUPdWB_register_Asm_16: |
| 6966 | case ARM::VLD3DUPdWB_register_Asm_32: |
| 6967 | case ARM::VLD3DUPqWB_register_Asm_8: |
| 6968 | case ARM::VLD3DUPqWB_register_Asm_16: |
| 6969 | case ARM::VLD3DUPqWB_register_Asm_32: { |
| 6970 | MCInst TmpInst; |
| 6971 | unsigned Spacing; |
| 6972 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
| 6973 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6974 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6975 | Spacing)); |
| 6976 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6977 | Spacing * 2)); |
| 6978 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 6979 | TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn |
| 6980 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 6981 | TmpInst.addOperand(Inst.getOperand(3)); // Rm |
| 6982 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 6983 | TmpInst.addOperand(Inst.getOperand(5)); |
| 6984 | Inst = TmpInst; |
| 6985 | return true; |
| 6986 | } |
| 6987 | |
Jim Grosbach | ac2af3f | 2012-01-23 23:20:46 +0000 | [diff] [blame] | 6988 | // VLD3 multiple 3-element structure instructions. |
| 6989 | case ARM::VLD3dAsm_8: |
| 6990 | case ARM::VLD3dAsm_16: |
| 6991 | case ARM::VLD3dAsm_32: |
| 6992 | case ARM::VLD3qAsm_8: |
| 6993 | case ARM::VLD3qAsm_16: |
| 6994 | case ARM::VLD3qAsm_32: { |
| 6995 | MCInst TmpInst; |
| 6996 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6997 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | ac2af3f | 2012-01-23 23:20:46 +0000 | [diff] [blame] | 6998 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6999 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7000 | Spacing)); |
| 7001 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7002 | Spacing * 2)); |
| 7003 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7004 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7005 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7006 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7007 | Inst = TmpInst; |
| 7008 | return true; |
| 7009 | } |
| 7010 | |
| 7011 | case ARM::VLD3dWB_fixed_Asm_8: |
| 7012 | case ARM::VLD3dWB_fixed_Asm_16: |
| 7013 | case ARM::VLD3dWB_fixed_Asm_32: |
| 7014 | case ARM::VLD3qWB_fixed_Asm_8: |
| 7015 | case ARM::VLD3qWB_fixed_Asm_16: |
| 7016 | case ARM::VLD3qWB_fixed_Asm_32: { |
| 7017 | MCInst TmpInst; |
| 7018 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 7019 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | ac2af3f | 2012-01-23 23:20:46 +0000 | [diff] [blame] | 7020 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7021 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7022 | Spacing)); |
| 7023 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7024 | Spacing * 2)); |
| 7025 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7026 | TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn |
| 7027 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7028 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 7029 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7030 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7031 | Inst = TmpInst; |
| 7032 | return true; |
| 7033 | } |
| 7034 | |
| 7035 | case ARM::VLD3dWB_register_Asm_8: |
| 7036 | case ARM::VLD3dWB_register_Asm_16: |
| 7037 | case ARM::VLD3dWB_register_Asm_32: |
| 7038 | case ARM::VLD3qWB_register_Asm_8: |
| 7039 | case ARM::VLD3qWB_register_Asm_16: |
| 7040 | case ARM::VLD3qWB_register_Asm_32: { |
| 7041 | MCInst TmpInst; |
| 7042 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 7043 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | ac2af3f | 2012-01-23 23:20:46 +0000 | [diff] [blame] | 7044 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7045 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7046 | Spacing)); |
| 7047 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7048 | Spacing * 2)); |
| 7049 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7050 | TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn |
| 7051 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7052 | TmpInst.addOperand(Inst.getOperand(3)); // Rm |
| 7053 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 7054 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7055 | Inst = TmpInst; |
| 7056 | return true; |
| 7057 | } |
| 7058 | |
Jim Grosbach | 086cbfa | 2012-01-25 00:01:08 +0000 | [diff] [blame] | 7059 | // VLD4DUP single 3-element structure to all lanes instructions. |
| 7060 | case ARM::VLD4DUPdAsm_8: |
| 7061 | case ARM::VLD4DUPdAsm_16: |
| 7062 | case ARM::VLD4DUPdAsm_32: |
| 7063 | case ARM::VLD4DUPqAsm_8: |
| 7064 | case ARM::VLD4DUPqAsm_16: |
| 7065 | case ARM::VLD4DUPqAsm_32: { |
| 7066 | MCInst TmpInst; |
| 7067 | unsigned Spacing; |
| 7068 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
| 7069 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7070 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7071 | Spacing)); |
| 7072 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7073 | Spacing * 2)); |
| 7074 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7075 | Spacing * 3)); |
| 7076 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7077 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7078 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7079 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7080 | Inst = TmpInst; |
| 7081 | return true; |
| 7082 | } |
| 7083 | |
| 7084 | case ARM::VLD4DUPdWB_fixed_Asm_8: |
| 7085 | case ARM::VLD4DUPdWB_fixed_Asm_16: |
| 7086 | case ARM::VLD4DUPdWB_fixed_Asm_32: |
| 7087 | case ARM::VLD4DUPqWB_fixed_Asm_8: |
| 7088 | case ARM::VLD4DUPqWB_fixed_Asm_16: |
| 7089 | case ARM::VLD4DUPqWB_fixed_Asm_32: { |
| 7090 | MCInst TmpInst; |
| 7091 | unsigned Spacing; |
| 7092 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
| 7093 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7094 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7095 | Spacing)); |
| 7096 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7097 | Spacing * 2)); |
| 7098 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7099 | Spacing * 3)); |
| 7100 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7101 | TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn |
| 7102 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7103 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 7104 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7105 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7106 | Inst = TmpInst; |
| 7107 | return true; |
| 7108 | } |
| 7109 | |
| 7110 | case ARM::VLD4DUPdWB_register_Asm_8: |
| 7111 | case ARM::VLD4DUPdWB_register_Asm_16: |
| 7112 | case ARM::VLD4DUPdWB_register_Asm_32: |
| 7113 | case ARM::VLD4DUPqWB_register_Asm_8: |
| 7114 | case ARM::VLD4DUPqWB_register_Asm_16: |
| 7115 | case ARM::VLD4DUPqWB_register_Asm_32: { |
| 7116 | MCInst TmpInst; |
| 7117 | unsigned Spacing; |
| 7118 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
| 7119 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7120 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7121 | Spacing)); |
| 7122 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7123 | Spacing * 2)); |
| 7124 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7125 | Spacing * 3)); |
| 7126 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7127 | TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn |
| 7128 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7129 | TmpInst.addOperand(Inst.getOperand(3)); // Rm |
| 7130 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 7131 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7132 | Inst = TmpInst; |
| 7133 | return true; |
| 7134 | } |
| 7135 | |
| 7136 | // VLD4 multiple 4-element structure instructions. |
Jim Grosbach | ed561fc | 2012-01-24 00:43:17 +0000 | [diff] [blame] | 7137 | case ARM::VLD4dAsm_8: |
| 7138 | case ARM::VLD4dAsm_16: |
| 7139 | case ARM::VLD4dAsm_32: |
| 7140 | case ARM::VLD4qAsm_8: |
| 7141 | case ARM::VLD4qAsm_16: |
| 7142 | case ARM::VLD4qAsm_32: { |
| 7143 | MCInst TmpInst; |
| 7144 | unsigned Spacing; |
| 7145 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
| 7146 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7147 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7148 | Spacing)); |
| 7149 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7150 | Spacing * 2)); |
| 7151 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7152 | Spacing * 3)); |
| 7153 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7154 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7155 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7156 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7157 | Inst = TmpInst; |
| 7158 | return true; |
| 7159 | } |
| 7160 | |
| 7161 | case ARM::VLD4dWB_fixed_Asm_8: |
| 7162 | case ARM::VLD4dWB_fixed_Asm_16: |
| 7163 | case ARM::VLD4dWB_fixed_Asm_32: |
| 7164 | case ARM::VLD4qWB_fixed_Asm_8: |
| 7165 | case ARM::VLD4qWB_fixed_Asm_16: |
| 7166 | case ARM::VLD4qWB_fixed_Asm_32: { |
| 7167 | MCInst TmpInst; |
| 7168 | unsigned Spacing; |
| 7169 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
| 7170 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7171 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7172 | Spacing)); |
| 7173 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7174 | Spacing * 2)); |
| 7175 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7176 | Spacing * 3)); |
| 7177 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7178 | TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn |
| 7179 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7180 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 7181 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7182 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7183 | Inst = TmpInst; |
| 7184 | return true; |
| 7185 | } |
| 7186 | |
| 7187 | case ARM::VLD4dWB_register_Asm_8: |
| 7188 | case ARM::VLD4dWB_register_Asm_16: |
| 7189 | case ARM::VLD4dWB_register_Asm_32: |
| 7190 | case ARM::VLD4qWB_register_Asm_8: |
| 7191 | case ARM::VLD4qWB_register_Asm_16: |
| 7192 | case ARM::VLD4qWB_register_Asm_32: { |
| 7193 | MCInst TmpInst; |
| 7194 | unsigned Spacing; |
| 7195 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
| 7196 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7197 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7198 | Spacing)); |
| 7199 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7200 | Spacing * 2)); |
| 7201 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7202 | Spacing * 3)); |
| 7203 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7204 | TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn |
| 7205 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7206 | TmpInst.addOperand(Inst.getOperand(3)); // Rm |
| 7207 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 7208 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7209 | Inst = TmpInst; |
| 7210 | return true; |
| 7211 | } |
| 7212 | |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 7213 | // VST3 multiple 3-element structure instructions. |
| 7214 | case ARM::VST3dAsm_8: |
| 7215 | case ARM::VST3dAsm_16: |
| 7216 | case ARM::VST3dAsm_32: |
| 7217 | case ARM::VST3qAsm_8: |
| 7218 | case ARM::VST3qAsm_16: |
| 7219 | case ARM::VST3qAsm_32: { |
| 7220 | MCInst TmpInst; |
| 7221 | unsigned Spacing; |
| 7222 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
| 7223 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7224 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7225 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7226 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7227 | Spacing)); |
| 7228 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7229 | Spacing * 2)); |
| 7230 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7231 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7232 | Inst = TmpInst; |
| 7233 | return true; |
| 7234 | } |
| 7235 | |
| 7236 | case ARM::VST3dWB_fixed_Asm_8: |
| 7237 | case ARM::VST3dWB_fixed_Asm_16: |
| 7238 | case ARM::VST3dWB_fixed_Asm_32: |
| 7239 | case ARM::VST3qWB_fixed_Asm_8: |
| 7240 | case ARM::VST3qWB_fixed_Asm_16: |
| 7241 | case ARM::VST3qWB_fixed_Asm_32: { |
| 7242 | MCInst TmpInst; |
| 7243 | unsigned Spacing; |
| 7244 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
| 7245 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7246 | TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn |
| 7247 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7248 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 7249 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7250 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7251 | Spacing)); |
| 7252 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7253 | Spacing * 2)); |
| 7254 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7255 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7256 | Inst = TmpInst; |
| 7257 | return true; |
| 7258 | } |
| 7259 | |
| 7260 | case ARM::VST3dWB_register_Asm_8: |
| 7261 | case ARM::VST3dWB_register_Asm_16: |
| 7262 | case ARM::VST3dWB_register_Asm_32: |
| 7263 | case ARM::VST3qWB_register_Asm_8: |
| 7264 | case ARM::VST3qWB_register_Asm_16: |
| 7265 | case ARM::VST3qWB_register_Asm_32: { |
| 7266 | MCInst TmpInst; |
| 7267 | unsigned Spacing; |
| 7268 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
| 7269 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7270 | TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn |
| 7271 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7272 | TmpInst.addOperand(Inst.getOperand(3)); // Rm |
| 7273 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7274 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7275 | Spacing)); |
| 7276 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7277 | Spacing * 2)); |
| 7278 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 7279 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7280 | Inst = TmpInst; |
| 7281 | return true; |
| 7282 | } |
| 7283 | |
Jim Grosbach | da70eac | 2012-01-24 00:58:13 +0000 | [diff] [blame] | 7284 | // VST4 multiple 3-element structure instructions. |
| 7285 | case ARM::VST4dAsm_8: |
| 7286 | case ARM::VST4dAsm_16: |
| 7287 | case ARM::VST4dAsm_32: |
| 7288 | case ARM::VST4qAsm_8: |
| 7289 | case ARM::VST4qAsm_16: |
| 7290 | case ARM::VST4qAsm_32: { |
| 7291 | MCInst TmpInst; |
| 7292 | unsigned Spacing; |
| 7293 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
| 7294 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7295 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7296 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7297 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7298 | Spacing)); |
| 7299 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7300 | Spacing * 2)); |
| 7301 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7302 | Spacing * 3)); |
| 7303 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7304 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7305 | Inst = TmpInst; |
| 7306 | return true; |
| 7307 | } |
| 7308 | |
| 7309 | case ARM::VST4dWB_fixed_Asm_8: |
| 7310 | case ARM::VST4dWB_fixed_Asm_16: |
| 7311 | case ARM::VST4dWB_fixed_Asm_32: |
| 7312 | case ARM::VST4qWB_fixed_Asm_8: |
| 7313 | case ARM::VST4qWB_fixed_Asm_16: |
| 7314 | case ARM::VST4qWB_fixed_Asm_32: { |
| 7315 | MCInst TmpInst; |
| 7316 | unsigned Spacing; |
| 7317 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
| 7318 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7319 | TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn |
| 7320 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7321 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 7322 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7323 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7324 | Spacing)); |
| 7325 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7326 | Spacing * 2)); |
| 7327 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7328 | Spacing * 3)); |
| 7329 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7330 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7331 | Inst = TmpInst; |
| 7332 | return true; |
| 7333 | } |
| 7334 | |
| 7335 | case ARM::VST4dWB_register_Asm_8: |
| 7336 | case ARM::VST4dWB_register_Asm_16: |
| 7337 | case ARM::VST4dWB_register_Asm_32: |
| 7338 | case ARM::VST4qWB_register_Asm_8: |
| 7339 | case ARM::VST4qWB_register_Asm_16: |
| 7340 | case ARM::VST4qWB_register_Asm_32: { |
| 7341 | MCInst TmpInst; |
| 7342 | unsigned Spacing; |
| 7343 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
| 7344 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7345 | TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn |
| 7346 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7347 | TmpInst.addOperand(Inst.getOperand(3)); // Rm |
| 7348 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7349 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7350 | Spacing)); |
| 7351 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7352 | Spacing * 2)); |
| 7353 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7354 | Spacing * 3)); |
| 7355 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 7356 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7357 | Inst = TmpInst; |
| 7358 | return true; |
| 7359 | } |
| 7360 | |
Jim Grosbach | ad66de1 | 2012-04-11 00:15:16 +0000 | [diff] [blame] | 7361 | // Handle encoding choice for the shift-immediate instructions. |
| 7362 | case ARM::t2LSLri: |
| 7363 | case ARM::t2LSRri: |
| 7364 | case ARM::t2ASRri: { |
| 7365 | if (isARMLowRegister(Inst.getOperand(0).getReg()) && |
| 7366 | Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() && |
| 7367 | Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 7368 | !(static_cast<ARMOperand &>(*Operands[3]).isToken() && |
| 7369 | static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w")) { |
Jim Grosbach | ad66de1 | 2012-04-11 00:15:16 +0000 | [diff] [blame] | 7370 | unsigned NewOpc; |
| 7371 | switch (Inst.getOpcode()) { |
| 7372 | default: llvm_unreachable("unexpected opcode"); |
| 7373 | case ARM::t2LSLri: NewOpc = ARM::tLSLri; break; |
| 7374 | case ARM::t2LSRri: NewOpc = ARM::tLSRri; break; |
| 7375 | case ARM::t2ASRri: NewOpc = ARM::tASRri; break; |
| 7376 | } |
| 7377 | // The Thumb1 operands aren't in the same order. Awesome, eh? |
| 7378 | MCInst TmpInst; |
| 7379 | TmpInst.setOpcode(NewOpc); |
| 7380 | TmpInst.addOperand(Inst.getOperand(0)); |
| 7381 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7382 | TmpInst.addOperand(Inst.getOperand(1)); |
| 7383 | TmpInst.addOperand(Inst.getOperand(2)); |
| 7384 | TmpInst.addOperand(Inst.getOperand(3)); |
| 7385 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7386 | Inst = TmpInst; |
| 7387 | return true; |
| 7388 | } |
| 7389 | return false; |
| 7390 | } |
| 7391 | |
Jim Grosbach | 485e562 | 2011-12-13 22:45:11 +0000 | [diff] [blame] | 7392 | // Handle the Thumb2 mode MOV complex aliases. |
Jim Grosbach | b3ef713 | 2011-12-21 20:54:00 +0000 | [diff] [blame] | 7393 | case ARM::t2MOVsr: |
| 7394 | case ARM::t2MOVSsr: { |
| 7395 | // Which instruction to expand to depends on the CCOut operand and |
| 7396 | // whether we're in an IT block if the register operands are low |
| 7397 | // registers. |
| 7398 | bool isNarrow = false; |
| 7399 | if (isARMLowRegister(Inst.getOperand(0).getReg()) && |
| 7400 | isARMLowRegister(Inst.getOperand(1).getReg()) && |
| 7401 | isARMLowRegister(Inst.getOperand(2).getReg()) && |
| 7402 | Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() && |
| 7403 | inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr)) |
| 7404 | isNarrow = true; |
| 7405 | MCInst TmpInst; |
| 7406 | unsigned newOpc; |
| 7407 | switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) { |
| 7408 | default: llvm_unreachable("unexpected opcode!"); |
| 7409 | case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break; |
| 7410 | case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break; |
| 7411 | case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break; |
| 7412 | case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break; |
| 7413 | } |
| 7414 | TmpInst.setOpcode(newOpc); |
| 7415 | TmpInst.addOperand(Inst.getOperand(0)); // Rd |
| 7416 | if (isNarrow) |
| 7417 | TmpInst.addOperand(MCOperand::CreateReg( |
| 7418 | Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0)); |
| 7419 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7420 | TmpInst.addOperand(Inst.getOperand(2)); // Rm |
| 7421 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 7422 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7423 | if (!isNarrow) |
| 7424 | TmpInst.addOperand(MCOperand::CreateReg( |
| 7425 | Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0)); |
| 7426 | Inst = TmpInst; |
| 7427 | return true; |
| 7428 | } |
Jim Grosbach | 485e562 | 2011-12-13 22:45:11 +0000 | [diff] [blame] | 7429 | case ARM::t2MOVsi: |
| 7430 | case ARM::t2MOVSsi: { |
| 7431 | // Which instruction to expand to depends on the CCOut operand and |
| 7432 | // whether we're in an IT block if the register operands are low |
| 7433 | // registers. |
| 7434 | bool isNarrow = false; |
| 7435 | if (isARMLowRegister(Inst.getOperand(0).getReg()) && |
| 7436 | isARMLowRegister(Inst.getOperand(1).getReg()) && |
| 7437 | inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi)) |
| 7438 | isNarrow = true; |
| 7439 | MCInst TmpInst; |
| 7440 | unsigned newOpc; |
| 7441 | switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) { |
| 7442 | default: llvm_unreachable("unexpected opcode!"); |
| 7443 | case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break; |
| 7444 | case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break; |
| 7445 | case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break; |
| 7446 | case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break; |
Jim Grosbach | 8c59bbc | 2011-12-21 21:04:19 +0000 | [diff] [blame] | 7447 | case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break; |
Jim Grosbach | 485e562 | 2011-12-13 22:45:11 +0000 | [diff] [blame] | 7448 | } |
Benjamin Kramer | bde9176 | 2012-06-02 10:20:22 +0000 | [diff] [blame] | 7449 | unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()); |
| 7450 | if (Amount == 32) Amount = 0; |
Jim Grosbach | 485e562 | 2011-12-13 22:45:11 +0000 | [diff] [blame] | 7451 | TmpInst.setOpcode(newOpc); |
| 7452 | TmpInst.addOperand(Inst.getOperand(0)); // Rd |
| 7453 | if (isNarrow) |
| 7454 | TmpInst.addOperand(MCOperand::CreateReg( |
| 7455 | Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0)); |
| 7456 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
Jim Grosbach | 8c59bbc | 2011-12-21 21:04:19 +0000 | [diff] [blame] | 7457 | if (newOpc != ARM::t2RRX) |
Benjamin Kramer | bde9176 | 2012-06-02 10:20:22 +0000 | [diff] [blame] | 7458 | TmpInst.addOperand(MCOperand::CreateImm(Amount)); |
Jim Grosbach | 485e562 | 2011-12-13 22:45:11 +0000 | [diff] [blame] | 7459 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7460 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7461 | if (!isNarrow) |
| 7462 | TmpInst.addOperand(MCOperand::CreateReg( |
| 7463 | Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0)); |
| 7464 | Inst = TmpInst; |
| 7465 | return true; |
| 7466 | } |
| 7467 | // Handle the ARM mode MOV complex aliases. |
Jim Grosbach | abcac56 | 2011-11-16 18:31:45 +0000 | [diff] [blame] | 7468 | case ARM::ASRr: |
| 7469 | case ARM::LSRr: |
| 7470 | case ARM::LSLr: |
| 7471 | case ARM::RORr: { |
| 7472 | ARM_AM::ShiftOpc ShiftTy; |
| 7473 | switch(Inst.getOpcode()) { |
| 7474 | default: llvm_unreachable("unexpected opcode!"); |
| 7475 | case ARM::ASRr: ShiftTy = ARM_AM::asr; break; |
| 7476 | case ARM::LSRr: ShiftTy = ARM_AM::lsr; break; |
| 7477 | case ARM::LSLr: ShiftTy = ARM_AM::lsl; break; |
| 7478 | case ARM::RORr: ShiftTy = ARM_AM::ror; break; |
| 7479 | } |
Jim Grosbach | abcac56 | 2011-11-16 18:31:45 +0000 | [diff] [blame] | 7480 | unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0); |
| 7481 | MCInst TmpInst; |
| 7482 | TmpInst.setOpcode(ARM::MOVsr); |
| 7483 | TmpInst.addOperand(Inst.getOperand(0)); // Rd |
| 7484 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7485 | TmpInst.addOperand(Inst.getOperand(2)); // Rm |
| 7486 | TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty |
| 7487 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7488 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7489 | TmpInst.addOperand(Inst.getOperand(5)); // cc_out |
| 7490 | Inst = TmpInst; |
| 7491 | return true; |
| 7492 | } |
Jim Grosbach | c14871c | 2011-11-10 19:18:01 +0000 | [diff] [blame] | 7493 | case ARM::ASRi: |
| 7494 | case ARM::LSRi: |
| 7495 | case ARM::LSLi: |
| 7496 | case ARM::RORi: { |
| 7497 | ARM_AM::ShiftOpc ShiftTy; |
Jim Grosbach | c14871c | 2011-11-10 19:18:01 +0000 | [diff] [blame] | 7498 | switch(Inst.getOpcode()) { |
| 7499 | default: llvm_unreachable("unexpected opcode!"); |
| 7500 | case ARM::ASRi: ShiftTy = ARM_AM::asr; break; |
| 7501 | case ARM::LSRi: ShiftTy = ARM_AM::lsr; break; |
| 7502 | case ARM::LSLi: ShiftTy = ARM_AM::lsl; break; |
| 7503 | case ARM::RORi: ShiftTy = ARM_AM::ror; break; |
| 7504 | } |
| 7505 | // A shift by zero is a plain MOVr, not a MOVsi. |
Jim Grosbach | 1a2f9ee | 2011-11-16 19:05:59 +0000 | [diff] [blame] | 7506 | unsigned Amt = Inst.getOperand(2).getImm(); |
Jim Grosbach | c14871c | 2011-11-10 19:18:01 +0000 | [diff] [blame] | 7507 | unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi; |
Richard Barton | ba5b0cc | 2012-04-25 18:00:18 +0000 | [diff] [blame] | 7508 | // A shift by 32 should be encoded as 0 when permitted |
| 7509 | if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr)) |
| 7510 | Amt = 0; |
Jim Grosbach | c14871c | 2011-11-10 19:18:01 +0000 | [diff] [blame] | 7511 | unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt); |
Jim Grosbach | 61db5a5 | 2011-11-10 16:44:55 +0000 | [diff] [blame] | 7512 | MCInst TmpInst; |
Jim Grosbach | c14871c | 2011-11-10 19:18:01 +0000 | [diff] [blame] | 7513 | TmpInst.setOpcode(Opc); |
Jim Grosbach | 61db5a5 | 2011-11-10 16:44:55 +0000 | [diff] [blame] | 7514 | TmpInst.addOperand(Inst.getOperand(0)); // Rd |
| 7515 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
Jim Grosbach | c14871c | 2011-11-10 19:18:01 +0000 | [diff] [blame] | 7516 | if (Opc == ARM::MOVsi) |
| 7517 | TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty |
Jim Grosbach | 61db5a5 | 2011-11-10 16:44:55 +0000 | [diff] [blame] | 7518 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7519 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7520 | TmpInst.addOperand(Inst.getOperand(5)); // cc_out |
| 7521 | Inst = TmpInst; |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7522 | return true; |
Jim Grosbach | 61db5a5 | 2011-11-10 16:44:55 +0000 | [diff] [blame] | 7523 | } |
Jim Grosbach | 1a2f9ee | 2011-11-16 19:05:59 +0000 | [diff] [blame] | 7524 | case ARM::RRXi: { |
| 7525 | unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0); |
| 7526 | MCInst TmpInst; |
| 7527 | TmpInst.setOpcode(ARM::MOVsi); |
| 7528 | TmpInst.addOperand(Inst.getOperand(0)); // Rd |
| 7529 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7530 | TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty |
| 7531 | TmpInst.addOperand(Inst.getOperand(2)); // CondCode |
| 7532 | TmpInst.addOperand(Inst.getOperand(3)); |
| 7533 | TmpInst.addOperand(Inst.getOperand(4)); // cc_out |
| 7534 | Inst = TmpInst; |
| 7535 | return true; |
| 7536 | } |
Jim Grosbach | d9a9be2 | 2011-11-10 23:58:34 +0000 | [diff] [blame] | 7537 | case ARM::t2LDMIA_UPD: { |
| 7538 | // If this is a load of a single register, then we should use |
| 7539 | // a post-indexed LDR instruction instead, per the ARM ARM. |
| 7540 | if (Inst.getNumOperands() != 5) |
| 7541 | return false; |
| 7542 | MCInst TmpInst; |
| 7543 | TmpInst.setOpcode(ARM::t2LDR_POST); |
| 7544 | TmpInst.addOperand(Inst.getOperand(4)); // Rt |
| 7545 | TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb |
| 7546 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7547 | TmpInst.addOperand(MCOperand::CreateImm(4)); |
| 7548 | TmpInst.addOperand(Inst.getOperand(2)); // CondCode |
| 7549 | TmpInst.addOperand(Inst.getOperand(3)); |
| 7550 | Inst = TmpInst; |
| 7551 | return true; |
| 7552 | } |
| 7553 | case ARM::t2STMDB_UPD: { |
| 7554 | // If this is a store of a single register, then we should use |
| 7555 | // a pre-indexed STR instruction instead, per the ARM ARM. |
| 7556 | if (Inst.getNumOperands() != 5) |
| 7557 | return false; |
| 7558 | MCInst TmpInst; |
| 7559 | TmpInst.setOpcode(ARM::t2STR_PRE); |
| 7560 | TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb |
| 7561 | TmpInst.addOperand(Inst.getOperand(4)); // Rt |
| 7562 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7563 | TmpInst.addOperand(MCOperand::CreateImm(-4)); |
| 7564 | TmpInst.addOperand(Inst.getOperand(2)); // CondCode |
| 7565 | TmpInst.addOperand(Inst.getOperand(3)); |
| 7566 | Inst = TmpInst; |
| 7567 | return true; |
| 7568 | } |
Jim Grosbach | 8ba76c6 | 2011-08-11 17:35:48 +0000 | [diff] [blame] | 7569 | case ARM::LDMIA_UPD: |
| 7570 | // If this is a load of a single register via a 'pop', then we should use |
| 7571 | // a post-indexed LDR instruction instead, per the ARM ARM. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 7572 | if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "pop" && |
Jim Grosbach | 8ba76c6 | 2011-08-11 17:35:48 +0000 | [diff] [blame] | 7573 | Inst.getNumOperands() == 5) { |
| 7574 | MCInst TmpInst; |
| 7575 | TmpInst.setOpcode(ARM::LDR_POST_IMM); |
| 7576 | TmpInst.addOperand(Inst.getOperand(4)); // Rt |
| 7577 | TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb |
| 7578 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7579 | TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset |
| 7580 | TmpInst.addOperand(MCOperand::CreateImm(4)); |
| 7581 | TmpInst.addOperand(Inst.getOperand(2)); // CondCode |
| 7582 | TmpInst.addOperand(Inst.getOperand(3)); |
| 7583 | Inst = TmpInst; |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7584 | return true; |
Jim Grosbach | 8ba76c6 | 2011-08-11 17:35:48 +0000 | [diff] [blame] | 7585 | } |
| 7586 | break; |
Jim Grosbach | 27ad83d | 2011-08-11 18:07:11 +0000 | [diff] [blame] | 7587 | case ARM::STMDB_UPD: |
| 7588 | // If this is a store of a single register via a 'push', then we should use |
| 7589 | // a pre-indexed STR instruction instead, per the ARM ARM. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 7590 | if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "push" && |
Jim Grosbach | 27ad83d | 2011-08-11 18:07:11 +0000 | [diff] [blame] | 7591 | Inst.getNumOperands() == 5) { |
| 7592 | MCInst TmpInst; |
| 7593 | TmpInst.setOpcode(ARM::STR_PRE_IMM); |
| 7594 | TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb |
| 7595 | TmpInst.addOperand(Inst.getOperand(4)); // Rt |
| 7596 | TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12 |
| 7597 | TmpInst.addOperand(MCOperand::CreateImm(-4)); |
| 7598 | TmpInst.addOperand(Inst.getOperand(2)); // CondCode |
| 7599 | TmpInst.addOperand(Inst.getOperand(3)); |
| 7600 | Inst = TmpInst; |
| 7601 | } |
| 7602 | break; |
Jim Grosbach | ec9ba98 | 2011-12-05 21:06:26 +0000 | [diff] [blame] | 7603 | case ARM::t2ADDri12: |
| 7604 | // If the immediate fits for encoding T3 (t2ADDri) and the generic "add" |
| 7605 | // mnemonic was used (not "addw"), encoding T3 is preferred. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 7606 | if (static_cast<ARMOperand &>(*Operands[0]).getToken() != "add" || |
Jim Grosbach | ec9ba98 | 2011-12-05 21:06:26 +0000 | [diff] [blame] | 7607 | ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1) |
| 7608 | break; |
| 7609 | Inst.setOpcode(ARM::t2ADDri); |
| 7610 | Inst.addOperand(MCOperand::CreateReg(0)); // cc_out |
| 7611 | break; |
| 7612 | case ARM::t2SUBri12: |
| 7613 | // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub" |
| 7614 | // mnemonic was used (not "subw"), encoding T3 is preferred. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 7615 | if (static_cast<ARMOperand &>(*Operands[0]).getToken() != "sub" || |
Jim Grosbach | ec9ba98 | 2011-12-05 21:06:26 +0000 | [diff] [blame] | 7616 | ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1) |
| 7617 | break; |
| 7618 | Inst.setOpcode(ARM::t2SUBri); |
| 7619 | Inst.addOperand(MCOperand::CreateReg(0)); // cc_out |
| 7620 | break; |
Jim Grosbach | e9ab47a | 2011-08-16 23:57:34 +0000 | [diff] [blame] | 7621 | case ARM::tADDi8: |
Sylvestre Ledru | 91ce36c | 2012-09-27 10:14:43 +0000 | [diff] [blame] | 7622 | // If the immediate is in the range 0-7, we want tADDi3 iff Rd was |
Jim Grosbach | 6d606fb | 2011-08-31 17:07:33 +0000 | [diff] [blame] | 7623 | // explicitly specified. From the ARM ARM: "Encoding T1 is preferred |
| 7624 | // to encoding T2 if <Rd> is specified and encoding T2 is preferred |
| 7625 | // to encoding T1 if <Rd> is omitted." |
Jim Grosbach | 199ab90 | 2012-03-30 16:31:31 +0000 | [diff] [blame] | 7626 | if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) { |
Jim Grosbach | e9ab47a | 2011-08-16 23:57:34 +0000 | [diff] [blame] | 7627 | Inst.setOpcode(ARM::tADDi3); |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7628 | return true; |
| 7629 | } |
Jim Grosbach | e9ab47a | 2011-08-16 23:57:34 +0000 | [diff] [blame] | 7630 | break; |
Jim Grosbach | d0c435c | 2011-09-16 22:58:42 +0000 | [diff] [blame] | 7631 | case ARM::tSUBi8: |
Sylvestre Ledru | 91ce36c | 2012-09-27 10:14:43 +0000 | [diff] [blame] | 7632 | // If the immediate is in the range 0-7, we want tADDi3 iff Rd was |
Jim Grosbach | d0c435c | 2011-09-16 22:58:42 +0000 | [diff] [blame] | 7633 | // explicitly specified. From the ARM ARM: "Encoding T1 is preferred |
| 7634 | // to encoding T2 if <Rd> is specified and encoding T2 is preferred |
| 7635 | // to encoding T1 if <Rd> is omitted." |
Jim Grosbach | 199ab90 | 2012-03-30 16:31:31 +0000 | [diff] [blame] | 7636 | if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) { |
Jim Grosbach | d0c435c | 2011-09-16 22:58:42 +0000 | [diff] [blame] | 7637 | Inst.setOpcode(ARM::tSUBi3); |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7638 | return true; |
| 7639 | } |
Jim Grosbach | d0c435c | 2011-09-16 22:58:42 +0000 | [diff] [blame] | 7640 | break; |
Jim Grosbach | def5e34 | 2012-03-30 17:20:40 +0000 | [diff] [blame] | 7641 | case ARM::t2ADDri: |
| 7642 | case ARM::t2SUBri: { |
| 7643 | // If the destination and first source operand are the same, and |
| 7644 | // the flags are compatible with the current IT status, use encoding T2 |
| 7645 | // instead of T3. For compatibility with the system 'as'. Make sure the |
| 7646 | // wide encoding wasn't explicit. |
| 7647 | if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() || |
Jim Grosbach | 74005ae | 2012-03-30 18:39:43 +0000 | [diff] [blame] | 7648 | !isARMLowRegister(Inst.getOperand(0).getReg()) || |
Jim Grosbach | def5e34 | 2012-03-30 17:20:40 +0000 | [diff] [blame] | 7649 | (unsigned)Inst.getOperand(2).getImm() > 255 || |
| 7650 | ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) || |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 7651 | (inITBlock() && Inst.getOperand(5).getReg() != 0)) || |
| 7652 | (static_cast<ARMOperand &>(*Operands[3]).isToken() && |
| 7653 | static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w")) |
Jim Grosbach | def5e34 | 2012-03-30 17:20:40 +0000 | [diff] [blame] | 7654 | break; |
| 7655 | MCInst TmpInst; |
| 7656 | TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ? |
| 7657 | ARM::tADDi8 : ARM::tSUBi8); |
| 7658 | TmpInst.addOperand(Inst.getOperand(0)); |
| 7659 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7660 | TmpInst.addOperand(Inst.getOperand(0)); |
| 7661 | TmpInst.addOperand(Inst.getOperand(2)); |
| 7662 | TmpInst.addOperand(Inst.getOperand(3)); |
| 7663 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7664 | Inst = TmpInst; |
| 7665 | return true; |
| 7666 | } |
Jim Grosbach | e489bab | 2011-12-05 22:16:39 +0000 | [diff] [blame] | 7667 | case ARM::t2ADDrr: { |
| 7668 | // If the destination and first source operand are the same, and |
| 7669 | // there's no setting of the flags, use encoding T2 instead of T3. |
| 7670 | // Note that this is only for ADD, not SUB. This mirrors the system |
| 7671 | // 'as' behaviour. Make sure the wide encoding wasn't explicit. |
| 7672 | if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() || |
| 7673 | Inst.getOperand(5).getReg() != 0 || |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 7674 | (static_cast<ARMOperand &>(*Operands[3]).isToken() && |
| 7675 | static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w")) |
Jim Grosbach | e489bab | 2011-12-05 22:16:39 +0000 | [diff] [blame] | 7676 | break; |
| 7677 | MCInst TmpInst; |
| 7678 | TmpInst.setOpcode(ARM::tADDhirr); |
| 7679 | TmpInst.addOperand(Inst.getOperand(0)); |
| 7680 | TmpInst.addOperand(Inst.getOperand(0)); |
| 7681 | TmpInst.addOperand(Inst.getOperand(2)); |
| 7682 | TmpInst.addOperand(Inst.getOperand(3)); |
| 7683 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7684 | Inst = TmpInst; |
| 7685 | return true; |
| 7686 | } |
Jim Grosbach | c6f32b3 | 2012-04-27 23:51:36 +0000 | [diff] [blame] | 7687 | case ARM::tADDrSP: { |
| 7688 | // If the non-SP source operand and the destination operand are not the |
| 7689 | // same, we need to use the 32-bit encoding if it's available. |
| 7690 | if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) { |
| 7691 | Inst.setOpcode(ARM::t2ADDrr); |
| 7692 | Inst.addOperand(MCOperand::CreateReg(0)); // cc_out |
| 7693 | return true; |
| 7694 | } |
| 7695 | break; |
| 7696 | } |
Owen Anderson | 29cfe6c | 2011-09-09 21:48:23 +0000 | [diff] [blame] | 7697 | case ARM::tB: |
| 7698 | // A Thumb conditional branch outside of an IT block is a tBcc. |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7699 | if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) { |
Owen Anderson | 29cfe6c | 2011-09-09 21:48:23 +0000 | [diff] [blame] | 7700 | Inst.setOpcode(ARM::tBcc); |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7701 | return true; |
| 7702 | } |
Owen Anderson | 29cfe6c | 2011-09-09 21:48:23 +0000 | [diff] [blame] | 7703 | break; |
| 7704 | case ARM::t2B: |
| 7705 | // A Thumb2 conditional branch outside of an IT block is a t2Bcc. |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7706 | if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){ |
Owen Anderson | 29cfe6c | 2011-09-09 21:48:23 +0000 | [diff] [blame] | 7707 | Inst.setOpcode(ARM::t2Bcc); |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7708 | return true; |
| 7709 | } |
Owen Anderson | 29cfe6c | 2011-09-09 21:48:23 +0000 | [diff] [blame] | 7710 | break; |
Jim Grosbach | 99bc846 | 2011-08-31 21:17:31 +0000 | [diff] [blame] | 7711 | case ARM::t2Bcc: |
Jim Grosbach | a0d34d3 | 2011-09-02 23:22:08 +0000 | [diff] [blame] | 7712 | // If the conditional is AL or we're in an IT block, we really want t2B. |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7713 | if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) { |
Jim Grosbach | 99bc846 | 2011-08-31 21:17:31 +0000 | [diff] [blame] | 7714 | Inst.setOpcode(ARM::t2B); |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7715 | return true; |
| 7716 | } |
Jim Grosbach | 99bc846 | 2011-08-31 21:17:31 +0000 | [diff] [blame] | 7717 | break; |
Jim Grosbach | cbd4ab1 | 2011-08-17 22:57:40 +0000 | [diff] [blame] | 7718 | case ARM::tBcc: |
| 7719 | // If the conditional is AL, we really want tB. |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7720 | if (Inst.getOperand(1).getImm() == ARMCC::AL) { |
Jim Grosbach | cbd4ab1 | 2011-08-17 22:57:40 +0000 | [diff] [blame] | 7721 | Inst.setOpcode(ARM::tB); |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7722 | return true; |
| 7723 | } |
Jim Grosbach | 6ddb568 | 2011-08-18 16:08:39 +0000 | [diff] [blame] | 7724 | break; |
Jim Grosbach | a31f223 | 2011-09-07 18:05:34 +0000 | [diff] [blame] | 7725 | case ARM::tLDMIA: { |
| 7726 | // If the register list contains any high registers, or if the writeback |
| 7727 | // doesn't match what tLDMIA can do, we need to use the 32-bit encoding |
| 7728 | // instead if we're in Thumb2. Otherwise, this should have generated |
| 7729 | // an error in validateInstruction(). |
| 7730 | unsigned Rn = Inst.getOperand(0).getReg(); |
| 7731 | bool hasWritebackToken = |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 7732 | (static_cast<ARMOperand &>(*Operands[3]).isToken() && |
| 7733 | static_cast<ARMOperand &>(*Operands[3]).getToken() == "!"); |
Jim Grosbach | a31f223 | 2011-09-07 18:05:34 +0000 | [diff] [blame] | 7734 | bool listContainsBase; |
| 7735 | if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) || |
| 7736 | (!listContainsBase && !hasWritebackToken) || |
| 7737 | (listContainsBase && hasWritebackToken)) { |
| 7738 | // 16-bit encoding isn't sufficient. Switch to the 32-bit version. |
| 7739 | assert (isThumbTwo()); |
| 7740 | Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA); |
| 7741 | // If we're switching to the updating version, we need to insert |
| 7742 | // the writeback tied operand. |
| 7743 | if (hasWritebackToken) |
| 7744 | Inst.insert(Inst.begin(), |
| 7745 | MCOperand::CreateReg(Inst.getOperand(0).getReg())); |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7746 | return true; |
Jim Grosbach | a31f223 | 2011-09-07 18:05:34 +0000 | [diff] [blame] | 7747 | } |
| 7748 | break; |
| 7749 | } |
Jim Grosbach | 099c976 | 2011-09-16 20:50:13 +0000 | [diff] [blame] | 7750 | case ARM::tSTMIA_UPD: { |
| 7751 | // If the register list contains any high registers, we need to use |
| 7752 | // the 32-bit encoding instead if we're in Thumb2. Otherwise, this |
| 7753 | // should have generated an error in validateInstruction(). |
| 7754 | unsigned Rn = Inst.getOperand(0).getReg(); |
| 7755 | bool listContainsBase; |
| 7756 | if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) { |
| 7757 | // 16-bit encoding isn't sufficient. Switch to the 32-bit version. |
| 7758 | assert (isThumbTwo()); |
| 7759 | Inst.setOpcode(ARM::t2STMIA_UPD); |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7760 | return true; |
Jim Grosbach | 099c976 | 2011-09-16 20:50:13 +0000 | [diff] [blame] | 7761 | } |
| 7762 | break; |
| 7763 | } |
Jim Grosbach | 9bded9d | 2011-11-10 23:17:11 +0000 | [diff] [blame] | 7764 | case ARM::tPOP: { |
| 7765 | bool listContainsBase; |
| 7766 | // If the register list contains any high registers, we need to use |
| 7767 | // the 32-bit encoding instead if we're in Thumb2. Otherwise, this |
| 7768 | // should have generated an error in validateInstruction(). |
| 7769 | if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase)) |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7770 | return false; |
Jim Grosbach | 9bded9d | 2011-11-10 23:17:11 +0000 | [diff] [blame] | 7771 | assert (isThumbTwo()); |
| 7772 | Inst.setOpcode(ARM::t2LDMIA_UPD); |
| 7773 | // Add the base register and writeback operands. |
| 7774 | Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP)); |
| 7775 | Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP)); |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7776 | return true; |
Jim Grosbach | 9bded9d | 2011-11-10 23:17:11 +0000 | [diff] [blame] | 7777 | } |
| 7778 | case ARM::tPUSH: { |
| 7779 | bool listContainsBase; |
| 7780 | if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase)) |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7781 | return false; |
Jim Grosbach | 9bded9d | 2011-11-10 23:17:11 +0000 | [diff] [blame] | 7782 | assert (isThumbTwo()); |
| 7783 | Inst.setOpcode(ARM::t2STMDB_UPD); |
| 7784 | // Add the base register and writeback operands. |
| 7785 | Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP)); |
| 7786 | Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP)); |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7787 | return true; |
Jim Grosbach | 9bded9d | 2011-11-10 23:17:11 +0000 | [diff] [blame] | 7788 | } |
Jim Grosbach | b908b7a | 2011-09-10 00:15:36 +0000 | [diff] [blame] | 7789 | case ARM::t2MOVi: { |
| 7790 | // If we can use the 16-bit encoding and the user didn't explicitly |
| 7791 | // request the 32-bit variant, transform it here. |
| 7792 | if (isARMLowRegister(Inst.getOperand(0).getReg()) && |
Jim Grosbach | 199ab90 | 2012-03-30 16:31:31 +0000 | [diff] [blame] | 7793 | (unsigned)Inst.getOperand(1).getImm() <= 255 && |
Jim Grosbach | 18b8b17 | 2011-09-14 19:12:11 +0000 | [diff] [blame] | 7794 | ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 7795 | Inst.getOperand(4).getReg() == ARM::CPSR) || |
| 7796 | (inITBlock() && Inst.getOperand(4).getReg() == 0)) && |
| 7797 | (!static_cast<ARMOperand &>(*Operands[2]).isToken() || |
| 7798 | static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) { |
Jim Grosbach | b908b7a | 2011-09-10 00:15:36 +0000 | [diff] [blame] | 7799 | // The operands aren't in the same order for tMOVi8... |
| 7800 | MCInst TmpInst; |
| 7801 | TmpInst.setOpcode(ARM::tMOVi8); |
| 7802 | TmpInst.addOperand(Inst.getOperand(0)); |
| 7803 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7804 | TmpInst.addOperand(Inst.getOperand(1)); |
| 7805 | TmpInst.addOperand(Inst.getOperand(2)); |
| 7806 | TmpInst.addOperand(Inst.getOperand(3)); |
| 7807 | Inst = TmpInst; |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7808 | return true; |
Jim Grosbach | b908b7a | 2011-09-10 00:15:36 +0000 | [diff] [blame] | 7809 | } |
| 7810 | break; |
| 7811 | } |
| 7812 | case ARM::t2MOVr: { |
| 7813 | // If we can use the 16-bit encoding and the user didn't explicitly |
| 7814 | // request the 32-bit variant, transform it here. |
| 7815 | if (isARMLowRegister(Inst.getOperand(0).getReg()) && |
| 7816 | isARMLowRegister(Inst.getOperand(1).getReg()) && |
| 7817 | Inst.getOperand(2).getImm() == ARMCC::AL && |
| 7818 | Inst.getOperand(4).getReg() == ARM::CPSR && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 7819 | (!static_cast<ARMOperand &>(*Operands[2]).isToken() || |
| 7820 | static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) { |
Jim Grosbach | b908b7a | 2011-09-10 00:15:36 +0000 | [diff] [blame] | 7821 | // The operands aren't the same for tMOV[S]r... (no cc_out) |
| 7822 | MCInst TmpInst; |
| 7823 | TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr); |
| 7824 | TmpInst.addOperand(Inst.getOperand(0)); |
| 7825 | TmpInst.addOperand(Inst.getOperand(1)); |
| 7826 | TmpInst.addOperand(Inst.getOperand(2)); |
| 7827 | TmpInst.addOperand(Inst.getOperand(3)); |
| 7828 | Inst = TmpInst; |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7829 | return true; |
Jim Grosbach | b908b7a | 2011-09-10 00:15:36 +0000 | [diff] [blame] | 7830 | } |
| 7831 | break; |
| 7832 | } |
Jim Grosbach | 8221319 | 2011-09-19 20:29:33 +0000 | [diff] [blame] | 7833 | case ARM::t2SXTH: |
Jim Grosbach | b351980 | 2011-09-20 00:46:54 +0000 | [diff] [blame] | 7834 | case ARM::t2SXTB: |
| 7835 | case ARM::t2UXTH: |
| 7836 | case ARM::t2UXTB: { |
Jim Grosbach | 8221319 | 2011-09-19 20:29:33 +0000 | [diff] [blame] | 7837 | // If we can use the 16-bit encoding and the user didn't explicitly |
| 7838 | // request the 32-bit variant, transform it here. |
| 7839 | if (isARMLowRegister(Inst.getOperand(0).getReg()) && |
| 7840 | isARMLowRegister(Inst.getOperand(1).getReg()) && |
| 7841 | Inst.getOperand(2).getImm() == 0 && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 7842 | (!static_cast<ARMOperand &>(*Operands[2]).isToken() || |
| 7843 | static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) { |
Jim Grosbach | b351980 | 2011-09-20 00:46:54 +0000 | [diff] [blame] | 7844 | unsigned NewOpc; |
| 7845 | switch (Inst.getOpcode()) { |
| 7846 | default: llvm_unreachable("Illegal opcode!"); |
| 7847 | case ARM::t2SXTH: NewOpc = ARM::tSXTH; break; |
| 7848 | case ARM::t2SXTB: NewOpc = ARM::tSXTB; break; |
| 7849 | case ARM::t2UXTH: NewOpc = ARM::tUXTH; break; |
| 7850 | case ARM::t2UXTB: NewOpc = ARM::tUXTB; break; |
| 7851 | } |
Jim Grosbach | 8221319 | 2011-09-19 20:29:33 +0000 | [diff] [blame] | 7852 | // The operands aren't the same for thumb1 (no rotate operand). |
| 7853 | MCInst TmpInst; |
| 7854 | TmpInst.setOpcode(NewOpc); |
| 7855 | TmpInst.addOperand(Inst.getOperand(0)); |
| 7856 | TmpInst.addOperand(Inst.getOperand(1)); |
| 7857 | TmpInst.addOperand(Inst.getOperand(3)); |
| 7858 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7859 | Inst = TmpInst; |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7860 | return true; |
Jim Grosbach | 8221319 | 2011-09-19 20:29:33 +0000 | [diff] [blame] | 7861 | } |
| 7862 | break; |
| 7863 | } |
Jim Grosbach | e2ca9e5 | 2011-12-20 00:59:38 +0000 | [diff] [blame] | 7864 | case ARM::MOVsi: { |
| 7865 | ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm()); |
Richard Barton | ba5b0cc | 2012-04-25 18:00:18 +0000 | [diff] [blame] | 7866 | // rrx shifts and asr/lsr of #32 is encoded as 0 |
| 7867 | if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr) |
| 7868 | return false; |
Jim Grosbach | e2ca9e5 | 2011-12-20 00:59:38 +0000 | [diff] [blame] | 7869 | if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) { |
| 7870 | // Shifting by zero is accepted as a vanilla 'MOVr' |
| 7871 | MCInst TmpInst; |
| 7872 | TmpInst.setOpcode(ARM::MOVr); |
| 7873 | TmpInst.addOperand(Inst.getOperand(0)); |
| 7874 | TmpInst.addOperand(Inst.getOperand(1)); |
| 7875 | TmpInst.addOperand(Inst.getOperand(3)); |
| 7876 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7877 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7878 | Inst = TmpInst; |
| 7879 | return true; |
| 7880 | } |
| 7881 | return false; |
| 7882 | } |
Jim Grosbach | 12ccf45 | 2011-12-22 18:04:04 +0000 | [diff] [blame] | 7883 | case ARM::ANDrsi: |
| 7884 | case ARM::ORRrsi: |
| 7885 | case ARM::EORrsi: |
| 7886 | case ARM::BICrsi: |
| 7887 | case ARM::SUBrsi: |
| 7888 | case ARM::ADDrsi: { |
| 7889 | unsigned newOpc; |
| 7890 | ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm()); |
| 7891 | if (SOpc == ARM_AM::rrx) return false; |
| 7892 | switch (Inst.getOpcode()) { |
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 7893 | default: llvm_unreachable("unexpected opcode!"); |
Jim Grosbach | 12ccf45 | 2011-12-22 18:04:04 +0000 | [diff] [blame] | 7894 | case ARM::ANDrsi: newOpc = ARM::ANDrr; break; |
| 7895 | case ARM::ORRrsi: newOpc = ARM::ORRrr; break; |
| 7896 | case ARM::EORrsi: newOpc = ARM::EORrr; break; |
| 7897 | case ARM::BICrsi: newOpc = ARM::BICrr; break; |
| 7898 | case ARM::SUBrsi: newOpc = ARM::SUBrr; break; |
| 7899 | case ARM::ADDrsi: newOpc = ARM::ADDrr; break; |
| 7900 | } |
| 7901 | // If the shift is by zero, use the non-shifted instruction definition. |
Richard Barton | 35aceb8 | 2012-07-09 16:31:14 +0000 | [diff] [blame] | 7902 | // The exception is for right shifts, where 0 == 32 |
| 7903 | if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 && |
| 7904 | !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) { |
Jim Grosbach | 12ccf45 | 2011-12-22 18:04:04 +0000 | [diff] [blame] | 7905 | MCInst TmpInst; |
| 7906 | TmpInst.setOpcode(newOpc); |
| 7907 | TmpInst.addOperand(Inst.getOperand(0)); |
| 7908 | TmpInst.addOperand(Inst.getOperand(1)); |
| 7909 | TmpInst.addOperand(Inst.getOperand(2)); |
| 7910 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7911 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7912 | TmpInst.addOperand(Inst.getOperand(6)); |
| 7913 | Inst = TmpInst; |
| 7914 | return true; |
| 7915 | } |
| 7916 | return false; |
| 7917 | } |
Jim Grosbach | 82f76d1 | 2012-01-25 19:52:01 +0000 | [diff] [blame] | 7918 | case ARM::ITasm: |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 7919 | case ARM::t2IT: { |
| 7920 | // The mask bits for all but the first condition are represented as |
| 7921 | // the low bit of the condition code value implies 't'. We currently |
| 7922 | // always have 1 implies 't', so XOR toggle the bits if the low bit |
Richard Barton | f435b09 | 2012-04-27 08:42:59 +0000 | [diff] [blame] | 7923 | // of the condition code is zero. |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 7924 | MCOperand &MO = Inst.getOperand(1); |
| 7925 | unsigned Mask = MO.getImm(); |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 7926 | unsigned OrigMask = Mask; |
Michael J. Spencer | df1ecbd7 | 2013-05-24 22:23:49 +0000 | [diff] [blame] | 7927 | unsigned TZ = countTrailingZeros(Mask); |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 7928 | if ((Inst.getOperand(0).getImm() & 1) == 0) { |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 7929 | assert(Mask && TZ <= 3 && "illegal IT mask value!"); |
Benjamin Kramer | 8bad66e | 2013-05-19 22:01:57 +0000 | [diff] [blame] | 7930 | Mask ^= (0xE << TZ) & 0xF; |
Richard Barton | f435b09 | 2012-04-27 08:42:59 +0000 | [diff] [blame] | 7931 | } |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 7932 | MO.setImm(Mask); |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 7933 | |
| 7934 | // Set up the IT block state according to the IT instruction we just |
| 7935 | // matched. |
| 7936 | assert(!inITBlock() && "nested IT blocks?!"); |
| 7937 | ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm()); |
| 7938 | ITState.Mask = OrigMask; // Use the original mask, not the updated one. |
| 7939 | ITState.CurPosition = 0; |
| 7940 | ITState.FirstCond = true; |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 7941 | break; |
| 7942 | } |
Richard Barton | a39625e | 2012-07-09 16:12:24 +0000 | [diff] [blame] | 7943 | case ARM::t2LSLrr: |
| 7944 | case ARM::t2LSRrr: |
| 7945 | case ARM::t2ASRrr: |
| 7946 | case ARM::t2SBCrr: |
| 7947 | case ARM::t2RORrr: |
| 7948 | case ARM::t2BICrr: |
| 7949 | { |
Richard Barton | d566037 | 2012-07-09 16:14:28 +0000 | [diff] [blame] | 7950 | // Assemblers should use the narrow encodings of these instructions when permissible. |
Richard Barton | a39625e | 2012-07-09 16:12:24 +0000 | [diff] [blame] | 7951 | if ((isARMLowRegister(Inst.getOperand(1).getReg()) && |
| 7952 | isARMLowRegister(Inst.getOperand(2).getReg())) && |
| 7953 | Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() && |
Richard Barton | 984d0ba | 2012-07-09 18:30:56 +0000 | [diff] [blame] | 7954 | ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) || |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 7955 | (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) && |
| 7956 | (!static_cast<ARMOperand &>(*Operands[3]).isToken() || |
| 7957 | !static_cast<ARMOperand &>(*Operands[3]).getToken().equals_lower( |
| 7958 | ".w"))) { |
Richard Barton | a39625e | 2012-07-09 16:12:24 +0000 | [diff] [blame] | 7959 | unsigned NewOpc; |
| 7960 | switch (Inst.getOpcode()) { |
| 7961 | default: llvm_unreachable("unexpected opcode"); |
| 7962 | case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break; |
| 7963 | case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break; |
| 7964 | case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break; |
| 7965 | case ARM::t2SBCrr: NewOpc = ARM::tSBC; break; |
| 7966 | case ARM::t2RORrr: NewOpc = ARM::tROR; break; |
| 7967 | case ARM::t2BICrr: NewOpc = ARM::tBIC; break; |
| 7968 | } |
| 7969 | MCInst TmpInst; |
| 7970 | TmpInst.setOpcode(NewOpc); |
| 7971 | TmpInst.addOperand(Inst.getOperand(0)); |
| 7972 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7973 | TmpInst.addOperand(Inst.getOperand(1)); |
| 7974 | TmpInst.addOperand(Inst.getOperand(2)); |
| 7975 | TmpInst.addOperand(Inst.getOperand(3)); |
| 7976 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7977 | Inst = TmpInst; |
| 7978 | return true; |
| 7979 | } |
| 7980 | return false; |
| 7981 | } |
| 7982 | case ARM::t2ANDrr: |
| 7983 | case ARM::t2EORrr: |
| 7984 | case ARM::t2ADCrr: |
| 7985 | case ARM::t2ORRrr: |
| 7986 | { |
Richard Barton | d566037 | 2012-07-09 16:14:28 +0000 | [diff] [blame] | 7987 | // Assemblers should use the narrow encodings of these instructions when permissible. |
Richard Barton | a39625e | 2012-07-09 16:12:24 +0000 | [diff] [blame] | 7988 | // These instructions are special in that they are commutable, so shorter encodings |
| 7989 | // are available more often. |
| 7990 | if ((isARMLowRegister(Inst.getOperand(1).getReg()) && |
| 7991 | isARMLowRegister(Inst.getOperand(2).getReg())) && |
| 7992 | (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() || |
| 7993 | Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) && |
Richard Barton | 984d0ba | 2012-07-09 18:30:56 +0000 | [diff] [blame] | 7994 | ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) || |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 7995 | (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) && |
| 7996 | (!static_cast<ARMOperand &>(*Operands[3]).isToken() || |
| 7997 | !static_cast<ARMOperand &>(*Operands[3]).getToken().equals_lower( |
| 7998 | ".w"))) { |
Richard Barton | a39625e | 2012-07-09 16:12:24 +0000 | [diff] [blame] | 7999 | unsigned NewOpc; |
| 8000 | switch (Inst.getOpcode()) { |
| 8001 | default: llvm_unreachable("unexpected opcode"); |
| 8002 | case ARM::t2ADCrr: NewOpc = ARM::tADC; break; |
| 8003 | case ARM::t2ANDrr: NewOpc = ARM::tAND; break; |
| 8004 | case ARM::t2EORrr: NewOpc = ARM::tEOR; break; |
| 8005 | case ARM::t2ORRrr: NewOpc = ARM::tORR; break; |
| 8006 | } |
| 8007 | MCInst TmpInst; |
| 8008 | TmpInst.setOpcode(NewOpc); |
| 8009 | TmpInst.addOperand(Inst.getOperand(0)); |
| 8010 | TmpInst.addOperand(Inst.getOperand(5)); |
| 8011 | if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) { |
| 8012 | TmpInst.addOperand(Inst.getOperand(1)); |
| 8013 | TmpInst.addOperand(Inst.getOperand(2)); |
| 8014 | } else { |
| 8015 | TmpInst.addOperand(Inst.getOperand(2)); |
| 8016 | TmpInst.addOperand(Inst.getOperand(1)); |
| 8017 | } |
| 8018 | TmpInst.addOperand(Inst.getOperand(3)); |
| 8019 | TmpInst.addOperand(Inst.getOperand(4)); |
| 8020 | Inst = TmpInst; |
| 8021 | return true; |
| 8022 | } |
| 8023 | return false; |
| 8024 | } |
Jim Grosbach | 8ba76c6 | 2011-08-11 17:35:48 +0000 | [diff] [blame] | 8025 | } |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 8026 | return false; |
Jim Grosbach | 8ba76c6 | 2011-08-11 17:35:48 +0000 | [diff] [blame] | 8027 | } |
| 8028 | |
Jim Grosbach | 3e941ae | 2011-08-16 20:45:50 +0000 | [diff] [blame] | 8029 | unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) { |
| 8030 | // 16-bit thumb arithmetic instructions either require or preclude the 'S' |
| 8031 | // suffix depending on whether they're in an IT block or not. |
Jim Grosbach | b7fa2c0 | 2011-08-16 22:20:01 +0000 | [diff] [blame] | 8032 | unsigned Opc = Inst.getOpcode(); |
Joey Gouly | 0e76fa7 | 2013-09-12 10:28:05 +0000 | [diff] [blame] | 8033 | const MCInstrDesc &MCID = MII.get(Opc); |
Jim Grosbach | 3e941ae | 2011-08-16 20:45:50 +0000 | [diff] [blame] | 8034 | if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) { |
| 8035 | assert(MCID.hasOptionalDef() && |
| 8036 | "optionally flag setting instruction missing optional def operand"); |
| 8037 | assert(MCID.NumOperands == Inst.getNumOperands() && |
| 8038 | "operand count mismatch!"); |
| 8039 | // Find the optional-def operand (cc_out). |
| 8040 | unsigned OpNo; |
| 8041 | for (OpNo = 0; |
| 8042 | !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands; |
| 8043 | ++OpNo) |
| 8044 | ; |
| 8045 | // If we're parsing Thumb1, reject it completely. |
| 8046 | if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR) |
| 8047 | return Match_MnemonicFail; |
| 8048 | // If we're parsing Thumb2, which form is legal depends on whether we're |
| 8049 | // in an IT block. |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 8050 | if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR && |
| 8051 | !inITBlock()) |
Jim Grosbach | 3e941ae | 2011-08-16 20:45:50 +0000 | [diff] [blame] | 8052 | return Match_RequiresITBlock; |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 8053 | if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR && |
| 8054 | inITBlock()) |
| 8055 | return Match_RequiresNotITBlock; |
Jim Grosbach | 3e941ae | 2011-08-16 20:45:50 +0000 | [diff] [blame] | 8056 | } |
Jim Grosbach | b7fa2c0 | 2011-08-16 22:20:01 +0000 | [diff] [blame] | 8057 | // Some high-register supporting Thumb1 encodings only allow both registers |
| 8058 | // to be from r0-r7 when in Thumb2. |
| 8059 | else if (Opc == ARM::tADDhirr && isThumbOne() && |
| 8060 | isARMLowRegister(Inst.getOperand(1).getReg()) && |
| 8061 | isARMLowRegister(Inst.getOperand(2).getReg())) |
| 8062 | return Match_RequiresThumb2; |
| 8063 | // Others only require ARMv6 or later. |
Jim Grosbach | f86cd37 | 2011-08-19 20:46:54 +0000 | [diff] [blame] | 8064 | else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() && |
Jim Grosbach | b7fa2c0 | 2011-08-16 22:20:01 +0000 | [diff] [blame] | 8065 | isARMLowRegister(Inst.getOperand(0).getReg()) && |
| 8066 | isARMLowRegister(Inst.getOperand(1).getReg())) |
| 8067 | return Match_RequiresV6; |
Jim Grosbach | 3e941ae | 2011-08-16 20:45:50 +0000 | [diff] [blame] | 8068 | return Match_Success; |
| 8069 | } |
| 8070 | |
Benjamin Kramer | 44a53da | 2014-04-12 18:45:24 +0000 | [diff] [blame] | 8071 | namespace llvm { |
| 8072 | template <> inline bool IsCPSRDead<MCInst>(MCInst *Instr) { |
Artyom Skrobov | 1a6cd1d | 2014-02-26 11:27:28 +0000 | [diff] [blame] | 8073 | return true; // In an assembly source, no need to second-guess |
| 8074 | } |
Benjamin Kramer | 44a53da | 2014-04-12 18:45:24 +0000 | [diff] [blame] | 8075 | } |
Artyom Skrobov | 1a6cd1d | 2014-02-26 11:27:28 +0000 | [diff] [blame] | 8076 | |
Jim Grosbach | 5117ef7 | 2012-04-24 22:40:08 +0000 | [diff] [blame] | 8077 | static const char *getSubtargetFeatureName(unsigned Val); |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8078 | bool ARMAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode, |
| 8079 | OperandVector &Operands, |
| 8080 | MCStreamer &Out, unsigned &ErrorInfo, |
| 8081 | bool MatchingInlineAsm) { |
Chris Lattner | 9487de6 | 2010-10-28 21:28:01 +0000 | [diff] [blame] | 8082 | MCInst Inst; |
Jim Grosbach | 120a96a | 2011-08-15 23:03:29 +0000 | [diff] [blame] | 8083 | unsigned MatchResult; |
Weiming Zhao | 8f56f88 | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 8084 | |
Chad Rosier | 2f480a8 | 2012-10-12 22:53:36 +0000 | [diff] [blame] | 8085 | MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo, |
Chad Rosier | 4996355 | 2012-10-13 00:26:04 +0000 | [diff] [blame] | 8086 | MatchingInlineAsm); |
Kevin Enderby | 3164a34 | 2010-12-09 19:19:43 +0000 | [diff] [blame] | 8087 | switch (MatchResult) { |
Jim Grosbach | 120a96a | 2011-08-15 23:03:29 +0000 | [diff] [blame] | 8088 | default: break; |
Chris Lattner | d27b05e | 2010-10-28 21:41:58 +0000 | [diff] [blame] | 8089 | case Match_Success: |
Jim Grosbach | edaa35a | 2011-07-26 18:25:39 +0000 | [diff] [blame] | 8090 | // Context sensitive operand constraints aren't handled by the matcher, |
| 8091 | // so check them here. |
Jim Grosbach | a0d34d3 | 2011-09-02 23:22:08 +0000 | [diff] [blame] | 8092 | if (validateInstruction(Inst, Operands)) { |
| 8093 | // Still progress the IT block, otherwise one wrong condition causes |
| 8094 | // nasty cascading errors. |
| 8095 | forwardITPosition(); |
Jim Grosbach | edaa35a | 2011-07-26 18:25:39 +0000 | [diff] [blame] | 8096 | return true; |
Jim Grosbach | a0d34d3 | 2011-09-02 23:22:08 +0000 | [diff] [blame] | 8097 | } |
Jim Grosbach | edaa35a | 2011-07-26 18:25:39 +0000 | [diff] [blame] | 8098 | |
Amara Emerson | 52cfb6a | 2013-10-03 09:31:51 +0000 | [diff] [blame] | 8099 | { // processInstruction() updates inITBlock state, we need to save it away |
| 8100 | bool wasInITBlock = inITBlock(); |
| 8101 | |
| 8102 | // Some instructions need post-processing to, for example, tweak which |
| 8103 | // encoding is selected. Loop on it while changes happen so the |
| 8104 | // individual transformations can chain off each other. E.g., |
| 8105 | // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8) |
| 8106 | while (processInstruction(Inst, Operands)) |
| 8107 | ; |
| 8108 | |
| 8109 | // Only after the instruction is fully processed, we can validate it |
| 8110 | if (wasInITBlock && hasV8Ops() && isThumb() && |
Weiming Zhao | 5930ae6 | 2014-01-23 19:55:33 +0000 | [diff] [blame] | 8111 | !isV8EligibleForIT(&Inst)) { |
Amara Emerson | 52cfb6a | 2013-10-03 09:31:51 +0000 | [diff] [blame] | 8112 | Warning(IDLoc, "deprecated instruction in IT block"); |
| 8113 | } |
| 8114 | } |
Jim Grosbach | 8ba76c6 | 2011-08-11 17:35:48 +0000 | [diff] [blame] | 8115 | |
Jim Grosbach | a0d34d3 | 2011-09-02 23:22:08 +0000 | [diff] [blame] | 8116 | // Only move forward at the very end so that everything in validate |
| 8117 | // and process gets a consistent answer about whether we're in an IT |
| 8118 | // block. |
| 8119 | forwardITPosition(); |
| 8120 | |
Jim Grosbach | 82f76d1 | 2012-01-25 19:52:01 +0000 | [diff] [blame] | 8121 | // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and |
| 8122 | // doesn't actually encode. |
| 8123 | if (Inst.getOpcode() == ARM::ITasm) |
| 8124 | return false; |
| 8125 | |
Jim Grosbach | 5e5eabb | 2012-01-26 23:20:15 +0000 | [diff] [blame] | 8126 | Inst.setLoc(IDLoc); |
David Woodhouse | e6c13e4 | 2014-01-28 23:12:42 +0000 | [diff] [blame] | 8127 | Out.EmitInstruction(Inst, STI); |
Chris Lattner | 9487de6 | 2010-10-28 21:28:01 +0000 | [diff] [blame] | 8128 | return false; |
Jim Grosbach | 5117ef7 | 2012-04-24 22:40:08 +0000 | [diff] [blame] | 8129 | case Match_MissingFeature: { |
| 8130 | assert(ErrorInfo && "Unknown missing feature!"); |
| 8131 | // Special case the error message for the very common case where only |
| 8132 | // a single subtarget feature is missing (Thumb vs. ARM, e.g.). |
| 8133 | std::string Msg = "instruction requires:"; |
| 8134 | unsigned Mask = 1; |
| 8135 | for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) { |
| 8136 | if (ErrorInfo & Mask) { |
| 8137 | Msg += " "; |
| 8138 | Msg += getSubtargetFeatureName(ErrorInfo & Mask); |
| 8139 | } |
| 8140 | Mask <<= 1; |
| 8141 | } |
| 8142 | return Error(IDLoc, Msg); |
| 8143 | } |
Chris Lattner | d27b05e | 2010-10-28 21:41:58 +0000 | [diff] [blame] | 8144 | case Match_InvalidOperand: { |
| 8145 | SMLoc ErrorLoc = IDLoc; |
| 8146 | if (ErrorInfo != ~0U) { |
| 8147 | if (ErrorInfo >= Operands.size()) |
| 8148 | return Error(IDLoc, "too few operands for instruction"); |
Jim Grosbach | 624bcc7 | 2010-10-29 14:46:02 +0000 | [diff] [blame] | 8149 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8150 | ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc(); |
Chris Lattner | d27b05e | 2010-10-28 21:41:58 +0000 | [diff] [blame] | 8151 | if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc; |
| 8152 | } |
Jim Grosbach | 624bcc7 | 2010-10-29 14:46:02 +0000 | [diff] [blame] | 8153 | |
Chris Lattner | d27b05e | 2010-10-28 21:41:58 +0000 | [diff] [blame] | 8154 | return Error(ErrorLoc, "invalid operand for instruction"); |
Chris Lattner | 9487de6 | 2010-10-28 21:28:01 +0000 | [diff] [blame] | 8155 | } |
Chris Lattner | d27b05e | 2010-10-28 21:41:58 +0000 | [diff] [blame] | 8156 | case Match_MnemonicFail: |
Benjamin Kramer | 673824b | 2012-04-15 17:04:27 +0000 | [diff] [blame] | 8157 | return Error(IDLoc, "invalid instruction", |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8158 | ((ARMOperand &)*Operands[0]).getLocRange()); |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 8159 | case Match_RequiresNotITBlock: |
| 8160 | return Error(IDLoc, "flag setting instruction only valid outside IT block"); |
Jim Grosbach | 3e941ae | 2011-08-16 20:45:50 +0000 | [diff] [blame] | 8161 | case Match_RequiresITBlock: |
| 8162 | return Error(IDLoc, "instruction only valid inside IT block"); |
Jim Grosbach | b7fa2c0 | 2011-08-16 22:20:01 +0000 | [diff] [blame] | 8163 | case Match_RequiresV6: |
| 8164 | return Error(IDLoc, "instruction variant requires ARMv6 or later"); |
| 8165 | case Match_RequiresThumb2: |
| 8166 | return Error(IDLoc, "instruction variant requires Thumb2"); |
Jim Grosbach | 087affe | 2012-06-22 23:56:48 +0000 | [diff] [blame] | 8167 | case Match_ImmRange0_15: { |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8168 | SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc(); |
Jim Grosbach | 087affe | 2012-06-22 23:56:48 +0000 | [diff] [blame] | 8169 | if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc; |
| 8170 | return Error(ErrorLoc, "immediate operand must be in the range [0,15]"); |
| 8171 | } |
Artyom Skrobov | fc12e70 | 2013-10-23 10:14:40 +0000 | [diff] [blame] | 8172 | case Match_ImmRange0_239: { |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8173 | SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc(); |
Artyom Skrobov | fc12e70 | 2013-10-23 10:14:40 +0000 | [diff] [blame] | 8174 | if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc; |
| 8175 | return Error(ErrorLoc, "immediate operand must be in the range [0,239]"); |
| 8176 | } |
Kevin Enderby | 488f20b | 2014-04-10 20:18:58 +0000 | [diff] [blame] | 8177 | case Match_AlignedMemoryRequiresNone: |
| 8178 | case Match_DupAlignedMemoryRequiresNone: |
| 8179 | case Match_AlignedMemoryRequires16: |
| 8180 | case Match_DupAlignedMemoryRequires16: |
| 8181 | case Match_AlignedMemoryRequires32: |
| 8182 | case Match_DupAlignedMemoryRequires32: |
| 8183 | case Match_AlignedMemoryRequires64: |
| 8184 | case Match_DupAlignedMemoryRequires64: |
| 8185 | case Match_AlignedMemoryRequires64or128: |
| 8186 | case Match_DupAlignedMemoryRequires64or128: |
| 8187 | case Match_AlignedMemoryRequires64or128or256: |
| 8188 | { |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8189 | SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getAlignmentLoc(); |
Kevin Enderby | 488f20b | 2014-04-10 20:18:58 +0000 | [diff] [blame] | 8190 | if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc; |
| 8191 | switch (MatchResult) { |
| 8192 | default: |
| 8193 | llvm_unreachable("Missing Match_Aligned type"); |
| 8194 | case Match_AlignedMemoryRequiresNone: |
| 8195 | case Match_DupAlignedMemoryRequiresNone: |
| 8196 | return Error(ErrorLoc, "alignment must be omitted"); |
| 8197 | case Match_AlignedMemoryRequires16: |
| 8198 | case Match_DupAlignedMemoryRequires16: |
| 8199 | return Error(ErrorLoc, "alignment must be 16 or omitted"); |
| 8200 | case Match_AlignedMemoryRequires32: |
| 8201 | case Match_DupAlignedMemoryRequires32: |
| 8202 | return Error(ErrorLoc, "alignment must be 32 or omitted"); |
| 8203 | case Match_AlignedMemoryRequires64: |
| 8204 | case Match_DupAlignedMemoryRequires64: |
| 8205 | return Error(ErrorLoc, "alignment must be 64 or omitted"); |
| 8206 | case Match_AlignedMemoryRequires64or128: |
| 8207 | case Match_DupAlignedMemoryRequires64or128: |
| 8208 | return Error(ErrorLoc, "alignment must be 64, 128 or omitted"); |
| 8209 | case Match_AlignedMemoryRequires64or128or256: |
| 8210 | return Error(ErrorLoc, "alignment must be 64, 128, 256 or omitted"); |
| 8211 | } |
| 8212 | } |
Chris Lattner | d27b05e | 2010-10-28 21:41:58 +0000 | [diff] [blame] | 8213 | } |
Jim Grosbach | 624bcc7 | 2010-10-29 14:46:02 +0000 | [diff] [blame] | 8214 | |
Eric Christopher | 91d7b90 | 2010-10-29 09:26:59 +0000 | [diff] [blame] | 8215 | llvm_unreachable("Implement any new match types added!"); |
Chris Lattner | 9487de6 | 2010-10-28 21:28:01 +0000 | [diff] [blame] | 8216 | } |
| 8217 | |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8218 | /// parseDirective parses the arm specific directives |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 8219 | bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) { |
Saleem Abdulrasool | dd979e6 | 2014-04-05 22:09:51 +0000 | [diff] [blame] | 8220 | const MCObjectFileInfo::Environment Format = |
| 8221 | getContext().getObjectFileInfo()->getObjectFileType(); |
| 8222 | bool IsMachO = Format == MCObjectFileInfo::IsMachO; |
| 8223 | |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 8224 | StringRef IDVal = DirectiveID.getIdentifier(); |
| 8225 | if (IDVal == ".word") |
Saleem Abdulrasool | 3897651 | 2014-02-23 06:22:09 +0000 | [diff] [blame] | 8226 | return parseLiteralValues(4, DirectiveID.getLoc()); |
| 8227 | else if (IDVal == ".short" || IDVal == ".hword") |
| 8228 | return parseLiteralValues(2, DirectiveID.getLoc()); |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8229 | else if (IDVal == ".thumb") |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8230 | return parseDirectiveThumb(DirectiveID.getLoc()); |
Jim Grosbach | 7f88239 | 2011-12-07 18:04:19 +0000 | [diff] [blame] | 8231 | else if (IDVal == ".arm") |
| 8232 | return parseDirectiveARM(DirectiveID.getLoc()); |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8233 | else if (IDVal == ".thumb_func") |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8234 | return parseDirectiveThumbFunc(DirectiveID.getLoc()); |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8235 | else if (IDVal == ".code") |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8236 | return parseDirectiveCode(DirectiveID.getLoc()); |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8237 | else if (IDVal == ".syntax") |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8238 | return parseDirectiveSyntax(DirectiveID.getLoc()); |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 8239 | else if (IDVal == ".unreq") |
| 8240 | return parseDirectiveUnreq(DirectiveID.getLoc()); |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8241 | else if (IDVal == ".fnend") |
| 8242 | return parseDirectiveFnEnd(DirectiveID.getLoc()); |
| 8243 | else if (IDVal == ".cantunwind") |
| 8244 | return parseDirectiveCantUnwind(DirectiveID.getLoc()); |
| 8245 | else if (IDVal == ".personality") |
| 8246 | return parseDirectivePersonality(DirectiveID.getLoc()); |
| 8247 | else if (IDVal == ".handlerdata") |
| 8248 | return parseDirectiveHandlerData(DirectiveID.getLoc()); |
| 8249 | else if (IDVal == ".setfp") |
| 8250 | return parseDirectiveSetFP(DirectiveID.getLoc()); |
| 8251 | else if (IDVal == ".pad") |
| 8252 | return parseDirectivePad(DirectiveID.getLoc()); |
| 8253 | else if (IDVal == ".save") |
| 8254 | return parseDirectiveRegSave(DirectiveID.getLoc(), false); |
| 8255 | else if (IDVal == ".vsave") |
| 8256 | return parseDirectiveRegSave(DirectiveID.getLoc(), true); |
Saleem Abdulrasool | 6e6c239 | 2013-12-20 07:21:16 +0000 | [diff] [blame] | 8257 | else if (IDVal == ".ltorg" || IDVal == ".pool") |
David Peixotto | 80c083a | 2013-12-19 18:26:07 +0000 | [diff] [blame] | 8258 | return parseDirectiveLtorg(DirectiveID.getLoc()); |
Saleem Abdulrasool | a554968 | 2013-12-26 01:52:28 +0000 | [diff] [blame] | 8259 | else if (IDVal == ".even") |
| 8260 | return parseDirectiveEven(DirectiveID.getLoc()); |
Saleem Abdulrasool | 662f5c1 | 2014-01-21 02:33:02 +0000 | [diff] [blame] | 8261 | else if (IDVal == ".personalityindex") |
| 8262 | return parseDirectivePersonalityIndex(DirectiveID.getLoc()); |
Saleem Abdulrasool | d9f0860 | 2014-01-21 02:33:10 +0000 | [diff] [blame] | 8263 | else if (IDVal == ".unwind_raw") |
| 8264 | return parseDirectiveUnwindRaw(DirectiveID.getLoc()); |
Saleem Abdulrasool | 5d962d3 | 2014-01-30 04:46:24 +0000 | [diff] [blame] | 8265 | else if (IDVal == ".movsp") |
| 8266 | return parseDirectiveMovSP(DirectiveID.getLoc()); |
Saleem Abdulrasool | 49480bf | 2014-02-16 00:16:41 +0000 | [diff] [blame] | 8267 | else if (IDVal == ".arch_extension") |
| 8268 | return parseDirectiveArchExtension(DirectiveID.getLoc()); |
Saleem Abdulrasool | fd6ed1e | 2014-02-23 17:45:32 +0000 | [diff] [blame] | 8269 | else if (IDVal == ".align") |
| 8270 | return parseDirectiveAlign(DirectiveID.getLoc()); |
Saleem Abdulrasool | 39f773f | 2014-03-20 06:05:33 +0000 | [diff] [blame] | 8271 | else if (IDVal == ".thumb_set") |
| 8272 | return parseDirectiveThumbSet(DirectiveID.getLoc()); |
Saleem Abdulrasool | dd979e6 | 2014-04-05 22:09:51 +0000 | [diff] [blame] | 8273 | |
| 8274 | if (!IsMachO) { |
| 8275 | if (IDVal == ".arch") |
| 8276 | return parseDirectiveArch(DirectiveID.getLoc()); |
| 8277 | else if (IDVal == ".cpu") |
| 8278 | return parseDirectiveCPU(DirectiveID.getLoc()); |
| 8279 | else if (IDVal == ".eabi_attribute") |
| 8280 | return parseDirectiveEabiAttr(DirectiveID.getLoc()); |
| 8281 | else if (IDVal == ".fpu") |
| 8282 | return parseDirectiveFPU(DirectiveID.getLoc()); |
| 8283 | else if (IDVal == ".fnstart") |
| 8284 | return parseDirectiveFnStart(DirectiveID.getLoc()); |
| 8285 | else if (IDVal == ".inst") |
| 8286 | return parseDirectiveInst(DirectiveID.getLoc()); |
| 8287 | else if (IDVal == ".inst.n") |
| 8288 | return parseDirectiveInst(DirectiveID.getLoc(), 'n'); |
| 8289 | else if (IDVal == ".inst.w") |
| 8290 | return parseDirectiveInst(DirectiveID.getLoc(), 'w'); |
| 8291 | else if (IDVal == ".object_arch") |
| 8292 | return parseDirectiveObjectArch(DirectiveID.getLoc()); |
| 8293 | else if (IDVal == ".tlsdescseq") |
| 8294 | return parseDirectiveTLSDescSeq(DirectiveID.getLoc()); |
| 8295 | } |
| 8296 | |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 8297 | return true; |
| 8298 | } |
| 8299 | |
Saleem Abdulrasool | 3897651 | 2014-02-23 06:22:09 +0000 | [diff] [blame] | 8300 | /// parseLiteralValues |
| 8301 | /// ::= .hword expression [, expression]* |
| 8302 | /// ::= .short expression [, expression]* |
| 8303 | /// ::= .word expression [, expression]* |
| 8304 | bool ARMAsmParser::parseLiteralValues(unsigned Size, SMLoc L) { |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 8305 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
| 8306 | for (;;) { |
| 8307 | const MCExpr *Value; |
Saleem Abdulrasool | a903661 | 2014-01-26 22:29:50 +0000 | [diff] [blame] | 8308 | if (getParser().parseExpression(Value)) { |
| 8309 | Parser.eatToEndOfStatement(); |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 8310 | return false; |
Saleem Abdulrasool | a903661 | 2014-01-26 22:29:50 +0000 | [diff] [blame] | 8311 | } |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 8312 | |
Eric Christopher | bf7bc49 | 2013-01-09 03:52:05 +0000 | [diff] [blame] | 8313 | getParser().getStreamer().EmitValue(Value, Size); |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 8314 | |
| 8315 | if (getLexer().is(AsmToken::EndOfStatement)) |
| 8316 | break; |
Jim Grosbach | 624bcc7 | 2010-10-29 14:46:02 +0000 | [diff] [blame] | 8317 | |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 8318 | // FIXME: Improve diagnostic. |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 8319 | if (getLexer().isNot(AsmToken::Comma)) { |
| 8320 | Error(L, "unexpected token in directive"); |
| 8321 | return false; |
| 8322 | } |
Sean Callanan | a83fd7d | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 8323 | Parser.Lex(); |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 8324 | } |
| 8325 | } |
| 8326 | |
Sean Callanan | a83fd7d | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 8327 | Parser.Lex(); |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 8328 | return false; |
| 8329 | } |
| 8330 | |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8331 | /// parseDirectiveThumb |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8332 | /// ::= .thumb |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8333 | bool ARMAsmParser::parseDirectiveThumb(SMLoc L) { |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 8334 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
| 8335 | Error(L, "unexpected token in directive"); |
| 8336 | return false; |
| 8337 | } |
Sean Callanan | a83fd7d | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 8338 | Parser.Lex(); |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8339 | |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 8340 | if (!hasThumb()) { |
| 8341 | Error(L, "target does not support Thumb mode"); |
| 8342 | return false; |
| 8343 | } |
Tim Northover | a2292d0 | 2013-06-10 23:20:58 +0000 | [diff] [blame] | 8344 | |
Jim Grosbach | 7f88239 | 2011-12-07 18:04:19 +0000 | [diff] [blame] | 8345 | if (!isThumb()) |
| 8346 | SwitchMode(); |
Saleem Abdulrasool | 44419fc | 2014-03-22 19:26:18 +0000 | [diff] [blame] | 8347 | |
Jim Grosbach | 7f88239 | 2011-12-07 18:04:19 +0000 | [diff] [blame] | 8348 | getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16); |
| 8349 | return false; |
| 8350 | } |
| 8351 | |
| 8352 | /// parseDirectiveARM |
| 8353 | /// ::= .arm |
| 8354 | bool ARMAsmParser::parseDirectiveARM(SMLoc L) { |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 8355 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
| 8356 | Error(L, "unexpected token in directive"); |
| 8357 | return false; |
| 8358 | } |
Jim Grosbach | 7f88239 | 2011-12-07 18:04:19 +0000 | [diff] [blame] | 8359 | Parser.Lex(); |
| 8360 | |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 8361 | if (!hasARM()) { |
| 8362 | Error(L, "target does not support ARM mode"); |
| 8363 | return false; |
| 8364 | } |
Tim Northover | a2292d0 | 2013-06-10 23:20:58 +0000 | [diff] [blame] | 8365 | |
Jim Grosbach | 7f88239 | 2011-12-07 18:04:19 +0000 | [diff] [blame] | 8366 | if (isThumb()) |
| 8367 | SwitchMode(); |
Saleem Abdulrasool | 44419fc | 2014-03-22 19:26:18 +0000 | [diff] [blame] | 8368 | |
Jim Grosbach | 7f88239 | 2011-12-07 18:04:19 +0000 | [diff] [blame] | 8369 | getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32); |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8370 | return false; |
| 8371 | } |
| 8372 | |
Tim Northover | 1744d0a | 2013-10-25 12:49:50 +0000 | [diff] [blame] | 8373 | void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) { |
| 8374 | if (NextSymbolIsThumb) { |
| 8375 | getParser().getStreamer().EmitThumbFunc(Symbol); |
| 8376 | NextSymbolIsThumb = false; |
| 8377 | } |
| 8378 | } |
| 8379 | |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8380 | /// parseDirectiveThumbFunc |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8381 | /// ::= .thumbfunc symbol_name |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8382 | bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) { |
Bill Wendling | bc07a89 | 2013-06-18 07:20:20 +0000 | [diff] [blame] | 8383 | const MCAsmInfo *MAI = getParser().getStreamer().getContext().getAsmInfo(); |
| 8384 | bool isMachO = MAI->hasSubsectionsViaSymbols(); |
Rafael Espindola | e90c1cb | 2011-05-16 16:17:21 +0000 | [diff] [blame] | 8385 | |
Jim Grosbach | 1152cc0 | 2011-12-21 22:30:16 +0000 | [diff] [blame] | 8386 | // Darwin asm has (optionally) function name after .thumb_func direction |
Rafael Espindola | e90c1cb | 2011-05-16 16:17:21 +0000 | [diff] [blame] | 8387 | // ELF doesn't |
| 8388 | if (isMachO) { |
| 8389 | const AsmToken &Tok = Parser.getTok(); |
Jim Grosbach | 1152cc0 | 2011-12-21 22:30:16 +0000 | [diff] [blame] | 8390 | if (Tok.isNot(AsmToken::EndOfStatement)) { |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 8391 | if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String)) { |
| 8392 | Error(L, "unexpected token in .thumb_func directive"); |
| 8393 | return false; |
| 8394 | } |
| 8395 | |
Tim Northover | 1744d0a | 2013-10-25 12:49:50 +0000 | [diff] [blame] | 8396 | MCSymbol *Func = |
| 8397 | getParser().getContext().GetOrCreateSymbol(Tok.getIdentifier()); |
| 8398 | getParser().getStreamer().EmitThumbFunc(Func); |
Jim Grosbach | 1152cc0 | 2011-12-21 22:30:16 +0000 | [diff] [blame] | 8399 | Parser.Lex(); // Consume the identifier token. |
Tim Northover | 1744d0a | 2013-10-25 12:49:50 +0000 | [diff] [blame] | 8400 | return false; |
Jim Grosbach | 1152cc0 | 2011-12-21 22:30:16 +0000 | [diff] [blame] | 8401 | } |
Rafael Espindola | e90c1cb | 2011-05-16 16:17:21 +0000 | [diff] [blame] | 8402 | } |
| 8403 | |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 8404 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
| 8405 | Error(L, "unexpected token in directive"); |
| 8406 | return false; |
| 8407 | } |
Jim Grosbach | 1152cc0 | 2011-12-21 22:30:16 +0000 | [diff] [blame] | 8408 | |
Tim Northover | 1744d0a | 2013-10-25 12:49:50 +0000 | [diff] [blame] | 8409 | NextSymbolIsThumb = true; |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8410 | return false; |
| 8411 | } |
| 8412 | |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8413 | /// parseDirectiveSyntax |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8414 | /// ::= .syntax unified | divided |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8415 | bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) { |
Sean Callanan | 936b0d3 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 8416 | const AsmToken &Tok = Parser.getTok(); |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 8417 | if (Tok.isNot(AsmToken::Identifier)) { |
| 8418 | Error(L, "unexpected token in .syntax directive"); |
| 8419 | return false; |
| 8420 | } |
| 8421 | |
Benjamin Kramer | 92d8998 | 2010-07-14 22:38:02 +0000 | [diff] [blame] | 8422 | StringRef Mode = Tok.getString(); |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 8423 | if (Mode == "unified" || Mode == "UNIFIED") { |
Sean Callanan | a83fd7d | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 8424 | Parser.Lex(); |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 8425 | } else if (Mode == "divided" || Mode == "DIVIDED") { |
| 8426 | Error(L, "'.syntax divided' arm asssembly not supported"); |
| 8427 | return false; |
| 8428 | } else { |
| 8429 | Error(L, "unrecognized syntax mode in .syntax directive"); |
| 8430 | return false; |
| 8431 | } |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8432 | |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8433 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
| 8434 | Error(Parser.getTok().getLoc(), "unexpected token in directive"); |
| 8435 | return false; |
| 8436 | } |
Sean Callanan | a83fd7d | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 8437 | Parser.Lex(); |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8438 | |
| 8439 | // TODO tell the MC streamer the mode |
| 8440 | // getParser().getStreamer().Emit???(); |
| 8441 | return false; |
| 8442 | } |
| 8443 | |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8444 | /// parseDirectiveCode |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8445 | /// ::= .code 16 | 32 |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8446 | bool ARMAsmParser::parseDirectiveCode(SMLoc L) { |
Sean Callanan | 936b0d3 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 8447 | const AsmToken &Tok = Parser.getTok(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8448 | if (Tok.isNot(AsmToken::Integer)) { |
| 8449 | Error(L, "unexpected token in .code directive"); |
| 8450 | return false; |
| 8451 | } |
Sean Callanan | 936b0d3 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 8452 | int64_t Val = Parser.getTok().getIntVal(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8453 | if (Val != 16 && Val != 32) { |
| 8454 | Error(L, "invalid operand to .code directive"); |
| 8455 | return false; |
| 8456 | } |
| 8457 | Parser.Lex(); |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8458 | |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8459 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
| 8460 | Error(Parser.getTok().getLoc(), "unexpected token in directive"); |
| 8461 | return false; |
| 8462 | } |
Sean Callanan | a83fd7d | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 8463 | Parser.Lex(); |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8464 | |
Evan Cheng | 284b467 | 2011-07-08 22:36:29 +0000 | [diff] [blame] | 8465 | if (Val == 16) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8466 | if (!hasThumb()) { |
| 8467 | Error(L, "target does not support Thumb mode"); |
| 8468 | return false; |
| 8469 | } |
Tim Northover | a2292d0 | 2013-06-10 23:20:58 +0000 | [diff] [blame] | 8470 | |
Jim Grosbach | f471ac3 | 2011-09-06 18:46:23 +0000 | [diff] [blame] | 8471 | if (!isThumb()) |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 8472 | SwitchMode(); |
Jim Grosbach | f471ac3 | 2011-09-06 18:46:23 +0000 | [diff] [blame] | 8473 | getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16); |
Evan Cheng | 284b467 | 2011-07-08 22:36:29 +0000 | [diff] [blame] | 8474 | } else { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8475 | if (!hasARM()) { |
| 8476 | Error(L, "target does not support ARM mode"); |
| 8477 | return false; |
| 8478 | } |
Tim Northover | a2292d0 | 2013-06-10 23:20:58 +0000 | [diff] [blame] | 8479 | |
Jim Grosbach | f471ac3 | 2011-09-06 18:46:23 +0000 | [diff] [blame] | 8480 | if (isThumb()) |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 8481 | SwitchMode(); |
Jim Grosbach | f471ac3 | 2011-09-06 18:46:23 +0000 | [diff] [blame] | 8482 | getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32); |
Evan Cheng | 45543ba | 2011-07-08 22:49:55 +0000 | [diff] [blame] | 8483 | } |
Jim Grosbach | 2db0ea0 | 2010-11-05 22:40:53 +0000 | [diff] [blame] | 8484 | |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8485 | return false; |
| 8486 | } |
| 8487 | |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 8488 | /// parseDirectiveReq |
| 8489 | /// ::= name .req registername |
| 8490 | bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) { |
| 8491 | Parser.Lex(); // Eat the '.req' token. |
| 8492 | unsigned Reg; |
| 8493 | SMLoc SRegLoc, ERegLoc; |
| 8494 | if (ParseRegister(Reg, SRegLoc, ERegLoc)) { |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 8495 | Parser.eatToEndOfStatement(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8496 | Error(SRegLoc, "register name expected"); |
| 8497 | return false; |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 8498 | } |
| 8499 | |
| 8500 | // Shouldn't be anything else. |
| 8501 | if (Parser.getTok().isNot(AsmToken::EndOfStatement)) { |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 8502 | Parser.eatToEndOfStatement(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8503 | Error(Parser.getTok().getLoc(), "unexpected input in .req directive."); |
| 8504 | return false; |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 8505 | } |
| 8506 | |
| 8507 | Parser.Lex(); // Consume the EndOfStatement |
| 8508 | |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8509 | if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg) { |
| 8510 | Error(SRegLoc, "redefinition of '" + Name + "' does not match original."); |
| 8511 | return false; |
| 8512 | } |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 8513 | |
| 8514 | return false; |
| 8515 | } |
| 8516 | |
| 8517 | /// parseDirectiveUneq |
| 8518 | /// ::= .unreq registername |
| 8519 | bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) { |
| 8520 | if (Parser.getTok().isNot(AsmToken::Identifier)) { |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 8521 | Parser.eatToEndOfStatement(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8522 | Error(L, "unexpected input in .unreq directive."); |
| 8523 | return false; |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 8524 | } |
Duncan P. N. Exon Smith | 29db0eb | 2014-03-07 16:16:52 +0000 | [diff] [blame] | 8525 | RegisterReqs.erase(Parser.getTok().getIdentifier().lower()); |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 8526 | Parser.Lex(); // Eat the identifier. |
| 8527 | return false; |
| 8528 | } |
| 8529 | |
Jason W Kim | 135d244 | 2011-12-20 17:38:12 +0000 | [diff] [blame] | 8530 | /// parseDirectiveArch |
| 8531 | /// ::= .arch token |
| 8532 | bool ARMAsmParser::parseDirectiveArch(SMLoc L) { |
Logan Chien | 439e8f9 | 2013-12-11 17:16:25 +0000 | [diff] [blame] | 8533 | StringRef Arch = getParser().parseStringToEndOfStatement().trim(); |
| 8534 | |
| 8535 | unsigned ID = StringSwitch<unsigned>(Arch) |
| 8536 | #define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \ |
| 8537 | .Case(NAME, ARM::ID) |
Joerg Sonnenberger | a13f8b4 | 2013-12-26 11:50:28 +0000 | [diff] [blame] | 8538 | #define ARM_ARCH_ALIAS(NAME, ID) \ |
| 8539 | .Case(NAME, ARM::ID) |
Logan Chien | 439e8f9 | 2013-12-11 17:16:25 +0000 | [diff] [blame] | 8540 | #include "MCTargetDesc/ARMArchName.def" |
| 8541 | .Default(ARM::INVALID_ARCH); |
| 8542 | |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8543 | if (ID == ARM::INVALID_ARCH) { |
| 8544 | Error(L, "Unknown arch name"); |
| 8545 | return false; |
| 8546 | } |
Logan Chien | 439e8f9 | 2013-12-11 17:16:25 +0000 | [diff] [blame] | 8547 | |
| 8548 | getTargetStreamer().emitArch(ID); |
| 8549 | return false; |
Jason W Kim | 135d244 | 2011-12-20 17:38:12 +0000 | [diff] [blame] | 8550 | } |
| 8551 | |
| 8552 | /// parseDirectiveEabiAttr |
Saleem Abdulrasool | 87ccd36 | 2014-01-07 02:28:42 +0000 | [diff] [blame] | 8553 | /// ::= .eabi_attribute int, int [, "str"] |
| 8554 | /// ::= .eabi_attribute Tag_name, int [, "str"] |
Jason W Kim | 135d244 | 2011-12-20 17:38:12 +0000 | [diff] [blame] | 8555 | bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) { |
Saleem Abdulrasool | 87ccd36 | 2014-01-07 02:28:42 +0000 | [diff] [blame] | 8556 | int64_t Tag; |
| 8557 | SMLoc TagLoc; |
Saleem Abdulrasool | 87ccd36 | 2014-01-07 02:28:42 +0000 | [diff] [blame] | 8558 | TagLoc = Parser.getTok().getLoc(); |
| 8559 | if (Parser.getTok().is(AsmToken::Identifier)) { |
| 8560 | StringRef Name = Parser.getTok().getIdentifier(); |
| 8561 | Tag = ARMBuildAttrs::AttrTypeFromString(Name); |
| 8562 | if (Tag == -1) { |
| 8563 | Error(TagLoc, "attribute name not recognised: " + Name); |
| 8564 | Parser.eatToEndOfStatement(); |
| 8565 | return false; |
| 8566 | } |
| 8567 | Parser.Lex(); |
| 8568 | } else { |
| 8569 | const MCExpr *AttrExpr; |
| 8570 | |
| 8571 | TagLoc = Parser.getTok().getLoc(); |
| 8572 | if (Parser.parseExpression(AttrExpr)) { |
| 8573 | Parser.eatToEndOfStatement(); |
| 8574 | return false; |
| 8575 | } |
| 8576 | |
| 8577 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(AttrExpr); |
| 8578 | if (!CE) { |
| 8579 | Error(TagLoc, "expected numeric constant"); |
| 8580 | Parser.eatToEndOfStatement(); |
| 8581 | return false; |
| 8582 | } |
| 8583 | |
| 8584 | Tag = CE->getValue(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8585 | } |
Logan Chien | 8cbb80d | 2013-10-28 17:51:12 +0000 | [diff] [blame] | 8586 | |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8587 | if (Parser.getTok().isNot(AsmToken::Comma)) { |
Saleem Abdulrasool | 87ccd36 | 2014-01-07 02:28:42 +0000 | [diff] [blame] | 8588 | Error(Parser.getTok().getLoc(), "comma expected"); |
| 8589 | Parser.eatToEndOfStatement(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8590 | return false; |
| 8591 | } |
Logan Chien | 8cbb80d | 2013-10-28 17:51:12 +0000 | [diff] [blame] | 8592 | Parser.Lex(); // skip comma |
| 8593 | |
Saleem Abdulrasool | 87ccd36 | 2014-01-07 02:28:42 +0000 | [diff] [blame] | 8594 | StringRef StringValue = ""; |
| 8595 | bool IsStringValue = false; |
Logan Chien | 8cbb80d | 2013-10-28 17:51:12 +0000 | [diff] [blame] | 8596 | |
Saleem Abdulrasool | 87ccd36 | 2014-01-07 02:28:42 +0000 | [diff] [blame] | 8597 | int64_t IntegerValue = 0; |
| 8598 | bool IsIntegerValue = false; |
| 8599 | |
| 8600 | if (Tag == ARMBuildAttrs::CPU_raw_name || Tag == ARMBuildAttrs::CPU_name) |
| 8601 | IsStringValue = true; |
| 8602 | else if (Tag == ARMBuildAttrs::compatibility) { |
| 8603 | IsStringValue = true; |
| 8604 | IsIntegerValue = true; |
Saleem Abdulrasool | 9dedf64 | 2014-01-19 08:25:19 +0000 | [diff] [blame] | 8605 | } else if (Tag < 32 || Tag % 2 == 0) |
Saleem Abdulrasool | 87ccd36 | 2014-01-07 02:28:42 +0000 | [diff] [blame] | 8606 | IsIntegerValue = true; |
| 8607 | else if (Tag % 2 == 1) |
| 8608 | IsStringValue = true; |
| 8609 | else |
| 8610 | llvm_unreachable("invalid tag type"); |
| 8611 | |
| 8612 | if (IsIntegerValue) { |
| 8613 | const MCExpr *ValueExpr; |
| 8614 | SMLoc ValueExprLoc = Parser.getTok().getLoc(); |
| 8615 | if (Parser.parseExpression(ValueExpr)) { |
| 8616 | Parser.eatToEndOfStatement(); |
| 8617 | return false; |
| 8618 | } |
| 8619 | |
| 8620 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ValueExpr); |
| 8621 | if (!CE) { |
| 8622 | Error(ValueExprLoc, "expected numeric constant"); |
| 8623 | Parser.eatToEndOfStatement(); |
| 8624 | return false; |
| 8625 | } |
| 8626 | |
| 8627 | IntegerValue = CE->getValue(); |
| 8628 | } |
| 8629 | |
| 8630 | if (Tag == ARMBuildAttrs::compatibility) { |
| 8631 | if (Parser.getTok().isNot(AsmToken::Comma)) |
| 8632 | IsStringValue = false; |
| 8633 | else |
| 8634 | Parser.Lex(); |
| 8635 | } |
| 8636 | |
| 8637 | if (IsStringValue) { |
| 8638 | if (Parser.getTok().isNot(AsmToken::String)) { |
| 8639 | Error(Parser.getTok().getLoc(), "bad string constant"); |
| 8640 | Parser.eatToEndOfStatement(); |
| 8641 | return false; |
| 8642 | } |
| 8643 | |
| 8644 | StringValue = Parser.getTok().getStringContents(); |
| 8645 | Parser.Lex(); |
| 8646 | } |
| 8647 | |
| 8648 | if (IsIntegerValue && IsStringValue) { |
| 8649 | assert(Tag == ARMBuildAttrs::compatibility); |
| 8650 | getTargetStreamer().emitIntTextAttribute(Tag, IntegerValue, StringValue); |
| 8651 | } else if (IsIntegerValue) |
| 8652 | getTargetStreamer().emitAttribute(Tag, IntegerValue); |
| 8653 | else if (IsStringValue) |
| 8654 | getTargetStreamer().emitTextAttribute(Tag, StringValue); |
Logan Chien | 8cbb80d | 2013-10-28 17:51:12 +0000 | [diff] [blame] | 8655 | return false; |
| 8656 | } |
| 8657 | |
| 8658 | /// parseDirectiveCPU |
| 8659 | /// ::= .cpu str |
| 8660 | bool ARMAsmParser::parseDirectiveCPU(SMLoc L) { |
| 8661 | StringRef CPU = getParser().parseStringToEndOfStatement().trim(); |
| 8662 | getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name, CPU); |
| 8663 | return false; |
| 8664 | } |
| 8665 | |
| 8666 | /// parseDirectiveFPU |
| 8667 | /// ::= .fpu str |
| 8668 | bool ARMAsmParser::parseDirectiveFPU(SMLoc L) { |
| 8669 | StringRef FPU = getParser().parseStringToEndOfStatement().trim(); |
| 8670 | |
| 8671 | unsigned ID = StringSwitch<unsigned>(FPU) |
| 8672 | #define ARM_FPU_NAME(NAME, ID) .Case(NAME, ARM::ID) |
| 8673 | #include "ARMFPUName.def" |
| 8674 | .Default(ARM::INVALID_FPU); |
| 8675 | |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8676 | if (ID == ARM::INVALID_FPU) { |
| 8677 | Error(L, "Unknown FPU name"); |
| 8678 | return false; |
| 8679 | } |
Logan Chien | 8cbb80d | 2013-10-28 17:51:12 +0000 | [diff] [blame] | 8680 | |
| 8681 | getTargetStreamer().emitFPU(ID); |
| 8682 | return false; |
Jason W Kim | 135d244 | 2011-12-20 17:38:12 +0000 | [diff] [blame] | 8683 | } |
| 8684 | |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8685 | /// parseDirectiveFnStart |
| 8686 | /// ::= .fnstart |
| 8687 | bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) { |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8688 | if (UC.hasFnStart()) { |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8689 | Error(L, ".fnstart starts before the end of previous one"); |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8690 | UC.emitFnStartLocNotes(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8691 | return false; |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8692 | } |
| 8693 | |
Saleem Abdulrasool | 662f5c1 | 2014-01-21 02:33:02 +0000 | [diff] [blame] | 8694 | // Reset the unwind directives parser state |
| 8695 | UC.reset(); |
| 8696 | |
Rafael Espindola | a17151a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 8697 | getTargetStreamer().emitFnStart(); |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8698 | |
| 8699 | UC.recordFnStart(L); |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8700 | return false; |
| 8701 | } |
| 8702 | |
| 8703 | /// parseDirectiveFnEnd |
| 8704 | /// ::= .fnend |
| 8705 | bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) { |
| 8706 | // Check the ordering of unwind directives |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8707 | if (!UC.hasFnStart()) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8708 | Error(L, ".fnstart must precede .fnend directive"); |
| 8709 | return false; |
| 8710 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8711 | |
| 8712 | // Reset the unwind directives parser state |
Rafael Espindola | a17151a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 8713 | getTargetStreamer().emitFnEnd(); |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8714 | |
| 8715 | UC.reset(); |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8716 | return false; |
| 8717 | } |
| 8718 | |
| 8719 | /// parseDirectiveCantUnwind |
| 8720 | /// ::= .cantunwind |
| 8721 | bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) { |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8722 | UC.recordCantUnwind(L); |
| 8723 | |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8724 | // Check the ordering of unwind directives |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8725 | if (!UC.hasFnStart()) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8726 | Error(L, ".fnstart must precede .cantunwind directive"); |
| 8727 | return false; |
| 8728 | } |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8729 | if (UC.hasHandlerData()) { |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8730 | Error(L, ".cantunwind can't be used with .handlerdata directive"); |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8731 | UC.emitHandlerDataLocNotes(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8732 | return false; |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8733 | } |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8734 | if (UC.hasPersonality()) { |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8735 | Error(L, ".cantunwind can't be used with .personality directive"); |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8736 | UC.emitPersonalityLocNotes(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8737 | return false; |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8738 | } |
| 8739 | |
Rafael Espindola | a17151a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 8740 | getTargetStreamer().emitCantUnwind(); |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8741 | return false; |
| 8742 | } |
| 8743 | |
| 8744 | /// parseDirectivePersonality |
| 8745 | /// ::= .personality name |
| 8746 | bool ARMAsmParser::parseDirectivePersonality(SMLoc L) { |
Saleem Abdulrasool | 662f5c1 | 2014-01-21 02:33:02 +0000 | [diff] [blame] | 8747 | bool HasExistingPersonality = UC.hasPersonality(); |
| 8748 | |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8749 | UC.recordPersonality(L); |
| 8750 | |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8751 | // Check the ordering of unwind directives |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8752 | if (!UC.hasFnStart()) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8753 | Error(L, ".fnstart must precede .personality directive"); |
| 8754 | return false; |
| 8755 | } |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8756 | if (UC.cantUnwind()) { |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8757 | Error(L, ".personality can't be used with .cantunwind directive"); |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8758 | UC.emitCantUnwindLocNotes(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8759 | return false; |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8760 | } |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8761 | if (UC.hasHandlerData()) { |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8762 | Error(L, ".personality must precede .handlerdata directive"); |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8763 | UC.emitHandlerDataLocNotes(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8764 | return false; |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8765 | } |
Saleem Abdulrasool | 662f5c1 | 2014-01-21 02:33:02 +0000 | [diff] [blame] | 8766 | if (HasExistingPersonality) { |
| 8767 | Parser.eatToEndOfStatement(); |
| 8768 | Error(L, "multiple personality directives"); |
| 8769 | UC.emitPersonalityLocNotes(); |
| 8770 | return false; |
| 8771 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8772 | |
| 8773 | // Parse the name of the personality routine |
| 8774 | if (Parser.getTok().isNot(AsmToken::Identifier)) { |
| 8775 | Parser.eatToEndOfStatement(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8776 | Error(L, "unexpected input in .personality directive."); |
| 8777 | return false; |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8778 | } |
| 8779 | StringRef Name(Parser.getTok().getIdentifier()); |
| 8780 | Parser.Lex(); |
| 8781 | |
| 8782 | MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name); |
Rafael Espindola | a17151a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 8783 | getTargetStreamer().emitPersonality(PR); |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8784 | return false; |
| 8785 | } |
| 8786 | |
| 8787 | /// parseDirectiveHandlerData |
| 8788 | /// ::= .handlerdata |
| 8789 | bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) { |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8790 | UC.recordHandlerData(L); |
| 8791 | |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8792 | // Check the ordering of unwind directives |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8793 | if (!UC.hasFnStart()) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8794 | Error(L, ".fnstart must precede .personality directive"); |
| 8795 | return false; |
| 8796 | } |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8797 | if (UC.cantUnwind()) { |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8798 | Error(L, ".handlerdata can't be used with .cantunwind directive"); |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8799 | UC.emitCantUnwindLocNotes(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8800 | return false; |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8801 | } |
| 8802 | |
Rafael Espindola | a17151a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 8803 | getTargetStreamer().emitHandlerData(); |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8804 | return false; |
| 8805 | } |
| 8806 | |
| 8807 | /// parseDirectiveSetFP |
| 8808 | /// ::= .setfp fpreg, spreg [, offset] |
| 8809 | bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) { |
| 8810 | // Check the ordering of unwind directives |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8811 | if (!UC.hasFnStart()) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8812 | Error(L, ".fnstart must precede .setfp directive"); |
| 8813 | return false; |
| 8814 | } |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8815 | if (UC.hasHandlerData()) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8816 | Error(L, ".setfp must precede .handlerdata directive"); |
| 8817 | return false; |
| 8818 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8819 | |
| 8820 | // Parse fpreg |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8821 | SMLoc FPRegLoc = Parser.getTok().getLoc(); |
| 8822 | int FPReg = tryParseRegister(); |
| 8823 | if (FPReg == -1) { |
| 8824 | Error(FPRegLoc, "frame pointer register expected"); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8825 | return false; |
| 8826 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8827 | |
| 8828 | // Consume comma |
Saleem Abdulrasool | 5d962d3 | 2014-01-30 04:46:24 +0000 | [diff] [blame] | 8829 | if (Parser.getTok().isNot(AsmToken::Comma)) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8830 | Error(Parser.getTok().getLoc(), "comma expected"); |
| 8831 | return false; |
| 8832 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8833 | Parser.Lex(); // skip comma |
| 8834 | |
| 8835 | // Parse spreg |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8836 | SMLoc SPRegLoc = Parser.getTok().getLoc(); |
| 8837 | int SPReg = tryParseRegister(); |
| 8838 | if (SPReg == -1) { |
| 8839 | Error(SPRegLoc, "stack pointer register expected"); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8840 | return false; |
| 8841 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8842 | |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8843 | if (SPReg != ARM::SP && SPReg != UC.getFPReg()) { |
| 8844 | Error(SPRegLoc, "register should be either $sp or the latest fp register"); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8845 | return false; |
| 8846 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8847 | |
| 8848 | // Update the frame pointer register |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8849 | UC.saveFPReg(FPReg); |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8850 | |
| 8851 | // Parse offset |
| 8852 | int64_t Offset = 0; |
| 8853 | if (Parser.getTok().is(AsmToken::Comma)) { |
| 8854 | Parser.Lex(); // skip comma |
| 8855 | |
| 8856 | if (Parser.getTok().isNot(AsmToken::Hash) && |
| 8857 | Parser.getTok().isNot(AsmToken::Dollar)) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8858 | Error(Parser.getTok().getLoc(), "'#' expected"); |
| 8859 | return false; |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8860 | } |
| 8861 | Parser.Lex(); // skip hash token. |
| 8862 | |
| 8863 | const MCExpr *OffsetExpr; |
| 8864 | SMLoc ExLoc = Parser.getTok().getLoc(); |
| 8865 | SMLoc EndLoc; |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8866 | if (getParser().parseExpression(OffsetExpr, EndLoc)) { |
| 8867 | Error(ExLoc, "malformed setfp offset"); |
| 8868 | return false; |
| 8869 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8870 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8871 | if (!CE) { |
| 8872 | Error(ExLoc, "setfp offset must be an immediate"); |
| 8873 | return false; |
| 8874 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8875 | |
| 8876 | Offset = CE->getValue(); |
| 8877 | } |
| 8878 | |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8879 | getTargetStreamer().emitSetFP(static_cast<unsigned>(FPReg), |
| 8880 | static_cast<unsigned>(SPReg), Offset); |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8881 | return false; |
| 8882 | } |
| 8883 | |
| 8884 | /// parseDirective |
| 8885 | /// ::= .pad offset |
| 8886 | bool ARMAsmParser::parseDirectivePad(SMLoc L) { |
| 8887 | // Check the ordering of unwind directives |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8888 | if (!UC.hasFnStart()) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8889 | Error(L, ".fnstart must precede .pad directive"); |
| 8890 | return false; |
| 8891 | } |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8892 | if (UC.hasHandlerData()) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8893 | Error(L, ".pad must precede .handlerdata directive"); |
| 8894 | return false; |
| 8895 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8896 | |
| 8897 | // Parse the offset |
| 8898 | if (Parser.getTok().isNot(AsmToken::Hash) && |
| 8899 | Parser.getTok().isNot(AsmToken::Dollar)) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8900 | Error(Parser.getTok().getLoc(), "'#' expected"); |
| 8901 | return false; |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8902 | } |
| 8903 | Parser.Lex(); // skip hash token. |
| 8904 | |
| 8905 | const MCExpr *OffsetExpr; |
| 8906 | SMLoc ExLoc = Parser.getTok().getLoc(); |
| 8907 | SMLoc EndLoc; |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8908 | if (getParser().parseExpression(OffsetExpr, EndLoc)) { |
| 8909 | Error(ExLoc, "malformed pad offset"); |
| 8910 | return false; |
| 8911 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8912 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8913 | if (!CE) { |
| 8914 | Error(ExLoc, "pad offset must be an immediate"); |
| 8915 | return false; |
| 8916 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8917 | |
Rafael Espindola | a17151a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 8918 | getTargetStreamer().emitPad(CE->getValue()); |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8919 | return false; |
| 8920 | } |
| 8921 | |
| 8922 | /// parseDirectiveRegSave |
| 8923 | /// ::= .save { registers } |
| 8924 | /// ::= .vsave { registers } |
| 8925 | bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) { |
| 8926 | // Check the ordering of unwind directives |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8927 | if (!UC.hasFnStart()) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8928 | Error(L, ".fnstart must precede .save or .vsave directives"); |
| 8929 | return false; |
| 8930 | } |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8931 | if (UC.hasHandlerData()) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8932 | Error(L, ".save or .vsave must precede .handlerdata directive"); |
| 8933 | return false; |
| 8934 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8935 | |
Benjamin Kramer | 23632bd | 2013-08-03 22:16:24 +0000 | [diff] [blame] | 8936 | // RAII object to make sure parsed operands are deleted. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8937 | SmallVector<std::unique_ptr<MCParsedAsmOperand>, 1> Operands; |
Benjamin Kramer | 23632bd | 2013-08-03 22:16:24 +0000 | [diff] [blame] | 8938 | |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8939 | // Parse the register list |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8940 | if (parseRegisterList(Operands)) |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 8941 | return false; |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8942 | ARMOperand &Op = (ARMOperand &)*Operands[0]; |
| 8943 | if (!IsVector && !Op.isRegList()) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8944 | Error(L, ".save expects GPR registers"); |
| 8945 | return false; |
| 8946 | } |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8947 | if (IsVector && !Op.isDPRRegList()) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8948 | Error(L, ".vsave expects DPR registers"); |
| 8949 | return false; |
| 8950 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8951 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8952 | getTargetStreamer().emitRegSave(Op.getRegList(), IsVector); |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8953 | return false; |
| 8954 | } |
| 8955 | |
Saleem Abdulrasool | c0da2cb | 2013-12-19 05:17:58 +0000 | [diff] [blame] | 8956 | /// parseDirectiveInst |
| 8957 | /// ::= .inst opcode [, ...] |
| 8958 | /// ::= .inst.n opcode [, ...] |
| 8959 | /// ::= .inst.w opcode [, ...] |
| 8960 | bool ARMAsmParser::parseDirectiveInst(SMLoc Loc, char Suffix) { |
| 8961 | int Width; |
| 8962 | |
| 8963 | if (isThumb()) { |
| 8964 | switch (Suffix) { |
| 8965 | case 'n': |
| 8966 | Width = 2; |
| 8967 | break; |
| 8968 | case 'w': |
| 8969 | Width = 4; |
| 8970 | break; |
| 8971 | default: |
| 8972 | Parser.eatToEndOfStatement(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8973 | Error(Loc, "cannot determine Thumb instruction size, " |
| 8974 | "use inst.n/inst.w instead"); |
| 8975 | return false; |
Saleem Abdulrasool | c0da2cb | 2013-12-19 05:17:58 +0000 | [diff] [blame] | 8976 | } |
| 8977 | } else { |
| 8978 | if (Suffix) { |
| 8979 | Parser.eatToEndOfStatement(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8980 | Error(Loc, "width suffixes are invalid in ARM mode"); |
| 8981 | return false; |
Saleem Abdulrasool | c0da2cb | 2013-12-19 05:17:58 +0000 | [diff] [blame] | 8982 | } |
| 8983 | Width = 4; |
| 8984 | } |
| 8985 | |
| 8986 | if (getLexer().is(AsmToken::EndOfStatement)) { |
| 8987 | Parser.eatToEndOfStatement(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8988 | Error(Loc, "expected expression following directive"); |
| 8989 | return false; |
Saleem Abdulrasool | c0da2cb | 2013-12-19 05:17:58 +0000 | [diff] [blame] | 8990 | } |
| 8991 | |
| 8992 | for (;;) { |
| 8993 | const MCExpr *Expr; |
| 8994 | |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8995 | if (getParser().parseExpression(Expr)) { |
| 8996 | Error(Loc, "expected expression"); |
| 8997 | return false; |
| 8998 | } |
Saleem Abdulrasool | c0da2cb | 2013-12-19 05:17:58 +0000 | [diff] [blame] | 8999 | |
| 9000 | const MCConstantExpr *Value = dyn_cast_or_null<MCConstantExpr>(Expr); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9001 | if (!Value) { |
| 9002 | Error(Loc, "expected constant expression"); |
| 9003 | return false; |
| 9004 | } |
Saleem Abdulrasool | c0da2cb | 2013-12-19 05:17:58 +0000 | [diff] [blame] | 9005 | |
| 9006 | switch (Width) { |
| 9007 | case 2: |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9008 | if (Value->getValue() > 0xffff) { |
| 9009 | Error(Loc, "inst.n operand is too big, use inst.w instead"); |
| 9010 | return false; |
| 9011 | } |
Saleem Abdulrasool | c0da2cb | 2013-12-19 05:17:58 +0000 | [diff] [blame] | 9012 | break; |
| 9013 | case 4: |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9014 | if (Value->getValue() > 0xffffffff) { |
| 9015 | Error(Loc, |
| 9016 | StringRef(Suffix ? "inst.w" : "inst") + " operand is too big"); |
| 9017 | return false; |
| 9018 | } |
Saleem Abdulrasool | c0da2cb | 2013-12-19 05:17:58 +0000 | [diff] [blame] | 9019 | break; |
| 9020 | default: |
| 9021 | llvm_unreachable("only supported widths are 2 and 4"); |
| 9022 | } |
| 9023 | |
| 9024 | getTargetStreamer().emitInst(Value->getValue(), Suffix); |
| 9025 | |
| 9026 | if (getLexer().is(AsmToken::EndOfStatement)) |
| 9027 | break; |
| 9028 | |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9029 | if (getLexer().isNot(AsmToken::Comma)) { |
| 9030 | Error(Loc, "unexpected token in directive"); |
| 9031 | return false; |
| 9032 | } |
Saleem Abdulrasool | c0da2cb | 2013-12-19 05:17:58 +0000 | [diff] [blame] | 9033 | |
| 9034 | Parser.Lex(); |
| 9035 | } |
| 9036 | |
| 9037 | Parser.Lex(); |
| 9038 | return false; |
| 9039 | } |
| 9040 | |
David Peixotto | 80c083a | 2013-12-19 18:26:07 +0000 | [diff] [blame] | 9041 | /// parseDirectiveLtorg |
Saleem Abdulrasool | 6e6c239 | 2013-12-20 07:21:16 +0000 | [diff] [blame] | 9042 | /// ::= .ltorg | .pool |
David Peixotto | 80c083a | 2013-12-19 18:26:07 +0000 | [diff] [blame] | 9043 | bool ARMAsmParser::parseDirectiveLtorg(SMLoc L) { |
David Peixotto | b9b7362 | 2014-02-04 17:22:40 +0000 | [diff] [blame] | 9044 | getTargetStreamer().emitCurrentConstantPool(); |
David Peixotto | 80c083a | 2013-12-19 18:26:07 +0000 | [diff] [blame] | 9045 | return false; |
| 9046 | } |
| 9047 | |
Saleem Abdulrasool | a554968 | 2013-12-26 01:52:28 +0000 | [diff] [blame] | 9048 | bool ARMAsmParser::parseDirectiveEven(SMLoc L) { |
| 9049 | const MCSection *Section = getStreamer().getCurrentSection().first; |
| 9050 | |
| 9051 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
| 9052 | TokError("unexpected token in directive"); |
| 9053 | return false; |
| 9054 | } |
| 9055 | |
| 9056 | if (!Section) { |
Rafael Espindola | f144034 | 2014-01-23 23:14:14 +0000 | [diff] [blame] | 9057 | getStreamer().InitSections(); |
Saleem Abdulrasool | a554968 | 2013-12-26 01:52:28 +0000 | [diff] [blame] | 9058 | Section = getStreamer().getCurrentSection().first; |
| 9059 | } |
| 9060 | |
Saleem Abdulrasool | 42b233a | 2014-03-18 05:26:55 +0000 | [diff] [blame] | 9061 | assert(Section && "must have section to emit alignment"); |
Saleem Abdulrasool | a554968 | 2013-12-26 01:52:28 +0000 | [diff] [blame] | 9062 | if (Section->UseCodeAlign()) |
Rafael Espindola | 7b51496 | 2014-02-04 18:34:04 +0000 | [diff] [blame] | 9063 | getStreamer().EmitCodeAlignment(2); |
Saleem Abdulrasool | a554968 | 2013-12-26 01:52:28 +0000 | [diff] [blame] | 9064 | else |
Rafael Espindola | 7b51496 | 2014-02-04 18:34:04 +0000 | [diff] [blame] | 9065 | getStreamer().EmitValueToAlignment(2); |
Saleem Abdulrasool | a554968 | 2013-12-26 01:52:28 +0000 | [diff] [blame] | 9066 | |
| 9067 | return false; |
| 9068 | } |
| 9069 | |
Saleem Abdulrasool | 662f5c1 | 2014-01-21 02:33:02 +0000 | [diff] [blame] | 9070 | /// parseDirectivePersonalityIndex |
| 9071 | /// ::= .personalityindex index |
| 9072 | bool ARMAsmParser::parseDirectivePersonalityIndex(SMLoc L) { |
| 9073 | bool HasExistingPersonality = UC.hasPersonality(); |
| 9074 | |
| 9075 | UC.recordPersonalityIndex(L); |
| 9076 | |
| 9077 | if (!UC.hasFnStart()) { |
| 9078 | Parser.eatToEndOfStatement(); |
| 9079 | Error(L, ".fnstart must precede .personalityindex directive"); |
| 9080 | return false; |
| 9081 | } |
| 9082 | if (UC.cantUnwind()) { |
| 9083 | Parser.eatToEndOfStatement(); |
| 9084 | Error(L, ".personalityindex cannot be used with .cantunwind"); |
| 9085 | UC.emitCantUnwindLocNotes(); |
| 9086 | return false; |
| 9087 | } |
| 9088 | if (UC.hasHandlerData()) { |
| 9089 | Parser.eatToEndOfStatement(); |
| 9090 | Error(L, ".personalityindex must precede .handlerdata directive"); |
| 9091 | UC.emitHandlerDataLocNotes(); |
| 9092 | return false; |
| 9093 | } |
| 9094 | if (HasExistingPersonality) { |
| 9095 | Parser.eatToEndOfStatement(); |
| 9096 | Error(L, "multiple personality directives"); |
| 9097 | UC.emitPersonalityLocNotes(); |
| 9098 | return false; |
| 9099 | } |
| 9100 | |
| 9101 | const MCExpr *IndexExpression; |
| 9102 | SMLoc IndexLoc = Parser.getTok().getLoc(); |
| 9103 | if (Parser.parseExpression(IndexExpression)) { |
| 9104 | Parser.eatToEndOfStatement(); |
| 9105 | return false; |
| 9106 | } |
| 9107 | |
| 9108 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(IndexExpression); |
| 9109 | if (!CE) { |
| 9110 | Parser.eatToEndOfStatement(); |
| 9111 | Error(IndexLoc, "index must be a constant number"); |
| 9112 | return false; |
| 9113 | } |
| 9114 | if (CE->getValue() < 0 || |
| 9115 | CE->getValue() >= ARM::EHABI::NUM_PERSONALITY_INDEX) { |
| 9116 | Parser.eatToEndOfStatement(); |
| 9117 | Error(IndexLoc, "personality routine index should be in range [0-3]"); |
| 9118 | return false; |
| 9119 | } |
| 9120 | |
| 9121 | getTargetStreamer().emitPersonalityIndex(CE->getValue()); |
| 9122 | return false; |
| 9123 | } |
| 9124 | |
Saleem Abdulrasool | d9f0860 | 2014-01-21 02:33:10 +0000 | [diff] [blame] | 9125 | /// parseDirectiveUnwindRaw |
| 9126 | /// ::= .unwind_raw offset, opcode [, opcode...] |
| 9127 | bool ARMAsmParser::parseDirectiveUnwindRaw(SMLoc L) { |
| 9128 | if (!UC.hasFnStart()) { |
| 9129 | Parser.eatToEndOfStatement(); |
| 9130 | Error(L, ".fnstart must precede .unwind_raw directives"); |
| 9131 | return false; |
| 9132 | } |
| 9133 | |
| 9134 | int64_t StackOffset; |
| 9135 | |
| 9136 | const MCExpr *OffsetExpr; |
| 9137 | SMLoc OffsetLoc = getLexer().getLoc(); |
| 9138 | if (getLexer().is(AsmToken::EndOfStatement) || |
| 9139 | getParser().parseExpression(OffsetExpr)) { |
| 9140 | Error(OffsetLoc, "expected expression"); |
| 9141 | Parser.eatToEndOfStatement(); |
| 9142 | return false; |
| 9143 | } |
| 9144 | |
| 9145 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr); |
| 9146 | if (!CE) { |
| 9147 | Error(OffsetLoc, "offset must be a constant"); |
| 9148 | Parser.eatToEndOfStatement(); |
| 9149 | return false; |
| 9150 | } |
| 9151 | |
| 9152 | StackOffset = CE->getValue(); |
| 9153 | |
| 9154 | if (getLexer().isNot(AsmToken::Comma)) { |
| 9155 | Error(getLexer().getLoc(), "expected comma"); |
| 9156 | Parser.eatToEndOfStatement(); |
| 9157 | return false; |
| 9158 | } |
| 9159 | Parser.Lex(); |
| 9160 | |
| 9161 | SmallVector<uint8_t, 16> Opcodes; |
| 9162 | for (;;) { |
| 9163 | const MCExpr *OE; |
| 9164 | |
| 9165 | SMLoc OpcodeLoc = getLexer().getLoc(); |
| 9166 | if (getLexer().is(AsmToken::EndOfStatement) || Parser.parseExpression(OE)) { |
| 9167 | Error(OpcodeLoc, "expected opcode expression"); |
| 9168 | Parser.eatToEndOfStatement(); |
| 9169 | return false; |
| 9170 | } |
| 9171 | |
| 9172 | const MCConstantExpr *OC = dyn_cast<MCConstantExpr>(OE); |
| 9173 | if (!OC) { |
| 9174 | Error(OpcodeLoc, "opcode value must be a constant"); |
| 9175 | Parser.eatToEndOfStatement(); |
| 9176 | return false; |
| 9177 | } |
| 9178 | |
| 9179 | const int64_t Opcode = OC->getValue(); |
| 9180 | if (Opcode & ~0xff) { |
| 9181 | Error(OpcodeLoc, "invalid opcode"); |
| 9182 | Parser.eatToEndOfStatement(); |
| 9183 | return false; |
| 9184 | } |
| 9185 | |
| 9186 | Opcodes.push_back(uint8_t(Opcode)); |
| 9187 | |
| 9188 | if (getLexer().is(AsmToken::EndOfStatement)) |
| 9189 | break; |
| 9190 | |
| 9191 | if (getLexer().isNot(AsmToken::Comma)) { |
| 9192 | Error(getLexer().getLoc(), "unexpected token in directive"); |
| 9193 | Parser.eatToEndOfStatement(); |
| 9194 | return false; |
| 9195 | } |
| 9196 | |
| 9197 | Parser.Lex(); |
| 9198 | } |
| 9199 | |
| 9200 | getTargetStreamer().emitUnwindRaw(StackOffset, Opcodes); |
| 9201 | |
| 9202 | Parser.Lex(); |
| 9203 | return false; |
| 9204 | } |
| 9205 | |
Saleem Abdulrasool | 56e06e8 | 2014-01-30 04:02:47 +0000 | [diff] [blame] | 9206 | /// parseDirectiveTLSDescSeq |
| 9207 | /// ::= .tlsdescseq tls-variable |
| 9208 | bool ARMAsmParser::parseDirectiveTLSDescSeq(SMLoc L) { |
| 9209 | if (getLexer().isNot(AsmToken::Identifier)) { |
| 9210 | TokError("expected variable after '.tlsdescseq' directive"); |
| 9211 | Parser.eatToEndOfStatement(); |
| 9212 | return false; |
| 9213 | } |
| 9214 | |
| 9215 | const MCSymbolRefExpr *SRE = |
| 9216 | MCSymbolRefExpr::Create(Parser.getTok().getIdentifier(), |
| 9217 | MCSymbolRefExpr::VK_ARM_TLSDESCSEQ, getContext()); |
| 9218 | Lex(); |
| 9219 | |
| 9220 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
| 9221 | Error(Parser.getTok().getLoc(), "unexpected token"); |
| 9222 | Parser.eatToEndOfStatement(); |
| 9223 | return false; |
| 9224 | } |
| 9225 | |
| 9226 | getTargetStreamer().AnnotateTLSDescriptorSequence(SRE); |
| 9227 | return false; |
| 9228 | } |
| 9229 | |
Saleem Abdulrasool | 5d962d3 | 2014-01-30 04:46:24 +0000 | [diff] [blame] | 9230 | /// parseDirectiveMovSP |
| 9231 | /// ::= .movsp reg [, #offset] |
| 9232 | bool ARMAsmParser::parseDirectiveMovSP(SMLoc L) { |
| 9233 | if (!UC.hasFnStart()) { |
| 9234 | Parser.eatToEndOfStatement(); |
| 9235 | Error(L, ".fnstart must precede .movsp directives"); |
| 9236 | return false; |
| 9237 | } |
| 9238 | if (UC.getFPReg() != ARM::SP) { |
| 9239 | Parser.eatToEndOfStatement(); |
| 9240 | Error(L, "unexpected .movsp directive"); |
| 9241 | return false; |
| 9242 | } |
| 9243 | |
| 9244 | SMLoc SPRegLoc = Parser.getTok().getLoc(); |
| 9245 | int SPReg = tryParseRegister(); |
| 9246 | if (SPReg == -1) { |
| 9247 | Parser.eatToEndOfStatement(); |
| 9248 | Error(SPRegLoc, "register expected"); |
| 9249 | return false; |
| 9250 | } |
| 9251 | |
| 9252 | if (SPReg == ARM::SP || SPReg == ARM::PC) { |
| 9253 | Parser.eatToEndOfStatement(); |
| 9254 | Error(SPRegLoc, "sp and pc are not permitted in .movsp directive"); |
| 9255 | return false; |
| 9256 | } |
| 9257 | |
| 9258 | int64_t Offset = 0; |
| 9259 | if (Parser.getTok().is(AsmToken::Comma)) { |
| 9260 | Parser.Lex(); |
| 9261 | |
| 9262 | if (Parser.getTok().isNot(AsmToken::Hash)) { |
| 9263 | Error(Parser.getTok().getLoc(), "expected #constant"); |
| 9264 | Parser.eatToEndOfStatement(); |
| 9265 | return false; |
| 9266 | } |
| 9267 | Parser.Lex(); |
| 9268 | |
| 9269 | const MCExpr *OffsetExpr; |
| 9270 | SMLoc OffsetLoc = Parser.getTok().getLoc(); |
| 9271 | if (Parser.parseExpression(OffsetExpr)) { |
| 9272 | Parser.eatToEndOfStatement(); |
| 9273 | Error(OffsetLoc, "malformed offset expression"); |
| 9274 | return false; |
| 9275 | } |
| 9276 | |
| 9277 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr); |
| 9278 | if (!CE) { |
| 9279 | Parser.eatToEndOfStatement(); |
| 9280 | Error(OffsetLoc, "offset must be an immediate constant"); |
| 9281 | return false; |
| 9282 | } |
| 9283 | |
| 9284 | Offset = CE->getValue(); |
| 9285 | } |
| 9286 | |
| 9287 | getTargetStreamer().emitMovSP(SPReg, Offset); |
| 9288 | UC.saveFPReg(SPReg); |
| 9289 | |
| 9290 | return false; |
| 9291 | } |
| 9292 | |
Saleem Abdulrasool | 4c4789b | 2014-01-30 04:46:41 +0000 | [diff] [blame] | 9293 | /// parseDirectiveObjectArch |
| 9294 | /// ::= .object_arch name |
| 9295 | bool ARMAsmParser::parseDirectiveObjectArch(SMLoc L) { |
| 9296 | if (getLexer().isNot(AsmToken::Identifier)) { |
| 9297 | Error(getLexer().getLoc(), "unexpected token"); |
| 9298 | Parser.eatToEndOfStatement(); |
| 9299 | return false; |
| 9300 | } |
| 9301 | |
| 9302 | StringRef Arch = Parser.getTok().getString(); |
| 9303 | SMLoc ArchLoc = Parser.getTok().getLoc(); |
| 9304 | getLexer().Lex(); |
| 9305 | |
| 9306 | unsigned ID = StringSwitch<unsigned>(Arch) |
| 9307 | #define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \ |
| 9308 | .Case(NAME, ARM::ID) |
| 9309 | #define ARM_ARCH_ALIAS(NAME, ID) \ |
| 9310 | .Case(NAME, ARM::ID) |
| 9311 | #include "MCTargetDesc/ARMArchName.def" |
| 9312 | #undef ARM_ARCH_NAME |
| 9313 | #undef ARM_ARCH_ALIAS |
| 9314 | .Default(ARM::INVALID_ARCH); |
| 9315 | |
| 9316 | if (ID == ARM::INVALID_ARCH) { |
| 9317 | Error(ArchLoc, "unknown architecture '" + Arch + "'"); |
| 9318 | Parser.eatToEndOfStatement(); |
| 9319 | return false; |
| 9320 | } |
| 9321 | |
| 9322 | getTargetStreamer().emitObjectArch(ID); |
| 9323 | |
| 9324 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
| 9325 | Error(getLexer().getLoc(), "unexpected token"); |
| 9326 | Parser.eatToEndOfStatement(); |
| 9327 | } |
| 9328 | |
| 9329 | return false; |
| 9330 | } |
| 9331 | |
Saleem Abdulrasool | fd6ed1e | 2014-02-23 17:45:32 +0000 | [diff] [blame] | 9332 | /// parseDirectiveAlign |
| 9333 | /// ::= .align |
| 9334 | bool ARMAsmParser::parseDirectiveAlign(SMLoc L) { |
| 9335 | // NOTE: if this is not the end of the statement, fall back to the target |
| 9336 | // agnostic handling for this directive which will correctly handle this. |
| 9337 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 9338 | return true; |
| 9339 | |
| 9340 | // '.align' is target specifically handled to mean 2**2 byte alignment. |
| 9341 | if (getStreamer().getCurrentSection().first->UseCodeAlign()) |
| 9342 | getStreamer().EmitCodeAlignment(4, 0); |
| 9343 | else |
| 9344 | getStreamer().EmitValueToAlignment(4, 0, 1, 0); |
| 9345 | |
| 9346 | return false; |
| 9347 | } |
| 9348 | |
Saleem Abdulrasool | 39f773f | 2014-03-20 06:05:33 +0000 | [diff] [blame] | 9349 | /// parseDirectiveThumbSet |
| 9350 | /// ::= .thumb_set name, value |
| 9351 | bool ARMAsmParser::parseDirectiveThumbSet(SMLoc L) { |
| 9352 | StringRef Name; |
| 9353 | if (Parser.parseIdentifier(Name)) { |
| 9354 | TokError("expected identifier after '.thumb_set'"); |
| 9355 | Parser.eatToEndOfStatement(); |
| 9356 | return false; |
| 9357 | } |
| 9358 | |
| 9359 | if (getLexer().isNot(AsmToken::Comma)) { |
| 9360 | TokError("expected comma after name '" + Name + "'"); |
| 9361 | Parser.eatToEndOfStatement(); |
| 9362 | return false; |
| 9363 | } |
| 9364 | Lex(); |
| 9365 | |
| 9366 | const MCExpr *Value; |
| 9367 | if (Parser.parseExpression(Value)) { |
| 9368 | TokError("missing expression"); |
| 9369 | Parser.eatToEndOfStatement(); |
| 9370 | return false; |
| 9371 | } |
| 9372 | |
| 9373 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
| 9374 | TokError("unexpected token"); |
| 9375 | Parser.eatToEndOfStatement(); |
| 9376 | return false; |
| 9377 | } |
| 9378 | Lex(); |
| 9379 | |
| 9380 | MCSymbol *Alias = getContext().GetOrCreateSymbol(Name); |
Rafael Espindola | 466d663 | 2014-04-27 20:23:58 +0000 | [diff] [blame] | 9381 | getTargetStreamer().emitThumbSet(Alias, Value); |
Saleem Abdulrasool | 39f773f | 2014-03-20 06:05:33 +0000 | [diff] [blame] | 9382 | return false; |
| 9383 | } |
| 9384 | |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 9385 | /// Force static initialization. |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 9386 | extern "C" void LLVMInitializeARMAsmParser() { |
Christian Pirker | dc9ff75 | 2014-04-01 15:19:30 +0000 | [diff] [blame] | 9387 | RegisterMCAsmParser<ARMAsmParser> X(TheARMLETarget); |
| 9388 | RegisterMCAsmParser<ARMAsmParser> Y(TheARMBETarget); |
| 9389 | RegisterMCAsmParser<ARMAsmParser> A(TheThumbLETarget); |
| 9390 | RegisterMCAsmParser<ARMAsmParser> B(TheThumbBETarget); |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 9391 | } |
Daniel Dunbar | 5cd4d0f | 2010-08-11 05:24:50 +0000 | [diff] [blame] | 9392 | |
Chris Lattner | 3e4582a | 2010-09-06 19:11:01 +0000 | [diff] [blame] | 9393 | #define GET_REGISTER_MATCHER |
Craig Topper | 3ec7c2a | 2012-04-25 06:56:34 +0000 | [diff] [blame] | 9394 | #define GET_SUBTARGET_FEATURE_NAME |
Chris Lattner | 3e4582a | 2010-09-06 19:11:01 +0000 | [diff] [blame] | 9395 | #define GET_MATCHER_IMPLEMENTATION |
Daniel Dunbar | 5cd4d0f | 2010-08-11 05:24:50 +0000 | [diff] [blame] | 9396 | #include "ARMGenAsmMatcher.inc" |
Jim Grosbach | 231e7aa | 2013-02-06 06:00:11 +0000 | [diff] [blame] | 9397 | |
Saleem Abdulrasool | 45cf67b | 2014-07-27 19:07:05 +0000 | [diff] [blame] | 9398 | static const struct { |
| 9399 | const char *Name; |
Saleem Abdulrasool | 49480bf | 2014-02-16 00:16:41 +0000 | [diff] [blame] | 9400 | const unsigned ArchCheck; |
| 9401 | const uint64_t Features; |
| 9402 | } Extensions[] = { |
| 9403 | { "crc", Feature_HasV8, ARM::FeatureCRC }, |
| 9404 | { "crypto", Feature_HasV8, |
| 9405 | ARM::FeatureCrypto | ARM::FeatureNEON | ARM::FeatureFPARMv8 }, |
| 9406 | { "fp", Feature_HasV8, ARM::FeatureFPARMv8 }, |
| 9407 | { "idiv", Feature_HasV7 | Feature_IsNotMClass, |
| 9408 | ARM::FeatureHWDiv | ARM::FeatureHWDivARM }, |
| 9409 | // FIXME: iWMMXT not supported |
| 9410 | { "iwmmxt", Feature_None, 0 }, |
| 9411 | // FIXME: iWMMXT2 not supported |
| 9412 | { "iwmmxt2", Feature_None, 0 }, |
| 9413 | // FIXME: Maverick not supported |
| 9414 | { "maverick", Feature_None, 0 }, |
| 9415 | { "mp", Feature_HasV7 | Feature_IsNotMClass, ARM::FeatureMP }, |
| 9416 | // FIXME: ARMv6-m OS Extensions feature not checked |
| 9417 | { "os", Feature_None, 0 }, |
| 9418 | // FIXME: Also available in ARMv6-K |
| 9419 | { "sec", Feature_HasV7, ARM::FeatureTrustZone }, |
| 9420 | { "simd", Feature_HasV8, ARM::FeatureNEON | ARM::FeatureFPARMv8 }, |
| 9421 | // FIXME: Only available in A-class, isel not predicated |
| 9422 | { "virt", Feature_HasV7, ARM::FeatureVirtualization }, |
| 9423 | // FIXME: xscale not supported |
| 9424 | { "xscale", Feature_None, 0 }, |
| 9425 | }; |
| 9426 | |
Saleem Abdulrasool | 49480bf | 2014-02-16 00:16:41 +0000 | [diff] [blame] | 9427 | /// parseDirectiveArchExtension |
| 9428 | /// ::= .arch_extension [no]feature |
| 9429 | bool ARMAsmParser::parseDirectiveArchExtension(SMLoc L) { |
| 9430 | if (getLexer().isNot(AsmToken::Identifier)) { |
| 9431 | Error(getLexer().getLoc(), "unexpected token"); |
| 9432 | Parser.eatToEndOfStatement(); |
| 9433 | return false; |
| 9434 | } |
| 9435 | |
Saleem Abdulrasool | 45cf67b | 2014-07-27 19:07:05 +0000 | [diff] [blame] | 9436 | StringRef Name = Parser.getTok().getString(); |
Saleem Abdulrasool | 49480bf | 2014-02-16 00:16:41 +0000 | [diff] [blame] | 9437 | SMLoc ExtLoc = Parser.getTok().getLoc(); |
| 9438 | getLexer().Lex(); |
| 9439 | |
| 9440 | bool EnableFeature = true; |
Saleem Abdulrasool | 45cf67b | 2014-07-27 19:07:05 +0000 | [diff] [blame] | 9441 | if (Name.startswith_lower("no")) { |
Saleem Abdulrasool | 49480bf | 2014-02-16 00:16:41 +0000 | [diff] [blame] | 9442 | EnableFeature = false; |
Saleem Abdulrasool | 45cf67b | 2014-07-27 19:07:05 +0000 | [diff] [blame] | 9443 | Name = Name.substr(2); |
Saleem Abdulrasool | 49480bf | 2014-02-16 00:16:41 +0000 | [diff] [blame] | 9444 | } |
| 9445 | |
Saleem Abdulrasool | 45cf67b | 2014-07-27 19:07:05 +0000 | [diff] [blame] | 9446 | for (const auto &Extension : Extensions) { |
| 9447 | if (Extension.Name != Name) |
Saleem Abdulrasool | 49480bf | 2014-02-16 00:16:41 +0000 | [diff] [blame] | 9448 | continue; |
| 9449 | |
Saleem Abdulrasool | 8988c2a | 2014-07-27 19:07:09 +0000 | [diff] [blame] | 9450 | if (!Extension.Features) |
| 9451 | report_fatal_error("unsupported architectural extension: " + Name); |
| 9452 | |
| 9453 | if ((getAvailableFeatures() & Extension.ArchCheck) != Extension.ArchCheck) { |
Saleem Abdulrasool | 45cf67b | 2014-07-27 19:07:05 +0000 | [diff] [blame] | 9454 | Error(ExtLoc, "architectural extension '" + Name + "' is not " |
Saleem Abdulrasool | 49480bf | 2014-02-16 00:16:41 +0000 | [diff] [blame] | 9455 | "allowed for the current base architecture"); |
| 9456 | return false; |
| 9457 | } |
| 9458 | |
Saleem Abdulrasool | 8988c2a | 2014-07-27 19:07:09 +0000 | [diff] [blame] | 9459 | bool ToggleFeatures = EnableFeature |
| 9460 | ? (~STI.getFeatureBits() & Extension.Features) |
| 9461 | : ( STI.getFeatureBits() & Extension.Features); |
| 9462 | if (ToggleFeatures) { |
| 9463 | unsigned Features = |
| 9464 | ComputeAvailableFeatures(STI.ToggleFeature(Extension.Features)); |
| 9465 | setAvailableFeatures(Features); |
| 9466 | } |
Saleem Abdulrasool | 49480bf | 2014-02-16 00:16:41 +0000 | [diff] [blame] | 9467 | return false; |
| 9468 | } |
| 9469 | |
Saleem Abdulrasool | 45cf67b | 2014-07-27 19:07:05 +0000 | [diff] [blame] | 9470 | Error(ExtLoc, "unknown architectural extension: " + Name); |
Saleem Abdulrasool | 49480bf | 2014-02-16 00:16:41 +0000 | [diff] [blame] | 9471 | Parser.eatToEndOfStatement(); |
| 9472 | return false; |
| 9473 | } |
| 9474 | |
Jim Grosbach | 231e7aa | 2013-02-06 06:00:11 +0000 | [diff] [blame] | 9475 | // Define this matcher function after the auto-generated include so we |
| 9476 | // have the match class enum definitions. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 9477 | unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand &AsmOp, |
Jim Grosbach | 231e7aa | 2013-02-06 06:00:11 +0000 | [diff] [blame] | 9478 | unsigned Kind) { |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 9479 | ARMOperand &Op = static_cast<ARMOperand &>(AsmOp); |
Jim Grosbach | 231e7aa | 2013-02-06 06:00:11 +0000 | [diff] [blame] | 9480 | // If the kind is a token for a literal immediate, check if our asm |
| 9481 | // operand matches. This is for InstAliases which have a fixed-value |
| 9482 | // immediate in the syntax. |
Saleem Abdulrasool | d88affb | 2014-01-08 03:28:14 +0000 | [diff] [blame] | 9483 | switch (Kind) { |
| 9484 | default: break; |
| 9485 | case MCK__35_0: |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 9486 | if (Op.isImm()) |
| 9487 | if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm())) |
Saleem Abdulrasool | d88affb | 2014-01-08 03:28:14 +0000 | [diff] [blame] | 9488 | if (CE->getValue() == 0) |
| 9489 | return Match_Success; |
| 9490 | break; |
| 9491 | case MCK_ARMSOImm: |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 9492 | if (Op.isImm()) { |
| 9493 | const MCExpr *SOExpr = Op.getImm(); |
Saleem Abdulrasool | d88affb | 2014-01-08 03:28:14 +0000 | [diff] [blame] | 9494 | int64_t Value; |
| 9495 | if (!SOExpr->EvaluateAsAbsolute(Value)) |
Stepan Dyatkovskiy | df657cc | 2014-03-29 13:12:40 +0000 | [diff] [blame] | 9496 | return Match_Success; |
Richard Barton | 3db1d58 | 2014-05-01 11:37:44 +0000 | [diff] [blame] | 9497 | assert((Value >= INT32_MIN && Value <= UINT32_MAX) && |
| 9498 | "expression value must be representable in 32 bits"); |
Saleem Abdulrasool | d88affb | 2014-01-08 03:28:14 +0000 | [diff] [blame] | 9499 | } |
| 9500 | break; |
Saleem Abdulrasool | e6e6d71 | 2014-01-10 04:38:35 +0000 | [diff] [blame] | 9501 | case MCK_GPRPair: |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 9502 | if (Op.isReg() && |
| 9503 | MRI->getRegClass(ARM::GPRRegClassID).contains(Op.getReg())) |
Saleem Abdulrasool | e6e6d71 | 2014-01-10 04:38:35 +0000 | [diff] [blame] | 9504 | return Match_Success; |
| 9505 | break; |
Jim Grosbach | 231e7aa | 2013-02-06 06:00:11 +0000 | [diff] [blame] | 9506 | } |
| 9507 | return Match_InvalidOperand; |
| 9508 | } |