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
diff --git a/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp b/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp
index 68ca53d..731f780 100644
--- a/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp
+++ b/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp
@@ -281,11 +281,11 @@
 TEST(JITMemoryManagerTest, AllocateSection) {
   OwningPtr<JITMemoryManager> 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 3b94d76..73976ab 100644
--- a/unittests/ExecutionEngine/JIT/JITTest.cpp
+++ b/unittests/ExecutionEngine/JIT/JITTest.cpp
@@ -135,13 +135,17 @@
       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 c434a7c..e4197dd 100644
--- a/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp
+++ b/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp
@@ -28,18 +28,20 @@
 
 static uint8_t *roundTripAllocateCodeSection(void *object, uintptr_t size,
                                              unsigned alignment,
-                                             unsigned sectionID) {
+                                             unsigned sectionID,
+                                             const char *sectionName) {
   didCallAllocateCodeSection = true;
   return static_cast<SectionMemoryManager*>(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<SectionMemoryManager*>(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 f6dbf98..c24346d 100644
--- a/unittests/ExecutionEngine/MCJIT/MCJITMemoryManagerTest.cpp
+++ b/unittests/ExecutionEngine/MCJIT/MCJITMemoryManagerTest.cpp
@@ -19,10 +19,10 @@
 TEST(MCJITMemoryManagerTest, BasicAllocations) {
   OwningPtr<SectionMemoryManager> 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, LargeAllocations) {
   OwningPtr<SectionMemoryManager> 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 @@
   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 @@
     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++) {