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
7d670b04
Unverified
Commit
7d670b04
authored
Apr 09, 2020
by
Animesh Jain
Committed by
GitHub
Apr 09, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Legalize - Use Non-recursive Rewriter. (#5296)
* Legalize - Use Non-recursive Rewriter. * Cleanup.
parent
2b968204
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
10 deletions
+9
-10
include/tvm/relay/expr_functor.h
+0
-0
src/relay/transforms/legalize.cc
+9
-10
No files found.
include/tvm/relay/expr_functor.h
View file @
7d670b04
src/relay/transforms/legalize.cc
View file @
7d670b04
...
...
@@ -35,19 +35,18 @@ namespace legalize {
// Call registered FTVMLegalize of an op
// Returns the legalized expression
class
Legalizer
:
public
Expr
Mutato
r
{
class
Legalizer
:
public
Expr
Rewrite
r
{
public
:
explicit
Legalizer
(
const
std
::
string
&
legalize_map_attr_name
)
:
legalize_map_attr_name_
{
legalize_map_attr_name
}
{}
Expr
VisitExpr_
(
const
CallNode
*
call_node
)
{
Expr
Rewrite_
(
const
CallNode
*
call_node
,
const
Expr
&
post
)
override
{
// Get the new_call node without any changes to current call node.
Expr
new_e
=
ExprMutator
::
VisitExpr_
(
call_node
);
Call
new_call
=
Downcast
<
Call
>
(
new_e
);
Call
new_call
=
Downcast
<
Call
>
(
post
);
// Check if the string is registered in the OpRegistry.
if
(
!
Op
::
HasAttr
(
legalize_map_attr_name_
))
{
return
new_e
;
return
post
;
}
// Collect the registered legalize function.
...
...
@@ -70,19 +69,18 @@ class Legalizer : public ExprMutator {
// Transform the op by calling the registered legalize function.
Expr
legalized_value
=
fop_legalize
[
op
](
call_node
->
attrs
,
call_args
,
types
);
// Re
assign new_e
if the transformation succeeded.
// Re
turn the new expr
if the transformation succeeded.
if
(
legalized_value
.
defined
())
{
// Check that the returned Expr from legalize is CallNode.
const
CallNode
*
legalized_call_node
=
legalized_value
.
as
<
CallNode
>
();
CHECK
(
legalized_call_node
)
<<
"Can only replace the original operator with another call node"
;
new_e
=
legalized_value
;
return
legalized_value
;
}
}
}
return
new_e
;
return
post
;
}
private
:
...
...
@@ -90,7 +88,8 @@ class Legalizer : public ExprMutator {
};
Expr
Legalize
(
const
Expr
&
expr
,
const
std
::
string
&
legalize_map_attr_name
)
{
return
Legalizer
(
legalize_map_attr_name
).
Mutate
(
expr
);
auto
rewriter
=
Legalizer
(
legalize_map_attr_name
);
return
PostOrderRewrite
(
expr
,
&
rewriter
);
}
}
// namespace legalize
...
...
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