[llvm-commits] [llvm] r83353 - in /llvm/trunk: lib/ExecutionEngine/JIT/JITEmitter.cpp unittests/ExecutionEngine/JIT/JITTest.cpp
Daniel Dunbar
daniel at zuster.org
Sun Oct 25 23:08:10 PDT 2009
On Mon, Oct 5, 2009 at 5:35 PM, Jeffrey Yasskin <jyasskin at google.com> wrote:
> Author: jyasskin
> Date: Mon Oct 5 19:35:55 2009
> New Revision: 83353
>
> URL: http://llvm.org/viewvc/llvm-project?rev=83353&view=rev
> Log:
> Fix http://llvm.org/PR5116 by rolling back r60822. This passes `make unittests
> check-lit` on both x86-64 Linux and x86-32 Darwin.
Note that the unittests are automatically run as part of 'make check-lit'.
- Daniel
>
> Modified:
> llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp
> llvm/trunk/unittests/ExecutionEngine/JIT/JITTest.cpp
>
> Modified: llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp?rev=83353&r1=83352&r2=83353&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp (original)
> +++ llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp Mon Oct 5 19:35:55 2009
> @@ -644,7 +644,7 @@
> // If we have already compiled the function, return a pointer to its body.
> Function *F = cast<Function>(V);
> void *ResultPtr;
> - if (!DoesntNeedStub && !TheJIT->isLazyCompilationDisabled()) {
> + if (!DoesntNeedStub) {
> // Return the function stub if it's already created.
> ResultPtr = Resolver.getFunctionStubIfAvailable(F);
> if (ResultPtr)
>
> Modified: llvm/trunk/unittests/ExecutionEngine/JIT/JITTest.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/JIT/JITTest.cpp?rev=83353&r1=83352&r2=83353&view=diff
>
> ==============================================================================
> --- llvm/trunk/unittests/ExecutionEngine/JIT/JITTest.cpp (original)
> +++ llvm/trunk/unittests/ExecutionEngine/JIT/JITTest.cpp Mon Oct 5 19:35:55 2009
> @@ -22,6 +22,7 @@
> #include "llvm/Module.h"
> #include "llvm/ModuleProvider.h"
> #include "llvm/Support/IRBuilder.h"
> +#include "llvm/Support/TypeBuilder.h"
> #include "llvm/Target/TargetSelect.h"
> #include "llvm/Type.h"
>
> @@ -44,6 +45,21 @@
> return F;
> }
>
> +class JITTest : public testing::Test {
> + protected:
> + virtual void SetUp() {
> + M = new Module("<main>", Context);
> + std::string Error;
> + TheJIT.reset(EngineBuilder(M).setEngineKind(EngineKind::JIT)
> + .setErrorStr(&Error).create());
> + ASSERT_TRUE(TheJIT.get() != NULL) << Error;
> + }
> +
> + LLVMContext Context;
> + Module *M; // Owned by ExecutionEngine.
> + OwningPtr<ExecutionEngine> TheJIT;
> +};
> +
> // Regression test for a bug. The JIT used to allocate globals inside the same
> // memory block used for the function, and when the function code was freed,
> // the global was left in the same place. This test allocates a function
> @@ -115,6 +131,43 @@
> EXPECT_EQ(3, *GPtr);
> }
>
> +int PlusOne(int arg) {
> + return arg + 1;
> +}
> +
> +TEST_F(JITTest, FarCallToKnownFunction) {
> + // x86-64 can only make direct calls to functions within 32 bits of
> + // the current PC. To call anything farther away, we have to load
> + // the address into a register and call through the register. The
> + // current JIT does this by allocating a stub for any far call.
> + // There was a bug in which the JIT tried to emit a direct call when
> + // the target was already in the JIT's global mappings and lazy
> + // compilation was disabled.
> +
> + Function *KnownFunction = Function::Create(
> + TypeBuilder<int(int), false>::get(Context),
> + GlobalValue::ExternalLinkage, "known", M);
> + TheJIT->addGlobalMapping(KnownFunction, (void*)(intptr_t)PlusOne);
> +
> + // int test() { return known(7); }
> + Function *TestFunction = Function::Create(
> + TypeBuilder<int(), false>::get(Context),
> + GlobalValue::ExternalLinkage, "test", M);
> + BasicBlock *Entry = BasicBlock::Create(Context, "entry", TestFunction);
> + IRBuilder<> Builder(Entry);
> + Value *result = Builder.CreateCall(
> + KnownFunction,
> + ConstantInt::get(TypeBuilder<int, false>::get(Context), 7));
> + Builder.CreateRet(result);
> +
> + TheJIT->EnableDlsymStubs(false);
> + TheJIT->DisableLazyCompilation();
> + int (*TestFunctionPtr)() = reinterpret_cast<int(*)()>(
> + (intptr_t)TheJIT->getPointerToFunction(TestFunction));
> + // This used to crash in trying to call PlusOne().
> + EXPECT_EQ(8, TestFunctionPtr());
> +}
> +
> // This code is copied from JITEventListenerTest, but it only runs once for all
> // the tests in this directory. Everything seems fine, but that's strange
> // behavior.
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
More information about the llvm-commits
mailing list