eric-haibin-lin commented on a change in pull request #6152: URL: https://github.com/apache/incubator-tvm/pull/6152#discussion_r463983464
########## File path: src/relay/transforms/pass_util.h ########## @@ -184,6 +188,37 @@ struct TreeBranchNode : TreeNode<ConditionObjectPtr> { ~TreeBranchNode() {} }; +struct ScopeNode; +using Scope = std::shared_ptr<ScopeNode>; + +/* Invariant: when parent is null level is 0 + * Invariant: when parent is not null level is 1 + parent->level + */ +struct ScopeNode { + // the level of the scope + size_t level; + // the parent scope + Scope parent; + // the corresponding let list which holds all let bindings in the scope + std::shared_ptr<LetList> ll = std::make_shared<LetList>(); + explicit ScopeNode(const Scope& parent) : level(1 + parent->level), parent(parent) {} + ScopeNode() : level(0) {} +}; + +/*! \brief Calculate the scope of nodes in the dependency graph by least common ancestor. + * + * \param dg the input dependency graph + * \param expr_scope the output node -> scope mapping for all nodes. + * \param lifted_exprs the output set of expressions whose scope is lifted due to dependency + */ +void CalcScope(const DependencyGraph& dg, + std::unordered_map<DependencyGraph::Node*, Scope>* expr_scope, Review comment: @MarisaKirisame thanks for the review! For BBlock I want to get a set of expressions whose scope should be lifted and rewritten with let bindings. I found `CalcScope` already performs finding the LCA for all nodes in the dependency graph, so i just added a few lines of code so that the set of corresponding expressions are also returned by this function. However, setting the return type to `std::pair<std::unordered_map<node, scope> std::unordered_set<expr>>` causes cpplint to fails due to the long length. So I instead used pointers for both outputs. Please let me know the preferred way for returning both outputs. Thanks! ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org