[llvm-dev] What is the proper usage of LLVMContext?

David Chisnall via llvm-dev llvm-dev at lists.llvm.org
Tue Feb 21 06:30:12 PST 2017


On 21 Feb 2017, at 14:15, via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> 
> Q1) What is the difference between the following (A)`my_context` and (B)`global_context`?

These questions are really the same question.  LLVMContext is an object that contains (in theory) all of the global state associated with a use of LLVM.  Most LLVM functions are not thread safe, so you create an LLVMContext for each thread and, if you want to be able to free some memory, for each separate use of LLVM APIs (e.g. create a module and JIT it in one context, then clean up all of the memory except for the generated code).

The global context object exists to help migrate legacy code that predated the introduction of LLVMContext.  I thought it had been removed already, but if not then it probably will be eventually.  You should not use it in new code.

David



More information about the llvm-dev mailing list