Misha Brukman | 3d9a6c2 | 2004-08-11 00:09:42 +0000 | [diff] [blame] | 1 | //===-- PPC32CodeEmitter.cpp - JIT Code Emitter for PowerPC32 -----*- C++ -*-=// |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 2 | // |
| 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 Brukman | d37faba | 2004-10-14 06:07:25 +0000 | [diff] [blame] | 10 | // This file defines the PowerPC 32-bit CodeEmitter and associated machinery to |
| 11 | // JIT-compile bytecode to native PowerPC. |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Misha Brukman | 3d9a6c2 | 2004-08-11 00:09:42 +0000 | [diff] [blame] | 15 | #include "PPC32JITInfo.h" |
| 16 | #include "PPC32TargetMachine.h" |
Misha Brukman | a4df350 | 2004-10-23 18:28:01 +0000 | [diff] [blame] | 17 | #include "PowerPC.h" |
Misha Brukman | 3070e2f | 2004-10-21 01:42:02 +0000 | [diff] [blame] | 18 | #include "llvm/Module.h" |
Misha Brukman | b05daff | 2004-08-09 23:03:59 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/MachineCodeEmitter.h" |
| 20 | #include "llvm/CodeGen/MachineFunctionPass.h" |
Misha Brukman | d4b4a99 | 2004-10-23 23:47:34 +0000 | [diff] [blame^] | 21 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Misha Brukman | b05daff | 2004-08-09 23:03:59 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/Passes.h" |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 23 | #include "llvm/Support/Debug.h" |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 24 | |
| 25 | namespace llvm { |
| 26 | |
Misha Brukman | b05daff | 2004-08-09 23:03:59 +0000 | [diff] [blame] | 27 | namespace { |
Misha Brukman | 3070e2f | 2004-10-21 01:42:02 +0000 | [diff] [blame] | 28 | class JITResolver { |
| 29 | MachineCodeEmitter &MCE; |
| 30 | |
| 31 | // LazyCodeGenMap - Keep track of call sites for functions that are to be |
| 32 | // lazily resolved. |
| 33 | std::map<unsigned, Function*> LazyCodeGenMap; |
| 34 | |
| 35 | // LazyResolverMap - Keep track of the lazy resolver created for a |
| 36 | // particular function so that we can reuse them if necessary. |
| 37 | std::map<Function*, unsigned> LazyResolverMap; |
| 38 | |
| 39 | public: |
| 40 | JITResolver(MachineCodeEmitter &mce) : MCE(mce) {} |
| 41 | unsigned getLazyResolver(Function *F); |
| 42 | unsigned addFunctionReference(unsigned Address, Function *F); |
| 43 | |
| 44 | private: |
| 45 | unsigned emitStubForFunction(Function *F); |
| 46 | static void CompilationCallback(); |
| 47 | unsigned resolveFunctionReference(unsigned RetAddr); |
| 48 | }; |
| 49 | |
| 50 | static JITResolver &getResolver(MachineCodeEmitter &MCE) { |
| 51 | static JITResolver *TheJITResolver = 0; |
| 52 | if (TheJITResolver == 0) |
| 53 | TheJITResolver = new JITResolver(MCE); |
| 54 | return *TheJITResolver; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | unsigned JITResolver::getLazyResolver(Function *F) { |
| 59 | std::map<Function*, unsigned>::iterator I = LazyResolverMap.lower_bound(F); |
| 60 | if (I != LazyResolverMap.end() && I->first == F) return I->second; |
| 61 | |
| 62 | unsigned Stub = emitStubForFunction(F); |
| 63 | LazyResolverMap.insert(I, std::make_pair(F, Stub)); |
| 64 | return Stub; |
| 65 | } |
| 66 | |
| 67 | /// addFunctionReference - This method is called when we need to emit the |
| 68 | /// address of a function that has not yet been emitted, so we don't know the |
| 69 | /// address. Instead, we emit a call to the CompilationCallback method, and |
| 70 | /// keep track of where we are. |
| 71 | /// |
| 72 | unsigned JITResolver::addFunctionReference(unsigned Address, Function *F) { |
| 73 | LazyCodeGenMap[Address] = F; |
| 74 | return (intptr_t)&JITResolver::CompilationCallback; |
| 75 | } |
| 76 | |
| 77 | unsigned JITResolver::resolveFunctionReference(unsigned RetAddr) { |
| 78 | std::map<unsigned, Function*>::iterator I = LazyCodeGenMap.find(RetAddr); |
| 79 | assert(I != LazyCodeGenMap.end() && "Not in map!"); |
| 80 | Function *F = I->second; |
| 81 | LazyCodeGenMap.erase(I); |
| 82 | return MCE.forceCompilationOf(F); |
| 83 | } |
| 84 | |
| 85 | /// emitStubForFunction - This method is used by the JIT when it needs to emit |
| 86 | /// the address of a function for a function whose code has not yet been |
| 87 | /// generated. In order to do this, it generates a stub which jumps to the lazy |
| 88 | /// function compiler, which will eventually get fixed to call the function |
| 89 | /// directly. |
| 90 | /// |
| 91 | unsigned JITResolver::emitStubForFunction(Function *F) { |
| 92 | std::cerr << "PPC32CodeEmitter::emitStubForFunction() unimplemented!\n"; |
| 93 | abort(); |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | void JITResolver::CompilationCallback() { |
| 98 | std::cerr << "PPC32CodeEmitter: CompilationCallback() unimplemented!"; |
| 99 | abort(); |
| 100 | } |
| 101 | |
| 102 | namespace { |
Misha Brukman | 3d9a6c2 | 2004-08-11 00:09:42 +0000 | [diff] [blame] | 103 | class PPC32CodeEmitter : public MachineFunctionPass { |
Misha Brukman | b05daff | 2004-08-09 23:03:59 +0000 | [diff] [blame] | 104 | TargetMachine &TM; |
| 105 | MachineCodeEmitter &MCE; |
| 106 | |
Misha Brukman | 3070e2f | 2004-10-21 01:42:02 +0000 | [diff] [blame] | 107 | // Tracks which instruction references which BasicBlock |
| 108 | std::vector<std::pair<const BasicBlock*, |
| 109 | std::pair<unsigned*,MachineInstr*> > > BBRefs; |
| 110 | // Tracks where each BasicBlock starts |
| 111 | std::map<const BasicBlock*, long> BBLocations; |
| 112 | |
| 113 | /// getMachineOpValue - evaluates the MachineOperand of a given MachineInstr |
| 114 | /// |
Misha Brukman | d37faba | 2004-10-14 06:07:25 +0000 | [diff] [blame] | 115 | int64_t getMachineOpValue(MachineInstr &MI, MachineOperand &MO); |
| 116 | |
Misha Brukman | 3070e2f | 2004-10-21 01:42:02 +0000 | [diff] [blame] | 117 | unsigned getAddressOfExternalFunction(Function *F); |
| 118 | |
Misha Brukman | b05daff | 2004-08-09 23:03:59 +0000 | [diff] [blame] | 119 | public: |
Misha Brukman | 3d9a6c2 | 2004-08-11 00:09:42 +0000 | [diff] [blame] | 120 | PPC32CodeEmitter(TargetMachine &T, MachineCodeEmitter &M) |
Misha Brukman | b05daff | 2004-08-09 23:03:59 +0000 | [diff] [blame] | 121 | : TM(T), MCE(M) {} |
| 122 | |
| 123 | const char *getPassName() const { return "PowerPC Machine Code Emitter"; } |
| 124 | |
| 125 | /// runOnMachineFunction - emits the given MachineFunction to memory |
| 126 | /// |
| 127 | bool runOnMachineFunction(MachineFunction &MF); |
| 128 | |
| 129 | /// emitBasicBlock - emits the given MachineBasicBlock to memory |
| 130 | /// |
| 131 | void emitBasicBlock(MachineBasicBlock &MBB); |
| 132 | |
| 133 | /// emitWord - write a 32-bit word to memory at the current PC |
| 134 | /// |
| 135 | void emitWord(unsigned w) { MCE.emitWord(w); } |
Misha Brukman | d37faba | 2004-10-14 06:07:25 +0000 | [diff] [blame] | 136 | |
| 137 | /// getValueBit - return the particular bit of Val |
| 138 | /// |
| 139 | unsigned getValueBit(int64_t Val, unsigned bit) { return (Val >> bit) & 1; } |
Misha Brukman | b05daff | 2004-08-09 23:03:59 +0000 | [diff] [blame] | 140 | |
Misha Brukman | 3070e2f | 2004-10-21 01:42:02 +0000 | [diff] [blame] | 141 | /// getBinaryCodeForInstr - This function, generated by the |
| 142 | /// CodeEmitterGenerator using TableGen, produces the binary encoding for |
| 143 | /// machine instructions. |
Misha Brukman | b05daff | 2004-08-09 23:03:59 +0000 | [diff] [blame] | 144 | /// |
Misha Brukman | d37faba | 2004-10-14 06:07:25 +0000 | [diff] [blame] | 145 | unsigned getBinaryCodeForInstr(MachineInstr &MI); |
Misha Brukman | b05daff | 2004-08-09 23:03:59 +0000 | [diff] [blame] | 146 | }; |
| 147 | } |
| 148 | |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 149 | /// addPassesToEmitMachineCode - Add passes to the specified pass manager to get |
| 150 | /// machine code emitted. This uses a MachineCodeEmitter object to handle |
| 151 | /// actually outputting the machine code and resolving things like the address |
| 152 | /// of functions. This method should returns true if machine code emission is |
| 153 | /// not supported. |
| 154 | /// |
Misha Brukman | 3d9a6c2 | 2004-08-11 00:09:42 +0000 | [diff] [blame] | 155 | bool PPC32TargetMachine::addPassesToEmitMachineCode(FunctionPassManager &PM, |
| 156 | MachineCodeEmitter &MCE) { |
Misha Brukman | 3070e2f | 2004-10-21 01:42:02 +0000 | [diff] [blame] | 157 | // Keep as `true' until this is a functional JIT to allow llvm-gcc to build |
| 158 | return true; |
| 159 | |
Misha Brukman | b05daff | 2004-08-09 23:03:59 +0000 | [diff] [blame] | 160 | // Machine code emitter pass for PowerPC |
Misha Brukman | 9691a89 | 2004-10-21 03:07:38 +0000 | [diff] [blame] | 161 | PM.add(new PPC32CodeEmitter(*this, MCE)); |
Misha Brukman | d37faba | 2004-10-14 06:07:25 +0000 | [diff] [blame] | 162 | // Delete machine code for this function after emitting it |
Misha Brukman | b05daff | 2004-08-09 23:03:59 +0000 | [diff] [blame] | 163 | PM.add(createMachineCodeDeleter()); |
Misha Brukman | c982cfa | 2004-10-14 06:39:56 +0000 | [diff] [blame] | 164 | return false; |
Misha Brukman | b05daff | 2004-08-09 23:03:59 +0000 | [diff] [blame] | 165 | } |
| 166 | |
Misha Brukman | 3d9a6c2 | 2004-08-11 00:09:42 +0000 | [diff] [blame] | 167 | bool PPC32CodeEmitter::runOnMachineFunction(MachineFunction &MF) { |
Misha Brukman | b05daff | 2004-08-09 23:03:59 +0000 | [diff] [blame] | 168 | MCE.startFunction(MF); |
| 169 | MCE.emitConstantPool(MF.getConstantPool()); |
Misha Brukman | 3070e2f | 2004-10-21 01:42:02 +0000 | [diff] [blame] | 170 | for (MachineFunction::iterator BB = MF.begin(), E = MF.end(); BB != E; ++BB) |
| 171 | emitBasicBlock(*BB); |
Misha Brukman | b05daff | 2004-08-09 23:03:59 +0000 | [diff] [blame] | 172 | MCE.finishFunction(MF); |
Misha Brukman | 3070e2f | 2004-10-21 01:42:02 +0000 | [diff] [blame] | 173 | |
| 174 | // Resolve branches to BasicBlocks for the entire function |
| 175 | for (unsigned i = 0, e = BBRefs.size(); i != e; ++i) { |
| 176 | long Location = BBLocations[BBRefs[i].first]; |
| 177 | unsigned *Ref = BBRefs[i].second.first; |
| 178 | MachineInstr *MI = BBRefs[i].second.second; |
| 179 | DEBUG(std::cerr << "Fixup @ " << std::hex << Ref << " to 0x" << Location |
| 180 | << " in instr: " << std::dec << *MI); |
| 181 | for (unsigned ii = 0, ee = MI->getNumOperands(); ii != ee; ++ii) { |
| 182 | MachineOperand &op = MI->getOperand(ii); |
| 183 | if (op.isPCRelativeDisp()) { |
| 184 | // the instruction's branch target is made such that it branches to |
| 185 | // PC + (branchTarget * 4), so undo that arithmetic here: |
| 186 | // Location is the target of the branch |
| 187 | // Ref is the location of the instruction, and hence the PC |
| 188 | int64_t branchTarget = (Location - (long)Ref) >> 2; |
| 189 | MI->SetMachineOperandConst(ii, MachineOperand::MO_SignExtendedImmed, |
| 190 | branchTarget); |
| 191 | unsigned fixedInstr = PPC32CodeEmitter::getBinaryCodeForInstr(*MI); |
| 192 | MCE.emitWordAt(fixedInstr, Ref); |
| 193 | break; |
| 194 | } |
| 195 | } |
| 196 | } |
| 197 | BBRefs.clear(); |
| 198 | BBLocations.clear(); |
| 199 | |
Misha Brukman | b05daff | 2004-08-09 23:03:59 +0000 | [diff] [blame] | 200 | return false; |
| 201 | } |
| 202 | |
Misha Brukman | 3d9a6c2 | 2004-08-11 00:09:42 +0000 | [diff] [blame] | 203 | void PPC32CodeEmitter::emitBasicBlock(MachineBasicBlock &MBB) { |
Misha Brukman | a4df350 | 2004-10-23 18:28:01 +0000 | [diff] [blame] | 204 | BBLocations[MBB.getBasicBlock()] = MCE.getCurrentPCValue(); |
| 205 | for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end(); I != E; ++I){ |
| 206 | MachineInstr &MI = *I; |
| 207 | unsigned Opcode = MI.getOpcode(); |
Misha Brukman | d4b4a99 | 2004-10-23 23:47:34 +0000 | [diff] [blame^] | 208 | if (Opcode == PPC::IMPLICIT_DEF) |
| 209 | continue; // pseudo opcode, no side effects |
| 210 | else if (Opcode == PPC::MovePCtoLR) { |
| 211 | // This can be simplified: the resulting 32-bit code is 0x48000005 |
| 212 | MachineInstr *MI = BuildMI(PPC::BL, 1).addImm(1); |
| 213 | emitWord(getBinaryCodeForInstr(*MI)); |
| 214 | delete MI; |
| 215 | } else |
| 216 | emitWord(getBinaryCodeForInstr(*I)); |
Misha Brukman | a4df350 | 2004-10-23 18:28:01 +0000 | [diff] [blame] | 217 | } |
Misha Brukman | b05daff | 2004-08-09 23:03:59 +0000 | [diff] [blame] | 218 | } |
| 219 | |
Misha Brukman | 3070e2f | 2004-10-21 01:42:02 +0000 | [diff] [blame] | 220 | unsigned PPC32CodeEmitter::getAddressOfExternalFunction(Function *F) { |
| 221 | static std::map<Function*, unsigned> ExternalFn2Addr; |
| 222 | std::map<Function*, unsigned>::iterator Addr = ExternalFn2Addr.find(F); |
| 223 | |
| 224 | if (Addr == ExternalFn2Addr.end()) |
| 225 | ExternalFn2Addr[F] = MCE.forceCompilationOf(F); |
| 226 | return ExternalFn2Addr[F]; |
| 227 | } |
| 228 | |
Misha Brukman | a4df350 | 2004-10-23 18:28:01 +0000 | [diff] [blame] | 229 | static unsigned enumRegToMachineReg(unsigned enumReg) { |
| 230 | switch (enumReg) { |
| 231 | case PPC::R0 : case PPC::F0 : return 0; |
| 232 | case PPC::R1 : case PPC::F1 : return 1; |
| 233 | case PPC::R2 : case PPC::F2 : return 2; |
| 234 | case PPC::R3 : case PPC::F3 : return 3; |
| 235 | case PPC::R4 : case PPC::F4 : return 4; |
| 236 | case PPC::R5 : case PPC::F5 : return 5; |
| 237 | case PPC::R6 : case PPC::F6 : return 6; |
| 238 | case PPC::R7 : case PPC::F7 : return 7; |
| 239 | case PPC::R8 : case PPC::F8 : return 8; |
| 240 | case PPC::R9 : case PPC::F9 : return 9; |
| 241 | case PPC::R10: case PPC::F10: return 10; |
| 242 | case PPC::R11: case PPC::F11: return 11; |
| 243 | case PPC::R12: case PPC::F12: return 12; |
| 244 | case PPC::R13: case PPC::F13: return 13; |
| 245 | case PPC::R14: case PPC::F14: return 14; |
| 246 | case PPC::R15: case PPC::F15: return 15; |
| 247 | case PPC::R16: case PPC::F16: return 16; |
| 248 | case PPC::R17: case PPC::F17: return 17; |
| 249 | case PPC::R18: case PPC::F18: return 18; |
| 250 | case PPC::R19: case PPC::F19: return 19; |
| 251 | case PPC::R20: case PPC::F20: return 20; |
| 252 | case PPC::R21: case PPC::F21: return 21; |
| 253 | case PPC::R22: case PPC::F22: return 22; |
| 254 | case PPC::R23: case PPC::F23: return 23; |
| 255 | case PPC::R24: case PPC::F24: return 24; |
| 256 | case PPC::R25: case PPC::F25: return 25; |
| 257 | case PPC::R26: case PPC::F26: return 26; |
| 258 | case PPC::R27: case PPC::F27: return 27; |
| 259 | case PPC::R28: case PPC::F28: return 28; |
| 260 | case PPC::R29: case PPC::F29: return 29; |
| 261 | case PPC::R30: case PPC::F30: return 30; |
| 262 | case PPC::R31: case PPC::F31: return 31; |
| 263 | default: |
| 264 | std::cerr << "Unhandled reg in enumRegToRealReg!\n"; |
| 265 | abort(); |
| 266 | } |
| 267 | } |
| 268 | |
Misha Brukman | d37faba | 2004-10-14 06:07:25 +0000 | [diff] [blame] | 269 | int64_t PPC32CodeEmitter::getMachineOpValue(MachineInstr &MI, |
| 270 | MachineOperand &MO) { |
Misha Brukman | c982cfa | 2004-10-14 06:39:56 +0000 | [diff] [blame] | 271 | int64_t rv = 0; // Return value; defaults to 0 for unhandled cases |
| 272 | // or things that get fixed up later by the JIT. |
Misha Brukman | 3070e2f | 2004-10-21 01:42:02 +0000 | [diff] [blame] | 273 | if (MO.isRegister()) { |
Misha Brukman | a4df350 | 2004-10-23 18:28:01 +0000 | [diff] [blame] | 274 | rv = enumRegToMachineReg(MO.getReg()); |
Misha Brukman | c982cfa | 2004-10-14 06:39:56 +0000 | [diff] [blame] | 275 | } else if (MO.isImmediate()) { |
| 276 | rv = MO.getImmedValue(); |
Misha Brukman | c982cfa | 2004-10-14 06:39:56 +0000 | [diff] [blame] | 277 | } else if (MO.isGlobalAddress()) { |
Misha Brukman | 3070e2f | 2004-10-21 01:42:02 +0000 | [diff] [blame] | 278 | GlobalValue *GV = MO.getGlobal(); |
Misha Brukman | d4b4a99 | 2004-10-23 23:47:34 +0000 | [diff] [blame^] | 279 | rv = MCE.getGlobalValueAddress(GV); |
| 280 | if (rv == 0) { |
Misha Brukman | 3070e2f | 2004-10-21 01:42:02 +0000 | [diff] [blame] | 281 | if (Function *F = dyn_cast<Function>(GV)) { |
| 282 | if (F->isExternal()) |
| 283 | rv = getAddressOfExternalFunction(F); |
| 284 | else { |
Misha Brukman | d4b4a99 | 2004-10-23 23:47:34 +0000 | [diff] [blame^] | 285 | // Function has not yet been code generated! Use lazy resolution. |
Misha Brukman | 3070e2f | 2004-10-21 01:42:02 +0000 | [diff] [blame] | 286 | getResolver(MCE).addFunctionReference(MCE.getCurrentPCValue(), F); |
Misha Brukman | d4b4a99 | 2004-10-23 23:47:34 +0000 | [diff] [blame^] | 287 | rv = getResolver(MCE).getLazyResolver(F); |
Misha Brukman | 3070e2f | 2004-10-21 01:42:02 +0000 | [diff] [blame] | 288 | } |
| 289 | } else if (GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV)) { |
Misha Brukman | a4df350 | 2004-10-23 18:28:01 +0000 | [diff] [blame] | 290 | if (GVar->isExternal()) { |
Misha Brukman | 3070e2f | 2004-10-21 01:42:02 +0000 | [diff] [blame] | 291 | rv = MCE.getGlobalValueAddress(MO.getSymbolName()); |
Misha Brukman | a4df350 | 2004-10-23 18:28:01 +0000 | [diff] [blame] | 292 | if (!rv) { |
| 293 | std::cerr << "PPC32CodeEmitter: External global addr not found: " |
| 294 | << *GVar; |
| 295 | abort(); |
| 296 | } |
| 297 | } else { |
| 298 | std::cerr << "PPC32CodeEmitter: global addr not found: " << *GVar; |
Misha Brukman | 3070e2f | 2004-10-21 01:42:02 +0000 | [diff] [blame] | 299 | abort(); |
| 300 | } |
| 301 | } |
| 302 | } |
| 303 | if (MO.isPCRelative()) { // Global variable reference |
Misha Brukman | d4b4a99 | 2004-10-23 23:47:34 +0000 | [diff] [blame^] | 304 | rv = (rv - MCE.getCurrentPCValue()) >> 2; |
Misha Brukman | 3070e2f | 2004-10-21 01:42:02 +0000 | [diff] [blame] | 305 | } |
Misha Brukman | c982cfa | 2004-10-14 06:39:56 +0000 | [diff] [blame] | 306 | } else if (MO.isMachineBasicBlock()) { |
Misha Brukman | 3070e2f | 2004-10-21 01:42:02 +0000 | [diff] [blame] | 307 | const BasicBlock *BB = MO.getMachineBasicBlock()->getBasicBlock(); |
| 308 | unsigned* CurrPC = (unsigned*)(intptr_t)MCE.getCurrentPCValue(); |
| 309 | BBRefs.push_back(std::make_pair(BB, std::make_pair(CurrPC, &MI))); |
Misha Brukman | c982cfa | 2004-10-14 06:39:56 +0000 | [diff] [blame] | 310 | } else if (MO.isConstantPoolIndex()) { |
Misha Brukman | 3070e2f | 2004-10-21 01:42:02 +0000 | [diff] [blame] | 311 | unsigned index = MO.getConstantPoolIndex(); |
| 312 | rv = MCE.getConstantPoolEntryAddress(index); |
| 313 | } else if (MO.isFrameIndex()) { |
| 314 | std::cerr << "PPC32CodeEmitter: error: Frame index unhandled!\n"; |
| 315 | abort(); |
Misha Brukman | c982cfa | 2004-10-14 06:39:56 +0000 | [diff] [blame] | 316 | } else { |
| 317 | std::cerr << "ERROR: Unknown type of MachineOperand: " << MO << "\n"; |
| 318 | abort(); |
| 319 | } |
| 320 | |
Misha Brukman | a4df350 | 2004-10-23 18:28:01 +0000 | [diff] [blame] | 321 | // Special treatment for global symbols: constants and vars |
| 322 | if (MO.isConstantPoolIndex() || MO.isGlobalAddress()) { |
| 323 | unsigned Opcode = MI.getOpcode(); |
| 324 | int64_t MBBLoc = BBLocations[MI.getParent()->getBasicBlock()]; |
| 325 | if (Opcode == PPC::LOADHiAddr) { |
| 326 | // LoadHiAddr wants hi16(addr - mbb) |
| 327 | rv = (rv - MBBLoc) >> 16; |
| 328 | } else if (Opcode == PPC::LWZ || Opcode == PPC::LA || |
| 329 | Opcode == PPC::LFS || Opcode == PPC::LFD) { |
| 330 | // These load opcodes want lo16(addr - mbb) |
| 331 | rv = (rv - MBBLoc) & 0xffff; |
| 332 | } |
| 333 | } |
| 334 | |
Misha Brukman | c982cfa | 2004-10-14 06:39:56 +0000 | [diff] [blame] | 335 | return rv; |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 336 | } |
| 337 | |
Misha Brukman | d37faba | 2004-10-14 06:07:25 +0000 | [diff] [blame] | 338 | |
Misha Brukman | 3070e2f | 2004-10-21 01:42:02 +0000 | [diff] [blame] | 339 | void *PPC32JITInfo::getJITStubForFunction(Function *F, MachineCodeEmitter &MCE){ |
| 340 | return (void*)((unsigned long)getResolver(MCE).getLazyResolver(F)); |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 341 | } |
| 342 | |
Misha Brukman | 3d9a6c2 | 2004-08-11 00:09:42 +0000 | [diff] [blame] | 343 | void PPC32JITInfo::replaceMachineCodeForFunction (void *Old, void *New) { |
Misha Brukman | d37faba | 2004-10-14 06:07:25 +0000 | [diff] [blame] | 344 | std::cerr << "PPC32JITInfo::replaceMachineCodeForFunction not implemented\n"; |
| 345 | abort(); |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 346 | } |
| 347 | |
Misha Brukman | d37faba | 2004-10-14 06:07:25 +0000 | [diff] [blame] | 348 | #include "PPC32GenCodeEmitter.inc" |
Misha Brukman | b05daff | 2004-08-09 23:03:59 +0000 | [diff] [blame] | 349 | |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 350 | } // end llvm namespace |
| 351 | |