提交 a8dc5978 编写于 作者: M mindspore-ci-bot 提交者: Gitee

!1151 Simplify node traversal strategy

Merge pull request !1151 from lyvette/master
......@@ -88,6 +88,22 @@ AnfNodePtr Substitution::operator()(const OptimizerPtr &optimizer, const AnfNode
return result;
}
inline bool isTraversable(const AnfNodePtr &node) {
if (node == nullptr) {
return false;
}
if (node->isa<CNode>() || node->isa<Parameter>()) {
return true;
}
if (IsValueNode<FuncGraph>(node) || IsValueNode<RefKey>(node)) {
return true;
}
return false;
}
bool SubstitutionList::ApplyTransform(const OptimizerPtr &optimizer, const AnfNodePtr &root_node,
const SubstitutionPtr &transform) const {
#ifdef ENABLE_PROFILE
......@@ -106,7 +122,7 @@ bool SubstitutionList::ApplyTransform(const OptimizerPtr &optimizer, const AnfNo
todo.pop_front();
// check whether this node has been matched.
if (node == nullptr || node->seen_ == seen || !all_nodes.contains(node)) {
if (node == nullptr || node->seen_ == seen || !isTraversable(node) || !all_nodes.contains(node)) {
continue;
}
node->seen_ = seen;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册