blob: 3995141eade91d2b200ad77ca33ab6ad36151fed [file] [log] [blame]
Chris Lattner4d326fa2003-12-20 01:46:27 +00001//===-- JIT.cpp - LLVM Just in Time Compiler ------------------------------===//
Misha Brukmanf976c852005-04-21 22:55:34 +00002//
John Criswellb576c942003-10-20 19:43:21 +00003// 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.
Misha Brukmanf976c852005-04-21 22:55:34 +00007//
John Criswellb576c942003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Chris Lattnerbd199fb2002-12-24 00:01:05 +00009//
Chris Lattner4d326fa2003-12-20 01:46:27 +000010// This tool implements a just-in-time compiler for LLVM, allowing direct
11// execution of LLVM bytecode in an efficient manner.
Chris Lattnerbd199fb2002-12-24 00:01:05 +000012//
13//===----------------------------------------------------------------------===//
14
Chris Lattner4d326fa2003-12-20 01:46:27 +000015#include "JIT.h"
Chris Lattnercc22e9f2004-08-16 00:14:18 +000016#include "llvm/Constants.h"
Chris Lattnerc07ed132003-12-20 03:36:47 +000017#include "llvm/DerivedTypes.h"
Chris Lattner4d326fa2003-12-20 01:46:27 +000018#include "llvm/Function.h"
Chris Lattnerc07ed132003-12-20 03:36:47 +000019#include "llvm/GlobalVariable.h"
Chris Lattnercc22e9f2004-08-16 00:14:18 +000020#include "llvm/Instructions.h"
Misha Brukman0f4f7d92003-10-16 21:19:34 +000021#include "llvm/ModuleProvider.h"
Chris Lattner4d326fa2003-12-20 01:46:27 +000022#include "llvm/CodeGen/MachineCodeEmitter.h"
23#include "llvm/CodeGen/MachineFunction.h"
Brian Gaeke97222942003-09-05 19:39:22 +000024#include "llvm/ExecutionEngine/GenericValue.h"
Chris Lattnere7fd5532006-05-08 22:00:52 +000025#include "llvm/Support/MutexGuard.h"
Reid Spencerdf5a37e2004-11-29 14:11:29 +000026#include "llvm/System/DynamicLibrary.h"
Owen Anderson07000c62006-05-12 06:33:49 +000027#include "llvm/Target/TargetData.h"
Chris Lattnerbd199fb2002-12-24 00:01:05 +000028#include "llvm/Target/TargetMachine.h"
Chris Lattner4d326fa2003-12-20 01:46:27 +000029#include "llvm/Target/TargetJITInfo.h"
Reid Spencer954da372004-07-04 12:19:56 +000030#include <iostream>
Chris Lattnerc19aade2003-12-08 08:06:28 +000031using namespace llvm;
Misha Brukmanabb027c2003-05-27 21:40:39 +000032
Nate Begemanb76ea742006-07-22 16:59:38 +000033#ifdef __APPLE__
34#include <AvailabilityMacros.h>
35#if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4
Evan Cheng5f42c552006-07-21 23:06:20 +000036// __dso_handle is resolved by Mac OS X dynamic linker.
37extern void *__dso_handle __attribute__ ((__visibility__ ("hidden")));
38#endif
Nate Begemanb76ea742006-07-22 16:59:38 +000039#endif
Evan Cheng5f42c552006-07-21 23:06:20 +000040
Chris Lattner2fe4bb02006-03-22 06:07:50 +000041static struct RegisterJIT {
42 RegisterJIT() { JIT::Register(); }
43} JITRegistrator;
44
Jeff Cohen2f519142006-03-24 02:53:49 +000045namespace llvm {
46 void LinkInJIT() {
47 }
48}
49
Chris Lattner4d326fa2003-12-20 01:46:27 +000050JIT::JIT(ModuleProvider *MP, TargetMachine &tm, TargetJITInfo &tji)
Reid Spenceree448632005-07-12 15:51:55 +000051 : ExecutionEngine(MP), TM(tm), TJI(tji), state(MP) {
Chris Lattnerbd199fb2002-12-24 00:01:05 +000052 setTargetData(TM.getTargetData());
Misha Brukmanabb027c2003-05-27 21:40:39 +000053
54 // Initialize MCE
Misha Brukman906f5fa2003-06-02 03:23:16 +000055 MCE = createEmitter(*this);
Misha Brukmanf976c852005-04-21 22:55:34 +000056
Brian Gaeke50872d52004-04-14 17:45:52 +000057 // Add target data
Reid Spenceree448632005-07-12 15:51:55 +000058 MutexGuard locked(lock);
59 FunctionPassManager& PM = state.getPM(locked);
Chris Lattnerb93b0342006-05-04 21:18:40 +000060 PM.add(new TargetData(*TM.getTargetData()));
Brian Gaeke50872d52004-04-14 17:45:52 +000061
Chris Lattner4d326fa2003-12-20 01:46:27 +000062 // Compile LLVM Code down to machine code in the intermediate representation
63 TJI.addPassesToJITCompile(PM);
64
65 // Turn the machine code intermediate representation into bytes in memory that
66 // may be executed.
67 if (TM.addPassesToEmitMachineCode(PM, *MCE)) {
Chris Lattnercc22e9f2004-08-16 00:14:18 +000068 std::cerr << "Target '" << TM.getName()
Chris Lattner4d326fa2003-12-20 01:46:27 +000069 << "' doesn't support machine code emission!\n";
70 abort();
71 }
Chris Lattnerbd199fb2002-12-24 00:01:05 +000072}
73
Chris Lattner4d326fa2003-12-20 01:46:27 +000074JIT::~JIT() {
75 delete MCE;
76 delete &TM;
77}
78
Brian Gaeke70975ee2003-09-05 18:42:01 +000079/// run - Start execution with the specified function and arguments.
Chris Lattner05a1a302003-08-21 21:32:12 +000080///
Chris Lattnerff0f1bb2003-12-26 06:13:47 +000081GenericValue JIT::runFunction(Function *F,
82 const std::vector<GenericValue> &ArgValues) {
Chris Lattnerb47130c2004-08-15 23:29:50 +000083 assert(F && "Function *F was null at entry to run()");
Chris Lattnerb47130c2004-08-15 23:29:50 +000084
85 void *FPtr = getPointerToFunction(F);
Chris Lattner7c45d782004-08-15 23:31:43 +000086 assert(FPtr && "Pointer to fn's code was null after getPointerToFunction");
Chris Lattnerf7bedf42004-08-15 23:39:59 +000087 const FunctionType *FTy = F->getFunctionType();
Chris Lattnere5eab142004-08-15 23:53:06 +000088 const Type *RetTy = FTy->getReturnType();
Chris Lattnerbd199fb2002-12-24 00:01:05 +000089
Chris Lattnere5eab142004-08-15 23:53:06 +000090 assert((FTy->getNumParams() <= ArgValues.size() || FTy->isVarArg()) &&
91 "Too many arguments passed into function!");
92 assert(FTy->getNumParams() == ArgValues.size() &&
93 "This doesn't support passing arguments through varargs (yet)!");
94
Misha Brukmanec843022004-10-22 23:35:57 +000095 // Handle some common cases first. These cases correspond to common `main'
Chris Lattnere5eab142004-08-15 23:53:06 +000096 // prototypes.
Chris Lattnerd297aea2004-08-15 23:34:48 +000097 if (RetTy == Type::IntTy || RetTy == Type::UIntTy || RetTy == Type::VoidTy) {
Chris Lattnerf7bedf42004-08-15 23:39:59 +000098 switch (ArgValues.size()) {
99 case 3:
Misha Brukmanf976c852005-04-21 22:55:34 +0000100 if ((FTy->getParamType(0) == Type::IntTy ||
Chris Lattnerf7bedf42004-08-15 23:39:59 +0000101 FTy->getParamType(0) == Type::UIntTy) &&
102 isa<PointerType>(FTy->getParamType(1)) &&
103 isa<PointerType>(FTy->getParamType(2))) {
104 int (*PF)(int, char **, const char **) =
Chris Lattner870286a2006-06-01 17:29:22 +0000105 (int(*)(int, char **, const char **))(intptr_t)FPtr;
Misha Brukmanec843022004-10-22 23:35:57 +0000106
Chris Lattnerf7bedf42004-08-15 23:39:59 +0000107 // Call the function.
Chris Lattnere5eab142004-08-15 23:53:06 +0000108 GenericValue rv;
Chris Lattnerf7bedf42004-08-15 23:39:59 +0000109 rv.IntVal = PF(ArgValues[0].IntVal, (char **)GVTOP(ArgValues[1]),
110 (const char **)GVTOP(ArgValues[2]));
111 return rv;
112 }
113 break;
Chris Lattner174f2262004-08-16 01:07:04 +0000114 case 2:
Misha Brukmanf976c852005-04-21 22:55:34 +0000115 if ((FTy->getParamType(0) == Type::IntTy ||
Chris Lattner174f2262004-08-16 01:07:04 +0000116 FTy->getParamType(0) == Type::UIntTy) &&
117 isa<PointerType>(FTy->getParamType(1))) {
Chris Lattner870286a2006-06-01 17:29:22 +0000118 int (*PF)(int, char **) = (int(*)(int, char **))(intptr_t)FPtr;
Misha Brukmanec843022004-10-22 23:35:57 +0000119
Chris Lattner174f2262004-08-16 01:07:04 +0000120 // Call the function.
121 GenericValue rv;
122 rv.IntVal = PF(ArgValues[0].IntVal, (char **)GVTOP(ArgValues[1]));
123 return rv;
124 }
125 break;
Chris Lattnerf7bedf42004-08-15 23:39:59 +0000126 case 1:
127 if (FTy->getNumParams() == 1 &&
Misha Brukmanf976c852005-04-21 22:55:34 +0000128 (FTy->getParamType(0) == Type::IntTy ||
Chris Lattnerf7bedf42004-08-15 23:39:59 +0000129 FTy->getParamType(0) == Type::UIntTy)) {
Chris Lattnere5eab142004-08-15 23:53:06 +0000130 GenericValue rv;
Chris Lattner870286a2006-06-01 17:29:22 +0000131 int (*PF)(int) = (int(*)(int))(intptr_t)FPtr;
Chris Lattnerf7bedf42004-08-15 23:39:59 +0000132 rv.IntVal = PF(ArgValues[0].IntVal);
133 return rv;
134 }
135 break;
Chris Lattnere5eab142004-08-15 23:53:06 +0000136 }
137 }
138
139 // Handle cases where no arguments are passed first.
140 if (ArgValues.empty()) {
141 GenericValue rv;
142 switch (RetTy->getTypeID()) {
143 default: assert(0 && "Unknown return type for function call!");
144 case Type::BoolTyID:
Chris Lattner870286a2006-06-01 17:29:22 +0000145 rv.BoolVal = ((bool(*)())(intptr_t)FPtr)();
Chris Lattnerd297aea2004-08-15 23:34:48 +0000146 return rv;
Chris Lattnere5eab142004-08-15 23:53:06 +0000147 case Type::SByteTyID:
148 case Type::UByteTyID:
Chris Lattner870286a2006-06-01 17:29:22 +0000149 rv.SByteVal = ((char(*)())(intptr_t)FPtr)();
Chris Lattnere5eab142004-08-15 23:53:06 +0000150 return rv;
151 case Type::ShortTyID:
152 case Type::UShortTyID:
Chris Lattner870286a2006-06-01 17:29:22 +0000153 rv.ShortVal = ((short(*)())(intptr_t)FPtr)();
Chris Lattnere5eab142004-08-15 23:53:06 +0000154 return rv;
155 case Type::VoidTyID:
156 case Type::IntTyID:
157 case Type::UIntTyID:
Chris Lattner870286a2006-06-01 17:29:22 +0000158 rv.IntVal = ((int(*)())(intptr_t)FPtr)();
Chris Lattnere5eab142004-08-15 23:53:06 +0000159 return rv;
160 case Type::LongTyID:
161 case Type::ULongTyID:
Chris Lattner870286a2006-06-01 17:29:22 +0000162 rv.LongVal = ((int64_t(*)())(intptr_t)FPtr)();
Chris Lattnere5eab142004-08-15 23:53:06 +0000163 return rv;
164 case Type::FloatTyID:
Chris Lattner870286a2006-06-01 17:29:22 +0000165 rv.FloatVal = ((float(*)())(intptr_t)FPtr)();
Chris Lattnere5eab142004-08-15 23:53:06 +0000166 return rv;
167 case Type::DoubleTyID:
Chris Lattner870286a2006-06-01 17:29:22 +0000168 rv.DoubleVal = ((double(*)())(intptr_t)FPtr)();
Chris Lattnere5eab142004-08-15 23:53:06 +0000169 return rv;
170 case Type::PointerTyID:
Chris Lattner870286a2006-06-01 17:29:22 +0000171 return PTOGV(((void*(*)())(intptr_t)FPtr)());
Chris Lattnerd297aea2004-08-15 23:34:48 +0000172 }
Chris Lattnerff0f1bb2003-12-26 06:13:47 +0000173 }
Chris Lattnerbd199fb2002-12-24 00:01:05 +0000174
Chris Lattnercc22e9f2004-08-16 00:14:18 +0000175 // Okay, this is not one of our quick and easy cases. Because we don't have a
176 // full FFI, we have to codegen a nullary stub function that just calls the
177 // function we are interested in, passing in constants for all of the
178 // arguments. Make this function and return.
179
180 // First, create the function.
181 FunctionType *STy=FunctionType::get(RetTy, std::vector<const Type*>(), false);
182 Function *Stub = new Function(STy, Function::InternalLinkage, "",
183 F->getParent());
184
185 // Insert a basic block.
186 BasicBlock *StubBB = new BasicBlock("", Stub);
187
188 // Convert all of the GenericValue arguments over to constants. Note that we
189 // currently don't support varargs.
190 std::vector<Value*> Args;
191 for (unsigned i = 0, e = ArgValues.size(); i != e; ++i) {
192 Constant *C = 0;
193 const Type *ArgTy = FTy->getParamType(i);
194 const GenericValue &AV = ArgValues[i];
195 switch (ArgTy->getTypeID()) {
196 default: assert(0 && "Unknown argument type for function call!");
197 case Type::BoolTyID: C = ConstantBool::get(AV.BoolVal); break;
198 case Type::SByteTyID: C = ConstantSInt::get(ArgTy, AV.SByteVal); break;
199 case Type::UByteTyID: C = ConstantUInt::get(ArgTy, AV.UByteVal); break;
200 case Type::ShortTyID: C = ConstantSInt::get(ArgTy, AV.ShortVal); break;
201 case Type::UShortTyID: C = ConstantUInt::get(ArgTy, AV.UShortVal); break;
202 case Type::IntTyID: C = ConstantSInt::get(ArgTy, AV.IntVal); break;
203 case Type::UIntTyID: C = ConstantUInt::get(ArgTy, AV.UIntVal); break;
204 case Type::LongTyID: C = ConstantSInt::get(ArgTy, AV.LongVal); break;
205 case Type::ULongTyID: C = ConstantUInt::get(ArgTy, AV.ULongVal); break;
206 case Type::FloatTyID: C = ConstantFP ::get(ArgTy, AV.FloatVal); break;
207 case Type::DoubleTyID: C = ConstantFP ::get(ArgTy, AV.DoubleVal); break;
208 case Type::PointerTyID:
209 void *ArgPtr = GVTOP(AV);
210 if (sizeof(void*) == 4) {
211 C = ConstantSInt::get(Type::IntTy, (int)(intptr_t)ArgPtr);
212 } else {
213 C = ConstantSInt::get(Type::LongTy, (intptr_t)ArgPtr);
214 }
215 C = ConstantExpr::getCast(C, ArgTy); // Cast the integer to pointer
216 break;
217 }
218 Args.push_back(C);
219 }
220
Chris Lattnera471e042005-05-06 06:48:54 +0000221 CallInst *TheCall = new CallInst(F, Args, "", StubBB);
222 TheCall->setTailCall();
Chris Lattnercc22e9f2004-08-16 00:14:18 +0000223 if (TheCall->getType() != Type::VoidTy)
224 new ReturnInst(TheCall, StubBB); // Return result of the call.
225 else
226 new ReturnInst(StubBB); // Just return void.
227
228 // Finally, return the value returned by our nullary stub function.
229 return runFunction(Stub, std::vector<GenericValue>());
Chris Lattnerbd199fb2002-12-24 00:01:05 +0000230}
Chris Lattner4d326fa2003-12-20 01:46:27 +0000231
232/// runJITOnFunction - Run the FunctionPassManager full of
233/// just-in-time compilation passes on F, hopefully filling in
234/// GlobalAddress[F] with the address of F's machine code.
235///
236void JIT::runJITOnFunction(Function *F) {
237 static bool isAlreadyCodeGenerating = false;
238 assert(!isAlreadyCodeGenerating && "Error: Recursive compilation detected!");
Jeff Cohen00b168892005-07-27 06:12:32 +0000239
Reid Spenceree448632005-07-12 15:51:55 +0000240 MutexGuard locked(lock);
Chris Lattner4d326fa2003-12-20 01:46:27 +0000241
242 // JIT the function
243 isAlreadyCodeGenerating = true;
Reid Spenceree448632005-07-12 15:51:55 +0000244 state.getPM(locked).run(*F);
Chris Lattner4d326fa2003-12-20 01:46:27 +0000245 isAlreadyCodeGenerating = false;
Chris Lattnerc07ed132003-12-20 03:36:47 +0000246
247 // If the function referred to a global variable that had not yet been
248 // emitted, it allocates memory for the global, but doesn't emit it yet. Emit
249 // all of these globals now.
Reid Spenceree448632005-07-12 15:51:55 +0000250 while (!state.getPendingGlobals(locked).empty()) {
251 const GlobalVariable *GV = state.getPendingGlobals(locked).back();
252 state.getPendingGlobals(locked).pop_back();
Chris Lattnerc07ed132003-12-20 03:36:47 +0000253 EmitGlobalVariable(GV);
254 }
Chris Lattner4d326fa2003-12-20 01:46:27 +0000255}
256
257/// getPointerToFunction - This method is used to get the address of the
258/// specified function, compiling it if neccesary.
259///
260void *JIT::getPointerToFunction(Function *F) {
Reid Spenceree448632005-07-12 15:51:55 +0000261 MutexGuard locked(lock);
262
Chris Lattnerc07ed132003-12-20 03:36:47 +0000263 if (void *Addr = getPointerToGlobalIfAvailable(F))
264 return Addr; // Check if function already code gen'd
Chris Lattner4d326fa2003-12-20 01:46:27 +0000265
Chris Lattnerfe854032006-08-16 01:24:12 +0000266 // Make sure we read in the function if it exists in this Module.
Chris Lattner5c72a3a2006-07-07 17:18:09 +0000267 if (F->hasNotBeenReadFromBytecode()) {
Chris Lattnerfe854032006-08-16 01:24:12 +0000268 // Determine the module provider this function is provided by.
269 Module *M = F->getParent();
270 ModuleProvider *MP = 0;
271 for (unsigned i = 0, e = Modules.size(); i != e; ++i) {
272 if (Modules[i]->getModule() == M) {
273 MP = Modules[i];
274 break;
275 }
276 }
277 assert(MP && "Function isn't in a module we know about!");
278
Chris Lattner5c72a3a2006-07-07 17:18:09 +0000279 std::string ErrorMsg;
280 if (MP->materializeFunction(F, &ErrorMsg)) {
Chris Lattner0050ef82004-11-15 23:18:09 +0000281 std::cerr << "Error reading function '" << F->getName()
Chris Lattner5c72a3a2006-07-07 17:18:09 +0000282 << "' from bytecode file: " << ErrorMsg << "\n";
Chris Lattner0050ef82004-11-15 23:18:09 +0000283 abort();
284 }
Chris Lattner5c72a3a2006-07-07 17:18:09 +0000285 }
Chris Lattner4d326fa2003-12-20 01:46:27 +0000286
Chris Lattnerc07ed132003-12-20 03:36:47 +0000287 if (F->isExternal()) {
288 void *Addr = getPointerToNamedFunction(F->getName());
289 addGlobalMapping(F, Addr);
290 return Addr;
291 }
Chris Lattner4d326fa2003-12-20 01:46:27 +0000292
293 runJITOnFunction(F);
Chris Lattnerc07ed132003-12-20 03:36:47 +0000294
295 void *Addr = getPointerToGlobalIfAvailable(F);
Chris Lattner4d326fa2003-12-20 01:46:27 +0000296 assert(Addr && "Code generation didn't add function to GlobalAddress table!");
297 return Addr;
298}
299
Chris Lattnerc07ed132003-12-20 03:36:47 +0000300/// getOrEmitGlobalVariable - Return the address of the specified global
301/// variable, possibly emitting it to memory if needed. This is used by the
302/// Emitter.
303void *JIT::getOrEmitGlobalVariable(const GlobalVariable *GV) {
Reid Spenceree448632005-07-12 15:51:55 +0000304 MutexGuard locked(lock);
305
Chris Lattnerc07ed132003-12-20 03:36:47 +0000306 void *Ptr = getPointerToGlobalIfAvailable(GV);
307 if (Ptr) return Ptr;
308
309 // If the global is external, just remember the address.
310 if (GV->isExternal()) {
Evan Chengb82ab942006-07-22 00:42:03 +0000311#ifdef __APPLE__
Nate Begemanb76ea742006-07-22 16:59:38 +0000312#if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4
Evan Cheng5f42c552006-07-21 23:06:20 +0000313 // __dso_handle is resolved by the Mac OS X dynamic linker.
314 if (GV->getName() == "__dso_handle")
315 return (void*)&__dso_handle;
Evan Chengb82ab942006-07-22 00:42:03 +0000316#endif
Nate Begemanb76ea742006-07-22 16:59:38 +0000317#endif
Reid Spencerdf5a37e2004-11-29 14:11:29 +0000318 Ptr = sys::DynamicLibrary::SearchForAddressOfSymbol(GV->getName().c_str());
Chris Lattnerc07ed132003-12-20 03:36:47 +0000319 if (Ptr == 0) {
320 std::cerr << "Could not resolve external global address: "
321 << GV->getName() << "\n";
322 abort();
323 }
324 } else {
325 // If the global hasn't been emitted to memory yet, allocate space. We will
326 // actually initialize the global after current function has finished
327 // compilation.
Chris Lattnerf5d438c2006-05-02 21:57:51 +0000328 const Type *GlobalType = GV->getType()->getElementType();
Owen Andersona69571c2006-05-03 01:29:57 +0000329 size_t S = getTargetData()->getTypeSize(GlobalType);
330 size_t A = getTargetData()->getTypeAlignment(GlobalType);
Chris Lattnerf5d438c2006-05-02 21:57:51 +0000331 if (A <= 8) {
332 Ptr = malloc(S);
333 } else {
334 // Allocate S+A bytes of memory, then use an aligned pointer within that
335 // space.
336 Ptr = malloc(S+A);
337 unsigned MisAligned = ((intptr_t)Ptr & (A-1));
Chris Lattner21c39a62006-07-12 00:31:47 +0000338 Ptr = (char*)Ptr + (MisAligned ? (A-MisAligned) : 0);
Chris Lattnerf5d438c2006-05-02 21:57:51 +0000339 }
Reid Spenceree448632005-07-12 15:51:55 +0000340 state.getPendingGlobals(locked).push_back(GV);
Chris Lattnerc07ed132003-12-20 03:36:47 +0000341 }
342 addGlobalMapping(GV, Ptr);
343 return Ptr;
344}
345
346
Chris Lattner4d326fa2003-12-20 01:46:27 +0000347/// recompileAndRelinkFunction - This method is used to force a function
348/// which has already been compiled, to be compiled again, possibly
349/// after it has been modified. Then the entry to the old copy is overwritten
350/// with a branch to the new copy. If there was no old copy, this acts
351/// just like JIT::getPointerToFunction().
352///
353void *JIT::recompileAndRelinkFunction(Function *F) {
Chris Lattnerc07ed132003-12-20 03:36:47 +0000354 void *OldAddr = getPointerToGlobalIfAvailable(F);
Chris Lattner4d326fa2003-12-20 01:46:27 +0000355
Chris Lattnerc07ed132003-12-20 03:36:47 +0000356 // If it's not already compiled there is no reason to patch it up.
357 if (OldAddr == 0) { return getPointerToFunction(F); }
Chris Lattner4d326fa2003-12-20 01:46:27 +0000358
Chris Lattnerc07ed132003-12-20 03:36:47 +0000359 // Delete the old function mapping.
360 addGlobalMapping(F, 0);
361
Chris Lattnerc07ed132003-12-20 03:36:47 +0000362 // Recodegen the function
Chris Lattner4d326fa2003-12-20 01:46:27 +0000363 runJITOnFunction(F);
Chris Lattnerc07ed132003-12-20 03:36:47 +0000364
365 // Update state, forward the old function to the new function.
366 void *Addr = getPointerToGlobalIfAvailable(F);
Chris Lattner4d326fa2003-12-20 01:46:27 +0000367 assert(Addr && "Code generation didn't add function to GlobalAddress table!");
368 TJI.replaceMachineCodeForFunction(OldAddr, Addr);
369 return Addr;
370}
Misha Brukman895eddf2004-11-07 23:58:46 +0000371