| 1 |
// RUN: fir-opt --function-attr="set-nocapture=true" %s | FileCheck %s |
| 2 |
|
| 3 |
// If a function has a body and is not bind(c), and if the dummy argument doesn't have the target, |
| 4 |
// asynchronous, volatile, or pointer attribute, then add llvm.nocapture to the dummy argument. |
| 5 |
|
| 6 |
func.func @_QParg_nocapture(%arg0: !fir.ref<i32> {fir.bindc_name = "tar", fir.target}, %arg1: !fir.ref<i32> {fir.asynchronous, fir.bindc_name = "asynch"}, %arg2: !fir.ref<i32> {fir.bindc_name = "vol", fir.volatile}, %arg3: !fir.ref<!fir.box<!fir.ptr<i32>>> {fir.bindc_name = "ptr"}, %arg4: !fir.ref<i32> {fir.bindc_name = "nocap"}) { |
| 7 |
%0 = fir.dummy_scope : !fir.dscope |
| 8 |
%1 = fir.declare %arg0 dummy_scope %0 {fortran_attrs = #fir.var_attrs<target>, uniq_name = "_QFarg_nocaptureEtar"} : (!fir.ref<i32>, !fir.dscope) -> !fir.ref<i32> |
| 9 |
%2 = fir.declare %arg1 dummy_scope %0 {fortran_attrs = #fir.var_attrs<asynchronous>, uniq_name = "_QFarg_nocaptureEasynch"} : (!fir.ref<i32>, !fir.dscope) -> !fir.ref<i32> |
| 10 |
%3 = fir.declare %arg2 dummy_scope %0 {uniq_name = "_QFarg_nocaptureEvol"} : (!fir.ref<i32>, !fir.dscope) -> !fir.ref<i32> |
| 11 |
%4 = fir.declare %arg3 dummy_scope %0 {fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QFarg_nocaptureEptr"} : (!fir.ref<!fir.box<!fir.ptr<i32>>>, !fir.dscope) -> !fir.ref<!fir.box<!fir.ptr<i32>>> |
| 12 |
%5 = fir.declare %arg4 dummy_scope %0 {uniq_name = "_QFarg_nocaptureEnocap"} : (!fir.ref<i32>, !fir.dscope) -> !fir.ref<i32> |
| 13 |
return |
| 14 |
} |
| 15 |
// CHECK-LABEL: func.func @_QParg_nocapture( |
| 16 |
// CHECK-SAME: %[[ARG0:.*]]: !fir.ref<i32> {fir.bindc_name = "tar", fir.target}, |
| 17 |
// CHECK-SAME: %[[ARG1:.*]]: !fir.ref<i32> {fir.asynchronous, fir.bindc_name = "asynch"}, |
| 18 |
// CHECK-SAME: %[[ARG2:.*]]: !fir.ref<i32> {fir.bindc_name = "vol", fir.volatile}, |
| 19 |
// CHECK-SAME: %[[ARG3:.*]]: !fir.ref<!fir.box<!fir.ptr<i32>>> {fir.bindc_name = "ptr", llvm.nocapture}, |
| 20 |
// CHECK-SAME: %[[ARG4:.*]]: !fir.ref<i32> {fir.bindc_name = "nocap", llvm.nocapture}) { |
| 21 |
// CHECK: return |
| 22 |
// CHECK-NEXT: } |
| 23 |
|
| 24 |
func.func @arg_nocapture_bindc(%arg0: !fir.ref<i32> {fir.bindc_name = "tar", fir.target}, %arg1: !fir.ref<i32> {fir.bindc_name = "nocap"}) attributes {fir.bindc_name = "arg_nocapture_bindc", fir.proc_attrs = #fir.proc_attrs<bind_c>} { |
| 25 |
%0 = fir.dummy_scope : !fir.dscope |
| 26 |
%1 = fir.declare %arg0 dummy_scope %0 {fortran_attrs = #fir.var_attrs<target>, uniq_name = "_QFarg_nocapture_bindcEtar"} : (!fir.ref<i32>, !fir.dscope) -> !fir.ref<i32> |
| 27 |
%2 = fir.declare %arg1 dummy_scope %0 {uniq_name = "_QFarg_nocapture_bindcEnocap"} : (!fir.ref<i32>, !fir.dscope) -> !fir.ref<i32> |
| 28 |
return |
| 29 |
} |
| 30 |
// CHECK-LABEL: func.func @arg_nocapture_bindc( |
| 31 |
// CHECK-NOT: llvm.nocapture |
| 32 |
|
| 33 |
|
| 34 |
// If a function declaration is from a module and is not bind(c), and if the dummy argument doesn't have |
| 35 |
// the target, asynchronous, volatile, or pointer attribute, then add llvm.nocapture to the dummy argument. |
| 36 |
|
| 37 |
func.func private @_QMarg_modPcheck_args(!fir.ref<i32> {fir.target}, !fir.ref<i32> {fir.asynchronous}, !fir.ref<i32> {fir.volatile}, !fir.ref<!fir.box<!fir.ptr<i32>>>, !fir.ref<i32>, !fir.boxchar<1>, !fir.ref<complex<f32>>) |
| 38 |
// CHECK-LABEL: func.func private @_QMarg_modPcheck_args( |
| 39 |
// CHECK-SAME: !fir.ref<i32> {fir.target}, |
| 40 |
// CHECK-SAME: !fir.ref<i32> {fir.asynchronous}, |
| 41 |
// CHECK-SAME: !fir.ref<i32> {fir.volatile}, |
| 42 |
// CHECK-SAME: !fir.ref<!fir.box<!fir.ptr<i32>>> {llvm.nocapture}, |
| 43 |
// CHECK-SAME: !fir.ref<i32> {llvm.nocapture}, |
| 44 |
// CHECK-SAME: !fir.boxchar<1>, |
| 45 |
// CHECK-SAME: !fir.ref<complex<f32>> {llvm.nocapture}) |
| 46 |
|
| 47 |
// Test !fir.box arguments: |
| 48 |
// CHECK-LABEL: func.func private @test_box( |
| 49 |
// CHECK-SAME: %[[ARG0:.*]]: !fir.box<i32> {llvm.nocapture}) { |
| 50 |
func.func private @test_box(%arg0: !fir.box<i32>) { |
| 51 |
return |
| 52 |
} |
| 53 |
|
| 54 |
// CHECK-LABEL: func.func private @test_box_target( |
| 55 |
// CHECK-SAME: %[[ARG0:.*]]: !fir.box<i32> {fir.target, llvm.nocapture}) { |
| 56 |
func.func private @test_box_target(%arg0: !fir.box<i32> {fir.target}) { |
| 57 |
return |
| 58 |
} |
| 59 |
|
| 60 |
// CHECK-LABEL: func.func private @test_box_volatile( |
| 61 |
// CHECK-SAME: %[[ARG0:.*]]: !fir.box<i32> {fir.volatile, llvm.nocapture}) { |
| 62 |
func.func private @test_box_volatile(%arg0: !fir.box<i32> {fir.volatile}) { |
| 63 |
return |
| 64 |
} |
| 65 |
|
| 66 |
// CHECK-LABEL: func.func private @test_box_asynchronous( |
| 67 |
// CHECK-SAME: %[[ARG0:.*]]: !fir.box<i32> {fir.asynchronous, llvm.nocapture}) { |
| 68 |
func.func private @test_box_asynchronous(%arg0: !fir.box<i32> {fir.asynchronous}) { |
| 69 |
return |
| 70 |
} |