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; |
Joey Gouly | 0e76fa7 | 2013-09-12 10:28:05 +0000 | [diff] [blame] | 132 | const MCInstrInfo &MII; |
Jim Grosbach | c988e0c | 2012-03-05 19:33:30 +0000 | [diff] [blame] | 133 | const MCRegisterInfo *MRI; |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 134 | UnwindContext UC; |
David Peixotto | e407d09 | 2013-12-19 18:12:36 +0000 | [diff] [blame] | 135 | |
Rafael Espindola | a17151a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 136 | ARMTargetStreamer &getTargetStreamer() { |
Saleem Abdulrasool | bfdfb14 | 2014-09-18 04:28:29 +0000 | [diff] [blame] | 137 | assert(getParser().getStreamer().getTargetStreamer() && |
| 138 | "do not have a target streamer"); |
Rafael Espindola | 4a1a360 | 2014-01-14 01:21:46 +0000 | [diff] [blame] | 139 | MCTargetStreamer &TS = *getParser().getStreamer().getTargetStreamer(); |
Rafael Espindola | a17151a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 140 | return static_cast<ARMTargetStreamer &>(TS); |
| 141 | } |
| 142 | |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 143 | // Map of register aliases registers via the .req directive. |
| 144 | StringMap<unsigned> RegisterReqs; |
| 145 | |
Tim Northover | 1744d0a | 2013-10-25 12:49:50 +0000 | [diff] [blame] | 146 | bool NextSymbolIsThumb; |
| 147 | |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 148 | struct { |
| 149 | ARMCC::CondCodes Cond; // Condition for IT block. |
| 150 | unsigned Mask:4; // Condition mask for instructions. |
| 151 | // Starting at first 1 (from lsb). |
| 152 | // '1' condition as indicated in IT. |
| 153 | // '0' inverse of condition (else). |
| 154 | // Count of instructions in IT block is |
| 155 | // 4 - trailingzeroes(mask) |
| 156 | |
| 157 | bool FirstCond; // Explicit flag for when we're parsing the |
| 158 | // First instruction in the IT block. It's |
| 159 | // implied in the mask, so needs special |
| 160 | // handling. |
| 161 | |
| 162 | unsigned CurPosition; // Current position in parsing of IT |
| 163 | // block. In range [0,3]. Initialized |
| 164 | // according to count of instructions in block. |
| 165 | // ~0U if no active IT block. |
| 166 | } ITState; |
| 167 | bool inITBlock() { return ITState.CurPosition != ~0U;} |
Jim Grosbach | a0d34d3 | 2011-09-02 23:22:08 +0000 | [diff] [blame] | 168 | void forwardITPosition() { |
| 169 | if (!inITBlock()) return; |
| 170 | // Move to the next instruction in the IT block, if there is one. If not, |
| 171 | // mark the block as done. |
Michael J. Spencer | df1ecbd7 | 2013-05-24 22:23:49 +0000 | [diff] [blame] | 172 | unsigned TZ = countTrailingZeros(ITState.Mask); |
Jim Grosbach | a0d34d3 | 2011-09-02 23:22:08 +0000 | [diff] [blame] | 173 | if (++ITState.CurPosition == 5 - TZ) |
| 174 | ITState.CurPosition = ~0U; // Done with the IT block after this. |
| 175 | } |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 176 | |
Saleem Abdulrasool | 69c7caf | 2014-01-07 02:28:31 +0000 | [diff] [blame] | 177 | void Note(SMLoc L, const Twine &Msg, ArrayRef<SMRange> Ranges = None) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 178 | return getParser().Note(L, Msg, Ranges); |
Saleem Abdulrasool | 69c7caf | 2014-01-07 02:28:31 +0000 | [diff] [blame] | 179 | } |
Benjamin Kramer | 673824b | 2012-04-15 17:04:27 +0000 | [diff] [blame] | 180 | bool Warning(SMLoc L, const Twine &Msg, |
Dmitri Gribenko | 3238fb7 | 2013-05-05 00:40:33 +0000 | [diff] [blame] | 181 | ArrayRef<SMRange> Ranges = None) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 182 | return getParser().Warning(L, Msg, Ranges); |
Benjamin Kramer | 673824b | 2012-04-15 17:04:27 +0000 | [diff] [blame] | 183 | } |
| 184 | bool Error(SMLoc L, const Twine &Msg, |
Dmitri Gribenko | 3238fb7 | 2013-05-05 00:40:33 +0000 | [diff] [blame] | 185 | ArrayRef<SMRange> Ranges = None) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 186 | return getParser().Error(L, Msg, Ranges); |
Benjamin Kramer | 673824b | 2012-04-15 17:04:27 +0000 | [diff] [blame] | 187 | } |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 188 | |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 189 | int tryParseRegister(); |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 190 | bool tryParseRegisterWithWriteBack(OperandVector &); |
| 191 | int tryParseShiftRegister(OperandVector &); |
| 192 | bool parseRegisterList(OperandVector &); |
| 193 | bool parseMemory(OperandVector &); |
| 194 | bool parseOperand(OperandVector &, StringRef Mnemonic); |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 195 | bool parsePrefix(ARMMCExpr::VariantKind &RefKind); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 196 | bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType, |
| 197 | unsigned &ShiftAmount); |
Saleem Abdulrasool | 3897651 | 2014-02-23 06:22:09 +0000 | [diff] [blame] | 198 | bool parseLiteralValues(unsigned Size, SMLoc L); |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 199 | bool parseDirectiveThumb(SMLoc L); |
Jim Grosbach | 7f88239 | 2011-12-07 18:04:19 +0000 | [diff] [blame] | 200 | bool parseDirectiveARM(SMLoc L); |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 201 | bool parseDirectiveThumbFunc(SMLoc L); |
| 202 | bool parseDirectiveCode(SMLoc L); |
| 203 | bool parseDirectiveSyntax(SMLoc L); |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 204 | bool parseDirectiveReq(StringRef Name, SMLoc L); |
| 205 | bool parseDirectiveUnreq(SMLoc L); |
Jason W Kim | 135d244 | 2011-12-20 17:38:12 +0000 | [diff] [blame] | 206 | bool parseDirectiveArch(SMLoc L); |
| 207 | bool parseDirectiveEabiAttr(SMLoc L); |
Logan Chien | 8cbb80d | 2013-10-28 17:51:12 +0000 | [diff] [blame] | 208 | bool parseDirectiveCPU(SMLoc L); |
| 209 | bool parseDirectiveFPU(SMLoc L); |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 210 | bool parseDirectiveFnStart(SMLoc L); |
| 211 | bool parseDirectiveFnEnd(SMLoc L); |
| 212 | bool parseDirectiveCantUnwind(SMLoc L); |
| 213 | bool parseDirectivePersonality(SMLoc L); |
| 214 | bool parseDirectiveHandlerData(SMLoc L); |
| 215 | bool parseDirectiveSetFP(SMLoc L); |
| 216 | bool parseDirectivePad(SMLoc L); |
| 217 | bool parseDirectiveRegSave(SMLoc L, bool IsVector); |
Saleem Abdulrasool | c0da2cb | 2013-12-19 05:17:58 +0000 | [diff] [blame] | 218 | bool parseDirectiveInst(SMLoc L, char Suffix = '\0'); |
David Peixotto | 80c083a | 2013-12-19 18:26:07 +0000 | [diff] [blame] | 219 | bool parseDirectiveLtorg(SMLoc L); |
Saleem Abdulrasool | a554968 | 2013-12-26 01:52:28 +0000 | [diff] [blame] | 220 | bool parseDirectiveEven(SMLoc L); |
Saleem Abdulrasool | 662f5c1 | 2014-01-21 02:33:02 +0000 | [diff] [blame] | 221 | bool parseDirectivePersonalityIndex(SMLoc L); |
Saleem Abdulrasool | d9f0860 | 2014-01-21 02:33:10 +0000 | [diff] [blame] | 222 | bool parseDirectiveUnwindRaw(SMLoc L); |
Saleem Abdulrasool | 56e06e8 | 2014-01-30 04:02:47 +0000 | [diff] [blame] | 223 | bool parseDirectiveTLSDescSeq(SMLoc L); |
Saleem Abdulrasool | 5d962d3 | 2014-01-30 04:46:24 +0000 | [diff] [blame] | 224 | bool parseDirectiveMovSP(SMLoc L); |
Saleem Abdulrasool | 4c4789b | 2014-01-30 04:46:41 +0000 | [diff] [blame] | 225 | bool parseDirectiveObjectArch(SMLoc L); |
Saleem Abdulrasool | 49480bf | 2014-02-16 00:16:41 +0000 | [diff] [blame] | 226 | bool parseDirectiveArchExtension(SMLoc L); |
Saleem Abdulrasool | fd6ed1e | 2014-02-23 17:45:32 +0000 | [diff] [blame] | 227 | bool parseDirectiveAlign(SMLoc L); |
Saleem Abdulrasool | 39f773f | 2014-03-20 06:05:33 +0000 | [diff] [blame] | 228 | bool parseDirectiveThumbSet(SMLoc L); |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 229 | |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 230 | StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode, |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 231 | bool &CarrySetting, unsigned &ProcessorIMod, |
| 232 | StringRef &ITMask); |
Amara Emerson | 3308909 | 2013-09-19 11:59:01 +0000 | [diff] [blame] | 233 | void getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst, |
| 234 | bool &CanAcceptCarrySet, |
Bruno Cardoso Lopes | e6290cc | 2011-01-18 20:55:11 +0000 | [diff] [blame] | 235 | bool &CanAcceptPredicationCode); |
Jim Grosbach | 624bcc7 | 2010-10-29 14:46:02 +0000 | [diff] [blame] | 236 | |
Evan Cheng | 4d1ca96 | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 237 | bool isThumb() const { |
| 238 | // FIXME: Can tablegen auto-generate this? |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 239 | return (STI.getFeatureBits() & ARM::ModeThumb) != 0; |
Evan Cheng | 4d1ca96 | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 240 | } |
Evan Cheng | 4d1ca96 | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 241 | bool isThumbOne() const { |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 242 | return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0; |
Evan Cheng | 4d1ca96 | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 243 | } |
Jim Grosbach | 3e941ae | 2011-08-16 20:45:50 +0000 | [diff] [blame] | 244 | bool isThumbTwo() const { |
| 245 | return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2); |
| 246 | } |
Tim Northover | a2292d0 | 2013-06-10 23:20:58 +0000 | [diff] [blame] | 247 | bool hasThumb() const { |
| 248 | return STI.getFeatureBits() & ARM::HasV4TOps; |
| 249 | } |
Jim Grosbach | b7fa2c0 | 2011-08-16 22:20:01 +0000 | [diff] [blame] | 250 | bool hasV6Ops() const { |
| 251 | return STI.getFeatureBits() & ARM::HasV6Ops; |
| 252 | } |
Tim Northover | f86d1f0 | 2013-10-07 11:10:47 +0000 | [diff] [blame] | 253 | bool hasV6MOps() const { |
| 254 | return STI.getFeatureBits() & ARM::HasV6MOps; |
| 255 | } |
James Molloy | 21efa7d | 2011-09-28 14:21:38 +0000 | [diff] [blame] | 256 | bool hasV7Ops() const { |
| 257 | return STI.getFeatureBits() & ARM::HasV7Ops; |
| 258 | } |
Joey Gouly | b3f550e | 2013-06-26 16:58:26 +0000 | [diff] [blame] | 259 | bool hasV8Ops() const { |
| 260 | return STI.getFeatureBits() & ARM::HasV8Ops; |
| 261 | } |
Tim Northover | a2292d0 | 2013-06-10 23:20:58 +0000 | [diff] [blame] | 262 | bool hasARM() const { |
| 263 | return !(STI.getFeatureBits() & ARM::FeatureNoARM); |
| 264 | } |
Renato Golin | 92c816c | 2014-09-01 11:25:07 +0000 | [diff] [blame] | 265 | bool hasThumb2DSP() const { |
| 266 | return STI.getFeatureBits() & ARM::FeatureDSPThumb2; |
| 267 | } |
Oliver Stannard | 9e89d8c | 2014-11-05 12:06:39 +0000 | [diff] [blame] | 268 | bool hasD16() const { |
| 269 | return STI.getFeatureBits() & ARM::FeatureD16; |
| 270 | } |
Tim Northover | a2292d0 | 2013-06-10 23:20:58 +0000 | [diff] [blame] | 271 | |
Evan Cheng | 284b467 | 2011-07-08 22:36:29 +0000 | [diff] [blame] | 272 | void SwitchMode() { |
Tim Northover | 26bb14e | 2014-08-18 11:49:42 +0000 | [diff] [blame] | 273 | uint64_t FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb)); |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 274 | setAvailableFeatures(FB); |
Evan Cheng | 284b467 | 2011-07-08 22:36:29 +0000 | [diff] [blame] | 275 | } |
James Molloy | 21efa7d | 2011-09-28 14:21:38 +0000 | [diff] [blame] | 276 | bool isMClass() const { |
| 277 | return STI.getFeatureBits() & ARM::FeatureMClass; |
| 278 | } |
Evan Cheng | 4d1ca96 | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 279 | |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 280 | /// @name Auto-generated Match Functions |
| 281 | /// { |
Daniel Dunbar | 5cd4d0f | 2010-08-11 05:24:50 +0000 | [diff] [blame] | 282 | |
Chris Lattner | 3e4582a | 2010-09-06 19:11:01 +0000 | [diff] [blame] | 283 | #define GET_ASSEMBLER_HEADER |
| 284 | #include "ARMGenAsmMatcher.inc" |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 285 | |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 286 | /// } |
| 287 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 288 | OperandMatchResultTy parseITCondCode(OperandVector &); |
| 289 | OperandMatchResultTy parseCoprocNumOperand(OperandVector &); |
| 290 | OperandMatchResultTy parseCoprocRegOperand(OperandVector &); |
| 291 | OperandMatchResultTy parseCoprocOptionOperand(OperandVector &); |
| 292 | OperandMatchResultTy parseMemBarrierOptOperand(OperandVector &); |
| 293 | OperandMatchResultTy parseInstSyncBarrierOptOperand(OperandVector &); |
| 294 | OperandMatchResultTy parseProcIFlagsOperand(OperandVector &); |
| 295 | OperandMatchResultTy parseMSRMaskOperand(OperandVector &); |
Tim Northover | ee843ef | 2014-08-15 10:47:12 +0000 | [diff] [blame] | 296 | OperandMatchResultTy parseBankedRegOperand(OperandVector &); |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 297 | OperandMatchResultTy parsePKHImm(OperandVector &O, StringRef Op, int Low, |
| 298 | int High); |
| 299 | OperandMatchResultTy parsePKHLSLImm(OperandVector &O) { |
Jim Grosbach | 27c1e25 | 2011-07-21 17:23:04 +0000 | [diff] [blame] | 300 | return parsePKHImm(O, "lsl", 0, 31); |
| 301 | } |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 302 | OperandMatchResultTy parsePKHASRImm(OperandVector &O) { |
Jim Grosbach | 27c1e25 | 2011-07-21 17:23:04 +0000 | [diff] [blame] | 303 | return parsePKHImm(O, "asr", 1, 32); |
| 304 | } |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 305 | OperandMatchResultTy parseSetEndImm(OperandVector &); |
| 306 | OperandMatchResultTy parseShifterImm(OperandVector &); |
| 307 | OperandMatchResultTy parseRotImm(OperandVector &); |
Asiri Rathnayake | a0199b9 | 2014-12-02 10:53:20 +0000 | [diff] [blame] | 308 | OperandMatchResultTy parseModImm(OperandVector &); |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 309 | OperandMatchResultTy parseBitfield(OperandVector &); |
| 310 | OperandMatchResultTy parsePostIdxReg(OperandVector &); |
| 311 | OperandMatchResultTy parseAM3Offset(OperandVector &); |
| 312 | OperandMatchResultTy parseFPImm(OperandVector &); |
| 313 | OperandMatchResultTy parseVectorList(OperandVector &); |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 314 | OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, |
| 315 | SMLoc &EndLoc); |
Bruno Cardoso Lopes | ab83050 | 2011-03-31 23:26:08 +0000 | [diff] [blame] | 316 | |
| 317 | // Asm Match Converter Methods |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 318 | void cvtThumbMultiply(MCInst &Inst, const OperandVector &); |
| 319 | void cvtThumbBranches(MCInst &Inst, const OperandVector &); |
Saleem Abdulrasool | 4ab6e73 | 2014-02-23 17:45:36 +0000 | [diff] [blame] | 320 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 321 | bool validateInstruction(MCInst &Inst, const OperandVector &Ops); |
Joerg Sonnenberger | 02b13a8 | 2014-11-21 22:39:34 +0000 | [diff] [blame] | 322 | bool processInstruction(MCInst &Inst, const OperandVector &Ops, MCStreamer &Out); |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 323 | bool shouldOmitCCOutOperand(StringRef Mnemonic, OperandVector &Operands); |
| 324 | bool shouldOmitPredicateOperand(StringRef Mnemonic, OperandVector &Operands); |
| 325 | |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 326 | public: |
Jim Grosbach | 3e941ae | 2011-08-16 20:45:50 +0000 | [diff] [blame] | 327 | enum ARMMatchResultTy { |
Jim Grosbach | b7fa2c0 | 2011-08-16 22:20:01 +0000 | [diff] [blame] | 328 | Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY, |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 329 | Match_RequiresNotITBlock, |
Jim Grosbach | b7fa2c0 | 2011-08-16 22:20:01 +0000 | [diff] [blame] | 330 | Match_RequiresV6, |
Jim Grosbach | 087affe | 2012-06-22 23:56:48 +0000 | [diff] [blame] | 331 | Match_RequiresThumb2, |
| 332 | #define GET_OPERAND_DIAGNOSTIC_TYPES |
| 333 | #include "ARMGenAsmMatcher.inc" |
| 334 | |
Jim Grosbach | 3e941ae | 2011-08-16 20:45:50 +0000 | [diff] [blame] | 335 | }; |
| 336 | |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 337 | ARMAsmParser(MCSubtargetInfo & _STI, MCAsmParser & _Parser, |
| 338 | const MCInstrInfo &MII, const MCTargetOptions &Options) |
| 339 | : MCTargetAsmParser(), STI(_STI), MII(MII), UC(_Parser) { |
Evan Cheng | 4d1ca96 | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 340 | MCAsmParserExtension::Initialize(_Parser); |
Evan Cheng | 284b467 | 2011-07-08 22:36:29 +0000 | [diff] [blame] | 341 | |
Jim Grosbach | c988e0c | 2012-03-05 19:33:30 +0000 | [diff] [blame] | 342 | // Cache the MCRegisterInfo. |
Bill Wendling | bc07a89 | 2013-06-18 07:20:20 +0000 | [diff] [blame] | 343 | MRI = getContext().getRegisterInfo(); |
Jim Grosbach | c988e0c | 2012-03-05 19:33:30 +0000 | [diff] [blame] | 344 | |
Evan Cheng | 4d1ca96 | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 345 | // Initialize the set of available features. |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 346 | setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits())); |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 347 | |
| 348 | // Not in an ITBlock to start with. |
| 349 | ITState.CurPosition = ~0U; |
Tim Northover | 1744d0a | 2013-10-25 12:49:50 +0000 | [diff] [blame] | 350 | |
| 351 | NextSymbolIsThumb = false; |
Evan Cheng | 4d1ca96 | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 352 | } |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 353 | |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 354 | // Implementation of the MCTargetAsmParser interface: |
Craig Topper | ca7e3e5 | 2014-03-10 03:19:03 +0000 | [diff] [blame] | 355 | bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc) override; |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 356 | bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name, |
| 357 | SMLoc NameLoc, OperandVector &Operands) override; |
Craig Topper | ca7e3e5 | 2014-03-10 03:19:03 +0000 | [diff] [blame] | 358 | bool ParseDirective(AsmToken DirectiveID) override; |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 359 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 360 | unsigned validateTargetOperandClass(MCParsedAsmOperand &Op, |
Craig Topper | ca7e3e5 | 2014-03-10 03:19:03 +0000 | [diff] [blame] | 361 | unsigned Kind) override; |
| 362 | unsigned checkTargetMatchPredicate(MCInst &Inst) override; |
Jim Grosbach | 3e941ae | 2011-08-16 20:45:50 +0000 | [diff] [blame] | 363 | |
Chad Rosier | 4996355 | 2012-10-13 00:26:04 +0000 | [diff] [blame] | 364 | bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode, |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 365 | OperandVector &Operands, MCStreamer &Out, |
Tim Northover | 26bb14e | 2014-08-18 11:49:42 +0000 | [diff] [blame] | 366 | uint64_t &ErrorInfo, |
Craig Topper | ca7e3e5 | 2014-03-10 03:19:03 +0000 | [diff] [blame] | 367 | bool MatchingInlineAsm) override; |
| 368 | void onLabelParsed(MCSymbol *Symbol) override; |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 369 | }; |
Jim Grosbach | 624bcc7 | 2010-10-29 14:46:02 +0000 | [diff] [blame] | 370 | } // end anonymous namespace |
| 371 | |
Chris Lattner | bd7c9fa | 2010-10-28 17:20:03 +0000 | [diff] [blame] | 372 | namespace { |
| 373 | |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 374 | /// ARMOperand - Instances of this class represent a parsed ARM machine |
Joel Jones | 5459754 | 2013-01-09 22:34:16 +0000 | [diff] [blame] | 375 | /// operand. |
Bill Wendling | ee7f1f9 | 2010-11-06 21:42:12 +0000 | [diff] [blame] | 376 | class ARMOperand : public MCParsedAsmOperand { |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 377 | enum KindTy { |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 378 | k_CondCode, |
| 379 | k_CCOut, |
| 380 | k_ITCondMask, |
| 381 | k_CoprocNum, |
| 382 | k_CoprocReg, |
Jim Grosbach | 4839958 | 2011-10-12 17:34:41 +0000 | [diff] [blame] | 383 | k_CoprocOption, |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 384 | k_Immediate, |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 385 | k_MemBarrierOpt, |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 386 | k_InstSyncBarrierOpt, |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 387 | k_Memory, |
| 388 | k_PostIndexRegister, |
| 389 | k_MSRMask, |
Tim Northover | ee843ef | 2014-08-15 10:47:12 +0000 | [diff] [blame] | 390 | k_BankedReg, |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 391 | k_ProcIFlags, |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 392 | k_VectorIndex, |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 393 | k_Register, |
| 394 | k_RegisterList, |
| 395 | k_DPRRegisterList, |
| 396 | k_SPRRegisterList, |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 397 | k_VectorList, |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 398 | k_VectorListAllLanes, |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 399 | k_VectorListIndexed, |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 400 | k_ShiftedRegister, |
| 401 | k_ShiftedImmediate, |
| 402 | k_ShifterImmediate, |
| 403 | k_RotateImmediate, |
Asiri Rathnayake | a0199b9 | 2014-12-02 10:53:20 +0000 | [diff] [blame] | 404 | k_ModifiedImmediate, |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 405 | k_BitfieldDescriptor, |
| 406 | k_Token |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 407 | } Kind; |
| 408 | |
Kevin Enderby | 488f20b | 2014-04-10 20:18:58 +0000 | [diff] [blame] | 409 | SMLoc StartLoc, EndLoc, AlignmentLoc; |
Bill Wendling | 0ab0f67 | 2010-11-18 21:50:54 +0000 | [diff] [blame] | 410 | SmallVector<unsigned, 8> Registers; |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 411 | |
Eric Christopher | 8996c5d | 2013-03-15 00:42:55 +0000 | [diff] [blame] | 412 | struct CCOp { |
| 413 | ARMCC::CondCodes Val; |
| 414 | }; |
| 415 | |
| 416 | struct CopOp { |
| 417 | unsigned Val; |
| 418 | }; |
| 419 | |
| 420 | struct CoprocOptionOp { |
| 421 | unsigned Val; |
| 422 | }; |
| 423 | |
| 424 | struct ITMaskOp { |
| 425 | unsigned Mask:4; |
| 426 | }; |
| 427 | |
| 428 | struct MBOptOp { |
| 429 | ARM_MB::MemBOpt Val; |
| 430 | }; |
| 431 | |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 432 | struct ISBOptOp { |
| 433 | ARM_ISB::InstSyncBOpt Val; |
| 434 | }; |
| 435 | |
Eric Christopher | 8996c5d | 2013-03-15 00:42:55 +0000 | [diff] [blame] | 436 | struct IFlagsOp { |
| 437 | ARM_PROC::IFlags Val; |
| 438 | }; |
| 439 | |
| 440 | struct MMaskOp { |
| 441 | unsigned Val; |
| 442 | }; |
| 443 | |
Tim Northover | ee843ef | 2014-08-15 10:47:12 +0000 | [diff] [blame] | 444 | struct BankedRegOp { |
| 445 | unsigned Val; |
| 446 | }; |
| 447 | |
Eric Christopher | 8996c5d | 2013-03-15 00:42:55 +0000 | [diff] [blame] | 448 | struct TokOp { |
| 449 | const char *Data; |
| 450 | unsigned Length; |
| 451 | }; |
| 452 | |
| 453 | struct RegOp { |
| 454 | unsigned RegNum; |
| 455 | }; |
| 456 | |
| 457 | // A vector register list is a sequential list of 1 to 4 registers. |
| 458 | struct VectorListOp { |
| 459 | unsigned RegNum; |
| 460 | unsigned Count; |
| 461 | unsigned LaneIndex; |
| 462 | bool isDoubleSpaced; |
| 463 | }; |
| 464 | |
| 465 | struct VectorIndexOp { |
| 466 | unsigned Val; |
| 467 | }; |
| 468 | |
| 469 | struct ImmOp { |
| 470 | const MCExpr *Val; |
| 471 | }; |
| 472 | |
| 473 | /// Combined record for all forms of ARM address expressions. |
| 474 | struct MemoryOp { |
| 475 | unsigned BaseRegNum; |
| 476 | // Offset is in OffsetReg or OffsetImm. If both are zero, no offset |
| 477 | // was specified. |
| 478 | const MCConstantExpr *OffsetImm; // Offset immediate value |
| 479 | unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL |
| 480 | ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg |
| 481 | unsigned ShiftImm; // shift for OffsetReg. |
| 482 | unsigned Alignment; // 0 = no alignment specified |
| 483 | // n = alignment in bytes (2, 4, 8, 16, or 32) |
| 484 | unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit) |
| 485 | }; |
| 486 | |
| 487 | struct PostIdxRegOp { |
| 488 | unsigned RegNum; |
| 489 | bool isAdd; |
| 490 | ARM_AM::ShiftOpc ShiftTy; |
| 491 | unsigned ShiftImm; |
| 492 | }; |
| 493 | |
| 494 | struct ShifterImmOp { |
| 495 | bool isASR; |
| 496 | unsigned Imm; |
| 497 | }; |
| 498 | |
| 499 | struct RegShiftedRegOp { |
| 500 | ARM_AM::ShiftOpc ShiftTy; |
| 501 | unsigned SrcReg; |
| 502 | unsigned ShiftReg; |
| 503 | unsigned ShiftImm; |
| 504 | }; |
| 505 | |
| 506 | struct RegShiftedImmOp { |
| 507 | ARM_AM::ShiftOpc ShiftTy; |
| 508 | unsigned SrcReg; |
| 509 | unsigned ShiftImm; |
| 510 | }; |
| 511 | |
| 512 | struct RotImmOp { |
| 513 | unsigned Imm; |
| 514 | }; |
| 515 | |
Asiri Rathnayake | a0199b9 | 2014-12-02 10:53:20 +0000 | [diff] [blame] | 516 | struct ModImmOp { |
| 517 | unsigned Bits; |
| 518 | unsigned Rot; |
| 519 | }; |
| 520 | |
Eric Christopher | 8996c5d | 2013-03-15 00:42:55 +0000 | [diff] [blame] | 521 | struct BitfieldOp { |
| 522 | unsigned LSB; |
| 523 | unsigned Width; |
| 524 | }; |
| 525 | |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 526 | union { |
Eric Christopher | 8996c5d | 2013-03-15 00:42:55 +0000 | [diff] [blame] | 527 | struct CCOp CC; |
| 528 | struct CopOp Cop; |
| 529 | struct CoprocOptionOp CoprocOption; |
| 530 | struct MBOptOp MBOpt; |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 531 | struct ISBOptOp ISBOpt; |
Eric Christopher | 8996c5d | 2013-03-15 00:42:55 +0000 | [diff] [blame] | 532 | struct ITMaskOp ITMask; |
| 533 | struct IFlagsOp IFlags; |
| 534 | struct MMaskOp MMask; |
Tim Northover | ee843ef | 2014-08-15 10:47:12 +0000 | [diff] [blame] | 535 | struct BankedRegOp BankedReg; |
Eric Christopher | 8996c5d | 2013-03-15 00:42:55 +0000 | [diff] [blame] | 536 | struct TokOp Tok; |
| 537 | struct RegOp Reg; |
| 538 | struct VectorListOp VectorList; |
| 539 | struct VectorIndexOp VectorIndex; |
| 540 | struct ImmOp Imm; |
| 541 | struct MemoryOp Memory; |
| 542 | struct PostIdxRegOp PostIdxReg; |
| 543 | struct ShifterImmOp ShifterImm; |
| 544 | struct RegShiftedRegOp RegShiftedReg; |
| 545 | struct RegShiftedImmOp RegShiftedImm; |
| 546 | struct RotImmOp RotImm; |
Asiri Rathnayake | a0199b9 | 2014-12-02 10:53:20 +0000 | [diff] [blame] | 547 | struct ModImmOp ModImm; |
Eric Christopher | 8996c5d | 2013-03-15 00:42:55 +0000 | [diff] [blame] | 548 | struct BitfieldOp Bitfield; |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 549 | }; |
Jim Grosbach | 624bcc7 | 2010-10-29 14:46:02 +0000 | [diff] [blame] | 550 | |
Bill Wendling | ee7f1f9 | 2010-11-06 21:42:12 +0000 | [diff] [blame] | 551 | public: |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 552 | ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {} |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 553 | ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() { |
| 554 | Kind = o.Kind; |
| 555 | StartLoc = o.StartLoc; |
| 556 | EndLoc = o.EndLoc; |
| 557 | switch (Kind) { |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 558 | case k_CondCode: |
Daniel Dunbar | d8042b7 | 2010-08-11 06:36:53 +0000 | [diff] [blame] | 559 | CC = o.CC; |
| 560 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 561 | case k_ITCondMask: |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 562 | ITMask = o.ITMask; |
| 563 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 564 | case k_Token: |
Daniel Dunbar | d8042b7 | 2010-08-11 06:36:53 +0000 | [diff] [blame] | 565 | Tok = o.Tok; |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 566 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 567 | case k_CCOut: |
| 568 | case k_Register: |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 569 | Reg = o.Reg; |
| 570 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 571 | case k_RegisterList: |
| 572 | case k_DPRRegisterList: |
| 573 | case k_SPRRegisterList: |
Bill Wendling | 0ab0f67 | 2010-11-18 21:50:54 +0000 | [diff] [blame] | 574 | Registers = o.Registers; |
Bill Wendling | 7cef447 | 2010-11-06 19:56:04 +0000 | [diff] [blame] | 575 | break; |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 576 | case k_VectorList: |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 577 | case k_VectorListAllLanes: |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 578 | case k_VectorListIndexed: |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 579 | VectorList = o.VectorList; |
| 580 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 581 | case k_CoprocNum: |
| 582 | case k_CoprocReg: |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 583 | Cop = o.Cop; |
| 584 | break; |
Jim Grosbach | 4839958 | 2011-10-12 17:34:41 +0000 | [diff] [blame] | 585 | case k_CoprocOption: |
| 586 | CoprocOption = o.CoprocOption; |
| 587 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 588 | case k_Immediate: |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 589 | Imm = o.Imm; |
| 590 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 591 | case k_MemBarrierOpt: |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 592 | MBOpt = o.MBOpt; |
| 593 | break; |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 594 | case k_InstSyncBarrierOpt: |
| 595 | ISBOpt = o.ISBOpt; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 596 | case k_Memory: |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 597 | Memory = o.Memory; |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 598 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 599 | case k_PostIndexRegister: |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 600 | PostIdxReg = o.PostIdxReg; |
| 601 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 602 | case k_MSRMask: |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 603 | MMask = o.MMask; |
| 604 | break; |
Tim Northover | ee843ef | 2014-08-15 10:47:12 +0000 | [diff] [blame] | 605 | case k_BankedReg: |
| 606 | BankedReg = o.BankedReg; |
| 607 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 608 | case k_ProcIFlags: |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 609 | IFlags = o.IFlags; |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 610 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 611 | case k_ShifterImmediate: |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 612 | ShifterImm = o.ShifterImm; |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 613 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 614 | case k_ShiftedRegister: |
Jim Grosbach | ac798e1 | 2011-07-25 20:49:51 +0000 | [diff] [blame] | 615 | RegShiftedReg = o.RegShiftedReg; |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 616 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 617 | case k_ShiftedImmediate: |
Jim Grosbach | ac798e1 | 2011-07-25 20:49:51 +0000 | [diff] [blame] | 618 | RegShiftedImm = o.RegShiftedImm; |
Owen Anderson | b595ed0 | 2011-07-21 18:54:16 +0000 | [diff] [blame] | 619 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 620 | case k_RotateImmediate: |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 621 | RotImm = o.RotImm; |
| 622 | break; |
Asiri Rathnayake | a0199b9 | 2014-12-02 10:53:20 +0000 | [diff] [blame] | 623 | case k_ModifiedImmediate: |
| 624 | ModImm = o.ModImm; |
| 625 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 626 | case k_BitfieldDescriptor: |
Jim Grosbach | 864b609 | 2011-07-28 21:34:26 +0000 | [diff] [blame] | 627 | Bitfield = o.Bitfield; |
| 628 | break; |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 629 | case k_VectorIndex: |
| 630 | VectorIndex = o.VectorIndex; |
| 631 | break; |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 632 | } |
| 633 | } |
Jim Grosbach | 624bcc7 | 2010-10-29 14:46:02 +0000 | [diff] [blame] | 634 | |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 635 | /// getStartLoc - Get the location of the first token of this operand. |
Craig Topper | ca7e3e5 | 2014-03-10 03:19:03 +0000 | [diff] [blame] | 636 | SMLoc getStartLoc() const override { return StartLoc; } |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 637 | /// getEndLoc - Get the location of the last token of this operand. |
Craig Topper | ca7e3e5 | 2014-03-10 03:19:03 +0000 | [diff] [blame] | 638 | SMLoc getEndLoc() const override { return EndLoc; } |
Chad Rosier | 143d0f7 | 2012-09-21 20:51:43 +0000 | [diff] [blame] | 639 | /// getLocRange - Get the range between the first and last token of this |
| 640 | /// operand. |
Benjamin Kramer | 673824b | 2012-04-15 17:04:27 +0000 | [diff] [blame] | 641 | SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); } |
| 642 | |
Kevin Enderby | 488f20b | 2014-04-10 20:18:58 +0000 | [diff] [blame] | 643 | /// getAlignmentLoc - Get the location of the Alignment token of this operand. |
| 644 | SMLoc getAlignmentLoc() const { |
| 645 | assert(Kind == k_Memory && "Invalid access!"); |
| 646 | return AlignmentLoc; |
| 647 | } |
| 648 | |
Daniel Dunbar | d8042b7 | 2010-08-11 06:36:53 +0000 | [diff] [blame] | 649 | ARMCC::CondCodes getCondCode() const { |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 650 | assert(Kind == k_CondCode && "Invalid access!"); |
Daniel Dunbar | d8042b7 | 2010-08-11 06:36:53 +0000 | [diff] [blame] | 651 | return CC.Val; |
| 652 | } |
| 653 | |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 654 | unsigned getCoproc() const { |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 655 | assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!"); |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 656 | return Cop.Val; |
| 657 | } |
| 658 | |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 659 | StringRef getToken() const { |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 660 | assert(Kind == k_Token && "Invalid access!"); |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 661 | return StringRef(Tok.Data, Tok.Length); |
| 662 | } |
| 663 | |
Craig Topper | ca7e3e5 | 2014-03-10 03:19:03 +0000 | [diff] [blame] | 664 | unsigned getReg() const override { |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 665 | assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!"); |
Bill Wendling | 2cae327 | 2010-11-09 22:44:22 +0000 | [diff] [blame] | 666 | return Reg.RegNum; |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 667 | } |
| 668 | |
Bill Wendling | bed9465 | 2010-11-09 23:28:44 +0000 | [diff] [blame] | 669 | const SmallVectorImpl<unsigned> &getRegList() const { |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 670 | assert((Kind == k_RegisterList || Kind == k_DPRRegisterList || |
| 671 | Kind == k_SPRRegisterList) && "Invalid access!"); |
Bill Wendling | 0ab0f67 | 2010-11-18 21:50:54 +0000 | [diff] [blame] | 672 | return Registers; |
Bill Wendling | 7cef447 | 2010-11-06 19:56:04 +0000 | [diff] [blame] | 673 | } |
| 674 | |
Kevin Enderby | f507994 | 2009-10-13 22:19:02 +0000 | [diff] [blame] | 675 | const MCExpr *getImm() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 676 | assert(isImm() && "Invalid access!"); |
Kevin Enderby | f507994 | 2009-10-13 22:19:02 +0000 | [diff] [blame] | 677 | return Imm.Val; |
| 678 | } |
| 679 | |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 680 | unsigned getVectorIndex() const { |
| 681 | assert(Kind == k_VectorIndex && "Invalid access!"); |
| 682 | return VectorIndex.Val; |
| 683 | } |
| 684 | |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 685 | ARM_MB::MemBOpt getMemBarrierOpt() const { |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 686 | assert(Kind == k_MemBarrierOpt && "Invalid access!"); |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 687 | return MBOpt.Val; |
| 688 | } |
| 689 | |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 690 | ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const { |
| 691 | assert(Kind == k_InstSyncBarrierOpt && "Invalid access!"); |
| 692 | return ISBOpt.Val; |
| 693 | } |
| 694 | |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 695 | ARM_PROC::IFlags getProcIFlags() const { |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 696 | assert(Kind == k_ProcIFlags && "Invalid access!"); |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 697 | return IFlags.Val; |
| 698 | } |
| 699 | |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 700 | unsigned getMSRMask() const { |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 701 | assert(Kind == k_MSRMask && "Invalid access!"); |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 702 | return MMask.Val; |
| 703 | } |
| 704 | |
Tim Northover | ee843ef | 2014-08-15 10:47:12 +0000 | [diff] [blame] | 705 | unsigned getBankedReg() const { |
| 706 | assert(Kind == k_BankedReg && "Invalid access!"); |
| 707 | return BankedReg.Val; |
| 708 | } |
| 709 | |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 710 | bool isCoprocNum() const { return Kind == k_CoprocNum; } |
| 711 | bool isCoprocReg() const { return Kind == k_CoprocReg; } |
Jim Grosbach | 4839958 | 2011-10-12 17:34:41 +0000 | [diff] [blame] | 712 | bool isCoprocOption() const { return Kind == k_CoprocOption; } |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 713 | bool isCondCode() const { return Kind == k_CondCode; } |
| 714 | bool isCCOut() const { return Kind == k_CCOut; } |
| 715 | bool isITMask() const { return Kind == k_ITCondMask; } |
| 716 | bool isITCondCode() const { return Kind == k_CondCode; } |
Craig Topper | ca7e3e5 | 2014-03-10 03:19:03 +0000 | [diff] [blame] | 717 | bool isImm() const override { return Kind == k_Immediate; } |
Mihai Popa | d36cbaa | 2013-07-03 09:21:44 +0000 | [diff] [blame] | 718 | // checks whether this operand is an unsigned offset which fits is a field |
| 719 | // of specified width and scaled by a specific number of bits |
| 720 | template<unsigned width, unsigned scale> |
| 721 | bool isUnsignedOffset() const { |
| 722 | if (!isImm()) return false; |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 723 | if (isa<MCSymbolRefExpr>(Imm.Val)) return true; |
Mihai Popa | d36cbaa | 2013-07-03 09:21:44 +0000 | [diff] [blame] | 724 | if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) { |
| 725 | int64_t Val = CE->getValue(); |
| 726 | int64_t Align = 1LL << scale; |
| 727 | int64_t Max = Align * ((1LL << width) - 1); |
| 728 | return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max); |
| 729 | } |
| 730 | return false; |
| 731 | } |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 732 | // checks whether this operand is an signed offset which fits is a field |
| 733 | // of specified width and scaled by a specific number of bits |
| 734 | template<unsigned width, unsigned scale> |
| 735 | bool isSignedOffset() const { |
| 736 | if (!isImm()) return false; |
| 737 | if (isa<MCSymbolRefExpr>(Imm.Val)) return true; |
| 738 | if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) { |
| 739 | int64_t Val = CE->getValue(); |
| 740 | int64_t Align = 1LL << scale; |
| 741 | int64_t Max = Align * ((1LL << (width-1)) - 1); |
| 742 | int64_t Min = -Align * (1LL << (width-1)); |
| 743 | return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max); |
| 744 | } |
| 745 | return false; |
| 746 | } |
| 747 | |
Mihai Popa | 8a9da5b | 2013-07-22 15:49:36 +0000 | [diff] [blame] | 748 | // checks whether this operand is a memory operand computed as an offset |
| 749 | // applied to PC. the offset may have 8 bits of magnitude and is represented |
| 750 | // with two bits of shift. textually it may be either [pc, #imm], #imm or |
| 751 | // relocable expression... |
| 752 | bool isThumbMemPC() const { |
| 753 | int64_t Val = 0; |
| 754 | if (isImm()) { |
| 755 | if (isa<MCSymbolRefExpr>(Imm.Val)) return true; |
| 756 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val); |
| 757 | if (!CE) return false; |
| 758 | Val = CE->getValue(); |
| 759 | } |
| 760 | else if (isMem()) { |
| 761 | if(!Memory.OffsetImm || Memory.OffsetRegNum) return false; |
| 762 | if(Memory.BaseRegNum != ARM::PC) return false; |
| 763 | Val = Memory.OffsetImm->getValue(); |
| 764 | } |
| 765 | else return false; |
Mihai Popa | d79f00b | 2013-08-15 15:43:06 +0000 | [diff] [blame] | 766 | return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020); |
Mihai Popa | 8a9da5b | 2013-07-22 15:49:36 +0000 | [diff] [blame] | 767 | } |
Jim Grosbach | a9d36fb | 2012-01-20 18:09:51 +0000 | [diff] [blame] | 768 | bool isFPImm() const { |
| 769 | if (!isImm()) return false; |
| 770 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 771 | if (!CE) return false; |
| 772 | int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue())); |
| 773 | return Val != -1; |
| 774 | } |
Jim Grosbach | ea23191 | 2011-12-22 22:19:05 +0000 | [diff] [blame] | 775 | bool isFBits16() const { |
| 776 | if (!isImm()) return false; |
| 777 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 778 | if (!CE) return false; |
| 779 | int64_t Value = CE->getValue(); |
| 780 | return Value >= 0 && Value <= 16; |
| 781 | } |
| 782 | bool isFBits32() 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 | return Value >= 1 && Value <= 32; |
| 788 | } |
Jim Grosbach | 7db8d69 | 2011-09-08 22:07:06 +0000 | [diff] [blame] | 789 | bool isImm8s4() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 790 | if (!isImm()) return false; |
Jim Grosbach | 7db8d69 | 2011-09-08 22:07:06 +0000 | [diff] [blame] | 791 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 792 | if (!CE) return false; |
| 793 | int64_t Value = CE->getValue(); |
| 794 | return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020; |
| 795 | } |
Jim Grosbach | 0a0b307 | 2011-08-24 21:22:15 +0000 | [diff] [blame] | 796 | bool isImm0_1020s4() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 797 | if (!isImm()) return false; |
Jim Grosbach | 0a0b307 | 2011-08-24 21:22:15 +0000 | [diff] [blame] | 798 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 799 | if (!CE) return false; |
| 800 | int64_t Value = CE->getValue(); |
| 801 | return ((Value & 3) == 0) && Value >= 0 && Value <= 1020; |
| 802 | } |
| 803 | bool isImm0_508s4() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 804 | if (!isImm()) return false; |
Jim Grosbach | 0a0b307 | 2011-08-24 21:22:15 +0000 | [diff] [blame] | 805 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 806 | if (!CE) return false; |
| 807 | int64_t Value = CE->getValue(); |
| 808 | return ((Value & 3) == 0) && Value >= 0 && Value <= 508; |
| 809 | } |
Jim Grosbach | 930f2f6 | 2012-04-05 20:57:13 +0000 | [diff] [blame] | 810 | bool isImm0_508s4Neg() const { |
| 811 | if (!isImm()) return false; |
| 812 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 813 | if (!CE) return false; |
| 814 | int64_t Value = -CE->getValue(); |
| 815 | // explicitly exclude zero. we want that to use the normal 0_508 version. |
| 816 | return ((Value & 3) == 0) && Value > 0 && Value <= 508; |
| 817 | } |
Artyom Skrobov | fc12e70 | 2013-10-23 10:14:40 +0000 | [diff] [blame] | 818 | bool isImm0_239() const { |
| 819 | if (!isImm()) return false; |
| 820 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 821 | if (!CE) return false; |
| 822 | int64_t Value = CE->getValue(); |
| 823 | return Value >= 0 && Value < 240; |
| 824 | } |
Jim Grosbach | a6f7a1e | 2011-06-27 23:54:06 +0000 | [diff] [blame] | 825 | bool isImm0_255() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 826 | if (!isImm()) return false; |
Jim Grosbach | a6f7a1e | 2011-06-27 23:54:06 +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 < 256; |
| 831 | } |
Jim Grosbach | 930f2f6 | 2012-04-05 20:57:13 +0000 | [diff] [blame] | 832 | bool isImm0_4095() const { |
| 833 | if (!isImm()) return false; |
| 834 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 835 | if (!CE) return false; |
| 836 | int64_t Value = CE->getValue(); |
| 837 | return Value >= 0 && Value < 4096; |
| 838 | } |
| 839 | bool isImm0_4095Neg() const { |
| 840 | if (!isImm()) return false; |
| 841 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 842 | if (!CE) return false; |
| 843 | int64_t Value = -CE->getValue(); |
| 844 | return Value > 0 && Value < 4096; |
| 845 | } |
Jim Grosbach | 9dff9f4 | 2011-12-02 23:34:39 +0000 | [diff] [blame] | 846 | bool isImm0_1() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 847 | if (!isImm()) return false; |
Jim Grosbach | 9dff9f4 | 2011-12-02 23:34:39 +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 < 2; |
| 852 | } |
| 853 | bool isImm0_3() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 854 | if (!isImm()) return false; |
Jim Grosbach | 9dff9f4 | 2011-12-02 23:34:39 +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 < 4; |
| 859 | } |
Jim Grosbach | 31756c2 | 2011-07-13 22:01:08 +0000 | [diff] [blame] | 860 | bool isImm0_7() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 861 | if (!isImm()) return false; |
Jim Grosbach | 31756c2 | 2011-07-13 22:01:08 +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 >= 0 && Value < 8; |
| 866 | } |
| 867 | bool isImm0_15() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 868 | if (!isImm()) return false; |
Jim Grosbach | 31756c2 | 2011-07-13 22:01:08 +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 >= 0 && Value < 16; |
| 873 | } |
Jim Grosbach | 72e7c4f | 2011-07-21 23:26:25 +0000 | [diff] [blame] | 874 | bool isImm0_31() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 875 | if (!isImm()) return false; |
Jim Grosbach | 72e7c4f | 2011-07-21 23:26:25 +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 >= 0 && Value < 32; |
| 880 | } |
Jim Grosbach | 0032640 | 2011-12-08 01:30:04 +0000 | [diff] [blame] | 881 | bool isImm0_63() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 882 | if (!isImm()) return false; |
Jim Grosbach | 0032640 | 2011-12-08 01:30:04 +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 < 64; |
| 887 | } |
Jim Grosbach | d4b8249 | 2011-12-07 01:07:24 +0000 | [diff] [blame] | 888 | bool isImm8() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 889 | if (!isImm()) return false; |
Jim Grosbach | d4b8249 | 2011-12-07 01:07:24 +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 == 8; |
| 894 | } |
| 895 | bool isImm16() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 896 | if (!isImm()) return false; |
Jim Grosbach | d4b8249 | 2011-12-07 01:07:24 +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 == 16; |
| 901 | } |
| 902 | bool isImm32() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 903 | if (!isImm()) return false; |
Jim Grosbach | d4b8249 | 2011-12-07 01:07:24 +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 == 32; |
| 908 | } |
Jim Grosbach | ba7d6ed | 2011-12-08 22:06:06 +0000 | [diff] [blame] | 909 | bool isShrImm8() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 910 | if (!isImm()) return false; |
Jim Grosbach | ba7d6ed | 2011-12-08 22:06:06 +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 isShrImm16() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 917 | if (!isImm()) return false; |
Jim Grosbach | ba7d6ed | 2011-12-08 22:06:06 +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 isShrImm32() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 924 | if (!isImm()) return false; |
Jim Grosbach | ba7d6ed | 2011-12-08 22:06:06 +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 | } |
| 930 | bool isShrImm64() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 931 | if (!isImm()) return false; |
Jim Grosbach | ba7d6ed | 2011-12-08 22:06:06 +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 <= 64; |
| 936 | } |
Jim Grosbach | d4b8249 | 2011-12-07 01:07:24 +0000 | [diff] [blame] | 937 | bool isImm1_7() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 938 | if (!isImm()) return false; |
Jim Grosbach | d4b8249 | 2011-12-07 01:07:24 +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 < 8; |
| 943 | } |
| 944 | bool isImm1_15() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 945 | if (!isImm()) return false; |
Jim Grosbach | d4b8249 | 2011-12-07 01:07:24 +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 < 16; |
| 950 | } |
| 951 | bool isImm1_31() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 952 | if (!isImm()) return false; |
Jim Grosbach | d4b8249 | 2011-12-07 01:07:24 +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 < 32; |
| 957 | } |
Jim Grosbach | 475c6db | 2011-07-25 23:09:14 +0000 | [diff] [blame] | 958 | bool isImm1_16() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 959 | if (!isImm()) return false; |
Jim Grosbach | 475c6db | 2011-07-25 23:09:14 +0000 | [diff] [blame] | 960 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 961 | if (!CE) return false; |
| 962 | int64_t Value = CE->getValue(); |
| 963 | return Value > 0 && Value < 17; |
| 964 | } |
Jim Grosbach | 801e0a3 | 2011-07-22 23:16:18 +0000 | [diff] [blame] | 965 | bool isImm1_32() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 966 | if (!isImm()) return false; |
Jim Grosbach | 801e0a3 | 2011-07-22 23:16:18 +0000 | [diff] [blame] | 967 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 968 | if (!CE) return false; |
| 969 | int64_t Value = CE->getValue(); |
| 970 | return Value > 0 && Value < 33; |
| 971 | } |
Jim Grosbach | c14871c | 2011-11-10 19:18:01 +0000 | [diff] [blame] | 972 | bool isImm0_32() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 973 | if (!isImm()) return false; |
Jim Grosbach | c14871c | 2011-11-10 19:18:01 +0000 | [diff] [blame] | 974 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 975 | if (!CE) return false; |
| 976 | int64_t Value = CE->getValue(); |
| 977 | return Value >= 0 && Value < 33; |
| 978 | } |
Jim Grosbach | 975b641 | 2011-07-13 20:10:10 +0000 | [diff] [blame] | 979 | bool isImm0_65535() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 980 | if (!isImm()) return false; |
Jim Grosbach | 975b641 | 2011-07-13 20:10:10 +0000 | [diff] [blame] | 981 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 982 | if (!CE) return false; |
| 983 | int64_t Value = CE->getValue(); |
| 984 | return Value >= 0 && Value < 65536; |
| 985 | } |
Mihai Popa | ae1112b | 2013-08-21 13:14:58 +0000 | [diff] [blame] | 986 | bool isImm256_65535Expr() const { |
| 987 | if (!isImm()) return false; |
| 988 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 989 | // If it's not a constant expression, it'll generate a fixup and be |
| 990 | // handled later. |
| 991 | if (!CE) return true; |
| 992 | int64_t Value = CE->getValue(); |
| 993 | return Value >= 256 && Value < 65536; |
| 994 | } |
Jim Grosbach | 7c09e3c | 2011-07-19 19:13:28 +0000 | [diff] [blame] | 995 | bool isImm0_65535Expr() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 996 | if (!isImm()) return false; |
Jim Grosbach | 7c09e3c | 2011-07-19 19:13:28 +0000 | [diff] [blame] | 997 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 998 | // If it's not a constant expression, it'll generate a fixup and be |
| 999 | // handled later. |
| 1000 | if (!CE) return true; |
| 1001 | int64_t Value = CE->getValue(); |
| 1002 | return Value >= 0 && Value < 65536; |
| 1003 | } |
Jim Grosbach | f163784 | 2011-07-26 16:24:27 +0000 | [diff] [blame] | 1004 | bool isImm24bit() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1005 | if (!isImm()) return false; |
Jim Grosbach | f163784 | 2011-07-26 16:24:27 +0000 | [diff] [blame] | 1006 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1007 | if (!CE) return false; |
| 1008 | int64_t Value = CE->getValue(); |
| 1009 | return Value >= 0 && Value <= 0xffffff; |
| 1010 | } |
Jim Grosbach | 46dd413 | 2011-08-17 21:51:27 +0000 | [diff] [blame] | 1011 | bool isImmThumbSR() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1012 | if (!isImm()) return false; |
Jim Grosbach | 46dd413 | 2011-08-17 21:51:27 +0000 | [diff] [blame] | 1013 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1014 | if (!CE) return false; |
| 1015 | int64_t Value = CE->getValue(); |
| 1016 | return Value > 0 && Value < 33; |
| 1017 | } |
Jim Grosbach | 27c1e25 | 2011-07-21 17:23:04 +0000 | [diff] [blame] | 1018 | bool isPKHLSLImm() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1019 | if (!isImm()) return false; |
Jim Grosbach | 27c1e25 | 2011-07-21 17:23:04 +0000 | [diff] [blame] | 1020 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1021 | if (!CE) return false; |
| 1022 | int64_t Value = CE->getValue(); |
| 1023 | return Value >= 0 && Value < 32; |
| 1024 | } |
| 1025 | bool isPKHASRImm() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1026 | if (!isImm()) return false; |
Jim Grosbach | 27c1e25 | 2011-07-21 17:23:04 +0000 | [diff] [blame] | 1027 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1028 | if (!CE) return false; |
| 1029 | int64_t Value = CE->getValue(); |
| 1030 | return Value > 0 && Value <= 32; |
| 1031 | } |
Jiangning Liu | 10dd40e | 2012-08-02 08:13:13 +0000 | [diff] [blame] | 1032 | bool isAdrLabel() const { |
| 1033 | // If we have an immediate that's not a constant, treat it as a label |
| 1034 | // reference needing a fixup. If it is a constant, but it can't fit |
| 1035 | // into shift immediate encoding, we reject it. |
| 1036 | if (isImm() && !isa<MCConstantExpr>(getImm())) return true; |
| 1037 | else return (isARMSOImm() || isARMSOImmNeg()); |
| 1038 | } |
Jim Grosbach | 9720dcf | 2011-07-19 16:50:30 +0000 | [diff] [blame] | 1039 | bool isARMSOImm() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1040 | if (!isImm()) return false; |
Jim Grosbach | 9720dcf | 2011-07-19 16:50:30 +0000 | [diff] [blame] | 1041 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1042 | if (!CE) return false; |
| 1043 | int64_t Value = CE->getValue(); |
| 1044 | return ARM_AM::getSOImmVal(Value) != -1; |
| 1045 | } |
Jim Grosbach | 3d785ed | 2011-10-28 22:50:54 +0000 | [diff] [blame] | 1046 | bool isARMSOImmNot() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1047 | if (!isImm()) return false; |
Jim Grosbach | 3d785ed | 2011-10-28 22:50:54 +0000 | [diff] [blame] | 1048 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1049 | if (!CE) return false; |
| 1050 | int64_t Value = CE->getValue(); |
| 1051 | return ARM_AM::getSOImmVal(~Value) != -1; |
| 1052 | } |
Jim Grosbach | 3050625 | 2011-12-08 00:31:07 +0000 | [diff] [blame] | 1053 | bool isARMSOImmNeg() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1054 | if (!isImm()) return false; |
Jim Grosbach | 3050625 | 2011-12-08 00:31:07 +0000 | [diff] [blame] | 1055 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1056 | if (!CE) return false; |
| 1057 | int64_t Value = CE->getValue(); |
Jim Grosbach | fdaab53 | 2012-03-30 19:59:02 +0000 | [diff] [blame] | 1058 | // Only use this when not representable as a plain so_imm. |
| 1059 | return ARM_AM::getSOImmVal(Value) == -1 && |
| 1060 | ARM_AM::getSOImmVal(-Value) != -1; |
Jim Grosbach | 3050625 | 2011-12-08 00:31:07 +0000 | [diff] [blame] | 1061 | } |
Jim Grosbach | a6f7a1e | 2011-06-27 23:54:06 +0000 | [diff] [blame] | 1062 | bool isT2SOImm() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1063 | if (!isImm()) return false; |
Jim Grosbach | a6f7a1e | 2011-06-27 23:54:06 +0000 | [diff] [blame] | 1064 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1065 | if (!CE) return false; |
| 1066 | int64_t Value = CE->getValue(); |
| 1067 | return ARM_AM::getT2SOImmVal(Value) != -1; |
| 1068 | } |
Jim Grosbach | b009a87 | 2011-10-28 22:36:30 +0000 | [diff] [blame] | 1069 | bool isT2SOImmNot() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1070 | if (!isImm()) return false; |
Jim Grosbach | b009a87 | 2011-10-28 22:36:30 +0000 | [diff] [blame] | 1071 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1072 | if (!CE) return false; |
| 1073 | int64_t Value = CE->getValue(); |
Mihai Popa | cf276b2 | 2013-08-16 11:55:44 +0000 | [diff] [blame] | 1074 | return ARM_AM::getT2SOImmVal(Value) == -1 && |
| 1075 | ARM_AM::getT2SOImmVal(~Value) != -1; |
Jim Grosbach | b009a87 | 2011-10-28 22:36:30 +0000 | [diff] [blame] | 1076 | } |
Jim Grosbach | 3050625 | 2011-12-08 00:31:07 +0000 | [diff] [blame] | 1077 | bool isT2SOImmNeg() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1078 | if (!isImm()) return false; |
Jim Grosbach | 3050625 | 2011-12-08 00:31:07 +0000 | [diff] [blame] | 1079 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1080 | if (!CE) return false; |
| 1081 | int64_t Value = CE->getValue(); |
Jim Grosbach | fdaab53 | 2012-03-30 19:59:02 +0000 | [diff] [blame] | 1082 | // Only use this when not representable as a plain so_imm. |
| 1083 | return ARM_AM::getT2SOImmVal(Value) == -1 && |
| 1084 | ARM_AM::getT2SOImmVal(-Value) != -1; |
Jim Grosbach | 3050625 | 2011-12-08 00:31:07 +0000 | [diff] [blame] | 1085 | } |
Jim Grosbach | 0a54770 | 2011-07-22 17:44:50 +0000 | [diff] [blame] | 1086 | bool isSetEndImm() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1087 | if (!isImm()) return false; |
Jim Grosbach | 0a54770 | 2011-07-22 17:44:50 +0000 | [diff] [blame] | 1088 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1089 | if (!CE) return false; |
| 1090 | int64_t Value = CE->getValue(); |
| 1091 | return Value == 1 || Value == 0; |
| 1092 | } |
Craig Topper | ca7e3e5 | 2014-03-10 03:19:03 +0000 | [diff] [blame] | 1093 | bool isReg() const override { return Kind == k_Register; } |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 1094 | bool isRegList() const { return Kind == k_RegisterList; } |
| 1095 | bool isDPRRegList() const { return Kind == k_DPRRegisterList; } |
| 1096 | bool isSPRRegList() const { return Kind == k_SPRRegisterList; } |
Craig Topper | ca7e3e5 | 2014-03-10 03:19:03 +0000 | [diff] [blame] | 1097 | bool isToken() const override { return Kind == k_Token; } |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 1098 | bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; } |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 1099 | bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; } |
Craig Topper | ca7e3e5 | 2014-03-10 03:19:03 +0000 | [diff] [blame] | 1100 | bool isMem() const override { return Kind == k_Memory; } |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 1101 | bool isShifterImm() const { return Kind == k_ShifterImmediate; } |
| 1102 | bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; } |
| 1103 | bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; } |
| 1104 | bool isRotImm() const { return Kind == k_RotateImmediate; } |
Asiri Rathnayake | a0199b9 | 2014-12-02 10:53:20 +0000 | [diff] [blame] | 1105 | bool isModImm() const { return Kind == k_ModifiedImmediate; } |
| 1106 | bool isModImmNot() const { |
| 1107 | if (!isImm()) return false; |
| 1108 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1109 | if (!CE) return false; |
| 1110 | int64_t Value = CE->getValue(); |
| 1111 | return ARM_AM::getSOImmVal(~Value) != -1; |
| 1112 | } |
| 1113 | bool isModImmNeg() const { |
| 1114 | if (!isImm()) return false; |
| 1115 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1116 | if (!CE) return false; |
| 1117 | int64_t Value = CE->getValue(); |
| 1118 | return ARM_AM::getSOImmVal(Value) == -1 && |
| 1119 | ARM_AM::getSOImmVal(-Value) != -1; |
| 1120 | } |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 1121 | bool isBitfield() const { return Kind == k_BitfieldDescriptor; } |
| 1122 | bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; } |
Jim Grosbach | c320c85 | 2011-08-05 21:28:30 +0000 | [diff] [blame] | 1123 | bool isPostIdxReg() const { |
Jim Grosbach | ee201fa | 2011-11-14 17:52:47 +0000 | [diff] [blame] | 1124 | return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift; |
Jim Grosbach | c320c85 | 2011-08-05 21:28:30 +0000 | [diff] [blame] | 1125 | } |
Kevin Enderby | 488f20b | 2014-04-10 20:18:58 +0000 | [diff] [blame] | 1126 | bool isMemNoOffset(bool alignOK = false, unsigned Alignment = 0) const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1127 | if (!isMem()) |
Bruno Cardoso Lopes | ab83050 | 2011-03-31 23:26:08 +0000 | [diff] [blame] | 1128 | return false; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1129 | // No offset of any kind. |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1130 | return Memory.OffsetRegNum == 0 && Memory.OffsetImm == nullptr && |
Kevin Enderby | 488f20b | 2014-04-10 20:18:58 +0000 | [diff] [blame] | 1131 | (alignOK || Memory.Alignment == Alignment); |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 1132 | } |
Jim Grosbach | 94298a9 | 2012-01-18 22:46:46 +0000 | [diff] [blame] | 1133 | bool isMemPCRelImm12() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1134 | if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) |
Jim Grosbach | 94298a9 | 2012-01-18 22:46:46 +0000 | [diff] [blame] | 1135 | return false; |
| 1136 | // Base register must be PC. |
| 1137 | if (Memory.BaseRegNum != ARM::PC) |
| 1138 | return false; |
| 1139 | // Immediate offset in range [-4095, 4095]. |
| 1140 | if (!Memory.OffsetImm) return true; |
| 1141 | int64_t Val = Memory.OffsetImm->getValue(); |
| 1142 | return (Val > -4096 && Val < 4096) || (Val == INT32_MIN); |
| 1143 | } |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 1144 | bool isAlignedMemory() const { |
| 1145 | return isMemNoOffset(true); |
Bruno Cardoso Lopes | ab83050 | 2011-03-31 23:26:08 +0000 | [diff] [blame] | 1146 | } |
Kevin Enderby | 488f20b | 2014-04-10 20:18:58 +0000 | [diff] [blame] | 1147 | bool isAlignedMemoryNone() const { |
| 1148 | return isMemNoOffset(false, 0); |
| 1149 | } |
| 1150 | bool isDupAlignedMemoryNone() const { |
| 1151 | return isMemNoOffset(false, 0); |
| 1152 | } |
| 1153 | bool isAlignedMemory16() const { |
| 1154 | if (isMemNoOffset(false, 2)) // alignment in bytes for 16-bits is 2. |
| 1155 | return true; |
| 1156 | return isMemNoOffset(false, 0); |
| 1157 | } |
| 1158 | bool isDupAlignedMemory16() const { |
| 1159 | if (isMemNoOffset(false, 2)) // alignment in bytes for 16-bits is 2. |
| 1160 | return true; |
| 1161 | return isMemNoOffset(false, 0); |
| 1162 | } |
| 1163 | bool isAlignedMemory32() const { |
| 1164 | if (isMemNoOffset(false, 4)) // alignment in bytes for 32-bits is 4. |
| 1165 | return true; |
| 1166 | return isMemNoOffset(false, 0); |
| 1167 | } |
| 1168 | bool isDupAlignedMemory32() const { |
| 1169 | if (isMemNoOffset(false, 4)) // alignment in bytes for 32-bits is 4. |
| 1170 | return true; |
| 1171 | return isMemNoOffset(false, 0); |
| 1172 | } |
| 1173 | bool isAlignedMemory64() const { |
| 1174 | if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8. |
| 1175 | return true; |
| 1176 | return isMemNoOffset(false, 0); |
| 1177 | } |
| 1178 | bool isDupAlignedMemory64() const { |
| 1179 | if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8. |
| 1180 | return true; |
| 1181 | return isMemNoOffset(false, 0); |
| 1182 | } |
| 1183 | bool isAlignedMemory64or128() const { |
| 1184 | if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8. |
| 1185 | return true; |
| 1186 | if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16. |
| 1187 | return true; |
| 1188 | return isMemNoOffset(false, 0); |
| 1189 | } |
| 1190 | bool isDupAlignedMemory64or128() const { |
| 1191 | if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8. |
| 1192 | return true; |
| 1193 | if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16. |
| 1194 | return true; |
| 1195 | return isMemNoOffset(false, 0); |
| 1196 | } |
| 1197 | bool isAlignedMemory64or128or256() const { |
| 1198 | if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8. |
| 1199 | return true; |
| 1200 | if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16. |
| 1201 | return true; |
| 1202 | if (isMemNoOffset(false, 32)) // alignment in bytes for 256-bits is 32. |
| 1203 | return true; |
| 1204 | return isMemNoOffset(false, 0); |
| 1205 | } |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1206 | bool isAddrMode2() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1207 | if (!isMem() || Memory.Alignment != 0) return false; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1208 | // Check for register offset. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1209 | if (Memory.OffsetRegNum) return true; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1210 | // Immediate offset in range [-4095, 4095]. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1211 | if (!Memory.OffsetImm) return true; |
| 1212 | int64_t Val = Memory.OffsetImm->getValue(); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1213 | return Val > -4096 && Val < 4096; |
Bruno Cardoso Lopes | bda3632 | 2011-04-04 17:18:19 +0000 | [diff] [blame] | 1214 | } |
Jim Grosbach | cd17c12 | 2011-08-04 23:01:30 +0000 | [diff] [blame] | 1215 | bool isAM2OffsetImm() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1216 | if (!isImm()) return false; |
Jim Grosbach | cd17c12 | 2011-08-04 23:01:30 +0000 | [diff] [blame] | 1217 | // Immediate offset in range [-4095, 4095]. |
| 1218 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1219 | if (!CE) return false; |
| 1220 | int64_t Val = CE->getValue(); |
Mihai Popa | c1d119e | 2013-06-11 09:48:35 +0000 | [diff] [blame] | 1221 | return (Val == INT32_MIN) || (Val > -4096 && Val < 4096); |
Jim Grosbach | cd17c12 | 2011-08-04 23:01:30 +0000 | [diff] [blame] | 1222 | } |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 1223 | bool isAddrMode3() const { |
Jim Grosbach | 8648c10 | 2011-12-19 23:06:24 +0000 | [diff] [blame] | 1224 | // If we have an immediate that's not a constant, treat it as a label |
| 1225 | // reference needing a fixup. If it is a constant, it's something else |
| 1226 | // and we reject it. |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1227 | if (isImm() && !isa<MCConstantExpr>(getImm())) |
Jim Grosbach | 8648c10 | 2011-12-19 23:06:24 +0000 | [diff] [blame] | 1228 | return true; |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1229 | if (!isMem() || Memory.Alignment != 0) return false; |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 1230 | // No shifts are legal for AM3. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1231 | if (Memory.ShiftType != ARM_AM::no_shift) return false; |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 1232 | // Check for register offset. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1233 | if (Memory.OffsetRegNum) return true; |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 1234 | // Immediate offset in range [-255, 255]. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1235 | if (!Memory.OffsetImm) return true; |
| 1236 | int64_t Val = Memory.OffsetImm->getValue(); |
Silviu Baranga | 5a719f9 | 2012-05-11 09:10:54 +0000 | [diff] [blame] | 1237 | // The #-0 offset is encoded as INT32_MIN, and we have to check |
| 1238 | // for this too. |
| 1239 | return (Val > -256 && Val < 256) || Val == INT32_MIN; |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 1240 | } |
| 1241 | bool isAM3Offset() const { |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 1242 | if (Kind != k_Immediate && Kind != k_PostIndexRegister) |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 1243 | return false; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 1244 | if (Kind == k_PostIndexRegister) |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 1245 | return PostIdxReg.ShiftTy == ARM_AM::no_shift; |
| 1246 | // Immediate offset in range [-255, 255]. |
| 1247 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1248 | if (!CE) return false; |
| 1249 | int64_t Val = CE->getValue(); |
Jim Grosbach | 1d9d5e9 | 2011-08-10 21:56:18 +0000 | [diff] [blame] | 1250 | // Special case, #-0 is INT32_MIN. |
| 1251 | return (Val > -256 && Val < 256) || Val == INT32_MIN; |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 1252 | } |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1253 | bool isAddrMode5() const { |
Jim Grosbach | fb2f1d6 | 2011-11-01 01:24:45 +0000 | [diff] [blame] | 1254 | // If we have an immediate that's not a constant, treat it as a label |
| 1255 | // reference needing a fixup. If it is a constant, it's something else |
| 1256 | // and we reject it. |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1257 | if (isImm() && !isa<MCConstantExpr>(getImm())) |
Jim Grosbach | fb2f1d6 | 2011-11-01 01:24:45 +0000 | [diff] [blame] | 1258 | return true; |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1259 | if (!isMem() || Memory.Alignment != 0) return false; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1260 | // Check for register offset. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1261 | if (Memory.OffsetRegNum) return false; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1262 | // Immediate offset in range [-1020, 1020] and a multiple of 4. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1263 | if (!Memory.OffsetImm) return true; |
| 1264 | int64_t Val = Memory.OffsetImm->getValue(); |
Owen Anderson | 967674d | 2011-08-29 19:36:44 +0000 | [diff] [blame] | 1265 | return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) || |
Jim Grosbach | fb2f1d6 | 2011-11-01 01:24:45 +0000 | [diff] [blame] | 1266 | Val == INT32_MIN; |
Bill Wendling | 8d2aa03 | 2010-11-08 23:49:57 +0000 | [diff] [blame] | 1267 | } |
Jim Grosbach | 05541f4 | 2011-09-19 22:21:13 +0000 | [diff] [blame] | 1268 | bool isMemTBB() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1269 | if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative || |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 1270 | Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0) |
Jim Grosbach | 05541f4 | 2011-09-19 22:21:13 +0000 | [diff] [blame] | 1271 | return false; |
| 1272 | return true; |
| 1273 | } |
| 1274 | bool isMemTBH() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1275 | if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative || |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 1276 | Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 || |
| 1277 | Memory.Alignment != 0 ) |
Jim Grosbach | 05541f4 | 2011-09-19 22:21:13 +0000 | [diff] [blame] | 1278 | return false; |
| 1279 | return true; |
| 1280 | } |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1281 | bool isMemRegOffset() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1282 | if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0) |
Bill Wendling | 092a7bd | 2010-12-14 03:36:38 +0000 | [diff] [blame] | 1283 | return false; |
Daniel Dunbar | 7ed4559 | 2011-01-18 05:34:11 +0000 | [diff] [blame] | 1284 | return true; |
Bill Wendling | 092a7bd | 2010-12-14 03:36:38 +0000 | [diff] [blame] | 1285 | } |
Jim Grosbach | e0ebc1c | 2011-09-07 23:10:15 +0000 | [diff] [blame] | 1286 | bool isT2MemRegOffset() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1287 | if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative || |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 1288 | Memory.Alignment != 0) |
Jim Grosbach | e0ebc1c | 2011-09-07 23:10:15 +0000 | [diff] [blame] | 1289 | return false; |
| 1290 | // Only lsl #{0, 1, 2, 3} allowed. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1291 | if (Memory.ShiftType == ARM_AM::no_shift) |
Jim Grosbach | e0ebc1c | 2011-09-07 23:10:15 +0000 | [diff] [blame] | 1292 | return true; |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1293 | if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3) |
Jim Grosbach | e0ebc1c | 2011-09-07 23:10:15 +0000 | [diff] [blame] | 1294 | return false; |
| 1295 | return true; |
| 1296 | } |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1297 | bool isMemThumbRR() const { |
| 1298 | // Thumb reg+reg addressing is simple. Just two registers, a base and |
| 1299 | // an offset. No shifts, negations or any other complicating factors. |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1300 | if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative || |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 1301 | Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0) |
Bill Wendling | 811c936 | 2010-11-30 07:44:32 +0000 | [diff] [blame] | 1302 | return false; |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1303 | return isARMLowRegister(Memory.BaseRegNum) && |
| 1304 | (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum)); |
Jim Grosbach | 3fe94e3 | 2011-08-19 17:55:24 +0000 | [diff] [blame] | 1305 | } |
| 1306 | bool isMemThumbRIs4() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1307 | if (!isMem() || Memory.OffsetRegNum != 0 || |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 1308 | !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0) |
Jim Grosbach | 3fe94e3 | 2011-08-19 17:55:24 +0000 | [diff] [blame] | 1309 | return false; |
| 1310 | // Immediate offset, multiple of 4 in range [0, 124]. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1311 | if (!Memory.OffsetImm) return true; |
| 1312 | int64_t Val = Memory.OffsetImm->getValue(); |
Jim Grosbach | 23983d6 | 2011-08-19 18:13:48 +0000 | [diff] [blame] | 1313 | return Val >= 0 && Val <= 124 && (Val % 4) == 0; |
| 1314 | } |
Jim Grosbach | 26d3587 | 2011-08-19 18:55:51 +0000 | [diff] [blame] | 1315 | bool isMemThumbRIs2() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1316 | if (!isMem() || Memory.OffsetRegNum != 0 || |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 1317 | !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0) |
Jim Grosbach | 26d3587 | 2011-08-19 18:55:51 +0000 | [diff] [blame] | 1318 | return false; |
| 1319 | // Immediate offset, multiple of 4 in range [0, 62]. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1320 | if (!Memory.OffsetImm) return true; |
| 1321 | int64_t Val = Memory.OffsetImm->getValue(); |
Jim Grosbach | 26d3587 | 2011-08-19 18:55:51 +0000 | [diff] [blame] | 1322 | return Val >= 0 && Val <= 62 && (Val % 2) == 0; |
| 1323 | } |
Jim Grosbach | a32c753 | 2011-08-19 18:49:59 +0000 | [diff] [blame] | 1324 | bool isMemThumbRIs1() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1325 | if (!isMem() || Memory.OffsetRegNum != 0 || |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 1326 | !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0) |
Jim Grosbach | a32c753 | 2011-08-19 18:49:59 +0000 | [diff] [blame] | 1327 | return false; |
| 1328 | // Immediate offset in range [0, 31]. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1329 | if (!Memory.OffsetImm) return true; |
| 1330 | int64_t Val = Memory.OffsetImm->getValue(); |
Jim Grosbach | a32c753 | 2011-08-19 18:49:59 +0000 | [diff] [blame] | 1331 | return Val >= 0 && Val <= 31; |
| 1332 | } |
Jim Grosbach | 23983d6 | 2011-08-19 18:13:48 +0000 | [diff] [blame] | 1333 | bool isMemThumbSPI() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1334 | if (!isMem() || Memory.OffsetRegNum != 0 || |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 1335 | Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0) |
Jim Grosbach | 23983d6 | 2011-08-19 18:13:48 +0000 | [diff] [blame] | 1336 | return false; |
| 1337 | // Immediate offset, multiple of 4 in range [0, 1020]. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1338 | if (!Memory.OffsetImm) return true; |
| 1339 | int64_t Val = Memory.OffsetImm->getValue(); |
Jim Grosbach | 23983d6 | 2011-08-19 18:13:48 +0000 | [diff] [blame] | 1340 | return Val >= 0 && Val <= 1020 && (Val % 4) == 0; |
Bill Wendling | 811c936 | 2010-11-30 07:44:32 +0000 | [diff] [blame] | 1341 | } |
Jim Grosbach | 7db8d69 | 2011-09-08 22:07:06 +0000 | [diff] [blame] | 1342 | bool isMemImm8s4Offset() const { |
Jim Grosbach | 8648c10 | 2011-12-19 23:06:24 +0000 | [diff] [blame] | 1343 | // If we have an immediate that's not a constant, treat it as a label |
| 1344 | // reference needing a fixup. If it is a constant, it's something else |
| 1345 | // and we reject it. |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1346 | if (isImm() && !isa<MCConstantExpr>(getImm())) |
Jim Grosbach | 8648c10 | 2011-12-19 23:06:24 +0000 | [diff] [blame] | 1347 | return true; |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1348 | if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) |
Jim Grosbach | 7db8d69 | 2011-09-08 22:07:06 +0000 | [diff] [blame] | 1349 | return false; |
| 1350 | // Immediate offset a multiple of 4 in range [-1020, 1020]. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1351 | if (!Memory.OffsetImm) return true; |
| 1352 | int64_t Val = Memory.OffsetImm->getValue(); |
Jiangning Liu | 6a43bf7 | 2012-08-02 08:29:50 +0000 | [diff] [blame] | 1353 | // Special case, #-0 is INT32_MIN. |
| 1354 | return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN; |
Jim Grosbach | 7db8d69 | 2011-09-08 22:07:06 +0000 | [diff] [blame] | 1355 | } |
Jim Grosbach | a05627e | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 1356 | bool isMemImm0_1020s4Offset() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1357 | if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) |
Jim Grosbach | a05627e | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 1358 | return false; |
| 1359 | // Immediate offset a multiple of 4 in range [0, 1020]. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1360 | if (!Memory.OffsetImm) return true; |
| 1361 | int64_t Val = Memory.OffsetImm->getValue(); |
Jim Grosbach | a05627e | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 1362 | return Val >= 0 && Val <= 1020 && (Val & 3) == 0; |
| 1363 | } |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1364 | bool isMemImm8Offset() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1365 | if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1366 | return false; |
Jim Grosbach | 94298a9 | 2012-01-18 22:46:46 +0000 | [diff] [blame] | 1367 | // Base reg of PC isn't allowed for these encodings. |
| 1368 | if (Memory.BaseRegNum == ARM::PC) return false; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1369 | // Immediate offset in range [-255, 255]. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1370 | if (!Memory.OffsetImm) return true; |
| 1371 | int64_t Val = Memory.OffsetImm->getValue(); |
Owen Anderson | 4916840 | 2011-09-23 22:25:02 +0000 | [diff] [blame] | 1372 | return (Val == INT32_MIN) || (Val > -256 && Val < 256); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1373 | } |
Jim Grosbach | 2392c53 | 2011-09-07 23:39:14 +0000 | [diff] [blame] | 1374 | bool isMemPosImm8Offset() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1375 | if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) |
Jim Grosbach | 2392c53 | 2011-09-07 23:39:14 +0000 | [diff] [blame] | 1376 | return false; |
| 1377 | // Immediate offset in range [0, 255]. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1378 | if (!Memory.OffsetImm) return true; |
| 1379 | int64_t Val = Memory.OffsetImm->getValue(); |
Jim Grosbach | 2392c53 | 2011-09-07 23:39:14 +0000 | [diff] [blame] | 1380 | return Val >= 0 && Val < 256; |
| 1381 | } |
Jim Grosbach | 5bfa8ba | 2011-09-07 20:58:57 +0000 | [diff] [blame] | 1382 | bool isMemNegImm8Offset() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1383 | if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) |
Jim Grosbach | 5bfa8ba | 2011-09-07 20:58:57 +0000 | [diff] [blame] | 1384 | return false; |
Jim Grosbach | 94298a9 | 2012-01-18 22:46:46 +0000 | [diff] [blame] | 1385 | // Base reg of PC isn't allowed for these encodings. |
| 1386 | if (Memory.BaseRegNum == ARM::PC) return false; |
Jim Grosbach | 5bfa8ba | 2011-09-07 20:58:57 +0000 | [diff] [blame] | 1387 | // Immediate offset in range [-255, -1]. |
Jim Grosbach | 175c7d0 | 2011-12-06 04:49:29 +0000 | [diff] [blame] | 1388 | if (!Memory.OffsetImm) return false; |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1389 | int64_t Val = Memory.OffsetImm->getValue(); |
Jim Grosbach | 175c7d0 | 2011-12-06 04:49:29 +0000 | [diff] [blame] | 1390 | return (Val == INT32_MIN) || (Val > -256 && Val < 0); |
Jim Grosbach | 5bfa8ba | 2011-09-07 20:58:57 +0000 | [diff] [blame] | 1391 | } |
| 1392 | bool isMemUImm12Offset() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1393 | if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) |
Jim Grosbach | 5bfa8ba | 2011-09-07 20:58:57 +0000 | [diff] [blame] | 1394 | return false; |
| 1395 | // Immediate offset in range [0, 4095]. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1396 | if (!Memory.OffsetImm) return true; |
| 1397 | int64_t Val = Memory.OffsetImm->getValue(); |
Jim Grosbach | 5bfa8ba | 2011-09-07 20:58:57 +0000 | [diff] [blame] | 1398 | return (Val >= 0 && Val < 4096); |
| 1399 | } |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1400 | bool isMemImm12Offset() const { |
Jim Grosbach | 95466ce | 2011-08-08 20:59:31 +0000 | [diff] [blame] | 1401 | // If we have an immediate that's not a constant, treat it as a label |
| 1402 | // reference needing a fixup. If it is a constant, it's something else |
| 1403 | // and we reject it. |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1404 | if (isImm() && !isa<MCConstantExpr>(getImm())) |
Jim Grosbach | 95466ce | 2011-08-08 20:59:31 +0000 | [diff] [blame] | 1405 | return true; |
| 1406 | |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1407 | if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1408 | return false; |
| 1409 | // Immediate offset in range [-4095, 4095]. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1410 | if (!Memory.OffsetImm) return true; |
| 1411 | int64_t Val = Memory.OffsetImm->getValue(); |
Owen Anderson | 967674d | 2011-08-29 19:36:44 +0000 | [diff] [blame] | 1412 | return (Val > -4096 && Val < 4096) || (Val == INT32_MIN); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1413 | } |
| 1414 | bool isPostIdxImm8() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1415 | if (!isImm()) return false; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1416 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1417 | if (!CE) return false; |
| 1418 | int64_t Val = CE->getValue(); |
Owen Anderson | f02d98d | 2011-08-29 17:17:09 +0000 | [diff] [blame] | 1419 | return (Val > -256 && Val < 256) || (Val == INT32_MIN); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1420 | } |
Jim Grosbach | 9398141 | 2011-10-11 21:55:36 +0000 | [diff] [blame] | 1421 | bool isPostIdxImm8s4() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1422 | if (!isImm()) return false; |
Jim Grosbach | 9398141 | 2011-10-11 21:55:36 +0000 | [diff] [blame] | 1423 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1424 | if (!CE) return false; |
| 1425 | int64_t Val = CE->getValue(); |
| 1426 | return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) || |
| 1427 | (Val == INT32_MIN); |
| 1428 | } |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1429 | |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 1430 | bool isMSRMask() const { return Kind == k_MSRMask; } |
Tim Northover | ee843ef | 2014-08-15 10:47:12 +0000 | [diff] [blame] | 1431 | bool isBankedReg() const { return Kind == k_BankedReg; } |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 1432 | bool isProcIFlags() const { return Kind == k_ProcIFlags; } |
Daniel Dunbar | 5cd4d0f | 2010-08-11 05:24:50 +0000 | [diff] [blame] | 1433 | |
Jim Grosbach | 741cd73 | 2011-10-17 22:26:03 +0000 | [diff] [blame] | 1434 | // NEON operands. |
Jim Grosbach | 2f50e92 | 2011-12-15 21:44:33 +0000 | [diff] [blame] | 1435 | bool isSingleSpacedVectorList() const { |
| 1436 | return Kind == k_VectorList && !VectorList.isDoubleSpaced; |
| 1437 | } |
| 1438 | bool isDoubleSpacedVectorList() const { |
| 1439 | return Kind == k_VectorList && VectorList.isDoubleSpaced; |
| 1440 | } |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 1441 | bool isVecListOneD() const { |
Jim Grosbach | 2f50e92 | 2011-12-15 21:44:33 +0000 | [diff] [blame] | 1442 | if (!isSingleSpacedVectorList()) return false; |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 1443 | return VectorList.Count == 1; |
| 1444 | } |
| 1445 | |
Jim Grosbach | c988e0c | 2012-03-05 19:33:30 +0000 | [diff] [blame] | 1446 | bool isVecListDPair() const { |
| 1447 | if (!isSingleSpacedVectorList()) return false; |
| 1448 | return (ARMMCRegisterClasses[ARM::DPairRegClassID] |
| 1449 | .contains(VectorList.RegNum)); |
| 1450 | } |
| 1451 | |
Jim Grosbach | c4360fe | 2011-10-21 20:02:19 +0000 | [diff] [blame] | 1452 | bool isVecListThreeD() const { |
Jim Grosbach | 2f50e92 | 2011-12-15 21:44:33 +0000 | [diff] [blame] | 1453 | if (!isSingleSpacedVectorList()) return false; |
Jim Grosbach | c4360fe | 2011-10-21 20:02:19 +0000 | [diff] [blame] | 1454 | return VectorList.Count == 3; |
| 1455 | } |
| 1456 | |
Jim Grosbach | 846bcff | 2011-10-21 20:35:01 +0000 | [diff] [blame] | 1457 | bool isVecListFourD() const { |
Jim Grosbach | 2f50e92 | 2011-12-15 21:44:33 +0000 | [diff] [blame] | 1458 | if (!isSingleSpacedVectorList()) return false; |
Jim Grosbach | 846bcff | 2011-10-21 20:35:01 +0000 | [diff] [blame] | 1459 | return VectorList.Count == 4; |
| 1460 | } |
| 1461 | |
Jim Grosbach | e5307f9 | 2012-03-05 21:43:40 +0000 | [diff] [blame] | 1462 | bool isVecListDPairSpaced() const { |
Kevin Enderby | 5611398 | 2014-03-26 21:54:11 +0000 | [diff] [blame] | 1463 | if (Kind != k_VectorList) return false; |
Kevin Enderby | 816ca27 | 2012-03-20 17:41:51 +0000 | [diff] [blame] | 1464 | if (isSingleSpacedVectorList()) return false; |
Jim Grosbach | e5307f9 | 2012-03-05 21:43:40 +0000 | [diff] [blame] | 1465 | return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID] |
| 1466 | .contains(VectorList.RegNum)); |
| 1467 | } |
| 1468 | |
Jim Grosbach | ac2af3f | 2012-01-23 23:20:46 +0000 | [diff] [blame] | 1469 | bool isVecListThreeQ() const { |
| 1470 | if (!isDoubleSpacedVectorList()) return false; |
| 1471 | return VectorList.Count == 3; |
| 1472 | } |
| 1473 | |
Jim Grosbach | 1e946a4 | 2012-01-24 00:43:12 +0000 | [diff] [blame] | 1474 | bool isVecListFourQ() const { |
| 1475 | if (!isDoubleSpacedVectorList()) return false; |
| 1476 | return VectorList.Count == 4; |
| 1477 | } |
| 1478 | |
Jim Grosbach | c5af54e | 2011-12-21 00:38:54 +0000 | [diff] [blame] | 1479 | bool isSingleSpacedVectorAllLanes() const { |
| 1480 | return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced; |
| 1481 | } |
| 1482 | bool isDoubleSpacedVectorAllLanes() const { |
| 1483 | return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced; |
| 1484 | } |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 1485 | bool isVecListOneDAllLanes() const { |
Jim Grosbach | c5af54e | 2011-12-21 00:38:54 +0000 | [diff] [blame] | 1486 | if (!isSingleSpacedVectorAllLanes()) return false; |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 1487 | return VectorList.Count == 1; |
| 1488 | } |
| 1489 | |
Jim Grosbach | 13a292c | 2012-03-06 22:01:44 +0000 | [diff] [blame] | 1490 | bool isVecListDPairAllLanes() const { |
Jim Grosbach | c5af54e | 2011-12-21 00:38:54 +0000 | [diff] [blame] | 1491 | if (!isSingleSpacedVectorAllLanes()) return false; |
Jim Grosbach | 13a292c | 2012-03-06 22:01:44 +0000 | [diff] [blame] | 1492 | return (ARMMCRegisterClasses[ARM::DPairRegClassID] |
| 1493 | .contains(VectorList.RegNum)); |
Jim Grosbach | c5af54e | 2011-12-21 00:38:54 +0000 | [diff] [blame] | 1494 | } |
| 1495 | |
Jim Grosbach | ed428bc | 2012-03-06 23:10:38 +0000 | [diff] [blame] | 1496 | bool isVecListDPairSpacedAllLanes() const { |
Jim Grosbach | c5af54e | 2011-12-21 00:38:54 +0000 | [diff] [blame] | 1497 | if (!isDoubleSpacedVectorAllLanes()) return false; |
Jim Grosbach | 3ecf976 | 2011-11-30 18:21:25 +0000 | [diff] [blame] | 1498 | return VectorList.Count == 2; |
| 1499 | } |
| 1500 | |
Jim Grosbach | b78403c | 2012-01-24 23:47:04 +0000 | [diff] [blame] | 1501 | bool isVecListThreeDAllLanes() const { |
| 1502 | if (!isSingleSpacedVectorAllLanes()) return false; |
| 1503 | return VectorList.Count == 3; |
| 1504 | } |
| 1505 | |
| 1506 | bool isVecListThreeQAllLanes() const { |
| 1507 | if (!isDoubleSpacedVectorAllLanes()) return false; |
| 1508 | return VectorList.Count == 3; |
| 1509 | } |
| 1510 | |
Jim Grosbach | 086cbfa | 2012-01-25 00:01:08 +0000 | [diff] [blame] | 1511 | bool isVecListFourDAllLanes() const { |
| 1512 | if (!isSingleSpacedVectorAllLanes()) return false; |
| 1513 | return VectorList.Count == 4; |
| 1514 | } |
| 1515 | |
| 1516 | bool isVecListFourQAllLanes() const { |
| 1517 | if (!isDoubleSpacedVectorAllLanes()) return false; |
| 1518 | return VectorList.Count == 4; |
| 1519 | } |
| 1520 | |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 1521 | bool isSingleSpacedVectorIndexed() const { |
| 1522 | return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced; |
| 1523 | } |
| 1524 | bool isDoubleSpacedVectorIndexed() const { |
| 1525 | return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced; |
| 1526 | } |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 1527 | bool isVecListOneDByteIndexed() const { |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 1528 | if (!isSingleSpacedVectorIndexed()) return false; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 1529 | return VectorList.Count == 1 && VectorList.LaneIndex <= 7; |
| 1530 | } |
| 1531 | |
Jim Grosbach | da51104 | 2011-12-14 23:35:06 +0000 | [diff] [blame] | 1532 | bool isVecListOneDHWordIndexed() const { |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 1533 | if (!isSingleSpacedVectorIndexed()) return false; |
Jim Grosbach | da51104 | 2011-12-14 23:35:06 +0000 | [diff] [blame] | 1534 | return VectorList.Count == 1 && VectorList.LaneIndex <= 3; |
| 1535 | } |
| 1536 | |
| 1537 | bool isVecListOneDWordIndexed() const { |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 1538 | if (!isSingleSpacedVectorIndexed()) return false; |
Jim Grosbach | da51104 | 2011-12-14 23:35:06 +0000 | [diff] [blame] | 1539 | return VectorList.Count == 1 && VectorList.LaneIndex <= 1; |
| 1540 | } |
| 1541 | |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 1542 | bool isVecListTwoDByteIndexed() const { |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 1543 | if (!isSingleSpacedVectorIndexed()) return false; |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 1544 | return VectorList.Count == 2 && VectorList.LaneIndex <= 7; |
| 1545 | } |
| 1546 | |
Jim Grosbach | da51104 | 2011-12-14 23:35:06 +0000 | [diff] [blame] | 1547 | bool isVecListTwoDHWordIndexed() const { |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 1548 | if (!isSingleSpacedVectorIndexed()) return false; |
| 1549 | return VectorList.Count == 2 && VectorList.LaneIndex <= 3; |
| 1550 | } |
| 1551 | |
| 1552 | bool isVecListTwoQWordIndexed() const { |
| 1553 | if (!isDoubleSpacedVectorIndexed()) return false; |
| 1554 | return VectorList.Count == 2 && VectorList.LaneIndex <= 1; |
| 1555 | } |
| 1556 | |
| 1557 | bool isVecListTwoQHWordIndexed() const { |
| 1558 | if (!isDoubleSpacedVectorIndexed()) return false; |
Jim Grosbach | da51104 | 2011-12-14 23:35:06 +0000 | [diff] [blame] | 1559 | return VectorList.Count == 2 && VectorList.LaneIndex <= 3; |
| 1560 | } |
| 1561 | |
| 1562 | bool isVecListTwoDWordIndexed() const { |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 1563 | if (!isSingleSpacedVectorIndexed()) return false; |
Jim Grosbach | da51104 | 2011-12-14 23:35:06 +0000 | [diff] [blame] | 1564 | return VectorList.Count == 2 && VectorList.LaneIndex <= 1; |
| 1565 | } |
| 1566 | |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 1567 | bool isVecListThreeDByteIndexed() const { |
| 1568 | if (!isSingleSpacedVectorIndexed()) return false; |
| 1569 | return VectorList.Count == 3 && VectorList.LaneIndex <= 7; |
| 1570 | } |
| 1571 | |
| 1572 | bool isVecListThreeDHWordIndexed() const { |
| 1573 | if (!isSingleSpacedVectorIndexed()) return false; |
| 1574 | return VectorList.Count == 3 && VectorList.LaneIndex <= 3; |
| 1575 | } |
| 1576 | |
| 1577 | bool isVecListThreeQWordIndexed() const { |
| 1578 | if (!isDoubleSpacedVectorIndexed()) return false; |
| 1579 | return VectorList.Count == 3 && VectorList.LaneIndex <= 1; |
| 1580 | } |
| 1581 | |
| 1582 | bool isVecListThreeQHWordIndexed() const { |
| 1583 | if (!isDoubleSpacedVectorIndexed()) return false; |
| 1584 | return VectorList.Count == 3 && VectorList.LaneIndex <= 3; |
| 1585 | } |
| 1586 | |
| 1587 | bool isVecListThreeDWordIndexed() const { |
| 1588 | if (!isSingleSpacedVectorIndexed()) return false; |
| 1589 | return VectorList.Count == 3 && VectorList.LaneIndex <= 1; |
| 1590 | } |
| 1591 | |
Jim Grosbach | 14952a0 | 2012-01-24 18:37:25 +0000 | [diff] [blame] | 1592 | bool isVecListFourDByteIndexed() const { |
| 1593 | if (!isSingleSpacedVectorIndexed()) return false; |
| 1594 | return VectorList.Count == 4 && VectorList.LaneIndex <= 7; |
| 1595 | } |
| 1596 | |
| 1597 | bool isVecListFourDHWordIndexed() const { |
| 1598 | if (!isSingleSpacedVectorIndexed()) return false; |
| 1599 | return VectorList.Count == 4 && VectorList.LaneIndex <= 3; |
| 1600 | } |
| 1601 | |
| 1602 | bool isVecListFourQWordIndexed() const { |
| 1603 | if (!isDoubleSpacedVectorIndexed()) return false; |
| 1604 | return VectorList.Count == 4 && VectorList.LaneIndex <= 1; |
| 1605 | } |
| 1606 | |
| 1607 | bool isVecListFourQHWordIndexed() const { |
| 1608 | if (!isDoubleSpacedVectorIndexed()) return false; |
| 1609 | return VectorList.Count == 4 && VectorList.LaneIndex <= 3; |
| 1610 | } |
| 1611 | |
| 1612 | bool isVecListFourDWordIndexed() const { |
| 1613 | if (!isSingleSpacedVectorIndexed()) return false; |
| 1614 | return VectorList.Count == 4 && VectorList.LaneIndex <= 1; |
| 1615 | } |
| 1616 | |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 1617 | bool isVectorIndex8() const { |
| 1618 | if (Kind != k_VectorIndex) return false; |
| 1619 | return VectorIndex.Val < 8; |
| 1620 | } |
| 1621 | bool isVectorIndex16() const { |
| 1622 | if (Kind != k_VectorIndex) return false; |
| 1623 | return VectorIndex.Val < 4; |
| 1624 | } |
| 1625 | bool isVectorIndex32() const { |
| 1626 | if (Kind != k_VectorIndex) return false; |
| 1627 | return VectorIndex.Val < 2; |
| 1628 | } |
| 1629 | |
Jim Grosbach | 741cd73 | 2011-10-17 22:26:03 +0000 | [diff] [blame] | 1630 | bool isNEONi8splat() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1631 | if (!isImm()) return false; |
Jim Grosbach | 741cd73 | 2011-10-17 22:26:03 +0000 | [diff] [blame] | 1632 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1633 | // Must be a constant. |
| 1634 | if (!CE) return false; |
| 1635 | int64_t Value = CE->getValue(); |
| 1636 | // i8 value splatted across 8 bytes. The immediate is just the 8 byte |
| 1637 | // value. |
Jim Grosbach | 741cd73 | 2011-10-17 22:26:03 +0000 | [diff] [blame] | 1638 | return Value >= 0 && Value < 256; |
| 1639 | } |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 1640 | |
Jim Grosbach | cda32ae | 2011-10-17 23:09:09 +0000 | [diff] [blame] | 1641 | bool isNEONi16splat() const { |
Stepan Dyatkovskiy | 00dcc0f | 2014-04-24 06:03:01 +0000 | [diff] [blame] | 1642 | if (isNEONByteReplicate(2)) |
| 1643 | return false; // Leave that for bytes replication and forbid by default. |
| 1644 | if (!isImm()) |
| 1645 | return false; |
Jim Grosbach | cda32ae | 2011-10-17 23:09:09 +0000 | [diff] [blame] | 1646 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1647 | // Must be a constant. |
| 1648 | if (!CE) return false; |
Renato Golin | f5dd1da | 2014-09-25 11:31:24 +0000 | [diff] [blame] | 1649 | unsigned Value = CE->getValue(); |
| 1650 | return ARM_AM::isNEONi16splat(Value); |
| 1651 | } |
| 1652 | |
| 1653 | bool isNEONi16splatNot() const { |
| 1654 | if (!isImm()) |
| 1655 | return false; |
| 1656 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1657 | // Must be a constant. |
| 1658 | if (!CE) return false; |
| 1659 | unsigned Value = CE->getValue(); |
| 1660 | return ARM_AM::isNEONi16splat(~Value & 0xffff); |
Jim Grosbach | cda32ae | 2011-10-17 23:09:09 +0000 | [diff] [blame] | 1661 | } |
| 1662 | |
Jim Grosbach | 8211c05 | 2011-10-18 00:22:00 +0000 | [diff] [blame] | 1663 | bool isNEONi32splat() const { |
Stepan Dyatkovskiy | 00dcc0f | 2014-04-24 06:03:01 +0000 | [diff] [blame] | 1664 | if (isNEONByteReplicate(4)) |
| 1665 | return false; // Leave that for bytes replication and forbid by default. |
| 1666 | if (!isImm()) |
| 1667 | return false; |
Jim Grosbach | 8211c05 | 2011-10-18 00:22:00 +0000 | [diff] [blame] | 1668 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1669 | // Must be a constant. |
| 1670 | if (!CE) return false; |
Renato Golin | f5dd1da | 2014-09-25 11:31:24 +0000 | [diff] [blame] | 1671 | unsigned Value = CE->getValue(); |
| 1672 | return ARM_AM::isNEONi32splat(Value); |
| 1673 | } |
| 1674 | |
| 1675 | bool isNEONi32splatNot() const { |
| 1676 | if (!isImm()) |
| 1677 | return false; |
| 1678 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1679 | // Must be a constant. |
| 1680 | if (!CE) return false; |
| 1681 | unsigned Value = CE->getValue(); |
| 1682 | return ARM_AM::isNEONi32splat(~Value); |
Jim Grosbach | 8211c05 | 2011-10-18 00:22:00 +0000 | [diff] [blame] | 1683 | } |
| 1684 | |
Stepan Dyatkovskiy | 00dcc0f | 2014-04-24 06:03:01 +0000 | [diff] [blame] | 1685 | bool isNEONByteReplicate(unsigned NumBytes) const { |
| 1686 | if (!isImm()) |
| 1687 | return false; |
Jim Grosbach | 8211c05 | 2011-10-18 00:22:00 +0000 | [diff] [blame] | 1688 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1689 | // Must be a constant. |
Stepan Dyatkovskiy | 00dcc0f | 2014-04-24 06:03:01 +0000 | [diff] [blame] | 1690 | if (!CE) |
| 1691 | return false; |
| 1692 | int64_t Value = CE->getValue(); |
| 1693 | if (!Value) |
| 1694 | return false; // Don't bother with zero. |
| 1695 | |
| 1696 | unsigned char B = Value & 0xff; |
| 1697 | for (unsigned i = 1; i < NumBytes; ++i) { |
| 1698 | Value >>= 8; |
| 1699 | if ((Value & 0xff) != B) |
| 1700 | return false; |
| 1701 | } |
| 1702 | return true; |
| 1703 | } |
| 1704 | bool isNEONi16ByteReplicate() const { return isNEONByteReplicate(2); } |
| 1705 | bool isNEONi32ByteReplicate() const { return isNEONByteReplicate(4); } |
| 1706 | bool isNEONi32vmov() const { |
| 1707 | if (isNEONByteReplicate(4)) |
| 1708 | return false; // Let it to be classified as byte-replicate case. |
| 1709 | if (!isImm()) |
| 1710 | return false; |
| 1711 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1712 | // Must be a constant. |
| 1713 | if (!CE) |
| 1714 | return false; |
Jim Grosbach | 8211c05 | 2011-10-18 00:22:00 +0000 | [diff] [blame] | 1715 | int64_t Value = CE->getValue(); |
| 1716 | // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X, |
| 1717 | // for VMOV/VMVN only, 00Xf or 0Xff are also accepted. |
Renato Golin | f5dd1da | 2014-09-25 11:31:24 +0000 | [diff] [blame] | 1718 | // FIXME: This is probably wrong and a copy and paste from previous example |
Jim Grosbach | 8211c05 | 2011-10-18 00:22:00 +0000 | [diff] [blame] | 1719 | return (Value >= 0 && Value < 256) || |
| 1720 | (Value >= 0x0100 && Value <= 0xff00) || |
| 1721 | (Value >= 0x010000 && Value <= 0xff0000) || |
| 1722 | (Value >= 0x01000000 && Value <= 0xff000000) || |
| 1723 | (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) || |
| 1724 | (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff); |
| 1725 | } |
Jim Grosbach | 045b6c7 | 2011-12-19 23:51:07 +0000 | [diff] [blame] | 1726 | bool isNEONi32vmovNeg() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1727 | if (!isImm()) return false; |
Jim Grosbach | 045b6c7 | 2011-12-19 23:51:07 +0000 | [diff] [blame] | 1728 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1729 | // Must be a constant. |
| 1730 | if (!CE) return false; |
| 1731 | int64_t Value = ~CE->getValue(); |
| 1732 | // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X, |
| 1733 | // for VMOV/VMVN only, 00Xf or 0Xff are also accepted. |
Renato Golin | f5dd1da | 2014-09-25 11:31:24 +0000 | [diff] [blame] | 1734 | // FIXME: This is probably wrong and a copy and paste from previous example |
Jim Grosbach | 045b6c7 | 2011-12-19 23:51:07 +0000 | [diff] [blame] | 1735 | return (Value >= 0 && Value < 256) || |
| 1736 | (Value >= 0x0100 && Value <= 0xff00) || |
| 1737 | (Value >= 0x010000 && Value <= 0xff0000) || |
| 1738 | (Value >= 0x01000000 && Value <= 0xff000000) || |
| 1739 | (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) || |
| 1740 | (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff); |
| 1741 | } |
Jim Grosbach | 8211c05 | 2011-10-18 00:22:00 +0000 | [diff] [blame] | 1742 | |
Jim Grosbach | e4454e0 | 2011-10-18 16:18:11 +0000 | [diff] [blame] | 1743 | bool isNEONi64splat() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1744 | if (!isImm()) return false; |
Jim Grosbach | e4454e0 | 2011-10-18 16:18:11 +0000 | [diff] [blame] | 1745 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1746 | // Must be a constant. |
| 1747 | if (!CE) return false; |
| 1748 | uint64_t Value = CE->getValue(); |
| 1749 | // i64 value with each byte being either 0 or 0xff. |
| 1750 | for (unsigned i = 0; i < 8; ++i) |
| 1751 | if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false; |
| 1752 | return true; |
| 1753 | } |
| 1754 | |
Daniel Dunbar | 5cd4d0f | 2010-08-11 05:24:50 +0000 | [diff] [blame] | 1755 | void addExpr(MCInst &Inst, const MCExpr *Expr) const { |
Chris Lattner | 5d6f6a0 | 2010-10-29 00:27:31 +0000 | [diff] [blame] | 1756 | // Add as immediates when possible. Null MCExpr = 0. |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1757 | if (!Expr) |
Chris Lattner | 5d6f6a0 | 2010-10-29 00:27:31 +0000 | [diff] [blame] | 1758 | Inst.addOperand(MCOperand::CreateImm(0)); |
| 1759 | else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr)) |
Daniel Dunbar | 5cd4d0f | 2010-08-11 05:24:50 +0000 | [diff] [blame] | 1760 | Inst.addOperand(MCOperand::CreateImm(CE->getValue())); |
| 1761 | else |
| 1762 | Inst.addOperand(MCOperand::CreateExpr(Expr)); |
| 1763 | } |
| 1764 | |
Daniel Dunbar | d8042b7 | 2010-08-11 06:36:53 +0000 | [diff] [blame] | 1765 | void addCondCodeOperands(MCInst &Inst, unsigned N) const { |
Daniel Dunbar | 188b47b | 2010-08-11 06:37:20 +0000 | [diff] [blame] | 1766 | assert(N == 2 && "Invalid number of operands!"); |
Daniel Dunbar | d8042b7 | 2010-08-11 06:36:53 +0000 | [diff] [blame] | 1767 | Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode()))); |
Jim Grosbach | 968c927 | 2010-12-06 18:30:57 +0000 | [diff] [blame] | 1768 | unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR; |
| 1769 | Inst.addOperand(MCOperand::CreateReg(RegNum)); |
Daniel Dunbar | d8042b7 | 2010-08-11 06:36:53 +0000 | [diff] [blame] | 1770 | } |
| 1771 | |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 1772 | void addCoprocNumOperands(MCInst &Inst, unsigned N) const { |
| 1773 | assert(N == 1 && "Invalid number of operands!"); |
| 1774 | Inst.addOperand(MCOperand::CreateImm(getCoproc())); |
| 1775 | } |
| 1776 | |
Jim Grosbach | 4839958 | 2011-10-12 17:34:41 +0000 | [diff] [blame] | 1777 | void addCoprocRegOperands(MCInst &Inst, unsigned N) const { |
| 1778 | assert(N == 1 && "Invalid number of operands!"); |
| 1779 | Inst.addOperand(MCOperand::CreateImm(getCoproc())); |
| 1780 | } |
| 1781 | |
| 1782 | void addCoprocOptionOperands(MCInst &Inst, unsigned N) const { |
| 1783 | assert(N == 1 && "Invalid number of operands!"); |
| 1784 | Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val)); |
| 1785 | } |
| 1786 | |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 1787 | void addITMaskOperands(MCInst &Inst, unsigned N) const { |
| 1788 | assert(N == 1 && "Invalid number of operands!"); |
| 1789 | Inst.addOperand(MCOperand::CreateImm(ITMask.Mask)); |
| 1790 | } |
| 1791 | |
| 1792 | void addITCondCodeOperands(MCInst &Inst, unsigned N) const { |
| 1793 | assert(N == 1 && "Invalid number of operands!"); |
| 1794 | Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode()))); |
| 1795 | } |
| 1796 | |
Jim Grosbach | 0bfb4d5 | 2010-12-06 18:21:12 +0000 | [diff] [blame] | 1797 | void addCCOutOperands(MCInst &Inst, unsigned N) const { |
| 1798 | assert(N == 1 && "Invalid number of operands!"); |
| 1799 | Inst.addOperand(MCOperand::CreateReg(getReg())); |
| 1800 | } |
| 1801 | |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 1802 | void addRegOperands(MCInst &Inst, unsigned N) const { |
| 1803 | assert(N == 1 && "Invalid number of operands!"); |
| 1804 | Inst.addOperand(MCOperand::CreateReg(getReg())); |
| 1805 | } |
| 1806 | |
Jim Grosbach | ac798e1 | 2011-07-25 20:49:51 +0000 | [diff] [blame] | 1807 | void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const { |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 1808 | assert(N == 3 && "Invalid number of operands!"); |
Jim Grosbach | ee201fa | 2011-11-14 17:52:47 +0000 | [diff] [blame] | 1809 | assert(isRegShiftedReg() && |
Alp Toker | f907b89 | 2013-12-05 05:44:44 +0000 | [diff] [blame] | 1810 | "addRegShiftedRegOperands() on non-RegShiftedReg!"); |
Jim Grosbach | ac798e1 | 2011-07-25 20:49:51 +0000 | [diff] [blame] | 1811 | Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg)); |
| 1812 | Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg)); |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 1813 | Inst.addOperand(MCOperand::CreateImm( |
Jim Grosbach | ac798e1 | 2011-07-25 20:49:51 +0000 | [diff] [blame] | 1814 | ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm))); |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 1815 | } |
| 1816 | |
Jim Grosbach | ac798e1 | 2011-07-25 20:49:51 +0000 | [diff] [blame] | 1817 | void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const { |
Owen Anderson | 0491270 | 2011-07-21 23:38:37 +0000 | [diff] [blame] | 1818 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | ee201fa | 2011-11-14 17:52:47 +0000 | [diff] [blame] | 1819 | assert(isRegShiftedImm() && |
Alp Toker | f907b89 | 2013-12-05 05:44:44 +0000 | [diff] [blame] | 1820 | "addRegShiftedImmOperands() on non-RegShiftedImm!"); |
Jim Grosbach | ac798e1 | 2011-07-25 20:49:51 +0000 | [diff] [blame] | 1821 | Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg)); |
Richard Barton | ba5b0cc | 2012-04-25 18:00:18 +0000 | [diff] [blame] | 1822 | // Shift of #32 is encoded as 0 where permitted |
| 1823 | unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm); |
Owen Anderson | b595ed0 | 2011-07-21 18:54:16 +0000 | [diff] [blame] | 1824 | Inst.addOperand(MCOperand::CreateImm( |
Richard Barton | ba5b0cc | 2012-04-25 18:00:18 +0000 | [diff] [blame] | 1825 | ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm))); |
Owen Anderson | b595ed0 | 2011-07-21 18:54:16 +0000 | [diff] [blame] | 1826 | } |
| 1827 | |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 1828 | void addShifterImmOperands(MCInst &Inst, unsigned N) const { |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 1829 | assert(N == 1 && "Invalid number of operands!"); |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 1830 | Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) | |
| 1831 | ShifterImm.Imm)); |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 1832 | } |
| 1833 | |
Bill Wendling | 8d2aa03 | 2010-11-08 23:49:57 +0000 | [diff] [blame] | 1834 | void addRegListOperands(MCInst &Inst, unsigned N) const { |
Bill Wendling | 2cae327 | 2010-11-09 22:44:22 +0000 | [diff] [blame] | 1835 | assert(N == 1 && "Invalid number of operands!"); |
Bill Wendling | bed9465 | 2010-11-09 23:28:44 +0000 | [diff] [blame] | 1836 | const SmallVectorImpl<unsigned> &RegList = getRegList(); |
| 1837 | for (SmallVectorImpl<unsigned>::const_iterator |
Bill Wendling | 2cae327 | 2010-11-09 22:44:22 +0000 | [diff] [blame] | 1838 | I = RegList.begin(), E = RegList.end(); I != E; ++I) |
| 1839 | Inst.addOperand(MCOperand::CreateReg(*I)); |
Bill Wendling | 8d2aa03 | 2010-11-08 23:49:57 +0000 | [diff] [blame] | 1840 | } |
| 1841 | |
Bill Wendling | 9898ac9 | 2010-11-17 04:32:08 +0000 | [diff] [blame] | 1842 | void addDPRRegListOperands(MCInst &Inst, unsigned N) const { |
| 1843 | addRegListOperands(Inst, N); |
| 1844 | } |
| 1845 | |
| 1846 | void addSPRRegListOperands(MCInst &Inst, unsigned N) const { |
| 1847 | addRegListOperands(Inst, N); |
| 1848 | } |
| 1849 | |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 1850 | void addRotImmOperands(MCInst &Inst, unsigned N) const { |
| 1851 | assert(N == 1 && "Invalid number of operands!"); |
| 1852 | // Encoded as val>>3. The printer handles display as 8, 16, 24. |
| 1853 | Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3)); |
| 1854 | } |
| 1855 | |
Asiri Rathnayake | a0199b9 | 2014-12-02 10:53:20 +0000 | [diff] [blame] | 1856 | void addModImmOperands(MCInst &Inst, unsigned N) const { |
| 1857 | assert(N == 1 && "Invalid number of operands!"); |
| 1858 | |
| 1859 | // Support for fixups (MCFixup) |
| 1860 | if (isImm()) |
| 1861 | return addImmOperands(Inst, N); |
| 1862 | |
| 1863 | if (Inst.getOpcode() == ARM::ADDri && |
| 1864 | Inst.getOperand(1).getReg() == ARM::PC) { |
| 1865 | // Instructions of the form [ADD <rd>, pc, #imm] are manually aliased |
| 1866 | // in processInstruction() to use ADR. We must keep the immediate in |
| 1867 | // its unencoded form in order to not clash with this aliasing. |
| 1868 | Inst.addOperand(MCOperand::CreateImm(ARM_AM::rotr32(ModImm.Bits, |
| 1869 | ModImm.Rot))); |
| 1870 | } else { |
| 1871 | Inst.addOperand(MCOperand::CreateImm(ModImm.Bits | (ModImm.Rot << 7))); |
| 1872 | } |
| 1873 | } |
| 1874 | |
| 1875 | void addModImmNotOperands(MCInst &Inst, unsigned N) const { |
| 1876 | assert(N == 1 && "Invalid number of operands!"); |
| 1877 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1878 | uint32_t Enc = ARM_AM::getSOImmVal(~CE->getValue()); |
| 1879 | Inst.addOperand(MCOperand::CreateImm(Enc)); |
| 1880 | } |
| 1881 | |
| 1882 | void addModImmNegOperands(MCInst &Inst, unsigned N) const { |
| 1883 | assert(N == 1 && "Invalid number of operands!"); |
| 1884 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1885 | uint32_t Enc = ARM_AM::getSOImmVal(-CE->getValue()); |
| 1886 | Inst.addOperand(MCOperand::CreateImm(Enc)); |
| 1887 | } |
| 1888 | |
Jim Grosbach | 864b609 | 2011-07-28 21:34:26 +0000 | [diff] [blame] | 1889 | void addBitfieldOperands(MCInst &Inst, unsigned N) const { |
| 1890 | assert(N == 1 && "Invalid number of operands!"); |
| 1891 | // Munge the lsb/width into a bitfield mask. |
| 1892 | unsigned lsb = Bitfield.LSB; |
| 1893 | unsigned width = Bitfield.Width; |
| 1894 | // Make a 32-bit mask w/ the referenced bits clear and all other bits set. |
| 1895 | uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >> |
| 1896 | (32 - (lsb + width))); |
| 1897 | Inst.addOperand(MCOperand::CreateImm(Mask)); |
| 1898 | } |
| 1899 | |
Daniel Dunbar | 5cd4d0f | 2010-08-11 05:24:50 +0000 | [diff] [blame] | 1900 | void addImmOperands(MCInst &Inst, unsigned N) const { |
| 1901 | assert(N == 1 && "Invalid number of operands!"); |
| 1902 | addExpr(Inst, getImm()); |
| 1903 | } |
Jim Grosbach | 624bcc7 | 2010-10-29 14:46:02 +0000 | [diff] [blame] | 1904 | |
Jim Grosbach | ea23191 | 2011-12-22 22:19:05 +0000 | [diff] [blame] | 1905 | void addFBits16Operands(MCInst &Inst, unsigned N) const { |
| 1906 | assert(N == 1 && "Invalid number of operands!"); |
| 1907 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1908 | Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue())); |
| 1909 | } |
| 1910 | |
| 1911 | void addFBits32Operands(MCInst &Inst, unsigned N) const { |
| 1912 | assert(N == 1 && "Invalid number of operands!"); |
| 1913 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1914 | Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue())); |
| 1915 | } |
| 1916 | |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 1917 | void addFPImmOperands(MCInst &Inst, unsigned N) const { |
| 1918 | assert(N == 1 && "Invalid number of operands!"); |
Jim Grosbach | a9d36fb | 2012-01-20 18:09:51 +0000 | [diff] [blame] | 1919 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1920 | int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue())); |
| 1921 | Inst.addOperand(MCOperand::CreateImm(Val)); |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 1922 | } |
| 1923 | |
Jim Grosbach | 7db8d69 | 2011-09-08 22:07:06 +0000 | [diff] [blame] | 1924 | void addImm8s4Operands(MCInst &Inst, unsigned N) const { |
| 1925 | assert(N == 1 && "Invalid number of operands!"); |
| 1926 | // FIXME: We really want to scale the value here, but the LDRD/STRD |
| 1927 | // instruction don't encode operands that way yet. |
| 1928 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1929 | Inst.addOperand(MCOperand::CreateImm(CE->getValue())); |
| 1930 | } |
| 1931 | |
Jim Grosbach | 0a0b307 | 2011-08-24 21:22:15 +0000 | [diff] [blame] | 1932 | void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const { |
| 1933 | assert(N == 1 && "Invalid number of operands!"); |
| 1934 | // The immediate is scaled by four in the encoding and is stored |
| 1935 | // in the MCInst as such. Lop off the low two bits here. |
| 1936 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1937 | Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4)); |
| 1938 | } |
| 1939 | |
Jim Grosbach | 930f2f6 | 2012-04-05 20:57:13 +0000 | [diff] [blame] | 1940 | void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const { |
| 1941 | assert(N == 1 && "Invalid number of operands!"); |
| 1942 | // The immediate is scaled by four in the encoding and is stored |
| 1943 | // in the MCInst as such. Lop off the low two bits here. |
| 1944 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1945 | Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4))); |
| 1946 | } |
| 1947 | |
Jim Grosbach | 0a0b307 | 2011-08-24 21:22:15 +0000 | [diff] [blame] | 1948 | void addImm0_508s4Operands(MCInst &Inst, unsigned N) const { |
| 1949 | assert(N == 1 && "Invalid number of operands!"); |
| 1950 | // The immediate is scaled by four in the encoding and is stored |
| 1951 | // in the MCInst as such. Lop off the low two bits here. |
| 1952 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1953 | Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4)); |
| 1954 | } |
| 1955 | |
Jim Grosbach | 475c6db | 2011-07-25 23:09:14 +0000 | [diff] [blame] | 1956 | void addImm1_16Operands(MCInst &Inst, unsigned N) const { |
| 1957 | assert(N == 1 && "Invalid number of operands!"); |
| 1958 | // The constant encodes as the immediate-1, and we store in the instruction |
| 1959 | // the bits as encoded, so subtract off one here. |
| 1960 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1961 | Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1)); |
| 1962 | } |
| 1963 | |
Jim Grosbach | 801e0a3 | 2011-07-22 23:16:18 +0000 | [diff] [blame] | 1964 | void addImm1_32Operands(MCInst &Inst, unsigned N) const { |
| 1965 | assert(N == 1 && "Invalid number of operands!"); |
| 1966 | // The constant encodes as the immediate-1, and we store in the instruction |
| 1967 | // the bits as encoded, so subtract off one here. |
| 1968 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1969 | Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1)); |
| 1970 | } |
| 1971 | |
Jim Grosbach | 46dd413 | 2011-08-17 21:51:27 +0000 | [diff] [blame] | 1972 | void addImmThumbSROperands(MCInst &Inst, unsigned N) const { |
| 1973 | assert(N == 1 && "Invalid number of operands!"); |
| 1974 | // The constant encodes as the immediate, except for 32, which encodes as |
| 1975 | // zero. |
| 1976 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1977 | unsigned Imm = CE->getValue(); |
| 1978 | Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm))); |
| 1979 | } |
| 1980 | |
Jim Grosbach | 27c1e25 | 2011-07-21 17:23:04 +0000 | [diff] [blame] | 1981 | void addPKHASRImmOperands(MCInst &Inst, unsigned N) const { |
| 1982 | assert(N == 1 && "Invalid number of operands!"); |
| 1983 | // An ASR value of 32 encodes as 0, so that's how we want to add it to |
| 1984 | // the instruction as well. |
| 1985 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1986 | int Val = CE->getValue(); |
| 1987 | Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val)); |
| 1988 | } |
| 1989 | |
Jim Grosbach | b009a87 | 2011-10-28 22:36:30 +0000 | [diff] [blame] | 1990 | void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const { |
| 1991 | assert(N == 1 && "Invalid number of operands!"); |
| 1992 | // The operand is actually a t2_so_imm, but we have its bitwise |
| 1993 | // negation in the assembly source, so twiddle it here. |
| 1994 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1995 | Inst.addOperand(MCOperand::CreateImm(~CE->getValue())); |
| 1996 | } |
| 1997 | |
Jim Grosbach | 3050625 | 2011-12-08 00:31:07 +0000 | [diff] [blame] | 1998 | void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const { |
| 1999 | assert(N == 1 && "Invalid number of operands!"); |
| 2000 | // The operand is actually a t2_so_imm, but we have its |
| 2001 | // negation in the assembly source, so twiddle it here. |
| 2002 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2003 | Inst.addOperand(MCOperand::CreateImm(-CE->getValue())); |
| 2004 | } |
| 2005 | |
Jim Grosbach | 930f2f6 | 2012-04-05 20:57:13 +0000 | [diff] [blame] | 2006 | void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const { |
| 2007 | assert(N == 1 && "Invalid number of operands!"); |
| 2008 | // The operand is actually an imm0_4095, but we have its |
| 2009 | // negation in the assembly source, so twiddle it here. |
| 2010 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2011 | Inst.addOperand(MCOperand::CreateImm(-CE->getValue())); |
| 2012 | } |
| 2013 | |
Mihai Popa | d36cbaa | 2013-07-03 09:21:44 +0000 | [diff] [blame] | 2014 | void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const { |
| 2015 | if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) { |
| 2016 | Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2)); |
| 2017 | return; |
| 2018 | } |
| 2019 | |
| 2020 | const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val); |
| 2021 | assert(SR && "Unknown value type!"); |
| 2022 | Inst.addOperand(MCOperand::CreateExpr(SR)); |
| 2023 | } |
| 2024 | |
Mihai Popa | 8a9da5b | 2013-07-22 15:49:36 +0000 | [diff] [blame] | 2025 | void addThumbMemPCOperands(MCInst &Inst, unsigned N) const { |
| 2026 | assert(N == 1 && "Invalid number of operands!"); |
| 2027 | if (isImm()) { |
| 2028 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2029 | if (CE) { |
| 2030 | Inst.addOperand(MCOperand::CreateImm(CE->getValue())); |
| 2031 | return; |
| 2032 | } |
| 2033 | |
| 2034 | const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val); |
| 2035 | assert(SR && "Unknown value type!"); |
| 2036 | Inst.addOperand(MCOperand::CreateExpr(SR)); |
| 2037 | return; |
| 2038 | } |
| 2039 | |
| 2040 | assert(isMem() && "Unknown value type!"); |
| 2041 | assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!"); |
| 2042 | Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue())); |
| 2043 | } |
| 2044 | |
Jim Grosbach | 3d785ed | 2011-10-28 22:50:54 +0000 | [diff] [blame] | 2045 | void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const { |
| 2046 | assert(N == 1 && "Invalid number of operands!"); |
| 2047 | // The operand is actually a so_imm, but we have its bitwise |
| 2048 | // negation in the assembly source, so twiddle it here. |
| 2049 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2050 | Inst.addOperand(MCOperand::CreateImm(~CE->getValue())); |
| 2051 | } |
| 2052 | |
Jim Grosbach | 3050625 | 2011-12-08 00:31:07 +0000 | [diff] [blame] | 2053 | void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const { |
| 2054 | assert(N == 1 && "Invalid number of operands!"); |
| 2055 | // The operand is actually a so_imm, but we have its |
| 2056 | // negation in the assembly source, so twiddle it here. |
| 2057 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2058 | Inst.addOperand(MCOperand::CreateImm(-CE->getValue())); |
| 2059 | } |
| 2060 | |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 2061 | void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const { |
| 2062 | assert(N == 1 && "Invalid number of operands!"); |
| 2063 | Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt()))); |
| 2064 | } |
| 2065 | |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 2066 | void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const { |
| 2067 | assert(N == 1 && "Invalid number of operands!"); |
| 2068 | Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt()))); |
| 2069 | } |
| 2070 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2071 | void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const { |
| 2072 | assert(N == 1 && "Invalid number of operands!"); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2073 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
Bruno Cardoso Lopes | f170f8b | 2011-03-24 21:04:58 +0000 | [diff] [blame] | 2074 | } |
| 2075 | |
Jim Grosbach | 94298a9 | 2012-01-18 22:46:46 +0000 | [diff] [blame] | 2076 | void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const { |
| 2077 | assert(N == 1 && "Invalid number of operands!"); |
| 2078 | int32_t Imm = Memory.OffsetImm->getValue(); |
Jim Grosbach | 94298a9 | 2012-01-18 22:46:46 +0000 | [diff] [blame] | 2079 | Inst.addOperand(MCOperand::CreateImm(Imm)); |
| 2080 | } |
| 2081 | |
Jiangning Liu | 10dd40e | 2012-08-02 08:13:13 +0000 | [diff] [blame] | 2082 | void addAdrLabelOperands(MCInst &Inst, unsigned N) const { |
| 2083 | assert(N == 1 && "Invalid number of operands!"); |
| 2084 | assert(isImm() && "Not an immediate!"); |
| 2085 | |
| 2086 | // If we have an immediate that's not a constant, treat it as a label |
| 2087 | // reference needing a fixup. |
| 2088 | if (!isa<MCConstantExpr>(getImm())) { |
| 2089 | Inst.addOperand(MCOperand::CreateExpr(getImm())); |
| 2090 | return; |
| 2091 | } |
| 2092 | |
| 2093 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2094 | int Val = CE->getValue(); |
| 2095 | Inst.addOperand(MCOperand::CreateImm(Val)); |
| 2096 | } |
| 2097 | |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 2098 | void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const { |
| 2099 | assert(N == 2 && "Invalid number of operands!"); |
| 2100 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
| 2101 | Inst.addOperand(MCOperand::CreateImm(Memory.Alignment)); |
| 2102 | } |
| 2103 | |
Kevin Enderby | 488f20b | 2014-04-10 20:18:58 +0000 | [diff] [blame] | 2104 | void addDupAlignedMemoryNoneOperands(MCInst &Inst, unsigned N) const { |
| 2105 | addAlignedMemoryOperands(Inst, N); |
| 2106 | } |
| 2107 | |
| 2108 | void addAlignedMemoryNoneOperands(MCInst &Inst, unsigned N) const { |
| 2109 | addAlignedMemoryOperands(Inst, N); |
| 2110 | } |
| 2111 | |
| 2112 | void addAlignedMemory16Operands(MCInst &Inst, unsigned N) const { |
| 2113 | addAlignedMemoryOperands(Inst, N); |
| 2114 | } |
| 2115 | |
| 2116 | void addDupAlignedMemory16Operands(MCInst &Inst, unsigned N) const { |
| 2117 | addAlignedMemoryOperands(Inst, N); |
| 2118 | } |
| 2119 | |
| 2120 | void addAlignedMemory32Operands(MCInst &Inst, unsigned N) const { |
| 2121 | addAlignedMemoryOperands(Inst, N); |
| 2122 | } |
| 2123 | |
| 2124 | void addDupAlignedMemory32Operands(MCInst &Inst, unsigned N) const { |
| 2125 | addAlignedMemoryOperands(Inst, N); |
| 2126 | } |
| 2127 | |
| 2128 | void addAlignedMemory64Operands(MCInst &Inst, unsigned N) const { |
| 2129 | addAlignedMemoryOperands(Inst, N); |
| 2130 | } |
| 2131 | |
| 2132 | void addDupAlignedMemory64Operands(MCInst &Inst, unsigned N) const { |
| 2133 | addAlignedMemoryOperands(Inst, N); |
| 2134 | } |
| 2135 | |
| 2136 | void addAlignedMemory64or128Operands(MCInst &Inst, unsigned N) const { |
| 2137 | addAlignedMemoryOperands(Inst, N); |
| 2138 | } |
| 2139 | |
| 2140 | void addDupAlignedMemory64or128Operands(MCInst &Inst, unsigned N) const { |
| 2141 | addAlignedMemoryOperands(Inst, N); |
| 2142 | } |
| 2143 | |
| 2144 | void addAlignedMemory64or128or256Operands(MCInst &Inst, unsigned N) const { |
| 2145 | addAlignedMemoryOperands(Inst, N); |
| 2146 | } |
| 2147 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2148 | void addAddrMode2Operands(MCInst &Inst, unsigned N) const { |
| 2149 | assert(N == 3 && "Invalid number of operands!"); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2150 | int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0; |
| 2151 | if (!Memory.OffsetRegNum) { |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2152 | ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add; |
| 2153 | // Special case for #-0 |
| 2154 | if (Val == INT32_MIN) Val = 0; |
| 2155 | if (Val < 0) Val = -Val; |
| 2156 | Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift); |
| 2157 | } else { |
| 2158 | // For register offset, we encode the shift type and negation flag |
| 2159 | // here. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2160 | Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, |
| 2161 | Memory.ShiftImm, Memory.ShiftType); |
Bruno Cardoso Lopes | ab83050 | 2011-03-31 23:26:08 +0000 | [diff] [blame] | 2162 | } |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2163 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
| 2164 | Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum)); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2165 | Inst.addOperand(MCOperand::CreateImm(Val)); |
Bruno Cardoso Lopes | ab83050 | 2011-03-31 23:26:08 +0000 | [diff] [blame] | 2166 | } |
| 2167 | |
Jim Grosbach | cd17c12 | 2011-08-04 23:01:30 +0000 | [diff] [blame] | 2168 | void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const { |
| 2169 | assert(N == 2 && "Invalid number of operands!"); |
| 2170 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2171 | assert(CE && "non-constant AM2OffsetImm operand!"); |
| 2172 | int32_t Val = CE->getValue(); |
| 2173 | ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add; |
| 2174 | // Special case for #-0 |
| 2175 | if (Val == INT32_MIN) Val = 0; |
| 2176 | if (Val < 0) Val = -Val; |
| 2177 | Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift); |
| 2178 | Inst.addOperand(MCOperand::CreateReg(0)); |
| 2179 | Inst.addOperand(MCOperand::CreateImm(Val)); |
| 2180 | } |
| 2181 | |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 2182 | void addAddrMode3Operands(MCInst &Inst, unsigned N) const { |
| 2183 | assert(N == 3 && "Invalid number of operands!"); |
Jim Grosbach | 8648c10 | 2011-12-19 23:06:24 +0000 | [diff] [blame] | 2184 | // If we have an immediate that's not a constant, treat it as a label |
| 2185 | // reference needing a fixup. If it is a constant, it's something else |
| 2186 | // and we reject it. |
| 2187 | if (isImm()) { |
| 2188 | Inst.addOperand(MCOperand::CreateExpr(getImm())); |
| 2189 | Inst.addOperand(MCOperand::CreateReg(0)); |
| 2190 | Inst.addOperand(MCOperand::CreateImm(0)); |
| 2191 | return; |
| 2192 | } |
| 2193 | |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2194 | int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0; |
| 2195 | if (!Memory.OffsetRegNum) { |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 2196 | ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add; |
| 2197 | // Special case for #-0 |
| 2198 | if (Val == INT32_MIN) Val = 0; |
| 2199 | if (Val < 0) Val = -Val; |
| 2200 | Val = ARM_AM::getAM3Opc(AddSub, Val); |
| 2201 | } else { |
| 2202 | // For register offset, we encode the shift type and negation flag |
| 2203 | // here. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2204 | 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] | 2205 | } |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2206 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
| 2207 | Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum)); |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 2208 | Inst.addOperand(MCOperand::CreateImm(Val)); |
| 2209 | } |
| 2210 | |
| 2211 | void addAM3OffsetOperands(MCInst &Inst, unsigned N) const { |
| 2212 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2213 | if (Kind == k_PostIndexRegister) { |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 2214 | int32_t Val = |
| 2215 | ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0); |
| 2216 | Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum)); |
| 2217 | Inst.addOperand(MCOperand::CreateImm(Val)); |
Jim Grosbach | 1d9d5e9 | 2011-08-10 21:56:18 +0000 | [diff] [blame] | 2218 | return; |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 2219 | } |
| 2220 | |
| 2221 | // Constant offset. |
| 2222 | const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm()); |
| 2223 | int32_t Val = CE->getValue(); |
| 2224 | ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add; |
| 2225 | // Special case for #-0 |
| 2226 | if (Val == INT32_MIN) Val = 0; |
| 2227 | if (Val < 0) Val = -Val; |
Jim Grosbach | 1d9d5e9 | 2011-08-10 21:56:18 +0000 | [diff] [blame] | 2228 | Val = ARM_AM::getAM3Opc(AddSub, Val); |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 2229 | Inst.addOperand(MCOperand::CreateReg(0)); |
| 2230 | Inst.addOperand(MCOperand::CreateImm(Val)); |
| 2231 | } |
| 2232 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2233 | void addAddrMode5Operands(MCInst &Inst, unsigned N) const { |
| 2234 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | fb2f1d6 | 2011-11-01 01:24:45 +0000 | [diff] [blame] | 2235 | // If we have an immediate that's not a constant, treat it as a label |
| 2236 | // reference needing a fixup. If it is a constant, it's something else |
| 2237 | // and we reject it. |
| 2238 | if (isImm()) { |
| 2239 | Inst.addOperand(MCOperand::CreateExpr(getImm())); |
| 2240 | Inst.addOperand(MCOperand::CreateImm(0)); |
| 2241 | return; |
| 2242 | } |
| 2243 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2244 | // 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] | 2245 | int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2246 | ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add; |
| 2247 | // Special case for #-0 |
| 2248 | if (Val == INT32_MIN) Val = 0; |
| 2249 | if (Val < 0) Val = -Val; |
| 2250 | Val = ARM_AM::getAM5Opc(AddSub, Val); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2251 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2252 | Inst.addOperand(MCOperand::CreateImm(Val)); |
Bruno Cardoso Lopes | bda3632 | 2011-04-04 17:18:19 +0000 | [diff] [blame] | 2253 | } |
| 2254 | |
Jim Grosbach | 7db8d69 | 2011-09-08 22:07:06 +0000 | [diff] [blame] | 2255 | void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const { |
| 2256 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | 8648c10 | 2011-12-19 23:06:24 +0000 | [diff] [blame] | 2257 | // If we have an immediate that's not a constant, treat it as a label |
| 2258 | // reference needing a fixup. If it is a constant, it's something else |
| 2259 | // and we reject it. |
| 2260 | if (isImm()) { |
| 2261 | Inst.addOperand(MCOperand::CreateExpr(getImm())); |
| 2262 | Inst.addOperand(MCOperand::CreateImm(0)); |
| 2263 | return; |
| 2264 | } |
| 2265 | |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2266 | int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0; |
| 2267 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
Jim Grosbach | 7db8d69 | 2011-09-08 22:07:06 +0000 | [diff] [blame] | 2268 | Inst.addOperand(MCOperand::CreateImm(Val)); |
| 2269 | } |
| 2270 | |
Jim Grosbach | a05627e | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 2271 | void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const { |
| 2272 | assert(N == 2 && "Invalid number of operands!"); |
| 2273 | // 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] | 2274 | int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0; |
| 2275 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
Jim Grosbach | a05627e | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 2276 | Inst.addOperand(MCOperand::CreateImm(Val)); |
| 2277 | } |
| 2278 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2279 | void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const { |
| 2280 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2281 | int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0; |
| 2282 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2283 | Inst.addOperand(MCOperand::CreateImm(Val)); |
Chris Lattner | 5d6f6a0 | 2010-10-29 00:27:31 +0000 | [diff] [blame] | 2284 | } |
Daniel Dunbar | 5cd4d0f | 2010-08-11 05:24:50 +0000 | [diff] [blame] | 2285 | |
Jim Grosbach | 2392c53 | 2011-09-07 23:39:14 +0000 | [diff] [blame] | 2286 | void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const { |
| 2287 | addMemImm8OffsetOperands(Inst, N); |
| 2288 | } |
| 2289 | |
Jim Grosbach | 5bfa8ba | 2011-09-07 20:58:57 +0000 | [diff] [blame] | 2290 | void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const { |
Jim Grosbach | 2392c53 | 2011-09-07 23:39:14 +0000 | [diff] [blame] | 2291 | addMemImm8OffsetOperands(Inst, N); |
Jim Grosbach | 5bfa8ba | 2011-09-07 20:58:57 +0000 | [diff] [blame] | 2292 | } |
| 2293 | |
| 2294 | void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const { |
| 2295 | assert(N == 2 && "Invalid number of operands!"); |
| 2296 | // If this is an immediate, it's a label reference. |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 2297 | if (isImm()) { |
Jim Grosbach | 5bfa8ba | 2011-09-07 20:58:57 +0000 | [diff] [blame] | 2298 | addExpr(Inst, getImm()); |
| 2299 | Inst.addOperand(MCOperand::CreateImm(0)); |
| 2300 | return; |
| 2301 | } |
| 2302 | |
| 2303 | // Otherwise, it's a normal memory reg+offset. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2304 | int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0; |
| 2305 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
Jim Grosbach | 5bfa8ba | 2011-09-07 20:58:57 +0000 | [diff] [blame] | 2306 | Inst.addOperand(MCOperand::CreateImm(Val)); |
| 2307 | } |
| 2308 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2309 | void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const { |
| 2310 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | 95466ce | 2011-08-08 20:59:31 +0000 | [diff] [blame] | 2311 | // If this is an immediate, it's a label reference. |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 2312 | if (isImm()) { |
Jim Grosbach | 95466ce | 2011-08-08 20:59:31 +0000 | [diff] [blame] | 2313 | addExpr(Inst, getImm()); |
| 2314 | Inst.addOperand(MCOperand::CreateImm(0)); |
| 2315 | return; |
| 2316 | } |
| 2317 | |
| 2318 | // Otherwise, it's a normal memory reg+offset. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2319 | int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0; |
| 2320 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2321 | Inst.addOperand(MCOperand::CreateImm(Val)); |
Bill Wendling | 092a7bd | 2010-12-14 03:36:38 +0000 | [diff] [blame] | 2322 | } |
Bill Wendling | 811c936 | 2010-11-30 07:44:32 +0000 | [diff] [blame] | 2323 | |
Jim Grosbach | 05541f4 | 2011-09-19 22:21:13 +0000 | [diff] [blame] | 2324 | void addMemTBBOperands(MCInst &Inst, unsigned N) const { |
| 2325 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2326 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
| 2327 | Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum)); |
Jim Grosbach | 05541f4 | 2011-09-19 22:21:13 +0000 | [diff] [blame] | 2328 | } |
| 2329 | |
| 2330 | void addMemTBHOperands(MCInst &Inst, unsigned N) const { |
| 2331 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2332 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
| 2333 | Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum)); |
Jim Grosbach | 05541f4 | 2011-09-19 22:21:13 +0000 | [diff] [blame] | 2334 | } |
| 2335 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2336 | void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const { |
| 2337 | assert(N == 3 && "Invalid number of operands!"); |
Jim Grosbach | ee201fa | 2011-11-14 17:52:47 +0000 | [diff] [blame] | 2338 | unsigned Val = |
| 2339 | ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, |
| 2340 | Memory.ShiftImm, Memory.ShiftType); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2341 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
| 2342 | Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum)); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2343 | Inst.addOperand(MCOperand::CreateImm(Val)); |
| 2344 | } |
| 2345 | |
Jim Grosbach | e0ebc1c | 2011-09-07 23:10:15 +0000 | [diff] [blame] | 2346 | void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const { |
| 2347 | assert(N == 3 && "Invalid number of operands!"); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2348 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
| 2349 | Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum)); |
| 2350 | Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm)); |
Jim Grosbach | e0ebc1c | 2011-09-07 23:10:15 +0000 | [diff] [blame] | 2351 | } |
| 2352 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2353 | void addMemThumbRROperands(MCInst &Inst, unsigned N) const { |
| 2354 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2355 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
| 2356 | Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum)); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2357 | } |
| 2358 | |
Jim Grosbach | 3fe94e3 | 2011-08-19 17:55:24 +0000 | [diff] [blame] | 2359 | void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const { |
| 2360 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2361 | int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0; |
| 2362 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
Jim Grosbach | 3fe94e3 | 2011-08-19 17:55:24 +0000 | [diff] [blame] | 2363 | Inst.addOperand(MCOperand::CreateImm(Val)); |
| 2364 | } |
| 2365 | |
Jim Grosbach | 26d3587 | 2011-08-19 18:55:51 +0000 | [diff] [blame] | 2366 | void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const { |
| 2367 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2368 | int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0; |
| 2369 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
Jim Grosbach | 26d3587 | 2011-08-19 18:55:51 +0000 | [diff] [blame] | 2370 | Inst.addOperand(MCOperand::CreateImm(Val)); |
| 2371 | } |
| 2372 | |
Jim Grosbach | a32c753 | 2011-08-19 18:49:59 +0000 | [diff] [blame] | 2373 | void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const { |
| 2374 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2375 | int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0; |
| 2376 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
Jim Grosbach | a32c753 | 2011-08-19 18:49:59 +0000 | [diff] [blame] | 2377 | Inst.addOperand(MCOperand::CreateImm(Val)); |
| 2378 | } |
| 2379 | |
Jim Grosbach | 23983d6 | 2011-08-19 18:13:48 +0000 | [diff] [blame] | 2380 | void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const { |
| 2381 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2382 | int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0; |
| 2383 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
Jim Grosbach | 23983d6 | 2011-08-19 18:13:48 +0000 | [diff] [blame] | 2384 | Inst.addOperand(MCOperand::CreateImm(Val)); |
| 2385 | } |
| 2386 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2387 | void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const { |
| 2388 | assert(N == 1 && "Invalid number of operands!"); |
| 2389 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2390 | assert(CE && "non-constant post-idx-imm8 operand!"); |
| 2391 | int Imm = CE->getValue(); |
| 2392 | bool isAdd = Imm >= 0; |
Owen Anderson | f02d98d | 2011-08-29 17:17:09 +0000 | [diff] [blame] | 2393 | if (Imm == INT32_MIN) Imm = 0; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2394 | Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8; |
| 2395 | Inst.addOperand(MCOperand::CreateImm(Imm)); |
| 2396 | } |
| 2397 | |
Jim Grosbach | 9398141 | 2011-10-11 21:55:36 +0000 | [diff] [blame] | 2398 | void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const { |
| 2399 | assert(N == 1 && "Invalid number of operands!"); |
| 2400 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2401 | assert(CE && "non-constant post-idx-imm8s4 operand!"); |
| 2402 | int Imm = CE->getValue(); |
| 2403 | bool isAdd = Imm >= 0; |
| 2404 | if (Imm == INT32_MIN) Imm = 0; |
| 2405 | // Immediate is scaled by 4. |
| 2406 | Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8; |
| 2407 | Inst.addOperand(MCOperand::CreateImm(Imm)); |
| 2408 | } |
| 2409 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2410 | void addPostIdxRegOperands(MCInst &Inst, unsigned N) const { |
| 2411 | assert(N == 2 && "Invalid number of operands!"); |
| 2412 | Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum)); |
Jim Grosbach | c320c85 | 2011-08-05 21:28:30 +0000 | [diff] [blame] | 2413 | Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd)); |
| 2414 | } |
| 2415 | |
| 2416 | void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const { |
| 2417 | assert(N == 2 && "Invalid number of operands!"); |
| 2418 | Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum)); |
| 2419 | // The sign, shift type, and shift amount are encoded in a single operand |
| 2420 | // using the AM2 encoding helpers. |
| 2421 | ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub; |
| 2422 | unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm, |
| 2423 | PostIdxReg.ShiftTy); |
| 2424 | Inst.addOperand(MCOperand::CreateImm(Imm)); |
Bill Wendling | 811c936 | 2010-11-30 07:44:32 +0000 | [diff] [blame] | 2425 | } |
| 2426 | |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 2427 | void addMSRMaskOperands(MCInst &Inst, unsigned N) const { |
| 2428 | assert(N == 1 && "Invalid number of operands!"); |
| 2429 | Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask()))); |
| 2430 | } |
| 2431 | |
Tim Northover | ee843ef | 2014-08-15 10:47:12 +0000 | [diff] [blame] | 2432 | void addBankedRegOperands(MCInst &Inst, unsigned N) const { |
| 2433 | assert(N == 1 && "Invalid number of operands!"); |
| 2434 | Inst.addOperand(MCOperand::CreateImm(unsigned(getBankedReg()))); |
| 2435 | } |
| 2436 | |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 2437 | void addProcIFlagsOperands(MCInst &Inst, unsigned N) const { |
| 2438 | assert(N == 1 && "Invalid number of operands!"); |
| 2439 | Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags()))); |
| 2440 | } |
| 2441 | |
Jim Grosbach | 182b6a0 | 2011-11-29 23:51:09 +0000 | [diff] [blame] | 2442 | void addVecListOperands(MCInst &Inst, unsigned N) const { |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 2443 | assert(N == 1 && "Invalid number of operands!"); |
| 2444 | Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum)); |
| 2445 | } |
| 2446 | |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 2447 | void addVecListIndexedOperands(MCInst &Inst, unsigned N) const { |
| 2448 | assert(N == 2 && "Invalid number of operands!"); |
| 2449 | Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum)); |
| 2450 | Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex)); |
| 2451 | } |
| 2452 | |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 2453 | void addVectorIndex8Operands(MCInst &Inst, unsigned N) const { |
| 2454 | assert(N == 1 && "Invalid number of operands!"); |
| 2455 | Inst.addOperand(MCOperand::CreateImm(getVectorIndex())); |
| 2456 | } |
| 2457 | |
| 2458 | void addVectorIndex16Operands(MCInst &Inst, unsigned N) const { |
| 2459 | assert(N == 1 && "Invalid number of operands!"); |
| 2460 | Inst.addOperand(MCOperand::CreateImm(getVectorIndex())); |
| 2461 | } |
| 2462 | |
| 2463 | void addVectorIndex32Operands(MCInst &Inst, unsigned N) const { |
| 2464 | assert(N == 1 && "Invalid number of operands!"); |
| 2465 | Inst.addOperand(MCOperand::CreateImm(getVectorIndex())); |
| 2466 | } |
| 2467 | |
Jim Grosbach | 741cd73 | 2011-10-17 22:26:03 +0000 | [diff] [blame] | 2468 | void addNEONi8splatOperands(MCInst &Inst, unsigned N) const { |
| 2469 | assert(N == 1 && "Invalid number of operands!"); |
| 2470 | // The immediate encodes the type of constant as well as the value. |
| 2471 | // Mask in that this is an i8 splat. |
| 2472 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2473 | Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00)); |
| 2474 | } |
| 2475 | |
Jim Grosbach | cda32ae | 2011-10-17 23:09:09 +0000 | [diff] [blame] | 2476 | void addNEONi16splatOperands(MCInst &Inst, unsigned N) const { |
| 2477 | assert(N == 1 && "Invalid number of operands!"); |
| 2478 | // The immediate encodes the type of constant as well as the value. |
| 2479 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2480 | unsigned Value = CE->getValue(); |
Renato Golin | f5dd1da | 2014-09-25 11:31:24 +0000 | [diff] [blame] | 2481 | Value = ARM_AM::encodeNEONi16splat(Value); |
| 2482 | Inst.addOperand(MCOperand::CreateImm(Value)); |
| 2483 | } |
| 2484 | |
| 2485 | void addNEONi16splatNotOperands(MCInst &Inst, unsigned N) const { |
| 2486 | assert(N == 1 && "Invalid number of operands!"); |
| 2487 | // The immediate encodes the type of constant as well as the value. |
| 2488 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2489 | unsigned Value = CE->getValue(); |
| 2490 | Value = ARM_AM::encodeNEONi16splat(~Value & 0xffff); |
Jim Grosbach | cda32ae | 2011-10-17 23:09:09 +0000 | [diff] [blame] | 2491 | Inst.addOperand(MCOperand::CreateImm(Value)); |
| 2492 | } |
| 2493 | |
Jim Grosbach | 8211c05 | 2011-10-18 00:22:00 +0000 | [diff] [blame] | 2494 | void addNEONi32splatOperands(MCInst &Inst, unsigned N) const { |
| 2495 | assert(N == 1 && "Invalid number of operands!"); |
| 2496 | // The immediate encodes the type of constant as well as the value. |
| 2497 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2498 | unsigned Value = CE->getValue(); |
Renato Golin | f5dd1da | 2014-09-25 11:31:24 +0000 | [diff] [blame] | 2499 | Value = ARM_AM::encodeNEONi32splat(Value); |
| 2500 | Inst.addOperand(MCOperand::CreateImm(Value)); |
| 2501 | } |
| 2502 | |
| 2503 | void addNEONi32splatNotOperands(MCInst &Inst, unsigned N) const { |
| 2504 | assert(N == 1 && "Invalid number of operands!"); |
| 2505 | // The immediate encodes the type of constant as well as the value. |
| 2506 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2507 | unsigned Value = CE->getValue(); |
| 2508 | Value = ARM_AM::encodeNEONi32splat(~Value); |
Jim Grosbach | 8211c05 | 2011-10-18 00:22:00 +0000 | [diff] [blame] | 2509 | Inst.addOperand(MCOperand::CreateImm(Value)); |
| 2510 | } |
| 2511 | |
Stepan Dyatkovskiy | 00dcc0f | 2014-04-24 06:03:01 +0000 | [diff] [blame] | 2512 | void addNEONinvByteReplicateOperands(MCInst &Inst, unsigned N) const { |
| 2513 | assert(N == 1 && "Invalid number of operands!"); |
| 2514 | // The immediate encodes the type of constant as well as the value. |
| 2515 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2516 | unsigned Value = CE->getValue(); |
| 2517 | assert((Inst.getOpcode() == ARM::VMOVv8i8 || |
| 2518 | Inst.getOpcode() == ARM::VMOVv16i8) && |
| 2519 | "All vmvn instructions that wants to replicate non-zero byte " |
| 2520 | "always must be replaced with VMOVv8i8 or VMOVv16i8."); |
| 2521 | unsigned B = ((~Value) & 0xff); |
| 2522 | B |= 0xe00; // cmode = 0b1110 |
| 2523 | Inst.addOperand(MCOperand::CreateImm(B)); |
| 2524 | } |
Jim Grosbach | 8211c05 | 2011-10-18 00:22:00 +0000 | [diff] [blame] | 2525 | void addNEONi32vmovOperands(MCInst &Inst, unsigned N) const { |
| 2526 | assert(N == 1 && "Invalid number of operands!"); |
| 2527 | // The immediate encodes the type of constant as well as the value. |
| 2528 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2529 | unsigned Value = CE->getValue(); |
| 2530 | if (Value >= 256 && Value <= 0xffff) |
| 2531 | Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200); |
| 2532 | else if (Value > 0xffff && Value <= 0xffffff) |
| 2533 | Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400); |
| 2534 | else if (Value > 0xffffff) |
| 2535 | Value = (Value >> 24) | 0x600; |
| 2536 | Inst.addOperand(MCOperand::CreateImm(Value)); |
| 2537 | } |
| 2538 | |
Stepan Dyatkovskiy | 00dcc0f | 2014-04-24 06:03:01 +0000 | [diff] [blame] | 2539 | void addNEONvmovByteReplicateOperands(MCInst &Inst, unsigned N) const { |
| 2540 | assert(N == 1 && "Invalid number of operands!"); |
| 2541 | // The immediate encodes the type of constant as well as the value. |
| 2542 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2543 | unsigned Value = CE->getValue(); |
| 2544 | assert((Inst.getOpcode() == ARM::VMOVv8i8 || |
| 2545 | Inst.getOpcode() == ARM::VMOVv16i8) && |
| 2546 | "All instructions that wants to replicate non-zero byte " |
| 2547 | "always must be replaced with VMOVv8i8 or VMOVv16i8."); |
| 2548 | unsigned B = Value & 0xff; |
| 2549 | B |= 0xe00; // cmode = 0b1110 |
| 2550 | Inst.addOperand(MCOperand::CreateImm(B)); |
| 2551 | } |
Jim Grosbach | 045b6c7 | 2011-12-19 23:51:07 +0000 | [diff] [blame] | 2552 | void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const { |
| 2553 | assert(N == 1 && "Invalid number of operands!"); |
| 2554 | // The immediate encodes the type of constant as well as the value. |
| 2555 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2556 | unsigned Value = ~CE->getValue(); |
| 2557 | if (Value >= 256 && Value <= 0xffff) |
| 2558 | Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200); |
| 2559 | else if (Value > 0xffff && Value <= 0xffffff) |
| 2560 | Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400); |
| 2561 | else if (Value > 0xffffff) |
| 2562 | Value = (Value >> 24) | 0x600; |
| 2563 | Inst.addOperand(MCOperand::CreateImm(Value)); |
| 2564 | } |
| 2565 | |
Jim Grosbach | e4454e0 | 2011-10-18 16:18:11 +0000 | [diff] [blame] | 2566 | void addNEONi64splatOperands(MCInst &Inst, unsigned N) const { |
| 2567 | assert(N == 1 && "Invalid number of operands!"); |
| 2568 | // The immediate encodes the type of constant as well as the value. |
| 2569 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2570 | uint64_t Value = CE->getValue(); |
| 2571 | unsigned Imm = 0; |
| 2572 | for (unsigned i = 0; i < 8; ++i, Value >>= 8) { |
| 2573 | Imm |= (Value & 1) << i; |
| 2574 | } |
| 2575 | Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00)); |
| 2576 | } |
| 2577 | |
Craig Topper | ca7e3e5 | 2014-03-10 03:19:03 +0000 | [diff] [blame] | 2578 | void print(raw_ostream &OS) const override; |
Daniel Dunbar | ebace22 | 2010-08-11 06:37:04 +0000 | [diff] [blame] | 2579 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2580 | static std::unique_ptr<ARMOperand> CreateITMask(unsigned Mask, SMLoc S) { |
| 2581 | auto Op = make_unique<ARMOperand>(k_ITCondMask); |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 2582 | Op->ITMask.Mask = Mask; |
| 2583 | Op->StartLoc = S; |
| 2584 | Op->EndLoc = S; |
| 2585 | return Op; |
| 2586 | } |
| 2587 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2588 | static std::unique_ptr<ARMOperand> CreateCondCode(ARMCC::CondCodes CC, |
| 2589 | SMLoc S) { |
| 2590 | auto Op = make_unique<ARMOperand>(k_CondCode); |
Daniel Dunbar | 188b47b | 2010-08-11 06:37:20 +0000 | [diff] [blame] | 2591 | Op->CC.Val = CC; |
| 2592 | Op->StartLoc = S; |
| 2593 | Op->EndLoc = S; |
Chris Lattner | bd7c9fa | 2010-10-28 17:20:03 +0000 | [diff] [blame] | 2594 | return Op; |
Daniel Dunbar | 188b47b | 2010-08-11 06:37:20 +0000 | [diff] [blame] | 2595 | } |
| 2596 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2597 | static std::unique_ptr<ARMOperand> CreateCoprocNum(unsigned CopVal, SMLoc S) { |
| 2598 | auto Op = make_unique<ARMOperand>(k_CoprocNum); |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 2599 | Op->Cop.Val = CopVal; |
| 2600 | Op->StartLoc = S; |
| 2601 | Op->EndLoc = S; |
| 2602 | return Op; |
| 2603 | } |
| 2604 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2605 | static std::unique_ptr<ARMOperand> CreateCoprocReg(unsigned CopVal, SMLoc S) { |
| 2606 | auto Op = make_unique<ARMOperand>(k_CoprocReg); |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 2607 | Op->Cop.Val = CopVal; |
| 2608 | Op->StartLoc = S; |
| 2609 | Op->EndLoc = S; |
| 2610 | return Op; |
| 2611 | } |
| 2612 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2613 | static std::unique_ptr<ARMOperand> CreateCoprocOption(unsigned Val, SMLoc S, |
| 2614 | SMLoc E) { |
| 2615 | auto Op = make_unique<ARMOperand>(k_CoprocOption); |
Jim Grosbach | 4839958 | 2011-10-12 17:34:41 +0000 | [diff] [blame] | 2616 | Op->Cop.Val = Val; |
| 2617 | Op->StartLoc = S; |
| 2618 | Op->EndLoc = E; |
| 2619 | return Op; |
| 2620 | } |
| 2621 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2622 | static std::unique_ptr<ARMOperand> CreateCCOut(unsigned RegNum, SMLoc S) { |
| 2623 | auto Op = make_unique<ARMOperand>(k_CCOut); |
Jim Grosbach | 0bfb4d5 | 2010-12-06 18:21:12 +0000 | [diff] [blame] | 2624 | Op->Reg.RegNum = RegNum; |
| 2625 | Op->StartLoc = S; |
| 2626 | Op->EndLoc = S; |
| 2627 | return Op; |
| 2628 | } |
| 2629 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2630 | static std::unique_ptr<ARMOperand> CreateToken(StringRef Str, SMLoc S) { |
| 2631 | auto Op = make_unique<ARMOperand>(k_Token); |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 2632 | Op->Tok.Data = Str.data(); |
| 2633 | Op->Tok.Length = Str.size(); |
| 2634 | Op->StartLoc = S; |
| 2635 | Op->EndLoc = S; |
Chris Lattner | bd7c9fa | 2010-10-28 17:20:03 +0000 | [diff] [blame] | 2636 | return Op; |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 2637 | } |
| 2638 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2639 | static std::unique_ptr<ARMOperand> CreateReg(unsigned RegNum, SMLoc S, |
| 2640 | SMLoc E) { |
| 2641 | auto Op = make_unique<ARMOperand>(k_Register); |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 2642 | Op->Reg.RegNum = RegNum; |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 2643 | Op->StartLoc = S; |
| 2644 | Op->EndLoc = E; |
Chris Lattner | bd7c9fa | 2010-10-28 17:20:03 +0000 | [diff] [blame] | 2645 | return Op; |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 2646 | } |
| 2647 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2648 | static std::unique_ptr<ARMOperand> |
| 2649 | CreateShiftedRegister(ARM_AM::ShiftOpc ShTy, unsigned SrcReg, |
| 2650 | unsigned ShiftReg, unsigned ShiftImm, SMLoc S, |
| 2651 | SMLoc E) { |
| 2652 | auto Op = make_unique<ARMOperand>(k_ShiftedRegister); |
Jim Grosbach | ac798e1 | 2011-07-25 20:49:51 +0000 | [diff] [blame] | 2653 | Op->RegShiftedReg.ShiftTy = ShTy; |
| 2654 | Op->RegShiftedReg.SrcReg = SrcReg; |
| 2655 | Op->RegShiftedReg.ShiftReg = ShiftReg; |
| 2656 | Op->RegShiftedReg.ShiftImm = ShiftImm; |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 2657 | Op->StartLoc = S; |
| 2658 | Op->EndLoc = E; |
| 2659 | return Op; |
| 2660 | } |
| 2661 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2662 | static std::unique_ptr<ARMOperand> |
| 2663 | CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy, unsigned SrcReg, |
| 2664 | unsigned ShiftImm, SMLoc S, SMLoc E) { |
| 2665 | auto Op = make_unique<ARMOperand>(k_ShiftedImmediate); |
Jim Grosbach | ac798e1 | 2011-07-25 20:49:51 +0000 | [diff] [blame] | 2666 | Op->RegShiftedImm.ShiftTy = ShTy; |
| 2667 | Op->RegShiftedImm.SrcReg = SrcReg; |
| 2668 | Op->RegShiftedImm.ShiftImm = ShiftImm; |
Owen Anderson | b595ed0 | 2011-07-21 18:54:16 +0000 | [diff] [blame] | 2669 | Op->StartLoc = S; |
| 2670 | Op->EndLoc = E; |
| 2671 | return Op; |
| 2672 | } |
| 2673 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2674 | static std::unique_ptr<ARMOperand> CreateShifterImm(bool isASR, unsigned Imm, |
| 2675 | SMLoc S, SMLoc E) { |
| 2676 | auto Op = make_unique<ARMOperand>(k_ShifterImmediate); |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 2677 | Op->ShifterImm.isASR = isASR; |
| 2678 | Op->ShifterImm.Imm = Imm; |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 2679 | Op->StartLoc = S; |
| 2680 | Op->EndLoc = E; |
| 2681 | return Op; |
| 2682 | } |
| 2683 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2684 | static std::unique_ptr<ARMOperand> CreateRotImm(unsigned Imm, SMLoc S, |
| 2685 | SMLoc E) { |
| 2686 | auto Op = make_unique<ARMOperand>(k_RotateImmediate); |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 2687 | Op->RotImm.Imm = Imm; |
| 2688 | Op->StartLoc = S; |
| 2689 | Op->EndLoc = E; |
| 2690 | return Op; |
| 2691 | } |
| 2692 | |
Asiri Rathnayake | a0199b9 | 2014-12-02 10:53:20 +0000 | [diff] [blame] | 2693 | static std::unique_ptr<ARMOperand> CreateModImm(unsigned Bits, unsigned Rot, |
| 2694 | SMLoc S, SMLoc E) { |
| 2695 | auto Op = make_unique<ARMOperand>(k_ModifiedImmediate); |
| 2696 | Op->ModImm.Bits = Bits; |
| 2697 | Op->ModImm.Rot = Rot; |
| 2698 | Op->StartLoc = S; |
| 2699 | Op->EndLoc = E; |
| 2700 | return Op; |
| 2701 | } |
| 2702 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2703 | static std::unique_ptr<ARMOperand> |
| 2704 | CreateBitfield(unsigned LSB, unsigned Width, SMLoc S, SMLoc E) { |
| 2705 | auto Op = make_unique<ARMOperand>(k_BitfieldDescriptor); |
Jim Grosbach | 864b609 | 2011-07-28 21:34:26 +0000 | [diff] [blame] | 2706 | Op->Bitfield.LSB = LSB; |
| 2707 | Op->Bitfield.Width = Width; |
| 2708 | Op->StartLoc = S; |
| 2709 | Op->EndLoc = E; |
| 2710 | return Op; |
| 2711 | } |
| 2712 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2713 | static std::unique_ptr<ARMOperand> |
| 2714 | CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned>> &Regs, |
Matt Beaumont-Gay | 55c4cc7 | 2010-11-10 00:08:58 +0000 | [diff] [blame] | 2715 | SMLoc StartLoc, SMLoc EndLoc) { |
Chad Rosier | fa705ee | 2013-07-01 20:49:23 +0000 | [diff] [blame] | 2716 | assert (Regs.size() > 0 && "RegList contains no registers?"); |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2717 | KindTy Kind = k_RegisterList; |
Bill Wendling | 9898ac9 | 2010-11-17 04:32:08 +0000 | [diff] [blame] | 2718 | |
Chad Rosier | fa705ee | 2013-07-01 20:49:23 +0000 | [diff] [blame] | 2719 | if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second)) |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2720 | Kind = k_DPRRegisterList; |
Jim Grosbach | 75461af | 2011-09-13 22:56:44 +0000 | [diff] [blame] | 2721 | else if (ARMMCRegisterClasses[ARM::SPRRegClassID]. |
Chad Rosier | fa705ee | 2013-07-01 20:49:23 +0000 | [diff] [blame] | 2722 | contains(Regs.front().second)) |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2723 | Kind = k_SPRRegisterList; |
Bill Wendling | 9898ac9 | 2010-11-17 04:32:08 +0000 | [diff] [blame] | 2724 | |
Chad Rosier | fa705ee | 2013-07-01 20:49:23 +0000 | [diff] [blame] | 2725 | // Sort based on the register encoding values. |
| 2726 | array_pod_sort(Regs.begin(), Regs.end()); |
| 2727 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2728 | auto Op = make_unique<ARMOperand>(Kind); |
Chad Rosier | fa705ee | 2013-07-01 20:49:23 +0000 | [diff] [blame] | 2729 | for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator |
Bill Wendling | 2cae327 | 2010-11-09 22:44:22 +0000 | [diff] [blame] | 2730 | I = Regs.begin(), E = Regs.end(); I != E; ++I) |
Chad Rosier | fa705ee | 2013-07-01 20:49:23 +0000 | [diff] [blame] | 2731 | Op->Registers.push_back(I->second); |
Matt Beaumont-Gay | 55c4cc7 | 2010-11-10 00:08:58 +0000 | [diff] [blame] | 2732 | Op->StartLoc = StartLoc; |
| 2733 | Op->EndLoc = EndLoc; |
Bill Wendling | 7cef447 | 2010-11-06 19:56:04 +0000 | [diff] [blame] | 2734 | return Op; |
| 2735 | } |
| 2736 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2737 | static std::unique_ptr<ARMOperand> CreateVectorList(unsigned RegNum, |
| 2738 | unsigned Count, |
| 2739 | bool isDoubleSpaced, |
| 2740 | SMLoc S, SMLoc E) { |
| 2741 | auto Op = make_unique<ARMOperand>(k_VectorList); |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 2742 | Op->VectorList.RegNum = RegNum; |
| 2743 | Op->VectorList.Count = Count; |
Jim Grosbach | 2f50e92 | 2011-12-15 21:44:33 +0000 | [diff] [blame] | 2744 | Op->VectorList.isDoubleSpaced = isDoubleSpaced; |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 2745 | Op->StartLoc = S; |
| 2746 | Op->EndLoc = E; |
| 2747 | return Op; |
| 2748 | } |
| 2749 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2750 | static std::unique_ptr<ARMOperand> |
| 2751 | CreateVectorListAllLanes(unsigned RegNum, unsigned Count, bool isDoubleSpaced, |
| 2752 | SMLoc S, SMLoc E) { |
| 2753 | auto Op = make_unique<ARMOperand>(k_VectorListAllLanes); |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 2754 | Op->VectorList.RegNum = RegNum; |
| 2755 | Op->VectorList.Count = Count; |
Jim Grosbach | c5af54e | 2011-12-21 00:38:54 +0000 | [diff] [blame] | 2756 | Op->VectorList.isDoubleSpaced = isDoubleSpaced; |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 2757 | Op->StartLoc = S; |
| 2758 | Op->EndLoc = E; |
| 2759 | return Op; |
| 2760 | } |
| 2761 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2762 | static std::unique_ptr<ARMOperand> |
| 2763 | CreateVectorListIndexed(unsigned RegNum, unsigned Count, unsigned Index, |
| 2764 | bool isDoubleSpaced, SMLoc S, SMLoc E) { |
| 2765 | auto Op = make_unique<ARMOperand>(k_VectorListIndexed); |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 2766 | Op->VectorList.RegNum = RegNum; |
| 2767 | Op->VectorList.Count = Count; |
| 2768 | Op->VectorList.LaneIndex = Index; |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 2769 | Op->VectorList.isDoubleSpaced = isDoubleSpaced; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 2770 | Op->StartLoc = S; |
| 2771 | Op->EndLoc = E; |
| 2772 | return Op; |
| 2773 | } |
| 2774 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2775 | static std::unique_ptr<ARMOperand> |
| 2776 | CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E, MCContext &Ctx) { |
| 2777 | auto Op = make_unique<ARMOperand>(k_VectorIndex); |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 2778 | Op->VectorIndex.Val = Idx; |
| 2779 | Op->StartLoc = S; |
| 2780 | Op->EndLoc = E; |
| 2781 | return Op; |
| 2782 | } |
| 2783 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2784 | static std::unique_ptr<ARMOperand> CreateImm(const MCExpr *Val, SMLoc S, |
| 2785 | SMLoc E) { |
| 2786 | auto Op = make_unique<ARMOperand>(k_Immediate); |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 2787 | Op->Imm.Val = Val; |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 2788 | Op->StartLoc = S; |
| 2789 | Op->EndLoc = E; |
Chris Lattner | bd7c9fa | 2010-10-28 17:20:03 +0000 | [diff] [blame] | 2790 | return Op; |
Kevin Enderby | f507994 | 2009-10-13 22:19:02 +0000 | [diff] [blame] | 2791 | } |
| 2792 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2793 | static std::unique_ptr<ARMOperand> |
| 2794 | CreateMem(unsigned BaseRegNum, const MCConstantExpr *OffsetImm, |
| 2795 | unsigned OffsetRegNum, ARM_AM::ShiftOpc ShiftType, |
| 2796 | unsigned ShiftImm, unsigned Alignment, bool isNegative, SMLoc S, |
| 2797 | SMLoc E, SMLoc AlignmentLoc = SMLoc()) { |
| 2798 | auto Op = make_unique<ARMOperand>(k_Memory); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2799 | Op->Memory.BaseRegNum = BaseRegNum; |
| 2800 | Op->Memory.OffsetImm = OffsetImm; |
| 2801 | Op->Memory.OffsetRegNum = OffsetRegNum; |
| 2802 | Op->Memory.ShiftType = ShiftType; |
| 2803 | Op->Memory.ShiftImm = ShiftImm; |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 2804 | Op->Memory.Alignment = Alignment; |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2805 | Op->Memory.isNegative = isNegative; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2806 | Op->StartLoc = S; |
| 2807 | Op->EndLoc = E; |
Kevin Enderby | 488f20b | 2014-04-10 20:18:58 +0000 | [diff] [blame] | 2808 | Op->AlignmentLoc = AlignmentLoc; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2809 | return Op; |
| 2810 | } |
Jim Grosbach | 624bcc7 | 2010-10-29 14:46:02 +0000 | [diff] [blame] | 2811 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2812 | static std::unique_ptr<ARMOperand> |
| 2813 | CreatePostIdxReg(unsigned RegNum, bool isAdd, ARM_AM::ShiftOpc ShiftTy, |
| 2814 | unsigned ShiftImm, SMLoc S, SMLoc E) { |
| 2815 | auto Op = make_unique<ARMOperand>(k_PostIndexRegister); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2816 | Op->PostIdxReg.RegNum = RegNum; |
Jim Grosbach | c320c85 | 2011-08-05 21:28:30 +0000 | [diff] [blame] | 2817 | Op->PostIdxReg.isAdd = isAdd; |
| 2818 | Op->PostIdxReg.ShiftTy = ShiftTy; |
| 2819 | Op->PostIdxReg.ShiftImm = ShiftImm; |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 2820 | Op->StartLoc = S; |
| 2821 | Op->EndLoc = E; |
Chris Lattner | bd7c9fa | 2010-10-28 17:20:03 +0000 | [diff] [blame] | 2822 | return Op; |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 2823 | } |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 2824 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2825 | static std::unique_ptr<ARMOperand> CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, |
| 2826 | SMLoc S) { |
| 2827 | auto Op = make_unique<ARMOperand>(k_MemBarrierOpt); |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 2828 | Op->MBOpt.Val = Opt; |
| 2829 | Op->StartLoc = S; |
| 2830 | Op->EndLoc = S; |
| 2831 | return Op; |
| 2832 | } |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 2833 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2834 | static std::unique_ptr<ARMOperand> |
| 2835 | CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt, SMLoc S) { |
| 2836 | auto Op = make_unique<ARMOperand>(k_InstSyncBarrierOpt); |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 2837 | Op->ISBOpt.Val = Opt; |
| 2838 | Op->StartLoc = S; |
| 2839 | Op->EndLoc = S; |
| 2840 | return Op; |
| 2841 | } |
| 2842 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2843 | static std::unique_ptr<ARMOperand> CreateProcIFlags(ARM_PROC::IFlags IFlags, |
| 2844 | SMLoc S) { |
| 2845 | auto Op = make_unique<ARMOperand>(k_ProcIFlags); |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 2846 | Op->IFlags.Val = IFlags; |
| 2847 | Op->StartLoc = S; |
| 2848 | Op->EndLoc = S; |
| 2849 | return Op; |
| 2850 | } |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 2851 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2852 | static std::unique_ptr<ARMOperand> CreateMSRMask(unsigned MMask, SMLoc S) { |
| 2853 | auto Op = make_unique<ARMOperand>(k_MSRMask); |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 2854 | Op->MMask.Val = MMask; |
| 2855 | Op->StartLoc = S; |
| 2856 | Op->EndLoc = S; |
| 2857 | return Op; |
| 2858 | } |
Tim Northover | ee843ef | 2014-08-15 10:47:12 +0000 | [diff] [blame] | 2859 | |
| 2860 | static std::unique_ptr<ARMOperand> CreateBankedReg(unsigned Reg, SMLoc S) { |
| 2861 | auto Op = make_unique<ARMOperand>(k_BankedReg); |
| 2862 | Op->BankedReg.Val = Reg; |
| 2863 | Op->StartLoc = S; |
| 2864 | Op->EndLoc = S; |
| 2865 | return Op; |
| 2866 | } |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 2867 | }; |
| 2868 | |
| 2869 | } // end anonymous namespace. |
| 2870 | |
Jim Grosbach | 602aa90 | 2011-07-13 15:34:57 +0000 | [diff] [blame] | 2871 | void ARMOperand::print(raw_ostream &OS) const { |
Daniel Dunbar | 4a863e6 | 2010-08-11 06:37:12 +0000 | [diff] [blame] | 2872 | switch (Kind) { |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2873 | case k_CondCode: |
Daniel Dunbar | 2be732a | 2011-01-10 15:26:21 +0000 | [diff] [blame] | 2874 | OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">"; |
Daniel Dunbar | 4a863e6 | 2010-08-11 06:37:12 +0000 | [diff] [blame] | 2875 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2876 | case k_CCOut: |
Jim Grosbach | 0bfb4d5 | 2010-12-06 18:21:12 +0000 | [diff] [blame] | 2877 | OS << "<ccout " << getReg() << ">"; |
| 2878 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2879 | case k_ITCondMask: { |
Craig Topper | 42b96d1 | 2012-05-24 04:11:15 +0000 | [diff] [blame] | 2880 | static const char *const MaskStr[] = { |
Benjamin Kramer | 0d6d098 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 2881 | "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)", |
| 2882 | "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)" |
| 2883 | }; |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 2884 | assert((ITMask.Mask & 0xf) == ITMask.Mask); |
| 2885 | OS << "<it-mask " << MaskStr[ITMask.Mask] << ">"; |
| 2886 | break; |
| 2887 | } |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2888 | case k_CoprocNum: |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 2889 | OS << "<coprocessor number: " << getCoproc() << ">"; |
| 2890 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2891 | case k_CoprocReg: |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 2892 | OS << "<coprocessor register: " << getCoproc() << ">"; |
| 2893 | break; |
Jim Grosbach | 4839958 | 2011-10-12 17:34:41 +0000 | [diff] [blame] | 2894 | case k_CoprocOption: |
| 2895 | OS << "<coprocessor option: " << CoprocOption.Val << ">"; |
| 2896 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2897 | case k_MSRMask: |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 2898 | OS << "<mask: " << getMSRMask() << ">"; |
| 2899 | break; |
Tim Northover | ee843ef | 2014-08-15 10:47:12 +0000 | [diff] [blame] | 2900 | case k_BankedReg: |
| 2901 | OS << "<banked reg: " << getBankedReg() << ">"; |
| 2902 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2903 | case k_Immediate: |
Daniel Dunbar | 4a863e6 | 2010-08-11 06:37:12 +0000 | [diff] [blame] | 2904 | getImm()->print(OS); |
| 2905 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2906 | case k_MemBarrierOpt: |
Joey Gouly | 926d3f5 | 2013-09-05 15:35:24 +0000 | [diff] [blame] | 2907 | OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">"; |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 2908 | break; |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 2909 | case k_InstSyncBarrierOpt: |
| 2910 | OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">"; |
| 2911 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2912 | case k_Memory: |
Daniel Dunbar | bcd8eb0 | 2011-01-18 05:55:21 +0000 | [diff] [blame] | 2913 | OS << "<memory " |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2914 | << " base:" << Memory.BaseRegNum; |
Daniel Dunbar | bcd8eb0 | 2011-01-18 05:55:21 +0000 | [diff] [blame] | 2915 | OS << ">"; |
Daniel Dunbar | 4a863e6 | 2010-08-11 06:37:12 +0000 | [diff] [blame] | 2916 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2917 | case k_PostIndexRegister: |
Jim Grosbach | c320c85 | 2011-08-05 21:28:30 +0000 | [diff] [blame] | 2918 | OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-") |
| 2919 | << PostIdxReg.RegNum; |
| 2920 | if (PostIdxReg.ShiftTy != ARM_AM::no_shift) |
| 2921 | OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " " |
| 2922 | << PostIdxReg.ShiftImm; |
| 2923 | OS << ">"; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2924 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2925 | case k_ProcIFlags: { |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 2926 | OS << "<ARM_PROC::"; |
| 2927 | unsigned IFlags = getProcIFlags(); |
| 2928 | for (int i=2; i >= 0; --i) |
| 2929 | if (IFlags & (1 << i)) |
| 2930 | OS << ARM_PROC::IFlagsToString(1 << i); |
| 2931 | OS << ">"; |
| 2932 | break; |
| 2933 | } |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2934 | case k_Register: |
Bill Wendling | 2063b84 | 2010-11-18 23:43:05 +0000 | [diff] [blame] | 2935 | OS << "<register " << getReg() << ">"; |
Daniel Dunbar | 4a863e6 | 2010-08-11 06:37:12 +0000 | [diff] [blame] | 2936 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2937 | case k_ShifterImmediate: |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 2938 | OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl") |
| 2939 | << " #" << ShifterImm.Imm << ">"; |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 2940 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2941 | case k_ShiftedRegister: |
Owen Anderson | b595ed0 | 2011-07-21 18:54:16 +0000 | [diff] [blame] | 2942 | OS << "<so_reg_reg " |
Jim Grosbach | 01e0439 | 2011-11-16 21:46:50 +0000 | [diff] [blame] | 2943 | << RegShiftedReg.SrcReg << " " |
| 2944 | << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy) |
| 2945 | << " " << RegShiftedReg.ShiftReg << ">"; |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 2946 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2947 | case k_ShiftedImmediate: |
Owen Anderson | b595ed0 | 2011-07-21 18:54:16 +0000 | [diff] [blame] | 2948 | OS << "<so_reg_imm " |
Jim Grosbach | 01e0439 | 2011-11-16 21:46:50 +0000 | [diff] [blame] | 2949 | << RegShiftedImm.SrcReg << " " |
| 2950 | << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy) |
| 2951 | << " #" << RegShiftedImm.ShiftImm << ">"; |
Owen Anderson | b595ed0 | 2011-07-21 18:54:16 +0000 | [diff] [blame] | 2952 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2953 | case k_RotateImmediate: |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 2954 | OS << "<ror " << " #" << (RotImm.Imm * 8) << ">"; |
| 2955 | break; |
Asiri Rathnayake | a0199b9 | 2014-12-02 10:53:20 +0000 | [diff] [blame] | 2956 | case k_ModifiedImmediate: |
| 2957 | OS << "<mod_imm #" << ModImm.Bits << ", #" |
| 2958 | << ModImm.Rot << ")>"; |
| 2959 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2960 | case k_BitfieldDescriptor: |
Jim Grosbach | 864b609 | 2011-07-28 21:34:26 +0000 | [diff] [blame] | 2961 | OS << "<bitfield " << "lsb: " << Bitfield.LSB |
| 2962 | << ", width: " << Bitfield.Width << ">"; |
| 2963 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2964 | case k_RegisterList: |
| 2965 | case k_DPRRegisterList: |
| 2966 | case k_SPRRegisterList: { |
Bill Wendling | 7cef447 | 2010-11-06 19:56:04 +0000 | [diff] [blame] | 2967 | OS << "<register_list "; |
Bill Wendling | 7cef447 | 2010-11-06 19:56:04 +0000 | [diff] [blame] | 2968 | |
Bill Wendling | bed9465 | 2010-11-09 23:28:44 +0000 | [diff] [blame] | 2969 | const SmallVectorImpl<unsigned> &RegList = getRegList(); |
| 2970 | for (SmallVectorImpl<unsigned>::const_iterator |
Bill Wendling | 2cae327 | 2010-11-09 22:44:22 +0000 | [diff] [blame] | 2971 | I = RegList.begin(), E = RegList.end(); I != E; ) { |
| 2972 | OS << *I; |
| 2973 | if (++I < E) OS << ", "; |
Bill Wendling | 7cef447 | 2010-11-06 19:56:04 +0000 | [diff] [blame] | 2974 | } |
| 2975 | |
| 2976 | OS << ">"; |
| 2977 | break; |
| 2978 | } |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 2979 | case k_VectorList: |
| 2980 | OS << "<vector_list " << VectorList.Count << " * " |
| 2981 | << VectorList.RegNum << ">"; |
| 2982 | break; |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 2983 | case k_VectorListAllLanes: |
| 2984 | OS << "<vector_list(all lanes) " << VectorList.Count << " * " |
| 2985 | << VectorList.RegNum << ">"; |
| 2986 | break; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 2987 | case k_VectorListIndexed: |
| 2988 | OS << "<vector_list(lane " << VectorList.LaneIndex << ") " |
| 2989 | << VectorList.Count << " * " << VectorList.RegNum << ">"; |
| 2990 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2991 | case k_Token: |
Daniel Dunbar | 4a863e6 | 2010-08-11 06:37:12 +0000 | [diff] [blame] | 2992 | OS << "'" << getToken() << "'"; |
| 2993 | break; |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 2994 | case k_VectorIndex: |
| 2995 | OS << "<vectorindex " << getVectorIndex() << ">"; |
| 2996 | break; |
Daniel Dunbar | 4a863e6 | 2010-08-11 06:37:12 +0000 | [diff] [blame] | 2997 | } |
| 2998 | } |
Daniel Dunbar | 5cd4d0f | 2010-08-11 05:24:50 +0000 | [diff] [blame] | 2999 | |
| 3000 | /// @name Auto-generated Match Functions |
| 3001 | /// { |
| 3002 | |
| 3003 | static unsigned MatchRegisterName(StringRef Name); |
| 3004 | |
| 3005 | /// } |
| 3006 | |
Bob Wilson | fb0bd04 | 2011-02-03 21:46:10 +0000 | [diff] [blame] | 3007 | bool ARMAsmParser::ParseRegister(unsigned &RegNo, |
| 3008 | SMLoc &StartLoc, SMLoc &EndLoc) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 3009 | const AsmToken &Tok = getParser().getTok(); |
| 3010 | StartLoc = Tok.getLoc(); |
| 3011 | EndLoc = Tok.getEndLoc(); |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 3012 | RegNo = tryParseRegister(); |
Roman Divacky | 36b1b47 | 2011-01-27 17:14:22 +0000 | [diff] [blame] | 3013 | |
| 3014 | return (RegNo == (unsigned)-1); |
| 3015 | } |
| 3016 | |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 3017 | /// 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] | 3018 | /// and if it is a register name the token is eaten and the register number is |
| 3019 | /// returned. Otherwise return -1. |
| 3020 | /// |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 3021 | int ARMAsmParser::tryParseRegister() { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 3022 | MCAsmParser &Parser = getParser(); |
Chris Lattner | 44e5981c | 2010-10-30 04:09:10 +0000 | [diff] [blame] | 3023 | const AsmToken &Tok = Parser.getTok(); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 3024 | if (Tok.isNot(AsmToken::Identifier)) return -1; |
Jim Grosbach | 99710a8 | 2010-11-01 16:44:21 +0000 | [diff] [blame] | 3025 | |
Benjamin Kramer | 20baffb | 2011-11-06 20:37:06 +0000 | [diff] [blame] | 3026 | std::string lowerCase = Tok.getString().lower(); |
Owen Anderson | a098d15 | 2011-01-13 22:50:36 +0000 | [diff] [blame] | 3027 | unsigned RegNum = MatchRegisterName(lowerCase); |
| 3028 | if (!RegNum) { |
| 3029 | RegNum = StringSwitch<unsigned>(lowerCase) |
| 3030 | .Case("r13", ARM::SP) |
| 3031 | .Case("r14", ARM::LR) |
| 3032 | .Case("r15", ARM::PC) |
| 3033 | .Case("ip", ARM::R12) |
Jim Grosbach | 4edc736 | 2011-12-08 19:27:38 +0000 | [diff] [blame] | 3034 | // Additional register name aliases for 'gas' compatibility. |
| 3035 | .Case("a1", ARM::R0) |
| 3036 | .Case("a2", ARM::R1) |
| 3037 | .Case("a3", ARM::R2) |
| 3038 | .Case("a4", ARM::R3) |
| 3039 | .Case("v1", ARM::R4) |
| 3040 | .Case("v2", ARM::R5) |
| 3041 | .Case("v3", ARM::R6) |
| 3042 | .Case("v4", ARM::R7) |
| 3043 | .Case("v5", ARM::R8) |
| 3044 | .Case("v6", ARM::R9) |
| 3045 | .Case("v7", ARM::R10) |
| 3046 | .Case("v8", ARM::R11) |
| 3047 | .Case("sb", ARM::R9) |
| 3048 | .Case("sl", ARM::R10) |
| 3049 | .Case("fp", ARM::R11) |
Owen Anderson | a098d15 | 2011-01-13 22:50:36 +0000 | [diff] [blame] | 3050 | .Default(0); |
| 3051 | } |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 3052 | if (!RegNum) { |
Jim Grosbach | cd22e4a | 2011-12-20 23:11:00 +0000 | [diff] [blame] | 3053 | // Check for aliases registered via .req. Canonicalize to lower case. |
| 3054 | // That's more consistent since register names are case insensitive, and |
| 3055 | // it's how the original entry was passed in from MC/MCParser/AsmParser. |
| 3056 | StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase); |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 3057 | // If no match, return failure. |
| 3058 | if (Entry == RegisterReqs.end()) |
| 3059 | return -1; |
| 3060 | Parser.Lex(); // Eat identifier token. |
| 3061 | return Entry->getValue(); |
| 3062 | } |
Bob Wilson | fb0bd04 | 2011-02-03 21:46:10 +0000 | [diff] [blame] | 3063 | |
Oliver Stannard | 9e89d8c | 2014-11-05 12:06:39 +0000 | [diff] [blame] | 3064 | // Some FPUs only have 16 D registers, so D16-D31 are invalid |
| 3065 | if (hasD16() && RegNum >= ARM::D16 && RegNum <= ARM::D31) |
| 3066 | return -1; |
| 3067 | |
Chris Lattner | 44e5981c | 2010-10-30 04:09:10 +0000 | [diff] [blame] | 3068 | Parser.Lex(); // Eat identifier token. |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 3069 | |
Chris Lattner | 44e5981c | 2010-10-30 04:09:10 +0000 | [diff] [blame] | 3070 | return RegNum; |
| 3071 | } |
Jim Grosbach | 99710a8 | 2010-11-01 16:44:21 +0000 | [diff] [blame] | 3072 | |
Jim Grosbach | bb24c59 | 2011-07-13 18:49:30 +0000 | [diff] [blame] | 3073 | // Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0. |
| 3074 | // If a recoverable error occurs, return 1. If an irrecoverable error |
| 3075 | // occurs, return -1. An irrecoverable error is one where tokens have been |
| 3076 | // consumed in the process of trying to parse the shifter (i.e., when it is |
| 3077 | // indeed a shifter operand, but malformed). |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 3078 | int ARMAsmParser::tryParseShiftRegister(OperandVector &Operands) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 3079 | MCAsmParser &Parser = getParser(); |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 3080 | SMLoc S = Parser.getTok().getLoc(); |
| 3081 | const AsmToken &Tok = Parser.getTok(); |
Kevin Enderby | 6287371 | 2014-02-17 21:45:27 +0000 | [diff] [blame] | 3082 | if (Tok.isNot(AsmToken::Identifier)) |
| 3083 | return -1; |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 3084 | |
Benjamin Kramer | 20baffb | 2011-11-06 20:37:06 +0000 | [diff] [blame] | 3085 | std::string lowerCase = Tok.getString().lower(); |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 3086 | ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase) |
Jim Grosbach | 3b559ff | 2011-12-07 23:40:58 +0000 | [diff] [blame] | 3087 | .Case("asl", ARM_AM::lsl) |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 3088 | .Case("lsl", ARM_AM::lsl) |
| 3089 | .Case("lsr", ARM_AM::lsr) |
| 3090 | .Case("asr", ARM_AM::asr) |
| 3091 | .Case("ror", ARM_AM::ror) |
| 3092 | .Case("rrx", ARM_AM::rrx) |
| 3093 | .Default(ARM_AM::no_shift); |
| 3094 | |
| 3095 | if (ShiftTy == ARM_AM::no_shift) |
Jim Grosbach | bb24c59 | 2011-07-13 18:49:30 +0000 | [diff] [blame] | 3096 | return 1; |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 3097 | |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 3098 | Parser.Lex(); // Eat the operator. |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 3099 | |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 3100 | // The source register for the shift has already been added to the |
| 3101 | // operand list, so we need to pop it off and combine it into the shifted |
| 3102 | // register operand instead. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 3103 | std::unique_ptr<ARMOperand> PrevOp( |
| 3104 | (ARMOperand *)Operands.pop_back_val().release()); |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 3105 | if (!PrevOp->isReg()) |
| 3106 | return Error(PrevOp->getStartLoc(), "shift must be of a register"); |
| 3107 | int SrcReg = PrevOp->getReg(); |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3108 | |
| 3109 | SMLoc EndLoc; |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 3110 | int64_t Imm = 0; |
| 3111 | int ShiftReg = 0; |
| 3112 | if (ShiftTy == ARM_AM::rrx) { |
| 3113 | // RRX Doesn't have an explicit shift amount. The encoder expects |
| 3114 | // the shift register to be the same as the source register. Seems odd, |
| 3115 | // but OK. |
| 3116 | ShiftReg = SrcReg; |
| 3117 | } else { |
| 3118 | // 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] | 3119 | if (Parser.getTok().is(AsmToken::Hash) || |
| 3120 | Parser.getTok().is(AsmToken::Dollar)) { |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 3121 | Parser.Lex(); // Eat hash. |
| 3122 | SMLoc ImmLoc = Parser.getTok().getLoc(); |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 3123 | const MCExpr *ShiftExpr = nullptr; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 3124 | if (getParser().parseExpression(ShiftExpr, EndLoc)) { |
Jim Grosbach | bb24c59 | 2011-07-13 18:49:30 +0000 | [diff] [blame] | 3125 | Error(ImmLoc, "invalid immediate shift value"); |
| 3126 | return -1; |
| 3127 | } |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 3128 | // The expression must be evaluatable as an immediate. |
| 3129 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr); |
Jim Grosbach | bb24c59 | 2011-07-13 18:49:30 +0000 | [diff] [blame] | 3130 | if (!CE) { |
| 3131 | Error(ImmLoc, "invalid immediate shift value"); |
| 3132 | return -1; |
| 3133 | } |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 3134 | // Range check the immediate. |
| 3135 | // lsl, ror: 0 <= imm <= 31 |
| 3136 | // lsr, asr: 0 <= imm <= 32 |
| 3137 | Imm = CE->getValue(); |
| 3138 | if (Imm < 0 || |
| 3139 | ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) || |
| 3140 | ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) { |
Jim Grosbach | bb24c59 | 2011-07-13 18:49:30 +0000 | [diff] [blame] | 3141 | Error(ImmLoc, "immediate shift value out of range"); |
| 3142 | return -1; |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 3143 | } |
Jim Grosbach | 21488b8 | 2011-12-22 17:37:00 +0000 | [diff] [blame] | 3144 | // shift by zero is a nop. Always send it through as lsl. |
| 3145 | // ('as' compatibility) |
| 3146 | if (Imm == 0) |
| 3147 | ShiftTy = ARM_AM::lsl; |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 3148 | } else if (Parser.getTok().is(AsmToken::Identifier)) { |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 3149 | SMLoc L = Parser.getTok().getLoc(); |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3150 | EndLoc = Parser.getTok().getEndLoc(); |
| 3151 | ShiftReg = tryParseRegister(); |
Jim Grosbach | bb24c59 | 2011-07-13 18:49:30 +0000 | [diff] [blame] | 3152 | if (ShiftReg == -1) { |
Saleem Abdulrasool | 6d11b7c | 2014-05-17 21:49:54 +0000 | [diff] [blame] | 3153 | Error(L, "expected immediate or register in shift operand"); |
Jim Grosbach | bb24c59 | 2011-07-13 18:49:30 +0000 | [diff] [blame] | 3154 | return -1; |
| 3155 | } |
| 3156 | } else { |
Saleem Abdulrasool | 6d11b7c | 2014-05-17 21:49:54 +0000 | [diff] [blame] | 3157 | Error(Parser.getTok().getLoc(), |
| 3158 | "expected immediate or register in shift operand"); |
Jim Grosbach | bb24c59 | 2011-07-13 18:49:30 +0000 | [diff] [blame] | 3159 | return -1; |
| 3160 | } |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 3161 | } |
| 3162 | |
Owen Anderson | b595ed0 | 2011-07-21 18:54:16 +0000 | [diff] [blame] | 3163 | if (ShiftReg && ShiftTy != ARM_AM::rrx) |
| 3164 | Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg, |
Jim Grosbach | ac798e1 | 2011-07-25 20:49:51 +0000 | [diff] [blame] | 3165 | ShiftReg, Imm, |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3166 | S, EndLoc)); |
Owen Anderson | b595ed0 | 2011-07-21 18:54:16 +0000 | [diff] [blame] | 3167 | else |
| 3168 | Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm, |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3169 | S, EndLoc)); |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 3170 | |
Jim Grosbach | bb24c59 | 2011-07-13 18:49:30 +0000 | [diff] [blame] | 3171 | return 0; |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 3172 | } |
| 3173 | |
| 3174 | |
Bill Wendling | 2063b84 | 2010-11-18 23:43:05 +0000 | [diff] [blame] | 3175 | /// Try to parse a register name. The token must be an Identifier when called. |
| 3176 | /// If it's a register, an AsmOperand is created. Another AsmOperand is created |
| 3177 | /// if there is a "writeback". 'true' if it's not a register. |
Chris Lattner | bd7c9fa | 2010-10-28 17:20:03 +0000 | [diff] [blame] | 3178 | /// |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 3179 | /// TODO this is likely to change to allow different register types and or to |
| 3180 | /// parse for a specific register type. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 3181 | bool ARMAsmParser::tryParseRegisterWithWriteBack(OperandVector &Operands) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 3182 | MCAsmParser &Parser = getParser(); |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3183 | const AsmToken &RegTok = Parser.getTok(); |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 3184 | int RegNo = tryParseRegister(); |
Bill Wendling | e18980a | 2010-11-06 22:36:58 +0000 | [diff] [blame] | 3185 | if (RegNo == -1) |
Bill Wendling | 2063b84 | 2010-11-18 23:43:05 +0000 | [diff] [blame] | 3186 | return true; |
Jim Grosbach | 99710a8 | 2010-11-01 16:44:21 +0000 | [diff] [blame] | 3187 | |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3188 | Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(), |
| 3189 | RegTok.getEndLoc())); |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 3190 | |
Chris Lattner | 44e5981c | 2010-10-30 04:09:10 +0000 | [diff] [blame] | 3191 | const AsmToken &ExclaimTok = Parser.getTok(); |
| 3192 | if (ExclaimTok.is(AsmToken::Exclaim)) { |
Bill Wendling | 2063b84 | 2010-11-18 23:43:05 +0000 | [diff] [blame] | 3193 | Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(), |
| 3194 | ExclaimTok.getLoc())); |
Chris Lattner | 44e5981c | 2010-10-30 04:09:10 +0000 | [diff] [blame] | 3195 | Parser.Lex(); // Eat exclaim token |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 3196 | return false; |
| 3197 | } |
| 3198 | |
| 3199 | // Also check for an index operand. This is only legal for vector registers, |
| 3200 | // but that'll get caught OK in operand matching, so we don't need to |
| 3201 | // explicitly filter everything else out here. |
| 3202 | if (Parser.getTok().is(AsmToken::LBrac)) { |
| 3203 | SMLoc SIdx = Parser.getTok().getLoc(); |
| 3204 | Parser.Lex(); // Eat left bracket token. |
| 3205 | |
| 3206 | const MCExpr *ImmVal; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 3207 | if (getParser().parseExpression(ImmVal)) |
Jim Grosbach | a2147ce | 2012-01-31 23:51:09 +0000 | [diff] [blame] | 3208 | return true; |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 3209 | const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal); |
Jim Grosbach | c8f2b78 | 2012-01-26 15:56:45 +0000 | [diff] [blame] | 3210 | if (!MCE) |
| 3211 | return TokError("immediate value expected for vector index"); |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 3212 | |
Jim Grosbach | c8f2b78 | 2012-01-26 15:56:45 +0000 | [diff] [blame] | 3213 | if (Parser.getTok().isNot(AsmToken::RBrac)) |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3214 | return Error(Parser.getTok().getLoc(), "']' expected"); |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 3215 | |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3216 | SMLoc E = Parser.getTok().getEndLoc(); |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 3217 | Parser.Lex(); // Eat right bracket token. |
| 3218 | |
| 3219 | Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(), |
| 3220 | SIdx, E, |
| 3221 | getContext())); |
Kevin Enderby | 2207e5f | 2009-10-07 18:01:35 +0000 | [diff] [blame] | 3222 | } |
| 3223 | |
Bill Wendling | 2063b84 | 2010-11-18 23:43:05 +0000 | [diff] [blame] | 3224 | return false; |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 3225 | } |
| 3226 | |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 3227 | /// MatchCoprocessorOperandName - Try to parse an coprocessor related |
Renato Golin | ac561c3 | 2014-06-26 13:10:53 +0000 | [diff] [blame] | 3228 | /// instruction with a symbolic operand name. |
| 3229 | /// We accept "crN" syntax for GAS compatibility. |
| 3230 | /// <operand-name> ::= <prefix><number> |
| 3231 | /// If CoprocOp is 'c', then: |
| 3232 | /// <prefix> ::= c | cr |
| 3233 | /// If CoprocOp is 'p', then : |
| 3234 | /// <prefix> ::= p |
| 3235 | /// <number> ::= integer in range [0, 15] |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 3236 | static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) { |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3237 | // Use the same layout as the tablegen'erated register name matcher. Ugly, |
| 3238 | // but efficient. |
Renato Golin | ac561c3 | 2014-06-26 13:10:53 +0000 | [diff] [blame] | 3239 | if (Name.size() < 2 || Name[0] != CoprocOp) |
| 3240 | return -1; |
| 3241 | Name = (Name[1] == 'r') ? Name.drop_front(2) : Name.drop_front(); |
| 3242 | |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3243 | switch (Name.size()) { |
David Blaikie | 46a9f01 | 2012-01-20 21:51:11 +0000 | [diff] [blame] | 3244 | default: return -1; |
Renato Golin | ac561c3 | 2014-06-26 13:10:53 +0000 | [diff] [blame] | 3245 | case 1: |
| 3246 | switch (Name[0]) { |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3247 | default: return -1; |
| 3248 | case '0': return 0; |
| 3249 | case '1': return 1; |
| 3250 | case '2': return 2; |
| 3251 | case '3': return 3; |
| 3252 | case '4': return 4; |
| 3253 | case '5': return 5; |
| 3254 | case '6': return 6; |
| 3255 | case '7': return 7; |
| 3256 | case '8': return 8; |
| 3257 | case '9': return 9; |
| 3258 | } |
Renato Golin | ac561c3 | 2014-06-26 13:10:53 +0000 | [diff] [blame] | 3259 | case 2: |
| 3260 | if (Name[0] != '1') |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3261 | return -1; |
Renato Golin | ac561c3 | 2014-06-26 13:10:53 +0000 | [diff] [blame] | 3262 | switch (Name[1]) { |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3263 | default: return -1; |
Renato Golin | bc0b037 | 2014-08-04 23:21:56 +0000 | [diff] [blame] | 3264 | // CP10 and CP11 are VFP/NEON and so vector instructions should be used. |
| 3265 | // However, old cores (v5/v6) did use them in that way. |
| 3266 | case '0': return 10; |
| 3267 | case '1': return 11; |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3268 | case '2': return 12; |
| 3269 | case '3': return 13; |
| 3270 | case '4': return 14; |
| 3271 | case '5': return 15; |
| 3272 | } |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3273 | } |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3274 | } |
| 3275 | |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 3276 | /// parseITCondCode - Try to parse a condition code for an IT instruction. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 3277 | ARMAsmParser::OperandMatchResultTy |
| 3278 | ARMAsmParser::parseITCondCode(OperandVector &Operands) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 3279 | MCAsmParser &Parser = getParser(); |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 3280 | SMLoc S = Parser.getTok().getLoc(); |
| 3281 | const AsmToken &Tok = Parser.getTok(); |
| 3282 | if (!Tok.is(AsmToken::Identifier)) |
| 3283 | return MatchOperand_NoMatch; |
Richard Barton | 82f95ea | 2012-04-27 17:34:01 +0000 | [diff] [blame] | 3284 | unsigned CC = StringSwitch<unsigned>(Tok.getString().lower()) |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 3285 | .Case("eq", ARMCC::EQ) |
| 3286 | .Case("ne", ARMCC::NE) |
| 3287 | .Case("hs", ARMCC::HS) |
| 3288 | .Case("cs", ARMCC::HS) |
| 3289 | .Case("lo", ARMCC::LO) |
| 3290 | .Case("cc", ARMCC::LO) |
| 3291 | .Case("mi", ARMCC::MI) |
| 3292 | .Case("pl", ARMCC::PL) |
| 3293 | .Case("vs", ARMCC::VS) |
| 3294 | .Case("vc", ARMCC::VC) |
| 3295 | .Case("hi", ARMCC::HI) |
| 3296 | .Case("ls", ARMCC::LS) |
| 3297 | .Case("ge", ARMCC::GE) |
| 3298 | .Case("lt", ARMCC::LT) |
| 3299 | .Case("gt", ARMCC::GT) |
| 3300 | .Case("le", ARMCC::LE) |
| 3301 | .Case("al", ARMCC::AL) |
| 3302 | .Default(~0U); |
| 3303 | if (CC == ~0U) |
| 3304 | return MatchOperand_NoMatch; |
| 3305 | Parser.Lex(); // Eat the token. |
| 3306 | |
| 3307 | Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S)); |
| 3308 | |
| 3309 | return MatchOperand_Success; |
| 3310 | } |
| 3311 | |
Jim Grosbach | 2d6ef44 | 2011-07-25 20:14:50 +0000 | [diff] [blame] | 3312 | /// parseCoprocNumOperand - Try to parse an coprocessor number operand. The |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 3313 | /// token must be an Identifier when called, and if it is a coprocessor |
| 3314 | /// 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] | 3315 | ARMAsmParser::OperandMatchResultTy |
| 3316 | ARMAsmParser::parseCoprocNumOperand(OperandVector &Operands) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 3317 | MCAsmParser &Parser = getParser(); |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3318 | SMLoc S = Parser.getTok().getLoc(); |
| 3319 | const AsmToken &Tok = Parser.getTok(); |
Jim Grosbach | 54a20ed | 2011-10-12 20:54:17 +0000 | [diff] [blame] | 3320 | if (Tok.isNot(AsmToken::Identifier)) |
| 3321 | return MatchOperand_NoMatch; |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3322 | |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 3323 | int Num = MatchCoprocessorOperandName(Tok.getString(), 'p'); |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3324 | if (Num == -1) |
Jim Grosbach | 861e49c | 2011-02-12 01:34:40 +0000 | [diff] [blame] | 3325 | return MatchOperand_NoMatch; |
Renato Golin | bc0b037 | 2014-08-04 23:21:56 +0000 | [diff] [blame] | 3326 | // ARMv7 and v8 don't allow cp10/cp11 due to VFP/NEON specific instructions |
| 3327 | if ((hasV7Ops() || hasV8Ops()) && (Num == 10 || Num == 11)) |
| 3328 | return MatchOperand_NoMatch; |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3329 | |
| 3330 | Parser.Lex(); // Eat identifier token. |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 3331 | Operands.push_back(ARMOperand::CreateCoprocNum(Num, S)); |
Jim Grosbach | 861e49c | 2011-02-12 01:34:40 +0000 | [diff] [blame] | 3332 | return MatchOperand_Success; |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 3333 | } |
| 3334 | |
Jim Grosbach | 2d6ef44 | 2011-07-25 20:14:50 +0000 | [diff] [blame] | 3335 | /// parseCoprocRegOperand - Try to parse an coprocessor register operand. The |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 3336 | /// token must be an Identifier when called, and if it is a coprocessor |
| 3337 | /// 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] | 3338 | ARMAsmParser::OperandMatchResultTy |
| 3339 | ARMAsmParser::parseCoprocRegOperand(OperandVector &Operands) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 3340 | MCAsmParser &Parser = getParser(); |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 3341 | SMLoc S = Parser.getTok().getLoc(); |
| 3342 | const AsmToken &Tok = Parser.getTok(); |
Jim Grosbach | 54a20ed | 2011-10-12 20:54:17 +0000 | [diff] [blame] | 3343 | if (Tok.isNot(AsmToken::Identifier)) |
| 3344 | return MatchOperand_NoMatch; |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 3345 | |
| 3346 | int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c'); |
| 3347 | if (Reg == -1) |
Jim Grosbach | 861e49c | 2011-02-12 01:34:40 +0000 | [diff] [blame] | 3348 | return MatchOperand_NoMatch; |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 3349 | |
| 3350 | Parser.Lex(); // Eat identifier token. |
| 3351 | Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S)); |
Jim Grosbach | 861e49c | 2011-02-12 01:34:40 +0000 | [diff] [blame] | 3352 | return MatchOperand_Success; |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3353 | } |
| 3354 | |
Jim Grosbach | 4839958 | 2011-10-12 17:34:41 +0000 | [diff] [blame] | 3355 | /// parseCoprocOptionOperand - Try to parse an coprocessor option operand. |
| 3356 | /// coproc_option : '{' imm0_255 '}' |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 3357 | ARMAsmParser::OperandMatchResultTy |
| 3358 | ARMAsmParser::parseCoprocOptionOperand(OperandVector &Operands) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 3359 | MCAsmParser &Parser = getParser(); |
Jim Grosbach | 4839958 | 2011-10-12 17:34:41 +0000 | [diff] [blame] | 3360 | SMLoc S = Parser.getTok().getLoc(); |
| 3361 | |
| 3362 | // If this isn't a '{', this isn't a coprocessor immediate operand. |
| 3363 | if (Parser.getTok().isNot(AsmToken::LCurly)) |
| 3364 | return MatchOperand_NoMatch; |
| 3365 | Parser.Lex(); // Eat the '{' |
| 3366 | |
| 3367 | const MCExpr *Expr; |
| 3368 | SMLoc Loc = Parser.getTok().getLoc(); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 3369 | if (getParser().parseExpression(Expr)) { |
Jim Grosbach | 4839958 | 2011-10-12 17:34:41 +0000 | [diff] [blame] | 3370 | Error(Loc, "illegal expression"); |
| 3371 | return MatchOperand_ParseFail; |
| 3372 | } |
| 3373 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr); |
| 3374 | if (!CE || CE->getValue() < 0 || CE->getValue() > 255) { |
| 3375 | Error(Loc, "coprocessor option must be an immediate in range [0, 255]"); |
| 3376 | return MatchOperand_ParseFail; |
| 3377 | } |
| 3378 | int Val = CE->getValue(); |
| 3379 | |
| 3380 | // Check for and consume the closing '}' |
| 3381 | if (Parser.getTok().isNot(AsmToken::RCurly)) |
| 3382 | return MatchOperand_ParseFail; |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3383 | SMLoc E = Parser.getTok().getEndLoc(); |
Jim Grosbach | 4839958 | 2011-10-12 17:34:41 +0000 | [diff] [blame] | 3384 | Parser.Lex(); // Eat the '}' |
| 3385 | |
| 3386 | Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E)); |
| 3387 | return MatchOperand_Success; |
| 3388 | } |
| 3389 | |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3390 | // For register list parsing, we need to map from raw GPR register numbering |
| 3391 | // to the enumeration values. The enumeration values aren't sorted by |
| 3392 | // register number due to our using "sp", "lr" and "pc" as canonical names. |
| 3393 | static unsigned getNextRegister(unsigned Reg) { |
| 3394 | // If this is a GPR, we need to do it manually, otherwise we can rely |
| 3395 | // on the sort ordering of the enumeration since the other reg-classes |
| 3396 | // are sane. |
| 3397 | if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg)) |
| 3398 | return Reg + 1; |
| 3399 | switch(Reg) { |
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 3400 | default: llvm_unreachable("Invalid GPR number!"); |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3401 | case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2; |
| 3402 | case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4; |
| 3403 | case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6; |
| 3404 | case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8; |
| 3405 | case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10; |
| 3406 | case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12; |
| 3407 | case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR; |
| 3408 | case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0; |
| 3409 | } |
| 3410 | } |
| 3411 | |
Jim Grosbach | 85a2343 | 2011-11-11 21:27:40 +0000 | [diff] [blame] | 3412 | // Return the low-subreg of a given Q register. |
| 3413 | static unsigned getDRegFromQReg(unsigned QReg) { |
| 3414 | switch (QReg) { |
| 3415 | default: llvm_unreachable("expected a Q register!"); |
| 3416 | case ARM::Q0: return ARM::D0; |
| 3417 | case ARM::Q1: return ARM::D2; |
| 3418 | case ARM::Q2: return ARM::D4; |
| 3419 | case ARM::Q3: return ARM::D6; |
| 3420 | case ARM::Q4: return ARM::D8; |
| 3421 | case ARM::Q5: return ARM::D10; |
| 3422 | case ARM::Q6: return ARM::D12; |
| 3423 | case ARM::Q7: return ARM::D14; |
| 3424 | case ARM::Q8: return ARM::D16; |
Jim Grosbach | a92a5d8 | 2011-11-15 21:01:30 +0000 | [diff] [blame] | 3425 | case ARM::Q9: return ARM::D18; |
Jim Grosbach | 85a2343 | 2011-11-11 21:27:40 +0000 | [diff] [blame] | 3426 | case ARM::Q10: return ARM::D20; |
| 3427 | case ARM::Q11: return ARM::D22; |
| 3428 | case ARM::Q12: return ARM::D24; |
| 3429 | case ARM::Q13: return ARM::D26; |
| 3430 | case ARM::Q14: return ARM::D28; |
| 3431 | case ARM::Q15: return ARM::D30; |
| 3432 | } |
| 3433 | } |
| 3434 | |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3435 | /// Parse a register list. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 3436 | bool ARMAsmParser::parseRegisterList(OperandVector &Operands) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 3437 | MCAsmParser &Parser = getParser(); |
Sean Callanan | 936b0d3 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 3438 | assert(Parser.getTok().is(AsmToken::LCurly) && |
Bill Wendling | 4f4bce0 | 2010-11-06 10:48:18 +0000 | [diff] [blame] | 3439 | "Token is not a Left Curly Brace"); |
Bill Wendling | e18980a | 2010-11-06 22:36:58 +0000 | [diff] [blame] | 3440 | SMLoc S = Parser.getTok().getLoc(); |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3441 | Parser.Lex(); // Eat '{' token. |
| 3442 | SMLoc RegLoc = Parser.getTok().getLoc(); |
Kevin Enderby | a2b9910 | 2009-10-09 21:12:28 +0000 | [diff] [blame] | 3443 | |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3444 | // Check the first register in the list to see what register class |
| 3445 | // this is a list of. |
| 3446 | int Reg = tryParseRegister(); |
| 3447 | if (Reg == -1) |
| 3448 | return Error(RegLoc, "register expected"); |
| 3449 | |
Jim Grosbach | 85a2343 | 2011-11-11 21:27:40 +0000 | [diff] [blame] | 3450 | // The reglist instructions have at most 16 registers, so reserve |
| 3451 | // space for that many. |
Chad Rosier | fa705ee | 2013-07-01 20:49:23 +0000 | [diff] [blame] | 3452 | int EReg = 0; |
| 3453 | SmallVector<std::pair<unsigned, unsigned>, 16> Registers; |
Jim Grosbach | 85a2343 | 2011-11-11 21:27:40 +0000 | [diff] [blame] | 3454 | |
| 3455 | // Allow Q regs and just interpret them as the two D sub-registers. |
| 3456 | if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) { |
| 3457 | Reg = getDRegFromQReg(Reg); |
Chad Rosier | fa705ee | 2013-07-01 20:49:23 +0000 | [diff] [blame] | 3458 | EReg = MRI->getEncodingValue(Reg); |
| 3459 | Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg)); |
Jim Grosbach | 85a2343 | 2011-11-11 21:27:40 +0000 | [diff] [blame] | 3460 | ++Reg; |
| 3461 | } |
Benjamin Kramer | 0d6d098 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 3462 | const MCRegisterClass *RC; |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3463 | if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg)) |
| 3464 | RC = &ARMMCRegisterClasses[ARM::GPRRegClassID]; |
| 3465 | else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) |
| 3466 | RC = &ARMMCRegisterClasses[ARM::DPRRegClassID]; |
| 3467 | else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg)) |
| 3468 | RC = &ARMMCRegisterClasses[ARM::SPRRegClassID]; |
| 3469 | else |
| 3470 | return Error(RegLoc, "invalid register in register list"); |
| 3471 | |
Jim Grosbach | 85a2343 | 2011-11-11 21:27:40 +0000 | [diff] [blame] | 3472 | // Store the register. |
Chad Rosier | fa705ee | 2013-07-01 20:49:23 +0000 | [diff] [blame] | 3473 | EReg = MRI->getEncodingValue(Reg); |
| 3474 | Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg)); |
Kevin Enderby | a2b9910 | 2009-10-09 21:12:28 +0000 | [diff] [blame] | 3475 | |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3476 | // This starts immediately after the first register token in the list, |
| 3477 | // so we can see either a comma or a minus (range separator) as a legal |
| 3478 | // next token. |
| 3479 | while (Parser.getTok().is(AsmToken::Comma) || |
| 3480 | Parser.getTok().is(AsmToken::Minus)) { |
| 3481 | if (Parser.getTok().is(AsmToken::Minus)) { |
Jim Grosbach | e891fe8 | 2011-11-15 23:19:15 +0000 | [diff] [blame] | 3482 | Parser.Lex(); // Eat the minus. |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3483 | SMLoc AfterMinusLoc = Parser.getTok().getLoc(); |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3484 | int EndReg = tryParseRegister(); |
| 3485 | if (EndReg == -1) |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3486 | return Error(AfterMinusLoc, "register expected"); |
Jim Grosbach | 85a2343 | 2011-11-11 21:27:40 +0000 | [diff] [blame] | 3487 | // Allow Q regs and just interpret them as the two D sub-registers. |
| 3488 | if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg)) |
| 3489 | EndReg = getDRegFromQReg(EndReg) + 1; |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3490 | // If the register is the same as the start reg, there's nothing |
| 3491 | // more to do. |
| 3492 | if (Reg == EndReg) |
| 3493 | continue; |
| 3494 | // The register must be in the same register class as the first. |
| 3495 | if (!RC->contains(EndReg)) |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3496 | return Error(AfterMinusLoc, "invalid register in register list"); |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3497 | // Ranges must go from low to high. |
Eric Christopher | 6ac277c | 2012-08-09 22:10:21 +0000 | [diff] [blame] | 3498 | if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg)) |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3499 | return Error(AfterMinusLoc, "bad range in register list"); |
Kevin Enderby | a2b9910 | 2009-10-09 21:12:28 +0000 | [diff] [blame] | 3500 | |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3501 | // Add all the registers in the range to the register list. |
| 3502 | while (Reg != EndReg) { |
| 3503 | Reg = getNextRegister(Reg); |
Chad Rosier | fa705ee | 2013-07-01 20:49:23 +0000 | [diff] [blame] | 3504 | EReg = MRI->getEncodingValue(Reg); |
| 3505 | Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg)); |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3506 | } |
| 3507 | continue; |
| 3508 | } |
| 3509 | Parser.Lex(); // Eat the comma. |
| 3510 | RegLoc = Parser.getTok().getLoc(); |
| 3511 | int OldReg = Reg; |
Jim Grosbach | 98bc797 | 2011-12-08 21:34:20 +0000 | [diff] [blame] | 3512 | const AsmToken RegTok = Parser.getTok(); |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3513 | Reg = tryParseRegister(); |
| 3514 | if (Reg == -1) |
Jim Grosbach | 3337e39 | 2011-09-12 23:36:42 +0000 | [diff] [blame] | 3515 | return Error(RegLoc, "register expected"); |
Jim Grosbach | 85a2343 | 2011-11-11 21:27:40 +0000 | [diff] [blame] | 3516 | // Allow Q regs and just interpret them as the two D sub-registers. |
| 3517 | bool isQReg = false; |
| 3518 | if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) { |
| 3519 | Reg = getDRegFromQReg(Reg); |
| 3520 | isQReg = true; |
| 3521 | } |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3522 | // The register must be in the same register class as the first. |
| 3523 | if (!RC->contains(Reg)) |
| 3524 | return Error(RegLoc, "invalid register in register list"); |
| 3525 | // List must be monotonically increasing. |
Eric Christopher | 6ac277c | 2012-08-09 22:10:21 +0000 | [diff] [blame] | 3526 | if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) { |
Jim Grosbach | 905686a | 2012-03-16 20:48:38 +0000 | [diff] [blame] | 3527 | if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg)) |
| 3528 | Warning(RegLoc, "register list not in ascending order"); |
| 3529 | else |
| 3530 | return Error(RegLoc, "register list not in ascending order"); |
| 3531 | } |
Eric Christopher | 6ac277c | 2012-08-09 22:10:21 +0000 | [diff] [blame] | 3532 | if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) { |
Jim Grosbach | 98bc797 | 2011-12-08 21:34:20 +0000 | [diff] [blame] | 3533 | Warning(RegLoc, "duplicated register (" + RegTok.getString() + |
| 3534 | ") in register list"); |
| 3535 | continue; |
| 3536 | } |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3537 | // VFP register lists must also be contiguous. |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3538 | if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] && |
| 3539 | Reg != OldReg + 1) |
| 3540 | return Error(RegLoc, "non-contiguous register range"); |
Chad Rosier | fa705ee | 2013-07-01 20:49:23 +0000 | [diff] [blame] | 3541 | EReg = MRI->getEncodingValue(Reg); |
| 3542 | Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg)); |
| 3543 | if (isQReg) { |
| 3544 | EReg = MRI->getEncodingValue(++Reg); |
| 3545 | Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg)); |
| 3546 | } |
Bill Wendling | e18980a | 2010-11-06 22:36:58 +0000 | [diff] [blame] | 3547 | } |
| 3548 | |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3549 | if (Parser.getTok().isNot(AsmToken::RCurly)) |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3550 | return Error(Parser.getTok().getLoc(), "'}' expected"); |
| 3551 | SMLoc E = Parser.getTok().getEndLoc(); |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3552 | Parser.Lex(); // Eat '}' token. |
| 3553 | |
Jim Grosbach | 18bf363 | 2011-12-13 21:48:29 +0000 | [diff] [blame] | 3554 | // Push the register list operand. |
Bill Wendling | 2063b84 | 2010-11-18 23:43:05 +0000 | [diff] [blame] | 3555 | Operands.push_back(ARMOperand::CreateRegList(Registers, S, E)); |
Jim Grosbach | 18bf363 | 2011-12-13 21:48:29 +0000 | [diff] [blame] | 3556 | |
| 3557 | // The ARM system instruction variants for LDM/STM have a '^' token here. |
| 3558 | if (Parser.getTok().is(AsmToken::Caret)) { |
| 3559 | Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc())); |
| 3560 | Parser.Lex(); // Eat '^' token. |
| 3561 | } |
| 3562 | |
Bill Wendling | 2063b84 | 2010-11-18 23:43:05 +0000 | [diff] [blame] | 3563 | return false; |
Kevin Enderby | a2b9910 | 2009-10-09 21:12:28 +0000 | [diff] [blame] | 3564 | } |
| 3565 | |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3566 | // Helper function to parse the lane index for vector lists. |
| 3567 | ARMAsmParser::OperandMatchResultTy ARMAsmParser:: |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3568 | parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 3569 | MCAsmParser &Parser = getParser(); |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3570 | Index = 0; // Always return a defined index value. |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3571 | if (Parser.getTok().is(AsmToken::LBrac)) { |
| 3572 | Parser.Lex(); // Eat the '['. |
| 3573 | if (Parser.getTok().is(AsmToken::RBrac)) { |
| 3574 | // "Dn[]" is the 'all lanes' syntax. |
| 3575 | LaneKind = AllLanes; |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3576 | EndLoc = Parser.getTok().getEndLoc(); |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3577 | Parser.Lex(); // Eat the ']'. |
| 3578 | return MatchOperand_Success; |
| 3579 | } |
Jim Grosbach | 67e76ba | 2012-03-19 20:39:53 +0000 | [diff] [blame] | 3580 | |
| 3581 | // There's an optional '#' token here. Normally there wouldn't be, but |
| 3582 | // inline assemble puts one in, and it's friendly to accept that. |
| 3583 | if (Parser.getTok().is(AsmToken::Hash)) |
Amaury de la Vieuville | bac917f | 2013-06-10 14:17:15 +0000 | [diff] [blame] | 3584 | Parser.Lex(); // Eat '#' or '$'. |
Jim Grosbach | 67e76ba | 2012-03-19 20:39:53 +0000 | [diff] [blame] | 3585 | |
Jim Grosbach | 7de7ab8 | 2011-12-21 01:19:23 +0000 | [diff] [blame] | 3586 | const MCExpr *LaneIndex; |
| 3587 | SMLoc Loc = Parser.getTok().getLoc(); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 3588 | if (getParser().parseExpression(LaneIndex)) { |
Jim Grosbach | 7de7ab8 | 2011-12-21 01:19:23 +0000 | [diff] [blame] | 3589 | Error(Loc, "illegal expression"); |
| 3590 | return MatchOperand_ParseFail; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3591 | } |
Jim Grosbach | 7de7ab8 | 2011-12-21 01:19:23 +0000 | [diff] [blame] | 3592 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex); |
| 3593 | if (!CE) { |
| 3594 | Error(Loc, "lane index must be empty or an integer"); |
| 3595 | return MatchOperand_ParseFail; |
| 3596 | } |
| 3597 | if (Parser.getTok().isNot(AsmToken::RBrac)) { |
| 3598 | Error(Parser.getTok().getLoc(), "']' expected"); |
| 3599 | return MatchOperand_ParseFail; |
| 3600 | } |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3601 | EndLoc = Parser.getTok().getEndLoc(); |
Jim Grosbach | 7de7ab8 | 2011-12-21 01:19:23 +0000 | [diff] [blame] | 3602 | Parser.Lex(); // Eat the ']'. |
| 3603 | int64_t Val = CE->getValue(); |
| 3604 | |
| 3605 | // FIXME: Make this range check context sensitive for .8, .16, .32. |
| 3606 | if (Val < 0 || Val > 7) { |
| 3607 | Error(Parser.getTok().getLoc(), "lane index out of range"); |
| 3608 | return MatchOperand_ParseFail; |
| 3609 | } |
| 3610 | Index = Val; |
| 3611 | LaneKind = IndexedLane; |
| 3612 | return MatchOperand_Success; |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3613 | } |
| 3614 | LaneKind = NoLanes; |
| 3615 | return MatchOperand_Success; |
| 3616 | } |
| 3617 | |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3618 | // parse a vector register list |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 3619 | ARMAsmParser::OperandMatchResultTy |
| 3620 | ARMAsmParser::parseVectorList(OperandVector &Operands) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 3621 | MCAsmParser &Parser = getParser(); |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3622 | VectorLaneTy LaneKind; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3623 | unsigned LaneIndex; |
Jim Grosbach | 8d57923 | 2011-11-15 21:45:55 +0000 | [diff] [blame] | 3624 | SMLoc S = Parser.getTok().getLoc(); |
| 3625 | // As an extension (to match gas), support a plain D register or Q register |
| 3626 | // (without encosing curly braces) as a single or double entry list, |
| 3627 | // respectively. |
| 3628 | if (Parser.getTok().is(AsmToken::Identifier)) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3629 | SMLoc E = Parser.getTok().getEndLoc(); |
Jim Grosbach | 8d57923 | 2011-11-15 21:45:55 +0000 | [diff] [blame] | 3630 | int Reg = tryParseRegister(); |
| 3631 | if (Reg == -1) |
| 3632 | return MatchOperand_NoMatch; |
Jim Grosbach | 8d57923 | 2011-11-15 21:45:55 +0000 | [diff] [blame] | 3633 | if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3634 | OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E); |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3635 | if (Res != MatchOperand_Success) |
| 3636 | return Res; |
| 3637 | switch (LaneKind) { |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3638 | case NoLanes: |
Jim Grosbach | 2f50e92 | 2011-12-15 21:44:33 +0000 | [diff] [blame] | 3639 | Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E)); |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3640 | break; |
| 3641 | case AllLanes: |
Jim Grosbach | c5af54e | 2011-12-21 00:38:54 +0000 | [diff] [blame] | 3642 | Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false, |
| 3643 | S, E)); |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3644 | break; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3645 | case IndexedLane: |
| 3646 | Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1, |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 3647 | LaneIndex, |
| 3648 | false, S, E)); |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3649 | break; |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3650 | } |
Jim Grosbach | 8d57923 | 2011-11-15 21:45:55 +0000 | [diff] [blame] | 3651 | return MatchOperand_Success; |
| 3652 | } |
| 3653 | if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) { |
| 3654 | Reg = getDRegFromQReg(Reg); |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3655 | OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E); |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3656 | if (Res != MatchOperand_Success) |
| 3657 | return Res; |
| 3658 | switch (LaneKind) { |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3659 | case NoLanes: |
Jim Grosbach | c988e0c | 2012-03-05 19:33:30 +0000 | [diff] [blame] | 3660 | Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0, |
Jim Grosbach | 13a292c | 2012-03-06 22:01:44 +0000 | [diff] [blame] | 3661 | &ARMMCRegisterClasses[ARM::DPairRegClassID]); |
Jim Grosbach | 2f50e92 | 2011-12-15 21:44:33 +0000 | [diff] [blame] | 3662 | Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E)); |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3663 | break; |
| 3664 | case AllLanes: |
Jim Grosbach | 13a292c | 2012-03-06 22:01:44 +0000 | [diff] [blame] | 3665 | Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0, |
| 3666 | &ARMMCRegisterClasses[ARM::DPairRegClassID]); |
Jim Grosbach | c5af54e | 2011-12-21 00:38:54 +0000 | [diff] [blame] | 3667 | Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false, |
| 3668 | S, E)); |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3669 | break; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3670 | case IndexedLane: |
| 3671 | Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2, |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 3672 | LaneIndex, |
| 3673 | false, S, E)); |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3674 | break; |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3675 | } |
Jim Grosbach | 8d57923 | 2011-11-15 21:45:55 +0000 | [diff] [blame] | 3676 | return MatchOperand_Success; |
| 3677 | } |
| 3678 | Error(S, "vector register expected"); |
| 3679 | return MatchOperand_ParseFail; |
| 3680 | } |
| 3681 | |
| 3682 | if (Parser.getTok().isNot(AsmToken::LCurly)) |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3683 | return MatchOperand_NoMatch; |
| 3684 | |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3685 | Parser.Lex(); // Eat '{' token. |
| 3686 | SMLoc RegLoc = Parser.getTok().getLoc(); |
| 3687 | |
| 3688 | int Reg = tryParseRegister(); |
| 3689 | if (Reg == -1) { |
| 3690 | Error(RegLoc, "register expected"); |
| 3691 | return MatchOperand_ParseFail; |
| 3692 | } |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3693 | unsigned Count = 1; |
Jim Grosbach | c2f16a3 | 2011-12-15 21:54:55 +0000 | [diff] [blame] | 3694 | int Spacing = 0; |
Jim Grosbach | 080a499 | 2011-10-28 00:06:50 +0000 | [diff] [blame] | 3695 | unsigned FirstReg = Reg; |
| 3696 | // The list is of D registers, but we also allow Q regs and just interpret |
| 3697 | // them as the two D sub-registers. |
| 3698 | if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) { |
| 3699 | FirstReg = Reg = getDRegFromQReg(Reg); |
Jim Grosbach | 2f50e92 | 2011-12-15 21:44:33 +0000 | [diff] [blame] | 3700 | Spacing = 1; // double-spacing requires explicit D registers, otherwise |
| 3701 | // it's ambiguous with four-register single spaced. |
Jim Grosbach | 080a499 | 2011-10-28 00:06:50 +0000 | [diff] [blame] | 3702 | ++Reg; |
| 3703 | ++Count; |
| 3704 | } |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3705 | |
| 3706 | SMLoc E; |
| 3707 | if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success) |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3708 | return MatchOperand_ParseFail; |
Jim Grosbach | 080a499 | 2011-10-28 00:06:50 +0000 | [diff] [blame] | 3709 | |
Jim Grosbach | e891fe8 | 2011-11-15 23:19:15 +0000 | [diff] [blame] | 3710 | while (Parser.getTok().is(AsmToken::Comma) || |
| 3711 | Parser.getTok().is(AsmToken::Minus)) { |
| 3712 | if (Parser.getTok().is(AsmToken::Minus)) { |
Jim Grosbach | 2f50e92 | 2011-12-15 21:44:33 +0000 | [diff] [blame] | 3713 | if (!Spacing) |
| 3714 | Spacing = 1; // Register range implies a single spaced list. |
| 3715 | else if (Spacing == 2) { |
| 3716 | Error(Parser.getTok().getLoc(), |
| 3717 | "sequential registers in double spaced list"); |
| 3718 | return MatchOperand_ParseFail; |
| 3719 | } |
Jim Grosbach | e891fe8 | 2011-11-15 23:19:15 +0000 | [diff] [blame] | 3720 | Parser.Lex(); // Eat the minus. |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3721 | SMLoc AfterMinusLoc = Parser.getTok().getLoc(); |
Jim Grosbach | e891fe8 | 2011-11-15 23:19:15 +0000 | [diff] [blame] | 3722 | int EndReg = tryParseRegister(); |
| 3723 | if (EndReg == -1) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3724 | Error(AfterMinusLoc, "register expected"); |
Jim Grosbach | e891fe8 | 2011-11-15 23:19:15 +0000 | [diff] [blame] | 3725 | return MatchOperand_ParseFail; |
| 3726 | } |
| 3727 | // Allow Q regs and just interpret them as the two D sub-registers. |
| 3728 | if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg)) |
| 3729 | EndReg = getDRegFromQReg(EndReg) + 1; |
| 3730 | // If the register is the same as the start reg, there's nothing |
| 3731 | // more to do. |
| 3732 | if (Reg == EndReg) |
| 3733 | continue; |
| 3734 | // The register must be in the same register class as the first. |
| 3735 | if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3736 | Error(AfterMinusLoc, "invalid register in register list"); |
Jim Grosbach | e891fe8 | 2011-11-15 23:19:15 +0000 | [diff] [blame] | 3737 | return MatchOperand_ParseFail; |
| 3738 | } |
| 3739 | // Ranges must go from low to high. |
| 3740 | if (Reg > EndReg) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3741 | Error(AfterMinusLoc, "bad range in register list"); |
Jim Grosbach | e891fe8 | 2011-11-15 23:19:15 +0000 | [diff] [blame] | 3742 | return MatchOperand_ParseFail; |
| 3743 | } |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3744 | // Parse the lane specifier if present. |
| 3745 | VectorLaneTy NextLaneKind; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3746 | unsigned NextLaneIndex; |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3747 | if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != |
| 3748 | MatchOperand_Success) |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3749 | return MatchOperand_ParseFail; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3750 | if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3751 | Error(AfterMinusLoc, "mismatched lane index in register list"); |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3752 | return MatchOperand_ParseFail; |
| 3753 | } |
Jim Grosbach | e891fe8 | 2011-11-15 23:19:15 +0000 | [diff] [blame] | 3754 | |
| 3755 | // Add all the registers in the range to the register list. |
| 3756 | Count += EndReg - Reg; |
| 3757 | Reg = EndReg; |
| 3758 | continue; |
| 3759 | } |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3760 | Parser.Lex(); // Eat the comma. |
| 3761 | RegLoc = Parser.getTok().getLoc(); |
| 3762 | int OldReg = Reg; |
| 3763 | Reg = tryParseRegister(); |
| 3764 | if (Reg == -1) { |
| 3765 | Error(RegLoc, "register expected"); |
| 3766 | return MatchOperand_ParseFail; |
| 3767 | } |
Jim Grosbach | 080a499 | 2011-10-28 00:06:50 +0000 | [diff] [blame] | 3768 | // vector register lists must be contiguous. |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3769 | // It's OK to use the enumeration values directly here rather, as the |
| 3770 | // VFP register classes have the enum sorted properly. |
Jim Grosbach | 080a499 | 2011-10-28 00:06:50 +0000 | [diff] [blame] | 3771 | // |
| 3772 | // The list is of D registers, but we also allow Q regs and just interpret |
| 3773 | // them as the two D sub-registers. |
| 3774 | if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) { |
Jim Grosbach | 2f50e92 | 2011-12-15 21:44:33 +0000 | [diff] [blame] | 3775 | if (!Spacing) |
| 3776 | Spacing = 1; // Register range implies a single spaced list. |
| 3777 | else if (Spacing == 2) { |
| 3778 | Error(RegLoc, |
| 3779 | "invalid register in double-spaced list (must be 'D' register')"); |
| 3780 | return MatchOperand_ParseFail; |
| 3781 | } |
Jim Grosbach | 080a499 | 2011-10-28 00:06:50 +0000 | [diff] [blame] | 3782 | Reg = getDRegFromQReg(Reg); |
| 3783 | if (Reg != OldReg + 1) { |
| 3784 | Error(RegLoc, "non-contiguous register range"); |
| 3785 | return MatchOperand_ParseFail; |
| 3786 | } |
| 3787 | ++Reg; |
| 3788 | Count += 2; |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3789 | // Parse the lane specifier if present. |
| 3790 | VectorLaneTy NextLaneKind; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3791 | unsigned NextLaneIndex; |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3792 | SMLoc LaneLoc = Parser.getTok().getLoc(); |
| 3793 | if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != |
| 3794 | MatchOperand_Success) |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3795 | return MatchOperand_ParseFail; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3796 | if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3797 | Error(LaneLoc, "mismatched lane index in register list"); |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3798 | return MatchOperand_ParseFail; |
| 3799 | } |
Jim Grosbach | 080a499 | 2011-10-28 00:06:50 +0000 | [diff] [blame] | 3800 | continue; |
| 3801 | } |
Jim Grosbach | 2f50e92 | 2011-12-15 21:44:33 +0000 | [diff] [blame] | 3802 | // Normal D register. |
| 3803 | // Figure out the register spacing (single or double) of the list if |
| 3804 | // we don't know it already. |
| 3805 | if (!Spacing) |
| 3806 | Spacing = 1 + (Reg == OldReg + 2); |
| 3807 | |
| 3808 | // Just check that it's contiguous and keep going. |
| 3809 | if (Reg != OldReg + Spacing) { |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3810 | Error(RegLoc, "non-contiguous register range"); |
| 3811 | return MatchOperand_ParseFail; |
| 3812 | } |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3813 | ++Count; |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3814 | // Parse the lane specifier if present. |
| 3815 | VectorLaneTy NextLaneKind; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3816 | unsigned NextLaneIndex; |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3817 | SMLoc EndLoc = Parser.getTok().getLoc(); |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3818 | if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success) |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3819 | return MatchOperand_ParseFail; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3820 | if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) { |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3821 | Error(EndLoc, "mismatched lane index in register list"); |
| 3822 | return MatchOperand_ParseFail; |
| 3823 | } |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3824 | } |
| 3825 | |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3826 | if (Parser.getTok().isNot(AsmToken::RCurly)) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3827 | Error(Parser.getTok().getLoc(), "'}' expected"); |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3828 | return MatchOperand_ParseFail; |
| 3829 | } |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3830 | E = Parser.getTok().getEndLoc(); |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3831 | Parser.Lex(); // Eat '}' token. |
| 3832 | |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3833 | switch (LaneKind) { |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3834 | case NoLanes: |
Jim Grosbach | 13a292c | 2012-03-06 22:01:44 +0000 | [diff] [blame] | 3835 | // Two-register operands have been converted to the |
Jim Grosbach | e5307f9 | 2012-03-05 21:43:40 +0000 | [diff] [blame] | 3836 | // composite register classes. |
| 3837 | if (Count == 2) { |
| 3838 | const MCRegisterClass *RC = (Spacing == 1) ? |
| 3839 | &ARMMCRegisterClasses[ARM::DPairRegClassID] : |
| 3840 | &ARMMCRegisterClasses[ARM::DPairSpcRegClassID]; |
| 3841 | FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC); |
| 3842 | } |
Jim Grosbach | c988e0c | 2012-03-05 19:33:30 +0000 | [diff] [blame] | 3843 | |
Jim Grosbach | 2f50e92 | 2011-12-15 21:44:33 +0000 | [diff] [blame] | 3844 | Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count, |
| 3845 | (Spacing == 2), S, E)); |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3846 | break; |
| 3847 | case AllLanes: |
Jim Grosbach | 13a292c | 2012-03-06 22:01:44 +0000 | [diff] [blame] | 3848 | // Two-register operands have been converted to the |
| 3849 | // composite register classes. |
Jim Grosbach | ed428bc | 2012-03-06 23:10:38 +0000 | [diff] [blame] | 3850 | if (Count == 2) { |
| 3851 | const MCRegisterClass *RC = (Spacing == 1) ? |
| 3852 | &ARMMCRegisterClasses[ARM::DPairRegClassID] : |
| 3853 | &ARMMCRegisterClasses[ARM::DPairSpcRegClassID]; |
Jim Grosbach | 13a292c | 2012-03-06 22:01:44 +0000 | [diff] [blame] | 3854 | FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC); |
| 3855 | } |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3856 | Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count, |
Jim Grosbach | c5af54e | 2011-12-21 00:38:54 +0000 | [diff] [blame] | 3857 | (Spacing == 2), |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3858 | S, E)); |
| 3859 | break; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3860 | case IndexedLane: |
| 3861 | Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count, |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 3862 | LaneIndex, |
| 3863 | (Spacing == 2), |
| 3864 | S, E)); |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3865 | break; |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3866 | } |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3867 | return MatchOperand_Success; |
| 3868 | } |
| 3869 | |
Jim Grosbach | 2d6ef44 | 2011-07-25 20:14:50 +0000 | [diff] [blame] | 3870 | /// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 3871 | ARMAsmParser::OperandMatchResultTy |
| 3872 | ARMAsmParser::parseMemBarrierOptOperand(OperandVector &Operands) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 3873 | MCAsmParser &Parser = getParser(); |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 3874 | SMLoc S = Parser.getTok().getLoc(); |
| 3875 | const AsmToken &Tok = Parser.getTok(); |
Jiangning Liu | 288e1af | 2012-08-02 08:21:27 +0000 | [diff] [blame] | 3876 | unsigned Opt; |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 3877 | |
Jiangning Liu | 288e1af | 2012-08-02 08:21:27 +0000 | [diff] [blame] | 3878 | if (Tok.is(AsmToken::Identifier)) { |
| 3879 | StringRef OptStr = Tok.getString(); |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 3880 | |
Jiangning Liu | 288e1af | 2012-08-02 08:21:27 +0000 | [diff] [blame] | 3881 | Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower()) |
| 3882 | .Case("sy", ARM_MB::SY) |
| 3883 | .Case("st", ARM_MB::ST) |
Joey Gouly | 926d3f5 | 2013-09-05 15:35:24 +0000 | [diff] [blame] | 3884 | .Case("ld", ARM_MB::LD) |
Jiangning Liu | 288e1af | 2012-08-02 08:21:27 +0000 | [diff] [blame] | 3885 | .Case("sh", ARM_MB::ISH) |
| 3886 | .Case("ish", ARM_MB::ISH) |
| 3887 | .Case("shst", ARM_MB::ISHST) |
| 3888 | .Case("ishst", ARM_MB::ISHST) |
Joey Gouly | 926d3f5 | 2013-09-05 15:35:24 +0000 | [diff] [blame] | 3889 | .Case("ishld", ARM_MB::ISHLD) |
Jiangning Liu | 288e1af | 2012-08-02 08:21:27 +0000 | [diff] [blame] | 3890 | .Case("nsh", ARM_MB::NSH) |
| 3891 | .Case("un", ARM_MB::NSH) |
| 3892 | .Case("nshst", ARM_MB::NSHST) |
Joey Gouly | 926d3f5 | 2013-09-05 15:35:24 +0000 | [diff] [blame] | 3893 | .Case("nshld", ARM_MB::NSHLD) |
Jiangning Liu | 288e1af | 2012-08-02 08:21:27 +0000 | [diff] [blame] | 3894 | .Case("unst", ARM_MB::NSHST) |
| 3895 | .Case("osh", ARM_MB::OSH) |
| 3896 | .Case("oshst", ARM_MB::OSHST) |
Joey Gouly | 926d3f5 | 2013-09-05 15:35:24 +0000 | [diff] [blame] | 3897 | .Case("oshld", ARM_MB::OSHLD) |
Jiangning Liu | 288e1af | 2012-08-02 08:21:27 +0000 | [diff] [blame] | 3898 | .Default(~0U); |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 3899 | |
Joey Gouly | 926d3f5 | 2013-09-05 15:35:24 +0000 | [diff] [blame] | 3900 | // ishld, oshld, nshld and ld are only available from ARMv8. |
| 3901 | if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD || |
| 3902 | Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD)) |
| 3903 | Opt = ~0U; |
| 3904 | |
Jiangning Liu | 288e1af | 2012-08-02 08:21:27 +0000 | [diff] [blame] | 3905 | if (Opt == ~0U) |
| 3906 | return MatchOperand_NoMatch; |
| 3907 | |
| 3908 | Parser.Lex(); // Eat identifier token. |
| 3909 | } else if (Tok.is(AsmToken::Hash) || |
| 3910 | Tok.is(AsmToken::Dollar) || |
| 3911 | Tok.is(AsmToken::Integer)) { |
| 3912 | if (Parser.getTok().isNot(AsmToken::Integer)) |
Amaury de la Vieuville | bac917f | 2013-06-10 14:17:15 +0000 | [diff] [blame] | 3913 | Parser.Lex(); // Eat '#' or '$'. |
Jiangning Liu | 288e1af | 2012-08-02 08:21:27 +0000 | [diff] [blame] | 3914 | SMLoc Loc = Parser.getTok().getLoc(); |
| 3915 | |
| 3916 | const MCExpr *MemBarrierID; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 3917 | if (getParser().parseExpression(MemBarrierID)) { |
Jiangning Liu | 288e1af | 2012-08-02 08:21:27 +0000 | [diff] [blame] | 3918 | Error(Loc, "illegal expression"); |
| 3919 | return MatchOperand_ParseFail; |
| 3920 | } |
Saleem Abdulrasool | 4ab6e73 | 2014-02-23 17:45:36 +0000 | [diff] [blame] | 3921 | |
Jiangning Liu | 288e1af | 2012-08-02 08:21:27 +0000 | [diff] [blame] | 3922 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID); |
| 3923 | if (!CE) { |
| 3924 | Error(Loc, "constant expression expected"); |
| 3925 | return MatchOperand_ParseFail; |
| 3926 | } |
| 3927 | |
| 3928 | int Val = CE->getValue(); |
| 3929 | if (Val & ~0xf) { |
| 3930 | Error(Loc, "immediate value out of range"); |
| 3931 | return MatchOperand_ParseFail; |
| 3932 | } |
| 3933 | |
| 3934 | Opt = ARM_MB::RESERVED_0 + Val; |
| 3935 | } else |
| 3936 | return MatchOperand_ParseFail; |
| 3937 | |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 3938 | Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S)); |
Jim Grosbach | 861e49c | 2011-02-12 01:34:40 +0000 | [diff] [blame] | 3939 | return MatchOperand_Success; |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 3940 | } |
| 3941 | |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 3942 | /// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 3943 | ARMAsmParser::OperandMatchResultTy |
| 3944 | ARMAsmParser::parseInstSyncBarrierOptOperand(OperandVector &Operands) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 3945 | MCAsmParser &Parser = getParser(); |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 3946 | SMLoc S = Parser.getTok().getLoc(); |
| 3947 | const AsmToken &Tok = Parser.getTok(); |
| 3948 | unsigned Opt; |
| 3949 | |
| 3950 | if (Tok.is(AsmToken::Identifier)) { |
| 3951 | StringRef OptStr = Tok.getString(); |
| 3952 | |
Benjamin Kramer | 3e9237a | 2013-11-09 22:48:13 +0000 | [diff] [blame] | 3953 | if (OptStr.equals_lower("sy")) |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 3954 | Opt = ARM_ISB::SY; |
| 3955 | else |
| 3956 | return MatchOperand_NoMatch; |
| 3957 | |
| 3958 | Parser.Lex(); // Eat identifier token. |
| 3959 | } else if (Tok.is(AsmToken::Hash) || |
| 3960 | Tok.is(AsmToken::Dollar) || |
| 3961 | Tok.is(AsmToken::Integer)) { |
| 3962 | if (Parser.getTok().isNot(AsmToken::Integer)) |
Amaury de la Vieuville | bac917f | 2013-06-10 14:17:15 +0000 | [diff] [blame] | 3963 | Parser.Lex(); // Eat '#' or '$'. |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 3964 | SMLoc Loc = Parser.getTok().getLoc(); |
| 3965 | |
| 3966 | const MCExpr *ISBarrierID; |
| 3967 | if (getParser().parseExpression(ISBarrierID)) { |
| 3968 | Error(Loc, "illegal expression"); |
| 3969 | return MatchOperand_ParseFail; |
| 3970 | } |
| 3971 | |
| 3972 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID); |
| 3973 | if (!CE) { |
| 3974 | Error(Loc, "constant expression expected"); |
| 3975 | return MatchOperand_ParseFail; |
| 3976 | } |
| 3977 | |
| 3978 | int Val = CE->getValue(); |
| 3979 | if (Val & ~0xf) { |
| 3980 | Error(Loc, "immediate value out of range"); |
| 3981 | return MatchOperand_ParseFail; |
| 3982 | } |
| 3983 | |
| 3984 | Opt = ARM_ISB::RESERVED_0 + Val; |
| 3985 | } else |
| 3986 | return MatchOperand_ParseFail; |
| 3987 | |
| 3988 | Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt( |
| 3989 | (ARM_ISB::InstSyncBOpt)Opt, S)); |
| 3990 | return MatchOperand_Success; |
| 3991 | } |
| 3992 | |
| 3993 | |
Jim Grosbach | 2d6ef44 | 2011-07-25 20:14:50 +0000 | [diff] [blame] | 3994 | /// parseProcIFlagsOperand - Try to parse iflags from CPS instruction. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 3995 | ARMAsmParser::OperandMatchResultTy |
| 3996 | ARMAsmParser::parseProcIFlagsOperand(OperandVector &Operands) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 3997 | MCAsmParser &Parser = getParser(); |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 3998 | SMLoc S = Parser.getTok().getLoc(); |
| 3999 | const AsmToken &Tok = Parser.getTok(); |
Richard Barton | b0ec375 | 2012-06-14 10:48:04 +0000 | [diff] [blame] | 4000 | if (!Tok.is(AsmToken::Identifier)) |
| 4001 | return MatchOperand_NoMatch; |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 4002 | StringRef IFlagsStr = Tok.getString(); |
| 4003 | |
Owen Anderson | 10c5b12 | 2011-10-05 17:16:40 +0000 | [diff] [blame] | 4004 | // An iflags string of "none" is interpreted to mean that none of the AIF |
| 4005 | // 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] | 4006 | unsigned IFlags = 0; |
Owen Anderson | 10c5b12 | 2011-10-05 17:16:40 +0000 | [diff] [blame] | 4007 | if (IFlagsStr != "none") { |
| 4008 | for (int i = 0, e = IFlagsStr.size(); i != e; ++i) { |
| 4009 | unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1)) |
| 4010 | .Case("a", ARM_PROC::A) |
| 4011 | .Case("i", ARM_PROC::I) |
| 4012 | .Case("f", ARM_PROC::F) |
| 4013 | .Default(~0U); |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 4014 | |
Owen Anderson | 10c5b12 | 2011-10-05 17:16:40 +0000 | [diff] [blame] | 4015 | // If some specific iflag is already set, it means that some letter is |
| 4016 | // present more than once, this is not acceptable. |
| 4017 | if (Flag == ~0U || (IFlags & Flag)) |
| 4018 | return MatchOperand_NoMatch; |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 4019 | |
Owen Anderson | 10c5b12 | 2011-10-05 17:16:40 +0000 | [diff] [blame] | 4020 | IFlags |= Flag; |
| 4021 | } |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 4022 | } |
| 4023 | |
| 4024 | Parser.Lex(); // Eat identifier token. |
| 4025 | Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S)); |
| 4026 | return MatchOperand_Success; |
| 4027 | } |
| 4028 | |
Jim Grosbach | 2d6ef44 | 2011-07-25 20:14:50 +0000 | [diff] [blame] | 4029 | /// parseMSRMaskOperand - Try to parse mask flags from MSR instruction. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4030 | ARMAsmParser::OperandMatchResultTy |
| 4031 | ARMAsmParser::parseMSRMaskOperand(OperandVector &Operands) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 4032 | MCAsmParser &Parser = getParser(); |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 4033 | SMLoc S = Parser.getTok().getLoc(); |
| 4034 | const AsmToken &Tok = Parser.getTok(); |
Craig Topper | a004b0d | 2012-10-09 04:55:28 +0000 | [diff] [blame] | 4035 | if (!Tok.is(AsmToken::Identifier)) |
| 4036 | return MatchOperand_NoMatch; |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 4037 | StringRef Mask = Tok.getString(); |
| 4038 | |
James Molloy | 21efa7d | 2011-09-28 14:21:38 +0000 | [diff] [blame] | 4039 | if (isMClass()) { |
| 4040 | // See ARMv6-M 10.1.1 |
Jim Grosbach | d28888d | 2012-03-15 21:34:14 +0000 | [diff] [blame] | 4041 | std::string Name = Mask.lower(); |
| 4042 | unsigned FlagsVal = StringSwitch<unsigned>(Name) |
Kevin Enderby | f1b225d | 2012-05-17 22:18:01 +0000 | [diff] [blame] | 4043 | // Note: in the documentation: |
| 4044 | // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias |
| 4045 | // for MSR APSR_nzcvq. |
| 4046 | // but we do make it an alias here. This is so to get the "mask encoding" |
| 4047 | // bits correct on MSR APSR writes. |
| 4048 | // |
| 4049 | // FIXME: Note the 0xc00 "mask encoding" bits version of the registers |
| 4050 | // should really only be allowed when writing a special register. Note |
| 4051 | // they get dropped in the MRS instruction reading a special register as |
| 4052 | // the SYSm field is only 8 bits. |
Kevin Enderby | f1b225d | 2012-05-17 22:18:01 +0000 | [diff] [blame] | 4053 | .Case("apsr", 0x800) |
| 4054 | .Case("apsr_nzcvq", 0x800) |
| 4055 | .Case("apsr_g", 0x400) |
| 4056 | .Case("apsr_nzcvqg", 0xc00) |
| 4057 | .Case("iapsr", 0x801) |
| 4058 | .Case("iapsr_nzcvq", 0x801) |
| 4059 | .Case("iapsr_g", 0x401) |
| 4060 | .Case("iapsr_nzcvqg", 0xc01) |
| 4061 | .Case("eapsr", 0x802) |
| 4062 | .Case("eapsr_nzcvq", 0x802) |
| 4063 | .Case("eapsr_g", 0x402) |
| 4064 | .Case("eapsr_nzcvqg", 0xc02) |
| 4065 | .Case("xpsr", 0x803) |
| 4066 | .Case("xpsr_nzcvq", 0x803) |
| 4067 | .Case("xpsr_g", 0x403) |
| 4068 | .Case("xpsr_nzcvqg", 0xc03) |
Kevin Enderby | 6c7279e | 2012-06-15 22:14:44 +0000 | [diff] [blame] | 4069 | .Case("ipsr", 0x805) |
| 4070 | .Case("epsr", 0x806) |
| 4071 | .Case("iepsr", 0x807) |
| 4072 | .Case("msp", 0x808) |
| 4073 | .Case("psp", 0x809) |
| 4074 | .Case("primask", 0x810) |
| 4075 | .Case("basepri", 0x811) |
| 4076 | .Case("basepri_max", 0x812) |
| 4077 | .Case("faultmask", 0x813) |
| 4078 | .Case("control", 0x814) |
James Molloy | 21efa7d | 2011-09-28 14:21:38 +0000 | [diff] [blame] | 4079 | .Default(~0U); |
Jim Grosbach | 3794d82 | 2011-12-22 17:17:10 +0000 | [diff] [blame] | 4080 | |
James Molloy | 21efa7d | 2011-09-28 14:21:38 +0000 | [diff] [blame] | 4081 | if (FlagsVal == ~0U) |
| 4082 | return MatchOperand_NoMatch; |
| 4083 | |
Renato Golin | 92c816c | 2014-09-01 11:25:07 +0000 | [diff] [blame] | 4084 | if (!hasThumb2DSP() && (FlagsVal & 0x400)) |
| 4085 | // The _g and _nzcvqg versions are only valid if the DSP extension is |
| 4086 | // available. |
| 4087 | return MatchOperand_NoMatch; |
| 4088 | |
Kevin Enderby | 6c7279e | 2012-06-15 22:14:44 +0000 | [diff] [blame] | 4089 | if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813) |
James Molloy | 21efa7d | 2011-09-28 14:21:38 +0000 | [diff] [blame] | 4090 | // basepri, basepri_max and faultmask only valid for V7m. |
| 4091 | return MatchOperand_NoMatch; |
Jim Grosbach | 3794d82 | 2011-12-22 17:17:10 +0000 | [diff] [blame] | 4092 | |
James Molloy | 21efa7d | 2011-09-28 14:21:38 +0000 | [diff] [blame] | 4093 | Parser.Lex(); // Eat identifier token. |
| 4094 | Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S)); |
| 4095 | return MatchOperand_Success; |
| 4096 | } |
| 4097 | |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 4098 | // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf" |
| 4099 | size_t Start = 0, Next = Mask.find('_'); |
| 4100 | StringRef Flags = ""; |
Benjamin Kramer | 20baffb | 2011-11-06 20:37:06 +0000 | [diff] [blame] | 4101 | std::string SpecReg = Mask.slice(Start, Next).lower(); |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 4102 | if (Next != StringRef::npos) |
| 4103 | Flags = Mask.slice(Next+1, Mask.size()); |
| 4104 | |
| 4105 | // FlagsVal contains the complete mask: |
| 4106 | // 3-0: Mask |
| 4107 | // 4: Special Reg (cpsr, apsr => 0; spsr => 1) |
| 4108 | unsigned FlagsVal = 0; |
| 4109 | |
| 4110 | if (SpecReg == "apsr") { |
| 4111 | FlagsVal = StringSwitch<unsigned>(Flags) |
Jim Grosbach | d25c2cd | 2011-07-19 22:45:10 +0000 | [diff] [blame] | 4112 | .Case("nzcvq", 0x8) // same as CPSR_f |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 4113 | .Case("g", 0x4) // same as CPSR_s |
| 4114 | .Case("nzcvqg", 0xc) // same as CPSR_fs |
| 4115 | .Default(~0U); |
| 4116 | |
Joerg Sonnenberger | 740467a | 2011-02-19 00:43:45 +0000 | [diff] [blame] | 4117 | if (FlagsVal == ~0U) { |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 4118 | if (!Flags.empty()) |
| 4119 | return MatchOperand_NoMatch; |
| 4120 | else |
Jim Grosbach | 0ecd395 | 2011-09-14 20:03:46 +0000 | [diff] [blame] | 4121 | FlagsVal = 8; // No flag |
Joerg Sonnenberger | 740467a | 2011-02-19 00:43:45 +0000 | [diff] [blame] | 4122 | } |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 4123 | } else if (SpecReg == "cpsr" || SpecReg == "spsr") { |
Jim Grosbach | 3d00eec | 2012-04-05 03:17:53 +0000 | [diff] [blame] | 4124 | // cpsr_all is an alias for cpsr_fc, as is plain cpsr. |
| 4125 | if (Flags == "all" || Flags == "") |
Bruno Cardoso Lopes | 5445213 | 2011-05-25 00:35:03 +0000 | [diff] [blame] | 4126 | Flags = "fc"; |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 4127 | for (int i = 0, e = Flags.size(); i != e; ++i) { |
| 4128 | unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1)) |
| 4129 | .Case("c", 1) |
| 4130 | .Case("x", 2) |
| 4131 | .Case("s", 4) |
| 4132 | .Case("f", 8) |
| 4133 | .Default(~0U); |
| 4134 | |
| 4135 | // If some specific flag is already set, it means that some letter is |
| 4136 | // present more than once, this is not acceptable. |
| 4137 | if (FlagsVal == ~0U || (FlagsVal & Flag)) |
| 4138 | return MatchOperand_NoMatch; |
| 4139 | FlagsVal |= Flag; |
| 4140 | } |
| 4141 | } else // No match for special register. |
| 4142 | return MatchOperand_NoMatch; |
| 4143 | |
Owen Anderson | 03a173e | 2011-10-21 18:43:28 +0000 | [diff] [blame] | 4144 | // Special register without flags is NOT equivalent to "fc" flags. |
| 4145 | // NOTE: This is a divergence from gas' behavior. Uncommenting the following |
| 4146 | // two lines would enable gas compatibility at the expense of breaking |
| 4147 | // round-tripping. |
| 4148 | // |
| 4149 | // if (!FlagsVal) |
| 4150 | // FlagsVal = 0x9; |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 4151 | |
| 4152 | // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1) |
| 4153 | if (SpecReg == "spsr") |
| 4154 | FlagsVal |= 16; |
| 4155 | |
| 4156 | Parser.Lex(); // Eat identifier token. |
| 4157 | Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S)); |
| 4158 | return MatchOperand_Success; |
| 4159 | } |
| 4160 | |
Tim Northover | ee843ef | 2014-08-15 10:47:12 +0000 | [diff] [blame] | 4161 | /// parseBankedRegOperand - Try to parse a banked register (e.g. "lr_irq") for |
| 4162 | /// use in the MRS/MSR instructions added to support virtualization. |
| 4163 | ARMAsmParser::OperandMatchResultTy |
| 4164 | ARMAsmParser::parseBankedRegOperand(OperandVector &Operands) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 4165 | MCAsmParser &Parser = getParser(); |
Tim Northover | ee843ef | 2014-08-15 10:47:12 +0000 | [diff] [blame] | 4166 | SMLoc S = Parser.getTok().getLoc(); |
| 4167 | const AsmToken &Tok = Parser.getTok(); |
| 4168 | if (!Tok.is(AsmToken::Identifier)) |
| 4169 | return MatchOperand_NoMatch; |
| 4170 | StringRef RegName = Tok.getString(); |
| 4171 | |
| 4172 | // The values here come from B9.2.3 of the ARM ARM, where bits 4-0 are SysM |
| 4173 | // and bit 5 is R. |
| 4174 | unsigned Encoding = StringSwitch<unsigned>(RegName.lower()) |
| 4175 | .Case("r8_usr", 0x00) |
| 4176 | .Case("r9_usr", 0x01) |
| 4177 | .Case("r10_usr", 0x02) |
| 4178 | .Case("r11_usr", 0x03) |
| 4179 | .Case("r12_usr", 0x04) |
| 4180 | .Case("sp_usr", 0x05) |
| 4181 | .Case("lr_usr", 0x06) |
| 4182 | .Case("r8_fiq", 0x08) |
| 4183 | .Case("r9_fiq", 0x09) |
| 4184 | .Case("r10_fiq", 0x0a) |
| 4185 | .Case("r11_fiq", 0x0b) |
| 4186 | .Case("r12_fiq", 0x0c) |
| 4187 | .Case("sp_fiq", 0x0d) |
| 4188 | .Case("lr_fiq", 0x0e) |
| 4189 | .Case("lr_irq", 0x10) |
| 4190 | .Case("sp_irq", 0x11) |
| 4191 | .Case("lr_svc", 0x12) |
| 4192 | .Case("sp_svc", 0x13) |
| 4193 | .Case("lr_abt", 0x14) |
| 4194 | .Case("sp_abt", 0x15) |
| 4195 | .Case("lr_und", 0x16) |
| 4196 | .Case("sp_und", 0x17) |
| 4197 | .Case("lr_mon", 0x1c) |
| 4198 | .Case("sp_mon", 0x1d) |
| 4199 | .Case("elr_hyp", 0x1e) |
| 4200 | .Case("sp_hyp", 0x1f) |
| 4201 | .Case("spsr_fiq", 0x2e) |
| 4202 | .Case("spsr_irq", 0x30) |
| 4203 | .Case("spsr_svc", 0x32) |
| 4204 | .Case("spsr_abt", 0x34) |
| 4205 | .Case("spsr_und", 0x36) |
| 4206 | .Case("spsr_mon", 0x3c) |
| 4207 | .Case("spsr_hyp", 0x3e) |
| 4208 | .Default(~0U); |
| 4209 | |
| 4210 | if (Encoding == ~0U) |
| 4211 | return MatchOperand_NoMatch; |
| 4212 | |
| 4213 | Parser.Lex(); // Eat identifier token. |
| 4214 | Operands.push_back(ARMOperand::CreateBankedReg(Encoding, S)); |
| 4215 | return MatchOperand_Success; |
| 4216 | } |
| 4217 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4218 | ARMAsmParser::OperandMatchResultTy |
| 4219 | ARMAsmParser::parsePKHImm(OperandVector &Operands, StringRef Op, int Low, |
| 4220 | int High) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 4221 | MCAsmParser &Parser = getParser(); |
Jim Grosbach | 27c1e25 | 2011-07-21 17:23:04 +0000 | [diff] [blame] | 4222 | const AsmToken &Tok = Parser.getTok(); |
| 4223 | if (Tok.isNot(AsmToken::Identifier)) { |
| 4224 | Error(Parser.getTok().getLoc(), Op + " operand expected."); |
| 4225 | return MatchOperand_ParseFail; |
| 4226 | } |
| 4227 | StringRef ShiftName = Tok.getString(); |
Benjamin Kramer | 20baffb | 2011-11-06 20:37:06 +0000 | [diff] [blame] | 4228 | std::string LowerOp = Op.lower(); |
| 4229 | std::string UpperOp = Op.upper(); |
Jim Grosbach | 27c1e25 | 2011-07-21 17:23:04 +0000 | [diff] [blame] | 4230 | if (ShiftName != LowerOp && ShiftName != UpperOp) { |
| 4231 | Error(Parser.getTok().getLoc(), Op + " operand expected."); |
| 4232 | return MatchOperand_ParseFail; |
| 4233 | } |
| 4234 | Parser.Lex(); // Eat shift type token. |
| 4235 | |
| 4236 | // There must be a '#' and a shift amount. |
Jim Grosbach | ef70e9b | 2011-12-09 22:25:03 +0000 | [diff] [blame] | 4237 | if (Parser.getTok().isNot(AsmToken::Hash) && |
| 4238 | Parser.getTok().isNot(AsmToken::Dollar)) { |
Jim Grosbach | 27c1e25 | 2011-07-21 17:23:04 +0000 | [diff] [blame] | 4239 | Error(Parser.getTok().getLoc(), "'#' expected"); |
| 4240 | return MatchOperand_ParseFail; |
| 4241 | } |
| 4242 | Parser.Lex(); // Eat hash token. |
| 4243 | |
| 4244 | const MCExpr *ShiftAmount; |
| 4245 | SMLoc Loc = Parser.getTok().getLoc(); |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4246 | SMLoc EndLoc; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 4247 | if (getParser().parseExpression(ShiftAmount, EndLoc)) { |
Jim Grosbach | 27c1e25 | 2011-07-21 17:23:04 +0000 | [diff] [blame] | 4248 | Error(Loc, "illegal expression"); |
| 4249 | return MatchOperand_ParseFail; |
| 4250 | } |
| 4251 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount); |
| 4252 | if (!CE) { |
| 4253 | Error(Loc, "constant expression expected"); |
| 4254 | return MatchOperand_ParseFail; |
| 4255 | } |
| 4256 | int Val = CE->getValue(); |
| 4257 | if (Val < Low || Val > High) { |
| 4258 | Error(Loc, "immediate value out of range"); |
| 4259 | return MatchOperand_ParseFail; |
| 4260 | } |
| 4261 | |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4262 | Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc)); |
Jim Grosbach | 27c1e25 | 2011-07-21 17:23:04 +0000 | [diff] [blame] | 4263 | |
| 4264 | return MatchOperand_Success; |
| 4265 | } |
| 4266 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4267 | ARMAsmParser::OperandMatchResultTy |
| 4268 | ARMAsmParser::parseSetEndImm(OperandVector &Operands) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 4269 | MCAsmParser &Parser = getParser(); |
Jim Grosbach | 0a54770 | 2011-07-22 17:44:50 +0000 | [diff] [blame] | 4270 | const AsmToken &Tok = Parser.getTok(); |
| 4271 | SMLoc S = Tok.getLoc(); |
| 4272 | if (Tok.isNot(AsmToken::Identifier)) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4273 | Error(S, "'be' or 'le' operand expected"); |
Jim Grosbach | 0a54770 | 2011-07-22 17:44:50 +0000 | [diff] [blame] | 4274 | return MatchOperand_ParseFail; |
| 4275 | } |
Tim Northover | 4d14144 | 2013-05-31 15:58:45 +0000 | [diff] [blame] | 4276 | int Val = StringSwitch<int>(Tok.getString().lower()) |
Jim Grosbach | 0a54770 | 2011-07-22 17:44:50 +0000 | [diff] [blame] | 4277 | .Case("be", 1) |
| 4278 | .Case("le", 0) |
| 4279 | .Default(-1); |
| 4280 | Parser.Lex(); // Eat the token. |
| 4281 | |
| 4282 | if (Val == -1) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4283 | Error(S, "'be' or 'le' operand expected"); |
Jim Grosbach | 0a54770 | 2011-07-22 17:44:50 +0000 | [diff] [blame] | 4284 | return MatchOperand_ParseFail; |
| 4285 | } |
| 4286 | Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val, |
| 4287 | getContext()), |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4288 | S, Tok.getEndLoc())); |
Jim Grosbach | 0a54770 | 2011-07-22 17:44:50 +0000 | [diff] [blame] | 4289 | return MatchOperand_Success; |
| 4290 | } |
| 4291 | |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 4292 | /// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT |
| 4293 | /// instructions. Legal values are: |
| 4294 | /// lsl #n 'n' in [0,31] |
| 4295 | /// asr #n 'n' in [1,32] |
| 4296 | /// n == 32 encoded as n == 0. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4297 | ARMAsmParser::OperandMatchResultTy |
| 4298 | ARMAsmParser::parseShifterImm(OperandVector &Operands) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 4299 | MCAsmParser &Parser = getParser(); |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 4300 | const AsmToken &Tok = Parser.getTok(); |
| 4301 | SMLoc S = Tok.getLoc(); |
| 4302 | if (Tok.isNot(AsmToken::Identifier)) { |
| 4303 | Error(S, "shift operator 'asr' or 'lsl' expected"); |
| 4304 | return MatchOperand_ParseFail; |
| 4305 | } |
| 4306 | StringRef ShiftName = Tok.getString(); |
| 4307 | bool isASR; |
| 4308 | if (ShiftName == "lsl" || ShiftName == "LSL") |
| 4309 | isASR = false; |
| 4310 | else if (ShiftName == "asr" || ShiftName == "ASR") |
| 4311 | isASR = true; |
| 4312 | else { |
| 4313 | Error(S, "shift operator 'asr' or 'lsl' expected"); |
| 4314 | return MatchOperand_ParseFail; |
| 4315 | } |
| 4316 | Parser.Lex(); // Eat the operator. |
| 4317 | |
| 4318 | // A '#' and a shift amount. |
Jim Grosbach | ef70e9b | 2011-12-09 22:25:03 +0000 | [diff] [blame] | 4319 | if (Parser.getTok().isNot(AsmToken::Hash) && |
| 4320 | Parser.getTok().isNot(AsmToken::Dollar)) { |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 4321 | Error(Parser.getTok().getLoc(), "'#' expected"); |
| 4322 | return MatchOperand_ParseFail; |
| 4323 | } |
| 4324 | Parser.Lex(); // Eat hash token. |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4325 | SMLoc ExLoc = Parser.getTok().getLoc(); |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 4326 | |
| 4327 | const MCExpr *ShiftAmount; |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4328 | SMLoc EndLoc; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 4329 | if (getParser().parseExpression(ShiftAmount, EndLoc)) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4330 | Error(ExLoc, "malformed shift expression"); |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 4331 | return MatchOperand_ParseFail; |
| 4332 | } |
| 4333 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount); |
| 4334 | if (!CE) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4335 | Error(ExLoc, "shift amount must be an immediate"); |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 4336 | return MatchOperand_ParseFail; |
| 4337 | } |
| 4338 | |
| 4339 | int64_t Val = CE->getValue(); |
| 4340 | if (isASR) { |
| 4341 | // Shift amount must be in [1,32] |
| 4342 | if (Val < 1 || Val > 32) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4343 | Error(ExLoc, "'asr' shift amount must be in range [1,32]"); |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 4344 | return MatchOperand_ParseFail; |
| 4345 | } |
Owen Anderson | f01e2de | 2011-09-26 21:06:22 +0000 | [diff] [blame] | 4346 | // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode. |
| 4347 | if (isThumb() && Val == 32) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4348 | Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode"); |
Owen Anderson | f01e2de | 2011-09-26 21:06:22 +0000 | [diff] [blame] | 4349 | return MatchOperand_ParseFail; |
| 4350 | } |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 4351 | if (Val == 32) Val = 0; |
| 4352 | } else { |
| 4353 | // Shift amount must be in [1,32] |
| 4354 | if (Val < 0 || Val > 31) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4355 | Error(ExLoc, "'lsr' shift amount must be in range [0,31]"); |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 4356 | return MatchOperand_ParseFail; |
| 4357 | } |
| 4358 | } |
| 4359 | |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4360 | Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc)); |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 4361 | |
| 4362 | return MatchOperand_Success; |
| 4363 | } |
| 4364 | |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 4365 | /// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family |
| 4366 | /// of instructions. Legal values are: |
| 4367 | /// ror #n 'n' in {0, 8, 16, 24} |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4368 | ARMAsmParser::OperandMatchResultTy |
| 4369 | ARMAsmParser::parseRotImm(OperandVector &Operands) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 4370 | MCAsmParser &Parser = getParser(); |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 4371 | const AsmToken &Tok = Parser.getTok(); |
| 4372 | SMLoc S = Tok.getLoc(); |
Jim Grosbach | 8221319 | 2011-09-19 20:29:33 +0000 | [diff] [blame] | 4373 | if (Tok.isNot(AsmToken::Identifier)) |
| 4374 | return MatchOperand_NoMatch; |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 4375 | StringRef ShiftName = Tok.getString(); |
Jim Grosbach | 8221319 | 2011-09-19 20:29:33 +0000 | [diff] [blame] | 4376 | if (ShiftName != "ror" && ShiftName != "ROR") |
| 4377 | return MatchOperand_NoMatch; |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 4378 | Parser.Lex(); // Eat the operator. |
| 4379 | |
| 4380 | // A '#' and a rotate amount. |
Jim Grosbach | ef70e9b | 2011-12-09 22:25:03 +0000 | [diff] [blame] | 4381 | if (Parser.getTok().isNot(AsmToken::Hash) && |
| 4382 | Parser.getTok().isNot(AsmToken::Dollar)) { |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 4383 | Error(Parser.getTok().getLoc(), "'#' expected"); |
| 4384 | return MatchOperand_ParseFail; |
| 4385 | } |
| 4386 | Parser.Lex(); // Eat hash token. |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4387 | SMLoc ExLoc = Parser.getTok().getLoc(); |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 4388 | |
| 4389 | const MCExpr *ShiftAmount; |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4390 | SMLoc EndLoc; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 4391 | if (getParser().parseExpression(ShiftAmount, EndLoc)) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4392 | Error(ExLoc, "malformed rotate expression"); |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 4393 | return MatchOperand_ParseFail; |
| 4394 | } |
| 4395 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount); |
| 4396 | if (!CE) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4397 | Error(ExLoc, "rotate amount must be an immediate"); |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 4398 | return MatchOperand_ParseFail; |
| 4399 | } |
| 4400 | |
| 4401 | int64_t Val = CE->getValue(); |
| 4402 | // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension) |
| 4403 | // normally, zero is represented in asm by omitting the rotate operand |
| 4404 | // entirely. |
| 4405 | if (Val != 8 && Val != 16 && Val != 24 && Val != 0) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4406 | Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24"); |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 4407 | return MatchOperand_ParseFail; |
| 4408 | } |
| 4409 | |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4410 | Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc)); |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 4411 | |
| 4412 | return MatchOperand_Success; |
| 4413 | } |
| 4414 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4415 | ARMAsmParser::OperandMatchResultTy |
Asiri Rathnayake | a0199b9 | 2014-12-02 10:53:20 +0000 | [diff] [blame] | 4416 | ARMAsmParser::parseModImm(OperandVector &Operands) { |
| 4417 | MCAsmParser &Parser = getParser(); |
| 4418 | MCAsmLexer &Lexer = getLexer(); |
| 4419 | int64_t Imm1, Imm2; |
| 4420 | |
Asiri Rathnayake | a0199b9 | 2014-12-02 10:53:20 +0000 | [diff] [blame] | 4421 | SMLoc S = Parser.getTok().getLoc(); |
| 4422 | |
Asiri Rathnayake | 13cef35 | 2014-12-04 19:34:59 +0000 | [diff] [blame] | 4423 | // 1) A mod_imm operand can appear in the place of a register name: |
| 4424 | // add r0, #mod_imm |
| 4425 | // add r0, r0, #mod_imm |
| 4426 | // to correctly handle the latter, we bail out as soon as we see an |
| 4427 | // identifier. |
| 4428 | // |
| 4429 | // 2) Similarly, we do not want to parse into complex operands: |
| 4430 | // mov r0, #mod_imm |
| 4431 | // mov r0, :lower16:(_foo) |
| 4432 | if (Parser.getTok().is(AsmToken::Identifier) || |
| 4433 | Parser.getTok().is(AsmToken::Colon)) |
| 4434 | return MatchOperand_NoMatch; |
| 4435 | |
| 4436 | // Hash (dollar) is optional as per the ARMARM |
| 4437 | if (Parser.getTok().is(AsmToken::Hash) || |
| 4438 | Parser.getTok().is(AsmToken::Dollar)) { |
| 4439 | // Avoid parsing into complex operands (#:) |
| 4440 | if (Lexer.peekTok().is(AsmToken::Colon)) |
| 4441 | return MatchOperand_NoMatch; |
| 4442 | |
| 4443 | // Eat the hash (dollar) |
| 4444 | Parser.Lex(); |
| 4445 | } |
Asiri Rathnayake | a0199b9 | 2014-12-02 10:53:20 +0000 | [diff] [blame] | 4446 | |
| 4447 | SMLoc Sx1, Ex1; |
| 4448 | Sx1 = Parser.getTok().getLoc(); |
| 4449 | const MCExpr *Imm1Exp; |
| 4450 | if (getParser().parseExpression(Imm1Exp, Ex1)) { |
| 4451 | Error(Sx1, "malformed expression"); |
| 4452 | return MatchOperand_ParseFail; |
| 4453 | } |
| 4454 | |
| 4455 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm1Exp); |
| 4456 | |
| 4457 | if (CE) { |
Asiri Rathnayake | d33304b | 2014-12-04 14:49:07 +0000 | [diff] [blame] | 4458 | // Immediate must fit within 32-bits |
Asiri Rathnayake | a0199b9 | 2014-12-02 10:53:20 +0000 | [diff] [blame] | 4459 | Imm1 = CE->getValue(); |
| 4460 | if (Imm1 < INT32_MIN || Imm1 > UINT32_MAX) { |
| 4461 | Error(Sx1, "immediate operand must be representable with 32 bits"); |
| 4462 | return MatchOperand_ParseFail; |
| 4463 | } |
| 4464 | |
| 4465 | int Enc = ARM_AM::getSOImmVal(Imm1); |
| 4466 | if (Enc != -1 && Parser.getTok().is(AsmToken::EndOfStatement)) { |
| 4467 | // We have a match! |
| 4468 | Operands.push_back(ARMOperand::CreateModImm((Enc & 0xFF), |
| 4469 | (Enc & 0xF00) >> 7, |
| 4470 | Sx1, Ex1)); |
| 4471 | return MatchOperand_Success; |
| 4472 | } |
Asiri Rathnayake | a0199b9 | 2014-12-02 10:53:20 +0000 | [diff] [blame] | 4473 | |
Asiri Rathnayake | d33304b | 2014-12-04 14:49:07 +0000 | [diff] [blame] | 4474 | // We have parsed an immediate which is not for us, fallback to a plain |
| 4475 | // immediate. This can happen for instruction aliases. For an example, |
| 4476 | // ARMInstrInfo.td defines the alias [mov <-> mvn] which can transform |
| 4477 | // a mov (mvn) with a mod_imm_neg/mod_imm_not operand into the opposite |
| 4478 | // instruction with a mod_imm operand. The alias is defined such that the |
| 4479 | // parser method is shared, that's why we have to do this here. |
| 4480 | if (Parser.getTok().is(AsmToken::EndOfStatement)) { |
| 4481 | Operands.push_back(ARMOperand::CreateImm(Imm1Exp, Sx1, Ex1)); |
| 4482 | return MatchOperand_Success; |
| 4483 | } |
| 4484 | } else { |
| 4485 | // Operands like #(l1 - l2) can only be evaluated at a later stage (via an |
| 4486 | // MCFixup). Fallback to a plain immediate. |
Asiri Rathnayake | a0199b9 | 2014-12-02 10:53:20 +0000 | [diff] [blame] | 4487 | Operands.push_back(ARMOperand::CreateImm(Imm1Exp, Sx1, Ex1)); |
| 4488 | return MatchOperand_Success; |
| 4489 | } |
| 4490 | |
| 4491 | // From this point onward, we expect the input to be a (#bits, #rot) pair |
Asiri Rathnayake | d33304b | 2014-12-04 14:49:07 +0000 | [diff] [blame] | 4492 | if (Parser.getTok().isNot(AsmToken::Comma)) { |
| 4493 | Error(Sx1, "expected modified immediate operand: #[0, 255], #even[0-30]"); |
| 4494 | return MatchOperand_ParseFail; |
| 4495 | } |
| 4496 | |
Asiri Rathnayake | a0199b9 | 2014-12-02 10:53:20 +0000 | [diff] [blame] | 4497 | if (Imm1 & ~0xFF) { |
| 4498 | Error(Sx1, "immediate operand must a number in the range [0, 255]"); |
| 4499 | return MatchOperand_ParseFail; |
| 4500 | } |
| 4501 | |
Asiri Rathnayake | a0199b9 | 2014-12-02 10:53:20 +0000 | [diff] [blame] | 4502 | // Eat the comma |
| 4503 | Parser.Lex(); |
| 4504 | |
| 4505 | // Repeat for #rot |
| 4506 | SMLoc Sx2, Ex2; |
| 4507 | Sx2 = Parser.getTok().getLoc(); |
| 4508 | |
Asiri Rathnayake | 13cef35 | 2014-12-04 19:34:59 +0000 | [diff] [blame] | 4509 | // Eat the optional hash (dollar) |
| 4510 | if (Parser.getTok().is(AsmToken::Hash) || |
| 4511 | Parser.getTok().is(AsmToken::Dollar)) |
| 4512 | Parser.Lex(); |
Asiri Rathnayake | a0199b9 | 2014-12-02 10:53:20 +0000 | [diff] [blame] | 4513 | |
| 4514 | const MCExpr *Imm2Exp; |
| 4515 | if (getParser().parseExpression(Imm2Exp, Ex2)) { |
| 4516 | Error(Sx2, "malformed expression"); |
| 4517 | return MatchOperand_ParseFail; |
| 4518 | } |
| 4519 | |
| 4520 | CE = dyn_cast<MCConstantExpr>(Imm2Exp); |
| 4521 | |
| 4522 | if (CE) { |
| 4523 | Imm2 = CE->getValue(); |
| 4524 | if (!(Imm2 & ~0x1E)) { |
| 4525 | // We have a match! |
| 4526 | Operands.push_back(ARMOperand::CreateModImm(Imm1, Imm2, S, Ex2)); |
| 4527 | return MatchOperand_Success; |
| 4528 | } |
| 4529 | Error(Sx2, "immediate operand must an even number in the range [0, 30]"); |
| 4530 | return MatchOperand_ParseFail; |
| 4531 | } else { |
| 4532 | Error(Sx2, "constant expression expected"); |
| 4533 | return MatchOperand_ParseFail; |
| 4534 | } |
| 4535 | } |
| 4536 | |
| 4537 | ARMAsmParser::OperandMatchResultTy |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4538 | ARMAsmParser::parseBitfield(OperandVector &Operands) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 4539 | MCAsmParser &Parser = getParser(); |
Jim Grosbach | 864b609 | 2011-07-28 21:34:26 +0000 | [diff] [blame] | 4540 | SMLoc S = Parser.getTok().getLoc(); |
| 4541 | // The bitfield descriptor is really two operands, the LSB and the width. |
Jim Grosbach | ef70e9b | 2011-12-09 22:25:03 +0000 | [diff] [blame] | 4542 | if (Parser.getTok().isNot(AsmToken::Hash) && |
| 4543 | Parser.getTok().isNot(AsmToken::Dollar)) { |
Jim Grosbach | 864b609 | 2011-07-28 21:34:26 +0000 | [diff] [blame] | 4544 | Error(Parser.getTok().getLoc(), "'#' expected"); |
| 4545 | return MatchOperand_ParseFail; |
| 4546 | } |
| 4547 | Parser.Lex(); // Eat hash token. |
| 4548 | |
| 4549 | const MCExpr *LSBExpr; |
| 4550 | SMLoc E = Parser.getTok().getLoc(); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 4551 | if (getParser().parseExpression(LSBExpr)) { |
Jim Grosbach | 864b609 | 2011-07-28 21:34:26 +0000 | [diff] [blame] | 4552 | Error(E, "malformed immediate expression"); |
| 4553 | return MatchOperand_ParseFail; |
| 4554 | } |
| 4555 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr); |
| 4556 | if (!CE) { |
| 4557 | Error(E, "'lsb' operand must be an immediate"); |
| 4558 | return MatchOperand_ParseFail; |
| 4559 | } |
| 4560 | |
| 4561 | int64_t LSB = CE->getValue(); |
| 4562 | // The LSB must be in the range [0,31] |
| 4563 | if (LSB < 0 || LSB > 31) { |
| 4564 | Error(E, "'lsb' operand must be in the range [0,31]"); |
| 4565 | return MatchOperand_ParseFail; |
| 4566 | } |
| 4567 | E = Parser.getTok().getLoc(); |
| 4568 | |
| 4569 | // Expect another immediate operand. |
| 4570 | if (Parser.getTok().isNot(AsmToken::Comma)) { |
| 4571 | Error(Parser.getTok().getLoc(), "too few operands"); |
| 4572 | return MatchOperand_ParseFail; |
| 4573 | } |
| 4574 | Parser.Lex(); // Eat hash token. |
Jim Grosbach | ef70e9b | 2011-12-09 22:25:03 +0000 | [diff] [blame] | 4575 | if (Parser.getTok().isNot(AsmToken::Hash) && |
| 4576 | Parser.getTok().isNot(AsmToken::Dollar)) { |
Jim Grosbach | 864b609 | 2011-07-28 21:34:26 +0000 | [diff] [blame] | 4577 | Error(Parser.getTok().getLoc(), "'#' expected"); |
| 4578 | return MatchOperand_ParseFail; |
| 4579 | } |
| 4580 | Parser.Lex(); // Eat hash token. |
| 4581 | |
| 4582 | const MCExpr *WidthExpr; |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4583 | SMLoc EndLoc; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 4584 | if (getParser().parseExpression(WidthExpr, EndLoc)) { |
Jim Grosbach | 864b609 | 2011-07-28 21:34:26 +0000 | [diff] [blame] | 4585 | Error(E, "malformed immediate expression"); |
| 4586 | return MatchOperand_ParseFail; |
| 4587 | } |
| 4588 | CE = dyn_cast<MCConstantExpr>(WidthExpr); |
| 4589 | if (!CE) { |
| 4590 | Error(E, "'width' operand must be an immediate"); |
| 4591 | return MatchOperand_ParseFail; |
| 4592 | } |
| 4593 | |
| 4594 | int64_t Width = CE->getValue(); |
| 4595 | // The LSB must be in the range [1,32-lsb] |
| 4596 | if (Width < 1 || Width > 32 - LSB) { |
| 4597 | Error(E, "'width' operand must be in the range [1,32-lsb]"); |
| 4598 | return MatchOperand_ParseFail; |
| 4599 | } |
Jim Grosbach | 864b609 | 2011-07-28 21:34:26 +0000 | [diff] [blame] | 4600 | |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4601 | Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc)); |
Jim Grosbach | 864b609 | 2011-07-28 21:34:26 +0000 | [diff] [blame] | 4602 | |
| 4603 | return MatchOperand_Success; |
| 4604 | } |
| 4605 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4606 | ARMAsmParser::OperandMatchResultTy |
| 4607 | ARMAsmParser::parsePostIdxReg(OperandVector &Operands) { |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4608 | // Check for a post-index addressing register operand. Specifically: |
Jim Grosbach | c320c85 | 2011-08-05 21:28:30 +0000 | [diff] [blame] | 4609 | // postidx_reg := '+' register {, shift} |
| 4610 | // | '-' register {, shift} |
| 4611 | // | register {, shift} |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4612 | |
| 4613 | // This method must return MatchOperand_NoMatch without consuming any tokens |
| 4614 | // in the case where there is no match, as other alternatives take other |
| 4615 | // parse methods. |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 4616 | MCAsmParser &Parser = getParser(); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4617 | AsmToken Tok = Parser.getTok(); |
| 4618 | SMLoc S = Tok.getLoc(); |
| 4619 | bool haveEaten = false; |
Jim Grosbach | a70fbfd5 | 2011-08-05 16:11:38 +0000 | [diff] [blame] | 4620 | bool isAdd = true; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4621 | if (Tok.is(AsmToken::Plus)) { |
| 4622 | Parser.Lex(); // Eat the '+' token. |
| 4623 | haveEaten = true; |
| 4624 | } else if (Tok.is(AsmToken::Minus)) { |
| 4625 | Parser.Lex(); // Eat the '-' token. |
Jim Grosbach | a70fbfd5 | 2011-08-05 16:11:38 +0000 | [diff] [blame] | 4626 | isAdd = false; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4627 | haveEaten = true; |
| 4628 | } |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4629 | |
| 4630 | SMLoc E = Parser.getTok().getEndLoc(); |
| 4631 | int Reg = tryParseRegister(); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4632 | if (Reg == -1) { |
| 4633 | if (!haveEaten) |
| 4634 | return MatchOperand_NoMatch; |
| 4635 | Error(Parser.getTok().getLoc(), "register expected"); |
| 4636 | return MatchOperand_ParseFail; |
| 4637 | } |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4638 | |
Jim Grosbach | c320c85 | 2011-08-05 21:28:30 +0000 | [diff] [blame] | 4639 | ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift; |
| 4640 | unsigned ShiftImm = 0; |
Jim Grosbach | 3d0b3a3 | 2011-08-05 22:03:36 +0000 | [diff] [blame] | 4641 | if (Parser.getTok().is(AsmToken::Comma)) { |
| 4642 | Parser.Lex(); // Eat the ','. |
| 4643 | if (parseMemRegOffsetShift(ShiftTy, ShiftImm)) |
| 4644 | return MatchOperand_ParseFail; |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4645 | |
| 4646 | // FIXME: Only approximates end...may include intervening whitespace. |
| 4647 | E = Parser.getTok().getLoc(); |
Jim Grosbach | 3d0b3a3 | 2011-08-05 22:03:36 +0000 | [diff] [blame] | 4648 | } |
Jim Grosbach | c320c85 | 2011-08-05 21:28:30 +0000 | [diff] [blame] | 4649 | |
| 4650 | Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy, |
| 4651 | ShiftImm, S, E)); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4652 | |
| 4653 | return MatchOperand_Success; |
| 4654 | } |
| 4655 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4656 | ARMAsmParser::OperandMatchResultTy |
| 4657 | ARMAsmParser::parseAM3Offset(OperandVector &Operands) { |
Jim Grosbach | 1d9d5e9 | 2011-08-10 21:56:18 +0000 | [diff] [blame] | 4658 | // Check for a post-index addressing register operand. Specifically: |
| 4659 | // am3offset := '+' register |
| 4660 | // | '-' register |
| 4661 | // | register |
| 4662 | // | # imm |
| 4663 | // | # + imm |
| 4664 | // | # - imm |
| 4665 | |
| 4666 | // This method must return MatchOperand_NoMatch without consuming any tokens |
| 4667 | // in the case where there is no match, as other alternatives take other |
| 4668 | // parse methods. |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 4669 | MCAsmParser &Parser = getParser(); |
Jim Grosbach | 1d9d5e9 | 2011-08-10 21:56:18 +0000 | [diff] [blame] | 4670 | AsmToken Tok = Parser.getTok(); |
| 4671 | SMLoc S = Tok.getLoc(); |
| 4672 | |
| 4673 | // Do immediates first, as we always parse those if we have a '#'. |
Jim Grosbach | ef70e9b | 2011-12-09 22:25:03 +0000 | [diff] [blame] | 4674 | if (Parser.getTok().is(AsmToken::Hash) || |
| 4675 | Parser.getTok().is(AsmToken::Dollar)) { |
Amaury de la Vieuville | bac917f | 2013-06-10 14:17:15 +0000 | [diff] [blame] | 4676 | Parser.Lex(); // Eat '#' or '$'. |
Jim Grosbach | 1d9d5e9 | 2011-08-10 21:56:18 +0000 | [diff] [blame] | 4677 | // Explicitly look for a '-', as we need to encode negative zero |
| 4678 | // differently. |
| 4679 | bool isNegative = Parser.getTok().is(AsmToken::Minus); |
| 4680 | const MCExpr *Offset; |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4681 | SMLoc E; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 4682 | if (getParser().parseExpression(Offset, E)) |
Jim Grosbach | 1d9d5e9 | 2011-08-10 21:56:18 +0000 | [diff] [blame] | 4683 | return MatchOperand_ParseFail; |
| 4684 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset); |
| 4685 | if (!CE) { |
| 4686 | Error(S, "constant expression expected"); |
| 4687 | return MatchOperand_ParseFail; |
| 4688 | } |
Jim Grosbach | 1d9d5e9 | 2011-08-10 21:56:18 +0000 | [diff] [blame] | 4689 | // Negative zero is encoded as the flag value INT32_MIN. |
| 4690 | int32_t Val = CE->getValue(); |
| 4691 | if (isNegative && Val == 0) |
| 4692 | Val = INT32_MIN; |
| 4693 | |
| 4694 | Operands.push_back( |
| 4695 | ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E)); |
| 4696 | |
| 4697 | return MatchOperand_Success; |
| 4698 | } |
| 4699 | |
| 4700 | |
| 4701 | bool haveEaten = false; |
| 4702 | bool isAdd = true; |
Jim Grosbach | 1d9d5e9 | 2011-08-10 21:56:18 +0000 | [diff] [blame] | 4703 | if (Tok.is(AsmToken::Plus)) { |
| 4704 | Parser.Lex(); // Eat the '+' token. |
| 4705 | haveEaten = true; |
| 4706 | } else if (Tok.is(AsmToken::Minus)) { |
| 4707 | Parser.Lex(); // Eat the '-' token. |
| 4708 | isAdd = false; |
| 4709 | haveEaten = true; |
| 4710 | } |
Saleem Abdulrasool | 4ab6e73 | 2014-02-23 17:45:36 +0000 | [diff] [blame] | 4711 | |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4712 | Tok = Parser.getTok(); |
| 4713 | int Reg = tryParseRegister(); |
Jim Grosbach | 1d9d5e9 | 2011-08-10 21:56:18 +0000 | [diff] [blame] | 4714 | if (Reg == -1) { |
| 4715 | if (!haveEaten) |
| 4716 | return MatchOperand_NoMatch; |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4717 | Error(Tok.getLoc(), "register expected"); |
Jim Grosbach | 1d9d5e9 | 2011-08-10 21:56:18 +0000 | [diff] [blame] | 4718 | return MatchOperand_ParseFail; |
| 4719 | } |
Jim Grosbach | 1d9d5e9 | 2011-08-10 21:56:18 +0000 | [diff] [blame] | 4720 | |
| 4721 | Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift, |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4722 | 0, S, Tok.getEndLoc())); |
Jim Grosbach | 1d9d5e9 | 2011-08-10 21:56:18 +0000 | [diff] [blame] | 4723 | |
| 4724 | return MatchOperand_Success; |
| 4725 | } |
| 4726 | |
Tim Northover | eb5e4d5 | 2013-07-22 09:06:12 +0000 | [diff] [blame] | 4727 | /// Convert parsed operands to MCInst. Needed here because this instruction |
| 4728 | /// only has two register operands, but multiplication is commutative so |
| 4729 | /// 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] | 4730 | void ARMAsmParser::cvtThumbMultiply(MCInst &Inst, |
| 4731 | const OperandVector &Operands) { |
| 4732 | ((ARMOperand &)*Operands[3]).addRegOperands(Inst, 1); |
| 4733 | ((ARMOperand &)*Operands[1]).addCCOutOperands(Inst, 1); |
Jim Grosbach | 5a5ce63 | 2011-11-10 22:10:12 +0000 | [diff] [blame] | 4734 | // If we have a three-operand form, make sure to set Rn to be the operand |
| 4735 | // that isn't the same as Rd. |
| 4736 | unsigned RegOp = 4; |
| 4737 | if (Operands.size() == 6 && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4738 | ((ARMOperand &)*Operands[4]).getReg() == |
| 4739 | ((ARMOperand &)*Operands[3]).getReg()) |
Jim Grosbach | 5a5ce63 | 2011-11-10 22:10:12 +0000 | [diff] [blame] | 4740 | RegOp = 5; |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4741 | ((ARMOperand &)*Operands[RegOp]).addRegOperands(Inst, 1); |
Jim Grosbach | 5a5ce63 | 2011-11-10 22:10:12 +0000 | [diff] [blame] | 4742 | Inst.addOperand(Inst.getOperand(0)); |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4743 | ((ARMOperand &)*Operands[2]).addCondCodeOperands(Inst, 2); |
Jim Grosbach | 8e04849 | 2011-08-19 22:07:46 +0000 | [diff] [blame] | 4744 | } |
Jim Grosbach | cd4dd25 | 2011-08-10 22:42:16 +0000 | [diff] [blame] | 4745 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4746 | void ARMAsmParser::cvtThumbBranches(MCInst &Inst, |
| 4747 | const OperandVector &Operands) { |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 4748 | int CondOp = -1, ImmOp = -1; |
| 4749 | switch(Inst.getOpcode()) { |
| 4750 | case ARM::tB: |
| 4751 | case ARM::tBcc: CondOp = 1; ImmOp = 2; break; |
| 4752 | |
| 4753 | case ARM::t2B: |
| 4754 | case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break; |
| 4755 | |
| 4756 | default: llvm_unreachable("Unexpected instruction in cvtThumbBranches"); |
| 4757 | } |
| 4758 | // first decide whether or not the branch should be conditional |
| 4759 | // by looking at it's location relative to an IT block |
| 4760 | if(inITBlock()) { |
| 4761 | // inside an IT block we cannot have any conditional branches. any |
| 4762 | // such instructions needs to be converted to unconditional form |
| 4763 | switch(Inst.getOpcode()) { |
| 4764 | case ARM::tBcc: Inst.setOpcode(ARM::tB); break; |
| 4765 | case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break; |
| 4766 | } |
| 4767 | } else { |
| 4768 | // outside IT blocks we can only have unconditional branches with AL |
| 4769 | // condition code or conditional branches with non-AL condition code |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4770 | unsigned Cond = static_cast<ARMOperand &>(*Operands[CondOp]).getCondCode(); |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 4771 | switch(Inst.getOpcode()) { |
| 4772 | case ARM::tB: |
| 4773 | case ARM::tBcc: |
| 4774 | Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc); |
| 4775 | break; |
| 4776 | case ARM::t2B: |
| 4777 | case ARM::t2Bcc: |
| 4778 | Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc); |
| 4779 | break; |
| 4780 | } |
| 4781 | } |
Saleem Abdulrasool | 4ab6e73 | 2014-02-23 17:45:36 +0000 | [diff] [blame] | 4782 | |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 4783 | // now decide on encoding size based on branch target range |
| 4784 | switch(Inst.getOpcode()) { |
| 4785 | // classify tB as either t2B or t1B based on range of immediate operand |
| 4786 | case ARM::tB: { |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4787 | ARMOperand &op = static_cast<ARMOperand &>(*Operands[ImmOp]); |
| 4788 | if (!op.isSignedOffset<11, 1>() && isThumbTwo()) |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 4789 | Inst.setOpcode(ARM::t2B); |
| 4790 | break; |
| 4791 | } |
| 4792 | // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand |
| 4793 | case ARM::tBcc: { |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4794 | ARMOperand &op = static_cast<ARMOperand &>(*Operands[ImmOp]); |
| 4795 | if (!op.isSignedOffset<8, 1>() && isThumbTwo()) |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 4796 | Inst.setOpcode(ARM::t2Bcc); |
| 4797 | break; |
| 4798 | } |
| 4799 | } |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4800 | ((ARMOperand &)*Operands[ImmOp]).addImmOperands(Inst, 1); |
| 4801 | ((ARMOperand &)*Operands[CondOp]).addCondCodeOperands(Inst, 2); |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 4802 | } |
| 4803 | |
Bill Wendling | e18980a | 2010-11-06 22:36:58 +0000 | [diff] [blame] | 4804 | /// Parse an ARM memory expression, return false if successful else return true |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 4805 | /// or an error. The first token must be a '[' when called. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4806 | bool ARMAsmParser::parseMemory(OperandVector &Operands) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 4807 | MCAsmParser &Parser = getParser(); |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 4808 | SMLoc S, E; |
Sean Callanan | 936b0d3 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 4809 | assert(Parser.getTok().is(AsmToken::LBrac) && |
Bill Wendling | 4f4bce0 | 2010-11-06 10:48:18 +0000 | [diff] [blame] | 4810 | "Token is not a Left Bracket"); |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 4811 | S = Parser.getTok().getLoc(); |
Sean Callanan | a83fd7d | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 4812 | Parser.Lex(); // Eat left bracket token. |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 4813 | |
Sean Callanan | 936b0d3 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 4814 | const AsmToken &BaseRegTok = Parser.getTok(); |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 4815 | int BaseRegNum = tryParseRegister(); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4816 | if (BaseRegNum == -1) |
| 4817 | return Error(BaseRegTok.getLoc(), "register expected"); |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 4818 | |
Kristof Beyls | 2efb59a | 2013-02-14 14:46:12 +0000 | [diff] [blame] | 4819 | // 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] | 4820 | const AsmToken &Tok = Parser.getTok(); |
Kristof Beyls | 2efb59a | 2013-02-14 14:46:12 +0000 | [diff] [blame] | 4821 | if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) && |
| 4822 | !Tok.is(AsmToken::RBrac)) |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4823 | return Error(Tok.getLoc(), "malformed memory operand"); |
Daniel Dunbar | 1d5e954 | 2011-01-18 05:34:17 +0000 | [diff] [blame] | 4824 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4825 | if (Tok.is(AsmToken::RBrac)) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4826 | E = Tok.getEndLoc(); |
Sean Callanan | a83fd7d | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 4827 | Parser.Lex(); // Eat right bracket token. |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 4828 | |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 4829 | Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, 0, |
| 4830 | ARM_AM::no_shift, 0, 0, false, |
| 4831 | S, E)); |
Jim Grosbach | 32ff558 | 2010-11-29 23:18:01 +0000 | [diff] [blame] | 4832 | |
Jim Grosbach | 40700e0 | 2011-09-19 18:42:21 +0000 | [diff] [blame] | 4833 | // If there's a pre-indexing writeback marker, '!', just add it as a token |
| 4834 | // operand. It's rather odd, but syntactically valid. |
| 4835 | if (Parser.getTok().is(AsmToken::Exclaim)) { |
| 4836 | Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc())); |
| 4837 | Parser.Lex(); // Eat the '!'. |
| 4838 | } |
| 4839 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4840 | return false; |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 4841 | } |
Daniel Dunbar | f5164f4 | 2011-01-18 05:34:24 +0000 | [diff] [blame] | 4842 | |
Kristof Beyls | 2efb59a | 2013-02-14 14:46:12 +0000 | [diff] [blame] | 4843 | assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) && |
| 4844 | "Lost colon or comma in memory operand?!"); |
| 4845 | if (Tok.is(AsmToken::Comma)) { |
| 4846 | Parser.Lex(); // Eat the comma. |
| 4847 | } |
Daniel Dunbar | f5164f4 | 2011-01-18 05:34:24 +0000 | [diff] [blame] | 4848 | |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 4849 | // If we have a ':', it's an alignment specifier. |
| 4850 | if (Parser.getTok().is(AsmToken::Colon)) { |
| 4851 | Parser.Lex(); // Eat the ':'. |
| 4852 | E = Parser.getTok().getLoc(); |
Kevin Enderby | 488f20b | 2014-04-10 20:18:58 +0000 | [diff] [blame] | 4853 | SMLoc AlignmentLoc = Tok.getLoc(); |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 4854 | |
| 4855 | const MCExpr *Expr; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 4856 | if (getParser().parseExpression(Expr)) |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 4857 | return true; |
| 4858 | |
| 4859 | // The expression has to be a constant. Memory references with relocations |
| 4860 | // don't come through here, as they use the <label> forms of the relevant |
| 4861 | // instructions. |
| 4862 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr); |
| 4863 | if (!CE) |
| 4864 | return Error (E, "constant expression expected"); |
| 4865 | |
| 4866 | unsigned Align = 0; |
| 4867 | switch (CE->getValue()) { |
| 4868 | default: |
Jim Grosbach | cef98cd | 2011-12-19 18:31:43 +0000 | [diff] [blame] | 4869 | return Error(E, |
| 4870 | "alignment specifier must be 16, 32, 64, 128, or 256 bits"); |
| 4871 | case 16: Align = 2; break; |
| 4872 | case 32: Align = 4; break; |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 4873 | case 64: Align = 8; break; |
| 4874 | case 128: Align = 16; break; |
| 4875 | case 256: Align = 32; break; |
| 4876 | } |
| 4877 | |
| 4878 | // Now we should have the closing ']' |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 4879 | if (Parser.getTok().isNot(AsmToken::RBrac)) |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4880 | return Error(Parser.getTok().getLoc(), "']' expected"); |
| 4881 | E = Parser.getTok().getEndLoc(); |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 4882 | Parser.Lex(); // Eat right bracket token. |
| 4883 | |
| 4884 | // Don't worry about range checking the value here. That's handled by |
| 4885 | // the is*() predicates. |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 4886 | Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, 0, |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 4887 | ARM_AM::no_shift, 0, Align, |
Kevin Enderby | 488f20b | 2014-04-10 20:18:58 +0000 | [diff] [blame] | 4888 | false, S, E, AlignmentLoc)); |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 4889 | |
| 4890 | // If there's a pre-indexing writeback marker, '!', just add it as a token |
| 4891 | // operand. |
| 4892 | if (Parser.getTok().is(AsmToken::Exclaim)) { |
| 4893 | Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc())); |
| 4894 | Parser.Lex(); // Eat the '!'. |
| 4895 | } |
| 4896 | |
| 4897 | return false; |
| 4898 | } |
| 4899 | |
| 4900 | // 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] | 4901 | // offset. Be friendly and also accept a plain integer (without a leading |
| 4902 | // hash) for gas compatibility. |
| 4903 | if (Parser.getTok().is(AsmToken::Hash) || |
Jim Grosbach | ef70e9b | 2011-12-09 22:25:03 +0000 | [diff] [blame] | 4904 | Parser.getTok().is(AsmToken::Dollar) || |
Jim Grosbach | 8279c18 | 2011-11-15 22:14:41 +0000 | [diff] [blame] | 4905 | Parser.getTok().is(AsmToken::Integer)) { |
Jim Grosbach | ef70e9b | 2011-12-09 22:25:03 +0000 | [diff] [blame] | 4906 | if (Parser.getTok().isNot(AsmToken::Integer)) |
Amaury de la Vieuville | bac917f | 2013-06-10 14:17:15 +0000 | [diff] [blame] | 4907 | Parser.Lex(); // Eat '#' or '$'. |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4908 | E = Parser.getTok().getLoc(); |
Daniel Dunbar | f5164f4 | 2011-01-18 05:34:24 +0000 | [diff] [blame] | 4909 | |
Owen Anderson | 967674d | 2011-08-29 19:36:44 +0000 | [diff] [blame] | 4910 | bool isNegative = getParser().getTok().is(AsmToken::Minus); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4911 | const MCExpr *Offset; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 4912 | if (getParser().parseExpression(Offset)) |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 4913 | return true; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4914 | |
| 4915 | // The expression has to be a constant. Memory references with relocations |
| 4916 | // don't come through here, as they use the <label> forms of the relevant |
| 4917 | // instructions. |
| 4918 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset); |
| 4919 | if (!CE) |
| 4920 | return Error (E, "constant expression expected"); |
| 4921 | |
Owen Anderson | 967674d | 2011-08-29 19:36:44 +0000 | [diff] [blame] | 4922 | // If the constant was #-0, represent it as INT32_MIN. |
| 4923 | int32_t Val = CE->getValue(); |
| 4924 | if (isNegative && Val == 0) |
| 4925 | CE = MCConstantExpr::Create(INT32_MIN, getContext()); |
| 4926 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4927 | // Now we should have the closing ']' |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4928 | if (Parser.getTok().isNot(AsmToken::RBrac)) |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4929 | return Error(Parser.getTok().getLoc(), "']' expected"); |
| 4930 | E = Parser.getTok().getEndLoc(); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4931 | Parser.Lex(); // Eat right bracket token. |
| 4932 | |
| 4933 | // Don't worry about range checking the value here. That's handled by |
| 4934 | // the is*() predicates. |
| 4935 | Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0, |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 4936 | ARM_AM::no_shift, 0, 0, |
| 4937 | false, S, E)); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4938 | |
| 4939 | // If there's a pre-indexing writeback marker, '!', just add it as a token |
| 4940 | // operand. |
| 4941 | if (Parser.getTok().is(AsmToken::Exclaim)) { |
| 4942 | Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc())); |
| 4943 | Parser.Lex(); // Eat the '!'. |
| 4944 | } |
| 4945 | |
| 4946 | return false; |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 4947 | } |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4948 | |
| 4949 | // The register offset is optionally preceded by a '+' or '-' |
| 4950 | bool isNegative = false; |
| 4951 | if (Parser.getTok().is(AsmToken::Minus)) { |
| 4952 | isNegative = true; |
| 4953 | Parser.Lex(); // Eat the '-'. |
| 4954 | } else if (Parser.getTok().is(AsmToken::Plus)) { |
| 4955 | // Nothing to do. |
| 4956 | Parser.Lex(); // Eat the '+'. |
| 4957 | } |
| 4958 | |
| 4959 | E = Parser.getTok().getLoc(); |
| 4960 | int OffsetRegNum = tryParseRegister(); |
| 4961 | if (OffsetRegNum == -1) |
| 4962 | return Error(E, "register expected"); |
| 4963 | |
| 4964 | // If there's a shift operator, handle it. |
| 4965 | ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift; |
Jim Grosbach | 3d0b3a3 | 2011-08-05 22:03:36 +0000 | [diff] [blame] | 4966 | unsigned ShiftImm = 0; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4967 | if (Parser.getTok().is(AsmToken::Comma)) { |
| 4968 | Parser.Lex(); // Eat the ','. |
Jim Grosbach | 3d0b3a3 | 2011-08-05 22:03:36 +0000 | [diff] [blame] | 4969 | if (parseMemRegOffsetShift(ShiftType, ShiftImm)) |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4970 | return true; |
| 4971 | } |
| 4972 | |
| 4973 | // Now we should have the closing ']' |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4974 | if (Parser.getTok().isNot(AsmToken::RBrac)) |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4975 | return Error(Parser.getTok().getLoc(), "']' expected"); |
| 4976 | E = Parser.getTok().getEndLoc(); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4977 | Parser.Lex(); // Eat right bracket token. |
| 4978 | |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 4979 | Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, OffsetRegNum, |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 4980 | ShiftType, ShiftImm, 0, isNegative, |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4981 | S, E)); |
| 4982 | |
Jim Grosbach | c320c85 | 2011-08-05 21:28:30 +0000 | [diff] [blame] | 4983 | // If there's a pre-indexing writeback marker, '!', just add it as a token |
| 4984 | // operand. |
| 4985 | if (Parser.getTok().is(AsmToken::Exclaim)) { |
| 4986 | Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc())); |
| 4987 | Parser.Lex(); // Eat the '!'. |
| 4988 | } |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4989 | |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 4990 | return false; |
| 4991 | } |
| 4992 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4993 | /// parseMemRegOffsetShift - one of these two: |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 4994 | /// ( lsl | lsr | asr | ror ) , # shift_amount |
| 4995 | /// rrx |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4996 | /// return true if it parses a shift otherwise it returns false. |
| 4997 | bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St, |
| 4998 | unsigned &Amount) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 4999 | MCAsmParser &Parser = getParser(); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 5000 | SMLoc Loc = Parser.getTok().getLoc(); |
Sean Callanan | 936b0d3 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 5001 | const AsmToken &Tok = Parser.getTok(); |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 5002 | if (Tok.isNot(AsmToken::Identifier)) |
| 5003 | return true; |
Benjamin Kramer | 92d8998 | 2010-07-14 22:38:02 +0000 | [diff] [blame] | 5004 | StringRef ShiftName = Tok.getString(); |
Jim Grosbach | 3b559ff | 2011-12-07 23:40:58 +0000 | [diff] [blame] | 5005 | if (ShiftName == "lsl" || ShiftName == "LSL" || |
| 5006 | ShiftName == "asl" || ShiftName == "ASL") |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 5007 | St = ARM_AM::lsl; |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 5008 | else if (ShiftName == "lsr" || ShiftName == "LSR") |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 5009 | St = ARM_AM::lsr; |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 5010 | else if (ShiftName == "asr" || ShiftName == "ASR") |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 5011 | St = ARM_AM::asr; |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 5012 | else if (ShiftName == "ror" || ShiftName == "ROR") |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 5013 | St = ARM_AM::ror; |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 5014 | else if (ShiftName == "rrx" || ShiftName == "RRX") |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 5015 | St = ARM_AM::rrx; |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 5016 | else |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 5017 | return Error(Loc, "illegal shift operator"); |
Sean Callanan | a83fd7d | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 5018 | Parser.Lex(); // Eat shift type token. |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 5019 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 5020 | // rrx stands alone. |
| 5021 | Amount = 0; |
| 5022 | if (St != ARM_AM::rrx) { |
| 5023 | Loc = Parser.getTok().getLoc(); |
| 5024 | // A '#' and a shift amount. |
| 5025 | const AsmToken &HashTok = Parser.getTok(); |
Jim Grosbach | ef70e9b | 2011-12-09 22:25:03 +0000 | [diff] [blame] | 5026 | if (HashTok.isNot(AsmToken::Hash) && |
| 5027 | HashTok.isNot(AsmToken::Dollar)) |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 5028 | return Error(HashTok.getLoc(), "'#' expected"); |
| 5029 | Parser.Lex(); // Eat hash token. |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 5030 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 5031 | const MCExpr *Expr; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 5032 | if (getParser().parseExpression(Expr)) |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 5033 | return true; |
| 5034 | // Range check the immediate. |
| 5035 | // lsl, ror: 0 <= imm <= 31 |
| 5036 | // lsr, asr: 0 <= imm <= 32 |
| 5037 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr); |
| 5038 | if (!CE) |
| 5039 | return Error(Loc, "shift amount must be an immediate"); |
| 5040 | int64_t Imm = CE->getValue(); |
| 5041 | if (Imm < 0 || |
| 5042 | ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) || |
| 5043 | ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32)) |
| 5044 | return Error(Loc, "immediate shift value out of range"); |
Tim Northover | 0c97e76 | 2012-09-22 11:18:12 +0000 | [diff] [blame] | 5045 | // If <ShiftTy> #0, turn it into a no_shift. |
| 5046 | if (Imm == 0) |
| 5047 | St = ARM_AM::lsl; |
| 5048 | // For consistency, treat lsr #32 and asr #32 as having immediate value 0. |
| 5049 | if (Imm == 32) |
| 5050 | Imm = 0; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 5051 | Amount = Imm; |
| 5052 | } |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 5053 | |
| 5054 | return false; |
| 5055 | } |
| 5056 | |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 5057 | /// parseFPImm - A floating point immediate expression operand. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5058 | ARMAsmParser::OperandMatchResultTy |
| 5059 | ARMAsmParser::parseFPImm(OperandVector &Operands) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 5060 | MCAsmParser &Parser = getParser(); |
Jim Grosbach | a9d36fb | 2012-01-20 18:09:51 +0000 | [diff] [blame] | 5061 | // Anything that can accept a floating point constant as an operand |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 5062 | // needs to go through here, as the regular parseExpression is |
Jim Grosbach | a9d36fb | 2012-01-20 18:09:51 +0000 | [diff] [blame] | 5063 | // integer only. |
| 5064 | // |
| 5065 | // This routine still creates a generic Immediate operand, containing |
| 5066 | // a bitcast of the 64-bit floating point value. The various operands |
| 5067 | // that accept floats can check whether the value is valid for them |
| 5068 | // via the standard is*() predicates. |
| 5069 | |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 5070 | SMLoc S = Parser.getTok().getLoc(); |
| 5071 | |
Jim Grosbach | ef70e9b | 2011-12-09 22:25:03 +0000 | [diff] [blame] | 5072 | if (Parser.getTok().isNot(AsmToken::Hash) && |
| 5073 | Parser.getTok().isNot(AsmToken::Dollar)) |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 5074 | return MatchOperand_NoMatch; |
Jim Grosbach | 741cd73 | 2011-10-17 22:26:03 +0000 | [diff] [blame] | 5075 | |
| 5076 | // Disambiguate the VMOV forms that can accept an FP immediate. |
| 5077 | // vmov.f32 <sreg>, #imm |
| 5078 | // vmov.f64 <dreg>, #imm |
| 5079 | // vmov.f32 <dreg>, #imm @ vector f32x2 |
| 5080 | // vmov.f32 <qreg>, #imm @ vector f32x4 |
| 5081 | // |
| 5082 | // There are also the NEON VMOV instructions which expect an |
| 5083 | // integer constant. Make sure we don't try to parse an FPImm |
| 5084 | // for these: |
| 5085 | // vmov.i{8|16|32|64} <dreg|qreg>, #imm |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5086 | ARMOperand &TyOp = static_cast<ARMOperand &>(*Operands[2]); |
| 5087 | bool isVmovf = TyOp.isToken() && |
| 5088 | (TyOp.getToken() == ".f32" || TyOp.getToken() == ".f64"); |
| 5089 | ARMOperand &Mnemonic = static_cast<ARMOperand &>(*Operands[0]); |
| 5090 | bool isFconst = Mnemonic.isToken() && (Mnemonic.getToken() == "fconstd" || |
| 5091 | Mnemonic.getToken() == "fconsts"); |
David Peixotto | a872e0e | 2014-01-07 18:19:23 +0000 | [diff] [blame] | 5092 | if (!(isVmovf || isFconst)) |
Jim Grosbach | 741cd73 | 2011-10-17 22:26:03 +0000 | [diff] [blame] | 5093 | return MatchOperand_NoMatch; |
| 5094 | |
Amaury de la Vieuville | bac917f | 2013-06-10 14:17:15 +0000 | [diff] [blame] | 5095 | Parser.Lex(); // Eat '#' or '$'. |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 5096 | |
| 5097 | // Handle negation, as that still comes through as a separate token. |
| 5098 | bool isNegative = false; |
| 5099 | if (Parser.getTok().is(AsmToken::Minus)) { |
| 5100 | isNegative = true; |
| 5101 | Parser.Lex(); |
| 5102 | } |
| 5103 | const AsmToken &Tok = Parser.getTok(); |
Jim Grosbach | 235c8d2 | 2012-01-19 02:47:30 +0000 | [diff] [blame] | 5104 | SMLoc Loc = Tok.getLoc(); |
David Peixotto | a872e0e | 2014-01-07 18:19:23 +0000 | [diff] [blame] | 5105 | if (Tok.is(AsmToken::Real) && isVmovf) { |
Jim Grosbach | a9d36fb | 2012-01-20 18:09:51 +0000 | [diff] [blame] | 5106 | APFloat RealVal(APFloat::IEEEsingle, Tok.getString()); |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 5107 | uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue(); |
| 5108 | // If we had a '-' in front, toggle the sign bit. |
Jim Grosbach | a9d36fb | 2012-01-20 18:09:51 +0000 | [diff] [blame] | 5109 | IntVal ^= (uint64_t)isNegative << 31; |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 5110 | Parser.Lex(); // Eat the token. |
Jim Grosbach | a9d36fb | 2012-01-20 18:09:51 +0000 | [diff] [blame] | 5111 | Operands.push_back(ARMOperand::CreateImm( |
| 5112 | MCConstantExpr::Create(IntVal, getContext()), |
| 5113 | S, Parser.getTok().getLoc())); |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 5114 | return MatchOperand_Success; |
| 5115 | } |
Jim Grosbach | a9d36fb | 2012-01-20 18:09:51 +0000 | [diff] [blame] | 5116 | // Also handle plain integers. Instructions which allow floating point |
| 5117 | // immediates also allow a raw encoded 8-bit value. |
David Peixotto | a872e0e | 2014-01-07 18:19:23 +0000 | [diff] [blame] | 5118 | if (Tok.is(AsmToken::Integer) && isFconst) { |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 5119 | int64_t Val = Tok.getIntVal(); |
| 5120 | Parser.Lex(); // Eat the token. |
| 5121 | if (Val > 255 || Val < 0) { |
Jim Grosbach | 235c8d2 | 2012-01-19 02:47:30 +0000 | [diff] [blame] | 5122 | Error(Loc, "encoded floating point value out of range"); |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 5123 | return MatchOperand_ParseFail; |
| 5124 | } |
David Peixotto | a872e0e | 2014-01-07 18:19:23 +0000 | [diff] [blame] | 5125 | float RealVal = ARM_AM::getFPImmFloat(Val); |
| 5126 | Val = APFloat(RealVal).bitcastToAPInt().getZExtValue(); |
| 5127 | |
Jim Grosbach | a9d36fb | 2012-01-20 18:09:51 +0000 | [diff] [blame] | 5128 | Operands.push_back(ARMOperand::CreateImm( |
| 5129 | MCConstantExpr::Create(Val, getContext()), S, |
| 5130 | Parser.getTok().getLoc())); |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 5131 | return MatchOperand_Success; |
| 5132 | } |
| 5133 | |
Jim Grosbach | 235c8d2 | 2012-01-19 02:47:30 +0000 | [diff] [blame] | 5134 | Error(Loc, "invalid floating point immediate"); |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 5135 | return MatchOperand_ParseFail; |
| 5136 | } |
Jim Grosbach | a9d36fb | 2012-01-20 18:09:51 +0000 | [diff] [blame] | 5137 | |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 5138 | /// Parse a arm instruction operand. For now this parses the operand regardless |
| 5139 | /// of the mnemonic. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5140 | bool ARMAsmParser::parseOperand(OperandVector &Operands, StringRef Mnemonic) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 5141 | MCAsmParser &Parser = getParser(); |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 5142 | SMLoc S, E; |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 5143 | |
| 5144 | // Check if the current operand has a custom associated parser, if so, try to |
| 5145 | // custom parse the operand, or fallback to the general approach. |
Jim Grosbach | 861e49c | 2011-02-12 01:34:40 +0000 | [diff] [blame] | 5146 | OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic); |
| 5147 | if (ResTy == MatchOperand_Success) |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 5148 | return false; |
Jim Grosbach | 861e49c | 2011-02-12 01:34:40 +0000 | [diff] [blame] | 5149 | // If there wasn't a custom match, try the generic matcher below. Otherwise, |
| 5150 | // there was a match, but an error occurred, in which case, just return that |
| 5151 | // the operand parsing failed. |
| 5152 | if (ResTy == MatchOperand_ParseFail) |
| 5153 | return true; |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 5154 | |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 5155 | switch (getLexer().getKind()) { |
Bill Wendling | ee7f1f9 | 2010-11-06 21:42:12 +0000 | [diff] [blame] | 5156 | default: |
| 5157 | Error(Parser.getTok().getLoc(), "unexpected token in operand"); |
Bill Wendling | 2063b84 | 2010-11-18 23:43:05 +0000 | [diff] [blame] | 5158 | return true; |
Jim Grosbach | bb24c59 | 2011-07-13 18:49:30 +0000 | [diff] [blame] | 5159 | case AsmToken::Identifier: { |
Chad Rosier | b162a5c | 2013-03-19 23:44:03 +0000 | [diff] [blame] | 5160 | // If we've seen a branch mnemonic, the next operand must be a label. This |
| 5161 | // is true even if the label is a register name. So "br r1" means branch to |
| 5162 | // label "r1". |
| 5163 | bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl"; |
| 5164 | if (!ExpectLabel) { |
| 5165 | if (!tryParseRegisterWithWriteBack(Operands)) |
| 5166 | return false; |
| 5167 | int Res = tryParseShiftRegister(Operands); |
| 5168 | if (Res == 0) // success |
| 5169 | return false; |
| 5170 | else if (Res == -1) // irrecoverable error |
| 5171 | return true; |
| 5172 | // If this is VMRS, check for the apsr_nzcv operand. |
| 5173 | if (Mnemonic == "vmrs" && |
| 5174 | Parser.getTok().getString().equals_lower("apsr_nzcv")) { |
| 5175 | S = Parser.getTok().getLoc(); |
| 5176 | Parser.Lex(); |
| 5177 | Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S)); |
| 5178 | return false; |
| 5179 | } |
Jim Grosbach | 4ab23b5 | 2011-10-03 21:12:43 +0000 | [diff] [blame] | 5180 | } |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 5181 | |
| 5182 | // Fall though for the Identifier case that is not a register or a |
| 5183 | // special name. |
Jim Grosbach | bb24c59 | 2011-07-13 18:49:30 +0000 | [diff] [blame] | 5184 | } |
Jim Grosbach | 4e38035 | 2011-10-26 21:14:08 +0000 | [diff] [blame] | 5185 | case AsmToken::LParen: // parenthesized expressions like (_strcmp-4) |
Kevin Enderby | b084be9 | 2011-01-13 20:32:36 +0000 | [diff] [blame] | 5186 | case AsmToken::Integer: // things like 1f and 2b as a branch targets |
Jim Grosbach | 5c6b634 | 2011-11-01 22:38:31 +0000 | [diff] [blame] | 5187 | case AsmToken::String: // quoted label names. |
Kevin Enderby | b084be9 | 2011-01-13 20:32:36 +0000 | [diff] [blame] | 5188 | case AsmToken::Dot: { // . as a branch target |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 5189 | // This was not a register so parse other operands that start with an |
| 5190 | // identifier (like labels) as expressions and create them as immediates. |
| 5191 | const MCExpr *IdVal; |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 5192 | S = Parser.getTok().getLoc(); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 5193 | if (getParser().parseExpression(IdVal)) |
Bill Wendling | 2063b84 | 2010-11-18 23:43:05 +0000 | [diff] [blame] | 5194 | return true; |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 5195 | E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1); |
Bill Wendling | 2063b84 | 2010-11-18 23:43:05 +0000 | [diff] [blame] | 5196 | Operands.push_back(ARMOperand::CreateImm(IdVal, S, E)); |
| 5197 | return false; |
| 5198 | } |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 5199 | case AsmToken::LBrac: |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 5200 | return parseMemory(Operands); |
Kevin Enderby | a2b9910 | 2009-10-09 21:12:28 +0000 | [diff] [blame] | 5201 | case AsmToken::LCurly: |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 5202 | return parseRegisterList(Operands); |
Jim Grosbach | ef70e9b | 2011-12-09 22:25:03 +0000 | [diff] [blame] | 5203 | case AsmToken::Dollar: |
Owen Anderson | f02d98d | 2011-08-29 17:17:09 +0000 | [diff] [blame] | 5204 | case AsmToken::Hash: { |
Kevin Enderby | 3a80dac | 2009-10-13 23:33:38 +0000 | [diff] [blame] | 5205 | // #42 -> immediate. |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 5206 | S = Parser.getTok().getLoc(); |
Sean Callanan | a83fd7d | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 5207 | Parser.Lex(); |
Jim Grosbach | 003607f | 2012-04-16 21:18:46 +0000 | [diff] [blame] | 5208 | |
| 5209 | if (Parser.getTok().isNot(AsmToken::Colon)) { |
| 5210 | bool isNegative = Parser.getTok().is(AsmToken::Minus); |
| 5211 | const MCExpr *ImmVal; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 5212 | if (getParser().parseExpression(ImmVal)) |
Jim Grosbach | 003607f | 2012-04-16 21:18:46 +0000 | [diff] [blame] | 5213 | return true; |
| 5214 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal); |
| 5215 | if (CE) { |
| 5216 | int32_t Val = CE->getValue(); |
| 5217 | if (isNegative && Val == 0) |
| 5218 | ImmVal = MCConstantExpr::Create(INT32_MIN, getContext()); |
| 5219 | } |
| 5220 | E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1); |
| 5221 | Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E)); |
Jim Grosbach | 9be2d71 | 2013-02-23 00:52:09 +0000 | [diff] [blame] | 5222 | |
| 5223 | // 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] | 5224 | // '!' Token operand. Handle that here. For example, the compatibility |
Jim Grosbach | 9be2d71 | 2013-02-23 00:52:09 +0000 | [diff] [blame] | 5225 | // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'. |
| 5226 | if (Parser.getTok().is(AsmToken::Exclaim)) { |
| 5227 | Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(), |
| 5228 | Parser.getTok().getLoc())); |
| 5229 | Parser.Lex(); // Eat exclaim token |
| 5230 | } |
Jim Grosbach | 003607f | 2012-04-16 21:18:46 +0000 | [diff] [blame] | 5231 | return false; |
Owen Anderson | f02d98d | 2011-08-29 17:17:09 +0000 | [diff] [blame] | 5232 | } |
Jim Grosbach | 003607f | 2012-04-16 21:18:46 +0000 | [diff] [blame] | 5233 | // w/ a ':' after the '#', it's just like a plain ':'. |
| 5234 | // FALLTHROUGH |
Owen Anderson | f02d98d | 2011-08-29 17:17:09 +0000 | [diff] [blame] | 5235 | } |
Jason W Kim | 1f7bc07 | 2011-01-11 23:53:41 +0000 | [diff] [blame] | 5236 | case AsmToken::Colon: { |
| 5237 | // ":lower16:" and ":upper16:" expression prefixes |
Evan Cheng | 965b3c7 | 2011-01-13 07:58:56 +0000 | [diff] [blame] | 5238 | // FIXME: Check it's an expression prefix, |
| 5239 | // e.g. (FOO - :lower16:BAR) isn't legal. |
| 5240 | ARMMCExpr::VariantKind RefKind; |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 5241 | if (parsePrefix(RefKind)) |
Jason W Kim | 1f7bc07 | 2011-01-11 23:53:41 +0000 | [diff] [blame] | 5242 | return true; |
| 5243 | |
Evan Cheng | 965b3c7 | 2011-01-13 07:58:56 +0000 | [diff] [blame] | 5244 | const MCExpr *SubExprVal; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 5245 | if (getParser().parseExpression(SubExprVal)) |
Jason W Kim | 1f7bc07 | 2011-01-11 23:53:41 +0000 | [diff] [blame] | 5246 | return true; |
| 5247 | |
Evan Cheng | 965b3c7 | 2011-01-13 07:58:56 +0000 | [diff] [blame] | 5248 | const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal, |
Jim Grosbach | 9659ed9 | 2012-09-21 00:26:53 +0000 | [diff] [blame] | 5249 | getContext()); |
Jason W Kim | 1f7bc07 | 2011-01-11 23:53:41 +0000 | [diff] [blame] | 5250 | E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1); |
Evan Cheng | 965b3c7 | 2011-01-13 07:58:56 +0000 | [diff] [blame] | 5251 | Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E)); |
Jason W Kim | 1f7bc07 | 2011-01-11 23:53:41 +0000 | [diff] [blame] | 5252 | return false; |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 5253 | } |
David Peixotto | e407d09 | 2013-12-19 18:12:36 +0000 | [diff] [blame] | 5254 | case AsmToken::Equal: { |
| 5255 | if (Mnemonic != "ldr") // only parse for ldr pseudo (e.g. ldr r0, =val) |
| 5256 | return Error(Parser.getTok().getLoc(), "unexpected token in operand"); |
| 5257 | |
David Peixotto | e407d09 | 2013-12-19 18:12:36 +0000 | [diff] [blame] | 5258 | Parser.Lex(); // Eat '=' |
| 5259 | const MCExpr *SubExprVal; |
| 5260 | if (getParser().parseExpression(SubExprVal)) |
| 5261 | return true; |
| 5262 | E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1); |
| 5263 | |
David Peixotto | b9b7362 | 2014-02-04 17:22:40 +0000 | [diff] [blame] | 5264 | const MCExpr *CPLoc = getTargetStreamer().addConstantPoolEntry(SubExprVal); |
David Peixotto | e407d09 | 2013-12-19 18:12:36 +0000 | [diff] [blame] | 5265 | Operands.push_back(ARMOperand::CreateImm(CPLoc, S, E)); |
| 5266 | return false; |
| 5267 | } |
Jason W Kim | 1f7bc07 | 2011-01-11 23:53:41 +0000 | [diff] [blame] | 5268 | } |
| 5269 | } |
| 5270 | |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 5271 | // parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e. |
Evan Cheng | 965b3c7 | 2011-01-13 07:58:56 +0000 | [diff] [blame] | 5272 | // :lower16: and :upper16:. |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 5273 | bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 5274 | MCAsmParser &Parser = getParser(); |
Evan Cheng | 965b3c7 | 2011-01-13 07:58:56 +0000 | [diff] [blame] | 5275 | RefKind = ARMMCExpr::VK_ARM_None; |
Jason W Kim | 1f7bc07 | 2011-01-11 23:53:41 +0000 | [diff] [blame] | 5276 | |
Saleem Abdulrasool | 435f456 | 2014-01-10 04:38:40 +0000 | [diff] [blame] | 5277 | // consume an optional '#' (GNU compatibility) |
| 5278 | if (getLexer().is(AsmToken::Hash)) |
| 5279 | Parser.Lex(); |
| 5280 | |
Jason W Kim | 1f7bc07 | 2011-01-11 23:53:41 +0000 | [diff] [blame] | 5281 | // :lower16: and :upper16: modifiers |
Jason W Kim | 9322997 | 2011-01-13 00:27:00 +0000 | [diff] [blame] | 5282 | assert(getLexer().is(AsmToken::Colon) && "expected a :"); |
Jason W Kim | 1f7bc07 | 2011-01-11 23:53:41 +0000 | [diff] [blame] | 5283 | Parser.Lex(); // Eat ':' |
| 5284 | |
| 5285 | if (getLexer().isNot(AsmToken::Identifier)) { |
| 5286 | Error(Parser.getTok().getLoc(), "expected prefix identifier in operand"); |
| 5287 | return true; |
| 5288 | } |
| 5289 | |
| 5290 | StringRef IDVal = Parser.getTok().getIdentifier(); |
| 5291 | if (IDVal == "lower16") { |
Evan Cheng | 965b3c7 | 2011-01-13 07:58:56 +0000 | [diff] [blame] | 5292 | RefKind = ARMMCExpr::VK_ARM_LO16; |
Jason W Kim | 1f7bc07 | 2011-01-11 23:53:41 +0000 | [diff] [blame] | 5293 | } else if (IDVal == "upper16") { |
Evan Cheng | 965b3c7 | 2011-01-13 07:58:56 +0000 | [diff] [blame] | 5294 | RefKind = ARMMCExpr::VK_ARM_HI16; |
Jason W Kim | 1f7bc07 | 2011-01-11 23:53:41 +0000 | [diff] [blame] | 5295 | } else { |
| 5296 | Error(Parser.getTok().getLoc(), "unexpected prefix in operand"); |
| 5297 | return true; |
| 5298 | } |
| 5299 | Parser.Lex(); |
| 5300 | |
| 5301 | if (getLexer().isNot(AsmToken::Colon)) { |
| 5302 | Error(Parser.getTok().getLoc(), "unexpected token after prefix"); |
| 5303 | return true; |
| 5304 | } |
| 5305 | Parser.Lex(); // Eat the last ':' |
| 5306 | return false; |
| 5307 | } |
| 5308 | |
Daniel Dunbar | 9d944b3 | 2011-01-11 15:59:50 +0000 | [diff] [blame] | 5309 | /// \brief Given a mnemonic, split out possible predication code and carry |
| 5310 | /// setting letters to form a canonical mnemonic and flags. |
| 5311 | // |
Daniel Dunbar | 876bb018 | 2011-01-10 12:24:52 +0000 | [diff] [blame] | 5312 | // FIXME: Would be nice to autogen this. |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 5313 | // FIXME: This is a bit of a maze of special cases. |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 5314 | StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic, |
Jim Grosbach | 5cc3b4c | 2011-07-19 20:10:31 +0000 | [diff] [blame] | 5315 | unsigned &PredicationCode, |
| 5316 | bool &CarrySetting, |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 5317 | unsigned &ProcessorIMod, |
| 5318 | StringRef &ITMask) { |
Daniel Dunbar | 9d944b3 | 2011-01-11 15:59:50 +0000 | [diff] [blame] | 5319 | PredicationCode = ARMCC::AL; |
| 5320 | CarrySetting = false; |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 5321 | ProcessorIMod = 0; |
Daniel Dunbar | 9d944b3 | 2011-01-11 15:59:50 +0000 | [diff] [blame] | 5322 | |
Daniel Dunbar | 876bb018 | 2011-01-10 12:24:52 +0000 | [diff] [blame] | 5323 | // Ignore some mnemonics we know aren't predicated forms. |
Daniel Dunbar | 9d944b3 | 2011-01-11 15:59:50 +0000 | [diff] [blame] | 5324 | // |
| 5325 | // FIXME: Would be nice to autogen this. |
Jim Grosbach | 5cc3b4c | 2011-07-19 20:10:31 +0000 | [diff] [blame] | 5326 | if ((Mnemonic == "movs" && isThumb()) || |
| 5327 | Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" || |
| 5328 | Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" || |
| 5329 | Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" || |
| 5330 | Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" || |
Richard Barton | 8d519fe | 2013-09-05 14:14:19 +0000 | [diff] [blame] | 5331 | Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" || |
Jim Grosbach | 5cc3b4c | 2011-07-19 20:10:31 +0000 | [diff] [blame] | 5332 | Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" || |
| 5333 | Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" || |
Jim Grosbach | e16acac | 2011-12-19 19:43:50 +0000 | [diff] [blame] | 5334 | Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" || |
Joey Gouly | 2efaa73 | 2013-07-06 20:50:18 +0000 | [diff] [blame] | 5335 | Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || |
Joey Gouly | 0f12aa2 | 2013-07-09 11:26:18 +0000 | [diff] [blame] | 5336 | Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || |
| 5337 | Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" || |
Charlie Turner | 4d88ae2 | 2014-12-01 08:33:28 +0000 | [diff] [blame] | 5338 | Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic == "hvc" || |
| 5339 | Mnemonic.startswith("vsel")) |
Daniel Dunbar | 9d944b3 | 2011-01-11 15:59:50 +0000 | [diff] [blame] | 5340 | return Mnemonic; |
Daniel Dunbar | 75d26be | 2010-08-11 06:37:16 +0000 | [diff] [blame] | 5341 | |
Jim Grosbach | a9a3f0a | 2011-07-11 17:09:57 +0000 | [diff] [blame] | 5342 | // First, split out any predication code. Ignore mnemonics we know aren't |
| 5343 | // 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] | 5344 | if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" && |
Jim Grosbach | 0c398b9 | 2011-07-27 21:58:11 +0000 | [diff] [blame] | 5345 | Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" && |
Jim Grosbach | 3636be3 | 2011-08-22 23:55:58 +0000 | [diff] [blame] | 5346 | Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" && |
Jim Grosbach | f6d5d60 | 2011-09-01 18:22:13 +0000 | [diff] [blame] | 5347 | Mnemonic != "sbcs" && Mnemonic != "rscs") { |
Jim Grosbach | a9a3f0a | 2011-07-11 17:09:57 +0000 | [diff] [blame] | 5348 | unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2)) |
| 5349 | .Case("eq", ARMCC::EQ) |
| 5350 | .Case("ne", ARMCC::NE) |
| 5351 | .Case("hs", ARMCC::HS) |
| 5352 | .Case("cs", ARMCC::HS) |
| 5353 | .Case("lo", ARMCC::LO) |
| 5354 | .Case("cc", ARMCC::LO) |
| 5355 | .Case("mi", ARMCC::MI) |
| 5356 | .Case("pl", ARMCC::PL) |
| 5357 | .Case("vs", ARMCC::VS) |
| 5358 | .Case("vc", ARMCC::VC) |
| 5359 | .Case("hi", ARMCC::HI) |
| 5360 | .Case("ls", ARMCC::LS) |
| 5361 | .Case("ge", ARMCC::GE) |
| 5362 | .Case("lt", ARMCC::LT) |
| 5363 | .Case("gt", ARMCC::GT) |
| 5364 | .Case("le", ARMCC::LE) |
| 5365 | .Case("al", ARMCC::AL) |
| 5366 | .Default(~0U); |
| 5367 | if (CC != ~0U) { |
| 5368 | Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2); |
| 5369 | PredicationCode = CC; |
| 5370 | } |
Bill Wendling | 193961b | 2010-10-29 23:50:21 +0000 | [diff] [blame] | 5371 | } |
Daniel Dunbar | 188b47b | 2010-08-11 06:37:20 +0000 | [diff] [blame] | 5372 | |
Daniel Dunbar | 9d944b3 | 2011-01-11 15:59:50 +0000 | [diff] [blame] | 5373 | // Next, determine if we have a carry setting bit. We explicitly ignore all |
| 5374 | // the instructions we know end in 's'. |
| 5375 | if (Mnemonic.endswith("s") && |
Jim Grosbach | d3e8e29 | 2011-08-17 22:49:09 +0000 | [diff] [blame] | 5376 | !(Mnemonic == "cps" || Mnemonic == "mls" || |
Jim Grosbach | 5cc3b4c | 2011-07-19 20:10:31 +0000 | [diff] [blame] | 5377 | Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" || |
| 5378 | Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" || |
| 5379 | Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" || |
Jim Grosbach | 086d013 | 2011-12-08 00:49:29 +0000 | [diff] [blame] | 5380 | Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" || |
Jim Grosbach | 54337b8 | 2011-12-10 00:01:02 +0000 | [diff] [blame] | 5381 | Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" || |
Jim Grosbach | 92a939a | 2011-12-19 19:02:41 +0000 | [diff] [blame] | 5382 | Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" || |
Jim Grosbach | d74560b | 2012-03-15 20:48:18 +0000 | [diff] [blame] | 5383 | Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" || |
David Peixotto | a872e0e | 2014-01-07 18:19:23 +0000 | [diff] [blame] | 5384 | Mnemonic == "vfms" || Mnemonic == "vfnms" || Mnemonic == "fconsts" || |
Jim Grosbach | 51726e2 | 2011-07-29 20:26:09 +0000 | [diff] [blame] | 5385 | (Mnemonic == "movs" && isThumb()))) { |
Daniel Dunbar | 9d944b3 | 2011-01-11 15:59:50 +0000 | [diff] [blame] | 5386 | Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1); |
| 5387 | CarrySetting = true; |
| 5388 | } |
| 5389 | |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 5390 | // The "cps" instruction can have a interrupt mode operand which is glued into |
| 5391 | // the mnemonic. Check if this is the case, split it and parse the imod op |
| 5392 | if (Mnemonic.startswith("cps")) { |
| 5393 | // Split out any imod code. |
| 5394 | unsigned IMod = |
| 5395 | StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2)) |
| 5396 | .Case("ie", ARM_PROC::IE) |
| 5397 | .Case("id", ARM_PROC::ID) |
| 5398 | .Default(~0U); |
| 5399 | if (IMod != ~0U) { |
| 5400 | Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2); |
| 5401 | ProcessorIMod = IMod; |
| 5402 | } |
| 5403 | } |
| 5404 | |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 5405 | // The "it" instruction has the condition mask on the end of the mnemonic. |
| 5406 | if (Mnemonic.startswith("it")) { |
| 5407 | ITMask = Mnemonic.slice(2, Mnemonic.size()); |
| 5408 | Mnemonic = Mnemonic.slice(0, 2); |
| 5409 | } |
| 5410 | |
Daniel Dunbar | 9d944b3 | 2011-01-11 15:59:50 +0000 | [diff] [blame] | 5411 | return Mnemonic; |
| 5412 | } |
Daniel Dunbar | 5a384c8 | 2011-01-11 15:59:53 +0000 | [diff] [blame] | 5413 | |
| 5414 | /// \brief Given a canonical mnemonic, determine if the instruction ever allows |
| 5415 | /// inclusion of carry set or predication code operands. |
| 5416 | // |
| 5417 | // FIXME: It would be nice to autogen this. |
Bruno Cardoso Lopes | e6290cc | 2011-01-18 20:55:11 +0000 | [diff] [blame] | 5418 | void ARMAsmParser:: |
Amara Emerson | 3308909 | 2013-09-19 11:59:01 +0000 | [diff] [blame] | 5419 | getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst, |
| 5420 | bool &CanAcceptCarrySet, bool &CanAcceptPredicationCode) { |
Daniel Dunbar | 0926412 | 2011-01-11 19:06:29 +0000 | [diff] [blame] | 5421 | if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" || |
| 5422 | Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" || |
Jim Grosbach | d73c645 | 2011-09-16 18:05:48 +0000 | [diff] [blame] | 5423 | Mnemonic == "add" || Mnemonic == "adc" || |
Daniel Dunbar | 0926412 | 2011-01-11 19:06:29 +0000 | [diff] [blame] | 5424 | Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" || |
Jim Grosbach | fc54518 | 2011-09-19 23:31:02 +0000 | [diff] [blame] | 5425 | Mnemonic == "orr" || Mnemonic == "mvn" || |
Daniel Dunbar | 0926412 | 2011-01-11 19:06:29 +0000 | [diff] [blame] | 5426 | Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" || |
Jim Grosbach | fc54518 | 2011-09-19 23:31:02 +0000 | [diff] [blame] | 5427 | Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" || |
Evan Cheng | aca6c82 | 2012-04-11 00:13:00 +0000 | [diff] [blame] | 5428 | Mnemonic == "vfm" || Mnemonic == "vfnm" || |
Jim Grosbach | d73c645 | 2011-09-16 18:05:48 +0000 | [diff] [blame] | 5429 | (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" || |
Jim Grosbach | fc54518 | 2011-09-19 23:31:02 +0000 | [diff] [blame] | 5430 | Mnemonic == "mla" || Mnemonic == "smlal" || |
| 5431 | Mnemonic == "umlal" || Mnemonic == "umull"))) { |
Daniel Dunbar | 0926412 | 2011-01-11 19:06:29 +0000 | [diff] [blame] | 5432 | CanAcceptCarrySet = true; |
Jim Grosbach | 6c45b75 | 2011-09-16 16:39:25 +0000 | [diff] [blame] | 5433 | } else |
Daniel Dunbar | 0926412 | 2011-01-11 19:06:29 +0000 | [diff] [blame] | 5434 | CanAcceptCarrySet = false; |
Daniel Dunbar | 5a384c8 | 2011-01-11 15:59:53 +0000 | [diff] [blame] | 5435 | |
Tim Northover | 2c45a38 | 2013-06-26 16:52:40 +0000 | [diff] [blame] | 5436 | if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" || |
| 5437 | Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" || |
Saleem Abdulrasool | 27351f2 | 2014-05-14 03:47:39 +0000 | [diff] [blame] | 5438 | Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic == "udf" || |
| 5439 | Mnemonic.startswith("crc32") || Mnemonic.startswith("cps") || |
| 5440 | Mnemonic.startswith("vsel") || |
Joey Gouly | 2d0175e | 2013-07-09 09:59:04 +0000 | [diff] [blame] | 5441 | Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" || |
Joey Gouly | 0f12aa2 | 2013-07-09 11:26:18 +0000 | [diff] [blame] | 5442 | Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" || |
| 5443 | Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" || |
Charlie Turner | 4d88ae2 | 2014-12-01 08:33:28 +0000 | [diff] [blame] | 5444 | Mnemonic == "vrintm" || Mnemonic.startswith("aes") || Mnemonic == "hvc" || |
Amara Emerson | 3308909 | 2013-09-19 11:59:01 +0000 | [diff] [blame] | 5445 | Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") || |
| 5446 | (FullInst.startswith("vmull") && FullInst.endswith(".p64"))) { |
Tim Northover | 2c45a38 | 2013-06-26 16:52:40 +0000 | [diff] [blame] | 5447 | // These mnemonics are never predicable |
Daniel Dunbar | 5a384c8 | 2011-01-11 15:59:53 +0000 | [diff] [blame] | 5448 | CanAcceptPredicationCode = false; |
Tim Northover | 2c45a38 | 2013-06-26 16:52:40 +0000 | [diff] [blame] | 5449 | } else if (!isThumb()) { |
| 5450 | // Some instructions are only predicable in Thumb mode |
| 5451 | CanAcceptPredicationCode |
| 5452 | = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" && |
| 5453 | Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" && |
| 5454 | Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" && |
| 5455 | Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" && |
| 5456 | Mnemonic != "ldc2" && Mnemonic != "ldc2l" && |
| 5457 | Mnemonic != "stc2" && Mnemonic != "stc2l" && |
| 5458 | !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs"); |
| 5459 | } else if (isThumbOne()) { |
Tim Northover | f86d1f0 | 2013-10-07 11:10:47 +0000 | [diff] [blame] | 5460 | if (hasV6MOps()) |
| 5461 | CanAcceptPredicationCode = Mnemonic != "movs"; |
| 5462 | else |
| 5463 | CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs"; |
Jim Grosbach | 6c45b75 | 2011-09-16 16:39:25 +0000 | [diff] [blame] | 5464 | } else |
Daniel Dunbar | 5a384c8 | 2011-01-11 15:59:53 +0000 | [diff] [blame] | 5465 | CanAcceptPredicationCode = true; |
Daniel Dunbar | 876bb018 | 2011-01-10 12:24:52 +0000 | [diff] [blame] | 5466 | } |
| 5467 | |
Jim Grosbach | 7283da9 | 2011-08-16 21:12:37 +0000 | [diff] [blame] | 5468 | bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic, |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5469 | OperandVector &Operands) { |
Jim Grosbach | 1d3c137 | 2011-09-01 00:28:52 +0000 | [diff] [blame] | 5470 | // FIXME: This is all horribly hacky. We really need a better way to deal |
| 5471 | // with optional operands like this in the matcher table. |
Jim Grosbach | 7283da9 | 2011-08-16 21:12:37 +0000 | [diff] [blame] | 5472 | |
| 5473 | // The 'mov' mnemonic is special. One variant has a cc_out operand, while |
| 5474 | // another does not. Specifically, the MOVW instruction does not. So we |
| 5475 | // special case it here and remove the defaulted (non-setting) cc_out |
| 5476 | // operand if that's the instruction we're trying to match. |
| 5477 | // |
| 5478 | // We do this as post-processing of the explicit operands rather than just |
| 5479 | // conditionally adding the cc_out in the first place because we need |
| 5480 | // to check the type of the parsed immediate operand. |
Owen Anderson | d7791b9 | 2011-09-14 22:46:14 +0000 | [diff] [blame] | 5481 | if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5482 | !static_cast<ARMOperand &>(*Operands[4]).isARMSOImm() && |
| 5483 | static_cast<ARMOperand &>(*Operands[4]).isImm0_65535Expr() && |
| 5484 | static_cast<ARMOperand &>(*Operands[1]).getReg() == 0) |
Jim Grosbach | 7283da9 | 2011-08-16 21:12:37 +0000 | [diff] [blame] | 5485 | return true; |
Jim Grosbach | 58ffdcc | 2011-08-16 21:34:08 +0000 | [diff] [blame] | 5486 | |
| 5487 | // Register-register 'add' for thumb does not have a cc_out operand |
| 5488 | // when there are only two register operands. |
| 5489 | if (isThumb() && Mnemonic == "add" && Operands.size() == 5 && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5490 | static_cast<ARMOperand &>(*Operands[3]).isReg() && |
| 5491 | static_cast<ARMOperand &>(*Operands[4]).isReg() && |
| 5492 | static_cast<ARMOperand &>(*Operands[1]).getReg() == 0) |
Jim Grosbach | 58ffdcc | 2011-08-16 21:34:08 +0000 | [diff] [blame] | 5493 | return true; |
Jim Grosbach | 0a0b307 | 2011-08-24 21:22:15 +0000 | [diff] [blame] | 5494 | // Register-register 'add' for thumb does not have a cc_out operand |
Jim Grosbach | 1d3c137 | 2011-09-01 00:28:52 +0000 | [diff] [blame] | 5495 | // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do |
| 5496 | // have to check the immediate range here since Thumb2 has a variant |
| 5497 | // that can handle a different range and has a cc_out operand. |
Jim Grosbach | d0c435c | 2011-09-16 22:58:42 +0000 | [diff] [blame] | 5498 | if (((isThumb() && Mnemonic == "add") || |
| 5499 | (isThumbTwo() && Mnemonic == "sub")) && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5500 | Operands.size() == 6 && static_cast<ARMOperand &>(*Operands[3]).isReg() && |
| 5501 | static_cast<ARMOperand &>(*Operands[4]).isReg() && |
| 5502 | static_cast<ARMOperand &>(*Operands[4]).getReg() == ARM::SP && |
| 5503 | static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 && |
| 5504 | ((Mnemonic == "add" && static_cast<ARMOperand &>(*Operands[5]).isReg()) || |
| 5505 | static_cast<ARMOperand &>(*Operands[5]).isImm0_1020s4())) |
Jim Grosbach | 0a0b307 | 2011-08-24 21:22:15 +0000 | [diff] [blame] | 5506 | return true; |
Jim Grosbach | d0c435c | 2011-09-16 22:58:42 +0000 | [diff] [blame] | 5507 | // For Thumb2, add/sub immediate does not have a cc_out operand for the |
| 5508 | // imm0_4095 variant. That's the least-preferred variant when |
Jim Grosbach | 1d3c137 | 2011-09-01 00:28:52 +0000 | [diff] [blame] | 5509 | // selecting via the generic "add" mnemonic, so to know that we |
| 5510 | // should remove the cc_out operand, we have to explicitly check that |
| 5511 | // it's not one of the other variants. Ugh. |
Jim Grosbach | d0c435c | 2011-09-16 22:58:42 +0000 | [diff] [blame] | 5512 | if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5513 | Operands.size() == 6 && static_cast<ARMOperand &>(*Operands[3]).isReg() && |
| 5514 | static_cast<ARMOperand &>(*Operands[4]).isReg() && |
| 5515 | static_cast<ARMOperand &>(*Operands[5]).isImm()) { |
Jim Grosbach | 1d3c137 | 2011-09-01 00:28:52 +0000 | [diff] [blame] | 5516 | // Nest conditions rather than one big 'if' statement for readability. |
| 5517 | // |
Jim Grosbach | 1d3c137 | 2011-09-01 00:28:52 +0000 | [diff] [blame] | 5518 | // If both registers are low, we're in an IT block, and the immediate is |
| 5519 | // in range, we should use encoding T1 instead, which has a cc_out. |
| 5520 | if (inITBlock() && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5521 | isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) && |
| 5522 | isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) && |
| 5523 | static_cast<ARMOperand &>(*Operands[5]).isImm0_7()) |
Jim Grosbach | 1d3c137 | 2011-09-01 00:28:52 +0000 | [diff] [blame] | 5524 | return false; |
Tilmann Scheller | ef5666f | 2013-07-03 20:38:01 +0000 | [diff] [blame] | 5525 | // Check against T3. If the second register is the PC, this is an |
| 5526 | // alternate form of ADR, which uses encoding T4, so check for that too. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5527 | if (static_cast<ARMOperand &>(*Operands[4]).getReg() != ARM::PC && |
| 5528 | static_cast<ARMOperand &>(*Operands[5]).isT2SOImm()) |
Tilmann Scheller | ef5666f | 2013-07-03 20:38:01 +0000 | [diff] [blame] | 5529 | return false; |
Jim Grosbach | 1d3c137 | 2011-09-01 00:28:52 +0000 | [diff] [blame] | 5530 | |
| 5531 | // Otherwise, we use encoding T4, which does not have a cc_out |
| 5532 | // operand. |
| 5533 | return true; |
| 5534 | } |
| 5535 | |
Jim Grosbach | 9c8b993 | 2011-09-14 21:00:40 +0000 | [diff] [blame] | 5536 | // The thumb2 multiply instruction doesn't have a CCOut register, so |
| 5537 | // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to |
| 5538 | // use the 16-bit encoding or not. |
| 5539 | if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5540 | static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 && |
| 5541 | static_cast<ARMOperand &>(*Operands[3]).isReg() && |
| 5542 | static_cast<ARMOperand &>(*Operands[4]).isReg() && |
| 5543 | static_cast<ARMOperand &>(*Operands[5]).isReg() && |
Jim Grosbach | 9c8b993 | 2011-09-14 21:00:40 +0000 | [diff] [blame] | 5544 | // If the registers aren't low regs, the destination reg isn't the |
| 5545 | // same as one of the source regs, or the cc_out operand is zero |
| 5546 | // outside of an IT block, we have to use the 32-bit encoding, so |
| 5547 | // remove the cc_out operand. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5548 | (!isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) || |
| 5549 | !isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) || |
| 5550 | !isARMLowRegister(static_cast<ARMOperand &>(*Operands[5]).getReg()) || |
| 5551 | !inITBlock() || (static_cast<ARMOperand &>(*Operands[3]).getReg() != |
| 5552 | static_cast<ARMOperand &>(*Operands[5]).getReg() && |
| 5553 | static_cast<ARMOperand &>(*Operands[3]).getReg() != |
| 5554 | static_cast<ARMOperand &>(*Operands[4]).getReg()))) |
Jim Grosbach | 9c8b993 | 2011-09-14 21:00:40 +0000 | [diff] [blame] | 5555 | return true; |
| 5556 | |
Jim Grosbach | efa7e95 | 2011-11-15 19:55:16 +0000 | [diff] [blame] | 5557 | // Also check the 'mul' syntax variant that doesn't specify an explicit |
| 5558 | // destination register. |
| 5559 | if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5560 | static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 && |
| 5561 | static_cast<ARMOperand &>(*Operands[3]).isReg() && |
| 5562 | static_cast<ARMOperand &>(*Operands[4]).isReg() && |
Jim Grosbach | efa7e95 | 2011-11-15 19:55:16 +0000 | [diff] [blame] | 5563 | // If the registers aren't low regs or the cc_out operand is zero |
| 5564 | // outside of an IT block, we have to use the 32-bit encoding, so |
| 5565 | // remove the cc_out operand. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5566 | (!isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) || |
| 5567 | !isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) || |
Jim Grosbach | efa7e95 | 2011-11-15 19:55:16 +0000 | [diff] [blame] | 5568 | !inITBlock())) |
| 5569 | return true; |
| 5570 | |
Jim Grosbach | 9c8b993 | 2011-09-14 21:00:40 +0000 | [diff] [blame] | 5571 | |
Jim Grosbach | 1d3c137 | 2011-09-01 00:28:52 +0000 | [diff] [blame] | 5572 | |
Jim Grosbach | 4b701af | 2011-08-24 21:42:27 +0000 | [diff] [blame] | 5573 | // Register-register 'add/sub' for thumb does not have a cc_out operand |
| 5574 | // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also |
| 5575 | // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't |
| 5576 | // right, this will result in better diagnostics (which operand is off) |
| 5577 | // anyway. |
| 5578 | if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") && |
| 5579 | (Operands.size() == 5 || Operands.size() == 6) && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5580 | static_cast<ARMOperand &>(*Operands[3]).isReg() && |
| 5581 | static_cast<ARMOperand &>(*Operands[3]).getReg() == ARM::SP && |
| 5582 | static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 && |
| 5583 | (static_cast<ARMOperand &>(*Operands[4]).isImm() || |
Jim Grosbach | df5a244 | 2012-04-10 17:31:55 +0000 | [diff] [blame] | 5584 | (Operands.size() == 6 && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5585 | static_cast<ARMOperand &>(*Operands[5]).isImm()))) |
Jim Grosbach | 0a0b307 | 2011-08-24 21:22:15 +0000 | [diff] [blame] | 5586 | return true; |
Jim Grosbach | 58ffdcc | 2011-08-16 21:34:08 +0000 | [diff] [blame] | 5587 | |
Jim Grosbach | 7283da9 | 2011-08-16 21:12:37 +0000 | [diff] [blame] | 5588 | return false; |
| 5589 | } |
| 5590 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5591 | bool ARMAsmParser::shouldOmitPredicateOperand(StringRef Mnemonic, |
| 5592 | OperandVector &Operands) { |
Joey Gouly | e860255 | 2013-07-19 16:34:16 +0000 | [diff] [blame] | 5593 | // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON |
| 5594 | unsigned RegIdx = 3; |
| 5595 | if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5596 | static_cast<ARMOperand &>(*Operands[2]).getToken() == ".f32") { |
| 5597 | if (static_cast<ARMOperand &>(*Operands[3]).isToken() && |
| 5598 | static_cast<ARMOperand &>(*Operands[3]).getToken() == ".f32") |
Joey Gouly | e860255 | 2013-07-19 16:34:16 +0000 | [diff] [blame] | 5599 | RegIdx = 4; |
| 5600 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5601 | if (static_cast<ARMOperand &>(*Operands[RegIdx]).isReg() && |
| 5602 | (ARMMCRegisterClasses[ARM::DPRRegClassID].contains( |
| 5603 | static_cast<ARMOperand &>(*Operands[RegIdx]).getReg()) || |
| 5604 | ARMMCRegisterClasses[ARM::QPRRegClassID].contains( |
| 5605 | static_cast<ARMOperand &>(*Operands[RegIdx]).getReg()))) |
Joey Gouly | e860255 | 2013-07-19 16:34:16 +0000 | [diff] [blame] | 5606 | return true; |
| 5607 | } |
Joey Gouly | f520d5e | 2013-07-19 16:45:16 +0000 | [diff] [blame] | 5608 | return false; |
Joey Gouly | e860255 | 2013-07-19 16:34:16 +0000 | [diff] [blame] | 5609 | } |
| 5610 | |
Jim Grosbach | 12952fe | 2011-11-11 23:08:10 +0000 | [diff] [blame] | 5611 | static bool isDataTypeToken(StringRef Tok) { |
| 5612 | return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" || |
| 5613 | Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" || |
| 5614 | Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" || |
| 5615 | Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" || |
| 5616 | Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" || |
| 5617 | Tok == ".f" || Tok == ".d"; |
| 5618 | } |
| 5619 | |
| 5620 | // FIXME: This bit should probably be handled via an explicit match class |
| 5621 | // in the .td files that matches the suffix instead of having it be |
| 5622 | // a literal string token the way it is now. |
| 5623 | static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) { |
| 5624 | return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm"); |
| 5625 | } |
Tim Northover | 26bb14e | 2014-08-18 11:49:42 +0000 | [diff] [blame] | 5626 | static void applyMnemonicAliases(StringRef &Mnemonic, uint64_t Features, |
Chad Rosier | 9f7a221 | 2013-04-18 22:35:36 +0000 | [diff] [blame] | 5627 | unsigned VariantID); |
Saleem Abdulrasool | e3a9dc1 | 2013-12-30 18:38:01 +0000 | [diff] [blame] | 5628 | |
| 5629 | static bool RequiresVFPRegListValidation(StringRef Inst, |
| 5630 | bool &AcceptSinglePrecisionOnly, |
| 5631 | bool &AcceptDoublePrecisionOnly) { |
| 5632 | if (Inst.size() < 7) |
| 5633 | return false; |
| 5634 | |
| 5635 | if (Inst.startswith("fldm") || Inst.startswith("fstm")) { |
| 5636 | StringRef AddressingMode = Inst.substr(4, 2); |
| 5637 | if (AddressingMode == "ia" || AddressingMode == "db" || |
| 5638 | AddressingMode == "ea" || AddressingMode == "fd") { |
| 5639 | AcceptSinglePrecisionOnly = Inst[6] == 's'; |
| 5640 | AcceptDoublePrecisionOnly = Inst[6] == 'd' || Inst[6] == 'x'; |
| 5641 | return true; |
| 5642 | } |
| 5643 | } |
| 5644 | |
| 5645 | return false; |
| 5646 | } |
| 5647 | |
Daniel Dunbar | 876bb018 | 2011-01-10 12:24:52 +0000 | [diff] [blame] | 5648 | /// Parse an arm instruction mnemonic followed by its operands. |
Chad Rosier | f0e8720 | 2012-10-25 20:41:34 +0000 | [diff] [blame] | 5649 | bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name, |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5650 | SMLoc NameLoc, OperandVector &Operands) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 5651 | MCAsmParser &Parser = getParser(); |
Saleem Abdulrasool | 4da9c6e | 2013-12-29 17:58:35 +0000 | [diff] [blame] | 5652 | // FIXME: Can this be done via tablegen in some fashion? |
Saleem Abdulrasool | e3a9dc1 | 2013-12-30 18:38:01 +0000 | [diff] [blame] | 5653 | bool RequireVFPRegisterListCheck; |
Saleem Abdulrasool | 4da9c6e | 2013-12-29 17:58:35 +0000 | [diff] [blame] | 5654 | bool AcceptSinglePrecisionOnly; |
Saleem Abdulrasool | e3a9dc1 | 2013-12-30 18:38:01 +0000 | [diff] [blame] | 5655 | bool AcceptDoublePrecisionOnly; |
| 5656 | RequireVFPRegisterListCheck = |
| 5657 | RequiresVFPRegListValidation(Name, AcceptSinglePrecisionOnly, |
| 5658 | AcceptDoublePrecisionOnly); |
Saleem Abdulrasool | 4da9c6e | 2013-12-29 17:58:35 +0000 | [diff] [blame] | 5659 | |
Jim Grosbach | 8be2f65 | 2011-12-09 23:34:09 +0000 | [diff] [blame] | 5660 | // Apply mnemonic aliases before doing anything else, as the destination |
Saleem Abdulrasool | a1937cb | 2013-12-29 17:58:31 +0000 | [diff] [blame] | 5661 | // mnemonic may include suffices and we want to handle them normally. |
Jim Grosbach | 8be2f65 | 2011-12-09 23:34:09 +0000 | [diff] [blame] | 5662 | // The generic tblgen'erated code does this later, at the start of |
| 5663 | // MatchInstructionImpl(), but that's too late for aliases that include |
| 5664 | // any sort of suffix. |
Tim Northover | 26bb14e | 2014-08-18 11:49:42 +0000 | [diff] [blame] | 5665 | uint64_t AvailableFeatures = getAvailableFeatures(); |
Chad Rosier | 9f7a221 | 2013-04-18 22:35:36 +0000 | [diff] [blame] | 5666 | unsigned AssemblerDialect = getParser().getAssemblerDialect(); |
| 5667 | applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect); |
Jim Grosbach | 8be2f65 | 2011-12-09 23:34:09 +0000 | [diff] [blame] | 5668 | |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 5669 | // First check for the ARM-specific .req directive. |
| 5670 | if (Parser.getTok().is(AsmToken::Identifier) && |
| 5671 | Parser.getTok().getIdentifier() == ".req") { |
| 5672 | parseDirectiveReq(Name, NameLoc); |
| 5673 | // We always return 'error' for this, as we're done with this |
| 5674 | // statement and don't need to match the 'instruction." |
| 5675 | return true; |
| 5676 | } |
| 5677 | |
Daniel Dunbar | 876bb018 | 2011-01-10 12:24:52 +0000 | [diff] [blame] | 5678 | // Create the leading tokens for the mnemonic, split by '.' characters. |
| 5679 | size_t Start = 0, Next = Name.find('.'); |
Jim Grosbach | 7c09e3c | 2011-07-19 19:13:28 +0000 | [diff] [blame] | 5680 | StringRef Mnemonic = Name.slice(Start, Next); |
Daniel Dunbar | 876bb018 | 2011-01-10 12:24:52 +0000 | [diff] [blame] | 5681 | |
Daniel Dunbar | 9d944b3 | 2011-01-11 15:59:50 +0000 | [diff] [blame] | 5682 | // Split out the predication code and carry setting flag from the mnemonic. |
| 5683 | unsigned PredicationCode; |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 5684 | unsigned ProcessorIMod; |
Daniel Dunbar | 9d944b3 | 2011-01-11 15:59:50 +0000 | [diff] [blame] | 5685 | bool CarrySetting; |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 5686 | StringRef ITMask; |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 5687 | Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting, |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 5688 | ProcessorIMod, ITMask); |
Daniel Dunbar | 876bb018 | 2011-01-10 12:24:52 +0000 | [diff] [blame] | 5689 | |
Jim Grosbach | 1c171b1 | 2011-08-25 17:23:55 +0000 | [diff] [blame] | 5690 | // In Thumb1, only the branch (B) instruction can be predicated. |
| 5691 | if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") { |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 5692 | Parser.eatToEndOfStatement(); |
Jim Grosbach | 1c171b1 | 2011-08-25 17:23:55 +0000 | [diff] [blame] | 5693 | return Error(NameLoc, "conditional execution not supported in Thumb1"); |
| 5694 | } |
| 5695 | |
Jim Grosbach | 7c09e3c | 2011-07-19 19:13:28 +0000 | [diff] [blame] | 5696 | Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc)); |
| 5697 | |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 5698 | // Handle the IT instruction ITMask. Convert it to a bitmask. This |
| 5699 | // is the mask as it will be for the IT encoding if the conditional |
| 5700 | // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case |
| 5701 | // where the conditional bit0 is zero, the instruction post-processing |
| 5702 | // will adjust the mask accordingly. |
| 5703 | if (Mnemonic == "it") { |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5704 | SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2); |
| 5705 | if (ITMask.size() > 3) { |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 5706 | Parser.eatToEndOfStatement(); |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5707 | return Error(Loc, "too many conditions on IT instruction"); |
| 5708 | } |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 5709 | unsigned Mask = 8; |
| 5710 | for (unsigned i = ITMask.size(); i != 0; --i) { |
| 5711 | char pos = ITMask[i - 1]; |
| 5712 | if (pos != 't' && pos != 'e') { |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 5713 | Parser.eatToEndOfStatement(); |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5714 | return Error(Loc, "illegal IT block condition mask '" + ITMask + "'"); |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 5715 | } |
| 5716 | Mask >>= 1; |
| 5717 | if (ITMask[i - 1] == 't') |
| 5718 | Mask |= 8; |
| 5719 | } |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5720 | Operands.push_back(ARMOperand::CreateITMask(Mask, Loc)); |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 5721 | } |
| 5722 | |
Jim Grosbach | 7c09e3c | 2011-07-19 19:13:28 +0000 | [diff] [blame] | 5723 | // FIXME: This is all a pretty gross hack. We should automatically handle |
| 5724 | // optional operands like this via tblgen. |
Bill Wendling | 219dabd | 2010-11-21 10:56:05 +0000 | [diff] [blame] | 5725 | |
Daniel Dunbar | 5a384c8 | 2011-01-11 15:59:53 +0000 | [diff] [blame] | 5726 | // Next, add the CCOut and ConditionCode operands, if needed. |
| 5727 | // |
| 5728 | // For mnemonics which can ever incorporate a carry setting bit or predication |
| 5729 | // code, our matching model involves us always generating CCOut and |
| 5730 | // ConditionCode operands to match the mnemonic "as written" and then we let |
| 5731 | // the matcher deal with finding the right instruction or generating an |
| 5732 | // appropriate error. |
| 5733 | bool CanAcceptCarrySet, CanAcceptPredicationCode; |
Amara Emerson | 3308909 | 2013-09-19 11:59:01 +0000 | [diff] [blame] | 5734 | getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode); |
Daniel Dunbar | 5a384c8 | 2011-01-11 15:59:53 +0000 | [diff] [blame] | 5735 | |
Jim Grosbach | 03a8a16 | 2011-07-14 22:04:21 +0000 | [diff] [blame] | 5736 | // If we had a carry-set on an instruction that can't do that, issue an |
| 5737 | // error. |
| 5738 | if (!CanAcceptCarrySet && CarrySetting) { |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 5739 | Parser.eatToEndOfStatement(); |
Jim Grosbach | 7c09e3c | 2011-07-19 19:13:28 +0000 | [diff] [blame] | 5740 | return Error(NameLoc, "instruction '" + Mnemonic + |
Jim Grosbach | 03a8a16 | 2011-07-14 22:04:21 +0000 | [diff] [blame] | 5741 | "' can not set flags, but 's' suffix specified"); |
| 5742 | } |
Jim Grosbach | 0a54770 | 2011-07-22 17:44:50 +0000 | [diff] [blame] | 5743 | // If we had a predication code on an instruction that can't do that, issue an |
| 5744 | // error. |
| 5745 | if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) { |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 5746 | Parser.eatToEndOfStatement(); |
Jim Grosbach | 0a54770 | 2011-07-22 17:44:50 +0000 | [diff] [blame] | 5747 | return Error(NameLoc, "instruction '" + Mnemonic + |
| 5748 | "' is not predicable, but condition code specified"); |
| 5749 | } |
Jim Grosbach | 03a8a16 | 2011-07-14 22:04:21 +0000 | [diff] [blame] | 5750 | |
Daniel Dunbar | 5a384c8 | 2011-01-11 15:59:53 +0000 | [diff] [blame] | 5751 | // Add the carry setting operand, if necessary. |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5752 | if (CanAcceptCarrySet) { |
| 5753 | SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size()); |
Daniel Dunbar | 5a384c8 | 2011-01-11 15:59:53 +0000 | [diff] [blame] | 5754 | Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0, |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5755 | Loc)); |
| 5756 | } |
Daniel Dunbar | 5a384c8 | 2011-01-11 15:59:53 +0000 | [diff] [blame] | 5757 | |
| 5758 | // Add the predication code operand, if necessary. |
| 5759 | if (CanAcceptPredicationCode) { |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5760 | SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() + |
| 5761 | CarrySetting); |
Daniel Dunbar | 5a384c8 | 2011-01-11 15:59:53 +0000 | [diff] [blame] | 5762 | Operands.push_back(ARMOperand::CreateCondCode( |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5763 | ARMCC::CondCodes(PredicationCode), Loc)); |
Daniel Dunbar | 876bb018 | 2011-01-10 12:24:52 +0000 | [diff] [blame] | 5764 | } |
Daniel Dunbar | 188b47b | 2010-08-11 06:37:20 +0000 | [diff] [blame] | 5765 | |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 5766 | // Add the processor imod operand, if necessary. |
| 5767 | if (ProcessorIMod) { |
| 5768 | Operands.push_back(ARMOperand::CreateImm( |
| 5769 | MCConstantExpr::Create(ProcessorIMod, getContext()), |
| 5770 | NameLoc, NameLoc)); |
Oliver Stannard | 1ae8b47 | 2014-09-24 14:20:01 +0000 | [diff] [blame] | 5771 | } else if (Mnemonic == "cps" && isMClass()) { |
| 5772 | return Error(NameLoc, "instruction 'cps' requires effect for M-class"); |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 5773 | } |
| 5774 | |
Daniel Dunbar | 188b47b | 2010-08-11 06:37:20 +0000 | [diff] [blame] | 5775 | // Add the remaining tokens in the mnemonic. |
Daniel Dunbar | 75d26be | 2010-08-11 06:37:16 +0000 | [diff] [blame] | 5776 | while (Next != StringRef::npos) { |
| 5777 | Start = Next; |
| 5778 | Next = Name.find('.', Start + 1); |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 5779 | StringRef ExtraToken = Name.slice(Start, Next); |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 5780 | |
Jim Grosbach | 12952fe | 2011-11-11 23:08:10 +0000 | [diff] [blame] | 5781 | // Some NEON instructions have an optional datatype suffix that is |
| 5782 | // completely ignored. Check for that. |
| 5783 | if (isDataTypeToken(ExtraToken) && |
| 5784 | doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken)) |
| 5785 | continue; |
| 5786 | |
Kevin Enderby | c5d0935 | 2013-06-18 20:19:24 +0000 | [diff] [blame] | 5787 | // For for ARM mode generate an error if the .n qualifier is used. |
| 5788 | if (ExtraToken == ".n" && !isThumb()) { |
| 5789 | SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start); |
Saleem Abdulrasool | bdae4b8 | 2014-01-12 05:25:44 +0000 | [diff] [blame] | 5790 | Parser.eatToEndOfStatement(); |
Kevin Enderby | c5d0935 | 2013-06-18 20:19:24 +0000 | [diff] [blame] | 5791 | return Error(Loc, "instruction with .n (narrow) qualifier not allowed in " |
| 5792 | "arm mode"); |
| 5793 | } |
| 5794 | |
| 5795 | // The .n qualifier is always discarded as that is what the tables |
| 5796 | // and matcher expect. In ARM mode the .w qualifier has no effect, |
| 5797 | // so discard it to avoid errors that can be caused by the matcher. |
| 5798 | if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) { |
Jim Grosbach | 39c6e1d | 2011-09-07 16:06:04 +0000 | [diff] [blame] | 5799 | SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start); |
| 5800 | Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc)); |
| 5801 | } |
Daniel Dunbar | 75d26be | 2010-08-11 06:37:16 +0000 | [diff] [blame] | 5802 | } |
| 5803 | |
| 5804 | // Read the remaining operands. |
| 5805 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 5806 | // Read the first operand. |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 5807 | if (parseOperand(Operands, Mnemonic)) { |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 5808 | Parser.eatToEndOfStatement(); |
Chris Lattner | a2a9d16 | 2010-09-11 16:18:25 +0000 | [diff] [blame] | 5809 | return true; |
| 5810 | } |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 5811 | |
| 5812 | while (getLexer().is(AsmToken::Comma)) { |
Sean Callanan | a83fd7d | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 5813 | Parser.Lex(); // Eat the comma. |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 5814 | |
| 5815 | // Parse and remember the operand. |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 5816 | if (parseOperand(Operands, Mnemonic)) { |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 5817 | Parser.eatToEndOfStatement(); |
Chris Lattner | a2a9d16 | 2010-09-11 16:18:25 +0000 | [diff] [blame] | 5818 | return true; |
| 5819 | } |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 5820 | } |
| 5821 | } |
Jim Grosbach | 624bcc7 | 2010-10-29 14:46:02 +0000 | [diff] [blame] | 5822 | |
Chris Lattner | a2a9d16 | 2010-09-11 16:18:25 +0000 | [diff] [blame] | 5823 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
Jim Grosbach | b8d9f51 | 2011-10-07 18:27:04 +0000 | [diff] [blame] | 5824 | SMLoc Loc = getLexer().getLoc(); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 5825 | Parser.eatToEndOfStatement(); |
Jim Grosbach | b8d9f51 | 2011-10-07 18:27:04 +0000 | [diff] [blame] | 5826 | return Error(Loc, "unexpected token in argument list"); |
Chris Lattner | a2a9d16 | 2010-09-11 16:18:25 +0000 | [diff] [blame] | 5827 | } |
Bill Wendling | ee7f1f9 | 2010-11-06 21:42:12 +0000 | [diff] [blame] | 5828 | |
Chris Lattner | 91689c1 | 2010-09-08 05:10:46 +0000 | [diff] [blame] | 5829 | Parser.Lex(); // Consume the EndOfStatement |
Jim Grosbach | 7c09e3c | 2011-07-19 19:13:28 +0000 | [diff] [blame] | 5830 | |
Saleem Abdulrasool | e3a9dc1 | 2013-12-30 18:38:01 +0000 | [diff] [blame] | 5831 | if (RequireVFPRegisterListCheck) { |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5832 | ARMOperand &Op = static_cast<ARMOperand &>(*Operands.back()); |
| 5833 | if (AcceptSinglePrecisionOnly && !Op.isSPRRegList()) |
| 5834 | return Error(Op.getStartLoc(), |
Saleem Abdulrasool | aca443c | 2013-12-29 18:53:16 +0000 | [diff] [blame] | 5835 | "VFP/Neon single precision register expected"); |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5836 | if (AcceptDoublePrecisionOnly && !Op.isDPRRegList()) |
| 5837 | return Error(Op.getStartLoc(), |
Saleem Abdulrasool | aca443c | 2013-12-29 18:53:16 +0000 | [diff] [blame] | 5838 | "VFP/Neon double precision register expected"); |
Saleem Abdulrasool | 4da9c6e | 2013-12-29 17:58:35 +0000 | [diff] [blame] | 5839 | } |
| 5840 | |
Jim Grosbach | 7283da9 | 2011-08-16 21:12:37 +0000 | [diff] [blame] | 5841 | // Some instructions, mostly Thumb, have forms for the same mnemonic that |
| 5842 | // do and don't have a cc_out optional-def operand. With some spot-checks |
| 5843 | // of the operand list, we can figure out which variant we're trying to |
Jim Grosbach | 1d3c137 | 2011-09-01 00:28:52 +0000 | [diff] [blame] | 5844 | // parse and adjust accordingly before actually matching. We shouldn't ever |
| 5845 | // try to remove a cc_out operand that was explicitly set on the the |
| 5846 | // mnemonic, of course (CarrySetting == true). Reason number #317 the |
| 5847 | // table driven matcher doesn't fit well with the ARM instruction set. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5848 | if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) |
Jim Grosbach | 7c09e3c | 2011-07-19 19:13:28 +0000 | [diff] [blame] | 5849 | Operands.erase(Operands.begin() + 1); |
Jim Grosbach | 7c09e3c | 2011-07-19 19:13:28 +0000 | [diff] [blame] | 5850 | |
Joey Gouly | e860255 | 2013-07-19 16:34:16 +0000 | [diff] [blame] | 5851 | // Some instructions have the same mnemonic, but don't always |
| 5852 | // have a predicate. Distinguish them here and delete the |
| 5853 | // predicate if needed. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5854 | if (shouldOmitPredicateOperand(Mnemonic, Operands)) |
Joey Gouly | e860255 | 2013-07-19 16:34:16 +0000 | [diff] [blame] | 5855 | Operands.erase(Operands.begin() + 1); |
Joey Gouly | e860255 | 2013-07-19 16:34:16 +0000 | [diff] [blame] | 5856 | |
Jim Grosbach | a03ab0e | 2011-07-28 21:57:55 +0000 | [diff] [blame] | 5857 | // ARM mode 'blx' need special handling, as the register operand version |
| 5858 | // is predicable, but the label operand version is not. So, we can't rely |
| 5859 | // on the Mnemonic based checking to correctly figure out when to put |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 5860 | // a k_CondCode operand in the list. If we're trying to match the label |
| 5861 | // version, remove the k_CondCode operand here. |
Jim Grosbach | a03ab0e | 2011-07-28 21:57:55 +0000 | [diff] [blame] | 5862 | if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5863 | static_cast<ARMOperand &>(*Operands[2]).isImm()) |
Jim Grosbach | a03ab0e | 2011-07-28 21:57:55 +0000 | [diff] [blame] | 5864 | Operands.erase(Operands.begin() + 1); |
Jim Grosbach | 8cffa28 | 2011-08-11 23:51:13 +0000 | [diff] [blame] | 5865 | |
Weiming Zhao | 8f56f88 | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 5866 | // Adjust operands of ldrexd/strexd to MCK_GPRPair. |
| 5867 | // ldrexd/strexd require even/odd GPR pair. To enforce this constraint, |
| 5868 | // a single GPRPair reg operand is used in the .td file to replace the two |
| 5869 | // GPRs. However, when parsing from asm, the two GRPs cannot be automatically |
| 5870 | // expressed as a GPRPair, so we have to manually merge them. |
| 5871 | // FIXME: We would really like to be able to tablegen'erate this. |
| 5872 | if (!isThumb() && Operands.size() > 4 && |
Joey Gouly | e6d165c | 2013-08-27 17:38:16 +0000 | [diff] [blame] | 5873 | (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" || |
| 5874 | Mnemonic == "stlexd")) { |
| 5875 | bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd"); |
Weiming Zhao | 8f56f88 | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 5876 | unsigned Idx = isLoad ? 2 : 3; |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5877 | ARMOperand &Op1 = static_cast<ARMOperand &>(*Operands[Idx]); |
| 5878 | ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[Idx + 1]); |
Weiming Zhao | 8f56f88 | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 5879 | |
| 5880 | const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID); |
| 5881 | // Adjust only if Op1 and Op2 are GPRs. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5882 | if (Op1.isReg() && Op2.isReg() && MRC.contains(Op1.getReg()) && |
| 5883 | MRC.contains(Op2.getReg())) { |
| 5884 | unsigned Reg1 = Op1.getReg(); |
| 5885 | unsigned Reg2 = Op2.getReg(); |
Weiming Zhao | 8f56f88 | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 5886 | unsigned Rt = MRI->getEncodingValue(Reg1); |
| 5887 | unsigned Rt2 = MRI->getEncodingValue(Reg2); |
| 5888 | |
| 5889 | // Rt2 must be Rt + 1 and Rt must be even. |
| 5890 | if (Rt + 1 != Rt2 || (Rt & 1)) { |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5891 | Error(Op2.getStartLoc(), isLoad |
| 5892 | ? "destination operands must be sequential" |
| 5893 | : "source operands must be sequential"); |
Weiming Zhao | 8f56f88 | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 5894 | return true; |
| 5895 | } |
| 5896 | unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0, |
| 5897 | &(MRI->getRegClass(ARM::GPRPairRegClassID))); |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5898 | Operands[Idx] = |
| 5899 | ARMOperand::CreateReg(NewReg, Op1.getStartLoc(), Op2.getEndLoc()); |
| 5900 | Operands.erase(Operands.begin() + Idx + 1); |
Weiming Zhao | 8f56f88 | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 5901 | } |
| 5902 | } |
| 5903 | |
Renato Golin | 36c626e | 2014-09-26 16:14:29 +0000 | [diff] [blame] | 5904 | // If first 2 operands of a 3 operand instruction are the same |
| 5905 | // then transform to 2 operand version of the same instruction |
| 5906 | // e.g. 'adds r0, r0, #1' transforms to 'adds r0, #1' |
| 5907 | // FIXME: We would really like to be able to tablegen'erate this. |
| 5908 | if (isThumbOne() && Operands.size() == 6 && |
| 5909 | (Mnemonic == "add" || Mnemonic == "sub" || Mnemonic == "and" || |
| 5910 | Mnemonic == "eor" || Mnemonic == "lsl" || Mnemonic == "lsr" || |
| 5911 | Mnemonic == "asr" || Mnemonic == "adc" || Mnemonic == "sbc" || |
| 5912 | Mnemonic == "ror" || Mnemonic == "orr" || Mnemonic == "bic")) { |
| 5913 | ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]); |
| 5914 | ARMOperand &Op4 = static_cast<ARMOperand &>(*Operands[4]); |
| 5915 | ARMOperand &Op5 = static_cast<ARMOperand &>(*Operands[5]); |
| 5916 | |
| 5917 | // If both registers are the same then remove one of them from |
| 5918 | // the operand list. |
| 5919 | if (Op3.isReg() && Op4.isReg() && Op3.getReg() == Op4.getReg()) { |
| 5920 | // If 3rd operand (variable Op5) is a register and the instruction is adds/sub |
| 5921 | // then do not transform as the backend already handles this instruction |
| 5922 | // correctly. |
| 5923 | if (!Op5.isReg() || !((Mnemonic == "add" && CarrySetting) || Mnemonic == "sub")) { |
| 5924 | Operands.erase(Operands.begin() + 3); |
| 5925 | if (Mnemonic == "add" && !CarrySetting) { |
| 5926 | // Special case for 'add' (not 'adds') instruction must |
| 5927 | // remove the CCOut operand as well. |
| 5928 | Operands.erase(Operands.begin() + 1); |
| 5929 | } |
| 5930 | } |
| 5931 | } |
| 5932 | } |
| 5933 | |
| 5934 | // If instruction is 'add' and first two register operands |
| 5935 | // use SP register, then remove one of the SP registers from |
| 5936 | // the instruction. |
| 5937 | // FIXME: We would really like to be able to tablegen'erate this. |
| 5938 | if (isThumbOne() && Operands.size() == 5 && Mnemonic == "add" && !CarrySetting) { |
| 5939 | ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[2]); |
| 5940 | ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]); |
| 5941 | if (Op2.isReg() && Op3.isReg() && Op2.getReg() == ARM::SP && Op3.getReg() == ARM::SP) { |
| 5942 | Operands.erase(Operands.begin() + 2); |
| 5943 | } |
| 5944 | } |
| 5945 | |
Saleem Abdulrasool | e6e6d71 | 2014-01-10 04:38:35 +0000 | [diff] [blame] | 5946 | // GNU Assembler extension (compatibility) |
Stepan Dyatkovskiy | 3f1fa3d | 2014-04-04 10:17:56 +0000 | [diff] [blame] | 5947 | if ((Mnemonic == "ldrd" || Mnemonic == "strd")) { |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5948 | ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[2]); |
| 5949 | ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]); |
| 5950 | if (Op3.isMem()) { |
| 5951 | assert(Op2.isReg() && "expected register argument"); |
Stepan Dyatkovskiy | 6207a4d | 2014-04-03 11:29:15 +0000 | [diff] [blame] | 5952 | |
Stepan Dyatkovskiy | 3f1fa3d | 2014-04-04 10:17:56 +0000 | [diff] [blame] | 5953 | unsigned SuperReg = MRI->getMatchingSuperReg( |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5954 | Op2.getReg(), ARM::gsub_0, &MRI->getRegClass(ARM::GPRPairRegClassID)); |
Stepan Dyatkovskiy | 6207a4d | 2014-04-03 11:29:15 +0000 | [diff] [blame] | 5955 | |
Stepan Dyatkovskiy | 3f1fa3d | 2014-04-04 10:17:56 +0000 | [diff] [blame] | 5956 | assert(SuperReg && "expected register pair"); |
Stepan Dyatkovskiy | 6207a4d | 2014-04-03 11:29:15 +0000 | [diff] [blame] | 5957 | |
Stepan Dyatkovskiy | 3f1fa3d | 2014-04-04 10:17:56 +0000 | [diff] [blame] | 5958 | unsigned PairedReg = MRI->getSubReg(SuperReg, ARM::gsub_1); |
Stepan Dyatkovskiy | 6207a4d | 2014-04-03 11:29:15 +0000 | [diff] [blame] | 5959 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5960 | Operands.insert( |
| 5961 | Operands.begin() + 3, |
| 5962 | ARMOperand::CreateReg(PairedReg, Op2.getStartLoc(), Op2.getEndLoc())); |
Stepan Dyatkovskiy | 3f1fa3d | 2014-04-04 10:17:56 +0000 | [diff] [blame] | 5963 | } |
Saleem Abdulrasool | e6e6d71 | 2014-01-10 04:38:35 +0000 | [diff] [blame] | 5964 | } |
| 5965 | |
Kevin Enderby | 78f9572 | 2013-07-31 21:05:30 +0000 | [diff] [blame] | 5966 | // FIXME: As said above, this is all a pretty gross hack. This instruction |
| 5967 | // does not fit with other "subs" and tblgen. |
| 5968 | // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction |
| 5969 | // so the Mnemonic is the original name "subs" and delete the predicate |
| 5970 | // operand so it will match the table entry. |
| 5971 | if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5972 | static_cast<ARMOperand &>(*Operands[3]).isReg() && |
| 5973 | static_cast<ARMOperand &>(*Operands[3]).getReg() == ARM::PC && |
| 5974 | static_cast<ARMOperand &>(*Operands[4]).isReg() && |
| 5975 | static_cast<ARMOperand &>(*Operands[4]).getReg() == ARM::LR && |
| 5976 | static_cast<ARMOperand &>(*Operands[5]).isImm()) { |
| 5977 | Operands.front() = ARMOperand::CreateToken(Name, NameLoc); |
Kevin Enderby | 78f9572 | 2013-07-31 21:05:30 +0000 | [diff] [blame] | 5978 | Operands.erase(Operands.begin() + 1); |
Kevin Enderby | 78f9572 | 2013-07-31 21:05:30 +0000 | [diff] [blame] | 5979 | } |
Chris Lattner | f29c0b6 | 2010-01-14 22:21:20 +0000 | [diff] [blame] | 5980 | return false; |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 5981 | } |
| 5982 | |
Jim Grosbach | edaa35a | 2011-07-26 18:25:39 +0000 | [diff] [blame] | 5983 | // Validate context-sensitive operand constraints. |
Jim Grosbach | 169b2be | 2011-08-23 18:13:04 +0000 | [diff] [blame] | 5984 | |
| 5985 | // return 'true' if register list contains non-low GPR registers, |
| 5986 | // 'false' otherwise. If Reg is in the register list or is HiReg, set |
| 5987 | // 'containsReg' to true. |
| 5988 | static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg, |
| 5989 | unsigned HiReg, bool &containsReg) { |
| 5990 | containsReg = false; |
| 5991 | for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) { |
| 5992 | unsigned OpReg = Inst.getOperand(i).getReg(); |
| 5993 | if (OpReg == Reg) |
| 5994 | containsReg = true; |
| 5995 | // Anything other than a low register isn't legal here. |
| 5996 | if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg)) |
| 5997 | return true; |
| 5998 | } |
| 5999 | return false; |
| 6000 | } |
| 6001 | |
Rafael Espindola | 5403da4 | 2014-12-04 14:10:20 +0000 | [diff] [blame] | 6002 | // Check if the specified regisgter is in the register list of the inst, |
Jim Grosbach | a31f223 | 2011-09-07 18:05:34 +0000 | [diff] [blame] | 6003 | // starting at the indicated operand number. |
Rafael Espindola | 5403da4 | 2014-12-04 14:10:20 +0000 | [diff] [blame] | 6004 | static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) { |
Jim Grosbach | a31f223 | 2011-09-07 18:05:34 +0000 | [diff] [blame] | 6005 | for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) { |
| 6006 | unsigned OpReg = Inst.getOperand(i).getReg(); |
Rafael Espindola | 5403da4 | 2014-12-04 14:10:20 +0000 | [diff] [blame] | 6007 | if (OpReg == Reg) |
| 6008 | return true; |
Jim Grosbach | a31f223 | 2011-09-07 18:05:34 +0000 | [diff] [blame] | 6009 | } |
| 6010 | return false; |
| 6011 | } |
| 6012 | |
Richard Barton | 8d519fe | 2013-09-05 14:14:19 +0000 | [diff] [blame] | 6013 | // Return true if instruction has the interesting property of being |
| 6014 | // allowed in IT blocks, but not being predicable. |
| 6015 | static bool instIsBreakpoint(const MCInst &Inst) { |
| 6016 | return Inst.getOpcode() == ARM::tBKPT || |
| 6017 | Inst.getOpcode() == ARM::BKPT || |
| 6018 | Inst.getOpcode() == ARM::tHLT || |
| 6019 | Inst.getOpcode() == ARM::HLT; |
| 6020 | |
| 6021 | } |
| 6022 | |
Jim Grosbach | edaa35a | 2011-07-26 18:25:39 +0000 | [diff] [blame] | 6023 | // FIXME: We would really like to be able to tablegen'erate this. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 6024 | bool ARMAsmParser::validateInstruction(MCInst &Inst, |
| 6025 | const OperandVector &Operands) { |
Joey Gouly | 0e76fa7 | 2013-09-12 10:28:05 +0000 | [diff] [blame] | 6026 | const MCInstrDesc &MCID = MII.get(Inst.getOpcode()); |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 6027 | SMLoc Loc = Operands[0]->getStartLoc(); |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 6028 | |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 6029 | // Check the IT block state first. |
Richard Barton | 8d519fe | 2013-09-05 14:14:19 +0000 | [diff] [blame] | 6030 | // NOTE: BKPT and HLT instructions have the interesting property of being |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 6031 | // allowed in IT blocks, but not being predicable. They just always execute. |
Richard Barton | 8d519fe | 2013-09-05 14:14:19 +0000 | [diff] [blame] | 6032 | if (inITBlock() && !instIsBreakpoint(Inst)) { |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 6033 | unsigned Bit = 1; |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 6034 | if (ITState.FirstCond) |
| 6035 | ITState.FirstCond = false; |
| 6036 | else |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 6037 | Bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1; |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 6038 | // The instruction must be predicable. |
| 6039 | if (!MCID.isPredicable()) |
| 6040 | return Error(Loc, "instructions in IT block must be predicable"); |
| 6041 | unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm(); |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 6042 | unsigned ITCond = Bit ? ITState.Cond : |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 6043 | ARMCC::getOppositeCondition(ITState.Cond); |
| 6044 | if (Cond != ITCond) { |
| 6045 | // Find the condition code Operand to get its SMLoc information. |
| 6046 | SMLoc CondLoc; |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 6047 | for (unsigned I = 1; I < Operands.size(); ++I) |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 6048 | if (static_cast<ARMOperand &>(*Operands[I]).isCondCode()) |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 6049 | CondLoc = Operands[I]->getStartLoc(); |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 6050 | return Error(CondLoc, "incorrect condition in IT block; got '" + |
| 6051 | StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) + |
| 6052 | "', but expected '" + |
| 6053 | ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'"); |
| 6054 | } |
Jim Grosbach | c61fc8f | 2011-08-31 18:29:05 +0000 | [diff] [blame] | 6055 | // Check for non-'al' condition codes outside of the IT block. |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 6056 | } else if (isThumbTwo() && MCID.isPredicable() && |
| 6057 | Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() != |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 6058 | ARMCC::AL && Inst.getOpcode() != ARM::tBcc && |
| 6059 | Inst.getOpcode() != ARM::t2Bcc) |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 6060 | return Error(Loc, "predicated instructions must be in IT block"); |
| 6061 | |
Tilmann Scheller | 255722b | 2013-09-30 16:11:48 +0000 | [diff] [blame] | 6062 | const unsigned Opcode = Inst.getOpcode(); |
| 6063 | switch (Opcode) { |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 6064 | case ARM::LDRD: |
| 6065 | case ARM::LDRD_PRE: |
Weiming Zhao | 8f56f88 | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 6066 | case ARM::LDRD_POST: { |
Tilmann Scheller | 255722b | 2013-09-30 16:11:48 +0000 | [diff] [blame] | 6067 | const unsigned RtReg = Inst.getOperand(0).getReg(); |
| 6068 | |
Tilmann Scheller | 1aebfa0 | 2013-09-27 13:28:17 +0000 | [diff] [blame] | 6069 | // Rt can't be R14. |
| 6070 | if (RtReg == ARM::LR) |
| 6071 | return Error(Operands[3]->getStartLoc(), |
| 6072 | "Rt can't be R14"); |
Tilmann Scheller | 255722b | 2013-09-30 16:11:48 +0000 | [diff] [blame] | 6073 | |
| 6074 | const unsigned Rt = MRI->getEncodingValue(RtReg); |
Tilmann Scheller | 1aebfa0 | 2013-09-27 13:28:17 +0000 | [diff] [blame] | 6075 | // Rt must be even-numbered. |
| 6076 | if ((Rt & 1) == 1) |
| 6077 | return Error(Operands[3]->getStartLoc(), |
| 6078 | "Rt must be even-numbered"); |
Tilmann Scheller | 255722b | 2013-09-30 16:11:48 +0000 | [diff] [blame] | 6079 | |
Jim Grosbach | edaa35a | 2011-07-26 18:25:39 +0000 | [diff] [blame] | 6080 | // Rt2 must be Rt + 1. |
Tilmann Scheller | 255722b | 2013-09-30 16:11:48 +0000 | [diff] [blame] | 6081 | const unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg()); |
Jim Grosbach | edaa35a | 2011-07-26 18:25:39 +0000 | [diff] [blame] | 6082 | if (Rt2 != Rt + 1) |
| 6083 | return Error(Operands[3]->getStartLoc(), |
| 6084 | "destination operands must be sequential"); |
Tilmann Scheller | 255722b | 2013-09-30 16:11:48 +0000 | [diff] [blame] | 6085 | |
| 6086 | if (Opcode == ARM::LDRD_PRE || Opcode == ARM::LDRD_POST) { |
| 6087 | const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg()); |
| 6088 | // For addressing modes with writeback, the base register needs to be |
| 6089 | // different from the destination registers. |
| 6090 | if (Rn == Rt || Rn == Rt2) |
| 6091 | return Error(Operands[3]->getStartLoc(), |
| 6092 | "base register needs to be different from destination " |
| 6093 | "registers"); |
| 6094 | } |
| 6095 | |
Jim Grosbach | edaa35a | 2011-07-26 18:25:39 +0000 | [diff] [blame] | 6096 | return false; |
| 6097 | } |
Tilmann Scheller | 88c8f16 | 2013-09-27 10:30:18 +0000 | [diff] [blame] | 6098 | case ARM::t2LDRDi8: |
| 6099 | case ARM::t2LDRD_PRE: |
| 6100 | case ARM::t2LDRD_POST: { |
Tilmann Scheller | 041f717 | 2013-09-27 10:38:11 +0000 | [diff] [blame] | 6101 | // Rt2 must be different from Rt. |
Tilmann Scheller | 88c8f16 | 2013-09-27 10:30:18 +0000 | [diff] [blame] | 6102 | unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg()); |
| 6103 | unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg()); |
| 6104 | if (Rt2 == Rt) |
| 6105 | return Error(Operands[3]->getStartLoc(), |
| 6106 | "destination operands can't be identical"); |
| 6107 | return false; |
| 6108 | } |
Jim Grosbach | eb09f49 | 2011-08-11 20:28:23 +0000 | [diff] [blame] | 6109 | case ARM::STRD: { |
| 6110 | // Rt2 must be Rt + 1. |
Eric Christopher | 6ac277c | 2012-08-09 22:10:21 +0000 | [diff] [blame] | 6111 | unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg()); |
| 6112 | unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg()); |
Jim Grosbach | eb09f49 | 2011-08-11 20:28:23 +0000 | [diff] [blame] | 6113 | if (Rt2 != Rt + 1) |
| 6114 | return Error(Operands[3]->getStartLoc(), |
| 6115 | "source operands must be sequential"); |
| 6116 | return false; |
| 6117 | } |
Jim Grosbach | f7164b2 | 2011-08-10 20:49:18 +0000 | [diff] [blame] | 6118 | case ARM::STRD_PRE: |
Weiming Zhao | 8f56f88 | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 6119 | case ARM::STRD_POST: { |
Jim Grosbach | edaa35a | 2011-07-26 18:25:39 +0000 | [diff] [blame] | 6120 | // Rt2 must be Rt + 1. |
Eric Christopher | 6ac277c | 2012-08-09 22:10:21 +0000 | [diff] [blame] | 6121 | unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg()); |
| 6122 | unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg()); |
Jim Grosbach | edaa35a | 2011-07-26 18:25:39 +0000 | [diff] [blame] | 6123 | if (Rt2 != Rt + 1) |
Jim Grosbach | eb09f49 | 2011-08-11 20:28:23 +0000 | [diff] [blame] | 6124 | return Error(Operands[3]->getStartLoc(), |
Jim Grosbach | edaa35a | 2011-07-26 18:25:39 +0000 | [diff] [blame] | 6125 | "source operands must be sequential"); |
| 6126 | return false; |
| 6127 | } |
Tilmann Scheller | 3352a58 | 2014-07-23 12:38:17 +0000 | [diff] [blame] | 6128 | case ARM::STR_PRE_IMM: |
| 6129 | case ARM::STR_PRE_REG: |
| 6130 | case ARM::STR_POST_IMM: |
Tilmann Scheller | 2727279 | 2014-07-23 13:03:47 +0000 | [diff] [blame] | 6131 | case ARM::STR_POST_REG: |
Tilmann Scheller | 96ef72e | 2014-07-24 09:55:46 +0000 | [diff] [blame] | 6132 | case ARM::STRH_PRE: |
| 6133 | case ARM::STRH_POST: |
Tilmann Scheller | 2727279 | 2014-07-23 13:03:47 +0000 | [diff] [blame] | 6134 | case ARM::STRB_PRE_IMM: |
| 6135 | case ARM::STRB_PRE_REG: |
| 6136 | case ARM::STRB_POST_IMM: |
| 6137 | case ARM::STRB_POST_REG: { |
Tilmann Scheller | 3352a58 | 2014-07-23 12:38:17 +0000 | [diff] [blame] | 6138 | // Rt must be different from Rn. |
| 6139 | const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg()); |
| 6140 | const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(2).getReg()); |
| 6141 | |
| 6142 | if (Rt == Rn) |
| 6143 | return Error(Operands[3]->getStartLoc(), |
| 6144 | "source register and base register can't be identical"); |
| 6145 | return false; |
| 6146 | } |
Tilmann Scheller | 8ba7430 | 2014-08-01 11:08:51 +0000 | [diff] [blame] | 6147 | case ARM::LDR_PRE_IMM: |
| 6148 | case ARM::LDR_PRE_REG: |
| 6149 | case ARM::LDR_POST_IMM: |
Tilmann Scheller | 8ff079c | 2014-08-01 11:33:47 +0000 | [diff] [blame] | 6150 | case ARM::LDR_POST_REG: |
| 6151 | case ARM::LDRH_PRE: |
| 6152 | case ARM::LDRH_POST: |
| 6153 | case ARM::LDRSH_PRE: |
Tilmann Scheller | 7cc0ed4 | 2014-08-01 12:08:04 +0000 | [diff] [blame] | 6154 | case ARM::LDRSH_POST: |
| 6155 | case ARM::LDRB_PRE_IMM: |
| 6156 | case ARM::LDRB_PRE_REG: |
| 6157 | case ARM::LDRB_POST_IMM: |
| 6158 | case ARM::LDRB_POST_REG: |
| 6159 | case ARM::LDRSB_PRE: |
| 6160 | case ARM::LDRSB_POST: { |
Tilmann Scheller | 8ba7430 | 2014-08-01 11:08:51 +0000 | [diff] [blame] | 6161 | // Rt must be different from Rn. |
| 6162 | const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg()); |
| 6163 | const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(2).getReg()); |
| 6164 | |
| 6165 | if (Rt == Rn) |
| 6166 | return Error(Operands[3]->getStartLoc(), |
| 6167 | "destination register and base register can't be identical"); |
| 6168 | return false; |
| 6169 | } |
Jim Grosbach | 03f56d9 | 2011-07-27 21:09:25 +0000 | [diff] [blame] | 6170 | case ARM::SBFX: |
| 6171 | case ARM::UBFX: { |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 6172 | // Width must be in range [1, 32-lsb]. |
| 6173 | unsigned LSB = Inst.getOperand(2).getImm(); |
| 6174 | unsigned Widthm1 = Inst.getOperand(3).getImm(); |
| 6175 | if (Widthm1 >= 32 - LSB) |
Jim Grosbach | 03f56d9 | 2011-07-27 21:09:25 +0000 | [diff] [blame] | 6176 | return Error(Operands[5]->getStartLoc(), |
| 6177 | "bitfield width must be in range [1,32-lsb]"); |
Jim Grosbach | 64610e5 | 2011-08-16 21:42:31 +0000 | [diff] [blame] | 6178 | return false; |
Jim Grosbach | 03f56d9 | 2011-07-27 21:09:25 +0000 | [diff] [blame] | 6179 | } |
Rafael Espindola | 5403da4 | 2014-12-04 14:10:20 +0000 | [diff] [blame] | 6180 | // Notionally handles ARM::tLDMIA_UPD too. |
| 6181 | case ARM::tLDMIA: { |
| 6182 | // If we're parsing Thumb2, the .w variant is available and handles |
| 6183 | // most cases that are normally illegal for a Thumb1 LDM instruction. |
| 6184 | // We'll make the transformation in processInstruction() if necessary. |
| 6185 | // |
| 6186 | // Thumb LDM instructions are writeback iff the base register is not |
| 6187 | // in the register list. |
| 6188 | unsigned Rn = Inst.getOperand(0).getReg(); |
| 6189 | bool HasWritebackToken = |
| 6190 | (static_cast<ARMOperand &>(*Operands[3]).isToken() && |
| 6191 | static_cast<ARMOperand &>(*Operands[3]).getToken() == "!"); |
| 6192 | bool ListContainsBase; |
| 6193 | if (checkLowRegisterList(Inst, 3, Rn, 0, ListContainsBase) && !isThumbTwo()) |
| 6194 | return Error(Operands[3 + HasWritebackToken]->getStartLoc(), |
| 6195 | "registers must be in range r0-r7"); |
| 6196 | // If we should have writeback, then there should be a '!' token. |
| 6197 | if (!ListContainsBase && !HasWritebackToken && !isThumbTwo()) |
| 6198 | return Error(Operands[2]->getStartLoc(), |
| 6199 | "writeback operator '!' expected"); |
| 6200 | // If we should not have writeback, there must not be a '!'. This is |
| 6201 | // true even for the 32-bit wide encodings. |
| 6202 | if (ListContainsBase && HasWritebackToken) |
| 6203 | return Error(Operands[3]->getStartLoc(), |
| 6204 | "writeback operator '!' not allowed when base register " |
| 6205 | "in register list"); |
| 6206 | if (listContainsReg(Inst, 3 + HasWritebackToken, ARM::SP)) |
| 6207 | return Error(Operands[3 + HasWritebackToken]->getStartLoc(), |
| 6208 | "SP not allowed in register list"); |
| 6209 | break; |
| 6210 | } |
Tim Northover | 08a8660 | 2013-10-22 19:00:39 +0000 | [diff] [blame] | 6211 | case ARM::LDMIA_UPD: |
| 6212 | case ARM::LDMDB_UPD: |
| 6213 | case ARM::LDMIB_UPD: |
| 6214 | case ARM::LDMDA_UPD: |
| 6215 | // ARM variants loading and updating the same register are only officially |
| 6216 | // UNPREDICTABLE on v7 upwards. Goodness knows what they did before. |
| 6217 | if (!hasV7Ops()) |
| 6218 | break; |
Rafael Espindola | 5403da4 | 2014-12-04 14:10:20 +0000 | [diff] [blame] | 6219 | if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg())) |
| 6220 | return Error(Operands.back()->getStartLoc(), |
| 6221 | "writeback register not allowed in register list"); |
| 6222 | break; |
Jyoti Allur | 3b68607 | 2014-10-22 10:41:14 +0000 | [diff] [blame] | 6223 | case ARM::t2LDMIA: |
| 6224 | case ARM::t2LDMDB: |
| 6225 | case ARM::t2STMIA: |
Rafael Espindola | 5403da4 | 2014-12-04 14:10:20 +0000 | [diff] [blame] | 6226 | case ARM::t2STMDB: { |
| 6227 | if (listContainsReg(Inst, 3, ARM::SP)) |
| 6228 | return Error(Operands.back()->getStartLoc(), |
| 6229 | "SP not allowed in register list"); |
| 6230 | break; |
| 6231 | } |
Tim Northover | 08a8660 | 2013-10-22 19:00:39 +0000 | [diff] [blame] | 6232 | case ARM::t2LDMIA_UPD: |
| 6233 | case ARM::t2LDMDB_UPD: |
| 6234 | case ARM::t2STMIA_UPD: |
Rafael Espindola | 5403da4 | 2014-12-04 14:10:20 +0000 | [diff] [blame] | 6235 | case ARM::t2STMDB_UPD: { |
| 6236 | if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg())) |
| 6237 | return Error(Operands.back()->getStartLoc(), |
| 6238 | "writeback register not allowed in register list"); |
| 6239 | |
| 6240 | if (listContainsReg(Inst, 4, ARM::SP)) |
| 6241 | return Error(Operands.back()->getStartLoc(), |
| 6242 | "SP not allowed in register list"); |
| 6243 | break; |
| 6244 | } |
Tim Northover | 8eaf154 | 2013-11-12 21:32:41 +0000 | [diff] [blame] | 6245 | case ARM::sysLDMIA_UPD: |
| 6246 | case ARM::sysLDMDA_UPD: |
| 6247 | case ARM::sysLDMDB_UPD: |
Rafael Espindola | 5403da4 | 2014-12-04 14:10:20 +0000 | [diff] [blame] | 6248 | case ARM::sysLDMIB_UPD: |
| 6249 | if (!listContainsReg(Inst, 3, ARM::PC)) |
| 6250 | return Error(Operands[4]->getStartLoc(), |
| 6251 | "writeback register only allowed on system LDM " |
| 6252 | "if PC in register-list"); |
Tim Northover | 8eaf154 | 2013-11-12 21:32:41 +0000 | [diff] [blame] | 6253 | break; |
| 6254 | case ARM::sysSTMIA_UPD: |
| 6255 | case ARM::sysSTMDA_UPD: |
| 6256 | case ARM::sysSTMDB_UPD: |
| 6257 | case ARM::sysSTMIB_UPD: |
| 6258 | return Error(Operands[2]->getStartLoc(), |
| 6259 | "system STM cannot have writeback register"); |
Chad Rosier | 8513ffb | 2012-08-30 23:20:38 +0000 | [diff] [blame] | 6260 | case ARM::tMUL: { |
| 6261 | // The second source operand must be the same register as the destination |
| 6262 | // operand. |
Chad Rosier | 9d1fc36 | 2012-08-31 17:24:10 +0000 | [diff] [blame] | 6263 | // |
| 6264 | // In this case, we must directly check the parsed operands because the |
| 6265 | // cvtThumbMultiply() function is written in such a way that it guarantees |
| 6266 | // this first statement is always true for the new Inst. Essentially, the |
| 6267 | // destination is unconditionally copied into the second source operand |
| 6268 | // without checking to see if it matches what we actually parsed. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 6269 | if (Operands.size() == 6 && (((ARMOperand &)*Operands[3]).getReg() != |
| 6270 | ((ARMOperand &)*Operands[5]).getReg()) && |
| 6271 | (((ARMOperand &)*Operands[3]).getReg() != |
| 6272 | ((ARMOperand &)*Operands[4]).getReg())) { |
Chad Rosier | db482ef | 2012-08-30 23:22:05 +0000 | [diff] [blame] | 6273 | return Error(Operands[3]->getStartLoc(), |
| 6274 | "destination register must match source register"); |
Chad Rosier | 8513ffb | 2012-08-30 23:20:38 +0000 | [diff] [blame] | 6275 | } |
| 6276 | break; |
| 6277 | } |
Jim Grosbach | 9bded9d | 2011-11-10 23:17:11 +0000 | [diff] [blame] | 6278 | // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2, |
| 6279 | // so only issue a diagnostic for thumb1. The instructions will be |
| 6280 | // switched to the t2 encodings in processInstruction() if necessary. |
Rafael Espindola | 5403da4 | 2014-12-04 14:10:20 +0000 | [diff] [blame] | 6281 | case ARM::tPOP: { |
| 6282 | bool ListContainsBase; |
| 6283 | if (checkLowRegisterList(Inst, 2, 0, ARM::PC, ListContainsBase) && |
| 6284 | !isThumbTwo()) |
| 6285 | return Error(Operands[2]->getStartLoc(), |
| 6286 | "registers must be in range r0-r7 or pc"); |
| 6287 | break; |
| 6288 | } |
Jim Grosbach | 38c59fc | 2011-08-22 23:17:34 +0000 | [diff] [blame] | 6289 | case ARM::tPUSH: { |
Rafael Espindola | 5403da4 | 2014-12-04 14:10:20 +0000 | [diff] [blame] | 6290 | bool ListContainsBase; |
| 6291 | if (checkLowRegisterList(Inst, 2, 0, ARM::LR, ListContainsBase) && |
| 6292 | !isThumbTwo()) |
| 6293 | return Error(Operands[2]->getStartLoc(), |
| 6294 | "registers must be in range r0-r7 or lr"); |
Jim Grosbach | 38c59fc | 2011-08-22 23:17:34 +0000 | [diff] [blame] | 6295 | break; |
| 6296 | } |
Jim Grosbach | d80d169 | 2011-08-23 18:15:37 +0000 | [diff] [blame] | 6297 | case ARM::tSTMIA_UPD: { |
Rafael Espindola | 5403da4 | 2014-12-04 14:10:20 +0000 | [diff] [blame] | 6298 | bool ListContainsBase, InvalidLowList; |
| 6299 | InvalidLowList = checkLowRegisterList(Inst, 4, Inst.getOperand(0).getReg(), |
| 6300 | 0, ListContainsBase); |
| 6301 | if (InvalidLowList && !isThumbTwo()) |
| 6302 | return Error(Operands[4]->getStartLoc(), |
| 6303 | "registers must be in range r0-r7"); |
| 6304 | |
| 6305 | // This would be converted to a 32-bit stm, but that's not valid if the |
| 6306 | // writeback register is in the list. |
| 6307 | if (InvalidLowList && ListContainsBase) |
| 6308 | return Error(Operands[4]->getStartLoc(), |
| 6309 | "writeback operator '!' not allowed when base register " |
| 6310 | "in register list"); |
| 6311 | if (listContainsReg(Inst, 4, ARM::SP) && !inITBlock()) |
| 6312 | return Error(Operands.back()->getStartLoc(), |
| 6313 | "SP not allowed in register list"); |
Jim Grosbach | d80d169 | 2011-08-23 18:15:37 +0000 | [diff] [blame] | 6314 | break; |
| 6315 | } |
Jim Grosbach | c6f32b3 | 2012-04-27 23:51:36 +0000 | [diff] [blame] | 6316 | case ARM::tADDrSP: { |
| 6317 | // If the non-SP source operand and the destination operand are not the |
| 6318 | // same, we need thumb2 (for the wide encoding), or we have an error. |
| 6319 | if (!isThumbTwo() && |
| 6320 | Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) { |
| 6321 | return Error(Operands[4]->getStartLoc(), |
| 6322 | "source register must be the same as destination"); |
| 6323 | } |
| 6324 | break; |
| 6325 | } |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 6326 | // Final range checking for Thumb unconditional branch instructions. |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 6327 | case ARM::tB: |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 6328 | if (!(static_cast<ARMOperand &>(*Operands[2])).isSignedOffset<11, 1>()) |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 6329 | return Error(Operands[2]->getStartLoc(), "branch target out of range"); |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 6330 | break; |
| 6331 | case ARM::t2B: { |
| 6332 | int op = (Operands[2]->isImm()) ? 2 : 3; |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 6333 | if (!static_cast<ARMOperand &>(*Operands[op]).isSignedOffset<24, 1>()) |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 6334 | return Error(Operands[op]->getStartLoc(), "branch target out of range"); |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 6335 | break; |
| 6336 | } |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 6337 | // Final range checking for Thumb conditional branch instructions. |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 6338 | case ARM::tBcc: |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 6339 | if (!static_cast<ARMOperand &>(*Operands[2]).isSignedOffset<8, 1>()) |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 6340 | return Error(Operands[2]->getStartLoc(), "branch target out of range"); |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 6341 | break; |
| 6342 | case ARM::t2Bcc: { |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 6343 | int Op = (Operands[2]->isImm()) ? 2 : 3; |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 6344 | if (!static_cast<ARMOperand &>(*Operands[Op]).isSignedOffset<20, 1>()) |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 6345 | return Error(Operands[Op]->getStartLoc(), "branch target out of range"); |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 6346 | break; |
| 6347 | } |
Kevin Enderby | b7e51f6 | 2014-04-18 23:06:39 +0000 | [diff] [blame] | 6348 | case ARM::MOVi16: |
| 6349 | case ARM::t2MOVi16: |
| 6350 | case ARM::t2MOVTi16: |
| 6351 | { |
| 6352 | // We want to avoid misleadingly allowing something like "mov r0, <symbol>" |
| 6353 | // especially when we turn it into a movw and the expression <symbol> does |
| 6354 | // not have a :lower16: or :upper16 as part of the expression. We don't |
| 6355 | // want the behavior of silently truncating, which can be unexpected and |
| 6356 | // lead to bugs that are difficult to find since this is an easy mistake |
| 6357 | // to make. |
| 6358 | int i = (Operands[3]->isImm()) ? 3 : 4; |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 6359 | ARMOperand &Op = static_cast<ARMOperand &>(*Operands[i]); |
| 6360 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm()); |
Kevin Enderby | b7e51f6 | 2014-04-18 23:06:39 +0000 | [diff] [blame] | 6361 | if (CE) break; |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 6362 | const MCExpr *E = dyn_cast<MCExpr>(Op.getImm()); |
Kevin Enderby | b7e51f6 | 2014-04-18 23:06:39 +0000 | [diff] [blame] | 6363 | if (!E) break; |
| 6364 | const ARMMCExpr *ARM16Expr = dyn_cast<ARMMCExpr>(E); |
| 6365 | if (!ARM16Expr || (ARM16Expr->getKind() != ARMMCExpr::VK_ARM_HI16 && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 6366 | ARM16Expr->getKind() != ARMMCExpr::VK_ARM_LO16)) |
| 6367 | return Error( |
| 6368 | Op.getStartLoc(), |
| 6369 | "immediate expression for mov requires :lower16: or :upper16"); |
| 6370 | break; |
| 6371 | } |
Jim Grosbach | edaa35a | 2011-07-26 18:25:39 +0000 | [diff] [blame] | 6372 | } |
| 6373 | |
| 6374 | return false; |
| 6375 | } |
| 6376 | |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6377 | static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) { |
Jim Grosbach | eb53822 | 2011-12-02 22:34:51 +0000 | [diff] [blame] | 6378 | switch(Opc) { |
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 6379 | default: llvm_unreachable("unexpected opcode!"); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6380 | // VST1LN |
Jim Grosbach | 1e946a4 | 2012-01-24 00:43:12 +0000 | [diff] [blame] | 6381 | case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD; |
| 6382 | case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD; |
| 6383 | case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD; |
| 6384 | case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD; |
| 6385 | case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD; |
| 6386 | case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD; |
| 6387 | case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8; |
| 6388 | case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16; |
| 6389 | case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32; |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6390 | |
| 6391 | // VST2LN |
Jim Grosbach | 1e946a4 | 2012-01-24 00:43:12 +0000 | [diff] [blame] | 6392 | case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD; |
| 6393 | case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD; |
| 6394 | case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD; |
| 6395 | case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD; |
| 6396 | case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD; |
Jim Grosbach | 2c59052 | 2011-12-20 20:46:29 +0000 | [diff] [blame] | 6397 | |
Jim Grosbach | 1e946a4 | 2012-01-24 00:43:12 +0000 | [diff] [blame] | 6398 | case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD; |
| 6399 | case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD; |
| 6400 | case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD; |
| 6401 | case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD; |
| 6402 | case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD; |
Jim Grosbach | 2c59052 | 2011-12-20 20:46:29 +0000 | [diff] [blame] | 6403 | |
Jim Grosbach | 1e946a4 | 2012-01-24 00:43:12 +0000 | [diff] [blame] | 6404 | case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8; |
| 6405 | case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16; |
| 6406 | case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32; |
| 6407 | case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16; |
| 6408 | case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6409 | |
Jim Grosbach | d3d36d9 | 2012-01-24 00:07:41 +0000 | [diff] [blame] | 6410 | // VST3LN |
Jim Grosbach | 1e946a4 | 2012-01-24 00:43:12 +0000 | [diff] [blame] | 6411 | case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD; |
| 6412 | case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD; |
| 6413 | case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD; |
| 6414 | case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD; |
| 6415 | case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD; |
| 6416 | case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD; |
| 6417 | case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD; |
| 6418 | case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD; |
| 6419 | case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD; |
| 6420 | case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD; |
| 6421 | case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8; |
| 6422 | case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16; |
| 6423 | case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32; |
| 6424 | case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16; |
| 6425 | case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32; |
Jim Grosbach | d3d36d9 | 2012-01-24 00:07:41 +0000 | [diff] [blame] | 6426 | |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6427 | // VST3 |
Jim Grosbach | 1e946a4 | 2012-01-24 00:43:12 +0000 | [diff] [blame] | 6428 | case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD; |
| 6429 | case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD; |
| 6430 | case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD; |
| 6431 | case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD; |
| 6432 | case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD; |
| 6433 | case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD; |
| 6434 | case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD; |
| 6435 | case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD; |
| 6436 | case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD; |
| 6437 | case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD; |
| 6438 | case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD; |
| 6439 | case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD; |
| 6440 | case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8; |
| 6441 | case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16; |
| 6442 | case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32; |
| 6443 | case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8; |
| 6444 | case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16; |
| 6445 | case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32; |
Jim Grosbach | da70eac | 2012-01-24 00:58:13 +0000 | [diff] [blame] | 6446 | |
Jim Grosbach | 8e2722c | 2012-01-24 18:53:13 +0000 | [diff] [blame] | 6447 | // VST4LN |
| 6448 | case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD; |
| 6449 | case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD; |
| 6450 | case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD; |
| 6451 | case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD; |
| 6452 | case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD; |
| 6453 | case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD; |
| 6454 | case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD; |
| 6455 | case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD; |
| 6456 | case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD; |
| 6457 | case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD; |
| 6458 | case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8; |
| 6459 | case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16; |
| 6460 | case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32; |
| 6461 | case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16; |
| 6462 | case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32; |
| 6463 | |
Jim Grosbach | da70eac | 2012-01-24 00:58:13 +0000 | [diff] [blame] | 6464 | // VST4 |
| 6465 | case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD; |
| 6466 | case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD; |
| 6467 | case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD; |
| 6468 | case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD; |
| 6469 | case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD; |
| 6470 | case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD; |
| 6471 | case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD; |
| 6472 | case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD; |
| 6473 | case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD; |
| 6474 | case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD; |
| 6475 | case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD; |
| 6476 | case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD; |
| 6477 | case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8; |
| 6478 | case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16; |
| 6479 | case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32; |
| 6480 | case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8; |
| 6481 | case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16; |
| 6482 | case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32; |
Jim Grosbach | eb53822 | 2011-12-02 22:34:51 +0000 | [diff] [blame] | 6483 | } |
| 6484 | } |
| 6485 | |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6486 | static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) { |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 6487 | switch(Opc) { |
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 6488 | default: llvm_unreachable("unexpected opcode!"); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6489 | // VLD1LN |
Jim Grosbach | 1e946a4 | 2012-01-24 00:43:12 +0000 | [diff] [blame] | 6490 | case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD; |
| 6491 | case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD; |
| 6492 | case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD; |
| 6493 | case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD; |
| 6494 | case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD; |
| 6495 | case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD; |
| 6496 | case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8; |
| 6497 | case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16; |
| 6498 | case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32; |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6499 | |
| 6500 | // VLD2LN |
Jim Grosbach | 1e946a4 | 2012-01-24 00:43:12 +0000 | [diff] [blame] | 6501 | case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD; |
| 6502 | case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD; |
| 6503 | case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD; |
| 6504 | case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD; |
| 6505 | case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD; |
| 6506 | case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD; |
| 6507 | case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD; |
| 6508 | case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD; |
| 6509 | case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD; |
| 6510 | case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD; |
| 6511 | case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8; |
| 6512 | case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16; |
| 6513 | case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32; |
| 6514 | case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16; |
| 6515 | case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32; |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 6516 | |
Jim Grosbach | b78403c | 2012-01-24 23:47:04 +0000 | [diff] [blame] | 6517 | // VLD3DUP |
| 6518 | case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD; |
| 6519 | case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD; |
| 6520 | case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD; |
| 6521 | case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD; |
Kevin Enderby | d88fec3 | 2014-04-08 18:00:52 +0000 | [diff] [blame] | 6522 | case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD; |
Jim Grosbach | b78403c | 2012-01-24 23:47:04 +0000 | [diff] [blame] | 6523 | case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD; |
| 6524 | case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD; |
| 6525 | case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD; |
| 6526 | case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD; |
| 6527 | case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD; |
| 6528 | case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD; |
| 6529 | case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD; |
| 6530 | case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8; |
| 6531 | case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16; |
| 6532 | case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32; |
| 6533 | case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8; |
| 6534 | case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16; |
| 6535 | case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32; |
| 6536 | |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 6537 | // VLD3LN |
Jim Grosbach | 1e946a4 | 2012-01-24 00:43:12 +0000 | [diff] [blame] | 6538 | case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD; |
| 6539 | case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD; |
| 6540 | case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD; |
| 6541 | case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD; |
| 6542 | case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD; |
| 6543 | case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD; |
| 6544 | case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD; |
| 6545 | case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD; |
| 6546 | case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD; |
| 6547 | case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD; |
| 6548 | case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8; |
| 6549 | case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16; |
| 6550 | case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32; |
| 6551 | case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16; |
| 6552 | case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32; |
Jim Grosbach | ac2af3f | 2012-01-23 23:20:46 +0000 | [diff] [blame] | 6553 | |
| 6554 | // VLD3 |
Jim Grosbach | 1e946a4 | 2012-01-24 00:43:12 +0000 | [diff] [blame] | 6555 | case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD; |
| 6556 | case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD; |
| 6557 | case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD; |
| 6558 | case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD; |
| 6559 | case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD; |
| 6560 | case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD; |
| 6561 | case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD; |
| 6562 | case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD; |
| 6563 | case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD; |
| 6564 | case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD; |
| 6565 | case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD; |
| 6566 | case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD; |
| 6567 | case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8; |
| 6568 | case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16; |
| 6569 | case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32; |
| 6570 | case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8; |
| 6571 | case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16; |
| 6572 | case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32; |
Jim Grosbach | ed561fc | 2012-01-24 00:43:17 +0000 | [diff] [blame] | 6573 | |
Jim Grosbach | 14952a0 | 2012-01-24 18:37:25 +0000 | [diff] [blame] | 6574 | // VLD4LN |
| 6575 | case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD; |
| 6576 | case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD; |
| 6577 | case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD; |
Kevin Enderby | 8108f38 | 2014-03-26 19:35:40 +0000 | [diff] [blame] | 6578 | case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD; |
Jim Grosbach | 14952a0 | 2012-01-24 18:37:25 +0000 | [diff] [blame] | 6579 | case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD; |
| 6580 | case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD; |
| 6581 | case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD; |
| 6582 | case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD; |
| 6583 | case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD; |
| 6584 | case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD; |
| 6585 | case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8; |
| 6586 | case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16; |
| 6587 | case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32; |
| 6588 | case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16; |
| 6589 | case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32; |
| 6590 | |
Jim Grosbach | 086cbfa | 2012-01-25 00:01:08 +0000 | [diff] [blame] | 6591 | // VLD4DUP |
| 6592 | case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD; |
| 6593 | case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD; |
| 6594 | case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD; |
| 6595 | case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD; |
| 6596 | case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD; |
| 6597 | case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD; |
| 6598 | case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD; |
| 6599 | case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD; |
| 6600 | case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD; |
| 6601 | case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD; |
| 6602 | case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD; |
| 6603 | case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD; |
| 6604 | case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8; |
| 6605 | case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16; |
| 6606 | case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32; |
| 6607 | case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8; |
| 6608 | case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16; |
| 6609 | case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32; |
| 6610 | |
Jim Grosbach | ed561fc | 2012-01-24 00:43:17 +0000 | [diff] [blame] | 6611 | // VLD4 |
| 6612 | case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD; |
| 6613 | case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD; |
| 6614 | case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD; |
| 6615 | case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD; |
| 6616 | case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD; |
| 6617 | case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD; |
| 6618 | case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD; |
| 6619 | case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD; |
| 6620 | case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD; |
| 6621 | case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD; |
| 6622 | case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD; |
| 6623 | case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD; |
| 6624 | case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8; |
| 6625 | case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16; |
| 6626 | case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32; |
| 6627 | case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8; |
| 6628 | case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16; |
| 6629 | case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 6630 | } |
| 6631 | } |
| 6632 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 6633 | bool ARMAsmParser::processInstruction(MCInst &Inst, |
Joerg Sonnenberger | 02b13a8 | 2014-11-21 22:39:34 +0000 | [diff] [blame] | 6634 | const OperandVector &Operands, |
| 6635 | MCStreamer &Out) { |
Jim Grosbach | 8ba76c6 | 2011-08-11 17:35:48 +0000 | [diff] [blame] | 6636 | switch (Inst.getOpcode()) { |
Saleem Abdulrasool | fb3950e | 2014-01-12 04:36:01 +0000 | [diff] [blame] | 6637 | // Alias for alternate form of 'ldr{,b}t Rt, [Rn], #imm' instruction. |
| 6638 | case ARM::LDRT_POST: |
| 6639 | case ARM::LDRBT_POST: { |
| 6640 | const unsigned Opcode = |
| 6641 | (Inst.getOpcode() == ARM::LDRT_POST) ? ARM::LDRT_POST_IMM |
| 6642 | : ARM::LDRBT_POST_IMM; |
| 6643 | MCInst TmpInst; |
| 6644 | TmpInst.setOpcode(Opcode); |
| 6645 | TmpInst.addOperand(Inst.getOperand(0)); |
| 6646 | TmpInst.addOperand(Inst.getOperand(1)); |
| 6647 | TmpInst.addOperand(Inst.getOperand(1)); |
| 6648 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 6649 | TmpInst.addOperand(MCOperand::CreateImm(0)); |
| 6650 | TmpInst.addOperand(Inst.getOperand(2)); |
| 6651 | TmpInst.addOperand(Inst.getOperand(3)); |
| 6652 | Inst = TmpInst; |
| 6653 | return true; |
| 6654 | } |
| 6655 | // Alias for alternate form of 'str{,b}t Rt, [Rn], #imm' instruction. |
| 6656 | case ARM::STRT_POST: |
| 6657 | case ARM::STRBT_POST: { |
| 6658 | const unsigned Opcode = |
| 6659 | (Inst.getOpcode() == ARM::STRT_POST) ? ARM::STRT_POST_IMM |
| 6660 | : ARM::STRBT_POST_IMM; |
| 6661 | MCInst TmpInst; |
| 6662 | TmpInst.setOpcode(Opcode); |
| 6663 | TmpInst.addOperand(Inst.getOperand(1)); |
| 6664 | TmpInst.addOperand(Inst.getOperand(0)); |
| 6665 | TmpInst.addOperand(Inst.getOperand(1)); |
| 6666 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 6667 | TmpInst.addOperand(MCOperand::CreateImm(0)); |
| 6668 | TmpInst.addOperand(Inst.getOperand(2)); |
| 6669 | TmpInst.addOperand(Inst.getOperand(3)); |
| 6670 | Inst = TmpInst; |
| 6671 | return true; |
| 6672 | } |
Jim Grosbach | e974a6a | 2012-09-25 00:08:13 +0000 | [diff] [blame] | 6673 | // Alias for alternate form of 'ADR Rd, #imm' instruction. |
| 6674 | case ARM::ADDri: { |
| 6675 | if (Inst.getOperand(1).getReg() != ARM::PC || |
Joerg Sonnenberger | 02b13a8 | 2014-11-21 22:39:34 +0000 | [diff] [blame] | 6676 | Inst.getOperand(5).getReg() != 0 || |
| 6677 | !(Inst.getOperand(2).isExpr() || Inst.getOperand(2).isImm())) |
Jim Grosbach | e974a6a | 2012-09-25 00:08:13 +0000 | [diff] [blame] | 6678 | return false; |
| 6679 | MCInst TmpInst; |
| 6680 | TmpInst.setOpcode(ARM::ADR); |
| 6681 | TmpInst.addOperand(Inst.getOperand(0)); |
Joerg Sonnenberger | 02b13a8 | 2014-11-21 22:39:34 +0000 | [diff] [blame] | 6682 | if (Inst.getOperand(2).isImm()) { |
| 6683 | TmpInst.addOperand(Inst.getOperand(2)); |
| 6684 | } else { |
| 6685 | // Turn PC-relative expression into absolute expression. |
| 6686 | // Reading PC provides the start of the current instruction + 8 and |
| 6687 | // the transform to adr is biased by that. |
| 6688 | MCSymbol *Dot = getContext().CreateTempSymbol(); |
| 6689 | Out.EmitLabel(Dot); |
| 6690 | const MCExpr *OpExpr = Inst.getOperand(2).getExpr(); |
| 6691 | const MCExpr *InstPC = MCSymbolRefExpr::Create(Dot, |
| 6692 | MCSymbolRefExpr::VK_None, |
| 6693 | getContext()); |
| 6694 | const MCExpr *Const8 = MCConstantExpr::Create(8, getContext()); |
| 6695 | const MCExpr *ReadPC = MCBinaryExpr::CreateAdd(InstPC, Const8, |
| 6696 | getContext()); |
| 6697 | const MCExpr *FixupAddr = MCBinaryExpr::CreateAdd(ReadPC, OpExpr, |
| 6698 | getContext()); |
| 6699 | TmpInst.addOperand(MCOperand::CreateExpr(FixupAddr)); |
| 6700 | } |
Jim Grosbach | e974a6a | 2012-09-25 00:08:13 +0000 | [diff] [blame] | 6701 | TmpInst.addOperand(Inst.getOperand(3)); |
| 6702 | TmpInst.addOperand(Inst.getOperand(4)); |
| 6703 | Inst = TmpInst; |
| 6704 | return true; |
| 6705 | } |
Jim Grosbach | 94298a9 | 2012-01-18 22:46:46 +0000 | [diff] [blame] | 6706 | // Aliases for alternate PC+imm syntax of LDR instructions. |
| 6707 | case ARM::t2LDRpcrel: |
Kevin Enderby | 06aa3eb8 | 2012-12-14 23:04:25 +0000 | [diff] [blame] | 6708 | // Select the narrow version if the immediate will fit. |
| 6709 | if (Inst.getOperand(1).getImm() > 0 && |
Amaury de la Vieuville | eac0bad | 2013-06-18 08:13:05 +0000 | [diff] [blame] | 6710 | Inst.getOperand(1).getImm() <= 0xff && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 6711 | !(static_cast<ARMOperand &>(*Operands[2]).isToken() && |
| 6712 | static_cast<ARMOperand &>(*Operands[2]).getToken() == ".w")) |
Kevin Enderby | 06aa3eb8 | 2012-12-14 23:04:25 +0000 | [diff] [blame] | 6713 | Inst.setOpcode(ARM::tLDRpci); |
| 6714 | else |
| 6715 | Inst.setOpcode(ARM::t2LDRpci); |
Jim Grosbach | 94298a9 | 2012-01-18 22:46:46 +0000 | [diff] [blame] | 6716 | return true; |
| 6717 | case ARM::t2LDRBpcrel: |
| 6718 | Inst.setOpcode(ARM::t2LDRBpci); |
| 6719 | return true; |
| 6720 | case ARM::t2LDRHpcrel: |
| 6721 | Inst.setOpcode(ARM::t2LDRHpci); |
| 6722 | return true; |
| 6723 | case ARM::t2LDRSBpcrel: |
| 6724 | Inst.setOpcode(ARM::t2LDRSBpci); |
| 6725 | return true; |
| 6726 | case ARM::t2LDRSHpcrel: |
| 6727 | Inst.setOpcode(ARM::t2LDRSHpci); |
| 6728 | return true; |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6729 | // Handle NEON VST complex aliases. |
Jim Grosbach | d28ef9a | 2012-01-23 19:39:08 +0000 | [diff] [blame] | 6730 | case ARM::VST1LNdWB_register_Asm_8: |
| 6731 | case ARM::VST1LNdWB_register_Asm_16: |
| 6732 | case ARM::VST1LNdWB_register_Asm_32: { |
Jim Grosbach | eb53822 | 2011-12-02 22:34:51 +0000 | [diff] [blame] | 6733 | MCInst TmpInst; |
| 6734 | // Shuffle the operands around so the lane index operand is in the |
| 6735 | // right place. |
Jim Grosbach | 2c59052 | 2011-12-20 20:46:29 +0000 | [diff] [blame] | 6736 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6737 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | eb53822 | 2011-12-02 22:34:51 +0000 | [diff] [blame] | 6738 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6739 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6740 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6741 | TmpInst.addOperand(Inst.getOperand(4)); // Rm |
| 6742 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6743 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6744 | TmpInst.addOperand(Inst.getOperand(5)); // CondCode |
| 6745 | TmpInst.addOperand(Inst.getOperand(6)); |
| 6746 | Inst = TmpInst; |
| 6747 | return true; |
| 6748 | } |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6749 | |
Jim Grosbach | d28ef9a | 2012-01-23 19:39:08 +0000 | [diff] [blame] | 6750 | case ARM::VST2LNdWB_register_Asm_8: |
| 6751 | case ARM::VST2LNdWB_register_Asm_16: |
| 6752 | case ARM::VST2LNdWB_register_Asm_32: |
| 6753 | case ARM::VST2LNqWB_register_Asm_16: |
| 6754 | case ARM::VST2LNqWB_register_Asm_32: { |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6755 | MCInst TmpInst; |
| 6756 | // Shuffle the operands around so the lane index operand is in the |
| 6757 | // right place. |
Jim Grosbach | 2c59052 | 2011-12-20 20:46:29 +0000 | [diff] [blame] | 6758 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6759 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +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(Inst.getOperand(4)); // Rm |
| 6764 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
Jim Grosbach | 2c59052 | 2011-12-20 20:46:29 +0000 | [diff] [blame] | 6765 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6766 | Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6767 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6768 | TmpInst.addOperand(Inst.getOperand(5)); // CondCode |
| 6769 | TmpInst.addOperand(Inst.getOperand(6)); |
| 6770 | Inst = TmpInst; |
| 6771 | return true; |
| 6772 | } |
Jim Grosbach | d3d36d9 | 2012-01-24 00:07:41 +0000 | [diff] [blame] | 6773 | |
| 6774 | case ARM::VST3LNdWB_register_Asm_8: |
| 6775 | case ARM::VST3LNdWB_register_Asm_16: |
| 6776 | case ARM::VST3LNdWB_register_Asm_32: |
| 6777 | case ARM::VST3LNqWB_register_Asm_16: |
| 6778 | case ARM::VST3LNqWB_register_Asm_32: { |
| 6779 | MCInst TmpInst; |
| 6780 | // Shuffle the operands around so the lane index operand is in the |
| 6781 | // right place. |
| 6782 | unsigned Spacing; |
| 6783 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
| 6784 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6785 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6786 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6787 | TmpInst.addOperand(Inst.getOperand(4)); // Rm |
| 6788 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6789 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6790 | Spacing)); |
| 6791 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6792 | Spacing * 2)); |
| 6793 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6794 | TmpInst.addOperand(Inst.getOperand(5)); // CondCode |
| 6795 | TmpInst.addOperand(Inst.getOperand(6)); |
| 6796 | Inst = TmpInst; |
| 6797 | return true; |
| 6798 | } |
| 6799 | |
Jim Grosbach | 8e2722c | 2012-01-24 18:53:13 +0000 | [diff] [blame] | 6800 | case ARM::VST4LNdWB_register_Asm_8: |
| 6801 | case ARM::VST4LNdWB_register_Asm_16: |
| 6802 | case ARM::VST4LNdWB_register_Asm_32: |
| 6803 | case ARM::VST4LNqWB_register_Asm_16: |
| 6804 | case ARM::VST4LNqWB_register_Asm_32: { |
| 6805 | MCInst TmpInst; |
| 6806 | // Shuffle the operands around so the lane index operand is in the |
| 6807 | // right place. |
| 6808 | unsigned Spacing; |
| 6809 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
| 6810 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6811 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6812 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6813 | TmpInst.addOperand(Inst.getOperand(4)); // Rm |
| 6814 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6815 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6816 | Spacing)); |
| 6817 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6818 | Spacing * 2)); |
| 6819 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6820 | Spacing * 3)); |
| 6821 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6822 | TmpInst.addOperand(Inst.getOperand(5)); // CondCode |
| 6823 | TmpInst.addOperand(Inst.getOperand(6)); |
| 6824 | Inst = TmpInst; |
| 6825 | return true; |
| 6826 | } |
| 6827 | |
Jim Grosbach | d28ef9a | 2012-01-23 19:39:08 +0000 | [diff] [blame] | 6828 | case ARM::VST1LNdWB_fixed_Asm_8: |
| 6829 | case ARM::VST1LNdWB_fixed_Asm_16: |
| 6830 | case ARM::VST1LNdWB_fixed_Asm_32: { |
Jim Grosbach | eb53822 | 2011-12-02 22:34:51 +0000 | [diff] [blame] | 6831 | MCInst TmpInst; |
| 6832 | // Shuffle the operands around so the lane index operand is in the |
| 6833 | // right place. |
Jim Grosbach | 2c59052 | 2011-12-20 20:46:29 +0000 | [diff] [blame] | 6834 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6835 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | eb53822 | 2011-12-02 22:34:51 +0000 | [diff] [blame] | 6836 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6837 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6838 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6839 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 6840 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6841 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6842 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 6843 | TmpInst.addOperand(Inst.getOperand(5)); |
| 6844 | Inst = TmpInst; |
| 6845 | return true; |
| 6846 | } |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6847 | |
Jim Grosbach | d28ef9a | 2012-01-23 19:39:08 +0000 | [diff] [blame] | 6848 | case ARM::VST2LNdWB_fixed_Asm_8: |
| 6849 | case ARM::VST2LNdWB_fixed_Asm_16: |
| 6850 | case ARM::VST2LNdWB_fixed_Asm_32: |
| 6851 | case ARM::VST2LNqWB_fixed_Asm_16: |
| 6852 | case ARM::VST2LNqWB_fixed_Asm_32: { |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6853 | MCInst TmpInst; |
| 6854 | // Shuffle the operands around so the lane index operand is in the |
| 6855 | // right place. |
Jim Grosbach | 2c59052 | 2011-12-20 20:46:29 +0000 | [diff] [blame] | 6856 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6857 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6858 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6859 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6860 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6861 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 6862 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
Jim Grosbach | 2c59052 | 2011-12-20 20:46:29 +0000 | [diff] [blame] | 6863 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6864 | Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6865 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6866 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 6867 | TmpInst.addOperand(Inst.getOperand(5)); |
| 6868 | Inst = TmpInst; |
| 6869 | return true; |
| 6870 | } |
Jim Grosbach | d3d36d9 | 2012-01-24 00:07:41 +0000 | [diff] [blame] | 6871 | |
| 6872 | case ARM::VST3LNdWB_fixed_Asm_8: |
| 6873 | case ARM::VST3LNdWB_fixed_Asm_16: |
| 6874 | case ARM::VST3LNdWB_fixed_Asm_32: |
| 6875 | case ARM::VST3LNqWB_fixed_Asm_16: |
| 6876 | case ARM::VST3LNqWB_fixed_Asm_32: { |
| 6877 | MCInst TmpInst; |
| 6878 | // Shuffle the operands around so the lane index operand is in the |
| 6879 | // right place. |
| 6880 | unsigned Spacing; |
| 6881 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
| 6882 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6883 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6884 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6885 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 6886 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6887 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6888 | Spacing)); |
| 6889 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6890 | Spacing * 2)); |
| 6891 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6892 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 6893 | TmpInst.addOperand(Inst.getOperand(5)); |
| 6894 | Inst = TmpInst; |
| 6895 | return true; |
| 6896 | } |
| 6897 | |
Jim Grosbach | 8e2722c | 2012-01-24 18:53:13 +0000 | [diff] [blame] | 6898 | case ARM::VST4LNdWB_fixed_Asm_8: |
| 6899 | case ARM::VST4LNdWB_fixed_Asm_16: |
| 6900 | case ARM::VST4LNdWB_fixed_Asm_32: |
| 6901 | case ARM::VST4LNqWB_fixed_Asm_16: |
| 6902 | case ARM::VST4LNqWB_fixed_Asm_32: { |
| 6903 | MCInst TmpInst; |
| 6904 | // Shuffle the operands around so the lane index operand is in the |
| 6905 | // right place. |
| 6906 | unsigned Spacing; |
| 6907 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
| 6908 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6909 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6910 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6911 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 6912 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6913 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6914 | Spacing)); |
| 6915 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6916 | Spacing * 2)); |
| 6917 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6918 | Spacing * 3)); |
| 6919 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6920 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 6921 | TmpInst.addOperand(Inst.getOperand(5)); |
| 6922 | Inst = TmpInst; |
| 6923 | return true; |
| 6924 | } |
| 6925 | |
Jim Grosbach | d28ef9a | 2012-01-23 19:39:08 +0000 | [diff] [blame] | 6926 | case ARM::VST1LNdAsm_8: |
| 6927 | case ARM::VST1LNdAsm_16: |
| 6928 | case ARM::VST1LNdAsm_32: { |
Jim Grosbach | eb53822 | 2011-12-02 22:34:51 +0000 | [diff] [blame] | 6929 | MCInst TmpInst; |
| 6930 | // Shuffle the operands around so the lane index operand is in the |
| 6931 | // right place. |
Jim Grosbach | 2c59052 | 2011-12-20 20:46:29 +0000 | [diff] [blame] | 6932 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6933 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | eb53822 | 2011-12-02 22:34:51 +0000 | [diff] [blame] | 6934 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6935 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6936 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6937 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6938 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 6939 | TmpInst.addOperand(Inst.getOperand(5)); |
| 6940 | Inst = TmpInst; |
| 6941 | return true; |
| 6942 | } |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6943 | |
Jim Grosbach | d28ef9a | 2012-01-23 19:39:08 +0000 | [diff] [blame] | 6944 | case ARM::VST2LNdAsm_8: |
| 6945 | case ARM::VST2LNdAsm_16: |
| 6946 | case ARM::VST2LNdAsm_32: |
| 6947 | case ARM::VST2LNqAsm_16: |
| 6948 | case ARM::VST2LNqAsm_32: { |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6949 | MCInst TmpInst; |
| 6950 | // Shuffle the operands around so the lane index operand is in the |
| 6951 | // right place. |
Jim Grosbach | 2c59052 | 2011-12-20 20:46:29 +0000 | [diff] [blame] | 6952 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6953 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6954 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6955 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6956 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
Jim Grosbach | 2c59052 | 2011-12-20 20:46:29 +0000 | [diff] [blame] | 6957 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6958 | Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6959 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6960 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 6961 | TmpInst.addOperand(Inst.getOperand(5)); |
| 6962 | Inst = TmpInst; |
| 6963 | return true; |
| 6964 | } |
Jim Grosbach | d3d36d9 | 2012-01-24 00:07:41 +0000 | [diff] [blame] | 6965 | |
| 6966 | case ARM::VST3LNdAsm_8: |
| 6967 | case ARM::VST3LNdAsm_16: |
| 6968 | case ARM::VST3LNdAsm_32: |
| 6969 | case ARM::VST3LNqAsm_16: |
| 6970 | case ARM::VST3LNqAsm_32: { |
| 6971 | MCInst TmpInst; |
| 6972 | // Shuffle the operands around so the lane index operand is in the |
| 6973 | // right place. |
| 6974 | unsigned Spacing; |
| 6975 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
| 6976 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6977 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6978 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6979 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6980 | Spacing)); |
| 6981 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6982 | Spacing * 2)); |
| 6983 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6984 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 6985 | TmpInst.addOperand(Inst.getOperand(5)); |
| 6986 | Inst = TmpInst; |
| 6987 | return true; |
| 6988 | } |
| 6989 | |
Jim Grosbach | 8e2722c | 2012-01-24 18:53:13 +0000 | [diff] [blame] | 6990 | case ARM::VST4LNdAsm_8: |
| 6991 | case ARM::VST4LNdAsm_16: |
| 6992 | case ARM::VST4LNdAsm_32: |
| 6993 | case ARM::VST4LNqAsm_16: |
| 6994 | case ARM::VST4LNqAsm_32: { |
| 6995 | MCInst TmpInst; |
| 6996 | // Shuffle the operands around so the lane index operand is in the |
| 6997 | // right place. |
| 6998 | unsigned Spacing; |
| 6999 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
| 7000 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 7001 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 7002 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7003 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7004 | Spacing)); |
| 7005 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7006 | Spacing * 2)); |
| 7007 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7008 | Spacing * 3)); |
| 7009 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 7010 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 7011 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7012 | Inst = TmpInst; |
| 7013 | return true; |
| 7014 | } |
| 7015 | |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 7016 | // Handle NEON VLD complex aliases. |
Jim Grosbach | d28ef9a | 2012-01-23 19:39:08 +0000 | [diff] [blame] | 7017 | case ARM::VLD1LNdWB_register_Asm_8: |
| 7018 | case ARM::VLD1LNdWB_register_Asm_16: |
| 7019 | case ARM::VLD1LNdWB_register_Asm_32: { |
Jim Grosbach | dda976b | 2011-12-02 22:01:52 +0000 | [diff] [blame] | 7020 | MCInst TmpInst; |
| 7021 | // Shuffle the operands around so the lane index operand is in the |
| 7022 | // right place. |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 7023 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 7024 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | dda976b | 2011-12-02 22:01:52 +0000 | [diff] [blame] | 7025 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7026 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 7027 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 7028 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 7029 | TmpInst.addOperand(Inst.getOperand(4)); // Rm |
| 7030 | TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) |
| 7031 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 7032 | TmpInst.addOperand(Inst.getOperand(5)); // CondCode |
| 7033 | TmpInst.addOperand(Inst.getOperand(6)); |
| 7034 | Inst = TmpInst; |
| 7035 | return true; |
| 7036 | } |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 7037 | |
Jim Grosbach | d28ef9a | 2012-01-23 19:39:08 +0000 | [diff] [blame] | 7038 | case ARM::VLD2LNdWB_register_Asm_8: |
| 7039 | case ARM::VLD2LNdWB_register_Asm_16: |
| 7040 | case ARM::VLD2LNdWB_register_Asm_32: |
| 7041 | case ARM::VLD2LNqWB_register_Asm_16: |
| 7042 | case ARM::VLD2LNqWB_register_Asm_32: { |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 7043 | MCInst TmpInst; |
| 7044 | // Shuffle the operands around so the lane index operand is in the |
| 7045 | // right place. |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 7046 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 7047 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 7048 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 7049 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7050 | Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 7051 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 7052 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 7053 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 7054 | TmpInst.addOperand(Inst.getOperand(4)); // Rm |
| 7055 | TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 7056 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7057 | Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 7058 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 7059 | TmpInst.addOperand(Inst.getOperand(5)); // CondCode |
| 7060 | TmpInst.addOperand(Inst.getOperand(6)); |
| 7061 | Inst = TmpInst; |
| 7062 | return true; |
| 7063 | } |
| 7064 | |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 7065 | case ARM::VLD3LNdWB_register_Asm_8: |
| 7066 | case ARM::VLD3LNdWB_register_Asm_16: |
| 7067 | case ARM::VLD3LNdWB_register_Asm_32: |
| 7068 | case ARM::VLD3LNqWB_register_Asm_16: |
| 7069 | case ARM::VLD3LNqWB_register_Asm_32: { |
| 7070 | MCInst TmpInst; |
| 7071 | // Shuffle the operands around so the lane index operand is in the |
| 7072 | // right place. |
| 7073 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 7074 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 7075 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7076 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7077 | Spacing)); |
| 7078 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
Jim Grosbach | ac2af3f | 2012-01-23 23:20:46 +0000 | [diff] [blame] | 7079 | Spacing * 2)); |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 7080 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 7081 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 7082 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 7083 | TmpInst.addOperand(Inst.getOperand(4)); // Rm |
| 7084 | TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) |
| 7085 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7086 | Spacing)); |
| 7087 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
Jim Grosbach | ac2af3f | 2012-01-23 23:20:46 +0000 | [diff] [blame] | 7088 | Spacing * 2)); |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 7089 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 7090 | TmpInst.addOperand(Inst.getOperand(5)); // CondCode |
| 7091 | TmpInst.addOperand(Inst.getOperand(6)); |
| 7092 | Inst = TmpInst; |
| 7093 | return true; |
| 7094 | } |
| 7095 | |
Jim Grosbach | 14952a0 | 2012-01-24 18:37:25 +0000 | [diff] [blame] | 7096 | case ARM::VLD4LNdWB_register_Asm_8: |
| 7097 | case ARM::VLD4LNdWB_register_Asm_16: |
| 7098 | case ARM::VLD4LNdWB_register_Asm_32: |
| 7099 | case ARM::VLD4LNqWB_register_Asm_16: |
| 7100 | case ARM::VLD4LNqWB_register_Asm_32: { |
| 7101 | MCInst TmpInst; |
| 7102 | // Shuffle the operands around so the lane index operand is in the |
| 7103 | // right place. |
| 7104 | unsigned Spacing; |
| 7105 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
| 7106 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7107 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7108 | Spacing)); |
| 7109 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7110 | Spacing * 2)); |
| 7111 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7112 | Spacing * 3)); |
| 7113 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 7114 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 7115 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 7116 | TmpInst.addOperand(Inst.getOperand(4)); // Rm |
| 7117 | TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) |
| 7118 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7119 | Spacing)); |
| 7120 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7121 | Spacing * 2)); |
| 7122 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7123 | Spacing * 3)); |
| 7124 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 7125 | TmpInst.addOperand(Inst.getOperand(5)); // CondCode |
| 7126 | TmpInst.addOperand(Inst.getOperand(6)); |
| 7127 | Inst = TmpInst; |
| 7128 | return true; |
| 7129 | } |
| 7130 | |
Jim Grosbach | d28ef9a | 2012-01-23 19:39:08 +0000 | [diff] [blame] | 7131 | case ARM::VLD1LNdWB_fixed_Asm_8: |
| 7132 | case ARM::VLD1LNdWB_fixed_Asm_16: |
| 7133 | case ARM::VLD1LNdWB_fixed_Asm_32: { |
Jim Grosbach | dda976b | 2011-12-02 22:01:52 +0000 | [diff] [blame] | 7134 | MCInst TmpInst; |
| 7135 | // Shuffle the operands around so the lane index operand is in the |
| 7136 | // right place. |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 7137 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 7138 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | dda976b | 2011-12-02 22:01:52 +0000 | [diff] [blame] | 7139 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7140 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 7141 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 7142 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 7143 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 7144 | TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) |
| 7145 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 7146 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 7147 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7148 | Inst = TmpInst; |
| 7149 | return true; |
| 7150 | } |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 7151 | |
Jim Grosbach | d28ef9a | 2012-01-23 19:39:08 +0000 | [diff] [blame] | 7152 | case ARM::VLD2LNdWB_fixed_Asm_8: |
| 7153 | case ARM::VLD2LNdWB_fixed_Asm_16: |
| 7154 | case ARM::VLD2LNdWB_fixed_Asm_32: |
| 7155 | case ARM::VLD2LNqWB_fixed_Asm_16: |
| 7156 | case ARM::VLD2LNqWB_fixed_Asm_32: { |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 7157 | MCInst TmpInst; |
| 7158 | // Shuffle the operands around so the lane index operand is in the |
| 7159 | // right place. |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 7160 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 7161 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 7162 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 7163 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7164 | Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 7165 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 7166 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 7167 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 7168 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 7169 | TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 7170 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7171 | Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 7172 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 7173 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 7174 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7175 | Inst = TmpInst; |
| 7176 | return true; |
| 7177 | } |
| 7178 | |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 7179 | case ARM::VLD3LNdWB_fixed_Asm_8: |
| 7180 | case ARM::VLD3LNdWB_fixed_Asm_16: |
| 7181 | case ARM::VLD3LNdWB_fixed_Asm_32: |
| 7182 | case ARM::VLD3LNqWB_fixed_Asm_16: |
| 7183 | case ARM::VLD3LNqWB_fixed_Asm_32: { |
| 7184 | MCInst TmpInst; |
| 7185 | // Shuffle the operands around so the lane index operand is in the |
| 7186 | // right place. |
| 7187 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 7188 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 7189 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7190 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7191 | Spacing)); |
| 7192 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
Jim Grosbach | ac2af3f | 2012-01-23 23:20:46 +0000 | [diff] [blame] | 7193 | Spacing * 2)); |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 7194 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 7195 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 7196 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 7197 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 7198 | TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) |
| 7199 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7200 | Spacing)); |
| 7201 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
Jim Grosbach | ac2af3f | 2012-01-23 23:20:46 +0000 | [diff] [blame] | 7202 | Spacing * 2)); |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 7203 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 7204 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 7205 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7206 | Inst = TmpInst; |
| 7207 | return true; |
| 7208 | } |
| 7209 | |
Jim Grosbach | 14952a0 | 2012-01-24 18:37:25 +0000 | [diff] [blame] | 7210 | case ARM::VLD4LNdWB_fixed_Asm_8: |
| 7211 | case ARM::VLD4LNdWB_fixed_Asm_16: |
| 7212 | case ARM::VLD4LNdWB_fixed_Asm_32: |
| 7213 | case ARM::VLD4LNqWB_fixed_Asm_16: |
| 7214 | case ARM::VLD4LNqWB_fixed_Asm_32: { |
| 7215 | MCInst TmpInst; |
| 7216 | // Shuffle the operands around so the lane index operand is in the |
| 7217 | // right place. |
| 7218 | unsigned Spacing; |
| 7219 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
| 7220 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7221 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7222 | Spacing)); |
| 7223 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7224 | Spacing * 2)); |
| 7225 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7226 | Spacing * 3)); |
| 7227 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 7228 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 7229 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 7230 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 7231 | TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) |
| 7232 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7233 | Spacing)); |
| 7234 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7235 | Spacing * 2)); |
| 7236 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7237 | Spacing * 3)); |
| 7238 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 7239 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 7240 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7241 | Inst = TmpInst; |
| 7242 | return true; |
| 7243 | } |
| 7244 | |
Jim Grosbach | d28ef9a | 2012-01-23 19:39:08 +0000 | [diff] [blame] | 7245 | case ARM::VLD1LNdAsm_8: |
| 7246 | case ARM::VLD1LNdAsm_16: |
| 7247 | case ARM::VLD1LNdAsm_32: { |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 7248 | MCInst TmpInst; |
| 7249 | // Shuffle the operands around so the lane index operand is in the |
| 7250 | // right place. |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 7251 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 7252 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 7253 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7254 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 7255 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 7256 | TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) |
| 7257 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 7258 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 7259 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7260 | Inst = TmpInst; |
| 7261 | return true; |
| 7262 | } |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 7263 | |
Jim Grosbach | d28ef9a | 2012-01-23 19:39:08 +0000 | [diff] [blame] | 7264 | case ARM::VLD2LNdAsm_8: |
| 7265 | case ARM::VLD2LNdAsm_16: |
| 7266 | case ARM::VLD2LNdAsm_32: |
| 7267 | case ARM::VLD2LNqAsm_16: |
| 7268 | case ARM::VLD2LNqAsm_32: { |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 7269 | MCInst TmpInst; |
| 7270 | // Shuffle the operands around so the lane index operand is in the |
| 7271 | // right place. |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 7272 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 7273 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 7274 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 7275 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7276 | Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 7277 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 7278 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 7279 | TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 7280 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7281 | Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 7282 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 7283 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 7284 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7285 | Inst = TmpInst; |
| 7286 | return true; |
| 7287 | } |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 7288 | |
| 7289 | case ARM::VLD3LNdAsm_8: |
| 7290 | case ARM::VLD3LNdAsm_16: |
| 7291 | case ARM::VLD3LNdAsm_32: |
| 7292 | case ARM::VLD3LNqAsm_16: |
| 7293 | case ARM::VLD3LNqAsm_32: { |
| 7294 | MCInst TmpInst; |
| 7295 | // Shuffle the operands around so the lane index operand is in the |
| 7296 | // right place. |
| 7297 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 7298 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 7299 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7300 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7301 | Spacing)); |
| 7302 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
Jim Grosbach | ac2af3f | 2012-01-23 23:20:46 +0000 | [diff] [blame] | 7303 | Spacing * 2)); |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 7304 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 7305 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 7306 | TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) |
| 7307 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7308 | Spacing)); |
| 7309 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
Jim Grosbach | ac2af3f | 2012-01-23 23:20:46 +0000 | [diff] [blame] | 7310 | Spacing * 2)); |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 7311 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 7312 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 7313 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7314 | Inst = TmpInst; |
| 7315 | return true; |
| 7316 | } |
| 7317 | |
Jim Grosbach | 14952a0 | 2012-01-24 18:37:25 +0000 | [diff] [blame] | 7318 | case ARM::VLD4LNdAsm_8: |
| 7319 | case ARM::VLD4LNdAsm_16: |
| 7320 | case ARM::VLD4LNdAsm_32: |
| 7321 | case ARM::VLD4LNqAsm_16: |
| 7322 | case ARM::VLD4LNqAsm_32: { |
| 7323 | MCInst TmpInst; |
| 7324 | // Shuffle the operands around so the lane index operand is in the |
| 7325 | // right place. |
| 7326 | unsigned Spacing; |
| 7327 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
| 7328 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7329 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7330 | Spacing)); |
| 7331 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7332 | Spacing * 2)); |
| 7333 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7334 | Spacing * 3)); |
| 7335 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 7336 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 7337 | TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) |
| 7338 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7339 | Spacing)); |
| 7340 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7341 | Spacing * 2)); |
| 7342 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7343 | Spacing * 3)); |
| 7344 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 7345 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 7346 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7347 | Inst = TmpInst; |
| 7348 | return true; |
| 7349 | } |
| 7350 | |
Jim Grosbach | b78403c | 2012-01-24 23:47:04 +0000 | [diff] [blame] | 7351 | // VLD3DUP single 3-element structure to all lanes instructions. |
| 7352 | case ARM::VLD3DUPdAsm_8: |
| 7353 | case ARM::VLD3DUPdAsm_16: |
| 7354 | case ARM::VLD3DUPdAsm_32: |
| 7355 | case ARM::VLD3DUPqAsm_8: |
| 7356 | case ARM::VLD3DUPqAsm_16: |
| 7357 | case ARM::VLD3DUPqAsm_32: { |
| 7358 | MCInst TmpInst; |
| 7359 | unsigned Spacing; |
| 7360 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
| 7361 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7362 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7363 | Spacing)); |
| 7364 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7365 | Spacing * 2)); |
| 7366 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7367 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7368 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7369 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7370 | Inst = TmpInst; |
| 7371 | return true; |
| 7372 | } |
| 7373 | |
| 7374 | case ARM::VLD3DUPdWB_fixed_Asm_8: |
| 7375 | case ARM::VLD3DUPdWB_fixed_Asm_16: |
| 7376 | case ARM::VLD3DUPdWB_fixed_Asm_32: |
| 7377 | case ARM::VLD3DUPqWB_fixed_Asm_8: |
| 7378 | case ARM::VLD3DUPqWB_fixed_Asm_16: |
| 7379 | case ARM::VLD3DUPqWB_fixed_Asm_32: { |
| 7380 | MCInst TmpInst; |
| 7381 | unsigned Spacing; |
| 7382 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
| 7383 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7384 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7385 | Spacing)); |
| 7386 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7387 | Spacing * 2)); |
| 7388 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7389 | TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn |
| 7390 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7391 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 7392 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7393 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7394 | Inst = TmpInst; |
| 7395 | return true; |
| 7396 | } |
| 7397 | |
| 7398 | case ARM::VLD3DUPdWB_register_Asm_8: |
| 7399 | case ARM::VLD3DUPdWB_register_Asm_16: |
| 7400 | case ARM::VLD3DUPdWB_register_Asm_32: |
| 7401 | case ARM::VLD3DUPqWB_register_Asm_8: |
| 7402 | case ARM::VLD3DUPqWB_register_Asm_16: |
| 7403 | case ARM::VLD3DUPqWB_register_Asm_32: { |
| 7404 | MCInst TmpInst; |
| 7405 | unsigned Spacing; |
| 7406 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
| 7407 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7408 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7409 | Spacing)); |
| 7410 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7411 | Spacing * 2)); |
| 7412 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7413 | TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn |
| 7414 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7415 | TmpInst.addOperand(Inst.getOperand(3)); // Rm |
| 7416 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 7417 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7418 | Inst = TmpInst; |
| 7419 | return true; |
| 7420 | } |
| 7421 | |
Jim Grosbach | ac2af3f | 2012-01-23 23:20:46 +0000 | [diff] [blame] | 7422 | // VLD3 multiple 3-element structure instructions. |
| 7423 | case ARM::VLD3dAsm_8: |
| 7424 | case ARM::VLD3dAsm_16: |
| 7425 | case ARM::VLD3dAsm_32: |
| 7426 | case ARM::VLD3qAsm_8: |
| 7427 | case ARM::VLD3qAsm_16: |
| 7428 | case ARM::VLD3qAsm_32: { |
| 7429 | MCInst TmpInst; |
| 7430 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 7431 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | ac2af3f | 2012-01-23 23:20:46 +0000 | [diff] [blame] | 7432 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7433 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7434 | Spacing)); |
| 7435 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7436 | Spacing * 2)); |
| 7437 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7438 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7439 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7440 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7441 | Inst = TmpInst; |
| 7442 | return true; |
| 7443 | } |
| 7444 | |
| 7445 | case ARM::VLD3dWB_fixed_Asm_8: |
| 7446 | case ARM::VLD3dWB_fixed_Asm_16: |
| 7447 | case ARM::VLD3dWB_fixed_Asm_32: |
| 7448 | case ARM::VLD3qWB_fixed_Asm_8: |
| 7449 | case ARM::VLD3qWB_fixed_Asm_16: |
| 7450 | case ARM::VLD3qWB_fixed_Asm_32: { |
| 7451 | MCInst TmpInst; |
| 7452 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 7453 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | ac2af3f | 2012-01-23 23:20:46 +0000 | [diff] [blame] | 7454 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7455 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7456 | Spacing)); |
| 7457 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7458 | Spacing * 2)); |
| 7459 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7460 | TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn |
| 7461 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7462 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 7463 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7464 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7465 | Inst = TmpInst; |
| 7466 | return true; |
| 7467 | } |
| 7468 | |
| 7469 | case ARM::VLD3dWB_register_Asm_8: |
| 7470 | case ARM::VLD3dWB_register_Asm_16: |
| 7471 | case ARM::VLD3dWB_register_Asm_32: |
| 7472 | case ARM::VLD3qWB_register_Asm_8: |
| 7473 | case ARM::VLD3qWB_register_Asm_16: |
| 7474 | case ARM::VLD3qWB_register_Asm_32: { |
| 7475 | MCInst TmpInst; |
| 7476 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 7477 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | ac2af3f | 2012-01-23 23:20:46 +0000 | [diff] [blame] | 7478 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7479 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7480 | Spacing)); |
| 7481 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7482 | Spacing * 2)); |
| 7483 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7484 | TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn |
| 7485 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7486 | TmpInst.addOperand(Inst.getOperand(3)); // Rm |
| 7487 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 7488 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7489 | Inst = TmpInst; |
| 7490 | return true; |
| 7491 | } |
| 7492 | |
Jim Grosbach | 086cbfa | 2012-01-25 00:01:08 +0000 | [diff] [blame] | 7493 | // VLD4DUP single 3-element structure to all lanes instructions. |
| 7494 | case ARM::VLD4DUPdAsm_8: |
| 7495 | case ARM::VLD4DUPdAsm_16: |
| 7496 | case ARM::VLD4DUPdAsm_32: |
| 7497 | case ARM::VLD4DUPqAsm_8: |
| 7498 | case ARM::VLD4DUPqAsm_16: |
| 7499 | case ARM::VLD4DUPqAsm_32: { |
| 7500 | MCInst TmpInst; |
| 7501 | unsigned Spacing; |
| 7502 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
| 7503 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7504 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7505 | Spacing)); |
| 7506 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7507 | Spacing * 2)); |
| 7508 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7509 | Spacing * 3)); |
| 7510 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7511 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7512 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7513 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7514 | Inst = TmpInst; |
| 7515 | return true; |
| 7516 | } |
| 7517 | |
| 7518 | case ARM::VLD4DUPdWB_fixed_Asm_8: |
| 7519 | case ARM::VLD4DUPdWB_fixed_Asm_16: |
| 7520 | case ARM::VLD4DUPdWB_fixed_Asm_32: |
| 7521 | case ARM::VLD4DUPqWB_fixed_Asm_8: |
| 7522 | case ARM::VLD4DUPqWB_fixed_Asm_16: |
| 7523 | case ARM::VLD4DUPqWB_fixed_Asm_32: { |
| 7524 | MCInst TmpInst; |
| 7525 | unsigned Spacing; |
| 7526 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
| 7527 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7528 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7529 | Spacing)); |
| 7530 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7531 | Spacing * 2)); |
| 7532 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7533 | Spacing * 3)); |
| 7534 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7535 | TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn |
| 7536 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7537 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 7538 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7539 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7540 | Inst = TmpInst; |
| 7541 | return true; |
| 7542 | } |
| 7543 | |
| 7544 | case ARM::VLD4DUPdWB_register_Asm_8: |
| 7545 | case ARM::VLD4DUPdWB_register_Asm_16: |
| 7546 | case ARM::VLD4DUPdWB_register_Asm_32: |
| 7547 | case ARM::VLD4DUPqWB_register_Asm_8: |
| 7548 | case ARM::VLD4DUPqWB_register_Asm_16: |
| 7549 | case ARM::VLD4DUPqWB_register_Asm_32: { |
| 7550 | MCInst TmpInst; |
| 7551 | unsigned Spacing; |
| 7552 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
| 7553 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7554 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7555 | Spacing)); |
| 7556 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7557 | Spacing * 2)); |
| 7558 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7559 | Spacing * 3)); |
| 7560 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7561 | TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn |
| 7562 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7563 | TmpInst.addOperand(Inst.getOperand(3)); // Rm |
| 7564 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 7565 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7566 | Inst = TmpInst; |
| 7567 | return true; |
| 7568 | } |
| 7569 | |
| 7570 | // VLD4 multiple 4-element structure instructions. |
Jim Grosbach | ed561fc | 2012-01-24 00:43:17 +0000 | [diff] [blame] | 7571 | case ARM::VLD4dAsm_8: |
| 7572 | case ARM::VLD4dAsm_16: |
| 7573 | case ARM::VLD4dAsm_32: |
| 7574 | case ARM::VLD4qAsm_8: |
| 7575 | case ARM::VLD4qAsm_16: |
| 7576 | case ARM::VLD4qAsm_32: { |
| 7577 | MCInst TmpInst; |
| 7578 | unsigned Spacing; |
| 7579 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
| 7580 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7581 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7582 | Spacing)); |
| 7583 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7584 | Spacing * 2)); |
| 7585 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7586 | Spacing * 3)); |
| 7587 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7588 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7589 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7590 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7591 | Inst = TmpInst; |
| 7592 | return true; |
| 7593 | } |
| 7594 | |
| 7595 | case ARM::VLD4dWB_fixed_Asm_8: |
| 7596 | case ARM::VLD4dWB_fixed_Asm_16: |
| 7597 | case ARM::VLD4dWB_fixed_Asm_32: |
| 7598 | case ARM::VLD4qWB_fixed_Asm_8: |
| 7599 | case ARM::VLD4qWB_fixed_Asm_16: |
| 7600 | case ARM::VLD4qWB_fixed_Asm_32: { |
| 7601 | MCInst TmpInst; |
| 7602 | unsigned Spacing; |
| 7603 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
| 7604 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7605 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7606 | Spacing)); |
| 7607 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7608 | Spacing * 2)); |
| 7609 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7610 | Spacing * 3)); |
| 7611 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7612 | TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn |
| 7613 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7614 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 7615 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7616 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7617 | Inst = TmpInst; |
| 7618 | return true; |
| 7619 | } |
| 7620 | |
| 7621 | case ARM::VLD4dWB_register_Asm_8: |
| 7622 | case ARM::VLD4dWB_register_Asm_16: |
| 7623 | case ARM::VLD4dWB_register_Asm_32: |
| 7624 | case ARM::VLD4qWB_register_Asm_8: |
| 7625 | case ARM::VLD4qWB_register_Asm_16: |
| 7626 | case ARM::VLD4qWB_register_Asm_32: { |
| 7627 | MCInst TmpInst; |
| 7628 | unsigned Spacing; |
| 7629 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
| 7630 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7631 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7632 | Spacing)); |
| 7633 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7634 | Spacing * 2)); |
| 7635 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7636 | Spacing * 3)); |
| 7637 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7638 | TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn |
| 7639 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7640 | TmpInst.addOperand(Inst.getOperand(3)); // Rm |
| 7641 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 7642 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7643 | Inst = TmpInst; |
| 7644 | return true; |
| 7645 | } |
| 7646 | |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 7647 | // VST3 multiple 3-element structure instructions. |
| 7648 | case ARM::VST3dAsm_8: |
| 7649 | case ARM::VST3dAsm_16: |
| 7650 | case ARM::VST3dAsm_32: |
| 7651 | case ARM::VST3qAsm_8: |
| 7652 | case ARM::VST3qAsm_16: |
| 7653 | case ARM::VST3qAsm_32: { |
| 7654 | MCInst TmpInst; |
| 7655 | unsigned Spacing; |
| 7656 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
| 7657 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7658 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7659 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7660 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7661 | Spacing)); |
| 7662 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7663 | Spacing * 2)); |
| 7664 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7665 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7666 | Inst = TmpInst; |
| 7667 | return true; |
| 7668 | } |
| 7669 | |
| 7670 | case ARM::VST3dWB_fixed_Asm_8: |
| 7671 | case ARM::VST3dWB_fixed_Asm_16: |
| 7672 | case ARM::VST3dWB_fixed_Asm_32: |
| 7673 | case ARM::VST3qWB_fixed_Asm_8: |
| 7674 | case ARM::VST3qWB_fixed_Asm_16: |
| 7675 | case ARM::VST3qWB_fixed_Asm_32: { |
| 7676 | MCInst TmpInst; |
| 7677 | unsigned Spacing; |
| 7678 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
| 7679 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7680 | TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn |
| 7681 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7682 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 7683 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7684 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7685 | Spacing)); |
| 7686 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7687 | Spacing * 2)); |
| 7688 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7689 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7690 | Inst = TmpInst; |
| 7691 | return true; |
| 7692 | } |
| 7693 | |
| 7694 | case ARM::VST3dWB_register_Asm_8: |
| 7695 | case ARM::VST3dWB_register_Asm_16: |
| 7696 | case ARM::VST3dWB_register_Asm_32: |
| 7697 | case ARM::VST3qWB_register_Asm_8: |
| 7698 | case ARM::VST3qWB_register_Asm_16: |
| 7699 | case ARM::VST3qWB_register_Asm_32: { |
| 7700 | MCInst TmpInst; |
| 7701 | unsigned Spacing; |
| 7702 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
| 7703 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7704 | TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn |
| 7705 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7706 | TmpInst.addOperand(Inst.getOperand(3)); // Rm |
| 7707 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7708 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7709 | Spacing)); |
| 7710 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7711 | Spacing * 2)); |
| 7712 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 7713 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7714 | Inst = TmpInst; |
| 7715 | return true; |
| 7716 | } |
| 7717 | |
Jim Grosbach | da70eac | 2012-01-24 00:58:13 +0000 | [diff] [blame] | 7718 | // VST4 multiple 3-element structure instructions. |
| 7719 | case ARM::VST4dAsm_8: |
| 7720 | case ARM::VST4dAsm_16: |
| 7721 | case ARM::VST4dAsm_32: |
| 7722 | case ARM::VST4qAsm_8: |
| 7723 | case ARM::VST4qAsm_16: |
| 7724 | case ARM::VST4qAsm_32: { |
| 7725 | MCInst TmpInst; |
| 7726 | unsigned Spacing; |
| 7727 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
| 7728 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7729 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7730 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7731 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7732 | Spacing)); |
| 7733 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7734 | Spacing * 2)); |
| 7735 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7736 | Spacing * 3)); |
| 7737 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7738 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7739 | Inst = TmpInst; |
| 7740 | return true; |
| 7741 | } |
| 7742 | |
| 7743 | case ARM::VST4dWB_fixed_Asm_8: |
| 7744 | case ARM::VST4dWB_fixed_Asm_16: |
| 7745 | case ARM::VST4dWB_fixed_Asm_32: |
| 7746 | case ARM::VST4qWB_fixed_Asm_8: |
| 7747 | case ARM::VST4qWB_fixed_Asm_16: |
| 7748 | case ARM::VST4qWB_fixed_Asm_32: { |
| 7749 | MCInst TmpInst; |
| 7750 | unsigned Spacing; |
| 7751 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
| 7752 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7753 | TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn |
| 7754 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7755 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 7756 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7757 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7758 | Spacing)); |
| 7759 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7760 | Spacing * 2)); |
| 7761 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7762 | Spacing * 3)); |
| 7763 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7764 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7765 | Inst = TmpInst; |
| 7766 | return true; |
| 7767 | } |
| 7768 | |
| 7769 | case ARM::VST4dWB_register_Asm_8: |
| 7770 | case ARM::VST4dWB_register_Asm_16: |
| 7771 | case ARM::VST4dWB_register_Asm_32: |
| 7772 | case ARM::VST4qWB_register_Asm_8: |
| 7773 | case ARM::VST4qWB_register_Asm_16: |
| 7774 | case ARM::VST4qWB_register_Asm_32: { |
| 7775 | MCInst TmpInst; |
| 7776 | unsigned Spacing; |
| 7777 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
| 7778 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7779 | TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn |
| 7780 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7781 | TmpInst.addOperand(Inst.getOperand(3)); // Rm |
| 7782 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7783 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7784 | Spacing)); |
| 7785 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7786 | Spacing * 2)); |
| 7787 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7788 | Spacing * 3)); |
| 7789 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 7790 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7791 | Inst = TmpInst; |
| 7792 | return true; |
| 7793 | } |
| 7794 | |
Jim Grosbach | ad66de1 | 2012-04-11 00:15:16 +0000 | [diff] [blame] | 7795 | // Handle encoding choice for the shift-immediate instructions. |
| 7796 | case ARM::t2LSLri: |
| 7797 | case ARM::t2LSRri: |
| 7798 | case ARM::t2ASRri: { |
| 7799 | if (isARMLowRegister(Inst.getOperand(0).getReg()) && |
| 7800 | Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() && |
| 7801 | Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 7802 | !(static_cast<ARMOperand &>(*Operands[3]).isToken() && |
| 7803 | static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w")) { |
Jim Grosbach | ad66de1 | 2012-04-11 00:15:16 +0000 | [diff] [blame] | 7804 | unsigned NewOpc; |
| 7805 | switch (Inst.getOpcode()) { |
| 7806 | default: llvm_unreachable("unexpected opcode"); |
| 7807 | case ARM::t2LSLri: NewOpc = ARM::tLSLri; break; |
| 7808 | case ARM::t2LSRri: NewOpc = ARM::tLSRri; break; |
| 7809 | case ARM::t2ASRri: NewOpc = ARM::tASRri; break; |
| 7810 | } |
| 7811 | // The Thumb1 operands aren't in the same order. Awesome, eh? |
| 7812 | MCInst TmpInst; |
| 7813 | TmpInst.setOpcode(NewOpc); |
| 7814 | TmpInst.addOperand(Inst.getOperand(0)); |
| 7815 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7816 | TmpInst.addOperand(Inst.getOperand(1)); |
| 7817 | TmpInst.addOperand(Inst.getOperand(2)); |
| 7818 | TmpInst.addOperand(Inst.getOperand(3)); |
| 7819 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7820 | Inst = TmpInst; |
| 7821 | return true; |
| 7822 | } |
| 7823 | return false; |
| 7824 | } |
| 7825 | |
Jim Grosbach | 485e562 | 2011-12-13 22:45:11 +0000 | [diff] [blame] | 7826 | // Handle the Thumb2 mode MOV complex aliases. |
Jim Grosbach | b3ef713 | 2011-12-21 20:54:00 +0000 | [diff] [blame] | 7827 | case ARM::t2MOVsr: |
| 7828 | case ARM::t2MOVSsr: { |
| 7829 | // Which instruction to expand to depends on the CCOut operand and |
| 7830 | // whether we're in an IT block if the register operands are low |
| 7831 | // registers. |
| 7832 | bool isNarrow = false; |
| 7833 | if (isARMLowRegister(Inst.getOperand(0).getReg()) && |
| 7834 | isARMLowRegister(Inst.getOperand(1).getReg()) && |
| 7835 | isARMLowRegister(Inst.getOperand(2).getReg()) && |
| 7836 | Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() && |
| 7837 | inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr)) |
| 7838 | isNarrow = true; |
| 7839 | MCInst TmpInst; |
| 7840 | unsigned newOpc; |
| 7841 | switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) { |
| 7842 | default: llvm_unreachable("unexpected opcode!"); |
| 7843 | case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break; |
| 7844 | case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break; |
| 7845 | case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break; |
| 7846 | case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break; |
| 7847 | } |
| 7848 | TmpInst.setOpcode(newOpc); |
| 7849 | TmpInst.addOperand(Inst.getOperand(0)); // Rd |
| 7850 | if (isNarrow) |
| 7851 | TmpInst.addOperand(MCOperand::CreateReg( |
| 7852 | Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0)); |
| 7853 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7854 | TmpInst.addOperand(Inst.getOperand(2)); // Rm |
| 7855 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 7856 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7857 | if (!isNarrow) |
| 7858 | TmpInst.addOperand(MCOperand::CreateReg( |
| 7859 | Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0)); |
| 7860 | Inst = TmpInst; |
| 7861 | return true; |
| 7862 | } |
Jim Grosbach | 485e562 | 2011-12-13 22:45:11 +0000 | [diff] [blame] | 7863 | case ARM::t2MOVsi: |
| 7864 | case ARM::t2MOVSsi: { |
| 7865 | // Which instruction to expand to depends on the CCOut operand and |
| 7866 | // whether we're in an IT block if the register operands are low |
| 7867 | // registers. |
| 7868 | bool isNarrow = false; |
| 7869 | if (isARMLowRegister(Inst.getOperand(0).getReg()) && |
| 7870 | isARMLowRegister(Inst.getOperand(1).getReg()) && |
| 7871 | inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi)) |
| 7872 | isNarrow = true; |
| 7873 | MCInst TmpInst; |
| 7874 | unsigned newOpc; |
| 7875 | switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) { |
| 7876 | default: llvm_unreachable("unexpected opcode!"); |
| 7877 | case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break; |
| 7878 | case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break; |
| 7879 | case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break; |
| 7880 | case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break; |
Jim Grosbach | 8c59bbc | 2011-12-21 21:04:19 +0000 | [diff] [blame] | 7881 | case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break; |
Jim Grosbach | 485e562 | 2011-12-13 22:45:11 +0000 | [diff] [blame] | 7882 | } |
Benjamin Kramer | bde9176 | 2012-06-02 10:20:22 +0000 | [diff] [blame] | 7883 | unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()); |
| 7884 | if (Amount == 32) Amount = 0; |
Jim Grosbach | 485e562 | 2011-12-13 22:45:11 +0000 | [diff] [blame] | 7885 | TmpInst.setOpcode(newOpc); |
| 7886 | TmpInst.addOperand(Inst.getOperand(0)); // Rd |
| 7887 | if (isNarrow) |
| 7888 | TmpInst.addOperand(MCOperand::CreateReg( |
| 7889 | Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0)); |
| 7890 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
Jim Grosbach | 8c59bbc | 2011-12-21 21:04:19 +0000 | [diff] [blame] | 7891 | if (newOpc != ARM::t2RRX) |
Benjamin Kramer | bde9176 | 2012-06-02 10:20:22 +0000 | [diff] [blame] | 7892 | TmpInst.addOperand(MCOperand::CreateImm(Amount)); |
Jim Grosbach | 485e562 | 2011-12-13 22:45:11 +0000 | [diff] [blame] | 7893 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7894 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7895 | if (!isNarrow) |
| 7896 | TmpInst.addOperand(MCOperand::CreateReg( |
| 7897 | Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0)); |
| 7898 | Inst = TmpInst; |
| 7899 | return true; |
| 7900 | } |
| 7901 | // Handle the ARM mode MOV complex aliases. |
Jim Grosbach | abcac56 | 2011-11-16 18:31:45 +0000 | [diff] [blame] | 7902 | case ARM::ASRr: |
| 7903 | case ARM::LSRr: |
| 7904 | case ARM::LSLr: |
| 7905 | case ARM::RORr: { |
| 7906 | ARM_AM::ShiftOpc ShiftTy; |
| 7907 | switch(Inst.getOpcode()) { |
| 7908 | default: llvm_unreachable("unexpected opcode!"); |
| 7909 | case ARM::ASRr: ShiftTy = ARM_AM::asr; break; |
| 7910 | case ARM::LSRr: ShiftTy = ARM_AM::lsr; break; |
| 7911 | case ARM::LSLr: ShiftTy = ARM_AM::lsl; break; |
| 7912 | case ARM::RORr: ShiftTy = ARM_AM::ror; break; |
| 7913 | } |
Jim Grosbach | abcac56 | 2011-11-16 18:31:45 +0000 | [diff] [blame] | 7914 | unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0); |
| 7915 | MCInst TmpInst; |
| 7916 | TmpInst.setOpcode(ARM::MOVsr); |
| 7917 | TmpInst.addOperand(Inst.getOperand(0)); // Rd |
| 7918 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7919 | TmpInst.addOperand(Inst.getOperand(2)); // Rm |
| 7920 | TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty |
| 7921 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7922 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7923 | TmpInst.addOperand(Inst.getOperand(5)); // cc_out |
| 7924 | Inst = TmpInst; |
| 7925 | return true; |
| 7926 | } |
Jim Grosbach | c14871c | 2011-11-10 19:18:01 +0000 | [diff] [blame] | 7927 | case ARM::ASRi: |
| 7928 | case ARM::LSRi: |
| 7929 | case ARM::LSLi: |
| 7930 | case ARM::RORi: { |
| 7931 | ARM_AM::ShiftOpc ShiftTy; |
Jim Grosbach | c14871c | 2011-11-10 19:18:01 +0000 | [diff] [blame] | 7932 | switch(Inst.getOpcode()) { |
| 7933 | default: llvm_unreachable("unexpected opcode!"); |
| 7934 | case ARM::ASRi: ShiftTy = ARM_AM::asr; break; |
| 7935 | case ARM::LSRi: ShiftTy = ARM_AM::lsr; break; |
| 7936 | case ARM::LSLi: ShiftTy = ARM_AM::lsl; break; |
| 7937 | case ARM::RORi: ShiftTy = ARM_AM::ror; break; |
| 7938 | } |
| 7939 | // A shift by zero is a plain MOVr, not a MOVsi. |
Jim Grosbach | 1a2f9ee | 2011-11-16 19:05:59 +0000 | [diff] [blame] | 7940 | unsigned Amt = Inst.getOperand(2).getImm(); |
Jim Grosbach | c14871c | 2011-11-10 19:18:01 +0000 | [diff] [blame] | 7941 | unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi; |
Richard Barton | ba5b0cc | 2012-04-25 18:00:18 +0000 | [diff] [blame] | 7942 | // A shift by 32 should be encoded as 0 when permitted |
| 7943 | if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr)) |
| 7944 | Amt = 0; |
Jim Grosbach | c14871c | 2011-11-10 19:18:01 +0000 | [diff] [blame] | 7945 | unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt); |
Jim Grosbach | 61db5a5 | 2011-11-10 16:44:55 +0000 | [diff] [blame] | 7946 | MCInst TmpInst; |
Jim Grosbach | c14871c | 2011-11-10 19:18:01 +0000 | [diff] [blame] | 7947 | TmpInst.setOpcode(Opc); |
Jim Grosbach | 61db5a5 | 2011-11-10 16:44:55 +0000 | [diff] [blame] | 7948 | TmpInst.addOperand(Inst.getOperand(0)); // Rd |
| 7949 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
Jim Grosbach | c14871c | 2011-11-10 19:18:01 +0000 | [diff] [blame] | 7950 | if (Opc == ARM::MOVsi) |
| 7951 | TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty |
Jim Grosbach | 61db5a5 | 2011-11-10 16:44:55 +0000 | [diff] [blame] | 7952 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7953 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7954 | TmpInst.addOperand(Inst.getOperand(5)); // cc_out |
| 7955 | Inst = TmpInst; |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7956 | return true; |
Jim Grosbach | 61db5a5 | 2011-11-10 16:44:55 +0000 | [diff] [blame] | 7957 | } |
Jim Grosbach | 1a2f9ee | 2011-11-16 19:05:59 +0000 | [diff] [blame] | 7958 | case ARM::RRXi: { |
| 7959 | unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0); |
| 7960 | MCInst TmpInst; |
| 7961 | TmpInst.setOpcode(ARM::MOVsi); |
| 7962 | TmpInst.addOperand(Inst.getOperand(0)); // Rd |
| 7963 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7964 | TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty |
| 7965 | TmpInst.addOperand(Inst.getOperand(2)); // CondCode |
| 7966 | TmpInst.addOperand(Inst.getOperand(3)); |
| 7967 | TmpInst.addOperand(Inst.getOperand(4)); // cc_out |
| 7968 | Inst = TmpInst; |
| 7969 | return true; |
| 7970 | } |
Jim Grosbach | d9a9be2 | 2011-11-10 23:58:34 +0000 | [diff] [blame] | 7971 | case ARM::t2LDMIA_UPD: { |
| 7972 | // If this is a load of a single register, then we should use |
| 7973 | // a post-indexed LDR instruction instead, per the ARM ARM. |
| 7974 | if (Inst.getNumOperands() != 5) |
| 7975 | return false; |
| 7976 | MCInst TmpInst; |
| 7977 | TmpInst.setOpcode(ARM::t2LDR_POST); |
| 7978 | TmpInst.addOperand(Inst.getOperand(4)); // Rt |
| 7979 | TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb |
| 7980 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7981 | TmpInst.addOperand(MCOperand::CreateImm(4)); |
| 7982 | TmpInst.addOperand(Inst.getOperand(2)); // CondCode |
| 7983 | TmpInst.addOperand(Inst.getOperand(3)); |
| 7984 | Inst = TmpInst; |
| 7985 | return true; |
| 7986 | } |
| 7987 | case ARM::t2STMDB_UPD: { |
| 7988 | // If this is a store of a single register, then we should use |
| 7989 | // a pre-indexed STR instruction instead, per the ARM ARM. |
| 7990 | if (Inst.getNumOperands() != 5) |
| 7991 | return false; |
| 7992 | MCInst TmpInst; |
| 7993 | TmpInst.setOpcode(ARM::t2STR_PRE); |
| 7994 | TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb |
| 7995 | TmpInst.addOperand(Inst.getOperand(4)); // Rt |
| 7996 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7997 | TmpInst.addOperand(MCOperand::CreateImm(-4)); |
| 7998 | TmpInst.addOperand(Inst.getOperand(2)); // CondCode |
| 7999 | TmpInst.addOperand(Inst.getOperand(3)); |
| 8000 | Inst = TmpInst; |
| 8001 | return true; |
| 8002 | } |
Jim Grosbach | 8ba76c6 | 2011-08-11 17:35:48 +0000 | [diff] [blame] | 8003 | case ARM::LDMIA_UPD: |
| 8004 | // If this is a load of a single register via a 'pop', then we should use |
| 8005 | // a post-indexed LDR instruction instead, per the ARM ARM. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8006 | if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "pop" && |
Jim Grosbach | 8ba76c6 | 2011-08-11 17:35:48 +0000 | [diff] [blame] | 8007 | Inst.getNumOperands() == 5) { |
| 8008 | MCInst TmpInst; |
| 8009 | TmpInst.setOpcode(ARM::LDR_POST_IMM); |
| 8010 | TmpInst.addOperand(Inst.getOperand(4)); // Rt |
| 8011 | TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb |
| 8012 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 8013 | TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset |
| 8014 | TmpInst.addOperand(MCOperand::CreateImm(4)); |
| 8015 | TmpInst.addOperand(Inst.getOperand(2)); // CondCode |
| 8016 | TmpInst.addOperand(Inst.getOperand(3)); |
| 8017 | Inst = TmpInst; |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 8018 | return true; |
Jim Grosbach | 8ba76c6 | 2011-08-11 17:35:48 +0000 | [diff] [blame] | 8019 | } |
| 8020 | break; |
Jim Grosbach | 27ad83d | 2011-08-11 18:07:11 +0000 | [diff] [blame] | 8021 | case ARM::STMDB_UPD: |
| 8022 | // If this is a store of a single register via a 'push', then we should use |
| 8023 | // a pre-indexed STR instruction instead, per the ARM ARM. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8024 | if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "push" && |
Jim Grosbach | 27ad83d | 2011-08-11 18:07:11 +0000 | [diff] [blame] | 8025 | Inst.getNumOperands() == 5) { |
| 8026 | MCInst TmpInst; |
| 8027 | TmpInst.setOpcode(ARM::STR_PRE_IMM); |
| 8028 | TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb |
| 8029 | TmpInst.addOperand(Inst.getOperand(4)); // Rt |
| 8030 | TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12 |
| 8031 | TmpInst.addOperand(MCOperand::CreateImm(-4)); |
| 8032 | TmpInst.addOperand(Inst.getOperand(2)); // CondCode |
| 8033 | TmpInst.addOperand(Inst.getOperand(3)); |
| 8034 | Inst = TmpInst; |
| 8035 | } |
| 8036 | break; |
Jim Grosbach | ec9ba98 | 2011-12-05 21:06:26 +0000 | [diff] [blame] | 8037 | case ARM::t2ADDri12: |
| 8038 | // If the immediate fits for encoding T3 (t2ADDri) and the generic "add" |
| 8039 | // mnemonic was used (not "addw"), encoding T3 is preferred. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8040 | if (static_cast<ARMOperand &>(*Operands[0]).getToken() != "add" || |
Jim Grosbach | ec9ba98 | 2011-12-05 21:06:26 +0000 | [diff] [blame] | 8041 | ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1) |
| 8042 | break; |
| 8043 | Inst.setOpcode(ARM::t2ADDri); |
| 8044 | Inst.addOperand(MCOperand::CreateReg(0)); // cc_out |
| 8045 | break; |
| 8046 | case ARM::t2SUBri12: |
| 8047 | // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub" |
| 8048 | // mnemonic was used (not "subw"), encoding T3 is preferred. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8049 | if (static_cast<ARMOperand &>(*Operands[0]).getToken() != "sub" || |
Jim Grosbach | ec9ba98 | 2011-12-05 21:06:26 +0000 | [diff] [blame] | 8050 | ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1) |
| 8051 | break; |
| 8052 | Inst.setOpcode(ARM::t2SUBri); |
| 8053 | Inst.addOperand(MCOperand::CreateReg(0)); // cc_out |
| 8054 | break; |
Jim Grosbach | e9ab47a | 2011-08-16 23:57:34 +0000 | [diff] [blame] | 8055 | case ARM::tADDi8: |
Sylvestre Ledru | 91ce36c | 2012-09-27 10:14:43 +0000 | [diff] [blame] | 8056 | // 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] | 8057 | // explicitly specified. From the ARM ARM: "Encoding T1 is preferred |
| 8058 | // to encoding T2 if <Rd> is specified and encoding T2 is preferred |
| 8059 | // to encoding T1 if <Rd> is omitted." |
Jim Grosbach | 199ab90 | 2012-03-30 16:31:31 +0000 | [diff] [blame] | 8060 | if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) { |
Jim Grosbach | e9ab47a | 2011-08-16 23:57:34 +0000 | [diff] [blame] | 8061 | Inst.setOpcode(ARM::tADDi3); |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 8062 | return true; |
| 8063 | } |
Jim Grosbach | e9ab47a | 2011-08-16 23:57:34 +0000 | [diff] [blame] | 8064 | break; |
Jim Grosbach | d0c435c | 2011-09-16 22:58:42 +0000 | [diff] [blame] | 8065 | case ARM::tSUBi8: |
Sylvestre Ledru | 91ce36c | 2012-09-27 10:14:43 +0000 | [diff] [blame] | 8066 | // 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] | 8067 | // explicitly specified. From the ARM ARM: "Encoding T1 is preferred |
| 8068 | // to encoding T2 if <Rd> is specified and encoding T2 is preferred |
| 8069 | // to encoding T1 if <Rd> is omitted." |
Jim Grosbach | 199ab90 | 2012-03-30 16:31:31 +0000 | [diff] [blame] | 8070 | if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) { |
Jim Grosbach | d0c435c | 2011-09-16 22:58:42 +0000 | [diff] [blame] | 8071 | Inst.setOpcode(ARM::tSUBi3); |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 8072 | return true; |
| 8073 | } |
Jim Grosbach | d0c435c | 2011-09-16 22:58:42 +0000 | [diff] [blame] | 8074 | break; |
Jim Grosbach | def5e34 | 2012-03-30 17:20:40 +0000 | [diff] [blame] | 8075 | case ARM::t2ADDri: |
| 8076 | case ARM::t2SUBri: { |
| 8077 | // If the destination and first source operand are the same, and |
| 8078 | // the flags are compatible with the current IT status, use encoding T2 |
| 8079 | // instead of T3. For compatibility with the system 'as'. Make sure the |
| 8080 | // wide encoding wasn't explicit. |
| 8081 | if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() || |
Jim Grosbach | 74005ae | 2012-03-30 18:39:43 +0000 | [diff] [blame] | 8082 | !isARMLowRegister(Inst.getOperand(0).getReg()) || |
Jim Grosbach | def5e34 | 2012-03-30 17:20:40 +0000 | [diff] [blame] | 8083 | (unsigned)Inst.getOperand(2).getImm() > 255 || |
| 8084 | ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) || |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8085 | (inITBlock() && Inst.getOperand(5).getReg() != 0)) || |
| 8086 | (static_cast<ARMOperand &>(*Operands[3]).isToken() && |
| 8087 | static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w")) |
Jim Grosbach | def5e34 | 2012-03-30 17:20:40 +0000 | [diff] [blame] | 8088 | break; |
| 8089 | MCInst TmpInst; |
| 8090 | TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ? |
| 8091 | ARM::tADDi8 : ARM::tSUBi8); |
| 8092 | TmpInst.addOperand(Inst.getOperand(0)); |
| 8093 | TmpInst.addOperand(Inst.getOperand(5)); |
| 8094 | TmpInst.addOperand(Inst.getOperand(0)); |
| 8095 | TmpInst.addOperand(Inst.getOperand(2)); |
| 8096 | TmpInst.addOperand(Inst.getOperand(3)); |
| 8097 | TmpInst.addOperand(Inst.getOperand(4)); |
| 8098 | Inst = TmpInst; |
| 8099 | return true; |
| 8100 | } |
Jim Grosbach | e489bab | 2011-12-05 22:16:39 +0000 | [diff] [blame] | 8101 | case ARM::t2ADDrr: { |
| 8102 | // If the destination and first source operand are the same, and |
| 8103 | // there's no setting of the flags, use encoding T2 instead of T3. |
| 8104 | // Note that this is only for ADD, not SUB. This mirrors the system |
| 8105 | // 'as' behaviour. Make sure the wide encoding wasn't explicit. |
| 8106 | if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() || |
| 8107 | Inst.getOperand(5).getReg() != 0 || |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8108 | (static_cast<ARMOperand &>(*Operands[3]).isToken() && |
| 8109 | static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w")) |
Jim Grosbach | e489bab | 2011-12-05 22:16:39 +0000 | [diff] [blame] | 8110 | break; |
| 8111 | MCInst TmpInst; |
| 8112 | TmpInst.setOpcode(ARM::tADDhirr); |
| 8113 | TmpInst.addOperand(Inst.getOperand(0)); |
| 8114 | TmpInst.addOperand(Inst.getOperand(0)); |
| 8115 | TmpInst.addOperand(Inst.getOperand(2)); |
| 8116 | TmpInst.addOperand(Inst.getOperand(3)); |
| 8117 | TmpInst.addOperand(Inst.getOperand(4)); |
| 8118 | Inst = TmpInst; |
| 8119 | return true; |
| 8120 | } |
Jim Grosbach | c6f32b3 | 2012-04-27 23:51:36 +0000 | [diff] [blame] | 8121 | case ARM::tADDrSP: { |
| 8122 | // If the non-SP source operand and the destination operand are not the |
| 8123 | // same, we need to use the 32-bit encoding if it's available. |
| 8124 | if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) { |
| 8125 | Inst.setOpcode(ARM::t2ADDrr); |
| 8126 | Inst.addOperand(MCOperand::CreateReg(0)); // cc_out |
| 8127 | return true; |
| 8128 | } |
| 8129 | break; |
| 8130 | } |
Owen Anderson | 29cfe6c | 2011-09-09 21:48:23 +0000 | [diff] [blame] | 8131 | case ARM::tB: |
| 8132 | // A Thumb conditional branch outside of an IT block is a tBcc. |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 8133 | if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) { |
Owen Anderson | 29cfe6c | 2011-09-09 21:48:23 +0000 | [diff] [blame] | 8134 | Inst.setOpcode(ARM::tBcc); |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 8135 | return true; |
| 8136 | } |
Owen Anderson | 29cfe6c | 2011-09-09 21:48:23 +0000 | [diff] [blame] | 8137 | break; |
| 8138 | case ARM::t2B: |
| 8139 | // A Thumb2 conditional branch outside of an IT block is a t2Bcc. |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 8140 | if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){ |
Owen Anderson | 29cfe6c | 2011-09-09 21:48:23 +0000 | [diff] [blame] | 8141 | Inst.setOpcode(ARM::t2Bcc); |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 8142 | return true; |
| 8143 | } |
Owen Anderson | 29cfe6c | 2011-09-09 21:48:23 +0000 | [diff] [blame] | 8144 | break; |
Jim Grosbach | 99bc846 | 2011-08-31 21:17:31 +0000 | [diff] [blame] | 8145 | case ARM::t2Bcc: |
Jim Grosbach | a0d34d3 | 2011-09-02 23:22:08 +0000 | [diff] [blame] | 8146 | // 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] | 8147 | if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) { |
Jim Grosbach | 99bc846 | 2011-08-31 21:17:31 +0000 | [diff] [blame] | 8148 | Inst.setOpcode(ARM::t2B); |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 8149 | return true; |
| 8150 | } |
Jim Grosbach | 99bc846 | 2011-08-31 21:17:31 +0000 | [diff] [blame] | 8151 | break; |
Jim Grosbach | cbd4ab1 | 2011-08-17 22:57:40 +0000 | [diff] [blame] | 8152 | case ARM::tBcc: |
| 8153 | // If the conditional is AL, we really want tB. |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 8154 | if (Inst.getOperand(1).getImm() == ARMCC::AL) { |
Jim Grosbach | cbd4ab1 | 2011-08-17 22:57:40 +0000 | [diff] [blame] | 8155 | Inst.setOpcode(ARM::tB); |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 8156 | return true; |
| 8157 | } |
Jim Grosbach | 6ddb568 | 2011-08-18 16:08:39 +0000 | [diff] [blame] | 8158 | break; |
Jim Grosbach | a31f223 | 2011-09-07 18:05:34 +0000 | [diff] [blame] | 8159 | case ARM::tLDMIA: { |
| 8160 | // If the register list contains any high registers, or if the writeback |
| 8161 | // doesn't match what tLDMIA can do, we need to use the 32-bit encoding |
| 8162 | // instead if we're in Thumb2. Otherwise, this should have generated |
| 8163 | // an error in validateInstruction(). |
| 8164 | unsigned Rn = Inst.getOperand(0).getReg(); |
| 8165 | bool hasWritebackToken = |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8166 | (static_cast<ARMOperand &>(*Operands[3]).isToken() && |
| 8167 | static_cast<ARMOperand &>(*Operands[3]).getToken() == "!"); |
Jim Grosbach | a31f223 | 2011-09-07 18:05:34 +0000 | [diff] [blame] | 8168 | bool listContainsBase; |
| 8169 | if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) || |
| 8170 | (!listContainsBase && !hasWritebackToken) || |
| 8171 | (listContainsBase && hasWritebackToken)) { |
| 8172 | // 16-bit encoding isn't sufficient. Switch to the 32-bit version. |
| 8173 | assert (isThumbTwo()); |
| 8174 | Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA); |
| 8175 | // If we're switching to the updating version, we need to insert |
| 8176 | // the writeback tied operand. |
| 8177 | if (hasWritebackToken) |
| 8178 | Inst.insert(Inst.begin(), |
| 8179 | MCOperand::CreateReg(Inst.getOperand(0).getReg())); |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 8180 | return true; |
Jim Grosbach | a31f223 | 2011-09-07 18:05:34 +0000 | [diff] [blame] | 8181 | } |
| 8182 | break; |
| 8183 | } |
Jim Grosbach | 099c976 | 2011-09-16 20:50:13 +0000 | [diff] [blame] | 8184 | case ARM::tSTMIA_UPD: { |
| 8185 | // If the register list contains any high registers, we need to use |
| 8186 | // the 32-bit encoding instead if we're in Thumb2. Otherwise, this |
| 8187 | // should have generated an error in validateInstruction(). |
| 8188 | unsigned Rn = Inst.getOperand(0).getReg(); |
| 8189 | bool listContainsBase; |
| 8190 | if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) { |
| 8191 | // 16-bit encoding isn't sufficient. Switch to the 32-bit version. |
| 8192 | assert (isThumbTwo()); |
| 8193 | Inst.setOpcode(ARM::t2STMIA_UPD); |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 8194 | return true; |
Jim Grosbach | 099c976 | 2011-09-16 20:50:13 +0000 | [diff] [blame] | 8195 | } |
| 8196 | break; |
| 8197 | } |
Jim Grosbach | 9bded9d | 2011-11-10 23:17:11 +0000 | [diff] [blame] | 8198 | case ARM::tPOP: { |
| 8199 | bool listContainsBase; |
| 8200 | // If the register list contains any high registers, we need to use |
| 8201 | // the 32-bit encoding instead if we're in Thumb2. Otherwise, this |
| 8202 | // should have generated an error in validateInstruction(). |
| 8203 | if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase)) |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 8204 | return false; |
Jim Grosbach | 9bded9d | 2011-11-10 23:17:11 +0000 | [diff] [blame] | 8205 | assert (isThumbTwo()); |
| 8206 | Inst.setOpcode(ARM::t2LDMIA_UPD); |
| 8207 | // Add the base register and writeback operands. |
| 8208 | Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP)); |
| 8209 | Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP)); |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 8210 | return true; |
Jim Grosbach | 9bded9d | 2011-11-10 23:17:11 +0000 | [diff] [blame] | 8211 | } |
| 8212 | case ARM::tPUSH: { |
| 8213 | bool listContainsBase; |
| 8214 | if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase)) |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 8215 | return false; |
Jim Grosbach | 9bded9d | 2011-11-10 23:17:11 +0000 | [diff] [blame] | 8216 | assert (isThumbTwo()); |
| 8217 | Inst.setOpcode(ARM::t2STMDB_UPD); |
| 8218 | // Add the base register and writeback operands. |
| 8219 | Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP)); |
| 8220 | Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP)); |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 8221 | return true; |
Jim Grosbach | 9bded9d | 2011-11-10 23:17:11 +0000 | [diff] [blame] | 8222 | } |
Jim Grosbach | b908b7a | 2011-09-10 00:15:36 +0000 | [diff] [blame] | 8223 | case ARM::t2MOVi: { |
| 8224 | // If we can use the 16-bit encoding and the user didn't explicitly |
| 8225 | // request the 32-bit variant, transform it here. |
| 8226 | if (isARMLowRegister(Inst.getOperand(0).getReg()) && |
Jim Grosbach | 199ab90 | 2012-03-30 16:31:31 +0000 | [diff] [blame] | 8227 | (unsigned)Inst.getOperand(1).getImm() <= 255 && |
Jim Grosbach | 18b8b17 | 2011-09-14 19:12:11 +0000 | [diff] [blame] | 8228 | ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8229 | Inst.getOperand(4).getReg() == ARM::CPSR) || |
| 8230 | (inITBlock() && Inst.getOperand(4).getReg() == 0)) && |
| 8231 | (!static_cast<ARMOperand &>(*Operands[2]).isToken() || |
| 8232 | static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) { |
Jim Grosbach | b908b7a | 2011-09-10 00:15:36 +0000 | [diff] [blame] | 8233 | // The operands aren't in the same order for tMOVi8... |
| 8234 | MCInst TmpInst; |
| 8235 | TmpInst.setOpcode(ARM::tMOVi8); |
| 8236 | TmpInst.addOperand(Inst.getOperand(0)); |
| 8237 | TmpInst.addOperand(Inst.getOperand(4)); |
| 8238 | TmpInst.addOperand(Inst.getOperand(1)); |
| 8239 | TmpInst.addOperand(Inst.getOperand(2)); |
| 8240 | TmpInst.addOperand(Inst.getOperand(3)); |
| 8241 | Inst = TmpInst; |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 8242 | return true; |
Jim Grosbach | b908b7a | 2011-09-10 00:15:36 +0000 | [diff] [blame] | 8243 | } |
| 8244 | break; |
| 8245 | } |
| 8246 | case ARM::t2MOVr: { |
| 8247 | // If we can use the 16-bit encoding and the user didn't explicitly |
| 8248 | // request the 32-bit variant, transform it here. |
| 8249 | if (isARMLowRegister(Inst.getOperand(0).getReg()) && |
| 8250 | isARMLowRegister(Inst.getOperand(1).getReg()) && |
| 8251 | Inst.getOperand(2).getImm() == ARMCC::AL && |
| 8252 | Inst.getOperand(4).getReg() == ARM::CPSR && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8253 | (!static_cast<ARMOperand &>(*Operands[2]).isToken() || |
| 8254 | static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) { |
Jim Grosbach | b908b7a | 2011-09-10 00:15:36 +0000 | [diff] [blame] | 8255 | // The operands aren't the same for tMOV[S]r... (no cc_out) |
| 8256 | MCInst TmpInst; |
| 8257 | TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr); |
| 8258 | TmpInst.addOperand(Inst.getOperand(0)); |
| 8259 | TmpInst.addOperand(Inst.getOperand(1)); |
| 8260 | TmpInst.addOperand(Inst.getOperand(2)); |
| 8261 | TmpInst.addOperand(Inst.getOperand(3)); |
| 8262 | Inst = TmpInst; |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 8263 | return true; |
Jim Grosbach | b908b7a | 2011-09-10 00:15:36 +0000 | [diff] [blame] | 8264 | } |
| 8265 | break; |
| 8266 | } |
Jim Grosbach | 8221319 | 2011-09-19 20:29:33 +0000 | [diff] [blame] | 8267 | case ARM::t2SXTH: |
Jim Grosbach | b351980 | 2011-09-20 00:46:54 +0000 | [diff] [blame] | 8268 | case ARM::t2SXTB: |
| 8269 | case ARM::t2UXTH: |
| 8270 | case ARM::t2UXTB: { |
Jim Grosbach | 8221319 | 2011-09-19 20:29:33 +0000 | [diff] [blame] | 8271 | // If we can use the 16-bit encoding and the user didn't explicitly |
| 8272 | // request the 32-bit variant, transform it here. |
| 8273 | if (isARMLowRegister(Inst.getOperand(0).getReg()) && |
| 8274 | isARMLowRegister(Inst.getOperand(1).getReg()) && |
| 8275 | Inst.getOperand(2).getImm() == 0 && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8276 | (!static_cast<ARMOperand &>(*Operands[2]).isToken() || |
| 8277 | static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) { |
Jim Grosbach | b351980 | 2011-09-20 00:46:54 +0000 | [diff] [blame] | 8278 | unsigned NewOpc; |
| 8279 | switch (Inst.getOpcode()) { |
| 8280 | default: llvm_unreachable("Illegal opcode!"); |
| 8281 | case ARM::t2SXTH: NewOpc = ARM::tSXTH; break; |
| 8282 | case ARM::t2SXTB: NewOpc = ARM::tSXTB; break; |
| 8283 | case ARM::t2UXTH: NewOpc = ARM::tUXTH; break; |
| 8284 | case ARM::t2UXTB: NewOpc = ARM::tUXTB; break; |
| 8285 | } |
Jim Grosbach | 8221319 | 2011-09-19 20:29:33 +0000 | [diff] [blame] | 8286 | // The operands aren't the same for thumb1 (no rotate operand). |
| 8287 | MCInst TmpInst; |
| 8288 | TmpInst.setOpcode(NewOpc); |
| 8289 | TmpInst.addOperand(Inst.getOperand(0)); |
| 8290 | TmpInst.addOperand(Inst.getOperand(1)); |
| 8291 | TmpInst.addOperand(Inst.getOperand(3)); |
| 8292 | TmpInst.addOperand(Inst.getOperand(4)); |
| 8293 | Inst = TmpInst; |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 8294 | return true; |
Jim Grosbach | 8221319 | 2011-09-19 20:29:33 +0000 | [diff] [blame] | 8295 | } |
| 8296 | break; |
| 8297 | } |
Jim Grosbach | e2ca9e5 | 2011-12-20 00:59:38 +0000 | [diff] [blame] | 8298 | case ARM::MOVsi: { |
| 8299 | ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm()); |
Richard Barton | ba5b0cc | 2012-04-25 18:00:18 +0000 | [diff] [blame] | 8300 | // rrx shifts and asr/lsr of #32 is encoded as 0 |
| 8301 | if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr) |
| 8302 | return false; |
Jim Grosbach | e2ca9e5 | 2011-12-20 00:59:38 +0000 | [diff] [blame] | 8303 | if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) { |
| 8304 | // Shifting by zero is accepted as a vanilla 'MOVr' |
| 8305 | MCInst TmpInst; |
| 8306 | TmpInst.setOpcode(ARM::MOVr); |
| 8307 | TmpInst.addOperand(Inst.getOperand(0)); |
| 8308 | TmpInst.addOperand(Inst.getOperand(1)); |
| 8309 | TmpInst.addOperand(Inst.getOperand(3)); |
| 8310 | TmpInst.addOperand(Inst.getOperand(4)); |
| 8311 | TmpInst.addOperand(Inst.getOperand(5)); |
| 8312 | Inst = TmpInst; |
| 8313 | return true; |
| 8314 | } |
| 8315 | return false; |
| 8316 | } |
Jim Grosbach | 12ccf45 | 2011-12-22 18:04:04 +0000 | [diff] [blame] | 8317 | case ARM::ANDrsi: |
| 8318 | case ARM::ORRrsi: |
| 8319 | case ARM::EORrsi: |
| 8320 | case ARM::BICrsi: |
| 8321 | case ARM::SUBrsi: |
| 8322 | case ARM::ADDrsi: { |
| 8323 | unsigned newOpc; |
| 8324 | ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm()); |
| 8325 | if (SOpc == ARM_AM::rrx) return false; |
| 8326 | switch (Inst.getOpcode()) { |
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 8327 | default: llvm_unreachable("unexpected opcode!"); |
Jim Grosbach | 12ccf45 | 2011-12-22 18:04:04 +0000 | [diff] [blame] | 8328 | case ARM::ANDrsi: newOpc = ARM::ANDrr; break; |
| 8329 | case ARM::ORRrsi: newOpc = ARM::ORRrr; break; |
| 8330 | case ARM::EORrsi: newOpc = ARM::EORrr; break; |
| 8331 | case ARM::BICrsi: newOpc = ARM::BICrr; break; |
| 8332 | case ARM::SUBrsi: newOpc = ARM::SUBrr; break; |
| 8333 | case ARM::ADDrsi: newOpc = ARM::ADDrr; break; |
| 8334 | } |
| 8335 | // If the shift is by zero, use the non-shifted instruction definition. |
Richard Barton | 35aceb8 | 2012-07-09 16:31:14 +0000 | [diff] [blame] | 8336 | // The exception is for right shifts, where 0 == 32 |
| 8337 | if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 && |
| 8338 | !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) { |
Jim Grosbach | 12ccf45 | 2011-12-22 18:04:04 +0000 | [diff] [blame] | 8339 | MCInst TmpInst; |
| 8340 | TmpInst.setOpcode(newOpc); |
| 8341 | TmpInst.addOperand(Inst.getOperand(0)); |
| 8342 | TmpInst.addOperand(Inst.getOperand(1)); |
| 8343 | TmpInst.addOperand(Inst.getOperand(2)); |
| 8344 | TmpInst.addOperand(Inst.getOperand(4)); |
| 8345 | TmpInst.addOperand(Inst.getOperand(5)); |
| 8346 | TmpInst.addOperand(Inst.getOperand(6)); |
| 8347 | Inst = TmpInst; |
| 8348 | return true; |
| 8349 | } |
| 8350 | return false; |
| 8351 | } |
Jim Grosbach | 82f76d1 | 2012-01-25 19:52:01 +0000 | [diff] [blame] | 8352 | case ARM::ITasm: |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 8353 | case ARM::t2IT: { |
| 8354 | // The mask bits for all but the first condition are represented as |
| 8355 | // the low bit of the condition code value implies 't'. We currently |
| 8356 | // 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] | 8357 | // of the condition code is zero. |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 8358 | MCOperand &MO = Inst.getOperand(1); |
| 8359 | unsigned Mask = MO.getImm(); |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 8360 | unsigned OrigMask = Mask; |
Michael J. Spencer | df1ecbd7 | 2013-05-24 22:23:49 +0000 | [diff] [blame] | 8361 | unsigned TZ = countTrailingZeros(Mask); |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 8362 | if ((Inst.getOperand(0).getImm() & 1) == 0) { |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 8363 | assert(Mask && TZ <= 3 && "illegal IT mask value!"); |
Benjamin Kramer | 8bad66e | 2013-05-19 22:01:57 +0000 | [diff] [blame] | 8364 | Mask ^= (0xE << TZ) & 0xF; |
Richard Barton | f435b09 | 2012-04-27 08:42:59 +0000 | [diff] [blame] | 8365 | } |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 8366 | MO.setImm(Mask); |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 8367 | |
| 8368 | // Set up the IT block state according to the IT instruction we just |
| 8369 | // matched. |
| 8370 | assert(!inITBlock() && "nested IT blocks?!"); |
| 8371 | ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm()); |
| 8372 | ITState.Mask = OrigMask; // Use the original mask, not the updated one. |
| 8373 | ITState.CurPosition = 0; |
| 8374 | ITState.FirstCond = true; |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 8375 | break; |
| 8376 | } |
Richard Barton | a39625e | 2012-07-09 16:12:24 +0000 | [diff] [blame] | 8377 | case ARM::t2LSLrr: |
| 8378 | case ARM::t2LSRrr: |
| 8379 | case ARM::t2ASRrr: |
| 8380 | case ARM::t2SBCrr: |
| 8381 | case ARM::t2RORrr: |
| 8382 | case ARM::t2BICrr: |
| 8383 | { |
Richard Barton | d566037 | 2012-07-09 16:14:28 +0000 | [diff] [blame] | 8384 | // Assemblers should use the narrow encodings of these instructions when permissible. |
Richard Barton | a39625e | 2012-07-09 16:12:24 +0000 | [diff] [blame] | 8385 | if ((isARMLowRegister(Inst.getOperand(1).getReg()) && |
| 8386 | isARMLowRegister(Inst.getOperand(2).getReg())) && |
| 8387 | Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() && |
Richard Barton | 984d0ba | 2012-07-09 18:30:56 +0000 | [diff] [blame] | 8388 | ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) || |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8389 | (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) && |
| 8390 | (!static_cast<ARMOperand &>(*Operands[3]).isToken() || |
| 8391 | !static_cast<ARMOperand &>(*Operands[3]).getToken().equals_lower( |
| 8392 | ".w"))) { |
Richard Barton | a39625e | 2012-07-09 16:12:24 +0000 | [diff] [blame] | 8393 | unsigned NewOpc; |
| 8394 | switch (Inst.getOpcode()) { |
| 8395 | default: llvm_unreachable("unexpected opcode"); |
| 8396 | case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break; |
| 8397 | case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break; |
| 8398 | case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break; |
| 8399 | case ARM::t2SBCrr: NewOpc = ARM::tSBC; break; |
| 8400 | case ARM::t2RORrr: NewOpc = ARM::tROR; break; |
| 8401 | case ARM::t2BICrr: NewOpc = ARM::tBIC; break; |
| 8402 | } |
| 8403 | MCInst TmpInst; |
| 8404 | TmpInst.setOpcode(NewOpc); |
| 8405 | TmpInst.addOperand(Inst.getOperand(0)); |
| 8406 | TmpInst.addOperand(Inst.getOperand(5)); |
| 8407 | TmpInst.addOperand(Inst.getOperand(1)); |
| 8408 | TmpInst.addOperand(Inst.getOperand(2)); |
| 8409 | TmpInst.addOperand(Inst.getOperand(3)); |
| 8410 | TmpInst.addOperand(Inst.getOperand(4)); |
| 8411 | Inst = TmpInst; |
| 8412 | return true; |
| 8413 | } |
| 8414 | return false; |
| 8415 | } |
| 8416 | case ARM::t2ANDrr: |
| 8417 | case ARM::t2EORrr: |
| 8418 | case ARM::t2ADCrr: |
| 8419 | case ARM::t2ORRrr: |
| 8420 | { |
Richard Barton | d566037 | 2012-07-09 16:14:28 +0000 | [diff] [blame] | 8421 | // Assemblers should use the narrow encodings of these instructions when permissible. |
Richard Barton | a39625e | 2012-07-09 16:12:24 +0000 | [diff] [blame] | 8422 | // These instructions are special in that they are commutable, so shorter encodings |
| 8423 | // are available more often. |
| 8424 | if ((isARMLowRegister(Inst.getOperand(1).getReg()) && |
| 8425 | isARMLowRegister(Inst.getOperand(2).getReg())) && |
| 8426 | (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() || |
| 8427 | Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) && |
Richard Barton | 984d0ba | 2012-07-09 18:30:56 +0000 | [diff] [blame] | 8428 | ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) || |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8429 | (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) && |
| 8430 | (!static_cast<ARMOperand &>(*Operands[3]).isToken() || |
| 8431 | !static_cast<ARMOperand &>(*Operands[3]).getToken().equals_lower( |
| 8432 | ".w"))) { |
Richard Barton | a39625e | 2012-07-09 16:12:24 +0000 | [diff] [blame] | 8433 | unsigned NewOpc; |
| 8434 | switch (Inst.getOpcode()) { |
| 8435 | default: llvm_unreachable("unexpected opcode"); |
| 8436 | case ARM::t2ADCrr: NewOpc = ARM::tADC; break; |
| 8437 | case ARM::t2ANDrr: NewOpc = ARM::tAND; break; |
| 8438 | case ARM::t2EORrr: NewOpc = ARM::tEOR; break; |
| 8439 | case ARM::t2ORRrr: NewOpc = ARM::tORR; break; |
| 8440 | } |
| 8441 | MCInst TmpInst; |
| 8442 | TmpInst.setOpcode(NewOpc); |
| 8443 | TmpInst.addOperand(Inst.getOperand(0)); |
| 8444 | TmpInst.addOperand(Inst.getOperand(5)); |
| 8445 | if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) { |
| 8446 | TmpInst.addOperand(Inst.getOperand(1)); |
| 8447 | TmpInst.addOperand(Inst.getOperand(2)); |
| 8448 | } else { |
| 8449 | TmpInst.addOperand(Inst.getOperand(2)); |
| 8450 | TmpInst.addOperand(Inst.getOperand(1)); |
| 8451 | } |
| 8452 | TmpInst.addOperand(Inst.getOperand(3)); |
| 8453 | TmpInst.addOperand(Inst.getOperand(4)); |
| 8454 | Inst = TmpInst; |
| 8455 | return true; |
| 8456 | } |
| 8457 | return false; |
| 8458 | } |
Jim Grosbach | 8ba76c6 | 2011-08-11 17:35:48 +0000 | [diff] [blame] | 8459 | } |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 8460 | return false; |
Jim Grosbach | 8ba76c6 | 2011-08-11 17:35:48 +0000 | [diff] [blame] | 8461 | } |
| 8462 | |
Jim Grosbach | 3e941ae | 2011-08-16 20:45:50 +0000 | [diff] [blame] | 8463 | unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) { |
| 8464 | // 16-bit thumb arithmetic instructions either require or preclude the 'S' |
| 8465 | // suffix depending on whether they're in an IT block or not. |
Jim Grosbach | b7fa2c0 | 2011-08-16 22:20:01 +0000 | [diff] [blame] | 8466 | unsigned Opc = Inst.getOpcode(); |
Joey Gouly | 0e76fa7 | 2013-09-12 10:28:05 +0000 | [diff] [blame] | 8467 | const MCInstrDesc &MCID = MII.get(Opc); |
Jim Grosbach | 3e941ae | 2011-08-16 20:45:50 +0000 | [diff] [blame] | 8468 | if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) { |
| 8469 | assert(MCID.hasOptionalDef() && |
| 8470 | "optionally flag setting instruction missing optional def operand"); |
| 8471 | assert(MCID.NumOperands == Inst.getNumOperands() && |
| 8472 | "operand count mismatch!"); |
| 8473 | // Find the optional-def operand (cc_out). |
| 8474 | unsigned OpNo; |
| 8475 | for (OpNo = 0; |
| 8476 | !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands; |
| 8477 | ++OpNo) |
| 8478 | ; |
| 8479 | // If we're parsing Thumb1, reject it completely. |
| 8480 | if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR) |
| 8481 | return Match_MnemonicFail; |
| 8482 | // If we're parsing Thumb2, which form is legal depends on whether we're |
| 8483 | // in an IT block. |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 8484 | if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR && |
| 8485 | !inITBlock()) |
Jim Grosbach | 3e941ae | 2011-08-16 20:45:50 +0000 | [diff] [blame] | 8486 | return Match_RequiresITBlock; |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 8487 | if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR && |
| 8488 | inITBlock()) |
| 8489 | return Match_RequiresNotITBlock; |
Jim Grosbach | 3e941ae | 2011-08-16 20:45:50 +0000 | [diff] [blame] | 8490 | } |
Jim Grosbach | b7fa2c0 | 2011-08-16 22:20:01 +0000 | [diff] [blame] | 8491 | // Some high-register supporting Thumb1 encodings only allow both registers |
| 8492 | // to be from r0-r7 when in Thumb2. |
Renato Golin | 36c626e | 2014-09-26 16:14:29 +0000 | [diff] [blame] | 8493 | else if (Opc == ARM::tADDhirr && isThumbOne() && !hasV6MOps() && |
Jim Grosbach | b7fa2c0 | 2011-08-16 22:20:01 +0000 | [diff] [blame] | 8494 | isARMLowRegister(Inst.getOperand(1).getReg()) && |
| 8495 | isARMLowRegister(Inst.getOperand(2).getReg())) |
| 8496 | return Match_RequiresThumb2; |
| 8497 | // Others only require ARMv6 or later. |
Jim Grosbach | f86cd37 | 2011-08-19 20:46:54 +0000 | [diff] [blame] | 8498 | else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() && |
Jim Grosbach | b7fa2c0 | 2011-08-16 22:20:01 +0000 | [diff] [blame] | 8499 | isARMLowRegister(Inst.getOperand(0).getReg()) && |
| 8500 | isARMLowRegister(Inst.getOperand(1).getReg())) |
| 8501 | return Match_RequiresV6; |
Jim Grosbach | 3e941ae | 2011-08-16 20:45:50 +0000 | [diff] [blame] | 8502 | return Match_Success; |
| 8503 | } |
| 8504 | |
Benjamin Kramer | 44a53da | 2014-04-12 18:45:24 +0000 | [diff] [blame] | 8505 | namespace llvm { |
| 8506 | template <> inline bool IsCPSRDead<MCInst>(MCInst *Instr) { |
Artyom Skrobov | 1a6cd1d | 2014-02-26 11:27:28 +0000 | [diff] [blame] | 8507 | return true; // In an assembly source, no need to second-guess |
| 8508 | } |
Benjamin Kramer | 44a53da | 2014-04-12 18:45:24 +0000 | [diff] [blame] | 8509 | } |
Artyom Skrobov | 1a6cd1d | 2014-02-26 11:27:28 +0000 | [diff] [blame] | 8510 | |
Tim Northover | 26bb14e | 2014-08-18 11:49:42 +0000 | [diff] [blame] | 8511 | static const char *getSubtargetFeatureName(uint64_t Val); |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8512 | bool ARMAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode, |
| 8513 | OperandVector &Operands, |
Tim Northover | 26bb14e | 2014-08-18 11:49:42 +0000 | [diff] [blame] | 8514 | MCStreamer &Out, uint64_t &ErrorInfo, |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8515 | bool MatchingInlineAsm) { |
Chris Lattner | 9487de6 | 2010-10-28 21:28:01 +0000 | [diff] [blame] | 8516 | MCInst Inst; |
Jim Grosbach | 120a96a | 2011-08-15 23:03:29 +0000 | [diff] [blame] | 8517 | unsigned MatchResult; |
Weiming Zhao | 8f56f88 | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 8518 | |
Chad Rosier | 2f480a8 | 2012-10-12 22:53:36 +0000 | [diff] [blame] | 8519 | MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo, |
Chad Rosier | 4996355 | 2012-10-13 00:26:04 +0000 | [diff] [blame] | 8520 | MatchingInlineAsm); |
Kevin Enderby | 3164a34 | 2010-12-09 19:19:43 +0000 | [diff] [blame] | 8521 | switch (MatchResult) { |
Jim Grosbach | 120a96a | 2011-08-15 23:03:29 +0000 | [diff] [blame] | 8522 | default: break; |
Chris Lattner | d27b05e | 2010-10-28 21:41:58 +0000 | [diff] [blame] | 8523 | case Match_Success: |
Jim Grosbach | edaa35a | 2011-07-26 18:25:39 +0000 | [diff] [blame] | 8524 | // Context sensitive operand constraints aren't handled by the matcher, |
| 8525 | // so check them here. |
Jim Grosbach | a0d34d3 | 2011-09-02 23:22:08 +0000 | [diff] [blame] | 8526 | if (validateInstruction(Inst, Operands)) { |
| 8527 | // Still progress the IT block, otherwise one wrong condition causes |
| 8528 | // nasty cascading errors. |
| 8529 | forwardITPosition(); |
Jim Grosbach | edaa35a | 2011-07-26 18:25:39 +0000 | [diff] [blame] | 8530 | return true; |
Jim Grosbach | a0d34d3 | 2011-09-02 23:22:08 +0000 | [diff] [blame] | 8531 | } |
Jim Grosbach | edaa35a | 2011-07-26 18:25:39 +0000 | [diff] [blame] | 8532 | |
Amara Emerson | 52cfb6a | 2013-10-03 09:31:51 +0000 | [diff] [blame] | 8533 | { // processInstruction() updates inITBlock state, we need to save it away |
| 8534 | bool wasInITBlock = inITBlock(); |
| 8535 | |
| 8536 | // Some instructions need post-processing to, for example, tweak which |
| 8537 | // encoding is selected. Loop on it while changes happen so the |
| 8538 | // individual transformations can chain off each other. E.g., |
| 8539 | // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8) |
Joerg Sonnenberger | 02b13a8 | 2014-11-21 22:39:34 +0000 | [diff] [blame] | 8540 | while (processInstruction(Inst, Operands, Out)) |
Amara Emerson | 52cfb6a | 2013-10-03 09:31:51 +0000 | [diff] [blame] | 8541 | ; |
| 8542 | |
| 8543 | // Only after the instruction is fully processed, we can validate it |
| 8544 | if (wasInITBlock && hasV8Ops() && isThumb() && |
Weiming Zhao | 5930ae6 | 2014-01-23 19:55:33 +0000 | [diff] [blame] | 8545 | !isV8EligibleForIT(&Inst)) { |
Amara Emerson | 52cfb6a | 2013-10-03 09:31:51 +0000 | [diff] [blame] | 8546 | Warning(IDLoc, "deprecated instruction in IT block"); |
| 8547 | } |
| 8548 | } |
Jim Grosbach | 8ba76c6 | 2011-08-11 17:35:48 +0000 | [diff] [blame] | 8549 | |
Jim Grosbach | a0d34d3 | 2011-09-02 23:22:08 +0000 | [diff] [blame] | 8550 | // Only move forward at the very end so that everything in validate |
| 8551 | // and process gets a consistent answer about whether we're in an IT |
| 8552 | // block. |
| 8553 | forwardITPosition(); |
| 8554 | |
Jim Grosbach | 82f76d1 | 2012-01-25 19:52:01 +0000 | [diff] [blame] | 8555 | // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and |
| 8556 | // doesn't actually encode. |
| 8557 | if (Inst.getOpcode() == ARM::ITasm) |
| 8558 | return false; |
| 8559 | |
Jim Grosbach | 5e5eabb | 2012-01-26 23:20:15 +0000 | [diff] [blame] | 8560 | Inst.setLoc(IDLoc); |
David Woodhouse | e6c13e4 | 2014-01-28 23:12:42 +0000 | [diff] [blame] | 8561 | Out.EmitInstruction(Inst, STI); |
Chris Lattner | 9487de6 | 2010-10-28 21:28:01 +0000 | [diff] [blame] | 8562 | return false; |
Jim Grosbach | 5117ef7 | 2012-04-24 22:40:08 +0000 | [diff] [blame] | 8563 | case Match_MissingFeature: { |
| 8564 | assert(ErrorInfo && "Unknown missing feature!"); |
| 8565 | // Special case the error message for the very common case where only |
| 8566 | // a single subtarget feature is missing (Thumb vs. ARM, e.g.). |
| 8567 | std::string Msg = "instruction requires:"; |
Tim Northover | 26bb14e | 2014-08-18 11:49:42 +0000 | [diff] [blame] | 8568 | uint64_t Mask = 1; |
Jim Grosbach | 5117ef7 | 2012-04-24 22:40:08 +0000 | [diff] [blame] | 8569 | for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) { |
| 8570 | if (ErrorInfo & Mask) { |
| 8571 | Msg += " "; |
| 8572 | Msg += getSubtargetFeatureName(ErrorInfo & Mask); |
| 8573 | } |
| 8574 | Mask <<= 1; |
| 8575 | } |
| 8576 | return Error(IDLoc, Msg); |
| 8577 | } |
Chris Lattner | d27b05e | 2010-10-28 21:41:58 +0000 | [diff] [blame] | 8578 | case Match_InvalidOperand: { |
| 8579 | SMLoc ErrorLoc = IDLoc; |
Tim Northover | 26bb14e | 2014-08-18 11:49:42 +0000 | [diff] [blame] | 8580 | if (ErrorInfo != ~0ULL) { |
Chris Lattner | d27b05e | 2010-10-28 21:41:58 +0000 | [diff] [blame] | 8581 | if (ErrorInfo >= Operands.size()) |
| 8582 | return Error(IDLoc, "too few operands for instruction"); |
Jim Grosbach | 624bcc7 | 2010-10-29 14:46:02 +0000 | [diff] [blame] | 8583 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8584 | ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc(); |
Chris Lattner | d27b05e | 2010-10-28 21:41:58 +0000 | [diff] [blame] | 8585 | if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc; |
| 8586 | } |
Jim Grosbach | 624bcc7 | 2010-10-29 14:46:02 +0000 | [diff] [blame] | 8587 | |
Chris Lattner | d27b05e | 2010-10-28 21:41:58 +0000 | [diff] [blame] | 8588 | return Error(ErrorLoc, "invalid operand for instruction"); |
Chris Lattner | 9487de6 | 2010-10-28 21:28:01 +0000 | [diff] [blame] | 8589 | } |
Chris Lattner | d27b05e | 2010-10-28 21:41:58 +0000 | [diff] [blame] | 8590 | case Match_MnemonicFail: |
Benjamin Kramer | 673824b | 2012-04-15 17:04:27 +0000 | [diff] [blame] | 8591 | return Error(IDLoc, "invalid instruction", |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8592 | ((ARMOperand &)*Operands[0]).getLocRange()); |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 8593 | case Match_RequiresNotITBlock: |
| 8594 | return Error(IDLoc, "flag setting instruction only valid outside IT block"); |
Jim Grosbach | 3e941ae | 2011-08-16 20:45:50 +0000 | [diff] [blame] | 8595 | case Match_RequiresITBlock: |
| 8596 | return Error(IDLoc, "instruction only valid inside IT block"); |
Jim Grosbach | b7fa2c0 | 2011-08-16 22:20:01 +0000 | [diff] [blame] | 8597 | case Match_RequiresV6: |
| 8598 | return Error(IDLoc, "instruction variant requires ARMv6 or later"); |
| 8599 | case Match_RequiresThumb2: |
| 8600 | return Error(IDLoc, "instruction variant requires Thumb2"); |
Jim Grosbach | 087affe | 2012-06-22 23:56:48 +0000 | [diff] [blame] | 8601 | case Match_ImmRange0_15: { |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8602 | SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc(); |
Jim Grosbach | 087affe | 2012-06-22 23:56:48 +0000 | [diff] [blame] | 8603 | if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc; |
| 8604 | return Error(ErrorLoc, "immediate operand must be in the range [0,15]"); |
| 8605 | } |
Artyom Skrobov | fc12e70 | 2013-10-23 10:14:40 +0000 | [diff] [blame] | 8606 | case Match_ImmRange0_239: { |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8607 | SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc(); |
Artyom Skrobov | fc12e70 | 2013-10-23 10:14:40 +0000 | [diff] [blame] | 8608 | if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc; |
| 8609 | return Error(ErrorLoc, "immediate operand must be in the range [0,239]"); |
| 8610 | } |
Kevin Enderby | 488f20b | 2014-04-10 20:18:58 +0000 | [diff] [blame] | 8611 | case Match_AlignedMemoryRequiresNone: |
| 8612 | case Match_DupAlignedMemoryRequiresNone: |
| 8613 | case Match_AlignedMemoryRequires16: |
| 8614 | case Match_DupAlignedMemoryRequires16: |
| 8615 | case Match_AlignedMemoryRequires32: |
| 8616 | case Match_DupAlignedMemoryRequires32: |
| 8617 | case Match_AlignedMemoryRequires64: |
| 8618 | case Match_DupAlignedMemoryRequires64: |
| 8619 | case Match_AlignedMemoryRequires64or128: |
| 8620 | case Match_DupAlignedMemoryRequires64or128: |
| 8621 | case Match_AlignedMemoryRequires64or128or256: |
| 8622 | { |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8623 | SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getAlignmentLoc(); |
Kevin Enderby | 488f20b | 2014-04-10 20:18:58 +0000 | [diff] [blame] | 8624 | if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc; |
| 8625 | switch (MatchResult) { |
| 8626 | default: |
| 8627 | llvm_unreachable("Missing Match_Aligned type"); |
| 8628 | case Match_AlignedMemoryRequiresNone: |
| 8629 | case Match_DupAlignedMemoryRequiresNone: |
| 8630 | return Error(ErrorLoc, "alignment must be omitted"); |
| 8631 | case Match_AlignedMemoryRequires16: |
| 8632 | case Match_DupAlignedMemoryRequires16: |
| 8633 | return Error(ErrorLoc, "alignment must be 16 or omitted"); |
| 8634 | case Match_AlignedMemoryRequires32: |
| 8635 | case Match_DupAlignedMemoryRequires32: |
| 8636 | return Error(ErrorLoc, "alignment must be 32 or omitted"); |
| 8637 | case Match_AlignedMemoryRequires64: |
| 8638 | case Match_DupAlignedMemoryRequires64: |
| 8639 | return Error(ErrorLoc, "alignment must be 64 or omitted"); |
| 8640 | case Match_AlignedMemoryRequires64or128: |
| 8641 | case Match_DupAlignedMemoryRequires64or128: |
| 8642 | return Error(ErrorLoc, "alignment must be 64, 128 or omitted"); |
| 8643 | case Match_AlignedMemoryRequires64or128or256: |
| 8644 | return Error(ErrorLoc, "alignment must be 64, 128, 256 or omitted"); |
| 8645 | } |
| 8646 | } |
Chris Lattner | d27b05e | 2010-10-28 21:41:58 +0000 | [diff] [blame] | 8647 | } |
Jim Grosbach | 624bcc7 | 2010-10-29 14:46:02 +0000 | [diff] [blame] | 8648 | |
Eric Christopher | 91d7b90 | 2010-10-29 09:26:59 +0000 | [diff] [blame] | 8649 | llvm_unreachable("Implement any new match types added!"); |
Chris Lattner | 9487de6 | 2010-10-28 21:28:01 +0000 | [diff] [blame] | 8650 | } |
| 8651 | |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8652 | /// parseDirective parses the arm specific directives |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 8653 | bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) { |
Saleem Abdulrasool | dd979e6 | 2014-04-05 22:09:51 +0000 | [diff] [blame] | 8654 | const MCObjectFileInfo::Environment Format = |
| 8655 | getContext().getObjectFileInfo()->getObjectFileType(); |
| 8656 | bool IsMachO = Format == MCObjectFileInfo::IsMachO; |
Saleem Abdulrasool | bfdfb14 | 2014-09-18 04:28:29 +0000 | [diff] [blame] | 8657 | bool IsCOFF = Format == MCObjectFileInfo::IsCOFF; |
Saleem Abdulrasool | dd979e6 | 2014-04-05 22:09:51 +0000 | [diff] [blame] | 8658 | |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 8659 | StringRef IDVal = DirectiveID.getIdentifier(); |
| 8660 | if (IDVal == ".word") |
Saleem Abdulrasool | 3897651 | 2014-02-23 06:22:09 +0000 | [diff] [blame] | 8661 | return parseLiteralValues(4, DirectiveID.getLoc()); |
| 8662 | else if (IDVal == ".short" || IDVal == ".hword") |
| 8663 | return parseLiteralValues(2, DirectiveID.getLoc()); |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8664 | else if (IDVal == ".thumb") |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8665 | return parseDirectiveThumb(DirectiveID.getLoc()); |
Jim Grosbach | 7f88239 | 2011-12-07 18:04:19 +0000 | [diff] [blame] | 8666 | else if (IDVal == ".arm") |
| 8667 | return parseDirectiveARM(DirectiveID.getLoc()); |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8668 | else if (IDVal == ".thumb_func") |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8669 | return parseDirectiveThumbFunc(DirectiveID.getLoc()); |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8670 | else if (IDVal == ".code") |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8671 | return parseDirectiveCode(DirectiveID.getLoc()); |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8672 | else if (IDVal == ".syntax") |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8673 | return parseDirectiveSyntax(DirectiveID.getLoc()); |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 8674 | else if (IDVal == ".unreq") |
| 8675 | return parseDirectiveUnreq(DirectiveID.getLoc()); |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8676 | else if (IDVal == ".fnend") |
| 8677 | return parseDirectiveFnEnd(DirectiveID.getLoc()); |
| 8678 | else if (IDVal == ".cantunwind") |
| 8679 | return parseDirectiveCantUnwind(DirectiveID.getLoc()); |
| 8680 | else if (IDVal == ".personality") |
| 8681 | return parseDirectivePersonality(DirectiveID.getLoc()); |
| 8682 | else if (IDVal == ".handlerdata") |
| 8683 | return parseDirectiveHandlerData(DirectiveID.getLoc()); |
| 8684 | else if (IDVal == ".setfp") |
| 8685 | return parseDirectiveSetFP(DirectiveID.getLoc()); |
| 8686 | else if (IDVal == ".pad") |
| 8687 | return parseDirectivePad(DirectiveID.getLoc()); |
| 8688 | else if (IDVal == ".save") |
| 8689 | return parseDirectiveRegSave(DirectiveID.getLoc(), false); |
| 8690 | else if (IDVal == ".vsave") |
| 8691 | return parseDirectiveRegSave(DirectiveID.getLoc(), true); |
Saleem Abdulrasool | 6e6c239 | 2013-12-20 07:21:16 +0000 | [diff] [blame] | 8692 | else if (IDVal == ".ltorg" || IDVal == ".pool") |
David Peixotto | 80c083a | 2013-12-19 18:26:07 +0000 | [diff] [blame] | 8693 | return parseDirectiveLtorg(DirectiveID.getLoc()); |
Saleem Abdulrasool | a554968 | 2013-12-26 01:52:28 +0000 | [diff] [blame] | 8694 | else if (IDVal == ".even") |
| 8695 | return parseDirectiveEven(DirectiveID.getLoc()); |
Saleem Abdulrasool | 662f5c1 | 2014-01-21 02:33:02 +0000 | [diff] [blame] | 8696 | else if (IDVal == ".personalityindex") |
| 8697 | return parseDirectivePersonalityIndex(DirectiveID.getLoc()); |
Saleem Abdulrasool | d9f0860 | 2014-01-21 02:33:10 +0000 | [diff] [blame] | 8698 | else if (IDVal == ".unwind_raw") |
| 8699 | return parseDirectiveUnwindRaw(DirectiveID.getLoc()); |
Saleem Abdulrasool | 5d962d3 | 2014-01-30 04:46:24 +0000 | [diff] [blame] | 8700 | else if (IDVal == ".movsp") |
| 8701 | return parseDirectiveMovSP(DirectiveID.getLoc()); |
Saleem Abdulrasool | 49480bf | 2014-02-16 00:16:41 +0000 | [diff] [blame] | 8702 | else if (IDVal == ".arch_extension") |
| 8703 | return parseDirectiveArchExtension(DirectiveID.getLoc()); |
Saleem Abdulrasool | fd6ed1e | 2014-02-23 17:45:32 +0000 | [diff] [blame] | 8704 | else if (IDVal == ".align") |
| 8705 | return parseDirectiveAlign(DirectiveID.getLoc()); |
Saleem Abdulrasool | 39f773f | 2014-03-20 06:05:33 +0000 | [diff] [blame] | 8706 | else if (IDVal == ".thumb_set") |
| 8707 | return parseDirectiveThumbSet(DirectiveID.getLoc()); |
Saleem Abdulrasool | dd979e6 | 2014-04-05 22:09:51 +0000 | [diff] [blame] | 8708 | |
Saleem Abdulrasool | bfdfb14 | 2014-09-18 04:28:29 +0000 | [diff] [blame] | 8709 | if (!IsMachO && !IsCOFF) { |
Saleem Abdulrasool | dd979e6 | 2014-04-05 22:09:51 +0000 | [diff] [blame] | 8710 | if (IDVal == ".arch") |
| 8711 | return parseDirectiveArch(DirectiveID.getLoc()); |
| 8712 | else if (IDVal == ".cpu") |
| 8713 | return parseDirectiveCPU(DirectiveID.getLoc()); |
| 8714 | else if (IDVal == ".eabi_attribute") |
| 8715 | return parseDirectiveEabiAttr(DirectiveID.getLoc()); |
| 8716 | else if (IDVal == ".fpu") |
| 8717 | return parseDirectiveFPU(DirectiveID.getLoc()); |
| 8718 | else if (IDVal == ".fnstart") |
| 8719 | return parseDirectiveFnStart(DirectiveID.getLoc()); |
| 8720 | else if (IDVal == ".inst") |
| 8721 | return parseDirectiveInst(DirectiveID.getLoc()); |
| 8722 | else if (IDVal == ".inst.n") |
| 8723 | return parseDirectiveInst(DirectiveID.getLoc(), 'n'); |
| 8724 | else if (IDVal == ".inst.w") |
| 8725 | return parseDirectiveInst(DirectiveID.getLoc(), 'w'); |
| 8726 | else if (IDVal == ".object_arch") |
| 8727 | return parseDirectiveObjectArch(DirectiveID.getLoc()); |
| 8728 | else if (IDVal == ".tlsdescseq") |
| 8729 | return parseDirectiveTLSDescSeq(DirectiveID.getLoc()); |
| 8730 | } |
| 8731 | |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 8732 | return true; |
| 8733 | } |
| 8734 | |
Saleem Abdulrasool | 3897651 | 2014-02-23 06:22:09 +0000 | [diff] [blame] | 8735 | /// parseLiteralValues |
| 8736 | /// ::= .hword expression [, expression]* |
| 8737 | /// ::= .short expression [, expression]* |
| 8738 | /// ::= .word expression [, expression]* |
| 8739 | bool ARMAsmParser::parseLiteralValues(unsigned Size, SMLoc L) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 8740 | MCAsmParser &Parser = getParser(); |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 8741 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
| 8742 | for (;;) { |
| 8743 | const MCExpr *Value; |
Saleem Abdulrasool | a903661 | 2014-01-26 22:29:50 +0000 | [diff] [blame] | 8744 | if (getParser().parseExpression(Value)) { |
| 8745 | Parser.eatToEndOfStatement(); |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 8746 | return false; |
Saleem Abdulrasool | a903661 | 2014-01-26 22:29:50 +0000 | [diff] [blame] | 8747 | } |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 8748 | |
Eric Christopher | bf7bc49 | 2013-01-09 03:52:05 +0000 | [diff] [blame] | 8749 | getParser().getStreamer().EmitValue(Value, Size); |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 8750 | |
| 8751 | if (getLexer().is(AsmToken::EndOfStatement)) |
| 8752 | break; |
Jim Grosbach | 624bcc7 | 2010-10-29 14:46:02 +0000 | [diff] [blame] | 8753 | |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 8754 | // FIXME: Improve diagnostic. |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 8755 | if (getLexer().isNot(AsmToken::Comma)) { |
| 8756 | Error(L, "unexpected token in directive"); |
| 8757 | return false; |
| 8758 | } |
Sean Callanan | a83fd7d | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 8759 | Parser.Lex(); |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 8760 | } |
| 8761 | } |
| 8762 | |
Sean Callanan | a83fd7d | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 8763 | Parser.Lex(); |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 8764 | return false; |
| 8765 | } |
| 8766 | |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8767 | /// parseDirectiveThumb |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8768 | /// ::= .thumb |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8769 | bool ARMAsmParser::parseDirectiveThumb(SMLoc L) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 8770 | MCAsmParser &Parser = getParser(); |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 8771 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
| 8772 | Error(L, "unexpected token in directive"); |
| 8773 | return false; |
| 8774 | } |
Sean Callanan | a83fd7d | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 8775 | Parser.Lex(); |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8776 | |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 8777 | if (!hasThumb()) { |
| 8778 | Error(L, "target does not support Thumb mode"); |
| 8779 | return false; |
| 8780 | } |
Tim Northover | a2292d0 | 2013-06-10 23:20:58 +0000 | [diff] [blame] | 8781 | |
Jim Grosbach | 7f88239 | 2011-12-07 18:04:19 +0000 | [diff] [blame] | 8782 | if (!isThumb()) |
| 8783 | SwitchMode(); |
Saleem Abdulrasool | 44419fc | 2014-03-22 19:26:18 +0000 | [diff] [blame] | 8784 | |
Jim Grosbach | 7f88239 | 2011-12-07 18:04:19 +0000 | [diff] [blame] | 8785 | getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16); |
| 8786 | return false; |
| 8787 | } |
| 8788 | |
| 8789 | /// parseDirectiveARM |
| 8790 | /// ::= .arm |
| 8791 | bool ARMAsmParser::parseDirectiveARM(SMLoc L) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 8792 | MCAsmParser &Parser = getParser(); |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 8793 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
| 8794 | Error(L, "unexpected token in directive"); |
| 8795 | return false; |
| 8796 | } |
Jim Grosbach | 7f88239 | 2011-12-07 18:04:19 +0000 | [diff] [blame] | 8797 | Parser.Lex(); |
| 8798 | |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 8799 | if (!hasARM()) { |
| 8800 | Error(L, "target does not support ARM mode"); |
| 8801 | return false; |
| 8802 | } |
Tim Northover | a2292d0 | 2013-06-10 23:20:58 +0000 | [diff] [blame] | 8803 | |
Jim Grosbach | 7f88239 | 2011-12-07 18:04:19 +0000 | [diff] [blame] | 8804 | if (isThumb()) |
| 8805 | SwitchMode(); |
Saleem Abdulrasool | 44419fc | 2014-03-22 19:26:18 +0000 | [diff] [blame] | 8806 | |
Jim Grosbach | 7f88239 | 2011-12-07 18:04:19 +0000 | [diff] [blame] | 8807 | getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32); |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8808 | return false; |
| 8809 | } |
| 8810 | |
Tim Northover | 1744d0a | 2013-10-25 12:49:50 +0000 | [diff] [blame] | 8811 | void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) { |
| 8812 | if (NextSymbolIsThumb) { |
| 8813 | getParser().getStreamer().EmitThumbFunc(Symbol); |
| 8814 | NextSymbolIsThumb = false; |
| 8815 | } |
| 8816 | } |
| 8817 | |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8818 | /// parseDirectiveThumbFunc |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8819 | /// ::= .thumbfunc symbol_name |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8820 | bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 8821 | MCAsmParser &Parser = getParser(); |
Saleem Abdulrasool | 8c61c6c | 2014-09-18 03:49:55 +0000 | [diff] [blame] | 8822 | const auto Format = getContext().getObjectFileInfo()->getObjectFileType(); |
| 8823 | bool IsMachO = Format == MCObjectFileInfo::IsMachO; |
Rafael Espindola | e90c1cb | 2011-05-16 16:17:21 +0000 | [diff] [blame] | 8824 | |
Jim Grosbach | 1152cc0 | 2011-12-21 22:30:16 +0000 | [diff] [blame] | 8825 | // Darwin asm has (optionally) function name after .thumb_func direction |
Rafael Espindola | e90c1cb | 2011-05-16 16:17:21 +0000 | [diff] [blame] | 8826 | // ELF doesn't |
Saleem Abdulrasool | 8c61c6c | 2014-09-18 03:49:55 +0000 | [diff] [blame] | 8827 | if (IsMachO) { |
Rafael Espindola | e90c1cb | 2011-05-16 16:17:21 +0000 | [diff] [blame] | 8828 | const AsmToken &Tok = Parser.getTok(); |
Jim Grosbach | 1152cc0 | 2011-12-21 22:30:16 +0000 | [diff] [blame] | 8829 | if (Tok.isNot(AsmToken::EndOfStatement)) { |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 8830 | if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String)) { |
| 8831 | Error(L, "unexpected token in .thumb_func directive"); |
| 8832 | return false; |
| 8833 | } |
| 8834 | |
Tim Northover | 1744d0a | 2013-10-25 12:49:50 +0000 | [diff] [blame] | 8835 | MCSymbol *Func = |
| 8836 | getParser().getContext().GetOrCreateSymbol(Tok.getIdentifier()); |
| 8837 | getParser().getStreamer().EmitThumbFunc(Func); |
Jim Grosbach | 1152cc0 | 2011-12-21 22:30:16 +0000 | [diff] [blame] | 8838 | Parser.Lex(); // Consume the identifier token. |
Tim Northover | 1744d0a | 2013-10-25 12:49:50 +0000 | [diff] [blame] | 8839 | return false; |
Jim Grosbach | 1152cc0 | 2011-12-21 22:30:16 +0000 | [diff] [blame] | 8840 | } |
Rafael Espindola | e90c1cb | 2011-05-16 16:17:21 +0000 | [diff] [blame] | 8841 | } |
| 8842 | |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 8843 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
Saleem Abdulrasool | 8c61c6c | 2014-09-18 03:49:55 +0000 | [diff] [blame] | 8844 | Error(Parser.getTok().getLoc(), "unexpected token in directive"); |
| 8845 | Parser.eatToEndOfStatement(); |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 8846 | return false; |
| 8847 | } |
Jim Grosbach | 1152cc0 | 2011-12-21 22:30:16 +0000 | [diff] [blame] | 8848 | |
Tim Northover | 1744d0a | 2013-10-25 12:49:50 +0000 | [diff] [blame] | 8849 | NextSymbolIsThumb = true; |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8850 | return false; |
| 8851 | } |
| 8852 | |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8853 | /// parseDirectiveSyntax |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8854 | /// ::= .syntax unified | divided |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8855 | bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 8856 | MCAsmParser &Parser = getParser(); |
Sean Callanan | 936b0d3 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 8857 | const AsmToken &Tok = Parser.getTok(); |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 8858 | if (Tok.isNot(AsmToken::Identifier)) { |
| 8859 | Error(L, "unexpected token in .syntax directive"); |
| 8860 | return false; |
| 8861 | } |
| 8862 | |
Benjamin Kramer | 92d8998 | 2010-07-14 22:38:02 +0000 | [diff] [blame] | 8863 | StringRef Mode = Tok.getString(); |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 8864 | if (Mode == "unified" || Mode == "UNIFIED") { |
Sean Callanan | a83fd7d | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 8865 | Parser.Lex(); |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 8866 | } else if (Mode == "divided" || Mode == "DIVIDED") { |
| 8867 | Error(L, "'.syntax divided' arm asssembly not supported"); |
| 8868 | return false; |
| 8869 | } else { |
| 8870 | Error(L, "unrecognized syntax mode in .syntax directive"); |
| 8871 | return false; |
| 8872 | } |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8873 | |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8874 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
| 8875 | Error(Parser.getTok().getLoc(), "unexpected token in directive"); |
| 8876 | return false; |
| 8877 | } |
Sean Callanan | a83fd7d | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 8878 | Parser.Lex(); |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8879 | |
| 8880 | // TODO tell the MC streamer the mode |
| 8881 | // getParser().getStreamer().Emit???(); |
| 8882 | return false; |
| 8883 | } |
| 8884 | |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8885 | /// parseDirectiveCode |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8886 | /// ::= .code 16 | 32 |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8887 | bool ARMAsmParser::parseDirectiveCode(SMLoc L) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 8888 | MCAsmParser &Parser = getParser(); |
Sean Callanan | 936b0d3 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 8889 | const AsmToken &Tok = Parser.getTok(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8890 | if (Tok.isNot(AsmToken::Integer)) { |
| 8891 | Error(L, "unexpected token in .code directive"); |
| 8892 | return false; |
| 8893 | } |
Sean Callanan | 936b0d3 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 8894 | int64_t Val = Parser.getTok().getIntVal(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8895 | if (Val != 16 && Val != 32) { |
| 8896 | Error(L, "invalid operand to .code directive"); |
| 8897 | return false; |
| 8898 | } |
| 8899 | Parser.Lex(); |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8900 | |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8901 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
| 8902 | Error(Parser.getTok().getLoc(), "unexpected token in directive"); |
| 8903 | return false; |
| 8904 | } |
Sean Callanan | a83fd7d | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 8905 | Parser.Lex(); |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8906 | |
Evan Cheng | 284b467 | 2011-07-08 22:36:29 +0000 | [diff] [blame] | 8907 | if (Val == 16) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8908 | if (!hasThumb()) { |
| 8909 | Error(L, "target does not support Thumb mode"); |
| 8910 | return false; |
| 8911 | } |
Tim Northover | a2292d0 | 2013-06-10 23:20:58 +0000 | [diff] [blame] | 8912 | |
Jim Grosbach | f471ac3 | 2011-09-06 18:46:23 +0000 | [diff] [blame] | 8913 | if (!isThumb()) |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 8914 | SwitchMode(); |
Jim Grosbach | f471ac3 | 2011-09-06 18:46:23 +0000 | [diff] [blame] | 8915 | getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16); |
Evan Cheng | 284b467 | 2011-07-08 22:36:29 +0000 | [diff] [blame] | 8916 | } else { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8917 | if (!hasARM()) { |
| 8918 | Error(L, "target does not support ARM mode"); |
| 8919 | return false; |
| 8920 | } |
Tim Northover | a2292d0 | 2013-06-10 23:20:58 +0000 | [diff] [blame] | 8921 | |
Jim Grosbach | f471ac3 | 2011-09-06 18:46:23 +0000 | [diff] [blame] | 8922 | if (isThumb()) |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 8923 | SwitchMode(); |
Jim Grosbach | f471ac3 | 2011-09-06 18:46:23 +0000 | [diff] [blame] | 8924 | getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32); |
Evan Cheng | 45543ba | 2011-07-08 22:49:55 +0000 | [diff] [blame] | 8925 | } |
Jim Grosbach | 2db0ea0 | 2010-11-05 22:40:53 +0000 | [diff] [blame] | 8926 | |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8927 | return false; |
| 8928 | } |
| 8929 | |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 8930 | /// parseDirectiveReq |
| 8931 | /// ::= name .req registername |
| 8932 | bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 8933 | MCAsmParser &Parser = getParser(); |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 8934 | Parser.Lex(); // Eat the '.req' token. |
| 8935 | unsigned Reg; |
| 8936 | SMLoc SRegLoc, ERegLoc; |
| 8937 | if (ParseRegister(Reg, SRegLoc, ERegLoc)) { |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 8938 | Parser.eatToEndOfStatement(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8939 | Error(SRegLoc, "register name expected"); |
| 8940 | return false; |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 8941 | } |
| 8942 | |
| 8943 | // Shouldn't be anything else. |
| 8944 | if (Parser.getTok().isNot(AsmToken::EndOfStatement)) { |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 8945 | Parser.eatToEndOfStatement(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8946 | Error(Parser.getTok().getLoc(), "unexpected input in .req directive."); |
| 8947 | return false; |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 8948 | } |
| 8949 | |
| 8950 | Parser.Lex(); // Consume the EndOfStatement |
| 8951 | |
David Blaikie | 5106ce7 | 2014-11-19 05:49:42 +0000 | [diff] [blame] | 8952 | if (!RegisterReqs.insert(std::make_pair(Name, Reg)).second) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8953 | Error(SRegLoc, "redefinition of '" + Name + "' does not match original."); |
| 8954 | return false; |
| 8955 | } |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 8956 | |
| 8957 | return false; |
| 8958 | } |
| 8959 | |
| 8960 | /// parseDirectiveUneq |
| 8961 | /// ::= .unreq registername |
| 8962 | bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 8963 | MCAsmParser &Parser = getParser(); |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 8964 | if (Parser.getTok().isNot(AsmToken::Identifier)) { |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 8965 | Parser.eatToEndOfStatement(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8966 | Error(L, "unexpected input in .unreq directive."); |
| 8967 | return false; |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 8968 | } |
Duncan P. N. Exon Smith | 29db0eb | 2014-03-07 16:16:52 +0000 | [diff] [blame] | 8969 | RegisterReqs.erase(Parser.getTok().getIdentifier().lower()); |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 8970 | Parser.Lex(); // Eat the identifier. |
| 8971 | return false; |
| 8972 | } |
| 8973 | |
Jason W Kim | 135d244 | 2011-12-20 17:38:12 +0000 | [diff] [blame] | 8974 | /// parseDirectiveArch |
| 8975 | /// ::= .arch token |
| 8976 | bool ARMAsmParser::parseDirectiveArch(SMLoc L) { |
Logan Chien | 439e8f9 | 2013-12-11 17:16:25 +0000 | [diff] [blame] | 8977 | StringRef Arch = getParser().parseStringToEndOfStatement().trim(); |
| 8978 | |
| 8979 | unsigned ID = StringSwitch<unsigned>(Arch) |
| 8980 | #define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \ |
| 8981 | .Case(NAME, ARM::ID) |
Joerg Sonnenberger | a13f8b4 | 2013-12-26 11:50:28 +0000 | [diff] [blame] | 8982 | #define ARM_ARCH_ALIAS(NAME, ID) \ |
| 8983 | .Case(NAME, ARM::ID) |
Logan Chien | 439e8f9 | 2013-12-11 17:16:25 +0000 | [diff] [blame] | 8984 | #include "MCTargetDesc/ARMArchName.def" |
| 8985 | .Default(ARM::INVALID_ARCH); |
| 8986 | |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8987 | if (ID == ARM::INVALID_ARCH) { |
| 8988 | Error(L, "Unknown arch name"); |
| 8989 | return false; |
| 8990 | } |
Logan Chien | 439e8f9 | 2013-12-11 17:16:25 +0000 | [diff] [blame] | 8991 | |
| 8992 | getTargetStreamer().emitArch(ID); |
| 8993 | return false; |
Jason W Kim | 135d244 | 2011-12-20 17:38:12 +0000 | [diff] [blame] | 8994 | } |
| 8995 | |
| 8996 | /// parseDirectiveEabiAttr |
Saleem Abdulrasool | 87ccd36 | 2014-01-07 02:28:42 +0000 | [diff] [blame] | 8997 | /// ::= .eabi_attribute int, int [, "str"] |
| 8998 | /// ::= .eabi_attribute Tag_name, int [, "str"] |
Jason W Kim | 135d244 | 2011-12-20 17:38:12 +0000 | [diff] [blame] | 8999 | bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 9000 | MCAsmParser &Parser = getParser(); |
Saleem Abdulrasool | 87ccd36 | 2014-01-07 02:28:42 +0000 | [diff] [blame] | 9001 | int64_t Tag; |
| 9002 | SMLoc TagLoc; |
Saleem Abdulrasool | 87ccd36 | 2014-01-07 02:28:42 +0000 | [diff] [blame] | 9003 | TagLoc = Parser.getTok().getLoc(); |
| 9004 | if (Parser.getTok().is(AsmToken::Identifier)) { |
| 9005 | StringRef Name = Parser.getTok().getIdentifier(); |
| 9006 | Tag = ARMBuildAttrs::AttrTypeFromString(Name); |
| 9007 | if (Tag == -1) { |
| 9008 | Error(TagLoc, "attribute name not recognised: " + Name); |
| 9009 | Parser.eatToEndOfStatement(); |
| 9010 | return false; |
| 9011 | } |
| 9012 | Parser.Lex(); |
| 9013 | } else { |
| 9014 | const MCExpr *AttrExpr; |
| 9015 | |
| 9016 | TagLoc = Parser.getTok().getLoc(); |
| 9017 | if (Parser.parseExpression(AttrExpr)) { |
| 9018 | Parser.eatToEndOfStatement(); |
| 9019 | return false; |
| 9020 | } |
| 9021 | |
| 9022 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(AttrExpr); |
| 9023 | if (!CE) { |
| 9024 | Error(TagLoc, "expected numeric constant"); |
| 9025 | Parser.eatToEndOfStatement(); |
| 9026 | return false; |
| 9027 | } |
| 9028 | |
| 9029 | Tag = CE->getValue(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9030 | } |
Logan Chien | 8cbb80d | 2013-10-28 17:51:12 +0000 | [diff] [blame] | 9031 | |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9032 | if (Parser.getTok().isNot(AsmToken::Comma)) { |
Saleem Abdulrasool | 87ccd36 | 2014-01-07 02:28:42 +0000 | [diff] [blame] | 9033 | Error(Parser.getTok().getLoc(), "comma expected"); |
| 9034 | Parser.eatToEndOfStatement(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9035 | return false; |
| 9036 | } |
Logan Chien | 8cbb80d | 2013-10-28 17:51:12 +0000 | [diff] [blame] | 9037 | Parser.Lex(); // skip comma |
| 9038 | |
Saleem Abdulrasool | 87ccd36 | 2014-01-07 02:28:42 +0000 | [diff] [blame] | 9039 | StringRef StringValue = ""; |
| 9040 | bool IsStringValue = false; |
Logan Chien | 8cbb80d | 2013-10-28 17:51:12 +0000 | [diff] [blame] | 9041 | |
Saleem Abdulrasool | 87ccd36 | 2014-01-07 02:28:42 +0000 | [diff] [blame] | 9042 | int64_t IntegerValue = 0; |
| 9043 | bool IsIntegerValue = false; |
| 9044 | |
| 9045 | if (Tag == ARMBuildAttrs::CPU_raw_name || Tag == ARMBuildAttrs::CPU_name) |
| 9046 | IsStringValue = true; |
| 9047 | else if (Tag == ARMBuildAttrs::compatibility) { |
| 9048 | IsStringValue = true; |
| 9049 | IsIntegerValue = true; |
Saleem Abdulrasool | 9dedf64 | 2014-01-19 08:25:19 +0000 | [diff] [blame] | 9050 | } else if (Tag < 32 || Tag % 2 == 0) |
Saleem Abdulrasool | 87ccd36 | 2014-01-07 02:28:42 +0000 | [diff] [blame] | 9051 | IsIntegerValue = true; |
| 9052 | else if (Tag % 2 == 1) |
| 9053 | IsStringValue = true; |
| 9054 | else |
| 9055 | llvm_unreachable("invalid tag type"); |
| 9056 | |
| 9057 | if (IsIntegerValue) { |
| 9058 | const MCExpr *ValueExpr; |
| 9059 | SMLoc ValueExprLoc = Parser.getTok().getLoc(); |
| 9060 | if (Parser.parseExpression(ValueExpr)) { |
| 9061 | Parser.eatToEndOfStatement(); |
| 9062 | return false; |
| 9063 | } |
| 9064 | |
| 9065 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ValueExpr); |
| 9066 | if (!CE) { |
| 9067 | Error(ValueExprLoc, "expected numeric constant"); |
| 9068 | Parser.eatToEndOfStatement(); |
| 9069 | return false; |
| 9070 | } |
| 9071 | |
| 9072 | IntegerValue = CE->getValue(); |
| 9073 | } |
| 9074 | |
| 9075 | if (Tag == ARMBuildAttrs::compatibility) { |
| 9076 | if (Parser.getTok().isNot(AsmToken::Comma)) |
| 9077 | IsStringValue = false; |
| 9078 | else |
| 9079 | Parser.Lex(); |
| 9080 | } |
| 9081 | |
| 9082 | if (IsStringValue) { |
| 9083 | if (Parser.getTok().isNot(AsmToken::String)) { |
| 9084 | Error(Parser.getTok().getLoc(), "bad string constant"); |
| 9085 | Parser.eatToEndOfStatement(); |
| 9086 | return false; |
| 9087 | } |
| 9088 | |
| 9089 | StringValue = Parser.getTok().getStringContents(); |
| 9090 | Parser.Lex(); |
| 9091 | } |
| 9092 | |
| 9093 | if (IsIntegerValue && IsStringValue) { |
| 9094 | assert(Tag == ARMBuildAttrs::compatibility); |
| 9095 | getTargetStreamer().emitIntTextAttribute(Tag, IntegerValue, StringValue); |
| 9096 | } else if (IsIntegerValue) |
| 9097 | getTargetStreamer().emitAttribute(Tag, IntegerValue); |
| 9098 | else if (IsStringValue) |
| 9099 | getTargetStreamer().emitTextAttribute(Tag, StringValue); |
Logan Chien | 8cbb80d | 2013-10-28 17:51:12 +0000 | [diff] [blame] | 9100 | return false; |
| 9101 | } |
| 9102 | |
| 9103 | /// parseDirectiveCPU |
| 9104 | /// ::= .cpu str |
| 9105 | bool ARMAsmParser::parseDirectiveCPU(SMLoc L) { |
| 9106 | StringRef CPU = getParser().parseStringToEndOfStatement().trim(); |
| 9107 | getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name, CPU); |
Roman Divacky | 7e6b595 | 2014-12-02 20:03:22 +0000 | [diff] [blame] | 9108 | |
Roman Divacky | fdf0560 | 2014-12-03 18:39:44 +0000 | [diff] [blame] | 9109 | if (!STI.isCPUStringValid(CPU)) { |
Roman Divacky | 7e6b595 | 2014-12-02 20:03:22 +0000 | [diff] [blame] | 9110 | Error(L, "Unknown CPU name"); |
| 9111 | return false; |
| 9112 | } |
| 9113 | |
Roman Divacky | 6fd64ff | 2014-12-04 21:39:24 +0000 | [diff] [blame^] | 9114 | // FIXME: This switches the CPU features globally, therefore it might |
| 9115 | // happen that code you would not expect to assemble will. For details |
| 9116 | // see: http://llvm.org/bugs/show_bug.cgi?id=20757 |
Roman Divacky | 7e6b595 | 2014-12-02 20:03:22 +0000 | [diff] [blame] | 9117 | STI.InitMCProcessorInfo(CPU, ""); |
| 9118 | STI.InitCPUSchedModel(CPU); |
| 9119 | unsigned FB = ComputeAvailableFeatures(STI.getFeatureBits()); |
| 9120 | setAvailableFeatures(FB); |
| 9121 | |
Logan Chien | 8cbb80d | 2013-10-28 17:51:12 +0000 | [diff] [blame] | 9122 | return false; |
| 9123 | } |
| 9124 | |
Nico Weber | ae050bb | 2014-08-16 05:37:51 +0000 | [diff] [blame] | 9125 | // FIXME: This is duplicated in getARMFPUFeatures() in |
| 9126 | // tools/clang/lib/Driver/Tools.cpp |
| 9127 | static const struct { |
| 9128 | const unsigned Fpu; |
| 9129 | const uint64_t Enabled; |
| 9130 | const uint64_t Disabled; |
| 9131 | } Fpus[] = { |
| 9132 | {ARM::VFP, ARM::FeatureVFP2, ARM::FeatureNEON}, |
| 9133 | {ARM::VFPV2, ARM::FeatureVFP2, ARM::FeatureNEON}, |
| 9134 | {ARM::VFPV3, ARM::FeatureVFP3, ARM::FeatureNEON}, |
| 9135 | {ARM::VFPV3_D16, ARM::FeatureVFP3 | ARM::FeatureD16, ARM::FeatureNEON}, |
| 9136 | {ARM::VFPV4, ARM::FeatureVFP4, ARM::FeatureNEON}, |
| 9137 | {ARM::VFPV4_D16, ARM::FeatureVFP4 | ARM::FeatureD16, ARM::FeatureNEON}, |
Oliver Stannard | 37e4daa | 2014-10-01 09:02:17 +0000 | [diff] [blame] | 9138 | {ARM::FPV5_D16, ARM::FeatureFPARMv8 | ARM::FeatureD16, |
| 9139 | ARM::FeatureNEON | ARM::FeatureCrypto}, |
Nico Weber | ae050bb | 2014-08-16 05:37:51 +0000 | [diff] [blame] | 9140 | {ARM::FP_ARMV8, ARM::FeatureFPARMv8, |
| 9141 | ARM::FeatureNEON | ARM::FeatureCrypto}, |
| 9142 | {ARM::NEON, ARM::FeatureNEON, 0}, |
| 9143 | {ARM::NEON_VFPV4, ARM::FeatureVFP4 | ARM::FeatureNEON, 0}, |
| 9144 | {ARM::NEON_FP_ARMV8, ARM::FeatureFPARMv8 | ARM::FeatureNEON, |
| 9145 | ARM::FeatureCrypto}, |
| 9146 | {ARM::CRYPTO_NEON_FP_ARMV8, |
| 9147 | ARM::FeatureFPARMv8 | ARM::FeatureNEON | ARM::FeatureCrypto, 0}, |
| 9148 | {ARM::SOFTVFP, 0, 0}, |
| 9149 | }; |
| 9150 | |
Logan Chien | 8cbb80d | 2013-10-28 17:51:12 +0000 | [diff] [blame] | 9151 | /// parseDirectiveFPU |
| 9152 | /// ::= .fpu str |
| 9153 | bool ARMAsmParser::parseDirectiveFPU(SMLoc L) { |
| 9154 | StringRef FPU = getParser().parseStringToEndOfStatement().trim(); |
| 9155 | |
| 9156 | unsigned ID = StringSwitch<unsigned>(FPU) |
| 9157 | #define ARM_FPU_NAME(NAME, ID) .Case(NAME, ARM::ID) |
| 9158 | #include "ARMFPUName.def" |
| 9159 | .Default(ARM::INVALID_FPU); |
| 9160 | |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9161 | if (ID == ARM::INVALID_FPU) { |
| 9162 | Error(L, "Unknown FPU name"); |
| 9163 | return false; |
| 9164 | } |
Logan Chien | 8cbb80d | 2013-10-28 17:51:12 +0000 | [diff] [blame] | 9165 | |
Nico Weber | ae050bb | 2014-08-16 05:37:51 +0000 | [diff] [blame] | 9166 | for (const auto &Fpu : Fpus) { |
| 9167 | if (Fpu.Fpu != ID) |
| 9168 | continue; |
| 9169 | |
| 9170 | // Need to toggle features that should be on but are off and that |
| 9171 | // should off but are on. |
Tim Northover | 26bb14e | 2014-08-18 11:49:42 +0000 | [diff] [blame] | 9172 | uint64_t Toggle = (Fpu.Enabled & ~STI.getFeatureBits()) | |
Nico Weber | ae050bb | 2014-08-16 05:37:51 +0000 | [diff] [blame] | 9173 | (Fpu.Disabled & STI.getFeatureBits()); |
| 9174 | setAvailableFeatures(ComputeAvailableFeatures(STI.ToggleFeature(Toggle))); |
| 9175 | break; |
| 9176 | } |
| 9177 | |
Logan Chien | 8cbb80d | 2013-10-28 17:51:12 +0000 | [diff] [blame] | 9178 | getTargetStreamer().emitFPU(ID); |
| 9179 | return false; |
Jason W Kim | 135d244 | 2011-12-20 17:38:12 +0000 | [diff] [blame] | 9180 | } |
| 9181 | |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9182 | /// parseDirectiveFnStart |
| 9183 | /// ::= .fnstart |
| 9184 | bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) { |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9185 | if (UC.hasFnStart()) { |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9186 | Error(L, ".fnstart starts before the end of previous one"); |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9187 | UC.emitFnStartLocNotes(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9188 | return false; |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9189 | } |
| 9190 | |
Saleem Abdulrasool | 662f5c1 | 2014-01-21 02:33:02 +0000 | [diff] [blame] | 9191 | // Reset the unwind directives parser state |
| 9192 | UC.reset(); |
| 9193 | |
Rafael Espindola | a17151a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 9194 | getTargetStreamer().emitFnStart(); |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9195 | |
| 9196 | UC.recordFnStart(L); |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9197 | return false; |
| 9198 | } |
| 9199 | |
| 9200 | /// parseDirectiveFnEnd |
| 9201 | /// ::= .fnend |
| 9202 | bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) { |
| 9203 | // Check the ordering of unwind directives |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9204 | if (!UC.hasFnStart()) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9205 | Error(L, ".fnstart must precede .fnend directive"); |
| 9206 | return false; |
| 9207 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9208 | |
| 9209 | // Reset the unwind directives parser state |
Rafael Espindola | a17151a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 9210 | getTargetStreamer().emitFnEnd(); |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9211 | |
| 9212 | UC.reset(); |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9213 | return false; |
| 9214 | } |
| 9215 | |
| 9216 | /// parseDirectiveCantUnwind |
| 9217 | /// ::= .cantunwind |
| 9218 | bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) { |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9219 | UC.recordCantUnwind(L); |
| 9220 | |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9221 | // Check the ordering of unwind directives |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9222 | if (!UC.hasFnStart()) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9223 | Error(L, ".fnstart must precede .cantunwind directive"); |
| 9224 | return false; |
| 9225 | } |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9226 | if (UC.hasHandlerData()) { |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9227 | Error(L, ".cantunwind can't be used with .handlerdata directive"); |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9228 | UC.emitHandlerDataLocNotes(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9229 | return false; |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9230 | } |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9231 | if (UC.hasPersonality()) { |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9232 | Error(L, ".cantunwind can't be used with .personality directive"); |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9233 | UC.emitPersonalityLocNotes(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9234 | return false; |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9235 | } |
| 9236 | |
Rafael Espindola | a17151a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 9237 | getTargetStreamer().emitCantUnwind(); |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9238 | return false; |
| 9239 | } |
| 9240 | |
| 9241 | /// parseDirectivePersonality |
| 9242 | /// ::= .personality name |
| 9243 | bool ARMAsmParser::parseDirectivePersonality(SMLoc L) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 9244 | MCAsmParser &Parser = getParser(); |
Saleem Abdulrasool | 662f5c1 | 2014-01-21 02:33:02 +0000 | [diff] [blame] | 9245 | bool HasExistingPersonality = UC.hasPersonality(); |
| 9246 | |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9247 | UC.recordPersonality(L); |
| 9248 | |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9249 | // Check the ordering of unwind directives |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9250 | if (!UC.hasFnStart()) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9251 | Error(L, ".fnstart must precede .personality directive"); |
| 9252 | return false; |
| 9253 | } |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9254 | if (UC.cantUnwind()) { |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9255 | Error(L, ".personality can't be used with .cantunwind directive"); |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9256 | UC.emitCantUnwindLocNotes(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9257 | return false; |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9258 | } |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9259 | if (UC.hasHandlerData()) { |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9260 | Error(L, ".personality must precede .handlerdata directive"); |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9261 | UC.emitHandlerDataLocNotes(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9262 | return false; |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9263 | } |
Saleem Abdulrasool | 662f5c1 | 2014-01-21 02:33:02 +0000 | [diff] [blame] | 9264 | if (HasExistingPersonality) { |
| 9265 | Parser.eatToEndOfStatement(); |
| 9266 | Error(L, "multiple personality directives"); |
| 9267 | UC.emitPersonalityLocNotes(); |
| 9268 | return false; |
| 9269 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9270 | |
| 9271 | // Parse the name of the personality routine |
| 9272 | if (Parser.getTok().isNot(AsmToken::Identifier)) { |
| 9273 | Parser.eatToEndOfStatement(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9274 | Error(L, "unexpected input in .personality directive."); |
| 9275 | return false; |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9276 | } |
| 9277 | StringRef Name(Parser.getTok().getIdentifier()); |
| 9278 | Parser.Lex(); |
| 9279 | |
| 9280 | MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name); |
Rafael Espindola | a17151a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 9281 | getTargetStreamer().emitPersonality(PR); |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9282 | return false; |
| 9283 | } |
| 9284 | |
| 9285 | /// parseDirectiveHandlerData |
| 9286 | /// ::= .handlerdata |
| 9287 | bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) { |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9288 | UC.recordHandlerData(L); |
| 9289 | |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9290 | // Check the ordering of unwind directives |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9291 | if (!UC.hasFnStart()) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9292 | Error(L, ".fnstart must precede .personality directive"); |
| 9293 | return false; |
| 9294 | } |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9295 | if (UC.cantUnwind()) { |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9296 | Error(L, ".handlerdata can't be used with .cantunwind directive"); |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9297 | UC.emitCantUnwindLocNotes(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9298 | return false; |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9299 | } |
| 9300 | |
Rafael Espindola | a17151a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 9301 | getTargetStreamer().emitHandlerData(); |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9302 | return false; |
| 9303 | } |
| 9304 | |
| 9305 | /// parseDirectiveSetFP |
| 9306 | /// ::= .setfp fpreg, spreg [, offset] |
| 9307 | bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 9308 | MCAsmParser &Parser = getParser(); |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9309 | // Check the ordering of unwind directives |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9310 | if (!UC.hasFnStart()) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9311 | Error(L, ".fnstart must precede .setfp directive"); |
| 9312 | return false; |
| 9313 | } |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9314 | if (UC.hasHandlerData()) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9315 | Error(L, ".setfp must precede .handlerdata directive"); |
| 9316 | return false; |
| 9317 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9318 | |
| 9319 | // Parse fpreg |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9320 | SMLoc FPRegLoc = Parser.getTok().getLoc(); |
| 9321 | int FPReg = tryParseRegister(); |
| 9322 | if (FPReg == -1) { |
| 9323 | Error(FPRegLoc, "frame pointer register expected"); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9324 | return false; |
| 9325 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9326 | |
| 9327 | // Consume comma |
Saleem Abdulrasool | 5d962d3 | 2014-01-30 04:46:24 +0000 | [diff] [blame] | 9328 | if (Parser.getTok().isNot(AsmToken::Comma)) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9329 | Error(Parser.getTok().getLoc(), "comma expected"); |
| 9330 | return false; |
| 9331 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9332 | Parser.Lex(); // skip comma |
| 9333 | |
| 9334 | // Parse spreg |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9335 | SMLoc SPRegLoc = Parser.getTok().getLoc(); |
| 9336 | int SPReg = tryParseRegister(); |
| 9337 | if (SPReg == -1) { |
| 9338 | Error(SPRegLoc, "stack pointer register expected"); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9339 | return false; |
| 9340 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9341 | |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9342 | if (SPReg != ARM::SP && SPReg != UC.getFPReg()) { |
| 9343 | Error(SPRegLoc, "register should be either $sp or the latest fp register"); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9344 | return false; |
| 9345 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9346 | |
| 9347 | // Update the frame pointer register |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9348 | UC.saveFPReg(FPReg); |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9349 | |
| 9350 | // Parse offset |
| 9351 | int64_t Offset = 0; |
| 9352 | if (Parser.getTok().is(AsmToken::Comma)) { |
| 9353 | Parser.Lex(); // skip comma |
| 9354 | |
| 9355 | if (Parser.getTok().isNot(AsmToken::Hash) && |
| 9356 | Parser.getTok().isNot(AsmToken::Dollar)) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9357 | Error(Parser.getTok().getLoc(), "'#' expected"); |
| 9358 | return false; |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9359 | } |
| 9360 | Parser.Lex(); // skip hash token. |
| 9361 | |
| 9362 | const MCExpr *OffsetExpr; |
| 9363 | SMLoc ExLoc = Parser.getTok().getLoc(); |
| 9364 | SMLoc EndLoc; |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9365 | if (getParser().parseExpression(OffsetExpr, EndLoc)) { |
| 9366 | Error(ExLoc, "malformed setfp offset"); |
| 9367 | return false; |
| 9368 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9369 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9370 | if (!CE) { |
| 9371 | Error(ExLoc, "setfp offset must be an immediate"); |
| 9372 | return false; |
| 9373 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9374 | |
| 9375 | Offset = CE->getValue(); |
| 9376 | } |
| 9377 | |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9378 | getTargetStreamer().emitSetFP(static_cast<unsigned>(FPReg), |
| 9379 | static_cast<unsigned>(SPReg), Offset); |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9380 | return false; |
| 9381 | } |
| 9382 | |
| 9383 | /// parseDirective |
| 9384 | /// ::= .pad offset |
| 9385 | bool ARMAsmParser::parseDirectivePad(SMLoc L) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 9386 | MCAsmParser &Parser = getParser(); |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9387 | // Check the ordering of unwind directives |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9388 | if (!UC.hasFnStart()) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9389 | Error(L, ".fnstart must precede .pad directive"); |
| 9390 | return false; |
| 9391 | } |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9392 | if (UC.hasHandlerData()) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9393 | Error(L, ".pad must precede .handlerdata directive"); |
| 9394 | return false; |
| 9395 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9396 | |
| 9397 | // Parse the offset |
| 9398 | if (Parser.getTok().isNot(AsmToken::Hash) && |
| 9399 | Parser.getTok().isNot(AsmToken::Dollar)) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9400 | Error(Parser.getTok().getLoc(), "'#' expected"); |
| 9401 | return false; |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9402 | } |
| 9403 | Parser.Lex(); // skip hash token. |
| 9404 | |
| 9405 | const MCExpr *OffsetExpr; |
| 9406 | SMLoc ExLoc = Parser.getTok().getLoc(); |
| 9407 | SMLoc EndLoc; |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9408 | if (getParser().parseExpression(OffsetExpr, EndLoc)) { |
| 9409 | Error(ExLoc, "malformed pad offset"); |
| 9410 | return false; |
| 9411 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9412 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9413 | if (!CE) { |
| 9414 | Error(ExLoc, "pad offset must be an immediate"); |
| 9415 | return false; |
| 9416 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9417 | |
Rafael Espindola | a17151a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 9418 | getTargetStreamer().emitPad(CE->getValue()); |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9419 | return false; |
| 9420 | } |
| 9421 | |
| 9422 | /// parseDirectiveRegSave |
| 9423 | /// ::= .save { registers } |
| 9424 | /// ::= .vsave { registers } |
| 9425 | bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) { |
| 9426 | // Check the ordering of unwind directives |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9427 | if (!UC.hasFnStart()) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9428 | Error(L, ".fnstart must precede .save or .vsave directives"); |
| 9429 | return false; |
| 9430 | } |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9431 | if (UC.hasHandlerData()) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9432 | Error(L, ".save or .vsave must precede .handlerdata directive"); |
| 9433 | return false; |
| 9434 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9435 | |
Benjamin Kramer | 23632bd | 2013-08-03 22:16:24 +0000 | [diff] [blame] | 9436 | // RAII object to make sure parsed operands are deleted. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 9437 | SmallVector<std::unique_ptr<MCParsedAsmOperand>, 1> Operands; |
Benjamin Kramer | 23632bd | 2013-08-03 22:16:24 +0000 | [diff] [blame] | 9438 | |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9439 | // Parse the register list |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 9440 | if (parseRegisterList(Operands)) |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 9441 | return false; |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 9442 | ARMOperand &Op = (ARMOperand &)*Operands[0]; |
| 9443 | if (!IsVector && !Op.isRegList()) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9444 | Error(L, ".save expects GPR registers"); |
| 9445 | return false; |
| 9446 | } |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 9447 | if (IsVector && !Op.isDPRRegList()) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9448 | Error(L, ".vsave expects DPR registers"); |
| 9449 | return false; |
| 9450 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9451 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 9452 | getTargetStreamer().emitRegSave(Op.getRegList(), IsVector); |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9453 | return false; |
| 9454 | } |
| 9455 | |
Saleem Abdulrasool | c0da2cb | 2013-12-19 05:17:58 +0000 | [diff] [blame] | 9456 | /// parseDirectiveInst |
| 9457 | /// ::= .inst opcode [, ...] |
| 9458 | /// ::= .inst.n opcode [, ...] |
| 9459 | /// ::= .inst.w opcode [, ...] |
| 9460 | bool ARMAsmParser::parseDirectiveInst(SMLoc Loc, char Suffix) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 9461 | MCAsmParser &Parser = getParser(); |
Saleem Abdulrasool | c0da2cb | 2013-12-19 05:17:58 +0000 | [diff] [blame] | 9462 | int Width; |
| 9463 | |
| 9464 | if (isThumb()) { |
| 9465 | switch (Suffix) { |
| 9466 | case 'n': |
| 9467 | Width = 2; |
| 9468 | break; |
| 9469 | case 'w': |
| 9470 | Width = 4; |
| 9471 | break; |
| 9472 | default: |
| 9473 | Parser.eatToEndOfStatement(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9474 | Error(Loc, "cannot determine Thumb instruction size, " |
| 9475 | "use inst.n/inst.w instead"); |
| 9476 | return false; |
Saleem Abdulrasool | c0da2cb | 2013-12-19 05:17:58 +0000 | [diff] [blame] | 9477 | } |
| 9478 | } else { |
| 9479 | if (Suffix) { |
| 9480 | Parser.eatToEndOfStatement(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9481 | Error(Loc, "width suffixes are invalid in ARM mode"); |
| 9482 | return false; |
Saleem Abdulrasool | c0da2cb | 2013-12-19 05:17:58 +0000 | [diff] [blame] | 9483 | } |
| 9484 | Width = 4; |
| 9485 | } |
| 9486 | |
| 9487 | if (getLexer().is(AsmToken::EndOfStatement)) { |
| 9488 | Parser.eatToEndOfStatement(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9489 | Error(Loc, "expected expression following directive"); |
| 9490 | return false; |
Saleem Abdulrasool | c0da2cb | 2013-12-19 05:17:58 +0000 | [diff] [blame] | 9491 | } |
| 9492 | |
| 9493 | for (;;) { |
| 9494 | const MCExpr *Expr; |
| 9495 | |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9496 | if (getParser().parseExpression(Expr)) { |
| 9497 | Error(Loc, "expected expression"); |
| 9498 | return false; |
| 9499 | } |
Saleem Abdulrasool | c0da2cb | 2013-12-19 05:17:58 +0000 | [diff] [blame] | 9500 | |
| 9501 | const MCConstantExpr *Value = dyn_cast_or_null<MCConstantExpr>(Expr); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9502 | if (!Value) { |
| 9503 | Error(Loc, "expected constant expression"); |
| 9504 | return false; |
| 9505 | } |
Saleem Abdulrasool | c0da2cb | 2013-12-19 05:17:58 +0000 | [diff] [blame] | 9506 | |
| 9507 | switch (Width) { |
| 9508 | case 2: |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9509 | if (Value->getValue() > 0xffff) { |
| 9510 | Error(Loc, "inst.n operand is too big, use inst.w instead"); |
| 9511 | return false; |
| 9512 | } |
Saleem Abdulrasool | c0da2cb | 2013-12-19 05:17:58 +0000 | [diff] [blame] | 9513 | break; |
| 9514 | case 4: |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9515 | if (Value->getValue() > 0xffffffff) { |
| 9516 | Error(Loc, |
| 9517 | StringRef(Suffix ? "inst.w" : "inst") + " operand is too big"); |
| 9518 | return false; |
| 9519 | } |
Saleem Abdulrasool | c0da2cb | 2013-12-19 05:17:58 +0000 | [diff] [blame] | 9520 | break; |
| 9521 | default: |
| 9522 | llvm_unreachable("only supported widths are 2 and 4"); |
| 9523 | } |
| 9524 | |
| 9525 | getTargetStreamer().emitInst(Value->getValue(), Suffix); |
| 9526 | |
| 9527 | if (getLexer().is(AsmToken::EndOfStatement)) |
| 9528 | break; |
| 9529 | |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9530 | if (getLexer().isNot(AsmToken::Comma)) { |
| 9531 | Error(Loc, "unexpected token in directive"); |
| 9532 | return false; |
| 9533 | } |
Saleem Abdulrasool | c0da2cb | 2013-12-19 05:17:58 +0000 | [diff] [blame] | 9534 | |
| 9535 | Parser.Lex(); |
| 9536 | } |
| 9537 | |
| 9538 | Parser.Lex(); |
| 9539 | return false; |
| 9540 | } |
| 9541 | |
David Peixotto | 80c083a | 2013-12-19 18:26:07 +0000 | [diff] [blame] | 9542 | /// parseDirectiveLtorg |
Saleem Abdulrasool | 6e6c239 | 2013-12-20 07:21:16 +0000 | [diff] [blame] | 9543 | /// ::= .ltorg | .pool |
David Peixotto | 80c083a | 2013-12-19 18:26:07 +0000 | [diff] [blame] | 9544 | bool ARMAsmParser::parseDirectiveLtorg(SMLoc L) { |
David Peixotto | b9b7362 | 2014-02-04 17:22:40 +0000 | [diff] [blame] | 9545 | getTargetStreamer().emitCurrentConstantPool(); |
David Peixotto | 80c083a | 2013-12-19 18:26:07 +0000 | [diff] [blame] | 9546 | return false; |
| 9547 | } |
| 9548 | |
Saleem Abdulrasool | a554968 | 2013-12-26 01:52:28 +0000 | [diff] [blame] | 9549 | bool ARMAsmParser::parseDirectiveEven(SMLoc L) { |
| 9550 | const MCSection *Section = getStreamer().getCurrentSection().first; |
| 9551 | |
| 9552 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
| 9553 | TokError("unexpected token in directive"); |
| 9554 | return false; |
| 9555 | } |
| 9556 | |
| 9557 | if (!Section) { |
Rafael Espindola | 7b61ddf | 2014-10-15 16:12:52 +0000 | [diff] [blame] | 9558 | getStreamer().InitSections(false); |
Saleem Abdulrasool | a554968 | 2013-12-26 01:52:28 +0000 | [diff] [blame] | 9559 | Section = getStreamer().getCurrentSection().first; |
| 9560 | } |
| 9561 | |
Saleem Abdulrasool | 42b233a | 2014-03-18 05:26:55 +0000 | [diff] [blame] | 9562 | assert(Section && "must have section to emit alignment"); |
Saleem Abdulrasool | a554968 | 2013-12-26 01:52:28 +0000 | [diff] [blame] | 9563 | if (Section->UseCodeAlign()) |
Rafael Espindola | 7b51496 | 2014-02-04 18:34:04 +0000 | [diff] [blame] | 9564 | getStreamer().EmitCodeAlignment(2); |
Saleem Abdulrasool | a554968 | 2013-12-26 01:52:28 +0000 | [diff] [blame] | 9565 | else |
Rafael Espindola | 7b51496 | 2014-02-04 18:34:04 +0000 | [diff] [blame] | 9566 | getStreamer().EmitValueToAlignment(2); |
Saleem Abdulrasool | a554968 | 2013-12-26 01:52:28 +0000 | [diff] [blame] | 9567 | |
| 9568 | return false; |
| 9569 | } |
| 9570 | |
Saleem Abdulrasool | 662f5c1 | 2014-01-21 02:33:02 +0000 | [diff] [blame] | 9571 | /// parseDirectivePersonalityIndex |
| 9572 | /// ::= .personalityindex index |
| 9573 | bool ARMAsmParser::parseDirectivePersonalityIndex(SMLoc L) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 9574 | MCAsmParser &Parser = getParser(); |
Saleem Abdulrasool | 662f5c1 | 2014-01-21 02:33:02 +0000 | [diff] [blame] | 9575 | bool HasExistingPersonality = UC.hasPersonality(); |
| 9576 | |
| 9577 | UC.recordPersonalityIndex(L); |
| 9578 | |
| 9579 | if (!UC.hasFnStart()) { |
| 9580 | Parser.eatToEndOfStatement(); |
| 9581 | Error(L, ".fnstart must precede .personalityindex directive"); |
| 9582 | return false; |
| 9583 | } |
| 9584 | if (UC.cantUnwind()) { |
| 9585 | Parser.eatToEndOfStatement(); |
| 9586 | Error(L, ".personalityindex cannot be used with .cantunwind"); |
| 9587 | UC.emitCantUnwindLocNotes(); |
| 9588 | return false; |
| 9589 | } |
| 9590 | if (UC.hasHandlerData()) { |
| 9591 | Parser.eatToEndOfStatement(); |
| 9592 | Error(L, ".personalityindex must precede .handlerdata directive"); |
| 9593 | UC.emitHandlerDataLocNotes(); |
| 9594 | return false; |
| 9595 | } |
| 9596 | if (HasExistingPersonality) { |
| 9597 | Parser.eatToEndOfStatement(); |
| 9598 | Error(L, "multiple personality directives"); |
| 9599 | UC.emitPersonalityLocNotes(); |
| 9600 | return false; |
| 9601 | } |
| 9602 | |
| 9603 | const MCExpr *IndexExpression; |
| 9604 | SMLoc IndexLoc = Parser.getTok().getLoc(); |
| 9605 | if (Parser.parseExpression(IndexExpression)) { |
| 9606 | Parser.eatToEndOfStatement(); |
| 9607 | return false; |
| 9608 | } |
| 9609 | |
| 9610 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(IndexExpression); |
| 9611 | if (!CE) { |
| 9612 | Parser.eatToEndOfStatement(); |
| 9613 | Error(IndexLoc, "index must be a constant number"); |
| 9614 | return false; |
| 9615 | } |
| 9616 | if (CE->getValue() < 0 || |
| 9617 | CE->getValue() >= ARM::EHABI::NUM_PERSONALITY_INDEX) { |
| 9618 | Parser.eatToEndOfStatement(); |
| 9619 | Error(IndexLoc, "personality routine index should be in range [0-3]"); |
| 9620 | return false; |
| 9621 | } |
| 9622 | |
| 9623 | getTargetStreamer().emitPersonalityIndex(CE->getValue()); |
| 9624 | return false; |
| 9625 | } |
| 9626 | |
Saleem Abdulrasool | d9f0860 | 2014-01-21 02:33:10 +0000 | [diff] [blame] | 9627 | /// parseDirectiveUnwindRaw |
| 9628 | /// ::= .unwind_raw offset, opcode [, opcode...] |
| 9629 | bool ARMAsmParser::parseDirectiveUnwindRaw(SMLoc L) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 9630 | MCAsmParser &Parser = getParser(); |
Saleem Abdulrasool | d9f0860 | 2014-01-21 02:33:10 +0000 | [diff] [blame] | 9631 | if (!UC.hasFnStart()) { |
| 9632 | Parser.eatToEndOfStatement(); |
| 9633 | Error(L, ".fnstart must precede .unwind_raw directives"); |
| 9634 | return false; |
| 9635 | } |
| 9636 | |
| 9637 | int64_t StackOffset; |
| 9638 | |
| 9639 | const MCExpr *OffsetExpr; |
| 9640 | SMLoc OffsetLoc = getLexer().getLoc(); |
| 9641 | if (getLexer().is(AsmToken::EndOfStatement) || |
| 9642 | getParser().parseExpression(OffsetExpr)) { |
| 9643 | Error(OffsetLoc, "expected expression"); |
| 9644 | Parser.eatToEndOfStatement(); |
| 9645 | return false; |
| 9646 | } |
| 9647 | |
| 9648 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr); |
| 9649 | if (!CE) { |
| 9650 | Error(OffsetLoc, "offset must be a constant"); |
| 9651 | Parser.eatToEndOfStatement(); |
| 9652 | return false; |
| 9653 | } |
| 9654 | |
| 9655 | StackOffset = CE->getValue(); |
| 9656 | |
| 9657 | if (getLexer().isNot(AsmToken::Comma)) { |
| 9658 | Error(getLexer().getLoc(), "expected comma"); |
| 9659 | Parser.eatToEndOfStatement(); |
| 9660 | return false; |
| 9661 | } |
| 9662 | Parser.Lex(); |
| 9663 | |
| 9664 | SmallVector<uint8_t, 16> Opcodes; |
| 9665 | for (;;) { |
| 9666 | const MCExpr *OE; |
| 9667 | |
| 9668 | SMLoc OpcodeLoc = getLexer().getLoc(); |
| 9669 | if (getLexer().is(AsmToken::EndOfStatement) || Parser.parseExpression(OE)) { |
| 9670 | Error(OpcodeLoc, "expected opcode expression"); |
| 9671 | Parser.eatToEndOfStatement(); |
| 9672 | return false; |
| 9673 | } |
| 9674 | |
| 9675 | const MCConstantExpr *OC = dyn_cast<MCConstantExpr>(OE); |
| 9676 | if (!OC) { |
| 9677 | Error(OpcodeLoc, "opcode value must be a constant"); |
| 9678 | Parser.eatToEndOfStatement(); |
| 9679 | return false; |
| 9680 | } |
| 9681 | |
| 9682 | const int64_t Opcode = OC->getValue(); |
| 9683 | if (Opcode & ~0xff) { |
| 9684 | Error(OpcodeLoc, "invalid opcode"); |
| 9685 | Parser.eatToEndOfStatement(); |
| 9686 | return false; |
| 9687 | } |
| 9688 | |
| 9689 | Opcodes.push_back(uint8_t(Opcode)); |
| 9690 | |
| 9691 | if (getLexer().is(AsmToken::EndOfStatement)) |
| 9692 | break; |
| 9693 | |
| 9694 | if (getLexer().isNot(AsmToken::Comma)) { |
| 9695 | Error(getLexer().getLoc(), "unexpected token in directive"); |
| 9696 | Parser.eatToEndOfStatement(); |
| 9697 | return false; |
| 9698 | } |
| 9699 | |
| 9700 | Parser.Lex(); |
| 9701 | } |
| 9702 | |
| 9703 | getTargetStreamer().emitUnwindRaw(StackOffset, Opcodes); |
| 9704 | |
| 9705 | Parser.Lex(); |
| 9706 | return false; |
| 9707 | } |
| 9708 | |
Saleem Abdulrasool | 56e06e8 | 2014-01-30 04:02:47 +0000 | [diff] [blame] | 9709 | /// parseDirectiveTLSDescSeq |
| 9710 | /// ::= .tlsdescseq tls-variable |
| 9711 | bool ARMAsmParser::parseDirectiveTLSDescSeq(SMLoc L) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 9712 | MCAsmParser &Parser = getParser(); |
| 9713 | |
Saleem Abdulrasool | 56e06e8 | 2014-01-30 04:02:47 +0000 | [diff] [blame] | 9714 | if (getLexer().isNot(AsmToken::Identifier)) { |
| 9715 | TokError("expected variable after '.tlsdescseq' directive"); |
| 9716 | Parser.eatToEndOfStatement(); |
| 9717 | return false; |
| 9718 | } |
| 9719 | |
| 9720 | const MCSymbolRefExpr *SRE = |
| 9721 | MCSymbolRefExpr::Create(Parser.getTok().getIdentifier(), |
| 9722 | MCSymbolRefExpr::VK_ARM_TLSDESCSEQ, getContext()); |
| 9723 | Lex(); |
| 9724 | |
| 9725 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
| 9726 | Error(Parser.getTok().getLoc(), "unexpected token"); |
| 9727 | Parser.eatToEndOfStatement(); |
| 9728 | return false; |
| 9729 | } |
| 9730 | |
| 9731 | getTargetStreamer().AnnotateTLSDescriptorSequence(SRE); |
| 9732 | return false; |
| 9733 | } |
| 9734 | |
Saleem Abdulrasool | 5d962d3 | 2014-01-30 04:46:24 +0000 | [diff] [blame] | 9735 | /// parseDirectiveMovSP |
| 9736 | /// ::= .movsp reg [, #offset] |
| 9737 | bool ARMAsmParser::parseDirectiveMovSP(SMLoc L) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 9738 | MCAsmParser &Parser = getParser(); |
Saleem Abdulrasool | 5d962d3 | 2014-01-30 04:46:24 +0000 | [diff] [blame] | 9739 | if (!UC.hasFnStart()) { |
| 9740 | Parser.eatToEndOfStatement(); |
| 9741 | Error(L, ".fnstart must precede .movsp directives"); |
| 9742 | return false; |
| 9743 | } |
| 9744 | if (UC.getFPReg() != ARM::SP) { |
| 9745 | Parser.eatToEndOfStatement(); |
| 9746 | Error(L, "unexpected .movsp directive"); |
| 9747 | return false; |
| 9748 | } |
| 9749 | |
| 9750 | SMLoc SPRegLoc = Parser.getTok().getLoc(); |
| 9751 | int SPReg = tryParseRegister(); |
| 9752 | if (SPReg == -1) { |
| 9753 | Parser.eatToEndOfStatement(); |
| 9754 | Error(SPRegLoc, "register expected"); |
| 9755 | return false; |
| 9756 | } |
| 9757 | |
| 9758 | if (SPReg == ARM::SP || SPReg == ARM::PC) { |
| 9759 | Parser.eatToEndOfStatement(); |
| 9760 | Error(SPRegLoc, "sp and pc are not permitted in .movsp directive"); |
| 9761 | return false; |
| 9762 | } |
| 9763 | |
| 9764 | int64_t Offset = 0; |
| 9765 | if (Parser.getTok().is(AsmToken::Comma)) { |
| 9766 | Parser.Lex(); |
| 9767 | |
| 9768 | if (Parser.getTok().isNot(AsmToken::Hash)) { |
| 9769 | Error(Parser.getTok().getLoc(), "expected #constant"); |
| 9770 | Parser.eatToEndOfStatement(); |
| 9771 | return false; |
| 9772 | } |
| 9773 | Parser.Lex(); |
| 9774 | |
| 9775 | const MCExpr *OffsetExpr; |
| 9776 | SMLoc OffsetLoc = Parser.getTok().getLoc(); |
| 9777 | if (Parser.parseExpression(OffsetExpr)) { |
| 9778 | Parser.eatToEndOfStatement(); |
| 9779 | Error(OffsetLoc, "malformed offset expression"); |
| 9780 | return false; |
| 9781 | } |
| 9782 | |
| 9783 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr); |
| 9784 | if (!CE) { |
| 9785 | Parser.eatToEndOfStatement(); |
| 9786 | Error(OffsetLoc, "offset must be an immediate constant"); |
| 9787 | return false; |
| 9788 | } |
| 9789 | |
| 9790 | Offset = CE->getValue(); |
| 9791 | } |
| 9792 | |
| 9793 | getTargetStreamer().emitMovSP(SPReg, Offset); |
| 9794 | UC.saveFPReg(SPReg); |
| 9795 | |
| 9796 | return false; |
| 9797 | } |
| 9798 | |
Saleem Abdulrasool | 4c4789b | 2014-01-30 04:46:41 +0000 | [diff] [blame] | 9799 | /// parseDirectiveObjectArch |
| 9800 | /// ::= .object_arch name |
| 9801 | bool ARMAsmParser::parseDirectiveObjectArch(SMLoc L) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 9802 | MCAsmParser &Parser = getParser(); |
Saleem Abdulrasool | 4c4789b | 2014-01-30 04:46:41 +0000 | [diff] [blame] | 9803 | if (getLexer().isNot(AsmToken::Identifier)) { |
| 9804 | Error(getLexer().getLoc(), "unexpected token"); |
| 9805 | Parser.eatToEndOfStatement(); |
| 9806 | return false; |
| 9807 | } |
| 9808 | |
| 9809 | StringRef Arch = Parser.getTok().getString(); |
| 9810 | SMLoc ArchLoc = Parser.getTok().getLoc(); |
| 9811 | getLexer().Lex(); |
| 9812 | |
| 9813 | unsigned ID = StringSwitch<unsigned>(Arch) |
| 9814 | #define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \ |
| 9815 | .Case(NAME, ARM::ID) |
| 9816 | #define ARM_ARCH_ALIAS(NAME, ID) \ |
| 9817 | .Case(NAME, ARM::ID) |
| 9818 | #include "MCTargetDesc/ARMArchName.def" |
| 9819 | #undef ARM_ARCH_NAME |
| 9820 | #undef ARM_ARCH_ALIAS |
| 9821 | .Default(ARM::INVALID_ARCH); |
| 9822 | |
| 9823 | if (ID == ARM::INVALID_ARCH) { |
| 9824 | Error(ArchLoc, "unknown architecture '" + Arch + "'"); |
| 9825 | Parser.eatToEndOfStatement(); |
| 9826 | return false; |
| 9827 | } |
| 9828 | |
| 9829 | getTargetStreamer().emitObjectArch(ID); |
| 9830 | |
| 9831 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
| 9832 | Error(getLexer().getLoc(), "unexpected token"); |
| 9833 | Parser.eatToEndOfStatement(); |
| 9834 | } |
| 9835 | |
| 9836 | return false; |
| 9837 | } |
| 9838 | |
Saleem Abdulrasool | fd6ed1e | 2014-02-23 17:45:32 +0000 | [diff] [blame] | 9839 | /// parseDirectiveAlign |
| 9840 | /// ::= .align |
| 9841 | bool ARMAsmParser::parseDirectiveAlign(SMLoc L) { |
| 9842 | // NOTE: if this is not the end of the statement, fall back to the target |
| 9843 | // agnostic handling for this directive which will correctly handle this. |
| 9844 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 9845 | return true; |
| 9846 | |
| 9847 | // '.align' is target specifically handled to mean 2**2 byte alignment. |
| 9848 | if (getStreamer().getCurrentSection().first->UseCodeAlign()) |
| 9849 | getStreamer().EmitCodeAlignment(4, 0); |
| 9850 | else |
| 9851 | getStreamer().EmitValueToAlignment(4, 0, 1, 0); |
| 9852 | |
| 9853 | return false; |
| 9854 | } |
| 9855 | |
Saleem Abdulrasool | 39f773f | 2014-03-20 06:05:33 +0000 | [diff] [blame] | 9856 | /// parseDirectiveThumbSet |
| 9857 | /// ::= .thumb_set name, value |
| 9858 | bool ARMAsmParser::parseDirectiveThumbSet(SMLoc L) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 9859 | MCAsmParser &Parser = getParser(); |
| 9860 | |
Saleem Abdulrasool | 39f773f | 2014-03-20 06:05:33 +0000 | [diff] [blame] | 9861 | StringRef Name; |
| 9862 | if (Parser.parseIdentifier(Name)) { |
| 9863 | TokError("expected identifier after '.thumb_set'"); |
| 9864 | Parser.eatToEndOfStatement(); |
| 9865 | return false; |
| 9866 | } |
| 9867 | |
| 9868 | if (getLexer().isNot(AsmToken::Comma)) { |
| 9869 | TokError("expected comma after name '" + Name + "'"); |
| 9870 | Parser.eatToEndOfStatement(); |
| 9871 | return false; |
| 9872 | } |
| 9873 | Lex(); |
| 9874 | |
| 9875 | const MCExpr *Value; |
| 9876 | if (Parser.parseExpression(Value)) { |
| 9877 | TokError("missing expression"); |
| 9878 | Parser.eatToEndOfStatement(); |
| 9879 | return false; |
| 9880 | } |
| 9881 | |
| 9882 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
| 9883 | TokError("unexpected token"); |
| 9884 | Parser.eatToEndOfStatement(); |
| 9885 | return false; |
| 9886 | } |
| 9887 | Lex(); |
| 9888 | |
| 9889 | MCSymbol *Alias = getContext().GetOrCreateSymbol(Name); |
Rafael Espindola | 466d663 | 2014-04-27 20:23:58 +0000 | [diff] [blame] | 9890 | getTargetStreamer().emitThumbSet(Alias, Value); |
Saleem Abdulrasool | 39f773f | 2014-03-20 06:05:33 +0000 | [diff] [blame] | 9891 | return false; |
| 9892 | } |
| 9893 | |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 9894 | /// Force static initialization. |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 9895 | extern "C" void LLVMInitializeARMAsmParser() { |
Christian Pirker | dc9ff75 | 2014-04-01 15:19:30 +0000 | [diff] [blame] | 9896 | RegisterMCAsmParser<ARMAsmParser> X(TheARMLETarget); |
| 9897 | RegisterMCAsmParser<ARMAsmParser> Y(TheARMBETarget); |
| 9898 | RegisterMCAsmParser<ARMAsmParser> A(TheThumbLETarget); |
| 9899 | RegisterMCAsmParser<ARMAsmParser> B(TheThumbBETarget); |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 9900 | } |
Daniel Dunbar | 5cd4d0f | 2010-08-11 05:24:50 +0000 | [diff] [blame] | 9901 | |
Chris Lattner | 3e4582a | 2010-09-06 19:11:01 +0000 | [diff] [blame] | 9902 | #define GET_REGISTER_MATCHER |
Craig Topper | 3ec7c2a | 2012-04-25 06:56:34 +0000 | [diff] [blame] | 9903 | #define GET_SUBTARGET_FEATURE_NAME |
Chris Lattner | 3e4582a | 2010-09-06 19:11:01 +0000 | [diff] [blame] | 9904 | #define GET_MATCHER_IMPLEMENTATION |
Daniel Dunbar | 5cd4d0f | 2010-08-11 05:24:50 +0000 | [diff] [blame] | 9905 | #include "ARMGenAsmMatcher.inc" |
Jim Grosbach | 231e7aa | 2013-02-06 06:00:11 +0000 | [diff] [blame] | 9906 | |
Saleem Abdulrasool | 45cf67b | 2014-07-27 19:07:05 +0000 | [diff] [blame] | 9907 | static const struct { |
| 9908 | const char *Name; |
Saleem Abdulrasool | 49480bf | 2014-02-16 00:16:41 +0000 | [diff] [blame] | 9909 | const unsigned ArchCheck; |
| 9910 | const uint64_t Features; |
| 9911 | } Extensions[] = { |
| 9912 | { "crc", Feature_HasV8, ARM::FeatureCRC }, |
| 9913 | { "crypto", Feature_HasV8, |
| 9914 | ARM::FeatureCrypto | ARM::FeatureNEON | ARM::FeatureFPARMv8 }, |
| 9915 | { "fp", Feature_HasV8, ARM::FeatureFPARMv8 }, |
| 9916 | { "idiv", Feature_HasV7 | Feature_IsNotMClass, |
| 9917 | ARM::FeatureHWDiv | ARM::FeatureHWDivARM }, |
| 9918 | // FIXME: iWMMXT not supported |
| 9919 | { "iwmmxt", Feature_None, 0 }, |
| 9920 | // FIXME: iWMMXT2 not supported |
| 9921 | { "iwmmxt2", Feature_None, 0 }, |
| 9922 | // FIXME: Maverick not supported |
| 9923 | { "maverick", Feature_None, 0 }, |
| 9924 | { "mp", Feature_HasV7 | Feature_IsNotMClass, ARM::FeatureMP }, |
| 9925 | // FIXME: ARMv6-m OS Extensions feature not checked |
| 9926 | { "os", Feature_None, 0 }, |
| 9927 | // FIXME: Also available in ARMv6-K |
| 9928 | { "sec", Feature_HasV7, ARM::FeatureTrustZone }, |
| 9929 | { "simd", Feature_HasV8, ARM::FeatureNEON | ARM::FeatureFPARMv8 }, |
| 9930 | // FIXME: Only available in A-class, isel not predicated |
| 9931 | { "virt", Feature_HasV7, ARM::FeatureVirtualization }, |
| 9932 | // FIXME: xscale not supported |
| 9933 | { "xscale", Feature_None, 0 }, |
| 9934 | }; |
| 9935 | |
Saleem Abdulrasool | 49480bf | 2014-02-16 00:16:41 +0000 | [diff] [blame] | 9936 | /// parseDirectiveArchExtension |
| 9937 | /// ::= .arch_extension [no]feature |
| 9938 | bool ARMAsmParser::parseDirectiveArchExtension(SMLoc L) { |
Rafael Espindola | 961d469 | 2014-11-11 05:18:41 +0000 | [diff] [blame] | 9939 | MCAsmParser &Parser = getParser(); |
| 9940 | |
Saleem Abdulrasool | 49480bf | 2014-02-16 00:16:41 +0000 | [diff] [blame] | 9941 | if (getLexer().isNot(AsmToken::Identifier)) { |
| 9942 | Error(getLexer().getLoc(), "unexpected token"); |
| 9943 | Parser.eatToEndOfStatement(); |
| 9944 | return false; |
| 9945 | } |
| 9946 | |
Saleem Abdulrasool | 45cf67b | 2014-07-27 19:07:05 +0000 | [diff] [blame] | 9947 | StringRef Name = Parser.getTok().getString(); |
Saleem Abdulrasool | 49480bf | 2014-02-16 00:16:41 +0000 | [diff] [blame] | 9948 | SMLoc ExtLoc = Parser.getTok().getLoc(); |
| 9949 | getLexer().Lex(); |
| 9950 | |
| 9951 | bool EnableFeature = true; |
Saleem Abdulrasool | 45cf67b | 2014-07-27 19:07:05 +0000 | [diff] [blame] | 9952 | if (Name.startswith_lower("no")) { |
Saleem Abdulrasool | 49480bf | 2014-02-16 00:16:41 +0000 | [diff] [blame] | 9953 | EnableFeature = false; |
Saleem Abdulrasool | 45cf67b | 2014-07-27 19:07:05 +0000 | [diff] [blame] | 9954 | Name = Name.substr(2); |
Saleem Abdulrasool | 49480bf | 2014-02-16 00:16:41 +0000 | [diff] [blame] | 9955 | } |
| 9956 | |
Saleem Abdulrasool | 45cf67b | 2014-07-27 19:07:05 +0000 | [diff] [blame] | 9957 | for (const auto &Extension : Extensions) { |
| 9958 | if (Extension.Name != Name) |
Saleem Abdulrasool | 49480bf | 2014-02-16 00:16:41 +0000 | [diff] [blame] | 9959 | continue; |
| 9960 | |
Saleem Abdulrasool | 8988c2a | 2014-07-27 19:07:09 +0000 | [diff] [blame] | 9961 | if (!Extension.Features) |
| 9962 | report_fatal_error("unsupported architectural extension: " + Name); |
| 9963 | |
| 9964 | if ((getAvailableFeatures() & Extension.ArchCheck) != Extension.ArchCheck) { |
Saleem Abdulrasool | 45cf67b | 2014-07-27 19:07:05 +0000 | [diff] [blame] | 9965 | Error(ExtLoc, "architectural extension '" + Name + "' is not " |
Saleem Abdulrasool | 49480bf | 2014-02-16 00:16:41 +0000 | [diff] [blame] | 9966 | "allowed for the current base architecture"); |
| 9967 | return false; |
| 9968 | } |
| 9969 | |
Tim Northover | 26bb14e | 2014-08-18 11:49:42 +0000 | [diff] [blame] | 9970 | uint64_t ToggleFeatures = EnableFeature |
Saleem Abdulrasool | 78c4472 | 2014-08-17 19:20:38 +0000 | [diff] [blame] | 9971 | ? (~STI.getFeatureBits() & Extension.Features) |
| 9972 | : ( STI.getFeatureBits() & Extension.Features); |
Tim Northover | 26bb14e | 2014-08-18 11:49:42 +0000 | [diff] [blame] | 9973 | uint64_t Features = |
Saleem Abdulrasool | 78c4472 | 2014-08-17 19:20:38 +0000 | [diff] [blame] | 9974 | ComputeAvailableFeatures(STI.ToggleFeature(ToggleFeatures)); |
| 9975 | setAvailableFeatures(Features); |
Saleem Abdulrasool | 49480bf | 2014-02-16 00:16:41 +0000 | [diff] [blame] | 9976 | return false; |
| 9977 | } |
| 9978 | |
Saleem Abdulrasool | 45cf67b | 2014-07-27 19:07:05 +0000 | [diff] [blame] | 9979 | Error(ExtLoc, "unknown architectural extension: " + Name); |
Saleem Abdulrasool | 49480bf | 2014-02-16 00:16:41 +0000 | [diff] [blame] | 9980 | Parser.eatToEndOfStatement(); |
| 9981 | return false; |
| 9982 | } |
| 9983 | |
Jim Grosbach | 231e7aa | 2013-02-06 06:00:11 +0000 | [diff] [blame] | 9984 | // Define this matcher function after the auto-generated include so we |
| 9985 | // have the match class enum definitions. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 9986 | unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand &AsmOp, |
Jim Grosbach | 231e7aa | 2013-02-06 06:00:11 +0000 | [diff] [blame] | 9987 | unsigned Kind) { |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 9988 | ARMOperand &Op = static_cast<ARMOperand &>(AsmOp); |
Jim Grosbach | 231e7aa | 2013-02-06 06:00:11 +0000 | [diff] [blame] | 9989 | // If the kind is a token for a literal immediate, check if our asm |
| 9990 | // operand matches. This is for InstAliases which have a fixed-value |
| 9991 | // immediate in the syntax. |
Saleem Abdulrasool | d88affb | 2014-01-08 03:28:14 +0000 | [diff] [blame] | 9992 | switch (Kind) { |
| 9993 | default: break; |
| 9994 | case MCK__35_0: |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 9995 | if (Op.isImm()) |
| 9996 | if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm())) |
Saleem Abdulrasool | d88affb | 2014-01-08 03:28:14 +0000 | [diff] [blame] | 9997 | if (CE->getValue() == 0) |
| 9998 | return Match_Success; |
| 9999 | break; |
Asiri Rathnayake | a0199b9 | 2014-12-02 10:53:20 +0000 | [diff] [blame] | 10000 | case MCK_ModImm: |
Saleem Abdulrasool | d88affb | 2014-01-08 03:28:14 +0000 | [diff] [blame] | 10001 | case MCK_ARMSOImm: |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 10002 | if (Op.isImm()) { |
| 10003 | const MCExpr *SOExpr = Op.getImm(); |
Saleem Abdulrasool | d88affb | 2014-01-08 03:28:14 +0000 | [diff] [blame] | 10004 | int64_t Value; |
| 10005 | if (!SOExpr->EvaluateAsAbsolute(Value)) |
Stepan Dyatkovskiy | df657cc | 2014-03-29 13:12:40 +0000 | [diff] [blame] | 10006 | return Match_Success; |
Richard Barton | 3db1d58 | 2014-05-01 11:37:44 +0000 | [diff] [blame] | 10007 | assert((Value >= INT32_MIN && Value <= UINT32_MAX) && |
| 10008 | "expression value must be representable in 32 bits"); |
Saleem Abdulrasool | d88affb | 2014-01-08 03:28:14 +0000 | [diff] [blame] | 10009 | } |
| 10010 | break; |
Saleem Abdulrasool | e6e6d71 | 2014-01-10 04:38:35 +0000 | [diff] [blame] | 10011 | case MCK_GPRPair: |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 10012 | if (Op.isReg() && |
| 10013 | MRI->getRegClass(ARM::GPRRegClassID).contains(Op.getReg())) |
Saleem Abdulrasool | e6e6d71 | 2014-01-10 04:38:35 +0000 | [diff] [blame] | 10014 | return Match_Success; |
| 10015 | break; |
Jim Grosbach | 231e7aa | 2013-02-06 06:00:11 +0000 | [diff] [blame] | 10016 | } |
| 10017 | return Match_InvalidOperand; |
| 10018 | } |