Skip to content

Commit

Permalink
ptrlist: make linearize_ptr_list() generic
Browse files Browse the repository at this point in the history
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
with a more descriptive name: ptr_list_to_array()

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
  • Loading branch information
lucvoo committed Mar 6, 2021
1 parent a69f8d7 commit c50f527
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions ptrlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down
4 changes: 2 additions & 2 deletions simplify.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit c50f527

Please sign in to comment.