forked from flang-compiler/flang-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert some ObjC msgSends to runtime calls.
It is faster to directly call the ObjC runtime for methods such as alloc/allocWithZone instead of sending a message to those functions. This patch adds support for converting messages to alloc/allocWithZone to their equivalent runtime calls. Tests included for the positive case of applying this transformation, negative tests that we ensure we only convert "alloc" to objc_alloc, not "alloc2", and also a driver test to ensure we enable this only for supported runtime versions. Reviewed By: rjmccall https://reviews.llvm.org/D55349 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@348687 91177308-0d34-0410-b5e6-96231b3b80d8
- Loading branch information
Showing
10 changed files
with
245 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// RUN: %clang_cc1 -fobjc-runtime=macosx-10.10.0 -emit-llvm -o - %s -fno-objc-convert-messages-to-runtime-calls | FileCheck %s --check-prefix=MSGS | ||
// RUN: %clang_cc1 -fobjc-runtime=macosx-10.10.0 -emit-llvm -o - %s | FileCheck %s --check-prefix=CALLS | ||
// RUN: %clang_cc1 -fobjc-runtime=macosx-10.9.0 -emit-llvm -o - %s | FileCheck %s --check-prefix=MSGS | ||
// RUN: %clang_cc1 -fobjc-runtime=macosx-fragile-10.10.0 -emit-llvm -o - %s | FileCheck %s --check-prefix=MSGS | ||
// RUN: %clang_cc1 -fobjc-runtime=ios-8.0 -emit-llvm -o - %s | FileCheck %s --check-prefix=CALLS | ||
// RUN: %clang_cc1 -fobjc-runtime=ios-7.0 -emit-llvm -o - %s | FileCheck %s --check-prefix=MSGS | ||
// Note: This line below is for tvos for which the driver passes through to use the ios9.0 runtime. | ||
// RUN: %clang_cc1 -fobjc-runtime=ios-9.0 -emit-llvm -o - %s | FileCheck %s --check-prefix=CALLS | ||
// RUN: %clang_cc1 -fobjc-runtime=watchos-2.0 -emit-llvm -o - %s | FileCheck %s --check-prefix=CALLS | ||
|
||
#define nil (id)0 | ||
|
||
@interface NSObject | ||
+ (id)alloc; | ||
+ (id)allocWithZone:(void*)zone; | ||
+ (id)alloc2; | ||
@end | ||
|
||
// CHECK-LABEL: define {{.*}}void @test1 | ||
void test1(id x) { | ||
// MSGS: {{call.*@objc_msgSend}} | ||
// MSGS: {{call.*@objc_msgSend}} | ||
// CALLS: {{call.*@objc_alloc}} | ||
// CALLS: {{call.*@objc_allocWithZone}} | ||
[NSObject alloc]; | ||
[NSObject allocWithZone:nil]; | ||
} | ||
|
||
// CHECK-LABEL: define {{.*}}void @test2 | ||
void test2(void* x) { | ||
// MSGS: {{call.*@objc_msgSend}} | ||
// MSGS: {{call.*@objc_msgSend}} | ||
// MSGS: {{call.*@objc_msgSend}} | ||
// CALLS: {{call.*@objc_msgSend}} | ||
// CALLS: {{call.*@objc_msgSend}} | ||
// CALLS: {{call.*@objc_msgSend}} | ||
[NSObject alloc2]; | ||
[NSObject allocWithZone:(void*)-1]; | ||
[NSObject allocWithZone:x]; | ||
} | ||
|
||
@class A; | ||
@interface B | ||
+ (A*) alloc; | ||
+ (A*)allocWithZone:(void*)zone; | ||
@end | ||
|
||
// Make sure we get a bitcast on the return type as the | ||
// call will return i8* which we have to cast to A* | ||
// CHECK-LABEL: define {{.*}}void @test_alloc_class_ptr | ||
A* test_alloc_class_ptr() { | ||
// CALLS: {{call.*@objc_alloc}} | ||
// CALLS-NEXT: bitcast i8* | ||
// CALLS-NEXT: ret | ||
return [B alloc]; | ||
} | ||
|
||
// Make sure we get a bitcast on the return type as the | ||
// call will return i8* which we have to cast to A* | ||
// CHECK-LABEL: define {{.*}}void @test_alloc_class_ptr | ||
A* test_allocWithZone_class_ptr() { | ||
// CALLS: {{call.*@objc_allocWithZone}} | ||
// CALLS-NEXT: bitcast i8* | ||
// CALLS-NEXT: ret | ||
return [B allocWithZone:nil]; | ||
} | ||
|
||
|
||
@interface C | ||
+ (id)allocWithZone:(int)intArg; | ||
@end | ||
|
||
// Make sure we only accept pointer types | ||
// CHECK-LABEL: define {{.*}}void @test_allocWithZone_int | ||
C* test_allocWithZone_int() { | ||
// MSGS: {{call.*@objc_msgSend}} | ||
// CALLS: {{call.*@objc_msgSend}} | ||
return [C allocWithZone:3]; | ||
} | ||
|
Oops, something went wrong.