"pure" functions"

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

"pure" functions"

Bugzilla from ghost@cs.msu.su

Hi,
say I've a LLVM module with a call instruction. The called function is
"pure", that is it has no side-effects at all. How can I communicate this
to LLVM, so that the function call can be removed if the return value is
never used?

Thanks,
Volodya


_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: "pure" functions"

Chris Lattner
On Sun, 4 Jun 2006, Vladimir Prus wrote:
> say I've a LLVM module with a call instruction. The called function is
> "pure", that is it has no side-effects at all. How can I communicate this
> to LLVM, so that the function call can be removed if the return value is
> never used?

There isn't a way to do this from the source code yet.  However, if this
is a standard library function, you can add it to the end of
lib/Analysis/BasicAliasAnalysis.cpp.  Search of "isspace".

-Chris

--
http://nondot.org/sabre/
http://llvm.org/
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: "pure" functions"

Reid Spencer
On Sun, 2006-06-04 at 11:49 -0500, Chris Lattner wrote:
> On Sun, 4 Jun 2006, Vladimir Prus wrote:
> > say I've a LLVM module with a call instruction. The called function is
> > "pure", that is it has no side-effects at all. How can I communicate this
> > to LLVM, so that the function call can be removed if the return value is
> > never used?
>
> There isn't a way to do this from the source code yet.  However, if this
> is a standard library function, you can add it to the end of
> lib/Analysis/BasicAliasAnalysis.cpp.  Search of "isspace".

That's a bit of a hack. Can we not deduce "pure" functions
conservatively? Basically, anything that doesn't do any load or store
outside of its parameters and no malloc or free?  Maybe a few other
constraints. Sounds fairly easy to deduce and might be useful for
optimization.

Reid.

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

signature.asc (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: "pure" functions"

Chris Lattner
On Sun, 4 Jun 2006, Reid Spencer wrote:
> That's a bit of a hack. Can we not deduce "pure" functions
> conservatively?

Yes, and we do.

> Basically, anything that doesn't do any load or store
> outside of its parameters and no malloc or free?  Maybe a few other
> constraints. Sounds fairly easy to deduce and might be useful for
> optimization.

We already do that, but it doesn't help for external functions (e.g.
strlen).

-Chris

--
http://nondot.org/sabre/
http://llvm.org/
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: "pure" functions"

Reid Spencer
On Sun, 2006-06-04 at 13:08 -0500, Chris Lattner wrote:
> On Sun, 4 Jun 2006, Reid Spencer wrote:
> > Basically, anything that doesn't do any load or store
> > outside of its parameters and no malloc or free?  Maybe a few other
> > constraints. Sounds fairly easy to deduce and might be useful for
> > optimization.
>
> We already do that, but it doesn't help for external functions (e.g.
> strlen).

I see. Just another reason why *everything* should be compiled with
LLVM :)

Reid.

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

signature.asc (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: "pure" functions"

Bugzilla from ghost@cs.msu.su
In reply to this post by Chris Lattner
Chris Lattner wrote:

> On Sun, 4 Jun 2006, Vladimir Prus wrote:
>> say I've a LLVM module with a call instruction. The called function is
>> "pure", that is it has no side-effects at all. How can I communicate this
>> to LLVM, so that the function call can be removed if the return value is
>> never used?
>
> There isn't a way to do this from the source code yet.  However, if this
> is a standard library function, you can add it to the end of
> lib/Analysis/BasicAliasAnalysis.cpp.  Search of "isspace".

No, it's not a library function. Besides, what is "library" function? Do you
mean libc as of specific revision ;-)

It would be nicer to have a method to declare function as pure without
modifying the code.

- Volodya

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: "pure" functions"

Bugzilla from ghost@cs.msu.su
In reply to this post by Reid Spencer
Reid Spencer wrote:

> On Sun, 2006-06-04 at 13:08 -0500, Chris Lattner wrote:
>> On Sun, 4 Jun 2006, Reid Spencer wrote:
>> > Basically, anything that doesn't do any load or store
>> > outside of its parameters and no malloc or free?  Maybe a few other
>> > constraints. Sounds fairly easy to deduce and might be useful for
>> > optimization.
>>
>> We already do that, but it doesn't help for external functions (e.g.
>> strlen).
>
> I see. Just another reason why *everything* should be compiled with
> LLVM :)

In my case, the function is much more "pure" then you can imagine -- its
body does not exist anywhere. It's just some "marker" I put in code during
certain transformation to communicate information to further
transformations. After those transformations are done the markers should be
optimized out.

- Volodya


_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev