提交 2899aaad 编写于 作者: W Wei Luning

fix bug in remove phiphi should replace the inner ones first

上级 031ce815
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
*/ */
#include "pipeline/jit/parse/parse.h" #include "pipeline/jit/parse/parse.h"
#include <utility>
#include <string> #include <string>
#include <memory> #include <memory>
#include <sstream> #include <sstream>
...@@ -1480,21 +1482,25 @@ AnfNodePtr FindPhis(const std::unordered_map<ParameterPtr, AnfNodePtr> &removabl ...@@ -1480,21 +1482,25 @@ AnfNodePtr FindPhis(const std::unordered_map<ParameterPtr, AnfNodePtr> &removabl
void Parser::RemoveUnnecessaryPhis() { void Parser::RemoveUnnecessaryPhis() {
// merge all removable phis to one map; // merge all removable phis to one map;
std::unordered_map<ParameterPtr, AnfNodePtr> removable_phis; std::unordered_map<ParameterPtr, AnfNodePtr> removable_phis;
std::vector<ParameterPtr> phis;
for (FunctionBlockPtr &block : func_block_list_) { for (FunctionBlockPtr &block : func_block_list_) {
MS_EXCEPTION_IF_NULL(block); MS_EXCEPTION_IF_NULL(block);
removable_phis.insert(block->removable_phis().begin(), block->removable_phis().end()); removable_phis.insert(block->removable_phis().begin(), block->removable_phis().end());
std::transform(block->removable_phis().begin(), block->removable_phis().end(), std::back_inserter(phis),
[](std::pair<ParameterPtr, AnfNodePtr> pair) { return pair.first; });
} }
if (removable_phis.size() == 0) { if (removable_phis.size() == 0) {
return; return;
} }
auto fg_name = func_graph_->ToString(); auto fg_name = func_graph_->ToString();
auto mng = Manage(func_graph_, false); auto mng = Manage(func_graph_, false);
// replace the nodes // replace the nodes
for (auto iter : removable_phis) { // remove from inside to outside
auto new_node = FindPhis(removable_phis, iter.first); for (int idx = SizeToInt(phis.size() - 1); idx >= 0; idx--) {
MS_LOG(DEBUG) << "phi " << iter.first->DebugString() << " to " << new_node->DebugString(); auto phi = phis[IntToSize(idx)];
mng->Replace(iter.first, new_node); auto new_node = FindPhis(removable_phis, phi);
MS_LOG(DEBUG) << "phi " << phi->DebugString() << " to " << new_node->DebugString();
mng->Replace(phi, new_node);
} }
// remove the parameter // remove the parameter
for (FunctionBlockPtr &block : func_block_list_) { for (FunctionBlockPtr &block : func_block_list_) {
......
...@@ -124,7 +124,7 @@ class OrderedMap { ...@@ -124,7 +124,7 @@ class OrderedMap {
std::pair<iterator, bool> insert(const pair_type &kv) { std::pair<iterator, bool> insert(const pair_type &kv) {
auto result = add(kv.first); auto result = add(kv.first);
if (result.second) { if (result.second) {
*(result.first) = kv.second; *(result.first) = kv;
return std::make_pair(std::prev(end()), true); return std::make_pair(std::prev(end()), true);
} }
return std::make_pair(result.first, false); return std::make_pair(result.first, false);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册