[llvm] r266380 - Nuke getGlobalContext() from LLVM (but the C API)

Mehdi Amini via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 14 14:59:18 PDT 2016


Author: mehdi_amini
Date: Thu Apr 14 16:59:18 2016
New Revision: 266380

URL: http://llvm.org/viewvc/llvm-project?rev=266380&view=rev
Log:
Nuke getGlobalContext() from LLVM (but the C API)

The only use for getGlobalContext() is in the C API.
Let's just move the static global here and nuke the C++ API.

Differential Revision: http://reviews.llvm.org/D19094

From: Mehdi Amini <mehdi.amini at apple.com>

Modified:
    llvm/trunk/include/llvm/IR/LLVMContext.h
    llvm/trunk/lib/IR/Core.cpp
    llvm/trunk/lib/IR/LLVMContext.cpp

Modified: llvm/trunk/include/llvm/IR/LLVMContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/LLVMContext.h?rev=266380&r1=266379&r2=266380&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/LLVMContext.h (original)
+++ llvm/trunk/include/llvm/IR/LLVMContext.h Thu Apr 14 16:59:18 2016
@@ -235,10 +235,6 @@ private:
   friend class Module;
 };
 
-/// getGlobalContext - Returns a global context.  This is for LLVM clients that
-/// only care about operating on a single thread.
-extern LLVMContext &getGlobalContext();
-
 // Create wrappers for C Binding types (see CBindingWrapping.h).
 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(LLVMContext, LLVMContextRef)
 

Modified: llvm/trunk/lib/IR/Core.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Core.cpp?rev=266380&r1=266379&r2=266380&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Core.cpp (original)
+++ llvm/trunk/lib/IR/Core.cpp Thu Apr 14 16:59:18 2016
@@ -73,13 +73,13 @@ void LLVMDisposeMessage(char *Message) {
 
 /*===-- Operations on contexts --------------------------------------------===*/
 
+static ManagedStatic<LLVMContext> GlobalContext;
+
 LLVMContextRef LLVMContextCreate() {
   return wrap(new LLVMContext());
 }
 
-LLVMContextRef LLVMGetGlobalContext() {
-  return wrap(&getGlobalContext());
-}
+LLVMContextRef LLVMGetGlobalContext() { return wrap(&*GlobalContext); }
 
 void LLVMContextSetDiagnosticHandler(LLVMContextRef C,
                                      LLVMDiagnosticHandler Handler,
@@ -155,7 +155,7 @@ LLVMDiagnosticSeverity LLVMGetDiagInfoSe
 /*===-- Operations on modules ---------------------------------------------===*/
 
 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID) {
-  return wrap(new Module(ModuleID, getGlobalContext()));
+  return wrap(new Module(ModuleID, *GlobalContext));
 }
 
 LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,

Modified: llvm/trunk/lib/IR/LLVMContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/LLVMContext.cpp?rev=266380&r1=266379&r2=266380&view=diff
==============================================================================
--- llvm/trunk/lib/IR/LLVMContext.cpp (original)
+++ llvm/trunk/lib/IR/LLVMContext.cpp Thu Apr 14 16:59:18 2016
@@ -25,12 +25,6 @@
 #include <cctype>
 using namespace llvm;
 
-static ManagedStatic<LLVMContext> GlobalContext;
-
-LLVMContext& llvm::getGlobalContext() {
-  return *GlobalContext;
-}
-
 LLVMContext::LLVMContext() : pImpl(new LLVMContextImpl(*this)) {
   // Create the fixed metadata kinds. This is done in the same order as the
   // MD_* enum values so that they correspond.




More information about the llvm-commits mailing list