blob: bf6ea414070757000afac173c98e6f05e2311c63 [file] [log] [blame]
Misha Brukman3d9a6c22004-08-11 00:09:42 +00001//===-- PPC32CodeEmitter.cpp - JIT Code Emitter for PowerPC32 -----*- C++ -*-=//
Misha Brukman5dfe3a92004-06-21 16:55:25 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
Misha Brukmand37faba2004-10-14 06:07:25 +000010// This file defines the PowerPC 32-bit CodeEmitter and associated machinery to
11// JIT-compile bytecode to native PowerPC.
Misha Brukman5dfe3a92004-06-21 16:55:25 +000012//
13//===----------------------------------------------------------------------===//
14
Misha Brukman3d9a6c22004-08-11 00:09:42 +000015#include "PPC32JITInfo.h"
16#include "PPC32TargetMachine.h"
Misha Brukmanb05daff2004-08-09 23:03:59 +000017#include "llvm/CodeGen/MachineCodeEmitter.h"
18#include "llvm/CodeGen/MachineFunctionPass.h"
19#include "llvm/CodeGen/Passes.h"
Reid Spencer551ccae2004-09-01 22:55:40 +000020#include "llvm/Support/Debug.h"
Misha Brukman5dfe3a92004-06-21 16:55:25 +000021
22namespace llvm {
23
Misha Brukmanb05daff2004-08-09 23:03:59 +000024namespace {
Misha Brukman3d9a6c22004-08-11 00:09:42 +000025 class PPC32CodeEmitter : public MachineFunctionPass {
Misha Brukmanb05daff2004-08-09 23:03:59 +000026 TargetMachine &TM;
27 MachineCodeEmitter &MCE;
28
Misha Brukmand37faba2004-10-14 06:07:25 +000029 int64_t getMachineOpValue(MachineInstr &MI, MachineOperand &MO);
30
Misha Brukmanb05daff2004-08-09 23:03:59 +000031 public:
Misha Brukman3d9a6c22004-08-11 00:09:42 +000032 PPC32CodeEmitter(TargetMachine &T, MachineCodeEmitter &M)
Misha Brukmanb05daff2004-08-09 23:03:59 +000033 : TM(T), MCE(M) {}
34
35 const char *getPassName() const { return "PowerPC Machine Code Emitter"; }
36
37 /// runOnMachineFunction - emits the given MachineFunction to memory
38 ///
39 bool runOnMachineFunction(MachineFunction &MF);
40
41 /// emitBasicBlock - emits the given MachineBasicBlock to memory
42 ///
43 void emitBasicBlock(MachineBasicBlock &MBB);
44
45 /// emitWord - write a 32-bit word to memory at the current PC
46 ///
47 void emitWord(unsigned w) { MCE.emitWord(w); }
Misha Brukmand37faba2004-10-14 06:07:25 +000048
49 /// getValueBit - return the particular bit of Val
50 ///
51 unsigned getValueBit(int64_t Val, unsigned bit) { return (Val >> bit) & 1; }
Misha Brukmanb05daff2004-08-09 23:03:59 +000052
53 /// getBinaryCodeForInstr - returns the assembled code for an instruction
54 ///
Misha Brukmand37faba2004-10-14 06:07:25 +000055 unsigned getBinaryCodeForInstr(MachineInstr &MI);
Misha Brukmanb05daff2004-08-09 23:03:59 +000056 };
57}
58
Misha Brukman5dfe3a92004-06-21 16:55:25 +000059/// addPassesToEmitMachineCode - Add passes to the specified pass manager to get
60/// machine code emitted. This uses a MachineCodeEmitter object to handle
61/// actually outputting the machine code and resolving things like the address
62/// of functions. This method should returns true if machine code emission is
63/// not supported.
64///
Misha Brukman3d9a6c22004-08-11 00:09:42 +000065bool PPC32TargetMachine::addPassesToEmitMachineCode(FunctionPassManager &PM,
66 MachineCodeEmitter &MCE) {
Misha Brukmanb05daff2004-08-09 23:03:59 +000067 // Machine code emitter pass for PowerPC
Misha Brukman3d9a6c22004-08-11 00:09:42 +000068 PM.add(new PPC32CodeEmitter(*this, MCE));
Misha Brukmand37faba2004-10-14 06:07:25 +000069 // Delete machine code for this function after emitting it
Misha Brukmanb05daff2004-08-09 23:03:59 +000070 PM.add(createMachineCodeDeleter());
71 // We don't yet support machine code emission
72 return true;
73}
74
Misha Brukman3d9a6c22004-08-11 00:09:42 +000075bool PPC32CodeEmitter::runOnMachineFunction(MachineFunction &MF) {
Misha Brukmanb05daff2004-08-09 23:03:59 +000076 MCE.startFunction(MF);
77 MCE.emitConstantPool(MF.getConstantPool());
78 for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I)
79 emitBasicBlock(*I);
80 MCE.finishFunction(MF);
81 return false;
82}
83
Misha Brukman3d9a6c22004-08-11 00:09:42 +000084void PPC32CodeEmitter::emitBasicBlock(MachineBasicBlock &MBB) {
Misha Brukmanb05daff2004-08-09 23:03:59 +000085 for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end(); I != E; ++I)
86 emitWord(getBinaryCodeForInstr(*I));
87}
88
Misha Brukmand37faba2004-10-14 06:07:25 +000089int64_t PPC32CodeEmitter::getMachineOpValue(MachineInstr &MI,
90 MachineOperand &MO) {
91 abort();
92 return 0;
Misha Brukman5dfe3a92004-06-21 16:55:25 +000093}
94
Misha Brukmand37faba2004-10-14 06:07:25 +000095
Misha Brukman3d9a6c22004-08-11 00:09:42 +000096void *PPC32JITInfo::getJITStubForFunction(Function *F,
97 MachineCodeEmitter &MCE) {
Misha Brukmand37faba2004-10-14 06:07:25 +000098 std::cerr << "PPC32JITInfo::getJITStubForFunction not implemented\n";
99 abort();
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000100 return 0;
101}
102
Misha Brukman3d9a6c22004-08-11 00:09:42 +0000103void PPC32JITInfo::replaceMachineCodeForFunction (void *Old, void *New) {
Misha Brukmand37faba2004-10-14 06:07:25 +0000104 std::cerr << "PPC32JITInfo::replaceMachineCodeForFunction not implemented\n";
105 abort();
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000106}
107
Misha Brukmand37faba2004-10-14 06:07:25 +0000108#include "PPC32GenCodeEmitter.inc"
Misha Brukmanb05daff2004-08-09 23:03:59 +0000109
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000110} // end llvm namespace
111