From 1a92dbcfa88a857bf735c897125d9a2f9be53e9e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Markus=20B=C3=B6ck?= Date: Wed, 6 Jul 2022 17:39:18 +0200 Subject: [PATCH] [mlir][ods] Replace redundant `Type` instances for interfaces This patch makes use of TypeInterface implementing Type to remove instances of Type that simply checked whether a type implemented a given interface. As part of this refactoring, some changes had to be done in the OpenMP Dialect files. In particular, they assumed that OpenMPOps.td to only ever include OpenMP TypeInterfaces, which did not hold anymore with a moved include in LLVMOpBase.td. For that reason, the type interface defintions were moved into a new file as is convention. Differential Revision: https://reviews.llvm.org/D129210 --- mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td | 10 ++----- mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td | 1 - mlir/include/mlir/Dialect/OpenMP/CMakeLists.txt | 8 ++++-- mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td | 23 +++------------- .../mlir/Dialect/OpenMP/OpenMPTypeInterfaces.td | 31 ++++++++++++++++++++++ mlir/include/mlir/IR/OpBase.td | 2 +- mlir/lib/Dialect/OpenMP/CMakeLists.txt | 1 + 7 files changed, 44 insertions(+), 32 deletions(-) create mode 100644 mlir/include/mlir/Dialect/OpenMP/OpenMPTypeInterfaces.td diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td index 37e4744..3c63cdc 100644 --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td @@ -14,6 +14,7 @@ #ifndef LLVMIR_OP_BASE #define LLVMIR_OP_BASE +include "mlir/Dialect/LLVMIR/LLVMOpsInterfaces.td" include "mlir/IR/EnumAttr.td" include "mlir/IR/OpBase.td" include "mlir/Interfaces/SideEffectInterfaces.td" @@ -141,18 +142,11 @@ def LLVM_OpaqueStruct : Type< And<[LLVM_AnyStruct.predicate, CPred<"$_self.cast<::mlir::LLVM::LLVMStructType>().isOpaque()">]>>; -// Type constraint accepting types that implement that pointer element -// interface. -def LLVM_PointerElementType : Type< - CPred<"$_self.isa<::mlir::LLVM::PointerElementTypeInterface>()">, - "LLVM-compatible pointer element type">; - - // Type constraint accepting any LLVM type that can be loaded or stored, i.e. a // type that has size (not void, function or opaque struct type). def LLVM_LoadableType : Type< Or<[And<[LLVM_PrimitiveType.predicate, Neg]>, - LLVM_PointerElementType.predicate]>, + LLVM_PointerElementTypeInterface.predicate]>, "LLVM type with size">; // Type constraint accepting any LLVM aggregate type, i.e. structure or array. diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td index 84f2624..0a919c4 100644 --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td @@ -14,7 +14,6 @@ #define LLVMIR_OPS include "mlir/Dialect/LLVMIR/LLVMOpBase.td" -include "mlir/Dialect/LLVMIR/LLVMOpsInterfaces.td" include "mlir/IR/FunctionInterfaces.td" include "mlir/IR/SymbolInterfaces.td" include "mlir/Interfaces/CallInterfaces.td" diff --git a/mlir/include/mlir/Dialect/OpenMP/CMakeLists.txt b/mlir/include/mlir/Dialect/OpenMP/CMakeLists.txt index e544c30..258b87d 100644 --- a/mlir/include/mlir/Dialect/OpenMP/CMakeLists.txt +++ b/mlir/include/mlir/Dialect/OpenMP/CMakeLists.txt @@ -9,11 +9,15 @@ mlir_tablegen(OpenMPOps.h.inc -gen-op-decls) mlir_tablegen(OpenMPOps.cpp.inc -gen-op-defs) mlir_tablegen(OpenMPOpsEnums.h.inc -gen-enum-decls) mlir_tablegen(OpenMPOpsEnums.cpp.inc -gen-enum-defs) -mlir_tablegen(OpenMPTypeInterfaces.h.inc -gen-type-interface-decls) -mlir_tablegen(OpenMPTypeInterfaces.cpp.inc -gen-type-interface-defs) mlir_tablegen(OpenMPOpsAttributes.h.inc -gen-attrdef-decls -attrdefs-dialect=omp) mlir_tablegen(OpenMPOpsAttributes.cpp.inc -gen-attrdef-defs -attrdefs-dialect=omp) add_mlir_doc(OpenMPOps OpenMPDialect Dialects/ -gen-dialect-doc -dialect=omp) add_public_tablegen_target(MLIROpenMPOpsIncGen) add_dependencies(OpenMPDialectDocGen omp_common_td) add_mlir_interface(OpenMPOpsInterfaces) + +set(LLVM_TARGET_DEFINITIONS OpenMPTypeInterfaces.td) +mlir_tablegen(OpenMPTypeInterfaces.h.inc -gen-type-interface-decls) +mlir_tablegen(OpenMPTypeInterfaces.cpp.inc -gen-type-interface-defs) +add_public_tablegen_target(MLIROpenMPTypeInterfacesIncGen) +add_dependencies(mlir-generic-headers MLIROpenMPTypeInterfacesIncGen) diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td index 0c85e6b..3ee3aa1 100644 --- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td +++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td @@ -21,6 +21,7 @@ include "mlir/Interfaces/ControlFlowInterfaces.td" include "mlir/IR/SymbolInterfaces.td" include "mlir/Dialect/LLVMIR/LLVMOpBase.td" include "mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td" +include "mlir/Dialect/OpenMP/OpenMPTypeInterfaces.td" def OpenMP_Dialect : Dialect { let name = "omp"; @@ -38,26 +39,8 @@ class OpenMP_Op traits = []> : // Type which can be constraint accepting standard integers and indices. def IntLikeType : AnyTypeOf<[AnyInteger, Index]>; -def OpenMP_PointerLikeTypeInterface : TypeInterface<"PointerLikeType"> { - let cppNamespace = "::mlir::omp"; - - let description = [{ - An interface for pointer-like types suitable to contain a value that OpenMP - specification refers to as variable. - }]; - - let methods = [ - InterfaceMethod< - /*description=*/"Returns the pointee type.", - /*retTy=*/"::mlir::Type", - /*methodName=*/"getElementType" - >, - ]; -} - -def OpenMP_PointerLikeType : Type< - CPred<"$_self.isa<::mlir::omp::PointerLikeType>()">, - "OpenMP-compatible variable type", "::mlir::omp::PointerLikeType">; +def OpenMP_PointerLikeType : TypeAlias; //===----------------------------------------------------------------------===// // 2.6 parallel Construct diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPTypeInterfaces.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPTypeInterfaces.td new file mode 100644 index 0000000..1075a8b --- /dev/null +++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPTypeInterfaces.td @@ -0,0 +1,31 @@ +//===-- OpenMPTypeInterfaces.td - OpenMP 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 +// +//===----------------------------------------------------------------------===// + +#ifndef OPENMP_TYPE_INTERFACES +#define OPENMP_TYPE_INTERFACES + +include "mlir/IR/OpBase.td" + +def OpenMP_PointerLikeTypeInterface : TypeInterface<"PointerLikeType"> { + let cppNamespace = "::mlir::omp"; + + let description = [{ + An interface for pointer-like types suitable to contain a value that OpenMP + specification refers to as variable. + }]; + + let methods = [ + InterfaceMethod< + /*description=*/"Returns the pointee type.", + /*retTy=*/"::mlir::Type", + /*methodName=*/"getElementType" + >, + ]; +} + +#endif // OPENMP_TYPE_INTERFACES diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td index 1617445..cd581fc 100644 --- a/mlir/include/mlir/IR/OpBase.td +++ b/mlir/include/mlir/IR/OpBase.td @@ -274,7 +274,7 @@ class Type : - Type { + Type { let description = t.description; let builderCall = t.builderCall; } diff --git a/mlir/lib/Dialect/OpenMP/CMakeLists.txt b/mlir/lib/Dialect/OpenMP/CMakeLists.txt index 5eb0ce8..20463c3 100644 --- a/mlir/lib/Dialect/OpenMP/CMakeLists.txt +++ b/mlir/lib/Dialect/OpenMP/CMakeLists.txt @@ -7,6 +7,7 @@ add_mlir_dialect_library(MLIROpenMPDialect DEPENDS MLIROpenMPOpsIncGen MLIROpenMPOpsInterfacesIncGen + MLIROpenMPTypeInterfacesIncGen LINK_LIBS PUBLIC MLIRIR -- 2.7.4