ETISS 0.8.0
Extendable Translating Instruction Set Simulator (version 0.8.0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
LLVMJIT.h
Go to the documentation of this file.
1/*
2
3 @copyright
4
5 <pre>
6
7 Copyright 2018 Infineon Technologies AG
8
9 This file is part of ETISS tool, see <https://github.com/tum-ei-eda/etiss>.
10
11 The initial version of this software has been created with the funding support by the German Federal
12 Ministry of Education and Research (BMBF) in the project EffektiV under grant 01IS13022.
13
14 Redistribution and use in source and binary forms, with or without modification, are permitted
15 provided that the following conditions are met:
16
17 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
18 the following disclaimer.
19
20 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
21 and the following disclaimer in the documentation and/or other materials provided with the distribution.
22
23 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse
24 or promote products derived from this software without specific prior written permission.
25
26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
27 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
28 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
29 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 POSSIBILITY OF SUCH DAMAGE.
34
35 </pre>
36
37 @author Chair of Electronic Design Automation, TUM
38
39 @version 0.1
40
41*/
42#include "etiss/JIT.h"
43
44#include "clang/Basic/DiagnosticOptions.h" // logging
45#include "clang/CodeGen/CodeGenAction.h" // code generation action "compile to IR" (for mcjit)
46#include "clang/Frontend/CompilerInstance.h" // compiler
47#include "clang/Frontend/CompilerInvocation.h" // compilation run
48#include "clang/Frontend/FrontendDiagnostic.h" // logging
49#include "clang/Frontend/TextDiagnosticPrinter.h" //logging
50#include "llvm/ADT/SmallString.h"
51#include "llvm/ExecutionEngine/ExecutionEngine.h" // interface to MCJIT
52#include "llvm/ExecutionEngine/Interpreter.h" // link interpreter into library (currently not used)
53#include "llvm/ExecutionEngine/MCJIT.h" // IMPORTANT link MCJIT into library. if this is not included then the performance will drop by ~50%
54#include "llvm/Support/TargetSelect.h" // target arch
55#include "llvm/Support/raw_ostream.h" // logging
56//#include "llvm/ExecutionEngine/JIT.h" // old execution engine (performance
57// drop ~50 to MCJIT)
58#include "clang/Basic/DiagnosticOptions.h"
59#include "clang/Basic/TargetInfo.h"
60#include "clang/Basic/TargetOptions.h"
61#include "clang/Frontend/CompilerInstance.h"
62#include "clang/Frontend/TextDiagnosticPrinter.h"
63#include "llvm/ADT/IntrusiveRefCntPtr.h"
64#include "llvm/Analysis/LoopPass.h"
65#include "llvm/Analysis/Passes.h"
66#include "llvm/ExecutionEngine/ExecutionEngine.h"
67#include "llvm/IR/DataLayout.h"
68#include "llvm/IR/DerivedTypes.h"
69#include "llvm/IR/IRBuilder.h"
70#include "llvm/IR/LLVMContext.h"
71#include "llvm/IR/Module.h" // compiled code container
72#include "llvm/IR/Module.h"
73#include "llvm/Support/CommandLine.h"
74#include "llvm/Support/DynamicLibrary.h"
75#include "llvm/Support/FileSystem.h"
76#include "llvm/Support/Host.h"
77#include "llvm/Support/ManagedStatic.h"
78#include "llvm/Support/Path.h"
79#include "llvm/Support/TargetSelect.h"
80#include "llvm/Support/raw_ostream.h"
81#include "llvm/Target/TargetMachine.h"
82#include "llvm/Transforms/IPO.h"
83#include "llvm/Transforms/Scalar.h"
84#include <cctype>
85#include <clang/CodeGen/CodeGenAction.h>
86#include <clang/Frontend/CompilerInstance.h>
87#include <clang/Frontend/CompilerInvocation.h>
88#include <clang/Frontend/TextDiagnosticPrinter.h>
89#include <cstdio>
90#include <llvm/ADT/IntrusiveRefCntPtr.h>
91#include <map>
92#include <memory>
93#include <mutex>
94#include <string>
95#include <vector>
96#include <unordered_set>
97
98class OrcJit;
99
100namespace etiss
101{
102
103class LLVMJIT : public etiss::JIT
104{
105 public:
106 LLVMJIT();
107 virtual ~LLVMJIT();
108 virtual void *translate(std::string code, std::set<std::string> headerpaths, std::set<std::string> librarypaths,
109 std::set<std::string> libraries, std::string &error, bool debug = false);
110 virtual void *getFunction(void *handle, std::string name, std::string &error);
111 virtual void free(void *handle);
112
113 private:
114 llvm::LLVMContext context_;
115 OrcJit *orcJit_ = nullptr;
116 std::unordered_set<std::string> loadedLibs_;
117
118};
119
120} // namespace etiss
JIT compiler interface definition.
compiler interface for just in time compilation of generated C code
Definition JIT.h:67
virtual ~LLVMJIT()
Definition LLVMJIT.cpp:195
virtual void * getFunction(void *handle, std::string name, std::string &error)
returns a function pointer to a compiled function from the handle returned by etiss::JIT::translate
Definition LLVMJIT.cpp:286
OrcJit * orcJit_
Definition LLVMJIT.h:115
llvm::LLVMContext context_
Definition LLVMJIT.h:114
std::unordered_set< std::string > loadedLibs_
Definition LLVMJIT.h:116
virtual void free(void *handle)
clean up handled returned by etiss::JIT::translate
Definition LLVMJIT.cpp:294
virtual void * translate(std::string code, std::set< std::string > headerpaths, std::set< std::string > librarypaths, std::set< std::string > libraries, std::string &error, bool debug=false)
translate C code to executable code and return a handle/pointer that identifies the compilation resul...
Definition LLVMJIT.cpp:200
Page Table Entry (PTE) defines the composition of Page Frame Number (PFN) and relavant flags.
Definition Benchmark.h:53