aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.fortran/allocate-6.f90
blob: 5034dd26b2e3d236865608e4bfba114522a2454a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
! { dg-additional-options "-fdump-tree-gimple" }
module m
  use iso_c_binding
  use omp_lib
  implicit none (type, external)
  integer(c_intptr_t) :: intptr

! { dg-final { scan-tree-dump-not "__builtin_stack_save" "gimple" } }
! { dg-final { scan-tree-dump-not "__builtin_alloca" "gimple" } }
! { dg-final { scan-tree-dump-not "__builtin_stack_restore" "gimple" } }

! { dg-final { scan-tree-dump-times "__builtin_GOMP_alloc \\(" 5 "gimple" } }
! { dg-final { scan-tree-dump-times "__builtin_GOMP_free \\(" 5 "gimple" } }

contains

subroutine one ()
  integer :: result, n, i
  result = 0
  n = 3
  !$omp target map(tofrom: result) firstprivate(n)
    block
      integer :: var, var2(n)
      !$omp allocate(var,var2) align(128) allocator(omp_low_lat_mem_alloc)
      var = 5
! { dg-final { scan-tree-dump-times "var\\.\[0-9\]+ = __builtin_GOMP_alloc \\(128, 4, 5\\);" 1 "gimple" } } */
! { dg-final { scan-tree-dump-times "var2 = __builtin_GOMP_alloc \\(128, D\\.\[0-9\]+, 5\\);" 1 "gimple" } } */

! { dg-final { scan-tree-dump-times "__builtin_GOMP_free \\(var\\.\[0-9\]+, 0B\\);" 1 "gimple" } } */
! { dg-final { scan-tree-dump-times "__builtin_GOMP_free \\(var2, 0B\\);" 1 "gimple" } } */

      if (mod(transfer(loc(var), intptr), 128_c_intptr_t) /= 0) &
        stop 1
      if (mod(transfer(loc(var2), intptr), 128_c_intptr_t) /= 0) &
        stop 2
      if (var /= 5) &
        stop 3

      !$omp parallel do
      do i = 1, n
        var2(i) = (i+32);
      end do

      !$omp parallel loop reduction(+:result)
      do i = 1, n
        result = result + var + var2(i)
      end do
    end block
  if (result /= (3*5 + 33 + 34 + 35)) &
    stop 4
end

subroutine two ()
  type st
    integer :: a, b
  end type
  integer :: scalar, array(5), i
  type(st) s
  !$omp allocate(scalar, array, s)
! { dg-final { scan-tree-dump-times "scalar\\.\[0-9\]+ = __builtin_GOMP_alloc \\(4, 4, 0B\\);" 1 "gimple" } }
! { dg-final { scan-tree-dump-times "array\\.\[0-9\]+ = __builtin_GOMP_alloc \\(4, 20, 0B\\);" 1 "gimple" } }
! { dg-final { scan-tree-dump-times "s\\.\[0-9\]+ = __builtin_GOMP_alloc \\(4, 8, 0B\\);" 1 "gimple" } }
! { dg-final { scan-tree-dump-times "__builtin_GOMP_free \\(scalar\\.\[0-9\]+, 0B\\);" 1 "gimple" } }
! { dg-final { scan-tree-dump-times "__builtin_GOMP_free \\(array\\.\[0-9\]+, 0B\\);" 1 "gimple" } }
! { dg-final { scan-tree-dump-times "__builtin_GOMP_free \\(s\\.\[0-9\]+, 0B\\);" 1 "gimple" } }

  scalar = 44
  array = [1,2,3,4,5]
  s = st(a=11, b=56)

  !$omp parallel firstprivate(scalar) firstprivate(array) firstprivate(s)
    if (scalar /= 44) &
      stop 5
    scalar = 33;
    if (any (array /= [1,2,3,4,5])) &
      stop 6
    array = [10,20,30,40,50]
    if (s%a /= 11 .or. s%b /= 56) &
      stop 7
    s%a = 74
    s%b = 674
  !$omp end parallel

  if (scalar /= 44) &
    stop 8
  if (any (array /= [1,2,3,4,5])) &
    stop 9
  if (s%a /= 11 .or. s%b /= 56) &
    stop 10

  !$omp target defaultmap(firstprivate : scalar) defaultmap(none : aggregate) defaultmap(none : pointer)
    if (scalar /= 44) &
      stop 11
    scalar = 33;
  !$omp end target

  if (scalar /= 44) &
    stop 12

  !$omp target defaultmap(none : scalar) defaultmap(firstprivate : aggregate) defaultmap(none : pointer) private(i)
    if (any (array /= [1,2,3,4,5])) &
      stop 13
    do i = 1, 5
      array(i) = 10*i
    end do
  !$omp end target

  if (any(array /= [1,2,3,4,5])) &
    stop 13
  !$omp target defaultmap(none : scalar) defaultmap(firstprivate : aggregate) defaultmap(none : pointer)
    if (s%a /= 11 .or. s%b /= 56) &
      stop 14
    s%a = 74
    s%b = 674
  !$omp end target
  if (s%a /= 11 .or. s%b /= 56) &
    stop 15
end
end module

use m
  call one ()
  call two ()
end