94 lines · plain
1// Test instrumentation of general constructs in objective C.2 3// 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 %s4 5// RUN: llvm-profdata merge %S/Inputs/objc-general.proftext -o %t.profdata6// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name objc-general.m %s -o - -emit-llvm -fblocks -fprofile-instrument-use=clang -fprofile-instrument-use-path=%t.profdata 2>&1 | FileCheck -check-prefix=PGOUSE %s7 8// PGOUSE-NOT: warning: profile data may be out of date9 10#ifdef HAVE_FOUNDATION11 12// Use this to build an instrumented version to regenerate the input file.13#import <Foundation/Foundation.h>14 15#else16 17// Minimal definitions to get this to compile without Foundation.h.18 19@protocol NSObject20@end21 22@interface NSObject <NSObject>23- (id)init;24+ (id)alloc;25@end26 27struct NSFastEnumerationState;28@interface NSArray : NSObject29- (unsigned long) countByEnumeratingWithState: (struct NSFastEnumerationState*) state30 objects: (id*) buffer31 count: (unsigned long) bufferSize;32+(NSArray*) arrayWithObjects: (id) first, ...;33@end;34#endif35 36// PGOGEN: @[[FRC:"__profc_objc_general.m_\+\[A foreach_\]"]] = private global [2 x i64] zeroinitializer37// PGOGEN: @[[BLC:"__profc_objc_general.m___13\+\[A foreach_\]_block_invoke"]] = private global [2 x i64] zeroinitializer38// PGOGEN: @[[MAC:__profc_main]] = private global [1 x i64] zeroinitializer39 40@interface A : NSObject41+ (void)foreach: (NSArray *)array;42@end43 44@implementation A45// PGOGEN: define {{.*}}+[A foreach:]46// PGOUSE: define {{.*}}+[A foreach:]47// PGOGEN: store {{.*}} @[[FRC]]48+ (void)foreach: (NSArray *)array49{50 __block id result;51 // PGOGEN: store {{.*}} @[[FRC]], i32 0, i32 152 // PGOUSE: br {{.*}} !prof ![[FR1:[0-9]+]]53 // PGOUSE: br {{.*}} !prof ![[FR2:[0-9]+]]54 for (id x in array) {55 // PGOGEN: define {{.*}}_block_invoke56 // PGOUSE: define {{.*}}_block_invoke57 // PGOGEN: store {{.*}} @[[BLC]]58 ^{59 static int init = 0;60 // PGOGEN: store {{.*}} @[[BLC]], i32 0, i32 161 // PGOUSE: br {{.*}} !prof ![[BL1:[0-9]+]]62 if (init)63 result = x;64 init = 1;65 }();66 }67}68@end69 70void nested_objc_for_ranges(NSArray *arr) {71 int x = 0;72 for (id a in arr)73 for (id b in arr)74 ++x;75}76 77void consecutive_objc_for_ranges(NSArray *arr) {78 int x = 0;79 for (id a in arr) {}80 for (id b in arr)81 ++x;82}83 84// PGOUSE-DAG: ![[FR1]] = !{!"branch_weights", i32 2, i32 3}85// PGOUSE-DAG: ![[FR2]] = !{!"branch_weights", i32 3, i32 2}86// PGOUSE-DAG: ![[BL1]] = !{!"branch_weights", i32 2, i32 2}87 88int main(int argc, const char *argv[]) {89 A *a = [[A alloc] init];90 NSArray *array = [NSArray arrayWithObjects: @"0", @"1", (void*)0];91 [A foreach: array];92 return 0;93}94