[Orc] New JIT APIs.
This patch adds a new set of JIT APIs to LLVM. The aim of these new APIs is to
cleanly support a wider range of JIT use cases in LLVM, and encourage the
development and contribution of re-usable infrastructure for LLVM JIT use-cases.
These APIs are intended to live alongside the MCJIT APIs, and should not affect
existing clients.
Included in this patch:
1) New headers in include/llvm/ExecutionEngine/Orc that provide a set of
components for building JIT infrastructure.
Implementation code for these headers lives in lib/ExecutionEngine/Orc.
2) A prototype re-implementation of MCJIT (OrcMCJITReplacement) built out of the
new components.
3) Minor changes to RTDyldMemoryManager needed to support the new components.
These changes should not impact existing clients.
4) A new flag for lli, -use-orcmcjit, which will cause lli to use the
OrcMCJITReplacement class as its underlying execution engine, rather than
MCJIT itself.
Tests to follow shortly.
Special thanks to Michael Ilseman, Pete Cooper, David Blaikie, Eric Christopher,
Justin Bogner, and Jim Grosbach for extensive feedback and discussion.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226940 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-23 21:25:00 +00:00
|
|
|
//===- LazyEmittingLayer.h - Lazily emit IR to lower JIT layers -*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Contains the definition for a lazy-emitting layer for the JIT.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_EXECUTIONENGINE_ORC_LAZYEMITTINGLAYER_H
|
|
|
|
#define LLVM_EXECUTIONENGINE_ORC_LAZYEMITTINGLAYER_H
|
|
|
|
|
2015-02-09 01:20:51 +00:00
|
|
|
#include "JITSymbol.h"
|
[Orc] New JIT APIs.
This patch adds a new set of JIT APIs to LLVM. The aim of these new APIs is to
cleanly support a wider range of JIT use cases in LLVM, and encourage the
development and contribution of re-usable infrastructure for LLVM JIT use-cases.
These APIs are intended to live alongside the MCJIT APIs, and should not affect
existing clients.
Included in this patch:
1) New headers in include/llvm/ExecutionEngine/Orc that provide a set of
components for building JIT infrastructure.
Implementation code for these headers lives in lib/ExecutionEngine/Orc.
2) A prototype re-implementation of MCJIT (OrcMCJITReplacement) built out of the
new components.
3) Minor changes to RTDyldMemoryManager needed to support the new components.
These changes should not impact existing clients.
4) A new flag for lli, -use-orcmcjit, which will cause lli to use the
OrcMCJITReplacement class as its underlying execution engine, rather than
MCJIT itself.
Tests to follow shortly.
Special thanks to Michael Ilseman, Pete Cooper, David Blaikie, Eric Christopher,
Justin Bogner, and Jim Grosbach for extensive feedback and discussion.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226940 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-23 21:25:00 +00:00
|
|
|
#include "LookasideRTDyldMM.h"
|
2015-02-06 22:48:43 +00:00
|
|
|
#include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
|
|
|
|
#include "llvm/IR/GlobalValue.h"
|
[Orc] New JIT APIs.
This patch adds a new set of JIT APIs to LLVM. The aim of these new APIs is to
cleanly support a wider range of JIT use cases in LLVM, and encourage the
development and contribution of re-usable infrastructure for LLVM JIT use-cases.
These APIs are intended to live alongside the MCJIT APIs, and should not affect
existing clients.
Included in this patch:
1) New headers in include/llvm/ExecutionEngine/Orc that provide a set of
components for building JIT infrastructure.
Implementation code for these headers lives in lib/ExecutionEngine/Orc.
2) A prototype re-implementation of MCJIT (OrcMCJITReplacement) built out of the
new components.
3) Minor changes to RTDyldMemoryManager needed to support the new components.
These changes should not impact existing clients.
4) A new flag for lli, -use-orcmcjit, which will cause lli to use the
OrcMCJITReplacement class as its underlying execution engine, rather than
MCJIT itself.
Tests to follow shortly.
Special thanks to Michael Ilseman, Pete Cooper, David Blaikie, Eric Christopher,
Justin Bogner, and Jim Grosbach for extensive feedback and discussion.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226940 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-23 21:25:00 +00:00
|
|
|
#include "llvm/IR/Mangler.h"
|
2015-02-23 00:36:25 +00:00
|
|
|
#include "llvm/IR/Module.h"
|
2015-02-22 22:18:55 +00:00
|
|
|
#include "llvm/ADT/StringMap.h"
|
[Orc] New JIT APIs.
This patch adds a new set of JIT APIs to LLVM. The aim of these new APIs is to
cleanly support a wider range of JIT use cases in LLVM, and encourage the
development and contribution of re-usable infrastructure for LLVM JIT use-cases.
These APIs are intended to live alongside the MCJIT APIs, and should not affect
existing clients.
Included in this patch:
1) New headers in include/llvm/ExecutionEngine/Orc that provide a set of
components for building JIT infrastructure.
Implementation code for these headers lives in lib/ExecutionEngine/Orc.
2) A prototype re-implementation of MCJIT (OrcMCJITReplacement) built out of the
new components.
3) Minor changes to RTDyldMemoryManager needed to support the new components.
These changes should not impact existing clients.
4) A new flag for lli, -use-orcmcjit, which will cause lli to use the
OrcMCJITReplacement class as its underlying execution engine, rather than
MCJIT itself.
Tests to follow shortly.
Special thanks to Michael Ilseman, Pete Cooper, David Blaikie, Eric Christopher,
Justin Bogner, and Jim Grosbach for extensive feedback and discussion.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226940 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-23 21:25:00 +00:00
|
|
|
#include <list>
|
|
|
|
|
|
|
|
namespace llvm {
|
2015-02-21 20:44:36 +00:00
|
|
|
namespace orc {
|
[Orc] New JIT APIs.
This patch adds a new set of JIT APIs to LLVM. The aim of these new APIs is to
cleanly support a wider range of JIT use cases in LLVM, and encourage the
development and contribution of re-usable infrastructure for LLVM JIT use-cases.
These APIs are intended to live alongside the MCJIT APIs, and should not affect
existing clients.
Included in this patch:
1) New headers in include/llvm/ExecutionEngine/Orc that provide a set of
components for building JIT infrastructure.
Implementation code for these headers lives in lib/ExecutionEngine/Orc.
2) A prototype re-implementation of MCJIT (OrcMCJITReplacement) built out of the
new components.
3) Minor changes to RTDyldMemoryManager needed to support the new components.
These changes should not impact existing clients.
4) A new flag for lli, -use-orcmcjit, which will cause lli to use the
OrcMCJITReplacement class as its underlying execution engine, rather than
MCJIT itself.
Tests to follow shortly.
Special thanks to Michael Ilseman, Pete Cooper, David Blaikie, Eric Christopher,
Justin Bogner, and Jim Grosbach for extensive feedback and discussion.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226940 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-23 21:25:00 +00:00
|
|
|
|
|
|
|
/// @brief Lazy-emitting IR layer.
|
|
|
|
///
|
|
|
|
/// This layer accepts sets of LLVM IR Modules (via addModuleSet), but does
|
|
|
|
/// not immediately emit them the layer below. Instead, emissing to the base
|
2015-02-09 01:20:51 +00:00
|
|
|
/// layer is deferred until the first time the client requests the address
|
|
|
|
/// (via JITSymbol::getAddress) for a symbol contained in this layer.
|
[Orc] New JIT APIs.
This patch adds a new set of JIT APIs to LLVM. The aim of these new APIs is to
cleanly support a wider range of JIT use cases in LLVM, and encourage the
development and contribution of re-usable infrastructure for LLVM JIT use-cases.
These APIs are intended to live alongside the MCJIT APIs, and should not affect
existing clients.
Included in this patch:
1) New headers in include/llvm/ExecutionEngine/Orc that provide a set of
components for building JIT infrastructure.
Implementation code for these headers lives in lib/ExecutionEngine/Orc.
2) A prototype re-implementation of MCJIT (OrcMCJITReplacement) built out of the
new components.
3) Minor changes to RTDyldMemoryManager needed to support the new components.
These changes should not impact existing clients.
4) A new flag for lli, -use-orcmcjit, which will cause lli to use the
OrcMCJITReplacement class as its underlying execution engine, rather than
MCJIT itself.
Tests to follow shortly.
Special thanks to Michael Ilseman, Pete Cooper, David Blaikie, Eric Christopher,
Justin Bogner, and Jim Grosbach for extensive feedback and discussion.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226940 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-23 21:25:00 +00:00
|
|
|
template <typename BaseLayerT> class LazyEmittingLayer {
|
|
|
|
public:
|
|
|
|
typedef typename BaseLayerT::ModuleSetHandleT BaseLayerHandleT;
|
|
|
|
|
|
|
|
private:
|
|
|
|
class EmissionDeferredSet {
|
|
|
|
public:
|
|
|
|
EmissionDeferredSet() : EmitState(NotEmitted) {}
|
|
|
|
virtual ~EmissionDeferredSet() {}
|
|
|
|
|
2015-02-09 01:20:51 +00:00
|
|
|
JITSymbol find(StringRef Name, bool ExportedSymbolsOnly, BaseLayerT &B) {
|
[Orc] New JIT APIs.
This patch adds a new set of JIT APIs to LLVM. The aim of these new APIs is to
cleanly support a wider range of JIT use cases in LLVM, and encourage the
development and contribution of re-usable infrastructure for LLVM JIT use-cases.
These APIs are intended to live alongside the MCJIT APIs, and should not affect
existing clients.
Included in this patch:
1) New headers in include/llvm/ExecutionEngine/Orc that provide a set of
components for building JIT infrastructure.
Implementation code for these headers lives in lib/ExecutionEngine/Orc.
2) A prototype re-implementation of MCJIT (OrcMCJITReplacement) built out of the
new components.
3) Minor changes to RTDyldMemoryManager needed to support the new components.
These changes should not impact existing clients.
4) A new flag for lli, -use-orcmcjit, which will cause lli to use the
OrcMCJITReplacement class as its underlying execution engine, rather than
MCJIT itself.
Tests to follow shortly.
Special thanks to Michael Ilseman, Pete Cooper, David Blaikie, Eric Christopher,
Justin Bogner, and Jim Grosbach for extensive feedback and discussion.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226940 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-23 21:25:00 +00:00
|
|
|
switch (EmitState) {
|
2015-02-09 01:20:51 +00:00
|
|
|
case NotEmitted:
|
2015-02-10 07:35:39 +00:00
|
|
|
if (provides(Name, ExportedSymbolsOnly)) {
|
|
|
|
// Create a std::string version of Name to capture here - the argument
|
|
|
|
// (a StringRef) may go away before the lambda is executed.
|
|
|
|
// FIXME: Use capture-init when we move to C++14.
|
|
|
|
std::string PName = Name;
|
2015-02-09 01:20:51 +00:00
|
|
|
return JITSymbol(
|
2015-02-10 07:35:39 +00:00
|
|
|
[this, ExportedSymbolsOnly, PName, &B]() -> TargetAddress {
|
2015-02-09 07:47:32 +00:00
|
|
|
if (this->EmitState == Emitting)
|
2015-02-09 01:20:51 +00:00
|
|
|
return 0;
|
2015-02-10 07:35:39 +00:00
|
|
|
else if (this->EmitState == NotEmitted) {
|
2015-02-09 07:47:32 +00:00
|
|
|
this->EmitState = Emitting;
|
2015-02-16 22:36:25 +00:00
|
|
|
Handle = this->emitToBaseLayer(B);
|
2015-02-09 07:47:32 +00:00
|
|
|
this->EmitState = Emitted;
|
2015-02-09 01:20:51 +00:00
|
|
|
}
|
2015-02-10 07:35:39 +00:00
|
|
|
return B.findSymbolIn(Handle, PName, ExportedSymbolsOnly)
|
2015-02-09 01:20:51 +00:00
|
|
|
.getAddress();
|
|
|
|
});
|
2015-02-10 07:35:39 +00:00
|
|
|
} else
|
2015-02-09 01:20:51 +00:00
|
|
|
return nullptr;
|
|
|
|
case Emitting:
|
|
|
|
// Calling "emit" can trigger external symbol lookup (e.g. to check for
|
|
|
|
// pre-existing definitions of common-symbol), but it will never find in
|
|
|
|
// this module that it would not have found already, so return null from
|
|
|
|
// here.
|
|
|
|
return nullptr;
|
|
|
|
case Emitted:
|
|
|
|
return B.findSymbolIn(Handle, Name, ExportedSymbolsOnly);
|
[Orc] New JIT APIs.
This patch adds a new set of JIT APIs to LLVM. The aim of these new APIs is to
cleanly support a wider range of JIT use cases in LLVM, and encourage the
development and contribution of re-usable infrastructure for LLVM JIT use-cases.
These APIs are intended to live alongside the MCJIT APIs, and should not affect
existing clients.
Included in this patch:
1) New headers in include/llvm/ExecutionEngine/Orc that provide a set of
components for building JIT infrastructure.
Implementation code for these headers lives in lib/ExecutionEngine/Orc.
2) A prototype re-implementation of MCJIT (OrcMCJITReplacement) built out of the
new components.
3) Minor changes to RTDyldMemoryManager needed to support the new components.
These changes should not impact existing clients.
4) A new flag for lli, -use-orcmcjit, which will cause lli to use the
OrcMCJITReplacement class as its underlying execution engine, rather than
MCJIT itself.
Tests to follow shortly.
Special thanks to Michael Ilseman, Pete Cooper, David Blaikie, Eric Christopher,
Justin Bogner, and Jim Grosbach for extensive feedback and discussion.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226940 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-23 21:25:00 +00:00
|
|
|
}
|
2015-02-09 01:20:51 +00:00
|
|
|
llvm_unreachable("Invalid emit-state.");
|
[Orc] New JIT APIs.
This patch adds a new set of JIT APIs to LLVM. The aim of these new APIs is to
cleanly support a wider range of JIT use cases in LLVM, and encourage the
development and contribution of re-usable infrastructure for LLVM JIT use-cases.
These APIs are intended to live alongside the MCJIT APIs, and should not affect
existing clients.
Included in this patch:
1) New headers in include/llvm/ExecutionEngine/Orc that provide a set of
components for building JIT infrastructure.
Implementation code for these headers lives in lib/ExecutionEngine/Orc.
2) A prototype re-implementation of MCJIT (OrcMCJITReplacement) built out of the
new components.
3) Minor changes to RTDyldMemoryManager needed to support the new components.
These changes should not impact existing clients.
4) A new flag for lli, -use-orcmcjit, which will cause lli to use the
OrcMCJITReplacement class as its underlying execution engine, rather than
MCJIT itself.
Tests to follow shortly.
Special thanks to Michael Ilseman, Pete Cooper, David Blaikie, Eric Christopher,
Justin Bogner, and Jim Grosbach for extensive feedback and discussion.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226940 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-23 21:25:00 +00:00
|
|
|
}
|
|
|
|
|
2015-02-09 01:20:51 +00:00
|
|
|
void removeModulesFromBaseLayer(BaseLayerT &BaseLayer) {
|
[Orc] New JIT APIs.
This patch adds a new set of JIT APIs to LLVM. The aim of these new APIs is to
cleanly support a wider range of JIT use cases in LLVM, and encourage the
development and contribution of re-usable infrastructure for LLVM JIT use-cases.
These APIs are intended to live alongside the MCJIT APIs, and should not affect
existing clients.
Included in this patch:
1) New headers in include/llvm/ExecutionEngine/Orc that provide a set of
components for building JIT infrastructure.
Implementation code for these headers lives in lib/ExecutionEngine/Orc.
2) A prototype re-implementation of MCJIT (OrcMCJITReplacement) built out of the
new components.
3) Minor changes to RTDyldMemoryManager needed to support the new components.
These changes should not impact existing clients.
4) A new flag for lli, -use-orcmcjit, which will cause lli to use the
OrcMCJITReplacement class as its underlying execution engine, rather than
MCJIT itself.
Tests to follow shortly.
Special thanks to Michael Ilseman, Pete Cooper, David Blaikie, Eric Christopher,
Justin Bogner, and Jim Grosbach for extensive feedback and discussion.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226940 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-23 21:25:00 +00:00
|
|
|
if (EmitState != NotEmitted)
|
|
|
|
BaseLayer.removeModuleSet(Handle);
|
|
|
|
}
|
|
|
|
|
2015-02-16 22:36:25 +00:00
|
|
|
void emitAndFinalize(BaseLayerT &BaseLayer) {
|
|
|
|
assert(EmitState != Emitting &&
|
|
|
|
"Cannot emitAndFinalize while already emitting");
|
|
|
|
if (EmitState == NotEmitted) {
|
|
|
|
EmitState = Emitting;
|
|
|
|
Handle = emitToBaseLayer(BaseLayer);
|
|
|
|
EmitState = Emitted;
|
|
|
|
}
|
|
|
|
BaseLayer.emitAndFinalize(Handle);
|
|
|
|
}
|
|
|
|
|
[Orc] New JIT APIs.
This patch adds a new set of JIT APIs to LLVM. The aim of these new APIs is to
cleanly support a wider range of JIT use cases in LLVM, and encourage the
development and contribution of re-usable infrastructure for LLVM JIT use-cases.
These APIs are intended to live alongside the MCJIT APIs, and should not affect
existing clients.
Included in this patch:
1) New headers in include/llvm/ExecutionEngine/Orc that provide a set of
components for building JIT infrastructure.
Implementation code for these headers lives in lib/ExecutionEngine/Orc.
2) A prototype re-implementation of MCJIT (OrcMCJITReplacement) built out of the
new components.
3) Minor changes to RTDyldMemoryManager needed to support the new components.
These changes should not impact existing clients.
4) A new flag for lli, -use-orcmcjit, which will cause lli to use the
OrcMCJITReplacement class as its underlying execution engine, rather than
MCJIT itself.
Tests to follow shortly.
Special thanks to Michael Ilseman, Pete Cooper, David Blaikie, Eric Christopher,
Justin Bogner, and Jim Grosbach for extensive feedback and discussion.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226940 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-23 21:25:00 +00:00
|
|
|
template <typename ModuleSetT>
|
|
|
|
static std::unique_ptr<EmissionDeferredSet>
|
|
|
|
create(BaseLayerT &B, ModuleSetT Ms,
|
|
|
|
std::unique_ptr<RTDyldMemoryManager> MM);
|
|
|
|
|
|
|
|
protected:
|
2015-02-09 01:20:51 +00:00
|
|
|
virtual bool provides(StringRef Name, bool ExportedSymbolsOnly) const = 0;
|
2015-02-16 22:36:25 +00:00
|
|
|
virtual BaseLayerHandleT emitToBaseLayer(BaseLayerT &BaseLayer) = 0;
|
[Orc] New JIT APIs.
This patch adds a new set of JIT APIs to LLVM. The aim of these new APIs is to
cleanly support a wider range of JIT use cases in LLVM, and encourage the
development and contribution of re-usable infrastructure for LLVM JIT use-cases.
These APIs are intended to live alongside the MCJIT APIs, and should not affect
existing clients.
Included in this patch:
1) New headers in include/llvm/ExecutionEngine/Orc that provide a set of
components for building JIT infrastructure.
Implementation code for these headers lives in lib/ExecutionEngine/Orc.
2) A prototype re-implementation of MCJIT (OrcMCJITReplacement) built out of the
new components.
3) Minor changes to RTDyldMemoryManager needed to support the new components.
These changes should not impact existing clients.
4) A new flag for lli, -use-orcmcjit, which will cause lli to use the
OrcMCJITReplacement class as its underlying execution engine, rather than
MCJIT itself.
Tests to follow shortly.
Special thanks to Michael Ilseman, Pete Cooper, David Blaikie, Eric Christopher,
Justin Bogner, and Jim Grosbach for extensive feedback and discussion.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226940 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-23 21:25:00 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
enum { NotEmitted, Emitting, Emitted } EmitState;
|
|
|
|
BaseLayerHandleT Handle;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename ModuleSetT>
|
|
|
|
class EmissionDeferredSetImpl : public EmissionDeferredSet {
|
|
|
|
public:
|
|
|
|
EmissionDeferredSetImpl(ModuleSetT Ms,
|
|
|
|
std::unique_ptr<RTDyldMemoryManager> MM)
|
|
|
|
: Ms(std::move(Ms)), MM(std::move(MM)) {}
|
|
|
|
|
|
|
|
protected:
|
2015-02-16 22:36:25 +00:00
|
|
|
|
|
|
|
BaseLayerHandleT emitToBaseLayer(BaseLayerT &BaseLayer) override {
|
[Orc] New JIT APIs.
This patch adds a new set of JIT APIs to LLVM. The aim of these new APIs is to
cleanly support a wider range of JIT use cases in LLVM, and encourage the
development and contribution of re-usable infrastructure for LLVM JIT use-cases.
These APIs are intended to live alongside the MCJIT APIs, and should not affect
existing clients.
Included in this patch:
1) New headers in include/llvm/ExecutionEngine/Orc that provide a set of
components for building JIT infrastructure.
Implementation code for these headers lives in lib/ExecutionEngine/Orc.
2) A prototype re-implementation of MCJIT (OrcMCJITReplacement) built out of the
new components.
3) Minor changes to RTDyldMemoryManager needed to support the new components.
These changes should not impact existing clients.
4) A new flag for lli, -use-orcmcjit, which will cause lli to use the
OrcMCJITReplacement class as its underlying execution engine, rather than
MCJIT itself.
Tests to follow shortly.
Special thanks to Michael Ilseman, Pete Cooper, David Blaikie, Eric Christopher,
Justin Bogner, and Jim Grosbach for extensive feedback and discussion.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226940 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-23 21:25:00 +00:00
|
|
|
// We don't need the mangled names set any more: Once we've emitted this
|
|
|
|
// to the base layer we'll just look for symbols there.
|
|
|
|
MangledNames.reset();
|
|
|
|
return BaseLayer.addModuleSet(std::move(Ms), std::move(MM));
|
|
|
|
}
|
|
|
|
|
2015-02-09 01:20:51 +00:00
|
|
|
bool provides(StringRef Name, bool ExportedSymbolsOnly) const override {
|
[Orc] New JIT APIs.
This patch adds a new set of JIT APIs to LLVM. The aim of these new APIs is to
cleanly support a wider range of JIT use cases in LLVM, and encourage the
development and contribution of re-usable infrastructure for LLVM JIT use-cases.
These APIs are intended to live alongside the MCJIT APIs, and should not affect
existing clients.
Included in this patch:
1) New headers in include/llvm/ExecutionEngine/Orc that provide a set of
components for building JIT infrastructure.
Implementation code for these headers lives in lib/ExecutionEngine/Orc.
2) A prototype re-implementation of MCJIT (OrcMCJITReplacement) built out of the
new components.
3) Minor changes to RTDyldMemoryManager needed to support the new components.
These changes should not impact existing clients.
4) A new flag for lli, -use-orcmcjit, which will cause lli to use the
OrcMCJITReplacement class as its underlying execution engine, rather than
MCJIT itself.
Tests to follow shortly.
Special thanks to Michael Ilseman, Pete Cooper, David Blaikie, Eric Christopher,
Justin Bogner, and Jim Grosbach for extensive feedback and discussion.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226940 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-23 21:25:00 +00:00
|
|
|
// FIXME: We could clean all this up if we had a way to reliably demangle
|
|
|
|
// names: We could just demangle name and search, rather than
|
|
|
|
// mangling everything else.
|
|
|
|
|
|
|
|
// If we have already built the mangled name set then just search it.
|
|
|
|
if (MangledNames) {
|
|
|
|
auto VI = MangledNames->find(Name);
|
|
|
|
if (VI == MangledNames->end())
|
|
|
|
return false;
|
|
|
|
return !ExportedSymbolsOnly || VI->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we haven't built the mangled name set yet, try to build it. As an
|
|
|
|
// optimization this will leave MangledNames set to nullptr if we find
|
|
|
|
// Name in the process of building the set.
|
|
|
|
buildMangledNames(Name, ExportedSymbolsOnly);
|
|
|
|
if (!MangledNames)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// If the mangled name of the given GlobalValue matches the given search
|
|
|
|
// name (and its visibility conforms to the ExportedSymbolsOnly flag) then
|
|
|
|
// just return 'true'. Otherwise, add the mangled name to the Names map and
|
|
|
|
// return 'false'.
|
|
|
|
bool addGlobalValue(StringMap<bool> &Names, const GlobalValue &GV,
|
|
|
|
const Mangler &Mang, StringRef SearchName,
|
|
|
|
bool ExportedSymbolsOnly) const {
|
|
|
|
// Modules don't "provide" decls or common symbols.
|
|
|
|
if (GV.isDeclaration() || GV.hasCommonLinkage())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Mangle the GV name.
|
|
|
|
std::string MangledName;
|
|
|
|
{
|
|
|
|
raw_string_ostream MangledNameStream(MangledName);
|
|
|
|
Mang.getNameWithPrefix(MangledNameStream, &GV, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check whether this is the name we were searching for, and if it is then
|
|
|
|
// bail out early.
|
|
|
|
if (MangledName == SearchName)
|
|
|
|
if (!ExportedSymbolsOnly || GV.hasDefaultVisibility())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Otherwise add this to the map for later.
|
|
|
|
Names[MangledName] = GV.hasDefaultVisibility();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build the MangledNames map. Bails out early (with MangledNames left set
|
|
|
|
// to nullptr) if the given SearchName is found while building the map.
|
|
|
|
void buildMangledNames(StringRef SearchName,
|
|
|
|
bool ExportedSymbolsOnly) const {
|
|
|
|
assert(!MangledNames && "Mangled names map already exists?");
|
|
|
|
|
|
|
|
auto Names = llvm::make_unique<StringMap<bool>>();
|
|
|
|
|
|
|
|
for (const auto &M : Ms) {
|
|
|
|
Mangler Mang(M->getDataLayout());
|
|
|
|
|
|
|
|
for (const auto &GV : M->globals())
|
|
|
|
if (addGlobalValue(*Names, GV, Mang, SearchName, ExportedSymbolsOnly))
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (const auto &F : *M)
|
|
|
|
if (addGlobalValue(*Names, F, Mang, SearchName, ExportedSymbolsOnly))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MangledNames = std::move(Names);
|
|
|
|
}
|
|
|
|
|
|
|
|
ModuleSetT Ms;
|
|
|
|
std::unique_ptr<RTDyldMemoryManager> MM;
|
|
|
|
mutable std::unique_ptr<StringMap<bool>> MangledNames;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::list<std::unique_ptr<EmissionDeferredSet>> ModuleSetListT;
|
|
|
|
|
|
|
|
BaseLayerT &BaseLayer;
|
|
|
|
ModuleSetListT ModuleSetList;
|
|
|
|
|
|
|
|
public:
|
|
|
|
/// @brief Handle to a set of loaded modules.
|
|
|
|
typedef typename ModuleSetListT::iterator ModuleSetHandleT;
|
|
|
|
|
|
|
|
/// @brief Construct a lazy emitting layer.
|
|
|
|
LazyEmittingLayer(BaseLayerT &BaseLayer) : BaseLayer(BaseLayer) {}
|
|
|
|
|
|
|
|
/// @brief Add the given set of modules to the lazy emitting layer.
|
|
|
|
template <typename ModuleSetT>
|
|
|
|
ModuleSetHandleT addModuleSet(ModuleSetT Ms,
|
|
|
|
std::unique_ptr<RTDyldMemoryManager> MM) {
|
|
|
|
return ModuleSetList.insert(
|
|
|
|
ModuleSetList.end(),
|
|
|
|
EmissionDeferredSet::create(BaseLayer, std::move(Ms), std::move(MM)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Remove the module set represented by the given handle.
|
|
|
|
///
|
|
|
|
/// This method will free the memory associated with the given module set,
|
|
|
|
/// both in this layer, and the base layer.
|
|
|
|
void removeModuleSet(ModuleSetHandleT H) {
|
2015-02-09 01:20:51 +00:00
|
|
|
(*H)->removeModulesFromBaseLayer(BaseLayer);
|
[Orc] New JIT APIs.
This patch adds a new set of JIT APIs to LLVM. The aim of these new APIs is to
cleanly support a wider range of JIT use cases in LLVM, and encourage the
development and contribution of re-usable infrastructure for LLVM JIT use-cases.
These APIs are intended to live alongside the MCJIT APIs, and should not affect
existing clients.
Included in this patch:
1) New headers in include/llvm/ExecutionEngine/Orc that provide a set of
components for building JIT infrastructure.
Implementation code for these headers lives in lib/ExecutionEngine/Orc.
2) A prototype re-implementation of MCJIT (OrcMCJITReplacement) built out of the
new components.
3) Minor changes to RTDyldMemoryManager needed to support the new components.
These changes should not impact existing clients.
4) A new flag for lli, -use-orcmcjit, which will cause lli to use the
OrcMCJITReplacement class as its underlying execution engine, rather than
MCJIT itself.
Tests to follow shortly.
Special thanks to Michael Ilseman, Pete Cooper, David Blaikie, Eric Christopher,
Justin Bogner, and Jim Grosbach for extensive feedback and discussion.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226940 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-23 21:25:00 +00:00
|
|
|
ModuleSetList.erase(H);
|
|
|
|
}
|
|
|
|
|
2015-02-09 01:20:51 +00:00
|
|
|
/// @brief Search for the given named symbol.
|
|
|
|
/// @param Name The name of the symbol to search for.
|
|
|
|
/// @param ExportedSymbolsOnly If true, search only for exported symbols.
|
|
|
|
/// @return A handle for the given named symbol, if it exists.
|
|
|
|
JITSymbol findSymbol(const std::string &Name, bool ExportedSymbolsOnly) {
|
|
|
|
// Look for the symbol among existing definitions.
|
|
|
|
if (auto Symbol = BaseLayer.findSymbol(Name, ExportedSymbolsOnly))
|
|
|
|
return Symbol;
|
|
|
|
|
|
|
|
// If not found then search the deferred sets. If any of these contain a
|
|
|
|
// definition of 'Name' then they will return a JITSymbol that will emit
|
|
|
|
// the corresponding module when the symbol address is requested.
|
[Orc] New JIT APIs.
This patch adds a new set of JIT APIs to LLVM. The aim of these new APIs is to
cleanly support a wider range of JIT use cases in LLVM, and encourage the
development and contribution of re-usable infrastructure for LLVM JIT use-cases.
These APIs are intended to live alongside the MCJIT APIs, and should not affect
existing clients.
Included in this patch:
1) New headers in include/llvm/ExecutionEngine/Orc that provide a set of
components for building JIT infrastructure.
Implementation code for these headers lives in lib/ExecutionEngine/Orc.
2) A prototype re-implementation of MCJIT (OrcMCJITReplacement) built out of the
new components.
3) Minor changes to RTDyldMemoryManager needed to support the new components.
These changes should not impact existing clients.
4) A new flag for lli, -use-orcmcjit, which will cause lli to use the
OrcMCJITReplacement class as its underlying execution engine, rather than
MCJIT itself.
Tests to follow shortly.
Special thanks to Michael Ilseman, Pete Cooper, David Blaikie, Eric Christopher,
Justin Bogner, and Jim Grosbach for extensive feedback and discussion.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226940 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-23 21:25:00 +00:00
|
|
|
for (auto &DeferredSet : ModuleSetList)
|
2015-02-09 01:20:51 +00:00
|
|
|
if (auto Symbol = DeferredSet->find(Name, ExportedSymbolsOnly, BaseLayer))
|
|
|
|
return Symbol;
|
[Orc] New JIT APIs.
This patch adds a new set of JIT APIs to LLVM. The aim of these new APIs is to
cleanly support a wider range of JIT use cases in LLVM, and encourage the
development and contribution of re-usable infrastructure for LLVM JIT use-cases.
These APIs are intended to live alongside the MCJIT APIs, and should not affect
existing clients.
Included in this patch:
1) New headers in include/llvm/ExecutionEngine/Orc that provide a set of
components for building JIT infrastructure.
Implementation code for these headers lives in lib/ExecutionEngine/Orc.
2) A prototype re-implementation of MCJIT (OrcMCJITReplacement) built out of the
new components.
3) Minor changes to RTDyldMemoryManager needed to support the new components.
These changes should not impact existing clients.
4) A new flag for lli, -use-orcmcjit, which will cause lli to use the
OrcMCJITReplacement class as its underlying execution engine, rather than
MCJIT itself.
Tests to follow shortly.
Special thanks to Michael Ilseman, Pete Cooper, David Blaikie, Eric Christopher,
Justin Bogner, and Jim Grosbach for extensive feedback and discussion.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226940 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-23 21:25:00 +00:00
|
|
|
|
2015-02-09 01:20:51 +00:00
|
|
|
// If no definition found anywhere return a null symbol.
|
|
|
|
return nullptr;
|
[Orc] New JIT APIs.
This patch adds a new set of JIT APIs to LLVM. The aim of these new APIs is to
cleanly support a wider range of JIT use cases in LLVM, and encourage the
development and contribution of re-usable infrastructure for LLVM JIT use-cases.
These APIs are intended to live alongside the MCJIT APIs, and should not affect
existing clients.
Included in this patch:
1) New headers in include/llvm/ExecutionEngine/Orc that provide a set of
components for building JIT infrastructure.
Implementation code for these headers lives in lib/ExecutionEngine/Orc.
2) A prototype re-implementation of MCJIT (OrcMCJITReplacement) built out of the
new components.
3) Minor changes to RTDyldMemoryManager needed to support the new components.
These changes should not impact existing clients.
4) A new flag for lli, -use-orcmcjit, which will cause lli to use the
OrcMCJITReplacement class as its underlying execution engine, rather than
MCJIT itself.
Tests to follow shortly.
Special thanks to Michael Ilseman, Pete Cooper, David Blaikie, Eric Christopher,
Justin Bogner, and Jim Grosbach for extensive feedback and discussion.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226940 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-23 21:25:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Get the address of the given symbol in the context of the set of
|
2015-02-09 01:20:51 +00:00
|
|
|
/// compiled modules represented by the handle H.
|
|
|
|
JITSymbol findSymbolIn(ModuleSetHandleT H, const std::string &Name,
|
|
|
|
bool ExportedSymbolsOnly) {
|
|
|
|
return (*H)->find(Name, ExportedSymbolsOnly, BaseLayer);
|
[Orc] New JIT APIs.
This patch adds a new set of JIT APIs to LLVM. The aim of these new APIs is to
cleanly support a wider range of JIT use cases in LLVM, and encourage the
development and contribution of re-usable infrastructure for LLVM JIT use-cases.
These APIs are intended to live alongside the MCJIT APIs, and should not affect
existing clients.
Included in this patch:
1) New headers in include/llvm/ExecutionEngine/Orc that provide a set of
components for building JIT infrastructure.
Implementation code for these headers lives in lib/ExecutionEngine/Orc.
2) A prototype re-implementation of MCJIT (OrcMCJITReplacement) built out of the
new components.
3) Minor changes to RTDyldMemoryManager needed to support the new components.
These changes should not impact existing clients.
4) A new flag for lli, -use-orcmcjit, which will cause lli to use the
OrcMCJITReplacement class as its underlying execution engine, rather than
MCJIT itself.
Tests to follow shortly.
Special thanks to Michael Ilseman, Pete Cooper, David Blaikie, Eric Christopher,
Justin Bogner, and Jim Grosbach for extensive feedback and discussion.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226940 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-23 21:25:00 +00:00
|
|
|
}
|
2015-02-16 22:36:25 +00:00
|
|
|
|
|
|
|
/// @brief Immediately emit and finalize the moduleOB set represented by the
|
|
|
|
/// given handle.
|
|
|
|
/// @param H Handle for module set to emit/finalize.
|
|
|
|
void emitAndFinalize(ModuleSetHandleT H) {
|
|
|
|
(*H)->emitAndFinalize(BaseLayer);
|
|
|
|
}
|
|
|
|
|
[Orc] New JIT APIs.
This patch adds a new set of JIT APIs to LLVM. The aim of these new APIs is to
cleanly support a wider range of JIT use cases in LLVM, and encourage the
development and contribution of re-usable infrastructure for LLVM JIT use-cases.
These APIs are intended to live alongside the MCJIT APIs, and should not affect
existing clients.
Included in this patch:
1) New headers in include/llvm/ExecutionEngine/Orc that provide a set of
components for building JIT infrastructure.
Implementation code for these headers lives in lib/ExecutionEngine/Orc.
2) A prototype re-implementation of MCJIT (OrcMCJITReplacement) built out of the
new components.
3) Minor changes to RTDyldMemoryManager needed to support the new components.
These changes should not impact existing clients.
4) A new flag for lli, -use-orcmcjit, which will cause lli to use the
OrcMCJITReplacement class as its underlying execution engine, rather than
MCJIT itself.
Tests to follow shortly.
Special thanks to Michael Ilseman, Pete Cooper, David Blaikie, Eric Christopher,
Justin Bogner, and Jim Grosbach for extensive feedback and discussion.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226940 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-23 21:25:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename BaseLayerT>
|
|
|
|
template <typename ModuleSetT>
|
|
|
|
std::unique_ptr<typename LazyEmittingLayer<BaseLayerT>::EmissionDeferredSet>
|
|
|
|
LazyEmittingLayer<BaseLayerT>::EmissionDeferredSet::create(
|
|
|
|
BaseLayerT &B, ModuleSetT Ms, std::unique_ptr<RTDyldMemoryManager> MM) {
|
|
|
|
return llvm::make_unique<EmissionDeferredSetImpl<ModuleSetT>>(std::move(Ms),
|
|
|
|
std::move(MM));
|
|
|
|
}
|
2015-02-21 20:44:36 +00:00
|
|
|
|
|
|
|
} // End namespace orc.
|
|
|
|
} // End namespace llvm.
|
[Orc] New JIT APIs.
This patch adds a new set of JIT APIs to LLVM. The aim of these new APIs is to
cleanly support a wider range of JIT use cases in LLVM, and encourage the
development and contribution of re-usable infrastructure for LLVM JIT use-cases.
These APIs are intended to live alongside the MCJIT APIs, and should not affect
existing clients.
Included in this patch:
1) New headers in include/llvm/ExecutionEngine/Orc that provide a set of
components for building JIT infrastructure.
Implementation code for these headers lives in lib/ExecutionEngine/Orc.
2) A prototype re-implementation of MCJIT (OrcMCJITReplacement) built out of the
new components.
3) Minor changes to RTDyldMemoryManager needed to support the new components.
These changes should not impact existing clients.
4) A new flag for lli, -use-orcmcjit, which will cause lli to use the
OrcMCJITReplacement class as its underlying execution engine, rather than
MCJIT itself.
Tests to follow shortly.
Special thanks to Michael Ilseman, Pete Cooper, David Blaikie, Eric Christopher,
Justin Bogner, and Jim Grosbach for extensive feedback and discussion.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226940 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-23 21:25:00 +00:00
|
|
|
|
|
|
|
#endif // LLVM_EXECUTIONENGINE_ORC_LAZYEMITTINGLAYER_H
|