brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.8 KiB · 7947a62 Raw
80 lines · cpp
1// RUN: %libomptarget-compilexx-run-and-check-generic2 3#include <stdio.h>4 5struct View {6  int Data;7};8 9struct ViewPtr {10  int *Data;11};12 13template <typename T> struct Foo {14  Foo(T &V) : VRef(V) {}15  T &VRef;16};17 18int main() {19  View V;20  V.Data = 123456;21  Foo<View> Bar(V);22  ViewPtr V1;23  int Data = 123456;24  V1.Data = &Data;25  Foo<ViewPtr> Baz(V1);26  int D1, D2;27 28  // CHECK: Host 123456.29  printf("Host %d.\n", Bar.VRef.Data);30#pragma omp target map(Bar.VRef) map(from : D1, D2)31  {32    // CHECK: Device 123456.33    D1 = Bar.VRef.Data;34    printf("Device %d.\n", D1);35    V.Data = 654321;36    // CHECK: Device 654321.37    D2 = Bar.VRef.Data;38    printf("Device %d.\n", D2);39  }40  printf("Device %d.\n", D1);41  printf("Device %d.\n", D2);42  // CHECK: Host 654321 654321.43  printf("Host %d %d.\n", Bar.VRef.Data, V.Data);44  V.Data = 123456;45  // CHECK: Host 123456.46  printf("Host %d.\n", Bar.VRef.Data);47#pragma omp target map(Bar) map(Bar.VRef) map(from : D1, D2)48  {49    // CHECK: Device 123456.50    D1 = Bar.VRef.Data;51    printf("Device %d.\n", D1);52    V.Data = 654321;53    // CHECK: Device 654321.54    D2 = Bar.VRef.Data;55    printf("Device %d.\n", D2);56  }57  printf("Device %d.\n", D1);58  printf("Device %d.\n", D2);59  // CHECK: Host 654321 654321.60  printf("Host %d %d.\n", Bar.VRef.Data, V.Data);61  // CHECK: Host 123456.62  printf("Host %d.\n", *Baz.VRef.Data);63#pragma omp target map(Baz.VRef.Data) map(*Baz.VRef.Data) map(V1.Data[0 : 0])  \64    map(from : D1, D2)65  {66    // CHECK: Device 123456.67    D1 = *Baz.VRef.Data;68    printf("Device %d.\n", D1);69    *V1.Data = 654321;70    // CHECK: Device 654321.71    D2 = *Baz.VRef.Data;72    printf("Device %d.\n", D2);73  }74  printf("Device %d.\n", D1);75  printf("Device %d.\n", D2);76  // CHECK: Host 654321 654321 654321.77  printf("Host %d %d %d.\n", *Baz.VRef.Data, *V1.Data, Data);78  return 0;79}80