From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Christopher Li <sparse@chrisli.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [RFC,original PATCH] CSE: let equivalent cast hash & compare identically
Date: Fri, 17 Feb 2017 01:06:08 +0100 [thread overview]
Message-ID: <20170217000608.6433-2-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20170217000608.6433-1-luc.vanoostenryck@gmail.com>
---
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");
--
2.11.0
next prev parent reply other threads:[~2017-02-17 0:06 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-17 0:06 [RFC] CSE: relax type checking in hashing/compare Luc Van Oostenryck
2017-02-17 0:06 ` Luc Van Oostenryck [this message]
2017-02-27 8:09 ` Christopher Li
2017-02-27 8:11 ` Christopher Li
2017-02-27 9:40 ` Luc Van Oostenryck
2017-04-19 0:32 ` Christopher Li
2017-04-19 16:32 ` 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=20170217000608.6433-2-luc.vanoostenryck@gmail.com \
--to=luc.vanoostenryck@gmail.com \
--cc=linux-sparse@vger.kernel.org \
--cc=sparse@chrisli.org \
--cc=torvalds@linux-foundation.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).