[GitHub] [incubator-tvm] zhiics commented on a change in pull request #5134: [RELAY] Add MergeCompilerRegions pass

2020-03-25 Thread GitBox
zhiics commented on a change in pull request #5134: [RELAY] Add 
MergeCompilerRegions pass
URL: https://github.com/apache/incubator-tvm/pull/5134#discussion_r397987916
 
 

 ##
 File path: src/relay/transforms/annotate_target.cc
 ##
 @@ -38,46 +38,144 @@ class AnnotateTargetWrapper : public ExprMutator {
  public:
   explicit AnnotateTargetWrapper(const std::string& target) : target_(target) 
{}
 
+  Expr Annotate(const Expr& expr) {
+return InsertEnd(Mutate(expr));
+  }
+
+  bool IsSupported(const Expr& expr) {
+if (expr->IsInstance()) {
+  Call call = Downcast(expr);
+  auto fannotate = Op::GetAttr("target." + target_);
+  Op op = Downcast(call->op);
+  CHECK(op.defined());
+  if (fannotate.count(op)) {
+return fannotate[op](call->attrs, call->args);
+  }
+}
+return false;
+  }
+
+  Expr InsertEnd(const Expr& arg) {
+if (IsSupported(arg)) {
+  const auto *end_op =
+runtime::Registry::Get("relay.op.annotation._make.compiler_end");
+  CHECK(end_op);
+  Expr end = (*end_op)(arg, target_);
+  return end;
+}
+return arg;
+  }
+
   Expr VisitExpr_(const CallNode* cn) {
 // TODO(@zhiics, @comaniac) Handle composite functions.
 auto new_e = ExprMutator::VisitExpr_(cn);
 
 Call call = Downcast(new_e);
-static auto fannotate = Op::GetAttr("target." + 
target_);
-Op op = Downcast(call->op);
-CHECK(op.defined());
-
-if (fannotate.count(op)) {
-  bool external = fannotate[op](call->attrs, call->args);
-  if (external) {
-tvm::Array compiler_begins;
-for (const auto& it : call->args) {
-  const auto* begin_op =
-runtime::Registry::Get("relay.op.annotation._make.compiler_begin");
-  CHECK(begin_op);
-  Expr begin = (*begin_op)(it, target_);
-  compiler_begins.push_back(begin);
-}
-Expr update_call = Call(call->op, compiler_begins, call->attrs);
-const auto* end_op =
-  runtime::Registry::Get("relay.op.annotation._make.compiler_end");
-CHECK(end_op);
-Expr end = (*end_op)(update_call, target_);
-return end;
+
+// add end annotations if the args are supported
+Array compiler_ends;
+for (const auto& it : call->args) {
+  compiler_ends.push_back(InsertEnd(it));
+}
+call = Call(call->op, compiler_ends, call->attrs);
+
+// add begin annotations if the call node is supported
+if (IsSupported(call)) {
+  tvm::Array compiler_begins;
+  for (const auto& it : call->args) {
+const auto* begin_op =
+  runtime::Registry::Get("relay.op.annotation._make.compiler_begin");
+CHECK(begin_op);
+Expr begin = (*begin_op)(it, target_);
+compiler_begins.push_back(begin);
   }
-} else {
-  LOG(WARNING) << op->name << " in " << target_
-   << " is not registered. It will be executed on CPU.";
+  call = Call(call->op, compiler_begins, call->attrs);
 }
-return new_e;
+
+return std::move(call);
+  }
+
+  Expr VisitExpr_(const TupleNode *op) {
 
 Review comment:
   use Google C++ code style: `TupleNode* op`, same to the other changes or 
this PR.


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


With regards,
Apache Git Services


[GitHub] [incubator-tvm] zhiics commented on a change in pull request #5134: [RELAY] Add MergeCompilerRegions pass

2020-03-25 Thread GitBox
zhiics commented on a change in pull request #5134: [RELAY] Add 
MergeCompilerRegions pass
URL: https://github.com/apache/incubator-tvm/pull/5134#discussion_r397998462
 
 

 ##
 File path: src/relay/transforms/merge_compiler_regions.cc
 ##
 @@ -0,0 +1,352 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ * \file src/relay/transforms/merge_compiler_regions.cc
+ *
+ * \brief After operators have been annotated with the targets that support
+ * them, this pass creates regions of the operators for each target. It
+ * is guaranteed that the regions will have a topological ordering so that
+ * no data dependency issues exist.
+ *
+ * This pass only introduces annotations to indicate the regions.
+ * partition_graph must subsequently be called to lift these regions out
+ * as external functions.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include "../analysis/annotated_region_set.h"
+
+
+namespace tvm {
+namespace relay {
+namespace partitioning {
+
+// Cache compiler_begin and compiler_end annotation ops for equivalence check 
to
+// reduce registry lookup overhead.
+static const Op& compiler_begin_op = Op::Get("annotation.compiler_begin");
+static const Op& compiler_end_op = Op::Get("annotation.compiler_end");
+
+/*! \brief This is a pre-requisite pass to merge-supported pass.
+ *  The AnnotateRestDefault pass will put "default" Compiler Annotations to
+ *  nodes that are not annotated already. This is there to ensure that the
+ *  user will not leave un-annotated nodes MergeCompilerRegions pass is run.
+ *  Why? Because, MergeCompilerRegions pass assumes every node to be annotated.
+ */
+class AnnotateRestDefault : public ExprMutator {
+ public:
+  explicit AnnotateRestDefault(const Expr& expr) {
+  regions_ = AnnotatedRegionSet::Create(expr, compiler_begin_op, 
compiler_end_op);
+  }
+
+  Expr Annotate(const Expr& expr) {
+// Its a function that is being passed on to annotate
+func_ = Downcast(expr);
+
+// Corner Case CC1 : If the last node does not belong
+// to a region nede to add a compiler_end
+auto region = regions_->GetRegion(func_->body);
+auto mutated_expr = this->VisitExpr(expr);
+if (!region.defined()) {
+  func_ = Downcast(mutated_expr);
+  // CC1 : add that compiler end after mutation
+  auto body = AddCompilerEnd_(func_->body);
+  func_ = Function(func_->params, body,
+   body->checked_type_, {}, DictAttrs());
+  return Downcast(func_);
+} else {
+  return mutated_expr;
+}
+  }
+
+  /*! \brief This function adds compiler ends to nodes that
+   * have a region AND they should not be arguments of the
+   * original function
+   * \param expr
+   * \return expr
+   */
+  Expr AddCompilerEnd(const Expr& expr) {
+auto region = regions_->GetRegion(expr);
+auto visited_expr = VisitExpr(expr);
+
+// The compiler ends are added to nodes that does have a region
+// AND they should not be arguments of the original function
+if (!region.defined() &&
+   std::find(func_->params.begin(),
+ func_->params.end(), visited_expr)
+   == func_->params.end()) {
+  return AddCompilerEnd_(visited_expr);
+} else {
+  return visited_expr;
+}
+  }
+
+  Expr AddCompilerEnd_(const Expr& expr) {
+const auto* end_op =
+  runtime::Registry::Get("relay.op.annotation._make.compiler_end");
+CHECK(end_op);
+Expr end = (*end_op)(expr, target_);
+return end;
+  }
+
+  Expr VisitExpr_(const CallNode* call) final {
+auto op_node = call->op.as();
+auto ret = GetRef(call);
+
+Array args;
+
+// Add compiler ends if the parent is supported
+for (auto arg : call->args) {
+  args.push_back(AddCompilerEnd(arg));
+}
+
+if (op_node == nullptr || call->attrs.as() == nullptr) {
+  // Skip annotatation ops, only add default compiler to actual compute 
nodes
+
+  auto region = regions_->GetRegion(ret);
+  if (!region.defined()) {
+// if the current node does not belong to annotated region
+// annotate the all incoming edges (args)
+// with 

[GitHub] [incubator-tvm] zhiics commented on a change in pull request #5134: [RELAY] Add MergeCompilerRegions pass

2020-03-25 Thread GitBox
zhiics commented on a change in pull request #5134: [RELAY] Add 
MergeCompilerRegions pass
URL: https://github.com/apache/incubator-tvm/pull/5134#discussion_r397993884
 
 

 ##
 File path: src/relay/transforms/merge_compiler_regions.cc
 ##
 @@ -0,0 +1,352 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ * \file src/relay/transforms/merge_compiler_regions.cc
+ *
+ * \brief After operators have been annotated with the targets that support
+ * them, this pass creates regions of the operators for each target. It
+ * is guaranteed that the regions will have a topological ordering so that
+ * no data dependency issues exist.
+ *
+ * This pass only introduces annotations to indicate the regions.
+ * partition_graph must subsequently be called to lift these regions out
+ * as external functions.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include "../analysis/annotated_region_set.h"
+
+
+namespace tvm {
+namespace relay {
+namespace partitioning {
+
+// Cache compiler_begin and compiler_end annotation ops for equivalence check 
to
+// reduce registry lookup overhead.
+static const Op& compiler_begin_op = Op::Get("annotation.compiler_begin");
+static const Op& compiler_end_op = Op::Get("annotation.compiler_end");
+
+/*! \brief This is a pre-requisite pass to merge-supported pass.
+ *  The AnnotateRestDefault pass will put "default" Compiler Annotations to
+ *  nodes that are not annotated already. This is there to ensure that the
+ *  user will not leave un-annotated nodes MergeCompilerRegions pass is run.
+ *  Why? Because, MergeCompilerRegions pass assumes every node to be annotated.
+ */
+class AnnotateRestDefault : public ExprMutator {
+ public:
+  explicit AnnotateRestDefault(const Expr& expr) {
+  regions_ = AnnotatedRegionSet::Create(expr, compiler_begin_op, 
compiler_end_op);
+  }
+
+  Expr Annotate(const Expr& expr) {
+// Its a function that is being passed on to annotate
+func_ = Downcast(expr);
+
+// Corner Case CC1 : If the last node does not belong
+// to a region nede to add a compiler_end
+auto region = regions_->GetRegion(func_->body);
+auto mutated_expr = this->VisitExpr(expr);
+if (!region.defined()) {
+  func_ = Downcast(mutated_expr);
+  // CC1 : add that compiler end after mutation
+  auto body = AddCompilerEnd_(func_->body);
+  func_ = Function(func_->params, body,
+   body->checked_type_, {}, DictAttrs());
+  return Downcast(func_);
+} else {
+  return mutated_expr;
+}
+  }
+
+  /*! \brief This function adds compiler ends to nodes that
+   * have a region AND they should not be arguments of the
+   * original function
+   * \param expr
+   * \return expr
+   */
+  Expr AddCompilerEnd(const Expr& expr) {
+auto region = regions_->GetRegion(expr);
+auto visited_expr = VisitExpr(expr);
+
+// The compiler ends are added to nodes that does have a region
+// AND they should not be arguments of the original function
+if (!region.defined() &&
+   std::find(func_->params.begin(),
+ func_->params.end(), visited_expr)
+   == func_->params.end()) {
+  return AddCompilerEnd_(visited_expr);
+} else {
+  return visited_expr;
+}
+  }
+
+  Expr AddCompilerEnd_(const Expr& expr) {
+const auto* end_op =
+  runtime::Registry::Get("relay.op.annotation._make.compiler_end");
+CHECK(end_op);
+Expr end = (*end_op)(expr, target_);
+return end;
+  }
+
+  Expr VisitExpr_(const CallNode* call) final {
+auto op_node = call->op.as();
+auto ret = GetRef(call);
+
+Array args;
+
+// Add compiler ends if the parent is supported
+for (auto arg : call->args) {
+  args.push_back(AddCompilerEnd(arg));
+}
+
+if (op_node == nullptr || call->attrs.as() == nullptr) {
+  // Skip annotatation ops, only add default compiler to actual compute 
nodes
+
+  auto region = regions_->GetRegion(ret);
+  if (!region.defined()) {
+// if the current node does not belong to annotated region
+// annotate the all incoming edges (args)
+// with 

[GitHub] [incubator-tvm] zhiics commented on a change in pull request #5134: [RELAY] Add MergeCompilerRegions pass

2020-03-25 Thread GitBox
zhiics commented on a change in pull request #5134: [RELAY] Add 
MergeCompilerRegions pass
URL: https://github.com/apache/incubator-tvm/pull/5134#discussion_r397994225
 
 

 ##
 File path: src/relay/transforms/merge_compiler_regions.cc
 ##
 @@ -0,0 +1,352 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ * \file src/relay/transforms/merge_compiler_regions.cc
+ *
+ * \brief After operators have been annotated with the targets that support
+ * them, this pass creates regions of the operators for each target. It
+ * is guaranteed that the regions will have a topological ordering so that
+ * no data dependency issues exist.
+ *
+ * This pass only introduces annotations to indicate the regions.
+ * partition_graph must subsequently be called to lift these regions out
+ * as external functions.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include "../analysis/annotated_region_set.h"
+
+
+namespace tvm {
+namespace relay {
+namespace partitioning {
+
+// Cache compiler_begin and compiler_end annotation ops for equivalence check 
to
+// reduce registry lookup overhead.
+static const Op& compiler_begin_op = Op::Get("annotation.compiler_begin");
+static const Op& compiler_end_op = Op::Get("annotation.compiler_end");
+
+/*! \brief This is a pre-requisite pass to merge-supported pass.
+ *  The AnnotateRestDefault pass will put "default" Compiler Annotations to
+ *  nodes that are not annotated already. This is there to ensure that the
+ *  user will not leave un-annotated nodes MergeCompilerRegions pass is run.
+ *  Why? Because, MergeCompilerRegions pass assumes every node to be annotated.
+ */
+class AnnotateRestDefault : public ExprMutator {
+ public:
+  explicit AnnotateRestDefault(const Expr& expr) {
+  regions_ = AnnotatedRegionSet::Create(expr, compiler_begin_op, 
compiler_end_op);
+  }
+
+  Expr Annotate(const Expr& expr) {
+// Its a function that is being passed on to annotate
+func_ = Downcast(expr);
+
+// Corner Case CC1 : If the last node does not belong
+// to a region nede to add a compiler_end
+auto region = regions_->GetRegion(func_->body);
+auto mutated_expr = this->VisitExpr(expr);
+if (!region.defined()) {
+  func_ = Downcast(mutated_expr);
+  // CC1 : add that compiler end after mutation
+  auto body = AddCompilerEnd_(func_->body);
+  func_ = Function(func_->params, body,
+   body->checked_type_, {}, DictAttrs());
+  return Downcast(func_);
+} else {
+  return mutated_expr;
+}
+  }
+
+  /*! \brief This function adds compiler ends to nodes that
+   * have a region AND they should not be arguments of the
+   * original function
+   * \param expr
+   * \return expr
+   */
+  Expr AddCompilerEnd(const Expr& expr) {
+auto region = regions_->GetRegion(expr);
+auto visited_expr = VisitExpr(expr);
+
+// The compiler ends are added to nodes that does have a region
+// AND they should not be arguments of the original function
+if (!region.defined() &&
+   std::find(func_->params.begin(),
+ func_->params.end(), visited_expr)
+   == func_->params.end()) {
+  return AddCompilerEnd_(visited_expr);
+} else {
+  return visited_expr;
+}
+  }
+
+  Expr AddCompilerEnd_(const Expr& expr) {
+const auto* end_op =
+  runtime::Registry::Get("relay.op.annotation._make.compiler_end");
+CHECK(end_op);
+Expr end = (*end_op)(expr, target_);
+return end;
+  }
+
+  Expr VisitExpr_(const CallNode* call) final {
+auto op_node = call->op.as();
+auto ret = GetRef(call);
+
+Array args;
+
+// Add compiler ends if the parent is supported
+for (auto arg : call->args) {
+  args.push_back(AddCompilerEnd(arg));
+}
+
+if (op_node == nullptr || call->attrs.as() == nullptr) {
+  // Skip annotatation ops, only add default compiler to actual compute 
nodes
+
+  auto region = regions_->GetRegion(ret);
+  if (!region.defined()) {
+// if the current node does not belong to annotated region
+// annotate the all incoming edges (args)
+// with 

[GitHub] [incubator-tvm] zhiics commented on a change in pull request #5134: [RELAY] Add MergeCompilerRegions pass

2020-03-25 Thread GitBox
zhiics commented on a change in pull request #5134: [RELAY] Add 
MergeCompilerRegions pass
URL: https://github.com/apache/incubator-tvm/pull/5134#discussion_r397986878
 
 

 ##
 File path: src/relay/transforms/annotate_target.cc
 ##
 @@ -38,46 +38,144 @@ class AnnotateTargetWrapper : public ExprMutator {
  public:
   explicit AnnotateTargetWrapper(const std::string& target) : target_(target) 
{}
 
+  Expr Annotate(const Expr& expr) {
+return InsertEnd(Mutate(expr));
+  }
+
+  bool IsSupported(const Expr& expr) {
+if (expr->IsInstance()) {
+  Call call = Downcast(expr);
+  auto fannotate = Op::GetAttr("target." + target_);
+  Op op = Downcast(call->op);
+  CHECK(op.defined());
+  if (fannotate.count(op)) {
+return fannotate[op](call->attrs, call->args);
+  }
+}
+return false;
+  }
+
+  Expr InsertEnd(const Expr& arg) {
+if (IsSupported(arg)) {
+  const auto *end_op =
+runtime::Registry::Get("relay.op.annotation._make.compiler_end");
+  CHECK(end_op);
+  Expr end = (*end_op)(arg, target_);
+  return end;
+}
+return arg;
+  }
+
   Expr VisitExpr_(const CallNode* cn) {
 // TODO(@zhiics, @comaniac) Handle composite functions.
 auto new_e = ExprMutator::VisitExpr_(cn);
 
 Call call = Downcast(new_e);
-static auto fannotate = Op::GetAttr("target." + 
target_);
-Op op = Downcast(call->op);
-CHECK(op.defined());
-
-if (fannotate.count(op)) {
-  bool external = fannotate[op](call->attrs, call->args);
-  if (external) {
-tvm::Array compiler_begins;
-for (const auto& it : call->args) {
-  const auto* begin_op =
-runtime::Registry::Get("relay.op.annotation._make.compiler_begin");
-  CHECK(begin_op);
-  Expr begin = (*begin_op)(it, target_);
-  compiler_begins.push_back(begin);
-}
-Expr update_call = Call(call->op, compiler_begins, call->attrs);
-const auto* end_op =
-  runtime::Registry::Get("relay.op.annotation._make.compiler_end");
-CHECK(end_op);
-Expr end = (*end_op)(update_call, target_);
-return end;
+
+// add end annotations if the args are supported
+Array compiler_ends;
+for (const auto& it : call->args) {
+  compiler_ends.push_back(InsertEnd(it));
+}
+call = Call(call->op, compiler_ends, call->attrs);
+
+// add begin annotations if the call node is supported
+if (IsSupported(call)) {
+  tvm::Array compiler_begins;
+  for (const auto& it : call->args) {
+const auto* begin_op =
 
 Review comment:
   move this outside of the for loop


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


With regards,
Apache Git Services


[GitHub] [incubator-tvm] zhiics commented on a change in pull request #5134: [RELAY] Add MergeCompilerRegions pass

2020-03-25 Thread GitBox
zhiics commented on a change in pull request #5134: [RELAY] Add 
MergeCompilerRegions pass
URL: https://github.com/apache/incubator-tvm/pull/5134#discussion_r397991560
 
 

 ##
 File path: src/relay/transforms/merge_compiler_regions.cc
 ##
 @@ -0,0 +1,352 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ * \file src/relay/transforms/merge_compiler_regions.cc
+ *
+ * \brief After operators have been annotated with the targets that support
+ * them, this pass creates regions of the operators for each target. It
+ * is guaranteed that the regions will have a topological ordering so that
+ * no data dependency issues exist.
+ *
+ * This pass only introduces annotations to indicate the regions.
+ * partition_graph must subsequently be called to lift these regions out
+ * as external functions.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include "../analysis/annotated_region_set.h"
+
+
+namespace tvm {
+namespace relay {
+namespace partitioning {
+
+// Cache compiler_begin and compiler_end annotation ops for equivalence check 
to
+// reduce registry lookup overhead.
+static const Op& compiler_begin_op = Op::Get("annotation.compiler_begin");
+static const Op& compiler_end_op = Op::Get("annotation.compiler_end");
+
+/*! \brief This is a pre-requisite pass to merge-supported pass.
+ *  The AnnotateRestDefault pass will put "default" Compiler Annotations to
+ *  nodes that are not annotated already. This is there to ensure that the
+ *  user will not leave un-annotated nodes MergeCompilerRegions pass is run.
+ *  Why? Because, MergeCompilerRegions pass assumes every node to be annotated.
+ */
+class AnnotateRestDefault : public ExprMutator {
+ public:
+  explicit AnnotateRestDefault(const Expr& expr) {
+  regions_ = AnnotatedRegionSet::Create(expr, compiler_begin_op, 
compiler_end_op);
+  }
+
+  Expr Annotate(const Expr& expr) {
+// Its a function that is being passed on to annotate
+func_ = Downcast(expr);
+
+// Corner Case CC1 : If the last node does not belong
+// to a region nede to add a compiler_end
+auto region = regions_->GetRegion(func_->body);
+auto mutated_expr = this->VisitExpr(expr);
+if (!region.defined()) {
+  func_ = Downcast(mutated_expr);
+  // CC1 : add that compiler end after mutation
+  auto body = AddCompilerEnd_(func_->body);
+  func_ = Function(func_->params, body,
+   body->checked_type_, {}, DictAttrs());
+  return Downcast(func_);
+} else {
+  return mutated_expr;
+}
+  }
+
+  /*! \brief This function adds compiler ends to nodes that
+   * have a region AND they should not be arguments of the
+   * original function
+   * \param expr
 
 Review comment:
   Complete it, same for return


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


With regards,
Apache Git Services