[RISCV][VLOPT] Add vector narrowing integer right shift instructions to isSupportedIn...
[llvm-project.git] / offload / test / offloading / requires.c
blob2a129a7ae86dcb2e0ce92af98703d4e1e6f21364
1 // clang-format off
2 // RUN: %libomptarget-compile-generic -DREQ=1 && %libomptarget-run-generic 2>&1 | %fcheck-generic -check-prefix=GOOD
3 // RUN: %libomptarget-compile-generic -DREQ=2 && not %libomptarget-run-generic 2>&1 | %fcheck-generic -check-prefix=BAD
4 // clang-format on
6 /*
7 Test for the 'requires' clause check.
8 When a target region is used, the requires flags are set in the
9 runtime for the entire compilation unit. If the flags are set again,
10 (for whatever reason) the set must be consistent with previously
11 set values.
13 #include <omp.h>
14 #include <stdio.h>
16 // ---------------------------------------------------------------------------
17 // Various definitions copied from OpenMP RTL
19 typedef struct {
20 void *addr;
21 char *name;
22 size_t size;
23 int32_t flags;
24 int32_t data;
25 } __tgt_offload_entry;
27 enum Flags {
28 OMP_REGISTER_REQUIRES = 0x10,
31 typedef struct {
32 void *ImageStart;
33 void *ImageEnd;
34 __tgt_offload_entry *EntriesBegin;
35 __tgt_offload_entry *EntriesEnd;
36 } __tgt_device_image;
38 typedef struct {
39 int32_t NumDeviceImages;
40 __tgt_device_image *DeviceImages;
41 __tgt_offload_entry *HostEntriesBegin;
42 __tgt_offload_entry *HostEntriesEnd;
43 } __tgt_bin_desc;
45 void __tgt_register_lib(__tgt_bin_desc *Desc);
46 void __tgt_unregister_lib(__tgt_bin_desc *Desc);
48 // End of definitions copied from OpenMP RTL.
49 // ---------------------------------------------------------------------------
51 void run_reg_requires() {
52 // Before the target region is registered, the requires registers the status
53 // of the requires clauses. Since there are no requires clauses in this file
54 // the flags state can only be OMP_REQ_NONE i.e. 1.
56 // This is the 2nd time this function is called so it should print SUCCESS if
57 // REQ is compatible with `1` and otherwise cause an error.
58 __tgt_offload_entry entries[] = {{NULL, "", 0, OMP_REGISTER_REQUIRES, 1},
59 {NULL, "", 0, OMP_REGISTER_REQUIRES, REQ}};
60 __tgt_device_image image = {NULL, NULL, &entries[0], &entries[1] + 1};
61 __tgt_bin_desc bin = {1, &image, &entries[0], &entries[1] + 1};
63 __tgt_register_lib(&bin);
65 printf("SUCCESS");
67 __tgt_unregister_lib(&bin);
69 // clang-format off
70 // GOOD: SUCCESS
71 // BAD: omptarget fatal error 2: '#pragma omp requires reverse_offload' not used consistently!
72 // clang-format on
75 // ---------------------------------------------------------------------------
76 int main() {
77 run_reg_requires();
79 // This also runs reg requires for the first time.
80 #pragma omp target
83 return 0;