12f0a5714SMatt Arsenault // REQUIRES: amdgpu-registered-target
22f0a5714SMatt Arsenault 
32f0a5714SMatt Arsenault // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-ppc-host.bc
42f0a5714SMatt Arsenault // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck -check-prefixes=DEFAULT,ALL %s
52f0a5714SMatt Arsenault // RUN: %clang_cc1 -target-cpu gfx900 -fopenmp -x c++ -std=c++11 -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck -check-prefixes=CPU,ALL %s
62f0a5714SMatt Arsenault 
72f0a5714SMatt Arsenault // RUN: %clang_cc1 -menable-no-nans -mno-amdgpu-ieee -fopenmp -x c++ -std=c++11 -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck -check-prefixes=NOIEEE,ALL %s
82f0a5714SMatt Arsenault // RUN: %clang_cc1 -munsafe-fp-atomics -fopenmp -x c++ -std=c++11 -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck -check-prefixes=UNSAFEATOMIC,ALL %s
92f0a5714SMatt Arsenault 
102f0a5714SMatt Arsenault // expected-no-diagnostics
112f0a5714SMatt Arsenault 
122f0a5714SMatt Arsenault #define N 100
132f0a5714SMatt Arsenault 
142f0a5714SMatt Arsenault int callable(int);
152f0a5714SMatt Arsenault 
162f0a5714SMatt Arsenault // Check that the target attributes are set on the generated kernel
func()172f0a5714SMatt Arsenault int func() {
182f0a5714SMatt Arsenault   // ALL-LABEL: amdgpu_kernel void @__omp_offloading{{.*}} #0
192f0a5714SMatt Arsenault 
202f0a5714SMatt Arsenault   int arr[N];
212f0a5714SMatt Arsenault 
222f0a5714SMatt Arsenault #pragma omp target
232f0a5714SMatt Arsenault   for (int i = 0; i < N; i++) {
242f0a5714SMatt Arsenault     arr[i] = callable(arr[i]);
252f0a5714SMatt Arsenault   }
262f0a5714SMatt Arsenault 
272f0a5714SMatt Arsenault   return arr[0];
282f0a5714SMatt Arsenault }
292f0a5714SMatt Arsenault 
callable(int x)302f0a5714SMatt Arsenault int callable(int x) {
311b1c8d83Shyeongyu kim   // ALL-LABEL: @_Z8callablei(i32 noundef %x) #1
322f0a5714SMatt Arsenault   return x + 1;
332f0a5714SMatt Arsenault }
342f0a5714SMatt Arsenault 
35*53d5757eSJoseph Huber   // DEFAULT: attributes #0 = { convergent noinline norecurse nounwind optnone "frame-pointer"="none" "kernel" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
36*53d5757eSJoseph Huber   // CPU: attributes #0 = { convergent noinline norecurse nounwind optnone "frame-pointer"="none" "kernel" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="gfx900" "target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst" }
37*53d5757eSJoseph Huber   // NOIEEE: attributes #0 = { convergent noinline norecurse nounwind optnone "amdgpu-ieee"="false" "frame-pointer"="none" "kernel" "min-legal-vector-width"="0" "no-nans-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
38*53d5757eSJoseph Huber   // UNSAFEATOMIC: attributes #0 = { convergent noinline norecurse nounwind optnone "amdgpu-unsafe-fp-atomics"="true" "frame-pointer"="none" "kernel" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
392f0a5714SMatt Arsenault 
402f0a5714SMatt Arsenault // DEFAULT: attributes #1 = { convergent mustprogress noinline nounwind optnone "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
412f0a5714SMatt Arsenault // CPU: attributes #1 = { convergent mustprogress noinline nounwind optnone "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="gfx900" "target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst" }
422f0a5714SMatt Arsenault // NOIEEE: attributes #1 = { convergent mustprogress noinline nounwind optnone "amdgpu-ieee"="false" "frame-pointer"="none" "min-legal-vector-width"="0" "no-nans-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
432f0a5714SMatt Arsenault // UNSAFEATOMIC: attributes #1 = { convergent mustprogress noinline nounwind optnone "amdgpu-unsafe-fp-atomics"="true" "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
44