2014-03-11 12:37:49 +08:00
|
|
|
// Test instrumentation of general constructs in objective C.
|
|
|
|
|
|
|
|
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name objc-general.m %s -o - -emit-llvm -fblocks -fprofile-instr-generate | FileCheck -check-prefix=PGOGEN %s
|
|
|
|
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name objc-general.m %s -o - -emit-llvm -fblocks -fprofile-instr-use=%S/Inputs/objc-general.profdata | FileCheck -check-prefix=PGOUSE %s
|
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
|
|
|
|
|
2014-03-21 04:00:41 +08:00
|
|
|
// PGOGEN: @[[FRC:"__llvm_profile_counters_\+\[A foreach:\]"]] = internal global [2 x i64] zeroinitializer
|
|
|
|
// PGOGEN: @[[BLC:"__llvm_profile_counters___13\+\[A foreach:\]_block_invoke"]] = internal global [2 x i64] zeroinitializer
|
|
|
|
// PGOGEN: @[[MAC:__llvm_profile_counters_main]] = 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-02-24 09:13:09 +08:00
|
|
|
// FIXME: We don't emit branch weights for this yet.
|
|
|
|
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
|
|
|
|
2014-03-07 04:24:27 +08:00
|
|
|
// PGOUSE-DAG: ![[BL1]] = metadata !{metadata !"branch_weights", i32 2, i32 2}
|
|
|
|
|
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
|
|
|
}
|