diff mbox series

[5/6] ptrlist: make linearize_ptr_list() generic

Message ID 20210306100552.33784-6-luc.vanoostenryck@gmail.com (mailing list archive)
State Mainlined, archived
Headers show
Series small changes to ptrlist API | expand

Commit Message

Luc Van Oostenryck March 6, 2021, 10:05 a.m. UTC
The ptrlist API has a function to copy the elements of a ptrlist
into an array but it's not typed and thus needs a wrapper (or casts)
for each type it's used for. Also, 'linearize' is confusing since
this is unrelated to Sparse's linearization.

Simplify this by adding a generic (but type-safe) macro for this
(and changing the name): ptr_list_to_array()

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 ptrlist.h  | 6 ++++++
 simplify.c | 4 ++--
 2 files changed, 8 insertions(+), 2 deletions(-)

Comments

Ramsay Jones March 6, 2021, 4:35 p.m. UTC | #1
On 06/03/2021 10:05, Luc Van Oostenryck wrote:
> The ptrlist API has a function to copy the elements of a ptrlist
> into an array but it's not typed and thus needs a wrapper (or casts)
> for each type it's used for. Also, 'linearize' is confusing since
> this is unrelated to Sparse's linearization.
> 
> Simplify this by adding a generic (but type-safe) macro for this
> (and changing the name): ptr_list_to_array()

Hmm, you have removed/renamed all current callers of linearize_ptr_list(),
but you haven't 'changed the name'; you can't, otherwise the new wrapper
macro wouldn't work! ;-)

Maybe, s/and changing the name/with a more descriptive name/

ATB,
Ramsay Jones

> 
> Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
> ---
>  ptrlist.h  | 6 ++++++
>  simplify.c | 4 ++--
>  2 files changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/ptrlist.h b/ptrlist.h
> index 0b06142252f5..5a3dcbeb97ae 100644
> --- a/ptrlist.h
> +++ b/ptrlist.h
> @@ -84,6 +84,12 @@ extern void __free_ptr_list(struct ptr_list **);
>  		(PTRLIST_TYPE(lst)) ptr_list_nth_entry(head, nth);\
>  	})
>  
> +#define ptr_list_to_array(list, array, size) ({				\
> +		struct ptr_list* head = (struct ptr_list*)(list);	\
> +		CHECK_TYPE(list, *array);				\
> +		linearize_ptr_list(head, (void**)array, size);		\
> +	})
> +
>  ////////////////////////////////////////////////////////////////////////
>  // API
>  #define PREPARE_PTR_LIST(head, ptr) \
> diff --git a/simplify.c b/simplify.c
> index 584078ddca89..cf5b3d748808 100644
> --- a/simplify.c
> +++ b/simplify.c
> @@ -83,7 +83,7 @@ static struct basic_block *phi_parent(struct basic_block *source, pseudo_t pseud
>  //	number of element, a positive number if there was
>  //	more than expected and a negative one if less.
>  //
> -// :note: we can't reuse a function like linearize_ptr_list()
> +// :note: we can't reuse ptr_list_to_array() for the phi-sources
>  //	because any VOIDs in the phi-list must be ignored here
>  //	as in this context they mean 'entry has been removed'.
>  static int get_phisources(struct instruction *sources[], int nbr, struct instruction *insn)
> @@ -116,7 +116,7 @@ static int if_convert_phi(struct instruction *insn)
>  	bb = insn->bb;
>  	if (get_phisources(array, 2, insn))
>  		return 0;
> -	if (linearize_ptr_list((struct ptr_list *)bb->parents, (void **)parents, 3) != 2)
> +	if (ptr_list_to_array(bb->parents, parents, 3) != 2)
>  		return 0;
>  	p1 = array[0]->phi_src;
>  	bb1 = array[0]->bb;
>
Luc Van Oostenryck March 6, 2021, 10:05 p.m. UTC | #2
On Sat, Mar 06, 2021 at 04:35:52PM +0000, Ramsay Jones wrote:
> On 06/03/2021 10:05, Luc Van Oostenryck wrote:
> > The ptrlist API has a function to copy the elements of a ptrlist
> > into an array but it's not typed and thus needs a wrapper (or casts)
> > for each type it's used for. Also, 'linearize' is confusing since
> > this is unrelated to Sparse's linearization.
> > 
> > Simplify this by adding a generic (but type-safe) macro for this
> > (and changing the name): ptr_list_to_array()
> 
> Hmm, you have removed/renamed all current callers of linearize_ptr_list(),
> but you haven't 'changed the name'; you can't, otherwise the new wrapper
> macro wouldn't work! ;-)

I've changed the name of the interface. But yes, the message was confusing.

> Maybe, s/and changing the name/with a more descriptive name/

Yes, this is better. Thank you.
-- Luc
diff mbox series

Patch

diff --git a/ptrlist.h b/ptrlist.h
index 0b06142252f5..5a3dcbeb97ae 100644
--- a/ptrlist.h
+++ b/ptrlist.h
@@ -84,6 +84,12 @@  extern void __free_ptr_list(struct ptr_list **);
 		(PTRLIST_TYPE(lst)) ptr_list_nth_entry(head, nth);\
 	})
 
+#define ptr_list_to_array(list, array, size) ({				\
+		struct ptr_list* head = (struct ptr_list*)(list);	\
+		CHECK_TYPE(list, *array);				\
+		linearize_ptr_list(head, (void**)array, size);		\
+	})
+
 ////////////////////////////////////////////////////////////////////////
 // API
 #define PREPARE_PTR_LIST(head, ptr) \
diff --git a/simplify.c b/simplify.c
index 584078ddca89..cf5b3d748808 100644
--- a/simplify.c
+++ b/simplify.c
@@ -83,7 +83,7 @@  static struct basic_block *phi_parent(struct basic_block *source, pseudo_t pseud
 //	number of element, a positive number if there was
 //	more than expected and a negative one if less.
 //
-// :note: we can't reuse a function like linearize_ptr_list()
+// :note: we can't reuse ptr_list_to_array() for the phi-sources
 //	because any VOIDs in the phi-list must be ignored here
 //	as in this context they mean 'entry has been removed'.
 static int get_phisources(struct instruction *sources[], int nbr, struct instruction *insn)
@@ -116,7 +116,7 @@  static int if_convert_phi(struct instruction *insn)
 	bb = insn->bb;
 	if (get_phisources(array, 2, insn))
 		return 0;
-	if (linearize_ptr_list((struct ptr_list *)bb->parents, (void **)parents, 3) != 2)
+	if (ptr_list_to_array(bb->parents, parents, 3) != 2)
 		return 0;
 	p1 = array[0]->phi_src;
 	bb1 = array[0]->bb;