blob: 543329562afd3d81331cdc1048a3ccffa0a34f93 [file] [log] [blame]
Jia Liuc5707112012-02-17 08:55:11 +00001//===-- Mips/MipsCodeEmitter.cpp - Convert Mips Code to Machine Code ------===//
Bruno Cardoso Lopesdca6cdd2011-07-21 16:28:51 +00002//
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 contains the pass that transforms the Mips machine instructions
11// into relocatable machine code.
12//
13//===---------------------------------------------------------------------===//
14
15#define DEBUG_TYPE "jit"
16#include "Mips.h"
17#include "MipsInstrInfo.h"
18#include "MipsRelocations.h"
19#include "MipsSubtarget.h"
20#include "MipsTargetMachine.h"
Bruno Cardoso Lopes47b92f32011-11-11 22:58:42 +000021#include "MCTargetDesc/MipsBaseInfo.h"
22#include "llvm/ADT/Statistic.h"
Bruno Cardoso Lopesdca6cdd2011-07-21 16:28:51 +000023#include "llvm/CodeGen/JITCodeEmitter.h"
24#include "llvm/CodeGen/MachineConstantPool.h"
25#include "llvm/CodeGen/MachineFunctionPass.h"
26#include "llvm/CodeGen/MachineInstr.h"
27#include "llvm/CodeGen/MachineJumpTableInfo.h"
28#include "llvm/CodeGen/MachineModuleInfo.h"
Bruno Cardoso Lopes47b92f32011-11-11 22:58:42 +000029#include "llvm/CodeGen/MachineOperand.h"
Bruno Cardoso Lopesdca6cdd2011-07-21 16:28:51 +000030#include "llvm/CodeGen/Passes.h"
Bruno Cardoso Lopes47b92f32011-11-11 22:58:42 +000031#include "llvm/Constants.h"
32#include "llvm/DerivedTypes.h"
Bruno Cardoso Lopes47b92f32011-11-11 22:58:42 +000033#include "llvm/PassManager.h"
Bruno Cardoso Lopesdca6cdd2011-07-21 16:28:51 +000034#include "llvm/Support/Debug.h"
35#include "llvm/Support/ErrorHandling.h"
36#include "llvm/Support/raw_ostream.h"
37#ifndef NDEBUG
38#include <iomanip>
39#endif
40
Bruno Cardoso Lopesdca6cdd2011-07-21 16:28:51 +000041using namespace llvm;
42
Bruno Cardoso Lopesc4cc40c2011-09-14 03:00:41 +000043STATISTIC(NumEmitted, "Number of machine instructions emitted");
44
Bruno Cardoso Lopesdca6cdd2011-07-21 16:28:51 +000045namespace {
46
47class MipsCodeEmitter : public MachineFunctionPass {
48 MipsJITInfo *JTI;
49 const MipsInstrInfo *II;
50 const TargetData *TD;
51 const MipsSubtarget *Subtarget;
52 TargetMachine &TM;
53 JITCodeEmitter &MCE;
54 const std::vector<MachineConstantPoolEntry> *MCPEs;
55 const std::vector<MachineJumpTableEntry> *MJTEs;
56 bool IsPIC;
57
58 void getAnalysisUsage(AnalysisUsage &AU) const {
59 AU.addRequired<MachineModuleInfo> ();
60 MachineFunctionPass::getAnalysisUsage(AU);
61 }
62
63 static char ID;
64
65 public:
66 MipsCodeEmitter(TargetMachine &tm, JITCodeEmitter &mce) :
67 MachineFunctionPass(ID), JTI(0),
Bruno Cardoso Lopes47b92f32011-11-11 22:58:42 +000068 II((const MipsInstrInfo *) tm.getInstrInfo()),
69 TD(tm.getTargetData()), TM(tm), MCE(mce), MCPEs(0), MJTEs(0),
70 IsPIC(TM.getRelocationModel() == Reloc::PIC_) {
Bruno Cardoso Lopesdca6cdd2011-07-21 16:28:51 +000071 }
72
73 bool runOnMachineFunction(MachineFunction &MF);
74
75 virtual const char *getPassName() const {
76 return "Mips Machine Code Emitter";
77 }
78
Bruno Cardoso Lopesc4cc40c2011-09-14 03:00:41 +000079 /// getBinaryCodeForInstr - This function, generated by the
80 /// CodeEmitterGenerator using TableGen, produces the binary encoding for
81 /// machine instructions.
Owen Anderson4f8dc7b2012-01-24 18:37:29 +000082 uint64_t getBinaryCodeForInstr(const MachineInstr &MI) const;
Bruno Cardoso Lopesc4cc40c2011-09-14 03:00:41 +000083
Bruno Cardoso Lopesdca6cdd2011-07-21 16:28:51 +000084 void emitInstruction(const MachineInstr &MI);
85
Bruno Cardoso Lopesc4cc40c2011-09-14 03:00:41 +000086 private:
Bruno Cardoso Lopesdca6cdd2011-07-21 16:28:51 +000087
Bruno Cardoso Lopesc4cc40c2011-09-14 03:00:41 +000088 void emitWordLE(unsigned Word);
89
90 /// Routines that handle operands which add machine relocations which are
91 /// fixed up by the relocation stage.
Bruno Cardoso Lopesdca6cdd2011-07-21 16:28:51 +000092 void emitGlobalAddress(const GlobalValue *GV, unsigned Reloc,
Bruno Cardoso Lopes47b92f32011-11-11 22:58:42 +000093 bool MayNeedFarStub) const;
Bruno Cardoso Lopesc4cc40c2011-09-14 03:00:41 +000094 void emitExternalSymbolAddress(const char *ES, unsigned Reloc) const;
95 void emitConstPoolAddress(unsigned CPI, unsigned Reloc) const;
Bruno Cardoso Lopesdca6cdd2011-07-21 16:28:51 +000096 void emitJumpTableAddress(unsigned JTIndex, unsigned Reloc) const;
Bruno Cardoso Lopesc4cc40c2011-09-14 03:00:41 +000097 void emitMachineBasicBlock(MachineBasicBlock *BB, unsigned Reloc) const;
98
99 /// getMachineOpValue - Return binary encoding of operand. If the machine
100 /// operand requires relocation, record the relocation and return zero.
101 unsigned getMachineOpValue(const MachineInstr &MI,
102 const MachineOperand &MO) const;
103
104 unsigned getRelocation(const MachineInstr &MI,
105 const MachineOperand &MO) const;
106
Bruno Cardoso Lopes47b92f32011-11-11 22:58:42 +0000107 unsigned getJumpTargetOpValue(const MachineInstr &MI, unsigned OpNo) const;
108
Akira Hatanaka82099682011-12-19 19:52:25 +0000109 unsigned getBranchTargetOpValue(const MachineInstr &MI,
110 unsigned OpNo) const;
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000111 unsigned getMemEncoding(const MachineInstr &MI, unsigned OpNo) const;
112 unsigned getSizeExtEncoding(const MachineInstr &MI, unsigned OpNo) const;
113 unsigned getSizeInsEncoding(const MachineInstr &MI, unsigned OpNo) const;
Bruno Cardoso Lopesad6eef42011-11-08 12:47:11 +0000114
115 int emitULW(const MachineInstr &MI);
116 int emitUSW(const MachineInstr &MI);
117 int emitULH(const MachineInstr &MI);
118 int emitULHu(const MachineInstr &MI);
119 int emitUSH(const MachineInstr &MI);
120
121 void emitGlobalAddressUnaligned(const GlobalValue *GV, unsigned Reloc,
Akira Hatanaka82099682011-12-19 19:52:25 +0000122 int Offset) const;
Bruno Cardoso Lopesc4cc40c2011-09-14 03:00:41 +0000123 };
Bruno Cardoso Lopesdca6cdd2011-07-21 16:28:51 +0000124}
125
Bruno Cardoso Lopesc4cc40c2011-09-14 03:00:41 +0000126char MipsCodeEmitter::ID = 0;
Bruno Cardoso Lopesdca6cdd2011-07-21 16:28:51 +0000127
128bool MipsCodeEmitter::runOnMachineFunction(MachineFunction &MF) {
129 JTI = ((MipsTargetMachine&) MF.getTarget()).getJITInfo();
130 II = ((const MipsTargetMachine&) MF.getTarget()).getInstrInfo();
131 TD = ((const MipsTargetMachine&) MF.getTarget()).getTargetData();
132 Subtarget = &TM.getSubtarget<MipsSubtarget> ();
133 MCPEs = &MF.getConstantPool()->getConstants();
134 MJTEs = 0;
135 if (MF.getJumpTableInfo()) MJTEs = &MF.getJumpTableInfo()->getJumpTables();
136 JTI->Initialize(MF, IsPIC);
137 MCE.setModuleInfo(&getAnalysis<MachineModuleInfo> ());
138
139 do {
140 DEBUG(errs() << "JITTing function '"
Craig Topper96601ca2012-08-22 06:07:19 +0000141 << MF.getName() << "'\n");
Bruno Cardoso Lopesdca6cdd2011-07-21 16:28:51 +0000142 MCE.startFunction(MF);
143
144 for (MachineFunction::iterator MBB = MF.begin(), E = MF.end();
145 MBB != E; ++MBB){
146 MCE.StartMachineBasicBlock(MBB);
Akira Hatanaka226ae402012-06-19 03:39:45 +0000147 for (MachineBasicBlock::instr_iterator I = MBB->instr_begin(),
148 E = MBB->instr_end(); I != E; ++I)
Bruno Cardoso Lopesdca6cdd2011-07-21 16:28:51 +0000149 emitInstruction(*I);
150 }
151 } while (MCE.finishFunction(MF));
152
153 return false;
154}
155
Bruno Cardoso Lopesc4cc40c2011-09-14 03:00:41 +0000156unsigned MipsCodeEmitter::getRelocation(const MachineInstr &MI,
157 const MachineOperand &MO) const {
158 // NOTE: This relocations are for static.
159 uint64_t TSFlags = MI.getDesc().TSFlags;
160 uint64_t Form = TSFlags & MipsII::FormMask;
161 if (Form == MipsII::FrmJ)
162 return Mips::reloc_mips_26;
163 if ((Form == MipsII::FrmI || Form == MipsII::FrmFI)
Evan Cheng5a96b3d2011-12-07 07:15:52 +0000164 && MI.isBranch())
Bruno Cardoso Lopes3aa035f2011-12-30 21:04:30 +0000165 return Mips::reloc_mips_pc16;
Bruno Cardoso Lopesc4cc40c2011-09-14 03:00:41 +0000166 if (Form == MipsII::FrmI && MI.getOpcode() == Mips::LUi)
167 return Mips::reloc_mips_hi;
168 return Mips::reloc_mips_lo;
Bruno Cardoso Lopesdca6cdd2011-07-21 16:28:51 +0000169}
170
Bruno Cardoso Lopes47b92f32011-11-11 22:58:42 +0000171unsigned MipsCodeEmitter::getJumpTargetOpValue(const MachineInstr &MI,
172 unsigned OpNo) const {
Bruno Cardoso Lopes3aa035f2011-12-30 21:04:30 +0000173 MachineOperand MO = MI.getOperand(OpNo);
174 if (MO.isGlobal())
175 emitGlobalAddress(MO.getGlobal(), getRelocation(MI, MO), true);
176 else if (MO.isSymbol())
177 emitExternalSymbolAddress(MO.getSymbolName(), getRelocation(MI, MO));
178 else if (MO.isMBB())
179 emitMachineBasicBlock(MO.getMBB(), getRelocation(MI, MO));
180 else
181 llvm_unreachable("Unexpected jump target operand kind.");
Bruno Cardoso Lopes47b92f32011-11-11 22:58:42 +0000182 return 0;
183}
184
185unsigned MipsCodeEmitter::getBranchTargetOpValue(const MachineInstr &MI,
186 unsigned OpNo) const {
Bruno Cardoso Lopes3aa035f2011-12-30 21:04:30 +0000187 MachineOperand MO = MI.getOperand(OpNo);
188 emitMachineBasicBlock(MO.getMBB(), getRelocation(MI, MO));
Bruno Cardoso Lopes47b92f32011-11-11 22:58:42 +0000189 return 0;
190}
191
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000192unsigned MipsCodeEmitter::getMemEncoding(const MachineInstr &MI,
Bruno Cardoso Lopes47b92f32011-11-11 22:58:42 +0000193 unsigned OpNo) const {
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000194 // Base register is encoded in bits 20-16, offset is encoded in bits 15-0.
195 assert(MI.getOperand(OpNo).isReg());
196 unsigned RegBits = getMachineOpValue(MI, MI.getOperand(OpNo)) << 16;
Bruno Cardoso Lopes47b92f32011-11-11 22:58:42 +0000197 return (getMachineOpValue(MI, MI.getOperand(OpNo+1)) & 0xFFFF) | RegBits;
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000198}
199
200unsigned MipsCodeEmitter::getSizeExtEncoding(const MachineInstr &MI,
Bruno Cardoso Lopes47b92f32011-11-11 22:58:42 +0000201 unsigned OpNo) const {
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000202 // size is encoded as size-1.
203 return getMachineOpValue(MI, MI.getOperand(OpNo)) - 1;
204}
205
206unsigned MipsCodeEmitter::getSizeInsEncoding(const MachineInstr &MI,
Bruno Cardoso Lopes47b92f32011-11-11 22:58:42 +0000207 unsigned OpNo) const {
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000208 // size is encoded as pos+size-1.
209 return getMachineOpValue(MI, MI.getOperand(OpNo-1)) +
210 getMachineOpValue(MI, MI.getOperand(OpNo)) - 1;
211}
212
Bruno Cardoso Lopesc4cc40c2011-09-14 03:00:41 +0000213/// getMachineOpValue - Return binary encoding of operand. If the machine
214/// operand requires relocation, record the relocation and return zero.
215unsigned MipsCodeEmitter::getMachineOpValue(const MachineInstr &MI,
Bruno Cardoso Lopes47b92f32011-11-11 22:58:42 +0000216 const MachineOperand &MO) const {
Bruno Cardoso Lopesc4cc40c2011-09-14 03:00:41 +0000217 if (MO.isReg())
Bruno Cardoso Lopesce8524c2011-12-30 21:09:41 +0000218 return getMipsRegisterNumbering(MO.getReg());
Bruno Cardoso Lopesc4cc40c2011-09-14 03:00:41 +0000219 else if (MO.isImm())
220 return static_cast<unsigned>(MO.getImm());
Bruno Cardoso Lopesad6eef42011-11-08 12:47:11 +0000221 else if (MO.isGlobal()) {
222 if (MI.getOpcode() == Mips::ULW || MI.getOpcode() == Mips::USW ||
223 MI.getOpcode() == Mips::ULH || MI.getOpcode() == Mips::ULHu)
224 emitGlobalAddressUnaligned(MO.getGlobal(), getRelocation(MI, MO), 4);
225 else if (MI.getOpcode() == Mips::USH)
226 emitGlobalAddressUnaligned(MO.getGlobal(), getRelocation(MI, MO), 8);
227 else
228 emitGlobalAddress(MO.getGlobal(), getRelocation(MI, MO), true);
229 } else if (MO.isSymbol())
Bruno Cardoso Lopesc4cc40c2011-09-14 03:00:41 +0000230 emitExternalSymbolAddress(MO.getSymbolName(), getRelocation(MI, MO));
231 else if (MO.isCPI())
232 emitConstPoolAddress(MO.getIndex(), getRelocation(MI, MO));
233 else if (MO.isJTI())
234 emitJumpTableAddress(MO.getIndex(), getRelocation(MI, MO));
235 else if (MO.isMBB())
236 emitMachineBasicBlock(MO.getMBB(), getRelocation(MI, MO));
237 else
238 llvm_unreachable("Unable to encode MachineOperand!");
239 return 0;
240}
241
242void MipsCodeEmitter::emitGlobalAddress(const GlobalValue *GV, unsigned Reloc,
Bruno Cardoso Lopes47b92f32011-11-11 22:58:42 +0000243 bool MayNeedFarStub) const {
Bruno Cardoso Lopesc4cc40c2011-09-14 03:00:41 +0000244 MCE.addRelocation(MachineRelocation::getGV(MCE.getCurrentPCOffset(), Reloc,
Bruno Cardoso Lopes47b92f32011-11-11 22:58:42 +0000245 const_cast<GlobalValue *>(GV), 0,
246 MayNeedFarStub));
Bruno Cardoso Lopesc4cc40c2011-09-14 03:00:41 +0000247}
248
Bruno Cardoso Lopesad6eef42011-11-08 12:47:11 +0000249void MipsCodeEmitter::emitGlobalAddressUnaligned(const GlobalValue *GV,
250 unsigned Reloc, int Offset) const {
251 MCE.addRelocation(MachineRelocation::getGV(MCE.getCurrentPCOffset(), Reloc,
252 const_cast<GlobalValue *>(GV), 0, false));
253 MCE.addRelocation(MachineRelocation::getGV(MCE.getCurrentPCOffset() + Offset,
254 Reloc, const_cast<GlobalValue *>(GV), 0, false));
255}
256
Bruno Cardoso Lopesc4cc40c2011-09-14 03:00:41 +0000257void MipsCodeEmitter::
258emitExternalSymbolAddress(const char *ES, unsigned Reloc) const {
259 MCE.addRelocation(MachineRelocation::getExtSym(MCE.getCurrentPCOffset(),
Akira Hatanakab5713452012-07-24 00:08:26 +0000260 Reloc, ES, 0, 0));
Bruno Cardoso Lopesc4cc40c2011-09-14 03:00:41 +0000261}
262
263void MipsCodeEmitter::emitConstPoolAddress(unsigned CPI, unsigned Reloc) const {
264 MCE.addRelocation(MachineRelocation::getConstPool(MCE.getCurrentPCOffset(),
265 Reloc, CPI, 0, false));
266}
267
268void MipsCodeEmitter::
269emitJumpTableAddress(unsigned JTIndex, unsigned Reloc) const {
270 MCE.addRelocation(MachineRelocation::getJumpTable(MCE.getCurrentPCOffset(),
271 Reloc, JTIndex, 0, false));
272}
273
274void MipsCodeEmitter::emitMachineBasicBlock(MachineBasicBlock *BB,
Bruno Cardoso Lopes47b92f32011-11-11 22:58:42 +0000275 unsigned Reloc) const {
Bruno Cardoso Lopesc4cc40c2011-09-14 03:00:41 +0000276 MCE.addRelocation(MachineRelocation::getBB(MCE.getCurrentPCOffset(),
277 Reloc, BB));
278}
279
Bruno Cardoso Lopesad6eef42011-11-08 12:47:11 +0000280int MipsCodeEmitter::emitUSW(const MachineInstr &MI) {
281 unsigned src = getMachineOpValue(MI, MI.getOperand(0));
282 unsigned base = getMachineOpValue(MI, MI.getOperand(1));
283 unsigned offset = getMachineOpValue(MI, MI.getOperand(2));
284 // swr src, offset(base)
285 // swl src, offset+3(base)
286 MCE.emitWordLE(
287 (0x2e << 26) | (base << 21) | (src << 16) | (offset & 0xffff));
288 MCE.emitWordLE(
289 (0x2a << 26) | (base << 21) | (src << 16) | ((offset+3) & 0xffff));
290 return 2;
291}
292
293int MipsCodeEmitter::emitULW(const MachineInstr &MI) {
294 unsigned dst = getMachineOpValue(MI, MI.getOperand(0));
295 unsigned base = getMachineOpValue(MI, MI.getOperand(1));
296 unsigned offset = getMachineOpValue(MI, MI.getOperand(2));
297 unsigned at = 1;
298 if (dst != base) {
299 // lwr dst, offset(base)
300 // lwl dst, offset+3(base)
301 MCE.emitWordLE(
302 (0x26 << 26) | (base << 21) | (dst << 16) | (offset & 0xffff));
303 MCE.emitWordLE(
304 (0x22 << 26) | (base << 21) | (dst << 16) | ((offset+3) & 0xffff));
305 return 2;
306 } else {
307 // lwr at, offset(base)
308 // lwl at, offset+3(base)
309 // addu dst, at, $zero
310 MCE.emitWordLE(
311 (0x26 << 26) | (base << 21) | (at << 16) | (offset & 0xffff));
312 MCE.emitWordLE(
313 (0x22 << 26) | (base << 21) | (at << 16) | ((offset+3) & 0xffff));
314 MCE.emitWordLE(
315 (0x0 << 26) | (at << 21) | (0x0 << 16) | (dst << 11) | (0x0 << 6) | 0x21);
316 return 3;
317 }
318}
319
320int MipsCodeEmitter::emitUSH(const MachineInstr &MI) {
321 unsigned src = getMachineOpValue(MI, MI.getOperand(0));
322 unsigned base = getMachineOpValue(MI, MI.getOperand(1));
323 unsigned offset = getMachineOpValue(MI, MI.getOperand(2));
324 unsigned at = 1;
325 // sb src, offset(base)
326 // srl at,src,8
327 // sb at, offset+1(base)
328 MCE.emitWordLE(
329 (0x28 << 26) | (base << 21) | (src << 16) | (offset & 0xffff));
330 MCE.emitWordLE(
331 (0x0 << 26) | (0x0 << 21) | (src << 16) | (at << 11) | (0x8 << 6) | 0x2);
332 MCE.emitWordLE(
333 (0x28 << 26) | (base << 21) | (at << 16) | ((offset+1) & 0xffff));
334 return 3;
335}
336
337int MipsCodeEmitter::emitULH(const MachineInstr &MI) {
338 unsigned dst = getMachineOpValue(MI, MI.getOperand(0));
339 unsigned base = getMachineOpValue(MI, MI.getOperand(1));
340 unsigned offset = getMachineOpValue(MI, MI.getOperand(2));
341 unsigned at = 1;
342 // lbu at, offset(base)
343 // lb dst, offset+1(base)
344 // sll dst,dst,8
345 // or dst,dst,at
346 MCE.emitWordLE(
347 (0x24 << 26) | (base << 21) | (at << 16) | (offset & 0xffff));
348 MCE.emitWordLE(
349 (0x20 << 26) | (base << 21) | (dst << 16) | ((offset+1) & 0xffff));
350 MCE.emitWordLE(
351 (0x0 << 26) | (0x0 << 21) | (dst << 16) | (dst << 11) | (0x8 << 6) | 0x0);
352 MCE.emitWordLE(
353 (0x0 << 26) | (dst << 21) | (at << 16) | (dst << 11) | (0x0 << 6) | 0x25);
354 return 4;
355}
356
357int MipsCodeEmitter::emitULHu(const MachineInstr &MI) {
358 unsigned dst = getMachineOpValue(MI, MI.getOperand(0));
359 unsigned base = getMachineOpValue(MI, MI.getOperand(1));
360 unsigned offset = getMachineOpValue(MI, MI.getOperand(2));
361 unsigned at = 1;
362 // lbu at, offset(base)
363 // lbu dst, offset+1(base)
364 // sll dst,dst,8
365 // or dst,dst,at
366 MCE.emitWordLE(
367 (0x24 << 26) | (base << 21) | (at << 16) | (offset & 0xffff));
368 MCE.emitWordLE(
369 (0x24 << 26) | (base << 21) | (dst << 16) | ((offset+1) & 0xffff));
370 MCE.emitWordLE(
371 (0x0 << 26) | (0x0 << 21) | (dst << 16) | (dst << 11) | (0x8 << 6) | 0x0);
372 MCE.emitWordLE(
373 (0x0 << 26) | (dst << 21) | (at << 16) | (dst << 11) | (0x0 << 6) | 0x25);
374 return 4;
375}
376
Bruno Cardoso Lopesc4cc40c2011-09-14 03:00:41 +0000377void MipsCodeEmitter::emitInstruction(const MachineInstr &MI) {
378 DEBUG(errs() << "JIT: " << (void*)MCE.getCurrentPCValue() << ":\t" << MI);
379
380 MCE.processDebugLoc(MI.getDebugLoc(), true);
381
382 // Skip pseudo instructions.
383 if ((MI.getDesc().TSFlags & MipsII::FormMask) == MipsII::Pseudo)
384 return;
385
Bruno Cardoso Lopesc4cc40c2011-09-14 03:00:41 +0000386
387 switch (MI.getOpcode()) {
Bruno Cardoso Lopesad6eef42011-11-08 12:47:11 +0000388 case Mips::USW:
389 NumEmitted += emitUSW(MI);
390 break;
391 case Mips::ULW:
392 NumEmitted += emitULW(MI);
393 break;
394 case Mips::ULH:
395 NumEmitted += emitULH(MI);
396 break;
397 case Mips::ULHu:
398 NumEmitted += emitULHu(MI);
399 break;
400 case Mips::USH:
401 NumEmitted += emitUSH(MI);
402 break;
403
Bruno Cardoso Lopesc4cc40c2011-09-14 03:00:41 +0000404 default:
405 emitWordLE(getBinaryCodeForInstr(MI));
Bruno Cardoso Lopesad6eef42011-11-08 12:47:11 +0000406 ++NumEmitted; // Keep track of the # of mi's emitted
Bruno Cardoso Lopesc4cc40c2011-09-14 03:00:41 +0000407 break;
408 }
409
410 MCE.processDebugLoc(MI.getDebugLoc(), false);
411}
412
413void MipsCodeEmitter::emitWordLE(unsigned Word) {
414 DEBUG(errs() << " 0x";
415 errs().write_hex(Word) << "\n");
416 MCE.emitWordLE(Word);
417}
418
419/// createMipsJITCodeEmitterPass - Return a pass that emits the collected Mips
420/// code to the specified MCE object.
421FunctionPass *llvm::createMipsJITCodeEmitterPass(MipsTargetMachine &TM,
Bruno Cardoso Lopes47b92f32011-11-11 22:58:42 +0000422 JITCodeEmitter &JCE) {
Bruno Cardoso Lopesc4cc40c2011-09-14 03:00:41 +0000423 return new MipsCodeEmitter(TM, JCE);
424}
425
Bruno Cardoso Lopesc3f16b32011-10-18 17:50:36 +0000426#include "MipsGenCodeEmitter.inc"