From 6eb43d295625cd2ff314c59b49d4fd11f3348cad Mon Sep 17 00:00:00 2001 From: Filip Pizlo Date: Wed, 2 Oct 2013 00:59:25 +0000 Subject: This threads SectionName through the allocateCodeSection/allocateDataSection APIs, both in C++ and C land. It's useful for the memory managers that are allocating a section to know what the name of the section is. At a minimum, this is useful for low-level debugging - it's customary for JITs to be able to tell you what memory they allocated, and as part of any such dump, they should be able to tell you some meta-data about what each allocation is for. This allows clients that supply their own memory managers to do this. Additionally, we also envision the SectionName being useful for passing meta-data from within LLVM to an LLVM client. This changes both the C and C++ APIs, and all of the clients of those APIs within LLVM. I'm assuming that it's safe to change the C++ API because that API is allowed to change. I'm assuming that it's safe to change the C API because we haven't shipped the API in a release yet (LLVM 3.3 doesn't include the MCJIT memory management C API). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191804 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../ExecutionEngine/JIT/JITMemoryManagerTest.cpp | 10 ++++----- unittests/ExecutionEngine/JIT/JITTest.cpp | 16 +++++++++------ unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp | 8 +++++--- .../MCJIT/MCJITMemoryManagerTest.cpp | 24 +++++++++++----------- 4 files changed, 32 insertions(+), 26 deletions(-) (limited to 'unittests') diff --git a/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp b/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp index 68ca53d4e6..731f7807f5 100644 --- a/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp +++ b/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp @@ -281,11 +281,11 @@ TEST(JITMemoryManagerTest, TestManyStubs) { TEST(JITMemoryManagerTest, AllocateSection) { OwningPtr MemMgr( JITMemoryManager::CreateDefaultMemManager()); - uint8_t *code1 = MemMgr->allocateCodeSection(256, 0, 1); - uint8_t *data1 = MemMgr->allocateDataSection(256, 16, 2, true); - uint8_t *code2 = MemMgr->allocateCodeSection(257, 32, 3); - uint8_t *data2 = MemMgr->allocateDataSection(256, 64, 4, false); - uint8_t *code3 = MemMgr->allocateCodeSection(258, 64, 5); + uint8_t *code1 = MemMgr->allocateCodeSection(256, 0, 1, StringRef()); + uint8_t *data1 = MemMgr->allocateDataSection(256, 16, 2, StringRef(), true); + uint8_t *code2 = MemMgr->allocateCodeSection(257, 32, 3, StringRef()); + uint8_t *data2 = MemMgr->allocateDataSection(256, 64, 4, StringRef(), false); + uint8_t *code3 = MemMgr->allocateCodeSection(258, 64, 5, StringRef()); EXPECT_NE((uint8_t*)0, code1); EXPECT_NE((uint8_t*)0, code2); diff --git a/unittests/ExecutionEngine/JIT/JITTest.cpp b/unittests/ExecutionEngine/JIT/JITTest.cpp index 3b94d76d76..73976ab0f9 100644 --- a/unittests/ExecutionEngine/JIT/JITTest.cpp +++ b/unittests/ExecutionEngine/JIT/JITTest.cpp @@ -135,13 +135,17 @@ public: EndFunctionBodyCall(F, FunctionStart, FunctionEnd)); Base->endFunctionBody(F, FunctionStart, FunctionEnd); } - virtual uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment, - unsigned SectionID, bool IsReadOnly) { - return Base->allocateDataSection(Size, Alignment, SectionID, IsReadOnly); + virtual uint8_t *allocateDataSection( + uintptr_t Size, unsigned Alignment, unsigned SectionID, + StringRef SectionName, bool IsReadOnly) { + return Base->allocateDataSection( + Size, Alignment, SectionID, SectionName, IsReadOnly); } - virtual uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment, - unsigned SectionID) { - return Base->allocateCodeSection(Size, Alignment, SectionID); + virtual uint8_t *allocateCodeSection( + uintptr_t Size, unsigned Alignment, unsigned SectionID, + StringRef SectionName) { + return Base->allocateCodeSection( + Size, Alignment, SectionID, SectionName); } virtual bool finalizeMemory(std::string *ErrMsg) { return false; } virtual uint8_t *allocateSpace(intptr_t Size, unsigned Alignment) { diff --git a/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp b/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp index c434a7c0b2..e4197ddced 100644 --- a/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp +++ b/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp @@ -28,18 +28,20 @@ static bool didCallAllocateCodeSection; static uint8_t *roundTripAllocateCodeSection(void *object, uintptr_t size, unsigned alignment, - unsigned sectionID) { + unsigned sectionID, + const char *sectionName) { didCallAllocateCodeSection = true; return static_cast(object)->allocateCodeSection( - size, alignment, sectionID); + size, alignment, sectionID, sectionName); } static uint8_t *roundTripAllocateDataSection(void *object, uintptr_t size, unsigned alignment, unsigned sectionID, + const char *sectionName, LLVMBool isReadOnly) { return static_cast(object)->allocateDataSection( - size, alignment, sectionID, isReadOnly); + size, alignment, sectionID, sectionName, isReadOnly); } static LLVMBool roundTripFinalizeMemory(void *object, char **errMsg) { diff --git a/unittests/ExecutionEngine/MCJIT/MCJITMemoryManagerTest.cpp b/unittests/ExecutionEngine/MCJIT/MCJITMemoryManagerTest.cpp index f6dbf98450..c24346de84 100644 --- a/unittests/ExecutionEngine/MCJIT/MCJITMemoryManagerTest.cpp +++ b/unittests/ExecutionEngine/MCJIT/MCJITMemoryManagerTest.cpp @@ -19,10 +19,10 @@ namespace { TEST(MCJITMemoryManagerTest, BasicAllocations) { OwningPtr MemMgr(new SectionMemoryManager()); - uint8_t *code1 = MemMgr->allocateCodeSection(256, 0, 1); - uint8_t *data1 = MemMgr->allocateDataSection(256, 0, 2, true); - uint8_t *code2 = MemMgr->allocateCodeSection(256, 0, 3); - uint8_t *data2 = MemMgr->allocateDataSection(256, 0, 4, false); + uint8_t *code1 = MemMgr->allocateCodeSection(256, 0, 1, ""); + uint8_t *data1 = MemMgr->allocateDataSection(256, 0, 2, "", true); + uint8_t *code2 = MemMgr->allocateCodeSection(256, 0, 3, ""); + uint8_t *data2 = MemMgr->allocateDataSection(256, 0, 4, "", false); EXPECT_NE((uint8_t*)0, code1); EXPECT_NE((uint8_t*)0, code2); @@ -52,10 +52,10 @@ TEST(MCJITMemoryManagerTest, BasicAllocations) { TEST(MCJITMemoryManagerTest, LargeAllocations) { OwningPtr MemMgr(new SectionMemoryManager()); - uint8_t *code1 = MemMgr->allocateCodeSection(0x100000, 0, 1); - uint8_t *data1 = MemMgr->allocateDataSection(0x100000, 0, 2, true); - uint8_t *code2 = MemMgr->allocateCodeSection(0x100000, 0, 3); - uint8_t *data2 = MemMgr->allocateDataSection(0x100000, 0, 4, false); + uint8_t *code1 = MemMgr->allocateCodeSection(0x100000, 0, 1, ""); + uint8_t *data1 = MemMgr->allocateDataSection(0x100000, 0, 2, "", true); + uint8_t *code2 = MemMgr->allocateCodeSection(0x100000, 0, 3, ""); + uint8_t *data2 = MemMgr->allocateDataSection(0x100000, 0, 4, "", false); EXPECT_NE((uint8_t*)0, code1); EXPECT_NE((uint8_t*)0, code2); @@ -91,8 +91,8 @@ TEST(MCJITMemoryManagerTest, ManyAllocations) { for (unsigned i = 0; i < 10000; ++i) { const bool isReadOnly = i % 2 == 0; - code[i] = MemMgr->allocateCodeSection(32, 0, 1); - data[i] = MemMgr->allocateDataSection(32, 0, 2, isReadOnly); + code[i] = MemMgr->allocateCodeSection(32, 0, 1, ""); + data[i] = MemMgr->allocateDataSection(32, 0, 2, "", isReadOnly); for (unsigned j = 0; j < 32; j++) { code[i][j] = 1 + (i % 254); @@ -130,8 +130,8 @@ TEST(MCJITMemoryManagerTest, ManyVariedAllocations) { bool isReadOnly = i % 3 == 0; unsigned Align = 8 << (i % 4); - code[i] = MemMgr->allocateCodeSection(CodeSize, Align, i); - data[i] = MemMgr->allocateDataSection(DataSize, Align, i + 10000, + code[i] = MemMgr->allocateCodeSection(CodeSize, Align, i, ""); + data[i] = MemMgr->allocateDataSection(DataSize, Align, i + 10000, "", isReadOnly); for (unsigned j = 0; j < CodeSize; j++) { -- cgit v1.2.3