@@ -439,20 +439,28 @@ static ModRefResult getCallModRef(fir::CallOp call, mlir::Value var) {
439
439
// An example of something currently problematic is the allocmem generated for
440
440
// ALLOCATE of allocatable target. It currently does not have the target
441
441
// attribute, which would lead this analysis to believe it cannot escape.
442
- if (!varSrc.isFortranUserVariable () || !isCallToFortranUserProcedure (call))
442
+ if (!varSrc.isFortranUserVariable () || !isCallToFortranUserProcedure (call)) {
443
+ LLVM_DEBUG (llvm::dbgs () << " ModAndRef because not a user variable or not a "
444
+ " call to user procedure.\n " );
443
445
return ModRefResult::getModAndRef ();
446
+ }
444
447
// Pointer and target may have been captured.
445
- if (varSrc.isTargetOrPointer ())
448
+ if (varSrc.isTargetOrPointer ()) {
449
+ LLVM_DEBUG (llvm::dbgs () << " ModAndRef because target or pointer.\n " );
446
450
return ModRefResult::getModAndRef ();
451
+ }
447
452
// Host associated variables may be addressed indirectly via an internal
448
453
// function call, whether the call is in the parent or an internal procedure.
449
454
// Note that the host associated/internal procedure may be referenced
450
455
// indirectly inside calls to non internal procedure. This is because internal
451
456
// procedures may be captured or passed. As this is tricky to analyze, always
452
457
// consider such variables may be accessed in any calls.
453
458
if (varSrc.kind == fir::AliasAnalysis::SourceKind::HostAssoc ||
454
- varSrc.isCapturedInInternalProcedure )
459
+ varSrc.isCapturedInInternalProcedure ) {
460
+ LLVM_DEBUG (llvm::dbgs () << " ModAndRef because var is host associated or "
461
+ " captured in internal procedure.\n " );
455
462
return ModRefResult::getModAndRef ();
463
+ }
456
464
// At that stage, it has been ruled out that local (including the saved ones)
457
465
// and dummy cannot be indirectly accessed in the call.
458
466
if (varSrc.kind != fir::AliasAnalysis::SourceKind::Allocate &&
@@ -485,6 +493,8 @@ ModRefResult AliasAnalysis::getModRef(Operation *op, Value location) {
485
493
if (!interface) {
486
494
if (auto call = llvm::dyn_cast<fir::CallOp>(op))
487
495
return getCallModRef (call, location);
496
+
497
+ LLVM_DEBUG (llvm::dbgs () << " ModAndRef because no interface or call.\n " );
488
498
return ModRefResult::getModAndRef ();
489
499
}
490
500
@@ -621,38 +631,33 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v,
621
631
if (mlir::isa<fir::PointerType>(boxTy.getEleTy ()))
622
632
attributes.set (Attribute::Pointer);
623
633
624
- auto def = getOriginalDef (op.getMemref (), attributes,
625
- isCapturedInInternalProcedure,
626
- approximateSource);
627
- if (auto addrOfOp = def.template getDefiningOp <fir::AddrOfOp>()) {
628
- global = addrOfOp.getSymbol ();
629
-
630
- if (hasGlobalOpTargetAttr (def, addrOfOp))
631
- attributes.set (Attribute::Target);
634
+ auto boxSrc = getSource (op.getMemref ());
635
+ attributes |= boxSrc.attributes ;
636
+ approximateSource |= boxSrc.approximateSource ;
637
+ isCapturedInInternalProcedure |= boxSrc.isCapturedInInternalProcedure ;
632
638
639
+ global = llvm::dyn_cast<mlir::SymbolRefAttr>(boxSrc.origin .u );
640
+ if (global) {
633
641
type = SourceKind::Global;
634
- }
635
- // TODO: Add support to fir.allocmem
636
- else if (auto allocOp =
637
- def.template getDefiningOp <fir::AllocaOp>()) {
638
- v = def;
639
- defOp = v.getDefiningOp ();
640
- type = SourceKind::Allocate;
641
- } else if (isDummyArgument (def)) {
642
- defOp = nullptr ;
643
- v = def;
644
642
} else {
645
- type = SourceKind::Indirect;
643
+ auto def = llvm::cast<mlir::Value>(boxSrc.origin .u );
644
+ // TODO: Add support to fir.allocmem
645
+ if (auto allocOp = def.template getDefiningOp <fir::AllocaOp>()) {
646
+ v = def;
647
+ defOp = v.getDefiningOp ();
648
+ type = SourceKind::Allocate;
649
+ } else if (isDummyArgument (def)) {
650
+ defOp = nullptr ;
651
+ v = def;
652
+ } else {
653
+ type = SourceKind::Indirect;
654
+ }
646
655
}
647
- // TODO: This assignment is redundant but somehow works around an
648
- // apparent MSVC bug reporting "undeclared identifier" at the next
649
- // "breakFromLoop = true;". See
650
- // <https://github.com/llvm/llvm-project/pull/127845#issuecomment-2669829610>.
651
656
breakFromLoop = true ;
652
- } else {
653
- // No further tracking for addresses loaded from memory for now.
654
- type = SourceKind::Indirect;
657
+ return ;
655
658
}
659
+ // No further tracking for addresses loaded from memory for now.
660
+ type = SourceKind::Indirect;
656
661
breakFromLoop = true ;
657
662
})
658
663
.Case <fir::AddrOfOp>([&](auto op) {
0 commit comments