Title: [156246] trunk/Source
Revision
156246
Author
[email protected]
Date
2013-09-22 05:49:59 -0700 (Sun, 22 Sep 2013)

Log Message

Give purity hints to compiler to avoid penalizing repeated calls to some functions.
<https://webkit.org/b/121744>

Reviewed by Darin Adler.

Source/WebCore:

Mark the following functions pure:

    - gcController()
    - cssValuePool()
    - threadGlobalData()

I had this idea when I saw Darin's patch to cache cssValuePool() in a local.
We know that this function will always return the same value, so we should just
share this knowledge with the compiler and let it do the cleverness instead.

Source/WTF:

Added a PURE_FUNCTION macro. This is supported on GCC and Clang for now.
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.

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (156245 => 156246)


--- trunk/Source/WTF/ChangeLog	2013-09-22 07:34:49 UTC (rev 156245)
+++ trunk/Source/WTF/ChangeLog	2013-09-22 12:49:59 UTC (rev 156246)
@@ -1,3 +1,15 @@
+2013-09-22  Andreas Kling  <[email protected]>
+
+        Give purity hints to compiler to avoid penalizing repeated calls to some functions.
+        <https://webkit.org/b/121744>
+
+        Reviewed by Darin Adler.
+
+        Added a PURE_FUNCTION macro. This is supported on GCC and Clang for now.
+        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.
+
 2013-09-20  Anders Carlsson  <[email protected]>
 
         Add an implementation of std::index_sequence from C++14

Modified: trunk/Source/WTF/wtf/Compiler.h (156245 => 156246)


--- trunk/Source/WTF/wtf/Compiler.h	2013-09-22 07:34:49 UTC (rev 156245)
+++ trunk/Source/WTF/wtf/Compiler.h	2013-09-22 12:49:59 UTC (rev 156246)
@@ -192,6 +192,14 @@
 #endif
 #endif
 
+/* PURE_FUNCTION */
+
+#if COMPILER(GCC)
+#define PURE_FUNCTION __attribute__ ((__pure__))
+#else
+#define PURE_FUNCTION
+#endif
+
 /* ALWAYS_INLINE */
 
 #ifndef ALWAYS_INLINE

Modified: trunk/Source/WebCore/ChangeLog (156245 => 156246)


--- trunk/Source/WebCore/ChangeLog	2013-09-22 07:34:49 UTC (rev 156245)
+++ trunk/Source/WebCore/ChangeLog	2013-09-22 12:49:59 UTC (rev 156246)
@@ -1,3 +1,20 @@
+2013-09-22  Andreas Kling  <[email protected]>
+
+        Give purity hints to compiler to avoid penalizing repeated calls to some functions.
+        <https://webkit.org/b/121744>
+
+        Reviewed by Darin Adler.
+
+        Mark the following functions pure:
+
+            - gcController()
+            - cssValuePool()
+            - threadGlobalData()
+
+        I had this idea when I saw Darin's patch to cache cssValuePool() in a local.
+        We know that this function will always return the same value, so we should just
+        share this knowledge with the compiler and let it do the cleverness instead.
+
 2013-09-21  Darin Adler  <[email protected]>
 
         Fix too-strict type error exceptions introduced in WebGL bindings

Modified: trunk/Source/WebCore/bindings/js/GCController.h (156245 => 156246)


--- trunk/Source/WebCore/bindings/js/GCController.h	2013-09-22 07:34:49 UTC (rev 156245)
+++ trunk/Source/WebCore/bindings/js/GCController.h	2013-09-22 12:49:59 UTC (rev 156246)
@@ -57,7 +57,7 @@
     };
 
     // Function to obtain the global GC controller.
-    GCController& gcController();
+    GCController& gcController() PURE_FUNCTION;
 
 } // namespace WebCore
 

Modified: trunk/Source/WebCore/css/CSSValuePool.h (156245 => 156246)


--- trunk/Source/WebCore/css/CSSValuePool.h	2013-09-22 07:34:49 UTC (rev 156245)
+++ trunk/Source/WebCore/css/CSSValuePool.h	2013-09-22 12:49:59 UTC (rev 156246)
@@ -86,7 +86,7 @@
     friend CSSValuePool& cssValuePool();
 };
 
-CSSValuePool& cssValuePool();
+CSSValuePool& cssValuePool() PURE_FUNCTION;
 
 }
 

Modified: trunk/Source/WebCore/platform/ThreadGlobalData.h (156245 => 156246)


--- trunk/Source/WebCore/platform/ThreadGlobalData.h	2013-09-22 07:34:49 UTC (rev 156245)
+++ trunk/Source/WebCore/platform/ThreadGlobalData.h	2013-09-22 12:49:59 UTC (rev 156246)
@@ -95,7 +95,7 @@
         friend ThreadGlobalData& threadGlobalData();
     };
 
-ThreadGlobalData& threadGlobalData();
+ThreadGlobalData& threadGlobalData() PURE_FUNCTION;
     
 } // namespace WebCore
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to