Home | History | Annotate | Download | only in OpenMP
      1 // RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -x c -emit-llvm %s -o - | FileCheck %s
      2 // RUN: %clang_cc1 -fopenmp -x c -triple x86_64-apple-darwin10 -emit-pch -o %t %s
      3 // RUN: %clang_cc1 -fopenmp -x c -triple x86_64-apple-darwin10 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
      4 // expected-no-diagnostics
      5 // REQUIRES: x86-registered-target
      6 #ifndef HEADER
      7 #define HEADER
      8 
      9 _Bool bv, bx;
     10 char cv, cx;
     11 unsigned char ucv, ucx;
     12 short sv, sx;
     13 unsigned short usv, usx;
     14 int iv, ix;
     15 unsigned int uiv, uix;
     16 long lv, lx;
     17 unsigned long ulv, ulx;
     18 long long llv, llx;
     19 unsigned long long ullv, ullx;
     20 float fv, fx;
     21 double dv, dx;
     22 long double ldv, ldx;
     23 _Complex int civ, cix;
     24 _Complex float cfv, cfx;
     25 _Complex double cdv, cdx;
     26 
     27 typedef int int4 __attribute__((__vector_size__(16)));
     28 int4 int4x;
     29 
     30 struct BitFields {
     31   int : 32;
     32   int a : 31;
     33 } bfx;
     34 
     35 struct BitFields_packed {
     36   int : 32;
     37   int a : 31;
     38 } __attribute__ ((__packed__)) bfx_packed;
     39 
     40 struct BitFields2 {
     41   int : 31;
     42   int a : 1;
     43 } bfx2;
     44 
     45 struct BitFields2_packed {
     46   int : 31;
     47   int a : 1;
     48 } __attribute__ ((__packed__)) bfx2_packed;
     49 
     50 struct BitFields3 {
     51   int : 11;
     52   int a : 14;
     53 } bfx3;
     54 
     55 struct BitFields3_packed {
     56   int : 11;
     57   int a : 14;
     58 } __attribute__ ((__packed__)) bfx3_packed;
     59 
     60 struct BitFields4 {
     61   short : 16;
     62   int a: 1;
     63   long b : 7;
     64 } bfx4;
     65 
     66 struct BitFields4_packed {
     67   short : 16;
     68   int a: 1;
     69   long b : 7;
     70 } __attribute__ ((__packed__)) bfx4_packed;
     71 
     72 typedef float float2 __attribute__((ext_vector_type(2)));
     73 float2 float2x;
     74 
     75 // Register "0" is currently an invalid register for global register variables.
     76 // Use "esp" instead of "0".
     77 // register int rix __asm__("0");
     78 register int rix __asm__("esp");
     79 
     80 int main() {
     81 // CHECK: load atomic i8, i8*
     82 // CHECK: store i8
     83 #pragma omp atomic read
     84   bv = bx;
     85 // CHECK: load atomic i8, i8*
     86 // CHECK: store i8
     87 #pragma omp atomic read
     88   cv = cx;
     89 // CHECK: load atomic i8, i8*
     90 // CHECK: store i8
     91 #pragma omp atomic read
     92   ucv = ucx;
     93 // CHECK: load atomic i16, i16*
     94 // CHECK: store i16
     95 #pragma omp atomic read
     96   sv = sx;
     97 // CHECK: load atomic i16, i16*
     98 // CHECK: store i16
     99 #pragma omp atomic read
    100   usv = usx;
    101 // CHECK: load atomic i32, i32*
    102 // CHECK: store i32
    103 #pragma omp atomic read
    104   iv = ix;
    105 // CHECK: load atomic i32, i32*
    106 // CHECK: store i32
    107 #pragma omp atomic read
    108   uiv = uix;
    109 // CHECK: load atomic i64, i64*
    110 // CHECK: store i64
    111 #pragma omp atomic read
    112   lv = lx;
    113 // CHECK: load atomic i64, i64*
    114 // CHECK: store i64
    115 #pragma omp atomic read
    116   ulv = ulx;
    117 // CHECK: load atomic i64, i64*
    118 // CHECK: store i64
    119 #pragma omp atomic read
    120   llv = llx;
    121 // CHECK: load atomic i64, i64*
    122 // CHECK: store i64
    123 #pragma omp atomic read
    124   ullv = ullx;
    125 // CHECK: load atomic i32, i32* bitcast (float*
    126 // CHECK: bitcast i32 {{.*}} to float
    127 // CHECK: store float
    128 #pragma omp atomic read
    129   fv = fx;
    130 // CHECK: load atomic i64, i64* bitcast (double*
    131 // CHECK: bitcast i64 {{.*}} to double
    132 // CHECK: store double
    133 #pragma omp atomic read
    134   dv = dx;
    135 // CHECK: [[LD:%.+]] = load atomic i128, i128* bitcast (x86_fp80*
    136 // CHECK: [[BITCAST:%.+]] = bitcast x86_fp80* [[LDTEMP:%.*]] to i128*
    137 // CHECK: store i128 [[LD]], i128* [[BITCAST]]
    138 // CHECK: [[LD:%.+]] = load x86_fp80, x86_fp80* [[LDTEMP]]
    139 // CHECK: store x86_fp80 [[LD]]
    140 #pragma omp atomic read
    141   ldv = ldx;
    142 // CHECK: call{{.*}} void @__atomic_load(i64 8,
    143 // CHECK: store i32
    144 // CHECK: store i32
    145 #pragma omp atomic read
    146   civ = cix;
    147 // CHECK: call{{.*}} void @__atomic_load(i64 8,
    148 // CHECK: store float
    149 // CHECK: store float
    150 #pragma omp atomic read
    151   cfv = cfx;
    152 // CHECK: call{{.*}} void @__atomic_load(i64 16,
    153 // CHECK: call{{.*}} @__kmpc_flush(
    154 // CHECK: store double
    155 // CHECK: store double
    156 #pragma omp atomic seq_cst read
    157   cdv = cdx;
    158 // CHECK: load atomic i64, i64*
    159 // CHECK: store i8
    160 #pragma omp atomic read
    161   bv = ulx;
    162 // CHECK: load atomic i8, i8*
    163 // CHECK: store i8
    164 #pragma omp atomic read
    165   cv = bx;
    166 // CHECK: load atomic i8, i8*
    167 // CHECK: call{{.*}} @__kmpc_flush(
    168 // CHECK: store i8
    169 #pragma omp atomic read, seq_cst
    170   ucv = cx;
    171 // CHECK: load atomic i64, i64*
    172 // CHECK: store i16
    173 #pragma omp atomic read
    174   sv = ulx;
    175 // CHECK: load atomic i64, i64*
    176 // CHECK: store i16
    177 #pragma omp atomic read
    178   usv = lx;
    179 // CHECK: load atomic i32, i32*
    180 // CHECK: call{{.*}} @__kmpc_flush(
    181 // CHECK: store i32
    182 #pragma omp atomic seq_cst, read
    183   iv = uix;
    184 // CHECK: load atomic i32, i32*
    185 // CHECK: store i32
    186 #pragma omp atomic read
    187   uiv = ix;
    188 // CHECK: call{{.*}} void @__atomic_load(i64 8,
    189 // CHECK: store i64
    190 #pragma omp atomic read
    191   lv = cix;
    192 // CHECK: load atomic i32, i32*
    193 // CHECK: store i64
    194 #pragma omp atomic read
    195   ulv = fx;
    196 // CHECK: load atomic i64, i64*
    197 // CHECK: store i64
    198 #pragma omp atomic read
    199   llv = dx;
    200 // CHECK: load atomic i128, i128*
    201 // CHECK: store i64
    202 #pragma omp atomic read
    203   ullv = ldx;
    204 // CHECK: call{{.*}} void @__atomic_load(i64 8,
    205 // CHECK: store float
    206 #pragma omp atomic read
    207   fv = cix;
    208 // CHECK: load atomic i16, i16*
    209 // CHECK: store double
    210 #pragma omp atomic read
    211   dv = sx;
    212 // CHECK: load atomic i8, i8*
    213 // CHECK: store x86_fp80
    214 #pragma omp atomic read
    215   ldv = bx;
    216 // CHECK: load atomic i8, i8*
    217 // CHECK: store i32
    218 // CHECK: store i32
    219 #pragma omp atomic read
    220   civ = bx;
    221 // CHECK: load atomic i16, i16*
    222 // CHECK: store float
    223 // CHECK: store float
    224 #pragma omp atomic read
    225   cfv = usx;
    226 // CHECK: load atomic i64, i64*
    227 // CHECK: store double
    228 // CHECK: store double
    229 #pragma omp atomic read
    230   cdv = llx;
    231 // CHECK: [[I128VAL:%.+]] = load atomic i128, i128* bitcast (<4 x i32>* @{{.+}} to i128*) monotonic
    232 // CHECK: [[I128PTR:%.+]] = bitcast <4 x i32>* [[LDTEMP:%.+]] to i128*
    233 // CHECK: store i128 [[I128VAL]], i128* [[I128PTR]]
    234 // CHECK: [[LD:%.+]] = load <4 x i32>, <4 x i32>* [[LDTEMP]]
    235 // CHECK: extractelement <4 x i32> [[LD]]
    236 // CHECK: store i8
    237 #pragma omp atomic read
    238   bv = int4x[0];
    239 // CHECK: [[LD:%.+]] = load atomic i32, i32* bitcast (i8* getelementptr (i8, i8* bitcast (%{{.+}}* @{{.+}} to i8*), i64 4) to i32*) monotonic
    240 // CHECK: store i32 [[LD]], i32* [[LDTEMP:%.+]]
    241 // CHECK: [[LD:%.+]] = load i32, i32* [[LDTEMP]]
    242 // CHECK: [[SHL:%.+]] = shl i32 [[LD]], 1
    243 // CHECK: ashr i32 [[SHL]], 1
    244 // CHECK: store x86_fp80
    245 #pragma omp atomic read
    246   ldv = bfx.a;
    247 // CHECK: [[LDTEMP_VOID_PTR:%.+]] = bitcast i32* [[LDTEMP:%.+]] to i8*
    248 // CHECK: call void @__atomic_load(i64 4, i8* getelementptr (i8, i8* bitcast (%struct.BitFields_packed* @bfx_packed to i8*), i64 4), i8* [[LDTEMP_VOID_PTR]], i32 0)
    249 // CHECK: [[LD:%.+]] = load i32, i32* [[LDTEMP]]
    250 // CHECK: [[SHL:%.+]] = shl i32 [[LD]], 1
    251 // CHECK: ashr i32 [[SHL]], 1
    252 // CHECK: store x86_fp80
    253 #pragma omp atomic read
    254   ldv = bfx_packed.a;
    255 // CHECK: [[LD:%.+]] = load atomic i32, i32* getelementptr inbounds (%struct.BitFields2, %struct.BitFields2* @bfx2, i32 0, i32 0) monotonic
    256 // CHECK: store i32 [[LD]], i32* [[LDTEMP:%.+]]
    257 // CHECK: [[LD:%.+]] = load i32, i32* [[LDTEMP]]
    258 // CHECK: ashr i32 [[LD]], 31
    259 // CHECK: store x86_fp80
    260 #pragma omp atomic read
    261   ldv = bfx2.a;
    262 // CHECK: [[LD:%.+]] = load atomic i8, i8* getelementptr (i8, i8* bitcast (%struct.BitFields2_packed* @bfx2_packed to i8*), i64 3) monotonic
    263 // CHECK: store i8 [[LD]], i8* [[LDTEMP:%.+]]
    264 // CHECK: [[LD:%.+]] = load i8, i8* [[LDTEMP]]
    265 // CHECK: ashr i8 [[LD]], 7
    266 // CHECK: store x86_fp80
    267 #pragma omp atomic read
    268   ldv = bfx2_packed.a;
    269 // CHECK: [[LD:%.+]] = load atomic i32, i32* getelementptr inbounds (%struct.BitFields3, %struct.BitFields3* @bfx3, i32 0, i32 0) monotonic
    270 // CHECK: store i32 [[LD]], i32* [[LDTEMP:%.+]]
    271 // CHECK: [[LD:%.+]] = load i32, i32* [[LDTEMP]]
    272 // CHECK: [[SHL:%.+]] = shl i32 [[LD]], 7
    273 // CHECK: ashr i32 [[SHL]], 18
    274 // CHECK: store x86_fp80
    275 #pragma omp atomic read
    276   ldv = bfx3.a;
    277 // CHECK: [[LDTEMP_VOID_PTR:%.+]] = bitcast i24* [[LDTEMP:%.+]] to i8*
    278 // CHECK: call void @__atomic_load(i64 3, i8* getelementptr (i8, i8* bitcast (%struct.BitFields3_packed* @bfx3_packed to i8*), i64 1), i8* [[LDTEMP_VOID_PTR]], i32 0)
    279 // CHECK: [[LD:%.+]] = load i24, i24* [[LDTEMP]]
    280 // CHECK: [[SHL:%.+]] = shl i24 [[LD]], 7
    281 // CHECK: [[ASHR:%.+]] = ashr i24 [[SHL]], 10
    282 // CHECK: sext i24 [[ASHR]] to i32
    283 // CHECK: store x86_fp80
    284 #pragma omp atomic read
    285   ldv = bfx3_packed.a;
    286 // CHECK: [[LD:%.+]] = load atomic i64, i64* bitcast (%struct.BitFields4* @bfx4 to i64*) monotonic
    287 // CHECK: store i64 [[LD]], i64* [[LDTEMP:%.+]]
    288 // CHECK: [[LD:%.+]] = load i64, i64* [[LDTEMP]]
    289 // CHECK: [[SHL:%.+]] = shl i64 [[LD]], 47
    290 // CHECK: [[ASHR:%.+]] = ashr i64 [[SHL]], 63
    291 // CHECK: trunc i64 [[ASHR]] to i32
    292 // CHECK: store x86_fp80
    293 #pragma omp atomic read
    294   ldv = bfx4.a;
    295 // CHECK: [[LD:%.+]] = load atomic i8, i8* getelementptr inbounds (%struct.BitFields4_packed, %struct.BitFields4_packed* @bfx4_packed, i32 0, i32 0, i64 2) monotonic
    296 // CHECK: store i8 [[LD]], i8* [[LDTEMP:%.+]]
    297 // CHECK: [[LD:%.+]] = load i8, i8* [[LDTEMP]]
    298 // CHECK: [[SHL:%.+]] = shl i8 [[LD]], 7
    299 // CHECK: [[ASHR:%.+]] = ashr i8 [[SHL]], 7
    300 // CHECK: sext i8 [[ASHR]] to i32
    301 // CHECK: store x86_fp80
    302 #pragma omp atomic read
    303   ldv = bfx4_packed.a;
    304 // CHECK: [[LD:%.+]] = load atomic i64, i64* bitcast (%struct.BitFields4* @bfx4 to i64*) monotonic
    305 // CHECK: store i64 [[LD]], i64* [[LDTEMP:%.+]]
    306 // CHECK: [[LD:%.+]] = load i64, i64* [[LDTEMP]]
    307 // CHECK: [[SHL:%.+]] = shl i64 [[LD]], 40
    308 // CHECK: [[ASHR:%.+]] = ashr i64 [[SHL]], 57
    309 // CHECK: store x86_fp80
    310 #pragma omp atomic read
    311   ldv = bfx4.b;
    312 // CHECK: [[LD:%.+]] = load atomic i8, i8* getelementptr inbounds (%struct.BitFields4_packed, %struct.BitFields4_packed* @bfx4_packed, i32 0, i32 0, i64 2) monotonic
    313 // CHECK: store i8 [[LD]], i8* [[LDTEMP:%.+]]
    314 // CHECK: [[LD:%.+]] = load i8, i8* [[LDTEMP]]
    315 // CHECK: [[ASHR:%.+]] = ashr i8 [[LD]], 1
    316 // CHECK: sext i8 [[ASHR]] to i64
    317 // CHECK: store x86_fp80
    318 #pragma omp atomic read
    319   ldv = bfx4_packed.b;
    320 // CHECK: [[LD:%.+]] = load atomic i64, i64* bitcast (<2 x float>* @{{.+}} to i64*) monotonic
    321 // CHECK: [[BITCAST:%.+]] = bitcast <2 x float>* [[LDTEMP:%.+]] to i64*
    322 // CHECK: store i64 [[LD]], i64* [[BITCAST]]
    323 // CHECK: [[LD:%.+]] = load <2 x float>, <2 x float>* [[LDTEMP]]
    324 // CHECK: extractelement <2 x float> [[LD]]
    325 // CHECK: store i64
    326 #pragma omp atomic read
    327   ulv = float2x.x;
    328 // CHECK: call{{.*}} i{{[0-9]+}} @llvm.read_register
    329 // CHECK: call{{.*}} @__kmpc_flush(
    330 // CHECK: store double
    331 #pragma omp atomic read seq_cst
    332   dv = rix;
    333   return 0;
    334 }
    335 
    336 #endif
    337