From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 5/6] ptrlist: make linearize_ptr_list() generic
Date: Sat, 6 Mar 2021 11:05:51 +0100 [thread overview]
Message-ID: <20210306100552.33784-6-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20210306100552.33784-1-luc.vanoostenryck@gmail.com>
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(-)
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;
--
2.30.0
next prev parent reply other threads:[~2021-03-06 10:07 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-06 10:05 [PATCH 0/6] small changes to ptrlist API Luc Van Oostenryck
2021-03-06 10:05 ` [PATCH 1/6] ptrlist: ~fix TYPEOF() Luc Van Oostenryck
2021-03-06 16:19 ` Ramsay Jones
2021-03-06 10:05 ` [PATCH 2/6] ptrlist: change TYPEOF() into PTRLIST_TYPE() Luc Van Oostenryck
2021-03-06 16:20 ` Ramsay Jones
2021-03-06 10:05 ` [PATCH 3/6] ptrlist: add pop_ptr_list() Luc Van Oostenryck
2021-03-06 16:22 ` Ramsay Jones
2021-03-06 10:05 ` [PATCH 4/6] ptrlist: use ptr_list_nth() instead of linearize_ptr_list() Luc Van Oostenryck
2021-03-06 16:24 ` Ramsay Jones
2021-03-06 10:05 ` Luc Van Oostenryck [this message]
2021-03-06 16:35 ` [PATCH 5/6] ptrlist: make linearize_ptr_list() generic Ramsay Jones
2021-03-06 22:05 ` Luc Van Oostenryck
2021-03-06 10:05 ` [PATCH 6/6] ptrlist: change return value of linearize_ptr_list()/ptr_list_to_array() Luc Van Oostenryck
2021-03-06 16:43 ` Ramsay Jones
2021-03-06 17:46 ` Luc Van Oostenryck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210306100552.33784-6-luc.vanoostenryck@gmail.com \
--to=luc.vanoostenryck@gmail.com \
--cc=linux-sparse@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).