-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DAPHNE-#911] Correct reference counter for arith.select result.
- The MLIR operation arith.select is frequently created during the canonicalization of scf.if (which, in turn, is created by DaphneDSL if-statements). - arith.select takes a boolean argument (condition) plus two additional arguments, one of which it selects/returns based on the value of the condition. - arith.select needs to be taken into account in DAPHNE's object reference counter management, because: - We decrease the reference counter of SSA values after their last use as operands (the arith.select could be the last user). - We have no clue which of the two last operands of arith.select is returned at run-time. - However, the return value is the same runtime object as one of the two latter operands. - To ensure the correct reference counter for the result after the arith.select, we need to increase the counter of the result before we decrease the counters of the operands. - We had already implemented this fix, but applied it only for string operands/results. - However, we must apply the fix for all operand/result types that have a reference counter at run-time. - Fixed ManageObjRefPass. - Added several script-level test cases testing the behavior for matrices, frames, lists, and strings and different settings of the if-then-else in DaphneDSL.
- Loading branch information
Showing
26 changed files
with
177 additions
and
6 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,12 @@ | ||
// Update a matrix inside else-branch of if-statement with value computed outside if-statement (scf.if gets rewritten to arith.select). | ||
X = [0]; | ||
Y = X + 1; | ||
# r must be unknown at compile-time (otherwise, the entire "if" gets optimized away) | ||
# TODO The rand() might get optimized away at some point in the future (but not at the moment), because the result is clear. | ||
r = as.scalar(rand(1, 1, 0, 1, 1, -1)); | ||
if(r) | ||
r = 99; # do something unrelated to X | ||
else | ||
X = Y; | ||
print(r); | ||
print(X); |
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,3 @@ | ||
99 | ||
DenseMatrix(1x1, int64_t) | ||
0 |
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,12 @@ | ||
// Update a matrix inside then-branch and else-branch of if-statement with values computed outside if-statement (scf.if gets rewritten to arith.select). | ||
X = [0]; | ||
Y = X + 1; | ||
Z = X + 2; | ||
# r must be unknown at compile-time (otherwise, the entire "if" gets optimized away) | ||
# TODO The rand() might get optimized away at some point in the future (but not at the moment), because the result is clear. | ||
r = as.scalar(rand(1, 1, 0, 1, 1, -1)); | ||
if(r) | ||
X = Y; | ||
else | ||
X = Z; | ||
print(X); |
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,2 @@ | ||
DenseMatrix(1x1, int64_t) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Update a frame inside then-branch of if-statement with value computed outside if-statement (scf.if gets rewritten to arith.select). | ||
X = {"a": [0]}; | ||
Y = rbind(X, X); | ||
# r must be unknown at compile-time (otherwise, the entire "if" gets optimized away) | ||
# TODO The rand() might get optimized away at some point in the future (but not at the moment), because the result is clear. | ||
r = as.scalar(rand(1, 1, 0, 1, 1, -1)); | ||
if(r) | ||
X = Y; | ||
print(X); |
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,3 @@ | ||
Frame(2x1, [a:int64_t]) | ||
0 | ||
0 |
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,12 @@ | ||
// Update a frame inside else-branch of if-statement with value computed outside if-statement (scf.if gets rewritten to arith.select). | ||
X = {"a": [0]}; | ||
Y = rbind(X, X); | ||
# r must be unknown at compile-time (otherwise, the entire "if" gets optimized away) | ||
# TODO The rand() might get optimized away at some point in the future (but not at the moment), because the result is clear. | ||
r = as.scalar(rand(1, 1, 0, 1, 1, -1)); | ||
if(r) | ||
r = 99; # do something unrelated to X | ||
else | ||
X = Y; | ||
print(r); | ||
print(X); |
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,3 @@ | ||
99 | ||
Frame(1x1, [a:int64_t]) | ||
0 |
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,12 @@ | ||
// Update a frame inside then-branch and else-branch of if-statement with values computed outside if-statement (scf.if gets rewritten to arith.select). | ||
X = {"a": [0]}; | ||
Y = rbind(X, X); | ||
Z = rbind(rbind(X, X), X); | ||
# r must be unknown at compile-time (otherwise, the entire "if" gets optimized away) | ||
# TODO The rand() might get optimized away at some point in the future (but not at the moment), because the result is clear. | ||
r = as.scalar(rand(1, 1, 0, 1, 1, -1)); | ||
if(r) | ||
X = Y; | ||
else | ||
X = Z; | ||
print(X); |
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,3 @@ | ||
Frame(2x1, [a:int64_t]) | ||
0 | ||
0 |
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,9 @@ | ||
// Update a list inside then-branch of if-statement with value computed outside if-statement (scf.if gets rewritten to arith.select). | ||
X = createList([0]); | ||
Y = append(X, [1]); | ||
# r must be unknown at compile-time (otherwise, the entire "if" gets optimized away) | ||
# TODO The rand() might get optimized away at some point in the future (but not at the moment), because the result is clear. | ||
r = as.scalar(rand(1, 1, 0, 1, 1, -1)); | ||
if(r) | ||
X = Y; | ||
print(X); |
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,5 @@ | ||
List(2, DenseMatrix, int64_t) | ||
DenseMatrix(1x1, int64_t) | ||
0 | ||
DenseMatrix(1x1, int64_t) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Update a list inside else-branch of if-statement with value computed outside if-statement (scf.if gets rewritten to arith.select). | ||
X = createList([0]); | ||
Y = append(X, [1]); | ||
# r must be unknown at compile-time (otherwise, the entire "if" gets optimized away) | ||
# TODO The rand() might get optimized away at some point in the future (but not at the moment), because the result is clear. | ||
r = as.scalar(rand(1, 1, 0, 1, 1, -1)); | ||
if(r) | ||
r = 99; # do something unrelated to X | ||
else | ||
X = Y; | ||
print(r); | ||
print(X); |
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,4 @@ | ||
99 | ||
List(1, DenseMatrix, int64_t) | ||
DenseMatrix(1x1, int64_t) | ||
0 |
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,12 @@ | ||
// Update a list inside then-branch and else-branch of if-statement with values computed outside if-statement (scf.if gets rewritten to arith.select). | ||
X = createList([0]); | ||
Y = append(X, [1]); | ||
Z = append(X, [2]); | ||
# r must be unknown at compile-time (otherwise, the entire "if" gets optimized away) | ||
# TODO The rand() might get optimized away at some point in the future (but not at the moment), because the result is clear. | ||
r = as.scalar(rand(1, 1, 0, 1, 1, -1)); | ||
if(r) | ||
X = Y; | ||
else | ||
X = Z; | ||
print(X); |
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,5 @@ | ||
List(2, DenseMatrix, int64_t) | ||
DenseMatrix(1x1, int64_t) | ||
0 | ||
DenseMatrix(1x1, int64_t) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Update a string inside then-branch of if-statement with value computed outside if-statement (scf.if gets rewritten to arith.select). | ||
X = "a"; | ||
Y = X + "b"; | ||
# r must be unknown at compile-time (otherwise, the entire "if" gets optimized away) | ||
# TODO The rand() might get optimized away at some point in the future (but not at the moment), because the result is clear. | ||
r = as.scalar(rand(1, 1, 0, 1, 1, -1)); | ||
if(r) | ||
X = Y; | ||
print(X); |
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 @@ | ||
ab |
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,12 @@ | ||
// Update a string inside else-branch of if-statement with value computed outside if-statement (scf.if gets rewritten to arith.select). | ||
X = "a"; | ||
Y = X + "b"; | ||
# r must be unknown at compile-time (otherwise, the entire "if" gets optimized away) | ||
# TODO The rand() might get optimized away at some point in the future (but not at the moment), because the result is clear. | ||
r = as.scalar(rand(1, 1, 0, 1, 1, -1)); | ||
if(r) | ||
r = 99; # do something unrelated to X | ||
else | ||
X = Y; | ||
print(r); | ||
print(X); |
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,2 @@ | ||
99 | ||
a |
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,12 @@ | ||
// Update a string inside then-branch and else-branch of if-statement with values computed outside if-statement (scf.if gets rewritten to arith.select). | ||
X = "a"; | ||
Y = X + "b"; | ||
Z = X + "c"; | ||
# r must be unknown at compile-time (otherwise, the entire "if" gets optimized away) | ||
# TODO The rand() might get optimized away at some point in the future (but not at the moment), because the result is clear. | ||
r = as.scalar(rand(1, 1, 0, 1, 1, -1)); | ||
if(r) | ||
X = Y; | ||
else | ||
X = Z; | ||
print(X); |
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 @@ | ||
ab |
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,9 @@ | ||
// Update a matrix inside then-branch of if-statement with value computed outside if-statement (scf.if gets rewritten to arith.select). | ||
X = [0]; | ||
Y = X + 1; | ||
# r must be unknown at compile-time (otherwise, the entire "if" gets optimized away) | ||
# TODO The rand() might get optimized away at some point in the future (but not at the moment), because the result is clear. | ||
r = as.scalar(rand(1, 1, 0, 1, 1, -1)); | ||
if(r) | ||
X = Y; | ||
print(X); |
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,2 @@ | ||
DenseMatrix(1x1, int64_t) | ||
1 |