================ @@ -329,14 +341,92 @@ AliasResult AliasAnalysis::alias(Source lhsSrc, Source rhsSrc, mlir::Value lhs, // AliasAnalysis: getModRef //===----------------------------------------------------------------------===// +static bool isSavedLocal(const fir::AliasAnalysis::Source &src) { + if (auto symRef = llvm::dyn_cast<mlir::SymbolRefAttr>(src.origin.u)) { + auto [nameKind, deconstruct] = + fir::NameUniquer::deconstruct(symRef.getLeafReference().getValue()); + return nameKind == fir::NameUniquer::NameKind::VARIABLE && + !deconstruct.procs.empty(); + } + return false; +} + +static bool isCallToFortranUserProcedure(fir::CallOp call) { + // TODO: indirect calls are excluded by these checks. Maybe some attribute is + // needed to flag user calls in this case. + if (fir::hasBindcAttr(call)) + return true; + if (std::optional<mlir::SymbolRefAttr> callee = call.getCallee()) + return fir::NameUniquer::deconstruct(callee->getLeafReference().getValue()) + .first == fir::NameUniquer::NameKind::PROCEDURE; + return false; +} + +static ModRefResult getCallModRef(fir::CallOp call, mlir::Value var) { + // TODO: limit to Fortran functions?? + // 1. Detect variables that can be accessed indirectly. + fir::AliasAnalysis aliasAnalysis; + fir::AliasAnalysis::Source varSrc = aliasAnalysis.getSource(var); + // If the variable is not a user variable, we cannot safely assume that + // Fortran semantics apply (e.g., a bare alloca/allocmem result may very well + // be placed in an allocatable/pointer descriptor and escape). + + // All the logic bellows are based on Fortran semantics and only holds if this ---------------- tblah wrote:
```suggestion // All the logic bellow is based on Fortran semantics and only holds if this ``` nit https://github.com/llvm/llvm-project/pull/117164 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits