forked from neo-ai/tvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TIR] Enhance Substitute, python bindings for Substitute/PostOrderVis…
…it/IRTransform. (apache#5400) Substitute now takes a std::function to customize more replacing behaviors. Co-authored-by: Siyuan Feng <hzfengsy@sjtu.edu.cn> Co-authored-by: Siyuan Feng <hzfengsy@sjtu.edu.cn>
- Loading branch information
1 parent
5c8d970
commit 10fc666
Showing
34 changed files
with
419 additions
and
317 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
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 |
---|---|---|
|
@@ -48,3 +48,4 @@ | |
from . import ir_pass | ||
from . import transform | ||
from . import analysis | ||
from . import stmt_functor |
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,77 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
"""Statement functor utilities for IR transformations""" | ||
from . import _ffi_api | ||
|
||
|
||
def ir_transform(stmt, preorder, postorder, only_enable=None): | ||
"""Recursively visit and transform ir nodes in post DFS order. | ||
Parameters | ||
---------- | ||
stmt : Stmt | ||
The input to be transformed. | ||
preorder: function | ||
The function called in before recursive mutation | ||
If preorder returns None, then the transform will proceed to recursive call. | ||
If preorder returns a not None Stmt/Expr, the transformer will simply return it and | ||
won't do further recursion. | ||
postorder : function | ||
The function called after recursive mutation. | ||
only_enable : Optional[List[str]] | ||
List of types that we only enable. | ||
Returns | ||
------- | ||
result : Stmt | ||
The result. | ||
""" | ||
return _ffi_api.IRTransform(stmt, preorder, postorder, only_enable) | ||
|
||
|
||
def post_order_visit(stmt, fvisit): | ||
"""Recursively visit the ir in post DFS order node, apply fvisit | ||
Each node is guaranteed to be visited only once. | ||
Parameters | ||
---------- | ||
fvisit: function | ||
The visitor function. | ||
""" | ||
return _ffi_api.PostOrderVisit(stmt, fvisit) | ||
|
||
|
||
def substitute(node, vmap): | ||
""" Substitute the var specified by vmap. | ||
Parameters | ||
---------- | ||
node: ObjectRef | ||
The input. | ||
vmap : Dict[Var, PrimExpr] | ||
The variable mapping. | ||
Returns | ||
------- | ||
result : Stmt | ||
The result. | ||
""" | ||
return _ffi_api.Substitute(node, vmap) |
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
Oops, something went wrong.