From: Hanke Zhang <hkzhang455@gmail.com>
To: gcc@gcc.gnu.org
Subject: Check whether a function is a pure function
Date: Tue, 17 Oct 2023 17:20:26 +0800 [thread overview]
Message-ID: <CAM_DAs-OART40kdNv5aWAEyh2xMM5f+8KDyZGRNBdd79gDVkdA@mail.gmail.com> (raw)
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.
Thanks
Hanke Zhang
next reply other threads:[~2023-10-17 9:20 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-17 9:20 Hanke Zhang [this message]
2023-10-17 9:26 ` Richard Biener
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=CAM_DAs-OART40kdNv5aWAEyh2xMM5f+8KDyZGRNBdd79gDVkdA@mail.gmail.com \
--to=hkzhang455@gmail.com \
--cc=gcc@gcc.gnu.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 read-only IMAP folder(s) and NNTP newsgroup(s).