-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement lowering of ?? and || via ternary operation
Signed-off-by: Anton Korobeynikov <[email protected]>
- Loading branch information
Showing
5 changed files
with
180 additions
and
2 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
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
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,23 @@ | ||
// RUN: p4mlir-opt %s -o %t.mlir | ||
// RUN: FileCheck --input-file=%t.mlir %s | ||
|
||
module { | ||
// No need to check stuff. If it parses, it's fine. | ||
// CHECK: module | ||
%0 = p4hir.const #p4hir.bool<false> : !p4hir.bool | ||
%1 = p4hir.ternary(%0, true { | ||
%29 = p4hir.const #p4hir.bool<true> : !p4hir.bool | ||
p4hir.yield %29 : !p4hir.bool | ||
}, false { | ||
%29 = p4hir.const #p4hir.bool<false> : !p4hir.bool | ||
p4hir.yield %29 : !p4hir.bool | ||
}) : (!p4hir.bool) -> !p4hir.bool | ||
|
||
%2 = p4hir.ternary(%1, true { | ||
%29 = p4hir.const #p4hir.int<42> : !p4hir.int<32> | ||
p4hir.yield %29 : !p4hir.int<32> | ||
}, false { | ||
%29 = p4hir.const #p4hir.int<100500> : !p4hir.int<32> | ||
p4hir.yield %29 : !p4hir.int<32> | ||
}) : (!p4hir.bool) -> !p4hir.int<32> | ||
} |
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,28 @@ | ||
// RUN: p4mlir-translate --typeinference-only %s | FileCheck %s | ||
|
||
action logical() { | ||
// CHECK-LABEL: module | ||
bool flag1; bool flag2; bool flag3; | ||
|
||
// CHECK: %[[FLAG1:.*]] = p4hir.alloca !p4hir.bool ["flag1"] : !p4hir.ref<!p4hir.bool> | ||
// CHECK: %[[FLAG2:.*]] = p4hir.alloca !p4hir.bool ["flag2"] : !p4hir.ref<!p4hir.bool> | ||
// CHECK: %[[FLAG3:.*]] = p4hir.alloca !p4hir.bool ["flag3"] : !p4hir.ref<!p4hir.bool> | ||
|
||
bool f1 = flag2 || flag3; | ||
// CHECK: %[[FLAG2_VAL:.*]] = p4hir.load %[[FLAG2]] : !p4hir.ref<!p4hir.bool>, !p4hir.bool | ||
// CHECK-NEXT: %[[F1_VAL:.*]] = p4hir.ternary(%[[FLAG2_VAL]], true { | ||
// CHECK-NEXT: %[[TRUE_VAL:.*]] = p4hir.const #p4hir.bool<true> : !p4hir.bool | ||
// CHECK-NEXT: p4hir.yield %[[TRUE_VAL]] : !p4hir.bool | ||
// CHECK-NEXT: }, false { | ||
// CHECK-NEXT: %[[FLAG3_VAL:.*]] = p4hir.load %[[FLAG3]] : !p4hir.ref<!p4hir.bool>, !p4hir.bool | ||
// CHECK-NEXT: p4hir.yield %[[FLAG3_VAL]] : !p4hir.bool | ||
// CHECK-NEXT }) : (!p4hir.bool) -> !p4hir.bool | ||
|
||
bool f2 = flag2 && flag3; | ||
bool f3 = flag2 && flag3 || flag3; | ||
bool f7 = flag2 || flag3 || flag3; | ||
bool f8 = flag2 || flag3 && flag3; | ||
bool f5 = flag2 || flag3; | ||
f5 = f1 && f5 || flag1; | ||
bool f6 = flag1 || flag2; | ||
} |
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