Clang Project

clang_source_code/test/OpenMP/master_codegen.cpp
1// RUN: %clang_cc1 -verify -fopenmp -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s
2// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
3// RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
4// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -fexceptions -fcxx-exceptions -debug-info-kind=line-tables-only -x c++ -emit-llvm %s -o - | FileCheck %s --check-prefix=TERM_DEBUG
5
6// RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck --check-prefix SIMD-ONLY0 %s
7// RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
8// RUN: %clang_cc1 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
9// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp-simd -fexceptions -fcxx-exceptions -debug-info-kind=line-tables-only -x c++ -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
10// SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
11// expected-no-diagnostics
12#ifndef HEADER
13#define HEADER
14
15// CHECK:       [[IDENT_T_TY:%.+]] = type { i32, i32, i32, i32, i8* }
16
17// CHECK:       define {{.*}}void [[FOO:@.+]]()
18
19void foo() {}
20
21// CHECK-LABEL: @main
22// TERM_DEBUG-LABEL: @main
23int main() {
24  // CHECK:       [[A_ADDR:%.+]] = alloca i8
25  char a;
26
27// CHECK:       [[GTID:%.+]] = call {{.*}}i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEFAULT_LOC:@.+]])
28// CHECK:       [[RES:%.+]] = call {{.*}}i32 @__kmpc_master([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]])
29// CHECK-NEXT:  [[IS_MASTER:%.+]] = icmp ne i32 [[RES]], 0
30// CHECK-NEXT:  br i1 [[IS_MASTER]], label {{%?}}[[THEN:.+]], label {{%?}}[[EXIT:.+]]
31// CHECK:       [[THEN]]
32// CHECK-NEXT:  store i8 2, i8* [[A_ADDR]]
33// CHECK-NEXT:  call {{.*}}void @__kmpc_end_master([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]])
34// CHECK-NEXT:  br label {{%?}}[[EXIT]]
35// CHECK:       [[EXIT]]
36#pragma omp master
37  a = 2;
38// CHECK:       [[RES:%.+]] = call {{.*}}i32 @__kmpc_master([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]])
39// CHECK-NEXT:  [[IS_MASTER:%.+]] = icmp ne i32 [[RES]], 0
40// CHECK-NEXT:  br i1 [[IS_MASTER]], label {{%?}}[[THEN:.+]], label {{%?}}[[EXIT:.+]]
41// CHECK:       [[THEN]]
42// CHECK-NEXT:  invoke {{.*}}void [[FOO]]()
43// CHECK:       call {{.*}}void @__kmpc_end_master([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]])
44// CHECK-NEXT:  br label {{%?}}[[EXIT]]
45// CHECK:       [[EXIT]]
46#pragma omp master
47  foo();
48// CHECK-NOT:   call i32 @__kmpc_master
49// CHECK-NOT:   call void @__kmpc_end_master
50  return a;
51}
52
53// CHECK-LABEL:      parallel_master
54// TERM_DEBUG-LABEL: parallel_master
55void parallel_master() {
56#pragma omp parallel
57#pragma omp master
58  // TERM_DEBUG-NOT: __kmpc_global_thread_num
59  // TERM_DEBUG:     call i32 @__kmpc_master({{.+}}), !dbg [[DBG_LOC_START:![0-9]+]]
60  // TERM_DEBUG:     invoke void {{.*}}foo{{.*}}()
61  // TERM_DEBUG:     unwind label %[[TERM_LPAD:.+]],
62  // TERM_DEBUG-NOT: __kmpc_global_thread_num
63  // TERM_DEBUG:     call void @__kmpc_end_master({{.+}}), !dbg [[DBG_LOC_END:![0-9]+]]
64  // TERM_DEBUG:     [[TERM_LPAD]]
65  // TERM_DEBUG:     call void @__clang_call_terminate
66  // TERM_DEBUG:     unreachable
67  foo();
68}
69// TERM_DEBUG-DAG: [[DBG_LOC_START]] = !DILocation(line: [[@LINE-12]],
70// TERM_DEBUG-DAG: [[DBG_LOC_END]] = !DILocation(line: [[@LINE-3]],
71
72#endif
73