ops.mlir
2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// RUN: mlir-opt -split-input-file %s | mlir-opt
// Verify the generic form can be parsed.
// RUN: mlir-opt -split-input-file -mlir-print-op-generic %s | mlir-opt
// -----
pdl.pattern @operations : benefit(1) {
// Operation with attributes and results.
%attribute = pdl.attribute
%type = pdl.type
%op0, %op0_result = pdl.operation {"attr" = %attribute} -> %type
// Operation with input.
%input = pdl.input
%root = pdl.operation(%op0_result, %input)
pdl.rewrite %root with "rewriter"
}
// -----
pdl.pattern @rewrite_with_args : benefit(1) {
%input = pdl.input
%root = pdl.operation(%input)
pdl.rewrite %root with "rewriter"(%input : !pdl.value)
}
// -----
pdl.pattern @rewrite_with_params : benefit(1) {
%root = pdl.operation
pdl.rewrite %root with "rewriter"["I am param"]
}
// -----
pdl.pattern @rewrite_with_args_and_params : benefit(1) {
%input = pdl.input
%root = pdl.operation(%input)
pdl.rewrite %root with "rewriter"["I am param"](%input : !pdl.value)
}
// -----
// Check that the result type of an operation within a rewrite can be inferred
// from a pdl.replace.
pdl.pattern @infer_type_from_operation_replace : benefit(1) {
%type1 = pdl.type : i32
%type2 = pdl.type
%root, %results:2 = pdl.operation -> %type1, %type2
pdl.rewrite %root {
%type3 = pdl.type
%newOp, %newResults:2 = pdl.operation "foo.op" -> %type1, %type3
pdl.replace %root with %newOp
}
}
// -----
// Check that the result type of an operation within a rewrite can be inferred
// from a pdl.replace.
pdl.pattern @infer_type_from_result_replace : benefit(1) {
%type1 = pdl.type : i32
%type2 = pdl.type
%root, %results:2 = pdl.operation -> %type1, %type2
pdl.rewrite %root {
%type3 = pdl.type
%newOp, %newResults:2 = pdl.operation "foo.op" -> %type1, %type3
pdl.replace %root with (%newResults#0, %newResults#1)
}
}
// -----
// Check that the result type of an operation within a rewrite can be inferred
// from a pdl.replace.
pdl.pattern @infer_type_from_type_used_in_match : benefit(1) {
%type1 = pdl.type : i32
%type2 = pdl.type
%root, %results:2 = pdl.operation -> %type1, %type2
pdl.rewrite %root {
%newOp, %newResults:2 = pdl.operation "foo.op" -> %type1, %type2
}
}