Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / llvm / tools / lli / ExecutionUtils.h
blob6bf9cd58e031b802a4148d92159748fa8e25a01e
1 //===- ExecutionUtils.h - Utilities for executing code in lli ---*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Contains utilities for executing code in lli.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_TOOLS_LLI_EXECUTIONUTILS_H
14 #define LLVM_TOOLS_LLI_EXECUTIONUTILS_H
16 #include "llvm/ExecutionEngine/JITSymbol.h"
17 #include "llvm/ExecutionEngine/Orc/Core.h"
18 #include "llvm/ExecutionEngine/Orc/Mangling.h"
19 #include "llvm/Support/Error.h"
20 #include "llvm/Support/ToolOutputFile.h"
22 #include <memory>
23 #include <utility>
25 namespace llvm {
27 enum class BuiltinFunctionKind {
28 DumpDebugDescriptor,
29 DumpDebugObjects,
32 // Utility class to expose symbols for special-purpose functions to the JIT.
33 class LLIBuiltinFunctionGenerator : public orc::DefinitionGenerator {
34 public:
35 LLIBuiltinFunctionGenerator(std::vector<BuiltinFunctionKind> Enabled,
36 orc::MangleAndInterner &Mangle);
38 Error tryToGenerate(orc::LookupState &LS, orc::LookupKind K,
39 orc::JITDylib &JD, orc::JITDylibLookupFlags JDLookupFlags,
40 const orc::SymbolLookupSet &Symbols) override;
42 void appendDebugObject(const char *Addr, size_t Size) {
43 TestOut->os().write(Addr, Size);
46 private:
47 orc::SymbolMap BuiltinFunctions;
48 std::unique_ptr<ToolOutputFile> TestOut;
50 template <typename T> void expose(orc::SymbolStringPtr Name, T *Handler) {
51 BuiltinFunctions[Name] = {orc::ExecutorAddr::fromPtr(Handler),
52 JITSymbolFlags::Exported};
55 static std::unique_ptr<ToolOutputFile> createToolOutput();
58 } // end namespace llvm
60 #endif // LLVM_TOOLS_LLI_EXECUTIONUTILS_H