-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missed translation of ternary operator (aka IR::Mux)
Signed-off-by: Anton Korobeynikov <[email protected]>
- Loading branch information
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// RUN: p4mlir-translate --typeinference-only %s | FileCheck %s | ||
|
||
// Adopted from testdata/p4_16_samples/pred.p4 | ||
// CHECK-LABEL: p4hir.func action @cond_0(%arg0: !p4hir.bool {p4hir.dir = #p4hir<dir undir>}) | ||
// CHECK: %[[TMP_1:.*]] = p4hir.alloca !p4hir.bool ["tmp_1"] : !p4hir.ref<!p4hir.bool> | ||
// CHECK: %[[TMP_2:.*]] = p4hir.alloca !p4hir.bool ["tmp_2"] : !p4hir.ref<!p4hir.bool> | ||
// CHECK: %[[NB:.*]] = p4hir.unary(not, %arg0) : !p4hir.bool | ||
// CHECK: %[[MUX:.*]] = p4hir.ternary(%[[NB]], true { | ||
// CHECK: %[[TMP_2_VAL:.*]] = p4hir.load %[[TMP_2]] : !p4hir.ref<!p4hir.bool>, !p4hir.bool | ||
// CHECK: p4hir.yield %[[TMP_2_VAL]] : !p4hir.bool | ||
// CHECK: }, false { | ||
// CHECK: %[[TMP_1_VAL:.*]] = p4hir.load %[[TMP_1]] : !p4hir.ref<!p4hir.bool>, !p4hir.bool | ||
// CHECK: p4hir.yield %[[TMP_1_VAL]] : !p4hir.bool | ||
// CHECK: }) : (!p4hir.bool) -> !p4hir.bool | ||
// CHECK: p4hir.store %[[MUX]], %[[TMP_1]] : !p4hir.bool, !p4hir.ref<!p4hir.bool> | ||
|
||
action cond_0(bool in_b) { | ||
bit<32> a; | ||
bool tmp_1; | ||
bool tmp_2; | ||
|
||
tmp_1 = (!in_b ? tmp_2 : tmp_1); | ||
tmp_2 = (!in_b && !!in_b ? a == 32w5 : tmp_2); | ||
tmp_1 = (!in_b && !!in_b ? (!in_b && !!in_b ? a == 32w5 : tmp_2) : (!in_b && !in_b ? false : tmp_1)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters