xref: /llvm-project/mlir/test/IR/print-value-users.mlir (revision 0a1569a400491e264060b8a6ff7b7f64e1865496)
1// RUN: mlir-opt -allow-unregistered-dialect -mlir-print-value-users -split-input-file %s | FileCheck %s
2
3module {
4    // CHECK: %[[ARG0:.+]]: i32, %[[ARG1:.+]]: i32, %[[ARG2:.+]]: i32
5    func.func @foo(%arg0: i32, %arg1: i32, %arg3: i32) -> i32 {
6        // CHECK-NEXT: // %[[ARG0]] is used by %[[ARG0U1:.+]], %[[ARG0U2:.+]], %[[ARG0U3:.+]]
7        // CHECK-NEXT: // %[[ARG1]] is used by %[[ARG1U1:.+]], %[[ARG1U2:.+]]
8        // CHECK-NEXT: // %[[ARG2]] is unused
9        // CHECK-NEXT: test.noop
10        // CHECK-NOT: // unused
11        "test.noop"() : () -> ()
12        // When no result is produced, an id should be printed.
13        // CHECK-NEXT: // id: %[[ARG0U3]]
14        "test.no_result"(%arg0) {} : (i32) -> ()
15        // Check for unused result.
16        // CHECK-NEXT: %[[ARG0U2]] =
17        // CHECK-SAME: // unused
18        %1 = "test.unused_result"(%arg0, %arg1) {} : (i32, i32) -> i32
19        // Check that both users are printed.
20        // CHECK-NEXT: %[[ARG0U1]] =
21        // CHECK-SAME: // users: %[[A:.+]]#0, %[[A]]#1
22        %2 = "test.one_result"(%arg0, %arg1) {} : (i32, i32) -> i32
23        // For multiple results, users should be grouped per result.
24        // CHECK-NEXT: %[[A]]:2 =
25        // CHECK-SAME: // users: (%[[B:.+]], %[[C:.+]]), (%[[B]], %[[D:.+]])
26        %3:2 = "test.many_results"(%2) {} : (i32) -> (i32, i32)
27        // Two results are produced, but there is only one user.
28        // CHECK-NEXT: // users:
29        %7:2 = "test.many_results"() : () -> (i32, i32)
30        // CHECK-NEXT: %[[C]] =
31        // Result is used twice in next operation but it produces only one result.
32        // CHECK-SAME: // user:
33        %4 = "test.foo"(%3#0) {} : (i32) -> i32
34        // CHECK-NEXT: %[[D]] =
35        %5 = "test.foo"(%3#1, %4, %4) {} : (i32, i32, i32) -> i32
36        // CHECK-NEXT: %[[B]] =
37        // Result is not used in any other result but in two operations.
38        // CHECK-SAME: // users:
39        %6 = "test.foo"(%3#0, %3#1) {} : (i32, i32) -> i32
40        "test.no_result"(%6) {} : (i32) -> ()
41        "test.no_result"(%7#0) : (i32) -> ()
42        return %6: i32
43    }
44}
45
46// -----
47
48module {
49    // Check with nested operation.
50    // CHECK: %[[CONSTNAME:.+]] = arith.constant
51    %0 = arith.constant 42 : i32
52    %test = "test.outerop"(%0) ({
53        // CHECK: "test.innerop"(%[[CONSTNAME]]) : (i32) -> () // id: %
54        "test.innerop"(%0) : (i32) -> ()
55    // CHECK: (i32) -> i32 // users: %r, %s, %p, %p_0, %q
56    }): (i32) -> i32
57
58    // Check named results.
59    // CHECK-NEXT: // users: (%u, %v), (unused), (%u, %v, %r, %s)
60    %p:2, %q = "test.custom_result_name"(%test) {names = ["p", "p", "q"]} : (i32) -> (i32, i32, i32)
61    // CHECK-NEXT: // users: (unused), (%u, %v)
62    %r, %s = "test.custom_result_name"(%q#0, %q#0, %test) {names = ["r", "s"]} : (i32, i32, i32) -> (i32, i32)
63    // CHECK-NEXT: // unused
64    %u, %v = "test.custom_result_name"(%s, %q#0, %p) {names = ["u", "v"]} : (i32, i32, i32) -> (i32, i32)
65}
66