15 #define DEBUG_TYPE "jit"
44 STATISTIC(NumEmitted,
"Number of machine instructions emitted");
55 const std::vector<MachineConstantPoolEntry> *MCPEs;
56 const std::vector<MachineJumpTableEntry> *MJTEs;
69 TM(tm), MCE(mce), MCPEs(0), MJTEs(0),
70 IsPIC(
TM.getRelocationModel() == Reloc::
PIC_) {}
74 virtual const char *getPassName()
const {
75 return "Mips Machine Code Emitter";
88 void emitWord(
unsigned Word);
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;
107 unsigned getJumpTargetOpValue(
const MachineInstr &
MI,
unsigned OpNo)
const;
108 unsigned getJumpTargetOpValueMM(
const MachineInstr &
MI,
unsigned OpNo)
const;
110 unsigned OpNo)
const;
113 unsigned getMemEncoding(
const MachineInstr &
MI,
unsigned OpNo)
const;
114 unsigned getMemEncodingMMImm12(
const MachineInstr &
MI,
unsigned OpNo)
const;
115 unsigned getSizeExtEncoding(
const MachineInstr &
MI,
unsigned OpNo)
const;
116 unsigned getSizeInsEncoding(
const MachineInstr &
MI,
unsigned OpNo)
const;
117 unsigned getLSAImmEncoding(
const MachineInstr &
MI,
unsigned OpNo)
const;
119 void emitGlobalAddressUnaligned(
const GlobalValue *GV,
unsigned Reloc,
145 JTI->Initialize(MF, IsPIC, Subtarget->isLittle());
146 MCE.setModuleInfo(&getAnalysis<MachineModuleInfo> ());
151 MCE.startFunction(MF);
155 MCE.StartMachineBasicBlock(MBB);
157 E = MBB->instr_end();
I != E;)
158 emitInstruction(*
I++, *MBB);
160 }
while (MCE.finishFunction(MF));
180 unsigned MipsCodeEmitter::getJumpTargetOpValue(
const MachineInstr &MI,
181 unsigned OpNo)
const {
184 emitGlobalAddress(MO.
getGlobal(), getRelocation(MI, MO),
true);
186 emitExternalSymbolAddress(MO.
getSymbolName(), getRelocation(MI, MO));
188 emitMachineBasicBlock(MO.
getMBB(), getRelocation(MI, MO));
194 unsigned MipsCodeEmitter::getJumpTargetOpValueMM(
const MachineInstr &MI,
195 unsigned OpNo)
const {
200 unsigned MipsCodeEmitter::getBranchTargetOpValueMM(
const MachineInstr &MI,
201 unsigned OpNo)
const {
207 unsigned OpNo)
const {
209 emitMachineBasicBlock(MO.
getMBB(), getRelocation(MI, MO));
213 unsigned MipsCodeEmitter::getMemEncoding(
const MachineInstr &MI,
214 unsigned OpNo)
const {
217 unsigned RegBits = getMachineOpValue(MI, MI.
getOperand(OpNo)) << 16;
218 return (getMachineOpValue(MI, MI.
getOperand(OpNo+1)) & 0xFFFF) | RegBits;
221 unsigned MipsCodeEmitter::getMemEncodingMMImm12(
const MachineInstr &MI,
222 unsigned OpNo)
const {
227 unsigned MipsCodeEmitter::getSizeExtEncoding(
const MachineInstr &MI,
228 unsigned OpNo)
const {
230 return getMachineOpValue(MI, MI.
getOperand(OpNo)) - 1;
233 unsigned MipsCodeEmitter::getSizeInsEncoding(
const MachineInstr &MI,
234 unsigned OpNo)
const {
236 return getMachineOpValue(MI, MI.
getOperand(OpNo-1)) +
237 getMachineOpValue(MI, MI.
getOperand(OpNo)) - 1;
240 unsigned MipsCodeEmitter::getLSAImmEncoding(
const MachineInstr &MI,
241 unsigned OpNo)
const {
248 unsigned MipsCodeEmitter::getMachineOpValue(
const MachineInstr &MI,
251 return TM.getRegisterInfo()->getEncodingValue(MO.
getReg());
253 return static_cast<unsigned>(MO.
getImm());
255 emitGlobalAddress(MO.
getGlobal(), getRelocation(MI, MO),
true);
257 emitExternalSymbolAddress(MO.
getSymbolName(), getRelocation(MI, MO));
259 emitConstPoolAddress(MO.
getIndex(), getRelocation(MI, MO));
261 emitJumpTableAddress(MO.
getIndex(), getRelocation(MI, MO));
263 emitMachineBasicBlock(MO.
getMBB(), getRelocation(MI, MO));
269 void MipsCodeEmitter::emitGlobalAddress(
const GlobalValue *GV,
unsigned Reloc,
270 bool MayNeedFarStub)
const {
276 void MipsCodeEmitter::emitGlobalAddressUnaligned(
const GlobalValue *GV,
277 unsigned Reloc,
int Offset)
const {
284 void MipsCodeEmitter::
285 emitExternalSymbolAddress(
const char *ES,
unsigned Reloc)
const {
290 void MipsCodeEmitter::emitConstPoolAddress(
unsigned CPI,
unsigned Reloc)
const {
292 Reloc, CPI, 0,
false));
295 void MipsCodeEmitter::
296 emitJumpTableAddress(
unsigned JTIndex,
unsigned Reloc)
const {
298 Reloc, JTIndex, 0,
false));
302 unsigned Reloc)
const {
309 DEBUG(
errs() <<
"JIT: " << (
void*)MCE.getCurrentPCValue() <<
":\t" << *
MI);
313 !expandPseudos(MI, MBB))
316 MCE.processDebugLoc(MI->getDebugLoc(),
true);
318 emitWord(getBinaryCodeForInstr(*MI));
321 MCE.processDebugLoc(MI->getDebugLoc(),
false);
324 void MipsCodeEmitter::emitWord(
unsigned Word) {
327 if (Subtarget->isLittle())
328 MCE.emitWordLE(Word);
330 MCE.emitWordBE(Word);
335 unsigned Opc)
const {
337 BuildMI(MBB, &*MI, MI->getDebugLoc(), II->get(Opc))
338 .addReg(MI->getOperand(1).getReg()).addReg(MI->getOperand(2).getReg());
343 switch (MI->getOpcode()) {
345 BuildMI(MBB, &*MI, MI->getDebugLoc(), II->get(Mips::SLL), Mips::ZERO)
346 .addReg(Mips::ZERO).
addImm(0);
349 BuildMI(MBB, &*MI, MI->getDebugLoc(), II->get(Mips::BEQ)).addReg(Mips::ZERO)
353 BuildMI(MBB, &*MI, MI->getDebugLoc(), II->get(Mips::BREAK)).addImm(0)
356 case Mips::JALRPseudo:
357 BuildMI(MBB, &*MI, MI->getDebugLoc(), II->get(Mips::JALR), Mips::RA)
358 .addReg(MI->getOperand(0).getReg());
360 case Mips::PseudoMULT:
363 case Mips::PseudoMULTu:
364 expandACCInstr(MI, MBB, Mips::MULTu);
366 case Mips::PseudoSDIV:
369 case Mips::PseudoUDIV:
372 case Mips::PseudoMADD:
373 expandACCInstr(MI, MBB, Mips::MADD);
375 case Mips::PseudoMADDU:
376 expandACCInstr(MI, MBB, Mips::MADDU);
378 case Mips::PseudoMSUB:
379 expandACCInstr(MI, MBB, Mips::MSUB);
381 case Mips::PseudoMSUBU:
382 expandACCInstr(MI, MBB, Mips::MSUBU);
388 (MI--)->eraseFromBundle();
396 return new MipsCodeEmitter(TM, JCE);
399 #include "MipsGenCodeEmitter.inc"
const GlobalValue * getGlobal() const
bool isBranch(QueryType Type=AnyInBundle) const
virtual const MipsInstrInfo * getInstrInfo() const
MachineBasicBlock * getMBB() const
FrmFI - This form is for instructions of the format FI.
const MCInstrDesc & getDesc() const
const char * getSymbolName() const
virtual MipsJITInfo * getJITInfo()
Instructions::iterator instr_iterator
FrmJ - This form is for instructions of the format J.
const std::vector< MachineJumpTableEntry > & getJumpTables() const
bool isJTI() const
isJTI - Tests if this is a MO_JumpTableIndex operand.
AnalysisUsage & addRequired()
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
#define llvm_unreachable(msg)
bool isReg() const
isReg - Tests if this is a MO_Register operand.
ID
LLVM Calling Convention Representation.
const MachineInstrBuilder & addImm(int64_t Val) const
static uint32_t getBranchTargetOpValue(const MCInst &MI, unsigned OpIdx, unsigned FixupKind, SmallVectorImpl< MCFixup > &Fixups)
bool isCPI() const
isCPI - Tests if this is a MO_ConstantPoolIndex operand.
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
raw_ostream & write_hex(unsigned long long N)
write_hex - Output N in hexadecimal, without any prefix or padding.
const MachineJumpTableInfo * getJumpTableInfo() const
static MachineRelocation getBB(uintptr_t offset, unsigned RelocationType, MachineBasicBlock *MBB, intptr_t cst=0)
const MachineOperand & getOperand(unsigned i) const
bool isSymbol() const
isSymbol - Tests if this is a MO_ExternalSymbol operand.
TRAP - Trapping instruction.
MachineConstantPool * getConstantPool()
MachineInstrBuilder BuildMI(MachineFunction &MF, DebugLoc DL, const MCInstrDesc &MCID)
FunctionPass * createMipsJITCodeEmitterPass(MipsTargetMachine &TM, JITCodeEmitter &JCE)
virtual const DataLayout * getDataLayout() const
bool isMBB() const
isMBB - Tests if this is a MO_MachineBasicBlock operand.
static MachineRelocation getGV(uintptr_t offset, unsigned RelocationType, GlobalValue *GV, intptr_t cst=0, bool MayNeedFarStub=0, bool GOTrelative=0)
STATISTIC(NumEmitted,"Number of machine instructions emitted")
FrmI - This form is for instructions of the format I.
virtual void getAnalysisUsage(AnalysisUsage &AU) const
const TargetMachine & getTarget() const
static MachineRelocation getJumpTable(uintptr_t offset, unsigned RelocationType, unsigned JTI, intptr_t cst=0, bool letTargetResolve=false)
unsigned getReg() const
getReg - Returns the register number.
static MachineRelocation getConstPool(uintptr_t offset, unsigned RelocationType, unsigned CPI, intptr_t cst=0, bool letTargetResolve=false)
const MachineInstrBuilder & addOperand(const MachineOperand &MO) const
BasicBlockListType::iterator iterator
const std::vector< MachineConstantPoolEntry > & getConstants() const
StringRef getName() const
static MachineRelocation getExtSym(uintptr_t offset, unsigned RelocationType, const char *ES, intptr_t cst=0, bool GOTrelative=0, bool NeedStub=true)
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
INITIALIZE_PASS(GlobalMerge,"global-merge","Global Merge", false, false) bool GlobalMerge const DataLayout * TD