Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tic
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenyuanbo
tic
Commits
3f43bee0
Unverified
Commit
3f43bee0
authored
Jan 02, 2020
by
Tianqi Chen
Committed by
GitHub
Jan 02, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bugfix StmtMutator IfThenElse (#4609)
parent
983eba88
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
4 deletions
+20
-4
src/pass/ir_functor.cc
+1
-1
tests/cpp/ir_functor_test.cc
+19
-3
No files found.
src/pass/ir_functor.cc
View file @
3f43bee0
...
...
@@ -417,7 +417,7 @@ Stmt StmtMutator::VisitStmt_(const IfThenElse* op) {
auto
n
=
CopyOnWrite
(
op
);
n
->
condition
=
std
::
move
(
condition
);
n
->
then_case
=
std
::
move
(
then_case
);
n
->
else_case
=
std
::
move
(
then
_case
);
n
->
else_case
=
std
::
move
(
else
_case
);
return
Stmt
(
n
);
}
}
...
...
tests/cpp/ir_functor_test.cc
View file @
3f43bee0
...
...
@@ -146,16 +146,22 @@ TEST(IRF, StmtMutator) {
return
ExprMutator
::
VisitExpr
(
expr
);
}
};
auto
fmake
test
=
[
&
]()
{
auto
fmake
alloc
=
[
&
]()
{
auto
z
=
x
+
1
;
Stmt
body
=
Evaluate
::
make
(
z
);
Var
buffer
(
"b"
,
DataType
::
Handle
());
return
Allocate
::
make
(
buffer
,
DataType
::
Float
(
32
),
{
1
,
z
},
const_true
(),
body
);
};
auto
fmakeif
=
[
&
]()
{
auto
z
=
x
+
1
;
Stmt
body
=
Evaluate
::
make
(
z
);
return
IfThenElse
::
make
(
x
<
0
,
Evaluate
::
make
(
0
),
body
);
};
MyVisitor
v
;
{
auto
body
=
fmake
test
();
auto
body
=
fmake
alloc
();
Stmt
body2
=
Evaluate
::
make
(
1
);
Stmt
bref
=
body
.
as
<
Allocate
>
()
->
body
;
auto
*
extentptr
=
body
.
as
<
Allocate
>
()
->
extents
.
get
();
...
...
@@ -172,7 +178,7 @@ TEST(IRF, StmtMutator) {
CHECK
(
bref
.
as
<
Evaluate
>
()
->
value
.
as
<
Add
>
());
}
{
Array
<
Stmt
>
arr
{
fmake
test
()};
Array
<
Stmt
>
arr
{
fmake
alloc
()};
// mutate array get reference by another one, triiger copy.
Array
<
Stmt
>
arr2
=
arr
;
auto
*
arrptr
=
arr
.
get
();
...
...
@@ -186,6 +192,16 @@ TEST(IRF, StmtMutator) {
CHECK
(
arr2
.
get
()
==
arr
.
get
());
}
{
Array
<
Stmt
>
arr
{
fmakeif
()};
arr
.
MutateByApply
([
&
](
Stmt
s
)
{
return
v
(
std
::
move
(
s
));
});
CHECK
(
arr
[
0
].
as
<
IfThenElse
>
()
->
else_case
.
as
<
Evaluate
>
()
->
value
.
same_as
(
x
));
// mutate but no content change.
auto
arr2
=
arr
;
arr
.
MutateByApply
([
&
](
Stmt
s
)
{
return
v
(
std
::
move
(
s
));
});
CHECK
(
arr2
.
get
()
==
arr
.
get
());
}
{
auto
body
=
Evaluate
::
make
(
Call
::
make
(
DataType
::
Int
(
32
),
"xyz"
,
{
x
+
1
},
Call
::
Extern
));
auto
res
=
v
(
std
::
move
(
body
));
CHECK
(
res
.
as
<
Evaluate
>
()
->
value
.
as
<
Call
>
()
->
args
[
0
].
same_as
(
x
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment