[flang-commits] [flang] [flang][rfc] Add represention of volatile references (PR #132486)
Asher Mancinelli via flang-commits
flang-commits at lists.llvm.org
Wed Mar 26 06:57:47 PDT 2025
ashermancinelli wrote:
> I think we will have to account for VOLATILE in flang/lib/Optimizer/Transforms/SetRuntimeCallAttributes.cpp.
Looking into this, thanks!
Also: I'm not sure we will need the volatile attribute on the dummy arguments as they are set right now:
```
! source
subroutine declared_volatile_in_this_scope(v,n)
integer,intent(in)::n
integer,volatile,intent(inout)::v(n)
v=1
end subroutine
// IR
func.func private @_QFPdeclared_volatile_in_this_scope(%arg0: !fir.ref<!fir.array<?xi32>> {fir.bindc_name = "v", fir.volatile}, %arg1: !fir.ref<i32> {fir.bindc_name = "n"}) attributes {fir.host_symbol = @_QQmain, llvm.linkage = #llvm.linkage<internal>} {
%c1_i32 = arith.constant 1 : i32
%c0 = arith.constant 0 : index
%0 = fir.dummy_scope : !fir.dscope
%1:2 = hlfir.declare %arg1 dummy_scope %0 {fortran_attrs = #fir.var_attrs<intent_in>, uniq_name = "_QFFdeclared_volatile_in_this_scopeEn"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>)
%2 = fir.load %1#0 : !fir.ref<i32>
%3 = fir.convert %2 : (i32) -> index
%4 = arith.cmpi sgt, %3, %c0 : index
%5 = arith.select %4, %3, %c0 : index
%6 = fir.shape %5 : (index) -> !fir.shape<1>
%7 = fir.volatile_cast %arg0 : (!fir.ref<!fir.array<?xi32>>) -> !fir.ref<!fir.array<?xi32>, volatile>
%8:2 = hlfir.declare %7(%6) dummy_scope %0 {fortran_attrs = #fir.var_attrs<intent_inout, volatile>, uniq_name = "_QFFdeclared_volatile_in_this_scopeEv"} : (!fir.ref<!fir.array<?xi32>, volatile>, !fir.shape<1>, !fir.dscope) -> (!fir.box<!fir.array<?xi32>, volatile>, !fir.ref<!fir.array<?xi32>, volatile>)
hlfir.assign %c1_i32 to %8#0 : i32, !fir.box<!fir.array<?xi32>, volatile>
return
}
```
The `fir.volatile` unit attribute is set on the argument, but if the dummy is declared volatile we should always get an `hlfir.declare` that makes it volatile anyways, right?
https://github.com/llvm/llvm-project/pull/132486
More information about the flang-commits
mailing list