• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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-instr-generate | FileCheck -check-prefix=PGOGEN %s
4
5// RUN: llvm-profdata merge %S/Inputs/objc-general.proftext -o %t.profdata
6// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name objc-general.m %s -o - -emit-llvm -fblocks -fprofile-instr-use=%t.profdata | FileCheck -check-prefix=PGOUSE %s
7
8#ifdef HAVE_FOUNDATION
9
10// Use this to build an instrumented version to regenerate the input file.
11#import <Foundation/Foundation.h>
12
13#else
14
15// Minimal definitions to get this to compile without Foundation.h.
16
17@protocol NSObject
18@end
19
20@interface NSObject <NSObject>
21- (id)init;
22+ (id)alloc;
23@end
24
25struct NSFastEnumerationState;
26@interface NSArray : NSObject
27- (unsigned long) countByEnumeratingWithState: (struct NSFastEnumerationState*) state
28                  objects: (id*) buffer
29                  count: (unsigned long) bufferSize;
30+(NSArray*) arrayWithObjects: (id) first, ...;
31@end;
32#endif
33
34// PGOGEN: @[[FRC:"__llvm_profile_counters_\+\[A foreach:\]"]] = internal global [2 x i64] zeroinitializer
35// PGOGEN: @[[BLC:"__llvm_profile_counters___13\+\[A foreach:\]_block_invoke"]] = internal global [2 x i64] zeroinitializer
36// PGOGEN: @[[MAC:__llvm_profile_counters_main]] = hidden global [1 x i64] zeroinitializer
37
38@interface A : NSObject
39+ (void)foreach: (NSArray *)array;
40@end
41
42@implementation A
43// PGOGEN: define {{.*}}+[A foreach:]
44// PGOUSE: define {{.*}}+[A foreach:]
45// PGOGEN: store {{.*}} @[[FRC]], i64 0, i64 0
46+ (void)foreach: (NSArray *)array
47{
48  __block id result;
49  // PGOGEN: store {{.*}} @[[FRC]], i64 0, i64 1
50  // PGOUSE: br {{.*}} !prof ![[FR1:[0-9]+]]
51  // PGOUSE: br {{.*}} !prof ![[FR2:[0-9]+]]
52  for (id x in array) {
53    // PGOGEN: define {{.*}}_block_invoke
54    // PGOUSE: define {{.*}}_block_invoke
55    // PGOGEN: store {{.*}} @[[BLC]], i64 0, i64 0
56    ^{ static int init = 0;
57      // PGOGEN: store {{.*}} @[[BLC]], i64 0, i64 1
58      // PGOUSE: br {{.*}} !prof ![[BL1:[0-9]+]]
59       if (init)
60         result = x;
61       init = 1; }();
62  }
63}
64@end
65
66// PGOUSE-DAG: ![[FR1]] = metadata !{metadata !"branch_weights", i32 2, i32 3}
67// PGOUSE-DAG: ![[FR2]] = metadata !{metadata !"branch_weights", i32 3, i32 2}
68// PGOUSE-DAG: ![[BL1]] = metadata !{metadata !"branch_weights", i32 2, i32 2}
69
70int main(int argc, const char *argv[]) {
71  A *a = [[A alloc] init];
72  NSArray *array = [NSArray arrayWithObjects: @"0", @"1", (void*)0];
73  [A foreach: array];
74  return 0;
75}
76