xref: /llvm-project/clang/test/Headers/amdgcn-openmp-device-math-complex.cpp (revision 63ca93c7d1d1ee91281ff7ccdbd7014151319324)
112dcbf91SPushpinder Singh // RUN: %clang_cc1 -verify -internal-isystem %S/Inputs/include -fopenmp -x c++ -triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-x86-host.bc
2*63ca93c7SSergio Afonso // RUN: %clang_cc1 -verify -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_device_functions.h -internal-isystem %S/Inputs/include -fopenmp -x c++ -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-x86-host.bc -aux-triple x86_64-unknown-unknown -o - | FileCheck %s
312dcbf91SPushpinder Singh // expected-no-diagnostics
412dcbf91SPushpinder Singh 
512dcbf91SPushpinder Singh #include <cmath>
612dcbf91SPushpinder Singh #include <complex>
712dcbf91SPushpinder Singh 
812dcbf91SPushpinder Singh // CHECK: define weak {{.*}} @__muldc3
912dcbf91SPushpinder Singh // CHECK-DAG: call i32 @__ocml_isnan_f64(
1012dcbf91SPushpinder Singh // CHECK-DAG: call i32 @__ocml_isinf_f64(
1112dcbf91SPushpinder Singh 
1212dcbf91SPushpinder Singh // CHECK: define weak {{.*}} @__mulsc3
1312dcbf91SPushpinder Singh // CHECK-DAG: call i32 @__ocml_isnan_f32(
1412dcbf91SPushpinder Singh // CHECK-DAG: call i32 @__ocml_isinf_f32(
1512dcbf91SPushpinder Singh // CHECK-DAG: call float @__ocml_copysign_f32(
1612dcbf91SPushpinder Singh 
1712dcbf91SPushpinder Singh // CHECK: define weak {{.*}} @__divdc3
1812dcbf91SPushpinder Singh // CHECK-DAG: call i32 @__ocml_isnan_f64(
1912dcbf91SPushpinder Singh // CHECK-DAG: call i32 @__ocml_isinf_f64(
2012dcbf91SPushpinder Singh // CHECK-DAG: call i32 @__ocml_isfinite_f64(
2112dcbf91SPushpinder Singh // CHECK-DAG: call double @__ocml_copysign_f64(
2212dcbf91SPushpinder Singh // CHECK-DAG: call double @__ocml_scalbn_f64(
2312dcbf91SPushpinder Singh // CHECK-DAG: call double @__ocml_fabs_f64(
2412dcbf91SPushpinder Singh // CHECK-DAG: call double @__ocml_logb_f64(
2512dcbf91SPushpinder Singh 
2612dcbf91SPushpinder Singh // CHECK: define weak {{.*}} @__divsc3
2712dcbf91SPushpinder Singh // CHECK-DAG: call i32 @__ocml_isnan_f32(
2812dcbf91SPushpinder Singh // CHECK-DAG: call i32 @__ocml_isinf_f32(
2912dcbf91SPushpinder Singh // CHECK-DAG: call i32 @__ocml_isfinite_f32(
3012dcbf91SPushpinder Singh // CHECK-DAG: call float @__ocml_copysign_f32(
3112dcbf91SPushpinder Singh // CHECK-DAG: call float @__ocml_scalbn_f32(
3212dcbf91SPushpinder Singh // CHECK-DAG: call float @__ocml_fabs_f32(
3312dcbf91SPushpinder Singh // CHECK-DAG: call float @__ocml_logb_f32(
3412dcbf91SPushpinder Singh 
3512dcbf91SPushpinder Singh // We actually check that there are no declarations of non-OpenMP functions.
3612dcbf91SPushpinder Singh // That is, as long as we don't call an unkown function with a name that
3712dcbf91SPushpinder Singh // doesn't start with '__' we are good :)
3812dcbf91SPushpinder Singh 
3912dcbf91SPushpinder Singh // CHECK-NOT: declare.*@[^_]
4012dcbf91SPushpinder Singh 
test_scmplx(std::complex<float> a)4112dcbf91SPushpinder Singh void test_scmplx(std::complex<float> a) {
4212dcbf91SPushpinder Singh #pragma omp target
4312dcbf91SPushpinder Singh   {
4412dcbf91SPushpinder Singh     (void)(a * (a / a));
4512dcbf91SPushpinder Singh   }
4612dcbf91SPushpinder Singh }
4712dcbf91SPushpinder Singh 
test_dcmplx(std::complex<double> a)4812dcbf91SPushpinder Singh void test_dcmplx(std::complex<double> a) {
4912dcbf91SPushpinder Singh #pragma omp target
5012dcbf91SPushpinder Singh   {
5112dcbf91SPushpinder Singh     (void)(a * (a / a));
5212dcbf91SPushpinder Singh   }
5312dcbf91SPushpinder Singh }
5412dcbf91SPushpinder Singh 
5512dcbf91SPushpinder Singh template <typename T>
test_template_math_calls(std::complex<T> a)5612dcbf91SPushpinder Singh std::complex<T> test_template_math_calls(std::complex<T> a) {
5712dcbf91SPushpinder Singh   decltype(a) r = a;
5812dcbf91SPushpinder Singh #pragma omp target
5912dcbf91SPushpinder Singh   {
6012dcbf91SPushpinder Singh     r = std::sin(r);
6112dcbf91SPushpinder Singh     r = std::cos(r);
6212dcbf91SPushpinder Singh     r = std::exp(r);
6312dcbf91SPushpinder Singh     r = std::atan(r);
6412dcbf91SPushpinder Singh     r = std::acos(r);
6512dcbf91SPushpinder Singh   }
6612dcbf91SPushpinder Singh   return r;
6712dcbf91SPushpinder Singh }
6812dcbf91SPushpinder Singh 
test_scall(std::complex<float> a)6912dcbf91SPushpinder Singh std::complex<float> test_scall(std::complex<float> a) {
7012dcbf91SPushpinder Singh   decltype(a) r;
7112dcbf91SPushpinder Singh #pragma omp target
7212dcbf91SPushpinder Singh   {
7312dcbf91SPushpinder Singh     r = std::sin(a);
7412dcbf91SPushpinder Singh   }
7512dcbf91SPushpinder Singh   return test_template_math_calls(r);
7612dcbf91SPushpinder Singh }
7712dcbf91SPushpinder Singh 
test_dcall(std::complex<double> a)7812dcbf91SPushpinder Singh std::complex<double> test_dcall(std::complex<double> a) {
7912dcbf91SPushpinder Singh   decltype(a) r;
8012dcbf91SPushpinder Singh #pragma omp target
8112dcbf91SPushpinder Singh   {
8212dcbf91SPushpinder Singh     r = std::exp(a);
8312dcbf91SPushpinder Singh   }
8412dcbf91SPushpinder Singh   return test_template_math_calls(r);
8512dcbf91SPushpinder Singh }
86