All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christopher Li <sparse@chrisli.org>
To: Johannes Berg <johannes@sipsolutions.net>
Cc: Linux-Sparse <linux-sparse@vger.kernel.org>
Subject: Re: [PATCH v2] implement constant-folding in __builtin_bswap*()
Date: Tue, 22 Nov 2016 19:13:11 +0800	[thread overview]
Message-ID: <CANeU7QmSSPT9cq1fNqUxqk5DNWDn7RNLjKnFVdKUdJtCrqfBLg@mail.gmail.com> (raw)
In-Reply-To: <1479721551.8662.10.camel@sipsolutions.net>

On Mon, Nov 21, 2016 at 5:45 PM, Johannes Berg
<johannes@sipsolutions.net> wrote:
> Yes, that'd make some sense. I have no idea how to pull it off though

I take a brief look.

It seems that you need to implement a symbol with ".expand" implement as
"expand_bswap", similar to "expand_constant_p".

Later in in "eval_init_table", just add one entry for __builtin_bswap.
eval_init_table[] = {
{ "__builtin_constant_p", &builtin_fn_type, MOD_TOPLEVEL, &constant_p_op },
{ "__builtin_safe_p", &builtin_fn_type, MOD_TOPLEVEL, &safe_p_op },
{ "__builtin_warning", &builtin_fn_type, MOD_TOPLEVEL, &warning_op },
{ "__builtin_expect", &builtin_fn_type, MOD_TOPLEVEL, &expect_op },
{ "__builtin_choose_expr", &builtin_fn_type, MOD_TOPLEVEL, &choose_op },
{ NULL, NULL, 0 }
};

As you can see in "expand_call", the cost of arguments is zero
if all arguments are constant.

The function "expand_symbol_call" even have the comment about expanding
the builtins there.

In side the "expand_bswap", it should abort if cost is not zero.
It means arguments are not constant, this expression can't
expand into a constant value.

Otherwise, expand_bswap should proceed to calculate the return
value of the bswap call and rewrite the call expression into a constant.
Some what similar to the "__builtin_constant_p".

I will see if I can hack up some thing very quick.

Chris

  reply	other threads:[~2016-11-22 11:13 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-17  9:55 [PATCH v2] implement constant-folding in __builtin_bswap*() Johannes Berg
2016-11-21  2:38 ` Christopher Li
2016-11-21  9:45   ` Johannes Berg
2016-11-22 11:13     ` Christopher Li [this message]
2016-11-22 11:39       ` Christopher Li
2016-11-22 13:15       ` Luc Van Oostenryck
2016-11-22 16:32         ` Christopher Li
2016-11-22 17:12           ` Luc Van Oostenryck
2016-11-23  1:23             ` Christopher Li
2016-11-22 20:16           ` Luc Van Oostenryck
2016-11-23  1:25             ` Christopher Li
2016-11-23 20:38               ` [PATCH] add test case for builtin bswap with constant args Luc Van Oostenryck
2016-11-24  0:17                 ` Christopher Li
2016-11-24  5:30                 ` Christopher Li
2016-11-24 13:00                   ` Luc Van Oostenryck
2016-11-23 20:48               ` [PATCH v2] implement constant-folding in __builtin_bswap*() Luc Van Oostenryck
2016-11-24  0:56                 ` Christopher Li
2016-11-24  0:58                   ` Christopher Li
2016-11-24  1:36                     ` Luc Van Oostenryck
2016-11-24  3:17                       ` Christopher Li
2016-11-24  1:31                   ` Luc Van Oostenryck
2016-11-24  3:23                     ` Christopher Li
2016-11-23  6:28           ` Johannes Berg
2016-11-23 14:30             ` Christopher Li

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=CANeU7QmSSPT9cq1fNqUxqk5DNWDn7RNLjKnFVdKUdJtCrqfBLg@mail.gmail.com \
    --to=sparse@chrisli.org \
    --cc=johannes@sipsolutions.net \
    --cc=linux-sparse@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.