You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2020/11/09 04:17:00 UTC

[GitHub] [incubator-tvm] Light-of-Hers opened a new pull request #6887: Fix bug of generate-unmatched-brackets in CodeGenC::PrintSSAAssign

Light-of-Hers opened a new pull request #6887:
URL: https://github.com/apache/incubator-tvm/pull/6887


   Fix the bug discussed in https://github.com/apache/incubator-tvm/issues/6884 @tqchen 


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [incubator-tvm] Light-of-Hers commented on pull request #6887: Fix bug of generate-unmatched-brackets in CodeGenC::PrintSSAAssign

Posted by GitBox <gi...@apache.org>.
Light-of-Hers commented on pull request #6887:
URL: https://github.com/apache/incubator-tvm/pull/6887#issuecomment-724726901


   Sorry, some low-level mistakes😂. Is it okay now? @tqchen 


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [incubator-tvm] Light-of-Hers commented on pull request #6887: Fix bug of generate-unmatched-brackets in CodeGenC::PrintSSAAssign

Posted by GitBox <gi...@apache.org>.
Light-of-Hers commented on pull request #6887:
URL: https://github.com/apache/incubator-tvm/pull/6887#issuecomment-724530077


   Updated @tqchen 
   Maybe future we can selectively generate surrouding brackets of sub-expressions based the operators' associativity/priority and code-gen context.


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [incubator-tvm] tqchen commented on pull request #6887: Fix bug of generate-unmatched-brackets in CodeGenC::PrintSSAAssign

Posted by GitBox <gi...@apache.org>.
tqchen commented on pull request #6887:
URL: https://github.com/apache/incubator-tvm/pull/6887#issuecomment-724025717


   Thanks @Light-of-Hers , can you enhance the code to still remove extra brackets if they match?
   
   The idea would be to add a CheckBracketMatch code that scans the string and use counter to check if the two bracket indeed matches each other (and remove if they do)
   
   
   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [incubator-tvm] tqchen commented on a change in pull request #6887: Fix bug of generate-unmatched-brackets in CodeGenC::PrintSSAAssign

Posted by GitBox <gi...@apache.org>.
tqchen commented on a change in pull request #6887:
URL: https://github.com/apache/incubator-tvm/pull/6887#discussion_r520560320



##########
File path: src/target/source/codegen_c.cc
##########
@@ -139,11 +139,29 @@ void CodeGenC::PrintExpr(const PrimExpr& n, std::ostream& os) {  // NOLINT(*)
   }
 }
 
+static bool CheckOutmostBracketMatch(const std::string& s) {
+  if (s.front() == '(' && s.back() == ')') {
+    int len = s.size();

Review comment:
       size_t

##########
File path: src/target/source/codegen_c.cc
##########
@@ -139,11 +139,29 @@ void CodeGenC::PrintExpr(const PrimExpr& n, std::ostream& os) {  // NOLINT(*)
   }
 }
 
+static bool CheckOutmostBracketMatch(const std::string& s) {
+  if (s.front() == '(' && s.back() == ')') {

Review comment:
       need tyo first check the length to avoid overflow

##########
File path: src/target/source/codegen_c.cc
##########
@@ -139,11 +139,29 @@ void CodeGenC::PrintExpr(const PrimExpr& n, std::ostream& os) {  // NOLINT(*)
   }
 }
 
+static bool CheckOutmostBracketMatch(const std::string& s) {
+  if (s.front() == '(' && s.back() == ')') {
+    int len = s.size();
+    int n_unmatched = 0;
+    for (int i = 0; i < len; ++i) {
+      if (s[i] == '(') {
+        n_unmatched++;
+      } else if (s[i] == ')') {
+        n_unmatched--;
+      }
+      if (n_unmatched == 0) {
+        return i == len - 1;
+      }
+    }
+  }
+  return false;
+}
+
 void CodeGenC::PrintSSAAssign(const std::string& target, const std::string& src, DataType t) {
   PrintType(t, stream);
   stream << ' ' << target << " = ";
-  if (src.length() > 3 && src[0] == '(' && src[src.length() - 1] == ')') {
-    stream << src.substr(1, src.length() - 2);
+  if (CheckOutmostBracketMatch(src)) {
+    stream << src.substr(1, src.length() - 1);

Review comment:
       change this line back as we need to also remove the bracket in the end

##########
File path: src/target/source/codegen_c.cc
##########
@@ -139,11 +139,29 @@ void CodeGenC::PrintExpr(const PrimExpr& n, std::ostream& os) {  // NOLINT(*)
   }
 }
 
+static bool CheckOutmostBracketMatch(const std::string& s) {

Review comment:
       Move static after all impl of the non-static function

##########
File path: src/target/source/codegen_c.cc
##########
@@ -139,11 +139,29 @@ void CodeGenC::PrintExpr(const PrimExpr& n, std::ostream& os) {  // NOLINT(*)
   }
 }
 
+static bool CheckOutmostBracketMatch(const std::string& s) {

Review comment:
       CheckOutermostBracketMatch




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [incubator-tvm] tqchen commented on pull request #6887: Fix bug of generate-unmatched-brackets in CodeGenC::PrintSSAAssign

Posted by GitBox <gi...@apache.org>.
tqchen commented on pull request #6887:
URL: https://github.com/apache/incubator-tvm/pull/6887#issuecomment-724959748


   Thanks @Light-of-Hers !


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [incubator-tvm] tqchen merged pull request #6887: Fix bug of generate-unmatched-brackets in CodeGenC::PrintSSAAssign

Posted by GitBox <gi...@apache.org>.
tqchen merged pull request #6887:
URL: https://github.com/apache/incubator-tvm/pull/6887


   


----------------------------------------------------------------
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:
users@infra.apache.org