ETISS 0.11.2
ExtendableTranslatingInstructionSetSimulator(version0.11.2)
Loading...
Searching...
No Matches
llvm_compat.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-3-Clause
2//
3// This file is part of ETISS. It is licensed under the BSD 3-Clause License; you may not use this file except in
4// compliance with the License. You should have received a copy of the license along with this project. If not, see the
5// LICENSE file.
6
7#pragma once
8
9#include <memory>
10
11#include "llvm/Config/llvm-config.h"
12
13// Core utilities
14#include "llvm/ADT/StringRef.h"
15#include "llvm/Support/Error.h"
16#include "llvm/Support/MemoryBuffer.h"
17#if LLVM_VERSION_MAJOR < 17
18#include "llvm/Support/Host.h"
19#else
20#include "llvm/TargetParser/Host.h"
21#endif
22#include "llvm/Support/TargetSelect.h" // target arch
23
24#include "llvm/IR/DataLayout.h"
25#include "llvm/IR/LLVMContext.h"
26#include "llvm/IR/LegacyPassManager.h"
27
28#include "llvm/ExecutionEngine/Orc/LLJIT.h"
29#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
30#include "llvm/ExecutionEngine/Orc/Core.h"
31#include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
32#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
33#include "llvm/ExecutionEngine/Orc/IRTransformLayer.h"
34#include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
35#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
36#include "llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h"
37#include "llvm/ExecutionEngine/SectionMemoryManager.h"
38#if LLVM_VERSION_MAJOR < 12 // ORC v1 – old JIT
39#include "llvm/ExecutionEngine/Orc/OrcABISupport.h"
40#include "llvm/ExecutionEngine/Orc/LambdaResolver.h"
41#else // LLVM_VERSION_MAJOR >= 12 // Thread safety abstractions appeared in LLVM 12
42#include "llvm/ExecutionEngine/Orc/ThreadSafeModule.h"
43#endif
44// Transform passes
45#include "llvm/Transforms/InstCombine/InstCombine.h"
46#include "llvm/Transforms/Scalar/GVN.h"
47#include "llvm/Transforms/Scalar.h"
48
49#include "clang/CodeGen/CodeGenAction.h" // code generation action "compile to IR" (for mcjit)
50#include "clang/Basic/TargetInfo.h"
51#include "clang/Basic/FileManager.h"
52#include "clang/Frontend/CompilerInstance.h"
53
54namespace compat
55{
56
57#if LLVM_VERSION_MAJOR >= 11 && LLVM_VERSION_MAJOR <= 16
58using lookup_symbol_T = llvm::JITEvaluatedSymbol;
59#elif LLVM_VERSION_MAJOR >= 17 && LLVM_VERSION_MAJOR <= 20
60using lookup_symbol_T = llvm::orc::ExecutorSymbolDef;
61#else // LLVM_VERSION_MAJOR < 11 -> deprecated
62#warning "LLVM>=11 required."
63#endif
64
65#if LLVM_VERSION_MAJOR >= 11 && LLVM_VERSION_MAJOR <= 18
66static constexpr auto tu_module_T{ clang::TranslationUnitKind::TU_Module };
67#elif LLVM_VERSION_MAJOR >= 19 && LLVM_VERSION_MAJOR <= 20
68static constexpr auto tu_module_T{ clang::TranslationUnitKind::TU_ClangModule };
69#else // LLVM_VERSION_MAJOR < 11 -> deprecated
70#warning "LLVM>=11 required."
71#endif
72
73std::unique_ptr<llvm::orc::ExecutionSession> createExecutionSession();
74
75std::unique_ptr<llvm::MemoryBuffer> get_virtual_source(llvm::StringRef code, clang::CompilerInstance &CI);
76
77void *get_function_ptr(const compat::lookup_symbol_T &func);
78
79void createDiagnostics(clang::CompilerInstance &CI);
80} // namespace compat
std::unique_ptr< llvm::MemoryBuffer > get_virtual_source(llvm::StringRef code, clang::CompilerInstance &CI)
void * get_function_ptr(const compat::lookup_symbol_T &func)
void createDiagnostics(clang::CompilerInstance &CI)
std::unique_ptr< llvm::orc::ExecutionSession > createExecutionSession()