Files
clang-p2996/mlir/test/Dialect/ControlFlow/invalid.mlir
Slava Zakharin 70343c8d44 [mlir][flang] Added Weighted[Region]BranchOpInterface's. (#142079)
The new interfaces provide getters and setters for the weight
information about the branches of BranchOpInterface and
RegionBranchOpInterface operations.

These interfaces are done the same way as LLVM dialect's
BranchWeightOpInterface.

The plan is to produce this information in Flang, e.g. mark
most probably "cold" code as such and allow LLVM to order
basic blocks accordingly. An example of such a code is
copy loops generated for arrays repacking - we can mark it
as "cold" assuming that the copy will not happen dynamically.
If the copy actually happens the overhead of the copy is probably high
enough so that we may not care about the little overhead
of jumping to the "cold" code and fetching it.
2025-06-17 16:14:13 -07:00

106 lines
2.2 KiB
MLIR

// RUN: mlir-opt -verify-diagnostics -split-input-file %s
func.func @switch_missing_case_value(%flag : i32, %caseOperand : i32) {
cf.switch %flag : i32, [
default: ^bb1(%caseOperand : i32),
45: ^bb2(%caseOperand : i32),
// expected-error@+1 {{expected integer value}}
: ^bb3(%caseOperand : i32)
]
^bb1(%bb1arg : i32):
return
^bb2(%bb2arg : i32):
return
^bb3(%bb3arg : i32):
return
}
// -----
func.func @switch_wrong_type_case_value(%flag : i32, %caseOperand : i32) {
cf.switch %flag : i32, [
default: ^bb1(%caseOperand : i32),
// expected-error@+1 {{expected integer value}}
"hello": ^bb2(%caseOperand : i32)
]
^bb1(%bb1arg : i32):
return
^bb2(%bb2arg : i32):
return
^bb3(%bb3arg : i32):
return
}
// -----
func.func @switch_missing_comma(%flag : i32, %caseOperand : i32) {
cf.switch %flag : i32, [
default: ^bb1(%caseOperand : i32),
// expected-error@+1 {{expected ']'}}
45: ^bb2(%caseOperand : i32)
43: ^bb3(%caseOperand : i32)
]
^bb1(%bb1arg : i32):
return
^bb2(%bb2arg : i32):
return
^bb3(%bb3arg : i32):
return
}
// -----
func.func @switch_missing_default(%flag : i32, %caseOperand : i32) {
cf.switch %flag : i32, [
// expected-error@+1 {{expected 'default'}}
45: ^bb2(%caseOperand : i32)
43: ^bb3(%caseOperand : i32)
]
^bb1(%bb1arg : i32):
return
^bb2(%bb2arg : i32):
return
^bb3(%bb3arg : i32):
return
}
// -----
// CHECK-LABEL: func @wrong_weights_number
func.func @wrong_weights_number(%cond: i1) {
// expected-error@+1 {{expects number of branch weights to match number of successors: 1 vs 2}}
cf.cond_br %cond weights([100]), ^bb1, ^bb2
^bb1:
return
^bb2:
return
}
// -----
// CHECK-LABEL: func @negative_weight
func.func @wrong_total_weight(%cond: i1) {
// expected-error@+1 {{weight #0 must be non-negative}}
cf.cond_br %cond weights([-1, 101]), ^bb1, ^bb2
^bb1:
return
^bb2:
return
}
// -----
// CHECK-LABEL: func @zero_weights
func.func @wrong_total_weight(%cond: i1) {
// expected-error@+1 {{branch weights cannot all be zero}}
cf.cond_br %cond weights([0, 0]), ^bb1, ^bb2
^bb1:
return
^bb2:
return
}