OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CompilationContext.h
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, 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  virtual size_t getMemSize() const = 0;
29  size_t size() const { return getMemSize(); }
30 };
31 
32 struct CompilationOptions;
33 
35  public:
37  ExecutionEngineWrapper(llvm::ExecutionEngine* execution_engine);
38  ExecutionEngineWrapper(llvm::ExecutionEngine* execution_engine,
39  const CompilationOptions& co);
40 
41  ExecutionEngineWrapper(const ExecutionEngineWrapper& other) = delete;
43 
46 
47  ExecutionEngineWrapper& operator=(llvm::ExecutionEngine* execution_engine);
48 
49  llvm::ExecutionEngine* get() { return execution_engine_.get(); }
50  const llvm::ExecutionEngine* get() const { return execution_engine_.get(); }
51 
52  llvm::ExecutionEngine& operator*() { return *execution_engine_; }
53  const llvm::ExecutionEngine& operator*() const { return *execution_engine_; }
54 
55  llvm::ExecutionEngine* operator->() { return execution_engine_.get(); }
56  const llvm::ExecutionEngine* operator->() const { return execution_engine_.get(); }
57 
58  private:
59  std::unique_ptr<llvm::ExecutionEngine> execution_engine_;
60  std::unique_ptr<llvm::JITEventListener> intel_jit_listener_;
61 };
62 
64  public:
66  : execution_engine_(std::move(execution_engine)) {}
67 
68  template <typename... Ts>
69  void call(Ts... args) const {
70  reinterpret_cast<void (*)(Ts...)>(func_)(args...);
71  }
72 
73  const std::string& name() const { return name_; }
74 
75  void setFunctionPointer(llvm::Function* function) {
76  func_ = execution_engine_->getPointerToFunction(function);
77  CHECK(func_);
78  name_ = function->getName().str();
79  execution_engine_->removeModule(function->getParent());
80  }
81 
82  void* func() const { return func_; }
83 
84  using TableFunctionEntryPointPtr = int32_t (*)(const int8_t* mgr_ptr,
85  const int8_t** input_cols,
86  const int64_t* input_row_count,
87  const int8_t** input_str_dict_proxy_ptrs,
88  int64_t** out,
89  int8_t** output_str_dict_proxy_ptrs,
90  int64_t* output_row_count);
93  }
94 
95  size_t getMemSize() const { return 0; }
96 
97  private:
98  void* func_{nullptr};
99  std::string name_;
101 };
void call(Ts...args) const
CpuCompilationContext(ExecutionEngineWrapper &&execution_engine)
void setFunctionPointer(llvm::Function *function)
size_t getMemSize() const
const std::string & name() const
ExecutionEngineWrapper execution_engine_
ExecutionEngineWrapper & operator=(const ExecutionEngineWrapper &other)=delete
virtual size_t getMemSize() const =0
std::unique_ptr< llvm::JITEventListener > intel_jit_listener_
const llvm::ExecutionEngine & operator*() const
size_t size() const
TableFunctionEntryPointPtr table_function_entry_point() const
llvm::ExecutionEngine * operator->()
const llvm::ExecutionEngine * operator->() const
std::unique_ptr< llvm::ExecutionEngine > execution_engine_
#define CHECK(condition)
Definition: Logger.h:291
llvm::ExecutionEngine & operator*()
int32_t(*)(const int8_t *mgr_ptr, const int8_t **input_cols, const int64_t *input_row_count, const int8_t **input_str_dict_proxy_ptrs, int64_t **out, int8_t **output_str_dict_proxy_ptrs, int64_t *output_row_count) TableFunctionEntryPointPtr