From patchwork Wed Jul 25 20:44:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 10544683 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 27CEE14E2 for ; Wed, 25 Jul 2018 20:46:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 15F5D2A9E7 for ; Wed, 25 Jul 2018 20:46:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0870F2A9EC; Wed, 25 Jul 2018 20:46:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EBEE82A9E7 for ; Wed, 25 Jul 2018 20:46:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731294AbeGYWAR (ORCPT ); Wed, 25 Jul 2018 18:00:17 -0400 Received: from mail-ed1-f67.google.com ([209.85.208.67]:40504 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731168AbeGYWAP (ORCPT ); Wed, 25 Jul 2018 18:00:15 -0400 Received: by mail-ed1-f67.google.com with SMTP id e19-v6so8333557edq.7 for ; Wed, 25 Jul 2018 13:46:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YGR57S52bPf98Q2RyUNjdE8chpASVD4PUz7g8pkgEe4=; b=YG6DviJEJQ+WIh9Tx43Ec+EYiGEWQK5epL2/ipo38PyNGfO95bpKIA1+AhGXcTunTt NxN81S5tl3oTsmsH+QKLev8lyFUA+ydOYYretagPyOJ2oVTk5EUkgqDrcywZdMG+j0y/ OeNTkV7i4us5+UB2D68umKWVZjZiLFNhsUP1u5/VDPDyny1iK0vozx4sKzlMNk2GeqTo ZmwZ9T+rFL65exsMFj95ba1L4jUfGrM63eaOSphjN+wL8QnR3AX3wgN8ucFxFdP1e1aJ yNaKpOxokD3AKvXgj3OB734NgLnUOfApTma+m2YtmoeuZfdEysSnjk4r6s+p6xaiXon2 bWJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=YGR57S52bPf98Q2RyUNjdE8chpASVD4PUz7g8pkgEe4=; b=IVll31eycfwbVNghsMwEflKuOYlJr8I+pMaaI31xRyoBYODEttj6e7kxSPFCwINOKd 0R44aZUr4MQIWEV8txe96QpinKN7QM2P6rjDzLj8Ohu8nP1PirVXgo58AQHvR3OJiHL/ ftYvWo7Jo2OO05qfe1goXdg2W/mvi/fuSVdfmXE0MHhLHwf05uSFhbVPWMB9v6Oj3cuU MBXBHpg5do2Ut2McHufzxwtwD4sR02orStM7hYTyEzzQFbVCVzATg56N7++BxqKdmmkj v1TF12vvo5mX46FAcwOQ1h81viWZWesjdNiKlPCa/BjgRepDS21Y9O5gKnT9UjoSCXSu i7rw== X-Gm-Message-State: AOUpUlF1SZq5z/NU/dwr8f26CWcmUK0i84FYTW9oi+DJd0Gl0Ktld4Xp gRbj805nWvjGmHjBCZUTGGuvcs9D X-Google-Smtp-Source: AAOMgpdSf0xfBW6h8Lo6W659M8YIbx5Sl6pCjTgSGBfPg+wo+/tjMqtULJ4UJgL5+Itppb97kQc9BA== X-Received: by 2002:a50:a186:: with SMTP id 6-v6mr25259253edk.12.1532551610758; Wed, 25 Jul 2018 13:46:50 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:40d9:b300:a08b:7c37:c755:ffe3]) by smtp.gmail.com with ESMTPSA id n64-v6sm11195114edc.49.2018.07.25.13.46.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Jul 2018 13:46:50 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Ramsay Jones , Luc Van Oostenryck Subject: [PATCH v2 4/5] add lookup_ptr_list_entry() Date: Wed, 25 Jul 2018 22:44:40 +0200 Message-Id: <20180725204441.91527-5-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180725204441.91527-1-luc.vanoostenryck@gmail.com> References: <20180725204441.91527-1-luc.vanoostenryck@gmail.com> Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP For liveness analysis, the ptrlists need to be used as sets. IOW, before adding a new element, it's needed to check if it doesn't already belong to the list. This check is currently done, specifically for pseudos, using the list walking macros FOR_EACH_PTR/END_FOR_EACH_PTR. Add a new generic ptrlist function: lookup_ptr_list_entry() which test if a given pointer already belong to the list. Signed-off-by: Luc Van Oostenryck --- linearize.h | 5 +++++ liveness.c | 9 --------- ptrlist.c | 21 +++++++++++++++++++++ ptrlist.h | 1 + 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/linearize.h b/linearize.h index b067b3e84..63a51ff35 100644 --- a/linearize.h +++ b/linearize.h @@ -303,6 +303,11 @@ static inline int remove_pseudo(struct pseudo_list **list, pseudo_t pseudo) return delete_ptr_list_entry((struct ptr_list **)list, pseudo, 0) != 0; } +static inline int pseudo_in_list(struct pseudo_list *list, pseudo_t pseudo) +{ + return lookup_ptr_list_entry((struct ptr_list *)list, pseudo); +} + static inline int bb_terminated(struct basic_block *bb) { struct instruction *insn; diff --git a/liveness.c b/liveness.c index 4c3339f10..d1968ce4b 100644 --- a/liveness.c +++ b/liveness.c @@ -139,15 +139,6 @@ static void track_instruction_usage(struct basic_block *bb, struct instruction * } } -int pseudo_in_list(struct pseudo_list *list, pseudo_t pseudo) -{ - pseudo_t old; - FOR_EACH_PTR(list,old) { - if (old == pseudo) - return 1; - } END_FOR_EACH_PTR(old); - return 0; -} static int liveness_changed; diff --git a/ptrlist.c b/ptrlist.c index ae00b5134..3677a347c 100644 --- a/ptrlist.c +++ b/ptrlist.c @@ -272,6 +272,27 @@ void **__add_ptr_list_tag(struct ptr_list **listp, void *ptr, unsigned long tag) return __add_ptr_list(listp, ptr); } +/// +// test if some entry is already present in a ptrlist +// @list: the head of the list +// @entry: the entry to test +// @return: ``true`` if the entry is already present, ``false`` otherwise. +bool lookup_ptr_list_entry(const struct ptr_list *head, const void *entry) +{ + const struct ptr_list *list = head; + + if (!head) + return false; + do { + int nr = list->nr; + int i; + for (i = 0; i < nr; i++) + if (list->list[i] == entry) + return true; + } while ((list = list->next) != head); + return false; +} + /// // delete an entry from a ptrlist // @list: a pointer to the list diff --git a/ptrlist.h b/ptrlist.h index 176bb0712..2f0234784 100644 --- a/ptrlist.h +++ b/ptrlist.h @@ -33,6 +33,7 @@ void * undo_ptr_list_last(struct ptr_list **head); void * delete_ptr_list_last(struct ptr_list **head); int delete_ptr_list_entry(struct ptr_list **, void *, int); int replace_ptr_list_entry(struct ptr_list **, void *old, void *new, int); +bool lookup_ptr_list_entry(const struct ptr_list *head, const void *entry); extern void sort_list(struct ptr_list **, int (*)(const void *, const void *)); extern void concat_ptr_list(struct ptr_list *a, struct ptr_list **b);