OmniSciDB  8a228a1076
CompilationContext.h
Go to the documentation of this file.
1 /*
2  * Copyright 2020 OmniSci, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <llvm/ExecutionEngine/ExecutionEngine.h>
20 #include <llvm/ExecutionEngine/JITEventListener.h>
21 #include <llvm/IR/Module.h>
22 
23 #include <memory>
24 
26  public:
27  virtual ~CompilationContext() {}
28 };
29 
30 struct CompilationOptions;
31 
33  public:
35  ExecutionEngineWrapper(llvm::ExecutionEngine* execution_engine);
36  ExecutionEngineWrapper(llvm::ExecutionEngine* execution_engine,
37  const CompilationOptions& co);
38 
39  ExecutionEngineWrapper(const ExecutionEngineWrapper& other) = delete;
41 
42  ExecutionEngineWrapper& operator=(const ExecutionEngineWrapper& other) = delete;
43  ExecutionEngineWrapper& operator=(ExecutionEngineWrapper&& other) = default;
44 
45  ExecutionEngineWrapper& operator=(llvm::ExecutionEngine* execution_engine);
46 
47  llvm::ExecutionEngine* get() { return execution_engine_.get(); }
48  const llvm::ExecutionEngine* get() const { return execution_engine_.get(); }
49 
50  llvm::ExecutionEngine& operator*() { return *execution_engine_; }
51  const llvm::ExecutionEngine& operator*() const { return *execution_engine_; }
52 
53  llvm::ExecutionEngine* operator->() { return execution_engine_.get(); }
54  const llvm::ExecutionEngine* operator->() const { return execution_engine_.get(); }
55 
56  private:
57  std::unique_ptr<llvm::ExecutionEngine> execution_engine_;
58  std::unique_ptr<llvm::JITEventListener> intel_jit_listener_;
59 };
60 
62  public:
64  : execution_engine_(std::move(execution_engine)) {}
65 
66  void setFunctionPointer(llvm::Function* function) {
67  func_ = execution_engine_->getPointerToFunction(function);
68  CHECK(func_);
69  }
70 
71  void* func() const { return func_; }
72 
73  private:
74  void* func_{nullptr};
76 };
CpuCompilationContext(ExecutionEngineWrapper &&execution_engine)
void setFunctionPointer(llvm::Function *function)
ExecutionEngineWrapper execution_engine_
std::unique_ptr< llvm::JITEventListener > intel_jit_listener_
llvm::ExecutionEngine * operator->()
std::unique_ptr< llvm::ExecutionEngine > execution_engine_
#define CHECK(condition)
Definition: Logger.h:197
const llvm::ExecutionEngine & operator*() const
llvm::ExecutionEngine & operator*()
const llvm::ExecutionEngine * operator->() const