summaryrefslogtreecommitdiffstats
path: root/src/glsl
diff options
context:
space:
mode:
authorIan Romanick <[email protected]>2015-03-16 12:14:10 -0700
committerIan Romanick <[email protected]>2015-03-19 15:35:42 -0700
commita44b95cd574ecab4a4c41c6380c82db6029ad114 (patch)
tree2f9f42da2cf6774b46bb59353ec43213471fcac4 /src/glsl
parentbf9d921936305e1514d4ce7a162c4f81eba3e9f5 (diff)
glsl: Annotate as_foo functions that the this pointer cannot be NULL
We use the idiom ir_foo *x = y->as_foo(); if (x == NULL) return; all over the place. GCC generates some quite lovely code for this. One such example: 340a5b: 83 7d 18 04 cmpl $0x4,0x18(%rbp) 340a5f: 0f 85 06 04 00 00 jne 340e6b 340a65: 48 85 ed test %rbp,%rbp 340a68: 0f 84 fd 03 00 00 je 340e6b This case used as_expression() (ir_type_expression is 4). Note that it checks the ir_type, then checks that the pointer isn't NULL. There is some disconnect in GCC around the condition in the as_foo functions. return ir_type == ir_type_##TYPE ? (ir_##TYPE *) this : NULL; \ It believes "this" could be NULL, so it emits check outside the function just for fun. This patch uses assume() to tell GCC that it need not bother with extra NULL checking of the pointer returned by the as_foo functions. text data bss dec hex filename 4836430 158688 26248 5021366 4c9eb6 i965_dri-before.so 4836173 158688 26248 5021109 4c9db5 i965_dri-after.so v2: Replace 'if (this == NULL) unreachable("this cannot be NULL")' with assume(this != NULL). Suggested by Ilia Mirkin. Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Matt Turner <[email protected]>
Diffstat (limited to 'src/glsl')
-rw-r--r--src/glsl/ir.h4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/glsl/ir.h b/src/glsl/ir.h
index 25f2ecada0f..fdc22edf133 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -119,6 +119,7 @@ public:
/*@{*/
class ir_rvalue *as_rvalue()
{
+ assume(this != NULL);
if (ir_type == ir_type_dereference_array ||
ir_type == ir_type_dereference_record ||
ir_type == ir_type_dereference_variable ||
@@ -132,6 +133,7 @@ public:
class ir_dereference *as_dereference()
{
+ assume(this != NULL);
if (ir_type == ir_type_dereference_array ||
ir_type == ir_type_dereference_record ||
ir_type == ir_type_dereference_variable)
@@ -141,6 +143,7 @@ public:
class ir_jump *as_jump()
{
+ assume(this != NULL);
if (ir_type == ir_type_loop_jump ||
ir_type == ir_type_return ||
ir_type == ir_type_discard)
@@ -151,6 +154,7 @@ public:
#define AS_CHILD(TYPE) \
class ir_##TYPE * as_##TYPE() \
{ \
+ assume(this != NULL); \
return ir_type == ir_type_##TYPE ? (ir_##TYPE *) this : NULL; \
}
AS_CHILD(variable)