From f8a1d652da00ecff448213c58522da5a61d9bc4b Mon Sep 17 00:00:00 2001 From: River Riddle Date: Thu, 10 Jun 2021 17:22:37 -0700 Subject: [PATCH] [mlir][IR] Move MemRefElementTypeInterface to a new BuiltinTypeInterfaces file This allows for using other type interfaces in the builtin dialect, which currently results in a compile time failure (as it generates duplicate interface declarations). --- mlir/include/mlir/IR/BuiltinTypeInterfaces.td | 44 +++++++++++++++++++++++++++ mlir/include/mlir/IR/BuiltinTypes.td | 26 +--------------- mlir/include/mlir/IR/CMakeLists.txt | 5 ++- mlir/lib/IR/CMakeLists.txt | 1 + 4 files changed, 50 insertions(+), 26 deletions(-) create mode 100644 mlir/include/mlir/IR/BuiltinTypeInterfaces.td diff --git a/mlir/include/mlir/IR/BuiltinTypeInterfaces.td b/mlir/include/mlir/IR/BuiltinTypeInterfaces.td new file mode 100644 index 0000000..f8879e5 --- /dev/null +++ b/mlir/include/mlir/IR/BuiltinTypeInterfaces.td @@ -0,0 +1,44 @@ +//===- BuiltinTypeInterfaces.td - Builtin type interfaces --*- tablegen -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// +// +// This file contains definitions for type interfaces that closely interact with +// attributes, types, and operations in the builtin dialect. +// +//===----------------------------------------------------------------------===// + +#ifndef MLIR_IR_BUILTINTYPEINTERFACES_TD_ +#define MLIR_IR_BUILTINTYPEINTERFACES_TD_ + +include "mlir/IR/OpBase.td" + +//===----------------------------------------------------------------------===// +// MemRefElementTypeInterface +//===----------------------------------------------------------------------===// + +def MemRefElementTypeInterface : TypeInterface<"MemRefElementTypeInterface"> { + let cppNamespace = "::mlir"; + let description = [{ + Indication that this type can be used as element in memref types. + + Implementing this interface establishes a contract between this type and the + memref type indicating that this type can be used as element of ranked or + unranked memrefs. The type is expected to: + + - model an entity stored in memory; + - have non-zero size. + + For example, scalar values such as integers can implement this interface, + but indicator types such as `void` or `unit` should not. + + The interface currently has no methods and is used by types to opt into + being memref elements. This may change in the future, in particular to + require types to provide their size or alignment given a data layout. + }]; +} + +#endif // MLIR_IR_BUILTINTYPEINTERFACES_TD_ diff --git a/mlir/include/mlir/IR/BuiltinTypes.td b/mlir/include/mlir/IR/BuiltinTypes.td index b142f6e..3ad6e15 100644 --- a/mlir/include/mlir/IR/BuiltinTypes.td +++ b/mlir/include/mlir/IR/BuiltinTypes.td @@ -15,6 +15,7 @@ #define BUILTIN_TYPES include "mlir/IR/BuiltinDialect.td" +include "mlir/IR/BuiltinTypeInterfaces.td" // TODO: Currently the types defined in this file are prefixed with `Builtin_`. // This is to differentiate the types here with the ones in OpBase.td. We should @@ -249,31 +250,6 @@ def Builtin_Integer : Builtin_Type<"Integer"> { } //===----------------------------------------------------------------------===// -// MemRefElementTypeInterface -//===----------------------------------------------------------------------===// - -def MemRefElementTypeInterface : TypeInterface<"MemRefElementTypeInterface"> { - let cppNamespace = "::mlir"; - let description = [{ - Indication that this type can be used as element in memref types. - - Implementing this interface establishes a contract between this type and the - memref type indicating that this type can be used as element of ranked or - unranked memrefs. The type is expected to: - - - model an entity stored in memory; - - have non-zero size. - - For example, scalar values such as integers can implement this interface, - but indicator types such as `void` or `unit` should not. - - The interface currently has no methods and is used by types to opt into - being memref elements. This may change in the future, in particular to - require types to provide their size or alignment given a data layout. - }]; -} - -//===----------------------------------------------------------------------===// // MemRefType //===----------------------------------------------------------------------===// diff --git a/mlir/include/mlir/IR/CMakeLists.txt b/mlir/include/mlir/IR/CMakeLists.txt index b8b49aa..8dafaa1 100644 --- a/mlir/include/mlir/IR/CMakeLists.txt +++ b/mlir/include/mlir/IR/CMakeLists.txt @@ -24,9 +24,12 @@ add_public_tablegen_target(MLIRBuiltinOpsIncGen) set(LLVM_TARGET_DEFINITIONS BuiltinTypes.td) mlir_tablegen(BuiltinTypes.h.inc -gen-typedef-decls) mlir_tablegen(BuiltinTypes.cpp.inc -gen-typedef-defs) +add_public_tablegen_target(MLIRBuiltinTypesIncGen) + +set(LLVM_TARGET_DEFINITIONS BuiltinTypeInterfaces.td) mlir_tablegen(BuiltinTypeInterfaces.h.inc -gen-type-interface-decls) mlir_tablegen(BuiltinTypeInterfaces.cpp.inc -gen-type-interface-defs) -add_public_tablegen_target(MLIRBuiltinTypesIncGen) +add_public_tablegen_target(MLIRBuiltinTypeInterfacesIncGen) set(LLVM_TARGET_DEFINITIONS TensorEncoding.td) mlir_tablegen(TensorEncInterfaces.h.inc -gen-attr-interface-decls) diff --git a/mlir/lib/IR/CMakeLists.txt b/mlir/lib/IR/CMakeLists.txt index 06f1985..a04bc35 100644 --- a/mlir/lib/IR/CMakeLists.txt +++ b/mlir/lib/IR/CMakeLists.txt @@ -39,6 +39,7 @@ add_mlir_library(MLIRIR MLIRBuiltinLocationAttributesIncGen MLIRBuiltinOpsIncGen MLIRBuiltinTypesIncGen + MLIRBuiltinTypeInterfacesIncGen MLIRCallInterfacesIncGen MLIRCastInterfacesIncGen MLIRDataLayoutInterfacesIncGen -- 2.7.4