MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / replace_var

Method replace_var

src/gopt/impl/framework.cpp:92–111  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90}
91
92void SubGraph::Rewriter::replace_var(VarNode* src, VarNode* dst, const char* msg) {
93 if (src == dst)
94 return;
95
96 // Optimizers should not create a loop in varaible replace map.
97 mgb_throw_if(
98 get_var_internal(dst).second == src, InternalError,
99 "dst %s maps back to src %s in SubGraph::Rewriter::replace_var",
100 dst->cname(), src->cname());
101
102 auto&& ins = m_varmap.insert({src, {false, dst}});
103 if (!ins.second) {
104 auto&& old_rep = ins.first->second;
105 mgb_assert(
106 old_rep.first || old_rep.second == dst, "can not replace a var twice");
107 old_rep.first = false;
108 old_rep.second = dst;
109 }
110 on_var_replaced(src, dst, msg);
111}
112
113void SubGraph::Rewriter::on_var_replaced(VarNode* src, VarNode* dst, const char* msg) {
114 if (auto state = m_owner_graph->owner_opt_state()) {

Callers 15

applyMethod · 0.45
replace_varsMethod · 0.45
update_graphMethod · 0.45
applyMethod · 0.45
applyMethod · 0.45
applyMethod · 0.45
applyMethod · 0.45
param_mergeFunction · 0.45
applyMethod · 0.45

Calls 2

cnameMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected