torch-mlir/lib/Dialect/Numpy/IR/NumpyDialect.cpp

46 lines
1.3 KiB
C++
Raw Normal View History

2020-04-27 08:20:58 +08:00
//===- NumpyDialect.cpp - Core numpy dialect --------------------*- C++ -*-===//
//
// This file is licensed 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 "npcomp/Dialect/Numpy/IR/NumpyDialect.h"
2020-04-30 09:20:42 +08:00
#include "mlir/IR/DialectImplementation.h"
#include "npcomp/Dialect/Numpy/IR/NumpyOps.h"
2020-04-27 08:20:58 +08:00
using namespace mlir;
2020-04-30 09:20:42 +08:00
using namespace mlir::NPCOMP::Numpy;
2020-04-27 08:20:58 +08:00
NumpyDialect::NumpyDialect(MLIRContext *context)
: Dialect(getDialectNamespace(), context) {
addOperations<
#define GET_OP_LIST
#include "npcomp/Dialect/Numpy/IR/NumpyOps.cpp.inc"
2020-04-27 08:20:58 +08:00
>();
2020-04-30 09:20:42 +08:00
addTypes<AnyDtypeType>();
}
Type NumpyDialect::parseType(DialectAsmParser &parser) const {
StringRef keyword;
if (parser.parseKeyword(&keyword))
return Type();
if (keyword == "any_dtype")
return AnyDtypeType::get(getContext());
parser.emitError(parser.getNameLoc(), "unknown numpy type: ") << keyword;
return Type();
}
void NumpyDialect::printType(Type type, DialectAsmPrinter &os) const {
switch (type.getKind()) {
case NumpyTypes::AnyDtypeType:
os << "any_dtype";
return;
default:
llvm_unreachable("unexpected 'numpy' type kind");
}
2020-04-27 08:20:58 +08:00
}