21 Commits

Author SHA1 Message Date
Lang Hames
58ecc853fc [ORC] Fix a data race in the lookup function.
The Error locals need to be protected by a mutex. (This could be fixed by
having the promises / futures contain Expected and Error values, but
MSVC's future implementation does not support this yet).

Hopefully this will fix some of the errors seen on the builders due to
r327474.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@327477 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-14 06:25:08 +00:00
Lang Hames
50f412d325 [ORC] Silence a compiler error.
This should fix the builder error at
http://lab.llvm.org:8011/builders/lld-x86_64-darwin13/builds/19006

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@327475 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-14 05:23:56 +00:00
Lang Hames
a4b7c02dd5 [ORC] Add a 'lookup' convenience function for finding symbols in a list of VSOs.
The lookup function takes a list of VSOs, a set of symbol names (or just one
symbol name) and a materialization function object. It returns an
Expected<SymbolMap> (if given a set of names) or an Expected<JITEvaluatedSymbol>
(if given just one name). The lookup method constructs an
AsynchronousSymbolQuery for the given names, applies that query to each VSO in
the list in turn, and then blocks waiting for the query to complete. If
threading is enabled then the materialization function object can be used to
execute the materialization on different threads. If threading is disabled the
MaterializeOnCurrentThread utility must be used.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@327474 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-14 04:18:04 +00:00
Lang Hames
734c4808f8 [ORC] Switch to shared_ptr ownership for SymbolSources in VSOs.
This makes it easy to free a SymbolSource (and any related
resources) when the last reference in a VSO is dropped.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@325727 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-21 21:55:57 +00:00
Lang Hames
d8d27ad50d [ORC] Switch to shared_ptr ownership for AsynchronousSymbolQueries.
Queries need to stay alive until each owner has set the values they are
responsible for.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@325179 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-14 22:12:56 +00:00
Lang Hames
faeaa17224 [ORC] Refactor the various lookupFlags methods to return the flags map via the
first argument.

This makes lookupFlags more consistent with lookup (which takes the query as the
first argument) and composes better in practice, since lookups are usually
linearly chained: Each lookupFlags can populate the result map based on the
symbols not found in the previous lookup. (If the maps were returned rather than
passed by reference there would have to be a merge step at the end).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@323398 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-25 01:43:00 +00:00
Lang Hames
e0267674fd [ORC] Add orc::SymbolResolver, a Orc/Legacy API interop header, and an
orc::SymbolResolver to JITSymbolResolver adapter.

The new orc::SymbolResolver interface uses asynchronous queries for better
performance. (Asynchronous queries with bulk lookup minimize RPC/IPC overhead,
support parallel incoming queries, and expose more available work for
distribution). Existing ORC layers will soon be updated to use the
orc::SymbolResolver API rather than the legacy llvm::JITSymbolResolver API.

Because RuntimeDyld still uses JITSymbolResolver, this patch also includes an
adapter that wraps an orc::SymbolResolver with a JITSymbolResolver API.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@323073 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-22 03:00:31 +00:00
Lang Hames
c69d5ffd14 [ORC] Add a lookupFlags method to VSO.
lookupFlags returns a SymbolFlagsMap for the requested symbols, along with a
set containing the SymbolStringPtr for any symbol not found in the VSO.

The JITSymbolFlags for each symbol will have been stripped of its transient
JIT-state flags (i.e. NotMaterialized, Materializing).

Calling lookupFlags does not trigger symbol materialization.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@323060 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-21 03:20:39 +00:00
Lang Hames
11d1660180 [ORC] More cleanup. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@323059 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-21 03:20:36 +00:00
Lang Hames
e85f69d55b [ORC] Cleanup. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@323057 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-21 02:24:45 +00:00
Lang Hames
08bbfe4e7a [ExecutionEngine] Rename JITSymbol::isStrongDefinition to isStrong.
For symmetry with isWeak, isCommon.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@322594 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-16 20:39:51 +00:00
Lang Hames
b8d3880c38 [ORC] Add a stub ExecutionSession and VModuleKey type.
ExecutionSession will represent a running JIT program.

VModuleKey is a unique key assigned to each module added as part of
an ExecutionSession. The Layer concept will be updated in future to
require a VModuleKey when a module is added.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@322336 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-12 00:22:05 +00:00
Lang Hames
c7c090f163 [ORC] Re-apply r321838 again with a workaround for a bug present in the libcxx
version being used on some of the green dragon builders (plus a clang-format).

Workaround: AsynchronousSymbolQuery and VSO want to work with
JITEvaluatedSymbols anyway, so just use them (instead of JITSymbol, which
happens to tickle the bug).

The libcxx bug being worked around was fixed in r276003, and there are plans to
update the offending builders.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@322140 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-10 00:09:38 +00:00
Lang Hames
f8f6c8dfc7 [ORC] Remove AsynchronousSymbolQuery while I debug an issue on one of the
builders.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@321941 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-06 20:14:22 +00:00
Lang Hames
173be72e84 [ORC] Yet more debugging output to diagnose test failures.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@321927 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-06 05:19:07 +00:00
Lang Hames
972c9575f0 [ORC] Temporarily adding some redundant asserts / debug output to aid in
debugging a tester failure.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@321920 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-06 01:06:07 +00:00
Lang Hames
cac7dd493a [ORC] Re-apply just the AsynchronousSymbolLookup class from r321838 while I
investigate builder / test failures.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@321910 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-05 22:50:43 +00:00
Lang Hames
d84b15b1d9 [ORC] Re-revert r321838: Tests are still failing.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@321858 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-05 03:10:15 +00:00
Lang Hames
9b3761cc7d [ORC] Re-apply r321838 - Addition of new ORC core APIs.
The original commit broke the builders due to a think-o in an assertion:
AsynchronousSymbolQuery's constructor needs to check the callback member
variables, not the constructor arguments.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@321853 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-05 02:21:02 +00:00
Lang Hames
60d5d5c881 Revert r321838 -- It broke some of the builders.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@321842 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-05 00:29:37 +00:00
Lang Hames
de9aafe93f [ORC] Add new core ORC APIs (Core.h/Core.cpp): VSO, AsynchronousSymbolQuery and
SymbolSource.

These new APIs are a first stab at tackling some current shortcomings of ORC,
especially in performance and threading support.

VSO (Virtual Shared Object) is a symbol table representing the symbol
definitions of a set of modules that behave as if they had been statically
linked together into a shared object or dylib. Symbol definitions, either
pre-defined addresses or lazy definitions, can be added and queries for symbol
addresses made. The table applies the same linkage strength rules that static
linkers do when constructing a dylib or shared object: duplicate definitions
result in errors, strong definitions override weak or common ones. This class
should improve symbol lookup speed by providing centralized symbol tables (as
compared to the findSymbol implementation in the in-tree ORC layers, which
maintain one symbol table per object file / module added).

AsynchronousSymbolQuery is a query for the addresses of a set of symbols.
Query results are returned via a callback once they become available. Querying
for a set of symbols, rather than one symbol at a time (as the current lookup
scheme does) the JIT has the opportunity to make better use of available
resources (e.g. by spawning multiple jobs to materialize the requested symbols
if possible). Returning results via a callback makes queries asynchronous, so
queries from multiple threads of JIT'd code can proceed simultaneously.

SymbolSource represents a source of symbol definitions. It is used when
adding lazy symbol definitions to a VSO. Symbol definitions can be materialized
when needed or discarded if a stronger definition is found. Materializing on
demand via SymbolSources should (eventually) allow us to remove the lazy
materializers from JITSymbol, which will in turn allow the removal of many
current error checks and reduce the number of RPC round-trips involved in
materializing remote symbols. Adding a discard function allows sources to
discard symbol definitions (or mark them as available_externally), reducing the
amount of redundant code generated by the JIT for ODR symbols.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@321838 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-05 00:04:16 +00:00