public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: new __builtin_choose_type (patch) (new builtin_equal_types patch)
@ 2001-10-04 19:33 mike stump
  2001-10-05  3:01 ` Jakub Jelinek
  0 siblings, 1 reply; 19+ messages in thread
From: mike stump @ 2001-10-04 19:33 UTC (permalink / raw)
  To: kenner; +Cc: gcc

> Date: Thu, 4 Oct 01 22:25:34 EDT
> From: kenner@vlsi1.ultra.nyu.edu (Richard Kenner)
> To: mrs@windriver.com
> Cc: gcc@gcc.gnu.org

>     In a frontend, we never play with modes...  The type can be found in
>     TREE_TYPE, and you should just use it.  This is frontend code.

> Mostly, but not totally, true.  When stripping NOPs to look for
> things, it's not uncommon for frontends to only strip NOPs that
> don't change the mode.

Sure, but you're going into way too much detail here.  I'd just add,
just in case people don't see the difference, bool != int, from a type
system perspective, it doesn't matter if they both are 32 bits.
Comparing modes can have them be the same.  Comparing types, they
never are, well, cept maybe in C when you use a typedef.

^ permalink raw reply	[flat|nested] 19+ messages in thread
* Re: new __builtin_choose_type (patch) (new builtin_equal_types patch)
@ 2001-10-05 11:47 mike stump
  2001-10-05 11:52 ` Joseph S. Myers
  0 siblings, 1 reply; 19+ messages in thread
From: mike stump @ 2001-10-05 11:47 UTC (permalink / raw)
  To: jakub, jsm28; +Cc: gcc

> Date: Fri, 5 Oct 2001 12:02:32 +0100 (BST)
> From: "Joseph S. Myers" <jsm28@cam.ac.uk>
> To: Jakub Jelinek <jakub@redhat.com>
> cc: <gcc@gcc.gnu.org>

> I think the following (which would need to be grammer symbols rather than
> simple built-in functions) should suffice:

Ick!

There isn't much wrong with __builtin_same_type (*(T *)0, *(int*)0)...
One can compare double to int, if one wants...  I don't favor a
grammar extension, since a trivial work around exists.  Since these
things are not `evaluated' we aren't actually dereferencing 0.  This
allows these things to fit more naturally into the present framework.

^ permalink raw reply	[flat|nested] 19+ messages in thread
* Re: new __builtin_choose_type (patch) (new builtin_equal_types patch)
@ 2001-10-04 19:19 Richard Kenner
  0 siblings, 0 replies; 19+ messages in thread
From: Richard Kenner @ 2001-10-04 19:19 UTC (permalink / raw)
  To: mrs; +Cc: gcc

    In a frontend, we never play with modes...  The type can be found in
    TREE_TYPE, and you should just use it.  This is frontend code.

Mostly, but not totally, true.  When stripping NOPs to look for
things, it's not uncommon for frontends to only strip NOPs that don't
change the mode.

^ permalink raw reply	[flat|nested] 19+ messages in thread
* Re: new __builtin_choose_type (patch) (new builtin_equal_types patch)
@ 2001-10-04 19:09 mike stump
  0 siblings, 0 replies; 19+ messages in thread
From: mike stump @ 2001-10-04 19:09 UTC (permalink / raw)
  To: aldyh, magfr; +Cc: gcc

> From: Aldy Hernandez <aldyh@redhat.com>
> To: Magnus Fromreide <magfr@lysator.liu.se>
> Cc: gcc@gcc.gnu.org
> Date: 03 Oct 2001 23:19:45 -0400

> On Wed, 2001-10-03 at 04:15, Magnus Fromreide wrote:
> > It is my feeling that it would be more general and cleaner to do something
> > along the lines of
> > 
> > _Bool __builtin_equal_types(arg|type, arg|type)
> > 
> > that doesn't evaluate the arguments if they are expressions and answers
> > the question of wether they are of the same type.

> is everyone ok with this approach?

I like it...  A simple extension, easy to document and understand,
possibly generally useful, trivial to maintain.

> + static rtx
> + expand_builtin_equal_types (exp, target)
> +      tree exp;
> +      rtx target;
> + {
> +   tree arg = TREE_OPERAND (exp, 1);
> +   tree chain;
> +   enum machine_mode exp0_mode, exp1_mode;
> + 
> +   if (!arg)
> +     return const0_rtx;
> + 
> +   chain = TREE_CHAIN (arg);
> +   arg = TREE_VALUE (arg);
> + 
> +   /* Strip off all NOPs.  */
> +   while (TREE_CODE (arg) == NOP_EXPR
> + 	 || TREE_CODE (arg) == CONVERT_EXPR
> + 	 || TREE_CODE (arg) == NON_LVALUE_EXPR
> + 	 || TREE_CODE (arg) == INDIRECT_REF)
> +     arg = TREE_OPERAND (arg, 0);
> + 
> +   /* Get <exp0> type.  */
> +   exp0_mode = TYPE_MODE (TREE_TYPE (arg));

In a frontend, we never play with modes...  The type can be found in
TREE_TYPE, and you should just use it.  This is frontend code.

> +   /* Get <exp1> type.  */
> +   arg = TREE_VALUE (chain);
> +   if (!arg)
> +     error ("missing argument in `__builtin_equal_types'");
> +   /* Strip off all NOPs.  */
> +   while (TREE_CODE (arg) == NOP_EXPR
> + 	 || TREE_CODE (arg) == CONVERT_EXPR
> + 	 || TREE_CODE (arg) == NON_LVALUE_EXPR
> + 	 || TREE_CODE (arg) == INDIRECT_REF)
> +     arg = TREE_OPERAND (arg, 0);

Again, this is wrong.  We don't peek under peoples dresses.  The type
can be found in TREE_TYPE of arg, that is is't type, no other value
is, or is as good.  The tree type inside one of these things need not
match the outer type.

> +   exp1_mode = TYPE_MODE (TREE_TYPE (arg));

Again, no modes in frontend code.


Now, the hard part, which someone eluded to, is a const int == int?
If the are !=, the you want to just compare the types.  If they are
==, then you want to use TYPE_MAIN_VARIANT on them both before
comparing.  Also, the comparison will be tricky, see
cp/typeck.c:comptypes for all the hair for one language.  You might
have to have a callback for it, as the backend is kinda stupid.

Also, since each frontend can have a different notion of same type,
you'll have to come up with enough documentation to exactly describe
what you mean.

^ permalink raw reply	[flat|nested] 19+ messages in thread
* Re: new __builtin_choose_type (patch)
@ 2001-10-03  1:15 Magnus Fromreide
  2001-10-03 20:16 ` new __builtin_choose_type (patch) (new builtin_equal_typespatch) Aldy Hernandez
  0 siblings, 1 reply; 19+ messages in thread
From: Magnus Fromreide @ 2001-10-03  1:15 UTC (permalink / raw)
  To: Aldy Hernandez; +Cc: gcc

It is my feeling that it would be more general and cleaner to do something
along the lines of

_Bool __builtin_equal_types(arg|type, arg|type)

that doesn't evaluate the arguments if they are expressions and answers
the question of wether they are of the same type.

Usage examples:

__builtin_equal_types(x, y) ? no() : x = 10;
if(__builtin_equal_types(x, y))
  {
  }
else
  {
  }

The part i react most against is that it implements a new code path
selection mechanism that is unlike all previously seen in C.

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2001-10-08 12:46 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-04 19:33 new __builtin_choose_type (patch) (new builtin_equal_types patch) mike stump
2001-10-05  3:01 ` Jakub Jelinek
2001-10-05  4:02   ` Joseph S. Myers
2001-10-05 16:14     ` Richard Henderson
2001-10-05 16:38       ` Joseph S. Myers
2001-10-05 16:57         ` Richard Henderson
2001-10-07 16:56     ` Aldy Hernandez
2001-10-07 17:06       ` Joseph S. Myers
2001-10-07 19:36         ` new __builtin_choose_type (patch) (new builtin_equal_typespatch) Aldy Hernandez
2001-10-08  3:46           ` new __builtin_choose_type (patch) (new builtin_equal_types patch) Joseph S. Myers
2001-10-08 12:46             ` new __builtin_choose_type (patch) (new builtin_equal_typespatch) Mark Mitchell
  -- strict thread matches above, loose matches on Subject: below --
2001-10-05 11:47 new __builtin_choose_type (patch) (new builtin_equal_types patch) mike stump
2001-10-05 11:52 ` Joseph S. Myers
2001-10-04 19:19 Richard Kenner
2001-10-04 19:09 mike stump
2001-10-03  1:15 new __builtin_choose_type (patch) Magnus Fromreide
2001-10-03 20:16 ` new __builtin_choose_type (patch) (new builtin_equal_typespatch) Aldy Hernandez
2001-10-03 20:33   ` new __builtin_choose_type (patch) (new builtin_equal_types patch) Stan Shebs
2001-10-03 20:53   ` Daniel Jacobowitz
2001-10-04  6:02     ` Joseph S. Myers
2001-10-05 16:04   ` Richard Henderson

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 read-only IMAP folder(s) and NNTP newsgroup(s).