2015-09-23 01:23:22 +08:00
|
|
|
// Tests that host and target builtins can be used in the same TU,
|
|
|
|
// have appropriate host/device attributes and that CUDA call
|
|
|
|
// restrictions are enforced. Also verify that non-target builtins can
|
|
|
|
// be used from both host and device functions.
|
2015-09-23 01:23:05 +08:00
|
|
|
//
|
|
|
|
// REQUIRES: x86-registered-target
|
|
|
|
// REQUIRES: nvptx-registered-target
|
|
|
|
// RUN: %clang_cc1 -triple x86_64-unknown-unknown \
|
2015-09-23 01:23:22 +08:00
|
|
|
// RUN: -aux-triple nvptx64-unknown-cuda \
|
2016-03-30 00:24:16 +08:00
|
|
|
// RUN: -fsyntax-only -verify %s
|
2015-09-23 01:23:05 +08:00
|
|
|
// RUN: %clang_cc1 -triple nvptx64-unknown-cuda -fcuda-is-device \
|
2015-09-23 01:23:22 +08:00
|
|
|
// RUN: -aux-triple x86_64-unknown-unknown \
|
2016-03-30 00:24:16 +08:00
|
|
|
// RUN: -fsyntax-only -verify %s
|
2015-09-23 01:23:05 +08:00
|
|
|
|
2018-08-31 04:53:15 +08:00
|
|
|
#if !(defined(__amd64__) && defined(__PTX__))
|
|
|
|
#error "Expected to see preprocessor macros from both sides of compilation."
|
2015-09-23 01:23:22 +08:00
|
|
|
#endif
|
2015-09-23 01:23:05 +08:00
|
|
|
|
|
|
|
void hf() {
|
2015-09-23 01:23:22 +08:00
|
|
|
int x = __builtin_ia32_rdtsc();
|
2016-07-08 00:41:08 +08:00
|
|
|
int y = __nvvm_read_ptx_sreg_tid_x(); // expected-note {{'__nvvm_read_ptx_sreg_tid_x' declared here}}
|
|
|
|
// expected-error@-1 {{reference to __device__ function '__nvvm_read_ptx_sreg_tid_x' in __host__ function}}
|
2015-09-23 01:23:05 +08:00
|
|
|
x = __builtin_abs(1);
|
|
|
|
}
|
2015-09-23 01:23:22 +08:00
|
|
|
|
2015-09-23 01:23:05 +08:00
|
|
|
__attribute__((device)) void df() {
|
2016-07-08 00:41:08 +08:00
|
|
|
int x = __nvvm_read_ptx_sreg_tid_x();
|
2015-09-23 01:23:22 +08:00
|
|
|
int y = __builtin_ia32_rdtsc(); // expected-error {{reference to __host__ function '__builtin_ia32_rdtsc' in __device__ function}}
|
|
|
|
// expected-note@20 {{'__builtin_ia32_rdtsc' declared here}}
|
2015-09-23 01:23:05 +08:00
|
|
|
x = __builtin_abs(1);
|
|
|
|
}
|