public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Hanke Zhang <hkzhang455@gmail.com>
Cc: gcc@gcc.gnu.org
Subject: Re: Check whether a function is a pure function
Date: Tue, 17 Oct 2023 11:26:42 +0200	[thread overview]
Message-ID: <CAFiYyc1UmDWgdQ-vmFzKU=gv391uBR3sL=p=e1JLnWgv31kcJA@mail.gmail.com> (raw)
In-Reply-To: <CAM_DAs-OART40kdNv5aWAEyh2xMM5f+8KDyZGRNBdd79gDVkdA@mail.gmail.com>

On Tue, Oct 17, 2023 at 11:21 AM Hanke Zhang via Gcc <gcc@gcc.gnu.org> wrote:
>
> Hi, I'm trying to write a pass to erase some useless functions or to
> put it another way, detect whether a function is pure or not. (Of
> course I know some passes can do the clean after inline)
>
> Here is the problem I got, If a function satisfy the following points,
> can it be considered safe to delete?
>
> 1. return value is ignored or has no return
> 2. params are pure 32bit Integer Const or has no params
> 3. No use of global variable
> 4. No function call, assembly code, goto statement
> 5. No cast
>
> And in my pass, I try to do these things through these points:
>
> 1. check GIMPLE_RETURN statement and check all the function call points
> 2. check DECL_PARAM(fndecl) and check the input params at all the
> function call points
> 3. check that fndecl is not in the global_var->referring list
> 4. check GIMPLE_CALL, GIMPLE_ASM, GIMPLE_GOTO are not present
> 5. check that there is no difference between TREE_TYPE(lhs) and
> TREE_TYPE(rhs1) types in the GIMPLE_ASSIGN statement
>
> I would like to ask that if there are any omissions or errors in the
> prerequisites and corresponding implementation plans I listed above.

You can look into ipa-pure-const.cc which implements pure/const (and more)
discovery.  The DCE pass should, with this info, already be able to
"erase some useless function [calls]"

> Thanks
> Hanke Zhang

      reply	other threads:[~2023-10-17  9:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-17  9:20 Hanke Zhang
2023-10-17  9:26 ` Richard Biener [this message]

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='CAFiYyc1UmDWgdQ-vmFzKU=gv391uBR3sL=p=e1JLnWgv31kcJA@mail.gmail.com' \
    --to=richard.guenther@gmail.com \
    --cc=gcc@gcc.gnu.org \
    --cc=hkzhang455@gmail.com \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).