1 // RUN: %libomptarget-compilexx-run-and-check-aarch64-unknown-linux-gnu
2 // RUN: %libomptarget-compilexx-run-and-check-powerpc64-ibm-linux-gnu
3 // RUN: %libomptarget-compilexx-run-and-check-powerpc64le-ibm-linux-gnu
4 // RUN: %libomptarget-compilexx-run-and-check-x86_64-pc-linux-gnu
5 // RUN: %libomptarget-compilexx-run-and-check-nvptx64-nvidia-cuda
6 
7 #include <cstdio>
8 #include <cstdlib>
9 #include <vector>
10 #include <cinttypes>
11 
12 // Data structure definitions copied from OpenMP RTL.
13 struct MapComponentInfoTy {
14   void *Base;
15   void *Begin;
16   int64_t Size;
17   int64_t Type;
18   void *Name;
19   MapComponentInfoTy() = default;
20   MapComponentInfoTy(void *Base, void *Begin, int64_t Size, int64_t Type, void *Name)
21       : Base(Base), Begin(Begin), Size(Size), Type(Type), Name(Name) {}
22 };
23 
24 struct MapperComponentsTy {
25   std::vector<MapComponentInfoTy> Components;
26 };
27 
28 // OpenMP RTL interfaces
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 int64_t __tgt_mapper_num_components(void *rt_mapper_handle);
33 void __tgt_push_mapper_component(void *rt_mapper_handle, void *base,
34                                  void *begin, int64_t size, int64_t type,
35                                  void *name);
36 #ifdef __cplusplus
37 }
38 #endif
39 
40 int main(int argc, char *argv[]) {
41   MapperComponentsTy MC;
42   void *base, *begin;
43   int64_t size, type;
44   // Push 2 elements into MC.
45   __tgt_push_mapper_component((void *)&MC, base, begin, size, type, nullptr);
46   __tgt_push_mapper_component((void *)&MC, base, begin, size, type, nullptr);
47   int64_t num = __tgt_mapper_num_components((void *)&MC);
48   // CHECK: num=2
49   printf("num=%" PRId64 "\n", num);
50   return 0;
51 }
52