xref: /llvm-project/mlir/test/IR/print-value-users.mlir (revision 0a1569a400491e264060b8a6ff7b7f64e1865496)
13e8560f8Scpillmayer// RUN: mlir-opt -allow-unregistered-dialect -mlir-print-value-users -split-input-file %s | FileCheck %s
23e8560f8Scpillmayer
33e8560f8Scpillmayermodule {
43e8560f8Scpillmayer    // CHECK: %[[ARG0:.+]]: i32, %[[ARG1:.+]]: i32, %[[ARG2:.+]]: i32
5*a8308020SRiver Riddle    func.func @foo(%arg0: i32, %arg1: i32, %arg3: i32) -> i32 {
63e8560f8Scpillmayer        // CHECK-NEXT: // %[[ARG0]] is used by %[[ARG0U1:.+]], %[[ARG0U2:.+]], %[[ARG0U3:.+]]
73e8560f8Scpillmayer        // CHECK-NEXT: // %[[ARG1]] is used by %[[ARG1U1:.+]], %[[ARG1U2:.+]]
83e8560f8Scpillmayer        // CHECK-NEXT: // %[[ARG2]] is unused
93e8560f8Scpillmayer        // CHECK-NEXT: test.noop
103e8560f8Scpillmayer        // CHECK-NOT: // unused
113e8560f8Scpillmayer        "test.noop"() : () -> ()
123e8560f8Scpillmayer        // When no result is produced, an id should be printed.
133e8560f8Scpillmayer        // CHECK-NEXT: // id: %[[ARG0U3]]
143e8560f8Scpillmayer        "test.no_result"(%arg0) {} : (i32) -> ()
153e8560f8Scpillmayer        // Check for unused result.
163e8560f8Scpillmayer        // CHECK-NEXT: %[[ARG0U2]] =
173e8560f8Scpillmayer        // CHECK-SAME: // unused
183e8560f8Scpillmayer        %1 = "test.unused_result"(%arg0, %arg1) {} : (i32, i32) -> i32
193e8560f8Scpillmayer        // Check that both users are printed.
203e8560f8Scpillmayer        // CHECK-NEXT: %[[ARG0U1]] =
213e8560f8Scpillmayer        // CHECK-SAME: // users: %[[A:.+]]#0, %[[A]]#1
223e8560f8Scpillmayer        %2 = "test.one_result"(%arg0, %arg1) {} : (i32, i32) -> i32
233e8560f8Scpillmayer        // For multiple results, users should be grouped per result.
243e8560f8Scpillmayer        // CHECK-NEXT: %[[A]]:2 =
253e8560f8Scpillmayer        // CHECK-SAME: // users: (%[[B:.+]], %[[C:.+]]), (%[[B]], %[[D:.+]])
263e8560f8Scpillmayer        %3:2 = "test.many_results"(%2) {} : (i32) -> (i32, i32)
273e8560f8Scpillmayer        // Two results are produced, but there is only one user.
283e8560f8Scpillmayer        // CHECK-NEXT: // users:
293e8560f8Scpillmayer        %7:2 = "test.many_results"() : () -> (i32, i32)
303e8560f8Scpillmayer        // CHECK-NEXT: %[[C]] =
313e8560f8Scpillmayer        // Result is used twice in next operation but it produces only one result.
323e8560f8Scpillmayer        // CHECK-SAME: // user:
333e8560f8Scpillmayer        %4 = "test.foo"(%3#0) {} : (i32) -> i32
343e8560f8Scpillmayer        // CHECK-NEXT: %[[D]] =
353e8560f8Scpillmayer        %5 = "test.foo"(%3#1, %4, %4) {} : (i32, i32, i32) -> i32
363e8560f8Scpillmayer        // CHECK-NEXT: %[[B]] =
373e8560f8Scpillmayer        // Result is not used in any other result but in two operations.
383e8560f8Scpillmayer        // CHECK-SAME: // users:
393e8560f8Scpillmayer        %6 = "test.foo"(%3#0, %3#1) {} : (i32, i32) -> i32
403e8560f8Scpillmayer        "test.no_result"(%6) {} : (i32) -> ()
413e8560f8Scpillmayer        "test.no_result"(%7#0) : (i32) -> ()
423e8560f8Scpillmayer        return %6: i32
433e8560f8Scpillmayer    }
443e8560f8Scpillmayer}
453e8560f8Scpillmayer
463e8560f8Scpillmayer// -----
473e8560f8Scpillmayer
483e8560f8Scpillmayermodule {
493e8560f8Scpillmayer    // Check with nested operation.
503e8560f8Scpillmayer    // CHECK: %[[CONSTNAME:.+]] = arith.constant
513e8560f8Scpillmayer    %0 = arith.constant 42 : i32
523e8560f8Scpillmayer    %test = "test.outerop"(%0) ({
533e8560f8Scpillmayer        // CHECK: "test.innerop"(%[[CONSTNAME]]) : (i32) -> () // id: %
543e8560f8Scpillmayer        "test.innerop"(%0) : (i32) -> ()
553e8560f8Scpillmayer    // CHECK: (i32) -> i32 // users: %r, %s, %p, %p_0, %q
563e8560f8Scpillmayer    }): (i32) -> i32
573e8560f8Scpillmayer
583e8560f8Scpillmayer    // Check named results.
593e8560f8Scpillmayer    // CHECK-NEXT: // users: (%u, %v), (unused), (%u, %v, %r, %s)
603e8560f8Scpillmayer    %p:2, %q = "test.custom_result_name"(%test) {names = ["p", "p", "q"]} : (i32) -> (i32, i32, i32)
613e8560f8Scpillmayer    // CHECK-NEXT: // users: (unused), (%u, %v)
623e8560f8Scpillmayer    %r, %s = "test.custom_result_name"(%q#0, %q#0, %test) {names = ["r", "s"]} : (i32, i32, i32) -> (i32, i32)
633e8560f8Scpillmayer    // CHECK-NEXT: // unused
643e8560f8Scpillmayer    %u, %v = "test.custom_result_name"(%s, %q#0, %p) {names = ["u", "v"]} : (i32, i32, i32) -> (i32, i32)
653e8560f8Scpillmayer}
66