| 35 | } |
| 36 | |
| 37 | OperatorNodeBase* GraphOptimizer::insert_post(OperatorNodeBase* opr) { |
| 38 | bool already_inserted = false; |
| 39 | auto hash = opr->hash(); |
| 40 | auto iter = m_opr_hash_list.find(hash); |
| 41 | if (iter != m_opr_hash_list.end()) { |
| 42 | for (auto i : iter->second) { |
| 43 | if (i->is_same(*opr)) { |
| 44 | already_inserted = true; |
| 45 | // If the hash of the operator to be saved is already saved in |
| 46 | // m_opr_hash_list, we validate that the to-be-saved operator |
| 47 | // is original one which we saved. |
| 48 | // If this fails, it usually means insert_post is not paired |
| 49 | // with a corresponding insert_pre, or the caller didn't use |
| 50 | // the saved operator returned by insert_pre. |
| 51 | mgb_assert(i == opr); |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | if (!already_inserted) { |
| 56 | m_opr_hash_list[hash].push_back(opr); |
| 57 | } |
| 58 | |
| 59 | #if !MGB_BUILD_SLIM_SERVING |
| 60 | // For eager mode, return the original opr without the opt pass |
| 61 | if (opr->owner_graph()->options().eager_evaluation) |
| 62 | return opr; |
| 63 | #endif |
| 64 | |
| 65 | OperatorNodeBase* ret = nullptr; |
| 66 | static const std::array<OperatorNodeBase* (GraphOptimizer::*)(VarNode*), 3> passes = |
| 67 | { |
| 68 | &GraphOptimizer::merge_bcast, |
| 69 | &GraphOptimizer::swap_typecvt_and_bcast, |
| 70 | &GraphOptimizer::replace_const_var, |
| 71 | }; |
| 72 | |
| 73 | for (auto pass : passes) { |
| 74 | if (opr->usable_output().size() > 1) |
| 75 | break; |
| 76 | |
| 77 | ret = (this->*pass)(opr->output(0)); |
| 78 | opr = ret ? ret : opr; |
| 79 | } |
| 80 | return opr; |
| 81 | } |
| 82 | |
| 83 | namespace { |
| 84 |
no test coverage detected