File: forall-index.fir

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (71 lines) | stat: -rw-r--r-- 3,042 bytes parent folder | download | duplicates (12)
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
// Test hlfir.forall_index operation parse, verify (no errors), unparse,
// and canonicalization.
// RUN: fir-opt %s | fir-opt | FileCheck %s
// RUN: fir-opt -canonicalize %s | FileCheck %s --check-prefix=CANONICALIZATION

func.func @forall_index(%x: !fir.ref<!fir.array<10xf32>>, %y: !fir.ref<!fir.array<10xf32>>) {
  %c1 = arith.constant 1 : index
  %c10 = arith.constant 10 : index
  hlfir.forall lb {
    hlfir.yield %c1 : index
  } ub {
    hlfir.yield %c10 : index
  } (%arg0: i64) {
    %i = hlfir.forall_index "i" %arg0 : (i64) -> !fir.ref<i64>
    hlfir.region_assign {
      %ival = fir.load %i : !fir.ref<i64>
      %yi = hlfir.designate %y(%ival) : (!fir.ref<!fir.array<10xf32>>, i64) -> !fir.ref<f32>
      hlfir.yield %yi : !fir.ref<f32>
    } to {
      %ival = fir.load %i : !fir.ref<i64>
      %xi = hlfir.designate %x(%ival) : (!fir.ref<!fir.array<10xf32>>, i64) -> !fir.ref<f32>
      hlfir.yield %xi : !fir.ref<f32>
    }
  }
  return
}
// CHECK-LABEL:  func.func @forall_index(
// CHECK:           hlfir.forall lb {
// CHECK:           } ub {
// CHECK:           }  (%[[VAL_4:.*]]: i64) {
// CHECK:             hlfir.forall_index "i" %[[VAL_4]] : (i64) -> !fir.ref<i64>

// CANONICALIZATION-LABEL:  func.func @forall_index(
// CANONICALIZATION:      hlfir.forall lb {
// CANONICALIZATION:      } ub {
// CANONICALIZATION:      }  (%[[VAL_4:.*]]: i64) {
// CANONICALIZATION-NOT:    hlfir.forall_index
// CANONICALIZATION:        hlfir.designate %{{.*}} (%[[VAL_4]])  : (!fir.ref<!fir.array<10xf32>>, i64) -> !fir.ref<f32>
// CANONICALIZATION:        hlfir.designate %{{.*}} (%[[VAL_4]])  : (!fir.ref<!fir.array<10xf32>>, i64) -> !fir.ref<f32>

func.func @forall_index_do_not_canonicalize(%x: !fir.ref<!fir.array<10xf32>>, %y: !fir.ref<!fir.array<10xf32>>) {
  %c1 = arith.constant 1 : index
  %c10 = arith.constant 10 : index
  hlfir.forall lb {
    hlfir.yield %c1 : index
  } ub {
    hlfir.yield %c10 : index
  } (%arg0: i64) {
    %i = hlfir.forall_index "i" %arg0 : (i64) -> !fir.ref<i64>
    hlfir.region_assign {
      %res = fir.call @taking_address(%i) : (!fir.ref<i64>) -> f32
      hlfir.yield %res : f32
    } to {
      %ival = fir.load %i : !fir.ref<i64>
      %xi = hlfir.designate %x(%ival) : (!fir.ref<!fir.array<10xf32>>, i64) -> !fir.ref<f32>
      hlfir.yield %xi : !fir.ref<f32>
    }
  }
  return
}
// CHECK-LABEL:  func.func @forall_index_do_not_canonicalize(
// CHECK:           hlfir.forall lb {
// CHECK:           } ub {
// CHECK:           }  (%[[VAL_4:.*]]: i64) {
// CHECK:             hlfir.forall_index "i" %[[VAL_4]] : (i64) -> !fir.ref<i64>

// CANONICALIZATION-LABEL:  func.func @forall_index_do_not_canonicalize(
// CANONICALIZATION:  %[[VAL_5:.*]] = hlfir.forall_index "i" %[[VAL_4:.*]] : (i64) -> !fir.ref<i64>
// CANONICALIZATION:  fir.call @taking_address(%[[VAL_5]]) : (!fir.ref<i64>) -> f32
// CANONICALIZATION:  %[[VAL_6:.*]] = fir.load %[[VAL_5]] : !fir.ref<i64>
// CANONICALIZATION:  hlfir.designate %{{.*}} (%[[VAL_6]])  : (!fir.ref<!fir.array<10xf32>>, i64) -> !fir.ref<f32>