[前][次][番号順一覧][スレッド一覧]

ruby-changes:69008

From: Maxime <ko1@a...>
Date: Thu, 21 Oct 2021 08:19:40 +0900 (JST)
Subject: [ruby-changes:69008] 33c975b813 (master): Merge pull request #114 from Shopify/yjit-dup-comments

https://git.ruby-lang.org/ruby.git/commit/?id=33c975b813

From 33c975b813a2be9fb02e526b7a63096dff385614 Mon Sep 17 00:00:00 2001
From: Maxime Chevalier-Boisvert <maximechevalierb@g...>
Date: Mon, 19 Apr 2021 15:29:48 -0400
Subject: Merge pull request #114 from Shopify/yjit-dup-comments

YJIT: Avoid adding duplicate code comments
---
 yjit_codegen.c | 19 ++++++++++++++++++-
 yjit_iface.h   |  2 +-
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/yjit_codegen.c b/yjit_codegen.c
index 42ed63b3de..8d4cd02677 100644
--- a/yjit_codegen.c
+++ b/yjit_codegen.c
@@ -218,8 +218,25 @@ _counted_side_exit(uint8_t *existing_side_exit, int64_t *counter) https://github.com/ruby/ruby/blob/trunk/yjit_codegen.c#L218
     return start;
 }
 
+// Add a comment at the current position in the code block
+static void
+_add_comment(codeblock_t* cb, const char* comment_str)
+{
+    // Avoid adding duplicate comment strings (can happen due to deferred codegen)
+    size_t num_comments = rb_darray_size(yjit_code_comments);
+    if (num_comments > 0) {
+        struct yjit_comment last_comment = rb_darray_get(yjit_code_comments, num_comments - 1);
+        if (last_comment.offset == cb->write_pos && strcmp(last_comment.comment, comment_str) == 0) {
+            return;
+        }
+    }
+
+    struct yjit_comment new_comment = (struct yjit_comment){ cb->write_pos, comment_str };
+    rb_darray_append(&yjit_code_comments, new_comment);
+}
+
 // Comments for generated machine code
-#define ADD_COMMENT(cb, comment) rb_darray_append(&yjit_code_comments, ((struct yjit_comment){(cb)->write_pos, (comment)}))
+#define ADD_COMMENT(cb, comment) _add_comment((cb), (comment))
 yjit_comment_array_t yjit_code_comments;
 
 #else
diff --git a/yjit_iface.h b/yjit_iface.h
index 14992a0be8..cc8d3f7012 100644
--- a/yjit_iface.h
+++ b/yjit_iface.h
@@ -70,7 +70,7 @@ YJIT_DECLARE_COUNTERS( https://github.com/ruby/ruby/blob/trunk/yjit_iface.h#L70
 #undef YJIT_DECLARE_COUNTERS
 
 struct yjit_comment {
-    int32_t offset;
+    uint32_t offset;
     const char *comment;
 };
 
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]