blob: b271618a5ffaf1680a17b732d878436d4bd637a2 [file] [log] [blame]
Chris Lattner9bcae072003-12-20 01:46:27 +00001//===-- JIT.cpp - LLVM Just in Time Compiler ------------------------------===//
Misha Brukman10468d82005-04-21 22:55:34 +00002//
John Criswell482202a2003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukman10468d82005-04-21 22:55:34 +00007//
John Criswell482202a2003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Chris Lattner996fe012002-12-24 00:01:05 +00009//
Chris Lattner9bcae072003-12-20 01:46:27 +000010// This tool implements a just-in-time compiler for LLVM, allowing direct
Gabor Greife16561c2007-07-05 17:07:56 +000011// execution of LLVM bitcode in an efficient manner.
Chris Lattner996fe012002-12-24 00:01:05 +000012//
13//===----------------------------------------------------------------------===//
14
Chris Lattner9bcae072003-12-20 01:46:27 +000015#include "JIT.h"
Jeffrey Yasskine0913882010-02-11 01:07:39 +000016#include "llvm/ADT/SmallPtrSet.h"
Bruno Cardoso Lopesa194c3a2009-05-30 20:51:52 +000017#include "llvm/CodeGen/JITCodeEmitter.h"
Argyrios Kyrtzidisc65c5252009-05-18 21:06:40 +000018#include "llvm/CodeGen/MachineCodeInfo.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000019#include "llvm/Config/config.h"
Jeffrey Yasskin0b08f3d2009-06-25 02:04:04 +000020#include "llvm/ExecutionEngine/GenericValue.h"
21#include "llvm/ExecutionEngine/JITEventListener.h"
Danil Malyshevbfee5422012-03-28 21:46:36 +000022#include "llvm/ExecutionEngine/JITMemoryManager.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000023#include "llvm/IR/Constants.h"
24#include "llvm/IR/DataLayout.h"
25#include "llvm/IR/DerivedTypes.h"
26#include "llvm/IR/Function.h"
27#include "llvm/IR/GlobalVariable.h"
28#include "llvm/IR/Instructions.h"
Rafael Espindola339430f2014-02-25 23:25:17 +000029#include "llvm/IR/Module.h"
Chris Lattner7956bba2009-03-03 20:10:23 +000030#include "llvm/Support/Dwarf.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000031#include "llvm/Support/DynamicLibrary.h"
Torok Edwin6c2d2332009-07-07 17:32:34 +000032#include "llvm/Support/ErrorHandling.h"
Jeffrey Yasskine0913882010-02-11 01:07:39 +000033#include "llvm/Support/ManagedStatic.h"
Chris Lattner7956bba2009-03-03 20:10:23 +000034#include "llvm/Support/MutexGuard.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000035#include "llvm/Target/TargetJITInfo.h"
36#include "llvm/Target/TargetMachine.h"
Anton Korobeynikov7ac25212007-07-30 20:02:02 +000037
Chris Lattnerc0e1b072003-12-08 08:06:28 +000038using namespace llvm;
Misha Brukman56d27322003-05-27 21:40:39 +000039
Jim Grosbach4ae30b62011-03-15 20:25:54 +000040#ifdef __APPLE__
Anton Korobeynikov7ac25212007-07-30 20:02:02 +000041// Apple gcc defaults to -fuse-cxa-atexit (i.e. calls __cxa_atexit instead
42// of atexit). It passes the address of linker generated symbol __dso_handle
43// to the function.
44// This configuration change happened at version 5330.
45# include <AvailabilityMacros.h>
46# if defined(MAC_OS_X_VERSION_10_4) && \
47 ((MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4) || \
48 (MAC_OS_X_VERSION_MIN_REQUIRED == MAC_OS_X_VERSION_10_4 && \
49 __APPLE_CC__ >= 5330))
50# ifndef HAVE___DSO_HANDLE
51# define HAVE___DSO_HANDLE 1
52# endif
53# endif
Evan Cheng71ebc91c2006-07-21 23:06:20 +000054#endif
Anton Korobeynikov7ac25212007-07-30 20:02:02 +000055
56#if HAVE___DSO_HANDLE
57extern void *__dso_handle __attribute__ ((__visibility__ ("hidden")));
Nate Begeman04810082006-07-22 16:59:38 +000058#endif
Evan Cheng71ebc91c2006-07-21 23:06:20 +000059
Dan Gohmand78c4002008-05-13 00:00:25 +000060namespace {
61
Chris Lattner2d52c1b2006-03-22 06:07:50 +000062static struct RegisterJIT {
63 RegisterJIT() { JIT::Register(); }
64} JITRegistrator;
65
Dan Gohmand78c4002008-05-13 00:00:25 +000066}
67
Bob Wilsona1d3e662009-06-24 21:09:18 +000068extern "C" void LLVMLinkInJIT() {
Jeff Cohen0eafbc32006-03-24 02:53:49 +000069}
70
Chris Lattner7f3587e2007-12-06 01:34:04 +000071/// createJIT - This is the factory method for creating a JIT for the current
72/// machine, it does not fall back to the interpreter. This takes ownership
Jeffrey Yasskin091217b2010-01-27 20:34:15 +000073/// of the module.
Jeffrey Yasskin091217b2010-01-27 20:34:15 +000074ExecutionEngine *JIT::createJIT(Module *M,
Reid Klecknerfc8a2d52009-07-18 00:42:18 +000075 std::string *ErrorStr,
76 JITMemoryManager *JMM,
Eric Christopher700d08e2009-11-17 21:58:16 +000077 bool GVsWithCode,
Dylan Noblesmith8418fdc2011-05-13 21:51:29 +000078 TargetMachine *TM) {
Nick Lewycky83a09f02010-08-17 16:19:18 +000079 // Try to register the program as a source of symbols to resolve against.
Dylan Noblesmith1756faa2011-05-13 21:36:16 +000080 //
81 // FIXME: Don't do this here.
Nick Lewycky83a09f02010-08-17 16:19:18 +000082 sys::DynamicLibrary::LoadLibraryPermanently(0, NULL);
83
Dylan Noblesmith1756faa2011-05-13 21:36:16 +000084 // If the target supports JIT code generation, create the JIT.
Reid Klecknerfc8a2d52009-07-18 00:42:18 +000085 if (TargetJITInfo *TJ = TM->getJITInfo()) {
Dylan Noblesmith7f262462011-12-12 04:20:36 +000086 return new JIT(M, *TM, *TJ, JMM, GVsWithCode);
Reid Klecknerfc8a2d52009-07-18 00:42:18 +000087 } else {
88 if (ErrorStr)
89 *ErrorStr = "target does not support JIT code generation";
90 return 0;
91 }
Chris Lattner7f3587e2007-12-06 01:34:04 +000092}
93
Jeffrey Yasskine0913882010-02-11 01:07:39 +000094namespace {
95/// This class supports the global getPointerToNamedFunction(), which allows
96/// bugpoint or gdb users to search for a function by name without any context.
97class JitPool {
98 SmallPtrSet<JIT*, 1> JITs; // Optimize for process containing just 1 JIT.
99 mutable sys::Mutex Lock;
100public:
101 void Add(JIT *jit) {
102 MutexGuard guard(Lock);
103 JITs.insert(jit);
104 }
105 void Remove(JIT *jit) {
106 MutexGuard guard(Lock);
107 JITs.erase(jit);
108 }
109 void *getPointerToNamedFunction(const char *Name) const {
110 MutexGuard guard(Lock);
111 assert(JITs.size() != 0 && "No Jit registered");
112 //search function in every instance of JIT
113 for (SmallPtrSet<JIT*, 1>::const_iterator Jit = JITs.begin(),
114 end = JITs.end();
115 Jit != end; ++Jit) {
116 if (Function *F = (*Jit)->FindFunctionNamed(Name))
117 return (*Jit)->getPointerToFunction(F);
118 }
119 // The function is not available : fallback on the first created (will
120 // search in symbol of the current program/library)
121 return (*JITs.begin())->getPointerToNamedFunction(Name);
122 }
123};
124ManagedStatic<JitPool> AllJits;
125}
126extern "C" {
127 // getPointerToNamedFunction - This function is used as a global wrapper to
128 // JIT::getPointerToNamedFunction for the purpose of resolving symbols when
129 // bugpoint is debugging the JIT. In that scenario, we are loading an .so and
130 // need to resolve function(s) that are being mis-codegenerated, so we need to
131 // resolve their addresses at runtime, and this is the way to do it.
132 void *getPointerToNamedFunction(const char *Name) {
133 return AllJits->getPointerToNamedFunction(Name);
134 }
135}
136
Jeffrey Yasskin091217b2010-01-27 20:34:15 +0000137JIT::JIT(Module *M, TargetMachine &tm, TargetJITInfo &tji,
Danil Malyshevbfee5422012-03-28 21:46:36 +0000138 JITMemoryManager *jmm, bool GVsWithCode)
139 : ExecutionEngine(M), TM(tm), TJI(tji),
140 JMM(jmm ? jmm : JITMemoryManager::CreateDefaultMemManager()),
141 AllocateGVsWithCode(GVsWithCode), isAlreadyCodeGenerating(false) {
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000142 setDataLayout(TM.getDataLayout());
Misha Brukman56d27322003-05-27 21:40:39 +0000143
Jeffrey Yasskin091217b2010-01-27 20:34:15 +0000144 jitstate = new JITState(M);
Nate Begeman8f83fc42008-05-21 16:34:48 +0000145
Bruno Cardoso Lopesa194c3a2009-05-30 20:51:52 +0000146 // Initialize JCE
Reid Kleckner9a10db82009-09-20 23:52:43 +0000147 JCE = createEmitter(*this, JMM, TM);
Misha Brukman10468d82005-04-21 22:55:34 +0000148
Jeffrey Yasskine0913882010-02-11 01:07:39 +0000149 // Register in global list of all JITs.
150 AllJits->Add(this);
151
Brian Gaekeaec2bcd2004-04-14 17:45:52 +0000152 // Add target data
Reid Spencer79876f52005-07-12 15:51:55 +0000153 MutexGuard locked(lock);
Nate Begeman8f83fc42008-05-21 16:34:48 +0000154 FunctionPassManager &PM = jitstate->getPM(locked);
Rafael Espindola339430f2014-02-25 23:25:17 +0000155 M->setDataLayout(TM.getDataLayout());
156 PM.add(new DataLayoutPass(M));
Brian Gaekeaec2bcd2004-04-14 17:45:52 +0000157
Chris Lattner9bcae072003-12-20 01:46:27 +0000158 // Turn the machine code intermediate representation into bytes in memory that
159 // may be executed.
Dylan Noblesmith19a58df2011-12-01 21:49:21 +0000160 if (TM.addPassesToEmitMachineCode(PM, *JCE)) {
Chris Lattner2104b8d2010-04-07 22:58:41 +0000161 report_fatal_error("Target does not support machine code emission!");
Chris Lattner9bcae072003-12-20 01:46:27 +0000162 }
Jim Grosbach4ae30b62011-03-15 20:25:54 +0000163
Chris Lattner12e97302006-09-04 04:14:57 +0000164 // Initialize passes.
165 PM.doInitialization();
Chris Lattner996fe012002-12-24 00:01:05 +0000166}
167
Chris Lattner9bcae072003-12-20 01:46:27 +0000168JIT::~JIT() {
Duncan Sandsabc79012010-10-21 08:57:29 +0000169 // Cleanup.
Jeffrey Yasskine0913882010-02-11 01:07:39 +0000170 AllJits->Remove(this);
Nate Begeman8f83fc42008-05-21 16:34:48 +0000171 delete jitstate;
Bruno Cardoso Lopesa194c3a2009-05-30 20:51:52 +0000172 delete JCE;
Danil Malyshevbfee5422012-03-28 21:46:36 +0000173 // JMM is a ownership of JCE, so we no need delete JMM here.
Chris Lattner9bcae072003-12-20 01:46:27 +0000174 delete &TM;
175}
176
Jeffrey Yasskin091217b2010-01-27 20:34:15 +0000177/// addModule - Add a new Module to the JIT. If we previously removed the last
178/// Module, we need re-initialize jitstate with a valid Module.
179void JIT::addModule(Module *M) {
Nate Begeman8f83fc42008-05-21 16:34:48 +0000180 MutexGuard locked(lock);
181
182 if (Modules.empty()) {
183 assert(!jitstate && "jitstate should be NULL if Modules vector is empty!");
184
Jeffrey Yasskin091217b2010-01-27 20:34:15 +0000185 jitstate = new JITState(M);
Nate Begeman8f83fc42008-05-21 16:34:48 +0000186
187 FunctionPassManager &PM = jitstate->getPM(locked);
Rafael Espindola339430f2014-02-25 23:25:17 +0000188 M->setDataLayout(TM.getDataLayout());
189 PM.add(new DataLayoutPass(M));
Nate Begeman8f83fc42008-05-21 16:34:48 +0000190
191 // Turn the machine code intermediate representation into bytes in memory
192 // that may be executed.
Dylan Noblesmith19a58df2011-12-01 21:49:21 +0000193 if (TM.addPassesToEmitMachineCode(PM, *JCE)) {
Chris Lattner2104b8d2010-04-07 22:58:41 +0000194 report_fatal_error("Target does not support machine code emission!");
Nate Begeman8f83fc42008-05-21 16:34:48 +0000195 }
Jim Grosbach4ae30b62011-03-15 20:25:54 +0000196
Nate Begeman8f83fc42008-05-21 16:34:48 +0000197 // Initialize passes.
198 PM.doInitialization();
199 }
Jim Grosbach4ae30b62011-03-15 20:25:54 +0000200
Jeffrey Yasskin091217b2010-01-27 20:34:15 +0000201 ExecutionEngine::addModule(M);
Nate Begeman8f83fc42008-05-21 16:34:48 +0000202}
203
Jeffrey Yasskin091217b2010-01-27 20:34:15 +0000204/// removeModule - If we are removing the last Module, invalidate the jitstate
205/// since the PassManager it contains references a released Module.
206bool JIT::removeModule(Module *M) {
207 bool result = ExecutionEngine::removeModule(M);
Jim Grosbach4ae30b62011-03-15 20:25:54 +0000208
Nate Begeman8f83fc42008-05-21 16:34:48 +0000209 MutexGuard locked(lock);
Jim Grosbach4ae30b62011-03-15 20:25:54 +0000210
Chad Rosier13198f82012-07-25 19:06:29 +0000211 if (jitstate && jitstate->getModule() == M) {
Nate Begeman8f83fc42008-05-21 16:34:48 +0000212 delete jitstate;
213 jitstate = 0;
214 }
Jim Grosbach4ae30b62011-03-15 20:25:54 +0000215
Nate Begeman18d85e72009-02-18 08:31:02 +0000216 if (!jitstate && !Modules.empty()) {
217 jitstate = new JITState(Modules[0]);
218
219 FunctionPassManager &PM = jitstate->getPM(locked);
Rafael Espindola339430f2014-02-25 23:25:17 +0000220 M->setDataLayout(TM.getDataLayout());
221 PM.add(new DataLayoutPass(M));
Jim Grosbach4ae30b62011-03-15 20:25:54 +0000222
Nate Begeman18d85e72009-02-18 08:31:02 +0000223 // Turn the machine code intermediate representation into bytes in memory
224 // that may be executed.
Dylan Noblesmith19a58df2011-12-01 21:49:21 +0000225 if (TM.addPassesToEmitMachineCode(PM, *JCE)) {
Chris Lattner2104b8d2010-04-07 22:58:41 +0000226 report_fatal_error("Target does not support machine code emission!");
Nate Begeman18d85e72009-02-18 08:31:02 +0000227 }
Jim Grosbach4ae30b62011-03-15 20:25:54 +0000228
Nate Begeman18d85e72009-02-18 08:31:02 +0000229 // Initialize passes.
230 PM.doInitialization();
Jim Grosbach4ae30b62011-03-15 20:25:54 +0000231 }
Nate Begeman8f83fc42008-05-21 16:34:48 +0000232 return result;
233}
234
Brian Gaekea7669032003-09-05 18:42:01 +0000235/// run - Start execution with the specified function and arguments.
Chris Lattnerabca19d2003-08-21 21:32:12 +0000236///
Chris Lattner385a90a2003-12-26 06:13:47 +0000237GenericValue JIT::runFunction(Function *F,
238 const std::vector<GenericValue> &ArgValues) {
Chris Lattnera349c032004-08-15 23:29:50 +0000239 assert(F && "Function *F was null at entry to run()");
Chris Lattnera349c032004-08-15 23:29:50 +0000240
241 void *FPtr = getPointerToFunction(F);
Chris Lattner47380e32004-08-15 23:31:43 +0000242 assert(FPtr && "Pointer to fn's code was null after getPointerToFunction");
Chris Lattner229907c2011-07-18 04:54:35 +0000243 FunctionType *FTy = F->getFunctionType();
244 Type *RetTy = FTy->getReturnType();
Chris Lattner996fe012002-12-24 00:01:05 +0000245
Dan Gohmanc0ae2492009-02-19 02:55:18 +0000246 assert((FTy->getNumParams() == ArgValues.size() ||
247 (FTy->isVarArg() && FTy->getNumParams() <= ArgValues.size())) &&
248 "Wrong number of arguments passed into function!");
Chris Lattner58d05822004-08-15 23:53:06 +0000249 assert(FTy->getNumParams() == ArgValues.size() &&
250 "This doesn't support passing arguments through varargs (yet)!");
251
Misha Brukman37a71022004-10-22 23:35:57 +0000252 // Handle some common cases first. These cases correspond to common `main'
Chris Lattner58d05822004-08-15 23:53:06 +0000253 // prototypes.
Duncan Sands9dff9be2010-02-15 16:12:20 +0000254 if (RetTy->isIntegerTy(32) || RetTy->isVoidTy()) {
Chris Lattner23f7c982004-08-15 23:39:59 +0000255 switch (ArgValues.size()) {
256 case 3:
Duncan Sands9dff9be2010-02-15 16:12:20 +0000257 if (FTy->getParamType(0)->isIntegerTy(32) &&
Duncan Sands19d0b472010-02-16 11:11:14 +0000258 FTy->getParamType(1)->isPointerTy() &&
259 FTy->getParamType(2)->isPointerTy()) {
Chris Lattner23f7c982004-08-15 23:39:59 +0000260 int (*PF)(int, char **, const char **) =
Chris Lattner71819be2006-06-01 17:29:22 +0000261 (int(*)(int, char **, const char **))(intptr_t)FPtr;
Misha Brukman37a71022004-10-22 23:35:57 +0000262
Chris Lattner23f7c982004-08-15 23:39:59 +0000263 // Call the function.
Chris Lattner58d05822004-08-15 23:53:06 +0000264 GenericValue rv;
Jim Grosbach4ae30b62011-03-15 20:25:54 +0000265 rv.IntVal = APInt(32, PF(ArgValues[0].IntVal.getZExtValue(),
Reid Spencerc764c552007-03-06 03:11:31 +0000266 (char **)GVTOP(ArgValues[1]),
267 (const char **)GVTOP(ArgValues[2])));
Chris Lattner23f7c982004-08-15 23:39:59 +0000268 return rv;
269 }
270 break;
Chris Lattner3361c5d2004-08-16 01:07:04 +0000271 case 2:
Duncan Sands9dff9be2010-02-15 16:12:20 +0000272 if (FTy->getParamType(0)->isIntegerTy(32) &&
Duncan Sands19d0b472010-02-16 11:11:14 +0000273 FTy->getParamType(1)->isPointerTy()) {
Chris Lattner71819be2006-06-01 17:29:22 +0000274 int (*PF)(int, char **) = (int(*)(int, char **))(intptr_t)FPtr;
Misha Brukman37a71022004-10-22 23:35:57 +0000275
Chris Lattner3361c5d2004-08-16 01:07:04 +0000276 // Call the function.
277 GenericValue rv;
Jim Grosbach4ae30b62011-03-15 20:25:54 +0000278 rv.IntVal = APInt(32, PF(ArgValues[0].IntVal.getZExtValue(),
Reid Spencerc764c552007-03-06 03:11:31 +0000279 (char **)GVTOP(ArgValues[1])));
Chris Lattner3361c5d2004-08-16 01:07:04 +0000280 return rv;
281 }
282 break;
Chris Lattner23f7c982004-08-15 23:39:59 +0000283 case 1:
Nuno Lopes79a44242012-08-02 12:09:32 +0000284 if (FTy->getParamType(0)->isIntegerTy(32)) {
Chris Lattner58d05822004-08-15 23:53:06 +0000285 GenericValue rv;
Chris Lattner71819be2006-06-01 17:29:22 +0000286 int (*PF)(int) = (int(*)(int))(intptr_t)FPtr;
Reid Spencerc764c552007-03-06 03:11:31 +0000287 rv.IntVal = APInt(32, PF(ArgValues[0].IntVal.getZExtValue()));
Chris Lattner23f7c982004-08-15 23:39:59 +0000288 return rv;
289 }
Nuno Lopes79a44242012-08-02 12:09:32 +0000290 if (FTy->getParamType(0)->isPointerTy()) {
291 GenericValue rv;
292 int (*PF)(char *) = (int(*)(char *))(intptr_t)FPtr;
293 rv.IntVal = APInt(32, PF((char*)GVTOP(ArgValues[0])));
294 return rv;
295 }
Chris Lattner23f7c982004-08-15 23:39:59 +0000296 break;
Chris Lattner58d05822004-08-15 23:53:06 +0000297 }
298 }
299
300 // Handle cases where no arguments are passed first.
301 if (ArgValues.empty()) {
302 GenericValue rv;
303 switch (RetTy->getTypeID()) {
Torok Edwinfbcc6632009-07-14 16:55:14 +0000304 default: llvm_unreachable("Unknown return type for function call!");
Reid Spencer7a9c62b2007-01-12 07:05:14 +0000305 case Type::IntegerTyID: {
306 unsigned BitWidth = cast<IntegerType>(RetTy)->getBitWidth();
307 if (BitWidth == 1)
Reid Spencerc764c552007-03-06 03:11:31 +0000308 rv.IntVal = APInt(BitWidth, ((bool(*)())(intptr_t)FPtr)());
Reid Spencer7a9c62b2007-01-12 07:05:14 +0000309 else if (BitWidth <= 8)
Reid Spencerc764c552007-03-06 03:11:31 +0000310 rv.IntVal = APInt(BitWidth, ((char(*)())(intptr_t)FPtr)());
Reid Spencer7a9c62b2007-01-12 07:05:14 +0000311 else if (BitWidth <= 16)
Reid Spencerc764c552007-03-06 03:11:31 +0000312 rv.IntVal = APInt(BitWidth, ((short(*)())(intptr_t)FPtr)());
Reid Spencer7a9c62b2007-01-12 07:05:14 +0000313 else if (BitWidth <= 32)
Reid Spencerc764c552007-03-06 03:11:31 +0000314 rv.IntVal = APInt(BitWidth, ((int(*)())(intptr_t)FPtr)());
Reid Spencer7a9c62b2007-01-12 07:05:14 +0000315 else if (BitWidth <= 64)
Reid Spencerc764c552007-03-06 03:11:31 +0000316 rv.IntVal = APInt(BitWidth, ((int64_t(*)())(intptr_t)FPtr)());
Jim Grosbach4ae30b62011-03-15 20:25:54 +0000317 else
Torok Edwinfbcc6632009-07-14 16:55:14 +0000318 llvm_unreachable("Integer types > 64 bits not supported");
Chris Lattner8f8f72f2004-08-15 23:34:48 +0000319 return rv;
Reid Spencer7a9c62b2007-01-12 07:05:14 +0000320 }
Chris Lattner58d05822004-08-15 23:53:06 +0000321 case Type::VoidTyID:
Reid Spencerc764c552007-03-06 03:11:31 +0000322 rv.IntVal = APInt(32, ((int(*)())(intptr_t)FPtr)());
Chris Lattner58d05822004-08-15 23:53:06 +0000323 return rv;
Chris Lattner58d05822004-08-15 23:53:06 +0000324 case Type::FloatTyID:
Chris Lattner71819be2006-06-01 17:29:22 +0000325 rv.FloatVal = ((float(*)())(intptr_t)FPtr)();
Chris Lattner58d05822004-08-15 23:53:06 +0000326 return rv;
327 case Type::DoubleTyID:
Chris Lattner71819be2006-06-01 17:29:22 +0000328 rv.DoubleVal = ((double(*)())(intptr_t)FPtr)();
Chris Lattner58d05822004-08-15 23:53:06 +0000329 return rv;
Dale Johannesena1336cf2007-09-17 18:44:13 +0000330 case Type::X86_FP80TyID:
331 case Type::FP128TyID:
332 case Type::PPC_FP128TyID:
Torok Edwinfbcc6632009-07-14 16:55:14 +0000333 llvm_unreachable("long double not supported yet");
Chris Lattner58d05822004-08-15 23:53:06 +0000334 case Type::PointerTyID:
Chris Lattner71819be2006-06-01 17:29:22 +0000335 return PTOGV(((void*(*)())(intptr_t)FPtr)());
Chris Lattner8f8f72f2004-08-15 23:34:48 +0000336 }
Chris Lattner385a90a2003-12-26 06:13:47 +0000337 }
Chris Lattner996fe012002-12-24 00:01:05 +0000338
Chris Lattner3f9d4ed2004-08-16 00:14:18 +0000339 // Okay, this is not one of our quick and easy cases. Because we don't have a
340 // full FFI, we have to codegen a nullary stub function that just calls the
341 // function we are interested in, passing in constants for all of the
342 // arguments. Make this function and return.
343
344 // First, create the function.
Owen Anderson4056ca92009-07-29 22:17:13 +0000345 FunctionType *STy=FunctionType::get(RetTy, false);
Gabor Greife9ecc682008-04-06 20:25:17 +0000346 Function *Stub = Function::Create(STy, Function::InternalLinkage, "",
347 F->getParent());
Chris Lattner3f9d4ed2004-08-16 00:14:18 +0000348
349 // Insert a basic block.
Owen Anderson55f1c092009-08-13 21:58:54 +0000350 BasicBlock *StubBB = BasicBlock::Create(F->getContext(), "", Stub);
Chris Lattner3f9d4ed2004-08-16 00:14:18 +0000351
352 // Convert all of the GenericValue arguments over to constants. Note that we
353 // currently don't support varargs.
Chris Lattner6ea07f12007-02-13 06:01:22 +0000354 SmallVector<Value*, 8> Args;
Chris Lattner3f9d4ed2004-08-16 00:14:18 +0000355 for (unsigned i = 0, e = ArgValues.size(); i != e; ++i) {
356 Constant *C = 0;
Chris Lattner229907c2011-07-18 04:54:35 +0000357 Type *ArgTy = FTy->getParamType(i);
Chris Lattner3f9d4ed2004-08-16 00:14:18 +0000358 const GenericValue &AV = ArgValues[i];
359 switch (ArgTy->getTypeID()) {
Torok Edwinfbcc6632009-07-14 16:55:14 +0000360 default: llvm_unreachable("Unknown argument type for function call!");
Chris Lattner3b187622008-04-20 00:41:09 +0000361 case Type::IntegerTyID:
Owen Andersonedb4a702009-07-24 23:12:02 +0000362 C = ConstantInt::get(F->getContext(), AV.IntVal);
Chris Lattner3b187622008-04-20 00:41:09 +0000363 break;
364 case Type::FloatTyID:
Owen Anderson69c464d2009-07-27 20:59:43 +0000365 C = ConstantFP::get(F->getContext(), APFloat(AV.FloatVal));
Chris Lattner3b187622008-04-20 00:41:09 +0000366 break;
367 case Type::DoubleTyID:
Owen Anderson69c464d2009-07-27 20:59:43 +0000368 C = ConstantFP::get(F->getContext(), APFloat(AV.DoubleVal));
Chris Lattner3b187622008-04-20 00:41:09 +0000369 break;
Dale Johannesena1336cf2007-09-17 18:44:13 +0000370 case Type::PPC_FP128TyID:
371 case Type::X86_FP80TyID:
Chris Lattner3b187622008-04-20 00:41:09 +0000372 case Type::FP128TyID:
Tim Northover29178a32013-01-22 09:46:31 +0000373 C = ConstantFP::get(F->getContext(), APFloat(ArgTy->getFltSemantics(),
374 AV.IntVal));
Chris Lattner3b187622008-04-20 00:41:09 +0000375 break;
Chris Lattner3f9d4ed2004-08-16 00:14:18 +0000376 case Type::PointerTyID:
377 void *ArgPtr = GVTOP(AV);
Chris Lattner3b187622008-04-20 00:41:09 +0000378 if (sizeof(void*) == 4)
Jim Grosbach4ae30b62011-03-15 20:25:54 +0000379 C = ConstantInt::get(Type::getInt32Ty(F->getContext()),
Owen Anderson55f1c092009-08-13 21:58:54 +0000380 (int)(intptr_t)ArgPtr);
Chris Lattner3b187622008-04-20 00:41:09 +0000381 else
Owen Anderson55f1c092009-08-13 21:58:54 +0000382 C = ConstantInt::get(Type::getInt64Ty(F->getContext()),
383 (intptr_t)ArgPtr);
Owen Andersonb6b25302009-07-14 23:09:55 +0000384 // Cast the integer to pointer
Owen Anderson487375e2009-07-29 18:55:55 +0000385 C = ConstantExpr::getIntToPtr(C, ArgTy);
Chris Lattner3f9d4ed2004-08-16 00:14:18 +0000386 break;
387 }
388 Args.push_back(C);
389 }
390
Jay Foad5bd375a2011-07-15 08:37:34 +0000391 CallInst *TheCall = CallInst::Create(F, Args, "", StubBB);
Chris Lattnerddd75812008-11-23 08:00:11 +0000392 TheCall->setCallingConv(F->getCallingConv());
Chris Lattnerec7773e2005-05-06 06:48:54 +0000393 TheCall->setTailCall();
Benjamin Kramerccce8ba2010-01-05 13:12:22 +0000394 if (!TheCall->getType()->isVoidTy())
Owen Anderson55f1c092009-08-13 21:58:54 +0000395 // Return result of the call.
396 ReturnInst::Create(F->getContext(), TheCall, StubBB);
Chris Lattner3f9d4ed2004-08-16 00:14:18 +0000397 else
Owen Anderson55f1c092009-08-13 21:58:54 +0000398 ReturnInst::Create(F->getContext(), StubBB); // Just return void.
Chris Lattner3f9d4ed2004-08-16 00:14:18 +0000399
Jeffrey Yasskin2d36eb62010-02-12 23:05:31 +0000400 // Finally, call our nullary stub function.
401 GenericValue Result = runFunction(Stub, std::vector<GenericValue>());
402 // Erase it, since no other function can have a reference to it.
403 Stub->eraseFromParent();
404 // And return the result.
405 return Result;
Chris Lattner996fe012002-12-24 00:01:05 +0000406}
Chris Lattner9bcae072003-12-20 01:46:27 +0000407
Jeffrey Yasskin0b08f3d2009-06-25 02:04:04 +0000408void JIT::RegisterJITEventListener(JITEventListener *L) {
409 if (L == NULL)
410 return;
411 MutexGuard locked(lock);
412 EventListeners.push_back(L);
413}
414void JIT::UnregisterJITEventListener(JITEventListener *L) {
415 if (L == NULL)
416 return;
417 MutexGuard locked(lock);
418 std::vector<JITEventListener*>::reverse_iterator I=
419 std::find(EventListeners.rbegin(), EventListeners.rend(), L);
420 if (I != EventListeners.rend()) {
421 std::swap(*I, EventListeners.back());
422 EventListeners.pop_back();
423 }
424}
425void JIT::NotifyFunctionEmitted(
426 const Function &F,
427 void *Code, size_t Size,
428 const JITEvent_EmittedFunctionDetails &Details) {
429 MutexGuard locked(lock);
430 for (unsigned I = 0, S = EventListeners.size(); I < S; ++I) {
431 EventListeners[I]->NotifyFunctionEmitted(F, Code, Size, Details);
432 }
433}
434
Jeffrey Yasskinbf43f652009-10-27 00:03:05 +0000435void JIT::NotifyFreeingMachineCode(void *OldPtr) {
Jeffrey Yasskin0b08f3d2009-06-25 02:04:04 +0000436 MutexGuard locked(lock);
437 for (unsigned I = 0, S = EventListeners.size(); I < S; ++I) {
Jeffrey Yasskinbf43f652009-10-27 00:03:05 +0000438 EventListeners[I]->NotifyFreeingMachineCode(OldPtr);
Jeffrey Yasskin0b08f3d2009-06-25 02:04:04 +0000439 }
440}
441
Chris Lattner9bcae072003-12-20 01:46:27 +0000442/// runJITOnFunction - Run the FunctionPassManager full of
443/// just-in-time compilation passes on F, hopefully filling in
444/// GlobalAddress[F] with the address of F's machine code.
445///
Argyrios Kyrtzidisc65c5252009-05-18 21:06:40 +0000446void JIT::runJITOnFunction(Function *F, MachineCodeInfo *MCI) {
Reid Spencer79876f52005-07-12 15:51:55 +0000447 MutexGuard locked(lock);
Argyrios Kyrtzidisc65c5252009-05-18 21:06:40 +0000448
Jeffrey Yasskin0b08f3d2009-06-25 02:04:04 +0000449 class MCIListener : public JITEventListener {
450 MachineCodeInfo *const MCI;
451 public:
452 MCIListener(MachineCodeInfo *mci) : MCI(mci) {}
453 virtual void NotifyFunctionEmitted(const Function &,
454 void *Code, size_t Size,
455 const EmittedFunctionDetails &) {
456 MCI->setAddress(Code);
457 MCI->setSize(Size);
458 }
459 };
460 MCIListener MCIL(MCI);
Jeffrey Yasskinad46e442009-12-22 23:18:18 +0000461 if (MCI)
462 RegisterJITEventListener(&MCIL);
Argyrios Kyrtzidisc65c5252009-05-18 21:06:40 +0000463
Dan Gohman21cb4112009-02-06 21:25:08 +0000464 runJITOnFunctionUnlocked(F, locked);
Argyrios Kyrtzidisc65c5252009-05-18 21:06:40 +0000465
Jeffrey Yasskinad46e442009-12-22 23:18:18 +0000466 if (MCI)
467 UnregisterJITEventListener(&MCIL);
Dan Gohman21cb4112009-02-06 21:25:08 +0000468}
469
470void JIT::runJITOnFunctionUnlocked(Function *F, const MutexGuard &locked) {
Chris Lattner2b40caa2007-08-13 20:08:16 +0000471 assert(!isAlreadyCodeGenerating && "Error: Recursive compilation detected!");
Chris Lattner9bcae072003-12-20 01:46:27 +0000472
Chris Lattnerb6df00c2010-07-11 23:07:28 +0000473 jitTheFunction(F, locked);
Chris Lattnerfbcc0aa2003-12-20 03:36:47 +0000474
Nate Begeman18d85e72009-02-18 08:31:02 +0000475 // If the function referred to another function that had not yet been
Jeffrey Yasskin4567db42009-10-27 20:30:28 +0000476 // read from bitcode, and we are jitting non-lazily, emit it now.
Nate Begeman18d85e72009-02-18 08:31:02 +0000477 while (!jitstate->getPendingFunctions(locked).empty()) {
478 Function *PF = jitstate->getPendingFunctions(locked).back();
479 jitstate->getPendingFunctions(locked).pop_back();
480
Jeffrey Yasskin2b73a4e2009-12-17 21:35:29 +0000481 assert(!PF->hasAvailableExternallyLinkage() &&
482 "Externally-defined function should not be in pending list.");
483
Chris Lattnerb6df00c2010-07-11 23:07:28 +0000484 jitTheFunction(PF, locked);
Jim Grosbach4ae30b62011-03-15 20:25:54 +0000485
Nate Begeman18d85e72009-02-18 08:31:02 +0000486 // Now that the function has been jitted, ask the JITEmitter to rewrite
487 // the stub with real address of the function.
488 updateFunctionStub(PF);
Chris Lattnerfbcc0aa2003-12-20 03:36:47 +0000489 }
Chris Lattner9bcae072003-12-20 01:46:27 +0000490}
491
Chris Lattnerb6df00c2010-07-11 23:07:28 +0000492void JIT::jitTheFunction(Function *F, const MutexGuard &locked) {
493 isAlreadyCodeGenerating = true;
494 jitstate->getPM(locked).run(*F);
495 isAlreadyCodeGenerating = false;
496
497 // clear basic block addresses after this function is done
498 getBasicBlockAddressMap(locked).clear();
499}
500
Chris Lattner9bcae072003-12-20 01:46:27 +0000501/// getPointerToFunction - This method is used to get the address of the
Chris Lattner0ab5e2c2011-04-15 05:18:47 +0000502/// specified function, compiling it if necessary.
Chris Lattner9bcae072003-12-20 01:46:27 +0000503///
504void *JIT::getPointerToFunction(Function *F) {
Reid Spencer79876f52005-07-12 15:51:55 +0000505
Chris Lattnerfbcc0aa2003-12-20 03:36:47 +0000506 if (void *Addr = getPointerToGlobalIfAvailable(F))
507 return Addr; // Check if function already code gen'd
Chris Lattner9bcae072003-12-20 01:46:27 +0000508
Dan Gohman6c109b42009-02-19 02:40:15 +0000509 MutexGuard locked(lock);
510
Jeffrey Yasskin2b73a4e2009-12-17 21:35:29 +0000511 // Now that this thread owns the lock, make sure we read in the function if it
512 // exists in this Module.
513 std::string ErrorMsg;
Jeffrey Yasskin091217b2010-01-27 20:34:15 +0000514 if (F->Materialize(&ErrorMsg)) {
Chris Lattner2104b8d2010-04-07 22:58:41 +0000515 report_fatal_error("Error reading function '" + F->getName()+
Jeffrey Yasskin2b73a4e2009-12-17 21:35:29 +0000516 "' from bitcode file: " + ErrorMsg);
Nicolas Geoffray568f9812008-04-20 08:33:02 +0000517 }
Chris Lattner9bcae072003-12-20 01:46:27 +0000518
Jeffrey Yasskin2b73a4e2009-12-17 21:35:29 +0000519 // ... and check if another thread has already code gen'd the function.
520 if (void *Addr = getPointerToGlobalIfAvailable(F))
521 return Addr;
522
Chris Lattnerf4c2a9f2009-10-25 23:06:42 +0000523 if (F->isDeclaration() || F->hasAvailableExternallyLinkage()) {
Jeffrey Yasskin8483f122009-11-09 22:34:19 +0000524 bool AbortOnFailure = !F->hasExternalWeakLinkage();
Dan Gohmand32ec012009-01-05 05:32:42 +0000525 void *Addr = getPointerToNamedFunction(F->getName(), AbortOnFailure);
Chris Lattnerfbcc0aa2003-12-20 03:36:47 +0000526 addGlobalMapping(F, Addr);
527 return Addr;
528 }
Chris Lattner9bcae072003-12-20 01:46:27 +0000529
Dan Gohman21cb4112009-02-06 21:25:08 +0000530 runJITOnFunctionUnlocked(F, locked);
Chris Lattnerfbcc0aa2003-12-20 03:36:47 +0000531
532 void *Addr = getPointerToGlobalIfAvailable(F);
Chris Lattner9bcae072003-12-20 01:46:27 +0000533 assert(Addr && "Code generation didn't add function to GlobalAddress table!");
534 return Addr;
535}
536
Chris Lattnerb6df00c2010-07-11 23:07:28 +0000537void JIT::addPointerToBasicBlock(const BasicBlock *BB, void *Addr) {
538 MutexGuard locked(lock);
Jim Grosbach4ae30b62011-03-15 20:25:54 +0000539
Chris Lattnerb6df00c2010-07-11 23:07:28 +0000540 BasicBlockAddressMapTy::iterator I =
541 getBasicBlockAddressMap(locked).find(BB);
542 if (I == getBasicBlockAddressMap(locked).end()) {
543 getBasicBlockAddressMap(locked)[BB] = Addr;
544 } else {
545 // ignore repeats: some BBs can be split into few MBBs?
546 }
547}
548
549void JIT::clearPointerToBasicBlock(const BasicBlock *BB) {
550 MutexGuard locked(lock);
551 getBasicBlockAddressMap(locked).erase(BB);
552}
553
554void *JIT::getPointerToBasicBlock(BasicBlock *BB) {
555 // make sure it's function is compiled by JIT
556 (void)getPointerToFunction(BB->getParent());
557
558 // resolve basic block address
559 MutexGuard locked(lock);
Jim Grosbach4ae30b62011-03-15 20:25:54 +0000560
Chris Lattnerb6df00c2010-07-11 23:07:28 +0000561 BasicBlockAddressMapTy::iterator I =
562 getBasicBlockAddressMap(locked).find(BB);
563 if (I != getBasicBlockAddressMap(locked).end()) {
564 return I->second;
565 } else {
Craig Toppera2886c22012-02-07 05:05:23 +0000566 llvm_unreachable("JIT does not have BB address for address-of-label, was"
567 " it eliminated by optimizer?");
Chris Lattnerb6df00c2010-07-11 23:07:28 +0000568 }
569}
570
Danil Malyshevbfee5422012-03-28 21:46:36 +0000571void *JIT::getPointerToNamedFunction(const std::string &Name,
572 bool AbortOnFailure){
573 if (!isSymbolSearchingDisabled()) {
574 void *ptr = JMM->getPointerToNamedFunction(Name, false);
575 if (ptr)
576 return ptr;
577 }
578
579 /// If a LazyFunctionCreator is installed, use it to get/create the function.
580 if (LazyFunctionCreator)
581 if (void *RP = LazyFunctionCreator(Name))
582 return RP;
583
584 if (AbortOnFailure) {
585 report_fatal_error("Program used external function '"+Name+
586 "' which could not be resolved!");
587 }
588 return 0;
589}
590
591
Chris Lattnerfbcc0aa2003-12-20 03:36:47 +0000592/// getOrEmitGlobalVariable - Return the address of the specified global
593/// variable, possibly emitting it to memory if needed. This is used by the
594/// Emitter.
595void *JIT::getOrEmitGlobalVariable(const GlobalVariable *GV) {
Reid Spencer79876f52005-07-12 15:51:55 +0000596 MutexGuard locked(lock);
597
Chris Lattnerfbcc0aa2003-12-20 03:36:47 +0000598 void *Ptr = getPointerToGlobalIfAvailable(GV);
599 if (Ptr) return Ptr;
600
601 // If the global is external, just remember the address.
Jeffrey Yasskin8c17e6d2009-12-13 20:30:32 +0000602 if (GV->isDeclaration() || GV->hasAvailableExternallyLinkage()) {
Anton Korobeynikov7ac25212007-07-30 20:02:02 +0000603#if HAVE___DSO_HANDLE
Evan Cheng71ebc91c2006-07-21 23:06:20 +0000604 if (GV->getName() == "__dso_handle")
605 return (void*)&__dso_handle;
Evan Chengabc95772006-07-22 00:42:03 +0000606#endif
Daniel Dunbar5899e342009-07-21 08:54:24 +0000607 Ptr = sys::DynamicLibrary::SearchForAddressOfSymbol(GV->getName());
Jeffrey Yasskin8483f122009-11-09 22:34:19 +0000608 if (Ptr == 0) {
Chris Lattner2104b8d2010-04-07 22:58:41 +0000609 report_fatal_error("Could not resolve external global address: "
Torok Edwin6c2d2332009-07-07 17:32:34 +0000610 +GV->getName());
Chris Lattnerfbcc0aa2003-12-20 03:36:47 +0000611 }
Nate Begeman920438e2009-03-04 19:10:38 +0000612 addGlobalMapping(GV, Ptr);
Chris Lattnerfbcc0aa2003-12-20 03:36:47 +0000613 } else {
Dale Johannesenb086d382008-08-07 01:30:15 +0000614 // If the global hasn't been emitted to memory yet, allocate space and
Jeffrey Yasskin70415d92009-07-08 21:59:57 +0000615 // emit it into memory.
616 Ptr = getMemoryForGV(GV);
Dale Johannesenb086d382008-08-07 01:30:15 +0000617 addGlobalMapping(GV, Ptr);
Jeffrey Yasskin70415d92009-07-08 21:59:57 +0000618 EmitGlobalVariable(GV); // Initialize the variable.
Chris Lattnerfbcc0aa2003-12-20 03:36:47 +0000619 }
Chris Lattnerfbcc0aa2003-12-20 03:36:47 +0000620 return Ptr;
621}
622
Chris Lattner9bcae072003-12-20 01:46:27 +0000623/// recompileAndRelinkFunction - This method is used to force a function
624/// which has already been compiled, to be compiled again, possibly
625/// after it has been modified. Then the entry to the old copy is overwritten
626/// with a branch to the new copy. If there was no old copy, this acts
627/// just like JIT::getPointerToFunction().
628///
629void *JIT::recompileAndRelinkFunction(Function *F) {
Chris Lattnerfbcc0aa2003-12-20 03:36:47 +0000630 void *OldAddr = getPointerToGlobalIfAvailable(F);
Chris Lattner9bcae072003-12-20 01:46:27 +0000631
Chris Lattnerfbcc0aa2003-12-20 03:36:47 +0000632 // If it's not already compiled there is no reason to patch it up.
633 if (OldAddr == 0) { return getPointerToFunction(F); }
Chris Lattner9bcae072003-12-20 01:46:27 +0000634
Chris Lattnerfbcc0aa2003-12-20 03:36:47 +0000635 // Delete the old function mapping.
636 addGlobalMapping(F, 0);
637
Chris Lattnerfbcc0aa2003-12-20 03:36:47 +0000638 // Recodegen the function
Chris Lattner9bcae072003-12-20 01:46:27 +0000639 runJITOnFunction(F);
Chris Lattnerfbcc0aa2003-12-20 03:36:47 +0000640
641 // Update state, forward the old function to the new function.
642 void *Addr = getPointerToGlobalIfAvailable(F);
Chris Lattner9bcae072003-12-20 01:46:27 +0000643 assert(Addr && "Code generation didn't add function to GlobalAddress table!");
644 TJI.replaceMachineCodeForFunction(OldAddr, Addr);
645 return Addr;
646}
Misha Brukman624685d2004-11-07 23:58:46 +0000647
Nicolas Geoffray5457ce92008-10-25 15:41:43 +0000648/// getMemoryForGV - This method abstracts memory allocation of global
649/// variable so that the JIT can allocate thread local variables depending
650/// on the target.
651///
652char* JIT::getMemoryForGV(const GlobalVariable* GV) {
Jeffrey Yasskin70415d92009-07-08 21:59:57 +0000653 char *Ptr;
654
655 // GlobalVariable's which are not "constant" will cause trouble in a server
656 // situation. It's returned in the same block of memory as code which may
657 // not be writable.
658 if (isGVCompilationDisabled() && !GV->isConstant()) {
Chris Lattner2104b8d2010-04-07 22:58:41 +0000659 report_fatal_error("Compilation of non-internal GlobalValue is disabled!");
Jeffrey Yasskin70415d92009-07-08 21:59:57 +0000660 }
661
662 // Some applications require globals and code to live together, so they may
663 // be allocated into the same buffer, but in general globals are allocated
664 // through the memory manager which puts them near the code but not in the
665 // same buffer.
Chris Lattner229907c2011-07-18 04:54:35 +0000666 Type *GlobalType = GV->getType()->getElementType();
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000667 size_t S = getDataLayout()->getTypeAllocSize(GlobalType);
668 size_t A = getDataLayout()->getPreferredAlignment(GV);
Nicolas Geoffray5457ce92008-10-25 15:41:43 +0000669 if (GV->isThreadLocal()) {
670 MutexGuard locked(lock);
Jeffrey Yasskin70415d92009-07-08 21:59:57 +0000671 Ptr = TJI.allocateThreadLocalMemory(S);
672 } else if (TJI.allocateSeparateGVMemory()) {
673 if (A <= 8) {
674 Ptr = (char*)malloc(S);
675 } else {
676 // Allocate S+A bytes of memory, then use an aligned pointer within that
677 // space.
678 Ptr = (char*)malloc(S+A);
679 unsigned MisAligned = ((intptr_t)Ptr & (A-1));
680 Ptr = Ptr + (MisAligned ? (A-MisAligned) : 0);
681 }
682 } else if (AllocateGVsWithCode) {
683 Ptr = (char*)JCE->allocateSpace(S, A);
Nicolas Geoffray5457ce92008-10-25 15:41:43 +0000684 } else {
Jeffrey Yasskin70415d92009-07-08 21:59:57 +0000685 Ptr = (char*)JCE->allocateGlobal(S, A);
Nicolas Geoffray5457ce92008-10-25 15:41:43 +0000686 }
Jeffrey Yasskin70415d92009-07-08 21:59:57 +0000687 return Ptr;
Nicolas Geoffray5457ce92008-10-25 15:41:43 +0000688}
Nate Begeman18d85e72009-02-18 08:31:02 +0000689
690void JIT::addPendingFunction(Function *F) {
691 MutexGuard locked(lock);
692 jitstate->getPendingFunctions(locked).push_back(F);
693}
Jeffrey Yasskin0b08f3d2009-06-25 02:04:04 +0000694
695
696JITEventListener::~JITEventListener() {}