blob: 30dadc9f3e3bd2475774ef53e457e035eef8c1d0 [file] [log] [blame]
Reid Kleckner4b1511b2009-07-18 00:42:18 +00001//===- JITTest.cpp - Unit tests for the JIT -------------------------------===//
Jeffrey Yasskin489393d2009-07-08 21:59:57 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Chandler Carruth5a88dda2012-12-04 10:23:08 +000010#include "llvm/ExecutionEngine/JIT.h"
11#include "llvm/ADT/OwningPtr.h"
12#include "llvm/ADT/SmallPtrSet.h"
13#include "llvm/Assembly/Parser.h"
Chandler Carruth5a88dda2012-12-04 10:23:08 +000014#include "llvm/Bitcode/ReaderWriter.h"
Chandler Carruth5a88dda2012-12-04 10:23:08 +000015#include "llvm/ExecutionEngine/JITMemoryManager.h"
Chandler Carruth0b8c9a82013-01-02 11:36:10 +000016#include "llvm/IR/BasicBlock.h"
17#include "llvm/IR/Constant.h"
18#include "llvm/IR/Constants.h"
19#include "llvm/IR/DerivedTypes.h"
20#include "llvm/IR/Function.h"
21#include "llvm/IR/GlobalValue.h"
22#include "llvm/IR/GlobalVariable.h"
23#include "llvm/IR/IRBuilder.h"
24#include "llvm/IR/LLVMContext.h"
25#include "llvm/IR/Module.h"
26#include "llvm/IR/Type.h"
27#include "llvm/IR/TypeBuilder.h"
Jeffrey Yasskinc5818fb2009-12-22 23:47:23 +000028#include "llvm/Support/MemoryBuffer.h"
Jeffrey Yasskin23e5fcf2009-10-23 22:37:43 +000029#include "llvm/Support/SourceMgr.h"
Evan Cheng3e74d6f2011-08-24 18:08:43 +000030#include "llvm/Support/TargetSelect.h"
Chandler Carruth06cb8ed2012-06-29 12:38:19 +000031#include "gtest/gtest.h"
Jeffrey Yasskin7a9034c2009-10-27 00:03:05 +000032#include <vector>
33
Jeffrey Yasskin489393d2009-07-08 21:59:57 +000034using namespace llvm;
35
36namespace {
37
38Function *makeReturnGlobal(std::string Name, GlobalVariable *G, Module *M) {
Jay Foad5fdd6c82011-07-12 14:06:48 +000039 std::vector<Type*> params;
Chris Lattnerdb125cf2011-07-18 04:54:35 +000040 FunctionType *FTy = FunctionType::get(G->getType()->getElementType(),
Dan Gohmanc6f40b62009-07-11 13:56:14 +000041 params, false);
Jeffrey Yasskin489393d2009-07-08 21:59:57 +000042 Function *F = Function::Create(FTy, GlobalValue::ExternalLinkage, Name, M);
Owen Anderson1d0be152009-08-13 21:58:54 +000043 BasicBlock *Entry = BasicBlock::Create(M->getContext(), "entry", F);
Jeffrey Yasskin489393d2009-07-08 21:59:57 +000044 IRBuilder<> builder(Entry);
45 Value *Load = builder.CreateLoad(G);
Chris Lattnerdb125cf2011-07-18 04:54:35 +000046 Type *GTy = G->getType()->getElementType();
Owen Andersoneed707b2009-07-24 23:12:02 +000047 Value *Add = builder.CreateAdd(Load, ConstantInt::get(GTy, 1LL));
Jeffrey Yasskin489393d2009-07-08 21:59:57 +000048 builder.CreateStore(Add, G);
49 builder.CreateRet(Add);
50 return F;
51}
52
Jeffrey Yasskin7a9034c2009-10-27 00:03:05 +000053std::string DumpFunction(const Function *F) {
54 std::string Result;
55 raw_string_ostream(Result) << "" << *F;
56 return Result;
57}
58
59class RecordingJITMemoryManager : public JITMemoryManager {
60 const OwningPtr<JITMemoryManager> Base;
61public:
62 RecordingJITMemoryManager()
63 : Base(JITMemoryManager::CreateDefaultMemManager()) {
Eric Christopher116664a2009-11-12 03:12:18 +000064 stubsAllocated = 0;
Jeffrey Yasskin7a9034c2009-10-27 00:03:05 +000065 }
Danil Malyshev30b9e322012-03-28 21:46:36 +000066 virtual void *getPointerToNamedFunction(const std::string &Name,
67 bool AbortOnFailure = true) {
68 return Base->getPointerToNamedFunction(Name, AbortOnFailure);
69 }
Jeffrey Yasskin7a9034c2009-10-27 00:03:05 +000070
71 virtual void setMemoryWritable() { Base->setMemoryWritable(); }
72 virtual void setMemoryExecutable() { Base->setMemoryExecutable(); }
73 virtual void setPoisonMemory(bool poison) { Base->setPoisonMemory(poison); }
74 virtual void AllocateGOT() { Base->AllocateGOT(); }
75 virtual uint8_t *getGOTBase() const { return Base->getGOTBase(); }
Jeffrey Yasskin7a9034c2009-10-27 00:03:05 +000076 struct StartFunctionBodyCall {
77 StartFunctionBodyCall(uint8_t *Result, const Function *F,
78 uintptr_t ActualSize, uintptr_t ActualSizeResult)
79 : Result(Result), F(F), F_dump(DumpFunction(F)),
80 ActualSize(ActualSize), ActualSizeResult(ActualSizeResult) {}
81 uint8_t *Result;
82 const Function *F;
83 std::string F_dump;
84 uintptr_t ActualSize;
85 uintptr_t ActualSizeResult;
86 };
87 std::vector<StartFunctionBodyCall> startFunctionBodyCalls;
88 virtual uint8_t *startFunctionBody(const Function *F,
89 uintptr_t &ActualSize) {
90 uintptr_t InitialActualSize = ActualSize;
91 uint8_t *Result = Base->startFunctionBody(F, ActualSize);
92 startFunctionBodyCalls.push_back(
93 StartFunctionBodyCall(Result, F, InitialActualSize, ActualSize));
94 return Result;
95 }
Eric Christopher116664a2009-11-12 03:12:18 +000096 int stubsAllocated;
Jeffrey Yasskin7a9034c2009-10-27 00:03:05 +000097 virtual uint8_t *allocateStub(const GlobalValue* F, unsigned StubSize,
98 unsigned Alignment) {
Eric Christopher116664a2009-11-12 03:12:18 +000099 stubsAllocated++;
Jeffrey Yasskin7a9034c2009-10-27 00:03:05 +0000100 return Base->allocateStub(F, StubSize, Alignment);
101 }
102 struct EndFunctionBodyCall {
103 EndFunctionBodyCall(const Function *F, uint8_t *FunctionStart,
104 uint8_t *FunctionEnd)
105 : F(F), F_dump(DumpFunction(F)),
106 FunctionStart(FunctionStart), FunctionEnd(FunctionEnd) {}
107 const Function *F;
108 std::string F_dump;
109 uint8_t *FunctionStart;
110 uint8_t *FunctionEnd;
111 };
112 std::vector<EndFunctionBodyCall> endFunctionBodyCalls;
113 virtual void endFunctionBody(const Function *F, uint8_t *FunctionStart,
114 uint8_t *FunctionEnd) {
115 endFunctionBodyCalls.push_back(
116 EndFunctionBodyCall(F, FunctionStart, FunctionEnd));
117 Base->endFunctionBody(F, FunctionStart, FunctionEnd);
118 }
Jim Grosbach61425c02012-01-16 22:26:39 +0000119 virtual uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
Andrew Kaylor53608a32012-11-15 23:50:01 +0000120 unsigned SectionID, bool IsReadOnly) {
121 return Base->allocateDataSection(Size, Alignment, SectionID, IsReadOnly);
Jim Grosbach61425c02012-01-16 22:26:39 +0000122 }
123 virtual uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
124 unsigned SectionID) {
125 return Base->allocateCodeSection(Size, Alignment, SectionID);
126 }
Andrew Kaylor53608a32012-11-15 23:50:01 +0000127 virtual bool applyPermissions(std::string *ErrMsg) { return false; }
Jeffrey Yasskin7a9034c2009-10-27 00:03:05 +0000128 virtual uint8_t *allocateSpace(intptr_t Size, unsigned Alignment) {
129 return Base->allocateSpace(Size, Alignment);
130 }
131 virtual uint8_t *allocateGlobal(uintptr_t Size, unsigned Alignment) {
132 return Base->allocateGlobal(Size, Alignment);
133 }
134 struct DeallocateFunctionBodyCall {
135 DeallocateFunctionBodyCall(const void *Body) : Body(Body) {}
136 const void *Body;
137 };
138 std::vector<DeallocateFunctionBodyCall> deallocateFunctionBodyCalls;
139 virtual void deallocateFunctionBody(void *Body) {
140 deallocateFunctionBodyCalls.push_back(DeallocateFunctionBodyCall(Body));
141 Base->deallocateFunctionBody(Body);
142 }
143 struct DeallocateExceptionTableCall {
144 DeallocateExceptionTableCall(const void *ET) : ET(ET) {}
145 const void *ET;
146 };
147 std::vector<DeallocateExceptionTableCall> deallocateExceptionTableCalls;
148 virtual void deallocateExceptionTable(void *ET) {
149 deallocateExceptionTableCalls.push_back(DeallocateExceptionTableCall(ET));
150 Base->deallocateExceptionTable(ET);
151 }
152 struct StartExceptionTableCall {
153 StartExceptionTableCall(uint8_t *Result, const Function *F,
154 uintptr_t ActualSize, uintptr_t ActualSizeResult)
155 : Result(Result), F(F), F_dump(DumpFunction(F)),
156 ActualSize(ActualSize), ActualSizeResult(ActualSizeResult) {}
157 uint8_t *Result;
158 const Function *F;
159 std::string F_dump;
160 uintptr_t ActualSize;
161 uintptr_t ActualSizeResult;
162 };
163 std::vector<StartExceptionTableCall> startExceptionTableCalls;
Eli Benderskydced3cd2013-01-11 16:33:30 +0000164 virtual uint8_t *startExceptionTable(const Function *F,
Jeffrey Yasskin7a9034c2009-10-27 00:03:05 +0000165 uintptr_t &ActualSize) {
166 uintptr_t InitialActualSize = ActualSize;
167 uint8_t *Result = Base->startExceptionTable(F, ActualSize);
168 startExceptionTableCalls.push_back(
169 StartExceptionTableCall(Result, F, InitialActualSize, ActualSize));
170 return Result;
171 }
172 struct EndExceptionTableCall {
173 EndExceptionTableCall(const Function *F, uint8_t *TableStart,
174 uint8_t *TableEnd, uint8_t* FrameRegister)
175 : F(F), F_dump(DumpFunction(F)),
176 TableStart(TableStart), TableEnd(TableEnd),
177 FrameRegister(FrameRegister) {}
178 const Function *F;
179 std::string F_dump;
180 uint8_t *TableStart;
181 uint8_t *TableEnd;
182 uint8_t *FrameRegister;
183 };
184 std::vector<EndExceptionTableCall> endExceptionTableCalls;
185 virtual void endExceptionTable(const Function *F, uint8_t *TableStart,
186 uint8_t *TableEnd, uint8_t* FrameRegister) {
187 endExceptionTableCalls.push_back(
188 EndExceptionTableCall(F, TableStart, TableEnd, FrameRegister));
189 return Base->endExceptionTable(F, TableStart, TableEnd, FrameRegister);
190 }
191};
192
Jeffrey Yasskinc5818fb2009-12-22 23:47:23 +0000193bool LoadAssemblyInto(Module *M, const char *assembly) {
194 SMDiagnostic Error;
195 bool success =
196 NULL != ParseAssemblyString(assembly, M, Error, M->getContext());
197 std::string errMsg;
198 raw_string_ostream os(errMsg);
Chris Lattnerd8b7aa22011-10-16 04:47:35 +0000199 Error.print("", os);
Jeffrey Yasskinc5818fb2009-12-22 23:47:23 +0000200 EXPECT_TRUE(success) << os.str();
201 return success;
202}
203
Jeffrey Yasskinea5ed002009-10-06 00:35:55 +0000204class JITTest : public testing::Test {
205 protected:
Eli Benderskydced3cd2013-01-11 16:33:30 +0000206 virtual RecordingJITMemoryManager *createMemoryManager() {
207 return new RecordingJITMemoryManager;
208 }
209
Jeffrey Yasskinea5ed002009-10-06 00:35:55 +0000210 virtual void SetUp() {
211 M = new Module("<main>", Context);
Eli Benderskydced3cd2013-01-11 16:33:30 +0000212 RJMM = createMemoryManager();
Jeffrey Yasskin108c8382009-11-23 23:35:19 +0000213 RJMM->setPoisonMemory(true);
Jeffrey Yasskinea5ed002009-10-06 00:35:55 +0000214 std::string Error;
Eli Benderskydced3cd2013-01-11 16:33:30 +0000215 TargetOptions Options;
216 Options.JITExceptionHandling = true;
Jeffrey Yasskinf0356fe2010-01-27 20:34:15 +0000217 TheJIT.reset(EngineBuilder(M).setEngineKind(EngineKind::JIT)
Jeffrey Yasskin7a9034c2009-10-27 00:03:05 +0000218 .setJITMemoryManager(RJMM)
Eli Benderskydced3cd2013-01-11 16:33:30 +0000219 .setErrorStr(&Error)
220 .setTargetOptions(Options).create());
Jeffrey Yasskinea5ed002009-10-06 00:35:55 +0000221 ASSERT_TRUE(TheJIT.get() != NULL) << Error;
222 }
223
Jeffrey Yasskin23e5fcf2009-10-23 22:37:43 +0000224 void LoadAssembly(const char *assembly) {
Jeffrey Yasskinc5818fb2009-12-22 23:47:23 +0000225 LoadAssemblyInto(M, assembly);
Jeffrey Yasskin23e5fcf2009-10-23 22:37:43 +0000226 }
227
Jeffrey Yasskinea5ed002009-10-06 00:35:55 +0000228 LLVMContext Context;
Jeffrey Yasskinf0356fe2010-01-27 20:34:15 +0000229 Module *M; // Owned by ExecutionEngine.
Jeffrey Yasskin7a9034c2009-10-27 00:03:05 +0000230 RecordingJITMemoryManager *RJMM;
Jeffrey Yasskinea5ed002009-10-06 00:35:55 +0000231 OwningPtr<ExecutionEngine> TheJIT;
232};
233
Ulrich Weigandf772f072012-10-31 16:18:02 +0000234// Tests on ARM and PowerPC disabled as we're running the old jit
235#if !defined(__arm__) && !defined(__powerpc__)
James Molloyc1054712012-10-08 13:06:30 +0000236
Jeffrey Yasskin489393d2009-07-08 21:59:57 +0000237// Regression test for a bug. The JIT used to allocate globals inside the same
238// memory block used for the function, and when the function code was freed,
239// the global was left in the same place. This test allocates a function
240// that uses and global, deallocates it, and then makes sure that the global
241// stays alive after that.
242TEST(JIT, GlobalInFunction) {
243 LLVMContext context;
244 Module *M = new Module("<main>", context);
Jeffrey Yasskin489393d2009-07-08 21:59:57 +0000245
246 JITMemoryManager *MemMgr = JITMemoryManager::CreateDefaultMemManager();
247 // Tell the memory manager to poison freed memory so that accessing freed
248 // memory is more easily tested.
249 MemMgr->setPoisonMemory(true);
250 std::string Error;
Jeffrey Yasskinf0356fe2010-01-27 20:34:15 +0000251 OwningPtr<ExecutionEngine> JIT(EngineBuilder(M)
Daniel Dunbard370d772009-07-18 06:08:49 +0000252 .setEngineKind(EngineKind::JIT)
Reid Kleckner4b1511b2009-07-18 00:42:18 +0000253 .setErrorStr(&Error)
254 .setJITMemoryManager(MemMgr)
255 // The next line enables the fix:
256 .setAllocateGVsWithCode(false)
257 .create());
Jeffrey Yasskin489393d2009-07-08 21:59:57 +0000258 ASSERT_EQ(Error, "");
259
260 // Create a global variable.
Chris Lattnerdb125cf2011-07-18 04:54:35 +0000261 Type *GTy = Type::getInt32Ty(context);
Jeffrey Yasskin489393d2009-07-08 21:59:57 +0000262 GlobalVariable *G = new GlobalVariable(
263 *M,
264 GTy,
265 false, // Not constant.
266 GlobalValue::InternalLinkage,
Benjamin Kramerfeba7562009-07-31 20:56:31 +0000267 Constant::getNullValue(GTy),
Jeffrey Yasskin489393d2009-07-08 21:59:57 +0000268 "myglobal");
269
270 // Make a function that points to a global.
271 Function *F1 = makeReturnGlobal("F1", G, M);
272
273 // Get the pointer to the native code to force it to JIT the function and
274 // allocate space for the global.
Jeffrey Yasskin0f2ba782009-10-06 19:06:16 +0000275 void (*F1Ptr)() =
276 reinterpret_cast<void(*)()>((intptr_t)JIT->getPointerToFunction(F1));
Jeffrey Yasskin489393d2009-07-08 21:59:57 +0000277
278 // Since F1 was codegen'd, a pointer to G should be available.
279 int32_t *GPtr = (int32_t*)JIT->getPointerToGlobalIfAvailable(G);
280 ASSERT_NE((int32_t*)NULL, GPtr);
281 EXPECT_EQ(0, *GPtr);
282
283 // F1() should increment G.
284 F1Ptr();
285 EXPECT_EQ(1, *GPtr);
286
287 // Make a second function identical to the first, referring to the same
288 // global.
289 Function *F2 = makeReturnGlobal("F2", G, M);
Jeffrey Yasskin0f2ba782009-10-06 19:06:16 +0000290 void (*F2Ptr)() =
291 reinterpret_cast<void(*)()>((intptr_t)JIT->getPointerToFunction(F2));
Jeffrey Yasskin489393d2009-07-08 21:59:57 +0000292
293 // F2() should increment G.
294 F2Ptr();
295 EXPECT_EQ(2, *GPtr);
296
297 // Deallocate F1.
298 JIT->freeMachineCodeForFunction(F1);
299
300 // F2() should *still* increment G.
301 F2Ptr();
302 EXPECT_EQ(3, *GPtr);
303}
304
Ulrich Weigandf772f072012-10-31 16:18:02 +0000305#endif // !defined(__arm__) && !defined(__powerpc__)
James Molloyc1054712012-10-08 13:06:30 +0000306
Eli Benderskydced3cd2013-01-11 16:33:30 +0000307// Regression test for a bug. The JITEmitter wasn't checking to verify that
308// it hadn't run out of space while generating the DWARF exception information
309// for an emitted function.
310
311class ExceptionMemoryManagerMock : public RecordingJITMemoryManager {
312 public:
313 virtual uint8_t *startExceptionTable(const Function *F,
314 uintptr_t &ActualSize) {
315 // force an insufficient size the first time through.
316 bool ChangeActualSize = false;
317 if (ActualSize == 0)
318 ChangeActualSize = true;;
319 uint8_t *result =
320 RecordingJITMemoryManager::startExceptionTable(F, ActualSize);
321 if (ChangeActualSize)
322 ActualSize = 1;
323 return result;
324 }
325};
326
327class JITExceptionMemoryTest : public JITTest {
328 protected:
329 virtual RecordingJITMemoryManager *createMemoryManager() {
330 return new ExceptionMemoryManagerMock;
331 }
332};
333
334TEST_F(JITExceptionMemoryTest, ExceptionTableOverflow) {
335 Function *F = Function::Create(TypeBuilder<void(void), false>::get(Context),
336 Function::ExternalLinkage,
337 "func1", M);
338 BasicBlock *Block = BasicBlock::Create(Context, "block", F);
339 IRBuilder<> Builder(Block);
340 Builder.CreateRetVoid();
341 TheJIT->getPointerToFunction(F);
342 ASSERT_TRUE(RJMM->startExceptionTableCalls.size() == 2);
343 ASSERT_TRUE(RJMM->deallocateExceptionTableCalls.size() == 1);
344 ASSERT_TRUE(RJMM->endExceptionTableCalls.size() == 1);
345}
346
Jeffrey Yasskinea5ed002009-10-06 00:35:55 +0000347int PlusOne(int arg) {
348 return arg + 1;
349}
350
Ulrich Weigandf772f072012-10-31 16:18:02 +0000351// ARM and PowerPC tests disabled pending fix for PR10783.
352#if !defined(__arm__) && !defined(__powerpc__)
Jeffrey Yasskinea5ed002009-10-06 00:35:55 +0000353TEST_F(JITTest, FarCallToKnownFunction) {
354 // x86-64 can only make direct calls to functions within 32 bits of
355 // the current PC. To call anything farther away, we have to load
356 // the address into a register and call through the register. The
357 // current JIT does this by allocating a stub for any far call.
358 // There was a bug in which the JIT tried to emit a direct call when
359 // the target was already in the JIT's global mappings and lazy
360 // compilation was disabled.
361
362 Function *KnownFunction = Function::Create(
363 TypeBuilder<int(int), false>::get(Context),
364 GlobalValue::ExternalLinkage, "known", M);
365 TheJIT->addGlobalMapping(KnownFunction, (void*)(intptr_t)PlusOne);
366
367 // int test() { return known(7); }
368 Function *TestFunction = Function::Create(
369 TypeBuilder<int(), false>::get(Context),
370 GlobalValue::ExternalLinkage, "test", M);
371 BasicBlock *Entry = BasicBlock::Create(Context, "entry", TestFunction);
372 IRBuilder<> Builder(Entry);
373 Value *result = Builder.CreateCall(
374 KnownFunction,
375 ConstantInt::get(TypeBuilder<int, false>::get(Context), 7));
376 Builder.CreateRet(result);
377
Jeffrey Yasskin18fec732009-10-27 22:39:42 +0000378 TheJIT->DisableLazyCompilation(true);
Jeffrey Yasskinea5ed002009-10-06 00:35:55 +0000379 int (*TestFunctionPtr)() = reinterpret_cast<int(*)()>(
380 (intptr_t)TheJIT->getPointerToFunction(TestFunction));
381 // This used to crash in trying to call PlusOne().
382 EXPECT_EQ(8, TestFunctionPtr());
383}
384
Jeffrey Yasskine5f87982009-10-13 21:32:57 +0000385// Test a function C which calls A and B which call each other.
386TEST_F(JITTest, NonLazyCompilationStillNeedsStubs) {
Jeffrey Yasskin18fec732009-10-27 22:39:42 +0000387 TheJIT->DisableLazyCompilation(true);
Jeffrey Yasskine5f87982009-10-13 21:32:57 +0000388
Chris Lattnerdb125cf2011-07-18 04:54:35 +0000389 FunctionType *Func1Ty =
Jeffrey Yasskine5f87982009-10-13 21:32:57 +0000390 cast<FunctionType>(TypeBuilder<void(void), false>::get(Context));
Jay Foad5fdd6c82011-07-12 14:06:48 +0000391 std::vector<Type*> arg_types;
Jeffrey Yasskine5f87982009-10-13 21:32:57 +0000392 arg_types.push_back(Type::getInt1Ty(Context));
Chris Lattnerdb125cf2011-07-18 04:54:35 +0000393 FunctionType *FuncTy = FunctionType::get(
Jeffrey Yasskine5f87982009-10-13 21:32:57 +0000394 Type::getVoidTy(Context), arg_types, false);
395 Function *Func1 = Function::Create(Func1Ty, Function::ExternalLinkage,
396 "func1", M);
397 Function *Func2 = Function::Create(FuncTy, Function::InternalLinkage,
398 "func2", M);
399 Function *Func3 = Function::Create(FuncTy, Function::InternalLinkage,
400 "func3", M);
401 BasicBlock *Block1 = BasicBlock::Create(Context, "block1", Func1);
402 BasicBlock *Block2 = BasicBlock::Create(Context, "block2", Func2);
403 BasicBlock *True2 = BasicBlock::Create(Context, "cond_true", Func2);
404 BasicBlock *False2 = BasicBlock::Create(Context, "cond_false", Func2);
405 BasicBlock *Block3 = BasicBlock::Create(Context, "block3", Func3);
406 BasicBlock *True3 = BasicBlock::Create(Context, "cond_true", Func3);
407 BasicBlock *False3 = BasicBlock::Create(Context, "cond_false", Func3);
408
409 // Make Func1 call Func2(0) and Func3(0).
410 IRBuilder<> Builder(Block1);
411 Builder.CreateCall(Func2, ConstantInt::getTrue(Context));
412 Builder.CreateCall(Func3, ConstantInt::getTrue(Context));
413 Builder.CreateRetVoid();
414
415 // void Func2(bool b) { if (b) { Func3(false); return; } return; }
416 Builder.SetInsertPoint(Block2);
417 Builder.CreateCondBr(Func2->arg_begin(), True2, False2);
418 Builder.SetInsertPoint(True2);
419 Builder.CreateCall(Func3, ConstantInt::getFalse(Context));
420 Builder.CreateRetVoid();
421 Builder.SetInsertPoint(False2);
422 Builder.CreateRetVoid();
423
424 // void Func3(bool b) { if (b) { Func2(false); return; } return; }
425 Builder.SetInsertPoint(Block3);
426 Builder.CreateCondBr(Func3->arg_begin(), True3, False3);
427 Builder.SetInsertPoint(True3);
428 Builder.CreateCall(Func2, ConstantInt::getFalse(Context));
429 Builder.CreateRetVoid();
430 Builder.SetInsertPoint(False3);
431 Builder.CreateRetVoid();
432
433 // Compile the function to native code
434 void (*F1Ptr)() =
435 reinterpret_cast<void(*)()>((intptr_t)TheJIT->getPointerToFunction(Func1));
436
437 F1Ptr();
438}
439
440// Regression test for PR5162. This used to trigger an AssertingVH inside the
441// JIT's Function to stub mapping.
442TEST_F(JITTest, NonLazyLeaksNoStubs) {
Jeffrey Yasskin18fec732009-10-27 22:39:42 +0000443 TheJIT->DisableLazyCompilation(true);
Jeffrey Yasskine5f87982009-10-13 21:32:57 +0000444
445 // Create two functions with a single basic block each.
Chris Lattnerdb125cf2011-07-18 04:54:35 +0000446 FunctionType *FuncTy =
Jeffrey Yasskine5f87982009-10-13 21:32:57 +0000447 cast<FunctionType>(TypeBuilder<int(), false>::get(Context));
448 Function *Func1 = Function::Create(FuncTy, Function::ExternalLinkage,
449 "func1", M);
450 Function *Func2 = Function::Create(FuncTy, Function::InternalLinkage,
451 "func2", M);
452 BasicBlock *Block1 = BasicBlock::Create(Context, "block1", Func1);
453 BasicBlock *Block2 = BasicBlock::Create(Context, "block2", Func2);
454
455 // The first function calls the second and returns the result
456 IRBuilder<> Builder(Block1);
457 Value *Result = Builder.CreateCall(Func2);
458 Builder.CreateRet(Result);
459
460 // The second function just returns a constant
461 Builder.SetInsertPoint(Block2);
462 Builder.CreateRet(ConstantInt::get(TypeBuilder<int, false>::get(Context),42));
463
464 // Compile the function to native code
465 (void)TheJIT->getPointerToFunction(Func1);
466
467 // Free the JIT state for the functions
468 TheJIT->freeMachineCodeForFunction(Func1);
469 TheJIT->freeMachineCodeForFunction(Func2);
470
471 // Delete the first function (and show that is has no users)
472 EXPECT_EQ(Func1->getNumUses(), 0u);
473 Func1->eraseFromParent();
474
475 // Delete the second function (and show that it has no users - it had one,
476 // func1 but that's gone now)
477 EXPECT_EQ(Func2->getNumUses(), 0u);
478 Func2->eraseFromParent();
479}
480
Jeffrey Yasskin23e5fcf2009-10-23 22:37:43 +0000481TEST_F(JITTest, ModuleDeletion) {
Jeffrey Yasskinb2352242009-10-28 00:28:31 +0000482 TheJIT->DisableLazyCompilation(false);
Jeffrey Yasskin23e5fcf2009-10-23 22:37:43 +0000483 LoadAssembly("define void @main() { "
484 " call i32 @computeVal() "
485 " ret void "
486 "} "
487 " "
488 "define internal i32 @computeVal() { "
489 " ret i32 0 "
490 "} ");
491 Function *func = M->getFunction("main");
492 TheJIT->getPointerToFunction(func);
Jeffrey Yasskinf0356fe2010-01-27 20:34:15 +0000493 TheJIT->removeModule(M);
494 delete M;
Jeffrey Yasskin7a9034c2009-10-27 00:03:05 +0000495
496 SmallPtrSet<const void*, 2> FunctionsDeallocated;
497 for (unsigned i = 0, e = RJMM->deallocateFunctionBodyCalls.size();
498 i != e; ++i) {
499 FunctionsDeallocated.insert(RJMM->deallocateFunctionBodyCalls[i].Body);
500 }
501 for (unsigned i = 0, e = RJMM->startFunctionBodyCalls.size(); i != e; ++i) {
502 EXPECT_TRUE(FunctionsDeallocated.count(
503 RJMM->startFunctionBodyCalls[i].Result))
504 << "Function leaked: \n" << RJMM->startFunctionBodyCalls[i].F_dump;
505 }
506 EXPECT_EQ(RJMM->startFunctionBodyCalls.size(),
507 RJMM->deallocateFunctionBodyCalls.size());
508
509 SmallPtrSet<const void*, 2> ExceptionTablesDeallocated;
Jeffrey Yasskinb069c912009-11-11 05:30:02 +0000510 unsigned NumTablesDeallocated = 0;
Jeffrey Yasskin7a9034c2009-10-27 00:03:05 +0000511 for (unsigned i = 0, e = RJMM->deallocateExceptionTableCalls.size();
512 i != e; ++i) {
513 ExceptionTablesDeallocated.insert(
514 RJMM->deallocateExceptionTableCalls[i].ET);
Jeffrey Yasskinb069c912009-11-11 05:30:02 +0000515 if (RJMM->deallocateExceptionTableCalls[i].ET != NULL) {
516 // If JITEmitDebugInfo is off, we'll "deallocate" NULL, which doesn't
517 // appear in startExceptionTableCalls.
518 NumTablesDeallocated++;
519 }
Jeffrey Yasskin7a9034c2009-10-27 00:03:05 +0000520 }
521 for (unsigned i = 0, e = RJMM->startExceptionTableCalls.size(); i != e; ++i) {
522 EXPECT_TRUE(ExceptionTablesDeallocated.count(
523 RJMM->startExceptionTableCalls[i].Result))
524 << "Function's exception table leaked: \n"
525 << RJMM->startExceptionTableCalls[i].F_dump;
526 }
527 EXPECT_EQ(RJMM->startExceptionTableCalls.size(),
Jeffrey Yasskinb069c912009-11-11 05:30:02 +0000528 NumTablesDeallocated);
Jeffrey Yasskin23e5fcf2009-10-23 22:37:43 +0000529}
Ulrich Weigandf772f072012-10-31 16:18:02 +0000530#endif // !defined(__arm__) && !defined(__powerpc__)
Jeffrey Yasskin23e5fcf2009-10-23 22:37:43 +0000531
Simon Atanasyand9389352012-05-16 19:07:55 +0000532// ARM, MIPS and PPC still emit stubs for calls since the target may be
533// too far away to call directly. This #if can probably be removed when
Jeffrey Yasskin630382a2009-11-24 02:11:14 +0000534// http://llvm.org/PR5201 is fixed.
Simon Atanasyand9389352012-05-16 19:07:55 +0000535#if !defined(__arm__) && !defined(__mips__) && \
536 !defined(__powerpc__) && !defined(__ppc__)
Eric Christopher116664a2009-11-12 03:12:18 +0000537typedef int (*FooPtr) ();
538
539TEST_F(JITTest, NoStubs) {
540 LoadAssembly("define void @bar() {"
541 "entry: "
542 "ret void"
543 "}"
544 " "
545 "define i32 @foo() {"
546 "entry:"
547 "call void @bar()"
548 "ret i32 undef"
549 "}"
550 " "
551 "define i32 @main() {"
552 "entry:"
553 "%0 = call i32 @foo()"
554 "call void @bar()"
555 "ret i32 undef"
556 "}");
557 Function *foo = M->getFunction("foo");
558 uintptr_t tmp = (uintptr_t)(TheJIT->getPointerToFunction(foo));
559 FooPtr ptr = (FooPtr)(tmp);
560
561 (ptr)();
562
563 // We should now allocate no more stubs, we have the code to foo
564 // and the existing stub for bar.
565 int stubsBefore = RJMM->stubsAllocated;
566 Function *func = M->getFunction("main");
567 TheJIT->getPointerToFunction(func);
568
569 Function *bar = M->getFunction("bar");
570 TheJIT->getPointerToFunction(bar);
571
572 ASSERT_EQ(stubsBefore, RJMM->stubsAllocated);
573}
Jeffrey Yasskin630382a2009-11-24 02:11:14 +0000574#endif // !ARM && !PPC
Jeffrey Yasskin108c8382009-11-23 23:35:19 +0000575
Ulrich Weigandf772f072012-10-31 16:18:02 +0000576// Tests on ARM and PowerPC disabled as we're running the old jit
577#if !defined(__arm__) && !defined(__powerpc__)
James Molloyc1054712012-10-08 13:06:30 +0000578
Jeffrey Yasskin108c8382009-11-23 23:35:19 +0000579TEST_F(JITTest, FunctionPointersOutliveTheirCreator) {
580 TheJIT->DisableLazyCompilation(true);
581 LoadAssembly("define i8()* @get_foo_addr() { "
582 " ret i8()* @foo "
583 "} "
584 " "
585 "define i8 @foo() { "
586 " ret i8 42 "
587 "} ");
588 Function *F_get_foo_addr = M->getFunction("get_foo_addr");
589
590 typedef char(*fooT)();
591 fooT (*get_foo_addr)() = reinterpret_cast<fooT(*)()>(
592 (intptr_t)TheJIT->getPointerToFunction(F_get_foo_addr));
593 fooT foo_addr = get_foo_addr();
594
595 // Now free get_foo_addr. This should not free the machine code for foo or
596 // any call stub returned as foo's canonical address.
597 TheJIT->freeMachineCodeForFunction(F_get_foo_addr);
598
599 // Check by calling the reported address of foo.
600 EXPECT_EQ(42, foo_addr());
601
602 // The reported address should also be the same as the result of a subsequent
603 // getPointerToFunction(foo).
604#if 0
605 // Fails until PR5126 is fixed:
606 Function *F_foo = M->getFunction("foo");
607 fooT foo = reinterpret_cast<fooT>(
608 (intptr_t)TheJIT->getPointerToFunction(F_foo));
609 EXPECT_EQ((intptr_t)foo, (intptr_t)foo_addr);
Bill Wendling0c2749f2009-11-13 21:58:54 +0000610#endif
Jeffrey Yasskin108c8382009-11-23 23:35:19 +0000611}
Eric Christopher116664a2009-11-12 03:12:18 +0000612
Ulrich Weigandf772f072012-10-31 16:18:02 +0000613#endif //!defined(__arm__) && !defined(__powerpc__)
James Molloyc1054712012-10-08 13:06:30 +0000614
Ulrich Weigandf772f072012-10-31 16:18:02 +0000615// Tests on ARM and PowerPC disabled as we're running the old jit
616// In addition, ARM does not have an implementation
Simon Atanasyand9389352012-05-16 19:07:55 +0000617// of replaceMachineCodeForFunction(), so recompileAndRelinkFunction
618// doesn't work.
Ulrich Weigandf772f072012-10-31 16:18:02 +0000619#if !defined(__arm__) && !defined(__powerpc__)
Jeffrey Yasskin92fdf452009-12-22 23:18:18 +0000620TEST_F(JITTest, FunctionIsRecompiledAndRelinked) {
621 Function *F = Function::Create(TypeBuilder<int(void), false>::get(Context),
622 GlobalValue::ExternalLinkage, "test", M);
623 BasicBlock *Entry = BasicBlock::Create(Context, "entry", F);
624 IRBuilder<> Builder(Entry);
625 Value *Val = ConstantInt::get(TypeBuilder<int, false>::get(Context), 1);
626 Builder.CreateRet(Val);
627
628 TheJIT->DisableLazyCompilation(true);
629 // Compile the function once, and make sure it works.
630 int (*OrigFPtr)() = reinterpret_cast<int(*)()>(
631 (intptr_t)TheJIT->recompileAndRelinkFunction(F));
632 EXPECT_EQ(1, OrigFPtr());
633
634 // Now change the function to return a different value.
635 Entry->eraseFromParent();
636 BasicBlock *NewEntry = BasicBlock::Create(Context, "new_entry", F);
637 Builder.SetInsertPoint(NewEntry);
638 Val = ConstantInt::get(TypeBuilder<int, false>::get(Context), 2);
639 Builder.CreateRet(Val);
640 // Recompile it, which should produce a new function pointer _and_ update the
641 // old one.
642 int (*NewFPtr)() = reinterpret_cast<int(*)()>(
643 (intptr_t)TheJIT->recompileAndRelinkFunction(F));
644
645 EXPECT_EQ(2, NewFPtr())
646 << "The new pointer should call the new version of the function";
647 EXPECT_EQ(2, OrigFPtr())
648 << "The old pointer's target should now jump to the new version";
649}
Ulrich Weigandf772f072012-10-31 16:18:02 +0000650#endif // !defined(__arm__) && !defined(__powerpc__)
Jeffrey Yasskin92fdf452009-12-22 23:18:18 +0000651
Jeffrey Yasskin898e9df2009-12-13 20:30:32 +0000652} // anonymous namespace
653// This variable is intentionally defined differently in the statically-compiled
654// program from the IR input to the JIT to assert that the JIT doesn't use its
655// definition.
656extern "C" int32_t JITTest_AvailableExternallyGlobal;
Bill Wendling80668fb2012-10-17 08:08:06 +0000657int32_t JITTest_AvailableExternallyGlobal LLVM_ATTRIBUTE_USED = 42;
Jeffrey Yasskin898e9df2009-12-13 20:30:32 +0000658namespace {
659
Ulrich Weigandf772f072012-10-31 16:18:02 +0000660// Tests on ARM and PowerPC disabled as we're running the old jit
661#if !defined(__arm__) && !defined(__powerpc__)
James Molloyc1054712012-10-08 13:06:30 +0000662
Jeffrey Yasskin898e9df2009-12-13 20:30:32 +0000663TEST_F(JITTest, AvailableExternallyGlobalIsntEmitted) {
664 TheJIT->DisableLazyCompilation(true);
665 LoadAssembly("@JITTest_AvailableExternallyGlobal = "
666 " available_externally global i32 7 "
667 " "
668 "define i32 @loader() { "
669 " %result = load i32* @JITTest_AvailableExternallyGlobal "
670 " ret i32 %result "
671 "} ");
672 Function *loaderIR = M->getFunction("loader");
673
674 int32_t (*loader)() = reinterpret_cast<int32_t(*)()>(
675 (intptr_t)TheJIT->getPointerToFunction(loaderIR));
676 EXPECT_EQ(42, loader()) << "func should return 42 from the external global,"
677 << " not 7 from the IR version.";
678}
Ulrich Weigandf772f072012-10-31 16:18:02 +0000679#endif //!defined(__arm__) && !defined(__powerpc__)
Jeffrey Yasskinaad0d522009-12-17 21:35:29 +0000680} // anonymous namespace
681// This function is intentionally defined differently in the statically-compiled
682// program from the IR input to the JIT to assert that the JIT doesn't use its
683// definition.
NAKAMURA Takumi8ab27a32012-10-12 08:09:29 +0000684extern "C" int32_t JITTest_AvailableExternallyFunction() LLVM_ATTRIBUTE_USED;
NAKAMURA Takumi97eb05b2012-10-12 01:34:07 +0000685extern "C" int32_t JITTest_AvailableExternallyFunction() {
Jeffrey Yasskinaad0d522009-12-17 21:35:29 +0000686 return 42;
687}
688namespace {
689
Ulrich Weigandf772f072012-10-31 16:18:02 +0000690// ARM and PowerPC tests disabled pending fix for PR10783.
691#if !defined(__arm__) && !defined(__powerpc__)
Jeffrey Yasskinaad0d522009-12-17 21:35:29 +0000692TEST_F(JITTest, AvailableExternallyFunctionIsntCompiled) {
693 TheJIT->DisableLazyCompilation(true);
694 LoadAssembly("define available_externally i32 "
695 " @JITTest_AvailableExternallyFunction() { "
696 " ret i32 7 "
697 "} "
698 " "
699 "define i32 @func() { "
700 " %result = tail call i32 "
701 " @JITTest_AvailableExternallyFunction() "
702 " ret i32 %result "
703 "} ");
704 Function *funcIR = M->getFunction("func");
705
706 int32_t (*func)() = reinterpret_cast<int32_t(*)()>(
707 (intptr_t)TheJIT->getPointerToFunction(funcIR));
708 EXPECT_EQ(42, func()) << "func should return 42 from the static version,"
709 << " not 7 from the IR version.";
710}
711
Jeffrey Yasskin39c75f22010-03-04 19:45:09 +0000712TEST_F(JITTest, EscapedLazyStubStillCallable) {
713 TheJIT->DisableLazyCompilation(false);
714 LoadAssembly("define internal i32 @stubbed() { "
715 " ret i32 42 "
716 "} "
717 " "
718 "define i32()* @get_stub() { "
719 " ret i32()* @stubbed "
720 "} ");
721 typedef int32_t(*StubTy)();
722
723 // Call get_stub() to get the address of @stubbed without actually JITting it.
724 Function *get_stubIR = M->getFunction("get_stub");
725 StubTy (*get_stub)() = reinterpret_cast<StubTy(*)()>(
726 (intptr_t)TheJIT->getPointerToFunction(get_stubIR));
727 StubTy stubbed = get_stub();
728 // Now get_stubIR is the only reference to stubbed's stub.
729 get_stubIR->eraseFromParent();
730 // Now there are no references inside the JIT, but we've got a pointer outside
731 // it. The stub should be callable and return the right value.
732 EXPECT_EQ(42, stubbed());
733}
734
Jeffrey Yasskinc5818fb2009-12-22 23:47:23 +0000735// Converts the LLVM assembly to bitcode and returns it in a std::string. An
736// empty string indicates an error.
737std::string AssembleToBitcode(LLVMContext &Context, const char *Assembly) {
738 Module TempModule("TempModule", Context);
739 if (!LoadAssemblyInto(&TempModule, Assembly)) {
740 return "";
741 }
742
743 std::string Result;
744 raw_string_ostream OS(Result);
745 WriteBitcodeToFile(&TempModule, OS);
746 OS.flush();
747 return Result;
748}
749
750// Returns a newly-created ExecutionEngine that reads the bitcode in 'Bitcode'
Jeffrey Yasskinf0356fe2010-01-27 20:34:15 +0000751// lazily. The associated Module (owned by the ExecutionEngine) is returned in
752// M. Both will be NULL on an error. Bitcode must live at least as long as the
753// ExecutionEngine.
Jeffrey Yasskinc5818fb2009-12-22 23:47:23 +0000754ExecutionEngine *getJITFromBitcode(
Jeffrey Yasskinf0356fe2010-01-27 20:34:15 +0000755 LLVMContext &Context, const std::string &Bitcode, Module *&M) {
Jeffrey Yasskinc5818fb2009-12-22 23:47:23 +0000756 // c_str() is null-terminated like MemoryBuffer::getMemBuffer requires.
757 MemoryBuffer *BitcodeBuffer =
Chris Lattner796e64b2010-04-05 22:49:48 +0000758 MemoryBuffer::getMemBuffer(Bitcode, "Bitcode for test");
Jeffrey Yasskinc5818fb2009-12-22 23:47:23 +0000759 std::string errMsg;
Jeffrey Yasskinf0356fe2010-01-27 20:34:15 +0000760 M = getLazyBitcodeModule(BitcodeBuffer, Context, &errMsg);
761 if (M == NULL) {
Jeffrey Yasskinc5818fb2009-12-22 23:47:23 +0000762 ADD_FAILURE() << errMsg;
763 delete BitcodeBuffer;
764 return NULL;
765 }
Jeffrey Yasskinf0356fe2010-01-27 20:34:15 +0000766 ExecutionEngine *TheJIT = EngineBuilder(M)
Jeffrey Yasskinc5818fb2009-12-22 23:47:23 +0000767 .setEngineKind(EngineKind::JIT)
768 .setErrorStr(&errMsg)
769 .create();
770 if (TheJIT == NULL) {
771 ADD_FAILURE() << errMsg;
Jeffrey Yasskinf0356fe2010-01-27 20:34:15 +0000772 delete M;
773 M = NULL;
Jeffrey Yasskinc5818fb2009-12-22 23:47:23 +0000774 return NULL;
775 }
776 return TheJIT;
777}
778
Jeffrey Yasskinf0356fe2010-01-27 20:34:15 +0000779TEST(LazyLoadedJITTest, MaterializableAvailableExternallyFunctionIsntCompiled) {
780 LLVMContext Context;
781 const std::string Bitcode =
782 AssembleToBitcode(Context,
783 "define available_externally i32 "
784 " @JITTest_AvailableExternallyFunction() { "
785 " ret i32 7 "
786 "} "
787 " "
788 "define i32 @func() { "
789 " %result = tail call i32 "
790 " @JITTest_AvailableExternallyFunction() "
791 " ret i32 %result "
792 "} ");
793 ASSERT_FALSE(Bitcode.empty()) << "Assembling failed";
794 Module *M;
795 OwningPtr<ExecutionEngine> TheJIT(getJITFromBitcode(Context, Bitcode, M));
796 ASSERT_TRUE(TheJIT.get()) << "Failed to create JIT.";
797 TheJIT->DisableLazyCompilation(true);
798
799 Function *funcIR = M->getFunction("func");
800 Function *availableFunctionIR =
801 M->getFunction("JITTest_AvailableExternallyFunction");
802
803 // Double-check that the available_externally function is still unmaterialized
804 // when getPointerToFunction needs to find out if it's available_externally.
805 EXPECT_TRUE(availableFunctionIR->isMaterializable());
806
807 int32_t (*func)() = reinterpret_cast<int32_t(*)()>(
808 (intptr_t)TheJIT->getPointerToFunction(funcIR));
809 EXPECT_EQ(42, func()) << "func should return 42 from the static version,"
810 << " not 7 from the IR version.";
811}
812
Jeffrey Yasskinc5818fb2009-12-22 23:47:23 +0000813TEST(LazyLoadedJITTest, EagerCompiledRecursionThroughGhost) {
814 LLVMContext Context;
815 const std::string Bitcode =
816 AssembleToBitcode(Context,
817 "define i32 @recur1(i32 %a) { "
818 " %zero = icmp eq i32 %a, 0 "
819 " br i1 %zero, label %done, label %notdone "
820 "done: "
821 " ret i32 3 "
822 "notdone: "
823 " %am1 = sub i32 %a, 1 "
824 " %result = call i32 @recur2(i32 %am1) "
825 " ret i32 %result "
826 "} "
827 " "
828 "define i32 @recur2(i32 %b) { "
829 " %result = call i32 @recur1(i32 %b) "
830 " ret i32 %result "
831 "} ");
832 ASSERT_FALSE(Bitcode.empty()) << "Assembling failed";
Jeffrey Yasskinf0356fe2010-01-27 20:34:15 +0000833 Module *M;
834 OwningPtr<ExecutionEngine> TheJIT(getJITFromBitcode(Context, Bitcode, M));
Jeffrey Yasskinc5818fb2009-12-22 23:47:23 +0000835 ASSERT_TRUE(TheJIT.get()) << "Failed to create JIT.";
836 TheJIT->DisableLazyCompilation(true);
837
Jeffrey Yasskinc5818fb2009-12-22 23:47:23 +0000838 Function *recur1IR = M->getFunction("recur1");
839 Function *recur2IR = M->getFunction("recur2");
Jeffrey Yasskinf0356fe2010-01-27 20:34:15 +0000840 EXPECT_TRUE(recur1IR->isMaterializable());
841 EXPECT_TRUE(recur2IR->isMaterializable());
Jeffrey Yasskinc5818fb2009-12-22 23:47:23 +0000842
843 int32_t (*recur1)(int32_t) = reinterpret_cast<int32_t(*)(int32_t)>(
844 (intptr_t)TheJIT->getPointerToFunction(recur1IR));
845 EXPECT_EQ(3, recur1(4));
846}
Ulrich Weigandf772f072012-10-31 16:18:02 +0000847#endif // !defined(__arm__) && !defined(__powerpc__)
Jeffrey Yasskinc5818fb2009-12-22 23:47:23 +0000848
Reid Kleckner4b1511b2009-07-18 00:42:18 +0000849// This code is copied from JITEventListenerTest, but it only runs once for all
850// the tests in this directory. Everything seems fine, but that's strange
851// behavior.
Jeffrey Yasskin489393d2009-07-08 21:59:57 +0000852class JITEnvironment : public testing::Environment {
853 virtual void SetUp() {
Reid Kleckner4b1511b2009-07-18 00:42:18 +0000854 // Required to create a JIT.
Jeffrey Yasskin489393d2009-07-08 21:59:57 +0000855 InitializeNativeTarget();
856 }
857};
858testing::Environment* const jit_env =
859 testing::AddGlobalTestEnvironment(new JITEnvironment);
860
861}