Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 1 | //===-- ARMAsmParser.cpp - Parse ARM assembly to MCInst instructions ------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Logan Chien | 8cbb80d | 2013-10-28 17:51:12 +0000 | [diff] [blame] | 10 | #include "ARMFPUName.h" |
Amara Emerson | 52cfb6a | 2013-10-03 09:31:51 +0000 | [diff] [blame] | 11 | #include "ARMFeatures.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 12 | #include "MCTargetDesc/ARMAddressingModes.h" |
Logan Chien | 439e8f9 | 2013-12-11 17:16:25 +0000 | [diff] [blame] | 13 | #include "MCTargetDesc/ARMArchName.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 14 | #include "MCTargetDesc/ARMBaseInfo.h" |
| 15 | #include "MCTargetDesc/ARMMCExpr.h" |
Evan Cheng | 1142444 | 2011-07-26 00:24:13 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/STLExtras.h" |
Chris Lattner | 00646cf | 2010-01-22 01:44:57 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/SmallVector.h" |
Saleem Abdulrasool | c0da2cb | 2013-12-19 05:17:58 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/StringExtras.h" |
Daniel Dunbar | 188b47b | 2010-08-11 06:37:20 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/StringSwitch.h" |
Chris Lattner | 00646cf | 2010-01-22 01:44:57 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/Twine.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 21 | #include "llvm/MC/MCAsmInfo.h" |
Jack Carter | 718da0b | 2013-01-30 02:24:33 +0000 | [diff] [blame] | 22 | #include "llvm/MC/MCAssembler.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 23 | #include "llvm/MC/MCContext.h" |
Tim Northover | d6a729b | 2014-01-06 14:28:05 +0000 | [diff] [blame] | 24 | #include "llvm/MC/MCDisassembler.h" |
Jack Carter | 718da0b | 2013-01-30 02:24:33 +0000 | [diff] [blame] | 25 | #include "llvm/MC/MCELFStreamer.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 26 | #include "llvm/MC/MCExpr.h" |
| 27 | #include "llvm/MC/MCInst.h" |
| 28 | #include "llvm/MC/MCInstrDesc.h" |
Joey Gouly | 0e76fa7 | 2013-09-12 10:28:05 +0000 | [diff] [blame] | 29 | #include "llvm/MC/MCInstrInfo.h" |
Saleem Abdulrasool | 39f773f | 2014-03-20 06:05:33 +0000 | [diff] [blame] | 30 | #include "llvm/MC/MCObjectFileInfo.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 31 | #include "llvm/MC/MCParser/MCAsmLexer.h" |
| 32 | #include "llvm/MC/MCParser/MCAsmParser.h" |
| 33 | #include "llvm/MC/MCParser/MCParsedAsmOperand.h" |
| 34 | #include "llvm/MC/MCRegisterInfo.h" |
Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 35 | #include "llvm/MC/MCSection.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 36 | #include "llvm/MC/MCStreamer.h" |
| 37 | #include "llvm/MC/MCSubtargetInfo.h" |
David Peixotto | e407d09 | 2013-12-19 18:12:36 +0000 | [diff] [blame] | 38 | #include "llvm/MC/MCSymbol.h" |
Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 39 | #include "llvm/MC/MCTargetAsmParser.h" |
Saleem Abdulrasool | 278a9f4 | 2014-01-19 08:25:27 +0000 | [diff] [blame] | 40 | #include "llvm/Support/ARMBuildAttributes.h" |
Saleem Abdulrasool | 662f5c1 | 2014-01-21 02:33:02 +0000 | [diff] [blame] | 41 | #include "llvm/Support/ARMEHABI.h" |
Saleem Abdulrasool | 39f773f | 2014-03-20 06:05:33 +0000 | [diff] [blame] | 42 | #include "llvm/Support/COFF.h" |
Tim Northover | d6a729b | 2014-01-06 14:28:05 +0000 | [diff] [blame] | 43 | #include "llvm/Support/Debug.h" |
Jack Carter | 718da0b | 2013-01-30 02:24:33 +0000 | [diff] [blame] | 44 | #include "llvm/Support/ELF.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 45 | #include "llvm/Support/MathExtras.h" |
| 46 | #include "llvm/Support/SourceMgr.h" |
| 47 | #include "llvm/Support/TargetRegistry.h" |
| 48 | #include "llvm/Support/raw_ostream.h" |
Evan Cheng | 4d1ca96 | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 49 | |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 50 | using namespace llvm; |
| 51 | |
Chris Lattner | bd7c9fa | 2010-10-28 17:20:03 +0000 | [diff] [blame] | 52 | namespace { |
Bill Wendling | ee7f1f9 | 2010-11-06 21:42:12 +0000 | [diff] [blame] | 53 | |
| 54 | class ARMOperand; |
Jim Grosbach | 624bcc7 | 2010-10-29 14:46:02 +0000 | [diff] [blame] | 55 | |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 56 | enum VectorLaneTy { NoLanes, AllLanes, IndexedLane }; |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 57 | |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 58 | class UnwindContext { |
| 59 | MCAsmParser &Parser; |
| 60 | |
Saleem Abdulrasool | 4cb063c | 2014-01-07 02:29:00 +0000 | [diff] [blame] | 61 | typedef SmallVector<SMLoc, 4> Locs; |
| 62 | |
| 63 | Locs FnStartLocs; |
| 64 | Locs CantUnwindLocs; |
| 65 | Locs PersonalityLocs; |
Saleem Abdulrasool | 662f5c1 | 2014-01-21 02:33:02 +0000 | [diff] [blame] | 66 | Locs PersonalityIndexLocs; |
Saleem Abdulrasool | 4cb063c | 2014-01-07 02:29:00 +0000 | [diff] [blame] | 67 | Locs HandlerDataLocs; |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 68 | int FPReg; |
| 69 | |
| 70 | public: |
Saleem Abdulrasool | 5d962d3 | 2014-01-30 04:46:24 +0000 | [diff] [blame] | 71 | UnwindContext(MCAsmParser &P) : Parser(P), FPReg(ARM::SP) {} |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 72 | |
Saleem Abdulrasool | 4cb063c | 2014-01-07 02:29:00 +0000 | [diff] [blame] | 73 | bool hasFnStart() const { return !FnStartLocs.empty(); } |
| 74 | bool cantUnwind() const { return !CantUnwindLocs.empty(); } |
| 75 | bool hasHandlerData() const { return !HandlerDataLocs.empty(); } |
Saleem Abdulrasool | 662f5c1 | 2014-01-21 02:33:02 +0000 | [diff] [blame] | 76 | bool hasPersonality() const { |
| 77 | return !(PersonalityLocs.empty() && PersonalityIndexLocs.empty()); |
| 78 | } |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 79 | |
Saleem Abdulrasool | 4cb063c | 2014-01-07 02:29:00 +0000 | [diff] [blame] | 80 | void recordFnStart(SMLoc L) { FnStartLocs.push_back(L); } |
| 81 | void recordCantUnwind(SMLoc L) { CantUnwindLocs.push_back(L); } |
| 82 | void recordPersonality(SMLoc L) { PersonalityLocs.push_back(L); } |
| 83 | void recordHandlerData(SMLoc L) { HandlerDataLocs.push_back(L); } |
Saleem Abdulrasool | 662f5c1 | 2014-01-21 02:33:02 +0000 | [diff] [blame] | 84 | void recordPersonalityIndex(SMLoc L) { PersonalityIndexLocs.push_back(L); } |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 85 | |
| 86 | void saveFPReg(int Reg) { FPReg = Reg; } |
| 87 | int getFPReg() const { return FPReg; } |
| 88 | |
| 89 | void emitFnStartLocNotes() const { |
Saleem Abdulrasool | 4cb063c | 2014-01-07 02:29:00 +0000 | [diff] [blame] | 90 | for (Locs::const_iterator FI = FnStartLocs.begin(), FE = FnStartLocs.end(); |
| 91 | FI != FE; ++FI) |
| 92 | Parser.Note(*FI, ".fnstart was specified here"); |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 93 | } |
| 94 | void emitCantUnwindLocNotes() const { |
Saleem Abdulrasool | 4cb063c | 2014-01-07 02:29:00 +0000 | [diff] [blame] | 95 | for (Locs::const_iterator UI = CantUnwindLocs.begin(), |
| 96 | UE = CantUnwindLocs.end(); UI != UE; ++UI) |
| 97 | Parser.Note(*UI, ".cantunwind was specified here"); |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 98 | } |
| 99 | void emitHandlerDataLocNotes() const { |
Saleem Abdulrasool | 4cb063c | 2014-01-07 02:29:00 +0000 | [diff] [blame] | 100 | for (Locs::const_iterator HI = HandlerDataLocs.begin(), |
| 101 | HE = HandlerDataLocs.end(); HI != HE; ++HI) |
| 102 | Parser.Note(*HI, ".handlerdata was specified here"); |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 103 | } |
| 104 | void emitPersonalityLocNotes() const { |
Saleem Abdulrasool | 4cb063c | 2014-01-07 02:29:00 +0000 | [diff] [blame] | 105 | for (Locs::const_iterator PI = PersonalityLocs.begin(), |
Saleem Abdulrasool | 662f5c1 | 2014-01-21 02:33:02 +0000 | [diff] [blame] | 106 | PE = PersonalityLocs.end(), |
| 107 | PII = PersonalityIndexLocs.begin(), |
| 108 | PIE = PersonalityIndexLocs.end(); |
| 109 | PI != PE || PII != PIE;) { |
| 110 | if (PI != PE && (PII == PIE || PI->getPointer() < PII->getPointer())) |
| 111 | Parser.Note(*PI++, ".personality was specified here"); |
| 112 | else if (PII != PIE && (PI == PE || PII->getPointer() < PI->getPointer())) |
| 113 | Parser.Note(*PII++, ".personalityindex was specified here"); |
| 114 | else |
| 115 | llvm_unreachable(".personality and .personalityindex cannot be " |
| 116 | "at the same location"); |
| 117 | } |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | void reset() { |
Saleem Abdulrasool | 4cb063c | 2014-01-07 02:29:00 +0000 | [diff] [blame] | 121 | FnStartLocs = Locs(); |
| 122 | CantUnwindLocs = Locs(); |
| 123 | PersonalityLocs = Locs(); |
| 124 | HandlerDataLocs = Locs(); |
Saleem Abdulrasool | 662f5c1 | 2014-01-21 02:33:02 +0000 | [diff] [blame] | 125 | PersonalityIndexLocs = Locs(); |
Saleem Abdulrasool | 5d962d3 | 2014-01-30 04:46:24 +0000 | [diff] [blame] | 126 | FPReg = ARM::SP; |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 127 | } |
| 128 | }; |
| 129 | |
Evan Cheng | 1142444 | 2011-07-26 00:24:13 +0000 | [diff] [blame] | 130 | class ARMAsmParser : public MCTargetAsmParser { |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 131 | MCSubtargetInfo &STI; |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 132 | MCAsmParser &Parser; |
Joey Gouly | 0e76fa7 | 2013-09-12 10:28:05 +0000 | [diff] [blame] | 133 | const MCInstrInfo &MII; |
Jim Grosbach | c988e0c | 2012-03-05 19:33:30 +0000 | [diff] [blame] | 134 | const MCRegisterInfo *MRI; |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 135 | UnwindContext UC; |
David Peixotto | e407d09 | 2013-12-19 18:12:36 +0000 | [diff] [blame] | 136 | |
Rafael Espindola | a17151a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 137 | ARMTargetStreamer &getTargetStreamer() { |
Saleem Abdulrasool | bfdfb14 | 2014-09-18 04:28:29 +0000 | [diff] [blame] | 138 | assert(getParser().getStreamer().getTargetStreamer() && |
| 139 | "do not have a target streamer"); |
Rafael Espindola | 4a1a360 | 2014-01-14 01:21:46 +0000 | [diff] [blame] | 140 | MCTargetStreamer &TS = *getParser().getStreamer().getTargetStreamer(); |
Rafael Espindola | a17151a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 141 | return static_cast<ARMTargetStreamer &>(TS); |
| 142 | } |
| 143 | |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 144 | // Map of register aliases registers via the .req directive. |
| 145 | StringMap<unsigned> RegisterReqs; |
| 146 | |
Tim Northover | 1744d0a | 2013-10-25 12:49:50 +0000 | [diff] [blame] | 147 | bool NextSymbolIsThumb; |
| 148 | |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 149 | struct { |
| 150 | ARMCC::CondCodes Cond; // Condition for IT block. |
| 151 | unsigned Mask:4; // Condition mask for instructions. |
| 152 | // Starting at first 1 (from lsb). |
| 153 | // '1' condition as indicated in IT. |
| 154 | // '0' inverse of condition (else). |
| 155 | // Count of instructions in IT block is |
| 156 | // 4 - trailingzeroes(mask) |
| 157 | |
| 158 | bool FirstCond; // Explicit flag for when we're parsing the |
| 159 | // First instruction in the IT block. It's |
| 160 | // implied in the mask, so needs special |
| 161 | // handling. |
| 162 | |
| 163 | unsigned CurPosition; // Current position in parsing of IT |
| 164 | // block. In range [0,3]. Initialized |
| 165 | // according to count of instructions in block. |
| 166 | // ~0U if no active IT block. |
| 167 | } ITState; |
| 168 | bool inITBlock() { return ITState.CurPosition != ~0U;} |
Jim Grosbach | a0d34d3 | 2011-09-02 23:22:08 +0000 | [diff] [blame] | 169 | void forwardITPosition() { |
| 170 | if (!inITBlock()) return; |
| 171 | // Move to the next instruction in the IT block, if there is one. If not, |
| 172 | // mark the block as done. |
Michael J. Spencer | df1ecbd7 | 2013-05-24 22:23:49 +0000 | [diff] [blame] | 173 | unsigned TZ = countTrailingZeros(ITState.Mask); |
Jim Grosbach | a0d34d3 | 2011-09-02 23:22:08 +0000 | [diff] [blame] | 174 | if (++ITState.CurPosition == 5 - TZ) |
| 175 | ITState.CurPosition = ~0U; // Done with the IT block after this. |
| 176 | } |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 177 | |
| 178 | |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 179 | MCAsmParser &getParser() const { return Parser; } |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 180 | MCAsmLexer &getLexer() const { return Parser.getLexer(); } |
| 181 | |
Saleem Abdulrasool | 69c7caf | 2014-01-07 02:28:31 +0000 | [diff] [blame] | 182 | void Note(SMLoc L, const Twine &Msg, ArrayRef<SMRange> Ranges = None) { |
| 183 | return Parser.Note(L, Msg, Ranges); |
| 184 | } |
Benjamin Kramer | 673824b | 2012-04-15 17:04:27 +0000 | [diff] [blame] | 185 | bool Warning(SMLoc L, const Twine &Msg, |
Dmitri Gribenko | 3238fb7 | 2013-05-05 00:40:33 +0000 | [diff] [blame] | 186 | ArrayRef<SMRange> Ranges = None) { |
Benjamin Kramer | 673824b | 2012-04-15 17:04:27 +0000 | [diff] [blame] | 187 | return Parser.Warning(L, Msg, Ranges); |
| 188 | } |
| 189 | bool Error(SMLoc L, const Twine &Msg, |
Dmitri Gribenko | 3238fb7 | 2013-05-05 00:40:33 +0000 | [diff] [blame] | 190 | ArrayRef<SMRange> Ranges = None) { |
Benjamin Kramer | 673824b | 2012-04-15 17:04:27 +0000 | [diff] [blame] | 191 | return Parser.Error(L, Msg, Ranges); |
| 192 | } |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 193 | |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 194 | int tryParseRegister(); |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 195 | bool tryParseRegisterWithWriteBack(OperandVector &); |
| 196 | int tryParseShiftRegister(OperandVector &); |
| 197 | bool parseRegisterList(OperandVector &); |
| 198 | bool parseMemory(OperandVector &); |
| 199 | bool parseOperand(OperandVector &, StringRef Mnemonic); |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 200 | bool parsePrefix(ARMMCExpr::VariantKind &RefKind); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 201 | bool parseMemRegOffsetShift(ARM_AM::ShiftOpc &ShiftType, |
| 202 | unsigned &ShiftAmount); |
Saleem Abdulrasool | 3897651 | 2014-02-23 06:22:09 +0000 | [diff] [blame] | 203 | bool parseLiteralValues(unsigned Size, SMLoc L); |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 204 | bool parseDirectiveThumb(SMLoc L); |
Jim Grosbach | 7f88239 | 2011-12-07 18:04:19 +0000 | [diff] [blame] | 205 | bool parseDirectiveARM(SMLoc L); |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 206 | bool parseDirectiveThumbFunc(SMLoc L); |
| 207 | bool parseDirectiveCode(SMLoc L); |
| 208 | bool parseDirectiveSyntax(SMLoc L); |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 209 | bool parseDirectiveReq(StringRef Name, SMLoc L); |
| 210 | bool parseDirectiveUnreq(SMLoc L); |
Jason W Kim | 135d244 | 2011-12-20 17:38:12 +0000 | [diff] [blame] | 211 | bool parseDirectiveArch(SMLoc L); |
| 212 | bool parseDirectiveEabiAttr(SMLoc L); |
Logan Chien | 8cbb80d | 2013-10-28 17:51:12 +0000 | [diff] [blame] | 213 | bool parseDirectiveCPU(SMLoc L); |
| 214 | bool parseDirectiveFPU(SMLoc L); |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 215 | bool parseDirectiveFnStart(SMLoc L); |
| 216 | bool parseDirectiveFnEnd(SMLoc L); |
| 217 | bool parseDirectiveCantUnwind(SMLoc L); |
| 218 | bool parseDirectivePersonality(SMLoc L); |
| 219 | bool parseDirectiveHandlerData(SMLoc L); |
| 220 | bool parseDirectiveSetFP(SMLoc L); |
| 221 | bool parseDirectivePad(SMLoc L); |
| 222 | bool parseDirectiveRegSave(SMLoc L, bool IsVector); |
Saleem Abdulrasool | c0da2cb | 2013-12-19 05:17:58 +0000 | [diff] [blame] | 223 | bool parseDirectiveInst(SMLoc L, char Suffix = '\0'); |
David Peixotto | 80c083a | 2013-12-19 18:26:07 +0000 | [diff] [blame] | 224 | bool parseDirectiveLtorg(SMLoc L); |
Saleem Abdulrasool | a554968 | 2013-12-26 01:52:28 +0000 | [diff] [blame] | 225 | bool parseDirectiveEven(SMLoc L); |
Saleem Abdulrasool | 662f5c1 | 2014-01-21 02:33:02 +0000 | [diff] [blame] | 226 | bool parseDirectivePersonalityIndex(SMLoc L); |
Saleem Abdulrasool | d9f0860 | 2014-01-21 02:33:10 +0000 | [diff] [blame] | 227 | bool parseDirectiveUnwindRaw(SMLoc L); |
Saleem Abdulrasool | 56e06e8 | 2014-01-30 04:02:47 +0000 | [diff] [blame] | 228 | bool parseDirectiveTLSDescSeq(SMLoc L); |
Saleem Abdulrasool | 5d962d3 | 2014-01-30 04:46:24 +0000 | [diff] [blame] | 229 | bool parseDirectiveMovSP(SMLoc L); |
Saleem Abdulrasool | 4c4789b | 2014-01-30 04:46:41 +0000 | [diff] [blame] | 230 | bool parseDirectiveObjectArch(SMLoc L); |
Saleem Abdulrasool | 49480bf | 2014-02-16 00:16:41 +0000 | [diff] [blame] | 231 | bool parseDirectiveArchExtension(SMLoc L); |
Saleem Abdulrasool | fd6ed1e | 2014-02-23 17:45:32 +0000 | [diff] [blame] | 232 | bool parseDirectiveAlign(SMLoc L); |
Saleem Abdulrasool | 39f773f | 2014-03-20 06:05:33 +0000 | [diff] [blame] | 233 | bool parseDirectiveThumbSet(SMLoc L); |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 234 | |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 235 | StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode, |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 236 | bool &CarrySetting, unsigned &ProcessorIMod, |
| 237 | StringRef &ITMask); |
Amara Emerson | 3308909 | 2013-09-19 11:59:01 +0000 | [diff] [blame] | 238 | void getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst, |
| 239 | bool &CanAcceptCarrySet, |
Bruno Cardoso Lopes | e6290cc | 2011-01-18 20:55:11 +0000 | [diff] [blame] | 240 | bool &CanAcceptPredicationCode); |
Jim Grosbach | 624bcc7 | 2010-10-29 14:46:02 +0000 | [diff] [blame] | 241 | |
Evan Cheng | 4d1ca96 | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 242 | bool isThumb() const { |
| 243 | // FIXME: Can tablegen auto-generate this? |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 244 | return (STI.getFeatureBits() & ARM::ModeThumb) != 0; |
Evan Cheng | 4d1ca96 | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 245 | } |
Evan Cheng | 4d1ca96 | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 246 | bool isThumbOne() const { |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 247 | return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2) == 0; |
Evan Cheng | 4d1ca96 | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 248 | } |
Jim Grosbach | 3e941ae | 2011-08-16 20:45:50 +0000 | [diff] [blame] | 249 | bool isThumbTwo() const { |
| 250 | return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2); |
| 251 | } |
Tim Northover | a2292d0 | 2013-06-10 23:20:58 +0000 | [diff] [blame] | 252 | bool hasThumb() const { |
| 253 | return STI.getFeatureBits() & ARM::HasV4TOps; |
| 254 | } |
Jim Grosbach | b7fa2c0 | 2011-08-16 22:20:01 +0000 | [diff] [blame] | 255 | bool hasV6Ops() const { |
| 256 | return STI.getFeatureBits() & ARM::HasV6Ops; |
| 257 | } |
Tim Northover | f86d1f0 | 2013-10-07 11:10:47 +0000 | [diff] [blame] | 258 | bool hasV6MOps() const { |
| 259 | return STI.getFeatureBits() & ARM::HasV6MOps; |
| 260 | } |
James Molloy | 21efa7d | 2011-09-28 14:21:38 +0000 | [diff] [blame] | 261 | bool hasV7Ops() const { |
| 262 | return STI.getFeatureBits() & ARM::HasV7Ops; |
| 263 | } |
Joey Gouly | b3f550e | 2013-06-26 16:58:26 +0000 | [diff] [blame] | 264 | bool hasV8Ops() const { |
| 265 | return STI.getFeatureBits() & ARM::HasV8Ops; |
| 266 | } |
Tim Northover | a2292d0 | 2013-06-10 23:20:58 +0000 | [diff] [blame] | 267 | bool hasARM() const { |
| 268 | return !(STI.getFeatureBits() & ARM::FeatureNoARM); |
| 269 | } |
Renato Golin | 92c816c | 2014-09-01 11:25:07 +0000 | [diff] [blame] | 270 | bool hasThumb2DSP() const { |
| 271 | return STI.getFeatureBits() & ARM::FeatureDSPThumb2; |
| 272 | } |
Tim Northover | a2292d0 | 2013-06-10 23:20:58 +0000 | [diff] [blame] | 273 | |
Evan Cheng | 284b467 | 2011-07-08 22:36:29 +0000 | [diff] [blame] | 274 | void SwitchMode() { |
Tim Northover | 26bb14e | 2014-08-18 11:49:42 +0000 | [diff] [blame] | 275 | uint64_t FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb)); |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 276 | setAvailableFeatures(FB); |
Evan Cheng | 284b467 | 2011-07-08 22:36:29 +0000 | [diff] [blame] | 277 | } |
James Molloy | 21efa7d | 2011-09-28 14:21:38 +0000 | [diff] [blame] | 278 | bool isMClass() const { |
| 279 | return STI.getFeatureBits() & ARM::FeatureMClass; |
| 280 | } |
Evan Cheng | 4d1ca96 | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 281 | |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 282 | /// @name Auto-generated Match Functions |
| 283 | /// { |
Daniel Dunbar | 5cd4d0f | 2010-08-11 05:24:50 +0000 | [diff] [blame] | 284 | |
Chris Lattner | 3e4582a | 2010-09-06 19:11:01 +0000 | [diff] [blame] | 285 | #define GET_ASSEMBLER_HEADER |
| 286 | #include "ARMGenAsmMatcher.inc" |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 287 | |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 288 | /// } |
| 289 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 290 | OperandMatchResultTy parseITCondCode(OperandVector &); |
| 291 | OperandMatchResultTy parseCoprocNumOperand(OperandVector &); |
| 292 | OperandMatchResultTy parseCoprocRegOperand(OperandVector &); |
| 293 | OperandMatchResultTy parseCoprocOptionOperand(OperandVector &); |
| 294 | OperandMatchResultTy parseMemBarrierOptOperand(OperandVector &); |
| 295 | OperandMatchResultTy parseInstSyncBarrierOptOperand(OperandVector &); |
| 296 | OperandMatchResultTy parseProcIFlagsOperand(OperandVector &); |
| 297 | OperandMatchResultTy parseMSRMaskOperand(OperandVector &); |
Tim Northover | ee843ef | 2014-08-15 10:47:12 +0000 | [diff] [blame] | 298 | OperandMatchResultTy parseBankedRegOperand(OperandVector &); |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 299 | OperandMatchResultTy parsePKHImm(OperandVector &O, StringRef Op, int Low, |
| 300 | int High); |
| 301 | OperandMatchResultTy parsePKHLSLImm(OperandVector &O) { |
Jim Grosbach | 27c1e25 | 2011-07-21 17:23:04 +0000 | [diff] [blame] | 302 | return parsePKHImm(O, "lsl", 0, 31); |
| 303 | } |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 304 | OperandMatchResultTy parsePKHASRImm(OperandVector &O) { |
Jim Grosbach | 27c1e25 | 2011-07-21 17:23:04 +0000 | [diff] [blame] | 305 | return parsePKHImm(O, "asr", 1, 32); |
| 306 | } |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 307 | OperandMatchResultTy parseSetEndImm(OperandVector &); |
| 308 | OperandMatchResultTy parseShifterImm(OperandVector &); |
| 309 | OperandMatchResultTy parseRotImm(OperandVector &); |
| 310 | OperandMatchResultTy parseBitfield(OperandVector &); |
| 311 | OperandMatchResultTy parsePostIdxReg(OperandVector &); |
| 312 | OperandMatchResultTy parseAM3Offset(OperandVector &); |
| 313 | OperandMatchResultTy parseFPImm(OperandVector &); |
| 314 | OperandMatchResultTy parseVectorList(OperandVector &); |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 315 | OperandMatchResultTy parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, |
| 316 | SMLoc &EndLoc); |
Bruno Cardoso Lopes | ab83050 | 2011-03-31 23:26:08 +0000 | [diff] [blame] | 317 | |
| 318 | // Asm Match Converter Methods |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 319 | void cvtThumbMultiply(MCInst &Inst, const OperandVector &); |
| 320 | void cvtThumbBranches(MCInst &Inst, const OperandVector &); |
Saleem Abdulrasool | 4ab6e73 | 2014-02-23 17:45:36 +0000 | [diff] [blame] | 321 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 322 | bool validateInstruction(MCInst &Inst, const OperandVector &Ops); |
| 323 | bool processInstruction(MCInst &Inst, const OperandVector &Ops); |
| 324 | bool shouldOmitCCOutOperand(StringRef Mnemonic, OperandVector &Operands); |
| 325 | bool shouldOmitPredicateOperand(StringRef Mnemonic, OperandVector &Operands); |
| 326 | |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 327 | public: |
Jim Grosbach | 3e941ae | 2011-08-16 20:45:50 +0000 | [diff] [blame] | 328 | enum ARMMatchResultTy { |
Jim Grosbach | b7fa2c0 | 2011-08-16 22:20:01 +0000 | [diff] [blame] | 329 | Match_RequiresITBlock = FIRST_TARGET_MATCH_RESULT_TY, |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 330 | Match_RequiresNotITBlock, |
Jim Grosbach | b7fa2c0 | 2011-08-16 22:20:01 +0000 | [diff] [blame] | 331 | Match_RequiresV6, |
Jim Grosbach | 087affe | 2012-06-22 23:56:48 +0000 | [diff] [blame] | 332 | Match_RequiresThumb2, |
| 333 | #define GET_OPERAND_DIAGNOSTIC_TYPES |
| 334 | #include "ARMGenAsmMatcher.inc" |
| 335 | |
Jim Grosbach | 3e941ae | 2011-08-16 20:45:50 +0000 | [diff] [blame] | 336 | }; |
| 337 | |
Joey Gouly | 0e76fa7 | 2013-09-12 10:28:05 +0000 | [diff] [blame] | 338 | ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser, |
Evgeniy Stepanov | 0a951b7 | 2014-04-23 11:16:03 +0000 | [diff] [blame] | 339 | const MCInstrInfo &MII, |
| 340 | const MCTargetOptions &Options) |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 341 | : MCTargetAsmParser(), STI(_STI), Parser(_Parser), MII(MII), UC(_Parser) { |
Evan Cheng | 4d1ca96 | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 342 | MCAsmParserExtension::Initialize(_Parser); |
Evan Cheng | 284b467 | 2011-07-08 22:36:29 +0000 | [diff] [blame] | 343 | |
Jim Grosbach | c988e0c | 2012-03-05 19:33:30 +0000 | [diff] [blame] | 344 | // Cache the MCRegisterInfo. |
Bill Wendling | bc07a89 | 2013-06-18 07:20:20 +0000 | [diff] [blame] | 345 | MRI = getContext().getRegisterInfo(); |
Jim Grosbach | c988e0c | 2012-03-05 19:33:30 +0000 | [diff] [blame] | 346 | |
Evan Cheng | 4d1ca96 | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 347 | // Initialize the set of available features. |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 348 | setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits())); |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 349 | |
| 350 | // Not in an ITBlock to start with. |
| 351 | ITState.CurPosition = ~0U; |
Tim Northover | 1744d0a | 2013-10-25 12:49:50 +0000 | [diff] [blame] | 352 | |
| 353 | NextSymbolIsThumb = false; |
Evan Cheng | 4d1ca96 | 2011-07-08 01:53:10 +0000 | [diff] [blame] | 354 | } |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 355 | |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 356 | // Implementation of the MCTargetAsmParser interface: |
Craig Topper | ca7e3e5 | 2014-03-10 03:19:03 +0000 | [diff] [blame] | 357 | bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc) override; |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 358 | bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name, |
| 359 | SMLoc NameLoc, OperandVector &Operands) override; |
Craig Topper | ca7e3e5 | 2014-03-10 03:19:03 +0000 | [diff] [blame] | 360 | bool ParseDirective(AsmToken DirectiveID) override; |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 361 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 362 | unsigned validateTargetOperandClass(MCParsedAsmOperand &Op, |
Craig Topper | ca7e3e5 | 2014-03-10 03:19:03 +0000 | [diff] [blame] | 363 | unsigned Kind) override; |
| 364 | unsigned checkTargetMatchPredicate(MCInst &Inst) override; |
Jim Grosbach | 3e941ae | 2011-08-16 20:45:50 +0000 | [diff] [blame] | 365 | |
Chad Rosier | 4996355 | 2012-10-13 00:26:04 +0000 | [diff] [blame] | 366 | bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode, |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 367 | OperandVector &Operands, MCStreamer &Out, |
Tim Northover | 26bb14e | 2014-08-18 11:49:42 +0000 | [diff] [blame] | 368 | uint64_t &ErrorInfo, |
Craig Topper | ca7e3e5 | 2014-03-10 03:19:03 +0000 | [diff] [blame] | 369 | bool MatchingInlineAsm) override; |
| 370 | void onLabelParsed(MCSymbol *Symbol) override; |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 371 | }; |
Jim Grosbach | 624bcc7 | 2010-10-29 14:46:02 +0000 | [diff] [blame] | 372 | } // end anonymous namespace |
| 373 | |
Chris Lattner | bd7c9fa | 2010-10-28 17:20:03 +0000 | [diff] [blame] | 374 | namespace { |
| 375 | |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 376 | /// ARMOperand - Instances of this class represent a parsed ARM machine |
Joel Jones | 5459754 | 2013-01-09 22:34:16 +0000 | [diff] [blame] | 377 | /// operand. |
Bill Wendling | ee7f1f9 | 2010-11-06 21:42:12 +0000 | [diff] [blame] | 378 | class ARMOperand : public MCParsedAsmOperand { |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 379 | enum KindTy { |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 380 | k_CondCode, |
| 381 | k_CCOut, |
| 382 | k_ITCondMask, |
| 383 | k_CoprocNum, |
| 384 | k_CoprocReg, |
Jim Grosbach | 4839958 | 2011-10-12 17:34:41 +0000 | [diff] [blame] | 385 | k_CoprocOption, |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 386 | k_Immediate, |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 387 | k_MemBarrierOpt, |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 388 | k_InstSyncBarrierOpt, |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 389 | k_Memory, |
| 390 | k_PostIndexRegister, |
| 391 | k_MSRMask, |
Tim Northover | ee843ef | 2014-08-15 10:47:12 +0000 | [diff] [blame] | 392 | k_BankedReg, |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 393 | k_ProcIFlags, |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 394 | k_VectorIndex, |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 395 | k_Register, |
| 396 | k_RegisterList, |
| 397 | k_DPRRegisterList, |
| 398 | k_SPRRegisterList, |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 399 | k_VectorList, |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 400 | k_VectorListAllLanes, |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 401 | k_VectorListIndexed, |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 402 | k_ShiftedRegister, |
| 403 | k_ShiftedImmediate, |
| 404 | k_ShifterImmediate, |
| 405 | k_RotateImmediate, |
| 406 | k_BitfieldDescriptor, |
| 407 | k_Token |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 408 | } Kind; |
| 409 | |
Kevin Enderby | 488f20b | 2014-04-10 20:18:58 +0000 | [diff] [blame] | 410 | SMLoc StartLoc, EndLoc, AlignmentLoc; |
Bill Wendling | 0ab0f67 | 2010-11-18 21:50:54 +0000 | [diff] [blame] | 411 | SmallVector<unsigned, 8> Registers; |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 412 | |
Eric Christopher | 8996c5d | 2013-03-15 00:42:55 +0000 | [diff] [blame] | 413 | struct CCOp { |
| 414 | ARMCC::CondCodes Val; |
| 415 | }; |
| 416 | |
| 417 | struct CopOp { |
| 418 | unsigned Val; |
| 419 | }; |
| 420 | |
| 421 | struct CoprocOptionOp { |
| 422 | unsigned Val; |
| 423 | }; |
| 424 | |
| 425 | struct ITMaskOp { |
| 426 | unsigned Mask:4; |
| 427 | }; |
| 428 | |
| 429 | struct MBOptOp { |
| 430 | ARM_MB::MemBOpt Val; |
| 431 | }; |
| 432 | |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 433 | struct ISBOptOp { |
| 434 | ARM_ISB::InstSyncBOpt Val; |
| 435 | }; |
| 436 | |
Eric Christopher | 8996c5d | 2013-03-15 00:42:55 +0000 | [diff] [blame] | 437 | struct IFlagsOp { |
| 438 | ARM_PROC::IFlags Val; |
| 439 | }; |
| 440 | |
| 441 | struct MMaskOp { |
| 442 | unsigned Val; |
| 443 | }; |
| 444 | |
Tim Northover | ee843ef | 2014-08-15 10:47:12 +0000 | [diff] [blame] | 445 | struct BankedRegOp { |
| 446 | unsigned Val; |
| 447 | }; |
| 448 | |
Eric Christopher | 8996c5d | 2013-03-15 00:42:55 +0000 | [diff] [blame] | 449 | struct TokOp { |
| 450 | const char *Data; |
| 451 | unsigned Length; |
| 452 | }; |
| 453 | |
| 454 | struct RegOp { |
| 455 | unsigned RegNum; |
| 456 | }; |
| 457 | |
| 458 | // A vector register list is a sequential list of 1 to 4 registers. |
| 459 | struct VectorListOp { |
| 460 | unsigned RegNum; |
| 461 | unsigned Count; |
| 462 | unsigned LaneIndex; |
| 463 | bool isDoubleSpaced; |
| 464 | }; |
| 465 | |
| 466 | struct VectorIndexOp { |
| 467 | unsigned Val; |
| 468 | }; |
| 469 | |
| 470 | struct ImmOp { |
| 471 | const MCExpr *Val; |
| 472 | }; |
| 473 | |
| 474 | /// Combined record for all forms of ARM address expressions. |
| 475 | struct MemoryOp { |
| 476 | unsigned BaseRegNum; |
| 477 | // Offset is in OffsetReg or OffsetImm. If both are zero, no offset |
| 478 | // was specified. |
| 479 | const MCConstantExpr *OffsetImm; // Offset immediate value |
| 480 | unsigned OffsetRegNum; // Offset register num, when OffsetImm == NULL |
| 481 | ARM_AM::ShiftOpc ShiftType; // Shift type for OffsetReg |
| 482 | unsigned ShiftImm; // shift for OffsetReg. |
| 483 | unsigned Alignment; // 0 = no alignment specified |
| 484 | // n = alignment in bytes (2, 4, 8, 16, or 32) |
| 485 | unsigned isNegative : 1; // Negated OffsetReg? (~'U' bit) |
| 486 | }; |
| 487 | |
| 488 | struct PostIdxRegOp { |
| 489 | unsigned RegNum; |
| 490 | bool isAdd; |
| 491 | ARM_AM::ShiftOpc ShiftTy; |
| 492 | unsigned ShiftImm; |
| 493 | }; |
| 494 | |
| 495 | struct ShifterImmOp { |
| 496 | bool isASR; |
| 497 | unsigned Imm; |
| 498 | }; |
| 499 | |
| 500 | struct RegShiftedRegOp { |
| 501 | ARM_AM::ShiftOpc ShiftTy; |
| 502 | unsigned SrcReg; |
| 503 | unsigned ShiftReg; |
| 504 | unsigned ShiftImm; |
| 505 | }; |
| 506 | |
| 507 | struct RegShiftedImmOp { |
| 508 | ARM_AM::ShiftOpc ShiftTy; |
| 509 | unsigned SrcReg; |
| 510 | unsigned ShiftImm; |
| 511 | }; |
| 512 | |
| 513 | struct RotImmOp { |
| 514 | unsigned Imm; |
| 515 | }; |
| 516 | |
| 517 | struct BitfieldOp { |
| 518 | unsigned LSB; |
| 519 | unsigned Width; |
| 520 | }; |
| 521 | |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 522 | union { |
Eric Christopher | 8996c5d | 2013-03-15 00:42:55 +0000 | [diff] [blame] | 523 | struct CCOp CC; |
| 524 | struct CopOp Cop; |
| 525 | struct CoprocOptionOp CoprocOption; |
| 526 | struct MBOptOp MBOpt; |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 527 | struct ISBOptOp ISBOpt; |
Eric Christopher | 8996c5d | 2013-03-15 00:42:55 +0000 | [diff] [blame] | 528 | struct ITMaskOp ITMask; |
| 529 | struct IFlagsOp IFlags; |
| 530 | struct MMaskOp MMask; |
Tim Northover | ee843ef | 2014-08-15 10:47:12 +0000 | [diff] [blame] | 531 | struct BankedRegOp BankedReg; |
Eric Christopher | 8996c5d | 2013-03-15 00:42:55 +0000 | [diff] [blame] | 532 | struct TokOp Tok; |
| 533 | struct RegOp Reg; |
| 534 | struct VectorListOp VectorList; |
| 535 | struct VectorIndexOp VectorIndex; |
| 536 | struct ImmOp Imm; |
| 537 | struct MemoryOp Memory; |
| 538 | struct PostIdxRegOp PostIdxReg; |
| 539 | struct ShifterImmOp ShifterImm; |
| 540 | struct RegShiftedRegOp RegShiftedReg; |
| 541 | struct RegShiftedImmOp RegShiftedImm; |
| 542 | struct RotImmOp RotImm; |
| 543 | struct BitfieldOp Bitfield; |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 544 | }; |
Jim Grosbach | 624bcc7 | 2010-10-29 14:46:02 +0000 | [diff] [blame] | 545 | |
Bill Wendling | ee7f1f9 | 2010-11-06 21:42:12 +0000 | [diff] [blame] | 546 | public: |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 547 | ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {} |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 548 | ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() { |
| 549 | Kind = o.Kind; |
| 550 | StartLoc = o.StartLoc; |
| 551 | EndLoc = o.EndLoc; |
| 552 | switch (Kind) { |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 553 | case k_CondCode: |
Daniel Dunbar | d8042b7 | 2010-08-11 06:36:53 +0000 | [diff] [blame] | 554 | CC = o.CC; |
| 555 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 556 | case k_ITCondMask: |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 557 | ITMask = o.ITMask; |
| 558 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 559 | case k_Token: |
Daniel Dunbar | d8042b7 | 2010-08-11 06:36:53 +0000 | [diff] [blame] | 560 | Tok = o.Tok; |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 561 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 562 | case k_CCOut: |
| 563 | case k_Register: |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 564 | Reg = o.Reg; |
| 565 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 566 | case k_RegisterList: |
| 567 | case k_DPRRegisterList: |
| 568 | case k_SPRRegisterList: |
Bill Wendling | 0ab0f67 | 2010-11-18 21:50:54 +0000 | [diff] [blame] | 569 | Registers = o.Registers; |
Bill Wendling | 7cef447 | 2010-11-06 19:56:04 +0000 | [diff] [blame] | 570 | break; |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 571 | case k_VectorList: |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 572 | case k_VectorListAllLanes: |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 573 | case k_VectorListIndexed: |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 574 | VectorList = o.VectorList; |
| 575 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 576 | case k_CoprocNum: |
| 577 | case k_CoprocReg: |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 578 | Cop = o.Cop; |
| 579 | break; |
Jim Grosbach | 4839958 | 2011-10-12 17:34:41 +0000 | [diff] [blame] | 580 | case k_CoprocOption: |
| 581 | CoprocOption = o.CoprocOption; |
| 582 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 583 | case k_Immediate: |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 584 | Imm = o.Imm; |
| 585 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 586 | case k_MemBarrierOpt: |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 587 | MBOpt = o.MBOpt; |
| 588 | break; |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 589 | case k_InstSyncBarrierOpt: |
| 590 | ISBOpt = o.ISBOpt; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 591 | case k_Memory: |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 592 | Memory = o.Memory; |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 593 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 594 | case k_PostIndexRegister: |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 595 | PostIdxReg = o.PostIdxReg; |
| 596 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 597 | case k_MSRMask: |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 598 | MMask = o.MMask; |
| 599 | break; |
Tim Northover | ee843ef | 2014-08-15 10:47:12 +0000 | [diff] [blame] | 600 | case k_BankedReg: |
| 601 | BankedReg = o.BankedReg; |
| 602 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 603 | case k_ProcIFlags: |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 604 | IFlags = o.IFlags; |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 605 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 606 | case k_ShifterImmediate: |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 607 | ShifterImm = o.ShifterImm; |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 608 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 609 | case k_ShiftedRegister: |
Jim Grosbach | ac798e1 | 2011-07-25 20:49:51 +0000 | [diff] [blame] | 610 | RegShiftedReg = o.RegShiftedReg; |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 611 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 612 | case k_ShiftedImmediate: |
Jim Grosbach | ac798e1 | 2011-07-25 20:49:51 +0000 | [diff] [blame] | 613 | RegShiftedImm = o.RegShiftedImm; |
Owen Anderson | b595ed0 | 2011-07-21 18:54:16 +0000 | [diff] [blame] | 614 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 615 | case k_RotateImmediate: |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 616 | RotImm = o.RotImm; |
| 617 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 618 | case k_BitfieldDescriptor: |
Jim Grosbach | 864b609 | 2011-07-28 21:34:26 +0000 | [diff] [blame] | 619 | Bitfield = o.Bitfield; |
| 620 | break; |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 621 | case k_VectorIndex: |
| 622 | VectorIndex = o.VectorIndex; |
| 623 | break; |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 624 | } |
| 625 | } |
Jim Grosbach | 624bcc7 | 2010-10-29 14:46:02 +0000 | [diff] [blame] | 626 | |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 627 | /// getStartLoc - Get the location of the first token of this operand. |
Craig Topper | ca7e3e5 | 2014-03-10 03:19:03 +0000 | [diff] [blame] | 628 | SMLoc getStartLoc() const override { return StartLoc; } |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 629 | /// getEndLoc - Get the location of the last token of this operand. |
Craig Topper | ca7e3e5 | 2014-03-10 03:19:03 +0000 | [diff] [blame] | 630 | SMLoc getEndLoc() const override { return EndLoc; } |
Chad Rosier | 143d0f7 | 2012-09-21 20:51:43 +0000 | [diff] [blame] | 631 | /// getLocRange - Get the range between the first and last token of this |
| 632 | /// operand. |
Benjamin Kramer | 673824b | 2012-04-15 17:04:27 +0000 | [diff] [blame] | 633 | SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); } |
| 634 | |
Kevin Enderby | 488f20b | 2014-04-10 20:18:58 +0000 | [diff] [blame] | 635 | /// getAlignmentLoc - Get the location of the Alignment token of this operand. |
| 636 | SMLoc getAlignmentLoc() const { |
| 637 | assert(Kind == k_Memory && "Invalid access!"); |
| 638 | return AlignmentLoc; |
| 639 | } |
| 640 | |
Daniel Dunbar | d8042b7 | 2010-08-11 06:36:53 +0000 | [diff] [blame] | 641 | ARMCC::CondCodes getCondCode() const { |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 642 | assert(Kind == k_CondCode && "Invalid access!"); |
Daniel Dunbar | d8042b7 | 2010-08-11 06:36:53 +0000 | [diff] [blame] | 643 | return CC.Val; |
| 644 | } |
| 645 | |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 646 | unsigned getCoproc() const { |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 647 | assert((Kind == k_CoprocNum || Kind == k_CoprocReg) && "Invalid access!"); |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 648 | return Cop.Val; |
| 649 | } |
| 650 | |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 651 | StringRef getToken() const { |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 652 | assert(Kind == k_Token && "Invalid access!"); |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 653 | return StringRef(Tok.Data, Tok.Length); |
| 654 | } |
| 655 | |
Craig Topper | ca7e3e5 | 2014-03-10 03:19:03 +0000 | [diff] [blame] | 656 | unsigned getReg() const override { |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 657 | assert((Kind == k_Register || Kind == k_CCOut) && "Invalid access!"); |
Bill Wendling | 2cae327 | 2010-11-09 22:44:22 +0000 | [diff] [blame] | 658 | return Reg.RegNum; |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 659 | } |
| 660 | |
Bill Wendling | bed9465 | 2010-11-09 23:28:44 +0000 | [diff] [blame] | 661 | const SmallVectorImpl<unsigned> &getRegList() const { |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 662 | assert((Kind == k_RegisterList || Kind == k_DPRRegisterList || |
| 663 | Kind == k_SPRRegisterList) && "Invalid access!"); |
Bill Wendling | 0ab0f67 | 2010-11-18 21:50:54 +0000 | [diff] [blame] | 664 | return Registers; |
Bill Wendling | 7cef447 | 2010-11-06 19:56:04 +0000 | [diff] [blame] | 665 | } |
| 666 | |
Kevin Enderby | f507994 | 2009-10-13 22:19:02 +0000 | [diff] [blame] | 667 | const MCExpr *getImm() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 668 | assert(isImm() && "Invalid access!"); |
Kevin Enderby | f507994 | 2009-10-13 22:19:02 +0000 | [diff] [blame] | 669 | return Imm.Val; |
| 670 | } |
| 671 | |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 672 | unsigned getVectorIndex() const { |
| 673 | assert(Kind == k_VectorIndex && "Invalid access!"); |
| 674 | return VectorIndex.Val; |
| 675 | } |
| 676 | |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 677 | ARM_MB::MemBOpt getMemBarrierOpt() const { |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 678 | assert(Kind == k_MemBarrierOpt && "Invalid access!"); |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 679 | return MBOpt.Val; |
| 680 | } |
| 681 | |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 682 | ARM_ISB::InstSyncBOpt getInstSyncBarrierOpt() const { |
| 683 | assert(Kind == k_InstSyncBarrierOpt && "Invalid access!"); |
| 684 | return ISBOpt.Val; |
| 685 | } |
| 686 | |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 687 | ARM_PROC::IFlags getProcIFlags() const { |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 688 | assert(Kind == k_ProcIFlags && "Invalid access!"); |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 689 | return IFlags.Val; |
| 690 | } |
| 691 | |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 692 | unsigned getMSRMask() const { |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 693 | assert(Kind == k_MSRMask && "Invalid access!"); |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 694 | return MMask.Val; |
| 695 | } |
| 696 | |
Tim Northover | ee843ef | 2014-08-15 10:47:12 +0000 | [diff] [blame] | 697 | unsigned getBankedReg() const { |
| 698 | assert(Kind == k_BankedReg && "Invalid access!"); |
| 699 | return BankedReg.Val; |
| 700 | } |
| 701 | |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 702 | bool isCoprocNum() const { return Kind == k_CoprocNum; } |
| 703 | bool isCoprocReg() const { return Kind == k_CoprocReg; } |
Jim Grosbach | 4839958 | 2011-10-12 17:34:41 +0000 | [diff] [blame] | 704 | bool isCoprocOption() const { return Kind == k_CoprocOption; } |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 705 | bool isCondCode() const { return Kind == k_CondCode; } |
| 706 | bool isCCOut() const { return Kind == k_CCOut; } |
| 707 | bool isITMask() const { return Kind == k_ITCondMask; } |
| 708 | bool isITCondCode() const { return Kind == k_CondCode; } |
Craig Topper | ca7e3e5 | 2014-03-10 03:19:03 +0000 | [diff] [blame] | 709 | bool isImm() const override { return Kind == k_Immediate; } |
Mihai Popa | d36cbaa | 2013-07-03 09:21:44 +0000 | [diff] [blame] | 710 | // checks whether this operand is an unsigned offset which fits is a field |
| 711 | // of specified width and scaled by a specific number of bits |
| 712 | template<unsigned width, unsigned scale> |
| 713 | bool isUnsignedOffset() const { |
| 714 | if (!isImm()) return false; |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 715 | if (isa<MCSymbolRefExpr>(Imm.Val)) return true; |
Mihai Popa | d36cbaa | 2013-07-03 09:21:44 +0000 | [diff] [blame] | 716 | if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) { |
| 717 | int64_t Val = CE->getValue(); |
| 718 | int64_t Align = 1LL << scale; |
| 719 | int64_t Max = Align * ((1LL << width) - 1); |
| 720 | return ((Val % Align) == 0) && (Val >= 0) && (Val <= Max); |
| 721 | } |
| 722 | return false; |
| 723 | } |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 724 | // checks whether this operand is an signed offset which fits is a field |
| 725 | // of specified width and scaled by a specific number of bits |
| 726 | template<unsigned width, unsigned scale> |
| 727 | bool isSignedOffset() const { |
| 728 | if (!isImm()) return false; |
| 729 | if (isa<MCSymbolRefExpr>(Imm.Val)) return true; |
| 730 | if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val)) { |
| 731 | int64_t Val = CE->getValue(); |
| 732 | int64_t Align = 1LL << scale; |
| 733 | int64_t Max = Align * ((1LL << (width-1)) - 1); |
| 734 | int64_t Min = -Align * (1LL << (width-1)); |
| 735 | return ((Val % Align) == 0) && (Val >= Min) && (Val <= Max); |
| 736 | } |
| 737 | return false; |
| 738 | } |
| 739 | |
Mihai Popa | 8a9da5b | 2013-07-22 15:49:36 +0000 | [diff] [blame] | 740 | // checks whether this operand is a memory operand computed as an offset |
| 741 | // applied to PC. the offset may have 8 bits of magnitude and is represented |
| 742 | // with two bits of shift. textually it may be either [pc, #imm], #imm or |
| 743 | // relocable expression... |
| 744 | bool isThumbMemPC() const { |
| 745 | int64_t Val = 0; |
| 746 | if (isImm()) { |
| 747 | if (isa<MCSymbolRefExpr>(Imm.Val)) return true; |
| 748 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Imm.Val); |
| 749 | if (!CE) return false; |
| 750 | Val = CE->getValue(); |
| 751 | } |
| 752 | else if (isMem()) { |
| 753 | if(!Memory.OffsetImm || Memory.OffsetRegNum) return false; |
| 754 | if(Memory.BaseRegNum != ARM::PC) return false; |
| 755 | Val = Memory.OffsetImm->getValue(); |
| 756 | } |
| 757 | else return false; |
Mihai Popa | d79f00b | 2013-08-15 15:43:06 +0000 | [diff] [blame] | 758 | return ((Val % 4) == 0) && (Val >= 0) && (Val <= 1020); |
Mihai Popa | 8a9da5b | 2013-07-22 15:49:36 +0000 | [diff] [blame] | 759 | } |
Jim Grosbach | a9d36fb | 2012-01-20 18:09:51 +0000 | [diff] [blame] | 760 | bool isFPImm() const { |
| 761 | if (!isImm()) return false; |
| 762 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 763 | if (!CE) return false; |
| 764 | int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue())); |
| 765 | return Val != -1; |
| 766 | } |
Jim Grosbach | ea23191 | 2011-12-22 22:19:05 +0000 | [diff] [blame] | 767 | bool isFBits16() const { |
| 768 | if (!isImm()) return false; |
| 769 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 770 | if (!CE) return false; |
| 771 | int64_t Value = CE->getValue(); |
| 772 | return Value >= 0 && Value <= 16; |
| 773 | } |
| 774 | bool isFBits32() const { |
| 775 | if (!isImm()) return false; |
| 776 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 777 | if (!CE) return false; |
| 778 | int64_t Value = CE->getValue(); |
| 779 | return Value >= 1 && Value <= 32; |
| 780 | } |
Jim Grosbach | 7db8d69 | 2011-09-08 22:07:06 +0000 | [diff] [blame] | 781 | bool isImm8s4() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 782 | if (!isImm()) return false; |
Jim Grosbach | 7db8d69 | 2011-09-08 22:07:06 +0000 | [diff] [blame] | 783 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 784 | if (!CE) return false; |
| 785 | int64_t Value = CE->getValue(); |
| 786 | return ((Value & 3) == 0) && Value >= -1020 && Value <= 1020; |
| 787 | } |
Jim Grosbach | 0a0b307 | 2011-08-24 21:22:15 +0000 | [diff] [blame] | 788 | bool isImm0_1020s4() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 789 | if (!isImm()) return false; |
Jim Grosbach | 0a0b307 | 2011-08-24 21:22:15 +0000 | [diff] [blame] | 790 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 791 | if (!CE) return false; |
| 792 | int64_t Value = CE->getValue(); |
| 793 | return ((Value & 3) == 0) && Value >= 0 && Value <= 1020; |
| 794 | } |
| 795 | bool isImm0_508s4() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 796 | if (!isImm()) return false; |
Jim Grosbach | 0a0b307 | 2011-08-24 21:22:15 +0000 | [diff] [blame] | 797 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 798 | if (!CE) return false; |
| 799 | int64_t Value = CE->getValue(); |
| 800 | return ((Value & 3) == 0) && Value >= 0 && Value <= 508; |
| 801 | } |
Jim Grosbach | 930f2f6 | 2012-04-05 20:57:13 +0000 | [diff] [blame] | 802 | bool isImm0_508s4Neg() const { |
| 803 | if (!isImm()) return false; |
| 804 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 805 | if (!CE) return false; |
| 806 | int64_t Value = -CE->getValue(); |
| 807 | // explicitly exclude zero. we want that to use the normal 0_508 version. |
| 808 | return ((Value & 3) == 0) && Value > 0 && Value <= 508; |
| 809 | } |
Artyom Skrobov | fc12e70 | 2013-10-23 10:14:40 +0000 | [diff] [blame] | 810 | bool isImm0_239() 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 | return Value >= 0 && Value < 240; |
| 816 | } |
Jim Grosbach | a6f7a1e | 2011-06-27 23:54:06 +0000 | [diff] [blame] | 817 | bool isImm0_255() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 818 | if (!isImm()) return false; |
Jim Grosbach | a6f7a1e | 2011-06-27 23:54:06 +0000 | [diff] [blame] | 819 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 820 | if (!CE) return false; |
| 821 | int64_t Value = CE->getValue(); |
| 822 | return Value >= 0 && Value < 256; |
| 823 | } |
Jim Grosbach | 930f2f6 | 2012-04-05 20:57:13 +0000 | [diff] [blame] | 824 | bool isImm0_4095() const { |
| 825 | if (!isImm()) return false; |
| 826 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 827 | if (!CE) return false; |
| 828 | int64_t Value = CE->getValue(); |
| 829 | return Value >= 0 && Value < 4096; |
| 830 | } |
| 831 | bool isImm0_4095Neg() const { |
| 832 | if (!isImm()) return false; |
| 833 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 834 | if (!CE) return false; |
| 835 | int64_t Value = -CE->getValue(); |
| 836 | return Value > 0 && Value < 4096; |
| 837 | } |
Jim Grosbach | 9dff9f4 | 2011-12-02 23:34:39 +0000 | [diff] [blame] | 838 | bool isImm0_1() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 839 | if (!isImm()) return false; |
Jim Grosbach | 9dff9f4 | 2011-12-02 23:34:39 +0000 | [diff] [blame] | 840 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 841 | if (!CE) return false; |
| 842 | int64_t Value = CE->getValue(); |
| 843 | return Value >= 0 && Value < 2; |
| 844 | } |
| 845 | bool isImm0_3() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 846 | if (!isImm()) return false; |
Jim Grosbach | 9dff9f4 | 2011-12-02 23:34:39 +0000 | [diff] [blame] | 847 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 848 | if (!CE) return false; |
| 849 | int64_t Value = CE->getValue(); |
| 850 | return Value >= 0 && Value < 4; |
| 851 | } |
Jim Grosbach | 31756c2 | 2011-07-13 22:01:08 +0000 | [diff] [blame] | 852 | bool isImm0_7() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 853 | if (!isImm()) return false; |
Jim Grosbach | 31756c2 | 2011-07-13 22:01:08 +0000 | [diff] [blame] | 854 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 855 | if (!CE) return false; |
| 856 | int64_t Value = CE->getValue(); |
| 857 | return Value >= 0 && Value < 8; |
| 858 | } |
| 859 | bool isImm0_15() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 860 | if (!isImm()) return false; |
Jim Grosbach | 31756c2 | 2011-07-13 22:01:08 +0000 | [diff] [blame] | 861 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 862 | if (!CE) return false; |
| 863 | int64_t Value = CE->getValue(); |
| 864 | return Value >= 0 && Value < 16; |
| 865 | } |
Jim Grosbach | 72e7c4f | 2011-07-21 23:26:25 +0000 | [diff] [blame] | 866 | bool isImm0_31() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 867 | if (!isImm()) return false; |
Jim Grosbach | 72e7c4f | 2011-07-21 23:26:25 +0000 | [diff] [blame] | 868 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 869 | if (!CE) return false; |
| 870 | int64_t Value = CE->getValue(); |
| 871 | return Value >= 0 && Value < 32; |
| 872 | } |
Jim Grosbach | 0032640 | 2011-12-08 01:30:04 +0000 | [diff] [blame] | 873 | bool isImm0_63() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 874 | if (!isImm()) return false; |
Jim Grosbach | 0032640 | 2011-12-08 01:30:04 +0000 | [diff] [blame] | 875 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 876 | if (!CE) return false; |
| 877 | int64_t Value = CE->getValue(); |
| 878 | return Value >= 0 && Value < 64; |
| 879 | } |
Jim Grosbach | d4b8249 | 2011-12-07 01:07:24 +0000 | [diff] [blame] | 880 | bool isImm8() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 881 | if (!isImm()) return false; |
Jim Grosbach | d4b8249 | 2011-12-07 01:07:24 +0000 | [diff] [blame] | 882 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 883 | if (!CE) return false; |
| 884 | int64_t Value = CE->getValue(); |
| 885 | return Value == 8; |
| 886 | } |
| 887 | bool isImm16() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 888 | if (!isImm()) return false; |
Jim Grosbach | d4b8249 | 2011-12-07 01:07:24 +0000 | [diff] [blame] | 889 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 890 | if (!CE) return false; |
| 891 | int64_t Value = CE->getValue(); |
| 892 | return Value == 16; |
| 893 | } |
| 894 | bool isImm32() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 895 | if (!isImm()) return false; |
Jim Grosbach | d4b8249 | 2011-12-07 01:07:24 +0000 | [diff] [blame] | 896 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 897 | if (!CE) return false; |
| 898 | int64_t Value = CE->getValue(); |
| 899 | return Value == 32; |
| 900 | } |
Jim Grosbach | ba7d6ed | 2011-12-08 22:06:06 +0000 | [diff] [blame] | 901 | bool isShrImm8() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 902 | if (!isImm()) return false; |
Jim Grosbach | ba7d6ed | 2011-12-08 22:06:06 +0000 | [diff] [blame] | 903 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 904 | if (!CE) return false; |
| 905 | int64_t Value = CE->getValue(); |
| 906 | return Value > 0 && Value <= 8; |
| 907 | } |
| 908 | bool isShrImm16() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 909 | if (!isImm()) return false; |
Jim Grosbach | ba7d6ed | 2011-12-08 22:06:06 +0000 | [diff] [blame] | 910 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 911 | if (!CE) return false; |
| 912 | int64_t Value = CE->getValue(); |
| 913 | return Value > 0 && Value <= 16; |
| 914 | } |
| 915 | bool isShrImm32() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 916 | if (!isImm()) return false; |
Jim Grosbach | ba7d6ed | 2011-12-08 22:06:06 +0000 | [diff] [blame] | 917 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 918 | if (!CE) return false; |
| 919 | int64_t Value = CE->getValue(); |
| 920 | return Value > 0 && Value <= 32; |
| 921 | } |
| 922 | bool isShrImm64() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 923 | if (!isImm()) return false; |
Jim Grosbach | ba7d6ed | 2011-12-08 22:06:06 +0000 | [diff] [blame] | 924 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 925 | if (!CE) return false; |
| 926 | int64_t Value = CE->getValue(); |
| 927 | return Value > 0 && Value <= 64; |
| 928 | } |
Jim Grosbach | d4b8249 | 2011-12-07 01:07:24 +0000 | [diff] [blame] | 929 | bool isImm1_7() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 930 | if (!isImm()) return false; |
Jim Grosbach | d4b8249 | 2011-12-07 01:07:24 +0000 | [diff] [blame] | 931 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 932 | if (!CE) return false; |
| 933 | int64_t Value = CE->getValue(); |
| 934 | return Value > 0 && Value < 8; |
| 935 | } |
| 936 | bool isImm1_15() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 937 | if (!isImm()) return false; |
Jim Grosbach | d4b8249 | 2011-12-07 01:07:24 +0000 | [diff] [blame] | 938 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 939 | if (!CE) return false; |
| 940 | int64_t Value = CE->getValue(); |
| 941 | return Value > 0 && Value < 16; |
| 942 | } |
| 943 | bool isImm1_31() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 944 | if (!isImm()) return false; |
Jim Grosbach | d4b8249 | 2011-12-07 01:07:24 +0000 | [diff] [blame] | 945 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 946 | if (!CE) return false; |
| 947 | int64_t Value = CE->getValue(); |
| 948 | return Value > 0 && Value < 32; |
| 949 | } |
Jim Grosbach | 475c6db | 2011-07-25 23:09:14 +0000 | [diff] [blame] | 950 | bool isImm1_16() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 951 | if (!isImm()) return false; |
Jim Grosbach | 475c6db | 2011-07-25 23:09:14 +0000 | [diff] [blame] | 952 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 953 | if (!CE) return false; |
| 954 | int64_t Value = CE->getValue(); |
| 955 | return Value > 0 && Value < 17; |
| 956 | } |
Jim Grosbach | 801e0a3 | 2011-07-22 23:16:18 +0000 | [diff] [blame] | 957 | bool isImm1_32() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 958 | if (!isImm()) return false; |
Jim Grosbach | 801e0a3 | 2011-07-22 23:16:18 +0000 | [diff] [blame] | 959 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 960 | if (!CE) return false; |
| 961 | int64_t Value = CE->getValue(); |
| 962 | return Value > 0 && Value < 33; |
| 963 | } |
Jim Grosbach | c14871c | 2011-11-10 19:18:01 +0000 | [diff] [blame] | 964 | bool isImm0_32() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 965 | if (!isImm()) return false; |
Jim Grosbach | c14871c | 2011-11-10 19:18:01 +0000 | [diff] [blame] | 966 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 967 | if (!CE) return false; |
| 968 | int64_t Value = CE->getValue(); |
| 969 | return Value >= 0 && Value < 33; |
| 970 | } |
Jim Grosbach | 975b641 | 2011-07-13 20:10:10 +0000 | [diff] [blame] | 971 | bool isImm0_65535() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 972 | if (!isImm()) return false; |
Jim Grosbach | 975b641 | 2011-07-13 20:10:10 +0000 | [diff] [blame] | 973 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 974 | if (!CE) return false; |
| 975 | int64_t Value = CE->getValue(); |
| 976 | return Value >= 0 && Value < 65536; |
| 977 | } |
Mihai Popa | ae1112b | 2013-08-21 13:14:58 +0000 | [diff] [blame] | 978 | bool isImm256_65535Expr() const { |
| 979 | if (!isImm()) return false; |
| 980 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 981 | // If it's not a constant expression, it'll generate a fixup and be |
| 982 | // handled later. |
| 983 | if (!CE) return true; |
| 984 | int64_t Value = CE->getValue(); |
| 985 | return Value >= 256 && Value < 65536; |
| 986 | } |
Jim Grosbach | 7c09e3c | 2011-07-19 19:13:28 +0000 | [diff] [blame] | 987 | bool isImm0_65535Expr() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 988 | if (!isImm()) return false; |
Jim Grosbach | 7c09e3c | 2011-07-19 19:13:28 +0000 | [diff] [blame] | 989 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 990 | // If it's not a constant expression, it'll generate a fixup and be |
| 991 | // handled later. |
| 992 | if (!CE) return true; |
| 993 | int64_t Value = CE->getValue(); |
| 994 | return Value >= 0 && Value < 65536; |
| 995 | } |
Jim Grosbach | f163784 | 2011-07-26 16:24:27 +0000 | [diff] [blame] | 996 | bool isImm24bit() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 997 | if (!isImm()) return false; |
Jim Grosbach | f163784 | 2011-07-26 16:24:27 +0000 | [diff] [blame] | 998 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 999 | if (!CE) return false; |
| 1000 | int64_t Value = CE->getValue(); |
| 1001 | return Value >= 0 && Value <= 0xffffff; |
| 1002 | } |
Jim Grosbach | 46dd413 | 2011-08-17 21:51:27 +0000 | [diff] [blame] | 1003 | bool isImmThumbSR() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1004 | if (!isImm()) return false; |
Jim Grosbach | 46dd413 | 2011-08-17 21:51:27 +0000 | [diff] [blame] | 1005 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1006 | if (!CE) return false; |
| 1007 | int64_t Value = CE->getValue(); |
| 1008 | return Value > 0 && Value < 33; |
| 1009 | } |
Jim Grosbach | 27c1e25 | 2011-07-21 17:23:04 +0000 | [diff] [blame] | 1010 | bool isPKHLSLImm() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1011 | if (!isImm()) return false; |
Jim Grosbach | 27c1e25 | 2011-07-21 17:23:04 +0000 | [diff] [blame] | 1012 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1013 | if (!CE) return false; |
| 1014 | int64_t Value = CE->getValue(); |
| 1015 | return Value >= 0 && Value < 32; |
| 1016 | } |
| 1017 | bool isPKHASRImm() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1018 | if (!isImm()) return false; |
Jim Grosbach | 27c1e25 | 2011-07-21 17:23:04 +0000 | [diff] [blame] | 1019 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1020 | if (!CE) return false; |
| 1021 | int64_t Value = CE->getValue(); |
| 1022 | return Value > 0 && Value <= 32; |
| 1023 | } |
Jiangning Liu | 10dd40e | 2012-08-02 08:13:13 +0000 | [diff] [blame] | 1024 | bool isAdrLabel() const { |
| 1025 | // If we have an immediate that's not a constant, treat it as a label |
| 1026 | // reference needing a fixup. If it is a constant, but it can't fit |
| 1027 | // into shift immediate encoding, we reject it. |
| 1028 | if (isImm() && !isa<MCConstantExpr>(getImm())) return true; |
| 1029 | else return (isARMSOImm() || isARMSOImmNeg()); |
| 1030 | } |
Jim Grosbach | 9720dcf | 2011-07-19 16:50:30 +0000 | [diff] [blame] | 1031 | bool isARMSOImm() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1032 | if (!isImm()) return false; |
Jim Grosbach | 9720dcf | 2011-07-19 16:50:30 +0000 | [diff] [blame] | 1033 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1034 | if (!CE) return false; |
| 1035 | int64_t Value = CE->getValue(); |
| 1036 | return ARM_AM::getSOImmVal(Value) != -1; |
| 1037 | } |
Jim Grosbach | 3d785ed | 2011-10-28 22:50:54 +0000 | [diff] [blame] | 1038 | bool isARMSOImmNot() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1039 | if (!isImm()) return false; |
Jim Grosbach | 3d785ed | 2011-10-28 22:50:54 +0000 | [diff] [blame] | 1040 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1041 | if (!CE) return false; |
| 1042 | int64_t Value = CE->getValue(); |
| 1043 | return ARM_AM::getSOImmVal(~Value) != -1; |
| 1044 | } |
Jim Grosbach | 3050625 | 2011-12-08 00:31:07 +0000 | [diff] [blame] | 1045 | bool isARMSOImmNeg() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1046 | if (!isImm()) return false; |
Jim Grosbach | 3050625 | 2011-12-08 00:31:07 +0000 | [diff] [blame] | 1047 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1048 | if (!CE) return false; |
| 1049 | int64_t Value = CE->getValue(); |
Jim Grosbach | fdaab53 | 2012-03-30 19:59:02 +0000 | [diff] [blame] | 1050 | // Only use this when not representable as a plain so_imm. |
| 1051 | return ARM_AM::getSOImmVal(Value) == -1 && |
| 1052 | ARM_AM::getSOImmVal(-Value) != -1; |
Jim Grosbach | 3050625 | 2011-12-08 00:31:07 +0000 | [diff] [blame] | 1053 | } |
Jim Grosbach | a6f7a1e | 2011-06-27 23:54:06 +0000 | [diff] [blame] | 1054 | bool isT2SOImm() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1055 | if (!isImm()) return false; |
Jim Grosbach | a6f7a1e | 2011-06-27 23:54:06 +0000 | [diff] [blame] | 1056 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1057 | if (!CE) return false; |
| 1058 | int64_t Value = CE->getValue(); |
| 1059 | return ARM_AM::getT2SOImmVal(Value) != -1; |
| 1060 | } |
Jim Grosbach | b009a87 | 2011-10-28 22:36:30 +0000 | [diff] [blame] | 1061 | bool isT2SOImmNot() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1062 | if (!isImm()) return false; |
Jim Grosbach | b009a87 | 2011-10-28 22:36:30 +0000 | [diff] [blame] | 1063 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1064 | if (!CE) return false; |
| 1065 | int64_t Value = CE->getValue(); |
Mihai Popa | cf276b2 | 2013-08-16 11:55:44 +0000 | [diff] [blame] | 1066 | return ARM_AM::getT2SOImmVal(Value) == -1 && |
| 1067 | ARM_AM::getT2SOImmVal(~Value) != -1; |
Jim Grosbach | b009a87 | 2011-10-28 22:36:30 +0000 | [diff] [blame] | 1068 | } |
Jim Grosbach | 3050625 | 2011-12-08 00:31:07 +0000 | [diff] [blame] | 1069 | bool isT2SOImmNeg() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1070 | if (!isImm()) return false; |
Jim Grosbach | 3050625 | 2011-12-08 00:31:07 +0000 | [diff] [blame] | 1071 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1072 | if (!CE) return false; |
| 1073 | int64_t Value = CE->getValue(); |
Jim Grosbach | fdaab53 | 2012-03-30 19:59:02 +0000 | [diff] [blame] | 1074 | // Only use this when not representable as a plain so_imm. |
| 1075 | return ARM_AM::getT2SOImmVal(Value) == -1 && |
| 1076 | ARM_AM::getT2SOImmVal(-Value) != -1; |
Jim Grosbach | 3050625 | 2011-12-08 00:31:07 +0000 | [diff] [blame] | 1077 | } |
Jim Grosbach | 0a54770 | 2011-07-22 17:44:50 +0000 | [diff] [blame] | 1078 | bool isSetEndImm() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1079 | if (!isImm()) return false; |
Jim Grosbach | 0a54770 | 2011-07-22 17:44:50 +0000 | [diff] [blame] | 1080 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1081 | if (!CE) return false; |
| 1082 | int64_t Value = CE->getValue(); |
| 1083 | return Value == 1 || Value == 0; |
| 1084 | } |
Craig Topper | ca7e3e5 | 2014-03-10 03:19:03 +0000 | [diff] [blame] | 1085 | bool isReg() const override { return Kind == k_Register; } |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 1086 | bool isRegList() const { return Kind == k_RegisterList; } |
| 1087 | bool isDPRRegList() const { return Kind == k_DPRRegisterList; } |
| 1088 | bool isSPRRegList() const { return Kind == k_SPRRegisterList; } |
Craig Topper | ca7e3e5 | 2014-03-10 03:19:03 +0000 | [diff] [blame] | 1089 | bool isToken() const override { return Kind == k_Token; } |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 1090 | bool isMemBarrierOpt() const { return Kind == k_MemBarrierOpt; } |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 1091 | bool isInstSyncBarrierOpt() const { return Kind == k_InstSyncBarrierOpt; } |
Craig Topper | ca7e3e5 | 2014-03-10 03:19:03 +0000 | [diff] [blame] | 1092 | bool isMem() const override { return Kind == k_Memory; } |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 1093 | bool isShifterImm() const { return Kind == k_ShifterImmediate; } |
| 1094 | bool isRegShiftedReg() const { return Kind == k_ShiftedRegister; } |
| 1095 | bool isRegShiftedImm() const { return Kind == k_ShiftedImmediate; } |
| 1096 | bool isRotImm() const { return Kind == k_RotateImmediate; } |
| 1097 | bool isBitfield() const { return Kind == k_BitfieldDescriptor; } |
| 1098 | bool isPostIdxRegShifted() const { return Kind == k_PostIndexRegister; } |
Jim Grosbach | c320c85 | 2011-08-05 21:28:30 +0000 | [diff] [blame] | 1099 | bool isPostIdxReg() const { |
Jim Grosbach | ee201fa | 2011-11-14 17:52:47 +0000 | [diff] [blame] | 1100 | return Kind == k_PostIndexRegister && PostIdxReg.ShiftTy ==ARM_AM::no_shift; |
Jim Grosbach | c320c85 | 2011-08-05 21:28:30 +0000 | [diff] [blame] | 1101 | } |
Kevin Enderby | 488f20b | 2014-04-10 20:18:58 +0000 | [diff] [blame] | 1102 | bool isMemNoOffset(bool alignOK = false, unsigned Alignment = 0) const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1103 | if (!isMem()) |
Bruno Cardoso Lopes | ab83050 | 2011-03-31 23:26:08 +0000 | [diff] [blame] | 1104 | return false; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1105 | // No offset of any kind. |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1106 | return Memory.OffsetRegNum == 0 && Memory.OffsetImm == nullptr && |
Kevin Enderby | 488f20b | 2014-04-10 20:18:58 +0000 | [diff] [blame] | 1107 | (alignOK || Memory.Alignment == Alignment); |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 1108 | } |
Jim Grosbach | 94298a9 | 2012-01-18 22:46:46 +0000 | [diff] [blame] | 1109 | bool isMemPCRelImm12() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1110 | if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) |
Jim Grosbach | 94298a9 | 2012-01-18 22:46:46 +0000 | [diff] [blame] | 1111 | return false; |
| 1112 | // Base register must be PC. |
| 1113 | if (Memory.BaseRegNum != ARM::PC) |
| 1114 | return false; |
| 1115 | // Immediate offset in range [-4095, 4095]. |
| 1116 | if (!Memory.OffsetImm) return true; |
| 1117 | int64_t Val = Memory.OffsetImm->getValue(); |
| 1118 | return (Val > -4096 && Val < 4096) || (Val == INT32_MIN); |
| 1119 | } |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 1120 | bool isAlignedMemory() const { |
| 1121 | return isMemNoOffset(true); |
Bruno Cardoso Lopes | ab83050 | 2011-03-31 23:26:08 +0000 | [diff] [blame] | 1122 | } |
Kevin Enderby | 488f20b | 2014-04-10 20:18:58 +0000 | [diff] [blame] | 1123 | bool isAlignedMemoryNone() const { |
| 1124 | return isMemNoOffset(false, 0); |
| 1125 | } |
| 1126 | bool isDupAlignedMemoryNone() const { |
| 1127 | return isMemNoOffset(false, 0); |
| 1128 | } |
| 1129 | bool isAlignedMemory16() const { |
| 1130 | if (isMemNoOffset(false, 2)) // alignment in bytes for 16-bits is 2. |
| 1131 | return true; |
| 1132 | return isMemNoOffset(false, 0); |
| 1133 | } |
| 1134 | bool isDupAlignedMemory16() const { |
| 1135 | if (isMemNoOffset(false, 2)) // alignment in bytes for 16-bits is 2. |
| 1136 | return true; |
| 1137 | return isMemNoOffset(false, 0); |
| 1138 | } |
| 1139 | bool isAlignedMemory32() const { |
| 1140 | if (isMemNoOffset(false, 4)) // alignment in bytes for 32-bits is 4. |
| 1141 | return true; |
| 1142 | return isMemNoOffset(false, 0); |
| 1143 | } |
| 1144 | bool isDupAlignedMemory32() const { |
| 1145 | if (isMemNoOffset(false, 4)) // alignment in bytes for 32-bits is 4. |
| 1146 | return true; |
| 1147 | return isMemNoOffset(false, 0); |
| 1148 | } |
| 1149 | bool isAlignedMemory64() const { |
| 1150 | if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8. |
| 1151 | return true; |
| 1152 | return isMemNoOffset(false, 0); |
| 1153 | } |
| 1154 | bool isDupAlignedMemory64() const { |
| 1155 | if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8. |
| 1156 | return true; |
| 1157 | return isMemNoOffset(false, 0); |
| 1158 | } |
| 1159 | bool isAlignedMemory64or128() const { |
| 1160 | if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8. |
| 1161 | return true; |
| 1162 | if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16. |
| 1163 | return true; |
| 1164 | return isMemNoOffset(false, 0); |
| 1165 | } |
| 1166 | bool isDupAlignedMemory64or128() const { |
| 1167 | if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8. |
| 1168 | return true; |
| 1169 | if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16. |
| 1170 | return true; |
| 1171 | return isMemNoOffset(false, 0); |
| 1172 | } |
| 1173 | bool isAlignedMemory64or128or256() const { |
| 1174 | if (isMemNoOffset(false, 8)) // alignment in bytes for 64-bits is 8. |
| 1175 | return true; |
| 1176 | if (isMemNoOffset(false, 16)) // alignment in bytes for 128-bits is 16. |
| 1177 | return true; |
| 1178 | if (isMemNoOffset(false, 32)) // alignment in bytes for 256-bits is 32. |
| 1179 | return true; |
| 1180 | return isMemNoOffset(false, 0); |
| 1181 | } |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1182 | bool isAddrMode2() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1183 | if (!isMem() || Memory.Alignment != 0) return false; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1184 | // Check for register offset. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1185 | if (Memory.OffsetRegNum) return true; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1186 | // Immediate offset in range [-4095, 4095]. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1187 | if (!Memory.OffsetImm) return true; |
| 1188 | int64_t Val = Memory.OffsetImm->getValue(); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1189 | return Val > -4096 && Val < 4096; |
Bruno Cardoso Lopes | bda3632 | 2011-04-04 17:18:19 +0000 | [diff] [blame] | 1190 | } |
Jim Grosbach | cd17c12 | 2011-08-04 23:01:30 +0000 | [diff] [blame] | 1191 | bool isAM2OffsetImm() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1192 | if (!isImm()) return false; |
Jim Grosbach | cd17c12 | 2011-08-04 23:01:30 +0000 | [diff] [blame] | 1193 | // Immediate offset in range [-4095, 4095]. |
| 1194 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1195 | if (!CE) return false; |
| 1196 | int64_t Val = CE->getValue(); |
Mihai Popa | c1d119e | 2013-06-11 09:48:35 +0000 | [diff] [blame] | 1197 | return (Val == INT32_MIN) || (Val > -4096 && Val < 4096); |
Jim Grosbach | cd17c12 | 2011-08-04 23:01:30 +0000 | [diff] [blame] | 1198 | } |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 1199 | bool isAddrMode3() const { |
Jim Grosbach | 8648c10 | 2011-12-19 23:06:24 +0000 | [diff] [blame] | 1200 | // If we have an immediate that's not a constant, treat it as a label |
| 1201 | // reference needing a fixup. If it is a constant, it's something else |
| 1202 | // and we reject it. |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1203 | if (isImm() && !isa<MCConstantExpr>(getImm())) |
Jim Grosbach | 8648c10 | 2011-12-19 23:06:24 +0000 | [diff] [blame] | 1204 | return true; |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1205 | if (!isMem() || Memory.Alignment != 0) return false; |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 1206 | // No shifts are legal for AM3. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1207 | if (Memory.ShiftType != ARM_AM::no_shift) return false; |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +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 | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 1210 | // Immediate offset in range [-255, 255]. |
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(); |
Silviu Baranga | 5a719f9 | 2012-05-11 09:10:54 +0000 | [diff] [blame] | 1213 | // The #-0 offset is encoded as INT32_MIN, and we have to check |
| 1214 | // for this too. |
| 1215 | return (Val > -256 && Val < 256) || Val == INT32_MIN; |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 1216 | } |
| 1217 | bool isAM3Offset() const { |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 1218 | if (Kind != k_Immediate && Kind != k_PostIndexRegister) |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 1219 | return false; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 1220 | if (Kind == k_PostIndexRegister) |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 1221 | return PostIdxReg.ShiftTy == ARM_AM::no_shift; |
| 1222 | // Immediate offset in range [-255, 255]. |
| 1223 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1224 | if (!CE) return false; |
| 1225 | int64_t Val = CE->getValue(); |
Jim Grosbach | 1d9d5e9 | 2011-08-10 21:56:18 +0000 | [diff] [blame] | 1226 | // Special case, #-0 is INT32_MIN. |
| 1227 | return (Val > -256 && Val < 256) || Val == INT32_MIN; |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 1228 | } |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1229 | bool isAddrMode5() const { |
Jim Grosbach | fb2f1d6 | 2011-11-01 01:24:45 +0000 | [diff] [blame] | 1230 | // If we have an immediate that's not a constant, treat it as a label |
| 1231 | // reference needing a fixup. If it is a constant, it's something else |
| 1232 | // and we reject it. |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1233 | if (isImm() && !isa<MCConstantExpr>(getImm())) |
Jim Grosbach | fb2f1d6 | 2011-11-01 01:24:45 +0000 | [diff] [blame] | 1234 | return true; |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1235 | if (!isMem() || Memory.Alignment != 0) return false; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1236 | // Check for register offset. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1237 | if (Memory.OffsetRegNum) return false; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1238 | // Immediate offset in range [-1020, 1020] and a multiple of 4. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1239 | if (!Memory.OffsetImm) return true; |
| 1240 | int64_t Val = Memory.OffsetImm->getValue(); |
Owen Anderson | 967674d | 2011-08-29 19:36:44 +0000 | [diff] [blame] | 1241 | return (Val >= -1020 && Val <= 1020 && ((Val & 3) == 0)) || |
Jim Grosbach | fb2f1d6 | 2011-11-01 01:24:45 +0000 | [diff] [blame] | 1242 | Val == INT32_MIN; |
Bill Wendling | 8d2aa03 | 2010-11-08 23:49:57 +0000 | [diff] [blame] | 1243 | } |
Jim Grosbach | 05541f4 | 2011-09-19 22:21:13 +0000 | [diff] [blame] | 1244 | bool isMemTBB() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1245 | if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative || |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 1246 | Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0) |
Jim Grosbach | 05541f4 | 2011-09-19 22:21:13 +0000 | [diff] [blame] | 1247 | return false; |
| 1248 | return true; |
| 1249 | } |
| 1250 | bool isMemTBH() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1251 | if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative || |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 1252 | Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm != 1 || |
| 1253 | Memory.Alignment != 0 ) |
Jim Grosbach | 05541f4 | 2011-09-19 22:21:13 +0000 | [diff] [blame] | 1254 | return false; |
| 1255 | return true; |
| 1256 | } |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1257 | bool isMemRegOffset() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1258 | if (!isMem() || !Memory.OffsetRegNum || Memory.Alignment != 0) |
Bill Wendling | 092a7bd | 2010-12-14 03:36:38 +0000 | [diff] [blame] | 1259 | return false; |
Daniel Dunbar | 7ed4559 | 2011-01-18 05:34:11 +0000 | [diff] [blame] | 1260 | return true; |
Bill Wendling | 092a7bd | 2010-12-14 03:36:38 +0000 | [diff] [blame] | 1261 | } |
Jim Grosbach | e0ebc1c | 2011-09-07 23:10:15 +0000 | [diff] [blame] | 1262 | bool isT2MemRegOffset() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1263 | if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative || |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 1264 | Memory.Alignment != 0) |
Jim Grosbach | e0ebc1c | 2011-09-07 23:10:15 +0000 | [diff] [blame] | 1265 | return false; |
| 1266 | // Only lsl #{0, 1, 2, 3} allowed. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1267 | if (Memory.ShiftType == ARM_AM::no_shift) |
Jim Grosbach | e0ebc1c | 2011-09-07 23:10:15 +0000 | [diff] [blame] | 1268 | return true; |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1269 | if (Memory.ShiftType != ARM_AM::lsl || Memory.ShiftImm > 3) |
Jim Grosbach | e0ebc1c | 2011-09-07 23:10:15 +0000 | [diff] [blame] | 1270 | return false; |
| 1271 | return true; |
| 1272 | } |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1273 | bool isMemThumbRR() const { |
| 1274 | // Thumb reg+reg addressing is simple. Just two registers, a base and |
| 1275 | // an offset. No shifts, negations or any other complicating factors. |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1276 | if (!isMem() || !Memory.OffsetRegNum || Memory.isNegative || |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 1277 | Memory.ShiftType != ARM_AM::no_shift || Memory.Alignment != 0) |
Bill Wendling | 811c936 | 2010-11-30 07:44:32 +0000 | [diff] [blame] | 1278 | return false; |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1279 | return isARMLowRegister(Memory.BaseRegNum) && |
| 1280 | (!Memory.OffsetRegNum || isARMLowRegister(Memory.OffsetRegNum)); |
Jim Grosbach | 3fe94e3 | 2011-08-19 17:55:24 +0000 | [diff] [blame] | 1281 | } |
| 1282 | bool isMemThumbRIs4() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1283 | if (!isMem() || Memory.OffsetRegNum != 0 || |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 1284 | !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0) |
Jim Grosbach | 3fe94e3 | 2011-08-19 17:55:24 +0000 | [diff] [blame] | 1285 | return false; |
| 1286 | // Immediate offset, multiple of 4 in range [0, 124]. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1287 | if (!Memory.OffsetImm) return true; |
| 1288 | int64_t Val = Memory.OffsetImm->getValue(); |
Jim Grosbach | 23983d6 | 2011-08-19 18:13:48 +0000 | [diff] [blame] | 1289 | return Val >= 0 && Val <= 124 && (Val % 4) == 0; |
| 1290 | } |
Jim Grosbach | 26d3587 | 2011-08-19 18:55:51 +0000 | [diff] [blame] | 1291 | bool isMemThumbRIs2() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1292 | if (!isMem() || Memory.OffsetRegNum != 0 || |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 1293 | !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0) |
Jim Grosbach | 26d3587 | 2011-08-19 18:55:51 +0000 | [diff] [blame] | 1294 | return false; |
| 1295 | // Immediate offset, multiple of 4 in range [0, 62]. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1296 | if (!Memory.OffsetImm) return true; |
| 1297 | int64_t Val = Memory.OffsetImm->getValue(); |
Jim Grosbach | 26d3587 | 2011-08-19 18:55:51 +0000 | [diff] [blame] | 1298 | return Val >= 0 && Val <= 62 && (Val % 2) == 0; |
| 1299 | } |
Jim Grosbach | a32c753 | 2011-08-19 18:49:59 +0000 | [diff] [blame] | 1300 | bool isMemThumbRIs1() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1301 | if (!isMem() || Memory.OffsetRegNum != 0 || |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 1302 | !isARMLowRegister(Memory.BaseRegNum) || Memory.Alignment != 0) |
Jim Grosbach | a32c753 | 2011-08-19 18:49:59 +0000 | [diff] [blame] | 1303 | return false; |
| 1304 | // Immediate offset in range [0, 31]. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1305 | if (!Memory.OffsetImm) return true; |
| 1306 | int64_t Val = Memory.OffsetImm->getValue(); |
Jim Grosbach | a32c753 | 2011-08-19 18:49:59 +0000 | [diff] [blame] | 1307 | return Val >= 0 && Val <= 31; |
| 1308 | } |
Jim Grosbach | 23983d6 | 2011-08-19 18:13:48 +0000 | [diff] [blame] | 1309 | bool isMemThumbSPI() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1310 | if (!isMem() || Memory.OffsetRegNum != 0 || |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 1311 | Memory.BaseRegNum != ARM::SP || Memory.Alignment != 0) |
Jim Grosbach | 23983d6 | 2011-08-19 18:13:48 +0000 | [diff] [blame] | 1312 | return false; |
| 1313 | // Immediate offset, multiple of 4 in range [0, 1020]. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1314 | if (!Memory.OffsetImm) return true; |
| 1315 | int64_t Val = Memory.OffsetImm->getValue(); |
Jim Grosbach | 23983d6 | 2011-08-19 18:13:48 +0000 | [diff] [blame] | 1316 | return Val >= 0 && Val <= 1020 && (Val % 4) == 0; |
Bill Wendling | 811c936 | 2010-11-30 07:44:32 +0000 | [diff] [blame] | 1317 | } |
Jim Grosbach | 7db8d69 | 2011-09-08 22:07:06 +0000 | [diff] [blame] | 1318 | bool isMemImm8s4Offset() const { |
Jim Grosbach | 8648c10 | 2011-12-19 23:06:24 +0000 | [diff] [blame] | 1319 | // If we have an immediate that's not a constant, treat it as a label |
| 1320 | // reference needing a fixup. If it is a constant, it's something else |
| 1321 | // and we reject it. |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1322 | if (isImm() && !isa<MCConstantExpr>(getImm())) |
Jim Grosbach | 8648c10 | 2011-12-19 23:06:24 +0000 | [diff] [blame] | 1323 | return true; |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1324 | if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) |
Jim Grosbach | 7db8d69 | 2011-09-08 22:07:06 +0000 | [diff] [blame] | 1325 | return false; |
| 1326 | // Immediate offset a multiple of 4 in range [-1020, 1020]. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1327 | if (!Memory.OffsetImm) return true; |
| 1328 | int64_t Val = Memory.OffsetImm->getValue(); |
Jiangning Liu | 6a43bf7 | 2012-08-02 08:29:50 +0000 | [diff] [blame] | 1329 | // Special case, #-0 is INT32_MIN. |
| 1330 | return (Val >= -1020 && Val <= 1020 && (Val & 3) == 0) || Val == INT32_MIN; |
Jim Grosbach | 7db8d69 | 2011-09-08 22:07:06 +0000 | [diff] [blame] | 1331 | } |
Jim Grosbach | a05627e | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 1332 | bool isMemImm0_1020s4Offset() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1333 | if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) |
Jim Grosbach | a05627e | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 1334 | return false; |
| 1335 | // Immediate offset a multiple of 4 in range [0, 1020]. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1336 | if (!Memory.OffsetImm) return true; |
| 1337 | int64_t Val = Memory.OffsetImm->getValue(); |
Jim Grosbach | a05627e | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 1338 | return Val >= 0 && Val <= 1020 && (Val & 3) == 0; |
| 1339 | } |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1340 | bool isMemImm8Offset() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1341 | if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1342 | return false; |
Jim Grosbach | 94298a9 | 2012-01-18 22:46:46 +0000 | [diff] [blame] | 1343 | // Base reg of PC isn't allowed for these encodings. |
| 1344 | if (Memory.BaseRegNum == ARM::PC) return false; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1345 | // Immediate offset in range [-255, 255]. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1346 | if (!Memory.OffsetImm) return true; |
| 1347 | int64_t Val = Memory.OffsetImm->getValue(); |
Owen Anderson | 4916840 | 2011-09-23 22:25:02 +0000 | [diff] [blame] | 1348 | return (Val == INT32_MIN) || (Val > -256 && Val < 256); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1349 | } |
Jim Grosbach | 2392c53 | 2011-09-07 23:39:14 +0000 | [diff] [blame] | 1350 | bool isMemPosImm8Offset() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1351 | if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) |
Jim Grosbach | 2392c53 | 2011-09-07 23:39:14 +0000 | [diff] [blame] | 1352 | return false; |
| 1353 | // Immediate offset in range [0, 255]. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1354 | if (!Memory.OffsetImm) return true; |
| 1355 | int64_t Val = Memory.OffsetImm->getValue(); |
Jim Grosbach | 2392c53 | 2011-09-07 23:39:14 +0000 | [diff] [blame] | 1356 | return Val >= 0 && Val < 256; |
| 1357 | } |
Jim Grosbach | 5bfa8ba | 2011-09-07 20:58:57 +0000 | [diff] [blame] | 1358 | bool isMemNegImm8Offset() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1359 | if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) |
Jim Grosbach | 5bfa8ba | 2011-09-07 20:58:57 +0000 | [diff] [blame] | 1360 | return false; |
Jim Grosbach | 94298a9 | 2012-01-18 22:46:46 +0000 | [diff] [blame] | 1361 | // Base reg of PC isn't allowed for these encodings. |
| 1362 | if (Memory.BaseRegNum == ARM::PC) return false; |
Jim Grosbach | 5bfa8ba | 2011-09-07 20:58:57 +0000 | [diff] [blame] | 1363 | // Immediate offset in range [-255, -1]. |
Jim Grosbach | 175c7d0 | 2011-12-06 04:49:29 +0000 | [diff] [blame] | 1364 | if (!Memory.OffsetImm) return false; |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1365 | int64_t Val = Memory.OffsetImm->getValue(); |
Jim Grosbach | 175c7d0 | 2011-12-06 04:49:29 +0000 | [diff] [blame] | 1366 | return (Val == INT32_MIN) || (Val > -256 && Val < 0); |
Jim Grosbach | 5bfa8ba | 2011-09-07 20:58:57 +0000 | [diff] [blame] | 1367 | } |
| 1368 | bool isMemUImm12Offset() const { |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1369 | if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) |
Jim Grosbach | 5bfa8ba | 2011-09-07 20:58:57 +0000 | [diff] [blame] | 1370 | return false; |
| 1371 | // Immediate offset in range [0, 4095]. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1372 | if (!Memory.OffsetImm) return true; |
| 1373 | int64_t Val = Memory.OffsetImm->getValue(); |
Jim Grosbach | 5bfa8ba | 2011-09-07 20:58:57 +0000 | [diff] [blame] | 1374 | return (Val >= 0 && Val < 4096); |
| 1375 | } |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1376 | bool isMemImm12Offset() const { |
Jim Grosbach | 95466ce | 2011-08-08 20:59:31 +0000 | [diff] [blame] | 1377 | // If we have an immediate that's not a constant, treat it as a label |
| 1378 | // reference needing a fixup. If it is a constant, it's something else |
| 1379 | // and we reject it. |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1380 | if (isImm() && !isa<MCConstantExpr>(getImm())) |
Jim Grosbach | 95466ce | 2011-08-08 20:59:31 +0000 | [diff] [blame] | 1381 | return true; |
| 1382 | |
Chad Rosier | 4109983 | 2012-09-11 23:02:35 +0000 | [diff] [blame] | 1383 | if (!isMem() || Memory.OffsetRegNum != 0 || Memory.Alignment != 0) |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1384 | return false; |
| 1385 | // Immediate offset in range [-4095, 4095]. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 1386 | if (!Memory.OffsetImm) return true; |
| 1387 | int64_t Val = Memory.OffsetImm->getValue(); |
Owen Anderson | 967674d | 2011-08-29 19:36:44 +0000 | [diff] [blame] | 1388 | return (Val > -4096 && Val < 4096) || (Val == INT32_MIN); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1389 | } |
| 1390 | bool isPostIdxImm8() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1391 | if (!isImm()) return false; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1392 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1393 | if (!CE) return false; |
| 1394 | int64_t Val = CE->getValue(); |
Owen Anderson | f02d98d | 2011-08-29 17:17:09 +0000 | [diff] [blame] | 1395 | return (Val > -256 && Val < 256) || (Val == INT32_MIN); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1396 | } |
Jim Grosbach | 9398141 | 2011-10-11 21:55:36 +0000 | [diff] [blame] | 1397 | bool isPostIdxImm8s4() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1398 | if (!isImm()) return false; |
Jim Grosbach | 9398141 | 2011-10-11 21:55:36 +0000 | [diff] [blame] | 1399 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1400 | if (!CE) return false; |
| 1401 | int64_t Val = CE->getValue(); |
| 1402 | return ((Val & 3) == 0 && Val >= -1020 && Val <= 1020) || |
| 1403 | (Val == INT32_MIN); |
| 1404 | } |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 1405 | |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 1406 | bool isMSRMask() const { return Kind == k_MSRMask; } |
Tim Northover | ee843ef | 2014-08-15 10:47:12 +0000 | [diff] [blame] | 1407 | bool isBankedReg() const { return Kind == k_BankedReg; } |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 1408 | bool isProcIFlags() const { return Kind == k_ProcIFlags; } |
Daniel Dunbar | 5cd4d0f | 2010-08-11 05:24:50 +0000 | [diff] [blame] | 1409 | |
Jim Grosbach | 741cd73 | 2011-10-17 22:26:03 +0000 | [diff] [blame] | 1410 | // NEON operands. |
Jim Grosbach | 2f50e92 | 2011-12-15 21:44:33 +0000 | [diff] [blame] | 1411 | bool isSingleSpacedVectorList() const { |
| 1412 | return Kind == k_VectorList && !VectorList.isDoubleSpaced; |
| 1413 | } |
| 1414 | bool isDoubleSpacedVectorList() const { |
| 1415 | return Kind == k_VectorList && VectorList.isDoubleSpaced; |
| 1416 | } |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 1417 | bool isVecListOneD() const { |
Jim Grosbach | 2f50e92 | 2011-12-15 21:44:33 +0000 | [diff] [blame] | 1418 | if (!isSingleSpacedVectorList()) return false; |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 1419 | return VectorList.Count == 1; |
| 1420 | } |
| 1421 | |
Jim Grosbach | c988e0c | 2012-03-05 19:33:30 +0000 | [diff] [blame] | 1422 | bool isVecListDPair() const { |
| 1423 | if (!isSingleSpacedVectorList()) return false; |
| 1424 | return (ARMMCRegisterClasses[ARM::DPairRegClassID] |
| 1425 | .contains(VectorList.RegNum)); |
| 1426 | } |
| 1427 | |
Jim Grosbach | c4360fe | 2011-10-21 20:02:19 +0000 | [diff] [blame] | 1428 | bool isVecListThreeD() const { |
Jim Grosbach | 2f50e92 | 2011-12-15 21:44:33 +0000 | [diff] [blame] | 1429 | if (!isSingleSpacedVectorList()) return false; |
Jim Grosbach | c4360fe | 2011-10-21 20:02:19 +0000 | [diff] [blame] | 1430 | return VectorList.Count == 3; |
| 1431 | } |
| 1432 | |
Jim Grosbach | 846bcff | 2011-10-21 20:35:01 +0000 | [diff] [blame] | 1433 | bool isVecListFourD() const { |
Jim Grosbach | 2f50e92 | 2011-12-15 21:44:33 +0000 | [diff] [blame] | 1434 | if (!isSingleSpacedVectorList()) return false; |
Jim Grosbach | 846bcff | 2011-10-21 20:35:01 +0000 | [diff] [blame] | 1435 | return VectorList.Count == 4; |
| 1436 | } |
| 1437 | |
Jim Grosbach | e5307f9 | 2012-03-05 21:43:40 +0000 | [diff] [blame] | 1438 | bool isVecListDPairSpaced() const { |
Kevin Enderby | 5611398 | 2014-03-26 21:54:11 +0000 | [diff] [blame] | 1439 | if (Kind != k_VectorList) return false; |
Kevin Enderby | 816ca27 | 2012-03-20 17:41:51 +0000 | [diff] [blame] | 1440 | if (isSingleSpacedVectorList()) return false; |
Jim Grosbach | e5307f9 | 2012-03-05 21:43:40 +0000 | [diff] [blame] | 1441 | return (ARMMCRegisterClasses[ARM::DPairSpcRegClassID] |
| 1442 | .contains(VectorList.RegNum)); |
| 1443 | } |
| 1444 | |
Jim Grosbach | ac2af3f | 2012-01-23 23:20:46 +0000 | [diff] [blame] | 1445 | bool isVecListThreeQ() const { |
| 1446 | if (!isDoubleSpacedVectorList()) return false; |
| 1447 | return VectorList.Count == 3; |
| 1448 | } |
| 1449 | |
Jim Grosbach | 1e946a4 | 2012-01-24 00:43:12 +0000 | [diff] [blame] | 1450 | bool isVecListFourQ() const { |
| 1451 | if (!isDoubleSpacedVectorList()) return false; |
| 1452 | return VectorList.Count == 4; |
| 1453 | } |
| 1454 | |
Jim Grosbach | c5af54e | 2011-12-21 00:38:54 +0000 | [diff] [blame] | 1455 | bool isSingleSpacedVectorAllLanes() const { |
| 1456 | return Kind == k_VectorListAllLanes && !VectorList.isDoubleSpaced; |
| 1457 | } |
| 1458 | bool isDoubleSpacedVectorAllLanes() const { |
| 1459 | return Kind == k_VectorListAllLanes && VectorList.isDoubleSpaced; |
| 1460 | } |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 1461 | bool isVecListOneDAllLanes() const { |
Jim Grosbach | c5af54e | 2011-12-21 00:38:54 +0000 | [diff] [blame] | 1462 | if (!isSingleSpacedVectorAllLanes()) return false; |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 1463 | return VectorList.Count == 1; |
| 1464 | } |
| 1465 | |
Jim Grosbach | 13a292c | 2012-03-06 22:01:44 +0000 | [diff] [blame] | 1466 | bool isVecListDPairAllLanes() const { |
Jim Grosbach | c5af54e | 2011-12-21 00:38:54 +0000 | [diff] [blame] | 1467 | if (!isSingleSpacedVectorAllLanes()) return false; |
Jim Grosbach | 13a292c | 2012-03-06 22:01:44 +0000 | [diff] [blame] | 1468 | return (ARMMCRegisterClasses[ARM::DPairRegClassID] |
| 1469 | .contains(VectorList.RegNum)); |
Jim Grosbach | c5af54e | 2011-12-21 00:38:54 +0000 | [diff] [blame] | 1470 | } |
| 1471 | |
Jim Grosbach | ed428bc | 2012-03-06 23:10:38 +0000 | [diff] [blame] | 1472 | bool isVecListDPairSpacedAllLanes() const { |
Jim Grosbach | c5af54e | 2011-12-21 00:38:54 +0000 | [diff] [blame] | 1473 | if (!isDoubleSpacedVectorAllLanes()) return false; |
Jim Grosbach | 3ecf976 | 2011-11-30 18:21:25 +0000 | [diff] [blame] | 1474 | return VectorList.Count == 2; |
| 1475 | } |
| 1476 | |
Jim Grosbach | b78403c | 2012-01-24 23:47:04 +0000 | [diff] [blame] | 1477 | bool isVecListThreeDAllLanes() const { |
| 1478 | if (!isSingleSpacedVectorAllLanes()) return false; |
| 1479 | return VectorList.Count == 3; |
| 1480 | } |
| 1481 | |
| 1482 | bool isVecListThreeQAllLanes() const { |
| 1483 | if (!isDoubleSpacedVectorAllLanes()) return false; |
| 1484 | return VectorList.Count == 3; |
| 1485 | } |
| 1486 | |
Jim Grosbach | 086cbfa | 2012-01-25 00:01:08 +0000 | [diff] [blame] | 1487 | bool isVecListFourDAllLanes() const { |
| 1488 | if (!isSingleSpacedVectorAllLanes()) return false; |
| 1489 | return VectorList.Count == 4; |
| 1490 | } |
| 1491 | |
| 1492 | bool isVecListFourQAllLanes() const { |
| 1493 | if (!isDoubleSpacedVectorAllLanes()) return false; |
| 1494 | return VectorList.Count == 4; |
| 1495 | } |
| 1496 | |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 1497 | bool isSingleSpacedVectorIndexed() const { |
| 1498 | return Kind == k_VectorListIndexed && !VectorList.isDoubleSpaced; |
| 1499 | } |
| 1500 | bool isDoubleSpacedVectorIndexed() const { |
| 1501 | return Kind == k_VectorListIndexed && VectorList.isDoubleSpaced; |
| 1502 | } |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 1503 | bool isVecListOneDByteIndexed() const { |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 1504 | if (!isSingleSpacedVectorIndexed()) return false; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 1505 | return VectorList.Count == 1 && VectorList.LaneIndex <= 7; |
| 1506 | } |
| 1507 | |
Jim Grosbach | da51104 | 2011-12-14 23:35:06 +0000 | [diff] [blame] | 1508 | bool isVecListOneDHWordIndexed() const { |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 1509 | if (!isSingleSpacedVectorIndexed()) return false; |
Jim Grosbach | da51104 | 2011-12-14 23:35:06 +0000 | [diff] [blame] | 1510 | return VectorList.Count == 1 && VectorList.LaneIndex <= 3; |
| 1511 | } |
| 1512 | |
| 1513 | bool isVecListOneDWordIndexed() const { |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 1514 | if (!isSingleSpacedVectorIndexed()) return false; |
Jim Grosbach | da51104 | 2011-12-14 23:35:06 +0000 | [diff] [blame] | 1515 | return VectorList.Count == 1 && VectorList.LaneIndex <= 1; |
| 1516 | } |
| 1517 | |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 1518 | bool isVecListTwoDByteIndexed() const { |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 1519 | if (!isSingleSpacedVectorIndexed()) return false; |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 1520 | return VectorList.Count == 2 && VectorList.LaneIndex <= 7; |
| 1521 | } |
| 1522 | |
Jim Grosbach | da51104 | 2011-12-14 23:35:06 +0000 | [diff] [blame] | 1523 | bool isVecListTwoDHWordIndexed() const { |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 1524 | if (!isSingleSpacedVectorIndexed()) return false; |
| 1525 | return VectorList.Count == 2 && VectorList.LaneIndex <= 3; |
| 1526 | } |
| 1527 | |
| 1528 | bool isVecListTwoQWordIndexed() const { |
| 1529 | if (!isDoubleSpacedVectorIndexed()) return false; |
| 1530 | return VectorList.Count == 2 && VectorList.LaneIndex <= 1; |
| 1531 | } |
| 1532 | |
| 1533 | bool isVecListTwoQHWordIndexed() const { |
| 1534 | if (!isDoubleSpacedVectorIndexed()) return false; |
Jim Grosbach | da51104 | 2011-12-14 23:35:06 +0000 | [diff] [blame] | 1535 | return VectorList.Count == 2 && VectorList.LaneIndex <= 3; |
| 1536 | } |
| 1537 | |
| 1538 | bool isVecListTwoDWordIndexed() const { |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 1539 | if (!isSingleSpacedVectorIndexed()) return false; |
Jim Grosbach | da51104 | 2011-12-14 23:35:06 +0000 | [diff] [blame] | 1540 | return VectorList.Count == 2 && VectorList.LaneIndex <= 1; |
| 1541 | } |
| 1542 | |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 1543 | bool isVecListThreeDByteIndexed() const { |
| 1544 | if (!isSingleSpacedVectorIndexed()) return false; |
| 1545 | return VectorList.Count == 3 && VectorList.LaneIndex <= 7; |
| 1546 | } |
| 1547 | |
| 1548 | bool isVecListThreeDHWordIndexed() const { |
| 1549 | if (!isSingleSpacedVectorIndexed()) return false; |
| 1550 | return VectorList.Count == 3 && VectorList.LaneIndex <= 3; |
| 1551 | } |
| 1552 | |
| 1553 | bool isVecListThreeQWordIndexed() const { |
| 1554 | if (!isDoubleSpacedVectorIndexed()) return false; |
| 1555 | return VectorList.Count == 3 && VectorList.LaneIndex <= 1; |
| 1556 | } |
| 1557 | |
| 1558 | bool isVecListThreeQHWordIndexed() const { |
| 1559 | if (!isDoubleSpacedVectorIndexed()) return false; |
| 1560 | return VectorList.Count == 3 && VectorList.LaneIndex <= 3; |
| 1561 | } |
| 1562 | |
| 1563 | bool isVecListThreeDWordIndexed() const { |
| 1564 | if (!isSingleSpacedVectorIndexed()) return false; |
| 1565 | return VectorList.Count == 3 && VectorList.LaneIndex <= 1; |
| 1566 | } |
| 1567 | |
Jim Grosbach | 14952a0 | 2012-01-24 18:37:25 +0000 | [diff] [blame] | 1568 | bool isVecListFourDByteIndexed() const { |
| 1569 | if (!isSingleSpacedVectorIndexed()) return false; |
| 1570 | return VectorList.Count == 4 && VectorList.LaneIndex <= 7; |
| 1571 | } |
| 1572 | |
| 1573 | bool isVecListFourDHWordIndexed() const { |
| 1574 | if (!isSingleSpacedVectorIndexed()) return false; |
| 1575 | return VectorList.Count == 4 && VectorList.LaneIndex <= 3; |
| 1576 | } |
| 1577 | |
| 1578 | bool isVecListFourQWordIndexed() const { |
| 1579 | if (!isDoubleSpacedVectorIndexed()) return false; |
| 1580 | return VectorList.Count == 4 && VectorList.LaneIndex <= 1; |
| 1581 | } |
| 1582 | |
| 1583 | bool isVecListFourQHWordIndexed() const { |
| 1584 | if (!isDoubleSpacedVectorIndexed()) return false; |
| 1585 | return VectorList.Count == 4 && VectorList.LaneIndex <= 3; |
| 1586 | } |
| 1587 | |
| 1588 | bool isVecListFourDWordIndexed() const { |
| 1589 | if (!isSingleSpacedVectorIndexed()) return false; |
| 1590 | return VectorList.Count == 4 && VectorList.LaneIndex <= 1; |
| 1591 | } |
| 1592 | |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 1593 | bool isVectorIndex8() const { |
| 1594 | if (Kind != k_VectorIndex) return false; |
| 1595 | return VectorIndex.Val < 8; |
| 1596 | } |
| 1597 | bool isVectorIndex16() const { |
| 1598 | if (Kind != k_VectorIndex) return false; |
| 1599 | return VectorIndex.Val < 4; |
| 1600 | } |
| 1601 | bool isVectorIndex32() const { |
| 1602 | if (Kind != k_VectorIndex) return false; |
| 1603 | return VectorIndex.Val < 2; |
| 1604 | } |
| 1605 | |
Jim Grosbach | 741cd73 | 2011-10-17 22:26:03 +0000 | [diff] [blame] | 1606 | bool isNEONi8splat() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1607 | if (!isImm()) return false; |
Jim Grosbach | 741cd73 | 2011-10-17 22:26:03 +0000 | [diff] [blame] | 1608 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1609 | // Must be a constant. |
| 1610 | if (!CE) return false; |
| 1611 | int64_t Value = CE->getValue(); |
| 1612 | // i8 value splatted across 8 bytes. The immediate is just the 8 byte |
| 1613 | // value. |
Jim Grosbach | 741cd73 | 2011-10-17 22:26:03 +0000 | [diff] [blame] | 1614 | return Value >= 0 && Value < 256; |
| 1615 | } |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 1616 | |
Jim Grosbach | cda32ae | 2011-10-17 23:09:09 +0000 | [diff] [blame] | 1617 | bool isNEONi16splat() const { |
Stepan Dyatkovskiy | 00dcc0f | 2014-04-24 06:03:01 +0000 | [diff] [blame] | 1618 | if (isNEONByteReplicate(2)) |
| 1619 | return false; // Leave that for bytes replication and forbid by default. |
| 1620 | if (!isImm()) |
| 1621 | return false; |
Jim Grosbach | cda32ae | 2011-10-17 23:09:09 +0000 | [diff] [blame] | 1622 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1623 | // Must be a constant. |
| 1624 | if (!CE) return false; |
Renato Golin | f5dd1da | 2014-09-25 11:31:24 +0000 | [diff] [blame] | 1625 | unsigned Value = CE->getValue(); |
| 1626 | return ARM_AM::isNEONi16splat(Value); |
| 1627 | } |
| 1628 | |
| 1629 | bool isNEONi16splatNot() const { |
| 1630 | if (!isImm()) |
| 1631 | return false; |
| 1632 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1633 | // Must be a constant. |
| 1634 | if (!CE) return false; |
| 1635 | unsigned Value = CE->getValue(); |
| 1636 | return ARM_AM::isNEONi16splat(~Value & 0xffff); |
Jim Grosbach | cda32ae | 2011-10-17 23:09:09 +0000 | [diff] [blame] | 1637 | } |
| 1638 | |
Jim Grosbach | 8211c05 | 2011-10-18 00:22:00 +0000 | [diff] [blame] | 1639 | bool isNEONi32splat() const { |
Stepan Dyatkovskiy | 00dcc0f | 2014-04-24 06:03:01 +0000 | [diff] [blame] | 1640 | if (isNEONByteReplicate(4)) |
| 1641 | return false; // Leave that for bytes replication and forbid by default. |
| 1642 | if (!isImm()) |
| 1643 | return false; |
Jim Grosbach | 8211c05 | 2011-10-18 00:22:00 +0000 | [diff] [blame] | 1644 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1645 | // Must be a constant. |
| 1646 | if (!CE) return false; |
Renato Golin | f5dd1da | 2014-09-25 11:31:24 +0000 | [diff] [blame] | 1647 | unsigned Value = CE->getValue(); |
| 1648 | return ARM_AM::isNEONi32splat(Value); |
| 1649 | } |
| 1650 | |
| 1651 | bool isNEONi32splatNot() const { |
| 1652 | if (!isImm()) |
| 1653 | return false; |
| 1654 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1655 | // Must be a constant. |
| 1656 | if (!CE) return false; |
| 1657 | unsigned Value = CE->getValue(); |
| 1658 | return ARM_AM::isNEONi32splat(~Value); |
Jim Grosbach | 8211c05 | 2011-10-18 00:22:00 +0000 | [diff] [blame] | 1659 | } |
| 1660 | |
Stepan Dyatkovskiy | 00dcc0f | 2014-04-24 06:03:01 +0000 | [diff] [blame] | 1661 | bool isNEONByteReplicate(unsigned NumBytes) const { |
| 1662 | if (!isImm()) |
| 1663 | return false; |
Jim Grosbach | 8211c05 | 2011-10-18 00:22:00 +0000 | [diff] [blame] | 1664 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1665 | // Must be a constant. |
Stepan Dyatkovskiy | 00dcc0f | 2014-04-24 06:03:01 +0000 | [diff] [blame] | 1666 | if (!CE) |
| 1667 | return false; |
| 1668 | int64_t Value = CE->getValue(); |
| 1669 | if (!Value) |
| 1670 | return false; // Don't bother with zero. |
| 1671 | |
| 1672 | unsigned char B = Value & 0xff; |
| 1673 | for (unsigned i = 1; i < NumBytes; ++i) { |
| 1674 | Value >>= 8; |
| 1675 | if ((Value & 0xff) != B) |
| 1676 | return false; |
| 1677 | } |
| 1678 | return true; |
| 1679 | } |
| 1680 | bool isNEONi16ByteReplicate() const { return isNEONByteReplicate(2); } |
| 1681 | bool isNEONi32ByteReplicate() const { return isNEONByteReplicate(4); } |
| 1682 | bool isNEONi32vmov() const { |
| 1683 | if (isNEONByteReplicate(4)) |
| 1684 | return false; // Let it to be classified as byte-replicate case. |
| 1685 | if (!isImm()) |
| 1686 | return false; |
| 1687 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1688 | // Must be a constant. |
| 1689 | if (!CE) |
| 1690 | return false; |
Jim Grosbach | 8211c05 | 2011-10-18 00:22:00 +0000 | [diff] [blame] | 1691 | int64_t Value = CE->getValue(); |
| 1692 | // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X, |
| 1693 | // for VMOV/VMVN only, 00Xf or 0Xff are also accepted. |
Renato Golin | f5dd1da | 2014-09-25 11:31:24 +0000 | [diff] [blame] | 1694 | // 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] | 1695 | return (Value >= 0 && Value < 256) || |
| 1696 | (Value >= 0x0100 && Value <= 0xff00) || |
| 1697 | (Value >= 0x010000 && Value <= 0xff0000) || |
| 1698 | (Value >= 0x01000000 && Value <= 0xff000000) || |
| 1699 | (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) || |
| 1700 | (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff); |
| 1701 | } |
Jim Grosbach | 045b6c7 | 2011-12-19 23:51:07 +0000 | [diff] [blame] | 1702 | bool isNEONi32vmovNeg() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1703 | if (!isImm()) return false; |
Jim Grosbach | 045b6c7 | 2011-12-19 23:51:07 +0000 | [diff] [blame] | 1704 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1705 | // Must be a constant. |
| 1706 | if (!CE) return false; |
| 1707 | int64_t Value = ~CE->getValue(); |
| 1708 | // i32 value with set bits only in one byte X000, 0X00, 00X0, or 000X, |
| 1709 | // for VMOV/VMVN only, 00Xf or 0Xff are also accepted. |
Renato Golin | f5dd1da | 2014-09-25 11:31:24 +0000 | [diff] [blame] | 1710 | // 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] | 1711 | return (Value >= 0 && Value < 256) || |
| 1712 | (Value >= 0x0100 && Value <= 0xff00) || |
| 1713 | (Value >= 0x010000 && Value <= 0xff0000) || |
| 1714 | (Value >= 0x01000000 && Value <= 0xff000000) || |
| 1715 | (Value >= 0x01ff && Value <= 0xffff && (Value & 0xff) == 0xff) || |
| 1716 | (Value >= 0x01ffff && Value <= 0xffffff && (Value & 0xffff) == 0xffff); |
| 1717 | } |
Jim Grosbach | 8211c05 | 2011-10-18 00:22:00 +0000 | [diff] [blame] | 1718 | |
Jim Grosbach | e4454e0 | 2011-10-18 16:18:11 +0000 | [diff] [blame] | 1719 | bool isNEONi64splat() const { |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 1720 | if (!isImm()) return false; |
Jim Grosbach | e4454e0 | 2011-10-18 16:18:11 +0000 | [diff] [blame] | 1721 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1722 | // Must be a constant. |
| 1723 | if (!CE) return false; |
| 1724 | uint64_t Value = CE->getValue(); |
| 1725 | // i64 value with each byte being either 0 or 0xff. |
| 1726 | for (unsigned i = 0; i < 8; ++i) |
| 1727 | if ((Value & 0xff) != 0 && (Value & 0xff) != 0xff) return false; |
| 1728 | return true; |
| 1729 | } |
| 1730 | |
Daniel Dunbar | 5cd4d0f | 2010-08-11 05:24:50 +0000 | [diff] [blame] | 1731 | void addExpr(MCInst &Inst, const MCExpr *Expr) const { |
Chris Lattner | 5d6f6a0 | 2010-10-29 00:27:31 +0000 | [diff] [blame] | 1732 | // Add as immediates when possible. Null MCExpr = 0. |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1733 | if (!Expr) |
Chris Lattner | 5d6f6a0 | 2010-10-29 00:27:31 +0000 | [diff] [blame] | 1734 | Inst.addOperand(MCOperand::CreateImm(0)); |
| 1735 | else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr)) |
Daniel Dunbar | 5cd4d0f | 2010-08-11 05:24:50 +0000 | [diff] [blame] | 1736 | Inst.addOperand(MCOperand::CreateImm(CE->getValue())); |
| 1737 | else |
| 1738 | Inst.addOperand(MCOperand::CreateExpr(Expr)); |
| 1739 | } |
| 1740 | |
Daniel Dunbar | d8042b7 | 2010-08-11 06:36:53 +0000 | [diff] [blame] | 1741 | void addCondCodeOperands(MCInst &Inst, unsigned N) const { |
Daniel Dunbar | 188b47b | 2010-08-11 06:37:20 +0000 | [diff] [blame] | 1742 | assert(N == 2 && "Invalid number of operands!"); |
Daniel Dunbar | d8042b7 | 2010-08-11 06:36:53 +0000 | [diff] [blame] | 1743 | Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode()))); |
Jim Grosbach | 968c927 | 2010-12-06 18:30:57 +0000 | [diff] [blame] | 1744 | unsigned RegNum = getCondCode() == ARMCC::AL ? 0: ARM::CPSR; |
| 1745 | Inst.addOperand(MCOperand::CreateReg(RegNum)); |
Daniel Dunbar | d8042b7 | 2010-08-11 06:36:53 +0000 | [diff] [blame] | 1746 | } |
| 1747 | |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 1748 | void addCoprocNumOperands(MCInst &Inst, unsigned N) const { |
| 1749 | assert(N == 1 && "Invalid number of operands!"); |
| 1750 | Inst.addOperand(MCOperand::CreateImm(getCoproc())); |
| 1751 | } |
| 1752 | |
Jim Grosbach | 4839958 | 2011-10-12 17:34:41 +0000 | [diff] [blame] | 1753 | void addCoprocRegOperands(MCInst &Inst, unsigned N) const { |
| 1754 | assert(N == 1 && "Invalid number of operands!"); |
| 1755 | Inst.addOperand(MCOperand::CreateImm(getCoproc())); |
| 1756 | } |
| 1757 | |
| 1758 | void addCoprocOptionOperands(MCInst &Inst, unsigned N) const { |
| 1759 | assert(N == 1 && "Invalid number of operands!"); |
| 1760 | Inst.addOperand(MCOperand::CreateImm(CoprocOption.Val)); |
| 1761 | } |
| 1762 | |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 1763 | void addITMaskOperands(MCInst &Inst, unsigned N) const { |
| 1764 | assert(N == 1 && "Invalid number of operands!"); |
| 1765 | Inst.addOperand(MCOperand::CreateImm(ITMask.Mask)); |
| 1766 | } |
| 1767 | |
| 1768 | void addITCondCodeOperands(MCInst &Inst, unsigned N) const { |
| 1769 | assert(N == 1 && "Invalid number of operands!"); |
| 1770 | Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode()))); |
| 1771 | } |
| 1772 | |
Jim Grosbach | 0bfb4d5 | 2010-12-06 18:21:12 +0000 | [diff] [blame] | 1773 | void addCCOutOperands(MCInst &Inst, unsigned N) const { |
| 1774 | assert(N == 1 && "Invalid number of operands!"); |
| 1775 | Inst.addOperand(MCOperand::CreateReg(getReg())); |
| 1776 | } |
| 1777 | |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 1778 | void addRegOperands(MCInst &Inst, unsigned N) const { |
| 1779 | assert(N == 1 && "Invalid number of operands!"); |
| 1780 | Inst.addOperand(MCOperand::CreateReg(getReg())); |
| 1781 | } |
| 1782 | |
Jim Grosbach | ac798e1 | 2011-07-25 20:49:51 +0000 | [diff] [blame] | 1783 | void addRegShiftedRegOperands(MCInst &Inst, unsigned N) const { |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 1784 | assert(N == 3 && "Invalid number of operands!"); |
Jim Grosbach | ee201fa | 2011-11-14 17:52:47 +0000 | [diff] [blame] | 1785 | assert(isRegShiftedReg() && |
Alp Toker | f907b89 | 2013-12-05 05:44:44 +0000 | [diff] [blame] | 1786 | "addRegShiftedRegOperands() on non-RegShiftedReg!"); |
Jim Grosbach | ac798e1 | 2011-07-25 20:49:51 +0000 | [diff] [blame] | 1787 | Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.SrcReg)); |
| 1788 | Inst.addOperand(MCOperand::CreateReg(RegShiftedReg.ShiftReg)); |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 1789 | Inst.addOperand(MCOperand::CreateImm( |
Jim Grosbach | ac798e1 | 2011-07-25 20:49:51 +0000 | [diff] [blame] | 1790 | ARM_AM::getSORegOpc(RegShiftedReg.ShiftTy, RegShiftedReg.ShiftImm))); |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 1791 | } |
| 1792 | |
Jim Grosbach | ac798e1 | 2011-07-25 20:49:51 +0000 | [diff] [blame] | 1793 | void addRegShiftedImmOperands(MCInst &Inst, unsigned N) const { |
Owen Anderson | 0491270 | 2011-07-21 23:38:37 +0000 | [diff] [blame] | 1794 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | ee201fa | 2011-11-14 17:52:47 +0000 | [diff] [blame] | 1795 | assert(isRegShiftedImm() && |
Alp Toker | f907b89 | 2013-12-05 05:44:44 +0000 | [diff] [blame] | 1796 | "addRegShiftedImmOperands() on non-RegShiftedImm!"); |
Jim Grosbach | ac798e1 | 2011-07-25 20:49:51 +0000 | [diff] [blame] | 1797 | Inst.addOperand(MCOperand::CreateReg(RegShiftedImm.SrcReg)); |
Richard Barton | ba5b0cc | 2012-04-25 18:00:18 +0000 | [diff] [blame] | 1798 | // Shift of #32 is encoded as 0 where permitted |
| 1799 | unsigned Imm = (RegShiftedImm.ShiftImm == 32 ? 0 : RegShiftedImm.ShiftImm); |
Owen Anderson | b595ed0 | 2011-07-21 18:54:16 +0000 | [diff] [blame] | 1800 | Inst.addOperand(MCOperand::CreateImm( |
Richard Barton | ba5b0cc | 2012-04-25 18:00:18 +0000 | [diff] [blame] | 1801 | ARM_AM::getSORegOpc(RegShiftedImm.ShiftTy, Imm))); |
Owen Anderson | b595ed0 | 2011-07-21 18:54:16 +0000 | [diff] [blame] | 1802 | } |
| 1803 | |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 1804 | void addShifterImmOperands(MCInst &Inst, unsigned N) const { |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 1805 | assert(N == 1 && "Invalid number of operands!"); |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 1806 | Inst.addOperand(MCOperand::CreateImm((ShifterImm.isASR << 5) | |
| 1807 | ShifterImm.Imm)); |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 1808 | } |
| 1809 | |
Bill Wendling | 8d2aa03 | 2010-11-08 23:49:57 +0000 | [diff] [blame] | 1810 | void addRegListOperands(MCInst &Inst, unsigned N) const { |
Bill Wendling | 2cae327 | 2010-11-09 22:44:22 +0000 | [diff] [blame] | 1811 | assert(N == 1 && "Invalid number of operands!"); |
Bill Wendling | bed9465 | 2010-11-09 23:28:44 +0000 | [diff] [blame] | 1812 | const SmallVectorImpl<unsigned> &RegList = getRegList(); |
| 1813 | for (SmallVectorImpl<unsigned>::const_iterator |
Bill Wendling | 2cae327 | 2010-11-09 22:44:22 +0000 | [diff] [blame] | 1814 | I = RegList.begin(), E = RegList.end(); I != E; ++I) |
| 1815 | Inst.addOperand(MCOperand::CreateReg(*I)); |
Bill Wendling | 8d2aa03 | 2010-11-08 23:49:57 +0000 | [diff] [blame] | 1816 | } |
| 1817 | |
Bill Wendling | 9898ac9 | 2010-11-17 04:32:08 +0000 | [diff] [blame] | 1818 | void addDPRRegListOperands(MCInst &Inst, unsigned N) const { |
| 1819 | addRegListOperands(Inst, N); |
| 1820 | } |
| 1821 | |
| 1822 | void addSPRRegListOperands(MCInst &Inst, unsigned N) const { |
| 1823 | addRegListOperands(Inst, N); |
| 1824 | } |
| 1825 | |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 1826 | void addRotImmOperands(MCInst &Inst, unsigned N) const { |
| 1827 | assert(N == 1 && "Invalid number of operands!"); |
| 1828 | // Encoded as val>>3. The printer handles display as 8, 16, 24. |
| 1829 | Inst.addOperand(MCOperand::CreateImm(RotImm.Imm >> 3)); |
| 1830 | } |
| 1831 | |
Jim Grosbach | 864b609 | 2011-07-28 21:34:26 +0000 | [diff] [blame] | 1832 | void addBitfieldOperands(MCInst &Inst, unsigned N) const { |
| 1833 | assert(N == 1 && "Invalid number of operands!"); |
| 1834 | // Munge the lsb/width into a bitfield mask. |
| 1835 | unsigned lsb = Bitfield.LSB; |
| 1836 | unsigned width = Bitfield.Width; |
| 1837 | // Make a 32-bit mask w/ the referenced bits clear and all other bits set. |
| 1838 | uint32_t Mask = ~(((uint32_t)0xffffffff >> lsb) << (32 - width) >> |
| 1839 | (32 - (lsb + width))); |
| 1840 | Inst.addOperand(MCOperand::CreateImm(Mask)); |
| 1841 | } |
| 1842 | |
Daniel Dunbar | 5cd4d0f | 2010-08-11 05:24:50 +0000 | [diff] [blame] | 1843 | void addImmOperands(MCInst &Inst, unsigned N) const { |
| 1844 | assert(N == 1 && "Invalid number of operands!"); |
| 1845 | addExpr(Inst, getImm()); |
| 1846 | } |
Jim Grosbach | 624bcc7 | 2010-10-29 14:46:02 +0000 | [diff] [blame] | 1847 | |
Jim Grosbach | ea23191 | 2011-12-22 22:19:05 +0000 | [diff] [blame] | 1848 | void addFBits16Operands(MCInst &Inst, unsigned N) const { |
| 1849 | assert(N == 1 && "Invalid number of operands!"); |
| 1850 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1851 | Inst.addOperand(MCOperand::CreateImm(16 - CE->getValue())); |
| 1852 | } |
| 1853 | |
| 1854 | void addFBits32Operands(MCInst &Inst, unsigned N) const { |
| 1855 | assert(N == 1 && "Invalid number of operands!"); |
| 1856 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1857 | Inst.addOperand(MCOperand::CreateImm(32 - CE->getValue())); |
| 1858 | } |
| 1859 | |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 1860 | void addFPImmOperands(MCInst &Inst, unsigned N) const { |
| 1861 | assert(N == 1 && "Invalid number of operands!"); |
Jim Grosbach | a9d36fb | 2012-01-20 18:09:51 +0000 | [diff] [blame] | 1862 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1863 | int Val = ARM_AM::getFP32Imm(APInt(32, CE->getValue())); |
| 1864 | Inst.addOperand(MCOperand::CreateImm(Val)); |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 1865 | } |
| 1866 | |
Jim Grosbach | 7db8d69 | 2011-09-08 22:07:06 +0000 | [diff] [blame] | 1867 | void addImm8s4Operands(MCInst &Inst, unsigned N) const { |
| 1868 | assert(N == 1 && "Invalid number of operands!"); |
| 1869 | // FIXME: We really want to scale the value here, but the LDRD/STRD |
| 1870 | // instruction don't encode operands that way yet. |
| 1871 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1872 | Inst.addOperand(MCOperand::CreateImm(CE->getValue())); |
| 1873 | } |
| 1874 | |
Jim Grosbach | 0a0b307 | 2011-08-24 21:22:15 +0000 | [diff] [blame] | 1875 | void addImm0_1020s4Operands(MCInst &Inst, unsigned N) const { |
| 1876 | assert(N == 1 && "Invalid number of operands!"); |
| 1877 | // The immediate is scaled by four in the encoding and is stored |
| 1878 | // in the MCInst as such. Lop off the low two bits here. |
| 1879 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1880 | Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4)); |
| 1881 | } |
| 1882 | |
Jim Grosbach | 930f2f6 | 2012-04-05 20:57:13 +0000 | [diff] [blame] | 1883 | void addImm0_508s4NegOperands(MCInst &Inst, unsigned N) const { |
| 1884 | assert(N == 1 && "Invalid number of operands!"); |
| 1885 | // The immediate is scaled by four in the encoding and is stored |
| 1886 | // in the MCInst as such. Lop off the low two bits here. |
| 1887 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1888 | Inst.addOperand(MCOperand::CreateImm(-(CE->getValue() / 4))); |
| 1889 | } |
| 1890 | |
Jim Grosbach | 0a0b307 | 2011-08-24 21:22:15 +0000 | [diff] [blame] | 1891 | void addImm0_508s4Operands(MCInst &Inst, unsigned N) const { |
| 1892 | assert(N == 1 && "Invalid number of operands!"); |
| 1893 | // The immediate is scaled by four in the encoding and is stored |
| 1894 | // in the MCInst as such. Lop off the low two bits here. |
| 1895 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1896 | Inst.addOperand(MCOperand::CreateImm(CE->getValue() / 4)); |
| 1897 | } |
| 1898 | |
Jim Grosbach | 475c6db | 2011-07-25 23:09:14 +0000 | [diff] [blame] | 1899 | void addImm1_16Operands(MCInst &Inst, unsigned N) const { |
| 1900 | assert(N == 1 && "Invalid number of operands!"); |
| 1901 | // The constant encodes as the immediate-1, and we store in the instruction |
| 1902 | // the bits as encoded, so subtract off one here. |
| 1903 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1904 | Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1)); |
| 1905 | } |
| 1906 | |
Jim Grosbach | 801e0a3 | 2011-07-22 23:16:18 +0000 | [diff] [blame] | 1907 | void addImm1_32Operands(MCInst &Inst, unsigned N) const { |
| 1908 | assert(N == 1 && "Invalid number of operands!"); |
| 1909 | // The constant encodes as the immediate-1, and we store in the instruction |
| 1910 | // the bits as encoded, so subtract off one here. |
| 1911 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1912 | Inst.addOperand(MCOperand::CreateImm(CE->getValue() - 1)); |
| 1913 | } |
| 1914 | |
Jim Grosbach | 46dd413 | 2011-08-17 21:51:27 +0000 | [diff] [blame] | 1915 | void addImmThumbSROperands(MCInst &Inst, unsigned N) const { |
| 1916 | assert(N == 1 && "Invalid number of operands!"); |
| 1917 | // The constant encodes as the immediate, except for 32, which encodes as |
| 1918 | // zero. |
| 1919 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1920 | unsigned Imm = CE->getValue(); |
| 1921 | Inst.addOperand(MCOperand::CreateImm((Imm == 32 ? 0 : Imm))); |
| 1922 | } |
| 1923 | |
Jim Grosbach | 27c1e25 | 2011-07-21 17:23:04 +0000 | [diff] [blame] | 1924 | void addPKHASRImmOperands(MCInst &Inst, unsigned N) const { |
| 1925 | assert(N == 1 && "Invalid number of operands!"); |
| 1926 | // An ASR value of 32 encodes as 0, so that's how we want to add it to |
| 1927 | // the instruction as well. |
| 1928 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1929 | int Val = CE->getValue(); |
| 1930 | Inst.addOperand(MCOperand::CreateImm(Val == 32 ? 0 : Val)); |
| 1931 | } |
| 1932 | |
Jim Grosbach | b009a87 | 2011-10-28 22:36:30 +0000 | [diff] [blame] | 1933 | void addT2SOImmNotOperands(MCInst &Inst, unsigned N) const { |
| 1934 | assert(N == 1 && "Invalid number of operands!"); |
| 1935 | // The operand is actually a t2_so_imm, but we have its bitwise |
| 1936 | // negation in the assembly source, so twiddle it here. |
| 1937 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1938 | Inst.addOperand(MCOperand::CreateImm(~CE->getValue())); |
| 1939 | } |
| 1940 | |
Jim Grosbach | 3050625 | 2011-12-08 00:31:07 +0000 | [diff] [blame] | 1941 | void addT2SOImmNegOperands(MCInst &Inst, unsigned N) const { |
| 1942 | assert(N == 1 && "Invalid number of operands!"); |
| 1943 | // The operand is actually a t2_so_imm, but we have its |
| 1944 | // negation in the assembly source, so twiddle it here. |
| 1945 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1946 | Inst.addOperand(MCOperand::CreateImm(-CE->getValue())); |
| 1947 | } |
| 1948 | |
Jim Grosbach | 930f2f6 | 2012-04-05 20:57:13 +0000 | [diff] [blame] | 1949 | void addImm0_4095NegOperands(MCInst &Inst, unsigned N) const { |
| 1950 | assert(N == 1 && "Invalid number of operands!"); |
| 1951 | // The operand is actually an imm0_4095, but we have its |
| 1952 | // negation in the assembly source, so twiddle it here. |
| 1953 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1954 | Inst.addOperand(MCOperand::CreateImm(-CE->getValue())); |
| 1955 | } |
| 1956 | |
Mihai Popa | d36cbaa | 2013-07-03 09:21:44 +0000 | [diff] [blame] | 1957 | void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const { |
| 1958 | if(const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) { |
| 1959 | Inst.addOperand(MCOperand::CreateImm(CE->getValue() >> 2)); |
| 1960 | return; |
| 1961 | } |
| 1962 | |
| 1963 | const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val); |
| 1964 | assert(SR && "Unknown value type!"); |
| 1965 | Inst.addOperand(MCOperand::CreateExpr(SR)); |
| 1966 | } |
| 1967 | |
Mihai Popa | 8a9da5b | 2013-07-22 15:49:36 +0000 | [diff] [blame] | 1968 | void addThumbMemPCOperands(MCInst &Inst, unsigned N) const { |
| 1969 | assert(N == 1 && "Invalid number of operands!"); |
| 1970 | if (isImm()) { |
| 1971 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1972 | if (CE) { |
| 1973 | Inst.addOperand(MCOperand::CreateImm(CE->getValue())); |
| 1974 | return; |
| 1975 | } |
| 1976 | |
| 1977 | const MCSymbolRefExpr *SR = dyn_cast<MCSymbolRefExpr>(Imm.Val); |
| 1978 | assert(SR && "Unknown value type!"); |
| 1979 | Inst.addOperand(MCOperand::CreateExpr(SR)); |
| 1980 | return; |
| 1981 | } |
| 1982 | |
| 1983 | assert(isMem() && "Unknown value type!"); |
| 1984 | assert(isa<MCConstantExpr>(Memory.OffsetImm) && "Unknown value type!"); |
| 1985 | Inst.addOperand(MCOperand::CreateImm(Memory.OffsetImm->getValue())); |
| 1986 | } |
| 1987 | |
Jim Grosbach | 3d785ed | 2011-10-28 22:50:54 +0000 | [diff] [blame] | 1988 | void addARMSOImmNotOperands(MCInst &Inst, unsigned N) const { |
| 1989 | assert(N == 1 && "Invalid number of operands!"); |
| 1990 | // The operand is actually a so_imm, but we have its bitwise |
| 1991 | // negation in the assembly source, so twiddle it here. |
| 1992 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 1993 | Inst.addOperand(MCOperand::CreateImm(~CE->getValue())); |
| 1994 | } |
| 1995 | |
Jim Grosbach | 3050625 | 2011-12-08 00:31:07 +0000 | [diff] [blame] | 1996 | void addARMSOImmNegOperands(MCInst &Inst, unsigned N) const { |
| 1997 | assert(N == 1 && "Invalid number of operands!"); |
| 1998 | // The operand is actually a so_imm, but we have its |
| 1999 | // negation in the assembly source, so twiddle it here. |
| 2000 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2001 | Inst.addOperand(MCOperand::CreateImm(-CE->getValue())); |
| 2002 | } |
| 2003 | |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 2004 | void addMemBarrierOptOperands(MCInst &Inst, unsigned N) const { |
| 2005 | assert(N == 1 && "Invalid number of operands!"); |
| 2006 | Inst.addOperand(MCOperand::CreateImm(unsigned(getMemBarrierOpt()))); |
| 2007 | } |
| 2008 | |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 2009 | void addInstSyncBarrierOptOperands(MCInst &Inst, unsigned N) const { |
| 2010 | assert(N == 1 && "Invalid number of operands!"); |
| 2011 | Inst.addOperand(MCOperand::CreateImm(unsigned(getInstSyncBarrierOpt()))); |
| 2012 | } |
| 2013 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2014 | void addMemNoOffsetOperands(MCInst &Inst, unsigned N) const { |
| 2015 | assert(N == 1 && "Invalid number of operands!"); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2016 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
Bruno Cardoso Lopes | f170f8b | 2011-03-24 21:04:58 +0000 | [diff] [blame] | 2017 | } |
| 2018 | |
Jim Grosbach | 94298a9 | 2012-01-18 22:46:46 +0000 | [diff] [blame] | 2019 | void addMemPCRelImm12Operands(MCInst &Inst, unsigned N) const { |
| 2020 | assert(N == 1 && "Invalid number of operands!"); |
| 2021 | int32_t Imm = Memory.OffsetImm->getValue(); |
Jim Grosbach | 94298a9 | 2012-01-18 22:46:46 +0000 | [diff] [blame] | 2022 | Inst.addOperand(MCOperand::CreateImm(Imm)); |
| 2023 | } |
| 2024 | |
Jiangning Liu | 10dd40e | 2012-08-02 08:13:13 +0000 | [diff] [blame] | 2025 | void addAdrLabelOperands(MCInst &Inst, unsigned N) const { |
| 2026 | assert(N == 1 && "Invalid number of operands!"); |
| 2027 | assert(isImm() && "Not an immediate!"); |
| 2028 | |
| 2029 | // If we have an immediate that's not a constant, treat it as a label |
| 2030 | // reference needing a fixup. |
| 2031 | if (!isa<MCConstantExpr>(getImm())) { |
| 2032 | Inst.addOperand(MCOperand::CreateExpr(getImm())); |
| 2033 | return; |
| 2034 | } |
| 2035 | |
| 2036 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2037 | int Val = CE->getValue(); |
| 2038 | Inst.addOperand(MCOperand::CreateImm(Val)); |
| 2039 | } |
| 2040 | |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 2041 | void addAlignedMemoryOperands(MCInst &Inst, unsigned N) const { |
| 2042 | assert(N == 2 && "Invalid number of operands!"); |
| 2043 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
| 2044 | Inst.addOperand(MCOperand::CreateImm(Memory.Alignment)); |
| 2045 | } |
| 2046 | |
Kevin Enderby | 488f20b | 2014-04-10 20:18:58 +0000 | [diff] [blame] | 2047 | void addDupAlignedMemoryNoneOperands(MCInst &Inst, unsigned N) const { |
| 2048 | addAlignedMemoryOperands(Inst, N); |
| 2049 | } |
| 2050 | |
| 2051 | void addAlignedMemoryNoneOperands(MCInst &Inst, unsigned N) const { |
| 2052 | addAlignedMemoryOperands(Inst, N); |
| 2053 | } |
| 2054 | |
| 2055 | void addAlignedMemory16Operands(MCInst &Inst, unsigned N) const { |
| 2056 | addAlignedMemoryOperands(Inst, N); |
| 2057 | } |
| 2058 | |
| 2059 | void addDupAlignedMemory16Operands(MCInst &Inst, unsigned N) const { |
| 2060 | addAlignedMemoryOperands(Inst, N); |
| 2061 | } |
| 2062 | |
| 2063 | void addAlignedMemory32Operands(MCInst &Inst, unsigned N) const { |
| 2064 | addAlignedMemoryOperands(Inst, N); |
| 2065 | } |
| 2066 | |
| 2067 | void addDupAlignedMemory32Operands(MCInst &Inst, unsigned N) const { |
| 2068 | addAlignedMemoryOperands(Inst, N); |
| 2069 | } |
| 2070 | |
| 2071 | void addAlignedMemory64Operands(MCInst &Inst, unsigned N) const { |
| 2072 | addAlignedMemoryOperands(Inst, N); |
| 2073 | } |
| 2074 | |
| 2075 | void addDupAlignedMemory64Operands(MCInst &Inst, unsigned N) const { |
| 2076 | addAlignedMemoryOperands(Inst, N); |
| 2077 | } |
| 2078 | |
| 2079 | void addAlignedMemory64or128Operands(MCInst &Inst, unsigned N) const { |
| 2080 | addAlignedMemoryOperands(Inst, N); |
| 2081 | } |
| 2082 | |
| 2083 | void addDupAlignedMemory64or128Operands(MCInst &Inst, unsigned N) const { |
| 2084 | addAlignedMemoryOperands(Inst, N); |
| 2085 | } |
| 2086 | |
| 2087 | void addAlignedMemory64or128or256Operands(MCInst &Inst, unsigned N) const { |
| 2088 | addAlignedMemoryOperands(Inst, N); |
| 2089 | } |
| 2090 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2091 | void addAddrMode2Operands(MCInst &Inst, unsigned N) const { |
| 2092 | assert(N == 3 && "Invalid number of operands!"); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2093 | int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0; |
| 2094 | if (!Memory.OffsetRegNum) { |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2095 | ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add; |
| 2096 | // Special case for #-0 |
| 2097 | if (Val == INT32_MIN) Val = 0; |
| 2098 | if (Val < 0) Val = -Val; |
| 2099 | Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift); |
| 2100 | } else { |
| 2101 | // For register offset, we encode the shift type and negation flag |
| 2102 | // here. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2103 | Val = ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, |
| 2104 | Memory.ShiftImm, Memory.ShiftType); |
Bruno Cardoso Lopes | ab83050 | 2011-03-31 23:26:08 +0000 | [diff] [blame] | 2105 | } |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2106 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
| 2107 | Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum)); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2108 | Inst.addOperand(MCOperand::CreateImm(Val)); |
Bruno Cardoso Lopes | ab83050 | 2011-03-31 23:26:08 +0000 | [diff] [blame] | 2109 | } |
| 2110 | |
Jim Grosbach | cd17c12 | 2011-08-04 23:01:30 +0000 | [diff] [blame] | 2111 | void addAM2OffsetImmOperands(MCInst &Inst, unsigned N) const { |
| 2112 | assert(N == 2 && "Invalid number of operands!"); |
| 2113 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2114 | assert(CE && "non-constant AM2OffsetImm operand!"); |
| 2115 | int32_t Val = CE->getValue(); |
| 2116 | ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add; |
| 2117 | // Special case for #-0 |
| 2118 | if (Val == INT32_MIN) Val = 0; |
| 2119 | if (Val < 0) Val = -Val; |
| 2120 | Val = ARM_AM::getAM2Opc(AddSub, Val, ARM_AM::no_shift); |
| 2121 | Inst.addOperand(MCOperand::CreateReg(0)); |
| 2122 | Inst.addOperand(MCOperand::CreateImm(Val)); |
| 2123 | } |
| 2124 | |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 2125 | void addAddrMode3Operands(MCInst &Inst, unsigned N) const { |
| 2126 | assert(N == 3 && "Invalid number of operands!"); |
Jim Grosbach | 8648c10 | 2011-12-19 23:06:24 +0000 | [diff] [blame] | 2127 | // If we have an immediate that's not a constant, treat it as a label |
| 2128 | // reference needing a fixup. If it is a constant, it's something else |
| 2129 | // and we reject it. |
| 2130 | if (isImm()) { |
| 2131 | Inst.addOperand(MCOperand::CreateExpr(getImm())); |
| 2132 | Inst.addOperand(MCOperand::CreateReg(0)); |
| 2133 | Inst.addOperand(MCOperand::CreateImm(0)); |
| 2134 | return; |
| 2135 | } |
| 2136 | |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2137 | int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0; |
| 2138 | if (!Memory.OffsetRegNum) { |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 2139 | ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add; |
| 2140 | // Special case for #-0 |
| 2141 | if (Val == INT32_MIN) Val = 0; |
| 2142 | if (Val < 0) Val = -Val; |
| 2143 | Val = ARM_AM::getAM3Opc(AddSub, Val); |
| 2144 | } else { |
| 2145 | // For register offset, we encode the shift type and negation flag |
| 2146 | // here. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2147 | 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] | 2148 | } |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2149 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
| 2150 | Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum)); |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 2151 | Inst.addOperand(MCOperand::CreateImm(Val)); |
| 2152 | } |
| 2153 | |
| 2154 | void addAM3OffsetOperands(MCInst &Inst, unsigned N) const { |
| 2155 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2156 | if (Kind == k_PostIndexRegister) { |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 2157 | int32_t Val = |
| 2158 | ARM_AM::getAM3Opc(PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub, 0); |
| 2159 | Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum)); |
| 2160 | Inst.addOperand(MCOperand::CreateImm(Val)); |
Jim Grosbach | 1d9d5e9 | 2011-08-10 21:56:18 +0000 | [diff] [blame] | 2161 | return; |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 2162 | } |
| 2163 | |
| 2164 | // Constant offset. |
| 2165 | const MCConstantExpr *CE = static_cast<const MCConstantExpr*>(getImm()); |
| 2166 | int32_t Val = CE->getValue(); |
| 2167 | ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add; |
| 2168 | // Special case for #-0 |
| 2169 | if (Val == INT32_MIN) Val = 0; |
| 2170 | if (Val < 0) Val = -Val; |
Jim Grosbach | 1d9d5e9 | 2011-08-10 21:56:18 +0000 | [diff] [blame] | 2171 | Val = ARM_AM::getAM3Opc(AddSub, Val); |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 2172 | Inst.addOperand(MCOperand::CreateReg(0)); |
| 2173 | Inst.addOperand(MCOperand::CreateImm(Val)); |
| 2174 | } |
| 2175 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2176 | void addAddrMode5Operands(MCInst &Inst, unsigned N) const { |
| 2177 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | fb2f1d6 | 2011-11-01 01:24:45 +0000 | [diff] [blame] | 2178 | // If we have an immediate that's not a constant, treat it as a label |
| 2179 | // reference needing a fixup. If it is a constant, it's something else |
| 2180 | // and we reject it. |
| 2181 | if (isImm()) { |
| 2182 | Inst.addOperand(MCOperand::CreateExpr(getImm())); |
| 2183 | Inst.addOperand(MCOperand::CreateImm(0)); |
| 2184 | return; |
| 2185 | } |
| 2186 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2187 | // 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] | 2188 | int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2189 | ARM_AM::AddrOpc AddSub = Val < 0 ? ARM_AM::sub : ARM_AM::add; |
| 2190 | // Special case for #-0 |
| 2191 | if (Val == INT32_MIN) Val = 0; |
| 2192 | if (Val < 0) Val = -Val; |
| 2193 | Val = ARM_AM::getAM5Opc(AddSub, Val); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2194 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2195 | Inst.addOperand(MCOperand::CreateImm(Val)); |
Bruno Cardoso Lopes | bda3632 | 2011-04-04 17:18:19 +0000 | [diff] [blame] | 2196 | } |
| 2197 | |
Jim Grosbach | 7db8d69 | 2011-09-08 22:07:06 +0000 | [diff] [blame] | 2198 | void addMemImm8s4OffsetOperands(MCInst &Inst, unsigned N) const { |
| 2199 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | 8648c10 | 2011-12-19 23:06:24 +0000 | [diff] [blame] | 2200 | // If we have an immediate that's not a constant, treat it as a label |
| 2201 | // reference needing a fixup. If it is a constant, it's something else |
| 2202 | // and we reject it. |
| 2203 | if (isImm()) { |
| 2204 | Inst.addOperand(MCOperand::CreateExpr(getImm())); |
| 2205 | Inst.addOperand(MCOperand::CreateImm(0)); |
| 2206 | return; |
| 2207 | } |
| 2208 | |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2209 | int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0; |
| 2210 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
Jim Grosbach | 7db8d69 | 2011-09-08 22:07:06 +0000 | [diff] [blame] | 2211 | Inst.addOperand(MCOperand::CreateImm(Val)); |
| 2212 | } |
| 2213 | |
Jim Grosbach | a05627e | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 2214 | void addMemImm0_1020s4OffsetOperands(MCInst &Inst, unsigned N) const { |
| 2215 | assert(N == 2 && "Invalid number of operands!"); |
| 2216 | // 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] | 2217 | int32_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() / 4 : 0; |
| 2218 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
Jim Grosbach | a05627e | 2011-09-09 18:37:27 +0000 | [diff] [blame] | 2219 | Inst.addOperand(MCOperand::CreateImm(Val)); |
| 2220 | } |
| 2221 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2222 | void addMemImm8OffsetOperands(MCInst &Inst, unsigned N) const { |
| 2223 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2224 | int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0; |
| 2225 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2226 | Inst.addOperand(MCOperand::CreateImm(Val)); |
Chris Lattner | 5d6f6a0 | 2010-10-29 00:27:31 +0000 | [diff] [blame] | 2227 | } |
Daniel Dunbar | 5cd4d0f | 2010-08-11 05:24:50 +0000 | [diff] [blame] | 2228 | |
Jim Grosbach | 2392c53 | 2011-09-07 23:39:14 +0000 | [diff] [blame] | 2229 | void addMemPosImm8OffsetOperands(MCInst &Inst, unsigned N) const { |
| 2230 | addMemImm8OffsetOperands(Inst, N); |
| 2231 | } |
| 2232 | |
Jim Grosbach | 5bfa8ba | 2011-09-07 20:58:57 +0000 | [diff] [blame] | 2233 | void addMemNegImm8OffsetOperands(MCInst &Inst, unsigned N) const { |
Jim Grosbach | 2392c53 | 2011-09-07 23:39:14 +0000 | [diff] [blame] | 2234 | addMemImm8OffsetOperands(Inst, N); |
Jim Grosbach | 5bfa8ba | 2011-09-07 20:58:57 +0000 | [diff] [blame] | 2235 | } |
| 2236 | |
| 2237 | void addMemUImm12OffsetOperands(MCInst &Inst, unsigned N) const { |
| 2238 | assert(N == 2 && "Invalid number of operands!"); |
| 2239 | // If this is an immediate, it's a label reference. |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 2240 | if (isImm()) { |
Jim Grosbach | 5bfa8ba | 2011-09-07 20:58:57 +0000 | [diff] [blame] | 2241 | addExpr(Inst, getImm()); |
| 2242 | Inst.addOperand(MCOperand::CreateImm(0)); |
| 2243 | return; |
| 2244 | } |
| 2245 | |
| 2246 | // Otherwise, it's a normal memory reg+offset. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2247 | int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0; |
| 2248 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
Jim Grosbach | 5bfa8ba | 2011-09-07 20:58:57 +0000 | [diff] [blame] | 2249 | Inst.addOperand(MCOperand::CreateImm(Val)); |
| 2250 | } |
| 2251 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2252 | void addMemImm12OffsetOperands(MCInst &Inst, unsigned N) const { |
| 2253 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | 95466ce | 2011-08-08 20:59:31 +0000 | [diff] [blame] | 2254 | // If this is an immediate, it's a label reference. |
Jim Grosbach | c4d8d2f | 2011-12-22 22:02:35 +0000 | [diff] [blame] | 2255 | if (isImm()) { |
Jim Grosbach | 95466ce | 2011-08-08 20:59:31 +0000 | [diff] [blame] | 2256 | addExpr(Inst, getImm()); |
| 2257 | Inst.addOperand(MCOperand::CreateImm(0)); |
| 2258 | return; |
| 2259 | } |
| 2260 | |
| 2261 | // Otherwise, it's a normal memory reg+offset. |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2262 | int64_t Val = Memory.OffsetImm ? Memory.OffsetImm->getValue() : 0; |
| 2263 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2264 | Inst.addOperand(MCOperand::CreateImm(Val)); |
Bill Wendling | 092a7bd | 2010-12-14 03:36:38 +0000 | [diff] [blame] | 2265 | } |
Bill Wendling | 811c936 | 2010-11-30 07:44:32 +0000 | [diff] [blame] | 2266 | |
Jim Grosbach | 05541f4 | 2011-09-19 22:21:13 +0000 | [diff] [blame] | 2267 | void addMemTBBOperands(MCInst &Inst, unsigned N) const { |
| 2268 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2269 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
| 2270 | Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum)); |
Jim Grosbach | 05541f4 | 2011-09-19 22:21:13 +0000 | [diff] [blame] | 2271 | } |
| 2272 | |
| 2273 | void addMemTBHOperands(MCInst &Inst, unsigned N) const { |
| 2274 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2275 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
| 2276 | Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum)); |
Jim Grosbach | 05541f4 | 2011-09-19 22:21:13 +0000 | [diff] [blame] | 2277 | } |
| 2278 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2279 | void addMemRegOffsetOperands(MCInst &Inst, unsigned N) const { |
| 2280 | assert(N == 3 && "Invalid number of operands!"); |
Jim Grosbach | ee201fa | 2011-11-14 17:52:47 +0000 | [diff] [blame] | 2281 | unsigned Val = |
| 2282 | ARM_AM::getAM2Opc(Memory.isNegative ? ARM_AM::sub : ARM_AM::add, |
| 2283 | Memory.ShiftImm, Memory.ShiftType); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2284 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
| 2285 | Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum)); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2286 | Inst.addOperand(MCOperand::CreateImm(Val)); |
| 2287 | } |
| 2288 | |
Jim Grosbach | e0ebc1c | 2011-09-07 23:10:15 +0000 | [diff] [blame] | 2289 | void addT2MemRegOffsetOperands(MCInst &Inst, unsigned N) const { |
| 2290 | assert(N == 3 && "Invalid number of operands!"); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2291 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
| 2292 | Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum)); |
| 2293 | Inst.addOperand(MCOperand::CreateImm(Memory.ShiftImm)); |
Jim Grosbach | e0ebc1c | 2011-09-07 23:10:15 +0000 | [diff] [blame] | 2294 | } |
| 2295 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2296 | void addMemThumbRROperands(MCInst &Inst, unsigned N) const { |
| 2297 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2298 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
| 2299 | Inst.addOperand(MCOperand::CreateReg(Memory.OffsetRegNum)); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2300 | } |
| 2301 | |
Jim Grosbach | 3fe94e3 | 2011-08-19 17:55:24 +0000 | [diff] [blame] | 2302 | void addMemThumbRIs4Operands(MCInst &Inst, unsigned N) const { |
| 2303 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2304 | int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0; |
| 2305 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
Jim Grosbach | 3fe94e3 | 2011-08-19 17:55:24 +0000 | [diff] [blame] | 2306 | Inst.addOperand(MCOperand::CreateImm(Val)); |
| 2307 | } |
| 2308 | |
Jim Grosbach | 26d3587 | 2011-08-19 18:55:51 +0000 | [diff] [blame] | 2309 | void addMemThumbRIs2Operands(MCInst &Inst, unsigned N) const { |
| 2310 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2311 | int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 2) : 0; |
| 2312 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
Jim Grosbach | 26d3587 | 2011-08-19 18:55:51 +0000 | [diff] [blame] | 2313 | Inst.addOperand(MCOperand::CreateImm(Val)); |
| 2314 | } |
| 2315 | |
Jim Grosbach | a32c753 | 2011-08-19 18:49:59 +0000 | [diff] [blame] | 2316 | void addMemThumbRIs1Operands(MCInst &Inst, unsigned N) const { |
| 2317 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2318 | int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue()) : 0; |
| 2319 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
Jim Grosbach | a32c753 | 2011-08-19 18:49:59 +0000 | [diff] [blame] | 2320 | Inst.addOperand(MCOperand::CreateImm(Val)); |
| 2321 | } |
| 2322 | |
Jim Grosbach | 23983d6 | 2011-08-19 18:13:48 +0000 | [diff] [blame] | 2323 | void addMemThumbSPIOperands(MCInst &Inst, unsigned N) const { |
| 2324 | assert(N == 2 && "Invalid number of operands!"); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2325 | int64_t Val = Memory.OffsetImm ? (Memory.OffsetImm->getValue() / 4) : 0; |
| 2326 | Inst.addOperand(MCOperand::CreateReg(Memory.BaseRegNum)); |
Jim Grosbach | 23983d6 | 2011-08-19 18:13:48 +0000 | [diff] [blame] | 2327 | Inst.addOperand(MCOperand::CreateImm(Val)); |
| 2328 | } |
| 2329 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2330 | void addPostIdxImm8Operands(MCInst &Inst, unsigned N) const { |
| 2331 | assert(N == 1 && "Invalid number of operands!"); |
| 2332 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2333 | assert(CE && "non-constant post-idx-imm8 operand!"); |
| 2334 | int Imm = CE->getValue(); |
| 2335 | bool isAdd = Imm >= 0; |
Owen Anderson | f02d98d | 2011-08-29 17:17:09 +0000 | [diff] [blame] | 2336 | if (Imm == INT32_MIN) Imm = 0; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2337 | Imm = (Imm < 0 ? -Imm : Imm) | (int)isAdd << 8; |
| 2338 | Inst.addOperand(MCOperand::CreateImm(Imm)); |
| 2339 | } |
| 2340 | |
Jim Grosbach | 9398141 | 2011-10-11 21:55:36 +0000 | [diff] [blame] | 2341 | void addPostIdxImm8s4Operands(MCInst &Inst, unsigned N) const { |
| 2342 | assert(N == 1 && "Invalid number of operands!"); |
| 2343 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2344 | assert(CE && "non-constant post-idx-imm8s4 operand!"); |
| 2345 | int Imm = CE->getValue(); |
| 2346 | bool isAdd = Imm >= 0; |
| 2347 | if (Imm == INT32_MIN) Imm = 0; |
| 2348 | // Immediate is scaled by 4. |
| 2349 | Imm = ((Imm < 0 ? -Imm : Imm) / 4) | (int)isAdd << 8; |
| 2350 | Inst.addOperand(MCOperand::CreateImm(Imm)); |
| 2351 | } |
| 2352 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2353 | void addPostIdxRegOperands(MCInst &Inst, unsigned N) const { |
| 2354 | assert(N == 2 && "Invalid number of operands!"); |
| 2355 | Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum)); |
Jim Grosbach | c320c85 | 2011-08-05 21:28:30 +0000 | [diff] [blame] | 2356 | Inst.addOperand(MCOperand::CreateImm(PostIdxReg.isAdd)); |
| 2357 | } |
| 2358 | |
| 2359 | void addPostIdxRegShiftedOperands(MCInst &Inst, unsigned N) const { |
| 2360 | assert(N == 2 && "Invalid number of operands!"); |
| 2361 | Inst.addOperand(MCOperand::CreateReg(PostIdxReg.RegNum)); |
| 2362 | // The sign, shift type, and shift amount are encoded in a single operand |
| 2363 | // using the AM2 encoding helpers. |
| 2364 | ARM_AM::AddrOpc opc = PostIdxReg.isAdd ? ARM_AM::add : ARM_AM::sub; |
| 2365 | unsigned Imm = ARM_AM::getAM2Opc(opc, PostIdxReg.ShiftImm, |
| 2366 | PostIdxReg.ShiftTy); |
| 2367 | Inst.addOperand(MCOperand::CreateImm(Imm)); |
Bill Wendling | 811c936 | 2010-11-30 07:44:32 +0000 | [diff] [blame] | 2368 | } |
| 2369 | |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 2370 | void addMSRMaskOperands(MCInst &Inst, unsigned N) const { |
| 2371 | assert(N == 1 && "Invalid number of operands!"); |
| 2372 | Inst.addOperand(MCOperand::CreateImm(unsigned(getMSRMask()))); |
| 2373 | } |
| 2374 | |
Tim Northover | ee843ef | 2014-08-15 10:47:12 +0000 | [diff] [blame] | 2375 | void addBankedRegOperands(MCInst &Inst, unsigned N) const { |
| 2376 | assert(N == 1 && "Invalid number of operands!"); |
| 2377 | Inst.addOperand(MCOperand::CreateImm(unsigned(getBankedReg()))); |
| 2378 | } |
| 2379 | |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 2380 | void addProcIFlagsOperands(MCInst &Inst, unsigned N) const { |
| 2381 | assert(N == 1 && "Invalid number of operands!"); |
| 2382 | Inst.addOperand(MCOperand::CreateImm(unsigned(getProcIFlags()))); |
| 2383 | } |
| 2384 | |
Jim Grosbach | 182b6a0 | 2011-11-29 23:51:09 +0000 | [diff] [blame] | 2385 | void addVecListOperands(MCInst &Inst, unsigned N) const { |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 2386 | assert(N == 1 && "Invalid number of operands!"); |
| 2387 | Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum)); |
| 2388 | } |
| 2389 | |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 2390 | void addVecListIndexedOperands(MCInst &Inst, unsigned N) const { |
| 2391 | assert(N == 2 && "Invalid number of operands!"); |
| 2392 | Inst.addOperand(MCOperand::CreateReg(VectorList.RegNum)); |
| 2393 | Inst.addOperand(MCOperand::CreateImm(VectorList.LaneIndex)); |
| 2394 | } |
| 2395 | |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 2396 | void addVectorIndex8Operands(MCInst &Inst, unsigned N) const { |
| 2397 | assert(N == 1 && "Invalid number of operands!"); |
| 2398 | Inst.addOperand(MCOperand::CreateImm(getVectorIndex())); |
| 2399 | } |
| 2400 | |
| 2401 | void addVectorIndex16Operands(MCInst &Inst, unsigned N) const { |
| 2402 | assert(N == 1 && "Invalid number of operands!"); |
| 2403 | Inst.addOperand(MCOperand::CreateImm(getVectorIndex())); |
| 2404 | } |
| 2405 | |
| 2406 | void addVectorIndex32Operands(MCInst &Inst, unsigned N) const { |
| 2407 | assert(N == 1 && "Invalid number of operands!"); |
| 2408 | Inst.addOperand(MCOperand::CreateImm(getVectorIndex())); |
| 2409 | } |
| 2410 | |
Jim Grosbach | 741cd73 | 2011-10-17 22:26:03 +0000 | [diff] [blame] | 2411 | void addNEONi8splatOperands(MCInst &Inst, unsigned N) const { |
| 2412 | assert(N == 1 && "Invalid number of operands!"); |
| 2413 | // The immediate encodes the type of constant as well as the value. |
| 2414 | // Mask in that this is an i8 splat. |
| 2415 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2416 | Inst.addOperand(MCOperand::CreateImm(CE->getValue() | 0xe00)); |
| 2417 | } |
| 2418 | |
Jim Grosbach | cda32ae | 2011-10-17 23:09:09 +0000 | [diff] [blame] | 2419 | void addNEONi16splatOperands(MCInst &Inst, unsigned N) const { |
| 2420 | assert(N == 1 && "Invalid number of operands!"); |
| 2421 | // The immediate encodes the type of constant as well as the value. |
| 2422 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2423 | unsigned Value = CE->getValue(); |
Renato Golin | f5dd1da | 2014-09-25 11:31:24 +0000 | [diff] [blame] | 2424 | Value = ARM_AM::encodeNEONi16splat(Value); |
| 2425 | Inst.addOperand(MCOperand::CreateImm(Value)); |
| 2426 | } |
| 2427 | |
| 2428 | void addNEONi16splatNotOperands(MCInst &Inst, unsigned N) const { |
| 2429 | assert(N == 1 && "Invalid number of operands!"); |
| 2430 | // The immediate encodes the type of constant as well as the value. |
| 2431 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2432 | unsigned Value = CE->getValue(); |
| 2433 | Value = ARM_AM::encodeNEONi16splat(~Value & 0xffff); |
Jim Grosbach | cda32ae | 2011-10-17 23:09:09 +0000 | [diff] [blame] | 2434 | Inst.addOperand(MCOperand::CreateImm(Value)); |
| 2435 | } |
| 2436 | |
Jim Grosbach | 8211c05 | 2011-10-18 00:22:00 +0000 | [diff] [blame] | 2437 | void addNEONi32splatOperands(MCInst &Inst, unsigned N) const { |
| 2438 | assert(N == 1 && "Invalid number of operands!"); |
| 2439 | // The immediate encodes the type of constant as well as the value. |
| 2440 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2441 | unsigned Value = CE->getValue(); |
Renato Golin | f5dd1da | 2014-09-25 11:31:24 +0000 | [diff] [blame] | 2442 | Value = ARM_AM::encodeNEONi32splat(Value); |
| 2443 | Inst.addOperand(MCOperand::CreateImm(Value)); |
| 2444 | } |
| 2445 | |
| 2446 | void addNEONi32splatNotOperands(MCInst &Inst, unsigned N) const { |
| 2447 | assert(N == 1 && "Invalid number of operands!"); |
| 2448 | // The immediate encodes the type of constant as well as the value. |
| 2449 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2450 | unsigned Value = CE->getValue(); |
| 2451 | Value = ARM_AM::encodeNEONi32splat(~Value); |
Jim Grosbach | 8211c05 | 2011-10-18 00:22:00 +0000 | [diff] [blame] | 2452 | Inst.addOperand(MCOperand::CreateImm(Value)); |
| 2453 | } |
| 2454 | |
Stepan Dyatkovskiy | 00dcc0f | 2014-04-24 06:03:01 +0000 | [diff] [blame] | 2455 | void addNEONinvByteReplicateOperands(MCInst &Inst, unsigned N) const { |
| 2456 | assert(N == 1 && "Invalid number of operands!"); |
| 2457 | // The immediate encodes the type of constant as well as the value. |
| 2458 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2459 | unsigned Value = CE->getValue(); |
| 2460 | assert((Inst.getOpcode() == ARM::VMOVv8i8 || |
| 2461 | Inst.getOpcode() == ARM::VMOVv16i8) && |
| 2462 | "All vmvn instructions that wants to replicate non-zero byte " |
| 2463 | "always must be replaced with VMOVv8i8 or VMOVv16i8."); |
| 2464 | unsigned B = ((~Value) & 0xff); |
| 2465 | B |= 0xe00; // cmode = 0b1110 |
| 2466 | Inst.addOperand(MCOperand::CreateImm(B)); |
| 2467 | } |
Jim Grosbach | 8211c05 | 2011-10-18 00:22:00 +0000 | [diff] [blame] | 2468 | void addNEONi32vmovOperands(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 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2472 | unsigned Value = CE->getValue(); |
| 2473 | if (Value >= 256 && Value <= 0xffff) |
| 2474 | Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200); |
| 2475 | else if (Value > 0xffff && Value <= 0xffffff) |
| 2476 | Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400); |
| 2477 | else if (Value > 0xffffff) |
| 2478 | Value = (Value >> 24) | 0x600; |
| 2479 | Inst.addOperand(MCOperand::CreateImm(Value)); |
| 2480 | } |
| 2481 | |
Stepan Dyatkovskiy | 00dcc0f | 2014-04-24 06:03:01 +0000 | [diff] [blame] | 2482 | void addNEONvmovByteReplicateOperands(MCInst &Inst, unsigned N) const { |
| 2483 | assert(N == 1 && "Invalid number of operands!"); |
| 2484 | // The immediate encodes the type of constant as well as the value. |
| 2485 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2486 | unsigned Value = CE->getValue(); |
| 2487 | assert((Inst.getOpcode() == ARM::VMOVv8i8 || |
| 2488 | Inst.getOpcode() == ARM::VMOVv16i8) && |
| 2489 | "All instructions that wants to replicate non-zero byte " |
| 2490 | "always must be replaced with VMOVv8i8 or VMOVv16i8."); |
| 2491 | unsigned B = Value & 0xff; |
| 2492 | B |= 0xe00; // cmode = 0b1110 |
| 2493 | Inst.addOperand(MCOperand::CreateImm(B)); |
| 2494 | } |
Jim Grosbach | 045b6c7 | 2011-12-19 23:51:07 +0000 | [diff] [blame] | 2495 | void addNEONi32vmovNegOperands(MCInst &Inst, unsigned N) const { |
| 2496 | assert(N == 1 && "Invalid number of operands!"); |
| 2497 | // The immediate encodes the type of constant as well as the value. |
| 2498 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2499 | unsigned Value = ~CE->getValue(); |
| 2500 | if (Value >= 256 && Value <= 0xffff) |
| 2501 | Value = (Value >> 8) | ((Value & 0xff) ? 0xc00 : 0x200); |
| 2502 | else if (Value > 0xffff && Value <= 0xffffff) |
| 2503 | Value = (Value >> 16) | ((Value & 0xff) ? 0xd00 : 0x400); |
| 2504 | else if (Value > 0xffffff) |
| 2505 | Value = (Value >> 24) | 0x600; |
| 2506 | Inst.addOperand(MCOperand::CreateImm(Value)); |
| 2507 | } |
| 2508 | |
Jim Grosbach | e4454e0 | 2011-10-18 16:18:11 +0000 | [diff] [blame] | 2509 | void addNEONi64splatOperands(MCInst &Inst, unsigned N) const { |
| 2510 | assert(N == 1 && "Invalid number of operands!"); |
| 2511 | // The immediate encodes the type of constant as well as the value. |
| 2512 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm()); |
| 2513 | uint64_t Value = CE->getValue(); |
| 2514 | unsigned Imm = 0; |
| 2515 | for (unsigned i = 0; i < 8; ++i, Value >>= 8) { |
| 2516 | Imm |= (Value & 1) << i; |
| 2517 | } |
| 2518 | Inst.addOperand(MCOperand::CreateImm(Imm | 0x1e00)); |
| 2519 | } |
| 2520 | |
Craig Topper | ca7e3e5 | 2014-03-10 03:19:03 +0000 | [diff] [blame] | 2521 | void print(raw_ostream &OS) const override; |
Daniel Dunbar | ebace22 | 2010-08-11 06:37:04 +0000 | [diff] [blame] | 2522 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2523 | static std::unique_ptr<ARMOperand> CreateITMask(unsigned Mask, SMLoc S) { |
| 2524 | auto Op = make_unique<ARMOperand>(k_ITCondMask); |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 2525 | Op->ITMask.Mask = Mask; |
| 2526 | Op->StartLoc = S; |
| 2527 | Op->EndLoc = S; |
| 2528 | return Op; |
| 2529 | } |
| 2530 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2531 | static std::unique_ptr<ARMOperand> CreateCondCode(ARMCC::CondCodes CC, |
| 2532 | SMLoc S) { |
| 2533 | auto Op = make_unique<ARMOperand>(k_CondCode); |
Daniel Dunbar | 188b47b | 2010-08-11 06:37:20 +0000 | [diff] [blame] | 2534 | Op->CC.Val = CC; |
| 2535 | Op->StartLoc = S; |
| 2536 | Op->EndLoc = S; |
Chris Lattner | bd7c9fa | 2010-10-28 17:20:03 +0000 | [diff] [blame] | 2537 | return Op; |
Daniel Dunbar | 188b47b | 2010-08-11 06:37:20 +0000 | [diff] [blame] | 2538 | } |
| 2539 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2540 | static std::unique_ptr<ARMOperand> CreateCoprocNum(unsigned CopVal, SMLoc S) { |
| 2541 | auto Op = make_unique<ARMOperand>(k_CoprocNum); |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 2542 | Op->Cop.Val = CopVal; |
| 2543 | Op->StartLoc = S; |
| 2544 | Op->EndLoc = S; |
| 2545 | return Op; |
| 2546 | } |
| 2547 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2548 | static std::unique_ptr<ARMOperand> CreateCoprocReg(unsigned CopVal, SMLoc S) { |
| 2549 | auto Op = make_unique<ARMOperand>(k_CoprocReg); |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 2550 | Op->Cop.Val = CopVal; |
| 2551 | Op->StartLoc = S; |
| 2552 | Op->EndLoc = S; |
| 2553 | return Op; |
| 2554 | } |
| 2555 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2556 | static std::unique_ptr<ARMOperand> CreateCoprocOption(unsigned Val, SMLoc S, |
| 2557 | SMLoc E) { |
| 2558 | auto Op = make_unique<ARMOperand>(k_CoprocOption); |
Jim Grosbach | 4839958 | 2011-10-12 17:34:41 +0000 | [diff] [blame] | 2559 | Op->Cop.Val = Val; |
| 2560 | Op->StartLoc = S; |
| 2561 | Op->EndLoc = E; |
| 2562 | return Op; |
| 2563 | } |
| 2564 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2565 | static std::unique_ptr<ARMOperand> CreateCCOut(unsigned RegNum, SMLoc S) { |
| 2566 | auto Op = make_unique<ARMOperand>(k_CCOut); |
Jim Grosbach | 0bfb4d5 | 2010-12-06 18:21:12 +0000 | [diff] [blame] | 2567 | Op->Reg.RegNum = RegNum; |
| 2568 | Op->StartLoc = S; |
| 2569 | Op->EndLoc = S; |
| 2570 | return Op; |
| 2571 | } |
| 2572 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2573 | static std::unique_ptr<ARMOperand> CreateToken(StringRef Str, SMLoc S) { |
| 2574 | auto Op = make_unique<ARMOperand>(k_Token); |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 2575 | Op->Tok.Data = Str.data(); |
| 2576 | Op->Tok.Length = Str.size(); |
| 2577 | Op->StartLoc = S; |
| 2578 | Op->EndLoc = S; |
Chris Lattner | bd7c9fa | 2010-10-28 17:20:03 +0000 | [diff] [blame] | 2579 | return Op; |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 2580 | } |
| 2581 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2582 | static std::unique_ptr<ARMOperand> CreateReg(unsigned RegNum, SMLoc S, |
| 2583 | SMLoc E) { |
| 2584 | auto Op = make_unique<ARMOperand>(k_Register); |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 2585 | Op->Reg.RegNum = RegNum; |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 2586 | Op->StartLoc = S; |
| 2587 | Op->EndLoc = E; |
Chris Lattner | bd7c9fa | 2010-10-28 17:20:03 +0000 | [diff] [blame] | 2588 | return Op; |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 2589 | } |
| 2590 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2591 | static std::unique_ptr<ARMOperand> |
| 2592 | CreateShiftedRegister(ARM_AM::ShiftOpc ShTy, unsigned SrcReg, |
| 2593 | unsigned ShiftReg, unsigned ShiftImm, SMLoc S, |
| 2594 | SMLoc E) { |
| 2595 | auto Op = make_unique<ARMOperand>(k_ShiftedRegister); |
Jim Grosbach | ac798e1 | 2011-07-25 20:49:51 +0000 | [diff] [blame] | 2596 | Op->RegShiftedReg.ShiftTy = ShTy; |
| 2597 | Op->RegShiftedReg.SrcReg = SrcReg; |
| 2598 | Op->RegShiftedReg.ShiftReg = ShiftReg; |
| 2599 | Op->RegShiftedReg.ShiftImm = ShiftImm; |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 2600 | Op->StartLoc = S; |
| 2601 | Op->EndLoc = E; |
| 2602 | return Op; |
| 2603 | } |
| 2604 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2605 | static std::unique_ptr<ARMOperand> |
| 2606 | CreateShiftedImmediate(ARM_AM::ShiftOpc ShTy, unsigned SrcReg, |
| 2607 | unsigned ShiftImm, SMLoc S, SMLoc E) { |
| 2608 | auto Op = make_unique<ARMOperand>(k_ShiftedImmediate); |
Jim Grosbach | ac798e1 | 2011-07-25 20:49:51 +0000 | [diff] [blame] | 2609 | Op->RegShiftedImm.ShiftTy = ShTy; |
| 2610 | Op->RegShiftedImm.SrcReg = SrcReg; |
| 2611 | Op->RegShiftedImm.ShiftImm = ShiftImm; |
Owen Anderson | b595ed0 | 2011-07-21 18:54:16 +0000 | [diff] [blame] | 2612 | Op->StartLoc = S; |
| 2613 | Op->EndLoc = E; |
| 2614 | return Op; |
| 2615 | } |
| 2616 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2617 | static std::unique_ptr<ARMOperand> CreateShifterImm(bool isASR, unsigned Imm, |
| 2618 | SMLoc S, SMLoc E) { |
| 2619 | auto Op = make_unique<ARMOperand>(k_ShifterImmediate); |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 2620 | Op->ShifterImm.isASR = isASR; |
| 2621 | Op->ShifterImm.Imm = Imm; |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 2622 | Op->StartLoc = S; |
| 2623 | Op->EndLoc = E; |
| 2624 | return Op; |
| 2625 | } |
| 2626 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2627 | static std::unique_ptr<ARMOperand> CreateRotImm(unsigned Imm, SMLoc S, |
| 2628 | SMLoc E) { |
| 2629 | auto Op = make_unique<ARMOperand>(k_RotateImmediate); |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 2630 | Op->RotImm.Imm = Imm; |
| 2631 | Op->StartLoc = S; |
| 2632 | Op->EndLoc = E; |
| 2633 | return Op; |
| 2634 | } |
| 2635 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2636 | static std::unique_ptr<ARMOperand> |
| 2637 | CreateBitfield(unsigned LSB, unsigned Width, SMLoc S, SMLoc E) { |
| 2638 | auto Op = make_unique<ARMOperand>(k_BitfieldDescriptor); |
Jim Grosbach | 864b609 | 2011-07-28 21:34:26 +0000 | [diff] [blame] | 2639 | Op->Bitfield.LSB = LSB; |
| 2640 | Op->Bitfield.Width = Width; |
| 2641 | Op->StartLoc = S; |
| 2642 | Op->EndLoc = E; |
| 2643 | return Op; |
| 2644 | } |
| 2645 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2646 | static std::unique_ptr<ARMOperand> |
| 2647 | CreateRegList(SmallVectorImpl<std::pair<unsigned, unsigned>> &Regs, |
Matt Beaumont-Gay | 55c4cc7 | 2010-11-10 00:08:58 +0000 | [diff] [blame] | 2648 | SMLoc StartLoc, SMLoc EndLoc) { |
Chad Rosier | fa705ee | 2013-07-01 20:49:23 +0000 | [diff] [blame] | 2649 | assert (Regs.size() > 0 && "RegList contains no registers?"); |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2650 | KindTy Kind = k_RegisterList; |
Bill Wendling | 9898ac9 | 2010-11-17 04:32:08 +0000 | [diff] [blame] | 2651 | |
Chad Rosier | fa705ee | 2013-07-01 20:49:23 +0000 | [diff] [blame] | 2652 | if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Regs.front().second)) |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2653 | Kind = k_DPRRegisterList; |
Jim Grosbach | 75461af | 2011-09-13 22:56:44 +0000 | [diff] [blame] | 2654 | else if (ARMMCRegisterClasses[ARM::SPRRegClassID]. |
Chad Rosier | fa705ee | 2013-07-01 20:49:23 +0000 | [diff] [blame] | 2655 | contains(Regs.front().second)) |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2656 | Kind = k_SPRRegisterList; |
Bill Wendling | 9898ac9 | 2010-11-17 04:32:08 +0000 | [diff] [blame] | 2657 | |
Chad Rosier | fa705ee | 2013-07-01 20:49:23 +0000 | [diff] [blame] | 2658 | // Sort based on the register encoding values. |
| 2659 | array_pod_sort(Regs.begin(), Regs.end()); |
| 2660 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2661 | auto Op = make_unique<ARMOperand>(Kind); |
Chad Rosier | fa705ee | 2013-07-01 20:49:23 +0000 | [diff] [blame] | 2662 | for (SmallVectorImpl<std::pair<unsigned, unsigned> >::const_iterator |
Bill Wendling | 2cae327 | 2010-11-09 22:44:22 +0000 | [diff] [blame] | 2663 | I = Regs.begin(), E = Regs.end(); I != E; ++I) |
Chad Rosier | fa705ee | 2013-07-01 20:49:23 +0000 | [diff] [blame] | 2664 | Op->Registers.push_back(I->second); |
Matt Beaumont-Gay | 55c4cc7 | 2010-11-10 00:08:58 +0000 | [diff] [blame] | 2665 | Op->StartLoc = StartLoc; |
| 2666 | Op->EndLoc = EndLoc; |
Bill Wendling | 7cef447 | 2010-11-06 19:56:04 +0000 | [diff] [blame] | 2667 | return Op; |
| 2668 | } |
| 2669 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2670 | static std::unique_ptr<ARMOperand> CreateVectorList(unsigned RegNum, |
| 2671 | unsigned Count, |
| 2672 | bool isDoubleSpaced, |
| 2673 | SMLoc S, SMLoc E) { |
| 2674 | auto Op = make_unique<ARMOperand>(k_VectorList); |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 2675 | Op->VectorList.RegNum = RegNum; |
| 2676 | Op->VectorList.Count = Count; |
Jim Grosbach | 2f50e92 | 2011-12-15 21:44:33 +0000 | [diff] [blame] | 2677 | Op->VectorList.isDoubleSpaced = isDoubleSpaced; |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 2678 | Op->StartLoc = S; |
| 2679 | Op->EndLoc = E; |
| 2680 | return Op; |
| 2681 | } |
| 2682 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2683 | static std::unique_ptr<ARMOperand> |
| 2684 | CreateVectorListAllLanes(unsigned RegNum, unsigned Count, bool isDoubleSpaced, |
| 2685 | SMLoc S, SMLoc E) { |
| 2686 | auto Op = make_unique<ARMOperand>(k_VectorListAllLanes); |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 2687 | Op->VectorList.RegNum = RegNum; |
| 2688 | Op->VectorList.Count = Count; |
Jim Grosbach | c5af54e | 2011-12-21 00:38:54 +0000 | [diff] [blame] | 2689 | Op->VectorList.isDoubleSpaced = isDoubleSpaced; |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 2690 | Op->StartLoc = S; |
| 2691 | Op->EndLoc = E; |
| 2692 | return Op; |
| 2693 | } |
| 2694 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2695 | static std::unique_ptr<ARMOperand> |
| 2696 | CreateVectorListIndexed(unsigned RegNum, unsigned Count, unsigned Index, |
| 2697 | bool isDoubleSpaced, SMLoc S, SMLoc E) { |
| 2698 | auto Op = make_unique<ARMOperand>(k_VectorListIndexed); |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 2699 | Op->VectorList.RegNum = RegNum; |
| 2700 | Op->VectorList.Count = Count; |
| 2701 | Op->VectorList.LaneIndex = Index; |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 2702 | Op->VectorList.isDoubleSpaced = isDoubleSpaced; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 2703 | Op->StartLoc = S; |
| 2704 | Op->EndLoc = E; |
| 2705 | return Op; |
| 2706 | } |
| 2707 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2708 | static std::unique_ptr<ARMOperand> |
| 2709 | CreateVectorIndex(unsigned Idx, SMLoc S, SMLoc E, MCContext &Ctx) { |
| 2710 | auto Op = make_unique<ARMOperand>(k_VectorIndex); |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 2711 | Op->VectorIndex.Val = Idx; |
| 2712 | Op->StartLoc = S; |
| 2713 | Op->EndLoc = E; |
| 2714 | return Op; |
| 2715 | } |
| 2716 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2717 | static std::unique_ptr<ARMOperand> CreateImm(const MCExpr *Val, SMLoc S, |
| 2718 | SMLoc E) { |
| 2719 | auto Op = make_unique<ARMOperand>(k_Immediate); |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 2720 | Op->Imm.Val = Val; |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 2721 | Op->StartLoc = S; |
| 2722 | Op->EndLoc = E; |
Chris Lattner | bd7c9fa | 2010-10-28 17:20:03 +0000 | [diff] [blame] | 2723 | return Op; |
Kevin Enderby | f507994 | 2009-10-13 22:19:02 +0000 | [diff] [blame] | 2724 | } |
| 2725 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2726 | static std::unique_ptr<ARMOperand> |
| 2727 | CreateMem(unsigned BaseRegNum, const MCConstantExpr *OffsetImm, |
| 2728 | unsigned OffsetRegNum, ARM_AM::ShiftOpc ShiftType, |
| 2729 | unsigned ShiftImm, unsigned Alignment, bool isNegative, SMLoc S, |
| 2730 | SMLoc E, SMLoc AlignmentLoc = SMLoc()) { |
| 2731 | auto Op = make_unique<ARMOperand>(k_Memory); |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2732 | Op->Memory.BaseRegNum = BaseRegNum; |
| 2733 | Op->Memory.OffsetImm = OffsetImm; |
| 2734 | Op->Memory.OffsetRegNum = OffsetRegNum; |
| 2735 | Op->Memory.ShiftType = ShiftType; |
| 2736 | Op->Memory.ShiftImm = ShiftImm; |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 2737 | Op->Memory.Alignment = Alignment; |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2738 | Op->Memory.isNegative = isNegative; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2739 | Op->StartLoc = S; |
| 2740 | Op->EndLoc = E; |
Kevin Enderby | 488f20b | 2014-04-10 20:18:58 +0000 | [diff] [blame] | 2741 | Op->AlignmentLoc = AlignmentLoc; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2742 | return Op; |
| 2743 | } |
Jim Grosbach | 624bcc7 | 2010-10-29 14:46:02 +0000 | [diff] [blame] | 2744 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2745 | static std::unique_ptr<ARMOperand> |
| 2746 | CreatePostIdxReg(unsigned RegNum, bool isAdd, ARM_AM::ShiftOpc ShiftTy, |
| 2747 | unsigned ShiftImm, SMLoc S, SMLoc E) { |
| 2748 | auto Op = make_unique<ARMOperand>(k_PostIndexRegister); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2749 | Op->PostIdxReg.RegNum = RegNum; |
Jim Grosbach | c320c85 | 2011-08-05 21:28:30 +0000 | [diff] [blame] | 2750 | Op->PostIdxReg.isAdd = isAdd; |
| 2751 | Op->PostIdxReg.ShiftTy = ShiftTy; |
| 2752 | Op->PostIdxReg.ShiftImm = ShiftImm; |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 2753 | Op->StartLoc = S; |
| 2754 | Op->EndLoc = E; |
Chris Lattner | bd7c9fa | 2010-10-28 17:20:03 +0000 | [diff] [blame] | 2755 | return Op; |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 2756 | } |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 2757 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2758 | static std::unique_ptr<ARMOperand> CreateMemBarrierOpt(ARM_MB::MemBOpt Opt, |
| 2759 | SMLoc S) { |
| 2760 | auto Op = make_unique<ARMOperand>(k_MemBarrierOpt); |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 2761 | Op->MBOpt.Val = Opt; |
| 2762 | Op->StartLoc = S; |
| 2763 | Op->EndLoc = S; |
| 2764 | return Op; |
| 2765 | } |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 2766 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2767 | static std::unique_ptr<ARMOperand> |
| 2768 | CreateInstSyncBarrierOpt(ARM_ISB::InstSyncBOpt Opt, SMLoc S) { |
| 2769 | auto Op = make_unique<ARMOperand>(k_InstSyncBarrierOpt); |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 2770 | Op->ISBOpt.Val = Opt; |
| 2771 | Op->StartLoc = S; |
| 2772 | Op->EndLoc = S; |
| 2773 | return Op; |
| 2774 | } |
| 2775 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2776 | static std::unique_ptr<ARMOperand> CreateProcIFlags(ARM_PROC::IFlags IFlags, |
| 2777 | SMLoc S) { |
| 2778 | auto Op = make_unique<ARMOperand>(k_ProcIFlags); |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 2779 | Op->IFlags.Val = IFlags; |
| 2780 | Op->StartLoc = S; |
| 2781 | Op->EndLoc = S; |
| 2782 | return Op; |
| 2783 | } |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 2784 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 2785 | static std::unique_ptr<ARMOperand> CreateMSRMask(unsigned MMask, SMLoc S) { |
| 2786 | auto Op = make_unique<ARMOperand>(k_MSRMask); |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 2787 | Op->MMask.Val = MMask; |
| 2788 | Op->StartLoc = S; |
| 2789 | Op->EndLoc = S; |
| 2790 | return Op; |
| 2791 | } |
Tim Northover | ee843ef | 2014-08-15 10:47:12 +0000 | [diff] [blame] | 2792 | |
| 2793 | static std::unique_ptr<ARMOperand> CreateBankedReg(unsigned Reg, SMLoc S) { |
| 2794 | auto Op = make_unique<ARMOperand>(k_BankedReg); |
| 2795 | Op->BankedReg.Val = Reg; |
| 2796 | Op->StartLoc = S; |
| 2797 | Op->EndLoc = S; |
| 2798 | return Op; |
| 2799 | } |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 2800 | }; |
| 2801 | |
| 2802 | } // end anonymous namespace. |
| 2803 | |
Jim Grosbach | 602aa90 | 2011-07-13 15:34:57 +0000 | [diff] [blame] | 2804 | void ARMOperand::print(raw_ostream &OS) const { |
Daniel Dunbar | 4a863e6 | 2010-08-11 06:37:12 +0000 | [diff] [blame] | 2805 | switch (Kind) { |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2806 | case k_CondCode: |
Daniel Dunbar | 2be732a | 2011-01-10 15:26:21 +0000 | [diff] [blame] | 2807 | OS << "<ARMCC::" << ARMCondCodeToString(getCondCode()) << ">"; |
Daniel Dunbar | 4a863e6 | 2010-08-11 06:37:12 +0000 | [diff] [blame] | 2808 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2809 | case k_CCOut: |
Jim Grosbach | 0bfb4d5 | 2010-12-06 18:21:12 +0000 | [diff] [blame] | 2810 | OS << "<ccout " << getReg() << ">"; |
| 2811 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2812 | case k_ITCondMask: { |
Craig Topper | 42b96d1 | 2012-05-24 04:11:15 +0000 | [diff] [blame] | 2813 | static const char *const MaskStr[] = { |
Benjamin Kramer | 0d6d098 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 2814 | "()", "(t)", "(e)", "(tt)", "(et)", "(te)", "(ee)", "(ttt)", "(ett)", |
| 2815 | "(tet)", "(eet)", "(tte)", "(ete)", "(tee)", "(eee)" |
| 2816 | }; |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 2817 | assert((ITMask.Mask & 0xf) == ITMask.Mask); |
| 2818 | OS << "<it-mask " << MaskStr[ITMask.Mask] << ">"; |
| 2819 | break; |
| 2820 | } |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2821 | case k_CoprocNum: |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 2822 | OS << "<coprocessor number: " << getCoproc() << ">"; |
| 2823 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2824 | case k_CoprocReg: |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 2825 | OS << "<coprocessor register: " << getCoproc() << ">"; |
| 2826 | break; |
Jim Grosbach | 4839958 | 2011-10-12 17:34:41 +0000 | [diff] [blame] | 2827 | case k_CoprocOption: |
| 2828 | OS << "<coprocessor option: " << CoprocOption.Val << ">"; |
| 2829 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2830 | case k_MSRMask: |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 2831 | OS << "<mask: " << getMSRMask() << ">"; |
| 2832 | break; |
Tim Northover | ee843ef | 2014-08-15 10:47:12 +0000 | [diff] [blame] | 2833 | case k_BankedReg: |
| 2834 | OS << "<banked reg: " << getBankedReg() << ">"; |
| 2835 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2836 | case k_Immediate: |
Daniel Dunbar | 4a863e6 | 2010-08-11 06:37:12 +0000 | [diff] [blame] | 2837 | getImm()->print(OS); |
| 2838 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2839 | case k_MemBarrierOpt: |
Joey Gouly | 926d3f5 | 2013-09-05 15:35:24 +0000 | [diff] [blame] | 2840 | OS << "<ARM_MB::" << MemBOptToString(getMemBarrierOpt(), false) << ">"; |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 2841 | break; |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 2842 | case k_InstSyncBarrierOpt: |
| 2843 | OS << "<ARM_ISB::" << InstSyncBOptToString(getInstSyncBarrierOpt()) << ">"; |
| 2844 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2845 | case k_Memory: |
Daniel Dunbar | bcd8eb0 | 2011-01-18 05:55:21 +0000 | [diff] [blame] | 2846 | OS << "<memory " |
Jim Grosbach | 871dff7 | 2011-10-11 15:59:20 +0000 | [diff] [blame] | 2847 | << " base:" << Memory.BaseRegNum; |
Daniel Dunbar | bcd8eb0 | 2011-01-18 05:55:21 +0000 | [diff] [blame] | 2848 | OS << ">"; |
Daniel Dunbar | 4a863e6 | 2010-08-11 06:37:12 +0000 | [diff] [blame] | 2849 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2850 | case k_PostIndexRegister: |
Jim Grosbach | c320c85 | 2011-08-05 21:28:30 +0000 | [diff] [blame] | 2851 | OS << "post-idx register " << (PostIdxReg.isAdd ? "" : "-") |
| 2852 | << PostIdxReg.RegNum; |
| 2853 | if (PostIdxReg.ShiftTy != ARM_AM::no_shift) |
| 2854 | OS << ARM_AM::getShiftOpcStr(PostIdxReg.ShiftTy) << " " |
| 2855 | << PostIdxReg.ShiftImm; |
| 2856 | OS << ">"; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2857 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2858 | case k_ProcIFlags: { |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 2859 | OS << "<ARM_PROC::"; |
| 2860 | unsigned IFlags = getProcIFlags(); |
| 2861 | for (int i=2; i >= 0; --i) |
| 2862 | if (IFlags & (1 << i)) |
| 2863 | OS << ARM_PROC::IFlagsToString(1 << i); |
| 2864 | OS << ">"; |
| 2865 | break; |
| 2866 | } |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2867 | case k_Register: |
Bill Wendling | 2063b84 | 2010-11-18 23:43:05 +0000 | [diff] [blame] | 2868 | OS << "<register " << getReg() << ">"; |
Daniel Dunbar | 4a863e6 | 2010-08-11 06:37:12 +0000 | [diff] [blame] | 2869 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2870 | case k_ShifterImmediate: |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 2871 | OS << "<shift " << (ShifterImm.isASR ? "asr" : "lsl") |
| 2872 | << " #" << ShifterImm.Imm << ">"; |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 2873 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2874 | case k_ShiftedRegister: |
Owen Anderson | b595ed0 | 2011-07-21 18:54:16 +0000 | [diff] [blame] | 2875 | OS << "<so_reg_reg " |
Jim Grosbach | 01e0439 | 2011-11-16 21:46:50 +0000 | [diff] [blame] | 2876 | << RegShiftedReg.SrcReg << " " |
| 2877 | << ARM_AM::getShiftOpcStr(RegShiftedReg.ShiftTy) |
| 2878 | << " " << RegShiftedReg.ShiftReg << ">"; |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 2879 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2880 | case k_ShiftedImmediate: |
Owen Anderson | b595ed0 | 2011-07-21 18:54:16 +0000 | [diff] [blame] | 2881 | OS << "<so_reg_imm " |
Jim Grosbach | 01e0439 | 2011-11-16 21:46:50 +0000 | [diff] [blame] | 2882 | << RegShiftedImm.SrcReg << " " |
| 2883 | << ARM_AM::getShiftOpcStr(RegShiftedImm.ShiftTy) |
| 2884 | << " #" << RegShiftedImm.ShiftImm << ">"; |
Owen Anderson | b595ed0 | 2011-07-21 18:54:16 +0000 | [diff] [blame] | 2885 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2886 | case k_RotateImmediate: |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 2887 | OS << "<ror " << " #" << (RotImm.Imm * 8) << ">"; |
| 2888 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2889 | case k_BitfieldDescriptor: |
Jim Grosbach | 864b609 | 2011-07-28 21:34:26 +0000 | [diff] [blame] | 2890 | OS << "<bitfield " << "lsb: " << Bitfield.LSB |
| 2891 | << ", width: " << Bitfield.Width << ">"; |
| 2892 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2893 | case k_RegisterList: |
| 2894 | case k_DPRRegisterList: |
| 2895 | case k_SPRRegisterList: { |
Bill Wendling | 7cef447 | 2010-11-06 19:56:04 +0000 | [diff] [blame] | 2896 | OS << "<register_list "; |
Bill Wendling | 7cef447 | 2010-11-06 19:56:04 +0000 | [diff] [blame] | 2897 | |
Bill Wendling | bed9465 | 2010-11-09 23:28:44 +0000 | [diff] [blame] | 2898 | const SmallVectorImpl<unsigned> &RegList = getRegList(); |
| 2899 | for (SmallVectorImpl<unsigned>::const_iterator |
Bill Wendling | 2cae327 | 2010-11-09 22:44:22 +0000 | [diff] [blame] | 2900 | I = RegList.begin(), E = RegList.end(); I != E; ) { |
| 2901 | OS << *I; |
| 2902 | if (++I < E) OS << ", "; |
Bill Wendling | 7cef447 | 2010-11-06 19:56:04 +0000 | [diff] [blame] | 2903 | } |
| 2904 | |
| 2905 | OS << ">"; |
| 2906 | break; |
| 2907 | } |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 2908 | case k_VectorList: |
| 2909 | OS << "<vector_list " << VectorList.Count << " * " |
| 2910 | << VectorList.RegNum << ">"; |
| 2911 | break; |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 2912 | case k_VectorListAllLanes: |
| 2913 | OS << "<vector_list(all lanes) " << VectorList.Count << " * " |
| 2914 | << VectorList.RegNum << ">"; |
| 2915 | break; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 2916 | case k_VectorListIndexed: |
| 2917 | OS << "<vector_list(lane " << VectorList.LaneIndex << ") " |
| 2918 | << VectorList.Count << " * " << VectorList.RegNum << ">"; |
| 2919 | break; |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 2920 | case k_Token: |
Daniel Dunbar | 4a863e6 | 2010-08-11 06:37:12 +0000 | [diff] [blame] | 2921 | OS << "'" << getToken() << "'"; |
| 2922 | break; |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 2923 | case k_VectorIndex: |
| 2924 | OS << "<vectorindex " << getVectorIndex() << ">"; |
| 2925 | break; |
Daniel Dunbar | 4a863e6 | 2010-08-11 06:37:12 +0000 | [diff] [blame] | 2926 | } |
| 2927 | } |
Daniel Dunbar | 5cd4d0f | 2010-08-11 05:24:50 +0000 | [diff] [blame] | 2928 | |
| 2929 | /// @name Auto-generated Match Functions |
| 2930 | /// { |
| 2931 | |
| 2932 | static unsigned MatchRegisterName(StringRef Name); |
| 2933 | |
| 2934 | /// } |
| 2935 | |
Bob Wilson | fb0bd04 | 2011-02-03 21:46:10 +0000 | [diff] [blame] | 2936 | bool ARMAsmParser::ParseRegister(unsigned &RegNo, |
| 2937 | SMLoc &StartLoc, SMLoc &EndLoc) { |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 2938 | StartLoc = Parser.getTok().getLoc(); |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 2939 | EndLoc = Parser.getTok().getEndLoc(); |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 2940 | RegNo = tryParseRegister(); |
Roman Divacky | 36b1b47 | 2011-01-27 17:14:22 +0000 | [diff] [blame] | 2941 | |
| 2942 | return (RegNo == (unsigned)-1); |
| 2943 | } |
| 2944 | |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 2945 | /// 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] | 2946 | /// and if it is a register name the token is eaten and the register number is |
| 2947 | /// returned. Otherwise return -1. |
| 2948 | /// |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 2949 | int ARMAsmParser::tryParseRegister() { |
Chris Lattner | 44e5981c | 2010-10-30 04:09:10 +0000 | [diff] [blame] | 2950 | const AsmToken &Tok = Parser.getTok(); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 2951 | if (Tok.isNot(AsmToken::Identifier)) return -1; |
Jim Grosbach | 99710a8 | 2010-11-01 16:44:21 +0000 | [diff] [blame] | 2952 | |
Benjamin Kramer | 20baffb | 2011-11-06 20:37:06 +0000 | [diff] [blame] | 2953 | std::string lowerCase = Tok.getString().lower(); |
Owen Anderson | a098d15 | 2011-01-13 22:50:36 +0000 | [diff] [blame] | 2954 | unsigned RegNum = MatchRegisterName(lowerCase); |
| 2955 | if (!RegNum) { |
| 2956 | RegNum = StringSwitch<unsigned>(lowerCase) |
| 2957 | .Case("r13", ARM::SP) |
| 2958 | .Case("r14", ARM::LR) |
| 2959 | .Case("r15", ARM::PC) |
| 2960 | .Case("ip", ARM::R12) |
Jim Grosbach | 4edc736 | 2011-12-08 19:27:38 +0000 | [diff] [blame] | 2961 | // Additional register name aliases for 'gas' compatibility. |
| 2962 | .Case("a1", ARM::R0) |
| 2963 | .Case("a2", ARM::R1) |
| 2964 | .Case("a3", ARM::R2) |
| 2965 | .Case("a4", ARM::R3) |
| 2966 | .Case("v1", ARM::R4) |
| 2967 | .Case("v2", ARM::R5) |
| 2968 | .Case("v3", ARM::R6) |
| 2969 | .Case("v4", ARM::R7) |
| 2970 | .Case("v5", ARM::R8) |
| 2971 | .Case("v6", ARM::R9) |
| 2972 | .Case("v7", ARM::R10) |
| 2973 | .Case("v8", ARM::R11) |
| 2974 | .Case("sb", ARM::R9) |
| 2975 | .Case("sl", ARM::R10) |
| 2976 | .Case("fp", ARM::R11) |
Owen Anderson | a098d15 | 2011-01-13 22:50:36 +0000 | [diff] [blame] | 2977 | .Default(0); |
| 2978 | } |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 2979 | if (!RegNum) { |
Jim Grosbach | cd22e4a | 2011-12-20 23:11:00 +0000 | [diff] [blame] | 2980 | // Check for aliases registered via .req. Canonicalize to lower case. |
| 2981 | // That's more consistent since register names are case insensitive, and |
| 2982 | // it's how the original entry was passed in from MC/MCParser/AsmParser. |
| 2983 | StringMap<unsigned>::const_iterator Entry = RegisterReqs.find(lowerCase); |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 2984 | // If no match, return failure. |
| 2985 | if (Entry == RegisterReqs.end()) |
| 2986 | return -1; |
| 2987 | Parser.Lex(); // Eat identifier token. |
| 2988 | return Entry->getValue(); |
| 2989 | } |
Bob Wilson | fb0bd04 | 2011-02-03 21:46:10 +0000 | [diff] [blame] | 2990 | |
Chris Lattner | 44e5981c | 2010-10-30 04:09:10 +0000 | [diff] [blame] | 2991 | Parser.Lex(); // Eat identifier token. |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 2992 | |
Chris Lattner | 44e5981c | 2010-10-30 04:09:10 +0000 | [diff] [blame] | 2993 | return RegNum; |
| 2994 | } |
Jim Grosbach | 99710a8 | 2010-11-01 16:44:21 +0000 | [diff] [blame] | 2995 | |
Jim Grosbach | bb24c59 | 2011-07-13 18:49:30 +0000 | [diff] [blame] | 2996 | // Try to parse a shifter (e.g., "lsl <amt>"). On success, return 0. |
| 2997 | // If a recoverable error occurs, return 1. If an irrecoverable error |
| 2998 | // occurs, return -1. An irrecoverable error is one where tokens have been |
| 2999 | // consumed in the process of trying to parse the shifter (i.e., when it is |
| 3000 | // indeed a shifter operand, but malformed). |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 3001 | int ARMAsmParser::tryParseShiftRegister(OperandVector &Operands) { |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 3002 | SMLoc S = Parser.getTok().getLoc(); |
| 3003 | const AsmToken &Tok = Parser.getTok(); |
Kevin Enderby | 6287371 | 2014-02-17 21:45:27 +0000 | [diff] [blame] | 3004 | if (Tok.isNot(AsmToken::Identifier)) |
| 3005 | return -1; |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 3006 | |
Benjamin Kramer | 20baffb | 2011-11-06 20:37:06 +0000 | [diff] [blame] | 3007 | std::string lowerCase = Tok.getString().lower(); |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 3008 | ARM_AM::ShiftOpc ShiftTy = StringSwitch<ARM_AM::ShiftOpc>(lowerCase) |
Jim Grosbach | 3b559ff | 2011-12-07 23:40:58 +0000 | [diff] [blame] | 3009 | .Case("asl", ARM_AM::lsl) |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 3010 | .Case("lsl", ARM_AM::lsl) |
| 3011 | .Case("lsr", ARM_AM::lsr) |
| 3012 | .Case("asr", ARM_AM::asr) |
| 3013 | .Case("ror", ARM_AM::ror) |
| 3014 | .Case("rrx", ARM_AM::rrx) |
| 3015 | .Default(ARM_AM::no_shift); |
| 3016 | |
| 3017 | if (ShiftTy == ARM_AM::no_shift) |
Jim Grosbach | bb24c59 | 2011-07-13 18:49:30 +0000 | [diff] [blame] | 3018 | return 1; |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 3019 | |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 3020 | Parser.Lex(); // Eat the operator. |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 3021 | |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 3022 | // The source register for the shift has already been added to the |
| 3023 | // operand list, so we need to pop it off and combine it into the shifted |
| 3024 | // register operand instead. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 3025 | std::unique_ptr<ARMOperand> PrevOp( |
| 3026 | (ARMOperand *)Operands.pop_back_val().release()); |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 3027 | if (!PrevOp->isReg()) |
| 3028 | return Error(PrevOp->getStartLoc(), "shift must be of a register"); |
| 3029 | int SrcReg = PrevOp->getReg(); |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3030 | |
| 3031 | SMLoc EndLoc; |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 3032 | int64_t Imm = 0; |
| 3033 | int ShiftReg = 0; |
| 3034 | if (ShiftTy == ARM_AM::rrx) { |
| 3035 | // RRX Doesn't have an explicit shift amount. The encoder expects |
| 3036 | // the shift register to be the same as the source register. Seems odd, |
| 3037 | // but OK. |
| 3038 | ShiftReg = SrcReg; |
| 3039 | } else { |
| 3040 | // 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] | 3041 | if (Parser.getTok().is(AsmToken::Hash) || |
| 3042 | Parser.getTok().is(AsmToken::Dollar)) { |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 3043 | Parser.Lex(); // Eat hash. |
| 3044 | SMLoc ImmLoc = Parser.getTok().getLoc(); |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 3045 | const MCExpr *ShiftExpr = nullptr; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 3046 | if (getParser().parseExpression(ShiftExpr, EndLoc)) { |
Jim Grosbach | bb24c59 | 2011-07-13 18:49:30 +0000 | [diff] [blame] | 3047 | Error(ImmLoc, "invalid immediate shift value"); |
| 3048 | return -1; |
| 3049 | } |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 3050 | // The expression must be evaluatable as an immediate. |
| 3051 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftExpr); |
Jim Grosbach | bb24c59 | 2011-07-13 18:49:30 +0000 | [diff] [blame] | 3052 | if (!CE) { |
| 3053 | Error(ImmLoc, "invalid immediate shift value"); |
| 3054 | return -1; |
| 3055 | } |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 3056 | // Range check the immediate. |
| 3057 | // lsl, ror: 0 <= imm <= 31 |
| 3058 | // lsr, asr: 0 <= imm <= 32 |
| 3059 | Imm = CE->getValue(); |
| 3060 | if (Imm < 0 || |
| 3061 | ((ShiftTy == ARM_AM::lsl || ShiftTy == ARM_AM::ror) && Imm > 31) || |
| 3062 | ((ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr) && Imm > 32)) { |
Jim Grosbach | bb24c59 | 2011-07-13 18:49:30 +0000 | [diff] [blame] | 3063 | Error(ImmLoc, "immediate shift value out of range"); |
| 3064 | return -1; |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 3065 | } |
Jim Grosbach | 21488b8 | 2011-12-22 17:37:00 +0000 | [diff] [blame] | 3066 | // shift by zero is a nop. Always send it through as lsl. |
| 3067 | // ('as' compatibility) |
| 3068 | if (Imm == 0) |
| 3069 | ShiftTy = ARM_AM::lsl; |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 3070 | } else if (Parser.getTok().is(AsmToken::Identifier)) { |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 3071 | SMLoc L = Parser.getTok().getLoc(); |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3072 | EndLoc = Parser.getTok().getEndLoc(); |
| 3073 | ShiftReg = tryParseRegister(); |
Jim Grosbach | bb24c59 | 2011-07-13 18:49:30 +0000 | [diff] [blame] | 3074 | if (ShiftReg == -1) { |
Saleem Abdulrasool | 6d11b7c | 2014-05-17 21:49:54 +0000 | [diff] [blame] | 3075 | Error(L, "expected immediate or register in shift operand"); |
Jim Grosbach | bb24c59 | 2011-07-13 18:49:30 +0000 | [diff] [blame] | 3076 | return -1; |
| 3077 | } |
| 3078 | } else { |
Saleem Abdulrasool | 6d11b7c | 2014-05-17 21:49:54 +0000 | [diff] [blame] | 3079 | Error(Parser.getTok().getLoc(), |
| 3080 | "expected immediate or register in shift operand"); |
Jim Grosbach | bb24c59 | 2011-07-13 18:49:30 +0000 | [diff] [blame] | 3081 | return -1; |
| 3082 | } |
Jim Grosbach | 7dcd135 | 2011-07-13 17:50:29 +0000 | [diff] [blame] | 3083 | } |
| 3084 | |
Owen Anderson | b595ed0 | 2011-07-21 18:54:16 +0000 | [diff] [blame] | 3085 | if (ShiftReg && ShiftTy != ARM_AM::rrx) |
| 3086 | Operands.push_back(ARMOperand::CreateShiftedRegister(ShiftTy, SrcReg, |
Jim Grosbach | ac798e1 | 2011-07-25 20:49:51 +0000 | [diff] [blame] | 3087 | ShiftReg, Imm, |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3088 | S, EndLoc)); |
Owen Anderson | b595ed0 | 2011-07-21 18:54:16 +0000 | [diff] [blame] | 3089 | else |
| 3090 | Operands.push_back(ARMOperand::CreateShiftedImmediate(ShiftTy, SrcReg, Imm, |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3091 | S, EndLoc)); |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 3092 | |
Jim Grosbach | bb24c59 | 2011-07-13 18:49:30 +0000 | [diff] [blame] | 3093 | return 0; |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 3094 | } |
| 3095 | |
| 3096 | |
Bill Wendling | 2063b84 | 2010-11-18 23:43:05 +0000 | [diff] [blame] | 3097 | /// Try to parse a register name. The token must be an Identifier when called. |
| 3098 | /// If it's a register, an AsmOperand is created. Another AsmOperand is created |
| 3099 | /// if there is a "writeback". 'true' if it's not a register. |
Chris Lattner | bd7c9fa | 2010-10-28 17:20:03 +0000 | [diff] [blame] | 3100 | /// |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 3101 | /// TODO this is likely to change to allow different register types and or to |
| 3102 | /// parse for a specific register type. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 3103 | bool ARMAsmParser::tryParseRegisterWithWriteBack(OperandVector &Operands) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3104 | const AsmToken &RegTok = Parser.getTok(); |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 3105 | int RegNo = tryParseRegister(); |
Bill Wendling | e18980a | 2010-11-06 22:36:58 +0000 | [diff] [blame] | 3106 | if (RegNo == -1) |
Bill Wendling | 2063b84 | 2010-11-18 23:43:05 +0000 | [diff] [blame] | 3107 | return true; |
Jim Grosbach | 99710a8 | 2010-11-01 16:44:21 +0000 | [diff] [blame] | 3108 | |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3109 | Operands.push_back(ARMOperand::CreateReg(RegNo, RegTok.getLoc(), |
| 3110 | RegTok.getEndLoc())); |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 3111 | |
Chris Lattner | 44e5981c | 2010-10-30 04:09:10 +0000 | [diff] [blame] | 3112 | const AsmToken &ExclaimTok = Parser.getTok(); |
| 3113 | if (ExclaimTok.is(AsmToken::Exclaim)) { |
Bill Wendling | 2063b84 | 2010-11-18 23:43:05 +0000 | [diff] [blame] | 3114 | Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(), |
| 3115 | ExclaimTok.getLoc())); |
Chris Lattner | 44e5981c | 2010-10-30 04:09:10 +0000 | [diff] [blame] | 3116 | Parser.Lex(); // Eat exclaim token |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 3117 | return false; |
| 3118 | } |
| 3119 | |
| 3120 | // Also check for an index operand. This is only legal for vector registers, |
| 3121 | // but that'll get caught OK in operand matching, so we don't need to |
| 3122 | // explicitly filter everything else out here. |
| 3123 | if (Parser.getTok().is(AsmToken::LBrac)) { |
| 3124 | SMLoc SIdx = Parser.getTok().getLoc(); |
| 3125 | Parser.Lex(); // Eat left bracket token. |
| 3126 | |
| 3127 | const MCExpr *ImmVal; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 3128 | if (getParser().parseExpression(ImmVal)) |
Jim Grosbach | a2147ce | 2012-01-31 23:51:09 +0000 | [diff] [blame] | 3129 | return true; |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 3130 | const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(ImmVal); |
Jim Grosbach | c8f2b78 | 2012-01-26 15:56:45 +0000 | [diff] [blame] | 3131 | if (!MCE) |
| 3132 | return TokError("immediate value expected for vector index"); |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 3133 | |
Jim Grosbach | c8f2b78 | 2012-01-26 15:56:45 +0000 | [diff] [blame] | 3134 | if (Parser.getTok().isNot(AsmToken::RBrac)) |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3135 | return Error(Parser.getTok().getLoc(), "']' expected"); |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 3136 | |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3137 | SMLoc E = Parser.getTok().getEndLoc(); |
Jim Grosbach | d0637bf | 2011-10-07 23:56:00 +0000 | [diff] [blame] | 3138 | Parser.Lex(); // Eat right bracket token. |
| 3139 | |
| 3140 | Operands.push_back(ARMOperand::CreateVectorIndex(MCE->getValue(), |
| 3141 | SIdx, E, |
| 3142 | getContext())); |
Kevin Enderby | 2207e5f | 2009-10-07 18:01:35 +0000 | [diff] [blame] | 3143 | } |
| 3144 | |
Bill Wendling | 2063b84 | 2010-11-18 23:43:05 +0000 | [diff] [blame] | 3145 | return false; |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 3146 | } |
| 3147 | |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 3148 | /// MatchCoprocessorOperandName - Try to parse an coprocessor related |
Renato Golin | ac561c3 | 2014-06-26 13:10:53 +0000 | [diff] [blame] | 3149 | /// instruction with a symbolic operand name. |
| 3150 | /// We accept "crN" syntax for GAS compatibility. |
| 3151 | /// <operand-name> ::= <prefix><number> |
| 3152 | /// If CoprocOp is 'c', then: |
| 3153 | /// <prefix> ::= c | cr |
| 3154 | /// If CoprocOp is 'p', then : |
| 3155 | /// <prefix> ::= p |
| 3156 | /// <number> ::= integer in range [0, 15] |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 3157 | static int MatchCoprocessorOperandName(StringRef Name, char CoprocOp) { |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3158 | // Use the same layout as the tablegen'erated register name matcher. Ugly, |
| 3159 | // but efficient. |
Renato Golin | ac561c3 | 2014-06-26 13:10:53 +0000 | [diff] [blame] | 3160 | if (Name.size() < 2 || Name[0] != CoprocOp) |
| 3161 | return -1; |
| 3162 | Name = (Name[1] == 'r') ? Name.drop_front(2) : Name.drop_front(); |
| 3163 | |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3164 | switch (Name.size()) { |
David Blaikie | 46a9f01 | 2012-01-20 21:51:11 +0000 | [diff] [blame] | 3165 | default: return -1; |
Renato Golin | ac561c3 | 2014-06-26 13:10:53 +0000 | [diff] [blame] | 3166 | case 1: |
| 3167 | switch (Name[0]) { |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3168 | default: return -1; |
| 3169 | case '0': return 0; |
| 3170 | case '1': return 1; |
| 3171 | case '2': return 2; |
| 3172 | case '3': return 3; |
| 3173 | case '4': return 4; |
| 3174 | case '5': return 5; |
| 3175 | case '6': return 6; |
| 3176 | case '7': return 7; |
| 3177 | case '8': return 8; |
| 3178 | case '9': return 9; |
| 3179 | } |
Renato Golin | ac561c3 | 2014-06-26 13:10:53 +0000 | [diff] [blame] | 3180 | case 2: |
| 3181 | if (Name[0] != '1') |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3182 | return -1; |
Renato Golin | ac561c3 | 2014-06-26 13:10:53 +0000 | [diff] [blame] | 3183 | switch (Name[1]) { |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3184 | default: return -1; |
Renato Golin | bc0b037 | 2014-08-04 23:21:56 +0000 | [diff] [blame] | 3185 | // CP10 and CP11 are VFP/NEON and so vector instructions should be used. |
| 3186 | // However, old cores (v5/v6) did use them in that way. |
| 3187 | case '0': return 10; |
| 3188 | case '1': return 11; |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3189 | case '2': return 12; |
| 3190 | case '3': return 13; |
| 3191 | case '4': return 14; |
| 3192 | case '5': return 15; |
| 3193 | } |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3194 | } |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3195 | } |
| 3196 | |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 3197 | /// parseITCondCode - Try to parse a condition code for an IT instruction. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 3198 | ARMAsmParser::OperandMatchResultTy |
| 3199 | ARMAsmParser::parseITCondCode(OperandVector &Operands) { |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 3200 | SMLoc S = Parser.getTok().getLoc(); |
| 3201 | const AsmToken &Tok = Parser.getTok(); |
| 3202 | if (!Tok.is(AsmToken::Identifier)) |
| 3203 | return MatchOperand_NoMatch; |
Richard Barton | 82f95ea | 2012-04-27 17:34:01 +0000 | [diff] [blame] | 3204 | unsigned CC = StringSwitch<unsigned>(Tok.getString().lower()) |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 3205 | .Case("eq", ARMCC::EQ) |
| 3206 | .Case("ne", ARMCC::NE) |
| 3207 | .Case("hs", ARMCC::HS) |
| 3208 | .Case("cs", ARMCC::HS) |
| 3209 | .Case("lo", ARMCC::LO) |
| 3210 | .Case("cc", ARMCC::LO) |
| 3211 | .Case("mi", ARMCC::MI) |
| 3212 | .Case("pl", ARMCC::PL) |
| 3213 | .Case("vs", ARMCC::VS) |
| 3214 | .Case("vc", ARMCC::VC) |
| 3215 | .Case("hi", ARMCC::HI) |
| 3216 | .Case("ls", ARMCC::LS) |
| 3217 | .Case("ge", ARMCC::GE) |
| 3218 | .Case("lt", ARMCC::LT) |
| 3219 | .Case("gt", ARMCC::GT) |
| 3220 | .Case("le", ARMCC::LE) |
| 3221 | .Case("al", ARMCC::AL) |
| 3222 | .Default(~0U); |
| 3223 | if (CC == ~0U) |
| 3224 | return MatchOperand_NoMatch; |
| 3225 | Parser.Lex(); // Eat the token. |
| 3226 | |
| 3227 | Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC), S)); |
| 3228 | |
| 3229 | return MatchOperand_Success; |
| 3230 | } |
| 3231 | |
Jim Grosbach | 2d6ef44 | 2011-07-25 20:14:50 +0000 | [diff] [blame] | 3232 | /// parseCoprocNumOperand - Try to parse an coprocessor number operand. The |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 3233 | /// token must be an Identifier when called, and if it is a coprocessor |
| 3234 | /// 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] | 3235 | ARMAsmParser::OperandMatchResultTy |
| 3236 | ARMAsmParser::parseCoprocNumOperand(OperandVector &Operands) { |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3237 | SMLoc S = Parser.getTok().getLoc(); |
| 3238 | const AsmToken &Tok = Parser.getTok(); |
Jim Grosbach | 54a20ed | 2011-10-12 20:54:17 +0000 | [diff] [blame] | 3239 | if (Tok.isNot(AsmToken::Identifier)) |
| 3240 | return MatchOperand_NoMatch; |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3241 | |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 3242 | int Num = MatchCoprocessorOperandName(Tok.getString(), 'p'); |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3243 | if (Num == -1) |
Jim Grosbach | 861e49c | 2011-02-12 01:34:40 +0000 | [diff] [blame] | 3244 | return MatchOperand_NoMatch; |
Renato Golin | bc0b037 | 2014-08-04 23:21:56 +0000 | [diff] [blame] | 3245 | // ARMv7 and v8 don't allow cp10/cp11 due to VFP/NEON specific instructions |
| 3246 | if ((hasV7Ops() || hasV8Ops()) && (Num == 10 || Num == 11)) |
| 3247 | return MatchOperand_NoMatch; |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3248 | |
| 3249 | Parser.Lex(); // Eat identifier token. |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 3250 | Operands.push_back(ARMOperand::CreateCoprocNum(Num, S)); |
Jim Grosbach | 861e49c | 2011-02-12 01:34:40 +0000 | [diff] [blame] | 3251 | return MatchOperand_Success; |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 3252 | } |
| 3253 | |
Jim Grosbach | 2d6ef44 | 2011-07-25 20:14:50 +0000 | [diff] [blame] | 3254 | /// parseCoprocRegOperand - Try to parse an coprocessor register operand. The |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 3255 | /// token must be an Identifier when called, and if it is a coprocessor |
| 3256 | /// 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] | 3257 | ARMAsmParser::OperandMatchResultTy |
| 3258 | ARMAsmParser::parseCoprocRegOperand(OperandVector &Operands) { |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 3259 | SMLoc S = Parser.getTok().getLoc(); |
| 3260 | const AsmToken &Tok = Parser.getTok(); |
Jim Grosbach | 54a20ed | 2011-10-12 20:54:17 +0000 | [diff] [blame] | 3261 | if (Tok.isNot(AsmToken::Identifier)) |
| 3262 | return MatchOperand_NoMatch; |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 3263 | |
| 3264 | int Reg = MatchCoprocessorOperandName(Tok.getString(), 'c'); |
| 3265 | if (Reg == -1) |
Jim Grosbach | 861e49c | 2011-02-12 01:34:40 +0000 | [diff] [blame] | 3266 | return MatchOperand_NoMatch; |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 3267 | |
| 3268 | Parser.Lex(); // Eat identifier token. |
| 3269 | Operands.push_back(ARMOperand::CreateCoprocReg(Reg, S)); |
Jim Grosbach | 861e49c | 2011-02-12 01:34:40 +0000 | [diff] [blame] | 3270 | return MatchOperand_Success; |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 3271 | } |
| 3272 | |
Jim Grosbach | 4839958 | 2011-10-12 17:34:41 +0000 | [diff] [blame] | 3273 | /// parseCoprocOptionOperand - Try to parse an coprocessor option operand. |
| 3274 | /// coproc_option : '{' imm0_255 '}' |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 3275 | ARMAsmParser::OperandMatchResultTy |
| 3276 | ARMAsmParser::parseCoprocOptionOperand(OperandVector &Operands) { |
Jim Grosbach | 4839958 | 2011-10-12 17:34:41 +0000 | [diff] [blame] | 3277 | SMLoc S = Parser.getTok().getLoc(); |
| 3278 | |
| 3279 | // If this isn't a '{', this isn't a coprocessor immediate operand. |
| 3280 | if (Parser.getTok().isNot(AsmToken::LCurly)) |
| 3281 | return MatchOperand_NoMatch; |
| 3282 | Parser.Lex(); // Eat the '{' |
| 3283 | |
| 3284 | const MCExpr *Expr; |
| 3285 | SMLoc Loc = Parser.getTok().getLoc(); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 3286 | if (getParser().parseExpression(Expr)) { |
Jim Grosbach | 4839958 | 2011-10-12 17:34:41 +0000 | [diff] [blame] | 3287 | Error(Loc, "illegal expression"); |
| 3288 | return MatchOperand_ParseFail; |
| 3289 | } |
| 3290 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr); |
| 3291 | if (!CE || CE->getValue() < 0 || CE->getValue() > 255) { |
| 3292 | Error(Loc, "coprocessor option must be an immediate in range [0, 255]"); |
| 3293 | return MatchOperand_ParseFail; |
| 3294 | } |
| 3295 | int Val = CE->getValue(); |
| 3296 | |
| 3297 | // Check for and consume the closing '}' |
| 3298 | if (Parser.getTok().isNot(AsmToken::RCurly)) |
| 3299 | return MatchOperand_ParseFail; |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3300 | SMLoc E = Parser.getTok().getEndLoc(); |
Jim Grosbach | 4839958 | 2011-10-12 17:34:41 +0000 | [diff] [blame] | 3301 | Parser.Lex(); // Eat the '}' |
| 3302 | |
| 3303 | Operands.push_back(ARMOperand::CreateCoprocOption(Val, S, E)); |
| 3304 | return MatchOperand_Success; |
| 3305 | } |
| 3306 | |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3307 | // For register list parsing, we need to map from raw GPR register numbering |
| 3308 | // to the enumeration values. The enumeration values aren't sorted by |
| 3309 | // register number due to our using "sp", "lr" and "pc" as canonical names. |
| 3310 | static unsigned getNextRegister(unsigned Reg) { |
| 3311 | // If this is a GPR, we need to do it manually, otherwise we can rely |
| 3312 | // on the sort ordering of the enumeration since the other reg-classes |
| 3313 | // are sane. |
| 3314 | if (!ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg)) |
| 3315 | return Reg + 1; |
| 3316 | switch(Reg) { |
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 3317 | default: llvm_unreachable("Invalid GPR number!"); |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3318 | case ARM::R0: return ARM::R1; case ARM::R1: return ARM::R2; |
| 3319 | case ARM::R2: return ARM::R3; case ARM::R3: return ARM::R4; |
| 3320 | case ARM::R4: return ARM::R5; case ARM::R5: return ARM::R6; |
| 3321 | case ARM::R6: return ARM::R7; case ARM::R7: return ARM::R8; |
| 3322 | case ARM::R8: return ARM::R9; case ARM::R9: return ARM::R10; |
| 3323 | case ARM::R10: return ARM::R11; case ARM::R11: return ARM::R12; |
| 3324 | case ARM::R12: return ARM::SP; case ARM::SP: return ARM::LR; |
| 3325 | case ARM::LR: return ARM::PC; case ARM::PC: return ARM::R0; |
| 3326 | } |
| 3327 | } |
| 3328 | |
Jim Grosbach | 85a2343 | 2011-11-11 21:27:40 +0000 | [diff] [blame] | 3329 | // Return the low-subreg of a given Q register. |
| 3330 | static unsigned getDRegFromQReg(unsigned QReg) { |
| 3331 | switch (QReg) { |
| 3332 | default: llvm_unreachable("expected a Q register!"); |
| 3333 | case ARM::Q0: return ARM::D0; |
| 3334 | case ARM::Q1: return ARM::D2; |
| 3335 | case ARM::Q2: return ARM::D4; |
| 3336 | case ARM::Q3: return ARM::D6; |
| 3337 | case ARM::Q4: return ARM::D8; |
| 3338 | case ARM::Q5: return ARM::D10; |
| 3339 | case ARM::Q6: return ARM::D12; |
| 3340 | case ARM::Q7: return ARM::D14; |
| 3341 | case ARM::Q8: return ARM::D16; |
Jim Grosbach | a92a5d8 | 2011-11-15 21:01:30 +0000 | [diff] [blame] | 3342 | case ARM::Q9: return ARM::D18; |
Jim Grosbach | 85a2343 | 2011-11-11 21:27:40 +0000 | [diff] [blame] | 3343 | case ARM::Q10: return ARM::D20; |
| 3344 | case ARM::Q11: return ARM::D22; |
| 3345 | case ARM::Q12: return ARM::D24; |
| 3346 | case ARM::Q13: return ARM::D26; |
| 3347 | case ARM::Q14: return ARM::D28; |
| 3348 | case ARM::Q15: return ARM::D30; |
| 3349 | } |
| 3350 | } |
| 3351 | |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3352 | /// Parse a register list. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 3353 | bool ARMAsmParser::parseRegisterList(OperandVector &Operands) { |
Sean Callanan | 936b0d3 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 3354 | assert(Parser.getTok().is(AsmToken::LCurly) && |
Bill Wendling | 4f4bce0 | 2010-11-06 10:48:18 +0000 | [diff] [blame] | 3355 | "Token is not a Left Curly Brace"); |
Bill Wendling | e18980a | 2010-11-06 22:36:58 +0000 | [diff] [blame] | 3356 | SMLoc S = Parser.getTok().getLoc(); |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3357 | Parser.Lex(); // Eat '{' token. |
| 3358 | SMLoc RegLoc = Parser.getTok().getLoc(); |
Kevin Enderby | a2b9910 | 2009-10-09 21:12:28 +0000 | [diff] [blame] | 3359 | |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3360 | // Check the first register in the list to see what register class |
| 3361 | // this is a list of. |
| 3362 | int Reg = tryParseRegister(); |
| 3363 | if (Reg == -1) |
| 3364 | return Error(RegLoc, "register expected"); |
| 3365 | |
Jim Grosbach | 85a2343 | 2011-11-11 21:27:40 +0000 | [diff] [blame] | 3366 | // The reglist instructions have at most 16 registers, so reserve |
| 3367 | // space for that many. |
Chad Rosier | fa705ee | 2013-07-01 20:49:23 +0000 | [diff] [blame] | 3368 | int EReg = 0; |
| 3369 | SmallVector<std::pair<unsigned, unsigned>, 16> Registers; |
Jim Grosbach | 85a2343 | 2011-11-11 21:27:40 +0000 | [diff] [blame] | 3370 | |
| 3371 | // Allow Q regs and just interpret them as the two D sub-registers. |
| 3372 | if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) { |
| 3373 | Reg = getDRegFromQReg(Reg); |
Chad Rosier | fa705ee | 2013-07-01 20:49:23 +0000 | [diff] [blame] | 3374 | EReg = MRI->getEncodingValue(Reg); |
| 3375 | Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg)); |
Jim Grosbach | 85a2343 | 2011-11-11 21:27:40 +0000 | [diff] [blame] | 3376 | ++Reg; |
| 3377 | } |
Benjamin Kramer | 0d6d098 | 2011-10-22 16:50:00 +0000 | [diff] [blame] | 3378 | const MCRegisterClass *RC; |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3379 | if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg)) |
| 3380 | RC = &ARMMCRegisterClasses[ARM::GPRRegClassID]; |
| 3381 | else if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) |
| 3382 | RC = &ARMMCRegisterClasses[ARM::DPRRegClassID]; |
| 3383 | else if (ARMMCRegisterClasses[ARM::SPRRegClassID].contains(Reg)) |
| 3384 | RC = &ARMMCRegisterClasses[ARM::SPRRegClassID]; |
| 3385 | else |
| 3386 | return Error(RegLoc, "invalid register in register list"); |
| 3387 | |
Jim Grosbach | 85a2343 | 2011-11-11 21:27:40 +0000 | [diff] [blame] | 3388 | // Store the register. |
Chad Rosier | fa705ee | 2013-07-01 20:49:23 +0000 | [diff] [blame] | 3389 | EReg = MRI->getEncodingValue(Reg); |
| 3390 | Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg)); |
Kevin Enderby | a2b9910 | 2009-10-09 21:12:28 +0000 | [diff] [blame] | 3391 | |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3392 | // This starts immediately after the first register token in the list, |
| 3393 | // so we can see either a comma or a minus (range separator) as a legal |
| 3394 | // next token. |
| 3395 | while (Parser.getTok().is(AsmToken::Comma) || |
| 3396 | Parser.getTok().is(AsmToken::Minus)) { |
| 3397 | if (Parser.getTok().is(AsmToken::Minus)) { |
Jim Grosbach | e891fe8 | 2011-11-15 23:19:15 +0000 | [diff] [blame] | 3398 | Parser.Lex(); // Eat the minus. |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3399 | SMLoc AfterMinusLoc = Parser.getTok().getLoc(); |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3400 | int EndReg = tryParseRegister(); |
| 3401 | if (EndReg == -1) |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3402 | return Error(AfterMinusLoc, "register expected"); |
Jim Grosbach | 85a2343 | 2011-11-11 21:27:40 +0000 | [diff] [blame] | 3403 | // Allow Q regs and just interpret them as the two D sub-registers. |
| 3404 | if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg)) |
| 3405 | EndReg = getDRegFromQReg(EndReg) + 1; |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3406 | // If the register is the same as the start reg, there's nothing |
| 3407 | // more to do. |
| 3408 | if (Reg == EndReg) |
| 3409 | continue; |
| 3410 | // The register must be in the same register class as the first. |
| 3411 | if (!RC->contains(EndReg)) |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3412 | return Error(AfterMinusLoc, "invalid register in register list"); |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3413 | // Ranges must go from low to high. |
Eric Christopher | 6ac277c | 2012-08-09 22:10:21 +0000 | [diff] [blame] | 3414 | if (MRI->getEncodingValue(Reg) > MRI->getEncodingValue(EndReg)) |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3415 | return Error(AfterMinusLoc, "bad range in register list"); |
Kevin Enderby | a2b9910 | 2009-10-09 21:12:28 +0000 | [diff] [blame] | 3416 | |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3417 | // Add all the registers in the range to the register list. |
| 3418 | while (Reg != EndReg) { |
| 3419 | Reg = getNextRegister(Reg); |
Chad Rosier | fa705ee | 2013-07-01 20:49:23 +0000 | [diff] [blame] | 3420 | EReg = MRI->getEncodingValue(Reg); |
| 3421 | Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg)); |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3422 | } |
| 3423 | continue; |
| 3424 | } |
| 3425 | Parser.Lex(); // Eat the comma. |
| 3426 | RegLoc = Parser.getTok().getLoc(); |
| 3427 | int OldReg = Reg; |
Jim Grosbach | 98bc797 | 2011-12-08 21:34:20 +0000 | [diff] [blame] | 3428 | const AsmToken RegTok = Parser.getTok(); |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3429 | Reg = tryParseRegister(); |
| 3430 | if (Reg == -1) |
Jim Grosbach | 3337e39 | 2011-09-12 23:36:42 +0000 | [diff] [blame] | 3431 | return Error(RegLoc, "register expected"); |
Jim Grosbach | 85a2343 | 2011-11-11 21:27:40 +0000 | [diff] [blame] | 3432 | // Allow Q regs and just interpret them as the two D sub-registers. |
| 3433 | bool isQReg = false; |
| 3434 | if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) { |
| 3435 | Reg = getDRegFromQReg(Reg); |
| 3436 | isQReg = true; |
| 3437 | } |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3438 | // The register must be in the same register class as the first. |
| 3439 | if (!RC->contains(Reg)) |
| 3440 | return Error(RegLoc, "invalid register in register list"); |
| 3441 | // List must be monotonically increasing. |
Eric Christopher | 6ac277c | 2012-08-09 22:10:21 +0000 | [diff] [blame] | 3442 | if (MRI->getEncodingValue(Reg) < MRI->getEncodingValue(OldReg)) { |
Jim Grosbach | 905686a | 2012-03-16 20:48:38 +0000 | [diff] [blame] | 3443 | if (ARMMCRegisterClasses[ARM::GPRRegClassID].contains(Reg)) |
| 3444 | Warning(RegLoc, "register list not in ascending order"); |
| 3445 | else |
| 3446 | return Error(RegLoc, "register list not in ascending order"); |
| 3447 | } |
Eric Christopher | 6ac277c | 2012-08-09 22:10:21 +0000 | [diff] [blame] | 3448 | if (MRI->getEncodingValue(Reg) == MRI->getEncodingValue(OldReg)) { |
Jim Grosbach | 98bc797 | 2011-12-08 21:34:20 +0000 | [diff] [blame] | 3449 | Warning(RegLoc, "duplicated register (" + RegTok.getString() + |
| 3450 | ") in register list"); |
| 3451 | continue; |
| 3452 | } |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3453 | // VFP register lists must also be contiguous. |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3454 | if (RC != &ARMMCRegisterClasses[ARM::GPRRegClassID] && |
| 3455 | Reg != OldReg + 1) |
| 3456 | return Error(RegLoc, "non-contiguous register range"); |
Chad Rosier | fa705ee | 2013-07-01 20:49:23 +0000 | [diff] [blame] | 3457 | EReg = MRI->getEncodingValue(Reg); |
| 3458 | Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg)); |
| 3459 | if (isQReg) { |
| 3460 | EReg = MRI->getEncodingValue(++Reg); |
| 3461 | Registers.push_back(std::pair<unsigned, unsigned>(EReg, Reg)); |
| 3462 | } |
Bill Wendling | e18980a | 2010-11-06 22:36:58 +0000 | [diff] [blame] | 3463 | } |
| 3464 | |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3465 | if (Parser.getTok().isNot(AsmToken::RCurly)) |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3466 | return Error(Parser.getTok().getLoc(), "'}' expected"); |
| 3467 | SMLoc E = Parser.getTok().getEndLoc(); |
Jim Grosbach | 3ac26b1 | 2011-09-14 18:08:35 +0000 | [diff] [blame] | 3468 | Parser.Lex(); // Eat '}' token. |
| 3469 | |
Jim Grosbach | 18bf363 | 2011-12-13 21:48:29 +0000 | [diff] [blame] | 3470 | // Push the register list operand. |
Bill Wendling | 2063b84 | 2010-11-18 23:43:05 +0000 | [diff] [blame] | 3471 | Operands.push_back(ARMOperand::CreateRegList(Registers, S, E)); |
Jim Grosbach | 18bf363 | 2011-12-13 21:48:29 +0000 | [diff] [blame] | 3472 | |
| 3473 | // The ARM system instruction variants for LDM/STM have a '^' token here. |
| 3474 | if (Parser.getTok().is(AsmToken::Caret)) { |
| 3475 | Operands.push_back(ARMOperand::CreateToken("^",Parser.getTok().getLoc())); |
| 3476 | Parser.Lex(); // Eat '^' token. |
| 3477 | } |
| 3478 | |
Bill Wendling | 2063b84 | 2010-11-18 23:43:05 +0000 | [diff] [blame] | 3479 | return false; |
Kevin Enderby | a2b9910 | 2009-10-09 21:12:28 +0000 | [diff] [blame] | 3480 | } |
| 3481 | |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3482 | // Helper function to parse the lane index for vector lists. |
| 3483 | ARMAsmParser::OperandMatchResultTy ARMAsmParser:: |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3484 | parseVectorLane(VectorLaneTy &LaneKind, unsigned &Index, SMLoc &EndLoc) { |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3485 | Index = 0; // Always return a defined index value. |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3486 | if (Parser.getTok().is(AsmToken::LBrac)) { |
| 3487 | Parser.Lex(); // Eat the '['. |
| 3488 | if (Parser.getTok().is(AsmToken::RBrac)) { |
| 3489 | // "Dn[]" is the 'all lanes' syntax. |
| 3490 | LaneKind = AllLanes; |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3491 | EndLoc = Parser.getTok().getEndLoc(); |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3492 | Parser.Lex(); // Eat the ']'. |
| 3493 | return MatchOperand_Success; |
| 3494 | } |
Jim Grosbach | 67e76ba | 2012-03-19 20:39:53 +0000 | [diff] [blame] | 3495 | |
| 3496 | // There's an optional '#' token here. Normally there wouldn't be, but |
| 3497 | // inline assemble puts one in, and it's friendly to accept that. |
| 3498 | if (Parser.getTok().is(AsmToken::Hash)) |
Amaury de la Vieuville | bac917f | 2013-06-10 14:17:15 +0000 | [diff] [blame] | 3499 | Parser.Lex(); // Eat '#' or '$'. |
Jim Grosbach | 67e76ba | 2012-03-19 20:39:53 +0000 | [diff] [blame] | 3500 | |
Jim Grosbach | 7de7ab8 | 2011-12-21 01:19:23 +0000 | [diff] [blame] | 3501 | const MCExpr *LaneIndex; |
| 3502 | SMLoc Loc = Parser.getTok().getLoc(); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 3503 | if (getParser().parseExpression(LaneIndex)) { |
Jim Grosbach | 7de7ab8 | 2011-12-21 01:19:23 +0000 | [diff] [blame] | 3504 | Error(Loc, "illegal expression"); |
| 3505 | return MatchOperand_ParseFail; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3506 | } |
Jim Grosbach | 7de7ab8 | 2011-12-21 01:19:23 +0000 | [diff] [blame] | 3507 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LaneIndex); |
| 3508 | if (!CE) { |
| 3509 | Error(Loc, "lane index must be empty or an integer"); |
| 3510 | return MatchOperand_ParseFail; |
| 3511 | } |
| 3512 | if (Parser.getTok().isNot(AsmToken::RBrac)) { |
| 3513 | Error(Parser.getTok().getLoc(), "']' expected"); |
| 3514 | return MatchOperand_ParseFail; |
| 3515 | } |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3516 | EndLoc = Parser.getTok().getEndLoc(); |
Jim Grosbach | 7de7ab8 | 2011-12-21 01:19:23 +0000 | [diff] [blame] | 3517 | Parser.Lex(); // Eat the ']'. |
| 3518 | int64_t Val = CE->getValue(); |
| 3519 | |
| 3520 | // FIXME: Make this range check context sensitive for .8, .16, .32. |
| 3521 | if (Val < 0 || Val > 7) { |
| 3522 | Error(Parser.getTok().getLoc(), "lane index out of range"); |
| 3523 | return MatchOperand_ParseFail; |
| 3524 | } |
| 3525 | Index = Val; |
| 3526 | LaneKind = IndexedLane; |
| 3527 | return MatchOperand_Success; |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3528 | } |
| 3529 | LaneKind = NoLanes; |
| 3530 | return MatchOperand_Success; |
| 3531 | } |
| 3532 | |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3533 | // parse a vector register list |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 3534 | ARMAsmParser::OperandMatchResultTy |
| 3535 | ARMAsmParser::parseVectorList(OperandVector &Operands) { |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3536 | VectorLaneTy LaneKind; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3537 | unsigned LaneIndex; |
Jim Grosbach | 8d57923 | 2011-11-15 21:45:55 +0000 | [diff] [blame] | 3538 | SMLoc S = Parser.getTok().getLoc(); |
| 3539 | // As an extension (to match gas), support a plain D register or Q register |
| 3540 | // (without encosing curly braces) as a single or double entry list, |
| 3541 | // respectively. |
| 3542 | if (Parser.getTok().is(AsmToken::Identifier)) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3543 | SMLoc E = Parser.getTok().getEndLoc(); |
Jim Grosbach | 8d57923 | 2011-11-15 21:45:55 +0000 | [diff] [blame] | 3544 | int Reg = tryParseRegister(); |
| 3545 | if (Reg == -1) |
| 3546 | return MatchOperand_NoMatch; |
Jim Grosbach | 8d57923 | 2011-11-15 21:45:55 +0000 | [diff] [blame] | 3547 | if (ARMMCRegisterClasses[ARM::DPRRegClassID].contains(Reg)) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3548 | OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E); |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3549 | if (Res != MatchOperand_Success) |
| 3550 | return Res; |
| 3551 | switch (LaneKind) { |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3552 | case NoLanes: |
Jim Grosbach | 2f50e92 | 2011-12-15 21:44:33 +0000 | [diff] [blame] | 3553 | Operands.push_back(ARMOperand::CreateVectorList(Reg, 1, false, S, E)); |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3554 | break; |
| 3555 | case AllLanes: |
Jim Grosbach | c5af54e | 2011-12-21 00:38:54 +0000 | [diff] [blame] | 3556 | Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 1, false, |
| 3557 | S, E)); |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3558 | break; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3559 | case IndexedLane: |
| 3560 | Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 1, |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 3561 | LaneIndex, |
| 3562 | false, S, E)); |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3563 | break; |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3564 | } |
Jim Grosbach | 8d57923 | 2011-11-15 21:45:55 +0000 | [diff] [blame] | 3565 | return MatchOperand_Success; |
| 3566 | } |
| 3567 | if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) { |
| 3568 | Reg = getDRegFromQReg(Reg); |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3569 | OperandMatchResultTy Res = parseVectorLane(LaneKind, LaneIndex, E); |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3570 | if (Res != MatchOperand_Success) |
| 3571 | return Res; |
| 3572 | switch (LaneKind) { |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3573 | case NoLanes: |
Jim Grosbach | c988e0c | 2012-03-05 19:33:30 +0000 | [diff] [blame] | 3574 | Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0, |
Jim Grosbach | 13a292c | 2012-03-06 22:01:44 +0000 | [diff] [blame] | 3575 | &ARMMCRegisterClasses[ARM::DPairRegClassID]); |
Jim Grosbach | 2f50e92 | 2011-12-15 21:44:33 +0000 | [diff] [blame] | 3576 | Operands.push_back(ARMOperand::CreateVectorList(Reg, 2, false, S, E)); |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3577 | break; |
| 3578 | case AllLanes: |
Jim Grosbach | 13a292c | 2012-03-06 22:01:44 +0000 | [diff] [blame] | 3579 | Reg = MRI->getMatchingSuperReg(Reg, ARM::dsub_0, |
| 3580 | &ARMMCRegisterClasses[ARM::DPairRegClassID]); |
Jim Grosbach | c5af54e | 2011-12-21 00:38:54 +0000 | [diff] [blame] | 3581 | Operands.push_back(ARMOperand::CreateVectorListAllLanes(Reg, 2, false, |
| 3582 | S, E)); |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3583 | break; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3584 | case IndexedLane: |
| 3585 | Operands.push_back(ARMOperand::CreateVectorListIndexed(Reg, 2, |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 3586 | LaneIndex, |
| 3587 | false, S, E)); |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3588 | break; |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3589 | } |
Jim Grosbach | 8d57923 | 2011-11-15 21:45:55 +0000 | [diff] [blame] | 3590 | return MatchOperand_Success; |
| 3591 | } |
| 3592 | Error(S, "vector register expected"); |
| 3593 | return MatchOperand_ParseFail; |
| 3594 | } |
| 3595 | |
| 3596 | if (Parser.getTok().isNot(AsmToken::LCurly)) |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3597 | return MatchOperand_NoMatch; |
| 3598 | |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3599 | Parser.Lex(); // Eat '{' token. |
| 3600 | SMLoc RegLoc = Parser.getTok().getLoc(); |
| 3601 | |
| 3602 | int Reg = tryParseRegister(); |
| 3603 | if (Reg == -1) { |
| 3604 | Error(RegLoc, "register expected"); |
| 3605 | return MatchOperand_ParseFail; |
| 3606 | } |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3607 | unsigned Count = 1; |
Jim Grosbach | c2f16a3 | 2011-12-15 21:54:55 +0000 | [diff] [blame] | 3608 | int Spacing = 0; |
Jim Grosbach | 080a499 | 2011-10-28 00:06:50 +0000 | [diff] [blame] | 3609 | unsigned FirstReg = Reg; |
| 3610 | // The list is of D registers, but we also allow Q regs and just interpret |
| 3611 | // them as the two D sub-registers. |
| 3612 | if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) { |
| 3613 | FirstReg = Reg = getDRegFromQReg(Reg); |
Jim Grosbach | 2f50e92 | 2011-12-15 21:44:33 +0000 | [diff] [blame] | 3614 | Spacing = 1; // double-spacing requires explicit D registers, otherwise |
| 3615 | // it's ambiguous with four-register single spaced. |
Jim Grosbach | 080a499 | 2011-10-28 00:06:50 +0000 | [diff] [blame] | 3616 | ++Reg; |
| 3617 | ++Count; |
| 3618 | } |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3619 | |
| 3620 | SMLoc E; |
| 3621 | if (parseVectorLane(LaneKind, LaneIndex, E) != MatchOperand_Success) |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3622 | return MatchOperand_ParseFail; |
Jim Grosbach | 080a499 | 2011-10-28 00:06:50 +0000 | [diff] [blame] | 3623 | |
Jim Grosbach | e891fe8 | 2011-11-15 23:19:15 +0000 | [diff] [blame] | 3624 | while (Parser.getTok().is(AsmToken::Comma) || |
| 3625 | Parser.getTok().is(AsmToken::Minus)) { |
| 3626 | if (Parser.getTok().is(AsmToken::Minus)) { |
Jim Grosbach | 2f50e92 | 2011-12-15 21:44:33 +0000 | [diff] [blame] | 3627 | if (!Spacing) |
| 3628 | Spacing = 1; // Register range implies a single spaced list. |
| 3629 | else if (Spacing == 2) { |
| 3630 | Error(Parser.getTok().getLoc(), |
| 3631 | "sequential registers in double spaced list"); |
| 3632 | return MatchOperand_ParseFail; |
| 3633 | } |
Jim Grosbach | e891fe8 | 2011-11-15 23:19:15 +0000 | [diff] [blame] | 3634 | Parser.Lex(); // Eat the minus. |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3635 | SMLoc AfterMinusLoc = Parser.getTok().getLoc(); |
Jim Grosbach | e891fe8 | 2011-11-15 23:19:15 +0000 | [diff] [blame] | 3636 | int EndReg = tryParseRegister(); |
| 3637 | if (EndReg == -1) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3638 | Error(AfterMinusLoc, "register expected"); |
Jim Grosbach | e891fe8 | 2011-11-15 23:19:15 +0000 | [diff] [blame] | 3639 | return MatchOperand_ParseFail; |
| 3640 | } |
| 3641 | // Allow Q regs and just interpret them as the two D sub-registers. |
| 3642 | if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(EndReg)) |
| 3643 | EndReg = getDRegFromQReg(EndReg) + 1; |
| 3644 | // If the register is the same as the start reg, there's nothing |
| 3645 | // more to do. |
| 3646 | if (Reg == EndReg) |
| 3647 | continue; |
| 3648 | // The register must be in the same register class as the first. |
| 3649 | if (!ARMMCRegisterClasses[ARM::DPRRegClassID].contains(EndReg)) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3650 | Error(AfterMinusLoc, "invalid register in register list"); |
Jim Grosbach | e891fe8 | 2011-11-15 23:19:15 +0000 | [diff] [blame] | 3651 | return MatchOperand_ParseFail; |
| 3652 | } |
| 3653 | // Ranges must go from low to high. |
| 3654 | if (Reg > EndReg) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3655 | Error(AfterMinusLoc, "bad range in register list"); |
Jim Grosbach | e891fe8 | 2011-11-15 23:19:15 +0000 | [diff] [blame] | 3656 | return MatchOperand_ParseFail; |
| 3657 | } |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3658 | // Parse the lane specifier if present. |
| 3659 | VectorLaneTy NextLaneKind; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3660 | unsigned NextLaneIndex; |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3661 | if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != |
| 3662 | MatchOperand_Success) |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3663 | return MatchOperand_ParseFail; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3664 | if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3665 | Error(AfterMinusLoc, "mismatched lane index in register list"); |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3666 | return MatchOperand_ParseFail; |
| 3667 | } |
Jim Grosbach | e891fe8 | 2011-11-15 23:19:15 +0000 | [diff] [blame] | 3668 | |
| 3669 | // Add all the registers in the range to the register list. |
| 3670 | Count += EndReg - Reg; |
| 3671 | Reg = EndReg; |
| 3672 | continue; |
| 3673 | } |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3674 | Parser.Lex(); // Eat the comma. |
| 3675 | RegLoc = Parser.getTok().getLoc(); |
| 3676 | int OldReg = Reg; |
| 3677 | Reg = tryParseRegister(); |
| 3678 | if (Reg == -1) { |
| 3679 | Error(RegLoc, "register expected"); |
| 3680 | return MatchOperand_ParseFail; |
| 3681 | } |
Jim Grosbach | 080a499 | 2011-10-28 00:06:50 +0000 | [diff] [blame] | 3682 | // vector register lists must be contiguous. |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3683 | // It's OK to use the enumeration values directly here rather, as the |
| 3684 | // VFP register classes have the enum sorted properly. |
Jim Grosbach | 080a499 | 2011-10-28 00:06:50 +0000 | [diff] [blame] | 3685 | // |
| 3686 | // The list is of D registers, but we also allow Q regs and just interpret |
| 3687 | // them as the two D sub-registers. |
| 3688 | if (ARMMCRegisterClasses[ARM::QPRRegClassID].contains(Reg)) { |
Jim Grosbach | 2f50e92 | 2011-12-15 21:44:33 +0000 | [diff] [blame] | 3689 | if (!Spacing) |
| 3690 | Spacing = 1; // Register range implies a single spaced list. |
| 3691 | else if (Spacing == 2) { |
| 3692 | Error(RegLoc, |
| 3693 | "invalid register in double-spaced list (must be 'D' register')"); |
| 3694 | return MatchOperand_ParseFail; |
| 3695 | } |
Jim Grosbach | 080a499 | 2011-10-28 00:06:50 +0000 | [diff] [blame] | 3696 | Reg = getDRegFromQReg(Reg); |
| 3697 | if (Reg != OldReg + 1) { |
| 3698 | Error(RegLoc, "non-contiguous register range"); |
| 3699 | return MatchOperand_ParseFail; |
| 3700 | } |
| 3701 | ++Reg; |
| 3702 | Count += 2; |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3703 | // Parse the lane specifier if present. |
| 3704 | VectorLaneTy NextLaneKind; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3705 | unsigned NextLaneIndex; |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3706 | SMLoc LaneLoc = Parser.getTok().getLoc(); |
| 3707 | if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != |
| 3708 | MatchOperand_Success) |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3709 | return MatchOperand_ParseFail; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3710 | if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3711 | Error(LaneLoc, "mismatched lane index in register list"); |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3712 | return MatchOperand_ParseFail; |
| 3713 | } |
Jim Grosbach | 080a499 | 2011-10-28 00:06:50 +0000 | [diff] [blame] | 3714 | continue; |
| 3715 | } |
Jim Grosbach | 2f50e92 | 2011-12-15 21:44:33 +0000 | [diff] [blame] | 3716 | // Normal D register. |
| 3717 | // Figure out the register spacing (single or double) of the list if |
| 3718 | // we don't know it already. |
| 3719 | if (!Spacing) |
| 3720 | Spacing = 1 + (Reg == OldReg + 2); |
| 3721 | |
| 3722 | // Just check that it's contiguous and keep going. |
| 3723 | if (Reg != OldReg + Spacing) { |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3724 | Error(RegLoc, "non-contiguous register range"); |
| 3725 | return MatchOperand_ParseFail; |
| 3726 | } |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3727 | ++Count; |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3728 | // Parse the lane specifier if present. |
| 3729 | VectorLaneTy NextLaneKind; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3730 | unsigned NextLaneIndex; |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3731 | SMLoc EndLoc = Parser.getTok().getLoc(); |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3732 | if (parseVectorLane(NextLaneKind, NextLaneIndex, E) != MatchOperand_Success) |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3733 | return MatchOperand_ParseFail; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3734 | if (NextLaneKind != LaneKind || LaneIndex != NextLaneIndex) { |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3735 | Error(EndLoc, "mismatched lane index in register list"); |
| 3736 | return MatchOperand_ParseFail; |
| 3737 | } |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3738 | } |
| 3739 | |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3740 | if (Parser.getTok().isNot(AsmToken::RCurly)) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3741 | Error(Parser.getTok().getLoc(), "'}' expected"); |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3742 | return MatchOperand_ParseFail; |
| 3743 | } |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 3744 | E = Parser.getTok().getEndLoc(); |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3745 | Parser.Lex(); // Eat '}' token. |
| 3746 | |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3747 | switch (LaneKind) { |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3748 | case NoLanes: |
Jim Grosbach | 13a292c | 2012-03-06 22:01:44 +0000 | [diff] [blame] | 3749 | // Two-register operands have been converted to the |
Jim Grosbach | e5307f9 | 2012-03-05 21:43:40 +0000 | [diff] [blame] | 3750 | // composite register classes. |
| 3751 | if (Count == 2) { |
| 3752 | const MCRegisterClass *RC = (Spacing == 1) ? |
| 3753 | &ARMMCRegisterClasses[ARM::DPairRegClassID] : |
| 3754 | &ARMMCRegisterClasses[ARM::DPairSpcRegClassID]; |
| 3755 | FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC); |
| 3756 | } |
Jim Grosbach | c988e0c | 2012-03-05 19:33:30 +0000 | [diff] [blame] | 3757 | |
Jim Grosbach | 2f50e92 | 2011-12-15 21:44:33 +0000 | [diff] [blame] | 3758 | Operands.push_back(ARMOperand::CreateVectorList(FirstReg, Count, |
| 3759 | (Spacing == 2), S, E)); |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3760 | break; |
| 3761 | case AllLanes: |
Jim Grosbach | 13a292c | 2012-03-06 22:01:44 +0000 | [diff] [blame] | 3762 | // Two-register operands have been converted to the |
| 3763 | // composite register classes. |
Jim Grosbach | ed428bc | 2012-03-06 23:10:38 +0000 | [diff] [blame] | 3764 | if (Count == 2) { |
| 3765 | const MCRegisterClass *RC = (Spacing == 1) ? |
| 3766 | &ARMMCRegisterClasses[ARM::DPairRegClassID] : |
| 3767 | &ARMMCRegisterClasses[ARM::DPairSpcRegClassID]; |
Jim Grosbach | 13a292c | 2012-03-06 22:01:44 +0000 | [diff] [blame] | 3768 | FirstReg = MRI->getMatchingSuperReg(FirstReg, ARM::dsub_0, RC); |
| 3769 | } |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3770 | Operands.push_back(ARMOperand::CreateVectorListAllLanes(FirstReg, Count, |
Jim Grosbach | c5af54e | 2011-12-21 00:38:54 +0000 | [diff] [blame] | 3771 | (Spacing == 2), |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3772 | S, E)); |
| 3773 | break; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3774 | case IndexedLane: |
| 3775 | Operands.push_back(ARMOperand::CreateVectorListIndexed(FirstReg, Count, |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 3776 | LaneIndex, |
| 3777 | (Spacing == 2), |
| 3778 | S, E)); |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 3779 | break; |
Jim Grosbach | cd6f5e7 | 2011-11-30 01:09:44 +0000 | [diff] [blame] | 3780 | } |
Jim Grosbach | ad47cfc | 2011-10-18 23:02:30 +0000 | [diff] [blame] | 3781 | return MatchOperand_Success; |
| 3782 | } |
| 3783 | |
Jim Grosbach | 2d6ef44 | 2011-07-25 20:14:50 +0000 | [diff] [blame] | 3784 | /// parseMemBarrierOptOperand - Try to parse DSB/DMB data barrier options. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 3785 | ARMAsmParser::OperandMatchResultTy |
| 3786 | ARMAsmParser::parseMemBarrierOptOperand(OperandVector &Operands) { |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 3787 | SMLoc S = Parser.getTok().getLoc(); |
| 3788 | const AsmToken &Tok = Parser.getTok(); |
Jiangning Liu | 288e1af | 2012-08-02 08:21:27 +0000 | [diff] [blame] | 3789 | unsigned Opt; |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 3790 | |
Jiangning Liu | 288e1af | 2012-08-02 08:21:27 +0000 | [diff] [blame] | 3791 | if (Tok.is(AsmToken::Identifier)) { |
| 3792 | StringRef OptStr = Tok.getString(); |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 3793 | |
Jiangning Liu | 288e1af | 2012-08-02 08:21:27 +0000 | [diff] [blame] | 3794 | Opt = StringSwitch<unsigned>(OptStr.slice(0, OptStr.size()).lower()) |
| 3795 | .Case("sy", ARM_MB::SY) |
| 3796 | .Case("st", ARM_MB::ST) |
Joey Gouly | 926d3f5 | 2013-09-05 15:35:24 +0000 | [diff] [blame] | 3797 | .Case("ld", ARM_MB::LD) |
Jiangning Liu | 288e1af | 2012-08-02 08:21:27 +0000 | [diff] [blame] | 3798 | .Case("sh", ARM_MB::ISH) |
| 3799 | .Case("ish", ARM_MB::ISH) |
| 3800 | .Case("shst", ARM_MB::ISHST) |
| 3801 | .Case("ishst", ARM_MB::ISHST) |
Joey Gouly | 926d3f5 | 2013-09-05 15:35:24 +0000 | [diff] [blame] | 3802 | .Case("ishld", ARM_MB::ISHLD) |
Jiangning Liu | 288e1af | 2012-08-02 08:21:27 +0000 | [diff] [blame] | 3803 | .Case("nsh", ARM_MB::NSH) |
| 3804 | .Case("un", ARM_MB::NSH) |
| 3805 | .Case("nshst", ARM_MB::NSHST) |
Joey Gouly | 926d3f5 | 2013-09-05 15:35:24 +0000 | [diff] [blame] | 3806 | .Case("nshld", ARM_MB::NSHLD) |
Jiangning Liu | 288e1af | 2012-08-02 08:21:27 +0000 | [diff] [blame] | 3807 | .Case("unst", ARM_MB::NSHST) |
| 3808 | .Case("osh", ARM_MB::OSH) |
| 3809 | .Case("oshst", ARM_MB::OSHST) |
Joey Gouly | 926d3f5 | 2013-09-05 15:35:24 +0000 | [diff] [blame] | 3810 | .Case("oshld", ARM_MB::OSHLD) |
Jiangning Liu | 288e1af | 2012-08-02 08:21:27 +0000 | [diff] [blame] | 3811 | .Default(~0U); |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 3812 | |
Joey Gouly | 926d3f5 | 2013-09-05 15:35:24 +0000 | [diff] [blame] | 3813 | // ishld, oshld, nshld and ld are only available from ARMv8. |
| 3814 | if (!hasV8Ops() && (Opt == ARM_MB::ISHLD || Opt == ARM_MB::OSHLD || |
| 3815 | Opt == ARM_MB::NSHLD || Opt == ARM_MB::LD)) |
| 3816 | Opt = ~0U; |
| 3817 | |
Jiangning Liu | 288e1af | 2012-08-02 08:21:27 +0000 | [diff] [blame] | 3818 | if (Opt == ~0U) |
| 3819 | return MatchOperand_NoMatch; |
| 3820 | |
| 3821 | Parser.Lex(); // Eat identifier token. |
| 3822 | } else if (Tok.is(AsmToken::Hash) || |
| 3823 | Tok.is(AsmToken::Dollar) || |
| 3824 | Tok.is(AsmToken::Integer)) { |
| 3825 | if (Parser.getTok().isNot(AsmToken::Integer)) |
Amaury de la Vieuville | bac917f | 2013-06-10 14:17:15 +0000 | [diff] [blame] | 3826 | Parser.Lex(); // Eat '#' or '$'. |
Jiangning Liu | 288e1af | 2012-08-02 08:21:27 +0000 | [diff] [blame] | 3827 | SMLoc Loc = Parser.getTok().getLoc(); |
| 3828 | |
| 3829 | const MCExpr *MemBarrierID; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 3830 | if (getParser().parseExpression(MemBarrierID)) { |
Jiangning Liu | 288e1af | 2012-08-02 08:21:27 +0000 | [diff] [blame] | 3831 | Error(Loc, "illegal expression"); |
| 3832 | return MatchOperand_ParseFail; |
| 3833 | } |
Saleem Abdulrasool | 4ab6e73 | 2014-02-23 17:45:36 +0000 | [diff] [blame] | 3834 | |
Jiangning Liu | 288e1af | 2012-08-02 08:21:27 +0000 | [diff] [blame] | 3835 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(MemBarrierID); |
| 3836 | if (!CE) { |
| 3837 | Error(Loc, "constant expression expected"); |
| 3838 | return MatchOperand_ParseFail; |
| 3839 | } |
| 3840 | |
| 3841 | int Val = CE->getValue(); |
| 3842 | if (Val & ~0xf) { |
| 3843 | Error(Loc, "immediate value out of range"); |
| 3844 | return MatchOperand_ParseFail; |
| 3845 | } |
| 3846 | |
| 3847 | Opt = ARM_MB::RESERVED_0 + Val; |
| 3848 | } else |
| 3849 | return MatchOperand_ParseFail; |
| 3850 | |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 3851 | Operands.push_back(ARMOperand::CreateMemBarrierOpt((ARM_MB::MemBOpt)Opt, S)); |
Jim Grosbach | 861e49c | 2011-02-12 01:34:40 +0000 | [diff] [blame] | 3852 | return MatchOperand_Success; |
Bruno Cardoso Lopes | 36dd43f | 2011-02-07 22:09:15 +0000 | [diff] [blame] | 3853 | } |
| 3854 | |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 3855 | /// parseInstSyncBarrierOptOperand - Try to parse ISB inst sync barrier options. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 3856 | ARMAsmParser::OperandMatchResultTy |
| 3857 | ARMAsmParser::parseInstSyncBarrierOptOperand(OperandVector &Operands) { |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 3858 | SMLoc S = Parser.getTok().getLoc(); |
| 3859 | const AsmToken &Tok = Parser.getTok(); |
| 3860 | unsigned Opt; |
| 3861 | |
| 3862 | if (Tok.is(AsmToken::Identifier)) { |
| 3863 | StringRef OptStr = Tok.getString(); |
| 3864 | |
Benjamin Kramer | 3e9237a | 2013-11-09 22:48:13 +0000 | [diff] [blame] | 3865 | if (OptStr.equals_lower("sy")) |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 3866 | Opt = ARM_ISB::SY; |
| 3867 | else |
| 3868 | return MatchOperand_NoMatch; |
| 3869 | |
| 3870 | Parser.Lex(); // Eat identifier token. |
| 3871 | } else if (Tok.is(AsmToken::Hash) || |
| 3872 | Tok.is(AsmToken::Dollar) || |
| 3873 | Tok.is(AsmToken::Integer)) { |
| 3874 | if (Parser.getTok().isNot(AsmToken::Integer)) |
Amaury de la Vieuville | bac917f | 2013-06-10 14:17:15 +0000 | [diff] [blame] | 3875 | Parser.Lex(); // Eat '#' or '$'. |
Amaury de la Vieuville | 43cb13a | 2013-06-10 14:17:08 +0000 | [diff] [blame] | 3876 | SMLoc Loc = Parser.getTok().getLoc(); |
| 3877 | |
| 3878 | const MCExpr *ISBarrierID; |
| 3879 | if (getParser().parseExpression(ISBarrierID)) { |
| 3880 | Error(Loc, "illegal expression"); |
| 3881 | return MatchOperand_ParseFail; |
| 3882 | } |
| 3883 | |
| 3884 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ISBarrierID); |
| 3885 | if (!CE) { |
| 3886 | Error(Loc, "constant expression expected"); |
| 3887 | return MatchOperand_ParseFail; |
| 3888 | } |
| 3889 | |
| 3890 | int Val = CE->getValue(); |
| 3891 | if (Val & ~0xf) { |
| 3892 | Error(Loc, "immediate value out of range"); |
| 3893 | return MatchOperand_ParseFail; |
| 3894 | } |
| 3895 | |
| 3896 | Opt = ARM_ISB::RESERVED_0 + Val; |
| 3897 | } else |
| 3898 | return MatchOperand_ParseFail; |
| 3899 | |
| 3900 | Operands.push_back(ARMOperand::CreateInstSyncBarrierOpt( |
| 3901 | (ARM_ISB::InstSyncBOpt)Opt, S)); |
| 3902 | return MatchOperand_Success; |
| 3903 | } |
| 3904 | |
| 3905 | |
Jim Grosbach | 2d6ef44 | 2011-07-25 20:14:50 +0000 | [diff] [blame] | 3906 | /// parseProcIFlagsOperand - Try to parse iflags from CPS instruction. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 3907 | ARMAsmParser::OperandMatchResultTy |
| 3908 | ARMAsmParser::parseProcIFlagsOperand(OperandVector &Operands) { |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 3909 | SMLoc S = Parser.getTok().getLoc(); |
| 3910 | const AsmToken &Tok = Parser.getTok(); |
Richard Barton | b0ec375 | 2012-06-14 10:48:04 +0000 | [diff] [blame] | 3911 | if (!Tok.is(AsmToken::Identifier)) |
| 3912 | return MatchOperand_NoMatch; |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 3913 | StringRef IFlagsStr = Tok.getString(); |
| 3914 | |
Owen Anderson | 10c5b12 | 2011-10-05 17:16:40 +0000 | [diff] [blame] | 3915 | // An iflags string of "none" is interpreted to mean that none of the AIF |
| 3916 | // 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] | 3917 | unsigned IFlags = 0; |
Owen Anderson | 10c5b12 | 2011-10-05 17:16:40 +0000 | [diff] [blame] | 3918 | if (IFlagsStr != "none") { |
| 3919 | for (int i = 0, e = IFlagsStr.size(); i != e; ++i) { |
| 3920 | unsigned Flag = StringSwitch<unsigned>(IFlagsStr.substr(i, 1)) |
| 3921 | .Case("a", ARM_PROC::A) |
| 3922 | .Case("i", ARM_PROC::I) |
| 3923 | .Case("f", ARM_PROC::F) |
| 3924 | .Default(~0U); |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 3925 | |
Owen Anderson | 10c5b12 | 2011-10-05 17:16:40 +0000 | [diff] [blame] | 3926 | // If some specific iflag is already set, it means that some letter is |
| 3927 | // present more than once, this is not acceptable. |
| 3928 | if (Flag == ~0U || (IFlags & Flag)) |
| 3929 | return MatchOperand_NoMatch; |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 3930 | |
Owen Anderson | 10c5b12 | 2011-10-05 17:16:40 +0000 | [diff] [blame] | 3931 | IFlags |= Flag; |
| 3932 | } |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 3933 | } |
| 3934 | |
| 3935 | Parser.Lex(); // Eat identifier token. |
| 3936 | Operands.push_back(ARMOperand::CreateProcIFlags((ARM_PROC::IFlags)IFlags, S)); |
| 3937 | return MatchOperand_Success; |
| 3938 | } |
| 3939 | |
Jim Grosbach | 2d6ef44 | 2011-07-25 20:14:50 +0000 | [diff] [blame] | 3940 | /// parseMSRMaskOperand - Try to parse mask flags from MSR instruction. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 3941 | ARMAsmParser::OperandMatchResultTy |
| 3942 | ARMAsmParser::parseMSRMaskOperand(OperandVector &Operands) { |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 3943 | SMLoc S = Parser.getTok().getLoc(); |
| 3944 | const AsmToken &Tok = Parser.getTok(); |
Craig Topper | a004b0d | 2012-10-09 04:55:28 +0000 | [diff] [blame] | 3945 | if (!Tok.is(AsmToken::Identifier)) |
| 3946 | return MatchOperand_NoMatch; |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 3947 | StringRef Mask = Tok.getString(); |
| 3948 | |
James Molloy | 21efa7d | 2011-09-28 14:21:38 +0000 | [diff] [blame] | 3949 | if (isMClass()) { |
| 3950 | // See ARMv6-M 10.1.1 |
Jim Grosbach | d28888d | 2012-03-15 21:34:14 +0000 | [diff] [blame] | 3951 | std::string Name = Mask.lower(); |
| 3952 | unsigned FlagsVal = StringSwitch<unsigned>(Name) |
Kevin Enderby | f1b225d | 2012-05-17 22:18:01 +0000 | [diff] [blame] | 3953 | // Note: in the documentation: |
| 3954 | // ARM deprecates using MSR APSR without a _<bits> qualifier as an alias |
| 3955 | // for MSR APSR_nzcvq. |
| 3956 | // but we do make it an alias here. This is so to get the "mask encoding" |
| 3957 | // bits correct on MSR APSR writes. |
| 3958 | // |
| 3959 | // FIXME: Note the 0xc00 "mask encoding" bits version of the registers |
| 3960 | // should really only be allowed when writing a special register. Note |
| 3961 | // they get dropped in the MRS instruction reading a special register as |
| 3962 | // the SYSm field is only 8 bits. |
Kevin Enderby | f1b225d | 2012-05-17 22:18:01 +0000 | [diff] [blame] | 3963 | .Case("apsr", 0x800) |
| 3964 | .Case("apsr_nzcvq", 0x800) |
| 3965 | .Case("apsr_g", 0x400) |
| 3966 | .Case("apsr_nzcvqg", 0xc00) |
| 3967 | .Case("iapsr", 0x801) |
| 3968 | .Case("iapsr_nzcvq", 0x801) |
| 3969 | .Case("iapsr_g", 0x401) |
| 3970 | .Case("iapsr_nzcvqg", 0xc01) |
| 3971 | .Case("eapsr", 0x802) |
| 3972 | .Case("eapsr_nzcvq", 0x802) |
| 3973 | .Case("eapsr_g", 0x402) |
| 3974 | .Case("eapsr_nzcvqg", 0xc02) |
| 3975 | .Case("xpsr", 0x803) |
| 3976 | .Case("xpsr_nzcvq", 0x803) |
| 3977 | .Case("xpsr_g", 0x403) |
| 3978 | .Case("xpsr_nzcvqg", 0xc03) |
Kevin Enderby | 6c7279e | 2012-06-15 22:14:44 +0000 | [diff] [blame] | 3979 | .Case("ipsr", 0x805) |
| 3980 | .Case("epsr", 0x806) |
| 3981 | .Case("iepsr", 0x807) |
| 3982 | .Case("msp", 0x808) |
| 3983 | .Case("psp", 0x809) |
| 3984 | .Case("primask", 0x810) |
| 3985 | .Case("basepri", 0x811) |
| 3986 | .Case("basepri_max", 0x812) |
| 3987 | .Case("faultmask", 0x813) |
| 3988 | .Case("control", 0x814) |
James Molloy | 21efa7d | 2011-09-28 14:21:38 +0000 | [diff] [blame] | 3989 | .Default(~0U); |
Jim Grosbach | 3794d82 | 2011-12-22 17:17:10 +0000 | [diff] [blame] | 3990 | |
James Molloy | 21efa7d | 2011-09-28 14:21:38 +0000 | [diff] [blame] | 3991 | if (FlagsVal == ~0U) |
| 3992 | return MatchOperand_NoMatch; |
| 3993 | |
Renato Golin | 92c816c | 2014-09-01 11:25:07 +0000 | [diff] [blame] | 3994 | if (!hasThumb2DSP() && (FlagsVal & 0x400)) |
| 3995 | // The _g and _nzcvqg versions are only valid if the DSP extension is |
| 3996 | // available. |
| 3997 | return MatchOperand_NoMatch; |
| 3998 | |
Kevin Enderby | 6c7279e | 2012-06-15 22:14:44 +0000 | [diff] [blame] | 3999 | if (!hasV7Ops() && FlagsVal >= 0x811 && FlagsVal <= 0x813) |
James Molloy | 21efa7d | 2011-09-28 14:21:38 +0000 | [diff] [blame] | 4000 | // basepri, basepri_max and faultmask only valid for V7m. |
| 4001 | return MatchOperand_NoMatch; |
Jim Grosbach | 3794d82 | 2011-12-22 17:17:10 +0000 | [diff] [blame] | 4002 | |
James Molloy | 21efa7d | 2011-09-28 14:21:38 +0000 | [diff] [blame] | 4003 | Parser.Lex(); // Eat identifier token. |
| 4004 | Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S)); |
| 4005 | return MatchOperand_Success; |
| 4006 | } |
| 4007 | |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 4008 | // Split spec_reg from flag, example: CPSR_sxf => "CPSR" and "sxf" |
| 4009 | size_t Start = 0, Next = Mask.find('_'); |
| 4010 | StringRef Flags = ""; |
Benjamin Kramer | 20baffb | 2011-11-06 20:37:06 +0000 | [diff] [blame] | 4011 | std::string SpecReg = Mask.slice(Start, Next).lower(); |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 4012 | if (Next != StringRef::npos) |
| 4013 | Flags = Mask.slice(Next+1, Mask.size()); |
| 4014 | |
| 4015 | // FlagsVal contains the complete mask: |
| 4016 | // 3-0: Mask |
| 4017 | // 4: Special Reg (cpsr, apsr => 0; spsr => 1) |
| 4018 | unsigned FlagsVal = 0; |
| 4019 | |
| 4020 | if (SpecReg == "apsr") { |
| 4021 | FlagsVal = StringSwitch<unsigned>(Flags) |
Jim Grosbach | d25c2cd | 2011-07-19 22:45:10 +0000 | [diff] [blame] | 4022 | .Case("nzcvq", 0x8) // same as CPSR_f |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 4023 | .Case("g", 0x4) // same as CPSR_s |
| 4024 | .Case("nzcvqg", 0xc) // same as CPSR_fs |
| 4025 | .Default(~0U); |
| 4026 | |
Joerg Sonnenberger | 740467a | 2011-02-19 00:43:45 +0000 | [diff] [blame] | 4027 | if (FlagsVal == ~0U) { |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 4028 | if (!Flags.empty()) |
| 4029 | return MatchOperand_NoMatch; |
| 4030 | else |
Jim Grosbach | 0ecd395 | 2011-09-14 20:03:46 +0000 | [diff] [blame] | 4031 | FlagsVal = 8; // No flag |
Joerg Sonnenberger | 740467a | 2011-02-19 00:43:45 +0000 | [diff] [blame] | 4032 | } |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 4033 | } else if (SpecReg == "cpsr" || SpecReg == "spsr") { |
Jim Grosbach | 3d00eec | 2012-04-05 03:17:53 +0000 | [diff] [blame] | 4034 | // cpsr_all is an alias for cpsr_fc, as is plain cpsr. |
| 4035 | if (Flags == "all" || Flags == "") |
Bruno Cardoso Lopes | 5445213 | 2011-05-25 00:35:03 +0000 | [diff] [blame] | 4036 | Flags = "fc"; |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 4037 | for (int i = 0, e = Flags.size(); i != e; ++i) { |
| 4038 | unsigned Flag = StringSwitch<unsigned>(Flags.substr(i, 1)) |
| 4039 | .Case("c", 1) |
| 4040 | .Case("x", 2) |
| 4041 | .Case("s", 4) |
| 4042 | .Case("f", 8) |
| 4043 | .Default(~0U); |
| 4044 | |
| 4045 | // If some specific flag is already set, it means that some letter is |
| 4046 | // present more than once, this is not acceptable. |
| 4047 | if (FlagsVal == ~0U || (FlagsVal & Flag)) |
| 4048 | return MatchOperand_NoMatch; |
| 4049 | FlagsVal |= Flag; |
| 4050 | } |
| 4051 | } else // No match for special register. |
| 4052 | return MatchOperand_NoMatch; |
| 4053 | |
Owen Anderson | 03a173e | 2011-10-21 18:43:28 +0000 | [diff] [blame] | 4054 | // Special register without flags is NOT equivalent to "fc" flags. |
| 4055 | // NOTE: This is a divergence from gas' behavior. Uncommenting the following |
| 4056 | // two lines would enable gas compatibility at the expense of breaking |
| 4057 | // round-tripping. |
| 4058 | // |
| 4059 | // if (!FlagsVal) |
| 4060 | // FlagsVal = 0x9; |
Bruno Cardoso Lopes | 9cd4397 | 2011-02-18 19:45:59 +0000 | [diff] [blame] | 4061 | |
| 4062 | // Bit 4: Special Reg (cpsr, apsr => 0; spsr => 1) |
| 4063 | if (SpecReg == "spsr") |
| 4064 | FlagsVal |= 16; |
| 4065 | |
| 4066 | Parser.Lex(); // Eat identifier token. |
| 4067 | Operands.push_back(ARMOperand::CreateMSRMask(FlagsVal, S)); |
| 4068 | return MatchOperand_Success; |
| 4069 | } |
| 4070 | |
Tim Northover | ee843ef | 2014-08-15 10:47:12 +0000 | [diff] [blame] | 4071 | /// parseBankedRegOperand - Try to parse a banked register (e.g. "lr_irq") for |
| 4072 | /// use in the MRS/MSR instructions added to support virtualization. |
| 4073 | ARMAsmParser::OperandMatchResultTy |
| 4074 | ARMAsmParser::parseBankedRegOperand(OperandVector &Operands) { |
| 4075 | SMLoc S = Parser.getTok().getLoc(); |
| 4076 | const AsmToken &Tok = Parser.getTok(); |
| 4077 | if (!Tok.is(AsmToken::Identifier)) |
| 4078 | return MatchOperand_NoMatch; |
| 4079 | StringRef RegName = Tok.getString(); |
| 4080 | |
| 4081 | // The values here come from B9.2.3 of the ARM ARM, where bits 4-0 are SysM |
| 4082 | // and bit 5 is R. |
| 4083 | unsigned Encoding = StringSwitch<unsigned>(RegName.lower()) |
| 4084 | .Case("r8_usr", 0x00) |
| 4085 | .Case("r9_usr", 0x01) |
| 4086 | .Case("r10_usr", 0x02) |
| 4087 | .Case("r11_usr", 0x03) |
| 4088 | .Case("r12_usr", 0x04) |
| 4089 | .Case("sp_usr", 0x05) |
| 4090 | .Case("lr_usr", 0x06) |
| 4091 | .Case("r8_fiq", 0x08) |
| 4092 | .Case("r9_fiq", 0x09) |
| 4093 | .Case("r10_fiq", 0x0a) |
| 4094 | .Case("r11_fiq", 0x0b) |
| 4095 | .Case("r12_fiq", 0x0c) |
| 4096 | .Case("sp_fiq", 0x0d) |
| 4097 | .Case("lr_fiq", 0x0e) |
| 4098 | .Case("lr_irq", 0x10) |
| 4099 | .Case("sp_irq", 0x11) |
| 4100 | .Case("lr_svc", 0x12) |
| 4101 | .Case("sp_svc", 0x13) |
| 4102 | .Case("lr_abt", 0x14) |
| 4103 | .Case("sp_abt", 0x15) |
| 4104 | .Case("lr_und", 0x16) |
| 4105 | .Case("sp_und", 0x17) |
| 4106 | .Case("lr_mon", 0x1c) |
| 4107 | .Case("sp_mon", 0x1d) |
| 4108 | .Case("elr_hyp", 0x1e) |
| 4109 | .Case("sp_hyp", 0x1f) |
| 4110 | .Case("spsr_fiq", 0x2e) |
| 4111 | .Case("spsr_irq", 0x30) |
| 4112 | .Case("spsr_svc", 0x32) |
| 4113 | .Case("spsr_abt", 0x34) |
| 4114 | .Case("spsr_und", 0x36) |
| 4115 | .Case("spsr_mon", 0x3c) |
| 4116 | .Case("spsr_hyp", 0x3e) |
| 4117 | .Default(~0U); |
| 4118 | |
| 4119 | if (Encoding == ~0U) |
| 4120 | return MatchOperand_NoMatch; |
| 4121 | |
| 4122 | Parser.Lex(); // Eat identifier token. |
| 4123 | Operands.push_back(ARMOperand::CreateBankedReg(Encoding, S)); |
| 4124 | return MatchOperand_Success; |
| 4125 | } |
| 4126 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4127 | ARMAsmParser::OperandMatchResultTy |
| 4128 | ARMAsmParser::parsePKHImm(OperandVector &Operands, StringRef Op, int Low, |
| 4129 | int High) { |
Jim Grosbach | 27c1e25 | 2011-07-21 17:23:04 +0000 | [diff] [blame] | 4130 | const AsmToken &Tok = Parser.getTok(); |
| 4131 | if (Tok.isNot(AsmToken::Identifier)) { |
| 4132 | Error(Parser.getTok().getLoc(), Op + " operand expected."); |
| 4133 | return MatchOperand_ParseFail; |
| 4134 | } |
| 4135 | StringRef ShiftName = Tok.getString(); |
Benjamin Kramer | 20baffb | 2011-11-06 20:37:06 +0000 | [diff] [blame] | 4136 | std::string LowerOp = Op.lower(); |
| 4137 | std::string UpperOp = Op.upper(); |
Jim Grosbach | 27c1e25 | 2011-07-21 17:23:04 +0000 | [diff] [blame] | 4138 | if (ShiftName != LowerOp && ShiftName != UpperOp) { |
| 4139 | Error(Parser.getTok().getLoc(), Op + " operand expected."); |
| 4140 | return MatchOperand_ParseFail; |
| 4141 | } |
| 4142 | Parser.Lex(); // Eat shift type token. |
| 4143 | |
| 4144 | // There must be a '#' and a shift amount. |
Jim Grosbach | ef70e9b | 2011-12-09 22:25:03 +0000 | [diff] [blame] | 4145 | if (Parser.getTok().isNot(AsmToken::Hash) && |
| 4146 | Parser.getTok().isNot(AsmToken::Dollar)) { |
Jim Grosbach | 27c1e25 | 2011-07-21 17:23:04 +0000 | [diff] [blame] | 4147 | Error(Parser.getTok().getLoc(), "'#' expected"); |
| 4148 | return MatchOperand_ParseFail; |
| 4149 | } |
| 4150 | Parser.Lex(); // Eat hash token. |
| 4151 | |
| 4152 | const MCExpr *ShiftAmount; |
| 4153 | SMLoc Loc = Parser.getTok().getLoc(); |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4154 | SMLoc EndLoc; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 4155 | if (getParser().parseExpression(ShiftAmount, EndLoc)) { |
Jim Grosbach | 27c1e25 | 2011-07-21 17:23:04 +0000 | [diff] [blame] | 4156 | Error(Loc, "illegal expression"); |
| 4157 | return MatchOperand_ParseFail; |
| 4158 | } |
| 4159 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount); |
| 4160 | if (!CE) { |
| 4161 | Error(Loc, "constant expression expected"); |
| 4162 | return MatchOperand_ParseFail; |
| 4163 | } |
| 4164 | int Val = CE->getValue(); |
| 4165 | if (Val < Low || Val > High) { |
| 4166 | Error(Loc, "immediate value out of range"); |
| 4167 | return MatchOperand_ParseFail; |
| 4168 | } |
| 4169 | |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4170 | Operands.push_back(ARMOperand::CreateImm(CE, Loc, EndLoc)); |
Jim Grosbach | 27c1e25 | 2011-07-21 17:23:04 +0000 | [diff] [blame] | 4171 | |
| 4172 | return MatchOperand_Success; |
| 4173 | } |
| 4174 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4175 | ARMAsmParser::OperandMatchResultTy |
| 4176 | ARMAsmParser::parseSetEndImm(OperandVector &Operands) { |
Jim Grosbach | 0a54770 | 2011-07-22 17:44:50 +0000 | [diff] [blame] | 4177 | const AsmToken &Tok = Parser.getTok(); |
| 4178 | SMLoc S = Tok.getLoc(); |
| 4179 | if (Tok.isNot(AsmToken::Identifier)) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4180 | Error(S, "'be' or 'le' operand expected"); |
Jim Grosbach | 0a54770 | 2011-07-22 17:44:50 +0000 | [diff] [blame] | 4181 | return MatchOperand_ParseFail; |
| 4182 | } |
Tim Northover | 4d14144 | 2013-05-31 15:58:45 +0000 | [diff] [blame] | 4183 | int Val = StringSwitch<int>(Tok.getString().lower()) |
Jim Grosbach | 0a54770 | 2011-07-22 17:44:50 +0000 | [diff] [blame] | 4184 | .Case("be", 1) |
| 4185 | .Case("le", 0) |
| 4186 | .Default(-1); |
| 4187 | Parser.Lex(); // Eat the token. |
| 4188 | |
| 4189 | if (Val == -1) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4190 | Error(S, "'be' or 'le' operand expected"); |
Jim Grosbach | 0a54770 | 2011-07-22 17:44:50 +0000 | [diff] [blame] | 4191 | return MatchOperand_ParseFail; |
| 4192 | } |
| 4193 | Operands.push_back(ARMOperand::CreateImm(MCConstantExpr::Create(Val, |
| 4194 | getContext()), |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4195 | S, Tok.getEndLoc())); |
Jim Grosbach | 0a54770 | 2011-07-22 17:44:50 +0000 | [diff] [blame] | 4196 | return MatchOperand_Success; |
| 4197 | } |
| 4198 | |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 4199 | /// parseShifterImm - Parse the shifter immediate operand for SSAT/USAT |
| 4200 | /// instructions. Legal values are: |
| 4201 | /// lsl #n 'n' in [0,31] |
| 4202 | /// asr #n 'n' in [1,32] |
| 4203 | /// n == 32 encoded as n == 0. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4204 | ARMAsmParser::OperandMatchResultTy |
| 4205 | ARMAsmParser::parseShifterImm(OperandVector &Operands) { |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 4206 | const AsmToken &Tok = Parser.getTok(); |
| 4207 | SMLoc S = Tok.getLoc(); |
| 4208 | if (Tok.isNot(AsmToken::Identifier)) { |
| 4209 | Error(S, "shift operator 'asr' or 'lsl' expected"); |
| 4210 | return MatchOperand_ParseFail; |
| 4211 | } |
| 4212 | StringRef ShiftName = Tok.getString(); |
| 4213 | bool isASR; |
| 4214 | if (ShiftName == "lsl" || ShiftName == "LSL") |
| 4215 | isASR = false; |
| 4216 | else if (ShiftName == "asr" || ShiftName == "ASR") |
| 4217 | isASR = true; |
| 4218 | else { |
| 4219 | Error(S, "shift operator 'asr' or 'lsl' expected"); |
| 4220 | return MatchOperand_ParseFail; |
| 4221 | } |
| 4222 | Parser.Lex(); // Eat the operator. |
| 4223 | |
| 4224 | // A '#' and a shift amount. |
Jim Grosbach | ef70e9b | 2011-12-09 22:25:03 +0000 | [diff] [blame] | 4225 | if (Parser.getTok().isNot(AsmToken::Hash) && |
| 4226 | Parser.getTok().isNot(AsmToken::Dollar)) { |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 4227 | Error(Parser.getTok().getLoc(), "'#' expected"); |
| 4228 | return MatchOperand_ParseFail; |
| 4229 | } |
| 4230 | Parser.Lex(); // Eat hash token. |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4231 | SMLoc ExLoc = Parser.getTok().getLoc(); |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 4232 | |
| 4233 | const MCExpr *ShiftAmount; |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4234 | SMLoc EndLoc; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 4235 | if (getParser().parseExpression(ShiftAmount, EndLoc)) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4236 | Error(ExLoc, "malformed shift expression"); |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 4237 | return MatchOperand_ParseFail; |
| 4238 | } |
| 4239 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount); |
| 4240 | if (!CE) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4241 | Error(ExLoc, "shift amount must be an immediate"); |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 4242 | return MatchOperand_ParseFail; |
| 4243 | } |
| 4244 | |
| 4245 | int64_t Val = CE->getValue(); |
| 4246 | if (isASR) { |
| 4247 | // Shift amount must be in [1,32] |
| 4248 | if (Val < 1 || Val > 32) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4249 | Error(ExLoc, "'asr' shift amount must be in range [1,32]"); |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 4250 | return MatchOperand_ParseFail; |
| 4251 | } |
Owen Anderson | f01e2de | 2011-09-26 21:06:22 +0000 | [diff] [blame] | 4252 | // asr #32 encoded as asr #0, but is not allowed in Thumb2 mode. |
| 4253 | if (isThumb() && Val == 32) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4254 | Error(ExLoc, "'asr #32' shift amount not allowed in Thumb mode"); |
Owen Anderson | f01e2de | 2011-09-26 21:06:22 +0000 | [diff] [blame] | 4255 | return MatchOperand_ParseFail; |
| 4256 | } |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 4257 | if (Val == 32) Val = 0; |
| 4258 | } else { |
| 4259 | // Shift amount must be in [1,32] |
| 4260 | if (Val < 0 || Val > 31) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4261 | Error(ExLoc, "'lsr' shift amount must be in range [0,31]"); |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 4262 | return MatchOperand_ParseFail; |
| 4263 | } |
| 4264 | } |
| 4265 | |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4266 | Operands.push_back(ARMOperand::CreateShifterImm(isASR, Val, S, EndLoc)); |
Jim Grosbach | 3a9cbee | 2011-07-25 22:20:28 +0000 | [diff] [blame] | 4267 | |
| 4268 | return MatchOperand_Success; |
| 4269 | } |
| 4270 | |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 4271 | /// parseRotImm - Parse the shifter immediate operand for SXTB/UXTB family |
| 4272 | /// of instructions. Legal values are: |
| 4273 | /// ror #n 'n' in {0, 8, 16, 24} |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4274 | ARMAsmParser::OperandMatchResultTy |
| 4275 | ARMAsmParser::parseRotImm(OperandVector &Operands) { |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 4276 | const AsmToken &Tok = Parser.getTok(); |
| 4277 | SMLoc S = Tok.getLoc(); |
Jim Grosbach | 8221319 | 2011-09-19 20:29:33 +0000 | [diff] [blame] | 4278 | if (Tok.isNot(AsmToken::Identifier)) |
| 4279 | return MatchOperand_NoMatch; |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 4280 | StringRef ShiftName = Tok.getString(); |
Jim Grosbach | 8221319 | 2011-09-19 20:29:33 +0000 | [diff] [blame] | 4281 | if (ShiftName != "ror" && ShiftName != "ROR") |
| 4282 | return MatchOperand_NoMatch; |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 4283 | Parser.Lex(); // Eat the operator. |
| 4284 | |
| 4285 | // A '#' and a rotate amount. |
Jim Grosbach | ef70e9b | 2011-12-09 22:25:03 +0000 | [diff] [blame] | 4286 | if (Parser.getTok().isNot(AsmToken::Hash) && |
| 4287 | Parser.getTok().isNot(AsmToken::Dollar)) { |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 4288 | Error(Parser.getTok().getLoc(), "'#' expected"); |
| 4289 | return MatchOperand_ParseFail; |
| 4290 | } |
| 4291 | Parser.Lex(); // Eat hash token. |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4292 | SMLoc ExLoc = Parser.getTok().getLoc(); |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 4293 | |
| 4294 | const MCExpr *ShiftAmount; |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4295 | SMLoc EndLoc; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 4296 | if (getParser().parseExpression(ShiftAmount, EndLoc)) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4297 | Error(ExLoc, "malformed rotate expression"); |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 4298 | return MatchOperand_ParseFail; |
| 4299 | } |
| 4300 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ShiftAmount); |
| 4301 | if (!CE) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4302 | Error(ExLoc, "rotate amount must be an immediate"); |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 4303 | return MatchOperand_ParseFail; |
| 4304 | } |
| 4305 | |
| 4306 | int64_t Val = CE->getValue(); |
| 4307 | // Shift amount must be in {0, 8, 16, 24} (0 is undocumented extension) |
| 4308 | // normally, zero is represented in asm by omitting the rotate operand |
| 4309 | // entirely. |
| 4310 | if (Val != 8 && Val != 16 && Val != 24 && Val != 0) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4311 | Error(ExLoc, "'ror' rotate amount must be 8, 16, or 24"); |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 4312 | return MatchOperand_ParseFail; |
| 4313 | } |
| 4314 | |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4315 | Operands.push_back(ARMOperand::CreateRotImm(Val, S, EndLoc)); |
Jim Grosbach | 833b9d3 | 2011-07-27 20:15:40 +0000 | [diff] [blame] | 4316 | |
| 4317 | return MatchOperand_Success; |
| 4318 | } |
| 4319 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4320 | ARMAsmParser::OperandMatchResultTy |
| 4321 | ARMAsmParser::parseBitfield(OperandVector &Operands) { |
Jim Grosbach | 864b609 | 2011-07-28 21:34:26 +0000 | [diff] [blame] | 4322 | SMLoc S = Parser.getTok().getLoc(); |
| 4323 | // The bitfield descriptor is really two operands, the LSB and the width. |
Jim Grosbach | ef70e9b | 2011-12-09 22:25:03 +0000 | [diff] [blame] | 4324 | if (Parser.getTok().isNot(AsmToken::Hash) && |
| 4325 | Parser.getTok().isNot(AsmToken::Dollar)) { |
Jim Grosbach | 864b609 | 2011-07-28 21:34:26 +0000 | [diff] [blame] | 4326 | Error(Parser.getTok().getLoc(), "'#' expected"); |
| 4327 | return MatchOperand_ParseFail; |
| 4328 | } |
| 4329 | Parser.Lex(); // Eat hash token. |
| 4330 | |
| 4331 | const MCExpr *LSBExpr; |
| 4332 | SMLoc E = Parser.getTok().getLoc(); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 4333 | if (getParser().parseExpression(LSBExpr)) { |
Jim Grosbach | 864b609 | 2011-07-28 21:34:26 +0000 | [diff] [blame] | 4334 | Error(E, "malformed immediate expression"); |
| 4335 | return MatchOperand_ParseFail; |
| 4336 | } |
| 4337 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(LSBExpr); |
| 4338 | if (!CE) { |
| 4339 | Error(E, "'lsb' operand must be an immediate"); |
| 4340 | return MatchOperand_ParseFail; |
| 4341 | } |
| 4342 | |
| 4343 | int64_t LSB = CE->getValue(); |
| 4344 | // The LSB must be in the range [0,31] |
| 4345 | if (LSB < 0 || LSB > 31) { |
| 4346 | Error(E, "'lsb' operand must be in the range [0,31]"); |
| 4347 | return MatchOperand_ParseFail; |
| 4348 | } |
| 4349 | E = Parser.getTok().getLoc(); |
| 4350 | |
| 4351 | // Expect another immediate operand. |
| 4352 | if (Parser.getTok().isNot(AsmToken::Comma)) { |
| 4353 | Error(Parser.getTok().getLoc(), "too few operands"); |
| 4354 | return MatchOperand_ParseFail; |
| 4355 | } |
| 4356 | Parser.Lex(); // Eat hash token. |
Jim Grosbach | ef70e9b | 2011-12-09 22:25:03 +0000 | [diff] [blame] | 4357 | if (Parser.getTok().isNot(AsmToken::Hash) && |
| 4358 | Parser.getTok().isNot(AsmToken::Dollar)) { |
Jim Grosbach | 864b609 | 2011-07-28 21:34:26 +0000 | [diff] [blame] | 4359 | Error(Parser.getTok().getLoc(), "'#' expected"); |
| 4360 | return MatchOperand_ParseFail; |
| 4361 | } |
| 4362 | Parser.Lex(); // Eat hash token. |
| 4363 | |
| 4364 | const MCExpr *WidthExpr; |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4365 | SMLoc EndLoc; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 4366 | if (getParser().parseExpression(WidthExpr, EndLoc)) { |
Jim Grosbach | 864b609 | 2011-07-28 21:34:26 +0000 | [diff] [blame] | 4367 | Error(E, "malformed immediate expression"); |
| 4368 | return MatchOperand_ParseFail; |
| 4369 | } |
| 4370 | CE = dyn_cast<MCConstantExpr>(WidthExpr); |
| 4371 | if (!CE) { |
| 4372 | Error(E, "'width' operand must be an immediate"); |
| 4373 | return MatchOperand_ParseFail; |
| 4374 | } |
| 4375 | |
| 4376 | int64_t Width = CE->getValue(); |
| 4377 | // The LSB must be in the range [1,32-lsb] |
| 4378 | if (Width < 1 || Width > 32 - LSB) { |
| 4379 | Error(E, "'width' operand must be in the range [1,32-lsb]"); |
| 4380 | return MatchOperand_ParseFail; |
| 4381 | } |
Jim Grosbach | 864b609 | 2011-07-28 21:34:26 +0000 | [diff] [blame] | 4382 | |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4383 | Operands.push_back(ARMOperand::CreateBitfield(LSB, Width, S, EndLoc)); |
Jim Grosbach | 864b609 | 2011-07-28 21:34:26 +0000 | [diff] [blame] | 4384 | |
| 4385 | return MatchOperand_Success; |
| 4386 | } |
| 4387 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4388 | ARMAsmParser::OperandMatchResultTy |
| 4389 | ARMAsmParser::parsePostIdxReg(OperandVector &Operands) { |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4390 | // Check for a post-index addressing register operand. Specifically: |
Jim Grosbach | c320c85 | 2011-08-05 21:28:30 +0000 | [diff] [blame] | 4391 | // postidx_reg := '+' register {, shift} |
| 4392 | // | '-' register {, shift} |
| 4393 | // | register {, shift} |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4394 | |
| 4395 | // This method must return MatchOperand_NoMatch without consuming any tokens |
| 4396 | // in the case where there is no match, as other alternatives take other |
| 4397 | // parse methods. |
| 4398 | AsmToken Tok = Parser.getTok(); |
| 4399 | SMLoc S = Tok.getLoc(); |
| 4400 | bool haveEaten = false; |
Jim Grosbach | a70fbfd5 | 2011-08-05 16:11:38 +0000 | [diff] [blame] | 4401 | bool isAdd = true; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4402 | if (Tok.is(AsmToken::Plus)) { |
| 4403 | Parser.Lex(); // Eat the '+' token. |
| 4404 | haveEaten = true; |
| 4405 | } else if (Tok.is(AsmToken::Minus)) { |
| 4406 | Parser.Lex(); // Eat the '-' token. |
Jim Grosbach | a70fbfd5 | 2011-08-05 16:11:38 +0000 | [diff] [blame] | 4407 | isAdd = false; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4408 | haveEaten = true; |
| 4409 | } |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4410 | |
| 4411 | SMLoc E = Parser.getTok().getEndLoc(); |
| 4412 | int Reg = tryParseRegister(); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4413 | if (Reg == -1) { |
| 4414 | if (!haveEaten) |
| 4415 | return MatchOperand_NoMatch; |
| 4416 | Error(Parser.getTok().getLoc(), "register expected"); |
| 4417 | return MatchOperand_ParseFail; |
| 4418 | } |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4419 | |
Jim Grosbach | c320c85 | 2011-08-05 21:28:30 +0000 | [diff] [blame] | 4420 | ARM_AM::ShiftOpc ShiftTy = ARM_AM::no_shift; |
| 4421 | unsigned ShiftImm = 0; |
Jim Grosbach | 3d0b3a3 | 2011-08-05 22:03:36 +0000 | [diff] [blame] | 4422 | if (Parser.getTok().is(AsmToken::Comma)) { |
| 4423 | Parser.Lex(); // Eat the ','. |
| 4424 | if (parseMemRegOffsetShift(ShiftTy, ShiftImm)) |
| 4425 | return MatchOperand_ParseFail; |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4426 | |
| 4427 | // FIXME: Only approximates end...may include intervening whitespace. |
| 4428 | E = Parser.getTok().getLoc(); |
Jim Grosbach | 3d0b3a3 | 2011-08-05 22:03:36 +0000 | [diff] [blame] | 4429 | } |
Jim Grosbach | c320c85 | 2011-08-05 21:28:30 +0000 | [diff] [blame] | 4430 | |
| 4431 | Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ShiftTy, |
| 4432 | ShiftImm, S, E)); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4433 | |
| 4434 | return MatchOperand_Success; |
| 4435 | } |
| 4436 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4437 | ARMAsmParser::OperandMatchResultTy |
| 4438 | ARMAsmParser::parseAM3Offset(OperandVector &Operands) { |
Jim Grosbach | 1d9d5e9 | 2011-08-10 21:56:18 +0000 | [diff] [blame] | 4439 | // Check for a post-index addressing register operand. Specifically: |
| 4440 | // am3offset := '+' register |
| 4441 | // | '-' register |
| 4442 | // | register |
| 4443 | // | # imm |
| 4444 | // | # + imm |
| 4445 | // | # - imm |
| 4446 | |
| 4447 | // This method must return MatchOperand_NoMatch without consuming any tokens |
| 4448 | // in the case where there is no match, as other alternatives take other |
| 4449 | // parse methods. |
| 4450 | AsmToken Tok = Parser.getTok(); |
| 4451 | SMLoc S = Tok.getLoc(); |
| 4452 | |
| 4453 | // Do immediates first, as we always parse those if we have a '#'. |
Jim Grosbach | ef70e9b | 2011-12-09 22:25:03 +0000 | [diff] [blame] | 4454 | if (Parser.getTok().is(AsmToken::Hash) || |
| 4455 | Parser.getTok().is(AsmToken::Dollar)) { |
Amaury de la Vieuville | bac917f | 2013-06-10 14:17:15 +0000 | [diff] [blame] | 4456 | Parser.Lex(); // Eat '#' or '$'. |
Jim Grosbach | 1d9d5e9 | 2011-08-10 21:56:18 +0000 | [diff] [blame] | 4457 | // Explicitly look for a '-', as we need to encode negative zero |
| 4458 | // differently. |
| 4459 | bool isNegative = Parser.getTok().is(AsmToken::Minus); |
| 4460 | const MCExpr *Offset; |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4461 | SMLoc E; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 4462 | if (getParser().parseExpression(Offset, E)) |
Jim Grosbach | 1d9d5e9 | 2011-08-10 21:56:18 +0000 | [diff] [blame] | 4463 | return MatchOperand_ParseFail; |
| 4464 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset); |
| 4465 | if (!CE) { |
| 4466 | Error(S, "constant expression expected"); |
| 4467 | return MatchOperand_ParseFail; |
| 4468 | } |
Jim Grosbach | 1d9d5e9 | 2011-08-10 21:56:18 +0000 | [diff] [blame] | 4469 | // Negative zero is encoded as the flag value INT32_MIN. |
| 4470 | int32_t Val = CE->getValue(); |
| 4471 | if (isNegative && Val == 0) |
| 4472 | Val = INT32_MIN; |
| 4473 | |
| 4474 | Operands.push_back( |
| 4475 | ARMOperand::CreateImm(MCConstantExpr::Create(Val, getContext()), S, E)); |
| 4476 | |
| 4477 | return MatchOperand_Success; |
| 4478 | } |
| 4479 | |
| 4480 | |
| 4481 | bool haveEaten = false; |
| 4482 | bool isAdd = true; |
Jim Grosbach | 1d9d5e9 | 2011-08-10 21:56:18 +0000 | [diff] [blame] | 4483 | if (Tok.is(AsmToken::Plus)) { |
| 4484 | Parser.Lex(); // Eat the '+' token. |
| 4485 | haveEaten = true; |
| 4486 | } else if (Tok.is(AsmToken::Minus)) { |
| 4487 | Parser.Lex(); // Eat the '-' token. |
| 4488 | isAdd = false; |
| 4489 | haveEaten = true; |
| 4490 | } |
Saleem Abdulrasool | 4ab6e73 | 2014-02-23 17:45:36 +0000 | [diff] [blame] | 4491 | |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4492 | Tok = Parser.getTok(); |
| 4493 | int Reg = tryParseRegister(); |
Jim Grosbach | 1d9d5e9 | 2011-08-10 21:56:18 +0000 | [diff] [blame] | 4494 | if (Reg == -1) { |
| 4495 | if (!haveEaten) |
| 4496 | return MatchOperand_NoMatch; |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4497 | Error(Tok.getLoc(), "register expected"); |
Jim Grosbach | 1d9d5e9 | 2011-08-10 21:56:18 +0000 | [diff] [blame] | 4498 | return MatchOperand_ParseFail; |
| 4499 | } |
Jim Grosbach | 1d9d5e9 | 2011-08-10 21:56:18 +0000 | [diff] [blame] | 4500 | |
| 4501 | Operands.push_back(ARMOperand::CreatePostIdxReg(Reg, isAdd, ARM_AM::no_shift, |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4502 | 0, S, Tok.getEndLoc())); |
Jim Grosbach | 1d9d5e9 | 2011-08-10 21:56:18 +0000 | [diff] [blame] | 4503 | |
| 4504 | return MatchOperand_Success; |
| 4505 | } |
| 4506 | |
Tim Northover | eb5e4d5 | 2013-07-22 09:06:12 +0000 | [diff] [blame] | 4507 | /// Convert parsed operands to MCInst. Needed here because this instruction |
| 4508 | /// only has two register operands, but multiplication is commutative so |
| 4509 | /// 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] | 4510 | void ARMAsmParser::cvtThumbMultiply(MCInst &Inst, |
| 4511 | const OperandVector &Operands) { |
| 4512 | ((ARMOperand &)*Operands[3]).addRegOperands(Inst, 1); |
| 4513 | ((ARMOperand &)*Operands[1]).addCCOutOperands(Inst, 1); |
Jim Grosbach | 5a5ce63 | 2011-11-10 22:10:12 +0000 | [diff] [blame] | 4514 | // If we have a three-operand form, make sure to set Rn to be the operand |
| 4515 | // that isn't the same as Rd. |
| 4516 | unsigned RegOp = 4; |
| 4517 | if (Operands.size() == 6 && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4518 | ((ARMOperand &)*Operands[4]).getReg() == |
| 4519 | ((ARMOperand &)*Operands[3]).getReg()) |
Jim Grosbach | 5a5ce63 | 2011-11-10 22:10:12 +0000 | [diff] [blame] | 4520 | RegOp = 5; |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4521 | ((ARMOperand &)*Operands[RegOp]).addRegOperands(Inst, 1); |
Jim Grosbach | 5a5ce63 | 2011-11-10 22:10:12 +0000 | [diff] [blame] | 4522 | Inst.addOperand(Inst.getOperand(0)); |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4523 | ((ARMOperand &)*Operands[2]).addCondCodeOperands(Inst, 2); |
Jim Grosbach | 8e04849 | 2011-08-19 22:07:46 +0000 | [diff] [blame] | 4524 | } |
Jim Grosbach | cd4dd25 | 2011-08-10 22:42:16 +0000 | [diff] [blame] | 4525 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4526 | void ARMAsmParser::cvtThumbBranches(MCInst &Inst, |
| 4527 | const OperandVector &Operands) { |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 4528 | int CondOp = -1, ImmOp = -1; |
| 4529 | switch(Inst.getOpcode()) { |
| 4530 | case ARM::tB: |
| 4531 | case ARM::tBcc: CondOp = 1; ImmOp = 2; break; |
| 4532 | |
| 4533 | case ARM::t2B: |
| 4534 | case ARM::t2Bcc: CondOp = 1; ImmOp = 3; break; |
| 4535 | |
| 4536 | default: llvm_unreachable("Unexpected instruction in cvtThumbBranches"); |
| 4537 | } |
| 4538 | // first decide whether or not the branch should be conditional |
| 4539 | // by looking at it's location relative to an IT block |
| 4540 | if(inITBlock()) { |
| 4541 | // inside an IT block we cannot have any conditional branches. any |
| 4542 | // such instructions needs to be converted to unconditional form |
| 4543 | switch(Inst.getOpcode()) { |
| 4544 | case ARM::tBcc: Inst.setOpcode(ARM::tB); break; |
| 4545 | case ARM::t2Bcc: Inst.setOpcode(ARM::t2B); break; |
| 4546 | } |
| 4547 | } else { |
| 4548 | // outside IT blocks we can only have unconditional branches with AL |
| 4549 | // condition code or conditional branches with non-AL condition code |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4550 | unsigned Cond = static_cast<ARMOperand &>(*Operands[CondOp]).getCondCode(); |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 4551 | switch(Inst.getOpcode()) { |
| 4552 | case ARM::tB: |
| 4553 | case ARM::tBcc: |
| 4554 | Inst.setOpcode(Cond == ARMCC::AL ? ARM::tB : ARM::tBcc); |
| 4555 | break; |
| 4556 | case ARM::t2B: |
| 4557 | case ARM::t2Bcc: |
| 4558 | Inst.setOpcode(Cond == ARMCC::AL ? ARM::t2B : ARM::t2Bcc); |
| 4559 | break; |
| 4560 | } |
| 4561 | } |
Saleem Abdulrasool | 4ab6e73 | 2014-02-23 17:45:36 +0000 | [diff] [blame] | 4562 | |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 4563 | // now decide on encoding size based on branch target range |
| 4564 | switch(Inst.getOpcode()) { |
| 4565 | // classify tB as either t2B or t1B based on range of immediate operand |
| 4566 | case ARM::tB: { |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4567 | ARMOperand &op = static_cast<ARMOperand &>(*Operands[ImmOp]); |
| 4568 | if (!op.isSignedOffset<11, 1>() && isThumbTwo()) |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 4569 | Inst.setOpcode(ARM::t2B); |
| 4570 | break; |
| 4571 | } |
| 4572 | // classify tBcc as either t2Bcc or t1Bcc based on range of immediate operand |
| 4573 | case ARM::tBcc: { |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4574 | ARMOperand &op = static_cast<ARMOperand &>(*Operands[ImmOp]); |
| 4575 | if (!op.isSignedOffset<8, 1>() && isThumbTwo()) |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 4576 | Inst.setOpcode(ARM::t2Bcc); |
| 4577 | break; |
| 4578 | } |
| 4579 | } |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4580 | ((ARMOperand &)*Operands[ImmOp]).addImmOperands(Inst, 1); |
| 4581 | ((ARMOperand &)*Operands[CondOp]).addCondCodeOperands(Inst, 2); |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 4582 | } |
| 4583 | |
Bill Wendling | e18980a | 2010-11-06 22:36:58 +0000 | [diff] [blame] | 4584 | /// Parse an ARM memory expression, return false if successful else return true |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 4585 | /// or an error. The first token must be a '[' when called. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4586 | bool ARMAsmParser::parseMemory(OperandVector &Operands) { |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 4587 | SMLoc S, E; |
Sean Callanan | 936b0d3 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 4588 | assert(Parser.getTok().is(AsmToken::LBrac) && |
Bill Wendling | 4f4bce0 | 2010-11-06 10:48:18 +0000 | [diff] [blame] | 4589 | "Token is not a Left Bracket"); |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 4590 | S = Parser.getTok().getLoc(); |
Sean Callanan | a83fd7d | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 4591 | Parser.Lex(); // Eat left bracket token. |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 4592 | |
Sean Callanan | 936b0d3 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 4593 | const AsmToken &BaseRegTok = Parser.getTok(); |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 4594 | int BaseRegNum = tryParseRegister(); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4595 | if (BaseRegNum == -1) |
| 4596 | return Error(BaseRegTok.getLoc(), "register expected"); |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 4597 | |
Kristof Beyls | 2efb59a | 2013-02-14 14:46:12 +0000 | [diff] [blame] | 4598 | // 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] | 4599 | const AsmToken &Tok = Parser.getTok(); |
Kristof Beyls | 2efb59a | 2013-02-14 14:46:12 +0000 | [diff] [blame] | 4600 | if (!Tok.is(AsmToken::Colon) && !Tok.is(AsmToken::Comma) && |
| 4601 | !Tok.is(AsmToken::RBrac)) |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4602 | return Error(Tok.getLoc(), "malformed memory operand"); |
Daniel Dunbar | 1d5e954 | 2011-01-18 05:34:17 +0000 | [diff] [blame] | 4603 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4604 | if (Tok.is(AsmToken::RBrac)) { |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4605 | E = Tok.getEndLoc(); |
Sean Callanan | a83fd7d | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 4606 | Parser.Lex(); // Eat right bracket token. |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 4607 | |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 4608 | Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, 0, |
| 4609 | ARM_AM::no_shift, 0, 0, false, |
| 4610 | S, E)); |
Jim Grosbach | 32ff558 | 2010-11-29 23:18:01 +0000 | [diff] [blame] | 4611 | |
Jim Grosbach | 40700e0 | 2011-09-19 18:42:21 +0000 | [diff] [blame] | 4612 | // If there's a pre-indexing writeback marker, '!', just add it as a token |
| 4613 | // operand. It's rather odd, but syntactically valid. |
| 4614 | if (Parser.getTok().is(AsmToken::Exclaim)) { |
| 4615 | Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc())); |
| 4616 | Parser.Lex(); // Eat the '!'. |
| 4617 | } |
| 4618 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4619 | return false; |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 4620 | } |
Daniel Dunbar | f5164f4 | 2011-01-18 05:34:24 +0000 | [diff] [blame] | 4621 | |
Kristof Beyls | 2efb59a | 2013-02-14 14:46:12 +0000 | [diff] [blame] | 4622 | assert((Tok.is(AsmToken::Colon) || Tok.is(AsmToken::Comma)) && |
| 4623 | "Lost colon or comma in memory operand?!"); |
| 4624 | if (Tok.is(AsmToken::Comma)) { |
| 4625 | Parser.Lex(); // Eat the comma. |
| 4626 | } |
Daniel Dunbar | f5164f4 | 2011-01-18 05:34:24 +0000 | [diff] [blame] | 4627 | |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 4628 | // If we have a ':', it's an alignment specifier. |
| 4629 | if (Parser.getTok().is(AsmToken::Colon)) { |
| 4630 | Parser.Lex(); // Eat the ':'. |
| 4631 | E = Parser.getTok().getLoc(); |
Kevin Enderby | 488f20b | 2014-04-10 20:18:58 +0000 | [diff] [blame] | 4632 | SMLoc AlignmentLoc = Tok.getLoc(); |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 4633 | |
| 4634 | const MCExpr *Expr; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 4635 | if (getParser().parseExpression(Expr)) |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 4636 | return true; |
| 4637 | |
| 4638 | // The expression has to be a constant. Memory references with relocations |
| 4639 | // don't come through here, as they use the <label> forms of the relevant |
| 4640 | // instructions. |
| 4641 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr); |
| 4642 | if (!CE) |
| 4643 | return Error (E, "constant expression expected"); |
| 4644 | |
| 4645 | unsigned Align = 0; |
| 4646 | switch (CE->getValue()) { |
| 4647 | default: |
Jim Grosbach | cef98cd | 2011-12-19 18:31:43 +0000 | [diff] [blame] | 4648 | return Error(E, |
| 4649 | "alignment specifier must be 16, 32, 64, 128, or 256 bits"); |
| 4650 | case 16: Align = 2; break; |
| 4651 | case 32: Align = 4; break; |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 4652 | case 64: Align = 8; break; |
| 4653 | case 128: Align = 16; break; |
| 4654 | case 256: Align = 32; break; |
| 4655 | } |
| 4656 | |
| 4657 | // Now we should have the closing ']' |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 4658 | if (Parser.getTok().isNot(AsmToken::RBrac)) |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4659 | return Error(Parser.getTok().getLoc(), "']' expected"); |
| 4660 | E = Parser.getTok().getEndLoc(); |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 4661 | Parser.Lex(); // Eat right bracket token. |
| 4662 | |
| 4663 | // Don't worry about range checking the value here. That's handled by |
| 4664 | // the is*() predicates. |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 4665 | Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, 0, |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 4666 | ARM_AM::no_shift, 0, Align, |
Kevin Enderby | 488f20b | 2014-04-10 20:18:58 +0000 | [diff] [blame] | 4667 | false, S, E, AlignmentLoc)); |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 4668 | |
| 4669 | // If there's a pre-indexing writeback marker, '!', just add it as a token |
| 4670 | // operand. |
| 4671 | if (Parser.getTok().is(AsmToken::Exclaim)) { |
| 4672 | Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc())); |
| 4673 | Parser.Lex(); // Eat the '!'. |
| 4674 | } |
| 4675 | |
| 4676 | return false; |
| 4677 | } |
| 4678 | |
| 4679 | // 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] | 4680 | // offset. Be friendly and also accept a plain integer (without a leading |
| 4681 | // hash) for gas compatibility. |
| 4682 | if (Parser.getTok().is(AsmToken::Hash) || |
Jim Grosbach | ef70e9b | 2011-12-09 22:25:03 +0000 | [diff] [blame] | 4683 | Parser.getTok().is(AsmToken::Dollar) || |
Jim Grosbach | 8279c18 | 2011-11-15 22:14:41 +0000 | [diff] [blame] | 4684 | Parser.getTok().is(AsmToken::Integer)) { |
Jim Grosbach | ef70e9b | 2011-12-09 22:25:03 +0000 | [diff] [blame] | 4685 | if (Parser.getTok().isNot(AsmToken::Integer)) |
Amaury de la Vieuville | bac917f | 2013-06-10 14:17:15 +0000 | [diff] [blame] | 4686 | Parser.Lex(); // Eat '#' or '$'. |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4687 | E = Parser.getTok().getLoc(); |
Daniel Dunbar | f5164f4 | 2011-01-18 05:34:24 +0000 | [diff] [blame] | 4688 | |
Owen Anderson | 967674d | 2011-08-29 19:36:44 +0000 | [diff] [blame] | 4689 | bool isNegative = getParser().getTok().is(AsmToken::Minus); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4690 | const MCExpr *Offset; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 4691 | if (getParser().parseExpression(Offset)) |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 4692 | return true; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4693 | |
| 4694 | // The expression has to be a constant. Memory references with relocations |
| 4695 | // don't come through here, as they use the <label> forms of the relevant |
| 4696 | // instructions. |
| 4697 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Offset); |
| 4698 | if (!CE) |
| 4699 | return Error (E, "constant expression expected"); |
| 4700 | |
Owen Anderson | 967674d | 2011-08-29 19:36:44 +0000 | [diff] [blame] | 4701 | // If the constant was #-0, represent it as INT32_MIN. |
| 4702 | int32_t Val = CE->getValue(); |
| 4703 | if (isNegative && Val == 0) |
| 4704 | CE = MCConstantExpr::Create(INT32_MIN, getContext()); |
| 4705 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4706 | // Now we should have the closing ']' |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4707 | if (Parser.getTok().isNot(AsmToken::RBrac)) |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4708 | return Error(Parser.getTok().getLoc(), "']' expected"); |
| 4709 | E = Parser.getTok().getEndLoc(); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4710 | Parser.Lex(); // Eat right bracket token. |
| 4711 | |
| 4712 | // Don't worry about range checking the value here. That's handled by |
| 4713 | // the is*() predicates. |
| 4714 | Operands.push_back(ARMOperand::CreateMem(BaseRegNum, CE, 0, |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 4715 | ARM_AM::no_shift, 0, 0, |
| 4716 | false, S, E)); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4717 | |
| 4718 | // If there's a pre-indexing writeback marker, '!', just add it as a token |
| 4719 | // operand. |
| 4720 | if (Parser.getTok().is(AsmToken::Exclaim)) { |
| 4721 | Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc())); |
| 4722 | Parser.Lex(); // Eat the '!'. |
| 4723 | } |
| 4724 | |
| 4725 | return false; |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 4726 | } |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4727 | |
| 4728 | // The register offset is optionally preceded by a '+' or '-' |
| 4729 | bool isNegative = false; |
| 4730 | if (Parser.getTok().is(AsmToken::Minus)) { |
| 4731 | isNegative = true; |
| 4732 | Parser.Lex(); // Eat the '-'. |
| 4733 | } else if (Parser.getTok().is(AsmToken::Plus)) { |
| 4734 | // Nothing to do. |
| 4735 | Parser.Lex(); // Eat the '+'. |
| 4736 | } |
| 4737 | |
| 4738 | E = Parser.getTok().getLoc(); |
| 4739 | int OffsetRegNum = tryParseRegister(); |
| 4740 | if (OffsetRegNum == -1) |
| 4741 | return Error(E, "register expected"); |
| 4742 | |
| 4743 | // If there's a shift operator, handle it. |
| 4744 | ARM_AM::ShiftOpc ShiftType = ARM_AM::no_shift; |
Jim Grosbach | 3d0b3a3 | 2011-08-05 22:03:36 +0000 | [diff] [blame] | 4745 | unsigned ShiftImm = 0; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4746 | if (Parser.getTok().is(AsmToken::Comma)) { |
| 4747 | Parser.Lex(); // Eat the ','. |
Jim Grosbach | 3d0b3a3 | 2011-08-05 22:03:36 +0000 | [diff] [blame] | 4748 | if (parseMemRegOffsetShift(ShiftType, ShiftImm)) |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4749 | return true; |
| 4750 | } |
| 4751 | |
| 4752 | // Now we should have the closing ']' |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4753 | if (Parser.getTok().isNot(AsmToken::RBrac)) |
Jordan Rose | e8f1eae | 2013-01-07 19:00:49 +0000 | [diff] [blame] | 4754 | return Error(Parser.getTok().getLoc(), "']' expected"); |
| 4755 | E = Parser.getTok().getEndLoc(); |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4756 | Parser.Lex(); // Eat right bracket token. |
| 4757 | |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 4758 | Operands.push_back(ARMOperand::CreateMem(BaseRegNum, nullptr, OffsetRegNum, |
Jim Grosbach | a95ec99 | 2011-10-11 17:29:55 +0000 | [diff] [blame] | 4759 | ShiftType, ShiftImm, 0, isNegative, |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4760 | S, E)); |
| 4761 | |
Jim Grosbach | c320c85 | 2011-08-05 21:28:30 +0000 | [diff] [blame] | 4762 | // If there's a pre-indexing writeback marker, '!', just add it as a token |
| 4763 | // operand. |
| 4764 | if (Parser.getTok().is(AsmToken::Exclaim)) { |
| 4765 | Operands.push_back(ARMOperand::CreateToken("!",Parser.getTok().getLoc())); |
| 4766 | Parser.Lex(); // Eat the '!'. |
| 4767 | } |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4768 | |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 4769 | return false; |
| 4770 | } |
| 4771 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4772 | /// parseMemRegOffsetShift - one of these two: |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 4773 | /// ( lsl | lsr | asr | ror ) , # shift_amount |
| 4774 | /// rrx |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4775 | /// return true if it parses a shift otherwise it returns false. |
| 4776 | bool ARMAsmParser::parseMemRegOffsetShift(ARM_AM::ShiftOpc &St, |
| 4777 | unsigned &Amount) { |
| 4778 | SMLoc Loc = Parser.getTok().getLoc(); |
Sean Callanan | 936b0d3 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 4779 | const AsmToken &Tok = Parser.getTok(); |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 4780 | if (Tok.isNot(AsmToken::Identifier)) |
| 4781 | return true; |
Benjamin Kramer | 92d8998 | 2010-07-14 22:38:02 +0000 | [diff] [blame] | 4782 | StringRef ShiftName = Tok.getString(); |
Jim Grosbach | 3b559ff | 2011-12-07 23:40:58 +0000 | [diff] [blame] | 4783 | if (ShiftName == "lsl" || ShiftName == "LSL" || |
| 4784 | ShiftName == "asl" || ShiftName == "ASL") |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 4785 | St = ARM_AM::lsl; |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 4786 | else if (ShiftName == "lsr" || ShiftName == "LSR") |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 4787 | St = ARM_AM::lsr; |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 4788 | else if (ShiftName == "asr" || ShiftName == "ASR") |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 4789 | St = ARM_AM::asr; |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 4790 | else if (ShiftName == "ror" || ShiftName == "ROR") |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 4791 | St = ARM_AM::ror; |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 4792 | else if (ShiftName == "rrx" || ShiftName == "RRX") |
Owen Anderson | 1d2f5ce | 2011-03-18 22:50:18 +0000 | [diff] [blame] | 4793 | St = ARM_AM::rrx; |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 4794 | else |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4795 | return Error(Loc, "illegal shift operator"); |
Sean Callanan | a83fd7d | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 4796 | Parser.Lex(); // Eat shift type token. |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 4797 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4798 | // rrx stands alone. |
| 4799 | Amount = 0; |
| 4800 | if (St != ARM_AM::rrx) { |
| 4801 | Loc = Parser.getTok().getLoc(); |
| 4802 | // A '#' and a shift amount. |
| 4803 | const AsmToken &HashTok = Parser.getTok(); |
Jim Grosbach | ef70e9b | 2011-12-09 22:25:03 +0000 | [diff] [blame] | 4804 | if (HashTok.isNot(AsmToken::Hash) && |
| 4805 | HashTok.isNot(AsmToken::Dollar)) |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4806 | return Error(HashTok.getLoc(), "'#' expected"); |
| 4807 | Parser.Lex(); // Eat hash token. |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 4808 | |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4809 | const MCExpr *Expr; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 4810 | if (getParser().parseExpression(Expr)) |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4811 | return true; |
| 4812 | // Range check the immediate. |
| 4813 | // lsl, ror: 0 <= imm <= 31 |
| 4814 | // lsr, asr: 0 <= imm <= 32 |
| 4815 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr); |
| 4816 | if (!CE) |
| 4817 | return Error(Loc, "shift amount must be an immediate"); |
| 4818 | int64_t Imm = CE->getValue(); |
| 4819 | if (Imm < 0 || |
| 4820 | ((St == ARM_AM::lsl || St == ARM_AM::ror) && Imm > 31) || |
| 4821 | ((St == ARM_AM::lsr || St == ARM_AM::asr) && Imm > 32)) |
| 4822 | return Error(Loc, "immediate shift value out of range"); |
Tim Northover | 0c97e76 | 2012-09-22 11:18:12 +0000 | [diff] [blame] | 4823 | // If <ShiftTy> #0, turn it into a no_shift. |
| 4824 | if (Imm == 0) |
| 4825 | St = ARM_AM::lsl; |
| 4826 | // For consistency, treat lsr #32 and asr #32 as having immediate value 0. |
| 4827 | if (Imm == 32) |
| 4828 | Imm = 0; |
Jim Grosbach | d359571 | 2011-08-03 23:50:40 +0000 | [diff] [blame] | 4829 | Amount = Imm; |
| 4830 | } |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 4831 | |
| 4832 | return false; |
| 4833 | } |
| 4834 | |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 4835 | /// parseFPImm - A floating point immediate expression operand. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4836 | ARMAsmParser::OperandMatchResultTy |
| 4837 | ARMAsmParser::parseFPImm(OperandVector &Operands) { |
Jim Grosbach | a9d36fb | 2012-01-20 18:09:51 +0000 | [diff] [blame] | 4838 | // Anything that can accept a floating point constant as an operand |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 4839 | // needs to go through here, as the regular parseExpression is |
Jim Grosbach | a9d36fb | 2012-01-20 18:09:51 +0000 | [diff] [blame] | 4840 | // integer only. |
| 4841 | // |
| 4842 | // This routine still creates a generic Immediate operand, containing |
| 4843 | // a bitcast of the 64-bit floating point value. The various operands |
| 4844 | // that accept floats can check whether the value is valid for them |
| 4845 | // via the standard is*() predicates. |
| 4846 | |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 4847 | SMLoc S = Parser.getTok().getLoc(); |
| 4848 | |
Jim Grosbach | ef70e9b | 2011-12-09 22:25:03 +0000 | [diff] [blame] | 4849 | if (Parser.getTok().isNot(AsmToken::Hash) && |
| 4850 | Parser.getTok().isNot(AsmToken::Dollar)) |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 4851 | return MatchOperand_NoMatch; |
Jim Grosbach | 741cd73 | 2011-10-17 22:26:03 +0000 | [diff] [blame] | 4852 | |
| 4853 | // Disambiguate the VMOV forms that can accept an FP immediate. |
| 4854 | // vmov.f32 <sreg>, #imm |
| 4855 | // vmov.f64 <dreg>, #imm |
| 4856 | // vmov.f32 <dreg>, #imm @ vector f32x2 |
| 4857 | // vmov.f32 <qreg>, #imm @ vector f32x4 |
| 4858 | // |
| 4859 | // There are also the NEON VMOV instructions which expect an |
| 4860 | // integer constant. Make sure we don't try to parse an FPImm |
| 4861 | // for these: |
| 4862 | // vmov.i{8|16|32|64} <dreg|qreg>, #imm |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4863 | ARMOperand &TyOp = static_cast<ARMOperand &>(*Operands[2]); |
| 4864 | bool isVmovf = TyOp.isToken() && |
| 4865 | (TyOp.getToken() == ".f32" || TyOp.getToken() == ".f64"); |
| 4866 | ARMOperand &Mnemonic = static_cast<ARMOperand &>(*Operands[0]); |
| 4867 | bool isFconst = Mnemonic.isToken() && (Mnemonic.getToken() == "fconstd" || |
| 4868 | Mnemonic.getToken() == "fconsts"); |
David Peixotto | a872e0e | 2014-01-07 18:19:23 +0000 | [diff] [blame] | 4869 | if (!(isVmovf || isFconst)) |
Jim Grosbach | 741cd73 | 2011-10-17 22:26:03 +0000 | [diff] [blame] | 4870 | return MatchOperand_NoMatch; |
| 4871 | |
Amaury de la Vieuville | bac917f | 2013-06-10 14:17:15 +0000 | [diff] [blame] | 4872 | Parser.Lex(); // Eat '#' or '$'. |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 4873 | |
| 4874 | // Handle negation, as that still comes through as a separate token. |
| 4875 | bool isNegative = false; |
| 4876 | if (Parser.getTok().is(AsmToken::Minus)) { |
| 4877 | isNegative = true; |
| 4878 | Parser.Lex(); |
| 4879 | } |
| 4880 | const AsmToken &Tok = Parser.getTok(); |
Jim Grosbach | 235c8d2 | 2012-01-19 02:47:30 +0000 | [diff] [blame] | 4881 | SMLoc Loc = Tok.getLoc(); |
David Peixotto | a872e0e | 2014-01-07 18:19:23 +0000 | [diff] [blame] | 4882 | if (Tok.is(AsmToken::Real) && isVmovf) { |
Jim Grosbach | a9d36fb | 2012-01-20 18:09:51 +0000 | [diff] [blame] | 4883 | APFloat RealVal(APFloat::IEEEsingle, Tok.getString()); |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 4884 | uint64_t IntVal = RealVal.bitcastToAPInt().getZExtValue(); |
| 4885 | // If we had a '-' in front, toggle the sign bit. |
Jim Grosbach | a9d36fb | 2012-01-20 18:09:51 +0000 | [diff] [blame] | 4886 | IntVal ^= (uint64_t)isNegative << 31; |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 4887 | Parser.Lex(); // Eat the token. |
Jim Grosbach | a9d36fb | 2012-01-20 18:09:51 +0000 | [diff] [blame] | 4888 | Operands.push_back(ARMOperand::CreateImm( |
| 4889 | MCConstantExpr::Create(IntVal, getContext()), |
| 4890 | S, Parser.getTok().getLoc())); |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 4891 | return MatchOperand_Success; |
| 4892 | } |
Jim Grosbach | a9d36fb | 2012-01-20 18:09:51 +0000 | [diff] [blame] | 4893 | // Also handle plain integers. Instructions which allow floating point |
| 4894 | // immediates also allow a raw encoded 8-bit value. |
David Peixotto | a872e0e | 2014-01-07 18:19:23 +0000 | [diff] [blame] | 4895 | if (Tok.is(AsmToken::Integer) && isFconst) { |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 4896 | int64_t Val = Tok.getIntVal(); |
| 4897 | Parser.Lex(); // Eat the token. |
| 4898 | if (Val > 255 || Val < 0) { |
Jim Grosbach | 235c8d2 | 2012-01-19 02:47:30 +0000 | [diff] [blame] | 4899 | Error(Loc, "encoded floating point value out of range"); |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 4900 | return MatchOperand_ParseFail; |
| 4901 | } |
David Peixotto | a872e0e | 2014-01-07 18:19:23 +0000 | [diff] [blame] | 4902 | float RealVal = ARM_AM::getFPImmFloat(Val); |
| 4903 | Val = APFloat(RealVal).bitcastToAPInt().getZExtValue(); |
| 4904 | |
Jim Grosbach | a9d36fb | 2012-01-20 18:09:51 +0000 | [diff] [blame] | 4905 | Operands.push_back(ARMOperand::CreateImm( |
| 4906 | MCConstantExpr::Create(Val, getContext()), S, |
| 4907 | Parser.getTok().getLoc())); |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 4908 | return MatchOperand_Success; |
| 4909 | } |
| 4910 | |
Jim Grosbach | 235c8d2 | 2012-01-19 02:47:30 +0000 | [diff] [blame] | 4911 | Error(Loc, "invalid floating point immediate"); |
Jim Grosbach | e7fbce7 | 2011-10-03 23:38:36 +0000 | [diff] [blame] | 4912 | return MatchOperand_ParseFail; |
| 4913 | } |
Jim Grosbach | a9d36fb | 2012-01-20 18:09:51 +0000 | [diff] [blame] | 4914 | |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 4915 | /// Parse a arm instruction operand. For now this parses the operand regardless |
| 4916 | /// of the mnemonic. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 4917 | bool ARMAsmParser::parseOperand(OperandVector &Operands, StringRef Mnemonic) { |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 4918 | SMLoc S, E; |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 4919 | |
| 4920 | // Check if the current operand has a custom associated parser, if so, try to |
| 4921 | // custom parse the operand, or fallback to the general approach. |
Jim Grosbach | 861e49c | 2011-02-12 01:34:40 +0000 | [diff] [blame] | 4922 | OperandMatchResultTy ResTy = MatchOperandParserImpl(Operands, Mnemonic); |
| 4923 | if (ResTy == MatchOperand_Success) |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 4924 | return false; |
Jim Grosbach | 861e49c | 2011-02-12 01:34:40 +0000 | [diff] [blame] | 4925 | // If there wasn't a custom match, try the generic matcher below. Otherwise, |
| 4926 | // there was a match, but an error occurred, in which case, just return that |
| 4927 | // the operand parsing failed. |
| 4928 | if (ResTy == MatchOperand_ParseFail) |
| 4929 | return true; |
Bruno Cardoso Lopes | c9253b4 | 2011-02-07 21:41:25 +0000 | [diff] [blame] | 4930 | |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 4931 | switch (getLexer().getKind()) { |
Bill Wendling | ee7f1f9 | 2010-11-06 21:42:12 +0000 | [diff] [blame] | 4932 | default: |
| 4933 | Error(Parser.getTok().getLoc(), "unexpected token in operand"); |
Bill Wendling | 2063b84 | 2010-11-18 23:43:05 +0000 | [diff] [blame] | 4934 | return true; |
Jim Grosbach | bb24c59 | 2011-07-13 18:49:30 +0000 | [diff] [blame] | 4935 | case AsmToken::Identifier: { |
Chad Rosier | b162a5c | 2013-03-19 23:44:03 +0000 | [diff] [blame] | 4936 | // If we've seen a branch mnemonic, the next operand must be a label. This |
| 4937 | // is true even if the label is a register name. So "br r1" means branch to |
| 4938 | // label "r1". |
| 4939 | bool ExpectLabel = Mnemonic == "b" || Mnemonic == "bl"; |
| 4940 | if (!ExpectLabel) { |
| 4941 | if (!tryParseRegisterWithWriteBack(Operands)) |
| 4942 | return false; |
| 4943 | int Res = tryParseShiftRegister(Operands); |
| 4944 | if (Res == 0) // success |
| 4945 | return false; |
| 4946 | else if (Res == -1) // irrecoverable error |
| 4947 | return true; |
| 4948 | // If this is VMRS, check for the apsr_nzcv operand. |
| 4949 | if (Mnemonic == "vmrs" && |
| 4950 | Parser.getTok().getString().equals_lower("apsr_nzcv")) { |
| 4951 | S = Parser.getTok().getLoc(); |
| 4952 | Parser.Lex(); |
| 4953 | Operands.push_back(ARMOperand::CreateToken("APSR_nzcv", S)); |
| 4954 | return false; |
| 4955 | } |
Jim Grosbach | 4ab23b5 | 2011-10-03 21:12:43 +0000 | [diff] [blame] | 4956 | } |
Owen Anderson | c3c7f5d | 2011-01-13 21:46:02 +0000 | [diff] [blame] | 4957 | |
| 4958 | // Fall though for the Identifier case that is not a register or a |
| 4959 | // special name. |
Jim Grosbach | bb24c59 | 2011-07-13 18:49:30 +0000 | [diff] [blame] | 4960 | } |
Jim Grosbach | 4e38035 | 2011-10-26 21:14:08 +0000 | [diff] [blame] | 4961 | case AsmToken::LParen: // parenthesized expressions like (_strcmp-4) |
Kevin Enderby | b084be9 | 2011-01-13 20:32:36 +0000 | [diff] [blame] | 4962 | case AsmToken::Integer: // things like 1f and 2b as a branch targets |
Jim Grosbach | 5c6b634 | 2011-11-01 22:38:31 +0000 | [diff] [blame] | 4963 | case AsmToken::String: // quoted label names. |
Kevin Enderby | b084be9 | 2011-01-13 20:32:36 +0000 | [diff] [blame] | 4964 | case AsmToken::Dot: { // . as a branch target |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 4965 | // This was not a register so parse other operands that start with an |
| 4966 | // identifier (like labels) as expressions and create them as immediates. |
| 4967 | const MCExpr *IdVal; |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 4968 | S = Parser.getTok().getLoc(); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 4969 | if (getParser().parseExpression(IdVal)) |
Bill Wendling | 2063b84 | 2010-11-18 23:43:05 +0000 | [diff] [blame] | 4970 | return true; |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 4971 | E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1); |
Bill Wendling | 2063b84 | 2010-11-18 23:43:05 +0000 | [diff] [blame] | 4972 | Operands.push_back(ARMOperand::CreateImm(IdVal, S, E)); |
| 4973 | return false; |
| 4974 | } |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 4975 | case AsmToken::LBrac: |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 4976 | return parseMemory(Operands); |
Kevin Enderby | a2b9910 | 2009-10-09 21:12:28 +0000 | [diff] [blame] | 4977 | case AsmToken::LCurly: |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 4978 | return parseRegisterList(Operands); |
Jim Grosbach | ef70e9b | 2011-12-09 22:25:03 +0000 | [diff] [blame] | 4979 | case AsmToken::Dollar: |
Owen Anderson | f02d98d | 2011-08-29 17:17:09 +0000 | [diff] [blame] | 4980 | case AsmToken::Hash: { |
Kevin Enderby | 3a80dac | 2009-10-13 23:33:38 +0000 | [diff] [blame] | 4981 | // #42 -> immediate. |
Sean Callanan | 7ad0ad0 | 2010-04-02 22:27:05 +0000 | [diff] [blame] | 4982 | S = Parser.getTok().getLoc(); |
Sean Callanan | a83fd7d | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 4983 | Parser.Lex(); |
Jim Grosbach | 003607f | 2012-04-16 21:18:46 +0000 | [diff] [blame] | 4984 | |
| 4985 | if (Parser.getTok().isNot(AsmToken::Colon)) { |
| 4986 | bool isNegative = Parser.getTok().is(AsmToken::Minus); |
| 4987 | const MCExpr *ImmVal; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 4988 | if (getParser().parseExpression(ImmVal)) |
Jim Grosbach | 003607f | 2012-04-16 21:18:46 +0000 | [diff] [blame] | 4989 | return true; |
| 4990 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ImmVal); |
| 4991 | if (CE) { |
| 4992 | int32_t Val = CE->getValue(); |
| 4993 | if (isNegative && Val == 0) |
| 4994 | ImmVal = MCConstantExpr::Create(INT32_MIN, getContext()); |
| 4995 | } |
| 4996 | E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1); |
| 4997 | Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E)); |
Jim Grosbach | 9be2d71 | 2013-02-23 00:52:09 +0000 | [diff] [blame] | 4998 | |
| 4999 | // 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] | 5000 | // '!' Token operand. Handle that here. For example, the compatibility |
Jim Grosbach | 9be2d71 | 2013-02-23 00:52:09 +0000 | [diff] [blame] | 5001 | // alias for 'srsdb sp!, #imm' is 'srsdb #imm!'. |
| 5002 | if (Parser.getTok().is(AsmToken::Exclaim)) { |
| 5003 | Operands.push_back(ARMOperand::CreateToken(Parser.getTok().getString(), |
| 5004 | Parser.getTok().getLoc())); |
| 5005 | Parser.Lex(); // Eat exclaim token |
| 5006 | } |
Jim Grosbach | 003607f | 2012-04-16 21:18:46 +0000 | [diff] [blame] | 5007 | return false; |
Owen Anderson | f02d98d | 2011-08-29 17:17:09 +0000 | [diff] [blame] | 5008 | } |
Jim Grosbach | 003607f | 2012-04-16 21:18:46 +0000 | [diff] [blame] | 5009 | // w/ a ':' after the '#', it's just like a plain ':'. |
| 5010 | // FALLTHROUGH |
Owen Anderson | f02d98d | 2011-08-29 17:17:09 +0000 | [diff] [blame] | 5011 | } |
Jason W Kim | 1f7bc07 | 2011-01-11 23:53:41 +0000 | [diff] [blame] | 5012 | case AsmToken::Colon: { |
| 5013 | // ":lower16:" and ":upper16:" expression prefixes |
Evan Cheng | 965b3c7 | 2011-01-13 07:58:56 +0000 | [diff] [blame] | 5014 | // FIXME: Check it's an expression prefix, |
| 5015 | // e.g. (FOO - :lower16:BAR) isn't legal. |
| 5016 | ARMMCExpr::VariantKind RefKind; |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 5017 | if (parsePrefix(RefKind)) |
Jason W Kim | 1f7bc07 | 2011-01-11 23:53:41 +0000 | [diff] [blame] | 5018 | return true; |
| 5019 | |
Evan Cheng | 965b3c7 | 2011-01-13 07:58:56 +0000 | [diff] [blame] | 5020 | const MCExpr *SubExprVal; |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 5021 | if (getParser().parseExpression(SubExprVal)) |
Jason W Kim | 1f7bc07 | 2011-01-11 23:53:41 +0000 | [diff] [blame] | 5022 | return true; |
| 5023 | |
Evan Cheng | 965b3c7 | 2011-01-13 07:58:56 +0000 | [diff] [blame] | 5024 | const MCExpr *ExprVal = ARMMCExpr::Create(RefKind, SubExprVal, |
Jim Grosbach | 9659ed9 | 2012-09-21 00:26:53 +0000 | [diff] [blame] | 5025 | getContext()); |
Jason W Kim | 1f7bc07 | 2011-01-11 23:53:41 +0000 | [diff] [blame] | 5026 | E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1); |
Evan Cheng | 965b3c7 | 2011-01-13 07:58:56 +0000 | [diff] [blame] | 5027 | Operands.push_back(ARMOperand::CreateImm(ExprVal, S, E)); |
Jason W Kim | 1f7bc07 | 2011-01-11 23:53:41 +0000 | [diff] [blame] | 5028 | return false; |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 5029 | } |
David Peixotto | e407d09 | 2013-12-19 18:12:36 +0000 | [diff] [blame] | 5030 | case AsmToken::Equal: { |
| 5031 | if (Mnemonic != "ldr") // only parse for ldr pseudo (e.g. ldr r0, =val) |
| 5032 | return Error(Parser.getTok().getLoc(), "unexpected token in operand"); |
| 5033 | |
David Peixotto | e407d09 | 2013-12-19 18:12:36 +0000 | [diff] [blame] | 5034 | Parser.Lex(); // Eat '=' |
| 5035 | const MCExpr *SubExprVal; |
| 5036 | if (getParser().parseExpression(SubExprVal)) |
| 5037 | return true; |
| 5038 | E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1); |
| 5039 | |
David Peixotto | b9b7362 | 2014-02-04 17:22:40 +0000 | [diff] [blame] | 5040 | const MCExpr *CPLoc = getTargetStreamer().addConstantPoolEntry(SubExprVal); |
David Peixotto | e407d09 | 2013-12-19 18:12:36 +0000 | [diff] [blame] | 5041 | Operands.push_back(ARMOperand::CreateImm(CPLoc, S, E)); |
| 5042 | return false; |
| 5043 | } |
Jason W Kim | 1f7bc07 | 2011-01-11 23:53:41 +0000 | [diff] [blame] | 5044 | } |
| 5045 | } |
| 5046 | |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 5047 | // parsePrefix - Parse ARM 16-bit relocations expression prefix, i.e. |
Evan Cheng | 965b3c7 | 2011-01-13 07:58:56 +0000 | [diff] [blame] | 5048 | // :lower16: and :upper16:. |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 5049 | bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) { |
Evan Cheng | 965b3c7 | 2011-01-13 07:58:56 +0000 | [diff] [blame] | 5050 | RefKind = ARMMCExpr::VK_ARM_None; |
Jason W Kim | 1f7bc07 | 2011-01-11 23:53:41 +0000 | [diff] [blame] | 5051 | |
Saleem Abdulrasool | 435f456 | 2014-01-10 04:38:40 +0000 | [diff] [blame] | 5052 | // consume an optional '#' (GNU compatibility) |
| 5053 | if (getLexer().is(AsmToken::Hash)) |
| 5054 | Parser.Lex(); |
| 5055 | |
Jason W Kim | 1f7bc07 | 2011-01-11 23:53:41 +0000 | [diff] [blame] | 5056 | // :lower16: and :upper16: modifiers |
Jason W Kim | 9322997 | 2011-01-13 00:27:00 +0000 | [diff] [blame] | 5057 | assert(getLexer().is(AsmToken::Colon) && "expected a :"); |
Jason W Kim | 1f7bc07 | 2011-01-11 23:53:41 +0000 | [diff] [blame] | 5058 | Parser.Lex(); // Eat ':' |
| 5059 | |
| 5060 | if (getLexer().isNot(AsmToken::Identifier)) { |
| 5061 | Error(Parser.getTok().getLoc(), "expected prefix identifier in operand"); |
| 5062 | return true; |
| 5063 | } |
| 5064 | |
| 5065 | StringRef IDVal = Parser.getTok().getIdentifier(); |
| 5066 | if (IDVal == "lower16") { |
Evan Cheng | 965b3c7 | 2011-01-13 07:58:56 +0000 | [diff] [blame] | 5067 | RefKind = ARMMCExpr::VK_ARM_LO16; |
Jason W Kim | 1f7bc07 | 2011-01-11 23:53:41 +0000 | [diff] [blame] | 5068 | } else if (IDVal == "upper16") { |
Evan Cheng | 965b3c7 | 2011-01-13 07:58:56 +0000 | [diff] [blame] | 5069 | RefKind = ARMMCExpr::VK_ARM_HI16; |
Jason W Kim | 1f7bc07 | 2011-01-11 23:53:41 +0000 | [diff] [blame] | 5070 | } else { |
| 5071 | Error(Parser.getTok().getLoc(), "unexpected prefix in operand"); |
| 5072 | return true; |
| 5073 | } |
| 5074 | Parser.Lex(); |
| 5075 | |
| 5076 | if (getLexer().isNot(AsmToken::Colon)) { |
| 5077 | Error(Parser.getTok().getLoc(), "unexpected token after prefix"); |
| 5078 | return true; |
| 5079 | } |
| 5080 | Parser.Lex(); // Eat the last ':' |
| 5081 | return false; |
| 5082 | } |
| 5083 | |
Daniel Dunbar | 9d944b3 | 2011-01-11 15:59:50 +0000 | [diff] [blame] | 5084 | /// \brief Given a mnemonic, split out possible predication code and carry |
| 5085 | /// setting letters to form a canonical mnemonic and flags. |
| 5086 | // |
Daniel Dunbar | 876bb018 | 2011-01-10 12:24:52 +0000 | [diff] [blame] | 5087 | // FIXME: Would be nice to autogen this. |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 5088 | // FIXME: This is a bit of a maze of special cases. |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 5089 | StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic, |
Jim Grosbach | 5cc3b4c | 2011-07-19 20:10:31 +0000 | [diff] [blame] | 5090 | unsigned &PredicationCode, |
| 5091 | bool &CarrySetting, |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 5092 | unsigned &ProcessorIMod, |
| 5093 | StringRef &ITMask) { |
Daniel Dunbar | 9d944b3 | 2011-01-11 15:59:50 +0000 | [diff] [blame] | 5094 | PredicationCode = ARMCC::AL; |
| 5095 | CarrySetting = false; |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 5096 | ProcessorIMod = 0; |
Daniel Dunbar | 9d944b3 | 2011-01-11 15:59:50 +0000 | [diff] [blame] | 5097 | |
Daniel Dunbar | 876bb018 | 2011-01-10 12:24:52 +0000 | [diff] [blame] | 5098 | // Ignore some mnemonics we know aren't predicated forms. |
Daniel Dunbar | 9d944b3 | 2011-01-11 15:59:50 +0000 | [diff] [blame] | 5099 | // |
| 5100 | // FIXME: Would be nice to autogen this. |
Jim Grosbach | 5cc3b4c | 2011-07-19 20:10:31 +0000 | [diff] [blame] | 5101 | if ((Mnemonic == "movs" && isThumb()) || |
| 5102 | Mnemonic == "teq" || Mnemonic == "vceq" || Mnemonic == "svc" || |
| 5103 | Mnemonic == "mls" || Mnemonic == "smmls" || Mnemonic == "vcls" || |
| 5104 | Mnemonic == "vmls" || Mnemonic == "vnmls" || Mnemonic == "vacge" || |
| 5105 | Mnemonic == "vcge" || Mnemonic == "vclt" || Mnemonic == "vacgt" || |
Richard Barton | 8d519fe | 2013-09-05 14:14:19 +0000 | [diff] [blame] | 5106 | Mnemonic == "vaclt" || Mnemonic == "vacle" || Mnemonic == "hlt" || |
Jim Grosbach | 5cc3b4c | 2011-07-19 20:10:31 +0000 | [diff] [blame] | 5107 | Mnemonic == "vcgt" || Mnemonic == "vcle" || Mnemonic == "smlal" || |
| 5108 | Mnemonic == "umaal" || Mnemonic == "umlal" || Mnemonic == "vabal" || |
Jim Grosbach | e16acac | 2011-12-19 19:43:50 +0000 | [diff] [blame] | 5109 | Mnemonic == "vmlal" || Mnemonic == "vpadal" || Mnemonic == "vqdmlal" || |
Joey Gouly | 2efaa73 | 2013-07-06 20:50:18 +0000 | [diff] [blame] | 5110 | Mnemonic == "fmuls" || Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || |
Joey Gouly | 0f12aa2 | 2013-07-09 11:26:18 +0000 | [diff] [blame] | 5111 | Mnemonic == "vcvta" || Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || |
| 5112 | Mnemonic == "vcvtm" || Mnemonic == "vrinta" || Mnemonic == "vrintn" || |
| 5113 | Mnemonic == "vrintp" || Mnemonic == "vrintm" || Mnemonic.startswith("vsel")) |
Daniel Dunbar | 9d944b3 | 2011-01-11 15:59:50 +0000 | [diff] [blame] | 5114 | return Mnemonic; |
Daniel Dunbar | 75d26be | 2010-08-11 06:37:16 +0000 | [diff] [blame] | 5115 | |
Jim Grosbach | a9a3f0a | 2011-07-11 17:09:57 +0000 | [diff] [blame] | 5116 | // First, split out any predication code. Ignore mnemonics we know aren't |
| 5117 | // 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] | 5118 | if (Mnemonic != "adcs" && Mnemonic != "bics" && Mnemonic != "movs" && |
Jim Grosbach | 0c398b9 | 2011-07-27 21:58:11 +0000 | [diff] [blame] | 5119 | Mnemonic != "muls" && Mnemonic != "smlals" && Mnemonic != "smulls" && |
Jim Grosbach | 3636be3 | 2011-08-22 23:55:58 +0000 | [diff] [blame] | 5120 | Mnemonic != "umlals" && Mnemonic != "umulls" && Mnemonic != "lsls" && |
Jim Grosbach | f6d5d60 | 2011-09-01 18:22:13 +0000 | [diff] [blame] | 5121 | Mnemonic != "sbcs" && Mnemonic != "rscs") { |
Jim Grosbach | a9a3f0a | 2011-07-11 17:09:57 +0000 | [diff] [blame] | 5122 | unsigned CC = StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2)) |
| 5123 | .Case("eq", ARMCC::EQ) |
| 5124 | .Case("ne", ARMCC::NE) |
| 5125 | .Case("hs", ARMCC::HS) |
| 5126 | .Case("cs", ARMCC::HS) |
| 5127 | .Case("lo", ARMCC::LO) |
| 5128 | .Case("cc", ARMCC::LO) |
| 5129 | .Case("mi", ARMCC::MI) |
| 5130 | .Case("pl", ARMCC::PL) |
| 5131 | .Case("vs", ARMCC::VS) |
| 5132 | .Case("vc", ARMCC::VC) |
| 5133 | .Case("hi", ARMCC::HI) |
| 5134 | .Case("ls", ARMCC::LS) |
| 5135 | .Case("ge", ARMCC::GE) |
| 5136 | .Case("lt", ARMCC::LT) |
| 5137 | .Case("gt", ARMCC::GT) |
| 5138 | .Case("le", ARMCC::LE) |
| 5139 | .Case("al", ARMCC::AL) |
| 5140 | .Default(~0U); |
| 5141 | if (CC != ~0U) { |
| 5142 | Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 2); |
| 5143 | PredicationCode = CC; |
| 5144 | } |
Bill Wendling | 193961b | 2010-10-29 23:50:21 +0000 | [diff] [blame] | 5145 | } |
Daniel Dunbar | 188b47b | 2010-08-11 06:37:20 +0000 | [diff] [blame] | 5146 | |
Daniel Dunbar | 9d944b3 | 2011-01-11 15:59:50 +0000 | [diff] [blame] | 5147 | // Next, determine if we have a carry setting bit. We explicitly ignore all |
| 5148 | // the instructions we know end in 's'. |
| 5149 | if (Mnemonic.endswith("s") && |
Jim Grosbach | d3e8e29 | 2011-08-17 22:49:09 +0000 | [diff] [blame] | 5150 | !(Mnemonic == "cps" || Mnemonic == "mls" || |
Jim Grosbach | 5cc3b4c | 2011-07-19 20:10:31 +0000 | [diff] [blame] | 5151 | Mnemonic == "mrs" || Mnemonic == "smmls" || Mnemonic == "vabs" || |
| 5152 | Mnemonic == "vcls" || Mnemonic == "vmls" || Mnemonic == "vmrs" || |
| 5153 | Mnemonic == "vnmls" || Mnemonic == "vqabs" || Mnemonic == "vrecps" || |
Jim Grosbach | 086d013 | 2011-12-08 00:49:29 +0000 | [diff] [blame] | 5154 | Mnemonic == "vrsqrts" || Mnemonic == "srs" || Mnemonic == "flds" || |
Jim Grosbach | 54337b8 | 2011-12-10 00:01:02 +0000 | [diff] [blame] | 5155 | Mnemonic == "fmrs" || Mnemonic == "fsqrts" || Mnemonic == "fsubs" || |
Jim Grosbach | 92a939a | 2011-12-19 19:02:41 +0000 | [diff] [blame] | 5156 | Mnemonic == "fsts" || Mnemonic == "fcpys" || Mnemonic == "fdivs" || |
Jim Grosbach | d74560b | 2012-03-15 20:48:18 +0000 | [diff] [blame] | 5157 | Mnemonic == "fmuls" || Mnemonic == "fcmps" || Mnemonic == "fcmpzs" || |
David Peixotto | a872e0e | 2014-01-07 18:19:23 +0000 | [diff] [blame] | 5158 | Mnemonic == "vfms" || Mnemonic == "vfnms" || Mnemonic == "fconsts" || |
Jim Grosbach | 51726e2 | 2011-07-29 20:26:09 +0000 | [diff] [blame] | 5159 | (Mnemonic == "movs" && isThumb()))) { |
Daniel Dunbar | 9d944b3 | 2011-01-11 15:59:50 +0000 | [diff] [blame] | 5160 | Mnemonic = Mnemonic.slice(0, Mnemonic.size() - 1); |
| 5161 | CarrySetting = true; |
| 5162 | } |
| 5163 | |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 5164 | // The "cps" instruction can have a interrupt mode operand which is glued into |
| 5165 | // the mnemonic. Check if this is the case, split it and parse the imod op |
| 5166 | if (Mnemonic.startswith("cps")) { |
| 5167 | // Split out any imod code. |
| 5168 | unsigned IMod = |
| 5169 | StringSwitch<unsigned>(Mnemonic.substr(Mnemonic.size()-2, 2)) |
| 5170 | .Case("ie", ARM_PROC::IE) |
| 5171 | .Case("id", ARM_PROC::ID) |
| 5172 | .Default(~0U); |
| 5173 | if (IMod != ~0U) { |
| 5174 | Mnemonic = Mnemonic.slice(0, Mnemonic.size()-2); |
| 5175 | ProcessorIMod = IMod; |
| 5176 | } |
| 5177 | } |
| 5178 | |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 5179 | // The "it" instruction has the condition mask on the end of the mnemonic. |
| 5180 | if (Mnemonic.startswith("it")) { |
| 5181 | ITMask = Mnemonic.slice(2, Mnemonic.size()); |
| 5182 | Mnemonic = Mnemonic.slice(0, 2); |
| 5183 | } |
| 5184 | |
Daniel Dunbar | 9d944b3 | 2011-01-11 15:59:50 +0000 | [diff] [blame] | 5185 | return Mnemonic; |
| 5186 | } |
Daniel Dunbar | 5a384c8 | 2011-01-11 15:59:53 +0000 | [diff] [blame] | 5187 | |
| 5188 | /// \brief Given a canonical mnemonic, determine if the instruction ever allows |
| 5189 | /// inclusion of carry set or predication code operands. |
| 5190 | // |
| 5191 | // FIXME: It would be nice to autogen this. |
Bruno Cardoso Lopes | e6290cc | 2011-01-18 20:55:11 +0000 | [diff] [blame] | 5192 | void ARMAsmParser:: |
Amara Emerson | 3308909 | 2013-09-19 11:59:01 +0000 | [diff] [blame] | 5193 | getMnemonicAcceptInfo(StringRef Mnemonic, StringRef FullInst, |
| 5194 | bool &CanAcceptCarrySet, bool &CanAcceptPredicationCode) { |
Daniel Dunbar | 0926412 | 2011-01-11 19:06:29 +0000 | [diff] [blame] | 5195 | if (Mnemonic == "and" || Mnemonic == "lsl" || Mnemonic == "lsr" || |
| 5196 | Mnemonic == "rrx" || Mnemonic == "ror" || Mnemonic == "sub" || |
Jim Grosbach | d73c645 | 2011-09-16 18:05:48 +0000 | [diff] [blame] | 5197 | Mnemonic == "add" || Mnemonic == "adc" || |
Daniel Dunbar | 0926412 | 2011-01-11 19:06:29 +0000 | [diff] [blame] | 5198 | Mnemonic == "mul" || Mnemonic == "bic" || Mnemonic == "asr" || |
Jim Grosbach | fc54518 | 2011-09-19 23:31:02 +0000 | [diff] [blame] | 5199 | Mnemonic == "orr" || Mnemonic == "mvn" || |
Daniel Dunbar | 0926412 | 2011-01-11 19:06:29 +0000 | [diff] [blame] | 5200 | Mnemonic == "rsb" || Mnemonic == "rsc" || Mnemonic == "orn" || |
Jim Grosbach | fc54518 | 2011-09-19 23:31:02 +0000 | [diff] [blame] | 5201 | Mnemonic == "sbc" || Mnemonic == "eor" || Mnemonic == "neg" || |
Evan Cheng | aca6c82 | 2012-04-11 00:13:00 +0000 | [diff] [blame] | 5202 | Mnemonic == "vfm" || Mnemonic == "vfnm" || |
Jim Grosbach | d73c645 | 2011-09-16 18:05:48 +0000 | [diff] [blame] | 5203 | (!isThumb() && (Mnemonic == "smull" || Mnemonic == "mov" || |
Jim Grosbach | fc54518 | 2011-09-19 23:31:02 +0000 | [diff] [blame] | 5204 | Mnemonic == "mla" || Mnemonic == "smlal" || |
| 5205 | Mnemonic == "umlal" || Mnemonic == "umull"))) { |
Daniel Dunbar | 0926412 | 2011-01-11 19:06:29 +0000 | [diff] [blame] | 5206 | CanAcceptCarrySet = true; |
Jim Grosbach | 6c45b75 | 2011-09-16 16:39:25 +0000 | [diff] [blame] | 5207 | } else |
Daniel Dunbar | 0926412 | 2011-01-11 19:06:29 +0000 | [diff] [blame] | 5208 | CanAcceptCarrySet = false; |
Daniel Dunbar | 5a384c8 | 2011-01-11 15:59:53 +0000 | [diff] [blame] | 5209 | |
Tim Northover | 2c45a38 | 2013-06-26 16:52:40 +0000 | [diff] [blame] | 5210 | if (Mnemonic == "bkpt" || Mnemonic == "cbnz" || Mnemonic == "setend" || |
| 5211 | Mnemonic == "cps" || Mnemonic == "it" || Mnemonic == "cbz" || |
Saleem Abdulrasool | 27351f2 | 2014-05-14 03:47:39 +0000 | [diff] [blame] | 5212 | Mnemonic == "trap" || Mnemonic == "hlt" || Mnemonic == "udf" || |
| 5213 | Mnemonic.startswith("crc32") || Mnemonic.startswith("cps") || |
| 5214 | Mnemonic.startswith("vsel") || |
Joey Gouly | 2d0175e | 2013-07-09 09:59:04 +0000 | [diff] [blame] | 5215 | Mnemonic == "vmaxnm" || Mnemonic == "vminnm" || Mnemonic == "vcvta" || |
Joey Gouly | 0f12aa2 | 2013-07-09 11:26:18 +0000 | [diff] [blame] | 5216 | Mnemonic == "vcvtn" || Mnemonic == "vcvtp" || Mnemonic == "vcvtm" || |
| 5217 | Mnemonic == "vrinta" || Mnemonic == "vrintn" || Mnemonic == "vrintp" || |
Amara Emerson | 3308909 | 2013-09-19 11:59:01 +0000 | [diff] [blame] | 5218 | Mnemonic == "vrintm" || Mnemonic.startswith("aes") || |
| 5219 | Mnemonic.startswith("sha1") || Mnemonic.startswith("sha256") || |
| 5220 | (FullInst.startswith("vmull") && FullInst.endswith(".p64"))) { |
Tim Northover | 2c45a38 | 2013-06-26 16:52:40 +0000 | [diff] [blame] | 5221 | // These mnemonics are never predicable |
Daniel Dunbar | 5a384c8 | 2011-01-11 15:59:53 +0000 | [diff] [blame] | 5222 | CanAcceptPredicationCode = false; |
Tim Northover | 2c45a38 | 2013-06-26 16:52:40 +0000 | [diff] [blame] | 5223 | } else if (!isThumb()) { |
| 5224 | // Some instructions are only predicable in Thumb mode |
| 5225 | CanAcceptPredicationCode |
| 5226 | = Mnemonic != "cdp2" && Mnemonic != "clrex" && Mnemonic != "mcr2" && |
| 5227 | Mnemonic != "mcrr2" && Mnemonic != "mrc2" && Mnemonic != "mrrc2" && |
| 5228 | Mnemonic != "dmb" && Mnemonic != "dsb" && Mnemonic != "isb" && |
| 5229 | Mnemonic != "pld" && Mnemonic != "pli" && Mnemonic != "pldw" && |
| 5230 | Mnemonic != "ldc2" && Mnemonic != "ldc2l" && |
| 5231 | Mnemonic != "stc2" && Mnemonic != "stc2l" && |
| 5232 | !Mnemonic.startswith("rfe") && !Mnemonic.startswith("srs"); |
| 5233 | } else if (isThumbOne()) { |
Tim Northover | f86d1f0 | 2013-10-07 11:10:47 +0000 | [diff] [blame] | 5234 | if (hasV6MOps()) |
| 5235 | CanAcceptPredicationCode = Mnemonic != "movs"; |
| 5236 | else |
| 5237 | CanAcceptPredicationCode = Mnemonic != "nop" && Mnemonic != "movs"; |
Jim Grosbach | 6c45b75 | 2011-09-16 16:39:25 +0000 | [diff] [blame] | 5238 | } else |
Daniel Dunbar | 5a384c8 | 2011-01-11 15:59:53 +0000 | [diff] [blame] | 5239 | CanAcceptPredicationCode = true; |
Daniel Dunbar | 876bb018 | 2011-01-10 12:24:52 +0000 | [diff] [blame] | 5240 | } |
| 5241 | |
Jim Grosbach | 7283da9 | 2011-08-16 21:12:37 +0000 | [diff] [blame] | 5242 | bool ARMAsmParser::shouldOmitCCOutOperand(StringRef Mnemonic, |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5243 | OperandVector &Operands) { |
Jim Grosbach | 1d3c137 | 2011-09-01 00:28:52 +0000 | [diff] [blame] | 5244 | // FIXME: This is all horribly hacky. We really need a better way to deal |
| 5245 | // with optional operands like this in the matcher table. |
Jim Grosbach | 7283da9 | 2011-08-16 21:12:37 +0000 | [diff] [blame] | 5246 | |
| 5247 | // The 'mov' mnemonic is special. One variant has a cc_out operand, while |
| 5248 | // another does not. Specifically, the MOVW instruction does not. So we |
| 5249 | // special case it here and remove the defaulted (non-setting) cc_out |
| 5250 | // operand if that's the instruction we're trying to match. |
| 5251 | // |
| 5252 | // We do this as post-processing of the explicit operands rather than just |
| 5253 | // conditionally adding the cc_out in the first place because we need |
| 5254 | // to check the type of the parsed immediate operand. |
Owen Anderson | d7791b9 | 2011-09-14 22:46:14 +0000 | [diff] [blame] | 5255 | if (Mnemonic == "mov" && Operands.size() > 4 && !isThumb() && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5256 | !static_cast<ARMOperand &>(*Operands[4]).isARMSOImm() && |
| 5257 | static_cast<ARMOperand &>(*Operands[4]).isImm0_65535Expr() && |
| 5258 | static_cast<ARMOperand &>(*Operands[1]).getReg() == 0) |
Jim Grosbach | 7283da9 | 2011-08-16 21:12:37 +0000 | [diff] [blame] | 5259 | return true; |
Jim Grosbach | 58ffdcc | 2011-08-16 21:34:08 +0000 | [diff] [blame] | 5260 | |
| 5261 | // Register-register 'add' for thumb does not have a cc_out operand |
| 5262 | // when there are only two register operands. |
| 5263 | if (isThumb() && Mnemonic == "add" && Operands.size() == 5 && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5264 | static_cast<ARMOperand &>(*Operands[3]).isReg() && |
| 5265 | static_cast<ARMOperand &>(*Operands[4]).isReg() && |
| 5266 | static_cast<ARMOperand &>(*Operands[1]).getReg() == 0) |
Jim Grosbach | 58ffdcc | 2011-08-16 21:34:08 +0000 | [diff] [blame] | 5267 | return true; |
Jim Grosbach | 0a0b307 | 2011-08-24 21:22:15 +0000 | [diff] [blame] | 5268 | // Register-register 'add' for thumb does not have a cc_out operand |
Jim Grosbach | 1d3c137 | 2011-09-01 00:28:52 +0000 | [diff] [blame] | 5269 | // when it's an ADD Rdm, SP, {Rdm|#imm0_255} instruction. We do |
| 5270 | // have to check the immediate range here since Thumb2 has a variant |
| 5271 | // that can handle a different range and has a cc_out operand. |
Jim Grosbach | d0c435c | 2011-09-16 22:58:42 +0000 | [diff] [blame] | 5272 | if (((isThumb() && Mnemonic == "add") || |
| 5273 | (isThumbTwo() && Mnemonic == "sub")) && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5274 | Operands.size() == 6 && static_cast<ARMOperand &>(*Operands[3]).isReg() && |
| 5275 | static_cast<ARMOperand &>(*Operands[4]).isReg() && |
| 5276 | static_cast<ARMOperand &>(*Operands[4]).getReg() == ARM::SP && |
| 5277 | static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 && |
| 5278 | ((Mnemonic == "add" && static_cast<ARMOperand &>(*Operands[5]).isReg()) || |
| 5279 | static_cast<ARMOperand &>(*Operands[5]).isImm0_1020s4())) |
Jim Grosbach | 0a0b307 | 2011-08-24 21:22:15 +0000 | [diff] [blame] | 5280 | return true; |
Jim Grosbach | d0c435c | 2011-09-16 22:58:42 +0000 | [diff] [blame] | 5281 | // For Thumb2, add/sub immediate does not have a cc_out operand for the |
| 5282 | // imm0_4095 variant. That's the least-preferred variant when |
Jim Grosbach | 1d3c137 | 2011-09-01 00:28:52 +0000 | [diff] [blame] | 5283 | // selecting via the generic "add" mnemonic, so to know that we |
| 5284 | // should remove the cc_out operand, we have to explicitly check that |
| 5285 | // it's not one of the other variants. Ugh. |
Jim Grosbach | d0c435c | 2011-09-16 22:58:42 +0000 | [diff] [blame] | 5286 | if (isThumbTwo() && (Mnemonic == "add" || Mnemonic == "sub") && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5287 | Operands.size() == 6 && static_cast<ARMOperand &>(*Operands[3]).isReg() && |
| 5288 | static_cast<ARMOperand &>(*Operands[4]).isReg() && |
| 5289 | static_cast<ARMOperand &>(*Operands[5]).isImm()) { |
Jim Grosbach | 1d3c137 | 2011-09-01 00:28:52 +0000 | [diff] [blame] | 5290 | // Nest conditions rather than one big 'if' statement for readability. |
| 5291 | // |
Jim Grosbach | 1d3c137 | 2011-09-01 00:28:52 +0000 | [diff] [blame] | 5292 | // If both registers are low, we're in an IT block, and the immediate is |
| 5293 | // in range, we should use encoding T1 instead, which has a cc_out. |
| 5294 | if (inITBlock() && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5295 | isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) && |
| 5296 | isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) && |
| 5297 | static_cast<ARMOperand &>(*Operands[5]).isImm0_7()) |
Jim Grosbach | 1d3c137 | 2011-09-01 00:28:52 +0000 | [diff] [blame] | 5298 | return false; |
Tilmann Scheller | ef5666f | 2013-07-03 20:38:01 +0000 | [diff] [blame] | 5299 | // Check against T3. If the second register is the PC, this is an |
| 5300 | // 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] | 5301 | if (static_cast<ARMOperand &>(*Operands[4]).getReg() != ARM::PC && |
| 5302 | static_cast<ARMOperand &>(*Operands[5]).isT2SOImm()) |
Tilmann Scheller | ef5666f | 2013-07-03 20:38:01 +0000 | [diff] [blame] | 5303 | return false; |
Jim Grosbach | 1d3c137 | 2011-09-01 00:28:52 +0000 | [diff] [blame] | 5304 | |
| 5305 | // Otherwise, we use encoding T4, which does not have a cc_out |
| 5306 | // operand. |
| 5307 | return true; |
| 5308 | } |
| 5309 | |
Jim Grosbach | 9c8b993 | 2011-09-14 21:00:40 +0000 | [diff] [blame] | 5310 | // The thumb2 multiply instruction doesn't have a CCOut register, so |
| 5311 | // if we have a "mul" mnemonic in Thumb mode, check if we'll be able to |
| 5312 | // use the 16-bit encoding or not. |
| 5313 | if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 6 && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5314 | static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 && |
| 5315 | static_cast<ARMOperand &>(*Operands[3]).isReg() && |
| 5316 | static_cast<ARMOperand &>(*Operands[4]).isReg() && |
| 5317 | static_cast<ARMOperand &>(*Operands[5]).isReg() && |
Jim Grosbach | 9c8b993 | 2011-09-14 21:00:40 +0000 | [diff] [blame] | 5318 | // If the registers aren't low regs, the destination reg isn't the |
| 5319 | // same as one of the source regs, or the cc_out operand is zero |
| 5320 | // outside of an IT block, we have to use the 32-bit encoding, so |
| 5321 | // remove the cc_out operand. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5322 | (!isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) || |
| 5323 | !isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) || |
| 5324 | !isARMLowRegister(static_cast<ARMOperand &>(*Operands[5]).getReg()) || |
| 5325 | !inITBlock() || (static_cast<ARMOperand &>(*Operands[3]).getReg() != |
| 5326 | static_cast<ARMOperand &>(*Operands[5]).getReg() && |
| 5327 | static_cast<ARMOperand &>(*Operands[3]).getReg() != |
| 5328 | static_cast<ARMOperand &>(*Operands[4]).getReg()))) |
Jim Grosbach | 9c8b993 | 2011-09-14 21:00:40 +0000 | [diff] [blame] | 5329 | return true; |
| 5330 | |
Jim Grosbach | efa7e95 | 2011-11-15 19:55:16 +0000 | [diff] [blame] | 5331 | // Also check the 'mul' syntax variant that doesn't specify an explicit |
| 5332 | // destination register. |
| 5333 | if (isThumbTwo() && Mnemonic == "mul" && Operands.size() == 5 && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5334 | static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 && |
| 5335 | static_cast<ARMOperand &>(*Operands[3]).isReg() && |
| 5336 | static_cast<ARMOperand &>(*Operands[4]).isReg() && |
Jim Grosbach | efa7e95 | 2011-11-15 19:55:16 +0000 | [diff] [blame] | 5337 | // If the registers aren't low regs or the cc_out operand is zero |
| 5338 | // outside of an IT block, we have to use the 32-bit encoding, so |
| 5339 | // remove the cc_out operand. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5340 | (!isARMLowRegister(static_cast<ARMOperand &>(*Operands[3]).getReg()) || |
| 5341 | !isARMLowRegister(static_cast<ARMOperand &>(*Operands[4]).getReg()) || |
Jim Grosbach | efa7e95 | 2011-11-15 19:55:16 +0000 | [diff] [blame] | 5342 | !inITBlock())) |
| 5343 | return true; |
| 5344 | |
Jim Grosbach | 9c8b993 | 2011-09-14 21:00:40 +0000 | [diff] [blame] | 5345 | |
Jim Grosbach | 1d3c137 | 2011-09-01 00:28:52 +0000 | [diff] [blame] | 5346 | |
Jim Grosbach | 4b701af | 2011-08-24 21:42:27 +0000 | [diff] [blame] | 5347 | // Register-register 'add/sub' for thumb does not have a cc_out operand |
| 5348 | // when it's an ADD/SUB SP, #imm. Be lenient on count since there's also |
| 5349 | // the "add/sub SP, SP, #imm" version. If the follow-up operands aren't |
| 5350 | // right, this will result in better diagnostics (which operand is off) |
| 5351 | // anyway. |
| 5352 | if (isThumb() && (Mnemonic == "add" || Mnemonic == "sub") && |
| 5353 | (Operands.size() == 5 || Operands.size() == 6) && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5354 | static_cast<ARMOperand &>(*Operands[3]).isReg() && |
| 5355 | static_cast<ARMOperand &>(*Operands[3]).getReg() == ARM::SP && |
| 5356 | static_cast<ARMOperand &>(*Operands[1]).getReg() == 0 && |
| 5357 | (static_cast<ARMOperand &>(*Operands[4]).isImm() || |
Jim Grosbach | df5a244 | 2012-04-10 17:31:55 +0000 | [diff] [blame] | 5358 | (Operands.size() == 6 && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5359 | static_cast<ARMOperand &>(*Operands[5]).isImm()))) |
Jim Grosbach | 0a0b307 | 2011-08-24 21:22:15 +0000 | [diff] [blame] | 5360 | return true; |
Jim Grosbach | 58ffdcc | 2011-08-16 21:34:08 +0000 | [diff] [blame] | 5361 | |
Jim Grosbach | 7283da9 | 2011-08-16 21:12:37 +0000 | [diff] [blame] | 5362 | return false; |
| 5363 | } |
| 5364 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5365 | bool ARMAsmParser::shouldOmitPredicateOperand(StringRef Mnemonic, |
| 5366 | OperandVector &Operands) { |
Joey Gouly | e860255 | 2013-07-19 16:34:16 +0000 | [diff] [blame] | 5367 | // VRINT{Z, R, X} have a predicate operand in VFP, but not in NEON |
| 5368 | unsigned RegIdx = 3; |
| 5369 | if ((Mnemonic == "vrintz" || Mnemonic == "vrintx" || Mnemonic == "vrintr") && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5370 | static_cast<ARMOperand &>(*Operands[2]).getToken() == ".f32") { |
| 5371 | if (static_cast<ARMOperand &>(*Operands[3]).isToken() && |
| 5372 | static_cast<ARMOperand &>(*Operands[3]).getToken() == ".f32") |
Joey Gouly | e860255 | 2013-07-19 16:34:16 +0000 | [diff] [blame] | 5373 | RegIdx = 4; |
| 5374 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5375 | if (static_cast<ARMOperand &>(*Operands[RegIdx]).isReg() && |
| 5376 | (ARMMCRegisterClasses[ARM::DPRRegClassID].contains( |
| 5377 | static_cast<ARMOperand &>(*Operands[RegIdx]).getReg()) || |
| 5378 | ARMMCRegisterClasses[ARM::QPRRegClassID].contains( |
| 5379 | static_cast<ARMOperand &>(*Operands[RegIdx]).getReg()))) |
Joey Gouly | e860255 | 2013-07-19 16:34:16 +0000 | [diff] [blame] | 5380 | return true; |
| 5381 | } |
Joey Gouly | f520d5e | 2013-07-19 16:45:16 +0000 | [diff] [blame] | 5382 | return false; |
Joey Gouly | e860255 | 2013-07-19 16:34:16 +0000 | [diff] [blame] | 5383 | } |
| 5384 | |
Jim Grosbach | 12952fe | 2011-11-11 23:08:10 +0000 | [diff] [blame] | 5385 | static bool isDataTypeToken(StringRef Tok) { |
| 5386 | return Tok == ".8" || Tok == ".16" || Tok == ".32" || Tok == ".64" || |
| 5387 | Tok == ".i8" || Tok == ".i16" || Tok == ".i32" || Tok == ".i64" || |
| 5388 | Tok == ".u8" || Tok == ".u16" || Tok == ".u32" || Tok == ".u64" || |
| 5389 | Tok == ".s8" || Tok == ".s16" || Tok == ".s32" || Tok == ".s64" || |
| 5390 | Tok == ".p8" || Tok == ".p16" || Tok == ".f32" || Tok == ".f64" || |
| 5391 | Tok == ".f" || Tok == ".d"; |
| 5392 | } |
| 5393 | |
| 5394 | // FIXME: This bit should probably be handled via an explicit match class |
| 5395 | // in the .td files that matches the suffix instead of having it be |
| 5396 | // a literal string token the way it is now. |
| 5397 | static bool doesIgnoreDataTypeSuffix(StringRef Mnemonic, StringRef DT) { |
| 5398 | return Mnemonic.startswith("vldm") || Mnemonic.startswith("vstm"); |
| 5399 | } |
Tim Northover | 26bb14e | 2014-08-18 11:49:42 +0000 | [diff] [blame] | 5400 | static void applyMnemonicAliases(StringRef &Mnemonic, uint64_t Features, |
Chad Rosier | 9f7a221 | 2013-04-18 22:35:36 +0000 | [diff] [blame] | 5401 | unsigned VariantID); |
Saleem Abdulrasool | e3a9dc1 | 2013-12-30 18:38:01 +0000 | [diff] [blame] | 5402 | |
| 5403 | static bool RequiresVFPRegListValidation(StringRef Inst, |
| 5404 | bool &AcceptSinglePrecisionOnly, |
| 5405 | bool &AcceptDoublePrecisionOnly) { |
| 5406 | if (Inst.size() < 7) |
| 5407 | return false; |
| 5408 | |
| 5409 | if (Inst.startswith("fldm") || Inst.startswith("fstm")) { |
| 5410 | StringRef AddressingMode = Inst.substr(4, 2); |
| 5411 | if (AddressingMode == "ia" || AddressingMode == "db" || |
| 5412 | AddressingMode == "ea" || AddressingMode == "fd") { |
| 5413 | AcceptSinglePrecisionOnly = Inst[6] == 's'; |
| 5414 | AcceptDoublePrecisionOnly = Inst[6] == 'd' || Inst[6] == 'x'; |
| 5415 | return true; |
| 5416 | } |
| 5417 | } |
| 5418 | |
| 5419 | return false; |
| 5420 | } |
| 5421 | |
Daniel Dunbar | 876bb018 | 2011-01-10 12:24:52 +0000 | [diff] [blame] | 5422 | /// Parse an arm instruction mnemonic followed by its operands. |
Chad Rosier | f0e8720 | 2012-10-25 20:41:34 +0000 | [diff] [blame] | 5423 | bool ARMAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name, |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5424 | SMLoc NameLoc, OperandVector &Operands) { |
Saleem Abdulrasool | 4da9c6e | 2013-12-29 17:58:35 +0000 | [diff] [blame] | 5425 | // FIXME: Can this be done via tablegen in some fashion? |
Saleem Abdulrasool | e3a9dc1 | 2013-12-30 18:38:01 +0000 | [diff] [blame] | 5426 | bool RequireVFPRegisterListCheck; |
Saleem Abdulrasool | 4da9c6e | 2013-12-29 17:58:35 +0000 | [diff] [blame] | 5427 | bool AcceptSinglePrecisionOnly; |
Saleem Abdulrasool | e3a9dc1 | 2013-12-30 18:38:01 +0000 | [diff] [blame] | 5428 | bool AcceptDoublePrecisionOnly; |
| 5429 | RequireVFPRegisterListCheck = |
| 5430 | RequiresVFPRegListValidation(Name, AcceptSinglePrecisionOnly, |
| 5431 | AcceptDoublePrecisionOnly); |
Saleem Abdulrasool | 4da9c6e | 2013-12-29 17:58:35 +0000 | [diff] [blame] | 5432 | |
Jim Grosbach | 8be2f65 | 2011-12-09 23:34:09 +0000 | [diff] [blame] | 5433 | // Apply mnemonic aliases before doing anything else, as the destination |
Saleem Abdulrasool | a1937cb | 2013-12-29 17:58:31 +0000 | [diff] [blame] | 5434 | // mnemonic may include suffices and we want to handle them normally. |
Jim Grosbach | 8be2f65 | 2011-12-09 23:34:09 +0000 | [diff] [blame] | 5435 | // The generic tblgen'erated code does this later, at the start of |
| 5436 | // MatchInstructionImpl(), but that's too late for aliases that include |
| 5437 | // any sort of suffix. |
Tim Northover | 26bb14e | 2014-08-18 11:49:42 +0000 | [diff] [blame] | 5438 | uint64_t AvailableFeatures = getAvailableFeatures(); |
Chad Rosier | 9f7a221 | 2013-04-18 22:35:36 +0000 | [diff] [blame] | 5439 | unsigned AssemblerDialect = getParser().getAssemblerDialect(); |
| 5440 | applyMnemonicAliases(Name, AvailableFeatures, AssemblerDialect); |
Jim Grosbach | 8be2f65 | 2011-12-09 23:34:09 +0000 | [diff] [blame] | 5441 | |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 5442 | // First check for the ARM-specific .req directive. |
| 5443 | if (Parser.getTok().is(AsmToken::Identifier) && |
| 5444 | Parser.getTok().getIdentifier() == ".req") { |
| 5445 | parseDirectiveReq(Name, NameLoc); |
| 5446 | // We always return 'error' for this, as we're done with this |
| 5447 | // statement and don't need to match the 'instruction." |
| 5448 | return true; |
| 5449 | } |
| 5450 | |
Daniel Dunbar | 876bb018 | 2011-01-10 12:24:52 +0000 | [diff] [blame] | 5451 | // Create the leading tokens for the mnemonic, split by '.' characters. |
| 5452 | size_t Start = 0, Next = Name.find('.'); |
Jim Grosbach | 7c09e3c | 2011-07-19 19:13:28 +0000 | [diff] [blame] | 5453 | StringRef Mnemonic = Name.slice(Start, Next); |
Daniel Dunbar | 876bb018 | 2011-01-10 12:24:52 +0000 | [diff] [blame] | 5454 | |
Daniel Dunbar | 9d944b3 | 2011-01-11 15:59:50 +0000 | [diff] [blame] | 5455 | // Split out the predication code and carry setting flag from the mnemonic. |
| 5456 | unsigned PredicationCode; |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 5457 | unsigned ProcessorIMod; |
Daniel Dunbar | 9d944b3 | 2011-01-11 15:59:50 +0000 | [diff] [blame] | 5458 | bool CarrySetting; |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 5459 | StringRef ITMask; |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 5460 | Mnemonic = splitMnemonic(Mnemonic, PredicationCode, CarrySetting, |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 5461 | ProcessorIMod, ITMask); |
Daniel Dunbar | 876bb018 | 2011-01-10 12:24:52 +0000 | [diff] [blame] | 5462 | |
Jim Grosbach | 1c171b1 | 2011-08-25 17:23:55 +0000 | [diff] [blame] | 5463 | // In Thumb1, only the branch (B) instruction can be predicated. |
| 5464 | if (isThumbOne() && PredicationCode != ARMCC::AL && Mnemonic != "b") { |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 5465 | Parser.eatToEndOfStatement(); |
Jim Grosbach | 1c171b1 | 2011-08-25 17:23:55 +0000 | [diff] [blame] | 5466 | return Error(NameLoc, "conditional execution not supported in Thumb1"); |
| 5467 | } |
| 5468 | |
Jim Grosbach | 7c09e3c | 2011-07-19 19:13:28 +0000 | [diff] [blame] | 5469 | Operands.push_back(ARMOperand::CreateToken(Mnemonic, NameLoc)); |
| 5470 | |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 5471 | // Handle the IT instruction ITMask. Convert it to a bitmask. This |
| 5472 | // is the mask as it will be for the IT encoding if the conditional |
| 5473 | // encoding has a '1' as it's bit0 (i.e. 't' ==> '1'). In the case |
| 5474 | // where the conditional bit0 is zero, the instruction post-processing |
| 5475 | // will adjust the mask accordingly. |
| 5476 | if (Mnemonic == "it") { |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5477 | SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + 2); |
| 5478 | if (ITMask.size() > 3) { |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 5479 | Parser.eatToEndOfStatement(); |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5480 | return Error(Loc, "too many conditions on IT instruction"); |
| 5481 | } |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 5482 | unsigned Mask = 8; |
| 5483 | for (unsigned i = ITMask.size(); i != 0; --i) { |
| 5484 | char pos = ITMask[i - 1]; |
| 5485 | if (pos != 't' && pos != 'e') { |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 5486 | Parser.eatToEndOfStatement(); |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5487 | return Error(Loc, "illegal IT block condition mask '" + ITMask + "'"); |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 5488 | } |
| 5489 | Mask >>= 1; |
| 5490 | if (ITMask[i - 1] == 't') |
| 5491 | Mask |= 8; |
| 5492 | } |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5493 | Operands.push_back(ARMOperand::CreateITMask(Mask, Loc)); |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 5494 | } |
| 5495 | |
Jim Grosbach | 7c09e3c | 2011-07-19 19:13:28 +0000 | [diff] [blame] | 5496 | // FIXME: This is all a pretty gross hack. We should automatically handle |
| 5497 | // optional operands like this via tblgen. |
Bill Wendling | 219dabd | 2010-11-21 10:56:05 +0000 | [diff] [blame] | 5498 | |
Daniel Dunbar | 5a384c8 | 2011-01-11 15:59:53 +0000 | [diff] [blame] | 5499 | // Next, add the CCOut and ConditionCode operands, if needed. |
| 5500 | // |
| 5501 | // For mnemonics which can ever incorporate a carry setting bit or predication |
| 5502 | // code, our matching model involves us always generating CCOut and |
| 5503 | // ConditionCode operands to match the mnemonic "as written" and then we let |
| 5504 | // the matcher deal with finding the right instruction or generating an |
| 5505 | // appropriate error. |
| 5506 | bool CanAcceptCarrySet, CanAcceptPredicationCode; |
Amara Emerson | 3308909 | 2013-09-19 11:59:01 +0000 | [diff] [blame] | 5507 | getMnemonicAcceptInfo(Mnemonic, Name, CanAcceptCarrySet, CanAcceptPredicationCode); |
Daniel Dunbar | 5a384c8 | 2011-01-11 15:59:53 +0000 | [diff] [blame] | 5508 | |
Jim Grosbach | 03a8a16 | 2011-07-14 22:04:21 +0000 | [diff] [blame] | 5509 | // If we had a carry-set on an instruction that can't do that, issue an |
| 5510 | // error. |
| 5511 | if (!CanAcceptCarrySet && CarrySetting) { |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 5512 | Parser.eatToEndOfStatement(); |
Jim Grosbach | 7c09e3c | 2011-07-19 19:13:28 +0000 | [diff] [blame] | 5513 | return Error(NameLoc, "instruction '" + Mnemonic + |
Jim Grosbach | 03a8a16 | 2011-07-14 22:04:21 +0000 | [diff] [blame] | 5514 | "' can not set flags, but 's' suffix specified"); |
| 5515 | } |
Jim Grosbach | 0a54770 | 2011-07-22 17:44:50 +0000 | [diff] [blame] | 5516 | // If we had a predication code on an instruction that can't do that, issue an |
| 5517 | // error. |
| 5518 | if (!CanAcceptPredicationCode && PredicationCode != ARMCC::AL) { |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 5519 | Parser.eatToEndOfStatement(); |
Jim Grosbach | 0a54770 | 2011-07-22 17:44:50 +0000 | [diff] [blame] | 5520 | return Error(NameLoc, "instruction '" + Mnemonic + |
| 5521 | "' is not predicable, but condition code specified"); |
| 5522 | } |
Jim Grosbach | 03a8a16 | 2011-07-14 22:04:21 +0000 | [diff] [blame] | 5523 | |
Daniel Dunbar | 5a384c8 | 2011-01-11 15:59:53 +0000 | [diff] [blame] | 5524 | // Add the carry setting operand, if necessary. |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5525 | if (CanAcceptCarrySet) { |
| 5526 | SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size()); |
Daniel Dunbar | 5a384c8 | 2011-01-11 15:59:53 +0000 | [diff] [blame] | 5527 | Operands.push_back(ARMOperand::CreateCCOut(CarrySetting ? ARM::CPSR : 0, |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5528 | Loc)); |
| 5529 | } |
Daniel Dunbar | 5a384c8 | 2011-01-11 15:59:53 +0000 | [diff] [blame] | 5530 | |
| 5531 | // Add the predication code operand, if necessary. |
| 5532 | if (CanAcceptPredicationCode) { |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5533 | SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Mnemonic.size() + |
| 5534 | CarrySetting); |
Daniel Dunbar | 5a384c8 | 2011-01-11 15:59:53 +0000 | [diff] [blame] | 5535 | Operands.push_back(ARMOperand::CreateCondCode( |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5536 | ARMCC::CondCodes(PredicationCode), Loc)); |
Daniel Dunbar | 876bb018 | 2011-01-10 12:24:52 +0000 | [diff] [blame] | 5537 | } |
Daniel Dunbar | 188b47b | 2010-08-11 06:37:20 +0000 | [diff] [blame] | 5538 | |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 5539 | // Add the processor imod operand, if necessary. |
| 5540 | if (ProcessorIMod) { |
| 5541 | Operands.push_back(ARMOperand::CreateImm( |
| 5542 | MCConstantExpr::Create(ProcessorIMod, getContext()), |
| 5543 | NameLoc, NameLoc)); |
Oliver Stannard | 1ae8b47 | 2014-09-24 14:20:01 +0000 | [diff] [blame] | 5544 | } else if (Mnemonic == "cps" && isMClass()) { |
| 5545 | return Error(NameLoc, "instruction 'cps' requires effect for M-class"); |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 5546 | } |
| 5547 | |
Daniel Dunbar | 188b47b | 2010-08-11 06:37:20 +0000 | [diff] [blame] | 5548 | // Add the remaining tokens in the mnemonic. |
Daniel Dunbar | 75d26be | 2010-08-11 06:37:16 +0000 | [diff] [blame] | 5549 | while (Next != StringRef::npos) { |
| 5550 | Start = Next; |
| 5551 | Next = Name.find('.', Start + 1); |
Bruno Cardoso Lopes | 90d1dfe | 2011-02-14 13:09:44 +0000 | [diff] [blame] | 5552 | StringRef ExtraToken = Name.slice(Start, Next); |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 5553 | |
Jim Grosbach | 12952fe | 2011-11-11 23:08:10 +0000 | [diff] [blame] | 5554 | // Some NEON instructions have an optional datatype suffix that is |
| 5555 | // completely ignored. Check for that. |
| 5556 | if (isDataTypeToken(ExtraToken) && |
| 5557 | doesIgnoreDataTypeSuffix(Mnemonic, ExtraToken)) |
| 5558 | continue; |
| 5559 | |
Kevin Enderby | c5d0935 | 2013-06-18 20:19:24 +0000 | [diff] [blame] | 5560 | // For for ARM mode generate an error if the .n qualifier is used. |
| 5561 | if (ExtraToken == ".n" && !isThumb()) { |
| 5562 | SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start); |
Saleem Abdulrasool | bdae4b8 | 2014-01-12 05:25:44 +0000 | [diff] [blame] | 5563 | Parser.eatToEndOfStatement(); |
Kevin Enderby | c5d0935 | 2013-06-18 20:19:24 +0000 | [diff] [blame] | 5564 | return Error(Loc, "instruction with .n (narrow) qualifier not allowed in " |
| 5565 | "arm mode"); |
| 5566 | } |
| 5567 | |
| 5568 | // The .n qualifier is always discarded as that is what the tables |
| 5569 | // and matcher expect. In ARM mode the .w qualifier has no effect, |
| 5570 | // so discard it to avoid errors that can be caused by the matcher. |
| 5571 | if (ExtraToken != ".n" && (isThumb() || ExtraToken != ".w")) { |
Jim Grosbach | 39c6e1d | 2011-09-07 16:06:04 +0000 | [diff] [blame] | 5572 | SMLoc Loc = SMLoc::getFromPointer(NameLoc.getPointer() + Start); |
| 5573 | Operands.push_back(ARMOperand::CreateToken(ExtraToken, Loc)); |
| 5574 | } |
Daniel Dunbar | 75d26be | 2010-08-11 06:37:16 +0000 | [diff] [blame] | 5575 | } |
| 5576 | |
| 5577 | // Read the remaining operands. |
| 5578 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 5579 | // Read the first operand. |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 5580 | if (parseOperand(Operands, Mnemonic)) { |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 5581 | Parser.eatToEndOfStatement(); |
Chris Lattner | a2a9d16 | 2010-09-11 16:18:25 +0000 | [diff] [blame] | 5582 | return true; |
| 5583 | } |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 5584 | |
| 5585 | while (getLexer().is(AsmToken::Comma)) { |
Sean Callanan | a83fd7d | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 5586 | Parser.Lex(); // Eat the comma. |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 5587 | |
| 5588 | // Parse and remember the operand. |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 5589 | if (parseOperand(Operands, Mnemonic)) { |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 5590 | Parser.eatToEndOfStatement(); |
Chris Lattner | a2a9d16 | 2010-09-11 16:18:25 +0000 | [diff] [blame] | 5591 | return true; |
| 5592 | } |
Kevin Enderby | febe39b | 2009-10-06 22:26:42 +0000 | [diff] [blame] | 5593 | } |
| 5594 | } |
Jim Grosbach | 624bcc7 | 2010-10-29 14:46:02 +0000 | [diff] [blame] | 5595 | |
Chris Lattner | a2a9d16 | 2010-09-11 16:18:25 +0000 | [diff] [blame] | 5596 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
Jim Grosbach | b8d9f51 | 2011-10-07 18:27:04 +0000 | [diff] [blame] | 5597 | SMLoc Loc = getLexer().getLoc(); |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 5598 | Parser.eatToEndOfStatement(); |
Jim Grosbach | b8d9f51 | 2011-10-07 18:27:04 +0000 | [diff] [blame] | 5599 | return Error(Loc, "unexpected token in argument list"); |
Chris Lattner | a2a9d16 | 2010-09-11 16:18:25 +0000 | [diff] [blame] | 5600 | } |
Bill Wendling | ee7f1f9 | 2010-11-06 21:42:12 +0000 | [diff] [blame] | 5601 | |
Chris Lattner | 91689c1 | 2010-09-08 05:10:46 +0000 | [diff] [blame] | 5602 | Parser.Lex(); // Consume the EndOfStatement |
Jim Grosbach | 7c09e3c | 2011-07-19 19:13:28 +0000 | [diff] [blame] | 5603 | |
Saleem Abdulrasool | e3a9dc1 | 2013-12-30 18:38:01 +0000 | [diff] [blame] | 5604 | if (RequireVFPRegisterListCheck) { |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5605 | ARMOperand &Op = static_cast<ARMOperand &>(*Operands.back()); |
| 5606 | if (AcceptSinglePrecisionOnly && !Op.isSPRRegList()) |
| 5607 | return Error(Op.getStartLoc(), |
Saleem Abdulrasool | aca443c | 2013-12-29 18:53:16 +0000 | [diff] [blame] | 5608 | "VFP/Neon single precision register expected"); |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5609 | if (AcceptDoublePrecisionOnly && !Op.isDPRRegList()) |
| 5610 | return Error(Op.getStartLoc(), |
Saleem Abdulrasool | aca443c | 2013-12-29 18:53:16 +0000 | [diff] [blame] | 5611 | "VFP/Neon double precision register expected"); |
Saleem Abdulrasool | 4da9c6e | 2013-12-29 17:58:35 +0000 | [diff] [blame] | 5612 | } |
| 5613 | |
Jim Grosbach | 7283da9 | 2011-08-16 21:12:37 +0000 | [diff] [blame] | 5614 | // Some instructions, mostly Thumb, have forms for the same mnemonic that |
| 5615 | // do and don't have a cc_out optional-def operand. With some spot-checks |
| 5616 | // 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] | 5617 | // parse and adjust accordingly before actually matching. We shouldn't ever |
| 5618 | // try to remove a cc_out operand that was explicitly set on the the |
| 5619 | // mnemonic, of course (CarrySetting == true). Reason number #317 the |
| 5620 | // table driven matcher doesn't fit well with the ARM instruction set. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5621 | if (!CarrySetting && shouldOmitCCOutOperand(Mnemonic, Operands)) |
Jim Grosbach | 7c09e3c | 2011-07-19 19:13:28 +0000 | [diff] [blame] | 5622 | Operands.erase(Operands.begin() + 1); |
Jim Grosbach | 7c09e3c | 2011-07-19 19:13:28 +0000 | [diff] [blame] | 5623 | |
Joey Gouly | e860255 | 2013-07-19 16:34:16 +0000 | [diff] [blame] | 5624 | // Some instructions have the same mnemonic, but don't always |
| 5625 | // have a predicate. Distinguish them here and delete the |
| 5626 | // predicate if needed. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5627 | if (shouldOmitPredicateOperand(Mnemonic, Operands)) |
Joey Gouly | e860255 | 2013-07-19 16:34:16 +0000 | [diff] [blame] | 5628 | Operands.erase(Operands.begin() + 1); |
Joey Gouly | e860255 | 2013-07-19 16:34:16 +0000 | [diff] [blame] | 5629 | |
Jim Grosbach | a03ab0e | 2011-07-28 21:57:55 +0000 | [diff] [blame] | 5630 | // ARM mode 'blx' need special handling, as the register operand version |
| 5631 | // is predicable, but the label operand version is not. So, we can't rely |
| 5632 | // on the Mnemonic based checking to correctly figure out when to put |
Jim Grosbach | 6e5778f | 2011-10-07 23:24:09 +0000 | [diff] [blame] | 5633 | // a k_CondCode operand in the list. If we're trying to match the label |
| 5634 | // version, remove the k_CondCode operand here. |
Jim Grosbach | a03ab0e | 2011-07-28 21:57:55 +0000 | [diff] [blame] | 5635 | if (!isThumb() && Mnemonic == "blx" && Operands.size() == 3 && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5636 | static_cast<ARMOperand &>(*Operands[2]).isImm()) |
Jim Grosbach | a03ab0e | 2011-07-28 21:57:55 +0000 | [diff] [blame] | 5637 | Operands.erase(Operands.begin() + 1); |
Jim Grosbach | 8cffa28 | 2011-08-11 23:51:13 +0000 | [diff] [blame] | 5638 | |
Weiming Zhao | 8f56f88 | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 5639 | // Adjust operands of ldrexd/strexd to MCK_GPRPair. |
| 5640 | // ldrexd/strexd require even/odd GPR pair. To enforce this constraint, |
| 5641 | // a single GPRPair reg operand is used in the .td file to replace the two |
| 5642 | // GPRs. However, when parsing from asm, the two GRPs cannot be automatically |
| 5643 | // expressed as a GPRPair, so we have to manually merge them. |
| 5644 | // FIXME: We would really like to be able to tablegen'erate this. |
| 5645 | if (!isThumb() && Operands.size() > 4 && |
Joey Gouly | e6d165c | 2013-08-27 17:38:16 +0000 | [diff] [blame] | 5646 | (Mnemonic == "ldrexd" || Mnemonic == "strexd" || Mnemonic == "ldaexd" || |
| 5647 | Mnemonic == "stlexd")) { |
| 5648 | bool isLoad = (Mnemonic == "ldrexd" || Mnemonic == "ldaexd"); |
Weiming Zhao | 8f56f88 | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 5649 | unsigned Idx = isLoad ? 2 : 3; |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5650 | ARMOperand &Op1 = static_cast<ARMOperand &>(*Operands[Idx]); |
| 5651 | ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[Idx + 1]); |
Weiming Zhao | 8f56f88 | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 5652 | |
| 5653 | const MCRegisterClass& MRC = MRI->getRegClass(ARM::GPRRegClassID); |
| 5654 | // Adjust only if Op1 and Op2 are GPRs. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5655 | if (Op1.isReg() && Op2.isReg() && MRC.contains(Op1.getReg()) && |
| 5656 | MRC.contains(Op2.getReg())) { |
| 5657 | unsigned Reg1 = Op1.getReg(); |
| 5658 | unsigned Reg2 = Op2.getReg(); |
Weiming Zhao | 8f56f88 | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 5659 | unsigned Rt = MRI->getEncodingValue(Reg1); |
| 5660 | unsigned Rt2 = MRI->getEncodingValue(Reg2); |
| 5661 | |
| 5662 | // Rt2 must be Rt + 1 and Rt must be even. |
| 5663 | if (Rt + 1 != Rt2 || (Rt & 1)) { |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5664 | Error(Op2.getStartLoc(), isLoad |
| 5665 | ? "destination operands must be sequential" |
| 5666 | : "source operands must be sequential"); |
Weiming Zhao | 8f56f88 | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 5667 | return true; |
| 5668 | } |
| 5669 | unsigned NewReg = MRI->getMatchingSuperReg(Reg1, ARM::gsub_0, |
| 5670 | &(MRI->getRegClass(ARM::GPRPairRegClassID))); |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5671 | Operands[Idx] = |
| 5672 | ARMOperand::CreateReg(NewReg, Op1.getStartLoc(), Op2.getEndLoc()); |
| 5673 | Operands.erase(Operands.begin() + Idx + 1); |
Weiming Zhao | 8f56f88 | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 5674 | } |
| 5675 | } |
| 5676 | |
Renato Golin | 36c626e | 2014-09-26 16:14:29 +0000 | [diff] [blame] | 5677 | // If first 2 operands of a 3 operand instruction are the same |
| 5678 | // then transform to 2 operand version of the same instruction |
| 5679 | // e.g. 'adds r0, r0, #1' transforms to 'adds r0, #1' |
| 5680 | // FIXME: We would really like to be able to tablegen'erate this. |
| 5681 | if (isThumbOne() && Operands.size() == 6 && |
| 5682 | (Mnemonic == "add" || Mnemonic == "sub" || Mnemonic == "and" || |
| 5683 | Mnemonic == "eor" || Mnemonic == "lsl" || Mnemonic == "lsr" || |
| 5684 | Mnemonic == "asr" || Mnemonic == "adc" || Mnemonic == "sbc" || |
| 5685 | Mnemonic == "ror" || Mnemonic == "orr" || Mnemonic == "bic")) { |
| 5686 | ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]); |
| 5687 | ARMOperand &Op4 = static_cast<ARMOperand &>(*Operands[4]); |
| 5688 | ARMOperand &Op5 = static_cast<ARMOperand &>(*Operands[5]); |
| 5689 | |
| 5690 | // If both registers are the same then remove one of them from |
| 5691 | // the operand list. |
| 5692 | if (Op3.isReg() && Op4.isReg() && Op3.getReg() == Op4.getReg()) { |
| 5693 | // If 3rd operand (variable Op5) is a register and the instruction is adds/sub |
| 5694 | // then do not transform as the backend already handles this instruction |
| 5695 | // correctly. |
| 5696 | if (!Op5.isReg() || !((Mnemonic == "add" && CarrySetting) || Mnemonic == "sub")) { |
| 5697 | Operands.erase(Operands.begin() + 3); |
| 5698 | if (Mnemonic == "add" && !CarrySetting) { |
| 5699 | // Special case for 'add' (not 'adds') instruction must |
| 5700 | // remove the CCOut operand as well. |
| 5701 | Operands.erase(Operands.begin() + 1); |
| 5702 | } |
| 5703 | } |
| 5704 | } |
| 5705 | } |
| 5706 | |
| 5707 | // If instruction is 'add' and first two register operands |
| 5708 | // use SP register, then remove one of the SP registers from |
| 5709 | // the instruction. |
| 5710 | // FIXME: We would really like to be able to tablegen'erate this. |
| 5711 | if (isThumbOne() && Operands.size() == 5 && Mnemonic == "add" && !CarrySetting) { |
| 5712 | ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[2]); |
| 5713 | ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]); |
| 5714 | if (Op2.isReg() && Op3.isReg() && Op2.getReg() == ARM::SP && Op3.getReg() == ARM::SP) { |
| 5715 | Operands.erase(Operands.begin() + 2); |
| 5716 | } |
| 5717 | } |
| 5718 | |
Saleem Abdulrasool | e6e6d71 | 2014-01-10 04:38:35 +0000 | [diff] [blame] | 5719 | // GNU Assembler extension (compatibility) |
Stepan Dyatkovskiy | 3f1fa3d | 2014-04-04 10:17:56 +0000 | [diff] [blame] | 5720 | if ((Mnemonic == "ldrd" || Mnemonic == "strd")) { |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5721 | ARMOperand &Op2 = static_cast<ARMOperand &>(*Operands[2]); |
| 5722 | ARMOperand &Op3 = static_cast<ARMOperand &>(*Operands[3]); |
| 5723 | if (Op3.isMem()) { |
| 5724 | assert(Op2.isReg() && "expected register argument"); |
Stepan Dyatkovskiy | 6207a4d | 2014-04-03 11:29:15 +0000 | [diff] [blame] | 5725 | |
Stepan Dyatkovskiy | 3f1fa3d | 2014-04-04 10:17:56 +0000 | [diff] [blame] | 5726 | unsigned SuperReg = MRI->getMatchingSuperReg( |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5727 | Op2.getReg(), ARM::gsub_0, &MRI->getRegClass(ARM::GPRPairRegClassID)); |
Stepan Dyatkovskiy | 6207a4d | 2014-04-03 11:29:15 +0000 | [diff] [blame] | 5728 | |
Stepan Dyatkovskiy | 3f1fa3d | 2014-04-04 10:17:56 +0000 | [diff] [blame] | 5729 | assert(SuperReg && "expected register pair"); |
Stepan Dyatkovskiy | 6207a4d | 2014-04-03 11:29:15 +0000 | [diff] [blame] | 5730 | |
Stepan Dyatkovskiy | 3f1fa3d | 2014-04-04 10:17:56 +0000 | [diff] [blame] | 5731 | unsigned PairedReg = MRI->getSubReg(SuperReg, ARM::gsub_1); |
Stepan Dyatkovskiy | 6207a4d | 2014-04-03 11:29:15 +0000 | [diff] [blame] | 5732 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5733 | Operands.insert( |
| 5734 | Operands.begin() + 3, |
| 5735 | ARMOperand::CreateReg(PairedReg, Op2.getStartLoc(), Op2.getEndLoc())); |
Stepan Dyatkovskiy | 3f1fa3d | 2014-04-04 10:17:56 +0000 | [diff] [blame] | 5736 | } |
Saleem Abdulrasool | e6e6d71 | 2014-01-10 04:38:35 +0000 | [diff] [blame] | 5737 | } |
| 5738 | |
Kevin Enderby | 78f9572 | 2013-07-31 21:05:30 +0000 | [diff] [blame] | 5739 | // FIXME: As said above, this is all a pretty gross hack. This instruction |
| 5740 | // does not fit with other "subs" and tblgen. |
| 5741 | // Adjust operands of B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction |
| 5742 | // so the Mnemonic is the original name "subs" and delete the predicate |
| 5743 | // operand so it will match the table entry. |
| 5744 | if (isThumbTwo() && Mnemonic == "sub" && Operands.size() == 6 && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5745 | static_cast<ARMOperand &>(*Operands[3]).isReg() && |
| 5746 | static_cast<ARMOperand &>(*Operands[3]).getReg() == ARM::PC && |
| 5747 | static_cast<ARMOperand &>(*Operands[4]).isReg() && |
| 5748 | static_cast<ARMOperand &>(*Operands[4]).getReg() == ARM::LR && |
| 5749 | static_cast<ARMOperand &>(*Operands[5]).isImm()) { |
| 5750 | Operands.front() = ARMOperand::CreateToken(Name, NameLoc); |
Kevin Enderby | 78f9572 | 2013-07-31 21:05:30 +0000 | [diff] [blame] | 5751 | Operands.erase(Operands.begin() + 1); |
Kevin Enderby | 78f9572 | 2013-07-31 21:05:30 +0000 | [diff] [blame] | 5752 | } |
Chris Lattner | f29c0b6 | 2010-01-14 22:21:20 +0000 | [diff] [blame] | 5753 | return false; |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 5754 | } |
| 5755 | |
Jim Grosbach | edaa35a | 2011-07-26 18:25:39 +0000 | [diff] [blame] | 5756 | // Validate context-sensitive operand constraints. |
Jim Grosbach | 169b2be | 2011-08-23 18:13:04 +0000 | [diff] [blame] | 5757 | |
| 5758 | // return 'true' if register list contains non-low GPR registers, |
| 5759 | // 'false' otherwise. If Reg is in the register list or is HiReg, set |
| 5760 | // 'containsReg' to true. |
| 5761 | static bool checkLowRegisterList(MCInst Inst, unsigned OpNo, unsigned Reg, |
| 5762 | unsigned HiReg, bool &containsReg) { |
| 5763 | containsReg = false; |
| 5764 | for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) { |
| 5765 | unsigned OpReg = Inst.getOperand(i).getReg(); |
| 5766 | if (OpReg == Reg) |
| 5767 | containsReg = true; |
| 5768 | // Anything other than a low register isn't legal here. |
| 5769 | if (!isARMLowRegister(OpReg) && (!HiReg || OpReg != HiReg)) |
| 5770 | return true; |
| 5771 | } |
| 5772 | return false; |
| 5773 | } |
| 5774 | |
Jim Grosbach | a31f223 | 2011-09-07 18:05:34 +0000 | [diff] [blame] | 5775 | // Check if the specified regisgter is in the register list of the inst, |
| 5776 | // starting at the indicated operand number. |
| 5777 | static bool listContainsReg(MCInst &Inst, unsigned OpNo, unsigned Reg) { |
| 5778 | for (unsigned i = OpNo; i < Inst.getNumOperands(); ++i) { |
| 5779 | unsigned OpReg = Inst.getOperand(i).getReg(); |
| 5780 | if (OpReg == Reg) |
| 5781 | return true; |
| 5782 | } |
| 5783 | return false; |
| 5784 | } |
| 5785 | |
Richard Barton | 8d519fe | 2013-09-05 14:14:19 +0000 | [diff] [blame] | 5786 | // Return true if instruction has the interesting property of being |
| 5787 | // allowed in IT blocks, but not being predicable. |
| 5788 | static bool instIsBreakpoint(const MCInst &Inst) { |
| 5789 | return Inst.getOpcode() == ARM::tBKPT || |
| 5790 | Inst.getOpcode() == ARM::BKPT || |
| 5791 | Inst.getOpcode() == ARM::tHLT || |
| 5792 | Inst.getOpcode() == ARM::HLT; |
| 5793 | |
| 5794 | } |
| 5795 | |
Jim Grosbach | edaa35a | 2011-07-26 18:25:39 +0000 | [diff] [blame] | 5796 | // FIXME: We would really like to be able to tablegen'erate this. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5797 | bool ARMAsmParser::validateInstruction(MCInst &Inst, |
| 5798 | const OperandVector &Operands) { |
Joey Gouly | 0e76fa7 | 2013-09-12 10:28:05 +0000 | [diff] [blame] | 5799 | const MCInstrDesc &MCID = MII.get(Inst.getOpcode()); |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5800 | SMLoc Loc = Operands[0]->getStartLoc(); |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 5801 | |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5802 | // Check the IT block state first. |
Richard Barton | 8d519fe | 2013-09-05 14:14:19 +0000 | [diff] [blame] | 5803 | // NOTE: BKPT and HLT instructions have the interesting property of being |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 5804 | // allowed in IT blocks, but not being predicable. They just always execute. |
Richard Barton | 8d519fe | 2013-09-05 14:14:19 +0000 | [diff] [blame] | 5805 | if (inITBlock() && !instIsBreakpoint(Inst)) { |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 5806 | unsigned Bit = 1; |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5807 | if (ITState.FirstCond) |
| 5808 | ITState.FirstCond = false; |
| 5809 | else |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 5810 | Bit = (ITState.Mask >> (5 - ITState.CurPosition)) & 1; |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5811 | // The instruction must be predicable. |
| 5812 | if (!MCID.isPredicable()) |
| 5813 | return Error(Loc, "instructions in IT block must be predicable"); |
| 5814 | unsigned Cond = Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm(); |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 5815 | unsigned ITCond = Bit ? ITState.Cond : |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5816 | ARMCC::getOppositeCondition(ITState.Cond); |
| 5817 | if (Cond != ITCond) { |
| 5818 | // Find the condition code Operand to get its SMLoc information. |
| 5819 | SMLoc CondLoc; |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 5820 | for (unsigned I = 1; I < Operands.size(); ++I) |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5821 | if (static_cast<ARMOperand &>(*Operands[I]).isCondCode()) |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 5822 | CondLoc = Operands[I]->getStartLoc(); |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5823 | return Error(CondLoc, "incorrect condition in IT block; got '" + |
| 5824 | StringRef(ARMCondCodeToString(ARMCC::CondCodes(Cond))) + |
| 5825 | "', but expected '" + |
| 5826 | ARMCondCodeToString(ARMCC::CondCodes(ITCond)) + "'"); |
| 5827 | } |
Jim Grosbach | c61fc8f | 2011-08-31 18:29:05 +0000 | [diff] [blame] | 5828 | // Check for non-'al' condition codes outside of the IT block. |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5829 | } else if (isThumbTwo() && MCID.isPredicable() && |
| 5830 | Inst.getOperand(MCID.findFirstPredOperandIdx()).getImm() != |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 5831 | ARMCC::AL && Inst.getOpcode() != ARM::tBcc && |
| 5832 | Inst.getOpcode() != ARM::t2Bcc) |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 5833 | return Error(Loc, "predicated instructions must be in IT block"); |
| 5834 | |
Tilmann Scheller | 255722b | 2013-09-30 16:11:48 +0000 | [diff] [blame] | 5835 | const unsigned Opcode = Inst.getOpcode(); |
| 5836 | switch (Opcode) { |
Jim Grosbach | 5b96b80 | 2011-08-10 20:29:19 +0000 | [diff] [blame] | 5837 | case ARM::LDRD: |
| 5838 | case ARM::LDRD_PRE: |
Weiming Zhao | 8f56f88 | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 5839 | case ARM::LDRD_POST: { |
Tilmann Scheller | 255722b | 2013-09-30 16:11:48 +0000 | [diff] [blame] | 5840 | const unsigned RtReg = Inst.getOperand(0).getReg(); |
| 5841 | |
Tilmann Scheller | 1aebfa0 | 2013-09-27 13:28:17 +0000 | [diff] [blame] | 5842 | // Rt can't be R14. |
| 5843 | if (RtReg == ARM::LR) |
| 5844 | return Error(Operands[3]->getStartLoc(), |
| 5845 | "Rt can't be R14"); |
Tilmann Scheller | 255722b | 2013-09-30 16:11:48 +0000 | [diff] [blame] | 5846 | |
| 5847 | const unsigned Rt = MRI->getEncodingValue(RtReg); |
Tilmann Scheller | 1aebfa0 | 2013-09-27 13:28:17 +0000 | [diff] [blame] | 5848 | // Rt must be even-numbered. |
| 5849 | if ((Rt & 1) == 1) |
| 5850 | return Error(Operands[3]->getStartLoc(), |
| 5851 | "Rt must be even-numbered"); |
Tilmann Scheller | 255722b | 2013-09-30 16:11:48 +0000 | [diff] [blame] | 5852 | |
Jim Grosbach | edaa35a | 2011-07-26 18:25:39 +0000 | [diff] [blame] | 5853 | // Rt2 must be Rt + 1. |
Tilmann Scheller | 255722b | 2013-09-30 16:11:48 +0000 | [diff] [blame] | 5854 | const unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg()); |
Jim Grosbach | edaa35a | 2011-07-26 18:25:39 +0000 | [diff] [blame] | 5855 | if (Rt2 != Rt + 1) |
| 5856 | return Error(Operands[3]->getStartLoc(), |
| 5857 | "destination operands must be sequential"); |
Tilmann Scheller | 255722b | 2013-09-30 16:11:48 +0000 | [diff] [blame] | 5858 | |
| 5859 | if (Opcode == ARM::LDRD_PRE || Opcode == ARM::LDRD_POST) { |
| 5860 | const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(3).getReg()); |
| 5861 | // For addressing modes with writeback, the base register needs to be |
| 5862 | // different from the destination registers. |
| 5863 | if (Rn == Rt || Rn == Rt2) |
| 5864 | return Error(Operands[3]->getStartLoc(), |
| 5865 | "base register needs to be different from destination " |
| 5866 | "registers"); |
| 5867 | } |
| 5868 | |
Jim Grosbach | edaa35a | 2011-07-26 18:25:39 +0000 | [diff] [blame] | 5869 | return false; |
| 5870 | } |
Tilmann Scheller | 88c8f16 | 2013-09-27 10:30:18 +0000 | [diff] [blame] | 5871 | case ARM::t2LDRDi8: |
| 5872 | case ARM::t2LDRD_PRE: |
| 5873 | case ARM::t2LDRD_POST: { |
Tilmann Scheller | 041f717 | 2013-09-27 10:38:11 +0000 | [diff] [blame] | 5874 | // Rt2 must be different from Rt. |
Tilmann Scheller | 88c8f16 | 2013-09-27 10:30:18 +0000 | [diff] [blame] | 5875 | unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg()); |
| 5876 | unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg()); |
| 5877 | if (Rt2 == Rt) |
| 5878 | return Error(Operands[3]->getStartLoc(), |
| 5879 | "destination operands can't be identical"); |
| 5880 | return false; |
| 5881 | } |
Jim Grosbach | eb09f49 | 2011-08-11 20:28:23 +0000 | [diff] [blame] | 5882 | case ARM::STRD: { |
| 5883 | // Rt2 must be Rt + 1. |
Eric Christopher | 6ac277c | 2012-08-09 22:10:21 +0000 | [diff] [blame] | 5884 | unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg()); |
| 5885 | unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(1).getReg()); |
Jim Grosbach | eb09f49 | 2011-08-11 20:28:23 +0000 | [diff] [blame] | 5886 | if (Rt2 != Rt + 1) |
| 5887 | return Error(Operands[3]->getStartLoc(), |
| 5888 | "source operands must be sequential"); |
| 5889 | return false; |
| 5890 | } |
Jim Grosbach | f7164b2 | 2011-08-10 20:49:18 +0000 | [diff] [blame] | 5891 | case ARM::STRD_PRE: |
Weiming Zhao | 8f56f88 | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 5892 | case ARM::STRD_POST: { |
Jim Grosbach | edaa35a | 2011-07-26 18:25:39 +0000 | [diff] [blame] | 5893 | // Rt2 must be Rt + 1. |
Eric Christopher | 6ac277c | 2012-08-09 22:10:21 +0000 | [diff] [blame] | 5894 | unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg()); |
| 5895 | unsigned Rt2 = MRI->getEncodingValue(Inst.getOperand(2).getReg()); |
Jim Grosbach | edaa35a | 2011-07-26 18:25:39 +0000 | [diff] [blame] | 5896 | if (Rt2 != Rt + 1) |
Jim Grosbach | eb09f49 | 2011-08-11 20:28:23 +0000 | [diff] [blame] | 5897 | return Error(Operands[3]->getStartLoc(), |
Jim Grosbach | edaa35a | 2011-07-26 18:25:39 +0000 | [diff] [blame] | 5898 | "source operands must be sequential"); |
| 5899 | return false; |
| 5900 | } |
Tilmann Scheller | 3352a58 | 2014-07-23 12:38:17 +0000 | [diff] [blame] | 5901 | case ARM::STR_PRE_IMM: |
| 5902 | case ARM::STR_PRE_REG: |
| 5903 | case ARM::STR_POST_IMM: |
Tilmann Scheller | 2727279 | 2014-07-23 13:03:47 +0000 | [diff] [blame] | 5904 | case ARM::STR_POST_REG: |
Tilmann Scheller | 96ef72e | 2014-07-24 09:55:46 +0000 | [diff] [blame] | 5905 | case ARM::STRH_PRE: |
| 5906 | case ARM::STRH_POST: |
Tilmann Scheller | 2727279 | 2014-07-23 13:03:47 +0000 | [diff] [blame] | 5907 | case ARM::STRB_PRE_IMM: |
| 5908 | case ARM::STRB_PRE_REG: |
| 5909 | case ARM::STRB_POST_IMM: |
| 5910 | case ARM::STRB_POST_REG: { |
Tilmann Scheller | 3352a58 | 2014-07-23 12:38:17 +0000 | [diff] [blame] | 5911 | // Rt must be different from Rn. |
| 5912 | const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(1).getReg()); |
| 5913 | const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(2).getReg()); |
| 5914 | |
| 5915 | if (Rt == Rn) |
| 5916 | return Error(Operands[3]->getStartLoc(), |
| 5917 | "source register and base register can't be identical"); |
| 5918 | return false; |
| 5919 | } |
Tilmann Scheller | 8ba7430 | 2014-08-01 11:08:51 +0000 | [diff] [blame] | 5920 | case ARM::LDR_PRE_IMM: |
| 5921 | case ARM::LDR_PRE_REG: |
| 5922 | case ARM::LDR_POST_IMM: |
Tilmann Scheller | 8ff079c | 2014-08-01 11:33:47 +0000 | [diff] [blame] | 5923 | case ARM::LDR_POST_REG: |
| 5924 | case ARM::LDRH_PRE: |
| 5925 | case ARM::LDRH_POST: |
| 5926 | case ARM::LDRSH_PRE: |
Tilmann Scheller | 7cc0ed4 | 2014-08-01 12:08:04 +0000 | [diff] [blame] | 5927 | case ARM::LDRSH_POST: |
| 5928 | case ARM::LDRB_PRE_IMM: |
| 5929 | case ARM::LDRB_PRE_REG: |
| 5930 | case ARM::LDRB_POST_IMM: |
| 5931 | case ARM::LDRB_POST_REG: |
| 5932 | case ARM::LDRSB_PRE: |
| 5933 | case ARM::LDRSB_POST: { |
Tilmann Scheller | 8ba7430 | 2014-08-01 11:08:51 +0000 | [diff] [blame] | 5934 | // Rt must be different from Rn. |
| 5935 | const unsigned Rt = MRI->getEncodingValue(Inst.getOperand(0).getReg()); |
| 5936 | const unsigned Rn = MRI->getEncodingValue(Inst.getOperand(2).getReg()); |
| 5937 | |
| 5938 | if (Rt == Rn) |
| 5939 | return Error(Operands[3]->getStartLoc(), |
| 5940 | "destination register and base register can't be identical"); |
| 5941 | return false; |
| 5942 | } |
Jim Grosbach | 03f56d9 | 2011-07-27 21:09:25 +0000 | [diff] [blame] | 5943 | case ARM::SBFX: |
| 5944 | case ARM::UBFX: { |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 5945 | // Width must be in range [1, 32-lsb]. |
| 5946 | unsigned LSB = Inst.getOperand(2).getImm(); |
| 5947 | unsigned Widthm1 = Inst.getOperand(3).getImm(); |
| 5948 | if (Widthm1 >= 32 - LSB) |
Jim Grosbach | 03f56d9 | 2011-07-27 21:09:25 +0000 | [diff] [blame] | 5949 | return Error(Operands[5]->getStartLoc(), |
| 5950 | "bitfield width must be in range [1,32-lsb]"); |
Jim Grosbach | 64610e5 | 2011-08-16 21:42:31 +0000 | [diff] [blame] | 5951 | return false; |
Jim Grosbach | 03f56d9 | 2011-07-27 21:09:25 +0000 | [diff] [blame] | 5952 | } |
Tim Northover | 08a8660 | 2013-10-22 19:00:39 +0000 | [diff] [blame] | 5953 | // Notionally handles ARM::tLDMIA_UPD too. |
Jim Grosbach | 90103cc | 2011-08-18 21:50:53 +0000 | [diff] [blame] | 5954 | case ARM::tLDMIA: { |
Jim Grosbach | a31f223 | 2011-09-07 18:05:34 +0000 | [diff] [blame] | 5955 | // If we're parsing Thumb2, the .w variant is available and handles |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 5956 | // most cases that are normally illegal for a Thumb1 LDM instruction. |
| 5957 | // We'll make the transformation in processInstruction() if necessary. |
Jim Grosbach | a31f223 | 2011-09-07 18:05:34 +0000 | [diff] [blame] | 5958 | // |
Sylvestre Ledru | 91ce36c | 2012-09-27 10:14:43 +0000 | [diff] [blame] | 5959 | // Thumb LDM instructions are writeback iff the base register is not |
Jim Grosbach | 90103cc | 2011-08-18 21:50:53 +0000 | [diff] [blame] | 5960 | // in the register list. |
| 5961 | unsigned Rn = Inst.getOperand(0).getReg(); |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 5962 | bool HasWritebackToken = |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 5963 | (static_cast<ARMOperand &>(*Operands[3]).isToken() && |
| 5964 | static_cast<ARMOperand &>(*Operands[3]).getToken() == "!"); |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 5965 | bool ListContainsBase; |
| 5966 | if (checkLowRegisterList(Inst, 3, Rn, 0, ListContainsBase) && !isThumbTwo()) |
| 5967 | return Error(Operands[3 + HasWritebackToken]->getStartLoc(), |
Jim Grosbach | 169b2be | 2011-08-23 18:13:04 +0000 | [diff] [blame] | 5968 | "registers must be in range r0-r7"); |
Jim Grosbach | 90103cc | 2011-08-18 21:50:53 +0000 | [diff] [blame] | 5969 | // If we should have writeback, then there should be a '!' token. |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 5970 | if (!ListContainsBase && !HasWritebackToken && !isThumbTwo()) |
Jim Grosbach | 90103cc | 2011-08-18 21:50:53 +0000 | [diff] [blame] | 5971 | return Error(Operands[2]->getStartLoc(), |
| 5972 | "writeback operator '!' expected"); |
Jim Grosbach | a31f223 | 2011-09-07 18:05:34 +0000 | [diff] [blame] | 5973 | // If we should not have writeback, there must not be a '!'. This is |
| 5974 | // true even for the 32-bit wide encodings. |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 5975 | if (ListContainsBase && HasWritebackToken) |
Jim Grosbach | 139acd2 | 2011-08-22 23:01:07 +0000 | [diff] [blame] | 5976 | return Error(Operands[3]->getStartLoc(), |
| 5977 | "writeback operator '!' not allowed when base register " |
| 5978 | "in register list"); |
Jyoti Allur | 3b68607 | 2014-10-22 10:41:14 +0000 | [diff] [blame^] | 5979 | if (listContainsReg(Inst, 3 + HasWritebackToken, ARM::SP)) |
| 5980 | return Error(Operands[3 + HasWritebackToken]->getStartLoc(), |
| 5981 | "SP not allowed in register list"); |
Jim Grosbach | 90103cc | 2011-08-18 21:50:53 +0000 | [diff] [blame] | 5982 | break; |
| 5983 | } |
Tim Northover | 08a8660 | 2013-10-22 19:00:39 +0000 | [diff] [blame] | 5984 | case ARM::LDMIA_UPD: |
| 5985 | case ARM::LDMDB_UPD: |
| 5986 | case ARM::LDMIB_UPD: |
| 5987 | case ARM::LDMDA_UPD: |
| 5988 | // ARM variants loading and updating the same register are only officially |
| 5989 | // UNPREDICTABLE on v7 upwards. Goodness knows what they did before. |
| 5990 | if (!hasV7Ops()) |
| 5991 | break; |
Jyoti Allur | 3b68607 | 2014-10-22 10:41:14 +0000 | [diff] [blame^] | 5992 | if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg())) |
| 5993 | return Error(Operands.back()->getStartLoc(), |
| 5994 | "writeback register not allowed in register list"); |
| 5995 | break; |
| 5996 | case ARM::t2LDMIA: |
| 5997 | case ARM::t2LDMDB: |
| 5998 | case ARM::t2STMIA: |
| 5999 | case ARM::t2STMDB: { |
| 6000 | if (listContainsReg(Inst, 3, ARM::SP)) |
| 6001 | return Error(Operands.back()->getStartLoc(), |
| 6002 | "SP not allowed in register list"); |
| 6003 | break; |
| 6004 | } |
Tim Northover | 08a8660 | 2013-10-22 19:00:39 +0000 | [diff] [blame] | 6005 | case ARM::t2LDMIA_UPD: |
| 6006 | case ARM::t2LDMDB_UPD: |
| 6007 | case ARM::t2STMIA_UPD: |
| 6008 | case ARM::t2STMDB_UPD: { |
Jim Grosbach | a31f223 | 2011-09-07 18:05:34 +0000 | [diff] [blame] | 6009 | if (listContainsReg(Inst, 3, Inst.getOperand(0).getReg())) |
Tim Northover | 741e6ef | 2013-10-24 09:37:18 +0000 | [diff] [blame] | 6010 | return Error(Operands.back()->getStartLoc(), |
| 6011 | "writeback register not allowed in register list"); |
Jyoti Allur | 3b68607 | 2014-10-22 10:41:14 +0000 | [diff] [blame^] | 6012 | |
| 6013 | if (listContainsReg(Inst, 4, ARM::SP)) |
| 6014 | return Error(Operands.back()->getStartLoc(), |
| 6015 | "SP not allowed in register list"); |
Jim Grosbach | a31f223 | 2011-09-07 18:05:34 +0000 | [diff] [blame] | 6016 | break; |
| 6017 | } |
Tim Northover | 8eaf154 | 2013-11-12 21:32:41 +0000 | [diff] [blame] | 6018 | case ARM::sysLDMIA_UPD: |
| 6019 | case ARM::sysLDMDA_UPD: |
| 6020 | case ARM::sysLDMDB_UPD: |
| 6021 | case ARM::sysLDMIB_UPD: |
| 6022 | if (!listContainsReg(Inst, 3, ARM::PC)) |
| 6023 | return Error(Operands[4]->getStartLoc(), |
| 6024 | "writeback register only allowed on system LDM " |
| 6025 | "if PC in register-list"); |
| 6026 | break; |
| 6027 | case ARM::sysSTMIA_UPD: |
| 6028 | case ARM::sysSTMDA_UPD: |
| 6029 | case ARM::sysSTMDB_UPD: |
| 6030 | case ARM::sysSTMIB_UPD: |
| 6031 | return Error(Operands[2]->getStartLoc(), |
| 6032 | "system STM cannot have writeback register"); |
Chad Rosier | 8513ffb | 2012-08-30 23:20:38 +0000 | [diff] [blame] | 6033 | case ARM::tMUL: { |
| 6034 | // The second source operand must be the same register as the destination |
| 6035 | // operand. |
Chad Rosier | 9d1fc36 | 2012-08-31 17:24:10 +0000 | [diff] [blame] | 6036 | // |
| 6037 | // In this case, we must directly check the parsed operands because the |
| 6038 | // cvtThumbMultiply() function is written in such a way that it guarantees |
| 6039 | // this first statement is always true for the new Inst. Essentially, the |
| 6040 | // destination is unconditionally copied into the second source operand |
| 6041 | // without checking to see if it matches what we actually parsed. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 6042 | if (Operands.size() == 6 && (((ARMOperand &)*Operands[3]).getReg() != |
| 6043 | ((ARMOperand &)*Operands[5]).getReg()) && |
| 6044 | (((ARMOperand &)*Operands[3]).getReg() != |
| 6045 | ((ARMOperand &)*Operands[4]).getReg())) { |
Chad Rosier | db482ef | 2012-08-30 23:22:05 +0000 | [diff] [blame] | 6046 | return Error(Operands[3]->getStartLoc(), |
| 6047 | "destination register must match source register"); |
Chad Rosier | 8513ffb | 2012-08-30 23:20:38 +0000 | [diff] [blame] | 6048 | } |
| 6049 | break; |
| 6050 | } |
Jim Grosbach | 9bded9d | 2011-11-10 23:17:11 +0000 | [diff] [blame] | 6051 | // Like for ldm/stm, push and pop have hi-reg handling version in Thumb2, |
| 6052 | // so only issue a diagnostic for thumb1. The instructions will be |
| 6053 | // switched to the t2 encodings in processInstruction() if necessary. |
Jim Grosbach | 38c59fc | 2011-08-22 23:17:34 +0000 | [diff] [blame] | 6054 | case ARM::tPOP: { |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 6055 | bool ListContainsBase; |
| 6056 | if (checkLowRegisterList(Inst, 2, 0, ARM::PC, ListContainsBase) && |
Jim Grosbach | 9bded9d | 2011-11-10 23:17:11 +0000 | [diff] [blame] | 6057 | !isThumbTwo()) |
Jim Grosbach | 169b2be | 2011-08-23 18:13:04 +0000 | [diff] [blame] | 6058 | return Error(Operands[2]->getStartLoc(), |
| 6059 | "registers must be in range r0-r7 or pc"); |
Jim Grosbach | 38c59fc | 2011-08-22 23:17:34 +0000 | [diff] [blame] | 6060 | break; |
| 6061 | } |
| 6062 | case ARM::tPUSH: { |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 6063 | bool ListContainsBase; |
| 6064 | if (checkLowRegisterList(Inst, 2, 0, ARM::LR, ListContainsBase) && |
Jim Grosbach | 9bded9d | 2011-11-10 23:17:11 +0000 | [diff] [blame] | 6065 | !isThumbTwo()) |
Jim Grosbach | 169b2be | 2011-08-23 18:13:04 +0000 | [diff] [blame] | 6066 | return Error(Operands[2]->getStartLoc(), |
| 6067 | "registers must be in range r0-r7 or lr"); |
Jim Grosbach | 38c59fc | 2011-08-22 23:17:34 +0000 | [diff] [blame] | 6068 | break; |
| 6069 | } |
Jim Grosbach | d80d169 | 2011-08-23 18:15:37 +0000 | [diff] [blame] | 6070 | case ARM::tSTMIA_UPD: { |
Tim Northover | 08a8660 | 2013-10-22 19:00:39 +0000 | [diff] [blame] | 6071 | bool ListContainsBase, InvalidLowList; |
| 6072 | InvalidLowList = checkLowRegisterList(Inst, 4, Inst.getOperand(0).getReg(), |
| 6073 | 0, ListContainsBase); |
| 6074 | if (InvalidLowList && !isThumbTwo()) |
Jim Grosbach | d80d169 | 2011-08-23 18:15:37 +0000 | [diff] [blame] | 6075 | return Error(Operands[4]->getStartLoc(), |
| 6076 | "registers must be in range r0-r7"); |
Tim Northover | 08a8660 | 2013-10-22 19:00:39 +0000 | [diff] [blame] | 6077 | |
| 6078 | // This would be converted to a 32-bit stm, but that's not valid if the |
| 6079 | // writeback register is in the list. |
| 6080 | if (InvalidLowList && ListContainsBase) |
| 6081 | return Error(Operands[4]->getStartLoc(), |
| 6082 | "writeback operator '!' not allowed when base register " |
| 6083 | "in register list"); |
Jyoti Allur | 3b68607 | 2014-10-22 10:41:14 +0000 | [diff] [blame^] | 6084 | if (listContainsReg(Inst, 4, ARM::SP) && !inITBlock()) |
| 6085 | return Error(Operands.back()->getStartLoc(), |
| 6086 | "SP not allowed in register list"); |
Jim Grosbach | d80d169 | 2011-08-23 18:15:37 +0000 | [diff] [blame] | 6087 | break; |
| 6088 | } |
Jim Grosbach | c6f32b3 | 2012-04-27 23:51:36 +0000 | [diff] [blame] | 6089 | case ARM::tADDrSP: { |
| 6090 | // If the non-SP source operand and the destination operand are not the |
| 6091 | // same, we need thumb2 (for the wide encoding), or we have an error. |
| 6092 | if (!isThumbTwo() && |
| 6093 | Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) { |
| 6094 | return Error(Operands[4]->getStartLoc(), |
| 6095 | "source register must be the same as destination"); |
| 6096 | } |
| 6097 | break; |
| 6098 | } |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 6099 | // Final range checking for Thumb unconditional branch instructions. |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 6100 | case ARM::tB: |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 6101 | if (!(static_cast<ARMOperand &>(*Operands[2])).isSignedOffset<11, 1>()) |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 6102 | return Error(Operands[2]->getStartLoc(), "branch target out of range"); |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 6103 | break; |
| 6104 | case ARM::t2B: { |
| 6105 | int op = (Operands[2]->isImm()) ? 2 : 3; |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 6106 | if (!static_cast<ARMOperand &>(*Operands[op]).isSignedOffset<24, 1>()) |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 6107 | return Error(Operands[op]->getStartLoc(), "branch target out of range"); |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 6108 | break; |
| 6109 | } |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 6110 | // Final range checking for Thumb conditional branch instructions. |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 6111 | case ARM::tBcc: |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 6112 | if (!static_cast<ARMOperand &>(*Operands[2]).isSignedOffset<8, 1>()) |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 6113 | return Error(Operands[2]->getStartLoc(), "branch target out of range"); |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 6114 | break; |
| 6115 | case ARM::t2Bcc: { |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 6116 | int Op = (Operands[2]->isImm()) ? 2 : 3; |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 6117 | if (!static_cast<ARMOperand &>(*Operands[Op]).isSignedOffset<20, 1>()) |
Tilmann Scheller | be90477 | 2013-09-30 17:57:30 +0000 | [diff] [blame] | 6118 | return Error(Operands[Op]->getStartLoc(), "branch target out of range"); |
Mihai Popa | ad18d3c | 2013-08-09 10:38:32 +0000 | [diff] [blame] | 6119 | break; |
| 6120 | } |
Kevin Enderby | b7e51f6 | 2014-04-18 23:06:39 +0000 | [diff] [blame] | 6121 | case ARM::MOVi16: |
| 6122 | case ARM::t2MOVi16: |
| 6123 | case ARM::t2MOVTi16: |
| 6124 | { |
| 6125 | // We want to avoid misleadingly allowing something like "mov r0, <symbol>" |
| 6126 | // especially when we turn it into a movw and the expression <symbol> does |
| 6127 | // not have a :lower16: or :upper16 as part of the expression. We don't |
| 6128 | // want the behavior of silently truncating, which can be unexpected and |
| 6129 | // lead to bugs that are difficult to find since this is an easy mistake |
| 6130 | // to make. |
| 6131 | int i = (Operands[3]->isImm()) ? 3 : 4; |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 6132 | ARMOperand &Op = static_cast<ARMOperand &>(*Operands[i]); |
| 6133 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm()); |
Kevin Enderby | b7e51f6 | 2014-04-18 23:06:39 +0000 | [diff] [blame] | 6134 | if (CE) break; |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 6135 | const MCExpr *E = dyn_cast<MCExpr>(Op.getImm()); |
Kevin Enderby | b7e51f6 | 2014-04-18 23:06:39 +0000 | [diff] [blame] | 6136 | if (!E) break; |
| 6137 | const ARMMCExpr *ARM16Expr = dyn_cast<ARMMCExpr>(E); |
| 6138 | if (!ARM16Expr || (ARM16Expr->getKind() != ARMMCExpr::VK_ARM_HI16 && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 6139 | ARM16Expr->getKind() != ARMMCExpr::VK_ARM_LO16)) |
| 6140 | return Error( |
| 6141 | Op.getStartLoc(), |
| 6142 | "immediate expression for mov requires :lower16: or :upper16"); |
| 6143 | break; |
| 6144 | } |
Jim Grosbach | edaa35a | 2011-07-26 18:25:39 +0000 | [diff] [blame] | 6145 | } |
| 6146 | |
| 6147 | return false; |
| 6148 | } |
| 6149 | |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6150 | static unsigned getRealVSTOpcode(unsigned Opc, unsigned &Spacing) { |
Jim Grosbach | eb53822 | 2011-12-02 22:34:51 +0000 | [diff] [blame] | 6151 | switch(Opc) { |
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 6152 | default: llvm_unreachable("unexpected opcode!"); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6153 | // VST1LN |
Jim Grosbach | 1e946a4 | 2012-01-24 00:43:12 +0000 | [diff] [blame] | 6154 | case ARM::VST1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD; |
| 6155 | case ARM::VST1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD; |
| 6156 | case ARM::VST1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD; |
| 6157 | case ARM::VST1LNdWB_register_Asm_8: Spacing = 1; return ARM::VST1LNd8_UPD; |
| 6158 | case ARM::VST1LNdWB_register_Asm_16: Spacing = 1; return ARM::VST1LNd16_UPD; |
| 6159 | case ARM::VST1LNdWB_register_Asm_32: Spacing = 1; return ARM::VST1LNd32_UPD; |
| 6160 | case ARM::VST1LNdAsm_8: Spacing = 1; return ARM::VST1LNd8; |
| 6161 | case ARM::VST1LNdAsm_16: Spacing = 1; return ARM::VST1LNd16; |
| 6162 | case ARM::VST1LNdAsm_32: Spacing = 1; return ARM::VST1LNd32; |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6163 | |
| 6164 | // VST2LN |
Jim Grosbach | 1e946a4 | 2012-01-24 00:43:12 +0000 | [diff] [blame] | 6165 | case ARM::VST2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD; |
| 6166 | case ARM::VST2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD; |
| 6167 | case ARM::VST2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD; |
| 6168 | case ARM::VST2LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD; |
| 6169 | case ARM::VST2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD; |
Jim Grosbach | 2c59052 | 2011-12-20 20:46:29 +0000 | [diff] [blame] | 6170 | |
Jim Grosbach | 1e946a4 | 2012-01-24 00:43:12 +0000 | [diff] [blame] | 6171 | case ARM::VST2LNdWB_register_Asm_8: Spacing = 1; return ARM::VST2LNd8_UPD; |
| 6172 | case ARM::VST2LNdWB_register_Asm_16: Spacing = 1; return ARM::VST2LNd16_UPD; |
| 6173 | case ARM::VST2LNdWB_register_Asm_32: Spacing = 1; return ARM::VST2LNd32_UPD; |
| 6174 | case ARM::VST2LNqWB_register_Asm_16: Spacing = 2; return ARM::VST2LNq16_UPD; |
| 6175 | case ARM::VST2LNqWB_register_Asm_32: Spacing = 2; return ARM::VST2LNq32_UPD; |
Jim Grosbach | 2c59052 | 2011-12-20 20:46:29 +0000 | [diff] [blame] | 6176 | |
Jim Grosbach | 1e946a4 | 2012-01-24 00:43:12 +0000 | [diff] [blame] | 6177 | case ARM::VST2LNdAsm_8: Spacing = 1; return ARM::VST2LNd8; |
| 6178 | case ARM::VST2LNdAsm_16: Spacing = 1; return ARM::VST2LNd16; |
| 6179 | case ARM::VST2LNdAsm_32: Spacing = 1; return ARM::VST2LNd32; |
| 6180 | case ARM::VST2LNqAsm_16: Spacing = 2; return ARM::VST2LNq16; |
| 6181 | case ARM::VST2LNqAsm_32: Spacing = 2; return ARM::VST2LNq32; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6182 | |
Jim Grosbach | d3d36d9 | 2012-01-24 00:07:41 +0000 | [diff] [blame] | 6183 | // VST3LN |
Jim Grosbach | 1e946a4 | 2012-01-24 00:43:12 +0000 | [diff] [blame] | 6184 | case ARM::VST3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD; |
| 6185 | case ARM::VST3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD; |
| 6186 | case ARM::VST3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD; |
| 6187 | case ARM::VST3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST3LNq16_UPD; |
| 6188 | case ARM::VST3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD; |
| 6189 | case ARM::VST3LNdWB_register_Asm_8: Spacing = 1; return ARM::VST3LNd8_UPD; |
| 6190 | case ARM::VST3LNdWB_register_Asm_16: Spacing = 1; return ARM::VST3LNd16_UPD; |
| 6191 | case ARM::VST3LNdWB_register_Asm_32: Spacing = 1; return ARM::VST3LNd32_UPD; |
| 6192 | case ARM::VST3LNqWB_register_Asm_16: Spacing = 2; return ARM::VST3LNq16_UPD; |
| 6193 | case ARM::VST3LNqWB_register_Asm_32: Spacing = 2; return ARM::VST3LNq32_UPD; |
| 6194 | case ARM::VST3LNdAsm_8: Spacing = 1; return ARM::VST3LNd8; |
| 6195 | case ARM::VST3LNdAsm_16: Spacing = 1; return ARM::VST3LNd16; |
| 6196 | case ARM::VST3LNdAsm_32: Spacing = 1; return ARM::VST3LNd32; |
| 6197 | case ARM::VST3LNqAsm_16: Spacing = 2; return ARM::VST3LNq16; |
| 6198 | case ARM::VST3LNqAsm_32: Spacing = 2; return ARM::VST3LNq32; |
Jim Grosbach | d3d36d9 | 2012-01-24 00:07:41 +0000 | [diff] [blame] | 6199 | |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6200 | // VST3 |
Jim Grosbach | 1e946a4 | 2012-01-24 00:43:12 +0000 | [diff] [blame] | 6201 | case ARM::VST3dWB_fixed_Asm_8: Spacing = 1; return ARM::VST3d8_UPD; |
| 6202 | case ARM::VST3dWB_fixed_Asm_16: Spacing = 1; return ARM::VST3d16_UPD; |
| 6203 | case ARM::VST3dWB_fixed_Asm_32: Spacing = 1; return ARM::VST3d32_UPD; |
| 6204 | case ARM::VST3qWB_fixed_Asm_8: Spacing = 2; return ARM::VST3q8_UPD; |
| 6205 | case ARM::VST3qWB_fixed_Asm_16: Spacing = 2; return ARM::VST3q16_UPD; |
| 6206 | case ARM::VST3qWB_fixed_Asm_32: Spacing = 2; return ARM::VST3q32_UPD; |
| 6207 | case ARM::VST3dWB_register_Asm_8: Spacing = 1; return ARM::VST3d8_UPD; |
| 6208 | case ARM::VST3dWB_register_Asm_16: Spacing = 1; return ARM::VST3d16_UPD; |
| 6209 | case ARM::VST3dWB_register_Asm_32: Spacing = 1; return ARM::VST3d32_UPD; |
| 6210 | case ARM::VST3qWB_register_Asm_8: Spacing = 2; return ARM::VST3q8_UPD; |
| 6211 | case ARM::VST3qWB_register_Asm_16: Spacing = 2; return ARM::VST3q16_UPD; |
| 6212 | case ARM::VST3qWB_register_Asm_32: Spacing = 2; return ARM::VST3q32_UPD; |
| 6213 | case ARM::VST3dAsm_8: Spacing = 1; return ARM::VST3d8; |
| 6214 | case ARM::VST3dAsm_16: Spacing = 1; return ARM::VST3d16; |
| 6215 | case ARM::VST3dAsm_32: Spacing = 1; return ARM::VST3d32; |
| 6216 | case ARM::VST3qAsm_8: Spacing = 2; return ARM::VST3q8; |
| 6217 | case ARM::VST3qAsm_16: Spacing = 2; return ARM::VST3q16; |
| 6218 | case ARM::VST3qAsm_32: Spacing = 2; return ARM::VST3q32; |
Jim Grosbach | da70eac | 2012-01-24 00:58:13 +0000 | [diff] [blame] | 6219 | |
Jim Grosbach | 8e2722c | 2012-01-24 18:53:13 +0000 | [diff] [blame] | 6220 | // VST4LN |
| 6221 | case ARM::VST4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD; |
| 6222 | case ARM::VST4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD; |
| 6223 | case ARM::VST4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD; |
| 6224 | case ARM::VST4LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VST4LNq16_UPD; |
| 6225 | case ARM::VST4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD; |
| 6226 | case ARM::VST4LNdWB_register_Asm_8: Spacing = 1; return ARM::VST4LNd8_UPD; |
| 6227 | case ARM::VST4LNdWB_register_Asm_16: Spacing = 1; return ARM::VST4LNd16_UPD; |
| 6228 | case ARM::VST4LNdWB_register_Asm_32: Spacing = 1; return ARM::VST4LNd32_UPD; |
| 6229 | case ARM::VST4LNqWB_register_Asm_16: Spacing = 2; return ARM::VST4LNq16_UPD; |
| 6230 | case ARM::VST4LNqWB_register_Asm_32: Spacing = 2; return ARM::VST4LNq32_UPD; |
| 6231 | case ARM::VST4LNdAsm_8: Spacing = 1; return ARM::VST4LNd8; |
| 6232 | case ARM::VST4LNdAsm_16: Spacing = 1; return ARM::VST4LNd16; |
| 6233 | case ARM::VST4LNdAsm_32: Spacing = 1; return ARM::VST4LNd32; |
| 6234 | case ARM::VST4LNqAsm_16: Spacing = 2; return ARM::VST4LNq16; |
| 6235 | case ARM::VST4LNqAsm_32: Spacing = 2; return ARM::VST4LNq32; |
| 6236 | |
Jim Grosbach | da70eac | 2012-01-24 00:58:13 +0000 | [diff] [blame] | 6237 | // VST4 |
| 6238 | case ARM::VST4dWB_fixed_Asm_8: Spacing = 1; return ARM::VST4d8_UPD; |
| 6239 | case ARM::VST4dWB_fixed_Asm_16: Spacing = 1; return ARM::VST4d16_UPD; |
| 6240 | case ARM::VST4dWB_fixed_Asm_32: Spacing = 1; return ARM::VST4d32_UPD; |
| 6241 | case ARM::VST4qWB_fixed_Asm_8: Spacing = 2; return ARM::VST4q8_UPD; |
| 6242 | case ARM::VST4qWB_fixed_Asm_16: Spacing = 2; return ARM::VST4q16_UPD; |
| 6243 | case ARM::VST4qWB_fixed_Asm_32: Spacing = 2; return ARM::VST4q32_UPD; |
| 6244 | case ARM::VST4dWB_register_Asm_8: Spacing = 1; return ARM::VST4d8_UPD; |
| 6245 | case ARM::VST4dWB_register_Asm_16: Spacing = 1; return ARM::VST4d16_UPD; |
| 6246 | case ARM::VST4dWB_register_Asm_32: Spacing = 1; return ARM::VST4d32_UPD; |
| 6247 | case ARM::VST4qWB_register_Asm_8: Spacing = 2; return ARM::VST4q8_UPD; |
| 6248 | case ARM::VST4qWB_register_Asm_16: Spacing = 2; return ARM::VST4q16_UPD; |
| 6249 | case ARM::VST4qWB_register_Asm_32: Spacing = 2; return ARM::VST4q32_UPD; |
| 6250 | case ARM::VST4dAsm_8: Spacing = 1; return ARM::VST4d8; |
| 6251 | case ARM::VST4dAsm_16: Spacing = 1; return ARM::VST4d16; |
| 6252 | case ARM::VST4dAsm_32: Spacing = 1; return ARM::VST4d32; |
| 6253 | case ARM::VST4qAsm_8: Spacing = 2; return ARM::VST4q8; |
| 6254 | case ARM::VST4qAsm_16: Spacing = 2; return ARM::VST4q16; |
| 6255 | case ARM::VST4qAsm_32: Spacing = 2; return ARM::VST4q32; |
Jim Grosbach | eb53822 | 2011-12-02 22:34:51 +0000 | [diff] [blame] | 6256 | } |
| 6257 | } |
| 6258 | |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6259 | static unsigned getRealVLDOpcode(unsigned Opc, unsigned &Spacing) { |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 6260 | switch(Opc) { |
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 6261 | default: llvm_unreachable("unexpected opcode!"); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6262 | // VLD1LN |
Jim Grosbach | 1e946a4 | 2012-01-24 00:43:12 +0000 | [diff] [blame] | 6263 | case ARM::VLD1LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD; |
| 6264 | case ARM::VLD1LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD; |
| 6265 | case ARM::VLD1LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD; |
| 6266 | case ARM::VLD1LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD1LNd8_UPD; |
| 6267 | case ARM::VLD1LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD1LNd16_UPD; |
| 6268 | case ARM::VLD1LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD1LNd32_UPD; |
| 6269 | case ARM::VLD1LNdAsm_8: Spacing = 1; return ARM::VLD1LNd8; |
| 6270 | case ARM::VLD1LNdAsm_16: Spacing = 1; return ARM::VLD1LNd16; |
| 6271 | case ARM::VLD1LNdAsm_32: Spacing = 1; return ARM::VLD1LNd32; |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6272 | |
| 6273 | // VLD2LN |
Jim Grosbach | 1e946a4 | 2012-01-24 00:43:12 +0000 | [diff] [blame] | 6274 | case ARM::VLD2LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD; |
| 6275 | case ARM::VLD2LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD; |
| 6276 | case ARM::VLD2LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD; |
| 6277 | case ARM::VLD2LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD2LNq16_UPD; |
| 6278 | case ARM::VLD2LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD; |
| 6279 | case ARM::VLD2LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD2LNd8_UPD; |
| 6280 | case ARM::VLD2LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD2LNd16_UPD; |
| 6281 | case ARM::VLD2LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD2LNd32_UPD; |
| 6282 | case ARM::VLD2LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD2LNq16_UPD; |
| 6283 | case ARM::VLD2LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD2LNq32_UPD; |
| 6284 | case ARM::VLD2LNdAsm_8: Spacing = 1; return ARM::VLD2LNd8; |
| 6285 | case ARM::VLD2LNdAsm_16: Spacing = 1; return ARM::VLD2LNd16; |
| 6286 | case ARM::VLD2LNdAsm_32: Spacing = 1; return ARM::VLD2LNd32; |
| 6287 | case ARM::VLD2LNqAsm_16: Spacing = 2; return ARM::VLD2LNq16; |
| 6288 | case ARM::VLD2LNqAsm_32: Spacing = 2; return ARM::VLD2LNq32; |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 6289 | |
Jim Grosbach | b78403c | 2012-01-24 23:47:04 +0000 | [diff] [blame] | 6290 | // VLD3DUP |
| 6291 | case ARM::VLD3DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD; |
| 6292 | case ARM::VLD3DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD; |
| 6293 | case ARM::VLD3DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD; |
| 6294 | case ARM::VLD3DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3DUPq8_UPD; |
Kevin Enderby | d88fec3 | 2014-04-08 18:00:52 +0000 | [diff] [blame] | 6295 | case ARM::VLD3DUPqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD; |
Jim Grosbach | b78403c | 2012-01-24 23:47:04 +0000 | [diff] [blame] | 6296 | case ARM::VLD3DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD; |
| 6297 | case ARM::VLD3DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD3DUPd8_UPD; |
| 6298 | case ARM::VLD3DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD3DUPd16_UPD; |
| 6299 | case ARM::VLD3DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD3DUPd32_UPD; |
| 6300 | case ARM::VLD3DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD3DUPq8_UPD; |
| 6301 | case ARM::VLD3DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD3DUPq16_UPD; |
| 6302 | case ARM::VLD3DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD3DUPq32_UPD; |
| 6303 | case ARM::VLD3DUPdAsm_8: Spacing = 1; return ARM::VLD3DUPd8; |
| 6304 | case ARM::VLD3DUPdAsm_16: Spacing = 1; return ARM::VLD3DUPd16; |
| 6305 | case ARM::VLD3DUPdAsm_32: Spacing = 1; return ARM::VLD3DUPd32; |
| 6306 | case ARM::VLD3DUPqAsm_8: Spacing = 2; return ARM::VLD3DUPq8; |
| 6307 | case ARM::VLD3DUPqAsm_16: Spacing = 2; return ARM::VLD3DUPq16; |
| 6308 | case ARM::VLD3DUPqAsm_32: Spacing = 2; return ARM::VLD3DUPq32; |
| 6309 | |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 6310 | // VLD3LN |
Jim Grosbach | 1e946a4 | 2012-01-24 00:43:12 +0000 | [diff] [blame] | 6311 | case ARM::VLD3LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD; |
| 6312 | case ARM::VLD3LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD; |
| 6313 | case ARM::VLD3LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD; |
| 6314 | case ARM::VLD3LNqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3LNq16_UPD; |
| 6315 | case ARM::VLD3LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD; |
| 6316 | case ARM::VLD3LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD3LNd8_UPD; |
| 6317 | case ARM::VLD3LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD3LNd16_UPD; |
| 6318 | case ARM::VLD3LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD3LNd32_UPD; |
| 6319 | case ARM::VLD3LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD3LNq16_UPD; |
| 6320 | case ARM::VLD3LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD3LNq32_UPD; |
| 6321 | case ARM::VLD3LNdAsm_8: Spacing = 1; return ARM::VLD3LNd8; |
| 6322 | case ARM::VLD3LNdAsm_16: Spacing = 1; return ARM::VLD3LNd16; |
| 6323 | case ARM::VLD3LNdAsm_32: Spacing = 1; return ARM::VLD3LNd32; |
| 6324 | case ARM::VLD3LNqAsm_16: Spacing = 2; return ARM::VLD3LNq16; |
| 6325 | case ARM::VLD3LNqAsm_32: Spacing = 2; return ARM::VLD3LNq32; |
Jim Grosbach | ac2af3f | 2012-01-23 23:20:46 +0000 | [diff] [blame] | 6326 | |
| 6327 | // VLD3 |
Jim Grosbach | 1e946a4 | 2012-01-24 00:43:12 +0000 | [diff] [blame] | 6328 | case ARM::VLD3dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD; |
| 6329 | case ARM::VLD3dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD; |
| 6330 | case ARM::VLD3dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD; |
| 6331 | case ARM::VLD3qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD; |
| 6332 | case ARM::VLD3qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD; |
| 6333 | case ARM::VLD3qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD; |
| 6334 | case ARM::VLD3dWB_register_Asm_8: Spacing = 1; return ARM::VLD3d8_UPD; |
| 6335 | case ARM::VLD3dWB_register_Asm_16: Spacing = 1; return ARM::VLD3d16_UPD; |
| 6336 | case ARM::VLD3dWB_register_Asm_32: Spacing = 1; return ARM::VLD3d32_UPD; |
| 6337 | case ARM::VLD3qWB_register_Asm_8: Spacing = 2; return ARM::VLD3q8_UPD; |
| 6338 | case ARM::VLD3qWB_register_Asm_16: Spacing = 2; return ARM::VLD3q16_UPD; |
| 6339 | case ARM::VLD3qWB_register_Asm_32: Spacing = 2; return ARM::VLD3q32_UPD; |
| 6340 | case ARM::VLD3dAsm_8: Spacing = 1; return ARM::VLD3d8; |
| 6341 | case ARM::VLD3dAsm_16: Spacing = 1; return ARM::VLD3d16; |
| 6342 | case ARM::VLD3dAsm_32: Spacing = 1; return ARM::VLD3d32; |
| 6343 | case ARM::VLD3qAsm_8: Spacing = 2; return ARM::VLD3q8; |
| 6344 | case ARM::VLD3qAsm_16: Spacing = 2; return ARM::VLD3q16; |
| 6345 | case ARM::VLD3qAsm_32: Spacing = 2; return ARM::VLD3q32; |
Jim Grosbach | ed561fc | 2012-01-24 00:43:17 +0000 | [diff] [blame] | 6346 | |
Jim Grosbach | 14952a0 | 2012-01-24 18:37:25 +0000 | [diff] [blame] | 6347 | // VLD4LN |
| 6348 | case ARM::VLD4LNdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD; |
| 6349 | case ARM::VLD4LNdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD; |
| 6350 | case ARM::VLD4LNdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD; |
Kevin Enderby | 8108f38 | 2014-03-26 19:35:40 +0000 | [diff] [blame] | 6351 | case ARM::VLD4LNqWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD; |
Jim Grosbach | 14952a0 | 2012-01-24 18:37:25 +0000 | [diff] [blame] | 6352 | case ARM::VLD4LNqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD; |
| 6353 | case ARM::VLD4LNdWB_register_Asm_8: Spacing = 1; return ARM::VLD4LNd8_UPD; |
| 6354 | case ARM::VLD4LNdWB_register_Asm_16: Spacing = 1; return ARM::VLD4LNd16_UPD; |
| 6355 | case ARM::VLD4LNdWB_register_Asm_32: Spacing = 1; return ARM::VLD4LNd32_UPD; |
| 6356 | case ARM::VLD4LNqWB_register_Asm_16: Spacing = 2; return ARM::VLD4LNq16_UPD; |
| 6357 | case ARM::VLD4LNqWB_register_Asm_32: Spacing = 2; return ARM::VLD4LNq32_UPD; |
| 6358 | case ARM::VLD4LNdAsm_8: Spacing = 1; return ARM::VLD4LNd8; |
| 6359 | case ARM::VLD4LNdAsm_16: Spacing = 1; return ARM::VLD4LNd16; |
| 6360 | case ARM::VLD4LNdAsm_32: Spacing = 1; return ARM::VLD4LNd32; |
| 6361 | case ARM::VLD4LNqAsm_16: Spacing = 2; return ARM::VLD4LNq16; |
| 6362 | case ARM::VLD4LNqAsm_32: Spacing = 2; return ARM::VLD4LNq32; |
| 6363 | |
Jim Grosbach | 086cbfa | 2012-01-25 00:01:08 +0000 | [diff] [blame] | 6364 | // VLD4DUP |
| 6365 | case ARM::VLD4DUPdWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD; |
| 6366 | case ARM::VLD4DUPdWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD; |
| 6367 | case ARM::VLD4DUPdWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD; |
| 6368 | case ARM::VLD4DUPqWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4DUPq8_UPD; |
| 6369 | case ARM::VLD4DUPqWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4DUPq16_UPD; |
| 6370 | case ARM::VLD4DUPqWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD; |
| 6371 | case ARM::VLD4DUPdWB_register_Asm_8: Spacing = 1; return ARM::VLD4DUPd8_UPD; |
| 6372 | case ARM::VLD4DUPdWB_register_Asm_16: Spacing = 1; return ARM::VLD4DUPd16_UPD; |
| 6373 | case ARM::VLD4DUPdWB_register_Asm_32: Spacing = 1; return ARM::VLD4DUPd32_UPD; |
| 6374 | case ARM::VLD4DUPqWB_register_Asm_8: Spacing = 2; return ARM::VLD4DUPq8_UPD; |
| 6375 | case ARM::VLD4DUPqWB_register_Asm_16: Spacing = 2; return ARM::VLD4DUPq16_UPD; |
| 6376 | case ARM::VLD4DUPqWB_register_Asm_32: Spacing = 2; return ARM::VLD4DUPq32_UPD; |
| 6377 | case ARM::VLD4DUPdAsm_8: Spacing = 1; return ARM::VLD4DUPd8; |
| 6378 | case ARM::VLD4DUPdAsm_16: Spacing = 1; return ARM::VLD4DUPd16; |
| 6379 | case ARM::VLD4DUPdAsm_32: Spacing = 1; return ARM::VLD4DUPd32; |
| 6380 | case ARM::VLD4DUPqAsm_8: Spacing = 2; return ARM::VLD4DUPq8; |
| 6381 | case ARM::VLD4DUPqAsm_16: Spacing = 2; return ARM::VLD4DUPq16; |
| 6382 | case ARM::VLD4DUPqAsm_32: Spacing = 2; return ARM::VLD4DUPq32; |
| 6383 | |
Jim Grosbach | ed561fc | 2012-01-24 00:43:17 +0000 | [diff] [blame] | 6384 | // VLD4 |
| 6385 | case ARM::VLD4dWB_fixed_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD; |
| 6386 | case ARM::VLD4dWB_fixed_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD; |
| 6387 | case ARM::VLD4dWB_fixed_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD; |
| 6388 | case ARM::VLD4qWB_fixed_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD; |
| 6389 | case ARM::VLD4qWB_fixed_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD; |
| 6390 | case ARM::VLD4qWB_fixed_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD; |
| 6391 | case ARM::VLD4dWB_register_Asm_8: Spacing = 1; return ARM::VLD4d8_UPD; |
| 6392 | case ARM::VLD4dWB_register_Asm_16: Spacing = 1; return ARM::VLD4d16_UPD; |
| 6393 | case ARM::VLD4dWB_register_Asm_32: Spacing = 1; return ARM::VLD4d32_UPD; |
| 6394 | case ARM::VLD4qWB_register_Asm_8: Spacing = 2; return ARM::VLD4q8_UPD; |
| 6395 | case ARM::VLD4qWB_register_Asm_16: Spacing = 2; return ARM::VLD4q16_UPD; |
| 6396 | case ARM::VLD4qWB_register_Asm_32: Spacing = 2; return ARM::VLD4q32_UPD; |
| 6397 | case ARM::VLD4dAsm_8: Spacing = 1; return ARM::VLD4d8; |
| 6398 | case ARM::VLD4dAsm_16: Spacing = 1; return ARM::VLD4d16; |
| 6399 | case ARM::VLD4dAsm_32: Spacing = 1; return ARM::VLD4d32; |
| 6400 | case ARM::VLD4qAsm_8: Spacing = 2; return ARM::VLD4q8; |
| 6401 | case ARM::VLD4qAsm_16: Spacing = 2; return ARM::VLD4q16; |
| 6402 | case ARM::VLD4qAsm_32: Spacing = 2; return ARM::VLD4q32; |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 6403 | } |
| 6404 | } |
| 6405 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 6406 | bool ARMAsmParser::processInstruction(MCInst &Inst, |
| 6407 | const OperandVector &Operands) { |
Jim Grosbach | 8ba76c6 | 2011-08-11 17:35:48 +0000 | [diff] [blame] | 6408 | switch (Inst.getOpcode()) { |
Saleem Abdulrasool | fb3950e | 2014-01-12 04:36:01 +0000 | [diff] [blame] | 6409 | // Alias for alternate form of 'ldr{,b}t Rt, [Rn], #imm' instruction. |
| 6410 | case ARM::LDRT_POST: |
| 6411 | case ARM::LDRBT_POST: { |
| 6412 | const unsigned Opcode = |
| 6413 | (Inst.getOpcode() == ARM::LDRT_POST) ? ARM::LDRT_POST_IMM |
| 6414 | : ARM::LDRBT_POST_IMM; |
| 6415 | MCInst TmpInst; |
| 6416 | TmpInst.setOpcode(Opcode); |
| 6417 | TmpInst.addOperand(Inst.getOperand(0)); |
| 6418 | TmpInst.addOperand(Inst.getOperand(1)); |
| 6419 | TmpInst.addOperand(Inst.getOperand(1)); |
| 6420 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 6421 | TmpInst.addOperand(MCOperand::CreateImm(0)); |
| 6422 | TmpInst.addOperand(Inst.getOperand(2)); |
| 6423 | TmpInst.addOperand(Inst.getOperand(3)); |
| 6424 | Inst = TmpInst; |
| 6425 | return true; |
| 6426 | } |
| 6427 | // Alias for alternate form of 'str{,b}t Rt, [Rn], #imm' instruction. |
| 6428 | case ARM::STRT_POST: |
| 6429 | case ARM::STRBT_POST: { |
| 6430 | const unsigned Opcode = |
| 6431 | (Inst.getOpcode() == ARM::STRT_POST) ? ARM::STRT_POST_IMM |
| 6432 | : ARM::STRBT_POST_IMM; |
| 6433 | MCInst TmpInst; |
| 6434 | TmpInst.setOpcode(Opcode); |
| 6435 | TmpInst.addOperand(Inst.getOperand(1)); |
| 6436 | TmpInst.addOperand(Inst.getOperand(0)); |
| 6437 | TmpInst.addOperand(Inst.getOperand(1)); |
| 6438 | TmpInst.addOperand(MCOperand::CreateReg(0)); |
| 6439 | TmpInst.addOperand(MCOperand::CreateImm(0)); |
| 6440 | TmpInst.addOperand(Inst.getOperand(2)); |
| 6441 | TmpInst.addOperand(Inst.getOperand(3)); |
| 6442 | Inst = TmpInst; |
| 6443 | return true; |
| 6444 | } |
Jim Grosbach | e974a6a | 2012-09-25 00:08:13 +0000 | [diff] [blame] | 6445 | // Alias for alternate form of 'ADR Rd, #imm' instruction. |
| 6446 | case ARM::ADDri: { |
| 6447 | if (Inst.getOperand(1).getReg() != ARM::PC || |
| 6448 | Inst.getOperand(5).getReg() != 0) |
| 6449 | return false; |
| 6450 | MCInst TmpInst; |
| 6451 | TmpInst.setOpcode(ARM::ADR); |
| 6452 | TmpInst.addOperand(Inst.getOperand(0)); |
| 6453 | TmpInst.addOperand(Inst.getOperand(2)); |
| 6454 | TmpInst.addOperand(Inst.getOperand(3)); |
| 6455 | TmpInst.addOperand(Inst.getOperand(4)); |
| 6456 | Inst = TmpInst; |
| 6457 | return true; |
| 6458 | } |
Jim Grosbach | 94298a9 | 2012-01-18 22:46:46 +0000 | [diff] [blame] | 6459 | // Aliases for alternate PC+imm syntax of LDR instructions. |
| 6460 | case ARM::t2LDRpcrel: |
Kevin Enderby | 06aa3eb8 | 2012-12-14 23:04:25 +0000 | [diff] [blame] | 6461 | // Select the narrow version if the immediate will fit. |
| 6462 | if (Inst.getOperand(1).getImm() > 0 && |
Amaury de la Vieuville | eac0bad | 2013-06-18 08:13:05 +0000 | [diff] [blame] | 6463 | Inst.getOperand(1).getImm() <= 0xff && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 6464 | !(static_cast<ARMOperand &>(*Operands[2]).isToken() && |
| 6465 | static_cast<ARMOperand &>(*Operands[2]).getToken() == ".w")) |
Kevin Enderby | 06aa3eb8 | 2012-12-14 23:04:25 +0000 | [diff] [blame] | 6466 | Inst.setOpcode(ARM::tLDRpci); |
| 6467 | else |
| 6468 | Inst.setOpcode(ARM::t2LDRpci); |
Jim Grosbach | 94298a9 | 2012-01-18 22:46:46 +0000 | [diff] [blame] | 6469 | return true; |
| 6470 | case ARM::t2LDRBpcrel: |
| 6471 | Inst.setOpcode(ARM::t2LDRBpci); |
| 6472 | return true; |
| 6473 | case ARM::t2LDRHpcrel: |
| 6474 | Inst.setOpcode(ARM::t2LDRHpci); |
| 6475 | return true; |
| 6476 | case ARM::t2LDRSBpcrel: |
| 6477 | Inst.setOpcode(ARM::t2LDRSBpci); |
| 6478 | return true; |
| 6479 | case ARM::t2LDRSHpcrel: |
| 6480 | Inst.setOpcode(ARM::t2LDRSHpci); |
| 6481 | return true; |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6482 | // Handle NEON VST complex aliases. |
Jim Grosbach | d28ef9a | 2012-01-23 19:39:08 +0000 | [diff] [blame] | 6483 | case ARM::VST1LNdWB_register_Asm_8: |
| 6484 | case ARM::VST1LNdWB_register_Asm_16: |
| 6485 | case ARM::VST1LNdWB_register_Asm_32: { |
Jim Grosbach | eb53822 | 2011-12-02 22:34:51 +0000 | [diff] [blame] | 6486 | MCInst TmpInst; |
| 6487 | // Shuffle the operands around so the lane index operand is in the |
| 6488 | // right place. |
Jim Grosbach | 2c59052 | 2011-12-20 20:46:29 +0000 | [diff] [blame] | 6489 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6490 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | eb53822 | 2011-12-02 22:34:51 +0000 | [diff] [blame] | 6491 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6492 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6493 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6494 | TmpInst.addOperand(Inst.getOperand(4)); // Rm |
| 6495 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6496 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6497 | TmpInst.addOperand(Inst.getOperand(5)); // CondCode |
| 6498 | TmpInst.addOperand(Inst.getOperand(6)); |
| 6499 | Inst = TmpInst; |
| 6500 | return true; |
| 6501 | } |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6502 | |
Jim Grosbach | d28ef9a | 2012-01-23 19:39:08 +0000 | [diff] [blame] | 6503 | case ARM::VST2LNdWB_register_Asm_8: |
| 6504 | case ARM::VST2LNdWB_register_Asm_16: |
| 6505 | case ARM::VST2LNdWB_register_Asm_32: |
| 6506 | case ARM::VST2LNqWB_register_Asm_16: |
| 6507 | case ARM::VST2LNqWB_register_Asm_32: { |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6508 | MCInst TmpInst; |
| 6509 | // Shuffle the operands around so the lane index operand is in the |
| 6510 | // right place. |
Jim Grosbach | 2c59052 | 2011-12-20 20:46:29 +0000 | [diff] [blame] | 6511 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6512 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6513 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6514 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6515 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6516 | TmpInst.addOperand(Inst.getOperand(4)); // Rm |
| 6517 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
Jim Grosbach | 2c59052 | 2011-12-20 20:46:29 +0000 | [diff] [blame] | 6518 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6519 | Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6520 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6521 | TmpInst.addOperand(Inst.getOperand(5)); // CondCode |
| 6522 | TmpInst.addOperand(Inst.getOperand(6)); |
| 6523 | Inst = TmpInst; |
| 6524 | return true; |
| 6525 | } |
Jim Grosbach | d3d36d9 | 2012-01-24 00:07:41 +0000 | [diff] [blame] | 6526 | |
| 6527 | case ARM::VST3LNdWB_register_Asm_8: |
| 6528 | case ARM::VST3LNdWB_register_Asm_16: |
| 6529 | case ARM::VST3LNdWB_register_Asm_32: |
| 6530 | case ARM::VST3LNqWB_register_Asm_16: |
| 6531 | case ARM::VST3LNqWB_register_Asm_32: { |
| 6532 | MCInst TmpInst; |
| 6533 | // Shuffle the operands around so the lane index operand is in the |
| 6534 | // right place. |
| 6535 | unsigned Spacing; |
| 6536 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
| 6537 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6538 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6539 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6540 | TmpInst.addOperand(Inst.getOperand(4)); // Rm |
| 6541 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6542 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6543 | Spacing)); |
| 6544 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6545 | Spacing * 2)); |
| 6546 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6547 | TmpInst.addOperand(Inst.getOperand(5)); // CondCode |
| 6548 | TmpInst.addOperand(Inst.getOperand(6)); |
| 6549 | Inst = TmpInst; |
| 6550 | return true; |
| 6551 | } |
| 6552 | |
Jim Grosbach | 8e2722c | 2012-01-24 18:53:13 +0000 | [diff] [blame] | 6553 | case ARM::VST4LNdWB_register_Asm_8: |
| 6554 | case ARM::VST4LNdWB_register_Asm_16: |
| 6555 | case ARM::VST4LNdWB_register_Asm_32: |
| 6556 | case ARM::VST4LNqWB_register_Asm_16: |
| 6557 | case ARM::VST4LNqWB_register_Asm_32: { |
| 6558 | MCInst TmpInst; |
| 6559 | // Shuffle the operands around so the lane index operand is in the |
| 6560 | // right place. |
| 6561 | unsigned Spacing; |
| 6562 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
| 6563 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6564 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6565 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6566 | TmpInst.addOperand(Inst.getOperand(4)); // Rm |
| 6567 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6568 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6569 | Spacing)); |
| 6570 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6571 | Spacing * 2)); |
| 6572 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6573 | Spacing * 3)); |
| 6574 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6575 | TmpInst.addOperand(Inst.getOperand(5)); // CondCode |
| 6576 | TmpInst.addOperand(Inst.getOperand(6)); |
| 6577 | Inst = TmpInst; |
| 6578 | return true; |
| 6579 | } |
| 6580 | |
Jim Grosbach | d28ef9a | 2012-01-23 19:39:08 +0000 | [diff] [blame] | 6581 | case ARM::VST1LNdWB_fixed_Asm_8: |
| 6582 | case ARM::VST1LNdWB_fixed_Asm_16: |
| 6583 | case ARM::VST1LNdWB_fixed_Asm_32: { |
Jim Grosbach | eb53822 | 2011-12-02 22:34:51 +0000 | [diff] [blame] | 6584 | MCInst TmpInst; |
| 6585 | // Shuffle the operands around so the lane index operand is in the |
| 6586 | // right place. |
Jim Grosbach | 2c59052 | 2011-12-20 20:46:29 +0000 | [diff] [blame] | 6587 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6588 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | eb53822 | 2011-12-02 22:34:51 +0000 | [diff] [blame] | 6589 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6590 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6591 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6592 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 6593 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6594 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6595 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 6596 | TmpInst.addOperand(Inst.getOperand(5)); |
| 6597 | Inst = TmpInst; |
| 6598 | return true; |
| 6599 | } |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6600 | |
Jim Grosbach | d28ef9a | 2012-01-23 19:39:08 +0000 | [diff] [blame] | 6601 | case ARM::VST2LNdWB_fixed_Asm_8: |
| 6602 | case ARM::VST2LNdWB_fixed_Asm_16: |
| 6603 | case ARM::VST2LNdWB_fixed_Asm_32: |
| 6604 | case ARM::VST2LNqWB_fixed_Asm_16: |
| 6605 | case ARM::VST2LNqWB_fixed_Asm_32: { |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6606 | MCInst TmpInst; |
| 6607 | // Shuffle the operands around so the lane index operand is in the |
| 6608 | // right place. |
Jim Grosbach | 2c59052 | 2011-12-20 20:46:29 +0000 | [diff] [blame] | 6609 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6610 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6611 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6612 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6613 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6614 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 6615 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
Jim Grosbach | 2c59052 | 2011-12-20 20:46:29 +0000 | [diff] [blame] | 6616 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6617 | Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6618 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6619 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 6620 | TmpInst.addOperand(Inst.getOperand(5)); |
| 6621 | Inst = TmpInst; |
| 6622 | return true; |
| 6623 | } |
Jim Grosbach | d3d36d9 | 2012-01-24 00:07:41 +0000 | [diff] [blame] | 6624 | |
| 6625 | case ARM::VST3LNdWB_fixed_Asm_8: |
| 6626 | case ARM::VST3LNdWB_fixed_Asm_16: |
| 6627 | case ARM::VST3LNdWB_fixed_Asm_32: |
| 6628 | case ARM::VST3LNqWB_fixed_Asm_16: |
| 6629 | case ARM::VST3LNqWB_fixed_Asm_32: { |
| 6630 | MCInst TmpInst; |
| 6631 | // Shuffle the operands around so the lane index operand is in the |
| 6632 | // right place. |
| 6633 | unsigned Spacing; |
| 6634 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
| 6635 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6636 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6637 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6638 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 6639 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6640 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6641 | Spacing)); |
| 6642 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6643 | Spacing * 2)); |
| 6644 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6645 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 6646 | TmpInst.addOperand(Inst.getOperand(5)); |
| 6647 | Inst = TmpInst; |
| 6648 | return true; |
| 6649 | } |
| 6650 | |
Jim Grosbach | 8e2722c | 2012-01-24 18:53:13 +0000 | [diff] [blame] | 6651 | case ARM::VST4LNdWB_fixed_Asm_8: |
| 6652 | case ARM::VST4LNdWB_fixed_Asm_16: |
| 6653 | case ARM::VST4LNdWB_fixed_Asm_32: |
| 6654 | case ARM::VST4LNqWB_fixed_Asm_16: |
| 6655 | case ARM::VST4LNqWB_fixed_Asm_32: { |
| 6656 | MCInst TmpInst; |
| 6657 | // Shuffle the operands around so the lane index operand is in the |
| 6658 | // right place. |
| 6659 | unsigned Spacing; |
| 6660 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
| 6661 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6662 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6663 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6664 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 6665 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6666 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6667 | Spacing)); |
| 6668 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6669 | Spacing * 2)); |
| 6670 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6671 | Spacing * 3)); |
| 6672 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6673 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 6674 | TmpInst.addOperand(Inst.getOperand(5)); |
| 6675 | Inst = TmpInst; |
| 6676 | return true; |
| 6677 | } |
| 6678 | |
Jim Grosbach | d28ef9a | 2012-01-23 19:39:08 +0000 | [diff] [blame] | 6679 | case ARM::VST1LNdAsm_8: |
| 6680 | case ARM::VST1LNdAsm_16: |
| 6681 | case ARM::VST1LNdAsm_32: { |
Jim Grosbach | eb53822 | 2011-12-02 22:34:51 +0000 | [diff] [blame] | 6682 | MCInst TmpInst; |
| 6683 | // Shuffle the operands around so the lane index operand is in the |
| 6684 | // right place. |
Jim Grosbach | 2c59052 | 2011-12-20 20:46:29 +0000 | [diff] [blame] | 6685 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6686 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | eb53822 | 2011-12-02 22:34:51 +0000 | [diff] [blame] | 6687 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6688 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6689 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6690 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6691 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 6692 | TmpInst.addOperand(Inst.getOperand(5)); |
| 6693 | Inst = TmpInst; |
| 6694 | return true; |
| 6695 | } |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6696 | |
Jim Grosbach | d28ef9a | 2012-01-23 19:39:08 +0000 | [diff] [blame] | 6697 | case ARM::VST2LNdAsm_8: |
| 6698 | case ARM::VST2LNdAsm_16: |
| 6699 | case ARM::VST2LNdAsm_32: |
| 6700 | case ARM::VST2LNqAsm_16: |
| 6701 | case ARM::VST2LNqAsm_32: { |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6702 | MCInst TmpInst; |
| 6703 | // Shuffle the operands around so the lane index operand is in the |
| 6704 | // right place. |
Jim Grosbach | 2c59052 | 2011-12-20 20:46:29 +0000 | [diff] [blame] | 6705 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6706 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6707 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6708 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6709 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
Jim Grosbach | 2c59052 | 2011-12-20 20:46:29 +0000 | [diff] [blame] | 6710 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6711 | Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6712 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6713 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 6714 | TmpInst.addOperand(Inst.getOperand(5)); |
| 6715 | Inst = TmpInst; |
| 6716 | return true; |
| 6717 | } |
Jim Grosbach | d3d36d9 | 2012-01-24 00:07:41 +0000 | [diff] [blame] | 6718 | |
| 6719 | case ARM::VST3LNdAsm_8: |
| 6720 | case ARM::VST3LNdAsm_16: |
| 6721 | case ARM::VST3LNdAsm_32: |
| 6722 | case ARM::VST3LNqAsm_16: |
| 6723 | case ARM::VST3LNqAsm_32: { |
| 6724 | MCInst TmpInst; |
| 6725 | // Shuffle the operands around so the lane index operand is in the |
| 6726 | // right place. |
| 6727 | unsigned Spacing; |
| 6728 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
| 6729 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6730 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6731 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6732 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6733 | Spacing)); |
| 6734 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6735 | Spacing * 2)); |
| 6736 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6737 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 6738 | TmpInst.addOperand(Inst.getOperand(5)); |
| 6739 | Inst = TmpInst; |
| 6740 | return true; |
| 6741 | } |
| 6742 | |
Jim Grosbach | 8e2722c | 2012-01-24 18:53:13 +0000 | [diff] [blame] | 6743 | case ARM::VST4LNdAsm_8: |
| 6744 | case ARM::VST4LNdAsm_16: |
| 6745 | case ARM::VST4LNdAsm_32: |
| 6746 | case ARM::VST4LNqAsm_16: |
| 6747 | case ARM::VST4LNqAsm_32: { |
| 6748 | MCInst TmpInst; |
| 6749 | // Shuffle the operands around so the lane index operand is in the |
| 6750 | // right place. |
| 6751 | unsigned Spacing; |
| 6752 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
| 6753 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6754 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6755 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6756 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6757 | Spacing)); |
| 6758 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6759 | Spacing * 2)); |
| 6760 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6761 | Spacing * 3)); |
| 6762 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6763 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 6764 | TmpInst.addOperand(Inst.getOperand(5)); |
| 6765 | Inst = TmpInst; |
| 6766 | return true; |
| 6767 | } |
| 6768 | |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6769 | // Handle NEON VLD complex aliases. |
Jim Grosbach | d28ef9a | 2012-01-23 19:39:08 +0000 | [diff] [blame] | 6770 | case ARM::VLD1LNdWB_register_Asm_8: |
| 6771 | case ARM::VLD1LNdWB_register_Asm_16: |
| 6772 | case ARM::VLD1LNdWB_register_Asm_32: { |
Jim Grosbach | dda976b | 2011-12-02 22:01:52 +0000 | [diff] [blame] | 6773 | MCInst TmpInst; |
| 6774 | // Shuffle the operands around so the lane index operand is in the |
| 6775 | // right place. |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 6776 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6777 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | dda976b | 2011-12-02 22:01:52 +0000 | [diff] [blame] | 6778 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6779 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6780 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6781 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6782 | TmpInst.addOperand(Inst.getOperand(4)); // Rm |
| 6783 | TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) |
| 6784 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6785 | TmpInst.addOperand(Inst.getOperand(5)); // CondCode |
| 6786 | TmpInst.addOperand(Inst.getOperand(6)); |
| 6787 | Inst = TmpInst; |
| 6788 | return true; |
| 6789 | } |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6790 | |
Jim Grosbach | d28ef9a | 2012-01-23 19:39:08 +0000 | [diff] [blame] | 6791 | case ARM::VLD2LNdWB_register_Asm_8: |
| 6792 | case ARM::VLD2LNdWB_register_Asm_16: |
| 6793 | case ARM::VLD2LNdWB_register_Asm_32: |
| 6794 | case ARM::VLD2LNqWB_register_Asm_16: |
| 6795 | case ARM::VLD2LNqWB_register_Asm_32: { |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6796 | MCInst TmpInst; |
| 6797 | // Shuffle the operands around so the lane index operand is in the |
| 6798 | // right place. |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 6799 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6800 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6801 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 6802 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6803 | Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6804 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6805 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6806 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6807 | TmpInst.addOperand(Inst.getOperand(4)); // Rm |
| 6808 | TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 6809 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6810 | Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6811 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6812 | TmpInst.addOperand(Inst.getOperand(5)); // CondCode |
| 6813 | TmpInst.addOperand(Inst.getOperand(6)); |
| 6814 | Inst = TmpInst; |
| 6815 | return true; |
| 6816 | } |
| 6817 | |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 6818 | case ARM::VLD3LNdWB_register_Asm_8: |
| 6819 | case ARM::VLD3LNdWB_register_Asm_16: |
| 6820 | case ARM::VLD3LNdWB_register_Asm_32: |
| 6821 | case ARM::VLD3LNqWB_register_Asm_16: |
| 6822 | case ARM::VLD3LNqWB_register_Asm_32: { |
| 6823 | MCInst TmpInst; |
| 6824 | // Shuffle the operands around so the lane index operand is in the |
| 6825 | // right place. |
| 6826 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6827 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 6828 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6829 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6830 | Spacing)); |
| 6831 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
Jim Grosbach | ac2af3f | 2012-01-23 23:20:46 +0000 | [diff] [blame] | 6832 | Spacing * 2)); |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 6833 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6834 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6835 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6836 | TmpInst.addOperand(Inst.getOperand(4)); // Rm |
| 6837 | TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) |
| 6838 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6839 | Spacing)); |
| 6840 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
Jim Grosbach | ac2af3f | 2012-01-23 23:20:46 +0000 | [diff] [blame] | 6841 | Spacing * 2)); |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 6842 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6843 | TmpInst.addOperand(Inst.getOperand(5)); // CondCode |
| 6844 | TmpInst.addOperand(Inst.getOperand(6)); |
| 6845 | Inst = TmpInst; |
| 6846 | return true; |
| 6847 | } |
| 6848 | |
Jim Grosbach | 14952a0 | 2012-01-24 18:37:25 +0000 | [diff] [blame] | 6849 | case ARM::VLD4LNdWB_register_Asm_8: |
| 6850 | case ARM::VLD4LNdWB_register_Asm_16: |
| 6851 | case ARM::VLD4LNdWB_register_Asm_32: |
| 6852 | case ARM::VLD4LNqWB_register_Asm_16: |
| 6853 | case ARM::VLD4LNqWB_register_Asm_32: { |
| 6854 | MCInst TmpInst; |
| 6855 | // Shuffle the operands around so the lane index operand is in the |
| 6856 | // right place. |
| 6857 | unsigned Spacing; |
| 6858 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
| 6859 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6860 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6861 | Spacing)); |
| 6862 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6863 | Spacing * 2)); |
| 6864 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6865 | Spacing * 3)); |
| 6866 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6867 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6868 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6869 | TmpInst.addOperand(Inst.getOperand(4)); // Rm |
| 6870 | TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) |
| 6871 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6872 | Spacing)); |
| 6873 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6874 | Spacing * 2)); |
| 6875 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6876 | Spacing * 3)); |
| 6877 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6878 | TmpInst.addOperand(Inst.getOperand(5)); // CondCode |
| 6879 | TmpInst.addOperand(Inst.getOperand(6)); |
| 6880 | Inst = TmpInst; |
| 6881 | return true; |
| 6882 | } |
| 6883 | |
Jim Grosbach | d28ef9a | 2012-01-23 19:39:08 +0000 | [diff] [blame] | 6884 | case ARM::VLD1LNdWB_fixed_Asm_8: |
| 6885 | case ARM::VLD1LNdWB_fixed_Asm_16: |
| 6886 | case ARM::VLD1LNdWB_fixed_Asm_32: { |
Jim Grosbach | dda976b | 2011-12-02 22:01:52 +0000 | [diff] [blame] | 6887 | MCInst TmpInst; |
| 6888 | // Shuffle the operands around so the lane index operand is in the |
| 6889 | // right place. |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 6890 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6891 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | dda976b | 2011-12-02 22:01:52 +0000 | [diff] [blame] | 6892 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6893 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6894 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6895 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6896 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 6897 | TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) |
| 6898 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6899 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 6900 | TmpInst.addOperand(Inst.getOperand(5)); |
| 6901 | Inst = TmpInst; |
| 6902 | return true; |
| 6903 | } |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6904 | |
Jim Grosbach | d28ef9a | 2012-01-23 19:39:08 +0000 | [diff] [blame] | 6905 | case ARM::VLD2LNdWB_fixed_Asm_8: |
| 6906 | case ARM::VLD2LNdWB_fixed_Asm_16: |
| 6907 | case ARM::VLD2LNdWB_fixed_Asm_32: |
| 6908 | case ARM::VLD2LNqWB_fixed_Asm_16: |
| 6909 | case ARM::VLD2LNqWB_fixed_Asm_32: { |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6910 | MCInst TmpInst; |
| 6911 | // Shuffle the operands around so the lane index operand is in the |
| 6912 | // right place. |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 6913 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6914 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6915 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 6916 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6917 | Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6918 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6919 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6920 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6921 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 6922 | TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 6923 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6924 | Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 6925 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6926 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 6927 | TmpInst.addOperand(Inst.getOperand(5)); |
| 6928 | Inst = TmpInst; |
| 6929 | return true; |
| 6930 | } |
| 6931 | |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 6932 | case ARM::VLD3LNdWB_fixed_Asm_8: |
| 6933 | case ARM::VLD3LNdWB_fixed_Asm_16: |
| 6934 | case ARM::VLD3LNdWB_fixed_Asm_32: |
| 6935 | case ARM::VLD3LNqWB_fixed_Asm_16: |
| 6936 | case ARM::VLD3LNqWB_fixed_Asm_32: { |
| 6937 | MCInst TmpInst; |
| 6938 | // Shuffle the operands around so the lane index operand is in the |
| 6939 | // right place. |
| 6940 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 6941 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 6942 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6943 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6944 | Spacing)); |
| 6945 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
Jim Grosbach | ac2af3f | 2012-01-23 23:20:46 +0000 | [diff] [blame] | 6946 | Spacing * 2)); |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 6947 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6948 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6949 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6950 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 6951 | TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) |
| 6952 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6953 | Spacing)); |
| 6954 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
Jim Grosbach | ac2af3f | 2012-01-23 23:20:46 +0000 | [diff] [blame] | 6955 | Spacing * 2)); |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 6956 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6957 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 6958 | TmpInst.addOperand(Inst.getOperand(5)); |
| 6959 | Inst = TmpInst; |
| 6960 | return true; |
| 6961 | } |
| 6962 | |
Jim Grosbach | 14952a0 | 2012-01-24 18:37:25 +0000 | [diff] [blame] | 6963 | case ARM::VLD4LNdWB_fixed_Asm_8: |
| 6964 | case ARM::VLD4LNdWB_fixed_Asm_16: |
| 6965 | case ARM::VLD4LNdWB_fixed_Asm_32: |
| 6966 | case ARM::VLD4LNqWB_fixed_Asm_16: |
| 6967 | case ARM::VLD4LNqWB_fixed_Asm_32: { |
| 6968 | MCInst TmpInst; |
| 6969 | // Shuffle the operands around so the lane index operand is in the |
| 6970 | // right place. |
| 6971 | unsigned Spacing; |
| 6972 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
| 6973 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 6974 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6975 | Spacing)); |
| 6976 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6977 | Spacing * 2)); |
| 6978 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6979 | Spacing * 3)); |
| 6980 | TmpInst.addOperand(Inst.getOperand(2)); // Rn_wb |
| 6981 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 6982 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 6983 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 6984 | TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) |
| 6985 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6986 | Spacing)); |
| 6987 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6988 | Spacing * 2)); |
| 6989 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 6990 | Spacing * 3)); |
| 6991 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 6992 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 6993 | TmpInst.addOperand(Inst.getOperand(5)); |
| 6994 | Inst = TmpInst; |
| 6995 | return true; |
| 6996 | } |
| 6997 | |
Jim Grosbach | d28ef9a | 2012-01-23 19:39:08 +0000 | [diff] [blame] | 6998 | case ARM::VLD1LNdAsm_8: |
| 6999 | case ARM::VLD1LNdAsm_16: |
| 7000 | case ARM::VLD1LNdAsm_32: { |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 7001 | MCInst TmpInst; |
| 7002 | // Shuffle the operands around so the lane index operand is in the |
| 7003 | // right place. |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 7004 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 7005 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | 04945c4 | 2011-12-02 00:35:16 +0000 | [diff] [blame] | 7006 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7007 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 7008 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 7009 | TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) |
| 7010 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 7011 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 7012 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7013 | Inst = TmpInst; |
| 7014 | return true; |
| 7015 | } |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 7016 | |
Jim Grosbach | d28ef9a | 2012-01-23 19:39:08 +0000 | [diff] [blame] | 7017 | case ARM::VLD2LNdAsm_8: |
| 7018 | case ARM::VLD2LNdAsm_16: |
| 7019 | case ARM::VLD2LNdAsm_32: |
| 7020 | case ARM::VLD2LNqAsm_16: |
| 7021 | case ARM::VLD2LNqAsm_32: { |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 7022 | MCInst TmpInst; |
| 7023 | // Shuffle the operands around so the lane index operand is in the |
| 7024 | // right place. |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 7025 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 7026 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 7027 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 7028 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7029 | Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 7030 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 7031 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 7032 | TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) |
Jim Grosbach | 75e2ab5 | 2011-12-20 19:21:26 +0000 | [diff] [blame] | 7033 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7034 | Spacing)); |
Jim Grosbach | a8aa30b | 2011-12-14 23:25:46 +0000 | [diff] [blame] | 7035 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 7036 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 7037 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7038 | Inst = TmpInst; |
| 7039 | return true; |
| 7040 | } |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 7041 | |
| 7042 | case ARM::VLD3LNdAsm_8: |
| 7043 | case ARM::VLD3LNdAsm_16: |
| 7044 | case ARM::VLD3LNdAsm_32: |
| 7045 | case ARM::VLD3LNqAsm_16: |
| 7046 | case ARM::VLD3LNqAsm_32: { |
| 7047 | MCInst TmpInst; |
| 7048 | // Shuffle the operands around so the lane index operand is in the |
| 7049 | // right place. |
| 7050 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 7051 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 7052 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7053 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7054 | Spacing)); |
| 7055 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
Jim Grosbach | ac2af3f | 2012-01-23 23:20:46 +0000 | [diff] [blame] | 7056 | Spacing * 2)); |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 7057 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 7058 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 7059 | TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) |
| 7060 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7061 | Spacing)); |
| 7062 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
Jim Grosbach | ac2af3f | 2012-01-23 23:20:46 +0000 | [diff] [blame] | 7063 | Spacing * 2)); |
Jim Grosbach | a8b444b | 2012-01-23 21:53:26 +0000 | [diff] [blame] | 7064 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 7065 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 7066 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7067 | Inst = TmpInst; |
| 7068 | return true; |
| 7069 | } |
| 7070 | |
Jim Grosbach | 14952a0 | 2012-01-24 18:37:25 +0000 | [diff] [blame] | 7071 | case ARM::VLD4LNdAsm_8: |
| 7072 | case ARM::VLD4LNdAsm_16: |
| 7073 | case ARM::VLD4LNdAsm_32: |
| 7074 | case ARM::VLD4LNqAsm_16: |
| 7075 | case ARM::VLD4LNqAsm_32: { |
| 7076 | MCInst TmpInst; |
| 7077 | // Shuffle the operands around so the lane index operand is in the |
| 7078 | // right place. |
| 7079 | unsigned Spacing; |
| 7080 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
| 7081 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7082 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7083 | Spacing)); |
| 7084 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7085 | Spacing * 2)); |
| 7086 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7087 | Spacing * 3)); |
| 7088 | TmpInst.addOperand(Inst.getOperand(2)); // Rn |
| 7089 | TmpInst.addOperand(Inst.getOperand(3)); // alignment |
| 7090 | TmpInst.addOperand(Inst.getOperand(0)); // Tied operand src (== Vd) |
| 7091 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7092 | Spacing)); |
| 7093 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7094 | Spacing * 2)); |
| 7095 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7096 | Spacing * 3)); |
| 7097 | TmpInst.addOperand(Inst.getOperand(1)); // lane |
| 7098 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 7099 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7100 | Inst = TmpInst; |
| 7101 | return true; |
| 7102 | } |
| 7103 | |
Jim Grosbach | b78403c | 2012-01-24 23:47:04 +0000 | [diff] [blame] | 7104 | // VLD3DUP single 3-element structure to all lanes instructions. |
| 7105 | case ARM::VLD3DUPdAsm_8: |
| 7106 | case ARM::VLD3DUPdAsm_16: |
| 7107 | case ARM::VLD3DUPdAsm_32: |
| 7108 | case ARM::VLD3DUPqAsm_8: |
| 7109 | case ARM::VLD3DUPqAsm_16: |
| 7110 | case ARM::VLD3DUPqAsm_32: { |
| 7111 | MCInst TmpInst; |
| 7112 | unsigned Spacing; |
| 7113 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
| 7114 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7115 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7116 | Spacing)); |
| 7117 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7118 | Spacing * 2)); |
| 7119 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7120 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7121 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7122 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7123 | Inst = TmpInst; |
| 7124 | return true; |
| 7125 | } |
| 7126 | |
| 7127 | case ARM::VLD3DUPdWB_fixed_Asm_8: |
| 7128 | case ARM::VLD3DUPdWB_fixed_Asm_16: |
| 7129 | case ARM::VLD3DUPdWB_fixed_Asm_32: |
| 7130 | case ARM::VLD3DUPqWB_fixed_Asm_8: |
| 7131 | case ARM::VLD3DUPqWB_fixed_Asm_16: |
| 7132 | case ARM::VLD3DUPqWB_fixed_Asm_32: { |
| 7133 | MCInst TmpInst; |
| 7134 | unsigned Spacing; |
| 7135 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
| 7136 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7137 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7138 | Spacing)); |
| 7139 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7140 | Spacing * 2)); |
| 7141 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7142 | TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn |
| 7143 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7144 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 7145 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7146 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7147 | Inst = TmpInst; |
| 7148 | return true; |
| 7149 | } |
| 7150 | |
| 7151 | case ARM::VLD3DUPdWB_register_Asm_8: |
| 7152 | case ARM::VLD3DUPdWB_register_Asm_16: |
| 7153 | case ARM::VLD3DUPdWB_register_Asm_32: |
| 7154 | case ARM::VLD3DUPqWB_register_Asm_8: |
| 7155 | case ARM::VLD3DUPqWB_register_Asm_16: |
| 7156 | case ARM::VLD3DUPqWB_register_Asm_32: { |
| 7157 | MCInst TmpInst; |
| 7158 | unsigned Spacing; |
| 7159 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
| 7160 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7161 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7162 | Spacing)); |
| 7163 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7164 | Spacing * 2)); |
| 7165 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7166 | TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn |
| 7167 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7168 | TmpInst.addOperand(Inst.getOperand(3)); // Rm |
| 7169 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 7170 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7171 | Inst = TmpInst; |
| 7172 | return true; |
| 7173 | } |
| 7174 | |
Jim Grosbach | ac2af3f | 2012-01-23 23:20:46 +0000 | [diff] [blame] | 7175 | // VLD3 multiple 3-element structure instructions. |
| 7176 | case ARM::VLD3dAsm_8: |
| 7177 | case ARM::VLD3dAsm_16: |
| 7178 | case ARM::VLD3dAsm_32: |
| 7179 | case ARM::VLD3qAsm_8: |
| 7180 | case ARM::VLD3qAsm_16: |
| 7181 | case ARM::VLD3qAsm_32: { |
| 7182 | MCInst TmpInst; |
| 7183 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 7184 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | ac2af3f | 2012-01-23 23:20:46 +0000 | [diff] [blame] | 7185 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7186 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7187 | Spacing)); |
| 7188 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7189 | Spacing * 2)); |
| 7190 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7191 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7192 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7193 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7194 | Inst = TmpInst; |
| 7195 | return true; |
| 7196 | } |
| 7197 | |
| 7198 | case ARM::VLD3dWB_fixed_Asm_8: |
| 7199 | case ARM::VLD3dWB_fixed_Asm_16: |
| 7200 | case ARM::VLD3dWB_fixed_Asm_32: |
| 7201 | case ARM::VLD3qWB_fixed_Asm_8: |
| 7202 | case ARM::VLD3qWB_fixed_Asm_16: |
| 7203 | case ARM::VLD3qWB_fixed_Asm_32: { |
| 7204 | MCInst TmpInst; |
| 7205 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 7206 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | ac2af3f | 2012-01-23 23:20:46 +0000 | [diff] [blame] | 7207 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7208 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7209 | Spacing)); |
| 7210 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7211 | Spacing * 2)); |
| 7212 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7213 | TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn |
| 7214 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7215 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 7216 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7217 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7218 | Inst = TmpInst; |
| 7219 | return true; |
| 7220 | } |
| 7221 | |
| 7222 | case ARM::VLD3dWB_register_Asm_8: |
| 7223 | case ARM::VLD3dWB_register_Asm_16: |
| 7224 | case ARM::VLD3dWB_register_Asm_32: |
| 7225 | case ARM::VLD3qWB_register_Asm_8: |
| 7226 | case ARM::VLD3qWB_register_Asm_16: |
| 7227 | case ARM::VLD3qWB_register_Asm_32: { |
| 7228 | MCInst TmpInst; |
| 7229 | unsigned Spacing; |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 7230 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
Jim Grosbach | ac2af3f | 2012-01-23 23:20:46 +0000 | [diff] [blame] | 7231 | TmpInst.addOperand(Inst.getOperand(0)); // 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(Inst.getOperand(1)); // Rn |
| 7237 | TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn |
| 7238 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7239 | TmpInst.addOperand(Inst.getOperand(3)); // Rm |
| 7240 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 7241 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7242 | Inst = TmpInst; |
| 7243 | return true; |
| 7244 | } |
| 7245 | |
Jim Grosbach | 086cbfa | 2012-01-25 00:01:08 +0000 | [diff] [blame] | 7246 | // VLD4DUP single 3-element structure to all lanes instructions. |
| 7247 | case ARM::VLD4DUPdAsm_8: |
| 7248 | case ARM::VLD4DUPdAsm_16: |
| 7249 | case ARM::VLD4DUPdAsm_32: |
| 7250 | case ARM::VLD4DUPqAsm_8: |
| 7251 | case ARM::VLD4DUPqAsm_16: |
| 7252 | case ARM::VLD4DUPqAsm_32: { |
| 7253 | MCInst TmpInst; |
| 7254 | unsigned Spacing; |
| 7255 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
| 7256 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7257 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7258 | Spacing)); |
| 7259 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7260 | Spacing * 2)); |
| 7261 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7262 | Spacing * 3)); |
| 7263 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7264 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7265 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7266 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7267 | Inst = TmpInst; |
| 7268 | return true; |
| 7269 | } |
| 7270 | |
| 7271 | case ARM::VLD4DUPdWB_fixed_Asm_8: |
| 7272 | case ARM::VLD4DUPdWB_fixed_Asm_16: |
| 7273 | case ARM::VLD4DUPdWB_fixed_Asm_32: |
| 7274 | case ARM::VLD4DUPqWB_fixed_Asm_8: |
| 7275 | case ARM::VLD4DUPqWB_fixed_Asm_16: |
| 7276 | case ARM::VLD4DUPqWB_fixed_Asm_32: { |
| 7277 | MCInst TmpInst; |
| 7278 | unsigned Spacing; |
| 7279 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
| 7280 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7281 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7282 | Spacing)); |
| 7283 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7284 | Spacing * 2)); |
| 7285 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7286 | Spacing * 3)); |
| 7287 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7288 | TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn |
| 7289 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7290 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 7291 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7292 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7293 | Inst = TmpInst; |
| 7294 | return true; |
| 7295 | } |
| 7296 | |
| 7297 | case ARM::VLD4DUPdWB_register_Asm_8: |
| 7298 | case ARM::VLD4DUPdWB_register_Asm_16: |
| 7299 | case ARM::VLD4DUPdWB_register_Asm_32: |
| 7300 | case ARM::VLD4DUPqWB_register_Asm_8: |
| 7301 | case ARM::VLD4DUPqWB_register_Asm_16: |
| 7302 | case ARM::VLD4DUPqWB_register_Asm_32: { |
| 7303 | MCInst TmpInst; |
| 7304 | unsigned Spacing; |
| 7305 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
| 7306 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7307 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7308 | Spacing)); |
| 7309 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7310 | Spacing * 2)); |
| 7311 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7312 | Spacing * 3)); |
| 7313 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7314 | TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn |
| 7315 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7316 | TmpInst.addOperand(Inst.getOperand(3)); // Rm |
| 7317 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 7318 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7319 | Inst = TmpInst; |
| 7320 | return true; |
| 7321 | } |
| 7322 | |
| 7323 | // VLD4 multiple 4-element structure instructions. |
Jim Grosbach | ed561fc | 2012-01-24 00:43:17 +0000 | [diff] [blame] | 7324 | case ARM::VLD4dAsm_8: |
| 7325 | case ARM::VLD4dAsm_16: |
| 7326 | case ARM::VLD4dAsm_32: |
| 7327 | case ARM::VLD4qAsm_8: |
| 7328 | case ARM::VLD4qAsm_16: |
| 7329 | case ARM::VLD4qAsm_32: { |
| 7330 | MCInst TmpInst; |
| 7331 | unsigned Spacing; |
| 7332 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
| 7333 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7334 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7335 | Spacing)); |
| 7336 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7337 | Spacing * 2)); |
| 7338 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7339 | Spacing * 3)); |
| 7340 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7341 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7342 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7343 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7344 | Inst = TmpInst; |
| 7345 | return true; |
| 7346 | } |
| 7347 | |
| 7348 | case ARM::VLD4dWB_fixed_Asm_8: |
| 7349 | case ARM::VLD4dWB_fixed_Asm_16: |
| 7350 | case ARM::VLD4dWB_fixed_Asm_32: |
| 7351 | case ARM::VLD4qWB_fixed_Asm_8: |
| 7352 | case ARM::VLD4qWB_fixed_Asm_16: |
| 7353 | case ARM::VLD4qWB_fixed_Asm_32: { |
| 7354 | MCInst TmpInst; |
| 7355 | unsigned Spacing; |
| 7356 | TmpInst.setOpcode(getRealVLDOpcode(Inst.getOpcode(), Spacing)); |
| 7357 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7358 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7359 | Spacing)); |
| 7360 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7361 | Spacing * 2)); |
| 7362 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7363 | Spacing * 3)); |
| 7364 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7365 | TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn |
| 7366 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7367 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 7368 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7369 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7370 | Inst = TmpInst; |
| 7371 | return true; |
| 7372 | } |
| 7373 | |
| 7374 | case ARM::VLD4dWB_register_Asm_8: |
| 7375 | case ARM::VLD4dWB_register_Asm_16: |
| 7376 | case ARM::VLD4dWB_register_Asm_32: |
| 7377 | case ARM::VLD4qWB_register_Asm_8: |
| 7378 | case ARM::VLD4qWB_register_Asm_16: |
| 7379 | case ARM::VLD4qWB_register_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(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7389 | Spacing * 3)); |
| 7390 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7391 | TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn |
| 7392 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7393 | TmpInst.addOperand(Inst.getOperand(3)); // Rm |
| 7394 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 7395 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7396 | Inst = TmpInst; |
| 7397 | return true; |
| 7398 | } |
| 7399 | |
Jim Grosbach | 1a74724 | 2012-01-23 23:45:44 +0000 | [diff] [blame] | 7400 | // VST3 multiple 3-element structure instructions. |
| 7401 | case ARM::VST3dAsm_8: |
| 7402 | case ARM::VST3dAsm_16: |
| 7403 | case ARM::VST3dAsm_32: |
| 7404 | case ARM::VST3qAsm_8: |
| 7405 | case ARM::VST3qAsm_16: |
| 7406 | case ARM::VST3qAsm_32: { |
| 7407 | MCInst TmpInst; |
| 7408 | unsigned Spacing; |
| 7409 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
| 7410 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7411 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7412 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7413 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7414 | Spacing)); |
| 7415 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7416 | Spacing * 2)); |
| 7417 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7418 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7419 | Inst = TmpInst; |
| 7420 | return true; |
| 7421 | } |
| 7422 | |
| 7423 | case ARM::VST3dWB_fixed_Asm_8: |
| 7424 | case ARM::VST3dWB_fixed_Asm_16: |
| 7425 | case ARM::VST3dWB_fixed_Asm_32: |
| 7426 | case ARM::VST3qWB_fixed_Asm_8: |
| 7427 | case ARM::VST3qWB_fixed_Asm_16: |
| 7428 | case ARM::VST3qWB_fixed_Asm_32: { |
| 7429 | MCInst TmpInst; |
| 7430 | unsigned Spacing; |
| 7431 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
| 7432 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7433 | TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn |
| 7434 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7435 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 7436 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7437 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7438 | Spacing)); |
| 7439 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7440 | Spacing * 2)); |
| 7441 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7442 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7443 | Inst = TmpInst; |
| 7444 | return true; |
| 7445 | } |
| 7446 | |
| 7447 | case ARM::VST3dWB_register_Asm_8: |
| 7448 | case ARM::VST3dWB_register_Asm_16: |
| 7449 | case ARM::VST3dWB_register_Asm_32: |
| 7450 | case ARM::VST3qWB_register_Asm_8: |
| 7451 | case ARM::VST3qWB_register_Asm_16: |
| 7452 | case ARM::VST3qWB_register_Asm_32: { |
| 7453 | MCInst TmpInst; |
| 7454 | unsigned Spacing; |
| 7455 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
| 7456 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7457 | TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn |
| 7458 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7459 | TmpInst.addOperand(Inst.getOperand(3)); // Rm |
| 7460 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7461 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7462 | Spacing)); |
| 7463 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7464 | Spacing * 2)); |
| 7465 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 7466 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7467 | Inst = TmpInst; |
| 7468 | return true; |
| 7469 | } |
| 7470 | |
Jim Grosbach | da70eac | 2012-01-24 00:58:13 +0000 | [diff] [blame] | 7471 | // VST4 multiple 3-element structure instructions. |
| 7472 | case ARM::VST4dAsm_8: |
| 7473 | case ARM::VST4dAsm_16: |
| 7474 | case ARM::VST4dAsm_32: |
| 7475 | case ARM::VST4qAsm_8: |
| 7476 | case ARM::VST4qAsm_16: |
| 7477 | case ARM::VST4qAsm_32: { |
| 7478 | MCInst TmpInst; |
| 7479 | unsigned Spacing; |
| 7480 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
| 7481 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7482 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7483 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7484 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7485 | Spacing)); |
| 7486 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7487 | Spacing * 2)); |
| 7488 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7489 | Spacing * 3)); |
| 7490 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7491 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7492 | Inst = TmpInst; |
| 7493 | return true; |
| 7494 | } |
| 7495 | |
| 7496 | case ARM::VST4dWB_fixed_Asm_8: |
| 7497 | case ARM::VST4dWB_fixed_Asm_16: |
| 7498 | case ARM::VST4dWB_fixed_Asm_32: |
| 7499 | case ARM::VST4qWB_fixed_Asm_8: |
| 7500 | case ARM::VST4qWB_fixed_Asm_16: |
| 7501 | case ARM::VST4qWB_fixed_Asm_32: { |
| 7502 | MCInst TmpInst; |
| 7503 | unsigned Spacing; |
| 7504 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
| 7505 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7506 | TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn |
| 7507 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7508 | TmpInst.addOperand(MCOperand::CreateReg(0)); // Rm |
| 7509 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7510 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7511 | Spacing)); |
| 7512 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7513 | Spacing * 2)); |
| 7514 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7515 | Spacing * 3)); |
| 7516 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7517 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7518 | Inst = TmpInst; |
| 7519 | return true; |
| 7520 | } |
| 7521 | |
| 7522 | case ARM::VST4dWB_register_Asm_8: |
| 7523 | case ARM::VST4dWB_register_Asm_16: |
| 7524 | case ARM::VST4dWB_register_Asm_32: |
| 7525 | case ARM::VST4qWB_register_Asm_8: |
| 7526 | case ARM::VST4qWB_register_Asm_16: |
| 7527 | case ARM::VST4qWB_register_Asm_32: { |
| 7528 | MCInst TmpInst; |
| 7529 | unsigned Spacing; |
| 7530 | TmpInst.setOpcode(getRealVSTOpcode(Inst.getOpcode(), Spacing)); |
| 7531 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7532 | TmpInst.addOperand(Inst.getOperand(1)); // Rn_wb == tied Rn |
| 7533 | TmpInst.addOperand(Inst.getOperand(2)); // alignment |
| 7534 | TmpInst.addOperand(Inst.getOperand(3)); // Rm |
| 7535 | TmpInst.addOperand(Inst.getOperand(0)); // Vd |
| 7536 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7537 | Spacing)); |
| 7538 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7539 | Spacing * 2)); |
| 7540 | TmpInst.addOperand(MCOperand::CreateReg(Inst.getOperand(0).getReg() + |
| 7541 | Spacing * 3)); |
| 7542 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 7543 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7544 | Inst = TmpInst; |
| 7545 | return true; |
| 7546 | } |
| 7547 | |
Jim Grosbach | ad66de1 | 2012-04-11 00:15:16 +0000 | [diff] [blame] | 7548 | // Handle encoding choice for the shift-immediate instructions. |
| 7549 | case ARM::t2LSLri: |
| 7550 | case ARM::t2LSRri: |
| 7551 | case ARM::t2ASRri: { |
| 7552 | if (isARMLowRegister(Inst.getOperand(0).getReg()) && |
| 7553 | Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() && |
| 7554 | Inst.getOperand(5).getReg() == (inITBlock() ? 0 : ARM::CPSR) && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 7555 | !(static_cast<ARMOperand &>(*Operands[3]).isToken() && |
| 7556 | static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w")) { |
Jim Grosbach | ad66de1 | 2012-04-11 00:15:16 +0000 | [diff] [blame] | 7557 | unsigned NewOpc; |
| 7558 | switch (Inst.getOpcode()) { |
| 7559 | default: llvm_unreachable("unexpected opcode"); |
| 7560 | case ARM::t2LSLri: NewOpc = ARM::tLSLri; break; |
| 7561 | case ARM::t2LSRri: NewOpc = ARM::tLSRri; break; |
| 7562 | case ARM::t2ASRri: NewOpc = ARM::tASRri; break; |
| 7563 | } |
| 7564 | // The Thumb1 operands aren't in the same order. Awesome, eh? |
| 7565 | MCInst TmpInst; |
| 7566 | TmpInst.setOpcode(NewOpc); |
| 7567 | TmpInst.addOperand(Inst.getOperand(0)); |
| 7568 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7569 | TmpInst.addOperand(Inst.getOperand(1)); |
| 7570 | TmpInst.addOperand(Inst.getOperand(2)); |
| 7571 | TmpInst.addOperand(Inst.getOperand(3)); |
| 7572 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7573 | Inst = TmpInst; |
| 7574 | return true; |
| 7575 | } |
| 7576 | return false; |
| 7577 | } |
| 7578 | |
Jim Grosbach | 485e562 | 2011-12-13 22:45:11 +0000 | [diff] [blame] | 7579 | // Handle the Thumb2 mode MOV complex aliases. |
Jim Grosbach | b3ef713 | 2011-12-21 20:54:00 +0000 | [diff] [blame] | 7580 | case ARM::t2MOVsr: |
| 7581 | case ARM::t2MOVSsr: { |
| 7582 | // Which instruction to expand to depends on the CCOut operand and |
| 7583 | // whether we're in an IT block if the register operands are low |
| 7584 | // registers. |
| 7585 | bool isNarrow = false; |
| 7586 | if (isARMLowRegister(Inst.getOperand(0).getReg()) && |
| 7587 | isARMLowRegister(Inst.getOperand(1).getReg()) && |
| 7588 | isARMLowRegister(Inst.getOperand(2).getReg()) && |
| 7589 | Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() && |
| 7590 | inITBlock() == (Inst.getOpcode() == ARM::t2MOVsr)) |
| 7591 | isNarrow = true; |
| 7592 | MCInst TmpInst; |
| 7593 | unsigned newOpc; |
| 7594 | switch(ARM_AM::getSORegShOp(Inst.getOperand(3).getImm())) { |
| 7595 | default: llvm_unreachable("unexpected opcode!"); |
| 7596 | case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRrr : ARM::t2ASRrr; break; |
| 7597 | case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRrr : ARM::t2LSRrr; break; |
| 7598 | case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLrr : ARM::t2LSLrr; break; |
| 7599 | case ARM_AM::ror: newOpc = isNarrow ? ARM::tROR : ARM::t2RORrr; break; |
| 7600 | } |
| 7601 | TmpInst.setOpcode(newOpc); |
| 7602 | TmpInst.addOperand(Inst.getOperand(0)); // Rd |
| 7603 | if (isNarrow) |
| 7604 | TmpInst.addOperand(MCOperand::CreateReg( |
| 7605 | Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0)); |
| 7606 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7607 | TmpInst.addOperand(Inst.getOperand(2)); // Rm |
| 7608 | TmpInst.addOperand(Inst.getOperand(4)); // CondCode |
| 7609 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7610 | if (!isNarrow) |
| 7611 | TmpInst.addOperand(MCOperand::CreateReg( |
| 7612 | Inst.getOpcode() == ARM::t2MOVSsr ? ARM::CPSR : 0)); |
| 7613 | Inst = TmpInst; |
| 7614 | return true; |
| 7615 | } |
Jim Grosbach | 485e562 | 2011-12-13 22:45:11 +0000 | [diff] [blame] | 7616 | case ARM::t2MOVsi: |
| 7617 | case ARM::t2MOVSsi: { |
| 7618 | // Which instruction to expand to depends on the CCOut operand and |
| 7619 | // whether we're in an IT block if the register operands are low |
| 7620 | // registers. |
| 7621 | bool isNarrow = false; |
| 7622 | if (isARMLowRegister(Inst.getOperand(0).getReg()) && |
| 7623 | isARMLowRegister(Inst.getOperand(1).getReg()) && |
| 7624 | inITBlock() == (Inst.getOpcode() == ARM::t2MOVsi)) |
| 7625 | isNarrow = true; |
| 7626 | MCInst TmpInst; |
| 7627 | unsigned newOpc; |
| 7628 | switch(ARM_AM::getSORegShOp(Inst.getOperand(2).getImm())) { |
| 7629 | default: llvm_unreachable("unexpected opcode!"); |
| 7630 | case ARM_AM::asr: newOpc = isNarrow ? ARM::tASRri : ARM::t2ASRri; break; |
| 7631 | case ARM_AM::lsr: newOpc = isNarrow ? ARM::tLSRri : ARM::t2LSRri; break; |
| 7632 | case ARM_AM::lsl: newOpc = isNarrow ? ARM::tLSLri : ARM::t2LSLri; break; |
| 7633 | case ARM_AM::ror: newOpc = ARM::t2RORri; isNarrow = false; break; |
Jim Grosbach | 8c59bbc | 2011-12-21 21:04:19 +0000 | [diff] [blame] | 7634 | case ARM_AM::rrx: isNarrow = false; newOpc = ARM::t2RRX; break; |
Jim Grosbach | 485e562 | 2011-12-13 22:45:11 +0000 | [diff] [blame] | 7635 | } |
Benjamin Kramer | bde9176 | 2012-06-02 10:20:22 +0000 | [diff] [blame] | 7636 | unsigned Amount = ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()); |
| 7637 | if (Amount == 32) Amount = 0; |
Jim Grosbach | 485e562 | 2011-12-13 22:45:11 +0000 | [diff] [blame] | 7638 | TmpInst.setOpcode(newOpc); |
| 7639 | TmpInst.addOperand(Inst.getOperand(0)); // Rd |
| 7640 | if (isNarrow) |
| 7641 | TmpInst.addOperand(MCOperand::CreateReg( |
| 7642 | Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0)); |
| 7643 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
Jim Grosbach | 8c59bbc | 2011-12-21 21:04:19 +0000 | [diff] [blame] | 7644 | if (newOpc != ARM::t2RRX) |
Benjamin Kramer | bde9176 | 2012-06-02 10:20:22 +0000 | [diff] [blame] | 7645 | TmpInst.addOperand(MCOperand::CreateImm(Amount)); |
Jim Grosbach | 485e562 | 2011-12-13 22:45:11 +0000 | [diff] [blame] | 7646 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7647 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7648 | if (!isNarrow) |
| 7649 | TmpInst.addOperand(MCOperand::CreateReg( |
| 7650 | Inst.getOpcode() == ARM::t2MOVSsi ? ARM::CPSR : 0)); |
| 7651 | Inst = TmpInst; |
| 7652 | return true; |
| 7653 | } |
| 7654 | // Handle the ARM mode MOV complex aliases. |
Jim Grosbach | abcac56 | 2011-11-16 18:31:45 +0000 | [diff] [blame] | 7655 | case ARM::ASRr: |
| 7656 | case ARM::LSRr: |
| 7657 | case ARM::LSLr: |
| 7658 | case ARM::RORr: { |
| 7659 | ARM_AM::ShiftOpc ShiftTy; |
| 7660 | switch(Inst.getOpcode()) { |
| 7661 | default: llvm_unreachable("unexpected opcode!"); |
| 7662 | case ARM::ASRr: ShiftTy = ARM_AM::asr; break; |
| 7663 | case ARM::LSRr: ShiftTy = ARM_AM::lsr; break; |
| 7664 | case ARM::LSLr: ShiftTy = ARM_AM::lsl; break; |
| 7665 | case ARM::RORr: ShiftTy = ARM_AM::ror; break; |
| 7666 | } |
Jim Grosbach | abcac56 | 2011-11-16 18:31:45 +0000 | [diff] [blame] | 7667 | unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, 0); |
| 7668 | MCInst TmpInst; |
| 7669 | TmpInst.setOpcode(ARM::MOVsr); |
| 7670 | TmpInst.addOperand(Inst.getOperand(0)); // Rd |
| 7671 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7672 | TmpInst.addOperand(Inst.getOperand(2)); // Rm |
| 7673 | TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty |
| 7674 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7675 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7676 | TmpInst.addOperand(Inst.getOperand(5)); // cc_out |
| 7677 | Inst = TmpInst; |
| 7678 | return true; |
| 7679 | } |
Jim Grosbach | c14871c | 2011-11-10 19:18:01 +0000 | [diff] [blame] | 7680 | case ARM::ASRi: |
| 7681 | case ARM::LSRi: |
| 7682 | case ARM::LSLi: |
| 7683 | case ARM::RORi: { |
| 7684 | ARM_AM::ShiftOpc ShiftTy; |
Jim Grosbach | c14871c | 2011-11-10 19:18:01 +0000 | [diff] [blame] | 7685 | switch(Inst.getOpcode()) { |
| 7686 | default: llvm_unreachable("unexpected opcode!"); |
| 7687 | case ARM::ASRi: ShiftTy = ARM_AM::asr; break; |
| 7688 | case ARM::LSRi: ShiftTy = ARM_AM::lsr; break; |
| 7689 | case ARM::LSLi: ShiftTy = ARM_AM::lsl; break; |
| 7690 | case ARM::RORi: ShiftTy = ARM_AM::ror; break; |
| 7691 | } |
| 7692 | // A shift by zero is a plain MOVr, not a MOVsi. |
Jim Grosbach | 1a2f9ee | 2011-11-16 19:05:59 +0000 | [diff] [blame] | 7693 | unsigned Amt = Inst.getOperand(2).getImm(); |
Jim Grosbach | c14871c | 2011-11-10 19:18:01 +0000 | [diff] [blame] | 7694 | unsigned Opc = Amt == 0 ? ARM::MOVr : ARM::MOVsi; |
Richard Barton | ba5b0cc | 2012-04-25 18:00:18 +0000 | [diff] [blame] | 7695 | // A shift by 32 should be encoded as 0 when permitted |
| 7696 | if (Amt == 32 && (ShiftTy == ARM_AM::lsr || ShiftTy == ARM_AM::asr)) |
| 7697 | Amt = 0; |
Jim Grosbach | c14871c | 2011-11-10 19:18:01 +0000 | [diff] [blame] | 7698 | unsigned Shifter = ARM_AM::getSORegOpc(ShiftTy, Amt); |
Jim Grosbach | 61db5a5 | 2011-11-10 16:44:55 +0000 | [diff] [blame] | 7699 | MCInst TmpInst; |
Jim Grosbach | c14871c | 2011-11-10 19:18:01 +0000 | [diff] [blame] | 7700 | TmpInst.setOpcode(Opc); |
Jim Grosbach | 61db5a5 | 2011-11-10 16:44:55 +0000 | [diff] [blame] | 7701 | TmpInst.addOperand(Inst.getOperand(0)); // Rd |
| 7702 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
Jim Grosbach | c14871c | 2011-11-10 19:18:01 +0000 | [diff] [blame] | 7703 | if (Opc == ARM::MOVsi) |
| 7704 | TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty |
Jim Grosbach | 61db5a5 | 2011-11-10 16:44:55 +0000 | [diff] [blame] | 7705 | TmpInst.addOperand(Inst.getOperand(3)); // CondCode |
| 7706 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7707 | TmpInst.addOperand(Inst.getOperand(5)); // cc_out |
| 7708 | Inst = TmpInst; |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7709 | return true; |
Jim Grosbach | 61db5a5 | 2011-11-10 16:44:55 +0000 | [diff] [blame] | 7710 | } |
Jim Grosbach | 1a2f9ee | 2011-11-16 19:05:59 +0000 | [diff] [blame] | 7711 | case ARM::RRXi: { |
| 7712 | unsigned Shifter = ARM_AM::getSORegOpc(ARM_AM::rrx, 0); |
| 7713 | MCInst TmpInst; |
| 7714 | TmpInst.setOpcode(ARM::MOVsi); |
| 7715 | TmpInst.addOperand(Inst.getOperand(0)); // Rd |
| 7716 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7717 | TmpInst.addOperand(MCOperand::CreateImm(Shifter)); // Shift value and ty |
| 7718 | TmpInst.addOperand(Inst.getOperand(2)); // CondCode |
| 7719 | TmpInst.addOperand(Inst.getOperand(3)); |
| 7720 | TmpInst.addOperand(Inst.getOperand(4)); // cc_out |
| 7721 | Inst = TmpInst; |
| 7722 | return true; |
| 7723 | } |
Jim Grosbach | d9a9be2 | 2011-11-10 23:58:34 +0000 | [diff] [blame] | 7724 | case ARM::t2LDMIA_UPD: { |
| 7725 | // If this is a load of a single register, then we should use |
| 7726 | // a post-indexed LDR instruction instead, per the ARM ARM. |
| 7727 | if (Inst.getNumOperands() != 5) |
| 7728 | return false; |
| 7729 | MCInst TmpInst; |
| 7730 | TmpInst.setOpcode(ARM::t2LDR_POST); |
| 7731 | TmpInst.addOperand(Inst.getOperand(4)); // Rt |
| 7732 | TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb |
| 7733 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7734 | TmpInst.addOperand(MCOperand::CreateImm(4)); |
| 7735 | TmpInst.addOperand(Inst.getOperand(2)); // CondCode |
| 7736 | TmpInst.addOperand(Inst.getOperand(3)); |
| 7737 | Inst = TmpInst; |
| 7738 | return true; |
| 7739 | } |
| 7740 | case ARM::t2STMDB_UPD: { |
| 7741 | // If this is a store of a single register, then we should use |
| 7742 | // a pre-indexed STR instruction instead, per the ARM ARM. |
| 7743 | if (Inst.getNumOperands() != 5) |
| 7744 | return false; |
| 7745 | MCInst TmpInst; |
| 7746 | TmpInst.setOpcode(ARM::t2STR_PRE); |
| 7747 | TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb |
| 7748 | TmpInst.addOperand(Inst.getOperand(4)); // Rt |
| 7749 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7750 | TmpInst.addOperand(MCOperand::CreateImm(-4)); |
| 7751 | TmpInst.addOperand(Inst.getOperand(2)); // CondCode |
| 7752 | TmpInst.addOperand(Inst.getOperand(3)); |
| 7753 | Inst = TmpInst; |
| 7754 | return true; |
| 7755 | } |
Jim Grosbach | 8ba76c6 | 2011-08-11 17:35:48 +0000 | [diff] [blame] | 7756 | case ARM::LDMIA_UPD: |
| 7757 | // If this is a load of a single register via a 'pop', then we should use |
| 7758 | // a post-indexed LDR instruction instead, per the ARM ARM. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 7759 | if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "pop" && |
Jim Grosbach | 8ba76c6 | 2011-08-11 17:35:48 +0000 | [diff] [blame] | 7760 | Inst.getNumOperands() == 5) { |
| 7761 | MCInst TmpInst; |
| 7762 | TmpInst.setOpcode(ARM::LDR_POST_IMM); |
| 7763 | TmpInst.addOperand(Inst.getOperand(4)); // Rt |
| 7764 | TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb |
| 7765 | TmpInst.addOperand(Inst.getOperand(1)); // Rn |
| 7766 | TmpInst.addOperand(MCOperand::CreateReg(0)); // am2offset |
| 7767 | TmpInst.addOperand(MCOperand::CreateImm(4)); |
| 7768 | TmpInst.addOperand(Inst.getOperand(2)); // CondCode |
| 7769 | TmpInst.addOperand(Inst.getOperand(3)); |
| 7770 | Inst = TmpInst; |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7771 | return true; |
Jim Grosbach | 8ba76c6 | 2011-08-11 17:35:48 +0000 | [diff] [blame] | 7772 | } |
| 7773 | break; |
Jim Grosbach | 27ad83d | 2011-08-11 18:07:11 +0000 | [diff] [blame] | 7774 | case ARM::STMDB_UPD: |
| 7775 | // If this is a store of a single register via a 'push', then we should use |
| 7776 | // a pre-indexed STR instruction instead, per the ARM ARM. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 7777 | if (static_cast<ARMOperand &>(*Operands[0]).getToken() == "push" && |
Jim Grosbach | 27ad83d | 2011-08-11 18:07:11 +0000 | [diff] [blame] | 7778 | Inst.getNumOperands() == 5) { |
| 7779 | MCInst TmpInst; |
| 7780 | TmpInst.setOpcode(ARM::STR_PRE_IMM); |
| 7781 | TmpInst.addOperand(Inst.getOperand(0)); // Rn_wb |
| 7782 | TmpInst.addOperand(Inst.getOperand(4)); // Rt |
| 7783 | TmpInst.addOperand(Inst.getOperand(1)); // addrmode_imm12 |
| 7784 | TmpInst.addOperand(MCOperand::CreateImm(-4)); |
| 7785 | TmpInst.addOperand(Inst.getOperand(2)); // CondCode |
| 7786 | TmpInst.addOperand(Inst.getOperand(3)); |
| 7787 | Inst = TmpInst; |
| 7788 | } |
| 7789 | break; |
Jim Grosbach | ec9ba98 | 2011-12-05 21:06:26 +0000 | [diff] [blame] | 7790 | case ARM::t2ADDri12: |
| 7791 | // If the immediate fits for encoding T3 (t2ADDri) and the generic "add" |
| 7792 | // mnemonic was used (not "addw"), encoding T3 is preferred. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 7793 | if (static_cast<ARMOperand &>(*Operands[0]).getToken() != "add" || |
Jim Grosbach | ec9ba98 | 2011-12-05 21:06:26 +0000 | [diff] [blame] | 7794 | ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1) |
| 7795 | break; |
| 7796 | Inst.setOpcode(ARM::t2ADDri); |
| 7797 | Inst.addOperand(MCOperand::CreateReg(0)); // cc_out |
| 7798 | break; |
| 7799 | case ARM::t2SUBri12: |
| 7800 | // If the immediate fits for encoding T3 (t2SUBri) and the generic "sub" |
| 7801 | // mnemonic was used (not "subw"), encoding T3 is preferred. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 7802 | if (static_cast<ARMOperand &>(*Operands[0]).getToken() != "sub" || |
Jim Grosbach | ec9ba98 | 2011-12-05 21:06:26 +0000 | [diff] [blame] | 7803 | ARM_AM::getT2SOImmVal(Inst.getOperand(2).getImm()) == -1) |
| 7804 | break; |
| 7805 | Inst.setOpcode(ARM::t2SUBri); |
| 7806 | Inst.addOperand(MCOperand::CreateReg(0)); // cc_out |
| 7807 | break; |
Jim Grosbach | e9ab47a | 2011-08-16 23:57:34 +0000 | [diff] [blame] | 7808 | case ARM::tADDi8: |
Sylvestre Ledru | 91ce36c | 2012-09-27 10:14:43 +0000 | [diff] [blame] | 7809 | // 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] | 7810 | // explicitly specified. From the ARM ARM: "Encoding T1 is preferred |
| 7811 | // to encoding T2 if <Rd> is specified and encoding T2 is preferred |
| 7812 | // to encoding T1 if <Rd> is omitted." |
Jim Grosbach | 199ab90 | 2012-03-30 16:31:31 +0000 | [diff] [blame] | 7813 | if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) { |
Jim Grosbach | e9ab47a | 2011-08-16 23:57:34 +0000 | [diff] [blame] | 7814 | Inst.setOpcode(ARM::tADDi3); |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7815 | return true; |
| 7816 | } |
Jim Grosbach | e9ab47a | 2011-08-16 23:57:34 +0000 | [diff] [blame] | 7817 | break; |
Jim Grosbach | d0c435c | 2011-09-16 22:58:42 +0000 | [diff] [blame] | 7818 | case ARM::tSUBi8: |
Sylvestre Ledru | 91ce36c | 2012-09-27 10:14:43 +0000 | [diff] [blame] | 7819 | // 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] | 7820 | // explicitly specified. From the ARM ARM: "Encoding T1 is preferred |
| 7821 | // to encoding T2 if <Rd> is specified and encoding T2 is preferred |
| 7822 | // to encoding T1 if <Rd> is omitted." |
Jim Grosbach | 199ab90 | 2012-03-30 16:31:31 +0000 | [diff] [blame] | 7823 | if ((unsigned)Inst.getOperand(3).getImm() < 8 && Operands.size() == 6) { |
Jim Grosbach | d0c435c | 2011-09-16 22:58:42 +0000 | [diff] [blame] | 7824 | Inst.setOpcode(ARM::tSUBi3); |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7825 | return true; |
| 7826 | } |
Jim Grosbach | d0c435c | 2011-09-16 22:58:42 +0000 | [diff] [blame] | 7827 | break; |
Jim Grosbach | def5e34 | 2012-03-30 17:20:40 +0000 | [diff] [blame] | 7828 | case ARM::t2ADDri: |
| 7829 | case ARM::t2SUBri: { |
| 7830 | // If the destination and first source operand are the same, and |
| 7831 | // the flags are compatible with the current IT status, use encoding T2 |
| 7832 | // instead of T3. For compatibility with the system 'as'. Make sure the |
| 7833 | // wide encoding wasn't explicit. |
| 7834 | if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() || |
Jim Grosbach | 74005ae | 2012-03-30 18:39:43 +0000 | [diff] [blame] | 7835 | !isARMLowRegister(Inst.getOperand(0).getReg()) || |
Jim Grosbach | def5e34 | 2012-03-30 17:20:40 +0000 | [diff] [blame] | 7836 | (unsigned)Inst.getOperand(2).getImm() > 255 || |
| 7837 | ((!inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR) || |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 7838 | (inITBlock() && Inst.getOperand(5).getReg() != 0)) || |
| 7839 | (static_cast<ARMOperand &>(*Operands[3]).isToken() && |
| 7840 | static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w")) |
Jim Grosbach | def5e34 | 2012-03-30 17:20:40 +0000 | [diff] [blame] | 7841 | break; |
| 7842 | MCInst TmpInst; |
| 7843 | TmpInst.setOpcode(Inst.getOpcode() == ARM::t2ADDri ? |
| 7844 | ARM::tADDi8 : ARM::tSUBi8); |
| 7845 | TmpInst.addOperand(Inst.getOperand(0)); |
| 7846 | TmpInst.addOperand(Inst.getOperand(5)); |
| 7847 | TmpInst.addOperand(Inst.getOperand(0)); |
| 7848 | TmpInst.addOperand(Inst.getOperand(2)); |
| 7849 | TmpInst.addOperand(Inst.getOperand(3)); |
| 7850 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7851 | Inst = TmpInst; |
| 7852 | return true; |
| 7853 | } |
Jim Grosbach | e489bab | 2011-12-05 22:16:39 +0000 | [diff] [blame] | 7854 | case ARM::t2ADDrr: { |
| 7855 | // If the destination and first source operand are the same, and |
| 7856 | // there's no setting of the flags, use encoding T2 instead of T3. |
| 7857 | // Note that this is only for ADD, not SUB. This mirrors the system |
| 7858 | // 'as' behaviour. Make sure the wide encoding wasn't explicit. |
| 7859 | if (Inst.getOperand(0).getReg() != Inst.getOperand(1).getReg() || |
| 7860 | Inst.getOperand(5).getReg() != 0 || |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 7861 | (static_cast<ARMOperand &>(*Operands[3]).isToken() && |
| 7862 | static_cast<ARMOperand &>(*Operands[3]).getToken() == ".w")) |
Jim Grosbach | e489bab | 2011-12-05 22:16:39 +0000 | [diff] [blame] | 7863 | break; |
| 7864 | MCInst TmpInst; |
| 7865 | TmpInst.setOpcode(ARM::tADDhirr); |
| 7866 | TmpInst.addOperand(Inst.getOperand(0)); |
| 7867 | TmpInst.addOperand(Inst.getOperand(0)); |
| 7868 | TmpInst.addOperand(Inst.getOperand(2)); |
| 7869 | TmpInst.addOperand(Inst.getOperand(3)); |
| 7870 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7871 | Inst = TmpInst; |
| 7872 | return true; |
| 7873 | } |
Jim Grosbach | c6f32b3 | 2012-04-27 23:51:36 +0000 | [diff] [blame] | 7874 | case ARM::tADDrSP: { |
| 7875 | // If the non-SP source operand and the destination operand are not the |
| 7876 | // same, we need to use the 32-bit encoding if it's available. |
| 7877 | if (Inst.getOperand(0).getReg() != Inst.getOperand(2).getReg()) { |
| 7878 | Inst.setOpcode(ARM::t2ADDrr); |
| 7879 | Inst.addOperand(MCOperand::CreateReg(0)); // cc_out |
| 7880 | return true; |
| 7881 | } |
| 7882 | break; |
| 7883 | } |
Owen Anderson | 29cfe6c | 2011-09-09 21:48:23 +0000 | [diff] [blame] | 7884 | case ARM::tB: |
| 7885 | // A Thumb conditional branch outside of an IT block is a tBcc. |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7886 | if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()) { |
Owen Anderson | 29cfe6c | 2011-09-09 21:48:23 +0000 | [diff] [blame] | 7887 | Inst.setOpcode(ARM::tBcc); |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7888 | return true; |
| 7889 | } |
Owen Anderson | 29cfe6c | 2011-09-09 21:48:23 +0000 | [diff] [blame] | 7890 | break; |
| 7891 | case ARM::t2B: |
| 7892 | // A Thumb2 conditional branch outside of an IT block is a t2Bcc. |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7893 | if (Inst.getOperand(1).getImm() != ARMCC::AL && !inITBlock()){ |
Owen Anderson | 29cfe6c | 2011-09-09 21:48:23 +0000 | [diff] [blame] | 7894 | Inst.setOpcode(ARM::t2Bcc); |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7895 | return true; |
| 7896 | } |
Owen Anderson | 29cfe6c | 2011-09-09 21:48:23 +0000 | [diff] [blame] | 7897 | break; |
Jim Grosbach | 99bc846 | 2011-08-31 21:17:31 +0000 | [diff] [blame] | 7898 | case ARM::t2Bcc: |
Jim Grosbach | a0d34d3 | 2011-09-02 23:22:08 +0000 | [diff] [blame] | 7899 | // 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] | 7900 | if (Inst.getOperand(1).getImm() == ARMCC::AL || inITBlock()) { |
Jim Grosbach | 99bc846 | 2011-08-31 21:17:31 +0000 | [diff] [blame] | 7901 | Inst.setOpcode(ARM::t2B); |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7902 | return true; |
| 7903 | } |
Jim Grosbach | 99bc846 | 2011-08-31 21:17:31 +0000 | [diff] [blame] | 7904 | break; |
Jim Grosbach | cbd4ab1 | 2011-08-17 22:57:40 +0000 | [diff] [blame] | 7905 | case ARM::tBcc: |
| 7906 | // If the conditional is AL, we really want tB. |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7907 | if (Inst.getOperand(1).getImm() == ARMCC::AL) { |
Jim Grosbach | cbd4ab1 | 2011-08-17 22:57:40 +0000 | [diff] [blame] | 7908 | Inst.setOpcode(ARM::tB); |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7909 | return true; |
| 7910 | } |
Jim Grosbach | 6ddb568 | 2011-08-18 16:08:39 +0000 | [diff] [blame] | 7911 | break; |
Jim Grosbach | a31f223 | 2011-09-07 18:05:34 +0000 | [diff] [blame] | 7912 | case ARM::tLDMIA: { |
| 7913 | // If the register list contains any high registers, or if the writeback |
| 7914 | // doesn't match what tLDMIA can do, we need to use the 32-bit encoding |
| 7915 | // instead if we're in Thumb2. Otherwise, this should have generated |
| 7916 | // an error in validateInstruction(). |
| 7917 | unsigned Rn = Inst.getOperand(0).getReg(); |
| 7918 | bool hasWritebackToken = |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 7919 | (static_cast<ARMOperand &>(*Operands[3]).isToken() && |
| 7920 | static_cast<ARMOperand &>(*Operands[3]).getToken() == "!"); |
Jim Grosbach | a31f223 | 2011-09-07 18:05:34 +0000 | [diff] [blame] | 7921 | bool listContainsBase; |
| 7922 | if (checkLowRegisterList(Inst, 3, Rn, 0, listContainsBase) || |
| 7923 | (!listContainsBase && !hasWritebackToken) || |
| 7924 | (listContainsBase && hasWritebackToken)) { |
| 7925 | // 16-bit encoding isn't sufficient. Switch to the 32-bit version. |
| 7926 | assert (isThumbTwo()); |
| 7927 | Inst.setOpcode(hasWritebackToken ? ARM::t2LDMIA_UPD : ARM::t2LDMIA); |
| 7928 | // If we're switching to the updating version, we need to insert |
| 7929 | // the writeback tied operand. |
| 7930 | if (hasWritebackToken) |
| 7931 | Inst.insert(Inst.begin(), |
| 7932 | MCOperand::CreateReg(Inst.getOperand(0).getReg())); |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7933 | return true; |
Jim Grosbach | a31f223 | 2011-09-07 18:05:34 +0000 | [diff] [blame] | 7934 | } |
| 7935 | break; |
| 7936 | } |
Jim Grosbach | 099c976 | 2011-09-16 20:50:13 +0000 | [diff] [blame] | 7937 | case ARM::tSTMIA_UPD: { |
| 7938 | // If the register list contains any high registers, we need to use |
| 7939 | // the 32-bit encoding instead if we're in Thumb2. Otherwise, this |
| 7940 | // should have generated an error in validateInstruction(). |
| 7941 | unsigned Rn = Inst.getOperand(0).getReg(); |
| 7942 | bool listContainsBase; |
| 7943 | if (checkLowRegisterList(Inst, 4, Rn, 0, listContainsBase)) { |
| 7944 | // 16-bit encoding isn't sufficient. Switch to the 32-bit version. |
| 7945 | assert (isThumbTwo()); |
| 7946 | Inst.setOpcode(ARM::t2STMIA_UPD); |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7947 | return true; |
Jim Grosbach | 099c976 | 2011-09-16 20:50:13 +0000 | [diff] [blame] | 7948 | } |
| 7949 | break; |
| 7950 | } |
Jim Grosbach | 9bded9d | 2011-11-10 23:17:11 +0000 | [diff] [blame] | 7951 | case ARM::tPOP: { |
| 7952 | bool listContainsBase; |
| 7953 | // If the register list contains any high registers, we need to use |
| 7954 | // the 32-bit encoding instead if we're in Thumb2. Otherwise, this |
| 7955 | // should have generated an error in validateInstruction(). |
| 7956 | if (!checkLowRegisterList(Inst, 2, 0, ARM::PC, listContainsBase)) |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7957 | return false; |
Jim Grosbach | 9bded9d | 2011-11-10 23:17:11 +0000 | [diff] [blame] | 7958 | assert (isThumbTwo()); |
| 7959 | Inst.setOpcode(ARM::t2LDMIA_UPD); |
| 7960 | // Add the base register and writeback operands. |
| 7961 | Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP)); |
| 7962 | Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP)); |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7963 | return true; |
Jim Grosbach | 9bded9d | 2011-11-10 23:17:11 +0000 | [diff] [blame] | 7964 | } |
| 7965 | case ARM::tPUSH: { |
| 7966 | bool listContainsBase; |
| 7967 | if (!checkLowRegisterList(Inst, 2, 0, ARM::LR, listContainsBase)) |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7968 | return false; |
Jim Grosbach | 9bded9d | 2011-11-10 23:17:11 +0000 | [diff] [blame] | 7969 | assert (isThumbTwo()); |
| 7970 | Inst.setOpcode(ARM::t2STMDB_UPD); |
| 7971 | // Add the base register and writeback operands. |
| 7972 | Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP)); |
| 7973 | Inst.insert(Inst.begin(), MCOperand::CreateReg(ARM::SP)); |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7974 | return true; |
Jim Grosbach | 9bded9d | 2011-11-10 23:17:11 +0000 | [diff] [blame] | 7975 | } |
Jim Grosbach | b908b7a | 2011-09-10 00:15:36 +0000 | [diff] [blame] | 7976 | case ARM::t2MOVi: { |
| 7977 | // If we can use the 16-bit encoding and the user didn't explicitly |
| 7978 | // request the 32-bit variant, transform it here. |
| 7979 | if (isARMLowRegister(Inst.getOperand(0).getReg()) && |
Jim Grosbach | 199ab90 | 2012-03-30 16:31:31 +0000 | [diff] [blame] | 7980 | (unsigned)Inst.getOperand(1).getImm() <= 255 && |
Jim Grosbach | 18b8b17 | 2011-09-14 19:12:11 +0000 | [diff] [blame] | 7981 | ((!inITBlock() && Inst.getOperand(2).getImm() == ARMCC::AL && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 7982 | Inst.getOperand(4).getReg() == ARM::CPSR) || |
| 7983 | (inITBlock() && Inst.getOperand(4).getReg() == 0)) && |
| 7984 | (!static_cast<ARMOperand &>(*Operands[2]).isToken() || |
| 7985 | static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) { |
Jim Grosbach | b908b7a | 2011-09-10 00:15:36 +0000 | [diff] [blame] | 7986 | // The operands aren't in the same order for tMOVi8... |
| 7987 | MCInst TmpInst; |
| 7988 | TmpInst.setOpcode(ARM::tMOVi8); |
| 7989 | TmpInst.addOperand(Inst.getOperand(0)); |
| 7990 | TmpInst.addOperand(Inst.getOperand(4)); |
| 7991 | TmpInst.addOperand(Inst.getOperand(1)); |
| 7992 | TmpInst.addOperand(Inst.getOperand(2)); |
| 7993 | TmpInst.addOperand(Inst.getOperand(3)); |
| 7994 | Inst = TmpInst; |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 7995 | return true; |
Jim Grosbach | b908b7a | 2011-09-10 00:15:36 +0000 | [diff] [blame] | 7996 | } |
| 7997 | break; |
| 7998 | } |
| 7999 | case ARM::t2MOVr: { |
| 8000 | // If we can use the 16-bit encoding and the user didn't explicitly |
| 8001 | // request the 32-bit variant, transform it here. |
| 8002 | if (isARMLowRegister(Inst.getOperand(0).getReg()) && |
| 8003 | isARMLowRegister(Inst.getOperand(1).getReg()) && |
| 8004 | Inst.getOperand(2).getImm() == ARMCC::AL && |
| 8005 | Inst.getOperand(4).getReg() == ARM::CPSR && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8006 | (!static_cast<ARMOperand &>(*Operands[2]).isToken() || |
| 8007 | static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) { |
Jim Grosbach | b908b7a | 2011-09-10 00:15:36 +0000 | [diff] [blame] | 8008 | // The operands aren't the same for tMOV[S]r... (no cc_out) |
| 8009 | MCInst TmpInst; |
| 8010 | TmpInst.setOpcode(Inst.getOperand(4).getReg() ? ARM::tMOVSr : ARM::tMOVr); |
| 8011 | TmpInst.addOperand(Inst.getOperand(0)); |
| 8012 | TmpInst.addOperand(Inst.getOperand(1)); |
| 8013 | TmpInst.addOperand(Inst.getOperand(2)); |
| 8014 | TmpInst.addOperand(Inst.getOperand(3)); |
| 8015 | Inst = TmpInst; |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 8016 | return true; |
Jim Grosbach | b908b7a | 2011-09-10 00:15:36 +0000 | [diff] [blame] | 8017 | } |
| 8018 | break; |
| 8019 | } |
Jim Grosbach | 8221319 | 2011-09-19 20:29:33 +0000 | [diff] [blame] | 8020 | case ARM::t2SXTH: |
Jim Grosbach | b351980 | 2011-09-20 00:46:54 +0000 | [diff] [blame] | 8021 | case ARM::t2SXTB: |
| 8022 | case ARM::t2UXTH: |
| 8023 | case ARM::t2UXTB: { |
Jim Grosbach | 8221319 | 2011-09-19 20:29:33 +0000 | [diff] [blame] | 8024 | // If we can use the 16-bit encoding and the user didn't explicitly |
| 8025 | // request the 32-bit variant, transform it here. |
| 8026 | if (isARMLowRegister(Inst.getOperand(0).getReg()) && |
| 8027 | isARMLowRegister(Inst.getOperand(1).getReg()) && |
| 8028 | Inst.getOperand(2).getImm() == 0 && |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8029 | (!static_cast<ARMOperand &>(*Operands[2]).isToken() || |
| 8030 | static_cast<ARMOperand &>(*Operands[2]).getToken() != ".w")) { |
Jim Grosbach | b351980 | 2011-09-20 00:46:54 +0000 | [diff] [blame] | 8031 | unsigned NewOpc; |
| 8032 | switch (Inst.getOpcode()) { |
| 8033 | default: llvm_unreachable("Illegal opcode!"); |
| 8034 | case ARM::t2SXTH: NewOpc = ARM::tSXTH; break; |
| 8035 | case ARM::t2SXTB: NewOpc = ARM::tSXTB; break; |
| 8036 | case ARM::t2UXTH: NewOpc = ARM::tUXTH; break; |
| 8037 | case ARM::t2UXTB: NewOpc = ARM::tUXTB; break; |
| 8038 | } |
Jim Grosbach | 8221319 | 2011-09-19 20:29:33 +0000 | [diff] [blame] | 8039 | // The operands aren't the same for thumb1 (no rotate operand). |
| 8040 | MCInst TmpInst; |
| 8041 | TmpInst.setOpcode(NewOpc); |
| 8042 | TmpInst.addOperand(Inst.getOperand(0)); |
| 8043 | TmpInst.addOperand(Inst.getOperand(1)); |
| 8044 | TmpInst.addOperand(Inst.getOperand(3)); |
| 8045 | TmpInst.addOperand(Inst.getOperand(4)); |
| 8046 | Inst = TmpInst; |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 8047 | return true; |
Jim Grosbach | 8221319 | 2011-09-19 20:29:33 +0000 | [diff] [blame] | 8048 | } |
| 8049 | break; |
| 8050 | } |
Jim Grosbach | e2ca9e5 | 2011-12-20 00:59:38 +0000 | [diff] [blame] | 8051 | case ARM::MOVsi: { |
| 8052 | ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(2).getImm()); |
Richard Barton | ba5b0cc | 2012-04-25 18:00:18 +0000 | [diff] [blame] | 8053 | // rrx shifts and asr/lsr of #32 is encoded as 0 |
| 8054 | if (SOpc == ARM_AM::rrx || SOpc == ARM_AM::asr || SOpc == ARM_AM::lsr) |
| 8055 | return false; |
Jim Grosbach | e2ca9e5 | 2011-12-20 00:59:38 +0000 | [diff] [blame] | 8056 | if (ARM_AM::getSORegOffset(Inst.getOperand(2).getImm()) == 0) { |
| 8057 | // Shifting by zero is accepted as a vanilla 'MOVr' |
| 8058 | MCInst TmpInst; |
| 8059 | TmpInst.setOpcode(ARM::MOVr); |
| 8060 | TmpInst.addOperand(Inst.getOperand(0)); |
| 8061 | TmpInst.addOperand(Inst.getOperand(1)); |
| 8062 | TmpInst.addOperand(Inst.getOperand(3)); |
| 8063 | TmpInst.addOperand(Inst.getOperand(4)); |
| 8064 | TmpInst.addOperand(Inst.getOperand(5)); |
| 8065 | Inst = TmpInst; |
| 8066 | return true; |
| 8067 | } |
| 8068 | return false; |
| 8069 | } |
Jim Grosbach | 12ccf45 | 2011-12-22 18:04:04 +0000 | [diff] [blame] | 8070 | case ARM::ANDrsi: |
| 8071 | case ARM::ORRrsi: |
| 8072 | case ARM::EORrsi: |
| 8073 | case ARM::BICrsi: |
| 8074 | case ARM::SUBrsi: |
| 8075 | case ARM::ADDrsi: { |
| 8076 | unsigned newOpc; |
| 8077 | ARM_AM::ShiftOpc SOpc = ARM_AM::getSORegShOp(Inst.getOperand(3).getImm()); |
| 8078 | if (SOpc == ARM_AM::rrx) return false; |
| 8079 | switch (Inst.getOpcode()) { |
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 8080 | default: llvm_unreachable("unexpected opcode!"); |
Jim Grosbach | 12ccf45 | 2011-12-22 18:04:04 +0000 | [diff] [blame] | 8081 | case ARM::ANDrsi: newOpc = ARM::ANDrr; break; |
| 8082 | case ARM::ORRrsi: newOpc = ARM::ORRrr; break; |
| 8083 | case ARM::EORrsi: newOpc = ARM::EORrr; break; |
| 8084 | case ARM::BICrsi: newOpc = ARM::BICrr; break; |
| 8085 | case ARM::SUBrsi: newOpc = ARM::SUBrr; break; |
| 8086 | case ARM::ADDrsi: newOpc = ARM::ADDrr; break; |
| 8087 | } |
| 8088 | // If the shift is by zero, use the non-shifted instruction definition. |
Richard Barton | 35aceb8 | 2012-07-09 16:31:14 +0000 | [diff] [blame] | 8089 | // The exception is for right shifts, where 0 == 32 |
| 8090 | if (ARM_AM::getSORegOffset(Inst.getOperand(3).getImm()) == 0 && |
| 8091 | !(SOpc == ARM_AM::lsr || SOpc == ARM_AM::asr)) { |
Jim Grosbach | 12ccf45 | 2011-12-22 18:04:04 +0000 | [diff] [blame] | 8092 | MCInst TmpInst; |
| 8093 | TmpInst.setOpcode(newOpc); |
| 8094 | TmpInst.addOperand(Inst.getOperand(0)); |
| 8095 | TmpInst.addOperand(Inst.getOperand(1)); |
| 8096 | TmpInst.addOperand(Inst.getOperand(2)); |
| 8097 | TmpInst.addOperand(Inst.getOperand(4)); |
| 8098 | TmpInst.addOperand(Inst.getOperand(5)); |
| 8099 | TmpInst.addOperand(Inst.getOperand(6)); |
| 8100 | Inst = TmpInst; |
| 8101 | return true; |
| 8102 | } |
| 8103 | return false; |
| 8104 | } |
Jim Grosbach | 82f76d1 | 2012-01-25 19:52:01 +0000 | [diff] [blame] | 8105 | case ARM::ITasm: |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 8106 | case ARM::t2IT: { |
| 8107 | // The mask bits for all but the first condition are represented as |
| 8108 | // the low bit of the condition code value implies 't'. We currently |
| 8109 | // 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] | 8110 | // of the condition code is zero. |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 8111 | MCOperand &MO = Inst.getOperand(1); |
| 8112 | unsigned Mask = MO.getImm(); |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 8113 | unsigned OrigMask = Mask; |
Michael J. Spencer | df1ecbd7 | 2013-05-24 22:23:49 +0000 | [diff] [blame] | 8114 | unsigned TZ = countTrailingZeros(Mask); |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 8115 | if ((Inst.getOperand(0).getImm() & 1) == 0) { |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 8116 | assert(Mask && TZ <= 3 && "illegal IT mask value!"); |
Benjamin Kramer | 8bad66e | 2013-05-19 22:01:57 +0000 | [diff] [blame] | 8117 | Mask ^= (0xE << TZ) & 0xF; |
Richard Barton | f435b09 | 2012-04-27 08:42:59 +0000 | [diff] [blame] | 8118 | } |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 8119 | MO.setImm(Mask); |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 8120 | |
| 8121 | // Set up the IT block state according to the IT instruction we just |
| 8122 | // matched. |
| 8123 | assert(!inITBlock() && "nested IT blocks?!"); |
| 8124 | ITState.Cond = ARMCC::CondCodes(Inst.getOperand(0).getImm()); |
| 8125 | ITState.Mask = OrigMask; // Use the original mask, not the updated one. |
| 8126 | ITState.CurPosition = 0; |
| 8127 | ITState.FirstCond = true; |
Jim Grosbach | 3d1eac8 | 2011-08-26 21:43:41 +0000 | [diff] [blame] | 8128 | break; |
| 8129 | } |
Richard Barton | a39625e | 2012-07-09 16:12:24 +0000 | [diff] [blame] | 8130 | case ARM::t2LSLrr: |
| 8131 | case ARM::t2LSRrr: |
| 8132 | case ARM::t2ASRrr: |
| 8133 | case ARM::t2SBCrr: |
| 8134 | case ARM::t2RORrr: |
| 8135 | case ARM::t2BICrr: |
| 8136 | { |
Richard Barton | d566037 | 2012-07-09 16:14:28 +0000 | [diff] [blame] | 8137 | // Assemblers should use the narrow encodings of these instructions when permissible. |
Richard Barton | a39625e | 2012-07-09 16:12:24 +0000 | [diff] [blame] | 8138 | if ((isARMLowRegister(Inst.getOperand(1).getReg()) && |
| 8139 | isARMLowRegister(Inst.getOperand(2).getReg())) && |
| 8140 | Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() && |
Richard Barton | 984d0ba | 2012-07-09 18:30:56 +0000 | [diff] [blame] | 8141 | ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) || |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8142 | (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) && |
| 8143 | (!static_cast<ARMOperand &>(*Operands[3]).isToken() || |
| 8144 | !static_cast<ARMOperand &>(*Operands[3]).getToken().equals_lower( |
| 8145 | ".w"))) { |
Richard Barton | a39625e | 2012-07-09 16:12:24 +0000 | [diff] [blame] | 8146 | unsigned NewOpc; |
| 8147 | switch (Inst.getOpcode()) { |
| 8148 | default: llvm_unreachable("unexpected opcode"); |
| 8149 | case ARM::t2LSLrr: NewOpc = ARM::tLSLrr; break; |
| 8150 | case ARM::t2LSRrr: NewOpc = ARM::tLSRrr; break; |
| 8151 | case ARM::t2ASRrr: NewOpc = ARM::tASRrr; break; |
| 8152 | case ARM::t2SBCrr: NewOpc = ARM::tSBC; break; |
| 8153 | case ARM::t2RORrr: NewOpc = ARM::tROR; break; |
| 8154 | case ARM::t2BICrr: NewOpc = ARM::tBIC; break; |
| 8155 | } |
| 8156 | MCInst TmpInst; |
| 8157 | TmpInst.setOpcode(NewOpc); |
| 8158 | TmpInst.addOperand(Inst.getOperand(0)); |
| 8159 | TmpInst.addOperand(Inst.getOperand(5)); |
| 8160 | TmpInst.addOperand(Inst.getOperand(1)); |
| 8161 | TmpInst.addOperand(Inst.getOperand(2)); |
| 8162 | TmpInst.addOperand(Inst.getOperand(3)); |
| 8163 | TmpInst.addOperand(Inst.getOperand(4)); |
| 8164 | Inst = TmpInst; |
| 8165 | return true; |
| 8166 | } |
| 8167 | return false; |
| 8168 | } |
| 8169 | case ARM::t2ANDrr: |
| 8170 | case ARM::t2EORrr: |
| 8171 | case ARM::t2ADCrr: |
| 8172 | case ARM::t2ORRrr: |
| 8173 | { |
Richard Barton | d566037 | 2012-07-09 16:14:28 +0000 | [diff] [blame] | 8174 | // Assemblers should use the narrow encodings of these instructions when permissible. |
Richard Barton | a39625e | 2012-07-09 16:12:24 +0000 | [diff] [blame] | 8175 | // These instructions are special in that they are commutable, so shorter encodings |
| 8176 | // are available more often. |
| 8177 | if ((isARMLowRegister(Inst.getOperand(1).getReg()) && |
| 8178 | isARMLowRegister(Inst.getOperand(2).getReg())) && |
| 8179 | (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg() || |
| 8180 | Inst.getOperand(0).getReg() == Inst.getOperand(2).getReg()) && |
Richard Barton | 984d0ba | 2012-07-09 18:30:56 +0000 | [diff] [blame] | 8181 | ((!inITBlock() && Inst.getOperand(5).getReg() == ARM::CPSR) || |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8182 | (inITBlock() && Inst.getOperand(5).getReg() != ARM::CPSR)) && |
| 8183 | (!static_cast<ARMOperand &>(*Operands[3]).isToken() || |
| 8184 | !static_cast<ARMOperand &>(*Operands[3]).getToken().equals_lower( |
| 8185 | ".w"))) { |
Richard Barton | a39625e | 2012-07-09 16:12:24 +0000 | [diff] [blame] | 8186 | unsigned NewOpc; |
| 8187 | switch (Inst.getOpcode()) { |
| 8188 | default: llvm_unreachable("unexpected opcode"); |
| 8189 | case ARM::t2ADCrr: NewOpc = ARM::tADC; break; |
| 8190 | case ARM::t2ANDrr: NewOpc = ARM::tAND; break; |
| 8191 | case ARM::t2EORrr: NewOpc = ARM::tEOR; break; |
| 8192 | case ARM::t2ORRrr: NewOpc = ARM::tORR; break; |
| 8193 | } |
| 8194 | MCInst TmpInst; |
| 8195 | TmpInst.setOpcode(NewOpc); |
| 8196 | TmpInst.addOperand(Inst.getOperand(0)); |
| 8197 | TmpInst.addOperand(Inst.getOperand(5)); |
| 8198 | if (Inst.getOperand(0).getReg() == Inst.getOperand(1).getReg()) { |
| 8199 | TmpInst.addOperand(Inst.getOperand(1)); |
| 8200 | TmpInst.addOperand(Inst.getOperand(2)); |
| 8201 | } else { |
| 8202 | TmpInst.addOperand(Inst.getOperand(2)); |
| 8203 | TmpInst.addOperand(Inst.getOperand(1)); |
| 8204 | } |
| 8205 | TmpInst.addOperand(Inst.getOperand(3)); |
| 8206 | TmpInst.addOperand(Inst.getOperand(4)); |
| 8207 | Inst = TmpInst; |
| 8208 | return true; |
| 8209 | } |
| 8210 | return false; |
| 8211 | } |
Jim Grosbach | 8ba76c6 | 2011-08-11 17:35:48 +0000 | [diff] [blame] | 8212 | } |
Jim Grosbach | afad053 | 2011-11-10 23:42:14 +0000 | [diff] [blame] | 8213 | return false; |
Jim Grosbach | 8ba76c6 | 2011-08-11 17:35:48 +0000 | [diff] [blame] | 8214 | } |
| 8215 | |
Jim Grosbach | 3e941ae | 2011-08-16 20:45:50 +0000 | [diff] [blame] | 8216 | unsigned ARMAsmParser::checkTargetMatchPredicate(MCInst &Inst) { |
| 8217 | // 16-bit thumb arithmetic instructions either require or preclude the 'S' |
| 8218 | // suffix depending on whether they're in an IT block or not. |
Jim Grosbach | b7fa2c0 | 2011-08-16 22:20:01 +0000 | [diff] [blame] | 8219 | unsigned Opc = Inst.getOpcode(); |
Joey Gouly | 0e76fa7 | 2013-09-12 10:28:05 +0000 | [diff] [blame] | 8220 | const MCInstrDesc &MCID = MII.get(Opc); |
Jim Grosbach | 3e941ae | 2011-08-16 20:45:50 +0000 | [diff] [blame] | 8221 | if (MCID.TSFlags & ARMII::ThumbArithFlagSetting) { |
| 8222 | assert(MCID.hasOptionalDef() && |
| 8223 | "optionally flag setting instruction missing optional def operand"); |
| 8224 | assert(MCID.NumOperands == Inst.getNumOperands() && |
| 8225 | "operand count mismatch!"); |
| 8226 | // Find the optional-def operand (cc_out). |
| 8227 | unsigned OpNo; |
| 8228 | for (OpNo = 0; |
| 8229 | !MCID.OpInfo[OpNo].isOptionalDef() && OpNo < MCID.NumOperands; |
| 8230 | ++OpNo) |
| 8231 | ; |
| 8232 | // If we're parsing Thumb1, reject it completely. |
| 8233 | if (isThumbOne() && Inst.getOperand(OpNo).getReg() != ARM::CPSR) |
| 8234 | return Match_MnemonicFail; |
| 8235 | // If we're parsing Thumb2, which form is legal depends on whether we're |
| 8236 | // in an IT block. |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 8237 | if (isThumbTwo() && Inst.getOperand(OpNo).getReg() != ARM::CPSR && |
| 8238 | !inITBlock()) |
Jim Grosbach | 3e941ae | 2011-08-16 20:45:50 +0000 | [diff] [blame] | 8239 | return Match_RequiresITBlock; |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 8240 | if (isThumbTwo() && Inst.getOperand(OpNo).getReg() == ARM::CPSR && |
| 8241 | inITBlock()) |
| 8242 | return Match_RequiresNotITBlock; |
Jim Grosbach | 3e941ae | 2011-08-16 20:45:50 +0000 | [diff] [blame] | 8243 | } |
Jim Grosbach | b7fa2c0 | 2011-08-16 22:20:01 +0000 | [diff] [blame] | 8244 | // Some high-register supporting Thumb1 encodings only allow both registers |
| 8245 | // to be from r0-r7 when in Thumb2. |
Renato Golin | 36c626e | 2014-09-26 16:14:29 +0000 | [diff] [blame] | 8246 | else if (Opc == ARM::tADDhirr && isThumbOne() && !hasV6MOps() && |
Jim Grosbach | b7fa2c0 | 2011-08-16 22:20:01 +0000 | [diff] [blame] | 8247 | isARMLowRegister(Inst.getOperand(1).getReg()) && |
| 8248 | isARMLowRegister(Inst.getOperand(2).getReg())) |
| 8249 | return Match_RequiresThumb2; |
| 8250 | // Others only require ARMv6 or later. |
Jim Grosbach | f86cd37 | 2011-08-19 20:46:54 +0000 | [diff] [blame] | 8251 | else if (Opc == ARM::tMOVr && isThumbOne() && !hasV6Ops() && |
Jim Grosbach | b7fa2c0 | 2011-08-16 22:20:01 +0000 | [diff] [blame] | 8252 | isARMLowRegister(Inst.getOperand(0).getReg()) && |
| 8253 | isARMLowRegister(Inst.getOperand(1).getReg())) |
| 8254 | return Match_RequiresV6; |
Jim Grosbach | 3e941ae | 2011-08-16 20:45:50 +0000 | [diff] [blame] | 8255 | return Match_Success; |
| 8256 | } |
| 8257 | |
Benjamin Kramer | 44a53da | 2014-04-12 18:45:24 +0000 | [diff] [blame] | 8258 | namespace llvm { |
| 8259 | template <> inline bool IsCPSRDead<MCInst>(MCInst *Instr) { |
Artyom Skrobov | 1a6cd1d | 2014-02-26 11:27:28 +0000 | [diff] [blame] | 8260 | return true; // In an assembly source, no need to second-guess |
| 8261 | } |
Benjamin Kramer | 44a53da | 2014-04-12 18:45:24 +0000 | [diff] [blame] | 8262 | } |
Artyom Skrobov | 1a6cd1d | 2014-02-26 11:27:28 +0000 | [diff] [blame] | 8263 | |
Tim Northover | 26bb14e | 2014-08-18 11:49:42 +0000 | [diff] [blame] | 8264 | static const char *getSubtargetFeatureName(uint64_t Val); |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8265 | bool ARMAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode, |
| 8266 | OperandVector &Operands, |
Tim Northover | 26bb14e | 2014-08-18 11:49:42 +0000 | [diff] [blame] | 8267 | MCStreamer &Out, uint64_t &ErrorInfo, |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8268 | bool MatchingInlineAsm) { |
Chris Lattner | 9487de6 | 2010-10-28 21:28:01 +0000 | [diff] [blame] | 8269 | MCInst Inst; |
Jim Grosbach | 120a96a | 2011-08-15 23:03:29 +0000 | [diff] [blame] | 8270 | unsigned MatchResult; |
Weiming Zhao | 8f56f88 | 2012-11-16 21:55:34 +0000 | [diff] [blame] | 8271 | |
Chad Rosier | 2f480a8 | 2012-10-12 22:53:36 +0000 | [diff] [blame] | 8272 | MatchResult = MatchInstructionImpl(Operands, Inst, ErrorInfo, |
Chad Rosier | 4996355 | 2012-10-13 00:26:04 +0000 | [diff] [blame] | 8273 | MatchingInlineAsm); |
Kevin Enderby | 3164a34 | 2010-12-09 19:19:43 +0000 | [diff] [blame] | 8274 | switch (MatchResult) { |
Jim Grosbach | 120a96a | 2011-08-15 23:03:29 +0000 | [diff] [blame] | 8275 | default: break; |
Chris Lattner | d27b05e | 2010-10-28 21:41:58 +0000 | [diff] [blame] | 8276 | case Match_Success: |
Jim Grosbach | edaa35a | 2011-07-26 18:25:39 +0000 | [diff] [blame] | 8277 | // Context sensitive operand constraints aren't handled by the matcher, |
| 8278 | // so check them here. |
Jim Grosbach | a0d34d3 | 2011-09-02 23:22:08 +0000 | [diff] [blame] | 8279 | if (validateInstruction(Inst, Operands)) { |
| 8280 | // Still progress the IT block, otherwise one wrong condition causes |
| 8281 | // nasty cascading errors. |
| 8282 | forwardITPosition(); |
Jim Grosbach | edaa35a | 2011-07-26 18:25:39 +0000 | [diff] [blame] | 8283 | return true; |
Jim Grosbach | a0d34d3 | 2011-09-02 23:22:08 +0000 | [diff] [blame] | 8284 | } |
Jim Grosbach | edaa35a | 2011-07-26 18:25:39 +0000 | [diff] [blame] | 8285 | |
Amara Emerson | 52cfb6a | 2013-10-03 09:31:51 +0000 | [diff] [blame] | 8286 | { // processInstruction() updates inITBlock state, we need to save it away |
| 8287 | bool wasInITBlock = inITBlock(); |
| 8288 | |
| 8289 | // Some instructions need post-processing to, for example, tweak which |
| 8290 | // encoding is selected. Loop on it while changes happen so the |
| 8291 | // individual transformations can chain off each other. E.g., |
| 8292 | // tPOP(r8)->t2LDMIA_UPD(sp,r8)->t2STR_POST(sp,r8) |
| 8293 | while (processInstruction(Inst, Operands)) |
| 8294 | ; |
| 8295 | |
| 8296 | // Only after the instruction is fully processed, we can validate it |
| 8297 | if (wasInITBlock && hasV8Ops() && isThumb() && |
Weiming Zhao | 5930ae6 | 2014-01-23 19:55:33 +0000 | [diff] [blame] | 8298 | !isV8EligibleForIT(&Inst)) { |
Amara Emerson | 52cfb6a | 2013-10-03 09:31:51 +0000 | [diff] [blame] | 8299 | Warning(IDLoc, "deprecated instruction in IT block"); |
| 8300 | } |
| 8301 | } |
Jim Grosbach | 8ba76c6 | 2011-08-11 17:35:48 +0000 | [diff] [blame] | 8302 | |
Jim Grosbach | a0d34d3 | 2011-09-02 23:22:08 +0000 | [diff] [blame] | 8303 | // Only move forward at the very end so that everything in validate |
| 8304 | // and process gets a consistent answer about whether we're in an IT |
| 8305 | // block. |
| 8306 | forwardITPosition(); |
| 8307 | |
Jim Grosbach | 82f76d1 | 2012-01-25 19:52:01 +0000 | [diff] [blame] | 8308 | // ITasm is an ARM mode pseudo-instruction that just sets the ITblock and |
| 8309 | // doesn't actually encode. |
| 8310 | if (Inst.getOpcode() == ARM::ITasm) |
| 8311 | return false; |
| 8312 | |
Jim Grosbach | 5e5eabb | 2012-01-26 23:20:15 +0000 | [diff] [blame] | 8313 | Inst.setLoc(IDLoc); |
David Woodhouse | e6c13e4 | 2014-01-28 23:12:42 +0000 | [diff] [blame] | 8314 | Out.EmitInstruction(Inst, STI); |
Chris Lattner | 9487de6 | 2010-10-28 21:28:01 +0000 | [diff] [blame] | 8315 | return false; |
Jim Grosbach | 5117ef7 | 2012-04-24 22:40:08 +0000 | [diff] [blame] | 8316 | case Match_MissingFeature: { |
| 8317 | assert(ErrorInfo && "Unknown missing feature!"); |
| 8318 | // Special case the error message for the very common case where only |
| 8319 | // a single subtarget feature is missing (Thumb vs. ARM, e.g.). |
| 8320 | std::string Msg = "instruction requires:"; |
Tim Northover | 26bb14e | 2014-08-18 11:49:42 +0000 | [diff] [blame] | 8321 | uint64_t Mask = 1; |
Jim Grosbach | 5117ef7 | 2012-04-24 22:40:08 +0000 | [diff] [blame] | 8322 | for (unsigned i = 0; i < (sizeof(ErrorInfo)*8-1); ++i) { |
| 8323 | if (ErrorInfo & Mask) { |
| 8324 | Msg += " "; |
| 8325 | Msg += getSubtargetFeatureName(ErrorInfo & Mask); |
| 8326 | } |
| 8327 | Mask <<= 1; |
| 8328 | } |
| 8329 | return Error(IDLoc, Msg); |
| 8330 | } |
Chris Lattner | d27b05e | 2010-10-28 21:41:58 +0000 | [diff] [blame] | 8331 | case Match_InvalidOperand: { |
| 8332 | SMLoc ErrorLoc = IDLoc; |
Tim Northover | 26bb14e | 2014-08-18 11:49:42 +0000 | [diff] [blame] | 8333 | if (ErrorInfo != ~0ULL) { |
Chris Lattner | d27b05e | 2010-10-28 21:41:58 +0000 | [diff] [blame] | 8334 | if (ErrorInfo >= Operands.size()) |
| 8335 | return Error(IDLoc, "too few operands for instruction"); |
Jim Grosbach | 624bcc7 | 2010-10-29 14:46:02 +0000 | [diff] [blame] | 8336 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8337 | ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc(); |
Chris Lattner | d27b05e | 2010-10-28 21:41:58 +0000 | [diff] [blame] | 8338 | if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc; |
| 8339 | } |
Jim Grosbach | 624bcc7 | 2010-10-29 14:46:02 +0000 | [diff] [blame] | 8340 | |
Chris Lattner | d27b05e | 2010-10-28 21:41:58 +0000 | [diff] [blame] | 8341 | return Error(ErrorLoc, "invalid operand for instruction"); |
Chris Lattner | 9487de6 | 2010-10-28 21:28:01 +0000 | [diff] [blame] | 8342 | } |
Chris Lattner | d27b05e | 2010-10-28 21:41:58 +0000 | [diff] [blame] | 8343 | case Match_MnemonicFail: |
Benjamin Kramer | 673824b | 2012-04-15 17:04:27 +0000 | [diff] [blame] | 8344 | return Error(IDLoc, "invalid instruction", |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8345 | ((ARMOperand &)*Operands[0]).getLocRange()); |
Jim Grosbach | ed16ec4 | 2011-08-29 22:24:09 +0000 | [diff] [blame] | 8346 | case Match_RequiresNotITBlock: |
| 8347 | return Error(IDLoc, "flag setting instruction only valid outside IT block"); |
Jim Grosbach | 3e941ae | 2011-08-16 20:45:50 +0000 | [diff] [blame] | 8348 | case Match_RequiresITBlock: |
| 8349 | return Error(IDLoc, "instruction only valid inside IT block"); |
Jim Grosbach | b7fa2c0 | 2011-08-16 22:20:01 +0000 | [diff] [blame] | 8350 | case Match_RequiresV6: |
| 8351 | return Error(IDLoc, "instruction variant requires ARMv6 or later"); |
| 8352 | case Match_RequiresThumb2: |
| 8353 | return Error(IDLoc, "instruction variant requires Thumb2"); |
Jim Grosbach | 087affe | 2012-06-22 23:56:48 +0000 | [diff] [blame] | 8354 | case Match_ImmRange0_15: { |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8355 | SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc(); |
Jim Grosbach | 087affe | 2012-06-22 23:56:48 +0000 | [diff] [blame] | 8356 | if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc; |
| 8357 | return Error(ErrorLoc, "immediate operand must be in the range [0,15]"); |
| 8358 | } |
Artyom Skrobov | fc12e70 | 2013-10-23 10:14:40 +0000 | [diff] [blame] | 8359 | case Match_ImmRange0_239: { |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8360 | SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getStartLoc(); |
Artyom Skrobov | fc12e70 | 2013-10-23 10:14:40 +0000 | [diff] [blame] | 8361 | if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc; |
| 8362 | return Error(ErrorLoc, "immediate operand must be in the range [0,239]"); |
| 8363 | } |
Kevin Enderby | 488f20b | 2014-04-10 20:18:58 +0000 | [diff] [blame] | 8364 | case Match_AlignedMemoryRequiresNone: |
| 8365 | case Match_DupAlignedMemoryRequiresNone: |
| 8366 | case Match_AlignedMemoryRequires16: |
| 8367 | case Match_DupAlignedMemoryRequires16: |
| 8368 | case Match_AlignedMemoryRequires32: |
| 8369 | case Match_DupAlignedMemoryRequires32: |
| 8370 | case Match_AlignedMemoryRequires64: |
| 8371 | case Match_DupAlignedMemoryRequires64: |
| 8372 | case Match_AlignedMemoryRequires64or128: |
| 8373 | case Match_DupAlignedMemoryRequires64or128: |
| 8374 | case Match_AlignedMemoryRequires64or128or256: |
| 8375 | { |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 8376 | SMLoc ErrorLoc = ((ARMOperand &)*Operands[ErrorInfo]).getAlignmentLoc(); |
Kevin Enderby | 488f20b | 2014-04-10 20:18:58 +0000 | [diff] [blame] | 8377 | if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc; |
| 8378 | switch (MatchResult) { |
| 8379 | default: |
| 8380 | llvm_unreachable("Missing Match_Aligned type"); |
| 8381 | case Match_AlignedMemoryRequiresNone: |
| 8382 | case Match_DupAlignedMemoryRequiresNone: |
| 8383 | return Error(ErrorLoc, "alignment must be omitted"); |
| 8384 | case Match_AlignedMemoryRequires16: |
| 8385 | case Match_DupAlignedMemoryRequires16: |
| 8386 | return Error(ErrorLoc, "alignment must be 16 or omitted"); |
| 8387 | case Match_AlignedMemoryRequires32: |
| 8388 | case Match_DupAlignedMemoryRequires32: |
| 8389 | return Error(ErrorLoc, "alignment must be 32 or omitted"); |
| 8390 | case Match_AlignedMemoryRequires64: |
| 8391 | case Match_DupAlignedMemoryRequires64: |
| 8392 | return Error(ErrorLoc, "alignment must be 64 or omitted"); |
| 8393 | case Match_AlignedMemoryRequires64or128: |
| 8394 | case Match_DupAlignedMemoryRequires64or128: |
| 8395 | return Error(ErrorLoc, "alignment must be 64, 128 or omitted"); |
| 8396 | case Match_AlignedMemoryRequires64or128or256: |
| 8397 | return Error(ErrorLoc, "alignment must be 64, 128, 256 or omitted"); |
| 8398 | } |
| 8399 | } |
Chris Lattner | d27b05e | 2010-10-28 21:41:58 +0000 | [diff] [blame] | 8400 | } |
Jim Grosbach | 624bcc7 | 2010-10-29 14:46:02 +0000 | [diff] [blame] | 8401 | |
Eric Christopher | 91d7b90 | 2010-10-29 09:26:59 +0000 | [diff] [blame] | 8402 | llvm_unreachable("Implement any new match types added!"); |
Chris Lattner | 9487de6 | 2010-10-28 21:28:01 +0000 | [diff] [blame] | 8403 | } |
| 8404 | |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8405 | /// parseDirective parses the arm specific directives |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 8406 | bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) { |
Saleem Abdulrasool | dd979e6 | 2014-04-05 22:09:51 +0000 | [diff] [blame] | 8407 | const MCObjectFileInfo::Environment Format = |
| 8408 | getContext().getObjectFileInfo()->getObjectFileType(); |
| 8409 | bool IsMachO = Format == MCObjectFileInfo::IsMachO; |
Saleem Abdulrasool | bfdfb14 | 2014-09-18 04:28:29 +0000 | [diff] [blame] | 8410 | bool IsCOFF = Format == MCObjectFileInfo::IsCOFF; |
Saleem Abdulrasool | dd979e6 | 2014-04-05 22:09:51 +0000 | [diff] [blame] | 8411 | |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 8412 | StringRef IDVal = DirectiveID.getIdentifier(); |
| 8413 | if (IDVal == ".word") |
Saleem Abdulrasool | 3897651 | 2014-02-23 06:22:09 +0000 | [diff] [blame] | 8414 | return parseLiteralValues(4, DirectiveID.getLoc()); |
| 8415 | else if (IDVal == ".short" || IDVal == ".hword") |
| 8416 | return parseLiteralValues(2, DirectiveID.getLoc()); |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8417 | else if (IDVal == ".thumb") |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8418 | return parseDirectiveThumb(DirectiveID.getLoc()); |
Jim Grosbach | 7f88239 | 2011-12-07 18:04:19 +0000 | [diff] [blame] | 8419 | else if (IDVal == ".arm") |
| 8420 | return parseDirectiveARM(DirectiveID.getLoc()); |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8421 | else if (IDVal == ".thumb_func") |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8422 | return parseDirectiveThumbFunc(DirectiveID.getLoc()); |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8423 | else if (IDVal == ".code") |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8424 | return parseDirectiveCode(DirectiveID.getLoc()); |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8425 | else if (IDVal == ".syntax") |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8426 | return parseDirectiveSyntax(DirectiveID.getLoc()); |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 8427 | else if (IDVal == ".unreq") |
| 8428 | return parseDirectiveUnreq(DirectiveID.getLoc()); |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8429 | else if (IDVal == ".fnend") |
| 8430 | return parseDirectiveFnEnd(DirectiveID.getLoc()); |
| 8431 | else if (IDVal == ".cantunwind") |
| 8432 | return parseDirectiveCantUnwind(DirectiveID.getLoc()); |
| 8433 | else if (IDVal == ".personality") |
| 8434 | return parseDirectivePersonality(DirectiveID.getLoc()); |
| 8435 | else if (IDVal == ".handlerdata") |
| 8436 | return parseDirectiveHandlerData(DirectiveID.getLoc()); |
| 8437 | else if (IDVal == ".setfp") |
| 8438 | return parseDirectiveSetFP(DirectiveID.getLoc()); |
| 8439 | else if (IDVal == ".pad") |
| 8440 | return parseDirectivePad(DirectiveID.getLoc()); |
| 8441 | else if (IDVal == ".save") |
| 8442 | return parseDirectiveRegSave(DirectiveID.getLoc(), false); |
| 8443 | else if (IDVal == ".vsave") |
| 8444 | return parseDirectiveRegSave(DirectiveID.getLoc(), true); |
Saleem Abdulrasool | 6e6c239 | 2013-12-20 07:21:16 +0000 | [diff] [blame] | 8445 | else if (IDVal == ".ltorg" || IDVal == ".pool") |
David Peixotto | 80c083a | 2013-12-19 18:26:07 +0000 | [diff] [blame] | 8446 | return parseDirectiveLtorg(DirectiveID.getLoc()); |
Saleem Abdulrasool | a554968 | 2013-12-26 01:52:28 +0000 | [diff] [blame] | 8447 | else if (IDVal == ".even") |
| 8448 | return parseDirectiveEven(DirectiveID.getLoc()); |
Saleem Abdulrasool | 662f5c1 | 2014-01-21 02:33:02 +0000 | [diff] [blame] | 8449 | else if (IDVal == ".personalityindex") |
| 8450 | return parseDirectivePersonalityIndex(DirectiveID.getLoc()); |
Saleem Abdulrasool | d9f0860 | 2014-01-21 02:33:10 +0000 | [diff] [blame] | 8451 | else if (IDVal == ".unwind_raw") |
| 8452 | return parseDirectiveUnwindRaw(DirectiveID.getLoc()); |
Saleem Abdulrasool | 5d962d3 | 2014-01-30 04:46:24 +0000 | [diff] [blame] | 8453 | else if (IDVal == ".movsp") |
| 8454 | return parseDirectiveMovSP(DirectiveID.getLoc()); |
Saleem Abdulrasool | 49480bf | 2014-02-16 00:16:41 +0000 | [diff] [blame] | 8455 | else if (IDVal == ".arch_extension") |
| 8456 | return parseDirectiveArchExtension(DirectiveID.getLoc()); |
Saleem Abdulrasool | fd6ed1e | 2014-02-23 17:45:32 +0000 | [diff] [blame] | 8457 | else if (IDVal == ".align") |
| 8458 | return parseDirectiveAlign(DirectiveID.getLoc()); |
Saleem Abdulrasool | 39f773f | 2014-03-20 06:05:33 +0000 | [diff] [blame] | 8459 | else if (IDVal == ".thumb_set") |
| 8460 | return parseDirectiveThumbSet(DirectiveID.getLoc()); |
Saleem Abdulrasool | dd979e6 | 2014-04-05 22:09:51 +0000 | [diff] [blame] | 8461 | |
Saleem Abdulrasool | bfdfb14 | 2014-09-18 04:28:29 +0000 | [diff] [blame] | 8462 | if (!IsMachO && !IsCOFF) { |
Saleem Abdulrasool | dd979e6 | 2014-04-05 22:09:51 +0000 | [diff] [blame] | 8463 | if (IDVal == ".arch") |
| 8464 | return parseDirectiveArch(DirectiveID.getLoc()); |
| 8465 | else if (IDVal == ".cpu") |
| 8466 | return parseDirectiveCPU(DirectiveID.getLoc()); |
| 8467 | else if (IDVal == ".eabi_attribute") |
| 8468 | return parseDirectiveEabiAttr(DirectiveID.getLoc()); |
| 8469 | else if (IDVal == ".fpu") |
| 8470 | return parseDirectiveFPU(DirectiveID.getLoc()); |
| 8471 | else if (IDVal == ".fnstart") |
| 8472 | return parseDirectiveFnStart(DirectiveID.getLoc()); |
| 8473 | else if (IDVal == ".inst") |
| 8474 | return parseDirectiveInst(DirectiveID.getLoc()); |
| 8475 | else if (IDVal == ".inst.n") |
| 8476 | return parseDirectiveInst(DirectiveID.getLoc(), 'n'); |
| 8477 | else if (IDVal == ".inst.w") |
| 8478 | return parseDirectiveInst(DirectiveID.getLoc(), 'w'); |
| 8479 | else if (IDVal == ".object_arch") |
| 8480 | return parseDirectiveObjectArch(DirectiveID.getLoc()); |
| 8481 | else if (IDVal == ".tlsdescseq") |
| 8482 | return parseDirectiveTLSDescSeq(DirectiveID.getLoc()); |
| 8483 | } |
| 8484 | |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 8485 | return true; |
| 8486 | } |
| 8487 | |
Saleem Abdulrasool | 3897651 | 2014-02-23 06:22:09 +0000 | [diff] [blame] | 8488 | /// parseLiteralValues |
| 8489 | /// ::= .hword expression [, expression]* |
| 8490 | /// ::= .short expression [, expression]* |
| 8491 | /// ::= .word expression [, expression]* |
| 8492 | bool ARMAsmParser::parseLiteralValues(unsigned Size, SMLoc L) { |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 8493 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
| 8494 | for (;;) { |
| 8495 | const MCExpr *Value; |
Saleem Abdulrasool | a903661 | 2014-01-26 22:29:50 +0000 | [diff] [blame] | 8496 | if (getParser().parseExpression(Value)) { |
| 8497 | Parser.eatToEndOfStatement(); |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 8498 | return false; |
Saleem Abdulrasool | a903661 | 2014-01-26 22:29:50 +0000 | [diff] [blame] | 8499 | } |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 8500 | |
Eric Christopher | bf7bc49 | 2013-01-09 03:52:05 +0000 | [diff] [blame] | 8501 | getParser().getStreamer().EmitValue(Value, Size); |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 8502 | |
| 8503 | if (getLexer().is(AsmToken::EndOfStatement)) |
| 8504 | break; |
Jim Grosbach | 624bcc7 | 2010-10-29 14:46:02 +0000 | [diff] [blame] | 8505 | |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 8506 | // FIXME: Improve diagnostic. |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 8507 | if (getLexer().isNot(AsmToken::Comma)) { |
| 8508 | Error(L, "unexpected token in directive"); |
| 8509 | return false; |
| 8510 | } |
Sean Callanan | a83fd7d | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 8511 | Parser.Lex(); |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 8512 | } |
| 8513 | } |
| 8514 | |
Sean Callanan | a83fd7d | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 8515 | Parser.Lex(); |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 8516 | return false; |
| 8517 | } |
| 8518 | |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8519 | /// parseDirectiveThumb |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8520 | /// ::= .thumb |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8521 | bool ARMAsmParser::parseDirectiveThumb(SMLoc L) { |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 8522 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
| 8523 | Error(L, "unexpected token in directive"); |
| 8524 | return false; |
| 8525 | } |
Sean Callanan | a83fd7d | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 8526 | Parser.Lex(); |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8527 | |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 8528 | if (!hasThumb()) { |
| 8529 | Error(L, "target does not support Thumb mode"); |
| 8530 | return false; |
| 8531 | } |
Tim Northover | a2292d0 | 2013-06-10 23:20:58 +0000 | [diff] [blame] | 8532 | |
Jim Grosbach | 7f88239 | 2011-12-07 18:04:19 +0000 | [diff] [blame] | 8533 | if (!isThumb()) |
| 8534 | SwitchMode(); |
Saleem Abdulrasool | 44419fc | 2014-03-22 19:26:18 +0000 | [diff] [blame] | 8535 | |
Jim Grosbach | 7f88239 | 2011-12-07 18:04:19 +0000 | [diff] [blame] | 8536 | getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16); |
| 8537 | return false; |
| 8538 | } |
| 8539 | |
| 8540 | /// parseDirectiveARM |
| 8541 | /// ::= .arm |
| 8542 | bool ARMAsmParser::parseDirectiveARM(SMLoc L) { |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 8543 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
| 8544 | Error(L, "unexpected token in directive"); |
| 8545 | return false; |
| 8546 | } |
Jim Grosbach | 7f88239 | 2011-12-07 18:04:19 +0000 | [diff] [blame] | 8547 | Parser.Lex(); |
| 8548 | |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 8549 | if (!hasARM()) { |
| 8550 | Error(L, "target does not support ARM mode"); |
| 8551 | return false; |
| 8552 | } |
Tim Northover | a2292d0 | 2013-06-10 23:20:58 +0000 | [diff] [blame] | 8553 | |
Jim Grosbach | 7f88239 | 2011-12-07 18:04:19 +0000 | [diff] [blame] | 8554 | if (isThumb()) |
| 8555 | SwitchMode(); |
Saleem Abdulrasool | 44419fc | 2014-03-22 19:26:18 +0000 | [diff] [blame] | 8556 | |
Jim Grosbach | 7f88239 | 2011-12-07 18:04:19 +0000 | [diff] [blame] | 8557 | getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32); |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8558 | return false; |
| 8559 | } |
| 8560 | |
Tim Northover | 1744d0a | 2013-10-25 12:49:50 +0000 | [diff] [blame] | 8561 | void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) { |
| 8562 | if (NextSymbolIsThumb) { |
| 8563 | getParser().getStreamer().EmitThumbFunc(Symbol); |
| 8564 | NextSymbolIsThumb = false; |
| 8565 | } |
| 8566 | } |
| 8567 | |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8568 | /// parseDirectiveThumbFunc |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8569 | /// ::= .thumbfunc symbol_name |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8570 | bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) { |
Saleem Abdulrasool | 8c61c6c | 2014-09-18 03:49:55 +0000 | [diff] [blame] | 8571 | const auto Format = getContext().getObjectFileInfo()->getObjectFileType(); |
| 8572 | bool IsMachO = Format == MCObjectFileInfo::IsMachO; |
Rafael Espindola | e90c1cb | 2011-05-16 16:17:21 +0000 | [diff] [blame] | 8573 | |
Jim Grosbach | 1152cc0 | 2011-12-21 22:30:16 +0000 | [diff] [blame] | 8574 | // Darwin asm has (optionally) function name after .thumb_func direction |
Rafael Espindola | e90c1cb | 2011-05-16 16:17:21 +0000 | [diff] [blame] | 8575 | // ELF doesn't |
Saleem Abdulrasool | 8c61c6c | 2014-09-18 03:49:55 +0000 | [diff] [blame] | 8576 | if (IsMachO) { |
Rafael Espindola | e90c1cb | 2011-05-16 16:17:21 +0000 | [diff] [blame] | 8577 | const AsmToken &Tok = Parser.getTok(); |
Jim Grosbach | 1152cc0 | 2011-12-21 22:30:16 +0000 | [diff] [blame] | 8578 | if (Tok.isNot(AsmToken::EndOfStatement)) { |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 8579 | if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String)) { |
| 8580 | Error(L, "unexpected token in .thumb_func directive"); |
| 8581 | return false; |
| 8582 | } |
| 8583 | |
Tim Northover | 1744d0a | 2013-10-25 12:49:50 +0000 | [diff] [blame] | 8584 | MCSymbol *Func = |
| 8585 | getParser().getContext().GetOrCreateSymbol(Tok.getIdentifier()); |
| 8586 | getParser().getStreamer().EmitThumbFunc(Func); |
Jim Grosbach | 1152cc0 | 2011-12-21 22:30:16 +0000 | [diff] [blame] | 8587 | Parser.Lex(); // Consume the identifier token. |
Tim Northover | 1744d0a | 2013-10-25 12:49:50 +0000 | [diff] [blame] | 8588 | return false; |
Jim Grosbach | 1152cc0 | 2011-12-21 22:30:16 +0000 | [diff] [blame] | 8589 | } |
Rafael Espindola | e90c1cb | 2011-05-16 16:17:21 +0000 | [diff] [blame] | 8590 | } |
| 8591 | |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 8592 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
Saleem Abdulrasool | 8c61c6c | 2014-09-18 03:49:55 +0000 | [diff] [blame] | 8593 | Error(Parser.getTok().getLoc(), "unexpected token in directive"); |
| 8594 | Parser.eatToEndOfStatement(); |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 8595 | return false; |
| 8596 | } |
Jim Grosbach | 1152cc0 | 2011-12-21 22:30:16 +0000 | [diff] [blame] | 8597 | |
Tim Northover | 1744d0a | 2013-10-25 12:49:50 +0000 | [diff] [blame] | 8598 | NextSymbolIsThumb = true; |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8599 | return false; |
| 8600 | } |
| 8601 | |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8602 | /// parseDirectiveSyntax |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8603 | /// ::= .syntax unified | divided |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8604 | bool ARMAsmParser::parseDirectiveSyntax(SMLoc L) { |
Sean Callanan | 936b0d3 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 8605 | const AsmToken &Tok = Parser.getTok(); |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 8606 | if (Tok.isNot(AsmToken::Identifier)) { |
| 8607 | Error(L, "unexpected token in .syntax directive"); |
| 8608 | return false; |
| 8609 | } |
| 8610 | |
Benjamin Kramer | 92d8998 | 2010-07-14 22:38:02 +0000 | [diff] [blame] | 8611 | StringRef Mode = Tok.getString(); |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 8612 | if (Mode == "unified" || Mode == "UNIFIED") { |
Sean Callanan | a83fd7d | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 8613 | Parser.Lex(); |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 8614 | } else if (Mode == "divided" || Mode == "DIVIDED") { |
| 8615 | Error(L, "'.syntax divided' arm asssembly not supported"); |
| 8616 | return false; |
| 8617 | } else { |
| 8618 | Error(L, "unrecognized syntax mode in .syntax directive"); |
| 8619 | return false; |
| 8620 | } |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8621 | |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8622 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
| 8623 | Error(Parser.getTok().getLoc(), "unexpected token in directive"); |
| 8624 | return false; |
| 8625 | } |
Sean Callanan | a83fd7d | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 8626 | Parser.Lex(); |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8627 | |
| 8628 | // TODO tell the MC streamer the mode |
| 8629 | // getParser().getStreamer().Emit???(); |
| 8630 | return false; |
| 8631 | } |
| 8632 | |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8633 | /// parseDirectiveCode |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8634 | /// ::= .code 16 | 32 |
Jim Grosbach | eab1c0d | 2011-07-26 17:10:22 +0000 | [diff] [blame] | 8635 | bool ARMAsmParser::parseDirectiveCode(SMLoc L) { |
Sean Callanan | 936b0d3 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 8636 | const AsmToken &Tok = Parser.getTok(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8637 | if (Tok.isNot(AsmToken::Integer)) { |
| 8638 | Error(L, "unexpected token in .code directive"); |
| 8639 | return false; |
| 8640 | } |
Sean Callanan | 936b0d3 | 2010-01-19 21:44:56 +0000 | [diff] [blame] | 8641 | int64_t Val = Parser.getTok().getIntVal(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8642 | if (Val != 16 && Val != 32) { |
| 8643 | Error(L, "invalid operand to .code directive"); |
| 8644 | return false; |
| 8645 | } |
| 8646 | Parser.Lex(); |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8647 | |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8648 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
| 8649 | Error(Parser.getTok().getLoc(), "unexpected token in directive"); |
| 8650 | return false; |
| 8651 | } |
Sean Callanan | a83fd7d | 2010-01-19 20:27:46 +0000 | [diff] [blame] | 8652 | Parser.Lex(); |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8653 | |
Evan Cheng | 284b467 | 2011-07-08 22:36:29 +0000 | [diff] [blame] | 8654 | if (Val == 16) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8655 | if (!hasThumb()) { |
| 8656 | Error(L, "target does not support Thumb mode"); |
| 8657 | return false; |
| 8658 | } |
Tim Northover | a2292d0 | 2013-06-10 23:20:58 +0000 | [diff] [blame] | 8659 | |
Jim Grosbach | f471ac3 | 2011-09-06 18:46:23 +0000 | [diff] [blame] | 8660 | if (!isThumb()) |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 8661 | SwitchMode(); |
Jim Grosbach | f471ac3 | 2011-09-06 18:46:23 +0000 | [diff] [blame] | 8662 | getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16); |
Evan Cheng | 284b467 | 2011-07-08 22:36:29 +0000 | [diff] [blame] | 8663 | } else { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8664 | if (!hasARM()) { |
| 8665 | Error(L, "target does not support ARM mode"); |
| 8666 | return false; |
| 8667 | } |
Tim Northover | a2292d0 | 2013-06-10 23:20:58 +0000 | [diff] [blame] | 8668 | |
Jim Grosbach | f471ac3 | 2011-09-06 18:46:23 +0000 | [diff] [blame] | 8669 | if (isThumb()) |
Evan Cheng | 91111d2 | 2011-07-09 05:47:46 +0000 | [diff] [blame] | 8670 | SwitchMode(); |
Jim Grosbach | f471ac3 | 2011-09-06 18:46:23 +0000 | [diff] [blame] | 8671 | getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32); |
Evan Cheng | 45543ba | 2011-07-08 22:49:55 +0000 | [diff] [blame] | 8672 | } |
Jim Grosbach | 2db0ea0 | 2010-11-05 22:40:53 +0000 | [diff] [blame] | 8673 | |
Kevin Enderby | 146dcf2 | 2009-10-15 20:48:48 +0000 | [diff] [blame] | 8674 | return false; |
| 8675 | } |
| 8676 | |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 8677 | /// parseDirectiveReq |
| 8678 | /// ::= name .req registername |
| 8679 | bool ARMAsmParser::parseDirectiveReq(StringRef Name, SMLoc L) { |
| 8680 | Parser.Lex(); // Eat the '.req' token. |
| 8681 | unsigned Reg; |
| 8682 | SMLoc SRegLoc, ERegLoc; |
| 8683 | if (ParseRegister(Reg, SRegLoc, ERegLoc)) { |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 8684 | Parser.eatToEndOfStatement(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8685 | Error(SRegLoc, "register name expected"); |
| 8686 | return false; |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 8687 | } |
| 8688 | |
| 8689 | // Shouldn't be anything else. |
| 8690 | if (Parser.getTok().isNot(AsmToken::EndOfStatement)) { |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 8691 | Parser.eatToEndOfStatement(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8692 | Error(Parser.getTok().getLoc(), "unexpected input in .req directive."); |
| 8693 | return false; |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 8694 | } |
| 8695 | |
| 8696 | Parser.Lex(); // Consume the EndOfStatement |
| 8697 | |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8698 | if (RegisterReqs.GetOrCreateValue(Name, Reg).getValue() != Reg) { |
| 8699 | Error(SRegLoc, "redefinition of '" + Name + "' does not match original."); |
| 8700 | return false; |
| 8701 | } |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 8702 | |
| 8703 | return false; |
| 8704 | } |
| 8705 | |
| 8706 | /// parseDirectiveUneq |
| 8707 | /// ::= .unreq registername |
| 8708 | bool ARMAsmParser::parseDirectiveUnreq(SMLoc L) { |
| 8709 | if (Parser.getTok().isNot(AsmToken::Identifier)) { |
Jim Grosbach | d2037eb | 2013-02-20 22:21:35 +0000 | [diff] [blame] | 8710 | Parser.eatToEndOfStatement(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8711 | Error(L, "unexpected input in .unreq directive."); |
| 8712 | return false; |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 8713 | } |
Duncan P. N. Exon Smith | 29db0eb | 2014-03-07 16:16:52 +0000 | [diff] [blame] | 8714 | RegisterReqs.erase(Parser.getTok().getIdentifier().lower()); |
Jim Grosbach | ab5830e | 2011-12-14 02:16:11 +0000 | [diff] [blame] | 8715 | Parser.Lex(); // Eat the identifier. |
| 8716 | return false; |
| 8717 | } |
| 8718 | |
Jason W Kim | 135d244 | 2011-12-20 17:38:12 +0000 | [diff] [blame] | 8719 | /// parseDirectiveArch |
| 8720 | /// ::= .arch token |
| 8721 | bool ARMAsmParser::parseDirectiveArch(SMLoc L) { |
Logan Chien | 439e8f9 | 2013-12-11 17:16:25 +0000 | [diff] [blame] | 8722 | StringRef Arch = getParser().parseStringToEndOfStatement().trim(); |
| 8723 | |
| 8724 | unsigned ID = StringSwitch<unsigned>(Arch) |
| 8725 | #define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \ |
| 8726 | .Case(NAME, ARM::ID) |
Joerg Sonnenberger | a13f8b4 | 2013-12-26 11:50:28 +0000 | [diff] [blame] | 8727 | #define ARM_ARCH_ALIAS(NAME, ID) \ |
| 8728 | .Case(NAME, ARM::ID) |
Logan Chien | 439e8f9 | 2013-12-11 17:16:25 +0000 | [diff] [blame] | 8729 | #include "MCTargetDesc/ARMArchName.def" |
| 8730 | .Default(ARM::INVALID_ARCH); |
| 8731 | |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8732 | if (ID == ARM::INVALID_ARCH) { |
| 8733 | Error(L, "Unknown arch name"); |
| 8734 | return false; |
| 8735 | } |
Logan Chien | 439e8f9 | 2013-12-11 17:16:25 +0000 | [diff] [blame] | 8736 | |
| 8737 | getTargetStreamer().emitArch(ID); |
| 8738 | return false; |
Jason W Kim | 135d244 | 2011-12-20 17:38:12 +0000 | [diff] [blame] | 8739 | } |
| 8740 | |
| 8741 | /// parseDirectiveEabiAttr |
Saleem Abdulrasool | 87ccd36 | 2014-01-07 02:28:42 +0000 | [diff] [blame] | 8742 | /// ::= .eabi_attribute int, int [, "str"] |
| 8743 | /// ::= .eabi_attribute Tag_name, int [, "str"] |
Jason W Kim | 135d244 | 2011-12-20 17:38:12 +0000 | [diff] [blame] | 8744 | bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) { |
Saleem Abdulrasool | 87ccd36 | 2014-01-07 02:28:42 +0000 | [diff] [blame] | 8745 | int64_t Tag; |
| 8746 | SMLoc TagLoc; |
Saleem Abdulrasool | 87ccd36 | 2014-01-07 02:28:42 +0000 | [diff] [blame] | 8747 | TagLoc = Parser.getTok().getLoc(); |
| 8748 | if (Parser.getTok().is(AsmToken::Identifier)) { |
| 8749 | StringRef Name = Parser.getTok().getIdentifier(); |
| 8750 | Tag = ARMBuildAttrs::AttrTypeFromString(Name); |
| 8751 | if (Tag == -1) { |
| 8752 | Error(TagLoc, "attribute name not recognised: " + Name); |
| 8753 | Parser.eatToEndOfStatement(); |
| 8754 | return false; |
| 8755 | } |
| 8756 | Parser.Lex(); |
| 8757 | } else { |
| 8758 | const MCExpr *AttrExpr; |
| 8759 | |
| 8760 | TagLoc = Parser.getTok().getLoc(); |
| 8761 | if (Parser.parseExpression(AttrExpr)) { |
| 8762 | Parser.eatToEndOfStatement(); |
| 8763 | return false; |
| 8764 | } |
| 8765 | |
| 8766 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(AttrExpr); |
| 8767 | if (!CE) { |
| 8768 | Error(TagLoc, "expected numeric constant"); |
| 8769 | Parser.eatToEndOfStatement(); |
| 8770 | return false; |
| 8771 | } |
| 8772 | |
| 8773 | Tag = CE->getValue(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8774 | } |
Logan Chien | 8cbb80d | 2013-10-28 17:51:12 +0000 | [diff] [blame] | 8775 | |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8776 | if (Parser.getTok().isNot(AsmToken::Comma)) { |
Saleem Abdulrasool | 87ccd36 | 2014-01-07 02:28:42 +0000 | [diff] [blame] | 8777 | Error(Parser.getTok().getLoc(), "comma expected"); |
| 8778 | Parser.eatToEndOfStatement(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8779 | return false; |
| 8780 | } |
Logan Chien | 8cbb80d | 2013-10-28 17:51:12 +0000 | [diff] [blame] | 8781 | Parser.Lex(); // skip comma |
| 8782 | |
Saleem Abdulrasool | 87ccd36 | 2014-01-07 02:28:42 +0000 | [diff] [blame] | 8783 | StringRef StringValue = ""; |
| 8784 | bool IsStringValue = false; |
Logan Chien | 8cbb80d | 2013-10-28 17:51:12 +0000 | [diff] [blame] | 8785 | |
Saleem Abdulrasool | 87ccd36 | 2014-01-07 02:28:42 +0000 | [diff] [blame] | 8786 | int64_t IntegerValue = 0; |
| 8787 | bool IsIntegerValue = false; |
| 8788 | |
| 8789 | if (Tag == ARMBuildAttrs::CPU_raw_name || Tag == ARMBuildAttrs::CPU_name) |
| 8790 | IsStringValue = true; |
| 8791 | else if (Tag == ARMBuildAttrs::compatibility) { |
| 8792 | IsStringValue = true; |
| 8793 | IsIntegerValue = true; |
Saleem Abdulrasool | 9dedf64 | 2014-01-19 08:25:19 +0000 | [diff] [blame] | 8794 | } else if (Tag < 32 || Tag % 2 == 0) |
Saleem Abdulrasool | 87ccd36 | 2014-01-07 02:28:42 +0000 | [diff] [blame] | 8795 | IsIntegerValue = true; |
| 8796 | else if (Tag % 2 == 1) |
| 8797 | IsStringValue = true; |
| 8798 | else |
| 8799 | llvm_unreachable("invalid tag type"); |
| 8800 | |
| 8801 | if (IsIntegerValue) { |
| 8802 | const MCExpr *ValueExpr; |
| 8803 | SMLoc ValueExprLoc = Parser.getTok().getLoc(); |
| 8804 | if (Parser.parseExpression(ValueExpr)) { |
| 8805 | Parser.eatToEndOfStatement(); |
| 8806 | return false; |
| 8807 | } |
| 8808 | |
| 8809 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(ValueExpr); |
| 8810 | if (!CE) { |
| 8811 | Error(ValueExprLoc, "expected numeric constant"); |
| 8812 | Parser.eatToEndOfStatement(); |
| 8813 | return false; |
| 8814 | } |
| 8815 | |
| 8816 | IntegerValue = CE->getValue(); |
| 8817 | } |
| 8818 | |
| 8819 | if (Tag == ARMBuildAttrs::compatibility) { |
| 8820 | if (Parser.getTok().isNot(AsmToken::Comma)) |
| 8821 | IsStringValue = false; |
| 8822 | else |
| 8823 | Parser.Lex(); |
| 8824 | } |
| 8825 | |
| 8826 | if (IsStringValue) { |
| 8827 | if (Parser.getTok().isNot(AsmToken::String)) { |
| 8828 | Error(Parser.getTok().getLoc(), "bad string constant"); |
| 8829 | Parser.eatToEndOfStatement(); |
| 8830 | return false; |
| 8831 | } |
| 8832 | |
| 8833 | StringValue = Parser.getTok().getStringContents(); |
| 8834 | Parser.Lex(); |
| 8835 | } |
| 8836 | |
| 8837 | if (IsIntegerValue && IsStringValue) { |
| 8838 | assert(Tag == ARMBuildAttrs::compatibility); |
| 8839 | getTargetStreamer().emitIntTextAttribute(Tag, IntegerValue, StringValue); |
| 8840 | } else if (IsIntegerValue) |
| 8841 | getTargetStreamer().emitAttribute(Tag, IntegerValue); |
| 8842 | else if (IsStringValue) |
| 8843 | getTargetStreamer().emitTextAttribute(Tag, StringValue); |
Logan Chien | 8cbb80d | 2013-10-28 17:51:12 +0000 | [diff] [blame] | 8844 | return false; |
| 8845 | } |
| 8846 | |
| 8847 | /// parseDirectiveCPU |
| 8848 | /// ::= .cpu str |
| 8849 | bool ARMAsmParser::parseDirectiveCPU(SMLoc L) { |
| 8850 | StringRef CPU = getParser().parseStringToEndOfStatement().trim(); |
| 8851 | getTargetStreamer().emitTextAttribute(ARMBuildAttrs::CPU_name, CPU); |
| 8852 | return false; |
| 8853 | } |
| 8854 | |
Nico Weber | ae050bb | 2014-08-16 05:37:51 +0000 | [diff] [blame] | 8855 | // FIXME: This is duplicated in getARMFPUFeatures() in |
| 8856 | // tools/clang/lib/Driver/Tools.cpp |
| 8857 | static const struct { |
| 8858 | const unsigned Fpu; |
| 8859 | const uint64_t Enabled; |
| 8860 | const uint64_t Disabled; |
| 8861 | } Fpus[] = { |
| 8862 | {ARM::VFP, ARM::FeatureVFP2, ARM::FeatureNEON}, |
| 8863 | {ARM::VFPV2, ARM::FeatureVFP2, ARM::FeatureNEON}, |
| 8864 | {ARM::VFPV3, ARM::FeatureVFP3, ARM::FeatureNEON}, |
| 8865 | {ARM::VFPV3_D16, ARM::FeatureVFP3 | ARM::FeatureD16, ARM::FeatureNEON}, |
| 8866 | {ARM::VFPV4, ARM::FeatureVFP4, ARM::FeatureNEON}, |
| 8867 | {ARM::VFPV4_D16, ARM::FeatureVFP4 | ARM::FeatureD16, ARM::FeatureNEON}, |
Oliver Stannard | 37e4daa | 2014-10-01 09:02:17 +0000 | [diff] [blame] | 8868 | {ARM::FPV5_D16, ARM::FeatureFPARMv8 | ARM::FeatureD16, |
| 8869 | ARM::FeatureNEON | ARM::FeatureCrypto}, |
Nico Weber | ae050bb | 2014-08-16 05:37:51 +0000 | [diff] [blame] | 8870 | {ARM::FP_ARMV8, ARM::FeatureFPARMv8, |
| 8871 | ARM::FeatureNEON | ARM::FeatureCrypto}, |
| 8872 | {ARM::NEON, ARM::FeatureNEON, 0}, |
| 8873 | {ARM::NEON_VFPV4, ARM::FeatureVFP4 | ARM::FeatureNEON, 0}, |
| 8874 | {ARM::NEON_FP_ARMV8, ARM::FeatureFPARMv8 | ARM::FeatureNEON, |
| 8875 | ARM::FeatureCrypto}, |
| 8876 | {ARM::CRYPTO_NEON_FP_ARMV8, |
| 8877 | ARM::FeatureFPARMv8 | ARM::FeatureNEON | ARM::FeatureCrypto, 0}, |
| 8878 | {ARM::SOFTVFP, 0, 0}, |
| 8879 | }; |
| 8880 | |
Logan Chien | 8cbb80d | 2013-10-28 17:51:12 +0000 | [diff] [blame] | 8881 | /// parseDirectiveFPU |
| 8882 | /// ::= .fpu str |
| 8883 | bool ARMAsmParser::parseDirectiveFPU(SMLoc L) { |
| 8884 | StringRef FPU = getParser().parseStringToEndOfStatement().trim(); |
| 8885 | |
| 8886 | unsigned ID = StringSwitch<unsigned>(FPU) |
| 8887 | #define ARM_FPU_NAME(NAME, ID) .Case(NAME, ARM::ID) |
| 8888 | #include "ARMFPUName.def" |
| 8889 | .Default(ARM::INVALID_FPU); |
| 8890 | |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8891 | if (ID == ARM::INVALID_FPU) { |
| 8892 | Error(L, "Unknown FPU name"); |
| 8893 | return false; |
| 8894 | } |
Logan Chien | 8cbb80d | 2013-10-28 17:51:12 +0000 | [diff] [blame] | 8895 | |
Nico Weber | ae050bb | 2014-08-16 05:37:51 +0000 | [diff] [blame] | 8896 | for (const auto &Fpu : Fpus) { |
| 8897 | if (Fpu.Fpu != ID) |
| 8898 | continue; |
| 8899 | |
| 8900 | // Need to toggle features that should be on but are off and that |
| 8901 | // should off but are on. |
Tim Northover | 26bb14e | 2014-08-18 11:49:42 +0000 | [diff] [blame] | 8902 | uint64_t Toggle = (Fpu.Enabled & ~STI.getFeatureBits()) | |
Nico Weber | ae050bb | 2014-08-16 05:37:51 +0000 | [diff] [blame] | 8903 | (Fpu.Disabled & STI.getFeatureBits()); |
| 8904 | setAvailableFeatures(ComputeAvailableFeatures(STI.ToggleFeature(Toggle))); |
| 8905 | break; |
| 8906 | } |
| 8907 | |
Logan Chien | 8cbb80d | 2013-10-28 17:51:12 +0000 | [diff] [blame] | 8908 | getTargetStreamer().emitFPU(ID); |
| 8909 | return false; |
Jason W Kim | 135d244 | 2011-12-20 17:38:12 +0000 | [diff] [blame] | 8910 | } |
| 8911 | |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8912 | /// parseDirectiveFnStart |
| 8913 | /// ::= .fnstart |
| 8914 | bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) { |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8915 | if (UC.hasFnStart()) { |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8916 | Error(L, ".fnstart starts before the end of previous one"); |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8917 | UC.emitFnStartLocNotes(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8918 | return false; |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8919 | } |
| 8920 | |
Saleem Abdulrasool | 662f5c1 | 2014-01-21 02:33:02 +0000 | [diff] [blame] | 8921 | // Reset the unwind directives parser state |
| 8922 | UC.reset(); |
| 8923 | |
Rafael Espindola | a17151a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 8924 | getTargetStreamer().emitFnStart(); |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8925 | |
| 8926 | UC.recordFnStart(L); |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8927 | return false; |
| 8928 | } |
| 8929 | |
| 8930 | /// parseDirectiveFnEnd |
| 8931 | /// ::= .fnend |
| 8932 | bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) { |
| 8933 | // Check the ordering of unwind directives |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8934 | if (!UC.hasFnStart()) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8935 | Error(L, ".fnstart must precede .fnend directive"); |
| 8936 | return false; |
| 8937 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8938 | |
| 8939 | // Reset the unwind directives parser state |
Rafael Espindola | a17151a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 8940 | getTargetStreamer().emitFnEnd(); |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8941 | |
| 8942 | UC.reset(); |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8943 | return false; |
| 8944 | } |
| 8945 | |
| 8946 | /// parseDirectiveCantUnwind |
| 8947 | /// ::= .cantunwind |
| 8948 | bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) { |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8949 | UC.recordCantUnwind(L); |
| 8950 | |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8951 | // Check the ordering of unwind directives |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8952 | if (!UC.hasFnStart()) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8953 | Error(L, ".fnstart must precede .cantunwind directive"); |
| 8954 | return false; |
| 8955 | } |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8956 | if (UC.hasHandlerData()) { |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8957 | Error(L, ".cantunwind can't be used with .handlerdata directive"); |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8958 | UC.emitHandlerDataLocNotes(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8959 | return false; |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8960 | } |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8961 | if (UC.hasPersonality()) { |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8962 | Error(L, ".cantunwind can't be used with .personality directive"); |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8963 | UC.emitPersonalityLocNotes(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8964 | return false; |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8965 | } |
| 8966 | |
Rafael Espindola | a17151a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 8967 | getTargetStreamer().emitCantUnwind(); |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8968 | return false; |
| 8969 | } |
| 8970 | |
| 8971 | /// parseDirectivePersonality |
| 8972 | /// ::= .personality name |
| 8973 | bool ARMAsmParser::parseDirectivePersonality(SMLoc L) { |
Saleem Abdulrasool | 662f5c1 | 2014-01-21 02:33:02 +0000 | [diff] [blame] | 8974 | bool HasExistingPersonality = UC.hasPersonality(); |
| 8975 | |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8976 | UC.recordPersonality(L); |
| 8977 | |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8978 | // Check the ordering of unwind directives |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8979 | if (!UC.hasFnStart()) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8980 | Error(L, ".fnstart must precede .personality directive"); |
| 8981 | return false; |
| 8982 | } |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8983 | if (UC.cantUnwind()) { |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8984 | Error(L, ".personality can't be used with .cantunwind directive"); |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8985 | UC.emitCantUnwindLocNotes(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8986 | return false; |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8987 | } |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8988 | if (UC.hasHandlerData()) { |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8989 | Error(L, ".personality must precede .handlerdata directive"); |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 8990 | UC.emitHandlerDataLocNotes(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 8991 | return false; |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8992 | } |
Saleem Abdulrasool | 662f5c1 | 2014-01-21 02:33:02 +0000 | [diff] [blame] | 8993 | if (HasExistingPersonality) { |
| 8994 | Parser.eatToEndOfStatement(); |
| 8995 | Error(L, "multiple personality directives"); |
| 8996 | UC.emitPersonalityLocNotes(); |
| 8997 | return false; |
| 8998 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 8999 | |
| 9000 | // Parse the name of the personality routine |
| 9001 | if (Parser.getTok().isNot(AsmToken::Identifier)) { |
| 9002 | Parser.eatToEndOfStatement(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9003 | Error(L, "unexpected input in .personality directive."); |
| 9004 | return false; |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9005 | } |
| 9006 | StringRef Name(Parser.getTok().getIdentifier()); |
| 9007 | Parser.Lex(); |
| 9008 | |
| 9009 | MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name); |
Rafael Espindola | a17151a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 9010 | getTargetStreamer().emitPersonality(PR); |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9011 | return false; |
| 9012 | } |
| 9013 | |
| 9014 | /// parseDirectiveHandlerData |
| 9015 | /// ::= .handlerdata |
| 9016 | bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) { |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9017 | UC.recordHandlerData(L); |
| 9018 | |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9019 | // Check the ordering of unwind directives |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9020 | if (!UC.hasFnStart()) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9021 | Error(L, ".fnstart must precede .personality directive"); |
| 9022 | return false; |
| 9023 | } |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9024 | if (UC.cantUnwind()) { |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9025 | Error(L, ".handlerdata can't be used with .cantunwind directive"); |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9026 | UC.emitCantUnwindLocNotes(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9027 | return false; |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9028 | } |
| 9029 | |
Rafael Espindola | a17151a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 9030 | getTargetStreamer().emitHandlerData(); |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9031 | return false; |
| 9032 | } |
| 9033 | |
| 9034 | /// parseDirectiveSetFP |
| 9035 | /// ::= .setfp fpreg, spreg [, offset] |
| 9036 | bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) { |
| 9037 | // Check the ordering of unwind directives |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9038 | if (!UC.hasFnStart()) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9039 | Error(L, ".fnstart must precede .setfp directive"); |
| 9040 | return false; |
| 9041 | } |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9042 | if (UC.hasHandlerData()) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9043 | Error(L, ".setfp must precede .handlerdata directive"); |
| 9044 | return false; |
| 9045 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9046 | |
| 9047 | // Parse fpreg |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9048 | SMLoc FPRegLoc = Parser.getTok().getLoc(); |
| 9049 | int FPReg = tryParseRegister(); |
| 9050 | if (FPReg == -1) { |
| 9051 | Error(FPRegLoc, "frame pointer register expected"); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9052 | return false; |
| 9053 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9054 | |
| 9055 | // Consume comma |
Saleem Abdulrasool | 5d962d3 | 2014-01-30 04:46:24 +0000 | [diff] [blame] | 9056 | if (Parser.getTok().isNot(AsmToken::Comma)) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9057 | Error(Parser.getTok().getLoc(), "comma expected"); |
| 9058 | return false; |
| 9059 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9060 | Parser.Lex(); // skip comma |
| 9061 | |
| 9062 | // Parse spreg |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9063 | SMLoc SPRegLoc = Parser.getTok().getLoc(); |
| 9064 | int SPReg = tryParseRegister(); |
| 9065 | if (SPReg == -1) { |
| 9066 | Error(SPRegLoc, "stack pointer register expected"); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9067 | return false; |
| 9068 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9069 | |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9070 | if (SPReg != ARM::SP && SPReg != UC.getFPReg()) { |
| 9071 | Error(SPRegLoc, "register should be either $sp or the latest fp register"); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9072 | return false; |
| 9073 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9074 | |
| 9075 | // Update the frame pointer register |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9076 | UC.saveFPReg(FPReg); |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9077 | |
| 9078 | // Parse offset |
| 9079 | int64_t Offset = 0; |
| 9080 | if (Parser.getTok().is(AsmToken::Comma)) { |
| 9081 | Parser.Lex(); // skip comma |
| 9082 | |
| 9083 | if (Parser.getTok().isNot(AsmToken::Hash) && |
| 9084 | Parser.getTok().isNot(AsmToken::Dollar)) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9085 | Error(Parser.getTok().getLoc(), "'#' expected"); |
| 9086 | return false; |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9087 | } |
| 9088 | Parser.Lex(); // skip hash token. |
| 9089 | |
| 9090 | const MCExpr *OffsetExpr; |
| 9091 | SMLoc ExLoc = Parser.getTok().getLoc(); |
| 9092 | SMLoc EndLoc; |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9093 | if (getParser().parseExpression(OffsetExpr, EndLoc)) { |
| 9094 | Error(ExLoc, "malformed setfp offset"); |
| 9095 | return false; |
| 9096 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9097 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9098 | if (!CE) { |
| 9099 | Error(ExLoc, "setfp offset must be an immediate"); |
| 9100 | return false; |
| 9101 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9102 | |
| 9103 | Offset = CE->getValue(); |
| 9104 | } |
| 9105 | |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9106 | getTargetStreamer().emitSetFP(static_cast<unsigned>(FPReg), |
| 9107 | static_cast<unsigned>(SPReg), Offset); |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9108 | return false; |
| 9109 | } |
| 9110 | |
| 9111 | /// parseDirective |
| 9112 | /// ::= .pad offset |
| 9113 | bool ARMAsmParser::parseDirectivePad(SMLoc L) { |
| 9114 | // Check the ordering of unwind directives |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9115 | if (!UC.hasFnStart()) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9116 | Error(L, ".fnstart must precede .pad directive"); |
| 9117 | return false; |
| 9118 | } |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9119 | if (UC.hasHandlerData()) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9120 | Error(L, ".pad must precede .handlerdata directive"); |
| 9121 | return false; |
| 9122 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9123 | |
| 9124 | // Parse the offset |
| 9125 | if (Parser.getTok().isNot(AsmToken::Hash) && |
| 9126 | Parser.getTok().isNot(AsmToken::Dollar)) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9127 | Error(Parser.getTok().getLoc(), "'#' expected"); |
| 9128 | return false; |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9129 | } |
| 9130 | Parser.Lex(); // skip hash token. |
| 9131 | |
| 9132 | const MCExpr *OffsetExpr; |
| 9133 | SMLoc ExLoc = Parser.getTok().getLoc(); |
| 9134 | SMLoc EndLoc; |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9135 | if (getParser().parseExpression(OffsetExpr, EndLoc)) { |
| 9136 | Error(ExLoc, "malformed pad offset"); |
| 9137 | return false; |
| 9138 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9139 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9140 | if (!CE) { |
| 9141 | Error(ExLoc, "pad offset must be an immediate"); |
| 9142 | return false; |
| 9143 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9144 | |
Rafael Espindola | a17151a | 2013-10-08 13:08:17 +0000 | [diff] [blame] | 9145 | getTargetStreamer().emitPad(CE->getValue()); |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9146 | return false; |
| 9147 | } |
| 9148 | |
| 9149 | /// parseDirectiveRegSave |
| 9150 | /// ::= .save { registers } |
| 9151 | /// ::= .vsave { registers } |
| 9152 | bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) { |
| 9153 | // Check the ordering of unwind directives |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9154 | if (!UC.hasFnStart()) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9155 | Error(L, ".fnstart must precede .save or .vsave directives"); |
| 9156 | return false; |
| 9157 | } |
Saleem Abdulrasool | c493d14 | 2014-01-07 02:28:55 +0000 | [diff] [blame] | 9158 | if (UC.hasHandlerData()) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9159 | Error(L, ".save or .vsave must precede .handlerdata directive"); |
| 9160 | return false; |
| 9161 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9162 | |
Benjamin Kramer | 23632bd | 2013-08-03 22:16:24 +0000 | [diff] [blame] | 9163 | // RAII object to make sure parsed operands are deleted. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 9164 | SmallVector<std::unique_ptr<MCParsedAsmOperand>, 1> Operands; |
Benjamin Kramer | 23632bd | 2013-08-03 22:16:24 +0000 | [diff] [blame] | 9165 | |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9166 | // Parse the register list |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 9167 | if (parseRegisterList(Operands)) |
Saleem Abdulrasool | a6505ca | 2014-01-13 01:15:39 +0000 | [diff] [blame] | 9168 | return false; |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 9169 | ARMOperand &Op = (ARMOperand &)*Operands[0]; |
| 9170 | if (!IsVector && !Op.isRegList()) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9171 | Error(L, ".save expects GPR registers"); |
| 9172 | return false; |
| 9173 | } |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 9174 | if (IsVector && !Op.isDPRRegList()) { |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9175 | Error(L, ".vsave expects DPR registers"); |
| 9176 | return false; |
| 9177 | } |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9178 | |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 9179 | getTargetStreamer().emitRegSave(Op.getRegList(), IsVector); |
Logan Chien | 4ea23b5 | 2013-05-10 16:17:24 +0000 | [diff] [blame] | 9180 | return false; |
| 9181 | } |
| 9182 | |
Saleem Abdulrasool | c0da2cb | 2013-12-19 05:17:58 +0000 | [diff] [blame] | 9183 | /// parseDirectiveInst |
| 9184 | /// ::= .inst opcode [, ...] |
| 9185 | /// ::= .inst.n opcode [, ...] |
| 9186 | /// ::= .inst.w opcode [, ...] |
| 9187 | bool ARMAsmParser::parseDirectiveInst(SMLoc Loc, char Suffix) { |
| 9188 | int Width; |
| 9189 | |
| 9190 | if (isThumb()) { |
| 9191 | switch (Suffix) { |
| 9192 | case 'n': |
| 9193 | Width = 2; |
| 9194 | break; |
| 9195 | case 'w': |
| 9196 | Width = 4; |
| 9197 | break; |
| 9198 | default: |
| 9199 | Parser.eatToEndOfStatement(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9200 | Error(Loc, "cannot determine Thumb instruction size, " |
| 9201 | "use inst.n/inst.w instead"); |
| 9202 | return false; |
Saleem Abdulrasool | c0da2cb | 2013-12-19 05:17:58 +0000 | [diff] [blame] | 9203 | } |
| 9204 | } else { |
| 9205 | if (Suffix) { |
| 9206 | Parser.eatToEndOfStatement(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9207 | Error(Loc, "width suffixes are invalid in ARM mode"); |
| 9208 | return false; |
Saleem Abdulrasool | c0da2cb | 2013-12-19 05:17:58 +0000 | [diff] [blame] | 9209 | } |
| 9210 | Width = 4; |
| 9211 | } |
| 9212 | |
| 9213 | if (getLexer().is(AsmToken::EndOfStatement)) { |
| 9214 | Parser.eatToEndOfStatement(); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9215 | Error(Loc, "expected expression following directive"); |
| 9216 | return false; |
Saleem Abdulrasool | c0da2cb | 2013-12-19 05:17:58 +0000 | [diff] [blame] | 9217 | } |
| 9218 | |
| 9219 | for (;;) { |
| 9220 | const MCExpr *Expr; |
| 9221 | |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9222 | if (getParser().parseExpression(Expr)) { |
| 9223 | Error(Loc, "expected expression"); |
| 9224 | return false; |
| 9225 | } |
Saleem Abdulrasool | c0da2cb | 2013-12-19 05:17:58 +0000 | [diff] [blame] | 9226 | |
| 9227 | const MCConstantExpr *Value = dyn_cast_or_null<MCConstantExpr>(Expr); |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9228 | if (!Value) { |
| 9229 | Error(Loc, "expected constant expression"); |
| 9230 | return false; |
| 9231 | } |
Saleem Abdulrasool | c0da2cb | 2013-12-19 05:17:58 +0000 | [diff] [blame] | 9232 | |
| 9233 | switch (Width) { |
| 9234 | case 2: |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9235 | if (Value->getValue() > 0xffff) { |
| 9236 | Error(Loc, "inst.n operand is too big, use inst.w instead"); |
| 9237 | return false; |
| 9238 | } |
Saleem Abdulrasool | c0da2cb | 2013-12-19 05:17:58 +0000 | [diff] [blame] | 9239 | break; |
| 9240 | case 4: |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9241 | if (Value->getValue() > 0xffffffff) { |
| 9242 | Error(Loc, |
| 9243 | StringRef(Suffix ? "inst.w" : "inst") + " operand is too big"); |
| 9244 | return false; |
| 9245 | } |
Saleem Abdulrasool | c0da2cb | 2013-12-19 05:17:58 +0000 | [diff] [blame] | 9246 | break; |
| 9247 | default: |
| 9248 | llvm_unreachable("only supported widths are 2 and 4"); |
| 9249 | } |
| 9250 | |
| 9251 | getTargetStreamer().emitInst(Value->getValue(), Suffix); |
| 9252 | |
| 9253 | if (getLexer().is(AsmToken::EndOfStatement)) |
| 9254 | break; |
| 9255 | |
Saleem Abdulrasool | 0c4b102 | 2013-12-28 22:47:53 +0000 | [diff] [blame] | 9256 | if (getLexer().isNot(AsmToken::Comma)) { |
| 9257 | Error(Loc, "unexpected token in directive"); |
| 9258 | return false; |
| 9259 | } |
Saleem Abdulrasool | c0da2cb | 2013-12-19 05:17:58 +0000 | [diff] [blame] | 9260 | |
| 9261 | Parser.Lex(); |
| 9262 | } |
| 9263 | |
| 9264 | Parser.Lex(); |
| 9265 | return false; |
| 9266 | } |
| 9267 | |
David Peixotto | 80c083a | 2013-12-19 18:26:07 +0000 | [diff] [blame] | 9268 | /// parseDirectiveLtorg |
Saleem Abdulrasool | 6e6c239 | 2013-12-20 07:21:16 +0000 | [diff] [blame] | 9269 | /// ::= .ltorg | .pool |
David Peixotto | 80c083a | 2013-12-19 18:26:07 +0000 | [diff] [blame] | 9270 | bool ARMAsmParser::parseDirectiveLtorg(SMLoc L) { |
David Peixotto | b9b7362 | 2014-02-04 17:22:40 +0000 | [diff] [blame] | 9271 | getTargetStreamer().emitCurrentConstantPool(); |
David Peixotto | 80c083a | 2013-12-19 18:26:07 +0000 | [diff] [blame] | 9272 | return false; |
| 9273 | } |
| 9274 | |
Saleem Abdulrasool | a554968 | 2013-12-26 01:52:28 +0000 | [diff] [blame] | 9275 | bool ARMAsmParser::parseDirectiveEven(SMLoc L) { |
| 9276 | const MCSection *Section = getStreamer().getCurrentSection().first; |
| 9277 | |
| 9278 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
| 9279 | TokError("unexpected token in directive"); |
| 9280 | return false; |
| 9281 | } |
| 9282 | |
| 9283 | if (!Section) { |
Rafael Espindola | 7b61ddf | 2014-10-15 16:12:52 +0000 | [diff] [blame] | 9284 | getStreamer().InitSections(false); |
Saleem Abdulrasool | a554968 | 2013-12-26 01:52:28 +0000 | [diff] [blame] | 9285 | Section = getStreamer().getCurrentSection().first; |
| 9286 | } |
| 9287 | |
Saleem Abdulrasool | 42b233a | 2014-03-18 05:26:55 +0000 | [diff] [blame] | 9288 | assert(Section && "must have section to emit alignment"); |
Saleem Abdulrasool | a554968 | 2013-12-26 01:52:28 +0000 | [diff] [blame] | 9289 | if (Section->UseCodeAlign()) |
Rafael Espindola | 7b51496 | 2014-02-04 18:34:04 +0000 | [diff] [blame] | 9290 | getStreamer().EmitCodeAlignment(2); |
Saleem Abdulrasool | a554968 | 2013-12-26 01:52:28 +0000 | [diff] [blame] | 9291 | else |
Rafael Espindola | 7b51496 | 2014-02-04 18:34:04 +0000 | [diff] [blame] | 9292 | getStreamer().EmitValueToAlignment(2); |
Saleem Abdulrasool | a554968 | 2013-12-26 01:52:28 +0000 | [diff] [blame] | 9293 | |
| 9294 | return false; |
| 9295 | } |
| 9296 | |
Saleem Abdulrasool | 662f5c1 | 2014-01-21 02:33:02 +0000 | [diff] [blame] | 9297 | /// parseDirectivePersonalityIndex |
| 9298 | /// ::= .personalityindex index |
| 9299 | bool ARMAsmParser::parseDirectivePersonalityIndex(SMLoc L) { |
| 9300 | bool HasExistingPersonality = UC.hasPersonality(); |
| 9301 | |
| 9302 | UC.recordPersonalityIndex(L); |
| 9303 | |
| 9304 | if (!UC.hasFnStart()) { |
| 9305 | Parser.eatToEndOfStatement(); |
| 9306 | Error(L, ".fnstart must precede .personalityindex directive"); |
| 9307 | return false; |
| 9308 | } |
| 9309 | if (UC.cantUnwind()) { |
| 9310 | Parser.eatToEndOfStatement(); |
| 9311 | Error(L, ".personalityindex cannot be used with .cantunwind"); |
| 9312 | UC.emitCantUnwindLocNotes(); |
| 9313 | return false; |
| 9314 | } |
| 9315 | if (UC.hasHandlerData()) { |
| 9316 | Parser.eatToEndOfStatement(); |
| 9317 | Error(L, ".personalityindex must precede .handlerdata directive"); |
| 9318 | UC.emitHandlerDataLocNotes(); |
| 9319 | return false; |
| 9320 | } |
| 9321 | if (HasExistingPersonality) { |
| 9322 | Parser.eatToEndOfStatement(); |
| 9323 | Error(L, "multiple personality directives"); |
| 9324 | UC.emitPersonalityLocNotes(); |
| 9325 | return false; |
| 9326 | } |
| 9327 | |
| 9328 | const MCExpr *IndexExpression; |
| 9329 | SMLoc IndexLoc = Parser.getTok().getLoc(); |
| 9330 | if (Parser.parseExpression(IndexExpression)) { |
| 9331 | Parser.eatToEndOfStatement(); |
| 9332 | return false; |
| 9333 | } |
| 9334 | |
| 9335 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(IndexExpression); |
| 9336 | if (!CE) { |
| 9337 | Parser.eatToEndOfStatement(); |
| 9338 | Error(IndexLoc, "index must be a constant number"); |
| 9339 | return false; |
| 9340 | } |
| 9341 | if (CE->getValue() < 0 || |
| 9342 | CE->getValue() >= ARM::EHABI::NUM_PERSONALITY_INDEX) { |
| 9343 | Parser.eatToEndOfStatement(); |
| 9344 | Error(IndexLoc, "personality routine index should be in range [0-3]"); |
| 9345 | return false; |
| 9346 | } |
| 9347 | |
| 9348 | getTargetStreamer().emitPersonalityIndex(CE->getValue()); |
| 9349 | return false; |
| 9350 | } |
| 9351 | |
Saleem Abdulrasool | d9f0860 | 2014-01-21 02:33:10 +0000 | [diff] [blame] | 9352 | /// parseDirectiveUnwindRaw |
| 9353 | /// ::= .unwind_raw offset, opcode [, opcode...] |
| 9354 | bool ARMAsmParser::parseDirectiveUnwindRaw(SMLoc L) { |
| 9355 | if (!UC.hasFnStart()) { |
| 9356 | Parser.eatToEndOfStatement(); |
| 9357 | Error(L, ".fnstart must precede .unwind_raw directives"); |
| 9358 | return false; |
| 9359 | } |
| 9360 | |
| 9361 | int64_t StackOffset; |
| 9362 | |
| 9363 | const MCExpr *OffsetExpr; |
| 9364 | SMLoc OffsetLoc = getLexer().getLoc(); |
| 9365 | if (getLexer().is(AsmToken::EndOfStatement) || |
| 9366 | getParser().parseExpression(OffsetExpr)) { |
| 9367 | Error(OffsetLoc, "expected expression"); |
| 9368 | Parser.eatToEndOfStatement(); |
| 9369 | return false; |
| 9370 | } |
| 9371 | |
| 9372 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr); |
| 9373 | if (!CE) { |
| 9374 | Error(OffsetLoc, "offset must be a constant"); |
| 9375 | Parser.eatToEndOfStatement(); |
| 9376 | return false; |
| 9377 | } |
| 9378 | |
| 9379 | StackOffset = CE->getValue(); |
| 9380 | |
| 9381 | if (getLexer().isNot(AsmToken::Comma)) { |
| 9382 | Error(getLexer().getLoc(), "expected comma"); |
| 9383 | Parser.eatToEndOfStatement(); |
| 9384 | return false; |
| 9385 | } |
| 9386 | Parser.Lex(); |
| 9387 | |
| 9388 | SmallVector<uint8_t, 16> Opcodes; |
| 9389 | for (;;) { |
| 9390 | const MCExpr *OE; |
| 9391 | |
| 9392 | SMLoc OpcodeLoc = getLexer().getLoc(); |
| 9393 | if (getLexer().is(AsmToken::EndOfStatement) || Parser.parseExpression(OE)) { |
| 9394 | Error(OpcodeLoc, "expected opcode expression"); |
| 9395 | Parser.eatToEndOfStatement(); |
| 9396 | return false; |
| 9397 | } |
| 9398 | |
| 9399 | const MCConstantExpr *OC = dyn_cast<MCConstantExpr>(OE); |
| 9400 | if (!OC) { |
| 9401 | Error(OpcodeLoc, "opcode value must be a constant"); |
| 9402 | Parser.eatToEndOfStatement(); |
| 9403 | return false; |
| 9404 | } |
| 9405 | |
| 9406 | const int64_t Opcode = OC->getValue(); |
| 9407 | if (Opcode & ~0xff) { |
| 9408 | Error(OpcodeLoc, "invalid opcode"); |
| 9409 | Parser.eatToEndOfStatement(); |
| 9410 | return false; |
| 9411 | } |
| 9412 | |
| 9413 | Opcodes.push_back(uint8_t(Opcode)); |
| 9414 | |
| 9415 | if (getLexer().is(AsmToken::EndOfStatement)) |
| 9416 | break; |
| 9417 | |
| 9418 | if (getLexer().isNot(AsmToken::Comma)) { |
| 9419 | Error(getLexer().getLoc(), "unexpected token in directive"); |
| 9420 | Parser.eatToEndOfStatement(); |
| 9421 | return false; |
| 9422 | } |
| 9423 | |
| 9424 | Parser.Lex(); |
| 9425 | } |
| 9426 | |
| 9427 | getTargetStreamer().emitUnwindRaw(StackOffset, Opcodes); |
| 9428 | |
| 9429 | Parser.Lex(); |
| 9430 | return false; |
| 9431 | } |
| 9432 | |
Saleem Abdulrasool | 56e06e8 | 2014-01-30 04:02:47 +0000 | [diff] [blame] | 9433 | /// parseDirectiveTLSDescSeq |
| 9434 | /// ::= .tlsdescseq tls-variable |
| 9435 | bool ARMAsmParser::parseDirectiveTLSDescSeq(SMLoc L) { |
| 9436 | if (getLexer().isNot(AsmToken::Identifier)) { |
| 9437 | TokError("expected variable after '.tlsdescseq' directive"); |
| 9438 | Parser.eatToEndOfStatement(); |
| 9439 | return false; |
| 9440 | } |
| 9441 | |
| 9442 | const MCSymbolRefExpr *SRE = |
| 9443 | MCSymbolRefExpr::Create(Parser.getTok().getIdentifier(), |
| 9444 | MCSymbolRefExpr::VK_ARM_TLSDESCSEQ, getContext()); |
| 9445 | Lex(); |
| 9446 | |
| 9447 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
| 9448 | Error(Parser.getTok().getLoc(), "unexpected token"); |
| 9449 | Parser.eatToEndOfStatement(); |
| 9450 | return false; |
| 9451 | } |
| 9452 | |
| 9453 | getTargetStreamer().AnnotateTLSDescriptorSequence(SRE); |
| 9454 | return false; |
| 9455 | } |
| 9456 | |
Saleem Abdulrasool | 5d962d3 | 2014-01-30 04:46:24 +0000 | [diff] [blame] | 9457 | /// parseDirectiveMovSP |
| 9458 | /// ::= .movsp reg [, #offset] |
| 9459 | bool ARMAsmParser::parseDirectiveMovSP(SMLoc L) { |
| 9460 | if (!UC.hasFnStart()) { |
| 9461 | Parser.eatToEndOfStatement(); |
| 9462 | Error(L, ".fnstart must precede .movsp directives"); |
| 9463 | return false; |
| 9464 | } |
| 9465 | if (UC.getFPReg() != ARM::SP) { |
| 9466 | Parser.eatToEndOfStatement(); |
| 9467 | Error(L, "unexpected .movsp directive"); |
| 9468 | return false; |
| 9469 | } |
| 9470 | |
| 9471 | SMLoc SPRegLoc = Parser.getTok().getLoc(); |
| 9472 | int SPReg = tryParseRegister(); |
| 9473 | if (SPReg == -1) { |
| 9474 | Parser.eatToEndOfStatement(); |
| 9475 | Error(SPRegLoc, "register expected"); |
| 9476 | return false; |
| 9477 | } |
| 9478 | |
| 9479 | if (SPReg == ARM::SP || SPReg == ARM::PC) { |
| 9480 | Parser.eatToEndOfStatement(); |
| 9481 | Error(SPRegLoc, "sp and pc are not permitted in .movsp directive"); |
| 9482 | return false; |
| 9483 | } |
| 9484 | |
| 9485 | int64_t Offset = 0; |
| 9486 | if (Parser.getTok().is(AsmToken::Comma)) { |
| 9487 | Parser.Lex(); |
| 9488 | |
| 9489 | if (Parser.getTok().isNot(AsmToken::Hash)) { |
| 9490 | Error(Parser.getTok().getLoc(), "expected #constant"); |
| 9491 | Parser.eatToEndOfStatement(); |
| 9492 | return false; |
| 9493 | } |
| 9494 | Parser.Lex(); |
| 9495 | |
| 9496 | const MCExpr *OffsetExpr; |
| 9497 | SMLoc OffsetLoc = Parser.getTok().getLoc(); |
| 9498 | if (Parser.parseExpression(OffsetExpr)) { |
| 9499 | Parser.eatToEndOfStatement(); |
| 9500 | Error(OffsetLoc, "malformed offset expression"); |
| 9501 | return false; |
| 9502 | } |
| 9503 | |
| 9504 | const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(OffsetExpr); |
| 9505 | if (!CE) { |
| 9506 | Parser.eatToEndOfStatement(); |
| 9507 | Error(OffsetLoc, "offset must be an immediate constant"); |
| 9508 | return false; |
| 9509 | } |
| 9510 | |
| 9511 | Offset = CE->getValue(); |
| 9512 | } |
| 9513 | |
| 9514 | getTargetStreamer().emitMovSP(SPReg, Offset); |
| 9515 | UC.saveFPReg(SPReg); |
| 9516 | |
| 9517 | return false; |
| 9518 | } |
| 9519 | |
Saleem Abdulrasool | 4c4789b | 2014-01-30 04:46:41 +0000 | [diff] [blame] | 9520 | /// parseDirectiveObjectArch |
| 9521 | /// ::= .object_arch name |
| 9522 | bool ARMAsmParser::parseDirectiveObjectArch(SMLoc L) { |
| 9523 | if (getLexer().isNot(AsmToken::Identifier)) { |
| 9524 | Error(getLexer().getLoc(), "unexpected token"); |
| 9525 | Parser.eatToEndOfStatement(); |
| 9526 | return false; |
| 9527 | } |
| 9528 | |
| 9529 | StringRef Arch = Parser.getTok().getString(); |
| 9530 | SMLoc ArchLoc = Parser.getTok().getLoc(); |
| 9531 | getLexer().Lex(); |
| 9532 | |
| 9533 | unsigned ID = StringSwitch<unsigned>(Arch) |
| 9534 | #define ARM_ARCH_NAME(NAME, ID, DEFAULT_CPU_NAME, DEFAULT_CPU_ARCH) \ |
| 9535 | .Case(NAME, ARM::ID) |
| 9536 | #define ARM_ARCH_ALIAS(NAME, ID) \ |
| 9537 | .Case(NAME, ARM::ID) |
| 9538 | #include "MCTargetDesc/ARMArchName.def" |
| 9539 | #undef ARM_ARCH_NAME |
| 9540 | #undef ARM_ARCH_ALIAS |
| 9541 | .Default(ARM::INVALID_ARCH); |
| 9542 | |
| 9543 | if (ID == ARM::INVALID_ARCH) { |
| 9544 | Error(ArchLoc, "unknown architecture '" + Arch + "'"); |
| 9545 | Parser.eatToEndOfStatement(); |
| 9546 | return false; |
| 9547 | } |
| 9548 | |
| 9549 | getTargetStreamer().emitObjectArch(ID); |
| 9550 | |
| 9551 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
| 9552 | Error(getLexer().getLoc(), "unexpected token"); |
| 9553 | Parser.eatToEndOfStatement(); |
| 9554 | } |
| 9555 | |
| 9556 | return false; |
| 9557 | } |
| 9558 | |
Saleem Abdulrasool | fd6ed1e | 2014-02-23 17:45:32 +0000 | [diff] [blame] | 9559 | /// parseDirectiveAlign |
| 9560 | /// ::= .align |
| 9561 | bool ARMAsmParser::parseDirectiveAlign(SMLoc L) { |
| 9562 | // NOTE: if this is not the end of the statement, fall back to the target |
| 9563 | // agnostic handling for this directive which will correctly handle this. |
| 9564 | if (getLexer().isNot(AsmToken::EndOfStatement)) |
| 9565 | return true; |
| 9566 | |
| 9567 | // '.align' is target specifically handled to mean 2**2 byte alignment. |
| 9568 | if (getStreamer().getCurrentSection().first->UseCodeAlign()) |
| 9569 | getStreamer().EmitCodeAlignment(4, 0); |
| 9570 | else |
| 9571 | getStreamer().EmitValueToAlignment(4, 0, 1, 0); |
| 9572 | |
| 9573 | return false; |
| 9574 | } |
| 9575 | |
Saleem Abdulrasool | 39f773f | 2014-03-20 06:05:33 +0000 | [diff] [blame] | 9576 | /// parseDirectiveThumbSet |
| 9577 | /// ::= .thumb_set name, value |
| 9578 | bool ARMAsmParser::parseDirectiveThumbSet(SMLoc L) { |
| 9579 | StringRef Name; |
| 9580 | if (Parser.parseIdentifier(Name)) { |
| 9581 | TokError("expected identifier after '.thumb_set'"); |
| 9582 | Parser.eatToEndOfStatement(); |
| 9583 | return false; |
| 9584 | } |
| 9585 | |
| 9586 | if (getLexer().isNot(AsmToken::Comma)) { |
| 9587 | TokError("expected comma after name '" + Name + "'"); |
| 9588 | Parser.eatToEndOfStatement(); |
| 9589 | return false; |
| 9590 | } |
| 9591 | Lex(); |
| 9592 | |
| 9593 | const MCExpr *Value; |
| 9594 | if (Parser.parseExpression(Value)) { |
| 9595 | TokError("missing expression"); |
| 9596 | Parser.eatToEndOfStatement(); |
| 9597 | return false; |
| 9598 | } |
| 9599 | |
| 9600 | if (getLexer().isNot(AsmToken::EndOfStatement)) { |
| 9601 | TokError("unexpected token"); |
| 9602 | Parser.eatToEndOfStatement(); |
| 9603 | return false; |
| 9604 | } |
| 9605 | Lex(); |
| 9606 | |
| 9607 | MCSymbol *Alias = getContext().GetOrCreateSymbol(Name); |
Rafael Espindola | 466d663 | 2014-04-27 20:23:58 +0000 | [diff] [blame] | 9608 | getTargetStreamer().emitThumbSet(Alias, Value); |
Saleem Abdulrasool | 39f773f | 2014-03-20 06:05:33 +0000 | [diff] [blame] | 9609 | return false; |
| 9610 | } |
| 9611 | |
Kevin Enderby | 8be42bd | 2009-10-30 22:55:57 +0000 | [diff] [blame] | 9612 | /// Force static initialization. |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 9613 | extern "C" void LLVMInitializeARMAsmParser() { |
Christian Pirker | dc9ff75 | 2014-04-01 15:19:30 +0000 | [diff] [blame] | 9614 | RegisterMCAsmParser<ARMAsmParser> X(TheARMLETarget); |
| 9615 | RegisterMCAsmParser<ARMAsmParser> Y(TheARMBETarget); |
| 9616 | RegisterMCAsmParser<ARMAsmParser> A(TheThumbLETarget); |
| 9617 | RegisterMCAsmParser<ARMAsmParser> B(TheThumbBETarget); |
Kevin Enderby | ccab317 | 2009-09-15 00:27:25 +0000 | [diff] [blame] | 9618 | } |
Daniel Dunbar | 5cd4d0f | 2010-08-11 05:24:50 +0000 | [diff] [blame] | 9619 | |
Chris Lattner | 3e4582a | 2010-09-06 19:11:01 +0000 | [diff] [blame] | 9620 | #define GET_REGISTER_MATCHER |
Craig Topper | 3ec7c2a | 2012-04-25 06:56:34 +0000 | [diff] [blame] | 9621 | #define GET_SUBTARGET_FEATURE_NAME |
Chris Lattner | 3e4582a | 2010-09-06 19:11:01 +0000 | [diff] [blame] | 9622 | #define GET_MATCHER_IMPLEMENTATION |
Daniel Dunbar | 5cd4d0f | 2010-08-11 05:24:50 +0000 | [diff] [blame] | 9623 | #include "ARMGenAsmMatcher.inc" |
Jim Grosbach | 231e7aa | 2013-02-06 06:00:11 +0000 | [diff] [blame] | 9624 | |
Saleem Abdulrasool | 45cf67b | 2014-07-27 19:07:05 +0000 | [diff] [blame] | 9625 | static const struct { |
| 9626 | const char *Name; |
Saleem Abdulrasool | 49480bf | 2014-02-16 00:16:41 +0000 | [diff] [blame] | 9627 | const unsigned ArchCheck; |
| 9628 | const uint64_t Features; |
| 9629 | } Extensions[] = { |
| 9630 | { "crc", Feature_HasV8, ARM::FeatureCRC }, |
| 9631 | { "crypto", Feature_HasV8, |
| 9632 | ARM::FeatureCrypto | ARM::FeatureNEON | ARM::FeatureFPARMv8 }, |
| 9633 | { "fp", Feature_HasV8, ARM::FeatureFPARMv8 }, |
| 9634 | { "idiv", Feature_HasV7 | Feature_IsNotMClass, |
| 9635 | ARM::FeatureHWDiv | ARM::FeatureHWDivARM }, |
| 9636 | // FIXME: iWMMXT not supported |
| 9637 | { "iwmmxt", Feature_None, 0 }, |
| 9638 | // FIXME: iWMMXT2 not supported |
| 9639 | { "iwmmxt2", Feature_None, 0 }, |
| 9640 | // FIXME: Maverick not supported |
| 9641 | { "maverick", Feature_None, 0 }, |
| 9642 | { "mp", Feature_HasV7 | Feature_IsNotMClass, ARM::FeatureMP }, |
| 9643 | // FIXME: ARMv6-m OS Extensions feature not checked |
| 9644 | { "os", Feature_None, 0 }, |
| 9645 | // FIXME: Also available in ARMv6-K |
| 9646 | { "sec", Feature_HasV7, ARM::FeatureTrustZone }, |
| 9647 | { "simd", Feature_HasV8, ARM::FeatureNEON | ARM::FeatureFPARMv8 }, |
| 9648 | // FIXME: Only available in A-class, isel not predicated |
| 9649 | { "virt", Feature_HasV7, ARM::FeatureVirtualization }, |
| 9650 | // FIXME: xscale not supported |
| 9651 | { "xscale", Feature_None, 0 }, |
| 9652 | }; |
| 9653 | |
Saleem Abdulrasool | 49480bf | 2014-02-16 00:16:41 +0000 | [diff] [blame] | 9654 | /// parseDirectiveArchExtension |
| 9655 | /// ::= .arch_extension [no]feature |
| 9656 | bool ARMAsmParser::parseDirectiveArchExtension(SMLoc L) { |
| 9657 | if (getLexer().isNot(AsmToken::Identifier)) { |
| 9658 | Error(getLexer().getLoc(), "unexpected token"); |
| 9659 | Parser.eatToEndOfStatement(); |
| 9660 | return false; |
| 9661 | } |
| 9662 | |
Saleem Abdulrasool | 45cf67b | 2014-07-27 19:07:05 +0000 | [diff] [blame] | 9663 | StringRef Name = Parser.getTok().getString(); |
Saleem Abdulrasool | 49480bf | 2014-02-16 00:16:41 +0000 | [diff] [blame] | 9664 | SMLoc ExtLoc = Parser.getTok().getLoc(); |
| 9665 | getLexer().Lex(); |
| 9666 | |
| 9667 | bool EnableFeature = true; |
Saleem Abdulrasool | 45cf67b | 2014-07-27 19:07:05 +0000 | [diff] [blame] | 9668 | if (Name.startswith_lower("no")) { |
Saleem Abdulrasool | 49480bf | 2014-02-16 00:16:41 +0000 | [diff] [blame] | 9669 | EnableFeature = false; |
Saleem Abdulrasool | 45cf67b | 2014-07-27 19:07:05 +0000 | [diff] [blame] | 9670 | Name = Name.substr(2); |
Saleem Abdulrasool | 49480bf | 2014-02-16 00:16:41 +0000 | [diff] [blame] | 9671 | } |
| 9672 | |
Saleem Abdulrasool | 45cf67b | 2014-07-27 19:07:05 +0000 | [diff] [blame] | 9673 | for (const auto &Extension : Extensions) { |
| 9674 | if (Extension.Name != Name) |
Saleem Abdulrasool | 49480bf | 2014-02-16 00:16:41 +0000 | [diff] [blame] | 9675 | continue; |
| 9676 | |
Saleem Abdulrasool | 8988c2a | 2014-07-27 19:07:09 +0000 | [diff] [blame] | 9677 | if (!Extension.Features) |
| 9678 | report_fatal_error("unsupported architectural extension: " + Name); |
| 9679 | |
| 9680 | if ((getAvailableFeatures() & Extension.ArchCheck) != Extension.ArchCheck) { |
Saleem Abdulrasool | 45cf67b | 2014-07-27 19:07:05 +0000 | [diff] [blame] | 9681 | Error(ExtLoc, "architectural extension '" + Name + "' is not " |
Saleem Abdulrasool | 49480bf | 2014-02-16 00:16:41 +0000 | [diff] [blame] | 9682 | "allowed for the current base architecture"); |
| 9683 | return false; |
| 9684 | } |
| 9685 | |
Tim Northover | 26bb14e | 2014-08-18 11:49:42 +0000 | [diff] [blame] | 9686 | uint64_t ToggleFeatures = EnableFeature |
Saleem Abdulrasool | 78c4472 | 2014-08-17 19:20:38 +0000 | [diff] [blame] | 9687 | ? (~STI.getFeatureBits() & Extension.Features) |
| 9688 | : ( STI.getFeatureBits() & Extension.Features); |
Tim Northover | 26bb14e | 2014-08-18 11:49:42 +0000 | [diff] [blame] | 9689 | uint64_t Features = |
Saleem Abdulrasool | 78c4472 | 2014-08-17 19:20:38 +0000 | [diff] [blame] | 9690 | ComputeAvailableFeatures(STI.ToggleFeature(ToggleFeatures)); |
| 9691 | setAvailableFeatures(Features); |
Saleem Abdulrasool | 49480bf | 2014-02-16 00:16:41 +0000 | [diff] [blame] | 9692 | return false; |
| 9693 | } |
| 9694 | |
Saleem Abdulrasool | 45cf67b | 2014-07-27 19:07:05 +0000 | [diff] [blame] | 9695 | Error(ExtLoc, "unknown architectural extension: " + Name); |
Saleem Abdulrasool | 49480bf | 2014-02-16 00:16:41 +0000 | [diff] [blame] | 9696 | Parser.eatToEndOfStatement(); |
| 9697 | return false; |
| 9698 | } |
| 9699 | |
Jim Grosbach | 231e7aa | 2013-02-06 06:00:11 +0000 | [diff] [blame] | 9700 | // Define this matcher function after the auto-generated include so we |
| 9701 | // have the match class enum definitions. |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 9702 | unsigned ARMAsmParser::validateTargetOperandClass(MCParsedAsmOperand &AsmOp, |
Jim Grosbach | 231e7aa | 2013-02-06 06:00:11 +0000 | [diff] [blame] | 9703 | unsigned Kind) { |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 9704 | ARMOperand &Op = static_cast<ARMOperand &>(AsmOp); |
Jim Grosbach | 231e7aa | 2013-02-06 06:00:11 +0000 | [diff] [blame] | 9705 | // If the kind is a token for a literal immediate, check if our asm |
| 9706 | // operand matches. This is for InstAliases which have a fixed-value |
| 9707 | // immediate in the syntax. |
Saleem Abdulrasool | d88affb | 2014-01-08 03:28:14 +0000 | [diff] [blame] | 9708 | switch (Kind) { |
| 9709 | default: break; |
| 9710 | case MCK__35_0: |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 9711 | if (Op.isImm()) |
| 9712 | if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Op.getImm())) |
Saleem Abdulrasool | d88affb | 2014-01-08 03:28:14 +0000 | [diff] [blame] | 9713 | if (CE->getValue() == 0) |
| 9714 | return Match_Success; |
| 9715 | break; |
| 9716 | case MCK_ARMSOImm: |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 9717 | if (Op.isImm()) { |
| 9718 | const MCExpr *SOExpr = Op.getImm(); |
Saleem Abdulrasool | d88affb | 2014-01-08 03:28:14 +0000 | [diff] [blame] | 9719 | int64_t Value; |
| 9720 | if (!SOExpr->EvaluateAsAbsolute(Value)) |
Stepan Dyatkovskiy | df657cc | 2014-03-29 13:12:40 +0000 | [diff] [blame] | 9721 | return Match_Success; |
Richard Barton | 3db1d58 | 2014-05-01 11:37:44 +0000 | [diff] [blame] | 9722 | assert((Value >= INT32_MIN && Value <= UINT32_MAX) && |
| 9723 | "expression value must be representable in 32 bits"); |
Saleem Abdulrasool | d88affb | 2014-01-08 03:28:14 +0000 | [diff] [blame] | 9724 | } |
| 9725 | break; |
Saleem Abdulrasool | e6e6d71 | 2014-01-10 04:38:35 +0000 | [diff] [blame] | 9726 | case MCK_GPRPair: |
David Blaikie | 960ea3f | 2014-06-08 16:18:35 +0000 | [diff] [blame] | 9727 | if (Op.isReg() && |
| 9728 | MRI->getRegClass(ARM::GPRRegClassID).contains(Op.getReg())) |
Saleem Abdulrasool | e6e6d71 | 2014-01-10 04:38:35 +0000 | [diff] [blame] | 9729 | return Match_Success; |
| 9730 | break; |
Jim Grosbach | 231e7aa | 2013-02-06 06:00:11 +0000 | [diff] [blame] | 9731 | } |
| 9732 | return Match_InvalidOperand; |
| 9733 | } |