2020-09-29 03:02:35 +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 "npcomp/Dialect/Torch/IR/TorchDialect.h"
|
2021-01-28 08:35:44 +08:00
|
|
|
#include "mlir/IR/DialectImplementation.h"
|
2021-02-19 10:31:06 +08:00
|
|
|
#include "mlir/Transforms/InliningUtils.h"
|
2020-09-29 03:02:35 +08:00
|
|
|
#include "npcomp/Dialect/Torch/IR/TorchOps.h"
|
2021-01-28 08:35:44 +08:00
|
|
|
#include "npcomp/Dialect/Torch/IR/TorchTypes.h"
|
2021-02-18 03:28:51 +08:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2021-01-28 08:35:44 +08:00
|
|
|
#include "llvm/ADT/TypeSwitch.h"
|
2020-09-29 03:02:35 +08:00
|
|
|
|
|
|
|
using namespace mlir;
|
|
|
|
using namespace mlir::NPCOMP::Torch;
|
|
|
|
|
2021-02-19 10:31:06 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Dialect Interfaces
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
struct TorchInlinerInterface : public DialectInlinerInterface {
|
|
|
|
using DialectInlinerInterface::DialectInlinerInterface;
|
|
|
|
bool isLegalToInline(Region *dest, Region *src, bool wouldBeCloned,
|
|
|
|
BlockAndValueMapping &valueMapping) const final {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool isLegalToInline(Operation *, Region *, bool wouldBeCloned,
|
|
|
|
BlockAndValueMapping &) const final {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
2021-01-28 08:35:44 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Tablegen Type Definitions
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#define GET_TYPEDEF_CLASSES
|
|
|
|
#include "npcomp/Dialect/Torch/IR/TorchTypes.cpp.inc"
|
|
|
|
|
2020-09-29 03:02:35 +08:00
|
|
|
void TorchDialect::initialize() {
|
|
|
|
addOperations<
|
|
|
|
#define GET_OP_LIST
|
|
|
|
#include "npcomp/Dialect/Torch/IR/TorchOps.cpp.inc"
|
|
|
|
>();
|
2021-01-28 08:35:44 +08:00
|
|
|
addTypes<
|
|
|
|
#define GET_TYPEDEF_LIST
|
|
|
|
#include "npcomp/Dialect/Torch/IR/TorchTypes.cpp.inc"
|
|
|
|
>();
|
2021-02-19 10:31:06 +08:00
|
|
|
addInterfaces<TorchInlinerInterface>();
|
2021-01-28 08:35:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Type TorchDialect::parseType(DialectAsmParser &parser) const {
|
|
|
|
StringRef keyword;
|
|
|
|
if (parser.parseKeyword(&keyword))
|
|
|
|
return Type();
|
|
|
|
if (Type type = generatedTypeParser(getContext(), parser, keyword))
|
|
|
|
return type;
|
|
|
|
|
|
|
|
parser.emitError(parser.getNameLoc(), "invalid 'torch' type: `")
|
|
|
|
<< keyword << "'";
|
|
|
|
return Type();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TorchDialect::printType(Type type, DialectAsmPrinter &printer) const {
|
|
|
|
if (failed(generatedTypePrinter(type, printer)))
|
|
|
|
llvm_unreachable("unknown 'torch' type");
|
2020-09-29 03:02:35 +08:00
|
|
|
}
|
2020-10-23 14:31:34 +08:00
|
|
|
|
|
|
|
#include "npcomp/Dialect/Torch/IR/OpInterfaces.h"
|