Bug 121744 - Give purity hints to compiler to avoid penalizing repeated calls to some functions.
Summary: Give purity hints to compiler to avoid penalizing repeated calls to some func...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore JavaScript (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Andreas Kling
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-09-21 09:23 PDT by Andreas Kling
Modified: 2013-09-22 21:08 PDT (History)
10 users (show)

See Also:


Attachments
Patch idea (3.30 KB, patch)
2013-09-21 09:29 PDT, Andreas Kling
darin: review+
Details | Formatted Diff | Diff
Land for patching (3.25 KB, patch)
2013-09-22 05:16 PDT, Andreas Kling
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Kling 2013-09-21 09:23:28 PDT
Help the CSE a bit.
Comment 1 Andreas Kling 2013-09-21 09:29:31 PDT
Created attachment 212274 [details]
Patch idea
Comment 2 Darin Adler 2013-09-21 11:46:42 PDT
Comment on attachment 212274 [details]
Patch idea

View in context: https://bugs.webkit.org/attachment.cgi?id=212274&action=review

Did you test? How well did this work?

> Source/WTF/wtf/Compiler.h:198
> +#define WTF_PURE_FUNCTION __attribute__ ((pure))

I never know if we should include the WTF prefixes. I would not like it if it was WTF_OVERRIDE, for example.

Also, I seem to recall that __attribute__((__pure__)) does the same thing and is a little more safe if someone has a macro named "pure".
Comment 3 Andreas Kling 2013-09-22 05:15:53 PDT
(In reply to comment #2)
> (From update of attachment 212274 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=212274&action=review
> 
> Did you test? How well did this work?

It knocks 4800 bytes off of the binary size, and does succeed in coalescing multiple function calls in the same function. Of course the real value is in calling threadGlobalData() as little as possible, since that has to do a pthread_getspecific().

> > Source/WTF/wtf/Compiler.h:198
> > +#define WTF_PURE_FUNCTION __attribute__ ((pure))
> 
> I never know if we should include the WTF prefixes. I would not like it if it was WTF_OVERRIDE, for example.

Let's just call it PURE_FUNCTION.

> Also, I seem to recall that __attribute__((__pure__)) does the same thing and is a little more safe if someone has a macro named "pure".

Good idea.
Comment 4 Andreas Kling 2013-09-22 05:16:32 PDT
Created attachment 212300 [details]
Land for patching
Comment 5 WebKit Commit Bot 2013-09-22 05:48:52 PDT
Comment on attachment 212300 [details]
Land for patching

Clearing flags on attachment: 212300

Committed r156246: <http://trac.webkit.org/changeset/156246>
Comment 6 WebKit Commit Bot 2013-09-22 05:48:54 PDT
All reviewed patches have been landed.  Closing bug.
Comment 7 Benjamin Poulain 2013-09-22 21:08:47 PDT
Comment on attachment 212300 [details]
Land for patching

View in context: https://bugs.webkit.org/attachment.cgi?id=212300&action=review

Pure has plenty of advantages for function used cross-compilation unit. I am really happy you added a macro for it.

> Source/WTF/ChangeLog:11
> +        Marking a function pure means that the compiler's CSE pass is free to coalesce
> +        multiple calls to this function because it has no globally observable side
> +        effects beyond the first call.

I don't think the definition of pure has anything to do with the first call though.
I could not find a formal definition from a quick search in Clang's doc.