summaryrefslogtreecommitdiff
path: root/tools/lli/lli.cpp
diff options
context:
space:
mode:
authorAndrew Kaylor <andrew.kaylor@intel.com>2013-10-02 17:12:36 +0000
committerAndrew Kaylor <andrew.kaylor@intel.com>2013-10-02 17:12:36 +0000
commit0ab5c6c16b1b09d76c3ba2d70443b10bcc26169c (patch)
treeaf098f261c3db5f9da3efd5aa5ab1ca9e05046e0 /tools/lli/lli.cpp
parentaf7ae9d6890ce5fae27e38ccebb5da09288c49e0 (diff)
downloadllvm-0ab5c6c16b1b09d76c3ba2d70443b10bcc26169c.tar.gz
llvm-0ab5c6c16b1b09d76c3ba2d70443b10bcc26169c.tar.bz2
llvm-0ab5c6c16b1b09d76c3ba2d70443b10bcc26169c.tar.xz
Adding out-of-process execution support to lli.
At this time only Unix-based systems are supported. Windows has stubs and should re-route to the simulated mode. Thanks to Sriram Murali for contributions to this patch. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191843 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/lli/lli.cpp')
-rw-r--r--tools/lli/lli.cpp49
1 files changed, 41 insertions, 8 deletions
diff --git a/tools/lli/lli.cpp b/tools/lli/lli.cpp
index ba9cb99d5a..17b8ea7993 100644
--- a/tools/lli/lli.cpp
+++ b/tools/lli/lli.cpp
@@ -41,6 +41,7 @@
#include "llvm/Support/PluginLoader.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Process.h"
+#include "llvm/Support/Program.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/TargetSelect.h"
@@ -83,6 +84,18 @@ namespace {
cl::desc("Execute MCJIT'ed code in a separate process."),
cl::init(false));
+ // Manually specify the child process for remote execution. This overrides
+ // the simulated remote execution that allocates address space for child
+ // execution. The child process resides in the disk and communicates with lli
+ // via stdin/stdout pipes.
+ cl::opt<std::string>
+ MCJITRemoteProcess("mcjit-remote-process",
+ cl::desc("Specify the filename of the process to launch "
+ "for remote MCJIT execution. If none is specified,"
+ "\n\tremote execution will be simulated in-process."),
+ cl::value_desc("filename"),
+ cl::init(""));
+
// Determine optimization level.
cl::opt<char>
OptLevel("O",
@@ -481,30 +494,50 @@ int main(int argc, char **argv, char * const *envp) {
// Everything is prepared now, so lay out our program for the target
// address space, assign the section addresses to resolve any relocations,
// and send it to the target.
- RemoteTarget Target;
- Target.create();
+
+ OwningPtr<RemoteTarget> Target;
+ if (!MCJITRemoteProcess.empty()) { // Remote execution on a child process
+ if (!RemoteTarget::hostSupportsExternalRemoteTarget()) {
+ errs() << "Warning: host does not support external remote targets.\n"
+ << " Defaulting to simulated remote execution\n";
+ Target.reset(RemoteTarget::createRemoteTarget());
+ } else {
+ std::string ChildEXE = sys::FindProgramByName(MCJITRemoteProcess);
+ if (ChildEXE == "") {
+ errs() << "Unable to find child target: '\''" << MCJITRemoteProcess << "\'\n";
+ return -1;
+ }
+ Target.reset(RemoteTarget::createExternalRemoteTarget(MCJITRemoteProcess));
+ }
+ } else {
+ // No child process name provided, use simulated remote execution.
+ Target.reset(RemoteTarget::createRemoteTarget());
+ }
+
+ // Create the remote target
+ Target->create();
// Trigger compilation.
EE->generateCodeForModule(Mod);
// Layout the target memory.
- layoutRemoteTargetMemory(&Target, MM);
+ layoutRemoteTargetMemory(Target.get(), MM);
// Since we're executing in a (at least simulated) remote address space,
// we can't use the ExecutionEngine::runFunctionAsMain(). We have to
// grab the function address directly here and tell the remote target
// to execute the function.
// FIXME: argv and envp handling.
- uint64_t Entry = (uint64_t)EE->getPointerToFunction(EntryFn);
+ uint64_t Entry = EE->getFunctionAddress(EntryFn->getName().str());
DEBUG(dbgs() << "Executing '" << EntryFn->getName() << "' at 0x"
<< format("%llx", Entry) << "\n");
- if (Target.executeCode(Entry, Result))
- errs() << "ERROR: " << Target.getErrorMsg() << "\n";
+ if (Target->executeCode(Entry, Result))
+ errs() << "ERROR: " << Target->getErrorMsg() << "\n";
- Target.stop();
- } else {
+ Target->stop();
+ } else { // !RemoteMCJIT
// Trigger compilation separately so code regions that need to be
// invalidated will be known.
(void)EE->getPointerToFunction(EntryFn);