llvm.org GIT mirror llvm / e0c951a
Add a first stab at describing LLVMContext. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79435 91177308-0d34-0410-b5e6-96231b3b80d8 Owen Anderson 10 years ago
1 changed file(s) with 45 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
146146
147147
  • Ending execution with llvm_shutdown()
  • 148148
  • Lazy initialization with ManagedStatic
  • 149
  • Achieving Isolation with LLVMContext
  • 149150
    150151
    151152
    23982399 APIs provide access to the global lock used to implement the double-checked
    23992400 locking for lazy initialization. These should only be used internally to LLVM,
    24002401 and only if you know what you're doing!
    2402

    2403
    2404
    2405
    2406
    2407 Achieving Isolation with LLVMContext
    2408
    2409
    2410
    2411

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

    2420
    2421

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

    2431
    2432

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

    2440
    2441

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

    24022447
    24032448