blob: f4e1e1848ee90c13beb4600849f35431cafb489b [file] [log] [blame]
Jia Liu9f610112012-02-17 08:55:11 +00001//===-- Mips/MipsCodeEmitter.cpp - Convert Mips Code to Machine Code ------===//
Bruno Cardoso Lopesd1d9c782011-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"
Chandler Carruthed0881b2012-12-03 16:50:05 +000017#include "MCTargetDesc/MipsBaseInfo.h"
Bruno Cardoso Lopesd1d9c782011-07-21 16:28:51 +000018#include "MipsInstrInfo.h"
19#include "MipsRelocations.h"
20#include "MipsSubtarget.h"
21#include "MipsTargetMachine.h"
Bruno Cardoso Lopesc85e3ff2011-11-11 22:58:42 +000022#include "llvm/ADT/Statistic.h"
Bruno Cardoso Lopesd1d9c782011-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"
Akira Hatanakabf1af1a2013-02-11 22:35:40 +000028#include "llvm/CodeGen/MachineInstrBuilder.h"
Bruno Cardoso Lopesd1d9c782011-07-21 16:28:51 +000029#include "llvm/CodeGen/MachineModuleInfo.h"
Bruno Cardoso Lopesc85e3ff2011-11-11 22:58:42 +000030#include "llvm/CodeGen/MachineOperand.h"
Bruno Cardoso Lopesd1d9c782011-07-21 16:28:51 +000031#include "llvm/CodeGen/Passes.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000032#include "llvm/IR/Constants.h"
33#include "llvm/IR/DerivedTypes.h"
Bruno Cardoso Lopesc85e3ff2011-11-11 22:58:42 +000034#include "llvm/PassManager.h"
Bruno Cardoso Lopesd1d9c782011-07-21 16:28:51 +000035#include "llvm/Support/Debug.h"
36#include "llvm/Support/ErrorHandling.h"
37#include "llvm/Support/raw_ostream.h"
38#ifndef NDEBUG
39#include <iomanip>
40#endif
41
Bruno Cardoso Lopesd1d9c782011-07-21 16:28:51 +000042using namespace llvm;
43
Bruno Cardoso Lopes483c2692011-09-14 03:00:41 +000044STATISTIC(NumEmitted, "Number of machine instructions emitted");
45
Bruno Cardoso Lopesd1d9c782011-07-21 16:28:51 +000046namespace {
47
48class MipsCodeEmitter : public MachineFunctionPass {
49 MipsJITInfo *JTI;
50 const MipsInstrInfo *II;
Micah Villmowcdfe20b2012-10-08 16:38:25 +000051 const DataLayout *TD;
Bruno Cardoso Lopesd1d9c782011-07-21 16:28:51 +000052 const MipsSubtarget *Subtarget;
53 TargetMachine &TM;
54 JITCodeEmitter &MCE;
55 const std::vector<MachineConstantPoolEntry> *MCPEs;
56 const std::vector<MachineJumpTableEntry> *MJTEs;
57 bool IsPIC;
58
59 void getAnalysisUsage(AnalysisUsage &AU) const {
60 AU.addRequired<MachineModuleInfo> ();
61 MachineFunctionPass::getAnalysisUsage(AU);
62 }
63
64 static char ID;
65
Akira Hatanaka3d386092013-02-11 22:03:52 +000066public:
67 MipsCodeEmitter(TargetMachine &tm, JITCodeEmitter &mce)
Bill Wendlingead89ef2013-06-07 07:04:14 +000068 : MachineFunctionPass(ID), JTI(0), II(0), TD(0),
Akira Hatanaka3d386092013-02-11 22:03:52 +000069 TM(tm), MCE(mce), MCPEs(0), MJTEs(0),
70 IsPIC(TM.getRelocationModel() == Reloc::PIC_) {}
Bruno Cardoso Lopesd1d9c782011-07-21 16:28:51 +000071
Akira Hatanaka3d386092013-02-11 22:03:52 +000072 bool runOnMachineFunction(MachineFunction &MF);
Bruno Cardoso Lopesd1d9c782011-07-21 16:28:51 +000073
Akira Hatanaka3d386092013-02-11 22:03:52 +000074 virtual const char *getPassName() const {
75 return "Mips Machine Code Emitter";
76 }
Bruno Cardoso Lopesd1d9c782011-07-21 16:28:51 +000077
Akira Hatanaka3d386092013-02-11 22:03:52 +000078 /// getBinaryCodeForInstr - This function, generated by the
79 /// CodeEmitterGenerator using TableGen, produces the binary encoding for
80 /// machine instructions.
81 uint64_t getBinaryCodeForInstr(const MachineInstr &MI) const;
Bruno Cardoso Lopes483c2692011-09-14 03:00:41 +000082
Akira Hatanakabf1af1a2013-02-11 22:35:40 +000083 void emitInstruction(MachineBasicBlock::instr_iterator MI,
84 MachineBasicBlock &MBB);
Bruno Cardoso Lopesd1d9c782011-07-21 16:28:51 +000085
Akira Hatanaka3d386092013-02-11 22:03:52 +000086private:
Bruno Cardoso Lopesd1d9c782011-07-21 16:28:51 +000087
Akira Hatanaka3d386092013-02-11 22:03:52 +000088 void emitWord(unsigned Word);
Bruno Cardoso Lopes483c2692011-09-14 03:00:41 +000089
Akira Hatanaka3d386092013-02-11 22:03:52 +000090 /// Routines that handle operands which add machine relocations which are
91 /// fixed up by the relocation stage.
92 void emitGlobalAddress(const GlobalValue *GV, unsigned Reloc,
93 bool MayNeedFarStub) const;
94 void emitExternalSymbolAddress(const char *ES, unsigned Reloc) const;
95 void emitConstPoolAddress(unsigned CPI, unsigned Reloc) const;
96 void emitJumpTableAddress(unsigned JTIndex, unsigned Reloc) const;
97 void emitMachineBasicBlock(MachineBasicBlock *BB, unsigned Reloc) const;
Bruno Cardoso Lopes483c2692011-09-14 03:00:41 +000098
Akira Hatanaka3d386092013-02-11 22:03:52 +000099 /// 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;
Bruno Cardoso Lopes483c2692011-09-14 03:00:41 +0000103
Akira Hatanaka3d386092013-02-11 22:03:52 +0000104 unsigned getRelocation(const MachineInstr &MI,
105 const MachineOperand &MO) const;
Bruno Cardoso Lopes483c2692011-09-14 03:00:41 +0000106
Akira Hatanaka3d386092013-02-11 22:03:52 +0000107 unsigned getJumpTargetOpValue(const MachineInstr &MI, unsigned OpNo) const;
Zoran Jovanovic507e0842013-10-29 16:38:59 +0000108 unsigned getJumpTargetOpValueMM(const MachineInstr &MI, unsigned OpNo) const;
Zoran Jovanovic8a80aa72013-11-04 14:53:22 +0000109 unsigned getBranchTargetOpValueMM(const MachineInstr &MI,
110 unsigned OpNo) const;
Bruno Cardoso Lopesc85e3ff2011-11-11 22:58:42 +0000111
Akira Hatanaka3d386092013-02-11 22:03:52 +0000112 unsigned getBranchTargetOpValue(const MachineInstr &MI, unsigned OpNo) const;
113 unsigned getMemEncoding(const MachineInstr &MI, unsigned OpNo) const;
Jack Carter97700972013-08-13 20:19:16 +0000114 unsigned getMemEncodingMMImm12(const MachineInstr &MI, unsigned OpNo) const;
Akira Hatanaka3d386092013-02-11 22:03:52 +0000115 unsigned getSizeExtEncoding(const MachineInstr &MI, unsigned OpNo) const;
116 unsigned getSizeInsEncoding(const MachineInstr &MI, unsigned OpNo) const;
Bruno Cardoso Lopes71133fe2011-11-08 12:47:11 +0000117
Akira Hatanaka3d386092013-02-11 22:03:52 +0000118 void emitGlobalAddressUnaligned(const GlobalValue *GV, unsigned Reloc,
119 int Offset) const;
Akira Hatanakabf1af1a2013-02-11 22:35:40 +0000120
Akira Hatanaka2ffc5732013-04-02 22:53:58 +0000121 /// Expand pseudo instructions with accumulator register operands.
Akira Hatanaka52f79fc2013-04-11 19:07:14 +0000122 void expandACCInstr(MachineBasicBlock::instr_iterator MI,
Akira Hatanaka2ffc5732013-04-02 22:53:58 +0000123 MachineBasicBlock &MBB, unsigned Opc) const;
124
Akira Hatanakabf1af1a2013-02-11 22:35:40 +0000125 /// \brief Expand pseudo instruction. Return true if MI was expanded.
126 bool expandPseudos(MachineBasicBlock::instr_iterator &MI,
127 MachineBasicBlock &MBB) const;
Akira Hatanaka3d386092013-02-11 22:03:52 +0000128};
Bruno Cardoso Lopesd1d9c782011-07-21 16:28:51 +0000129}
130
Bruno Cardoso Lopes483c2692011-09-14 03:00:41 +0000131char MipsCodeEmitter::ID = 0;
Bruno Cardoso Lopesd1d9c782011-07-21 16:28:51 +0000132
133bool MipsCodeEmitter::runOnMachineFunction(MachineFunction &MF) {
Dmitri Gribenko2e1df0e2013-01-14 22:08:37 +0000134 MipsTargetMachine &Target = static_cast<MipsTargetMachine &>(
135 const_cast<TargetMachine &>(MF.getTarget()));
136
137 JTI = Target.getJITInfo();
138 II = Target.getInstrInfo();
139 TD = Target.getDataLayout();
Bruno Cardoso Lopesd1d9c782011-07-21 16:28:51 +0000140 Subtarget = &TM.getSubtarget<MipsSubtarget> ();
141 MCPEs = &MF.getConstantPool()->getConstants();
142 MJTEs = 0;
143 if (MF.getJumpTableInfo()) MJTEs = &MF.getJumpTableInfo()->getJumpTables();
Akira Hatanaka4c128502012-12-03 23:11:12 +0000144 JTI->Initialize(MF, IsPIC, Subtarget->isLittle());
Bruno Cardoso Lopesd1d9c782011-07-21 16:28:51 +0000145 MCE.setModuleInfo(&getAnalysis<MachineModuleInfo> ());
146
147 do {
148 DEBUG(errs() << "JITTing function '"
Craig Toppera538d832012-08-22 06:07:19 +0000149 << MF.getName() << "'\n");
Bruno Cardoso Lopesd1d9c782011-07-21 16:28:51 +0000150 MCE.startFunction(MF);
151
152 for (MachineFunction::iterator MBB = MF.begin(), E = MF.end();
153 MBB != E; ++MBB){
154 MCE.StartMachineBasicBlock(MBB);
Akira Hatanaka98462392012-06-19 03:39:45 +0000155 for (MachineBasicBlock::instr_iterator I = MBB->instr_begin(),
Akira Hatanakabf1af1a2013-02-11 22:35:40 +0000156 E = MBB->instr_end(); I != E;)
157 emitInstruction(*I++, *MBB);
Bruno Cardoso Lopesd1d9c782011-07-21 16:28:51 +0000158 }
159 } while (MCE.finishFunction(MF));
160
161 return false;
162}
163
Bruno Cardoso Lopes483c2692011-09-14 03:00:41 +0000164unsigned MipsCodeEmitter::getRelocation(const MachineInstr &MI,
165 const MachineOperand &MO) const {
166 // NOTE: This relocations are for static.
167 uint64_t TSFlags = MI.getDesc().TSFlags;
168 uint64_t Form = TSFlags & MipsII::FormMask;
169 if (Form == MipsII::FrmJ)
170 return Mips::reloc_mips_26;
171 if ((Form == MipsII::FrmI || Form == MipsII::FrmFI)
Evan Cheng7f8e5632011-12-07 07:15:52 +0000172 && MI.isBranch())
Bruno Cardoso Lopesd5b28342011-12-30 21:04:30 +0000173 return Mips::reloc_mips_pc16;
Bruno Cardoso Lopes483c2692011-09-14 03:00:41 +0000174 if (Form == MipsII::FrmI && MI.getOpcode() == Mips::LUi)
175 return Mips::reloc_mips_hi;
176 return Mips::reloc_mips_lo;
Bruno Cardoso Lopesd1d9c782011-07-21 16:28:51 +0000177}
178
Bruno Cardoso Lopesc85e3ff2011-11-11 22:58:42 +0000179unsigned MipsCodeEmitter::getJumpTargetOpValue(const MachineInstr &MI,
180 unsigned OpNo) const {
Bruno Cardoso Lopesd5b28342011-12-30 21:04:30 +0000181 MachineOperand MO = MI.getOperand(OpNo);
182 if (MO.isGlobal())
183 emitGlobalAddress(MO.getGlobal(), getRelocation(MI, MO), true);
184 else if (MO.isSymbol())
185 emitExternalSymbolAddress(MO.getSymbolName(), getRelocation(MI, MO));
186 else if (MO.isMBB())
187 emitMachineBasicBlock(MO.getMBB(), getRelocation(MI, MO));
188 else
189 llvm_unreachable("Unexpected jump target operand kind.");
Bruno Cardoso Lopesc85e3ff2011-11-11 22:58:42 +0000190 return 0;
191}
192
Zoran Jovanovic507e0842013-10-29 16:38:59 +0000193unsigned MipsCodeEmitter::getJumpTargetOpValueMM(const MachineInstr &MI,
194 unsigned OpNo) const {
195 llvm_unreachable("Unimplemented function.");
196 return 0;
197}
198
Zoran Jovanovic8a80aa72013-11-04 14:53:22 +0000199unsigned MipsCodeEmitter::getBranchTargetOpValueMM(const MachineInstr &MI,
200 unsigned OpNo) const {
201 llvm_unreachable("Unimplemented function.");
202 return 0;
203}
204
Bruno Cardoso Lopesc85e3ff2011-11-11 22:58:42 +0000205unsigned MipsCodeEmitter::getBranchTargetOpValue(const MachineInstr &MI,
206 unsigned OpNo) const {
Bruno Cardoso Lopesd5b28342011-12-30 21:04:30 +0000207 MachineOperand MO = MI.getOperand(OpNo);
208 emitMachineBasicBlock(MO.getMBB(), getRelocation(MI, MO));
Bruno Cardoso Lopesc85e3ff2011-11-11 22:58:42 +0000209 return 0;
210}
211
Bruno Cardoso Lopes2312a3a2011-10-18 17:50:36 +0000212unsigned MipsCodeEmitter::getMemEncoding(const MachineInstr &MI,
Bruno Cardoso Lopesc85e3ff2011-11-11 22:58:42 +0000213 unsigned OpNo) const {
Bruno Cardoso Lopes2312a3a2011-10-18 17:50:36 +0000214 // Base register is encoded in bits 20-16, offset is encoded in bits 15-0.
215 assert(MI.getOperand(OpNo).isReg());
216 unsigned RegBits = getMachineOpValue(MI, MI.getOperand(OpNo)) << 16;
Bruno Cardoso Lopesc85e3ff2011-11-11 22:58:42 +0000217 return (getMachineOpValue(MI, MI.getOperand(OpNo+1)) & 0xFFFF) | RegBits;
Bruno Cardoso Lopes2312a3a2011-10-18 17:50:36 +0000218}
219
Jack Carter97700972013-08-13 20:19:16 +0000220unsigned MipsCodeEmitter::getMemEncodingMMImm12(const MachineInstr &MI,
221 unsigned OpNo) const {
222 llvm_unreachable("Unimplemented function.");
223 return 0;
224}
225
Bruno Cardoso Lopes2312a3a2011-10-18 17:50:36 +0000226unsigned MipsCodeEmitter::getSizeExtEncoding(const MachineInstr &MI,
Bruno Cardoso Lopesc85e3ff2011-11-11 22:58:42 +0000227 unsigned OpNo) const {
Bruno Cardoso Lopes2312a3a2011-10-18 17:50:36 +0000228 // size is encoded as size-1.
229 return getMachineOpValue(MI, MI.getOperand(OpNo)) - 1;
230}
231
232unsigned MipsCodeEmitter::getSizeInsEncoding(const MachineInstr &MI,
Bruno Cardoso Lopesc85e3ff2011-11-11 22:58:42 +0000233 unsigned OpNo) const {
Bruno Cardoso Lopes2312a3a2011-10-18 17:50:36 +0000234 // size is encoded as pos+size-1.
235 return getMachineOpValue(MI, MI.getOperand(OpNo-1)) +
236 getMachineOpValue(MI, MI.getOperand(OpNo)) - 1;
237}
238
Bruno Cardoso Lopes483c2692011-09-14 03:00:41 +0000239/// getMachineOpValue - Return binary encoding of operand. If the machine
240/// operand requires relocation, record the relocation and return zero.
241unsigned MipsCodeEmitter::getMachineOpValue(const MachineInstr &MI,
Bruno Cardoso Lopesc85e3ff2011-11-11 22:58:42 +0000242 const MachineOperand &MO) const {
Bruno Cardoso Lopes483c2692011-09-14 03:00:41 +0000243 if (MO.isReg())
Akira Hatanaka5d6faed2012-12-10 20:04:40 +0000244 return TM.getRegisterInfo()->getEncodingValue(MO.getReg());
Bruno Cardoso Lopes483c2692011-09-14 03:00:41 +0000245 else if (MO.isImm())
246 return static_cast<unsigned>(MO.getImm());
Akira Hatanaka3e7ba762012-09-15 01:52:08 +0000247 else if (MO.isGlobal())
248 emitGlobalAddress(MO.getGlobal(), getRelocation(MI, MO), true);
249 else if (MO.isSymbol())
Bruno Cardoso Lopes483c2692011-09-14 03:00:41 +0000250 emitExternalSymbolAddress(MO.getSymbolName(), getRelocation(MI, MO));
251 else if (MO.isCPI())
252 emitConstPoolAddress(MO.getIndex(), getRelocation(MI, MO));
253 else if (MO.isJTI())
254 emitJumpTableAddress(MO.getIndex(), getRelocation(MI, MO));
255 else if (MO.isMBB())
256 emitMachineBasicBlock(MO.getMBB(), getRelocation(MI, MO));
257 else
258 llvm_unreachable("Unable to encode MachineOperand!");
259 return 0;
260}
261
262void MipsCodeEmitter::emitGlobalAddress(const GlobalValue *GV, unsigned Reloc,
Bruno Cardoso Lopesc85e3ff2011-11-11 22:58:42 +0000263 bool MayNeedFarStub) const {
Bruno Cardoso Lopes483c2692011-09-14 03:00:41 +0000264 MCE.addRelocation(MachineRelocation::getGV(MCE.getCurrentPCOffset(), Reloc,
Bruno Cardoso Lopesc85e3ff2011-11-11 22:58:42 +0000265 const_cast<GlobalValue *>(GV), 0,
266 MayNeedFarStub));
Bruno Cardoso Lopes483c2692011-09-14 03:00:41 +0000267}
268
Bruno Cardoso Lopes71133fe2011-11-08 12:47:11 +0000269void MipsCodeEmitter::emitGlobalAddressUnaligned(const GlobalValue *GV,
270 unsigned Reloc, int Offset) const {
271 MCE.addRelocation(MachineRelocation::getGV(MCE.getCurrentPCOffset(), Reloc,
272 const_cast<GlobalValue *>(GV), 0, false));
273 MCE.addRelocation(MachineRelocation::getGV(MCE.getCurrentPCOffset() + Offset,
274 Reloc, const_cast<GlobalValue *>(GV), 0, false));
275}
276
Bruno Cardoso Lopes483c2692011-09-14 03:00:41 +0000277void MipsCodeEmitter::
278emitExternalSymbolAddress(const char *ES, unsigned Reloc) const {
279 MCE.addRelocation(MachineRelocation::getExtSym(MCE.getCurrentPCOffset(),
Akira Hatanaka45da9e22012-07-24 00:08:26 +0000280 Reloc, ES, 0, 0));
Bruno Cardoso Lopes483c2692011-09-14 03:00:41 +0000281}
282
283void MipsCodeEmitter::emitConstPoolAddress(unsigned CPI, unsigned Reloc) const {
284 MCE.addRelocation(MachineRelocation::getConstPool(MCE.getCurrentPCOffset(),
285 Reloc, CPI, 0, false));
286}
287
288void MipsCodeEmitter::
289emitJumpTableAddress(unsigned JTIndex, unsigned Reloc) const {
290 MCE.addRelocation(MachineRelocation::getJumpTable(MCE.getCurrentPCOffset(),
291 Reloc, JTIndex, 0, false));
292}
293
294void MipsCodeEmitter::emitMachineBasicBlock(MachineBasicBlock *BB,
Bruno Cardoso Lopesc85e3ff2011-11-11 22:58:42 +0000295 unsigned Reloc) const {
Bruno Cardoso Lopes483c2692011-09-14 03:00:41 +0000296 MCE.addRelocation(MachineRelocation::getBB(MCE.getCurrentPCOffset(),
297 Reloc, BB));
298}
299
Akira Hatanakabf1af1a2013-02-11 22:35:40 +0000300void MipsCodeEmitter::emitInstruction(MachineBasicBlock::instr_iterator MI,
301 MachineBasicBlock &MBB) {
302 DEBUG(errs() << "JIT: " << (void*)MCE.getCurrentPCValue() << ":\t" << *MI);
Bruno Cardoso Lopes483c2692011-09-14 03:00:41 +0000303
Akira Hatanakabf1af1a2013-02-11 22:35:40 +0000304 // Expand pseudo instruction. Skip if MI was not expanded.
305 if (((MI->getDesc().TSFlags & MipsII::FormMask) == MipsII::Pseudo) &&
306 !expandPseudos(MI, MBB))
Bruno Cardoso Lopes483c2692011-09-14 03:00:41 +0000307 return;
308
Akira Hatanakabf1af1a2013-02-11 22:35:40 +0000309 MCE.processDebugLoc(MI->getDebugLoc(), true);
310
311 emitWord(getBinaryCodeForInstr(*MI));
Akira Hatanaka3e7ba762012-09-15 01:52:08 +0000312 ++NumEmitted; // Keep track of the # of mi's emitted
Bruno Cardoso Lopes483c2692011-09-14 03:00:41 +0000313
Akira Hatanakabf1af1a2013-02-11 22:35:40 +0000314 MCE.processDebugLoc(MI->getDebugLoc(), false);
Bruno Cardoso Lopes483c2692011-09-14 03:00:41 +0000315}
316
Akira Hatanaka4c128502012-12-03 23:11:12 +0000317void MipsCodeEmitter::emitWord(unsigned Word) {
Bruno Cardoso Lopes483c2692011-09-14 03:00:41 +0000318 DEBUG(errs() << " 0x";
319 errs().write_hex(Word) << "\n");
Akira Hatanaka4c128502012-12-03 23:11:12 +0000320 if (Subtarget->isLittle())
321 MCE.emitWordLE(Word);
322 else
323 MCE.emitWordBE(Word);
Bruno Cardoso Lopes483c2692011-09-14 03:00:41 +0000324}
325
Akira Hatanaka52f79fc2013-04-11 19:07:14 +0000326void MipsCodeEmitter::expandACCInstr(MachineBasicBlock::instr_iterator MI,
Akira Hatanaka2ffc5732013-04-02 22:53:58 +0000327 MachineBasicBlock &MBB,
328 unsigned Opc) const {
329 // Expand "pseudomult $ac0, $t0, $t1" to "mult $t0, $t1".
330 BuildMI(MBB, &*MI, MI->getDebugLoc(), II->get(Opc))
331 .addReg(MI->getOperand(1).getReg()).addReg(MI->getOperand(2).getReg());
332}
333
Akira Hatanakabf1af1a2013-02-11 22:35:40 +0000334bool MipsCodeEmitter::expandPseudos(MachineBasicBlock::instr_iterator &MI,
335 MachineBasicBlock &MBB) const {
336 switch (MI->getOpcode()) {
337 case Mips::NOP:
338 BuildMI(MBB, &*MI, MI->getDebugLoc(), II->get(Mips::SLL), Mips::ZERO)
339 .addReg(Mips::ZERO).addImm(0);
340 break;
Akira Hatanaka2c544d82013-09-06 23:40:15 +0000341 case Mips::B:
342 BuildMI(MBB, &*MI, MI->getDebugLoc(), II->get(Mips::BEQ)).addReg(Mips::ZERO)
343 .addReg(Mips::ZERO).addOperand(MI->getOperand(0));
344 break;
Akira Hatanaka79e38cd2013-09-06 23:52:46 +0000345 case Mips::TRAP:
346 BuildMI(MBB, &*MI, MI->getDebugLoc(), II->get(Mips::BREAK)).addImm(0)
347 .addImm(0);
348 break;
Akira Hatanakabf1af1a2013-02-11 22:35:40 +0000349 case Mips::JALRPseudo:
350 BuildMI(MBB, &*MI, MI->getDebugLoc(), II->get(Mips::JALR), Mips::RA)
351 .addReg(MI->getOperand(0).getReg());
352 break;
Akira Hatanaka2ffc5732013-04-02 22:53:58 +0000353 case Mips::PseudoMULT:
354 expandACCInstr(MI, MBB, Mips::MULT);
355 break;
356 case Mips::PseudoMULTu:
357 expandACCInstr(MI, MBB, Mips::MULTu);
358 break;
359 case Mips::PseudoSDIV:
360 expandACCInstr(MI, MBB, Mips::SDIV);
361 break;
362 case Mips::PseudoUDIV:
363 expandACCInstr(MI, MBB, Mips::UDIV);
364 break;
365 case Mips::PseudoMADD:
366 expandACCInstr(MI, MBB, Mips::MADD);
367 break;
368 case Mips::PseudoMADDU:
369 expandACCInstr(MI, MBB, Mips::MADDU);
370 break;
371 case Mips::PseudoMSUB:
372 expandACCInstr(MI, MBB, Mips::MSUB);
373 break;
374 case Mips::PseudoMSUBU:
375 expandACCInstr(MI, MBB, Mips::MSUBU);
376 break;
Akira Hatanakabf1af1a2013-02-11 22:35:40 +0000377 default:
378 return false;
379 }
380
381 (MI--)->eraseFromBundle();
382 return true;
383}
384
Bruno Cardoso Lopes483c2692011-09-14 03:00:41 +0000385/// createMipsJITCodeEmitterPass - Return a pass that emits the collected Mips
386/// code to the specified MCE object.
387FunctionPass *llvm::createMipsJITCodeEmitterPass(MipsTargetMachine &TM,
Bruno Cardoso Lopesc85e3ff2011-11-11 22:58:42 +0000388 JITCodeEmitter &JCE) {
Bruno Cardoso Lopes483c2692011-09-14 03:00:41 +0000389 return new MipsCodeEmitter(TM, JCE);
390}
391
Bruno Cardoso Lopes2312a3a2011-10-18 17:50:36 +0000392#include "MipsGenCodeEmitter.inc"