Skip to content

Commit ce74c3b

Browse files
committed
[Orc] Address the remaining move-capture FIXMEs
This required spreading unique_function a bit more, which I think is a good thing. llvm-svn: 371843
1 parent 0d9a201 commit ce74c3b

File tree

15 files changed

+69
-86
lines changed

15 files changed

+69
-86
lines changed

llvm/examples/SpeculativeJIT/SpeculativeJIT.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,7 @@ class SpeculativeJIT {
114114
this->ES->setDispatchMaterialization(
115115

116116
[this](JITDylib &JD, std::unique_ptr<MaterializationUnit> MU) {
117-
// FIXME: Switch to move capture once we have c 14.
118-
auto SharedMU = std::shared_ptr<MaterializationUnit>(std::move(MU));
119-
auto Work = [SharedMU, &JD]() { SharedMU->doMaterialize(JD); };
117+
auto Work = [MU = std::move(MU), &JD] { MU->doMaterialize(JD); };
120118
CompileThreads.async(std::move(Work));
121119
});
122120
ExitOnErr(S.addSpeculationRuntime(this->ES->getMainJITDylib(), Mangle));

llvm/include/llvm/ExecutionEngine/JITSymbol.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <string>
2424

2525
#include "llvm/ADT/BitmaskEnum.h"
26+
#include "llvm/ADT/FunctionExtras.h"
2627
#include "llvm/ADT/StringRef.h"
2728
#include "llvm/Support/Error.h"
2829

@@ -217,7 +218,7 @@ class JITEvaluatedSymbol {
217218
/// Represents a symbol in the JIT.
218219
class JITSymbol {
219220
public:
220-
using GetAddressFtor = std::function<Expected<JITTargetAddress>()>;
221+
using GetAddressFtor = unique_function<Expected<JITTargetAddress>()>;
221222

222223
/// Create a 'null' symbol, used to represent a "symbol not found"
223224
/// result from a successful (non-erroneous) lookup.
@@ -325,7 +326,7 @@ class JITSymbolResolver {
325326
public:
326327
using LookupSet = std::set<StringRef>;
327328
using LookupResult = std::map<StringRef, JITEvaluatedSymbol>;
328-
using OnResolvedFunction = std::function<void(Expected<LookupResult>)>;
329+
using OnResolvedFunction = unique_function<void(Expected<LookupResult>)>;
329330

330331
virtual ~JITSymbolResolver() = default;
331332

llvm/include/llvm/ExecutionEngine/Orc/Core.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define LLVM_EXECUTIONENGINE_ORC_CORE_H
1515

1616
#include "llvm/ADT/BitmaskEnum.h"
17+
#include "llvm/ADT/FunctionExtras.h"
1718
#include "llvm/ExecutionEngine/JITSymbol.h"
1819
#include "llvm/ExecutionEngine/Orc/SymbolStringPool.h"
1920
#include "llvm/ExecutionEngine/OrcV1Deprecation.h"
@@ -107,7 +108,7 @@ raw_ostream &operator<<(raw_ostream &OS, const SymbolAliasMap &Aliases);
107108
raw_ostream &operator<<(raw_ostream &OS, const SymbolState &S);
108109

109110
/// Callback to notify client that symbols have been resolved.
110-
using SymbolsResolvedCallback = std::function<void(Expected<SymbolMap>)>;
111+
using SymbolsResolvedCallback = unique_function<void(Expected<SymbolMap>)>;
111112

112113
/// Callback to register the dependencies for a given query.
113114
using RegisterDependenciesFunction =

llvm/include/llvm/ExecutionEngine/Orc/LazyEmittingLayer.h

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,28 +49,24 @@ template <typename BaseLayerT> class LazyEmittingLayer {
4949
switch (EmitState) {
5050
case NotEmitted:
5151
if (auto GV = searchGVs(Name, ExportedSymbolsOnly)) {
52-
// Create a std::string version of Name to capture here - the argument
53-
// (a StringRef) may go away before the lambda is executed.
54-
// FIXME: Use capture-init when we move to C++14.
55-
std::string PName = Name;
5652
JITSymbolFlags Flags = JITSymbolFlags::fromGlobalValue(*GV);
57-
auto GetAddress =
58-
[this, ExportedSymbolsOnly, PName, &B]() -> Expected<JITTargetAddress> {
59-
if (this->EmitState == Emitting)
60-
return 0;
61-
else if (this->EmitState == NotEmitted) {
62-
this->EmitState = Emitting;
63-
if (auto Err = this->emitToBaseLayer(B))
64-
return std::move(Err);
65-
this->EmitState = Emitted;
66-
}
67-
if (auto Sym = B.findSymbolIn(K, PName, ExportedSymbolsOnly))
68-
return Sym.getAddress();
69-
else if (auto Err = Sym.takeError())
53+
auto GetAddress = [this, ExportedSymbolsOnly, Name = Name.str(),
54+
&B]() -> Expected<JITTargetAddress> {
55+
if (this->EmitState == Emitting)
56+
return 0;
57+
else if (this->EmitState == NotEmitted) {
58+
this->EmitState = Emitting;
59+
if (auto Err = this->emitToBaseLayer(B))
7060
return std::move(Err);
71-
else
72-
llvm_unreachable("Successful symbol lookup should return "
73-
"definition address here");
61+
this->EmitState = Emitted;
62+
}
63+
if (auto Sym = B.findSymbolIn(K, Name, ExportedSymbolsOnly))
64+
return Sym.getAddress();
65+
else if (auto Err = Sym.takeError())
66+
return std::move(Err);
67+
else
68+
llvm_unreachable("Successful symbol lookup should return "
69+
"definition address here");
7470
};
7571
return JITSymbol(std::move(GetAddress), Flags);
7672
} else

llvm/include/llvm/ExecutionEngine/Orc/RPCSerialization.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,9 @@ class SerializationTraits<ChannelT, Error> {
359359
{
360360
assert(KeyName != nullptr && "No keyname pointer");
361361
std::lock_guard<std::recursive_mutex> Lock(SerializersMutex);
362-
// FIXME: Move capture Serialize once we have C++14.
363362
Serializers[ErrorInfoT::classID()] =
364-
[KeyName, Serialize](ChannelT &C, const ErrorInfoBase &EIB) -> Error {
363+
[KeyName, Serialize = std::move(Serialize)](
364+
ChannelT &C, const ErrorInfoBase &EIB) -> Error {
365365
assert(EIB.dynamicClassID() == ErrorInfoT::classID() &&
366366
"Serializer called for wrong error type");
367367
if (auto Err = serializeSeq(C, *KeyName))

llvm/include/llvm/ExecutionEngine/Orc/RPCUtils.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,14 +1413,12 @@ class MultiThreadedRPCEndpoint
14131413
using ErrorReturn = typename RTraits::ErrorReturnType;
14141414
using ErrorReturnPromise = typename RTraits::ReturnPromiseType;
14151415

1416-
// FIXME: Stack allocate and move this into the handler once LLVM builds
1417-
// with C++14.
1418-
auto Promise = std::make_shared<ErrorReturnPromise>();
1419-
auto FutureResult = Promise->get_future();
1416+
ErrorReturnPromise Promise;
1417+
auto FutureResult = Promise.get_future();
14201418

14211419
if (auto Err = this->template appendCallAsync<Func>(
1422-
[Promise](ErrorReturn RetOrErr) {
1423-
Promise->set_value(std::move(RetOrErr));
1420+
[Promise = std::move(Promise)](ErrorReturn RetOrErr) {
1421+
Promise.set_value(std::move(RetOrErr));
14241422
return Error::success();
14251423
},
14261424
Args...)) {
@@ -1598,8 +1596,7 @@ class ParallelCallGroup {
15981596
// outstanding calls count, then poke the condition variable.
15991597
using ArgType = typename detail::ResponseHandlerArg<
16001598
typename detail::HandlerTraits<HandlerT>::Type>::ArgType;
1601-
// FIXME: Move handler into wrapped handler once we have C++14.
1602-
auto WrappedHandler = [this, Handler](ArgType Arg) {
1599+
auto WrappedHandler = [this, Handler = std::move(Handler)](ArgType Arg) {
16031600
auto Err = Handler(std::move(Arg));
16041601
std::unique_lock<std::mutex> Lock(M);
16051602
--NumOutstandingCalls;

llvm/include/llvm/ExecutionEngine/Orc/RemoteObjectLayer.h

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,12 @@ class RemoteObjectLayer : public RemoteObjectLayerAPI {
137137
RemoteSymbolId Id)
138138
: C(C), Id(Id) {}
139139

140-
RemoteSymbolMaterializer(const RemoteSymbolMaterializer &Other)
141-
: C(Other.C), Id(Other.Id) {
142-
// FIXME: This is a horrible, auto_ptr-style, copy-as-move operation.
143-
// It should be removed as soon as LLVM has C++14's generalized
144-
// lambda capture (at which point the materializer can be moved
145-
// into the lambda in remoteToJITSymbol below).
146-
const_cast<RemoteSymbolMaterializer&>(Other).Id = 0;
140+
RemoteSymbolMaterializer(RemoteSymbolMaterializer &&Other)
141+
: C(Other.C), Id(Other.Id) {
142+
Other.Id = 0;
147143
}
148144

149-
RemoteSymbolMaterializer&
150-
operator=(const RemoteSymbolMaterializer&) = delete;
145+
RemoteSymbolMaterializer &operator=(RemoteSymbolMaterializer &&) = delete;
151146

152147
/// Release the remote symbol.
153148
~RemoteSymbolMaterializer() {
@@ -218,9 +213,9 @@ class RemoteObjectLayer : public RemoteObjectLayerAPI {
218213
return nullptr;
219214
// else...
220215
RemoteSymbolMaterializer RSM(*this, RemoteSym.first);
221-
auto Sym =
222-
JITSymbol([RSM]() mutable { return RSM.materialize(); },
223-
RemoteSym.second);
216+
auto Sym = JITSymbol(
217+
[RSM = std::move(RSM)]() mutable { return RSM.materialize(); },
218+
RemoteSym.second);
224219
return Sym;
225220
} else
226221
return RemoteSymOrErr.takeError();

llvm/include/llvm/ExecutionEngine/RuntimeDyld.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef LLVM_EXECUTIONENGINE_RUNTIMEDYLD_H
1414
#define LLVM_EXECUTIONENGINE_RUNTIMEDYLD_H
1515

16+
#include "llvm/ADT/FunctionExtras.h"
1617
#include "llvm/ADT/STLExtras.h"
1718
#include "llvm/ADT/StringRef.h"
1819
#include "llvm/DebugInfo/DIContext.h"
@@ -271,10 +272,10 @@ class RuntimeDyld {
271272
std::unique_ptr<MemoryBuffer> UnderlyingBuffer,
272273
RuntimeDyld::MemoryManager &MemMgr, JITSymbolResolver &Resolver,
273274
bool ProcessAllSections,
274-
std::function<Error(std::unique_ptr<LoadedObjectInfo>,
275-
std::map<StringRef, JITEvaluatedSymbol>)>
275+
unique_function<Error(std::unique_ptr<LoadedObjectInfo>,
276+
std::map<StringRef, JITEvaluatedSymbol>)>
276277
OnLoaded,
277-
std::function<void(Error)> OnEmitted);
278+
unique_function<void(Error)> OnEmitted);
278279

279280
// RuntimeDyldImpl is the actual class. RuntimeDyld is just the public
280281
// interface.
@@ -291,14 +292,14 @@ class RuntimeDyld {
291292
// but ORC's RTDyldObjectLinkingLayer2. Internally it constructs a RuntimeDyld
292293
// instance and uses continuation passing to perform the fix-up and finalize
293294
// steps asynchronously.
294-
void jitLinkForORC(object::ObjectFile &Obj,
295-
std::unique_ptr<MemoryBuffer> UnderlyingBuffer,
296-
RuntimeDyld::MemoryManager &MemMgr,
297-
JITSymbolResolver &Resolver, bool ProcessAllSections,
298-
std::function<Error(std::unique_ptr<LoadedObjectInfo>,
299-
std::map<StringRef, JITEvaluatedSymbol>)>
300-
OnLoaded,
301-
std::function<void(Error)> OnEmitted);
295+
void jitLinkForORC(
296+
object::ObjectFile &Obj, std::unique_ptr<MemoryBuffer> UnderlyingBuffer,
297+
RuntimeDyld::MemoryManager &MemMgr, JITSymbolResolver &Resolver,
298+
bool ProcessAllSections,
299+
unique_function<Error(std::unique_ptr<RuntimeDyld::LoadedObjectInfo>,
300+
std::map<StringRef, JITEvaluatedSymbol>)>
301+
OnLoaded,
302+
unique_function<void(Error)> OnEmitted);
302303

303304
} // end namespace llvm
304305

llvm/include/llvm/Support/ThreadPool.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef LLVM_SUPPORT_THREAD_POOL_H
1414
#define LLVM_SUPPORT_THREAD_POOL_H
1515

16+
#include "llvm/ADT/FunctionExtras.h"
1617
#include "llvm/Config/llvm-config.h"
1718
#include "llvm/Support/thread.h"
1819

@@ -35,7 +36,7 @@ namespace llvm {
3536
/// for some work to become available.
3637
class ThreadPool {
3738
public:
38-
using TaskTy = std::function<void()>;
39+
using TaskTy = unique_function<void()>;
3940
using PackagedTaskTy = std::packaged_task<void()>;
4041

4142
/// Construct a pool with the number of threads found by

llvm/lib/ExecutionEngine/Orc/LLJIT.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,7 @@ LLJIT::LLJIT(LLJITBuilderState &S, Error &Err)
132132
CompileThreads = std::make_unique<ThreadPool>(S.NumCompileThreads);
133133
ES->setDispatchMaterialization(
134134
[this](JITDylib &JD, std::unique_ptr<MaterializationUnit> MU) {
135-
// FIXME: Switch to move capture once we have c++14.
136-
auto SharedMU = std::shared_ptr<MaterializationUnit>(std::move(MU));
137-
auto Work = [SharedMU, &JD]() { SharedMU->doMaterialize(JD); };
135+
auto Work = [MU = std::move(MU), &JD] { MU->doMaterialize(JD); };
138136
CompileThreads->async(std::move(Work));
139137
});
140138
}

0 commit comments

Comments
 (0)