1//===-- TestInterfaces.td - Test dialect 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#ifndef MLIR_TEST_DIALECT_TEST_INTERFACES 10#define MLIR_TEST_DIALECT_TEST_INTERFACES 11 12include "mlir/IR/OpBase.td" 13include "mlir/Interfaces/SideEffectInterfaceBase.td" 14 15// A type interface used to test the ODS generation of type interfaces. 16def TestTypeInterface : TypeInterface<"TestTypeInterface"> { 17 let methods = [ 18 InterfaceMethod<"Prints the type name.", 19 "void", "printTypeA", (ins "Location":$loc), [{ 20 emitRemark(loc) << $_type << " - TestA"; 21 }] 22 >, 23 InterfaceMethod<"Prints the type name.", 24 "void", "printTypeB", (ins "Location":$loc), 25 [{}], /*defaultImplementation=*/[{ 26 emitRemark(loc) << $_type << " - TestB"; 27 }] 28 >, 29 InterfaceMethod<"Prints the type name.", 30 "void", "printTypeC", (ins "Location":$loc) 31 >, 32 // It should be possible to use the interface type name as result type 33 // as well as in the implementation. 34 InterfaceMethod<"Prints the type name and returns the type as interface.", 35 "TestTypeInterface", "printTypeRet", (ins "Location":$loc), 36 [{}], /*defaultImplementation=*/[{ 37 emitRemark(loc) << $_type << " - TestRet"; 38 return $_type; 39 }] 40 >, 41 ]; 42 let extraClassDeclaration = [{ 43 /// Prints the type name. 44 void printTypeD(Location loc) const { 45 emitRemark(loc) << *this << " - TestD"; 46 } 47 }]; 48 let extraTraitClassDeclaration = [{ 49 /// Prints the type name. 50 void printTypeE(Location loc) const { 51 emitRemark(loc) << $_type << " - TestE"; 52 } 53 }]; 54} 55 56def TestEffectOpInterface 57 : EffectOpInterfaceBase<"TestEffectOpInterface", 58 "::mlir::TestEffects::Effect"> { 59 let cppNamespace = "::mlir"; 60} 61 62class TestEffect<string effectName> 63 : SideEffect<TestEffectOpInterface, effectName, DefaultResource>; 64 65class TestEffects<list<TestEffect> effects = []> 66 : SideEffectsTraitBase<TestEffectOpInterface, effects>; 67 68def TestConcreteEffect : TestEffect<"TestEffects::Concrete">; 69 70#endif // MLIR_TEST_DIALECT_TEST_INTERFACES 71