llvm-project/mlir/test/mlir-tblgen/testdialect-attrdefs.mlir
Jeff Niu 7fe2294e47 [mlir][ods] Allow specifying return types of builders
This patch allows custom attribute and type builders to return
something other than the C++ type of the attribute or type.

This is useful for attributes or types that may perform extra work during
construction (e.g. canonicalization) that could result in a different
kind of attribute or type being returned.

Reviewed By: rriddle, lattner

Differential Revision: https://reviews.llvm.org/D129792
2022-07-15 18:00:35 -07:00

22 lines
1.0 KiB
MLIR

// RUN: mlir-opt %s | mlir-opt -verify-diagnostics | FileCheck %s
// CHECK-LABEL: func private @compoundA()
// CHECK-SAME: #test.cmpnd_a<1, !test.smpla, [5, 6]>
func.func private @compoundA() attributes {foo = #test.cmpnd_a<1, !test.smpla, [5, 6]>}
// CHECK: test.result_has_same_type_as_attr #test.attr_with_self_type_param : i32 -> i32
%a = test.result_has_same_type_as_attr #test.attr_with_self_type_param : i32 -> i32
// CHECK: test.result_has_same_type_as_attr #test<attr_with_type_builder 10 : i16> : i16 -> i16
%b = test.result_has_same_type_as_attr #test<attr_with_type_builder 10 : i16> -> i16
// CHECK-LABEL: @qualifiedAttr()
// CHECK-SAME: #test.cmpnd_nested_outer_qual<i #test.cmpnd_nested_inner<42 <1, !test.smpla, [5, 6]>>>
func.func private @qualifiedAttr() attributes {foo = #test.cmpnd_nested_outer_qual<i #test.cmpnd_nested_inner<42 <1, !test.smpla, [5, 6]>>>}
// CHECK-LABEL: @overriddenAttr
// CHECK-SAME: foo = 5 : index
func.func private @overriddenAttr() attributes {
foo = #test.override_builder<5>
}