mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Merge pull request #114 from Shopify/yjit-dup-comments
YJIT: Avoid adding duplicate code comments
This commit is contained in:
parent
23f88957e6
commit
33c975b813
2 changed files with 19 additions and 2 deletions
|
@ -218,8 +218,25 @@ _counted_side_exit(uint8_t *existing_side_exit, int64_t *counter)
|
||||||
return start;
|
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
|
// 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;
|
yjit_comment_array_t yjit_code_comments;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -70,7 +70,7 @@ YJIT_DECLARE_COUNTERS(
|
||||||
#undef YJIT_DECLARE_COUNTERS
|
#undef YJIT_DECLARE_COUNTERS
|
||||||
|
|
||||||
struct yjit_comment {
|
struct yjit_comment {
|
||||||
int32_t offset;
|
uint32_t offset;
|
||||||
const char *comment;
|
const char *comment;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue