[flang-commits] [flang] [flang][rfc] Add represention of volatile references (PR #132486)
Asher Mancinelli via flang-commits
flang-commits at lists.llvm.org
Mon Mar 24 11:22:50 PDT 2025
================
@@ -0,0 +1,21 @@
+// RUN: fir-opt --convert-hlfir-to-fir %s -o - | FileCheck %s
+func.func @foo() {
+ %true = arith.constant true
+ %false = arith.constant false
+ %0 = fir.alloca !fir.logical<4> {bindc_name = "a", uniq_name = "_QFEa"}
+ %1 = fir.convert %0 : (!fir.ref<!fir.logical<4>>) -> !fir.ref<!fir.logical<4>, volatile>
+ %2:2 = hlfir.declare %1 {fortran_attrs = #fir.var_attrs<volatile>, uniq_name = "_QFEa"} : (!fir.ref<!fir.logical<4>, volatile>) -> (!fir.ref<!fir.logical<4>, volatile>, !fir.ref<!fir.logical<4>, volatile>)
+ %3 = fir.alloca !fir.logical<4> {bindc_name = "b", uniq_name = "_QFEb"}
+ %4:2 = hlfir.declare %3 {uniq_name = "_QFEb"} : (!fir.ref<!fir.logical<4>>) -> (!fir.ref<!fir.logical<4>>, !fir.ref<!fir.logical<4>>)
+ %5 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFEi"}
+ %6:2 = hlfir.declare %5 {uniq_name = "_QFEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
+ %7 = fir.convert %false : (i1) -> !fir.logical<4>
+ hlfir.assign %7 to %2#0 : !fir.logical<4>, !fir.ref<!fir.logical<4>, volatile>
+ %8 = fir.load %2#0 : !fir.ref<!fir.logical<4>, volatile>
----------------
ashermancinelli wrote:
I believe the semantic differences should be handled by updating memory effects, which are modeled by adding generic read and write effects to all ops taking a volatile reference (even those that technically only read). We might want to use read+write effects on a specific memory resource for volatile variables as Slava suggested.
The docs should be updated to reflect this too, thanks!
https://github.com/llvm/llvm-project/pull/132486
More information about the flang-commits
mailing list