Artem Belevich | b5bc923 | 2015-09-22 17:23:22 +0000 | [diff] [blame] | 1 | // Tests that host and target builtins can be used in the same TU, |
| 2 | // have appropriate host/device attributes and that CUDA call |
| 3 | // restrictions are enforced. Also verify that non-target builtins can |
| 4 | // be used from both host and device functions. |
Artem Belevich | 9674a64 | 2015-09-22 17:23:05 +0000 | [diff] [blame] | 5 | // |
| 6 | // REQUIRES: x86-registered-target |
| 7 | // REQUIRES: nvptx-registered-target |
| 8 | // RUN: %clang_cc1 -triple x86_64-unknown-unknown \ |
Artem Belevich | b5bc923 | 2015-09-22 17:23:22 +0000 | [diff] [blame] | 9 | // RUN: -aux-triple nvptx64-unknown-cuda \ |
Artem Belevich | 9674a64 | 2015-09-22 17:23:05 +0000 | [diff] [blame] | 10 | // RUN: -fcuda-target-overloads -fsyntax-only -verify %s |
| 11 | // RUN: %clang_cc1 -triple nvptx64-unknown-cuda -fcuda-is-device \ |
Artem Belevich | b5bc923 | 2015-09-22 17:23:22 +0000 | [diff] [blame] | 12 | // RUN: -aux-triple x86_64-unknown-unknown \ |
Artem Belevich | 9674a64 | 2015-09-22 17:23:05 +0000 | [diff] [blame] | 13 | // RUN: -fcuda-target-overloads -fsyntax-only -verify %s |
| 14 | |
Artem Belevich | b5bc923 | 2015-09-22 17:23:22 +0000 | [diff] [blame] | 15 | #if !(defined(__amd64__) && defined(__PTX__)) |
| 16 | #error "Expected to see preprocessor macros from both sides of compilation." |
| 17 | #endif |
Artem Belevich | 9674a64 | 2015-09-22 17:23:05 +0000 | [diff] [blame] | 18 | |
Artem Belevich | 9674a64 | 2015-09-22 17:23:05 +0000 | [diff] [blame] | 19 | void hf() { |
Artem Belevich | b5bc923 | 2015-09-22 17:23:22 +0000 | [diff] [blame] | 20 | int x = __builtin_ia32_rdtsc(); |
| 21 | int y = __builtin_ptx_read_tid_x(); // expected-note {{'__builtin_ptx_read_tid_x' declared here}} |
Artem Belevich | 9674a64 | 2015-09-22 17:23:05 +0000 | [diff] [blame] | 22 | // expected-error@-1 {{reference to __device__ function '__builtin_ptx_read_tid_x' in __host__ function}} |
| 23 | x = __builtin_abs(1); |
| 24 | } |
Artem Belevich | b5bc923 | 2015-09-22 17:23:22 +0000 | [diff] [blame] | 25 | |
Artem Belevich | 9674a64 | 2015-09-22 17:23:05 +0000 | [diff] [blame] | 26 | __attribute__((device)) void df() { |
| 27 | int x = __builtin_ptx_read_tid_x(); |
Artem Belevich | b5bc923 | 2015-09-22 17:23:22 +0000 | [diff] [blame] | 28 | int y = __builtin_ia32_rdtsc(); // expected-error {{reference to __host__ function '__builtin_ia32_rdtsc' in __device__ function}} |
| 29 | // expected-note@20 {{'__builtin_ia32_rdtsc' declared here}} |
Artem Belevich | 9674a64 | 2015-09-22 17:23:05 +0000 | [diff] [blame] | 30 | x = __builtin_abs(1); |
| 31 | } |