From b2bdb0ba0f6d331844c1b9dcccd522472c7188c9 Mon Sep 17 00:00:00 2001 From: River Riddle Date: Fri, 16 Dec 2022 02:33:53 -0800 Subject: [PATCH] [mlir] Make FunctionOpInterface inherit SymbolOpInterface This lets users of FunctionOpInterface finally have the name/visibility accessors from SymbolOpInterface. This also lets us remove the clunky "getName" method from FunctionOpInterface. Differential Revision: https://reviews.llvm.org/D140199 --- mlir/examples/toy/Ch2/include/toy/Ops.td | 2 +- mlir/examples/toy/Ch3/include/toy/Ops.td | 2 +- mlir/examples/toy/Ch4/include/toy/Ops.td | 2 +- mlir/examples/toy/Ch5/include/toy/Ops.td | 2 +- mlir/examples/toy/Ch6/include/toy/Ops.td | 2 +- mlir/examples/toy/Ch7/include/toy/Ops.td | 2 +- mlir/include/mlir/Dialect/Async/IR/AsyncOps.td | 2 +- mlir/include/mlir/Dialect/Func/IR/FuncOps.td | 2 +- mlir/include/mlir/Dialect/GPU/IR/GPUOps.td | 2 +- mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td | 2 +- mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td | 2 +- mlir/include/mlir/Dialect/SPIRV/IR/SPIRVStructureOps.td | 2 +- mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td | 2 +- mlir/include/mlir/IR/FunctionInterfaces.td | 12 ++---------- mlir/test/Dialect/Func/invalid.mlir | 4 ++-- 15 files changed, 17 insertions(+), 25 deletions(-) diff --git a/mlir/examples/toy/Ch2/include/toy/Ops.td b/mlir/examples/toy/Ch2/include/toy/Ops.td index 08514d4..ffe56e2 100644 --- a/mlir/examples/toy/Ch2/include/toy/Ops.td +++ b/mlir/examples/toy/Ch2/include/toy/Ops.td @@ -114,7 +114,7 @@ def AddOp : Toy_Op<"add"> { //===----------------------------------------------------------------------===// def FuncOp : Toy_Op<"func", [ - FunctionOpInterface, IsolatedFromAbove, Symbol + FunctionOpInterface, IsolatedFromAbove ]> { let summary = "user defined function operation"; let description = [{ diff --git a/mlir/examples/toy/Ch3/include/toy/Ops.td b/mlir/examples/toy/Ch3/include/toy/Ops.td index 0836e3c..41536c0 100644 --- a/mlir/examples/toy/Ch3/include/toy/Ops.td +++ b/mlir/examples/toy/Ch3/include/toy/Ops.td @@ -113,7 +113,7 @@ def AddOp : Toy_Op<"add", [Pure]> { //===----------------------------------------------------------------------===// def FuncOp : Toy_Op<"func", [ - FunctionOpInterface, IsolatedFromAbove, Symbol + FunctionOpInterface, IsolatedFromAbove ]> { let summary = "user defined function operation"; let description = [{ diff --git a/mlir/examples/toy/Ch4/include/toy/Ops.td b/mlir/examples/toy/Ch4/include/toy/Ops.td index dcf9996..a91786f 100644 --- a/mlir/examples/toy/Ch4/include/toy/Ops.td +++ b/mlir/examples/toy/Ch4/include/toy/Ops.td @@ -143,7 +143,7 @@ def CastOp : Toy_Op<"cast", [ def FuncOp : Toy_Op<"func", [ DeclareOpInterfaceMethods, FunctionOpInterface, - IsolatedFromAbove, Symbol + IsolatedFromAbove ]> { let summary = "user defined function operation"; let description = [{ diff --git a/mlir/examples/toy/Ch5/include/toy/Ops.td b/mlir/examples/toy/Ch5/include/toy/Ops.td index d6675b7..5cf677d 100644 --- a/mlir/examples/toy/Ch5/include/toy/Ops.td +++ b/mlir/examples/toy/Ch5/include/toy/Ops.td @@ -143,7 +143,7 @@ def CastOp : Toy_Op<"cast", [ def FuncOp : Toy_Op<"func", [ DeclareOpInterfaceMethods, FunctionOpInterface, - IsolatedFromAbove, Symbol + IsolatedFromAbove ]> { let summary = "user defined function operation"; let description = [{ diff --git a/mlir/examples/toy/Ch6/include/toy/Ops.td b/mlir/examples/toy/Ch6/include/toy/Ops.td index 2229cde..e15bcb9 100644 --- a/mlir/examples/toy/Ch6/include/toy/Ops.td +++ b/mlir/examples/toy/Ch6/include/toy/Ops.td @@ -143,7 +143,7 @@ def CastOp : Toy_Op<"cast", [ def FuncOp : Toy_Op<"func", [ DeclareOpInterfaceMethods, FunctionOpInterface, - IsolatedFromAbove, Symbol + IsolatedFromAbove ]> { let summary = "user defined function operation"; let description = [{ diff --git a/mlir/examples/toy/Ch7/include/toy/Ops.td b/mlir/examples/toy/Ch7/include/toy/Ops.td index 504d316..04d6e31 100644 --- a/mlir/examples/toy/Ch7/include/toy/Ops.td +++ b/mlir/examples/toy/Ch7/include/toy/Ops.td @@ -167,7 +167,7 @@ def CastOp : Toy_Op<"cast", [ def FuncOp : Toy_Op<"func", [ DeclareOpInterfaceMethods, FunctionOpInterface, - IsolatedFromAbove, Symbol + IsolatedFromAbove ]> { let summary = "user defined function operation"; let description = [{ diff --git a/mlir/include/mlir/Dialect/Async/IR/AsyncOps.td b/mlir/include/mlir/Dialect/Async/IR/AsyncOps.td index 9db2167..2cf5ee8 100644 --- a/mlir/include/mlir/Dialect/Async/IR/AsyncOps.td +++ b/mlir/include/mlir/Dialect/Async/IR/AsyncOps.td @@ -106,7 +106,7 @@ def Async_ExecuteOp : def Async_FuncOp : Async_Op<"func", [CallableOpInterface, FunctionOpInterface, - IsolatedFromAbove, OpAsmOpInterface, Symbol]> { + IsolatedFromAbove, OpAsmOpInterface]> { let summary = "async function operation"; let description = [{ An async function is like a normal function, but supports non-blocking diff --git a/mlir/include/mlir/Dialect/Func/IR/FuncOps.td b/mlir/include/mlir/Dialect/Func/IR/FuncOps.td index 50c01cf..8804c31 100644 --- a/mlir/include/mlir/Dialect/Func/IR/FuncOps.td +++ b/mlir/include/mlir/Dialect/Func/IR/FuncOps.td @@ -209,7 +209,7 @@ def ConstantOp : Func_Op<"constant", def FuncOp : Func_Op<"func", [ AffineScope, AutomaticAllocationScope, CallableOpInterface, - FunctionOpInterface, IsolatedFromAbove, OpAsmOpInterface, Symbol + FunctionOpInterface, IsolatedFromAbove, OpAsmOpInterface ]> { let summary = "An operation with a name containing a single `SSACFG` region"; let description = [{ diff --git a/mlir/include/mlir/Dialect/GPU/IR/GPUOps.td b/mlir/include/mlir/Dialect/GPU/IR/GPUOps.td index 650ebe4..498117e 100644 --- a/mlir/include/mlir/Dialect/GPU/IR/GPUOps.td +++ b/mlir/include/mlir/Dialect/GPU/IR/GPUOps.td @@ -180,7 +180,7 @@ def GPU_SubgroupSizeOp : GPU_Op<"subgroup_size", [ def GPU_GPUFuncOp : GPU_Op<"func", [ HasParent<"GPUModuleOp">, AutomaticAllocationScope, FunctionOpInterface, - IsolatedFromAbove, Symbol + IsolatedFromAbove ]> { let summary = "Function executable on a GPU"; diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td index e01c6bb..a97073e 100644 --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td @@ -1443,7 +1443,7 @@ def LLVM_GlobalDtorsOp : LLVM_Op<"mlir.global_dtors", [ def LLVM_LLVMFuncOp : LLVM_Op<"func", [ AutomaticAllocationScope, IsolatedFromAbove, FunctionOpInterface, - CallableOpInterface, Symbol + CallableOpInterface ]> { let summary = "LLVM dialect function."; diff --git a/mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td b/mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td index af6fcb9..9734e1d 100644 --- a/mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td +++ b/mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td @@ -631,7 +631,7 @@ def PDLInterp_ForEachOp //===----------------------------------------------------------------------===// def PDLInterp_FuncOp : PDLInterp_Op<"func", [ - FunctionOpInterface, IsolatedFromAbove, Symbol + FunctionOpInterface, IsolatedFromAbove ]> { let summary = "PDL Interpreter Function Operation"; let description = [{ diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVStructureOps.td b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVStructureOps.td index 8c432b2..78944e8 100644 --- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVStructureOps.td +++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVStructureOps.td @@ -257,7 +257,7 @@ def SPIRV_ExecutionModeOp : SPIRV_Op<"ExecutionMode", [InModuleScope]> { def SPIRV_FuncOp : SPIRV_Op<"func", [ AutomaticAllocationScope, DeclareOpInterfaceMethods, - FunctionOpInterface, InModuleScope, IsolatedFromAbove, Symbol + FunctionOpInterface, InModuleScope, IsolatedFromAbove ]> { let summary = "Declare or define a function"; diff --git a/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td b/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td index b8a3fb7..ae84b07 100644 --- a/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td +++ b/mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td @@ -1103,7 +1103,7 @@ def Shape_FunctionLibraryOp : Shape_Op<"function_library", def Shape_FuncOp : Shape_Op<"func", [AffineScope, AutomaticAllocationScope, CallableOpInterface, - FunctionOpInterface, IsolatedFromAbove, OpAsmOpInterface, Symbol]> { + FunctionOpInterface, IsolatedFromAbove, OpAsmOpInterface]> { let summary = "Shape function"; let description = [{ An operation with a name containing a single `SSACFG` region which diff --git a/mlir/include/mlir/IR/FunctionInterfaces.td b/mlir/include/mlir/IR/FunctionInterfaces.td index 0e8a3ad..c30454a 100644 --- a/mlir/include/mlir/IR/FunctionInterfaces.td +++ b/mlir/include/mlir/IR/FunctionInterfaces.td @@ -14,13 +14,13 @@ #ifndef MLIR_IR_FUNCTIONINTERFACES_TD_ #define MLIR_IR_FUNCTIONINTERFACES_TD_ -include "mlir/IR/OpBase.td" +include "mlir/IR/SymbolInterfaces.td" //===----------------------------------------------------------------------===// // FunctionOpInterface //===----------------------------------------------------------------------===// -def FunctionOpInterface : OpInterface<"FunctionOpInterface"> { +def FunctionOpInterface : OpInterface<"FunctionOpInterface", [Symbol]> { let cppNamespace = "::mlir"; let description = [{ This interfaces provides support for interacting with operations that @@ -164,14 +164,6 @@ def FunctionOpInterface : OpInterface<"FunctionOpInterface"> { }]>, ]; - let extraClassDeclaration = [{ - //===------------------------------------------------------------------===// - // Name - //===------------------------------------------------------------------===// - - /// Return the name of the function. - StringRef getName() { return SymbolTable::getSymbolName(*this); } - }]; let extraTraitClassDeclaration = [{ //===------------------------------------------------------------------===// // Builders diff --git a/mlir/test/Dialect/Func/invalid.mlir b/mlir/test/Dialect/Func/invalid.mlir index 34eda5e..a30aa44 100644 --- a/mlir/test/Dialect/Func/invalid.mlir +++ b/mlir/test/Dialect/Func/invalid.mlir @@ -181,12 +181,12 @@ func.func @$invalid_function_name() // ----- // expected-error @+1 {{arguments may only have dialect attributes}} -func.func @invalid_func_arg_attr(i1 {non_dialect_attr = 10}) +func.func private @invalid_func_arg_attr(i1 {non_dialect_attr = 10}) // ----- // expected-error @+1 {{results may only have dialect attributes}} -func.func @invalid_func_result_attr() -> (i1 {non_dialect_attr = 10}) +func.func private @invalid_func_result_attr() -> (i1 {non_dialect_attr = 10}) // ----- -- 2.7.4