From e0c951a5afe253c1e66b565e0d28b3dfe5d586a7 Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Wed, 19 Aug 2009 17:58:52 +0000 Subject: [PATCH 1/1] Add a first stab at describing LLVMContext. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79435 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/ProgrammersManual.html | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/docs/ProgrammersManual.html b/docs/ProgrammersManual.html index e920cbbc646..eaed402d8af 100644 --- a/docs/ProgrammersManual.html +++ b/docs/ProgrammersManual.html @@ -147,6 +147,7 @@ with another Value
  • Ending execution with llvm_shutdown()
  • Lazy initialization with ManagedStatic
  • +
  • Achieving Isolation with LLVMContext
  • @@ -2402,6 +2403,50 @@ and only if you know what you're doing!

    + +
    + Achieving Isolation with LLVMContext +
    + +
    +

    +LLVMContext is an opaque class in the LLVM API which clients can use +to operate multiple, isolated instances of LLVM concurrently within the same +address space. For instance, in a hypothetical compile-server, the compilation +of an individual translation unit is conceptually independent from all the +others, and it would be desirable to be able to compile incoming translation +units concurrently on independent server threads. Fortunately, +LLVMContext exists to enable just this kind of scenario! +

    + +

    +Conceptually, LLVMContext provides isolation. Every LLVM entity +(Modules, Values, Types, Constants, etc.) +in LLVM's in-memory IR belongs to an LLVMContext. Entities in +different contexts cannot interact with each other: Modules in +different contexts cannot be linked together, Functions cannot be added +to Modules in different contexts, etc. What this means is that is is +safe to compile on multiple threads simultaneously, as long as no two threads +operate on entities within the same context. +

    + +

    +In practice, very few places in the API require the explicit specification of a +LLVMContext, other than the Type creation/lookup APIs. +Because every Type carries a reference to its owning context, most +other entities can determine what context they belong to by looking at their +own Type. If you are adding new entities to LLVM IR, please try to +maintain this interface design. +

    + +

    +For clients that do not require the benefits of isolation, LLVM +provides a convenience API getGlobalContext(). This returns a global, +lazily initialized LLVMContext that may be used in situations where +isolation is not a concern. +

    +
    +
    Advanced Topics -- 2.34.1