blob: 435a93f78c1d3ca1d64c412eeb4f264764f46f3e [file] [log] [blame]
Chris Lattner9ec375c2010-11-15 04:16:32 +00001//===-- 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
Chandler Carruthed0881b2012-12-03 16:50:05 +000014#include "MCTargetDesc/PPCMCTargetDesc.h"
Evan Cheng61d4a202011-07-25 19:53:23 +000015#include "MCTargetDesc/PPCFixupKinds.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000016#include "llvm/ADT/Statistic.h"
Chris Lattner9ec375c2010-11-15 04:16:32 +000017#include "llvm/MC/MCCodeEmitter.h"
Hal Finkelfeea6532013-03-26 20:08:20 +000018#include "llvm/MC/MCContext.h"
Bill Schmidtc56f1d32012-12-11 20:30:11 +000019#include "llvm/MC/MCExpr.h"
Chris Lattner9ec375c2010-11-15 04:16:32 +000020#include "llvm/MC/MCInst.h"
Adhemerval Zanellaf2aceda2012-10-25 12:27:42 +000021#include "llvm/MC/MCInstrInfo.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000022#include "llvm/MC/MCSubtargetInfo.h"
Chris Lattner9ec375c2010-11-15 04:16:32 +000023#include "llvm/Support/ErrorHandling.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000024#include "llvm/Support/raw_ostream.h"
Bill Schmidtc763c222013-09-16 17:25:12 +000025#include "llvm/Target/TargetOpcodes.h"
Chris Lattner9ec375c2010-11-15 04:16:32 +000026using namespace llvm;
27
Chandler Carruth84e68b22014-04-22 02:41:26 +000028#define DEBUG_TYPE "mccodeemitter"
29
Chris Lattner9ec375c2010-11-15 04:16:32 +000030STATISTIC(MCNumEmitted, "Number of MC instructions emitted");
31
32namespace {
33class PPCMCCodeEmitter : public MCCodeEmitter {
Craig Toppera60c0f12012-09-15 17:09:36 +000034 PPCMCCodeEmitter(const PPCMCCodeEmitter &) LLVM_DELETED_FUNCTION;
35 void operator=(const PPCMCCodeEmitter &) LLVM_DELETED_FUNCTION;
36
Hal Finkela7bbaf62014-02-02 06:12:27 +000037 const MCInstrInfo &MCII;
Hal Finkelfeea6532013-03-26 20:08:20 +000038 const MCContext &CTX;
Ulrich Weigandcae3a172014-03-24 18:16:09 +000039 bool IsLittleEndian;
Adhemerval Zanellaf2aceda2012-10-25 12:27:42 +000040
Chris Lattner9ec375c2010-11-15 04:16:32 +000041public:
Ulrich Weigandcae3a172014-03-24 18:16:09 +000042 PPCMCCodeEmitter(const MCInstrInfo &mcii, MCContext &ctx, bool isLittle)
43 : MCII(mcii), CTX(ctx), IsLittleEndian(isLittle) {
Chris Lattner9ec375c2010-11-15 04:16:32 +000044 }
45
46 ~PPCMCCodeEmitter() {}
Chris Lattnerd6a07cc2010-11-15 05:19:25 +000047
Chris Lattner0e3461e2010-11-15 06:09:35 +000048 unsigned getDirectBrEncoding(const MCInst &MI, unsigned OpNo,
David Woodhouse3fa98a62014-01-28 23:13:18 +000049 SmallVectorImpl<MCFixup> &Fixups,
50 const MCSubtargetInfo &STI) const;
Chris Lattner0e3461e2010-11-15 06:09:35 +000051 unsigned getCondBrEncoding(const MCInst &MI, unsigned OpNo,
David Woodhouse3fa98a62014-01-28 23:13:18 +000052 SmallVectorImpl<MCFixup> &Fixups,
53 const MCSubtargetInfo &STI) const;
Ulrich Weigandb6a30d12013-06-24 11:03:33 +000054 unsigned getAbsDirectBrEncoding(const MCInst &MI, unsigned OpNo,
David Woodhouse3fa98a62014-01-28 23:13:18 +000055 SmallVectorImpl<MCFixup> &Fixups,
56 const MCSubtargetInfo &STI) const;
Ulrich Weigandb6a30d12013-06-24 11:03:33 +000057 unsigned getAbsCondBrEncoding(const MCInst &MI, unsigned OpNo,
David Woodhouse3fa98a62014-01-28 23:13:18 +000058 SmallVectorImpl<MCFixup> &Fixups,
59 const MCSubtargetInfo &STI) const;
Ulrich Weigandfd3ad692013-06-26 13:49:15 +000060 unsigned getImm16Encoding(const MCInst &MI, unsigned OpNo,
David Woodhouse3fa98a62014-01-28 23:13:18 +000061 SmallVectorImpl<MCFixup> &Fixups,
62 const MCSubtargetInfo &STI) const;
Chris Lattnerefacb9e2010-11-15 08:22:03 +000063 unsigned getMemRIEncoding(const MCInst &MI, unsigned OpNo,
David Woodhouse3fa98a62014-01-28 23:13:18 +000064 SmallVectorImpl<MCFixup> &Fixups,
65 const MCSubtargetInfo &STI) const;
Chris Lattner8f4444d2010-11-15 08:02:41 +000066 unsigned getMemRIXEncoding(const MCInst &MI, unsigned OpNo,
David Woodhouse3fa98a62014-01-28 23:13:18 +000067 SmallVectorImpl<MCFixup> &Fixups,
68 const MCSubtargetInfo &STI) const;
Bill Schmidtca4a0c92012-12-04 16:18:08 +000069 unsigned getTLSRegEncoding(const MCInst &MI, unsigned OpNo,
David Woodhouse3fa98a62014-01-28 23:13:18 +000070 SmallVectorImpl<MCFixup> &Fixups,
71 const MCSubtargetInfo &STI) const;
Ulrich Weigand5143bab2013-07-02 21:31:04 +000072 unsigned getTLSCallEncoding(const MCInst &MI, unsigned OpNo,
David Woodhouse3fa98a62014-01-28 23:13:18 +000073 SmallVectorImpl<MCFixup> &Fixups,
74 const MCSubtargetInfo &STI) const;
Chris Lattnerd6a07cc2010-11-15 05:19:25 +000075 unsigned get_crbitm_encoding(const MCInst &MI, unsigned OpNo,
David Woodhouse3fa98a62014-01-28 23:13:18 +000076 SmallVectorImpl<MCFixup> &Fixups,
77 const MCSubtargetInfo &STI) const;
Chris Lattnerd6a07cc2010-11-15 05:19:25 +000078
Chris Lattner9ec375c2010-11-15 04:16:32 +000079 /// getMachineOpValue - Return binary encoding of operand. If the machine
80 /// operand requires relocation, record the relocation and return zero.
81 unsigned getMachineOpValue(const MCInst &MI,const MCOperand &MO,
David Woodhouse3fa98a62014-01-28 23:13:18 +000082 SmallVectorImpl<MCFixup> &Fixups,
83 const MCSubtargetInfo &STI) const;
Chris Lattner9ec375c2010-11-15 04:16:32 +000084
85 // getBinaryCodeForInstr - TableGen'erated function for getting the
86 // binary encoding for an instruction.
Owen Andersond845d9d2012-01-24 18:37:29 +000087 uint64_t getBinaryCodeForInstr(const MCInst &MI,
David Woodhouse3fa98a62014-01-28 23:13:18 +000088 SmallVectorImpl<MCFixup> &Fixups,
89 const MCSubtargetInfo &STI) const;
Chris Lattner9ec375c2010-11-15 04:16:32 +000090 void EncodeInstruction(const MCInst &MI, raw_ostream &OS,
David Woodhouse9784cef2014-01-28 23:13:07 +000091 SmallVectorImpl<MCFixup> &Fixups,
Craig Topper0d3fa922014-04-29 07:57:37 +000092 const MCSubtargetInfo &STI) const override {
Bill Schmidtc763c222013-09-16 17:25:12 +000093 // For fast-isel, a float COPY_TO_REGCLASS can survive this long.
94 // It's just a nop to keep the register classes happy, so don't
95 // generate anything.
96 unsigned Opcode = MI.getOpcode();
Hal Finkela7bbaf62014-02-02 06:12:27 +000097 const MCInstrDesc &Desc = MCII.get(Opcode);
Bill Schmidtc763c222013-09-16 17:25:12 +000098 if (Opcode == TargetOpcode::COPY_TO_REGCLASS)
99 return;
100
David Woodhouse3fa98a62014-01-28 23:13:18 +0000101 uint64_t Bits = getBinaryCodeForInstr(MI, Fixups, STI);
Adhemerval Zanella1be10dc2012-10-25 14:29:13 +0000102
Ulrich Weigandcae3a172014-03-24 18:16:09 +0000103 // Output the constant in big/little endian byte order.
Hal Finkela7bbaf62014-02-02 06:12:27 +0000104 unsigned Size = Desc.getSize();
Ulrich Weigand7c3f0dc2014-06-18 15:37:07 +0000105 switch (Size) {
106 case 4:
107 if (IsLittleEndian) {
108 OS << (char)(Bits);
109 OS << (char)(Bits >> 8);
110 OS << (char)(Bits >> 16);
111 OS << (char)(Bits >> 24);
112 } else {
113 OS << (char)(Bits >> 24);
114 OS << (char)(Bits >> 16);
115 OS << (char)(Bits >> 8);
116 OS << (char)(Bits);
Ulrich Weigandcae3a172014-03-24 18:16:09 +0000117 }
Ulrich Weigand7c3f0dc2014-06-18 15:37:07 +0000118 break;
119 case 8:
120 // If we emit a pair of instructions, the first one is
121 // always in the top 32 bits, even on little-endian.
122 if (IsLittleEndian) {
123 OS << (char)(Bits >> 32);
124 OS << (char)(Bits >> 40);
125 OS << (char)(Bits >> 48);
126 OS << (char)(Bits >> 56);
127 OS << (char)(Bits);
128 OS << (char)(Bits >> 8);
129 OS << (char)(Bits >> 16);
130 OS << (char)(Bits >> 24);
131 } else {
132 OS << (char)(Bits >> 56);
133 OS << (char)(Bits >> 48);
134 OS << (char)(Bits >> 40);
135 OS << (char)(Bits >> 32);
136 OS << (char)(Bits >> 24);
137 OS << (char)(Bits >> 16);
138 OS << (char)(Bits >> 8);
139 OS << (char)(Bits);
Ulrich Weigandcae3a172014-03-24 18:16:09 +0000140 }
Ulrich Weigand7c3f0dc2014-06-18 15:37:07 +0000141 break;
142 default:
143 llvm_unreachable ("Invalid instruction size");
Chris Lattner9ec375c2010-11-15 04:16:32 +0000144 }
145
146 ++MCNumEmitted; // Keep track of the # of mi's emitted.
147 }
148
149};
150
151} // end anonymous namespace
152
Evan Chengc5e6d2f2011-07-11 03:57:24 +0000153MCCodeEmitter *llvm::createPPCMCCodeEmitter(const MCInstrInfo &MCII,
Jim Grosbachc3b04272012-05-15 17:35:52 +0000154 const MCRegisterInfo &MRI,
Evan Chengc5e6d2f2011-07-11 03:57:24 +0000155 const MCSubtargetInfo &STI,
Chris Lattner9ec375c2010-11-15 04:16:32 +0000156 MCContext &Ctx) {
Ulrich Weigandcae3a172014-03-24 18:16:09 +0000157 Triple TT(STI.getTargetTriple());
158 bool IsLittleEndian = TT.getArch() == Triple::ppc64le;
159 return new PPCMCCodeEmitter(MCII, Ctx, IsLittleEndian);
Chris Lattner9ec375c2010-11-15 04:16:32 +0000160}
161
162unsigned PPCMCCodeEmitter::
Chris Lattner0e3461e2010-11-15 06:09:35 +0000163getDirectBrEncoding(const MCInst &MI, unsigned OpNo,
David Woodhouse3fa98a62014-01-28 23:13:18 +0000164 SmallVectorImpl<MCFixup> &Fixups,
165 const MCSubtargetInfo &STI) const {
Chris Lattner79fa3712010-11-15 05:57:53 +0000166 const MCOperand &MO = MI.getOperand(OpNo);
David Woodhouse3fa98a62014-01-28 23:13:18 +0000167 if (MO.isReg() || MO.isImm()) return getMachineOpValue(MI, MO, Fixups, STI);
Chris Lattner79fa3712010-11-15 05:57:53 +0000168
169 // Add a fixup for the branch target.
170 Fixups.push_back(MCFixup::Create(0, MO.getExpr(),
171 (MCFixupKind)PPC::fixup_ppc_br24));
172 return 0;
173}
174
Chris Lattner0e3461e2010-11-15 06:09:35 +0000175unsigned PPCMCCodeEmitter::getCondBrEncoding(const MCInst &MI, unsigned OpNo,
David Woodhouse3fa98a62014-01-28 23:13:18 +0000176 SmallVectorImpl<MCFixup> &Fixups,
177 const MCSubtargetInfo &STI) const {
Chris Lattner0e3461e2010-11-15 06:09:35 +0000178 const MCOperand &MO = MI.getOperand(OpNo);
David Woodhouse3fa98a62014-01-28 23:13:18 +0000179 if (MO.isReg() || MO.isImm()) return getMachineOpValue(MI, MO, Fixups, STI);
Chris Lattner0e3461e2010-11-15 06:09:35 +0000180
Chris Lattner85e37682010-11-15 06:12:22 +0000181 // Add a fixup for the branch target.
182 Fixups.push_back(MCFixup::Create(0, MO.getExpr(),
183 (MCFixupKind)PPC::fixup_ppc_brcond14));
Chris Lattner0e3461e2010-11-15 06:09:35 +0000184 return 0;
185}
186
Ulrich Weigandb6a30d12013-06-24 11:03:33 +0000187unsigned PPCMCCodeEmitter::
188getAbsDirectBrEncoding(const MCInst &MI, unsigned OpNo,
David Woodhouse3fa98a62014-01-28 23:13:18 +0000189 SmallVectorImpl<MCFixup> &Fixups,
190 const MCSubtargetInfo &STI) const {
Ulrich Weigandb6a30d12013-06-24 11:03:33 +0000191 const MCOperand &MO = MI.getOperand(OpNo);
David Woodhouse3fa98a62014-01-28 23:13:18 +0000192 if (MO.isReg() || MO.isImm()) return getMachineOpValue(MI, MO, Fixups, STI);
Ulrich Weigandb6a30d12013-06-24 11:03:33 +0000193
194 // Add a fixup for the branch target.
195 Fixups.push_back(MCFixup::Create(0, MO.getExpr(),
196 (MCFixupKind)PPC::fixup_ppc_br24abs));
197 return 0;
198}
199
200unsigned PPCMCCodeEmitter::
201getAbsCondBrEncoding(const MCInst &MI, unsigned OpNo,
David Woodhouse3fa98a62014-01-28 23:13:18 +0000202 SmallVectorImpl<MCFixup> &Fixups,
203 const MCSubtargetInfo &STI) const {
Ulrich Weigandb6a30d12013-06-24 11:03:33 +0000204 const MCOperand &MO = MI.getOperand(OpNo);
David Woodhouse3fa98a62014-01-28 23:13:18 +0000205 if (MO.isReg() || MO.isImm()) return getMachineOpValue(MI, MO, Fixups, STI);
Ulrich Weigandb6a30d12013-06-24 11:03:33 +0000206
207 // Add a fixup for the branch target.
208 Fixups.push_back(MCFixup::Create(0, MO.getExpr(),
209 (MCFixupKind)PPC::fixup_ppc_brcond14abs));
210 return 0;
211}
212
Ulrich Weigandfd3ad692013-06-26 13:49:15 +0000213unsigned PPCMCCodeEmitter::getImm16Encoding(const MCInst &MI, unsigned OpNo,
David Woodhouse3fa98a62014-01-28 23:13:18 +0000214 SmallVectorImpl<MCFixup> &Fixups,
215 const MCSubtargetInfo &STI) const {
Chris Lattner65661122010-11-15 06:33:39 +0000216 const MCOperand &MO = MI.getOperand(OpNo);
David Woodhouse3fa98a62014-01-28 23:13:18 +0000217 if (MO.isReg() || MO.isImm()) return getMachineOpValue(MI, MO, Fixups, STI);
Chris Lattner65661122010-11-15 06:33:39 +0000218
Ulrich Weigandfd3ad692013-06-26 13:49:15 +0000219 // Add a fixup for the immediate field.
Ulrich Weigandcae3a172014-03-24 18:16:09 +0000220 Fixups.push_back(MCFixup::Create(IsLittleEndian? 0 : 2, MO.getExpr(),
Ulrich Weigand6e23ac62013-05-17 12:37:21 +0000221 (MCFixupKind)PPC::fixup_ppc_half16));
Chris Lattner65661122010-11-15 06:33:39 +0000222 return 0;
223}
224
Chris Lattnerefacb9e2010-11-15 08:22:03 +0000225unsigned PPCMCCodeEmitter::getMemRIEncoding(const MCInst &MI, unsigned OpNo,
David Woodhouse3fa98a62014-01-28 23:13:18 +0000226 SmallVectorImpl<MCFixup> &Fixups,
227 const MCSubtargetInfo &STI) const {
Chris Lattnerefacb9e2010-11-15 08:22:03 +0000228 // Encode (imm, reg) as a memri, which has the low 16-bits as the
229 // displacement and the next 5 bits as the register #.
230 assert(MI.getOperand(OpNo+1).isReg());
David Woodhouse3fa98a62014-01-28 23:13:18 +0000231 unsigned RegBits = getMachineOpValue(MI, MI.getOperand(OpNo+1), Fixups, STI) << 16;
Chris Lattnerefacb9e2010-11-15 08:22:03 +0000232
233 const MCOperand &MO = MI.getOperand(OpNo);
234 if (MO.isImm())
David Woodhouse3fa98a62014-01-28 23:13:18 +0000235 return (getMachineOpValue(MI, MO, Fixups, STI) & 0xFFFF) | RegBits;
Chris Lattnerefacb9e2010-11-15 08:22:03 +0000236
237 // Add a fixup for the displacement field.
Ulrich Weigandcae3a172014-03-24 18:16:09 +0000238 Fixups.push_back(MCFixup::Create(IsLittleEndian? 0 : 2, MO.getExpr(),
Ulrich Weigand6e23ac62013-05-17 12:37:21 +0000239 (MCFixupKind)PPC::fixup_ppc_half16));
Chris Lattnerefacb9e2010-11-15 08:22:03 +0000240 return RegBits;
241}
242
243
Chris Lattner8f4444d2010-11-15 08:02:41 +0000244unsigned PPCMCCodeEmitter::getMemRIXEncoding(const MCInst &MI, unsigned OpNo,
David Woodhouse3fa98a62014-01-28 23:13:18 +0000245 SmallVectorImpl<MCFixup> &Fixups,
246 const MCSubtargetInfo &STI) const {
Chris Lattner8f4444d2010-11-15 08:02:41 +0000247 // Encode (imm, reg) as a memrix, which has the low 14-bits as the
248 // displacement and the next 5 bits as the register #.
Chris Lattnerefacb9e2010-11-15 08:22:03 +0000249 assert(MI.getOperand(OpNo+1).isReg());
David Woodhouse3fa98a62014-01-28 23:13:18 +0000250 unsigned RegBits = getMachineOpValue(MI, MI.getOperand(OpNo+1), Fixups, STI) << 14;
Chris Lattner8f4444d2010-11-15 08:02:41 +0000251
Chris Lattner65661122010-11-15 06:33:39 +0000252 const MCOperand &MO = MI.getOperand(OpNo);
Chris Lattner8f4444d2010-11-15 08:02:41 +0000253 if (MO.isImm())
David Woodhouse3fa98a62014-01-28 23:13:18 +0000254 return ((getMachineOpValue(MI, MO, Fixups, STI) >> 2) & 0x3FFF) | RegBits;
Chris Lattner65661122010-11-15 06:33:39 +0000255
Ulrich Weigand3e186012013-03-26 10:56:47 +0000256 // Add a fixup for the displacement field.
Ulrich Weigandcae3a172014-03-24 18:16:09 +0000257 Fixups.push_back(MCFixup::Create(IsLittleEndian? 0 : 2, MO.getExpr(),
Ulrich Weigand6e23ac62013-05-17 12:37:21 +0000258 (MCFixupKind)PPC::fixup_ppc_half16ds));
Chris Lattner8f4444d2010-11-15 08:02:41 +0000259 return RegBits;
Chris Lattner65661122010-11-15 06:33:39 +0000260}
261
Chris Lattner0e3461e2010-11-15 06:09:35 +0000262
Bill Schmidtca4a0c92012-12-04 16:18:08 +0000263unsigned PPCMCCodeEmitter::getTLSRegEncoding(const MCInst &MI, unsigned OpNo,
David Woodhouse3fa98a62014-01-28 23:13:18 +0000264 SmallVectorImpl<MCFixup> &Fixups,
265 const MCSubtargetInfo &STI) const {
Bill Schmidtca4a0c92012-12-04 16:18:08 +0000266 const MCOperand &MO = MI.getOperand(OpNo);
David Woodhouse3fa98a62014-01-28 23:13:18 +0000267 if (MO.isReg()) return getMachineOpValue(MI, MO, Fixups, STI);
Bill Schmidtca4a0c92012-12-04 16:18:08 +0000268
269 // Add a fixup for the TLS register, which simply provides a relocation
270 // hint to the linker that this statement is part of a relocation sequence.
271 // Return the thread-pointer register's encoding.
272 Fixups.push_back(MCFixup::Create(0, MO.getExpr(),
Ulrich Weigand5b427592013-07-05 12:22:36 +0000273 (MCFixupKind)PPC::fixup_ppc_nofixup));
David Woodhoused2cca112014-01-28 23:13:25 +0000274 Triple TT(STI.getTargetTriple());
Roman Divackybc1655b42013-12-22 10:45:37 +0000275 bool isPPC64 = TT.getArch() == Triple::ppc64 || TT.getArch() == Triple::ppc64le;
276 return CTX.getRegisterInfo()->getEncodingValue(isPPC64 ? PPC::X13 : PPC::R2);
Bill Schmidtca4a0c92012-12-04 16:18:08 +0000277}
278
Ulrich Weigand5143bab2013-07-02 21:31:04 +0000279unsigned PPCMCCodeEmitter::getTLSCallEncoding(const MCInst &MI, unsigned OpNo,
David Woodhouse3fa98a62014-01-28 23:13:18 +0000280 SmallVectorImpl<MCFixup> &Fixups,
281 const MCSubtargetInfo &STI) const {
Ulrich Weigand5143bab2013-07-02 21:31:04 +0000282 // For special TLS calls, we need two fixups; one for the branch target
283 // (__tls_get_addr), which we create via getDirectBrEncoding as usual,
284 // and one for the TLSGD or TLSLD symbol, which is emitted here.
285 const MCOperand &MO = MI.getOperand(OpNo+1);
286 Fixups.push_back(MCFixup::Create(0, MO.getExpr(),
287 (MCFixupKind)PPC::fixup_ppc_nofixup));
David Woodhouse3fa98a62014-01-28 23:13:18 +0000288 return getDirectBrEncoding(MI, OpNo, Fixups, STI);
Ulrich Weigand5143bab2013-07-02 21:31:04 +0000289}
290
Chris Lattner79fa3712010-11-15 05:57:53 +0000291unsigned PPCMCCodeEmitter::
Chris Lattnerd6a07cc2010-11-15 05:19:25 +0000292get_crbitm_encoding(const MCInst &MI, unsigned OpNo,
David Woodhouse3fa98a62014-01-28 23:13:18 +0000293 SmallVectorImpl<MCFixup> &Fixups,
294 const MCSubtargetInfo &STI) const {
Chris Lattnerd6a07cc2010-11-15 05:19:25 +0000295 const MCOperand &MO = MI.getOperand(OpNo);
Ulrich Weigand49f487e2013-07-03 17:59:07 +0000296 assert((MI.getOpcode() == PPC::MTOCRF || MI.getOpcode() == PPC::MTOCRF8 ||
Ulrich Weigandd5ebc622013-07-03 17:05:42 +0000297 MI.getOpcode() == PPC::MFOCRF || MI.getOpcode() == PPC::MFOCRF8) &&
Chris Lattnerd6a07cc2010-11-15 05:19:25 +0000298 (MO.getReg() >= PPC::CR0 && MO.getReg() <= PPC::CR7));
Bill Wendlingbc07a892013-06-18 07:20:20 +0000299 return 0x80 >> CTX.getRegisterInfo()->getEncodingValue(MO.getReg());
Chris Lattnerd6a07cc2010-11-15 05:19:25 +0000300}
301
302
303unsigned PPCMCCodeEmitter::
Chris Lattner9ec375c2010-11-15 04:16:32 +0000304getMachineOpValue(const MCInst &MI, const MCOperand &MO,
David Woodhouse3fa98a62014-01-28 23:13:18 +0000305 SmallVectorImpl<MCFixup> &Fixups,
306 const MCSubtargetInfo &STI) const {
Chris Lattnerd6a07cc2010-11-15 05:19:25 +0000307 if (MO.isReg()) {
Ulrich Weigand49f487e2013-07-03 17:59:07 +0000308 // MTOCRF/MFOCRF should go through get_crbitm_encoding for the CR operand.
Chris Lattner7b25d6f2010-11-16 00:57:32 +0000309 // The GPR operand should come through here though.
Ulrich Weigand49f487e2013-07-03 17:59:07 +0000310 assert((MI.getOpcode() != PPC::MTOCRF && MI.getOpcode() != PPC::MTOCRF8 &&
Ulrich Weigandd5ebc622013-07-03 17:05:42 +0000311 MI.getOpcode() != PPC::MFOCRF && MI.getOpcode() != PPC::MFOCRF8) ||
Chris Lattner73716a62010-11-16 00:55:51 +0000312 MO.getReg() < PPC::CR0 || MO.getReg() > PPC::CR7);
Bill Wendlingbc07a892013-06-18 07:20:20 +0000313 return CTX.getRegisterInfo()->getEncodingValue(MO.getReg());
Chris Lattnerd6a07cc2010-11-15 05:19:25 +0000314 }
Chris Lattnerc877d8f2010-11-15 04:51:55 +0000315
Chris Lattnerefacb9e2010-11-15 08:22:03 +0000316 assert(MO.isImm() &&
317 "Relocation required in an instruction that we cannot encode!");
318 return MO.getImm();
Chris Lattner9ec375c2010-11-15 04:16:32 +0000319}
320
321
322#include "PPCGenMCCodeEmitter.inc"