X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=unittests%2FExecutionEngine%2FMCJIT%2FMCJITObjectCacheTest.cpp;h=a245dbec999892f7ff0d5fe796ee025615f75ca2;hb=875710a2fd6b3c4f814961582594bd5c1cdb493a;hp=0061e30e7a541cfa0cc5c58f37020fd93a3a4d55;hpb=07f03923137a91e3cca5d7fc075a22f8c9baf33a;p=oota-llvm.git diff --git a/unittests/ExecutionEngine/MCJIT/MCJITObjectCacheTest.cpp b/unittests/ExecutionEngine/MCJIT/MCJITObjectCacheTest.cpp index 0061e30e7a5..a245dbec999 100644 --- a/unittests/ExecutionEngine/MCJIT/MCJITObjectCacheTest.cpp +++ b/unittests/ExecutionEngine/MCJIT/MCJITObjectCacheTest.cpp @@ -7,15 +7,13 @@ // //===----------------------------------------------------------------------===// -#include "llvm/ADT/OwningPtr.h" +#include "MCJITTestBase.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringSet.h" -#include "llvm/ExecutionEngine/JIT.h" #include "llvm/ExecutionEngine/MCJIT.h" #include "llvm/ExecutionEngine/ObjectCache.h" #include "llvm/ExecutionEngine/SectionMemoryManager.h" -#include "MCJITTestBase.h" #include "gtest/gtest.h" using namespace llvm; @@ -28,7 +26,7 @@ public: virtual ~TestObjectCache() { // Free any buffers we've allocated. - SmallVector::iterator it, end; + SmallVectorImpl::iterator it, end; end = AllocatedBuffers.end(); for (it = AllocatedBuffers.begin(); it != end; ++it) { delete *it; @@ -45,6 +43,16 @@ public: ObjMap[ModuleID] = copyBuffer(Obj); } + virtual MemoryBuffer* getObject(const Module* M) { + const MemoryBuffer* BufferFound = getObjectInternal(M); + ModulesLookedUp.insert(M->getModuleIdentifier()); + if (!BufferFound) + return nullptr; + // Our test cache wants to maintain ownership of its object buffers + // so we make a copy here for the execution engine. + return MemoryBuffer::getMemBufferCopy(BufferFound->getBuffer()); + } + // Test-harness-specific functions bool wereDuplicatesInserted() { return DuplicateInserted; } @@ -58,17 +66,10 @@ public: const std::string ModuleID = M->getModuleIdentifier(); StringMap::iterator it = ObjMap.find(ModuleID); if (it == ObjMap.end()) - return 0; + return nullptr; return it->second; } -protected: - virtual const MemoryBuffer* getObject(const Module* M) { - const MemoryBuffer* BufferFound = getObjectInternal(M); - ModulesLookedUp.insert(M->getModuleIdentifier()); - return BufferFound; - } - private: MemoryBuffer *copyBuffer(const MemoryBuffer *Buf) { // Create a local copy of the buffer. @@ -98,15 +99,14 @@ protected: void compileAndRun(int ExpectedRC = OriginalRC) { // This function shouldn't be called until after SetUp. - ASSERT_TRUE(0 != TheJIT); - ASSERT_TRUE(0 != Main); + ASSERT_TRUE(bool(TheJIT)); + ASSERT_TRUE(nullptr != Main); + // We may be using a null cache, so ensure compilation is valid. TheJIT->finalizeObject(); void *vPtr = TheJIT->getPointerToFunction(Main); - static_cast(MM)->invalidateInstructionCache(); - - EXPECT_TRUE(0 != vPtr) + EXPECT_TRUE(nullptr != vPtr) << "Unable to get pointer to main() from JIT"; int (*FuncPtr)(void) = (int(*)(void))(intptr_t)vPtr; @@ -120,9 +120,9 @@ protected: TEST_F(MCJITObjectCacheTest, SetNullObjectCache) { SKIP_UNSUPPORTED_PLATFORM; - createJIT(M.take()); + createJIT(M.release()); - TheJIT->setObjectCache(NULL); + TheJIT->setObjectCache(nullptr); compileAndRun(); } @@ -131,18 +131,18 @@ TEST_F(MCJITObjectCacheTest, SetNullObjectCache) { TEST_F(MCJITObjectCacheTest, VerifyBasicObjectCaching) { SKIP_UNSUPPORTED_PLATFORM; - OwningPtr Cache(new TestObjectCache); + std::unique_ptr Cache(new TestObjectCache); // Save a copy of the module pointer before handing it off to MCJIT. const Module * SavedModulePointer = M.get(); - createJIT(M.take()); + createJIT(M.release()); TheJIT->setObjectCache(Cache.get()); // Verify that our object cache does not contain the module yet. const MemoryBuffer *ObjBuffer = Cache->getObjectInternal(SavedModulePointer); - EXPECT_EQ(0, ObjBuffer); + EXPECT_EQ(nullptr, ObjBuffer); compileAndRun(); @@ -151,7 +151,7 @@ TEST_F(MCJITObjectCacheTest, VerifyBasicObjectCaching) { // Verify that our object cache now contains the module. ObjBuffer = Cache->getObjectInternal(SavedModulePointer); - EXPECT_TRUE(0 != ObjBuffer); + EXPECT_TRUE(nullptr != ObjBuffer); // Verify that the cache was only notified once. EXPECT_FALSE(Cache->wereDuplicatesInserted()); @@ -160,10 +160,10 @@ TEST_F(MCJITObjectCacheTest, VerifyBasicObjectCaching) { TEST_F(MCJITObjectCacheTest, VerifyLoadFromCache) { SKIP_UNSUPPORTED_PLATFORM; - OwningPtr Cache(new TestObjectCache); + std::unique_ptr Cache(new TestObjectCache); // Compile this module with an MCJIT engine - createJIT(M.take()); + createJIT(M.release()); TheJIT->setObjectCache(Cache.get()); TheJIT->finalizeObject(); @@ -180,7 +180,7 @@ TEST_F(MCJITObjectCacheTest, VerifyLoadFromCache) { const Module * SecondModulePointer = M.get(); // Create a new MCJIT instance to load this module then execute it. - createJIT(M.take()); + createJIT(M.release()); TheJIT->setObjectCache(Cache.get()); compileAndRun(); @@ -194,10 +194,10 @@ TEST_F(MCJITObjectCacheTest, VerifyLoadFromCache) { TEST_F(MCJITObjectCacheTest, VerifyNonLoadFromCache) { SKIP_UNSUPPORTED_PLATFORM; - OwningPtr Cache(new TestObjectCache); + std::unique_ptr Cache(new TestObjectCache); // Compile this module with an MCJIT engine - createJIT(M.take()); + createJIT(M.release()); TheJIT->setObjectCache(Cache.get()); TheJIT->finalizeObject(); @@ -215,12 +215,12 @@ TEST_F(MCJITObjectCacheTest, VerifyNonLoadFromCache) { const Module * SecondModulePointer = M.get(); // Create a new MCJIT instance to load this module then execute it. - createJIT(M.take()); + createJIT(M.release()); TheJIT->setObjectCache(Cache.get()); // Verify that our object cache does not contain the module yet. const MemoryBuffer *ObjBuffer = Cache->getObjectInternal(SecondModulePointer); - EXPECT_EQ(0, ObjBuffer); + EXPECT_EQ(nullptr, ObjBuffer); // Run the function and look for the replacement return code. compileAndRun(ReplacementRC); @@ -230,7 +230,7 @@ TEST_F(MCJITObjectCacheTest, VerifyNonLoadFromCache) { // Verify that our object cache now contains the module. ObjBuffer = Cache->getObjectInternal(SecondModulePointer); - EXPECT_TRUE(0 != ObjBuffer); + EXPECT_TRUE(nullptr != ObjBuffer); // Verify that MCJIT didn't try to cache this again. EXPECT_FALSE(Cache->wereDuplicatesInserted());