diff options
author | Erik Pilkington <erik.pilkington@gmail.com> | 2019-01-17 18:18:53 +0000 |
---|---|---|
committer | Erik Pilkington <erik.pilkington@gmail.com> | 2019-01-17 18:18:53 +0000 |
commit | 2ff012df81760f62b655135ab335956c06cbcb22 (patch) | |
tree | 65904ee3c73c496fe9387067a7cbc178f7c12b1b /clang/test/CodeGenObjC | |
parent | f3b762a0b6cef251afef8907cb4cf5b35bffb0d8 (diff) | |
download | bcm5719-llvm-2ff012df81760f62b655135ab335956c06cbcb22.tar.gz bcm5719-llvm-2ff012df81760f62b655135ab335956c06cbcb22.zip |
[CodeGenObjC] Use a constant value for non-fragile ivar offsets when possible
If a class inherits from NSObject and has an implementation, then we
can assume that ivar offsets won't need to be updated by the runtime.
This allows us to index into the object using a constant value and
avoid loading from the ivar offset variable.
This patch was adapted from one written by Pete Cooper.
rdar://problem/10132568
Differential revision: https://reviews.llvm.org/D56802
llvm-svn: 351461
Diffstat (limited to 'clang/test/CodeGenObjC')
-rw-r--r-- | clang/test/CodeGenObjC/constant-non-fragile-ivar-offset.m | 38 | ||||
-rw-r--r-- | clang/test/CodeGenObjC/optimize-ivar-offset-load.m | 6 | ||||
-rw-r--r-- | clang/test/CodeGenObjC/reorder-synthesized-ivars.m | 34 |
3 files changed, 58 insertions, 20 deletions
diff --git a/clang/test/CodeGenObjC/constant-non-fragile-ivar-offset.m b/clang/test/CodeGenObjC/constant-non-fragile-ivar-offset.m new file mode 100644 index 00000000000..34c393d8ed3 --- /dev/null +++ b/clang/test/CodeGenObjC/constant-non-fragile-ivar-offset.m @@ -0,0 +1,38 @@ +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.14.0 -emit-llvm %s -o - | FileCheck %s + +// CHECK: @"OBJC_IVAR_$_StaticLayout.static_layout_ivar" = hidden constant i64 20 +// CHECK: @"OBJC_IVAR_$_NotStaticLayout.not_static_layout_ivar" = hidden global i64 12 + +@interface NSObject { + int these, will, never, change, ever; +} +@end + +@interface StaticLayout : NSObject +@end + +@implementation StaticLayout { + int static_layout_ivar; +} +-(void)meth { + static_layout_ivar = 0; + // CHECK-NOT: load i64, i64* @"OBJC_IVAR_$_StaticLayout +} +@end + +@interface NotNSObject { + int these, might, change; +} +@end + +@interface NotStaticLayout : NotNSObject +@end + +@implementation NotStaticLayout { + int not_static_layout_ivar; +} +-(void)meth { + not_static_layout_ivar = 0; + // CHECK: load i64, i64* @"OBJC_IVAR_$_NotStaticLayout.not_static_layout_ivar +} +@end diff --git a/clang/test/CodeGenObjC/optimize-ivar-offset-load.m b/clang/test/CodeGenObjC/optimize-ivar-offset-load.m index 6a073dbd29c..6f902d79d36 100644 --- a/clang/test/CodeGenObjC/optimize-ivar-offset-load.m +++ b/clang/test/CodeGenObjC/optimize-ivar-offset-load.m @@ -1,17 +1,17 @@ // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -O0 -emit-llvm %s -o - | FileCheck %s // rdar://16095748 -@interface NSObject +@interface MyNSObject @end -@interface SampleClass : NSObject { +@interface SampleClass : MyNSObject { @public int _value; } + (SampleClass*) new; @end -@interface AppDelegate : NSObject +@interface AppDelegate : MyNSObject @end extern void foo(int); diff --git a/clang/test/CodeGenObjC/reorder-synthesized-ivars.m b/clang/test/CodeGenObjC/reorder-synthesized-ivars.m index ef1bb79bccc..90f39f1a89e 100644 --- a/clang/test/CodeGenObjC/reorder-synthesized-ivars.m +++ b/clang/test/CodeGenObjC/reorder-synthesized-ivars.m @@ -39,20 +39,20 @@ typedef signed char BOOL; @end // CHECK: @{{.*}} = private unnamed_addr constant [10 x i8] c"_boolean1 -// CHECK-NEXT: @{{.*}} = private unnamed_addr constant [10 x i8] c"_boolean2 -// CHECK-NEXT: @{{.*}} = private unnamed_addr constant [10 x i8] c"_boolean3 -// CHECK-NEXT: @{{.*}} = private unnamed_addr constant [10 x i8] c"_boolean4 -// CHECK-NEXT: @{{.*}} = private unnamed_addr constant [10 x i8] c"_boolean5 -// CHECK-NEXT: @{{.*}} = private unnamed_addr constant [10 x i8] c"_boolean6 -// CHECK-NEXT: @{{.*}} = private unnamed_addr constant [10 x i8] c"_boolean7 -// CHECK-NEXT: @{{.*}} = private unnamed_addr constant [10 x i8] c"_boolean8 -// CHECK-NEXT: @{{.*}} = private unnamed_addr constant [10 x i8] c"_boolean9 -// CHECK-NEXT: @{{.*}} = private unnamed_addr constant [9 x i8] c"_object1 -// CHECK-NEXT: @{{.*}} = private unnamed_addr constant [9 x i8] c"_object2 -// CHECK-NEXT: @{{.*}} = private unnamed_addr constant [9 x i8] c"_object3 -// CHECK-NEXT: @{{.*}} = private unnamed_addr constant [9 x i8] c"_object4 -// CHECK-NEXT: @{{.*}} = private unnamed_addr constant [9 x i8] c"_object5 -// CHECK-NEXT: @{{.*}} = private unnamed_addr constant [9 x i8] c"_object6 -// CHECK-NEXT: @{{.*}} = private unnamed_addr constant [9 x i8] c"_object7 -// CHECK-NEXT: @{{.*}} = private unnamed_addr constant [9 x i8] c"_object8 -// CHECK-NEXT: @{{.*}} = private unnamed_addr constant [9 x i8] c"_object9 +// CHECK: @{{.*}} = private unnamed_addr constant [10 x i8] c"_boolean2 +// CHECK: @{{.*}} = private unnamed_addr constant [10 x i8] c"_boolean3 +// CHECK: @{{.*}} = private unnamed_addr constant [10 x i8] c"_boolean4 +// CHECK: @{{.*}} = private unnamed_addr constant [10 x i8] c"_boolean5 +// CHECK: @{{.*}} = private unnamed_addr constant [10 x i8] c"_boolean6 +// CHECK: @{{.*}} = private unnamed_addr constant [10 x i8] c"_boolean7 +// CHECK: @{{.*}} = private unnamed_addr constant [10 x i8] c"_boolean8 +// CHECK: @{{.*}} = private unnamed_addr constant [10 x i8] c"_boolean9 +// CHECK: @{{.*}} = private unnamed_addr constant [9 x i8] c"_object1 +// CHECK: @{{.*}} = private unnamed_addr constant [9 x i8] c"_object2 +// CHECK: @{{.*}} = private unnamed_addr constant [9 x i8] c"_object3 +// CHECK: @{{.*}} = private unnamed_addr constant [9 x i8] c"_object4 +// CHECK: @{{.*}} = private unnamed_addr constant [9 x i8] c"_object5 +// CHECK: @{{.*}} = private unnamed_addr constant [9 x i8] c"_object6 +// CHECK: @{{.*}} = private unnamed_addr constant [9 x i8] c"_object7 +// CHECK: @{{.*}} = private unnamed_addr constant [9 x i8] c"_object8 +// CHECK: @{{.*}} = private unnamed_addr constant [9 x i8] c"_object9 |