Chris Lattner | 9ec375c | 2010-11-15 04:16:32 +0000 | [diff] [blame] | 1 | //===-- PPCMCCodeEmitter.cpp - Convert PPC code to machine code -----------===// |
| 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 PPCMCCodeEmitter class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #define DEBUG_TYPE "mccodeemitter" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 15 | #include "MCTargetDesc/PPCMCTargetDesc.h" |
Evan Cheng | 61d4a20 | 2011-07-25 19:53:23 +0000 | [diff] [blame] | 16 | #include "MCTargetDesc/PPCFixupKinds.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/Statistic.h" |
Chris Lattner | 9ec375c | 2010-11-15 04:16:32 +0000 | [diff] [blame] | 18 | #include "llvm/MC/MCCodeEmitter.h" |
Hal Finkel | feea653 | 2013-03-26 20:08:20 +0000 | [diff] [blame] | 19 | #include "llvm/MC/MCContext.h" |
Bill Schmidt | c56f1d3 | 2012-12-11 20:30:11 +0000 | [diff] [blame] | 20 | #include "llvm/MC/MCExpr.h" |
Chris Lattner | 9ec375c | 2010-11-15 04:16:32 +0000 | [diff] [blame] | 21 | #include "llvm/MC/MCInst.h" |
Adhemerval Zanella | f2aceda | 2012-10-25 12:27:42 +0000 | [diff] [blame] | 22 | #include "llvm/MC/MCInstrInfo.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 23 | #include "llvm/MC/MCSubtargetInfo.h" |
Chris Lattner | 9ec375c | 2010-11-15 04:16:32 +0000 | [diff] [blame] | 24 | #include "llvm/Support/ErrorHandling.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 25 | #include "llvm/Support/raw_ostream.h" |
Bill Schmidt | c763c22 | 2013-09-16 17:25:12 +0000 | [diff] [blame^] | 26 | #include "llvm/Target/TargetOpcodes.h" |
Chris Lattner | 9ec375c | 2010-11-15 04:16:32 +0000 | [diff] [blame] | 27 | using namespace llvm; |
| 28 | |
| 29 | STATISTIC(MCNumEmitted, "Number of MC instructions emitted"); |
| 30 | |
| 31 | namespace { |
| 32 | class PPCMCCodeEmitter : public MCCodeEmitter { |
Craig Topper | a60c0f1 | 2012-09-15 17:09:36 +0000 | [diff] [blame] | 33 | PPCMCCodeEmitter(const PPCMCCodeEmitter &) LLVM_DELETED_FUNCTION; |
| 34 | void operator=(const PPCMCCodeEmitter &) LLVM_DELETED_FUNCTION; |
| 35 | |
Adhemerval Zanella | f2aceda | 2012-10-25 12:27:42 +0000 | [diff] [blame] | 36 | const MCSubtargetInfo &STI; |
Hal Finkel | feea653 | 2013-03-26 20:08:20 +0000 | [diff] [blame] | 37 | const MCContext &CTX; |
Adhemerval Zanella | f2aceda | 2012-10-25 12:27:42 +0000 | [diff] [blame] | 38 | Triple TT; |
| 39 | |
Chris Lattner | 9ec375c | 2010-11-15 04:16:32 +0000 | [diff] [blame] | 40 | public: |
Evan Cheng | c5e6d2f | 2011-07-11 03:57:24 +0000 | [diff] [blame] | 41 | PPCMCCodeEmitter(const MCInstrInfo &mcii, const MCSubtargetInfo &sti, |
Adhemerval Zanella | f2aceda | 2012-10-25 12:27:42 +0000 | [diff] [blame] | 42 | MCContext &ctx) |
Hal Finkel | feea653 | 2013-03-26 20:08:20 +0000 | [diff] [blame] | 43 | : STI(sti), CTX(ctx), TT(STI.getTargetTriple()) { |
Chris Lattner | 9ec375c | 2010-11-15 04:16:32 +0000 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | ~PPCMCCodeEmitter() {} |
Chris Lattner | d6a07cc | 2010-11-15 05:19:25 +0000 | [diff] [blame] | 47 | |
Chris Lattner | 0e3461e | 2010-11-15 06:09:35 +0000 | [diff] [blame] | 48 | unsigned getDirectBrEncoding(const MCInst &MI, unsigned OpNo, |
| 49 | SmallVectorImpl<MCFixup> &Fixups) const; |
Chris Lattner | 0e3461e | 2010-11-15 06:09:35 +0000 | [diff] [blame] | 50 | unsigned getCondBrEncoding(const MCInst &MI, unsigned OpNo, |
| 51 | SmallVectorImpl<MCFixup> &Fixups) const; |
Ulrich Weigand | b6a30d1 | 2013-06-24 11:03:33 +0000 | [diff] [blame] | 52 | unsigned getAbsDirectBrEncoding(const MCInst &MI, unsigned OpNo, |
| 53 | SmallVectorImpl<MCFixup> &Fixups) const; |
| 54 | unsigned getAbsCondBrEncoding(const MCInst &MI, unsigned OpNo, |
| 55 | SmallVectorImpl<MCFixup> &Fixups) const; |
Ulrich Weigand | fd3ad69 | 2013-06-26 13:49:15 +0000 | [diff] [blame] | 56 | unsigned getImm16Encoding(const MCInst &MI, unsigned OpNo, |
Ulrich Weigand | 2dbe06a | 2013-05-17 14:14:12 +0000 | [diff] [blame] | 57 | SmallVectorImpl<MCFixup> &Fixups) const; |
Chris Lattner | efacb9e | 2010-11-15 08:22:03 +0000 | [diff] [blame] | 58 | unsigned getMemRIEncoding(const MCInst &MI, unsigned OpNo, |
| 59 | SmallVectorImpl<MCFixup> &Fixups) const; |
Chris Lattner | 8f4444d | 2010-11-15 08:02:41 +0000 | [diff] [blame] | 60 | unsigned getMemRIXEncoding(const MCInst &MI, unsigned OpNo, |
| 61 | SmallVectorImpl<MCFixup> &Fixups) const; |
Bill Schmidt | ca4a0c9 | 2012-12-04 16:18:08 +0000 | [diff] [blame] | 62 | unsigned getTLSRegEncoding(const MCInst &MI, unsigned OpNo, |
| 63 | SmallVectorImpl<MCFixup> &Fixups) const; |
Ulrich Weigand | 5143bab | 2013-07-02 21:31:04 +0000 | [diff] [blame] | 64 | unsigned getTLSCallEncoding(const MCInst &MI, unsigned OpNo, |
| 65 | SmallVectorImpl<MCFixup> &Fixups) const; |
Chris Lattner | d6a07cc | 2010-11-15 05:19:25 +0000 | [diff] [blame] | 66 | unsigned get_crbitm_encoding(const MCInst &MI, unsigned OpNo, |
| 67 | SmallVectorImpl<MCFixup> &Fixups) const; |
| 68 | |
Chris Lattner | 9ec375c | 2010-11-15 04:16:32 +0000 | [diff] [blame] | 69 | /// getMachineOpValue - Return binary encoding of operand. If the machine |
| 70 | /// operand requires relocation, record the relocation and return zero. |
| 71 | unsigned getMachineOpValue(const MCInst &MI,const MCOperand &MO, |
| 72 | SmallVectorImpl<MCFixup> &Fixups) const; |
Chris Lattner | 9ec375c | 2010-11-15 04:16:32 +0000 | [diff] [blame] | 73 | |
| 74 | // getBinaryCodeForInstr - TableGen'erated function for getting the |
| 75 | // binary encoding for an instruction. |
Owen Anderson | d845d9d | 2012-01-24 18:37:29 +0000 | [diff] [blame] | 76 | uint64_t getBinaryCodeForInstr(const MCInst &MI, |
Chris Lattner | 9ec375c | 2010-11-15 04:16:32 +0000 | [diff] [blame] | 77 | SmallVectorImpl<MCFixup> &Fixups) const; |
| 78 | void EncodeInstruction(const MCInst &MI, raw_ostream &OS, |
| 79 | SmallVectorImpl<MCFixup> &Fixups) const { |
Bill Schmidt | c763c22 | 2013-09-16 17:25:12 +0000 | [diff] [blame^] | 80 | // For fast-isel, a float COPY_TO_REGCLASS can survive this long. |
| 81 | // It's just a nop to keep the register classes happy, so don't |
| 82 | // generate anything. |
| 83 | unsigned Opcode = MI.getOpcode(); |
| 84 | if (Opcode == TargetOpcode::COPY_TO_REGCLASS) |
| 85 | return; |
| 86 | |
Adhemerval Zanella | 1be10dc | 2012-10-25 14:29:13 +0000 | [diff] [blame] | 87 | uint64_t Bits = getBinaryCodeForInstr(MI, Fixups); |
| 88 | |
Ulrich Weigand | f62e83f | 2013-03-22 15:24:13 +0000 | [diff] [blame] | 89 | // BL8_NOP etc. all have a size of 8 because of the following 'nop'. |
Adhemerval Zanella | 1be10dc | 2012-10-25 14:29:13 +0000 | [diff] [blame] | 90 | unsigned Size = 4; // FIXME: Have Desc.getSize() return the correct value! |
Ulrich Weigand | f62e83f | 2013-03-22 15:24:13 +0000 | [diff] [blame] | 91 | if (Opcode == PPC::BL8_NOP || Opcode == PPC::BLA8_NOP || |
Ulrich Weigand | 5143bab | 2013-07-02 21:31:04 +0000 | [diff] [blame] | 92 | Opcode == PPC::BL8_NOP_TLS) |
Adhemerval Zanella | 1be10dc | 2012-10-25 14:29:13 +0000 | [diff] [blame] | 93 | Size = 8; |
Chris Lattner | 9ec375c | 2010-11-15 04:16:32 +0000 | [diff] [blame] | 94 | |
| 95 | // Output the constant in big endian byte order. |
Adhemerval Zanella | 1be10dc | 2012-10-25 14:29:13 +0000 | [diff] [blame] | 96 | int ShiftValue = (Size * 8) - 8; |
| 97 | for (unsigned i = 0; i != Size; ++i) { |
| 98 | OS << (char)(Bits >> ShiftValue); |
Chris Lattner | 9ec375c | 2010-11-15 04:16:32 +0000 | [diff] [blame] | 99 | Bits <<= 8; |
| 100 | } |
| 101 | |
| 102 | ++MCNumEmitted; // Keep track of the # of mi's emitted. |
| 103 | } |
| 104 | |
| 105 | }; |
| 106 | |
| 107 | } // end anonymous namespace |
| 108 | |
Evan Cheng | c5e6d2f | 2011-07-11 03:57:24 +0000 | [diff] [blame] | 109 | MCCodeEmitter *llvm::createPPCMCCodeEmitter(const MCInstrInfo &MCII, |
Jim Grosbach | c3b0427 | 2012-05-15 17:35:52 +0000 | [diff] [blame] | 110 | const MCRegisterInfo &MRI, |
Evan Cheng | c5e6d2f | 2011-07-11 03:57:24 +0000 | [diff] [blame] | 111 | const MCSubtargetInfo &STI, |
Chris Lattner | 9ec375c | 2010-11-15 04:16:32 +0000 | [diff] [blame] | 112 | MCContext &Ctx) { |
Evan Cheng | c5e6d2f | 2011-07-11 03:57:24 +0000 | [diff] [blame] | 113 | return new PPCMCCodeEmitter(MCII, STI, Ctx); |
Chris Lattner | 9ec375c | 2010-11-15 04:16:32 +0000 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | unsigned PPCMCCodeEmitter:: |
Chris Lattner | 0e3461e | 2010-11-15 06:09:35 +0000 | [diff] [blame] | 117 | getDirectBrEncoding(const MCInst &MI, unsigned OpNo, |
| 118 | SmallVectorImpl<MCFixup> &Fixups) const { |
Chris Lattner | 79fa371 | 2010-11-15 05:57:53 +0000 | [diff] [blame] | 119 | const MCOperand &MO = MI.getOperand(OpNo); |
| 120 | if (MO.isReg() || MO.isImm()) return getMachineOpValue(MI, MO, Fixups); |
| 121 | |
| 122 | // Add a fixup for the branch target. |
| 123 | Fixups.push_back(MCFixup::Create(0, MO.getExpr(), |
| 124 | (MCFixupKind)PPC::fixup_ppc_br24)); |
| 125 | return 0; |
| 126 | } |
| 127 | |
Chris Lattner | 0e3461e | 2010-11-15 06:09:35 +0000 | [diff] [blame] | 128 | unsigned PPCMCCodeEmitter::getCondBrEncoding(const MCInst &MI, unsigned OpNo, |
| 129 | SmallVectorImpl<MCFixup> &Fixups) const { |
| 130 | const MCOperand &MO = MI.getOperand(OpNo); |
| 131 | if (MO.isReg() || MO.isImm()) return getMachineOpValue(MI, MO, Fixups); |
| 132 | |
Chris Lattner | 85e3768 | 2010-11-15 06:12:22 +0000 | [diff] [blame] | 133 | // Add a fixup for the branch target. |
| 134 | Fixups.push_back(MCFixup::Create(0, MO.getExpr(), |
| 135 | (MCFixupKind)PPC::fixup_ppc_brcond14)); |
Chris Lattner | 0e3461e | 2010-11-15 06:09:35 +0000 | [diff] [blame] | 136 | return 0; |
| 137 | } |
| 138 | |
Ulrich Weigand | b6a30d1 | 2013-06-24 11:03:33 +0000 | [diff] [blame] | 139 | unsigned PPCMCCodeEmitter:: |
| 140 | getAbsDirectBrEncoding(const MCInst &MI, unsigned OpNo, |
| 141 | SmallVectorImpl<MCFixup> &Fixups) const { |
| 142 | const MCOperand &MO = MI.getOperand(OpNo); |
| 143 | if (MO.isReg() || MO.isImm()) return getMachineOpValue(MI, MO, Fixups); |
| 144 | |
| 145 | // Add a fixup for the branch target. |
| 146 | Fixups.push_back(MCFixup::Create(0, MO.getExpr(), |
| 147 | (MCFixupKind)PPC::fixup_ppc_br24abs)); |
| 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | unsigned PPCMCCodeEmitter:: |
| 152 | getAbsCondBrEncoding(const MCInst &MI, unsigned OpNo, |
| 153 | SmallVectorImpl<MCFixup> &Fixups) const { |
| 154 | const MCOperand &MO = MI.getOperand(OpNo); |
| 155 | if (MO.isReg() || MO.isImm()) return getMachineOpValue(MI, MO, Fixups); |
| 156 | |
| 157 | // Add a fixup for the branch target. |
| 158 | Fixups.push_back(MCFixup::Create(0, MO.getExpr(), |
| 159 | (MCFixupKind)PPC::fixup_ppc_brcond14abs)); |
| 160 | return 0; |
| 161 | } |
| 162 | |
Ulrich Weigand | fd3ad69 | 2013-06-26 13:49:15 +0000 | [diff] [blame] | 163 | unsigned PPCMCCodeEmitter::getImm16Encoding(const MCInst &MI, unsigned OpNo, |
Chris Lattner | 6566112 | 2010-11-15 06:33:39 +0000 | [diff] [blame] | 164 | SmallVectorImpl<MCFixup> &Fixups) const { |
| 165 | const MCOperand &MO = MI.getOperand(OpNo); |
| 166 | if (MO.isReg() || MO.isImm()) return getMachineOpValue(MI, MO, Fixups); |
| 167 | |
Ulrich Weigand | fd3ad69 | 2013-06-26 13:49:15 +0000 | [diff] [blame] | 168 | // Add a fixup for the immediate field. |
Ulrich Weigand | 2fb140e | 2013-05-15 15:07:06 +0000 | [diff] [blame] | 169 | Fixups.push_back(MCFixup::Create(2, MO.getExpr(), |
Ulrich Weigand | 6e23ac6 | 2013-05-17 12:37:21 +0000 | [diff] [blame] | 170 | (MCFixupKind)PPC::fixup_ppc_half16)); |
Chris Lattner | 6566112 | 2010-11-15 06:33:39 +0000 | [diff] [blame] | 171 | return 0; |
| 172 | } |
| 173 | |
Chris Lattner | efacb9e | 2010-11-15 08:22:03 +0000 | [diff] [blame] | 174 | unsigned PPCMCCodeEmitter::getMemRIEncoding(const MCInst &MI, unsigned OpNo, |
| 175 | SmallVectorImpl<MCFixup> &Fixups) const { |
| 176 | // Encode (imm, reg) as a memri, which has the low 16-bits as the |
| 177 | // displacement and the next 5 bits as the register #. |
| 178 | assert(MI.getOperand(OpNo+1).isReg()); |
| 179 | unsigned RegBits = getMachineOpValue(MI, MI.getOperand(OpNo+1), Fixups) << 16; |
| 180 | |
| 181 | const MCOperand &MO = MI.getOperand(OpNo); |
| 182 | if (MO.isImm()) |
| 183 | return (getMachineOpValue(MI, MO, Fixups) & 0xFFFF) | RegBits; |
| 184 | |
| 185 | // Add a fixup for the displacement field. |
Ulrich Weigand | 2fb140e | 2013-05-15 15:07:06 +0000 | [diff] [blame] | 186 | Fixups.push_back(MCFixup::Create(2, MO.getExpr(), |
Ulrich Weigand | 6e23ac6 | 2013-05-17 12:37:21 +0000 | [diff] [blame] | 187 | (MCFixupKind)PPC::fixup_ppc_half16)); |
Chris Lattner | efacb9e | 2010-11-15 08:22:03 +0000 | [diff] [blame] | 188 | return RegBits; |
| 189 | } |
| 190 | |
| 191 | |
Chris Lattner | 8f4444d | 2010-11-15 08:02:41 +0000 | [diff] [blame] | 192 | unsigned PPCMCCodeEmitter::getMemRIXEncoding(const MCInst &MI, unsigned OpNo, |
Chris Lattner | 6566112 | 2010-11-15 06:33:39 +0000 | [diff] [blame] | 193 | SmallVectorImpl<MCFixup> &Fixups) const { |
Chris Lattner | 8f4444d | 2010-11-15 08:02:41 +0000 | [diff] [blame] | 194 | // Encode (imm, reg) as a memrix, which has the low 14-bits as the |
| 195 | // displacement and the next 5 bits as the register #. |
Chris Lattner | efacb9e | 2010-11-15 08:22:03 +0000 | [diff] [blame] | 196 | assert(MI.getOperand(OpNo+1).isReg()); |
Chris Lattner | 8f4444d | 2010-11-15 08:02:41 +0000 | [diff] [blame] | 197 | unsigned RegBits = getMachineOpValue(MI, MI.getOperand(OpNo+1), Fixups) << 14; |
| 198 | |
Chris Lattner | 6566112 | 2010-11-15 06:33:39 +0000 | [diff] [blame] | 199 | const MCOperand &MO = MI.getOperand(OpNo); |
Chris Lattner | 8f4444d | 2010-11-15 08:02:41 +0000 | [diff] [blame] | 200 | if (MO.isImm()) |
Ulrich Weigand | 9d980cb | 2013-05-16 17:58:02 +0000 | [diff] [blame] | 201 | return ((getMachineOpValue(MI, MO, Fixups) >> 2) & 0x3FFF) | RegBits; |
Chris Lattner | 6566112 | 2010-11-15 06:33:39 +0000 | [diff] [blame] | 202 | |
Ulrich Weigand | 3e18601 | 2013-03-26 10:56:47 +0000 | [diff] [blame] | 203 | // Add a fixup for the displacement field. |
Ulrich Weigand | 2fb140e | 2013-05-15 15:07:06 +0000 | [diff] [blame] | 204 | Fixups.push_back(MCFixup::Create(2, MO.getExpr(), |
Ulrich Weigand | 6e23ac6 | 2013-05-17 12:37:21 +0000 | [diff] [blame] | 205 | (MCFixupKind)PPC::fixup_ppc_half16ds)); |
Chris Lattner | 8f4444d | 2010-11-15 08:02:41 +0000 | [diff] [blame] | 206 | return RegBits; |
Chris Lattner | 6566112 | 2010-11-15 06:33:39 +0000 | [diff] [blame] | 207 | } |
| 208 | |
Chris Lattner | 0e3461e | 2010-11-15 06:09:35 +0000 | [diff] [blame] | 209 | |
Bill Schmidt | ca4a0c9 | 2012-12-04 16:18:08 +0000 | [diff] [blame] | 210 | unsigned PPCMCCodeEmitter::getTLSRegEncoding(const MCInst &MI, unsigned OpNo, |
| 211 | SmallVectorImpl<MCFixup> &Fixups) const { |
| 212 | const MCOperand &MO = MI.getOperand(OpNo); |
| 213 | if (MO.isReg()) return getMachineOpValue(MI, MO, Fixups); |
| 214 | |
| 215 | // Add a fixup for the TLS register, which simply provides a relocation |
| 216 | // hint to the linker that this statement is part of a relocation sequence. |
| 217 | // Return the thread-pointer register's encoding. |
| 218 | Fixups.push_back(MCFixup::Create(0, MO.getExpr(), |
Ulrich Weigand | 5b42759 | 2013-07-05 12:22:36 +0000 | [diff] [blame] | 219 | (MCFixupKind)PPC::fixup_ppc_nofixup)); |
Bill Wendling | bc07a89 | 2013-06-18 07:20:20 +0000 | [diff] [blame] | 220 | return CTX.getRegisterInfo()->getEncodingValue(PPC::X13); |
Bill Schmidt | ca4a0c9 | 2012-12-04 16:18:08 +0000 | [diff] [blame] | 221 | } |
| 222 | |
Ulrich Weigand | 5143bab | 2013-07-02 21:31:04 +0000 | [diff] [blame] | 223 | unsigned PPCMCCodeEmitter::getTLSCallEncoding(const MCInst &MI, unsigned OpNo, |
| 224 | SmallVectorImpl<MCFixup> &Fixups) const { |
| 225 | // For special TLS calls, we need two fixups; one for the branch target |
| 226 | // (__tls_get_addr), which we create via getDirectBrEncoding as usual, |
| 227 | // and one for the TLSGD or TLSLD symbol, which is emitted here. |
| 228 | const MCOperand &MO = MI.getOperand(OpNo+1); |
| 229 | Fixups.push_back(MCFixup::Create(0, MO.getExpr(), |
| 230 | (MCFixupKind)PPC::fixup_ppc_nofixup)); |
| 231 | return getDirectBrEncoding(MI, OpNo, Fixups); |
| 232 | } |
| 233 | |
Chris Lattner | 79fa371 | 2010-11-15 05:57:53 +0000 | [diff] [blame] | 234 | unsigned PPCMCCodeEmitter:: |
Chris Lattner | d6a07cc | 2010-11-15 05:19:25 +0000 | [diff] [blame] | 235 | get_crbitm_encoding(const MCInst &MI, unsigned OpNo, |
| 236 | SmallVectorImpl<MCFixup> &Fixups) const { |
| 237 | const MCOperand &MO = MI.getOperand(OpNo); |
Ulrich Weigand | 49f487e | 2013-07-03 17:59:07 +0000 | [diff] [blame] | 238 | assert((MI.getOpcode() == PPC::MTOCRF || MI.getOpcode() == PPC::MTOCRF8 || |
Ulrich Weigand | d5ebc62 | 2013-07-03 17:05:42 +0000 | [diff] [blame] | 239 | MI.getOpcode() == PPC::MFOCRF || MI.getOpcode() == PPC::MFOCRF8) && |
Chris Lattner | d6a07cc | 2010-11-15 05:19:25 +0000 | [diff] [blame] | 240 | (MO.getReg() >= PPC::CR0 && MO.getReg() <= PPC::CR7)); |
Bill Wendling | bc07a89 | 2013-06-18 07:20:20 +0000 | [diff] [blame] | 241 | return 0x80 >> CTX.getRegisterInfo()->getEncodingValue(MO.getReg()); |
Chris Lattner | d6a07cc | 2010-11-15 05:19:25 +0000 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | |
| 245 | unsigned PPCMCCodeEmitter:: |
Chris Lattner | 9ec375c | 2010-11-15 04:16:32 +0000 | [diff] [blame] | 246 | getMachineOpValue(const MCInst &MI, const MCOperand &MO, |
| 247 | SmallVectorImpl<MCFixup> &Fixups) const { |
Chris Lattner | d6a07cc | 2010-11-15 05:19:25 +0000 | [diff] [blame] | 248 | if (MO.isReg()) { |
Ulrich Weigand | 49f487e | 2013-07-03 17:59:07 +0000 | [diff] [blame] | 249 | // MTOCRF/MFOCRF should go through get_crbitm_encoding for the CR operand. |
Chris Lattner | 7b25d6f | 2010-11-16 00:57:32 +0000 | [diff] [blame] | 250 | // The GPR operand should come through here though. |
Ulrich Weigand | 49f487e | 2013-07-03 17:59:07 +0000 | [diff] [blame] | 251 | assert((MI.getOpcode() != PPC::MTOCRF && MI.getOpcode() != PPC::MTOCRF8 && |
Ulrich Weigand | d5ebc62 | 2013-07-03 17:05:42 +0000 | [diff] [blame] | 252 | MI.getOpcode() != PPC::MFOCRF && MI.getOpcode() != PPC::MFOCRF8) || |
Chris Lattner | 73716a6 | 2010-11-16 00:55:51 +0000 | [diff] [blame] | 253 | MO.getReg() < PPC::CR0 || MO.getReg() > PPC::CR7); |
Bill Wendling | bc07a89 | 2013-06-18 07:20:20 +0000 | [diff] [blame] | 254 | return CTX.getRegisterInfo()->getEncodingValue(MO.getReg()); |
Chris Lattner | d6a07cc | 2010-11-15 05:19:25 +0000 | [diff] [blame] | 255 | } |
Chris Lattner | c877d8f | 2010-11-15 04:51:55 +0000 | [diff] [blame] | 256 | |
Chris Lattner | efacb9e | 2010-11-15 08:22:03 +0000 | [diff] [blame] | 257 | assert(MO.isImm() && |
| 258 | "Relocation required in an instruction that we cannot encode!"); |
| 259 | return MO.getImm(); |
Chris Lattner | 9ec375c | 2010-11-15 04:16:32 +0000 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | |
| 263 | #include "PPCGenMCCodeEmitter.inc" |