2020-12-30 05:22:18 +08:00
|
|
|
//===- NpcompModule.cpp - MLIR Python bindings ----------------------------===//
|
2020-04-27 06:50:23 +08:00
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
#include <unordered_map>
|
|
|
|
|
2021-07-28 07:10:10 +08:00
|
|
|
#include "./NpcompModule.h"
|
|
|
|
#include "./NpcompPybindUtils.h"
|
|
|
|
|
2020-12-30 05:22:18 +08:00
|
|
|
#include "mlir-c/BuiltinAttributes.h"
|
|
|
|
#include "mlir-c/BuiltinTypes.h"
|
|
|
|
#include "mlir-c/Diagnostics.h"
|
|
|
|
#include "npcomp-c/InitLLVM.h"
|
2020-11-11 13:38:13 +08:00
|
|
|
#include "npcomp-c/Registration.h"
|
2020-07-11 08:36:32 +08:00
|
|
|
|
2020-12-30 05:22:18 +08:00
|
|
|
namespace {
|
2020-05-01 07:00:00 +08:00
|
|
|
|
2020-12-30 05:22:18 +08:00
|
|
|
// TODO: Move this upstream.
|
|
|
|
void emitError(MlirLocation loc, std::string message) {
|
|
|
|
::mlirEmitError(loc, message.c_str());
|
|
|
|
}
|
2020-05-01 07:00:00 +08:00
|
|
|
|
2020-12-30 05:22:18 +08:00
|
|
|
} // namespace
|
2020-05-07 09:24:51 +08:00
|
|
|
|
2020-12-30 05:22:18 +08:00
|
|
|
PYBIND11_MODULE(_npcomp, m) {
|
|
|
|
m.doc() = "Npcomp native python bindings";
|
2021-08-23 03:17:12 +08:00
|
|
|
::npcompRegisterAllPasses();
|
|
|
|
::npcompInitializeLLVMCodegen();
|
2020-06-19 14:28:30 +08:00
|
|
|
|
2020-12-30 05:22:18 +08:00
|
|
|
m.def("register_all_dialects", ::npcompRegisterAllDialects);
|
|
|
|
m.def("emit_error", emitError);
|
2020-11-11 13:38:13 +08:00
|
|
|
|
2020-06-19 14:28:30 +08:00
|
|
|
// Optional backend modules.
|
|
|
|
auto backend_m = m.def_submodule("backend", "Backend support");
|
|
|
|
(void)backend_m;
|
|
|
|
|
2020-07-11 08:36:32 +08:00
|
|
|
#ifdef NPCOMP_ENABLE_REFJIT
|
|
|
|
auto refjit_m =
|
|
|
|
backend_m.def_submodule("refjit", "Reference CPU Jit Backend");
|
|
|
|
::npcomp::python::defineBackendRefJitModule(refjit_m);
|
|
|
|
#endif
|
2020-04-27 06:50:23 +08:00
|
|
|
}
|