Add a first stab at describing LLVMContext.

llvm-svn: 79435
This commit is contained in:
Owen Anderson 2009-08-19 17:58:52 +00:00
parent b090bf4626
commit fe7bbc92e1
1 changed files with 45 additions and 0 deletions

View File

@ -147,6 +147,7 @@ with another <tt>Value</tt></a> </li>
</a></li>
<li><a href="#shutdown">Ending execution with <tt>llvm_shutdown()</tt></a></li>
<li><a href="#managedstatic">Lazy initialization with <tt>ManagedStatic</tt></a></li>
<li><a href="#llvmcontext">Achieving Isolation with <tt>LLVMContext</tt></a></li>
</ul>
</li>
@ -2402,6 +2403,50 @@ and only if you know what you're doing!
</p>
</div>
<!-- ======================================================================= -->
<div class="doc_subsection">
<a name="llvmcontext">Achieving Isolation with <tt>LLVMContext</tt></a>
</div>
<div class="doc_text">
<p>
<tt>LLVMContext</tt> 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,
<tt>LLVMContext</tt> exists to enable just this kind of scenario!
</p>
<p>
Conceptually, <tt>LLVMContext</tt> provides isolation. Every LLVM entity
(<tt>Module</tt>s, <tt>Value</tt>s, <tt>Type</tt>s, <tt>Constant</tt>s, etc.)
in LLVM's in-memory IR belongs to an <tt>LLVMContext</tt>. Entities in
different contexts <em>cannot</em> interact with each other: <tt>Module</tt>s in
different contexts cannot be linked together, <tt>Function</tt>s cannot be added
to <tt>Module</tt>s 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.
</p>
<p>
In practice, very few places in the API require the explicit specification of a
<tt>LLVMContext</tt>, other than the <tt>Type</tt> creation/lookup APIs.
Because every <tt>Type</tt> carries a reference to its owning context, most
other entities can determine what context they belong to by looking at their
own <tt>Type</tt>. If you are adding new entities to LLVM IR, please try to
maintain this interface design.
</p>
<p>
For clients that do <em>not</em> require the benefits of isolation, LLVM
provides a convenience API <tt>getGlobalContext()</tt>. This returns a global,
lazily initialized <tt>LLVMContext</tt> that may be used in situations where
isolation is not a concern.
</p>
</div>
<!-- *********************************************************************** -->
<div class="doc_section">
<a name="advanced">Advanced Topics</a>