diff options
| author | Lang Hames <lhames@gmail.com> | 2019-11-14 15:58:21 -0800 |
|---|---|---|
| committer | Lang Hames <lhames@gmail.com> | 2019-11-14 21:27:19 -0800 |
| commit | 16f38dda292c6e2963e77f722042a9eb5da56d28 (patch) | |
| tree | 412b958c6d721df8ad15a3b014872fc5c8d9292e /llvm/examples/LLJITExamples/LLJITDumpObjects | |
| parent | bc11830c6a67025186d39fd9de6e49b3b570e2bd (diff) | |
| download | bcm5719-llvm-16f38dda292c6e2963e77f722042a9eb5da56d28.tar.gz bcm5719-llvm-16f38dda292c6e2963e77f722042a9eb5da56d28.zip | |
[ORC] Add a utility to support dumping JIT'd objects to disk for debugging.
Adds a DumpObjects utility that can be used to dump JIT'd objects to disk.
Instances of DebugObjects may be used by ObjectTransformLayer as no-op
transforms.
This patch also adds an ObjectTransformLayer to LLJIT and an example of how
to use this utility to dump JIT'd objects in LLJIT.
Diffstat (limited to 'llvm/examples/LLJITExamples/LLJITDumpObjects')
| -rw-r--r-- | llvm/examples/LLJITExamples/LLJITDumpObjects/CMakeLists.txt | 12 | ||||
| -rw-r--r-- | llvm/examples/LLJITExamples/LLJITDumpObjects/LLJITDumpObjects.cpp | 70 |
2 files changed, 82 insertions, 0 deletions
diff --git a/llvm/examples/LLJITExamples/LLJITDumpObjects/CMakeLists.txt b/llvm/examples/LLJITExamples/LLJITDumpObjects/CMakeLists.txt new file mode 100644 index 00000000000..bf3bc7193ae --- /dev/null +++ b/llvm/examples/LLJITExamples/LLJITDumpObjects/CMakeLists.txt @@ -0,0 +1,12 @@ +set(LLVM_LINK_COMPONENTS + Core + ExecutionEngine + IRReader + OrcJIT + Support + nativecodegen + ) + +add_llvm_example(LLJITDumpObjects + LLJITDumpObjects.cpp + ) diff --git a/llvm/examples/LLJITExamples/LLJITDumpObjects/LLJITDumpObjects.cpp b/llvm/examples/LLJITExamples/LLJITDumpObjects/LLJITDumpObjects.cpp new file mode 100644 index 00000000000..875292a2e09 --- /dev/null +++ b/llvm/examples/LLJITExamples/LLJITDumpObjects/LLJITDumpObjects.cpp @@ -0,0 +1,70 @@ +//===----- LLJITDumpObjects.cpp - How to dump JIT'd objects with LLJIT ----===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "llvm/ADT/StringMap.h" +#include "llvm/ExecutionEngine/Orc/DebugUtils.h" +#include "llvm/ExecutionEngine/Orc/LLJIT.h" +#include "llvm/Support/InitLLVM.h" +#include "llvm/Support/TargetSelect.h" +#include "llvm/Support/raw_ostream.h" + +#include "../ExampleModules.h" + +using namespace llvm; +using namespace llvm::orc; + +ExitOnError ExitOnErr; + +cl::opt<bool> DumpJITdObjects("dump-jitted-objects", + cl::desc("dump jitted objects"), cl::Optional, + cl::init(true)); + +cl::opt<std::string> DumpDir("dump-dir", + cl::desc("directory to dump objects to"), + cl::Optional, cl::init("")); + +cl::opt<std::string> DumpFileStem("dump-file-stem", + cl::desc("Override default dump names"), + cl::Optional, cl::init("")); + +int main(int argc, char *argv[]) { + // Initialize LLVM. + InitLLVM X(argc, argv); + + InitializeNativeTarget(); + InitializeNativeTargetAsmPrinter(); + + cl::ParseCommandLineOptions(argc, argv, "HowToUseLLJIT"); + ExitOnErr.setBanner(std::string(argv[0]) + ": "); + + outs() + << "Usage notes:\n" + " Use -debug-only=orc on debug builds to see log messages of objects " + "being dumped\n" + " Specify -dump-dir to specify a dump directory\n" + " Specify -dump-file-stem to override the dump file stem\n" + " Specify -dump-jitted-objects=false to disable dumping\n"; + + auto J = ExitOnErr(LLJITBuilder().create()); + + if (DumpJITdObjects) + J->getObjTransformLayer().setTransform(DumpObjects(DumpDir, DumpFileStem)); + + auto M = ExitOnErr(parseExampleModule(Add1Example, "add1")); + + ExitOnErr(J->addIRModule(std::move(M))); + + // Look up the JIT'd function, cast it to a function pointer, then call it. + auto Add1Sym = ExitOnErr(J->lookup("add1")); + int (*Add1)(int) = (int (*)(int))Add1Sym.getAddress(); + + int Result = Add1(42); + outs() << "add1(42) = " << Result << "\n"; + + return 0; +} |

