Do not run `cf-to-llvm` as part of `func-to-llvm`. This commit fixes https://github.com/llvm/llvm-project/issues/70982. This commit changes the way how `func.func` ops are lowered to LLVM. Previously, the signature of the entire region (i.e., entry block and all other blocks in the `func.func` op) was converted as part of the `func.func` lowering pattern. Now, only the entry block is converted. The remaining block signatures are converted together with `cf.br` and `cf.cond_br` as part of `cf-to-llvm`. All unstructured control flow is not converted as part of a single pass (`cf-to-llvm`). `func-to-llvm` no longer deals with unstructured control flow. Also add more test cases for control flow dialect ops. Note: This PR is in preparation of #120431, which adds an additional GPU-specific lowering for `cf.assert`. This was a problem because `cf.assert` used to be converted as part of `func-to-llvm`. Note for LLVM integration: If you see failures, add `-convert-cf-to-llvm` to your pass pipeline.
70 lines
2.2 KiB
MLIR
70 lines
2.2 KiB
MLIR
// RUN: mlir-opt %s -convert-cf-to-llvm -split-input-file | FileCheck %s
|
|
|
|
// Unstructured control flow is converted, but the enclosing op is not
|
|
// converted.
|
|
|
|
// CHECK-LABEL: func.func @cf_br(
|
|
// CHECK-SAME: %[[arg0:.*]]: index) -> index {
|
|
// CHECK: %[[cast0:.*]] = builtin.unrealized_conversion_cast %[[arg0]] : index to i64
|
|
// CHECK: llvm.br ^[[bb1:.*]](%[[cast0]] : i64)
|
|
// CHECK: ^[[bb1]](%[[arg1:.*]]: i64):
|
|
// CHECK: %[[cast1:.*]] = builtin.unrealized_conversion_cast %[[arg1]] : i64 to index
|
|
// CHECK: return %[[cast1]] : index
|
|
// CHECK: }
|
|
func.func @cf_br(%arg0: index) -> index {
|
|
cf.br ^bb1(%arg0 : index)
|
|
^bb1(%arg1: index):
|
|
return %arg1 : index
|
|
}
|
|
|
|
// -----
|
|
|
|
// func.func and func.return types match. No unrealized_conversion_cast is
|
|
// needed.
|
|
|
|
// CHECK-LABEL: func.func @cf_br_type_match(
|
|
// CHECK-SAME: %[[arg0:.*]]: i64) -> i64 {
|
|
// CHECK: llvm.br ^[[bb1:.*]](%[[arg0:.*]] : i64)
|
|
// CHECK: ^[[bb1]](%[[arg1:.*]]: i64):
|
|
// CHECK: return %[[arg1]] : i64
|
|
// CHECK: }
|
|
func.func @cf_br_type_match(%arg0: i64) -> i64 {
|
|
cf.br ^bb1(%arg0 : i64)
|
|
^bb1(%arg1: i64):
|
|
return %arg1 : i64
|
|
}
|
|
|
|
// -----
|
|
|
|
// Test case for cf.cond_br.
|
|
|
|
// CHECK-LABEL: func.func @cf_cond_br
|
|
// CHECK-COUNT-2: unrealized_conversion_cast {{.*}} : index to i64
|
|
// CHECK: llvm.cond_br %{{.*}}, ^{{.*}}(%{{.*}} : i64), ^{{.*}}(%{{.*}} : i64)
|
|
// CHECK: ^{{.*}}(%{{.*}}: i64):
|
|
// CHECK: unrealized_conversion_cast {{.*}} : i64 to index
|
|
// CHECK: ^{{.*}}(%{{.*}}: i64):
|
|
// CHECK: unrealized_conversion_cast {{.*}} : i64 to index
|
|
func.func @cf_cond_br(%cond: i1, %a: index, %b: index) -> index {
|
|
cf.cond_br %cond, ^bb1(%a : index), ^bb2(%b : index)
|
|
^bb1(%arg1: index):
|
|
return %arg1 : index
|
|
^bb2(%arg2: index):
|
|
return %arg2 : index
|
|
}
|
|
|
|
// -----
|
|
|
|
// Unreachable block (and IR in general) is not converted during a dialect
|
|
// conversion.
|
|
|
|
// CHECK-LABEL: func.func @unreachable_block()
|
|
// CHECK: return
|
|
// CHECK: ^[[bb1:.*]](%[[arg0:.*]]: index):
|
|
// CHECK: cf.br ^[[bb1]](%[[arg0]] : index)
|
|
func.func @unreachable_block() {
|
|
return
|
|
^bb1(%arg0: index):
|
|
cf.br ^bb1(%arg0 : index)
|
|
}
|