1#include "taichi/runtime/cpu/aot_module_loader_impl.h"
2#include "taichi/runtime/llvm/llvm_aot_module_loader.h"
3
4#include "taichi/runtime/llvm/llvm_offline_cache.h"
5#include "taichi/runtime/llvm/llvm_runtime_executor.h"
6#include "taichi/codegen/cpu/codegen_cpu.h"
7
8namespace taichi::lang {
9namespace {
10
11class AotModuleImpl : public LlvmAotModule {
12 public:
13 explicit AotModuleImpl(const cpu::AotModuleParams &params)
14 : LlvmAotModule(params.module_path, params.executor_) {
15 }
16
17 private:
18 FunctionType convert_module_to_function(
19 const std::string &name,
20 LlvmOfflineCache::KernelCacheData &&loaded) override {
21 Arch arch = executor_->get_config().arch;
22 TI_ASSERT(arch == Arch::x64 || arch == Arch::arm64);
23 auto *tlctx = executor_->get_llvm_context();
24
25 CPUModuleToFunctionConverter converter{tlctx, executor_};
26 return converter.convert(name, loaded.args,
27 std::move(loaded.compiled_data));
28 }
29
30 std::unique_ptr<aot::KernelTemplate> make_new_kernel_template(
31 const std::string &name) override {
32 TI_NOT_IMPLEMENTED;
33 return nullptr;
34 }
35};
36
37} // namespace
38
39namespace cpu {
40
41std::unique_ptr<aot::Module> make_aot_module(std::any mod_params) {
42 auto mod = std::make_unique<AotModuleImpl>(
43 std::any_cast<const AotModuleParams &>(mod_params));
44 return mod;
45}
46
47} // namespace cpu
48} // namespace taichi::lang
49