2020-05-07 13:44:12 +08:00
|
|
|
//===- MlirInit.cpp -------------------------------------------------------===//
|
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
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2020-06-19 09:02:39 +08:00
|
|
|
#include "npcomp/Python/MlirInit.h"
|
2020-06-04 14:58:58 +08:00
|
|
|
|
2020-07-11 13:45:30 +08:00
|
|
|
#include "mlir/ExecutionEngine/OptUtils.h"
|
2020-05-01 07:00:00 +08:00
|
|
|
#include "mlir/IR/Dialect.h"
|
2020-04-27 06:50:23 +08:00
|
|
|
#include "mlir/InitAllDialects.h"
|
2020-06-03 16:29:59 +08:00
|
|
|
#include "mlir/InitAllPasses.h"
|
2020-05-01 07:00:00 +08:00
|
|
|
#include "mlir/Pass/PassManager.h"
|
2020-06-04 14:58:58 +08:00
|
|
|
#include "mlir/Pass/PassRegistry.h"
|
2020-10-09 09:29:59 +08:00
|
|
|
#include "npcomp-c/InitLLVM.h"
|
2020-06-10 10:22:24 +08:00
|
|
|
#include "npcomp/Dialect/Basicpy/IR/BasicpyDialect.h"
|
|
|
|
#include "npcomp/Dialect/Numpy/IR/NumpyDialect.h"
|
2020-06-04 14:58:58 +08:00
|
|
|
#include "npcomp/InitAll.h"
|
2020-05-01 07:00:00 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2020-07-11 13:45:30 +08:00
|
|
|
#include "llvm/Support/InitLLVM.h"
|
2020-05-01 07:00:00 +08:00
|
|
|
#include "llvm/Support/PrettyStackTrace.h"
|
|
|
|
#include "llvm/Support/Signals.h"
|
2020-07-11 13:45:30 +08:00
|
|
|
#include "llvm/Support/TargetSelect.h"
|
2020-04-27 06:50:23 +08:00
|
|
|
|
2020-08-28 06:09:10 +08:00
|
|
|
bool mlir::npcomp::python::npcompMlirInitialize() {
|
2020-05-01 07:00:00 +08:00
|
|
|
// Enable LLVM's signal handler to get nice stack traces.
|
|
|
|
llvm::sys::SetOneShotPipeSignalFunction(
|
|
|
|
llvm::sys::DefaultOneShotPipeSignalHandler);
|
|
|
|
llvm::sys::PrintStackTraceOnErrorSignal("npcomp");
|
|
|
|
|
|
|
|
// Register any pass manager command line options.
|
|
|
|
mlir::registerPassManagerCLOptions();
|
|
|
|
mlir::registerMLIRContextCLOptions();
|
|
|
|
|
|
|
|
std::string program_name = "npcomp";
|
|
|
|
std::vector<const char *> default_options = {program_name.c_str(), nullptr};
|
|
|
|
llvm::cl::ParseCommandLineOptions(1, default_options.data());
|
|
|
|
|
2020-08-28 06:09:10 +08:00
|
|
|
// Pass registration.
|
2020-06-03 16:29:59 +08:00
|
|
|
::mlir::registerAllPasses();
|
2020-06-04 14:58:58 +08:00
|
|
|
::mlir::NPCOMP::registerAllPasses();
|
2020-05-01 07:00:00 +08:00
|
|
|
|
2020-10-09 09:29:59 +08:00
|
|
|
// Initialize code generation.
|
|
|
|
npcompInitializeLLVMCodegen();
|
2020-07-11 13:45:30 +08:00
|
|
|
|
2020-05-01 07:00:00 +08:00
|
|
|
return true;
|
2020-04-27 06:50:23 +08:00
|
|
|
}
|
|
|
|
|
2020-08-28 06:09:10 +08:00
|
|
|
void mlir::npcomp::python::loadGlobalDialectsIntoContext(MLIRContext *context) {
|
|
|
|
static mlir::DialectRegistry registry = ([]() {
|
|
|
|
mlir::DialectRegistry registry;
|
|
|
|
::mlir::registerAllDialects(registry);
|
|
|
|
::mlir::NPCOMP::registerAllDialects(registry);
|
|
|
|
return registry;
|
|
|
|
})();
|
|
|
|
registry.loadAll(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace mlir {
|
|
|
|
namespace npcomp {
|
|
|
|
namespace python {
|
|
|
|
|
2020-09-16 08:54:58 +08:00
|
|
|
LogicalResult parsePassPipeline(StringRef pipeline, OpPassManager &pm,
|
|
|
|
raw_ostream &errorStream = llvm::errs()) {
|
2020-06-04 14:58:58 +08:00
|
|
|
return ::mlir::parsePassPipeline(pipeline, pm, errorStream);
|
|
|
|
}
|
|
|
|
|
2020-04-27 06:50:23 +08:00
|
|
|
} // namespace python
|
2020-05-01 07:00:00 +08:00
|
|
|
} // namespace npcomp
|
|
|
|
} // namespace mlir
|