2014-03-11 12:37:49 +08:00
|
|
|
// Test instrumentation of general constructs in objective C.
|
|
|
|
|
2016-02-05 02:39:09 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name objc-general.m %s -o - -emit-llvm -fblocks -fprofile-instrument=clang | FileCheck -check-prefix=PGOGEN %s
|
2014-04-18 06:49:06 +08:00
|
|
|
|
|
|
|
// RUN: llvm-profdata merge %S/Inputs/objc-general.proftext -o %t.profdata
|
2017-11-15 07:56:53 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name objc-general.m %s -o - -emit-llvm -fblocks -fprofile-instrument-use-path=%t.profdata 2>&1 | FileCheck -check-prefix=PGOUSE %s
|
|
|
|
|
|
|
|
// PGOUSE-NOT: warning: profile data may be out of date
|
2014-02-24 09:13:09 +08:00
|
|
|
|
|
|
|
#ifdef HAVE_FOUNDATION
|
2014-03-06 14:10:02 +08:00
|
|
|
|
2014-02-24 09:13:09 +08:00
|
|
|
// Use this to build an instrumented version to regenerate the input file.
|
|
|
|
#import <Foundation/Foundation.h>
|
2014-03-06 14:10:02 +08:00
|
|
|
|
2014-02-24 09:13:09 +08:00
|
|
|
#else
|
2014-03-06 14:10:02 +08:00
|
|
|
|
|
|
|
// Minimal definitions to get this to compile without Foundation.h.
|
|
|
|
|
|
|
|
@protocol NSObject
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface NSObject <NSObject>
|
|
|
|
- (id)init;
|
|
|
|
+ (id)alloc;
|
|
|
|
@end
|
|
|
|
|
2014-02-24 09:13:09 +08:00
|
|
|
struct NSFastEnumerationState;
|
2014-03-06 14:10:02 +08:00
|
|
|
@interface NSArray : NSObject
|
2014-02-24 09:13:09 +08:00
|
|
|
- (unsigned long) countByEnumeratingWithState: (struct NSFastEnumerationState*) state
|
|
|
|
objects: (id*) buffer
|
|
|
|
count: (unsigned long) bufferSize;
|
|
|
|
+(NSArray*) arrayWithObjects: (id) first, ...;
|
|
|
|
@end;
|
|
|
|
#endif
|
|
|
|
|
2015-12-15 08:33:12 +08:00
|
|
|
// PGOGEN: @[[FRC:"__profc_objc_general.m_\+\[A foreach_\]"]] = private global [2 x i64] zeroinitializer
|
|
|
|
// PGOGEN: @[[BLC:"__profc_objc_general.m___13\+\[A foreach_\]_block_invoke"]] = private global [2 x i64] zeroinitializer
|
|
|
|
// PGOGEN: @[[MAC:__profc_main]] = private global [1 x i64] zeroinitializer
|
2014-02-24 09:13:09 +08:00
|
|
|
|
2014-03-06 14:10:02 +08:00
|
|
|
@interface A : NSObject
|
|
|
|
+ (void)foreach: (NSArray *)array;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation A
|
2014-03-06 14:49:37 +08:00
|
|
|
// PGOGEN: define {{.*}}+[A foreach:]
|
|
|
|
// PGOUSE: define {{.*}}+[A foreach:]
|
2014-03-07 04:24:27 +08:00
|
|
|
// PGOGEN: store {{.*}} @[[FRC]], i64 0, i64 0
|
2014-03-06 14:10:02 +08:00
|
|
|
+ (void)foreach: (NSArray *)array
|
|
|
|
{
|
2014-03-07 04:24:27 +08:00
|
|
|
__block id result;
|
|
|
|
// PGOGEN: store {{.*}} @[[FRC]], i64 0, i64 1
|
2014-03-26 07:26:31 +08:00
|
|
|
// PGOUSE: br {{.*}} !prof ![[FR1:[0-9]+]]
|
|
|
|
// PGOUSE: br {{.*}} !prof ![[FR2:[0-9]+]]
|
2014-02-24 09:13:09 +08:00
|
|
|
for (id x in array) {
|
2014-03-07 04:24:27 +08:00
|
|
|
// PGOGEN: define {{.*}}_block_invoke
|
|
|
|
// PGOUSE: define {{.*}}_block_invoke
|
|
|
|
// PGOGEN: store {{.*}} @[[BLC]], i64 0, i64 0
|
|
|
|
^{ static int init = 0;
|
|
|
|
// PGOGEN: store {{.*}} @[[BLC]], i64 0, i64 1
|
|
|
|
// PGOUSE: br {{.*}} !prof ![[BL1:[0-9]+]]
|
|
|
|
if (init)
|
|
|
|
result = x;
|
|
|
|
init = 1; }();
|
2014-02-24 09:13:09 +08:00
|
|
|
}
|
|
|
|
}
|
2014-03-06 14:10:02 +08:00
|
|
|
@end
|
2014-02-24 09:13:09 +08:00
|
|
|
|
2017-11-15 07:56:53 +08:00
|
|
|
void nested_objc_for_ranges(NSArray *arr) {
|
|
|
|
int x = 0;
|
|
|
|
for (id a in arr)
|
|
|
|
for (id b in arr)
|
|
|
|
++x;
|
|
|
|
}
|
|
|
|
|
|
|
|
void consecutive_objc_for_ranges(NSArray *arr) {
|
|
|
|
int x = 0;
|
|
|
|
for (id a in arr) {}
|
|
|
|
for (id b in arr)
|
|
|
|
++x;
|
|
|
|
}
|
|
|
|
|
2014-12-16 03:10:08 +08:00
|
|
|
// PGOUSE-DAG: ![[FR1]] = !{!"branch_weights", i32 2, i32 3}
|
|
|
|
// PGOUSE-DAG: ![[FR2]] = !{!"branch_weights", i32 3, i32 2}
|
|
|
|
// PGOUSE-DAG: ![[BL1]] = !{!"branch_weights", i32 2, i32 2}
|
2014-03-07 04:24:27 +08:00
|
|
|
|
2014-02-24 09:13:09 +08:00
|
|
|
int main(int argc, const char *argv[]) {
|
2014-03-06 14:10:02 +08:00
|
|
|
A *a = [[A alloc] init];
|
2014-02-24 09:13:09 +08:00
|
|
|
NSArray *array = [NSArray arrayWithObjects: @"0", @"1", (void*)0];
|
2014-03-06 14:10:02 +08:00
|
|
|
[A foreach: array];
|
|
|
|
return 0;
|
2014-02-24 09:13:09 +08:00
|
|
|
}
|