[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 07:30:09 PDT 2025


================
@@ -37,6 +37,15 @@ namespace {
 #include "flang/Optimizer/Dialect/CanonicalizationPatterns.inc"
 } // namespace
 
+static void addVolatileMemoryEffects(
+    mlir::Type type, llvm::SmallVectorImpl<mlir::SideEffects::EffectInstance<
+                         mlir::MemoryEffects::Effect>> &effects) {
+  if (fir::isa_volatile_ref_type(type)) {
+    effects.emplace_back(mlir::MemoryEffects::Read::get());
+    effects.emplace_back(mlir::MemoryEffects::Write::get());
----------------
ashermancinelli wrote:

Thanks for the review, the memory effects is the part I'm least sure about.

I wanted to use the most conservative memory effects to shut down any mlir-level optimizations. For example, if we only reported read effects for the logical and we were to use standard dialects and optimizations, would a read effect alone be enough to keep the `if (l)` around? 
```
logical,volatile::l
integer::i
l=.false.
do i=1,huge(i)
if(l) exit
enddo
end
```
Does 'unknown memory effects' mean returning no memory effects? 

https://github.com/llvm/llvm-project/pull/132486


More information about the flang-commits mailing list