Commit Graph

14 Commits

Author SHA1 Message Date
Chandler Carruth
6b547686c5 Update the file headers across all of the LLVM projects in the monorepo
to reflect the new license.

We understand that people may be surprised that we're moving the header
entirely to discuss the new license. We checked this carefully with the
Foundation's lawyer and we believe this is the correct approach.

Essentially, all code in the project is now made available by the LLVM
project under our new license, so you will see that the license headers
include that license only. Some of our contributors have contributed
code under our old license, and accordingly, we have retained a copy of
our old license notice in the top-level files in each project and
repository.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351636 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-19 08:50:56 +00:00
Lang Hames
7373792b4a [ORC] Add more utilities to aid debugging output.
(1) A const accessor for the LLVMContext held by a ThreadSafeContext.

(2) A const accessor for the ThreadSafeModules held by an IRMaterializationUnit.

(3) A const MaterializationResponsibility reference to IRTransformLayer2's
    transform function. This makes IRTransformLayer2 useful for JIT debugging
    (since it can inspect JIT state through the responsibility argument) as well
    as program transformations.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@343365 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-28 21:49:53 +00:00
Lang Hames
217504b6a8 [ORC] clang-format the ThreadSafeModule code.
Evidently I forgot to do this before committing r343055.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@343288 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-28 01:41:33 +00:00
Lang Hames
7ea842c013 [ORC] Add a const version of ThreadSafeModule::getModule().
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@343287 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-28 01:41:33 +00:00
Lang Hames
2c78ea3621 [ORC] Lock ThreadSafeContext during module destruction in ThreadSafeModule's
move constructor.

This is basically the same fix as r343261, but applied to the move constructor:
Failure to lock the context during module destruction can lead to data races if
other threads are operating on the context.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@343286 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-28 01:41:29 +00:00
Lang Hames
3a5e132bb3 [ORC] Lock ThreadSafeContext during Module destructing in ThreadSafeModule.
Failure to lock the context can lead to data races if other threads are
operating on other ThreadSafeModules that share the same context.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@343261 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-27 20:36:08 +00:00
Lang Hames
d177f9e9bf Revert "Re-revert r343129."
This reverts commit 4e2557dbc7.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@343161 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-27 02:09:36 +00:00
Lang Hames
4e2557dbc7 Re-revert r343129.
Apparently the fixes in r343149 did not cover all the issues. Re-reverting
while I investigate.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@343151 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-26 23:32:53 +00:00
Lang Hames
1f88aa3059 Reapply r343129 with fix.
Explicitly defines ThreadSafeModule's move-assignment operator to move fields in
reverse order. This is required to ensure that the context field outlives the
module field.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@343149 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-26 22:34:33 +00:00
Lang Hames
bdab5ef14b Revert r343129 "[ORC] Change the field order of ThreadSafeModule to ensure the "
It broke several bots.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@343133 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-26 19:36:30 +00:00
Lang Hames
665fc45e84 [ORC] Change the field order of ThreadSafeModule to ensure the Module is
destroyed before its ThreadSharedContext.

Destroying the context first is an error if this ThreadSafeModule is the only
owner of its underlying context.

Add a unit test for ThreadSafeModule/ThreadSafeContext to catch this and other
basic usage issues.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@343129 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-26 18:50:01 +00:00
Lang Hames
d3429e96fe [ORC] Include-what-you-use fixes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@343057 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-26 02:01:39 +00:00
Lang Hames
6e5c098df1 [ORC] Fix a missing include in r343055.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@343056 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-26 01:54:13 +00:00
Lang Hames
d813c35f4c [ORC] Add ThreadSafeModule and ThreadSafeContext wrappers to support concurrent
compilation of IR in the JIT.

ThreadSafeContext is a pair of an LLVMContext and a mutex that can be used to
lock that context when it needs to be accessed from multiple threads.

ThreadSafeModule is a pair of a unique_ptr<Module> and a
shared_ptr<ThreadSafeContext>. This allows the lifetime of a ThreadSafeContext
to be managed automatically in terms of the ThreadSafeModules that refer to it:
Once all modules using a ThreadSafeContext are destructed, and providing the
client has not held on to a copy of shared context pointer, the context will be
automatically destructed.

This scheme is necessary due to the following constraits: (1) We need multiple
contexts for multithreaded compilation (at least one per compile thread plus
one to store any IR not currently being compiled, though one context per module
is simpler). (2) We need to free contexts that are no longer being used so that
the JIT does not leak memory over time. (3) Module lifetimes are not
predictable (modules are compiled as needed depending on the flow of JIT'd
code) so there is no single point where contexts could be reclaimed.

JIT clients not using concurrency can safely use one ThreadSafeContext for all
ThreadSafeModules.

JIT clients who want to be able to compile concurrently should use a different
ThreadSafeContext for each module, or call setCloneToNewContextOnEmit on their
top-level IRLayer. The former reduces compile latency (since no clone step is
needed) at the cost of additional memory overhead for uncompiled modules (as
every uncompiled module will duplicate the LLVM types, constants and metadata
that have been shared).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@343055 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-26 01:24:12 +00:00