Jia Liu | 9f61011 | 2012-02-17 08:55:11 +0000 | [diff] [blame] | 1 | //===-- MipsMCCodeEmitter.cpp - Convert Mips Code to Machine Code ---------===// |
Akira Hatanaka | 750ecec | 2011-09-30 20:40:03 +0000 | [diff] [blame] | 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 | // |
| 10 | // This file implements the MipsMCCodeEmitter class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | // |
Matheus Almeida | 9e1450b | 2014-03-20 09:29:54 +0000 | [diff] [blame] | 14 | |
Matheus Almeida | 9e1450b | 2014-03-20 09:29:54 +0000 | [diff] [blame] | 15 | #include "MipsMCCodeEmitter.h" |
Bruno Cardoso Lopes | c85e3ff | 2011-11-11 22:58:42 +0000 | [diff] [blame] | 16 | #include "MCTargetDesc/MipsFixupKinds.h" |
Petar Jovanovic | a5da588 | 2014-02-04 18:41:57 +0000 | [diff] [blame] | 17 | #include "MCTargetDesc/MipsMCExpr.h" |
Bruno Cardoso Lopes | c85e3ff | 2011-11-11 22:58:42 +0000 | [diff] [blame] | 18 | #include "MCTargetDesc/MipsMCTargetDesc.h" |
| 19 | #include "llvm/ADT/APFloat.h" |
Matheus Almeida | 9e1450b | 2014-03-20 09:29:54 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/SmallVector.h" |
Akira Hatanaka | 5d6faed | 2012-12-10 20:04:40 +0000 | [diff] [blame] | 21 | #include "llvm/MC/MCContext.h" |
Akira Hatanaka | 750ecec | 2011-09-30 20:40:03 +0000 | [diff] [blame] | 22 | #include "llvm/MC/MCExpr.h" |
Chandler Carruth | d990388 | 2015-01-14 11:23:27 +0000 | [diff] [blame] | 23 | #include "llvm/MC/MCFixup.h" |
Akira Hatanaka | 750ecec | 2011-09-30 20:40:03 +0000 | [diff] [blame] | 24 | #include "llvm/MC/MCInst.h" |
| 25 | #include "llvm/MC/MCInstrInfo.h" |
Akira Hatanaka | 750ecec | 2011-09-30 20:40:03 +0000 | [diff] [blame] | 26 | #include "llvm/MC/MCSubtargetInfo.h" |
Akira Hatanaka | 750ecec | 2011-09-30 20:40:03 +0000 | [diff] [blame] | 27 | #include "llvm/Support/raw_ostream.h" |
Akira Hatanaka | 750ecec | 2011-09-30 20:40:03 +0000 | [diff] [blame] | 28 | |
Chandler Carruth | 84e68b2 | 2014-04-22 02:41:26 +0000 | [diff] [blame] | 29 | #define DEBUG_TYPE "mccodeemitter" |
| 30 | |
Akira Hatanaka | be6a818 | 2013-04-19 19:03:11 +0000 | [diff] [blame] | 31 | #define GET_INSTRMAP_INFO |
| 32 | #include "MipsGenInstrInfo.inc" |
Matheus Almeida | 9e1450b | 2014-03-20 09:29:54 +0000 | [diff] [blame] | 33 | #undef GET_INSTRMAP_INFO |
Akira Hatanaka | be6a818 | 2013-04-19 19:03:11 +0000 | [diff] [blame] | 34 | |
Matheus Almeida | 9e1450b | 2014-03-20 09:29:54 +0000 | [diff] [blame] | 35 | namespace llvm { |
| 36 | MCCodeEmitter *createMipsMCCodeEmitterEB(const MCInstrInfo &MCII, |
| 37 | const MCRegisterInfo &MRI, |
Matheus Almeida | 9e1450b | 2014-03-20 09:29:54 +0000 | [diff] [blame] | 38 | MCContext &Ctx) { |
David Woodhouse | d2cca11 | 2014-01-28 23:13:25 +0000 | [diff] [blame] | 39 | return new MipsMCCodeEmitter(MCII, Ctx, false); |
Akira Hatanaka | 1ee768d | 2012-03-01 01:53:15 +0000 | [diff] [blame] | 40 | } |
| 41 | |
Matheus Almeida | 9e1450b | 2014-03-20 09:29:54 +0000 | [diff] [blame] | 42 | MCCodeEmitter *createMipsMCCodeEmitterEL(const MCInstrInfo &MCII, |
| 43 | const MCRegisterInfo &MRI, |
Matheus Almeida | 9e1450b | 2014-03-20 09:29:54 +0000 | [diff] [blame] | 44 | MCContext &Ctx) { |
David Woodhouse | d2cca11 | 2014-01-28 23:13:25 +0000 | [diff] [blame] | 45 | return new MipsMCCodeEmitter(MCII, Ctx, true); |
Akira Hatanaka | 750ecec | 2011-09-30 20:40:03 +0000 | [diff] [blame] | 46 | } |
Matheus Almeida | 9e1450b | 2014-03-20 09:29:54 +0000 | [diff] [blame] | 47 | } // End of namespace llvm. |
Rafael Espindola | f30f2cc | 2013-05-27 22:34:59 +0000 | [diff] [blame] | 48 | |
| 49 | // If the D<shift> instruction has a shift amount that is greater |
| 50 | // than 31 (checked in calling routine), lower it to a D<shift>32 instruction |
| 51 | static void LowerLargeShift(MCInst& Inst) { |
| 52 | |
| 53 | assert(Inst.getNumOperands() == 3 && "Invalid no. of operands for shift!"); |
| 54 | assert(Inst.getOperand(2).isImm()); |
| 55 | |
| 56 | int64_t Shift = Inst.getOperand(2).getImm(); |
| 57 | if (Shift <= 31) |
| 58 | return; // Do nothing |
| 59 | Shift -= 32; |
| 60 | |
| 61 | // saminus32 |
| 62 | Inst.getOperand(2).setImm(Shift); |
| 63 | |
| 64 | switch (Inst.getOpcode()) { |
| 65 | default: |
| 66 | // Calling function is not synchronized |
| 67 | llvm_unreachable("Unexpected shift instruction"); |
| 68 | case Mips::DSLL: |
| 69 | Inst.setOpcode(Mips::DSLL32); |
| 70 | return; |
| 71 | case Mips::DSRL: |
| 72 | Inst.setOpcode(Mips::DSRL32); |
| 73 | return; |
| 74 | case Mips::DSRA: |
| 75 | Inst.setOpcode(Mips::DSRA32); |
| 76 | return; |
Akira Hatanaka | 6a3fe57 | 2013-09-07 00:18:01 +0000 | [diff] [blame] | 77 | case Mips::DROTR: |
| 78 | Inst.setOpcode(Mips::DROTR32); |
| 79 | return; |
Rafael Espindola | f30f2cc | 2013-05-27 22:34:59 +0000 | [diff] [blame] | 80 | } |
| 81 | } |
| 82 | |
| 83 | // Pick a DEXT or DINS instruction variant based on the pos and size operands |
| 84 | static void LowerDextDins(MCInst& InstIn) { |
| 85 | int Opcode = InstIn.getOpcode(); |
| 86 | |
| 87 | if (Opcode == Mips::DEXT) |
| 88 | assert(InstIn.getNumOperands() == 4 && |
| 89 | "Invalid no. of machine operands for DEXT!"); |
| 90 | else // Only DEXT and DINS are possible |
| 91 | assert(InstIn.getNumOperands() == 5 && |
| 92 | "Invalid no. of machine operands for DINS!"); |
| 93 | |
| 94 | assert(InstIn.getOperand(2).isImm()); |
| 95 | int64_t pos = InstIn.getOperand(2).getImm(); |
| 96 | assert(InstIn.getOperand(3).isImm()); |
| 97 | int64_t size = InstIn.getOperand(3).getImm(); |
| 98 | |
| 99 | if (size <= 32) { |
| 100 | if (pos < 32) // DEXT/DINS, do nothing |
| 101 | return; |
| 102 | // DEXTU/DINSU |
| 103 | InstIn.getOperand(2).setImm(pos - 32); |
| 104 | InstIn.setOpcode((Opcode == Mips::DEXT) ? Mips::DEXTU : Mips::DINSU); |
| 105 | return; |
| 106 | } |
| 107 | // DEXTM/DINSM |
| 108 | assert(pos < 32 && "DEXT/DINS cannot have both size and pos > 32"); |
| 109 | InstIn.getOperand(3).setImm(size - 32); |
| 110 | InstIn.setOpcode((Opcode == Mips::DEXT) ? Mips::DEXTM : Mips::DINSM); |
| 111 | return; |
| 112 | } |
| 113 | |
Matheus Almeida | 9e1450b | 2014-03-20 09:29:54 +0000 | [diff] [blame] | 114 | bool MipsMCCodeEmitter::isMicroMips(const MCSubtargetInfo &STI) const { |
Michael Kuperstein | efd7a96 | 2015-02-19 11:38:11 +0000 | [diff] [blame] | 115 | return STI.getFeatureBits() & Mips::FeatureMicroMips; |
Matheus Almeida | 9e1450b | 2014-03-20 09:29:54 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | void MipsMCCodeEmitter::EmitByte(unsigned char C, raw_ostream &OS) const { |
| 119 | OS << (char)C; |
| 120 | } |
| 121 | |
| 122 | void MipsMCCodeEmitter::EmitInstruction(uint64_t Val, unsigned Size, |
| 123 | const MCSubtargetInfo &STI, |
| 124 | raw_ostream &OS) const { |
| 125 | // Output the instruction encoding in little endian byte order. |
| 126 | // Little-endian byte ordering: |
| 127 | // mips32r2: 4 | 3 | 2 | 1 |
| 128 | // microMIPS: 2 | 1 | 4 | 3 |
| 129 | if (IsLittleEndian && Size == 4 && isMicroMips(STI)) { |
| 130 | EmitInstruction(Val >> 16, 2, STI, OS); |
| 131 | EmitInstruction(Val, 2, STI, OS); |
| 132 | } else { |
| 133 | for (unsigned i = 0; i < Size; ++i) { |
| 134 | unsigned Shift = IsLittleEndian ? i * 8 : (Size - 1 - i) * 8; |
| 135 | EmitByte((Val >> Shift) & 0xff, OS); |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | |
Bruno Cardoso Lopes | c85e3ff | 2011-11-11 22:58:42 +0000 | [diff] [blame] | 140 | /// EncodeInstruction - Emit the instruction. |
Jack Carter | 4e07b95d | 2013-08-27 19:45:28 +0000 | [diff] [blame] | 141 | /// Size the instruction with Desc.getSize(). |
Bruno Cardoso Lopes | c85e3ff | 2011-11-11 22:58:42 +0000 | [diff] [blame] | 142 | void MipsMCCodeEmitter:: |
| 143 | EncodeInstruction(const MCInst &MI, raw_ostream &OS, |
David Woodhouse | 9784cef | 2014-01-28 23:13:07 +0000 | [diff] [blame] | 144 | SmallVectorImpl<MCFixup> &Fixups, |
| 145 | const MCSubtargetInfo &STI) const |
Bruno Cardoso Lopes | c85e3ff | 2011-11-11 22:58:42 +0000 | [diff] [blame] | 146 | { |
Jack Carter | aa7aeaa | 2012-10-02 23:09:40 +0000 | [diff] [blame] | 147 | |
| 148 | // Non-pseudo instructions that get changed for direct object |
| 149 | // only based on operand values. |
| 150 | // If this list of instructions get much longer we will move |
| 151 | // the check to a function call. Until then, this is more efficient. |
| 152 | MCInst TmpInst = MI; |
| 153 | switch (MI.getOpcode()) { |
| 154 | // If shift amount is >= 32 it the inst needs to be lowered further |
| 155 | case Mips::DSLL: |
| 156 | case Mips::DSRL: |
| 157 | case Mips::DSRA: |
Akira Hatanaka | 6a3fe57 | 2013-09-07 00:18:01 +0000 | [diff] [blame] | 158 | case Mips::DROTR: |
Rafael Espindola | f30f2cc | 2013-05-27 22:34:59 +0000 | [diff] [blame] | 159 | LowerLargeShift(TmpInst); |
Jack Carter | aa7aeaa | 2012-10-02 23:09:40 +0000 | [diff] [blame] | 160 | break; |
| 161 | // Double extract instruction is chosen by pos and size operands |
| 162 | case Mips::DEXT: |
| 163 | case Mips::DINS: |
Rafael Espindola | f30f2cc | 2013-05-27 22:34:59 +0000 | [diff] [blame] | 164 | LowerDextDins(TmpInst); |
Jack Carter | aa7aeaa | 2012-10-02 23:09:40 +0000 | [diff] [blame] | 165 | } |
| 166 | |
Jack Carter | 9770097 | 2013-08-13 20:19:16 +0000 | [diff] [blame] | 167 | unsigned long N = Fixups.size(); |
David Woodhouse | 3fa98a6 | 2014-01-28 23:13:18 +0000 | [diff] [blame] | 168 | uint32_t Binary = getBinaryCodeForInstr(TmpInst, Fixups, STI); |
Bruno Cardoso Lopes | c85e3ff | 2011-11-11 22:58:42 +0000 | [diff] [blame] | 169 | |
| 170 | // Check for unimplemented opcodes. |
Jack Carter | aa7aeaa | 2012-10-02 23:09:40 +0000 | [diff] [blame] | 171 | // Unfortunately in MIPS both NOP and SLL will come in with Binary == 0 |
Bruno Cardoso Lopes | c85e3ff | 2011-11-11 22:58:42 +0000 | [diff] [blame] | 172 | // so we have to special check for them. |
Jack Carter | aa7aeaa | 2012-10-02 23:09:40 +0000 | [diff] [blame] | 173 | unsigned Opcode = TmpInst.getOpcode(); |
Jozef Kolek | c7e220f | 2014-11-29 13:29:24 +0000 | [diff] [blame] | 174 | if ((Opcode != Mips::NOP) && (Opcode != Mips::SLL) && |
| 175 | (Opcode != Mips::SLL_MM) && !Binary) |
Bruno Cardoso Lopes | c85e3ff | 2011-11-11 22:58:42 +0000 | [diff] [blame] | 176 | llvm_unreachable("unimplemented opcode in EncodeInstruction()"); |
| 177 | |
Michael Kuperstein | efd7a96 | 2015-02-19 11:38:11 +0000 | [diff] [blame] | 178 | if (STI.getFeatureBits() & Mips::FeatureMicroMips) { |
Akira Hatanaka | be6a818 | 2013-04-19 19:03:11 +0000 | [diff] [blame] | 179 | int NewOpcode = Mips::Std2MicroMips (Opcode, Mips::Arch_micromips); |
| 180 | if (NewOpcode != -1) { |
Jack Carter | 9770097 | 2013-08-13 20:19:16 +0000 | [diff] [blame] | 181 | if (Fixups.size() > N) |
| 182 | Fixups.pop_back(); |
Akira Hatanaka | be6a818 | 2013-04-19 19:03:11 +0000 | [diff] [blame] | 183 | Opcode = NewOpcode; |
| 184 | TmpInst.setOpcode (NewOpcode); |
David Woodhouse | 3fa98a6 | 2014-01-28 23:13:18 +0000 | [diff] [blame] | 185 | Binary = getBinaryCodeForInstr(TmpInst, Fixups, STI); |
Akira Hatanaka | be6a818 | 2013-04-19 19:03:11 +0000 | [diff] [blame] | 186 | } |
| 187 | } |
| 188 | |
Jack Carter | aa7aeaa | 2012-10-02 23:09:40 +0000 | [diff] [blame] | 189 | const MCInstrDesc &Desc = MCII.get(TmpInst.getOpcode()); |
Bruno Cardoso Lopes | c85e3ff | 2011-11-11 22:58:42 +0000 | [diff] [blame] | 190 | |
Jack Carter | 5b5559d | 2012-10-03 21:58:54 +0000 | [diff] [blame] | 191 | // Get byte count of instruction |
| 192 | unsigned Size = Desc.getSize(); |
| 193 | if (!Size) |
| 194 | llvm_unreachable("Desc.getSize() returns 0"); |
Bruno Cardoso Lopes | c85e3ff | 2011-11-11 22:58:42 +0000 | [diff] [blame] | 195 | |
David Woodhouse | d2cca11 | 2014-01-28 23:13:25 +0000 | [diff] [blame] | 196 | EmitInstruction(Binary, Size, STI, OS); |
Bruno Cardoso Lopes | c85e3ff | 2011-11-11 22:58:42 +0000 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | /// getBranchTargetOpValue - Return binary encoding of the branch |
| 200 | /// target operand. If the machine operand requires relocation, |
| 201 | /// record the relocation and return zero. |
| 202 | unsigned MipsMCCodeEmitter:: |
| 203 | getBranchTargetOpValue(const MCInst &MI, unsigned OpNo, |
David Woodhouse | 3fa98a6 | 2014-01-28 23:13:18 +0000 | [diff] [blame] | 204 | SmallVectorImpl<MCFixup> &Fixups, |
| 205 | const MCSubtargetInfo &STI) const { |
Bruno Cardoso Lopes | c85e3ff | 2011-11-11 22:58:42 +0000 | [diff] [blame] | 206 | |
| 207 | const MCOperand &MO = MI.getOperand(OpNo); |
Jack Carter | 71e6a74 | 2012-09-06 00:43:26 +0000 | [diff] [blame] | 208 | |
Jack Carter | 4f69a0f | 2013-03-22 00:29:10 +0000 | [diff] [blame] | 209 | // If the destination is an immediate, divide by 4. |
| 210 | if (MO.isImm()) return MO.getImm() >> 2; |
| 211 | |
Jack Carter | 71e6a74 | 2012-09-06 00:43:26 +0000 | [diff] [blame] | 212 | assert(MO.isExpr() && |
| 213 | "getBranchTargetOpValue expects only expressions or immediates"); |
Bruno Cardoso Lopes | c85e3ff | 2011-11-11 22:58:42 +0000 | [diff] [blame] | 214 | |
| 215 | const MCExpr *Expr = MO.getExpr(); |
| 216 | Fixups.push_back(MCFixup::Create(0, Expr, |
| 217 | MCFixupKind(Mips::fixup_Mips_PC16))); |
| 218 | return 0; |
| 219 | } |
| 220 | |
Jozef Kolek | 9761e96 | 2015-01-12 12:03:34 +0000 | [diff] [blame] | 221 | /// getBranchTarget7OpValueMM - Return binary encoding of the microMIPS branch |
| 222 | /// target operand. If the machine operand requires relocation, |
| 223 | /// record the relocation and return zero. |
| 224 | unsigned MipsMCCodeEmitter:: |
| 225 | getBranchTarget7OpValueMM(const MCInst &MI, unsigned OpNo, |
| 226 | SmallVectorImpl<MCFixup> &Fixups, |
| 227 | const MCSubtargetInfo &STI) const { |
| 228 | |
| 229 | const MCOperand &MO = MI.getOperand(OpNo); |
| 230 | |
| 231 | // If the destination is an immediate, divide by 2. |
| 232 | if (MO.isImm()) return MO.getImm() >> 1; |
| 233 | |
| 234 | assert(MO.isExpr() && |
| 235 | "getBranchTargetOpValueMM expects only expressions or immediates"); |
| 236 | |
| 237 | const MCExpr *Expr = MO.getExpr(); |
| 238 | Fixups.push_back(MCFixup::Create(0, Expr, |
| 239 | MCFixupKind(Mips::fixup_MICROMIPS_PC7_S1))); |
| 240 | return 0; |
| 241 | } |
| 242 | |
Jozef Kolek | 5cfebdd | 2015-01-21 12:39:30 +0000 | [diff] [blame] | 243 | /// getBranchTargetOpValueMMPC10 - Return binary encoding of the microMIPS |
| 244 | /// 10-bit branch target operand. If the machine operand requires relocation, |
| 245 | /// record the relocation and return zero. |
| 246 | unsigned MipsMCCodeEmitter:: |
| 247 | getBranchTargetOpValueMMPC10(const MCInst &MI, unsigned OpNo, |
| 248 | SmallVectorImpl<MCFixup> &Fixups, |
| 249 | const MCSubtargetInfo &STI) const { |
| 250 | |
| 251 | const MCOperand &MO = MI.getOperand(OpNo); |
| 252 | |
| 253 | // If the destination is an immediate, divide by 2. |
| 254 | if (MO.isImm()) return MO.getImm() >> 1; |
| 255 | |
| 256 | assert(MO.isExpr() && |
| 257 | "getBranchTargetOpValuePC10 expects only expressions or immediates"); |
| 258 | |
| 259 | const MCExpr *Expr = MO.getExpr(); |
| 260 | Fixups.push_back(MCFixup::Create(0, Expr, |
| 261 | MCFixupKind(Mips::fixup_MICROMIPS_PC10_S1))); |
| 262 | return 0; |
| 263 | } |
| 264 | |
Zoran Jovanovic | 8a80aa7 | 2013-11-04 14:53:22 +0000 | [diff] [blame] | 265 | /// getBranchTargetOpValue - Return binary encoding of the microMIPS branch |
| 266 | /// target operand. If the machine operand requires relocation, |
| 267 | /// record the relocation and return zero. |
| 268 | unsigned MipsMCCodeEmitter:: |
| 269 | getBranchTargetOpValueMM(const MCInst &MI, unsigned OpNo, |
David Woodhouse | 3fa98a6 | 2014-01-28 23:13:18 +0000 | [diff] [blame] | 270 | SmallVectorImpl<MCFixup> &Fixups, |
| 271 | const MCSubtargetInfo &STI) const { |
Zoran Jovanovic | 8a80aa7 | 2013-11-04 14:53:22 +0000 | [diff] [blame] | 272 | |
| 273 | const MCOperand &MO = MI.getOperand(OpNo); |
| 274 | |
| 275 | // If the destination is an immediate, divide by 2. |
| 276 | if (MO.isImm()) return MO.getImm() >> 1; |
| 277 | |
| 278 | assert(MO.isExpr() && |
| 279 | "getBranchTargetOpValueMM expects only expressions or immediates"); |
| 280 | |
| 281 | const MCExpr *Expr = MO.getExpr(); |
| 282 | Fixups.push_back(MCFixup::Create(0, Expr, |
| 283 | MCFixupKind(Mips:: |
| 284 | fixup_MICROMIPS_PC16_S1))); |
| 285 | return 0; |
| 286 | } |
| 287 | |
Zoran Jovanovic | 3c8869d | 2014-05-16 11:03:45 +0000 | [diff] [blame] | 288 | /// getBranchTarget21OpValue - Return binary encoding of the branch |
| 289 | /// target operand. If the machine operand requires relocation, |
| 290 | /// record the relocation and return zero. |
| 291 | unsigned MipsMCCodeEmitter:: |
| 292 | getBranchTarget21OpValue(const MCInst &MI, unsigned OpNo, |
| 293 | SmallVectorImpl<MCFixup> &Fixups, |
| 294 | const MCSubtargetInfo &STI) const { |
| 295 | |
| 296 | const MCOperand &MO = MI.getOperand(OpNo); |
| 297 | |
| 298 | // If the destination is an immediate, divide by 4. |
| 299 | if (MO.isImm()) return MO.getImm() >> 2; |
| 300 | |
| 301 | assert(MO.isExpr() && |
| 302 | "getBranchTarget21OpValue expects only expressions or immediates"); |
| 303 | |
Zoran Jovanovic | 10e06da | 2014-05-27 12:55:40 +0000 | [diff] [blame] | 304 | const MCExpr *Expr = MO.getExpr(); |
| 305 | Fixups.push_back(MCFixup::Create(0, Expr, |
| 306 | MCFixupKind(Mips::fixup_MIPS_PC21_S2))); |
Zoran Jovanovic | 3c8869d | 2014-05-16 11:03:45 +0000 | [diff] [blame] | 307 | return 0; |
| 308 | } |
| 309 | |
| 310 | /// getBranchTarget26OpValue - Return binary encoding of the branch |
| 311 | /// target operand. If the machine operand requires relocation, |
| 312 | /// record the relocation and return zero. |
| 313 | unsigned MipsMCCodeEmitter:: |
| 314 | getBranchTarget26OpValue(const MCInst &MI, unsigned OpNo, |
| 315 | SmallVectorImpl<MCFixup> &Fixups, |
| 316 | const MCSubtargetInfo &STI) const { |
| 317 | |
| 318 | const MCOperand &MO = MI.getOperand(OpNo); |
| 319 | |
| 320 | // If the destination is an immediate, divide by 4. |
| 321 | if (MO.isImm()) return MO.getImm() >> 2; |
| 322 | |
| 323 | assert(MO.isExpr() && |
| 324 | "getBranchTarget26OpValue expects only expressions or immediates"); |
| 325 | |
Zoran Jovanovic | 10e06da | 2014-05-27 12:55:40 +0000 | [diff] [blame] | 326 | const MCExpr *Expr = MO.getExpr(); |
| 327 | Fixups.push_back(MCFixup::Create(0, Expr, |
| 328 | MCFixupKind(Mips::fixup_MIPS_PC26_S2))); |
Zoran Jovanovic | 3c8869d | 2014-05-16 11:03:45 +0000 | [diff] [blame] | 329 | return 0; |
| 330 | } |
| 331 | |
Zoran Jovanovic | 52c56b9 | 2014-05-16 13:19:46 +0000 | [diff] [blame] | 332 | /// getJumpOffset16OpValue - Return binary encoding of the jump |
| 333 | /// target operand. If the machine operand requires relocation, |
| 334 | /// record the relocation and return zero. |
| 335 | unsigned MipsMCCodeEmitter:: |
| 336 | getJumpOffset16OpValue(const MCInst &MI, unsigned OpNo, |
| 337 | SmallVectorImpl<MCFixup> &Fixups, |
| 338 | const MCSubtargetInfo &STI) const { |
| 339 | |
| 340 | const MCOperand &MO = MI.getOperand(OpNo); |
| 341 | |
| 342 | if (MO.isImm()) return MO.getImm(); |
| 343 | |
| 344 | assert(MO.isExpr() && |
| 345 | "getJumpOffset16OpValue expects only expressions or an immediate"); |
| 346 | |
| 347 | // TODO: Push fixup. |
| 348 | return 0; |
| 349 | } |
| 350 | |
Bruno Cardoso Lopes | c85e3ff | 2011-11-11 22:58:42 +0000 | [diff] [blame] | 351 | /// getJumpTargetOpValue - Return binary encoding of the jump |
| 352 | /// target operand. If the machine operand requires relocation, |
| 353 | /// record the relocation and return zero. |
| 354 | unsigned MipsMCCodeEmitter:: |
| 355 | getJumpTargetOpValue(const MCInst &MI, unsigned OpNo, |
David Woodhouse | 3fa98a6 | 2014-01-28 23:13:18 +0000 | [diff] [blame] | 356 | SmallVectorImpl<MCFixup> &Fixups, |
| 357 | const MCSubtargetInfo &STI) const { |
Bruno Cardoso Lopes | c85e3ff | 2011-11-11 22:58:42 +0000 | [diff] [blame] | 358 | |
| 359 | const MCOperand &MO = MI.getOperand(OpNo); |
Jack Carter | 4f69a0f | 2013-03-22 00:29:10 +0000 | [diff] [blame] | 360 | // If the destination is an immediate, divide by 4. |
| 361 | if (MO.isImm()) return MO.getImm()>>2; |
| 362 | |
Jack Carter | 71e6a74 | 2012-09-06 00:43:26 +0000 | [diff] [blame] | 363 | assert(MO.isExpr() && |
| 364 | "getJumpTargetOpValue expects only expressions or an immediate"); |
Bruno Cardoso Lopes | c85e3ff | 2011-11-11 22:58:42 +0000 | [diff] [blame] | 365 | |
| 366 | const MCExpr *Expr = MO.getExpr(); |
| 367 | Fixups.push_back(MCFixup::Create(0, Expr, |
| 368 | MCFixupKind(Mips::fixup_Mips_26))); |
| 369 | return 0; |
| 370 | } |
| 371 | |
Bruno Cardoso Lopes | c85e3ff | 2011-11-11 22:58:42 +0000 | [diff] [blame] | 372 | unsigned MipsMCCodeEmitter:: |
Zoran Jovanovic | 507e084 | 2013-10-29 16:38:59 +0000 | [diff] [blame] | 373 | getJumpTargetOpValueMM(const MCInst &MI, unsigned OpNo, |
David Woodhouse | 3fa98a6 | 2014-01-28 23:13:18 +0000 | [diff] [blame] | 374 | SmallVectorImpl<MCFixup> &Fixups, |
| 375 | const MCSubtargetInfo &STI) const { |
Zoran Jovanovic | 507e084 | 2013-10-29 16:38:59 +0000 | [diff] [blame] | 376 | |
| 377 | const MCOperand &MO = MI.getOperand(OpNo); |
| 378 | // If the destination is an immediate, divide by 2. |
| 379 | if (MO.isImm()) return MO.getImm() >> 1; |
| 380 | |
| 381 | assert(MO.isExpr() && |
| 382 | "getJumpTargetOpValueMM expects only expressions or an immediate"); |
| 383 | |
| 384 | const MCExpr *Expr = MO.getExpr(); |
| 385 | Fixups.push_back(MCFixup::Create(0, Expr, |
| 386 | MCFixupKind(Mips::fixup_MICROMIPS_26_S1))); |
| 387 | return 0; |
| 388 | } |
| 389 | |
| 390 | unsigned MipsMCCodeEmitter:: |
Zoran Jovanovic | c74e3eb9 | 2014-09-12 14:29:54 +0000 | [diff] [blame] | 391 | getUImm5Lsl2Encoding(const MCInst &MI, unsigned OpNo, |
| 392 | SmallVectorImpl<MCFixup> &Fixups, |
| 393 | const MCSubtargetInfo &STI) const { |
| 394 | |
| 395 | const MCOperand &MO = MI.getOperand(OpNo); |
| 396 | if (MO.isImm()) { |
| 397 | // The immediate is encoded as 'immediate << 2'. |
| 398 | unsigned Res = getMachineOpValue(MI, MO, Fixups, STI); |
| 399 | assert((Res & 3) == 0); |
| 400 | return Res >> 2; |
| 401 | } |
| 402 | |
| 403 | assert(MO.isExpr() && |
| 404 | "getUImm5Lsl2Encoding expects only expressions or an immediate"); |
| 405 | |
| 406 | return 0; |
| 407 | } |
| 408 | |
| 409 | unsigned MipsMCCodeEmitter:: |
Zoran Jovanovic | bac3619 | 2014-10-23 11:06:34 +0000 | [diff] [blame] | 410 | getSImm3Lsa2Value(const MCInst &MI, unsigned OpNo, |
| 411 | SmallVectorImpl<MCFixup> &Fixups, |
| 412 | const MCSubtargetInfo &STI) const { |
| 413 | |
| 414 | const MCOperand &MO = MI.getOperand(OpNo); |
| 415 | if (MO.isImm()) { |
| 416 | int Value = MO.getImm(); |
| 417 | return Value >> 2; |
| 418 | } |
| 419 | |
| 420 | return 0; |
| 421 | } |
| 422 | |
| 423 | unsigned MipsMCCodeEmitter:: |
Zoran Jovanovic | 42b8444 | 2014-10-23 11:13:59 +0000 | [diff] [blame] | 424 | getUImm6Lsl2Encoding(const MCInst &MI, unsigned OpNo, |
| 425 | SmallVectorImpl<MCFixup> &Fixups, |
| 426 | const MCSubtargetInfo &STI) const { |
| 427 | |
| 428 | const MCOperand &MO = MI.getOperand(OpNo); |
| 429 | if (MO.isImm()) { |
| 430 | unsigned Value = MO.getImm(); |
| 431 | return Value >> 2; |
| 432 | } |
| 433 | |
| 434 | return 0; |
| 435 | } |
| 436 | |
| 437 | unsigned MipsMCCodeEmitter:: |
Zoran Jovanovic | 98bd58c | 2014-10-10 14:37:30 +0000 | [diff] [blame] | 438 | getSImm9AddiuspValue(const MCInst &MI, unsigned OpNo, |
| 439 | SmallVectorImpl<MCFixup> &Fixups, |
| 440 | const MCSubtargetInfo &STI) const { |
| 441 | |
| 442 | const MCOperand &MO = MI.getOperand(OpNo); |
| 443 | if (MO.isImm()) { |
| 444 | unsigned Binary = (MO.getImm() >> 2) & 0x0000ffff; |
| 445 | return (((Binary & 0x8000) >> 7) | (Binary & 0x00ff)); |
| 446 | } |
| 447 | |
| 448 | return 0; |
| 449 | } |
| 450 | |
| 451 | unsigned MipsMCCodeEmitter:: |
Daniel Sanders | 60f1db0 | 2015-03-13 12:45:09 +0000 | [diff] [blame^] | 452 | getExprOpValue(const MCExpr *Expr, SmallVectorImpl<MCFixup> &Fixups, |
David Woodhouse | 3fa98a6 | 2014-01-28 23:13:18 +0000 | [diff] [blame] | 453 | const MCSubtargetInfo &STI) const { |
Jack Carter | b5cf590 | 2013-04-17 00:18:04 +0000 | [diff] [blame] | 454 | int64_t Res; |
Akira Hatanaka | 049e9e4 | 2011-11-23 22:19:28 +0000 | [diff] [blame] | 455 | |
Jack Carter | b5cf590 | 2013-04-17 00:18:04 +0000 | [diff] [blame] | 456 | if (Expr->EvaluateAsAbsolute(Res)) |
| 457 | return Res; |
Akira Hatanaka | 049e9e4 | 2011-11-23 22:19:28 +0000 | [diff] [blame] | 458 | |
Akira Hatanaka | fe384a2 | 2012-03-27 02:33:05 +0000 | [diff] [blame] | 459 | MCExpr::ExprKind Kind = Expr->getKind(); |
Jack Carter | b5cf590 | 2013-04-17 00:18:04 +0000 | [diff] [blame] | 460 | if (Kind == MCExpr::Constant) { |
| 461 | return cast<MCConstantExpr>(Expr)->getValue(); |
| 462 | } |
Akira Hatanaka | e2eed96 | 2011-12-22 01:05:17 +0000 | [diff] [blame] | 463 | |
Akira Hatanaka | fe384a2 | 2012-03-27 02:33:05 +0000 | [diff] [blame] | 464 | if (Kind == MCExpr::Binary) { |
David Woodhouse | 3fa98a6 | 2014-01-28 23:13:18 +0000 | [diff] [blame] | 465 | unsigned Res = getExprOpValue(cast<MCBinaryExpr>(Expr)->getLHS(), Fixups, STI); |
| 466 | Res += getExprOpValue(cast<MCBinaryExpr>(Expr)->getRHS(), Fixups, STI); |
Jack Carter | b5cf590 | 2013-04-17 00:18:04 +0000 | [diff] [blame] | 467 | return Res; |
Bruno Cardoso Lopes | c85e3ff | 2011-11-11 22:58:42 +0000 | [diff] [blame] | 468 | } |
Petar Jovanovic | a5da588 | 2014-02-04 18:41:57 +0000 | [diff] [blame] | 469 | |
| 470 | if (Kind == MCExpr::Target) { |
| 471 | const MipsMCExpr *MipsExpr = cast<MipsMCExpr>(Expr); |
| 472 | |
| 473 | Mips::Fixups FixupKind = Mips::Fixups(0); |
| 474 | switch (MipsExpr->getKind()) { |
| 475 | default: llvm_unreachable("Unsupported fixup kind for target expression!"); |
Sasa Stankovic | 06c4780 | 2014-04-03 10:37:45 +0000 | [diff] [blame] | 476 | case MipsMCExpr::VK_Mips_HIGHEST: |
| 477 | FixupKind = Mips::fixup_Mips_HIGHEST; |
| 478 | break; |
| 479 | case MipsMCExpr::VK_Mips_HIGHER: |
| 480 | FixupKind = Mips::fixup_Mips_HIGHER; |
| 481 | break; |
| 482 | case MipsMCExpr::VK_Mips_HI: |
Petar Jovanovic | a5da588 | 2014-02-04 18:41:57 +0000 | [diff] [blame] | 483 | FixupKind = isMicroMips(STI) ? Mips::fixup_MICROMIPS_HI16 |
| 484 | : Mips::fixup_Mips_HI16; |
| 485 | break; |
Sasa Stankovic | 06c4780 | 2014-04-03 10:37:45 +0000 | [diff] [blame] | 486 | case MipsMCExpr::VK_Mips_LO: |
Petar Jovanovic | a5da588 | 2014-02-04 18:41:57 +0000 | [diff] [blame] | 487 | FixupKind = isMicroMips(STI) ? Mips::fixup_MICROMIPS_LO16 |
| 488 | : Mips::fixup_Mips_LO16; |
| 489 | break; |
| 490 | } |
| 491 | Fixups.push_back(MCFixup::Create(0, MipsExpr, MCFixupKind(FixupKind))); |
| 492 | return 0; |
| 493 | } |
| 494 | |
Jack Carter | b5cf590 | 2013-04-17 00:18:04 +0000 | [diff] [blame] | 495 | if (Kind == MCExpr::SymbolRef) { |
Mark Seaborn | c3bd177 | 2013-12-31 13:05:15 +0000 | [diff] [blame] | 496 | Mips::Fixups FixupKind = Mips::Fixups(0); |
Akira Hatanaka | fe384a2 | 2012-03-27 02:33:05 +0000 | [diff] [blame] | 497 | |
Mark Seaborn | c3bd177 | 2013-12-31 13:05:15 +0000 | [diff] [blame] | 498 | switch(cast<MCSymbolRefExpr>(Expr)->getKind()) { |
| 499 | default: llvm_unreachable("Unknown fixup kind!"); |
| 500 | break; |
Daniel Sanders | 60f1db0 | 2015-03-13 12:45:09 +0000 | [diff] [blame^] | 501 | case MCSymbolRefExpr::VK_None: |
| 502 | FixupKind = Mips::fixup_Mips_32; // FIXME: This is ok for O32/N32 but not N64. |
| 503 | break; |
Mark Seaborn | c3bd177 | 2013-12-31 13:05:15 +0000 | [diff] [blame] | 504 | case MCSymbolRefExpr::VK_Mips_GPOFF_HI : |
| 505 | FixupKind = Mips::fixup_Mips_GPOFF_HI; |
| 506 | break; |
| 507 | case MCSymbolRefExpr::VK_Mips_GPOFF_LO : |
| 508 | FixupKind = Mips::fixup_Mips_GPOFF_LO; |
| 509 | break; |
| 510 | case MCSymbolRefExpr::VK_Mips_GOT_PAGE : |
David Woodhouse | d2cca11 | 2014-01-28 23:13:25 +0000 | [diff] [blame] | 511 | FixupKind = isMicroMips(STI) ? Mips::fixup_MICROMIPS_GOT_PAGE |
Mark Seaborn | c3bd177 | 2013-12-31 13:05:15 +0000 | [diff] [blame] | 512 | : Mips::fixup_Mips_GOT_PAGE; |
| 513 | break; |
| 514 | case MCSymbolRefExpr::VK_Mips_GOT_OFST : |
David Woodhouse | d2cca11 | 2014-01-28 23:13:25 +0000 | [diff] [blame] | 515 | FixupKind = isMicroMips(STI) ? Mips::fixup_MICROMIPS_GOT_OFST |
Mark Seaborn | c3bd177 | 2013-12-31 13:05:15 +0000 | [diff] [blame] | 516 | : Mips::fixup_Mips_GOT_OFST; |
| 517 | break; |
| 518 | case MCSymbolRefExpr::VK_Mips_GOT_DISP : |
David Woodhouse | d2cca11 | 2014-01-28 23:13:25 +0000 | [diff] [blame] | 519 | FixupKind = isMicroMips(STI) ? Mips::fixup_MICROMIPS_GOT_DISP |
Mark Seaborn | c3bd177 | 2013-12-31 13:05:15 +0000 | [diff] [blame] | 520 | : Mips::fixup_Mips_GOT_DISP; |
| 521 | break; |
| 522 | case MCSymbolRefExpr::VK_Mips_GPREL: |
| 523 | FixupKind = Mips::fixup_Mips_GPREL16; |
| 524 | break; |
| 525 | case MCSymbolRefExpr::VK_Mips_GOT_CALL: |
David Woodhouse | d2cca11 | 2014-01-28 23:13:25 +0000 | [diff] [blame] | 526 | FixupKind = isMicroMips(STI) ? Mips::fixup_MICROMIPS_CALL16 |
Mark Seaborn | c3bd177 | 2013-12-31 13:05:15 +0000 | [diff] [blame] | 527 | : Mips::fixup_Mips_CALL16; |
| 528 | break; |
| 529 | case MCSymbolRefExpr::VK_Mips_GOT16: |
David Woodhouse | d2cca11 | 2014-01-28 23:13:25 +0000 | [diff] [blame] | 530 | FixupKind = isMicroMips(STI) ? Mips::fixup_MICROMIPS_GOT16 |
Mark Seaborn | c3bd177 | 2013-12-31 13:05:15 +0000 | [diff] [blame] | 531 | : Mips::fixup_Mips_GOT_Global; |
| 532 | break; |
| 533 | case MCSymbolRefExpr::VK_Mips_GOT: |
David Woodhouse | d2cca11 | 2014-01-28 23:13:25 +0000 | [diff] [blame] | 534 | FixupKind = isMicroMips(STI) ? Mips::fixup_MICROMIPS_GOT16 |
Mark Seaborn | c3bd177 | 2013-12-31 13:05:15 +0000 | [diff] [blame] | 535 | : Mips::fixup_Mips_GOT_Local; |
| 536 | break; |
| 537 | case MCSymbolRefExpr::VK_Mips_ABS_HI: |
David Woodhouse | d2cca11 | 2014-01-28 23:13:25 +0000 | [diff] [blame] | 538 | FixupKind = isMicroMips(STI) ? Mips::fixup_MICROMIPS_HI16 |
Mark Seaborn | c3bd177 | 2013-12-31 13:05:15 +0000 | [diff] [blame] | 539 | : Mips::fixup_Mips_HI16; |
| 540 | break; |
| 541 | case MCSymbolRefExpr::VK_Mips_ABS_LO: |
David Woodhouse | d2cca11 | 2014-01-28 23:13:25 +0000 | [diff] [blame] | 542 | FixupKind = isMicroMips(STI) ? Mips::fixup_MICROMIPS_LO16 |
Mark Seaborn | c3bd177 | 2013-12-31 13:05:15 +0000 | [diff] [blame] | 543 | : Mips::fixup_Mips_LO16; |
| 544 | break; |
| 545 | case MCSymbolRefExpr::VK_Mips_TLSGD: |
David Woodhouse | d2cca11 | 2014-01-28 23:13:25 +0000 | [diff] [blame] | 546 | FixupKind = isMicroMips(STI) ? Mips::fixup_MICROMIPS_TLS_GD |
Mark Seaborn | c3bd177 | 2013-12-31 13:05:15 +0000 | [diff] [blame] | 547 | : Mips::fixup_Mips_TLSGD; |
| 548 | break; |
| 549 | case MCSymbolRefExpr::VK_Mips_TLSLDM: |
David Woodhouse | d2cca11 | 2014-01-28 23:13:25 +0000 | [diff] [blame] | 550 | FixupKind = isMicroMips(STI) ? Mips::fixup_MICROMIPS_TLS_LDM |
Mark Seaborn | c3bd177 | 2013-12-31 13:05:15 +0000 | [diff] [blame] | 551 | : Mips::fixup_Mips_TLSLDM; |
| 552 | break; |
| 553 | case MCSymbolRefExpr::VK_Mips_DTPREL_HI: |
David Woodhouse | d2cca11 | 2014-01-28 23:13:25 +0000 | [diff] [blame] | 554 | FixupKind = isMicroMips(STI) ? Mips::fixup_MICROMIPS_TLS_DTPREL_HI16 |
Mark Seaborn | c3bd177 | 2013-12-31 13:05:15 +0000 | [diff] [blame] | 555 | : Mips::fixup_Mips_DTPREL_HI; |
| 556 | break; |
| 557 | case MCSymbolRefExpr::VK_Mips_DTPREL_LO: |
David Woodhouse | d2cca11 | 2014-01-28 23:13:25 +0000 | [diff] [blame] | 558 | FixupKind = isMicroMips(STI) ? Mips::fixup_MICROMIPS_TLS_DTPREL_LO16 |
Mark Seaborn | c3bd177 | 2013-12-31 13:05:15 +0000 | [diff] [blame] | 559 | : Mips::fixup_Mips_DTPREL_LO; |
| 560 | break; |
| 561 | case MCSymbolRefExpr::VK_Mips_GOTTPREL: |
| 562 | FixupKind = Mips::fixup_Mips_GOTTPREL; |
| 563 | break; |
| 564 | case MCSymbolRefExpr::VK_Mips_TPREL_HI: |
David Woodhouse | d2cca11 | 2014-01-28 23:13:25 +0000 | [diff] [blame] | 565 | FixupKind = isMicroMips(STI) ? Mips::fixup_MICROMIPS_TLS_TPREL_HI16 |
Mark Seaborn | c3bd177 | 2013-12-31 13:05:15 +0000 | [diff] [blame] | 566 | : Mips::fixup_Mips_TPREL_HI; |
| 567 | break; |
| 568 | case MCSymbolRefExpr::VK_Mips_TPREL_LO: |
David Woodhouse | d2cca11 | 2014-01-28 23:13:25 +0000 | [diff] [blame] | 569 | FixupKind = isMicroMips(STI) ? Mips::fixup_MICROMIPS_TLS_TPREL_LO16 |
Mark Seaborn | c3bd177 | 2013-12-31 13:05:15 +0000 | [diff] [blame] | 570 | : Mips::fixup_Mips_TPREL_LO; |
| 571 | break; |
| 572 | case MCSymbolRefExpr::VK_Mips_HIGHER: |
| 573 | FixupKind = Mips::fixup_Mips_HIGHER; |
| 574 | break; |
| 575 | case MCSymbolRefExpr::VK_Mips_HIGHEST: |
| 576 | FixupKind = Mips::fixup_Mips_HIGHEST; |
| 577 | break; |
| 578 | case MCSymbolRefExpr::VK_Mips_GOT_HI16: |
| 579 | FixupKind = Mips::fixup_Mips_GOT_HI16; |
| 580 | break; |
| 581 | case MCSymbolRefExpr::VK_Mips_GOT_LO16: |
| 582 | FixupKind = Mips::fixup_Mips_GOT_LO16; |
| 583 | break; |
| 584 | case MCSymbolRefExpr::VK_Mips_CALL_HI16: |
| 585 | FixupKind = Mips::fixup_Mips_CALL_HI16; |
| 586 | break; |
| 587 | case MCSymbolRefExpr::VK_Mips_CALL_LO16: |
| 588 | FixupKind = Mips::fixup_Mips_CALL_LO16; |
| 589 | break; |
Zoran Jovanovic | b355e8f | 2014-05-27 14:58:51 +0000 | [diff] [blame] | 590 | case MCSymbolRefExpr::VK_Mips_PCREL_HI16: |
| 591 | FixupKind = Mips::fixup_MIPS_PCHI16; |
| 592 | break; |
| 593 | case MCSymbolRefExpr::VK_Mips_PCREL_LO16: |
| 594 | FixupKind = Mips::fixup_MIPS_PCLO16; |
| 595 | break; |
Mark Seaborn | c3bd177 | 2013-12-31 13:05:15 +0000 | [diff] [blame] | 596 | } // switch |
Akira Hatanaka | fe384a2 | 2012-03-27 02:33:05 +0000 | [diff] [blame] | 597 | |
Jack Carter | b5cf590 | 2013-04-17 00:18:04 +0000 | [diff] [blame] | 598 | Fixups.push_back(MCFixup::Create(0, Expr, MCFixupKind(FixupKind))); |
| 599 | return 0; |
| 600 | } |
Akira Hatanaka | fe384a2 | 2012-03-27 02:33:05 +0000 | [diff] [blame] | 601 | return 0; |
Bruno Cardoso Lopes | c85e3ff | 2011-11-11 22:58:42 +0000 | [diff] [blame] | 602 | } |
| 603 | |
Jack Carter | b5cf590 | 2013-04-17 00:18:04 +0000 | [diff] [blame] | 604 | /// getMachineOpValue - Return binary encoding of operand. If the machine |
| 605 | /// operand requires relocation, record the relocation and return zero. |
| 606 | unsigned MipsMCCodeEmitter:: |
| 607 | getMachineOpValue(const MCInst &MI, const MCOperand &MO, |
David Woodhouse | 3fa98a6 | 2014-01-28 23:13:18 +0000 | [diff] [blame] | 608 | SmallVectorImpl<MCFixup> &Fixups, |
| 609 | const MCSubtargetInfo &STI) const { |
Jack Carter | b5cf590 | 2013-04-17 00:18:04 +0000 | [diff] [blame] | 610 | if (MO.isReg()) { |
| 611 | unsigned Reg = MO.getReg(); |
Bill Wendling | bc07a89 | 2013-06-18 07:20:20 +0000 | [diff] [blame] | 612 | unsigned RegNo = Ctx.getRegisterInfo()->getEncodingValue(Reg); |
Jack Carter | b5cf590 | 2013-04-17 00:18:04 +0000 | [diff] [blame] | 613 | return RegNo; |
| 614 | } else if (MO.isImm()) { |
| 615 | return static_cast<unsigned>(MO.getImm()); |
| 616 | } else if (MO.isFPImm()) { |
| 617 | return static_cast<unsigned>(APFloat(MO.getFPImm()) |
| 618 | .bitcastToAPInt().getHiBits(32).getLimitedValue()); |
| 619 | } |
| 620 | // MO must be an Expr. |
| 621 | assert(MO.isExpr()); |
David Woodhouse | 3fa98a6 | 2014-01-28 23:13:18 +0000 | [diff] [blame] | 622 | return getExprOpValue(MO.getExpr(),Fixups, STI); |
Jack Carter | b5cf590 | 2013-04-17 00:18:04 +0000 | [diff] [blame] | 623 | } |
| 624 | |
Matheus Almeida | 6b59c44 | 2013-12-05 11:06:22 +0000 | [diff] [blame] | 625 | /// getMSAMemEncoding - Return binary encoding of memory operand for LD/ST |
| 626 | /// instructions. |
| 627 | unsigned |
| 628 | MipsMCCodeEmitter::getMSAMemEncoding(const MCInst &MI, unsigned OpNo, |
David Woodhouse | 3fa98a6 | 2014-01-28 23:13:18 +0000 | [diff] [blame] | 629 | SmallVectorImpl<MCFixup> &Fixups, |
| 630 | const MCSubtargetInfo &STI) const { |
Matheus Almeida | 6b59c44 | 2013-12-05 11:06:22 +0000 | [diff] [blame] | 631 | // Base register is encoded in bits 20-16, offset is encoded in bits 15-0. |
| 632 | assert(MI.getOperand(OpNo).isReg()); |
David Woodhouse | 3fa98a6 | 2014-01-28 23:13:18 +0000 | [diff] [blame] | 633 | unsigned RegBits = getMachineOpValue(MI, MI.getOperand(OpNo),Fixups, STI) << 16; |
| 634 | unsigned OffBits = getMachineOpValue(MI, MI.getOperand(OpNo+1), Fixups, STI); |
Matheus Almeida | 6b59c44 | 2013-12-05 11:06:22 +0000 | [diff] [blame] | 635 | |
| 636 | // The immediate field of an LD/ST instruction is scaled which means it must |
| 637 | // be divided (when encoding) by the size (in bytes) of the instructions' |
| 638 | // data format. |
| 639 | // .b - 1 byte |
| 640 | // .h - 2 bytes |
| 641 | // .w - 4 bytes |
| 642 | // .d - 8 bytes |
| 643 | switch(MI.getOpcode()) |
| 644 | { |
| 645 | default: |
| 646 | assert (0 && "Unexpected instruction"); |
| 647 | break; |
| 648 | case Mips::LD_B: |
| 649 | case Mips::ST_B: |
| 650 | // We don't need to scale the offset in this case |
| 651 | break; |
| 652 | case Mips::LD_H: |
| 653 | case Mips::ST_H: |
| 654 | OffBits >>= 1; |
| 655 | break; |
| 656 | case Mips::LD_W: |
| 657 | case Mips::ST_W: |
| 658 | OffBits >>= 2; |
| 659 | break; |
| 660 | case Mips::LD_D: |
| 661 | case Mips::ST_D: |
| 662 | OffBits >>= 3; |
| 663 | break; |
| 664 | } |
| 665 | |
| 666 | return (OffBits & 0xFFFF) | RegBits; |
| 667 | } |
| 668 | |
Bruno Cardoso Lopes | c85e3ff | 2011-11-11 22:58:42 +0000 | [diff] [blame] | 669 | /// getMemEncoding - Return binary encoding of memory related operand. |
| 670 | /// If the offset operand requires relocation, record the relocation. |
| 671 | unsigned |
| 672 | MipsMCCodeEmitter::getMemEncoding(const MCInst &MI, unsigned OpNo, |
David Woodhouse | 3fa98a6 | 2014-01-28 23:13:18 +0000 | [diff] [blame] | 673 | SmallVectorImpl<MCFixup> &Fixups, |
| 674 | const MCSubtargetInfo &STI) const { |
Bruno Cardoso Lopes | c85e3ff | 2011-11-11 22:58:42 +0000 | [diff] [blame] | 675 | // Base register is encoded in bits 20-16, offset is encoded in bits 15-0. |
| 676 | assert(MI.getOperand(OpNo).isReg()); |
David Woodhouse | 3fa98a6 | 2014-01-28 23:13:18 +0000 | [diff] [blame] | 677 | unsigned RegBits = getMachineOpValue(MI, MI.getOperand(OpNo),Fixups, STI) << 16; |
| 678 | unsigned OffBits = getMachineOpValue(MI, MI.getOperand(OpNo+1), Fixups, STI); |
Bruno Cardoso Lopes | c85e3ff | 2011-11-11 22:58:42 +0000 | [diff] [blame] | 679 | |
| 680 | return (OffBits & 0xFFFF) | RegBits; |
| 681 | } |
| 682 | |
Jack Carter | 9770097 | 2013-08-13 20:19:16 +0000 | [diff] [blame] | 683 | unsigned MipsMCCodeEmitter:: |
Jozef Kolek | e8c9d1e | 2014-11-24 14:39:13 +0000 | [diff] [blame] | 684 | getMemEncodingMMImm4(const MCInst &MI, unsigned OpNo, |
| 685 | SmallVectorImpl<MCFixup> &Fixups, |
| 686 | const MCSubtargetInfo &STI) const { |
| 687 | // Base register is encoded in bits 6-4, offset is encoded in bits 3-0. |
| 688 | assert(MI.getOperand(OpNo).isReg()); |
| 689 | unsigned RegBits = getMachineOpValue(MI, MI.getOperand(OpNo), |
| 690 | Fixups, STI) << 4; |
| 691 | unsigned OffBits = getMachineOpValue(MI, MI.getOperand(OpNo+1), |
| 692 | Fixups, STI); |
| 693 | |
| 694 | return (OffBits & 0xF) | RegBits; |
| 695 | } |
| 696 | |
| 697 | unsigned MipsMCCodeEmitter:: |
| 698 | getMemEncodingMMImm4Lsl1(const MCInst &MI, unsigned OpNo, |
| 699 | SmallVectorImpl<MCFixup> &Fixups, |
| 700 | const MCSubtargetInfo &STI) const { |
| 701 | // Base register is encoded in bits 6-4, offset is encoded in bits 3-0. |
| 702 | assert(MI.getOperand(OpNo).isReg()); |
| 703 | unsigned RegBits = getMachineOpValue(MI, MI.getOperand(OpNo), |
| 704 | Fixups, STI) << 4; |
| 705 | unsigned OffBits = getMachineOpValue(MI, MI.getOperand(OpNo+1), |
| 706 | Fixups, STI) >> 1; |
| 707 | |
| 708 | return (OffBits & 0xF) | RegBits; |
| 709 | } |
| 710 | |
| 711 | unsigned MipsMCCodeEmitter:: |
| 712 | getMemEncodingMMImm4Lsl2(const MCInst &MI, unsigned OpNo, |
| 713 | SmallVectorImpl<MCFixup> &Fixups, |
| 714 | const MCSubtargetInfo &STI) const { |
| 715 | // Base register is encoded in bits 6-4, offset is encoded in bits 3-0. |
| 716 | assert(MI.getOperand(OpNo).isReg()); |
| 717 | unsigned RegBits = getMachineOpValue(MI, MI.getOperand(OpNo), |
| 718 | Fixups, STI) << 4; |
| 719 | unsigned OffBits = getMachineOpValue(MI, MI.getOperand(OpNo+1), |
| 720 | Fixups, STI) >> 2; |
| 721 | |
| 722 | return (OffBits & 0xF) | RegBits; |
| 723 | } |
| 724 | |
| 725 | unsigned MipsMCCodeEmitter:: |
Jozef Kolek | 12c6982 | 2014-12-23 16:16:33 +0000 | [diff] [blame] | 726 | getMemEncodingMMSPImm5Lsl2(const MCInst &MI, unsigned OpNo, |
| 727 | SmallVectorImpl<MCFixup> &Fixups, |
| 728 | const MCSubtargetInfo &STI) const { |
| 729 | // Register is encoded in bits 9-5, offset is encoded in bits 4-0. |
| 730 | assert(MI.getOperand(OpNo).isReg() && |
| 731 | MI.getOperand(OpNo).getReg() == Mips::SP && |
| 732 | "Unexpected base register!"); |
| 733 | unsigned OffBits = getMachineOpValue(MI, MI.getOperand(OpNo+1), |
| 734 | Fixups, STI) >> 2; |
| 735 | |
| 736 | return OffBits & 0x1F; |
| 737 | } |
| 738 | |
| 739 | unsigned MipsMCCodeEmitter:: |
Jozef Kolek | e10a02e | 2015-01-28 17:27:26 +0000 | [diff] [blame] | 740 | getMemEncodingMMGPImm7Lsl2(const MCInst &MI, unsigned OpNo, |
| 741 | SmallVectorImpl<MCFixup> &Fixups, |
| 742 | const MCSubtargetInfo &STI) const { |
| 743 | // Register is encoded in bits 9-7, offset is encoded in bits 6-0. |
| 744 | assert(MI.getOperand(OpNo).isReg() && |
| 745 | MI.getOperand(OpNo).getReg() == Mips::GP && |
| 746 | "Unexpected base register!"); |
| 747 | |
| 748 | unsigned OffBits = getMachineOpValue(MI, MI.getOperand(OpNo+1), |
| 749 | Fixups, STI) >> 2; |
| 750 | |
| 751 | return OffBits & 0x7F; |
| 752 | } |
| 753 | |
| 754 | unsigned MipsMCCodeEmitter:: |
Jack Carter | 9770097 | 2013-08-13 20:19:16 +0000 | [diff] [blame] | 755 | getMemEncodingMMImm12(const MCInst &MI, unsigned OpNo, |
David Woodhouse | 3fa98a6 | 2014-01-28 23:13:18 +0000 | [diff] [blame] | 756 | SmallVectorImpl<MCFixup> &Fixups, |
| 757 | const MCSubtargetInfo &STI) const { |
Zoran Jovanovic | a4c4b5f | 2014-11-19 16:44:02 +0000 | [diff] [blame] | 758 | // opNum can be invalid if instruction had reglist as operand. |
| 759 | // MemOperand is always last operand of instruction (base + offset). |
| 760 | switch (MI.getOpcode()) { |
| 761 | default: |
| 762 | break; |
| 763 | case Mips::SWM32_MM: |
| 764 | case Mips::LWM32_MM: |
| 765 | OpNo = MI.getNumOperands() - 2; |
| 766 | break; |
| 767 | } |
| 768 | |
Jack Carter | 9770097 | 2013-08-13 20:19:16 +0000 | [diff] [blame] | 769 | // Base register is encoded in bits 20-16, offset is encoded in bits 11-0. |
| 770 | assert(MI.getOperand(OpNo).isReg()); |
David Woodhouse | 3fa98a6 | 2014-01-28 23:13:18 +0000 | [diff] [blame] | 771 | unsigned RegBits = getMachineOpValue(MI, MI.getOperand(OpNo), Fixups, STI) << 16; |
| 772 | unsigned OffBits = getMachineOpValue(MI, MI.getOperand(OpNo+1), Fixups, STI); |
Jack Carter | 9770097 | 2013-08-13 20:19:16 +0000 | [diff] [blame] | 773 | |
| 774 | return (OffBits & 0x0FFF) | RegBits; |
| 775 | } |
| 776 | |
Zoran Jovanovic | f9a0250 | 2014-11-27 18:28:59 +0000 | [diff] [blame] | 777 | unsigned MipsMCCodeEmitter:: |
| 778 | getMemEncodingMMImm4sp(const MCInst &MI, unsigned OpNo, |
| 779 | SmallVectorImpl<MCFixup> &Fixups, |
| 780 | const MCSubtargetInfo &STI) const { |
| 781 | // opNum can be invalid if instruction had reglist as operand |
| 782 | // MemOperand is always last operand of instruction (base + offset) |
| 783 | switch (MI.getOpcode()) { |
| 784 | default: |
| 785 | break; |
| 786 | case Mips::SWM16_MM: |
| 787 | case Mips::LWM16_MM: |
| 788 | OpNo = MI.getNumOperands() - 2; |
| 789 | break; |
| 790 | } |
| 791 | |
| 792 | // Offset is encoded in bits 4-0. |
| 793 | assert(MI.getOperand(OpNo).isReg()); |
| 794 | // Base register is always SP - thus it is not encoded. |
| 795 | assert(MI.getOperand(OpNo+1).isImm()); |
| 796 | unsigned OffBits = getMachineOpValue(MI, MI.getOperand(OpNo+1), Fixups, STI); |
| 797 | |
| 798 | return ((OffBits >> 2) & 0x0F); |
| 799 | } |
| 800 | |
Bruno Cardoso Lopes | c85e3ff | 2011-11-11 22:58:42 +0000 | [diff] [blame] | 801 | unsigned |
| 802 | MipsMCCodeEmitter::getSizeExtEncoding(const MCInst &MI, unsigned OpNo, |
David Woodhouse | 3fa98a6 | 2014-01-28 23:13:18 +0000 | [diff] [blame] | 803 | SmallVectorImpl<MCFixup> &Fixups, |
| 804 | const MCSubtargetInfo &STI) const { |
Akira Hatanaka | 049e9e4 | 2011-11-23 22:19:28 +0000 | [diff] [blame] | 805 | assert(MI.getOperand(OpNo).isImm()); |
David Woodhouse | 3fa98a6 | 2014-01-28 23:13:18 +0000 | [diff] [blame] | 806 | unsigned SizeEncoding = getMachineOpValue(MI, MI.getOperand(OpNo), Fixups, STI); |
Bruno Cardoso Lopes | 56b70de | 2011-12-07 22:35:30 +0000 | [diff] [blame] | 807 | return SizeEncoding - 1; |
Bruno Cardoso Lopes | c85e3ff | 2011-11-11 22:58:42 +0000 | [diff] [blame] | 808 | } |
| 809 | |
Akira Hatanaka | 049e9e4 | 2011-11-23 22:19:28 +0000 | [diff] [blame] | 810 | // FIXME: should be called getMSBEncoding |
| 811 | // |
Bruno Cardoso Lopes | c85e3ff | 2011-11-11 22:58:42 +0000 | [diff] [blame] | 812 | unsigned |
| 813 | MipsMCCodeEmitter::getSizeInsEncoding(const MCInst &MI, unsigned OpNo, |
David Woodhouse | 3fa98a6 | 2014-01-28 23:13:18 +0000 | [diff] [blame] | 814 | SmallVectorImpl<MCFixup> &Fixups, |
| 815 | const MCSubtargetInfo &STI) const { |
Akira Hatanaka | 049e9e4 | 2011-11-23 22:19:28 +0000 | [diff] [blame] | 816 | assert(MI.getOperand(OpNo-1).isImm()); |
| 817 | assert(MI.getOperand(OpNo).isImm()); |
David Woodhouse | 3fa98a6 | 2014-01-28 23:13:18 +0000 | [diff] [blame] | 818 | unsigned Position = getMachineOpValue(MI, MI.getOperand(OpNo-1), Fixups, STI); |
| 819 | unsigned Size = getMachineOpValue(MI, MI.getOperand(OpNo), Fixups, STI); |
Akira Hatanaka | 049e9e4 | 2011-11-23 22:19:28 +0000 | [diff] [blame] | 820 | |
Bruno Cardoso Lopes | 56b70de | 2011-12-07 22:35:30 +0000 | [diff] [blame] | 821 | return Position + Size - 1; |
Bruno Cardoso Lopes | c85e3ff | 2011-11-11 22:58:42 +0000 | [diff] [blame] | 822 | } |
| 823 | |
Matheus Almeida | 779c593 | 2013-11-18 12:32:49 +0000 | [diff] [blame] | 824 | unsigned |
| 825 | MipsMCCodeEmitter::getLSAImmEncoding(const MCInst &MI, unsigned OpNo, |
David Woodhouse | 3fa98a6 | 2014-01-28 23:13:18 +0000 | [diff] [blame] | 826 | SmallVectorImpl<MCFixup> &Fixups, |
| 827 | const MCSubtargetInfo &STI) const { |
Matheus Almeida | 779c593 | 2013-11-18 12:32:49 +0000 | [diff] [blame] | 828 | assert(MI.getOperand(OpNo).isImm()); |
| 829 | // The immediate is encoded as 'immediate - 1'. |
David Woodhouse | 3fa98a6 | 2014-01-28 23:13:18 +0000 | [diff] [blame] | 830 | return getMachineOpValue(MI, MI.getOperand(OpNo), Fixups, STI) - 1; |
Matheus Almeida | 779c593 | 2013-11-18 12:32:49 +0000 | [diff] [blame] | 831 | } |
| 832 | |
Daniel Sanders | b59e1a4 | 2014-05-15 10:45:58 +0000 | [diff] [blame] | 833 | unsigned |
| 834 | MipsMCCodeEmitter::getSimm19Lsl2Encoding(const MCInst &MI, unsigned OpNo, |
| 835 | SmallVectorImpl<MCFixup> &Fixups, |
| 836 | const MCSubtargetInfo &STI) const { |
Zoran Jovanovic | b9c07f3 | 2014-06-12 12:40:00 +0000 | [diff] [blame] | 837 | const MCOperand &MO = MI.getOperand(OpNo); |
| 838 | if (MO.isImm()) { |
| 839 | // The immediate is encoded as 'immediate << 2'. |
| 840 | unsigned Res = getMachineOpValue(MI, MO, Fixups, STI); |
| 841 | assert((Res & 3) == 0); |
| 842 | return Res >> 2; |
| 843 | } |
| 844 | |
| 845 | assert(MO.isExpr() && |
| 846 | "getSimm19Lsl2Encoding expects only expressions or an immediate"); |
| 847 | |
| 848 | const MCExpr *Expr = MO.getExpr(); |
| 849 | Fixups.push_back(MCFixup::Create(0, Expr, |
| 850 | MCFixupKind(Mips::fixup_MIPS_PC19_S2))); |
| 851 | return 0; |
Daniel Sanders | b59e1a4 | 2014-05-15 10:45:58 +0000 | [diff] [blame] | 852 | } |
Bruno Cardoso Lopes | c85e3ff | 2011-11-11 22:58:42 +0000 | [diff] [blame] | 853 | |
Zoran Jovanovic | 2855142 | 2014-06-09 09:49:51 +0000 | [diff] [blame] | 854 | unsigned |
| 855 | MipsMCCodeEmitter::getSimm18Lsl3Encoding(const MCInst &MI, unsigned OpNo, |
| 856 | SmallVectorImpl<MCFixup> &Fixups, |
| 857 | const MCSubtargetInfo &STI) const { |
Zoran Jovanovic | a5acdcf | 2014-06-13 14:26:47 +0000 | [diff] [blame] | 858 | const MCOperand &MO = MI.getOperand(OpNo); |
| 859 | if (MO.isImm()) { |
| 860 | // The immediate is encoded as 'immediate << 3'. |
| 861 | unsigned Res = getMachineOpValue(MI, MI.getOperand(OpNo), Fixups, STI); |
| 862 | assert((Res & 7) == 0); |
| 863 | return Res >> 3; |
| 864 | } |
| 865 | |
| 866 | assert(MO.isExpr() && |
| 867 | "getSimm18Lsl2Encoding expects only expressions or an immediate"); |
| 868 | |
| 869 | const MCExpr *Expr = MO.getExpr(); |
| 870 | Fixups.push_back(MCFixup::Create(0, Expr, |
| 871 | MCFixupKind(Mips::fixup_MIPS_PC18_S3))); |
| 872 | return 0; |
Zoran Jovanovic | 2855142 | 2014-06-09 09:49:51 +0000 | [diff] [blame] | 873 | } |
| 874 | |
Zoran Jovanovic | 4a00fdc | 2014-10-23 10:42:01 +0000 | [diff] [blame] | 875 | unsigned |
| 876 | MipsMCCodeEmitter::getUImm3Mod8Encoding(const MCInst &MI, unsigned OpNo, |
| 877 | SmallVectorImpl<MCFixup> &Fixups, |
| 878 | const MCSubtargetInfo &STI) const { |
| 879 | assert(MI.getOperand(OpNo).isImm()); |
| 880 | const MCOperand &MO = MI.getOperand(OpNo); |
| 881 | return MO.getImm() % 8; |
| 882 | } |
| 883 | |
Zoran Jovanovic | 8853171 | 2014-11-05 17:31:00 +0000 | [diff] [blame] | 884 | unsigned |
| 885 | MipsMCCodeEmitter::getUImm4AndValue(const MCInst &MI, unsigned OpNo, |
| 886 | SmallVectorImpl<MCFixup> &Fixups, |
| 887 | const MCSubtargetInfo &STI) const { |
| 888 | assert(MI.getOperand(OpNo).isImm()); |
| 889 | const MCOperand &MO = MI.getOperand(OpNo); |
| 890 | unsigned Value = MO.getImm(); |
| 891 | switch (Value) { |
| 892 | case 128: return 0x0; |
| 893 | case 1: return 0x1; |
| 894 | case 2: return 0x2; |
| 895 | case 3: return 0x3; |
| 896 | case 4: return 0x4; |
| 897 | case 7: return 0x5; |
| 898 | case 8: return 0x6; |
| 899 | case 15: return 0x7; |
| 900 | case 16: return 0x8; |
| 901 | case 31: return 0x9; |
| 902 | case 32: return 0xa; |
| 903 | case 63: return 0xb; |
| 904 | case 64: return 0xc; |
| 905 | case 255: return 0xd; |
| 906 | case 32768: return 0xe; |
| 907 | case 65535: return 0xf; |
| 908 | } |
| 909 | llvm_unreachable("Unexpected value"); |
| 910 | } |
| 911 | |
Zoran Jovanovic | a4c4b5f | 2014-11-19 16:44:02 +0000 | [diff] [blame] | 912 | unsigned |
| 913 | MipsMCCodeEmitter::getRegisterListOpValue(const MCInst &MI, unsigned OpNo, |
| 914 | SmallVectorImpl<MCFixup> &Fixups, |
| 915 | const MCSubtargetInfo &STI) const { |
| 916 | unsigned res = 0; |
| 917 | |
| 918 | // Register list operand is always first operand of instruction and it is |
| 919 | // placed before memory operand (register + imm). |
| 920 | |
| 921 | for (unsigned I = OpNo, E = MI.getNumOperands() - 2; I < E; ++I) { |
| 922 | unsigned Reg = MI.getOperand(I).getReg(); |
| 923 | unsigned RegNo = Ctx.getRegisterInfo()->getEncodingValue(Reg); |
| 924 | if (RegNo != 31) |
| 925 | res++; |
| 926 | else |
| 927 | res |= 0x10; |
| 928 | } |
| 929 | return res; |
| 930 | } |
| 931 | |
Zoran Jovanovic | f9a0250 | 2014-11-27 18:28:59 +0000 | [diff] [blame] | 932 | unsigned |
| 933 | MipsMCCodeEmitter::getRegisterListOpValue16(const MCInst &MI, unsigned OpNo, |
| 934 | SmallVectorImpl<MCFixup> &Fixups, |
| 935 | const MCSubtargetInfo &STI) const { |
| 936 | return (MI.getNumOperands() - 4); |
| 937 | } |
| 938 | |
Zoran Jovanovic | 2deca34 | 2014-12-16 14:59:10 +0000 | [diff] [blame] | 939 | unsigned |
| 940 | MipsMCCodeEmitter::getRegisterPairOpValue(const MCInst &MI, unsigned OpNo, |
| 941 | SmallVectorImpl<MCFixup> &Fixups, |
| 942 | const MCSubtargetInfo &STI) const { |
| 943 | return getMachineOpValue(MI, MI.getOperand(OpNo), Fixups, STI); |
| 944 | } |
| 945 | |
Jozef Kolek | 2c6d732 | 2015-01-21 12:10:11 +0000 | [diff] [blame] | 946 | unsigned |
Zoran Jovanovic | 4168867 | 2015-02-10 16:36:20 +0000 | [diff] [blame] | 947 | MipsMCCodeEmitter::getMovePRegPairOpValue(const MCInst &MI, unsigned OpNo, |
| 948 | SmallVectorImpl<MCFixup> &Fixups, |
| 949 | const MCSubtargetInfo &STI) const { |
| 950 | unsigned res = 0; |
| 951 | |
| 952 | if (MI.getOperand(0).getReg() == Mips::A1 && |
| 953 | MI.getOperand(1).getReg() == Mips::A2) |
| 954 | res = 0; |
| 955 | else if (MI.getOperand(0).getReg() == Mips::A1 && |
| 956 | MI.getOperand(1).getReg() == Mips::A3) |
| 957 | res = 1; |
| 958 | else if (MI.getOperand(0).getReg() == Mips::A2 && |
| 959 | MI.getOperand(1).getReg() == Mips::A3) |
| 960 | res = 2; |
| 961 | else if (MI.getOperand(0).getReg() == Mips::A0 && |
| 962 | MI.getOperand(1).getReg() == Mips::S5) |
| 963 | res = 3; |
| 964 | else if (MI.getOperand(0).getReg() == Mips::A0 && |
| 965 | MI.getOperand(1).getReg() == Mips::S6) |
| 966 | res = 4; |
| 967 | else if (MI.getOperand(0).getReg() == Mips::A0 && |
| 968 | MI.getOperand(1).getReg() == Mips::A1) |
| 969 | res = 5; |
| 970 | else if (MI.getOperand(0).getReg() == Mips::A0 && |
| 971 | MI.getOperand(1).getReg() == Mips::A2) |
| 972 | res = 6; |
| 973 | else if (MI.getOperand(0).getReg() == Mips::A0 && |
| 974 | MI.getOperand(1).getReg() == Mips::A3) |
| 975 | res = 7; |
| 976 | |
| 977 | return res; |
| 978 | } |
| 979 | |
| 980 | unsigned |
Jozef Kolek | 2c6d732 | 2015-01-21 12:10:11 +0000 | [diff] [blame] | 981 | MipsMCCodeEmitter::getSimm23Lsl2Encoding(const MCInst &MI, unsigned OpNo, |
| 982 | SmallVectorImpl<MCFixup> &Fixups, |
| 983 | const MCSubtargetInfo &STI) const { |
| 984 | const MCOperand &MO = MI.getOperand(OpNo); |
| 985 | assert(MO.isImm() && "getSimm23Lsl2Encoding expects only an immediate"); |
| 986 | // The immediate is encoded as 'immediate >> 2'. |
| 987 | unsigned Res = static_cast<unsigned>(MO.getImm()); |
| 988 | assert((Res & 3) == 0); |
| 989 | return Res >> 2; |
| 990 | } |
| 991 | |
Daniel Sanders | b59e1a4 | 2014-05-15 10:45:58 +0000 | [diff] [blame] | 992 | #include "MipsGenMCCodeEmitter.inc" |