File: apply-codegen.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 (31 lines) | stat: -rw-r--r-- 2,205 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
// Test hlfir.apply code generation
// RUN: fir-opt %s -bufferize-hlfir | FileCheck %s

func.func @numeric_apply(%arg0 : !fir.ref<!fir.array<100xi32>>) {
  %expr = hlfir.as_expr %arg0 : (!fir.ref<!fir.array<100xi32>>) -> !hlfir.expr<100xi32>
  %c42 = arith.constant 42 : index
  %elem = hlfir.apply %expr, %c42 : (!hlfir.expr<100xi32>, index) -> i32
  return
}
// CHECK-LABEL:   func.func @numeric_apply(
// CHECK:    %[[VAL_5:.*]]:2 = hlfir.declare %{{.*}}(%{{.*}}) {uniq_name = ".tmp"}
// CHECK:    %[[VAL_9:.*]] = arith.constant 42 : index
// CHECK:    %[[VAL_10:.*]] = hlfir.designate %[[VAL_5]]#0 (%[[VAL_9]])  : (!fir.heap<!fir.array<100xi32>>, index) -> !fir.ref<i32>
// CHECK:    %[[VAL_11:.*]] = fir.load %[[VAL_10]] : !fir.ref<i32>

func.func @character_apply(%arg0 : !fir.ref<!fir.array<?x!fir.char<2,?>>>, %l: index, %n: index) {
  %shape = fir.shape %n : (index) -> !fir.shape<1>
  %c:2 = hlfir.declare %arg0(%shape) typeparams %l {uniq_name = "c"} : (!fir.ref<!fir.array<?x!fir.char<2,?>>>, !fir.shape<1>, index) -> (!fir.box<!fir.array<?x!fir.char<2,?>>>, !fir.ref<!fir.array<?x!fir.char<2,?>>>)
  %expr = hlfir.as_expr %c#0 : (!fir.box<!fir.array<?x!fir.char<2,?>>>) -> !hlfir.expr<?x!fir.char<2,?>>
  %c42 = arith.constant 42 : index
  %elem = hlfir.apply %expr, %c42 typeparams %l: (!hlfir.expr<?x!fir.char<2,?>>, index, index) -> !hlfir.expr<!fir.char<2,?>>
  return
}
// CHECK-LABEL:   func.func @character_apply(
// CHECK:    %[[VAL_7:.*]]:2 = hlfir.declare %{{.*}}(%{{.*}}) typeparams %[[VAL_1:.*]] {uniq_name = ".tmp"}
// CHECK:    %[[VAL_11:.*]] = arith.constant 42 : index
// CHECK:    %[[VAL_12:.*]] = hlfir.designate %[[VAL_7]]#0 (%[[VAL_11]])  typeparams %[[VAL_1]] : (!fir.box<!fir.array<?x!fir.char<2,?>>>, index, index) -> !fir.boxchar<2>
// CHECK:    %[[VAL_13:.*]] = arith.constant false
// CHECK:    %[[VAL_14:.*]] = fir.undefined tuple<!fir.boxchar<2>, i1>
// CHECK:    %[[VAL_15:.*]] = fir.insert_value %[[VAL_14]], %[[VAL_13]], [1 : index] : (tuple<!fir.boxchar<2>, i1>, i1) -> tuple<!fir.boxchar<2>, i1>
// CHECK:    %[[VAL_16:.*]] = fir.insert_value %[[VAL_15]], %[[VAL_12]], [0 : index] : (tuple<!fir.boxchar<2>, i1>, !fir.boxchar<2>) -> tuple<!fir.boxchar<2>, i1>