1//===-- SubElementInterfaces.td - Sub-Element Interfaces ---*- tablegen -*-===// 2// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6// 7//===----------------------------------------------------------------------===// 8// 9// This file contains a set of interfaces that can be used to interface with 10// sub-elements, e.g. held attributes and types, of a composite attribute or 11// type. 12// 13//===----------------------------------------------------------------------===// 14 15#ifndef MLIR_IR_SUBELEMENTINTERFACES_TD_ 16#define MLIR_IR_SUBELEMENTINTERFACES_TD_ 17 18include "mlir/IR/OpBase.td" 19 20//===----------------------------------------------------------------------===// 21// SubElementInterfaceBase 22//===----------------------------------------------------------------------===// 23 24class SubElementInterfaceBase<string interfaceName, string derivedValue> { 25 string cppNamespace = "::mlir"; 26 27 list<InterfaceMethod> methods = [ 28 InterfaceMethod< 29 /*desc=*/[{ 30 Walk all of the immediately nested sub-attributes and sub-types. This 31 method does not recurse into sub elements. 32 }], "void", "walkImmediateSubElements", 33 (ins "llvm::function_ref<void(mlir::Attribute)>":$walkAttrsFn, 34 "llvm::function_ref<void(mlir::Type)>":$walkTypesFn) 35 >, 36 ]; 37 38 code extraClassDeclaration = [{ 39 /// Walk all of the held sub-attributes. 40 void walkSubAttrs(llvm::function_ref<void(mlir::Attribute)> walkFn) { 41 walkSubElements(walkFn, /*walkTypesFn=*/[](mlir::Type) {}); 42 } 43 44 /// Walk all of the held sub-types. 45 void walkSubTypes(llvm::function_ref<void(mlir::Type)> walkFn) { 46 walkSubElements(/*walkAttrsFn=*/[](mlir::Attribute) {}, walkFn); 47 } 48 49 /// Walk all of the held sub-attributes and sub-types. 50 void walkSubElements(llvm::function_ref<void(mlir::Attribute)> walkAttrsFn, 51 llvm::function_ref<void(mlir::Type)> walkTypesFn); 52 }]; 53 54 code extraTraitClassDeclaration = [{ 55 /// Walk all of the held sub-attributes. 56 void walkSubAttrs(llvm::function_ref<void(mlir::Attribute)> walkFn) { 57 walkSubElements(walkFn, /*walkTypesFn=*/[](mlir::Type) {}); 58 } 59 60 /// Walk all of the held sub-types. 61 void walkSubTypes(llvm::function_ref<void(mlir::Type)> walkFn) { 62 walkSubElements(/*walkAttrsFn=*/[](mlir::Attribute) {}, walkFn); 63 } 64 65 /// Walk all of the held sub-attributes and sub-types. 66 void walkSubElements(llvm::function_ref<void(mlir::Attribute)> walkAttrsFn, 67 llvm::function_ref<void(mlir::Type)> walkTypesFn) { 68 }] # interfaceName # " interface(" # derivedValue # [{); 69 interface.walkSubElements(walkAttrsFn, walkTypesFn); 70 } 71 }]; 72} 73 74//===----------------------------------------------------------------------===// 75// SubElementAttrInterface 76//===----------------------------------------------------------------------===// 77 78def SubElementAttrInterface 79 : AttrInterface<"SubElementAttrInterface">, 80 SubElementInterfaceBase<"SubElementAttrInterface", "$_attr"> { 81 let description = [{ 82 An interface used to query and manipulate sub-elements, such as sub-types 83 and sub-attributes of a composite attribute. 84 }]; 85} 86 87//===----------------------------------------------------------------------===// 88// SubElementTypeInterface 89//===----------------------------------------------------------------------===// 90 91def SubElementTypeInterface 92 : TypeInterface<"SubElementTypeInterface">, 93 SubElementInterfaceBase<"SubElementTypeInterface", "$_type"> { 94 let description = [{ 95 An interface used to query and manipulate sub-elements, such as sub-types 96 and sub-attributes of a composite type. 97 }]; 98} 99 100#endif // MLIR_IR_SUBELEMENTINTERFACES_TD_ 101