[flang-commits] [flang] [flang][NFCI] Stop tracking memory source after a load in a more explicit manner. (PR #126156)
via flang-commits
flang-commits at lists.llvm.org
Thu Feb 13 08:50:23 PST 2025
================
@@ -600,6 +590,40 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v,
defOp = v.getDefiningOp();
return;
}
+
+ // If we are loading a box reference, but following the data,
+ // we gather the attributes of the box to populate the source
+ // and stop tracking.
+ if (auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(ty);
+ boxTy && followingData) {
+
+ if (mlir::isa<fir::PointerType>(boxTy.getEleTy()))
+ attributes.set(Attribute::Pointer);
+
+ auto def = getOriginalDef(op.getMemref());
+ if (auto addrOfOp = def.template getDefiningOp<fir::AddrOfOp>()) {
+ global = addrOfOp.getSymbol();
+
+ if (hasGlobalOpTargetAttr(def, addrOfOp))
+ attributes.set(Attribute::Target);
+
+ type = SourceKind::Global;
+ }
+
+ // TODO: Add support to fir.alloca and fir.allocmem
+ // if (auto allocOp = def.template getDefiningOp<fir::AllocaOp>()) {
+ // ...
+ // }
+
+ if (isDummyArgument(def)) {
+ defOp = nullptr;
+ v = def;
+ }
+
+ breakFromLoop = true;
+ return;
----------------
jeanPerier wrote:
Yes, I am afraid we will end-up duplicating a lot of logic to walk and gather information, and that people will update `getSource` without `getOriginalDef`.
I think it would be more powerfull/generic to call `getSource` on the memref indirection and to propagate the info from the memref source info to the address being analyzed.
For instance, if the memref is a POINTER, technically the loaded address is not a pointer, it is a TARGET. If we cared about OPTIONAL, this aspect would not propagate from the memref to the loaded address, but things like VOLATILE and ASYNCHRONOUS probably would. TARGET propagates (an allocatable component of a deriver type that is TARGET can be taken by a pointer).... INTENT propagates. I believe Fortran committee wants to introduce a way to specify data vs descriptor "constness" (since INTENT always apply to both), and whatever attribute they come up with would not propagate.
https://github.com/llvm/llvm-project/pull/126156
More information about the flang-commits
mailing list