This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Identifying Pure and Const Functions
- From: Pritam Gharat <pritam01gharat at gmail dot com>
- To: Marek Polacek <polacek at redhat dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Fri, 29 May 2015 20:33:33 +0530
- Subject: Re: Identifying Pure and Const Functions
- Authentication-results: sourceware.org; auth=none
- References: <CAPHYrQUOhOqzb7qBKhgCFU+zWusRVv1RzhWQbndAJ3-uCNt13g at mail dot gmail dot com> <20150529075610 dot GF27320 at redhat dot com>
I had a look at the file ipa-pure-const.c. I have wriiten a Simple IPA
Pass which identifies pure and const functions in the program. I have
inserted this pass after ipa-pta pass which is executed after
ipa-pure-const pass. Also, the option -fipa-pure-const is enabled.
I am using DECL_PURE_P(t) and TREE_READONLY(t) to identify whether t
is a pure or a const function.
I tested this code on a sample program which consists of a function
"error" which returns a constant value. gcc fails to identify it as a
pure function. However, if I specify the function as pure as shown
below, gcc identifies it as pure function
__attribute__((pure))
int error()
{
return 2;
}
I am unable to understand why error function is not identified as a
pure function by gcc? Are the checks to identify pure and const
functions correct?
Thanks,
Pritam Gharat
On Fri, May 29, 2015 at 1:26 PM, Marek Polacek <polacek@redhat.com> wrote:
> On Fri, May 29, 2015 at 01:16:32PM +0530, Pritam Gharat wrote:
>> How do we identify whether a function is a pure or a const function?
>> Is there any flag associated with its cgraph_node or the tree node
>> (decl of cgraph_node)?
>
> You'll want to look into ipa-pure-const.c.
>
> Marek