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

Mehdi Amini via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 29 15:31:45 PDT 2016


Answer here for the archive:

if any client was relying on this API, there is a very easy solution:

LLVMContext &getMyLLVMGlobalContext() {
  static LLVMContext MyGlobalContext;
  return MyGlobalContext;
}

I encourage people to avoid global mutable state in general though :)

-- 
Mehdi



> On Apr 14, 2016, at 2:59 PM, Mehdi Amini via llvm-commits <llvm-commits at lists.llvm.org> wrote:
> 
> 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.
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list