18 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
e87aaa1093 [ORC] Make the VModuleKey optional, propagate it via MaterializationUnit and
MaterializationResponsibility.

VModuleKeys are intended to enable selective removal of modules from a JIT
session, however for a wide variety of use cases selective removal is not
needed and introduces unnecessary overhead. As of this commit, the default
constructed VModuleKey value is reserved as a "do not track" value, and
becomes the default when adding a new module to the JIT.

This commit also changes the propagation of VModuleKeys. They were passed
alongside the MaterializationResponsibity instance in XXLayer::emit methods,
but are now propagated as part of the MaterializationResponsibility instance
itself (and as part of MaterializationUnit when stored in a JITDylib).
Associating VModuleKeys with MaterializationUnits in this way should allow
for a thread-safe module removal mechanism in the future, even when a module
is in the process of being compiled, by having the
MaterializationResponsibility object check in on its VModuleKey's state
before commiting its results to the JITDylib.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@344643 91177308-0d34-0410-b5e6-96231b3b80d8
2018-10-16 20:13:06 +00:00
Lang Hames
c8d6c1623d [ORC] Pass symbol name to discard by const reference.
This saves some unnecessary atomic ref-counting operations.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@343927 91177308-0d34-0410-b5e6-96231b3b80d8
2018-10-06 23:02:06 +00:00
Lang Hames
0e735f0b53 [ORC] Add an 'intern' method to ExecutionEngine for interning symbol names.
This cuts down on boilerplate by reducing 'ES.getSymbolStringPool().intern(...)'
to 'ES.intern(...)'.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@343427 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-30 23:18:24 +00:00
Lang Hames
974e704961 [ORC] Clear SymbolToDefinitionMap when materializing a MaterializationUnit.
The map is inaccessible at this point, so we may as well reclaim the memory
early.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@343395 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-29 23:49:56 +00:00
Lang Hames
a6f5223feb [ORC] Improve debugging output for ORC.
(1) Print debugging output under a session lock to avoid garbled messages when
compiling on multiple threads.

(2) Name MaterializationUnits, add an ostream operator for them, and so they can
be easily referenced in debugging output, and have that ostream operator
optionally print code/data/hidden symbols provided by that materialization unit
based on command line options.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@343323 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-28 15:03:11 +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
Lang Hames
4029ff6aeb [ORC] Do not include non-global symbols in getObjectSymbolFlags.
Private symbols are not visible outside the object file, and so not defined by
the object file from ORC's perspective.

No test case yet. Ideally this would be a unit test parsing a checked-in binary,
but I am not aware of any way to reference the LLVM source root from a unit
test.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@340703 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-26 16:46:02 +00:00
Lang Hames
7aacef06ca [ORC] Rename VSO to JITDylib.
VSO was a little close to VDSO (an acronym on Linux for Virtual Dynamic Shared
Object) for comfort. It also risks giving the impression that instances of this
class could be shared between ExecutionSessions, which they can not.

JITDylib seems moderately less confusing, while still hinting at how this
class is intended to be used, i.e. as a JIT-compiled stand-in for a dynamic
library (code that would have been a dynamic library if you had wanted to
compile it ahead of time).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@340084 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-17 21:18:18 +00:00
Lang Hames
c64ea65b56 [ORC] Remove an incorrect use of 'cantFail'.
This code was moved out from BasicObjectLayerMaterializationUnit, which required
the supplied object to be well formed. The getObjectSymbolFlags function does
not require a well-formed object, so we have to propagate the error here.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338975 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-05 23:55:35 +00:00
Lang Hames
9a3ece15dd [ORC] Change JITSymbolFlags debug output, add a function for getting a symbol
flags map from a buffer representing an object file.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338974 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-05 22:35:37 +00:00
Lang Hames
2722237399 [ORC] Add a 'Callable' flag to JITSymbolFlags.
The callable flag can be used to indicate that a symbol is callable. If present,
the symbol is callable. If absent, the symbol may or may not be callable (the
client must determine this by context, for example by examining the program
representation that will provide the symbol definition).

This flag will be used in the near future to enable creation of lazy compilation
stubs based on SymbolFlagsMap instances only (without having to provide
additional information to determine which symbols need stubs).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338649 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-01 22:42:23 +00:00
Lang Hames
9f1c2395ce [ORC] Add LLJIT and LLLazyJIT, and replace OrcLazyJIT in LLI with LLLazyJIT.
LLJIT is a prefabricated ORC based JIT class that is meant to be the go-to
replacement for MCJIT. Unlike OrcMCJITReplacement (which will continue to be
supported) it is not API or bug-for-bug compatible, but targets the same
use cases: Simple, non-lazy compilation and execution of LLVM IR.

LLLazyJIT extends LLJIT with support for function-at-a-time lazy compilation,
similar to what was provided by LLVM's original (now long deprecated) JIT APIs.

This commit also contains some simple utility classes (CtorDtorRunner2,
LocalCXXRuntimeOverrides2, JITTargetMachineBuilder) to support LLJIT and
LLLazyJIT.

Both of these classes are works in progress. Feedback from JIT clients is very
welcome!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@335670 91177308-0d34-0410-b5e6-96231b3b80d8
2018-06-26 21:35:48 +00:00
Lang Hames
fdc08234d7 [ORC] Fix a FIXME by moving MangleAndInterner to Core.h.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@335661 91177308-0d34-0410-b5e6-96231b3b80d8
2018-06-26 20:59:46 +00:00
Lang Hames
33c00a3db2 [ORC] Add a constructor to create an IRMaterializationUnit from a module and
pre-existing SymbolFlags and SymbolToDefinition maps.

This constructor is useful when delegating work from an existing
IRMaterialiaztionUnit to a new one, as it avoids the cost of re-computing these
maps.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@333852 91177308-0d34-0410-b5e6-96231b3b80d8
2018-06-03 19:22:48 +00:00
Lang Hames
5da314cda8 [ORC] Rename IRMaterializationUnit's Discardable member to SymbolToDefinition,
and make it protected rather than private.

The new name reflects the actual information in the map, and this information
can be useful to derived classes (for example, to quickly look up the IR
definition of a requested symbol).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@333683 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-31 19:29:01 +00:00
Lang Hames
6e22163f52 [ORC] Move symbol-scanning and discard from BasicIRLayerMaterializationUnit in
to a base class (IRMaterializationUnit).

The new class, IRMaterializationUnit, provides a convenient base for any client
that wants to write a materializer for LLVM IR.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@332993 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-22 16:15:38 +00:00
Lang Hames
e0b0d5fab7 [ORC] Add IRLayer and ObjectLayer interfaces and related MaterializationUnits.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@332896 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-21 21:11:13 +00:00