tlopex commented on code in PR #18554:
URL: https://github.com/apache/tvm/pull/18554#discussion_r2595973891
##########
src/relax/transform/fuse_tir.cc:
##########
@@ -357,17 +357,43 @@ class BlockNameDeduplicator : public tir::StmtMutator {
}
ffi::String GetUniqueName(const ffi::String& prefix) {
- ffi::String unique_prefix = prefix;
- auto it = name_count_.find(prefix);
- while (name_count_.count(unique_prefix)) {
- unique_prefix = prefix + "_" + std::to_string(++it->second);
+ std::string str_prefix = std::string(prefix);
+
+ // Find where the trailing digits start
+ size_t base_len = str_prefix.length();
+ while (base_len > 0 && std::isdigit(str_prefix[base_len - 1])) {
+ --base_len;
+ }
+
+ std::string base_name;
+ int start_num = 0;
+
+ if (base_len < str_prefix.length()) {
+ base_name = str_prefix.substr(0, base_len);
+ start_num = std::stoi(str_prefix.substr(base_len));
+ } else {
+ base_name = str_prefix;
+ }
+
+ // Check if the original name is available
+ ffi::String candidate = prefix;
+ if (!name_count_.count(candidate)) {
+ name_count_[candidate] = 0;
+ return candidate;
+ }
+
+ // Generate unique name by incrementing the numeric suffix
+ int counter = (start_num > 0) ? start_num + 1 : 1;
+ while (true) {
+ candidate = ffi::String(base_name + std::to_string(counter));
+ if (!name_count_.count(candidate)) {
+ name_count_[candidate] = 0;
+ return candidate;
+ }
+ ++counter;
}
- name_count_[unique_prefix] = 0;
- return unique_prefix;
}
Review Comment:
I think this review makes sense especially the second. Could you modify the
code like that?
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]