qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/4] target/hexagon: Minor idef-parser cleanup
@ 2024-05-23 12:58 Anton Johansson via
  2024-05-23 12:58 ` [PATCH v4 1/4] target/hexagon: idef-parser remove unused defines Anton Johansson via
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Anton Johansson via @ 2024-05-23 12:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: ale, ltaylorsimpson, bcain

Was running idef-parser with ASAN and noticed we were leaking the
init_list GArray, which is used to hold instruction arguments that may
need initialization.  This patchset fixes the leak, removes unused
macros and undefined functions, and simplifies gen_inst_init_args() to
only handle predicate values.

Changes in v2:
  * Update comment in 3rd patch
  * Follow style guide in 4th patch

Changes in v3/v4:
  * Added reviewed-bys

Anton Johansson (4):
  target/hexagon: idef-parser remove unused defines
  target/hexagon: idef-parser remove undefined functions
  target/hexagon: idef-parser fix leak of init_list
  target/hexagon: idef-parser simplify predicate init

 target/hexagon/idef-parser/idef-parser.h    | 10 ------
 target/hexagon/idef-parser/idef-parser.y    |  2 --
 target/hexagon/idef-parser/parser-helpers.c | 35 +++++++++++++--------
 target/hexagon/idef-parser/parser-helpers.h | 13 --------
 4 files changed, 22 insertions(+), 38 deletions(-)

-- 
2.45.0



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v4 1/4] target/hexagon: idef-parser remove unused defines
  2024-05-23 12:58 [PATCH v4 0/4] target/hexagon: Minor idef-parser cleanup Anton Johansson via
@ 2024-05-23 12:58 ` Anton Johansson via
  2024-06-06  3:14   ` Brian Cain
  2024-05-23 12:58 ` [PATCH v4 2/4] target/hexagon: idef-parser remove undefined functions Anton Johansson via
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Anton Johansson via @ 2024-05-23 12:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: ale, ltaylorsimpson, bcain

Before switching to GArray/g_string_printf we used fixed size arrays for
output buffers and instructions arguments among other things.

Macros defining the sizes of these buffers were left behind, remove
them.

Signed-off-by: Anton Johansson <anjo@rev.ng>
Reviewed-by: Taylor Simpson <ltaylorsimpson@gmail.com>
Reviewed-by: Brian Cain <bcain@quicinc.com>
---
 target/hexagon/idef-parser/idef-parser.h | 10 ----------
 1 file changed, 10 deletions(-)

diff --git a/target/hexagon/idef-parser/idef-parser.h b/target/hexagon/idef-parser/idef-parser.h
index 3faa1deecd..8594cbe3a2 100644
--- a/target/hexagon/idef-parser/idef-parser.h
+++ b/target/hexagon/idef-parser/idef-parser.h
@@ -23,16 +23,6 @@
 #include <stdbool.h>
 #include <glib.h>
 
-#define TCGV_NAME_SIZE 7
-#define MAX_WRITTEN_REGS 32
-#define OFFSET_STR_LEN 32
-#define ALLOC_LIST_LEN 32
-#define ALLOC_NAME_SIZE 32
-#define INIT_LIST_LEN 32
-#define OUT_BUF_LEN (1024 * 1024)
-#define SIGNATURE_BUF_LEN (128 * 1024)
-#define HEADER_BUF_LEN (128 * 1024)
-
 /* Variadic macros to wrap the buffer printing functions */
 #define EMIT(c, ...)                                                           \
     do {                                                                       \
-- 
2.45.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v4 2/4] target/hexagon: idef-parser remove undefined functions
  2024-05-23 12:58 [PATCH v4 0/4] target/hexagon: Minor idef-parser cleanup Anton Johansson via
  2024-05-23 12:58 ` [PATCH v4 1/4] target/hexagon: idef-parser remove unused defines Anton Johansson via
@ 2024-05-23 12:58 ` Anton Johansson via
  2024-05-23 12:59 ` [PATCH v4 3/4] target/hexagon: idef-parser fix leak of init_list Anton Johansson via
  2024-05-23 12:59 ` [PATCH v4 4/4] target/hexagon: idef-parser simplify predicate init Anton Johansson via
  3 siblings, 0 replies; 6+ messages in thread
From: Anton Johansson via @ 2024-05-23 12:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: ale, ltaylorsimpson, bcain

Signed-off-by: Anton Johansson <anjo@rev.ng>
Reviewed-by: Taylor Simpson <ltaylorsimpson@gmail.com>
Reviewed-by: Brian Cain <bcain@quicinc.com>
---
 target/hexagon/idef-parser/parser-helpers.h | 13 -------------
 1 file changed, 13 deletions(-)

diff --git a/target/hexagon/idef-parser/parser-helpers.h b/target/hexagon/idef-parser/parser-helpers.h
index 7c58087169..2087d534a9 100644
--- a/target/hexagon/idef-parser/parser-helpers.h
+++ b/target/hexagon/idef-parser/parser-helpers.h
@@ -143,8 +143,6 @@ void commit(Context *c);
 
 #define OUT(c, locp, ...) FOR_EACH((c), (locp), OUT_IMPL, __VA_ARGS__)
 
-const char *cmp_swap(Context *c, YYLTYPE *locp, const char *type);
-
 /**
  * Temporary values creation
  */
@@ -236,8 +234,6 @@ HexValue gen_extract_op(Context *c,
                         HexValue *index,
                         HexExtract *extract);
 
-HexValue gen_read_reg(Context *c, YYLTYPE *locp, HexValue *reg);
-
 void gen_write_reg(Context *c, YYLTYPE *locp, HexValue *reg, HexValue *value);
 
 void gen_assign(Context *c,
@@ -274,13 +270,6 @@ HexValue gen_ctpop_op(Context *c, YYLTYPE *locp, HexValue *src);
 
 HexValue gen_rotl(Context *c, YYLTYPE *locp, HexValue *src, HexValue *n);
 
-HexValue gen_deinterleave(Context *c, YYLTYPE *locp, HexValue *mixed);
-
-HexValue gen_interleave(Context *c,
-                        YYLTYPE *locp,
-                        HexValue *odd,
-                        HexValue *even);
-
 HexValue gen_carry_from_add(Context *c,
                             YYLTYPE *locp,
                             HexValue *op1,
@@ -349,8 +338,6 @@ HexValue gen_rvalue_ternary(Context *c, YYLTYPE *locp, HexValue *cond,
 
 const char *cond_to_str(TCGCond cond);
 
-void emit_header(Context *c);
-
 void emit_arg(Context *c, YYLTYPE *locp, HexValue *arg);
 
 void emit_footer(Context *c);
-- 
2.45.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v4 3/4] target/hexagon: idef-parser fix leak of init_list
  2024-05-23 12:58 [PATCH v4 0/4] target/hexagon: Minor idef-parser cleanup Anton Johansson via
  2024-05-23 12:58 ` [PATCH v4 1/4] target/hexagon: idef-parser remove unused defines Anton Johansson via
  2024-05-23 12:58 ` [PATCH v4 2/4] target/hexagon: idef-parser remove undefined functions Anton Johansson via
@ 2024-05-23 12:59 ` Anton Johansson via
  2024-05-23 12:59 ` [PATCH v4 4/4] target/hexagon: idef-parser simplify predicate init Anton Johansson via
  3 siblings, 0 replies; 6+ messages in thread
From: Anton Johansson via @ 2024-05-23 12:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: ale, ltaylorsimpson, bcain

gen_inst_init_args() is called for instructions using a predicate as an
rvalue. Upon first call, the list of arguments which might need
initialization init_list is freed to indicate that they have been
processed. For instructions without an rvalue predicate,
gen_inst_init_args() isn't called and init_list will never be freed.

Free init_list from free_instruction() if it hasn't already been freed.
A comment in free_instruction is also updated.

Signed-off-by: Anton Johansson <anjo@rev.ng>
Reviewed-by: Taylor Simpson <ltaylorsimpson@gmail.com>
Reviewed-by: Brian Cain <bcain@quicinc.com>
---
 target/hexagon/idef-parser/parser-helpers.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/target/hexagon/idef-parser/parser-helpers.c b/target/hexagon/idef-parser/parser-helpers.c
index 95f2b43076..c150c308be 100644
--- a/target/hexagon/idef-parser/parser-helpers.c
+++ b/target/hexagon/idef-parser/parser-helpers.c
@@ -2121,9 +2121,16 @@ void free_instruction(Context *c)
         g_string_free(g_array_index(c->inst.strings, GString*, i), TRUE);
     }
     g_array_free(c->inst.strings, TRUE);
+    /*
+     * Free list of arguments that might need initialization, if they haven't
+     * already been freed.
+     */
+    if (c->inst.init_list) {
+        g_array_free(c->inst.init_list, TRUE);
+    }
     /* Free INAME token value */
     g_string_free(c->inst.name, TRUE);
-    /* Free variables and registers */
+    /* Free declared TCGv variables */
     g_array_free(c->inst.allocated, TRUE);
     /* Initialize instruction-specific portion of the context */
     memset(&(c->inst), 0, sizeof(Inst));
-- 
2.45.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v4 4/4] target/hexagon: idef-parser simplify predicate init
  2024-05-23 12:58 [PATCH v4 0/4] target/hexagon: Minor idef-parser cleanup Anton Johansson via
                   ` (2 preceding siblings ...)
  2024-05-23 12:59 ` [PATCH v4 3/4] target/hexagon: idef-parser fix leak of init_list Anton Johansson via
@ 2024-05-23 12:59 ` Anton Johansson via
  3 siblings, 0 replies; 6+ messages in thread
From: Anton Johansson via @ 2024-05-23 12:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: ale, ltaylorsimpson, bcain

Only predicate instruction arguments need to be initialized by
idef-parser. This commit removes registers from the init_list and
simplifies gen_inst_init_args() slightly.

Signed-off-by: Anton Johansson <anjo@rev.ng>
Reviewed-by: Taylor Simpson <ltaylorsimpson@gmail.com>
Reviewed-by: Brian Cain <bcain@quicinc.com>
---
 target/hexagon/idef-parser/idef-parser.y    |  2 --
 target/hexagon/idef-parser/parser-helpers.c | 26 +++++++++++----------
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/target/hexagon/idef-parser/idef-parser.y b/target/hexagon/idef-parser/idef-parser.y
index cd2612eb8c..9ffb9f9699 100644
--- a/target/hexagon/idef-parser/idef-parser.y
+++ b/target/hexagon/idef-parser/idef-parser.y
@@ -233,8 +233,6 @@ code : '{' statements '}'
 argument_decl : REG
                 {
                     emit_arg(c, &@1, &$1);
-                    /* Enqueue register into initialization list */
-                    g_array_append_val(c->inst.init_list, $1);
                 }
               | PRED
                 {
diff --git a/target/hexagon/idef-parser/parser-helpers.c b/target/hexagon/idef-parser/parser-helpers.c
index c150c308be..a7dcd85fe4 100644
--- a/target/hexagon/idef-parser/parser-helpers.c
+++ b/target/hexagon/idef-parser/parser-helpers.c
@@ -1652,26 +1652,28 @@ void gen_inst(Context *c, GString *iname)
 
 
 /*
- * Initialize declared but uninitialized registers, but only for
- * non-conditional instructions
+ * Initialize declared but uninitialized instruction arguments. Only needed for
+ * predicate arguments, initialization of registers is handled by the Hexagon
+ * frontend.
  */
 void gen_inst_init_args(Context *c, YYLTYPE *locp)
 {
+    HexValue *val = NULL;
+    char suffix;
+
+    /* If init_list is NULL arguments have already been initialized */
     if (!c->inst.init_list) {
         return;
     }
 
     for (unsigned i = 0; i < c->inst.init_list->len; i++) {
-        HexValue *val = &g_array_index(c->inst.init_list, HexValue, i);
-        if (val->type == REGISTER_ARG) {
-            /* Nothing to do here */
-        } else if (val->type == PREDICATE) {
-            char suffix = val->is_dotnew ? 'N' : 'V';
-            EMIT_HEAD(c, "tcg_gen_movi_i%u(P%c%c, 0);\n", val->bit_width,
-                      val->pred.id, suffix);
-        } else {
-            yyassert(c, locp, false, "Invalid arg type!");
-        }
+        val = &g_array_index(c->inst.init_list, HexValue, i);
+        suffix = val->is_dotnew ? 'N' : 'V';
+        yyassert(c, locp, val->type == PREDICATE,
+                 "Only predicates need to be initialized!");
+        yyassert(c, locp, val->bit_width == 32,
+                 "Predicates should always be 32 bits");
+        EMIT_HEAD(c, "tcg_gen_movi_i32(P%c%c, 0);\n", val->pred.id, suffix);
     }
 
     /* Free argument init list once we have initialized everything */
-- 
2.45.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v4 1/4] target/hexagon: idef-parser remove unused defines
  2024-05-23 12:58 ` [PATCH v4 1/4] target/hexagon: idef-parser remove unused defines Anton Johansson via
@ 2024-06-06  3:14   ` Brian Cain
  0 siblings, 0 replies; 6+ messages in thread
From: Brian Cain @ 2024-06-06  3:14 UTC (permalink / raw)
  To: Anton Johansson, qemu-devel; +Cc: ale, ltaylorsimpson, bcain


On 5/23/2024 7:58 AM, Anton Johansson via wrote:
> Before switching to GArray/g_string_printf we used fixed size arrays for
> output buffers and instructions arguments among other things.
>
> Macros defining the sizes of these buffers were left behind, remove
> them.
>
> Signed-off-by: Anton Johansson <anjo@rev.ng>
> Reviewed-by: Taylor Simpson <ltaylorsimpson@gmail.com>
> Reviewed-by: Brian Cain <bcain@quicinc.com>
> ---

Queued -- at https://github.com/quic/qemu/tree/hex.next


>   target/hexagon/idef-parser/idef-parser.h | 10 ----------
>   1 file changed, 10 deletions(-)
>
> diff --git a/target/hexagon/idef-parser/idef-parser.h b/target/hexagon/idef-parser/idef-parser.h
> index 3faa1deecd..8594cbe3a2 100644
> --- a/target/hexagon/idef-parser/idef-parser.h
> +++ b/target/hexagon/idef-parser/idef-parser.h
> @@ -23,16 +23,6 @@
>   #include <stdbool.h>
>   #include <glib.h>
>   
> -#define TCGV_NAME_SIZE 7
> -#define MAX_WRITTEN_REGS 32
> -#define OFFSET_STR_LEN 32
> -#define ALLOC_LIST_LEN 32
> -#define ALLOC_NAME_SIZE 32
> -#define INIT_LIST_LEN 32
> -#define OUT_BUF_LEN (1024 * 1024)
> -#define SIGNATURE_BUF_LEN (128 * 1024)
> -#define HEADER_BUF_LEN (128 * 1024)
> -
>   /* Variadic macros to wrap the buffer printing functions */
>   #define EMIT(c, ...)                                                           \
>       do {                                                                       \


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-06-06  3:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-23 12:58 [PATCH v4 0/4] target/hexagon: Minor idef-parser cleanup Anton Johansson via
2024-05-23 12:58 ` [PATCH v4 1/4] target/hexagon: idef-parser remove unused defines Anton Johansson via
2024-06-06  3:14   ` Brian Cain
2024-05-23 12:58 ` [PATCH v4 2/4] target/hexagon: idef-parser remove undefined functions Anton Johansson via
2024-05-23 12:59 ` [PATCH v4 3/4] target/hexagon: idef-parser fix leak of init_list Anton Johansson via
2024-05-23 12:59 ` [PATCH v4 4/4] target/hexagon: idef-parser simplify predicate init Anton Johansson via

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).