After the introduction of `OpAsmAttrInterface`, it is favorable to migrate code using `OpAsmDialectInterface` for ASM alias generation, which lives in `Dialect.cpp`, to use `OpAsmAttrInterface`, which lives in `Attrs.td`. In this way, attribute behavior is placed near its tablegen definition and people won't need to go through other files to know what other (unexpected) hooks comes into play. See #124721 for the interface itself and #128191 and #130479 for prior migrations. Note that `MLProgramOpAsmInterface` has no content now. However, if we delete it, a failure related to dialect resource handling will occur ``` within split at llvm-project/mlir/test/IR/invalid-file-metadata.mlir:60 offset :7:7: error: unexpected error: unexpected 'resource' section for dialect 'ml_program' ``` To support resource such interface must be registered.
63 lines
2.0 KiB
C++
63 lines
2.0 KiB
C++
//===- MLProgramDialect.cpp - MLProgram dialect implementation ------------===//
|
|
//
|
|
// 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 "mlir/Dialect/MLProgram/IR/MLProgram.h"
|
|
#include "mlir/IR/DialectImplementation.h"
|
|
#include "mlir/Transforms/InliningUtils.h"
|
|
#include "llvm/ADT/TypeSwitch.h"
|
|
|
|
using namespace mlir;
|
|
using namespace mlir::ml_program;
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
/// Tablegen Definitions
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "mlir/Dialect/MLProgram/IR/MLProgramOpsDialect.cpp.inc"
|
|
#define GET_ATTRDEF_CLASSES
|
|
#include "mlir/Dialect/MLProgram/IR/MLProgramAttributes.cpp.inc"
|
|
#define GET_TYPEDEF_CLASSES
|
|
#include "mlir/Dialect/MLProgram/IR/MLProgramTypes.cpp.inc"
|
|
|
|
namespace {
|
|
|
|
struct MLProgramInlinerInterface : public DialectInlinerInterface {
|
|
using DialectInlinerInterface::DialectInlinerInterface;
|
|
|
|
bool isLegalToInline(Operation *, Region *, bool,
|
|
IRMapping &) const override {
|
|
// We have no specific opinion on whether ops defined in this dialect should
|
|
// be inlined.
|
|
return true;
|
|
}
|
|
};
|
|
|
|
struct MLProgramOpAsmDialectInterface : public OpAsmDialectInterface {
|
|
using OpAsmDialectInterface::OpAsmDialectInterface;
|
|
};
|
|
} // namespace
|
|
|
|
void ml_program::MLProgramDialect::initialize() {
|
|
#define GET_ATTRDEF_LIST
|
|
addAttributes<
|
|
#include "mlir/Dialect/MLProgram/IR/MLProgramAttributes.cpp.inc"
|
|
>();
|
|
|
|
#define GET_TYPEDEF_LIST
|
|
addTypes<
|
|
#include "mlir/Dialect/MLProgram/IR/MLProgramTypes.cpp.inc"
|
|
>();
|
|
|
|
addOperations<
|
|
#define GET_OP_LIST
|
|
#include "mlir/Dialect/MLProgram/IR/MLProgramOps.cpp.inc"
|
|
>();
|
|
|
|
addInterfaces<MLProgramInlinerInterface, MLProgramOpAsmDialectInterface>();
|
|
}
|