From patchwork Fri Feb 17 00:06:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 9578543 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7E76360244 for ; Fri, 17 Feb 2017 00:06:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6F81A28673 for ; Fri, 17 Feb 2017 00:06:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 64699286A3; Fri, 17 Feb 2017 00:06:19 +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=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, 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 01BD428673 for ; Fri, 17 Feb 2017 00:06:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751801AbdBQAGS (ORCPT ); Thu, 16 Feb 2017 19:06:18 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:34621 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752688AbdBQAGR (ORCPT ); Thu, 16 Feb 2017 19:06:17 -0500 Received: by mail-wm0-f66.google.com with SMTP id c85so44433wmi.1 for ; Thu, 16 Feb 2017 16:06:16 -0800 (PST) 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=purIq1iH/H8HKPOZ9qqXskxIgn8v3Vun789EofymRE0=; b=VTmQO/S2XnvyM+4wwaYHNuhK0XRpV3mfS+iJNBQpG///TIaOCxnU5IMWM76CpygN8W sPbbU3K9m25WrZt6Lm5Otr/y222rwK3SFdxhDjz9Tnip+TGAmNJc7ZvY+FSpgKHFvkdP wR5wWaJwJUsPG571U8LIvQZgN3aLvQ7hOSBk74PL216ja8VLhDQjbz9ZZvTpm57qthMr ptZmUuCfdUbqdyT3hDvSl7uY0jpIiEeN7ESm+FBaC076G4XVp3szoyW8GRbUjyX1UIcZ OY45u2NNuvzURd0ME3PUts8zcGRxG15E3tZWxofmO88YTWHnHeKgrpGiJEMLNjX6ZpJl E/Rw== 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=purIq1iH/H8HKPOZ9qqXskxIgn8v3Vun789EofymRE0=; b=RP26dGFMUHdi2ldaAnyq+OsmoX1bGuubD+TgY1q68kay4QliJZJFiobMtXA/9Z1a+Y TUR9yOFWR7h35aPevhgbfOLSZXqbxAjsLjErBOE7Y99K7aHBjQLi8t4Xk5wWO4+3VXLn V+B7wN3W4wrfpCvzpOk4fMzOcsIjSVF7JMS/dmZrShcMm3rr5/5yxyIUxmY74hXZZ/eQ S6NZXTM6rq4C8tEN461C3Iro0KvaBSBazrj5P4hOjRtMoI8e0BDFUscI0ZD/GNZY9EX5 G66MV5l2kKrUpqnCvfw2GcTslN/M38pC0i3dxoS8fb19k3P+Ak5BYZHHwWlaJkuqR8Rv GF9A== X-Gm-Message-State: AMke39nbOzmWqWpAar5/f9ER5coKvQENo4tQJkJw6/kqB48EdFXmYswGsamYcT8WX0Ne0w== X-Received: by 10.28.156.151 with SMTP id f145mr40033wme.8.1487289975784; Thu, 16 Feb 2017 16:06:15 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:82f:a300:5964:5014:4d9b:afe1]) by smtp.gmail.com with ESMTPSA id c133sm47686wmd.13.2017.02.16.16.06.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Feb 2017 16:06:15 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Christopher Li , Linus Torvalds , Luc Van Oostenryck Subject: [RFC, original PATCH] CSE: let equivalent cast hash & compare identically Date: Fri, 17 Feb 2017 01:06:08 +0100 Message-Id: <20170217000608.6433-2-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170217000608.6433-1-luc.vanoostenryck@gmail.com> References: <20170217000608.6433-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 --- cse.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 64 insertions(+), 14 deletions(-) diff --git a/cse.c b/cse.c index 89812afae..aab6bc7a4 100644 --- a/cse.c +++ b/cse.c @@ -34,6 +34,49 @@ static int phi_compare(pseudo_t phi1, pseudo_t phi2) return 0; } +// for cast's hashing & comparison +struct typeinfo { + struct symbol *type; + unsigned int size; + int kind; +}; + +static void get_typeinfo(struct symbol *type, struct typeinfo *info) +{ + struct symbol *basetype; + +redo: + basetype = type->ctype.base_type; + switch (type->type) { + case SYM_NODE: + type = basetype; + goto redo; + + case SYM_BASETYPE: + if (basetype == &int_ctype) + break; + if (basetype == &fp_type) + break; + basetype = type; + break; + + case SYM_ENUM: + case SYM_BITFIELD: + case SYM_PTR: + case SYM_FN: + case SYM_ARRAY: + break; + + default: + basetype = type; + break; + } + + info->type = basetype; + info->size = type->bit_size; + info->kind = type->type; + return; +} static void clean_up_one_instruction(struct basic_block *bb, struct instruction *insn) { @@ -90,16 +133,16 @@ static void clean_up_one_instruction(struct basic_block *bb, struct instruction case OP_CAST: case OP_SCAST: - case OP_PTRCAST: - /* - * This is crap! Many "orig_types" are the - * same as far as casts go, we should generate - * some kind of "type hash" that is identical - * for identical casts - */ - hash += hashval(insn->orig_type); + case OP_PTRCAST: { + struct typeinfo info; + + get_typeinfo(insn->orig_type, &info); + hash += hashval(info.type); + hash += hashval(info.size); + hash += hashval(info.kind); hash += hashval(insn->src); break; + } /* Other */ case OP_PHI: { @@ -234,15 +277,22 @@ static int insn_compare(const void *_i1, const void *_i2) case OP_CAST: case OP_SCAST: - case OP_PTRCAST: - /* - * This is crap! See the comments on hashing. - */ - if (i1->orig_type != i2->orig_type) - return i1->orig_type < i2->orig_type ? -1 : 1; + case OP_PTRCAST: { + struct typeinfo info1, info2; + + get_typeinfo(i1->orig_type, &info1); + get_typeinfo(i2->orig_type, &info2); + if (i1->src != i2->src) return i1->src < i2->src ? -1 : 1; + if (info1.type != info2.type) + return info1.type < info2.type ? -1 : 1; + if (info1.size != info2.size) + return info1.size < info2.size ? -1 : 1; + if (info1.kind != info2.kind) + return info1.kind < info2.kind ? -1 : 1; break; + } default: warning(i1->pos, "bad instruction on hash chain");