@@ -51,7 +51,7 @@ static bool hasGlobalOpTargetAttr(mlir::Value v, fir::AddrOfOp op) {
5151 v, fir::GlobalOp::getTargetAttrName (globalOpName));
5252}
5353
54- mlir::Value getOriginalDef (mlir::Value v) {
54+ static mlir::Value getOriginalDef (mlir::Value v) {
5555 mlir::Operation *defOp;
5656 bool breakFromLoop = false ;
5757 while (!breakFromLoop && (defOp = v.getDefiningOp ())) {
@@ -578,16 +578,6 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v,
578578 breakFromLoop = true ;
579579 })
580580 .Case <fir::LoadOp>([&](auto op) {
581- // If the load is from a leaf source, return the leaf. Do not track
582- // through indirections otherwise.
583- // TODO: Add support to fir.alloca and fir.allocmem
584- auto def = getOriginalDef (op.getMemref ());
585- if (isDummyArgument (def) ||
586- def.template getDefiningOp <fir::AddrOfOp>()) {
587- v = def;
588- defOp = v.getDefiningOp ();
589- return ;
590- }
591581 // If load is inside target and it points to mapped item,
592582 // continue tracking.
593583 Operation *loadMemrefOp = op.getMemref ().getDefiningOp ();
@@ -600,6 +590,41 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v,
600590 defOp = v.getDefiningOp ();
601591 return ;
602592 }
593+
594+ // If we are loading a box reference, but following the data,
595+ // we gather the attributes of the box to populate the source
596+ // and stop tracking.
597+ if (auto boxTy = mlir::dyn_cast<fir::BaseBoxType>(ty);
598+ boxTy && followingData) {
599+
600+ if (mlir::isa<fir::PointerType>(boxTy.getEleTy ())) {
601+ attributes.set (Attribute::Pointer);
602+ }
603+
604+ auto def = getOriginalDef (op.getMemref ());
605+ if (auto addrOfOp = def.template getDefiningOp <fir::AddrOfOp>()) {
606+ global = addrOfOp.getSymbol ();
607+
608+ if (hasGlobalOpTargetAttr (def, addrOfOp))
609+ attributes.set (Attribute::Target);
610+
611+ type = SourceKind::Global;
612+ }
613+
614+ // TODO: Add support to fir.alloca and fir.allocmem
615+ // if (auto allocOp = def.template getDefiningOp<fir::AllocaOp>()) {
616+ // ...
617+ // }
618+
619+ if (isDummyArgument (def)) {
620+ defOp = nullptr ;
621+ v = def;
622+ }
623+
624+ breakFromLoop = true ;
625+ return ;
626+ }
627+
603628 // No further tracking for addresses loaded from memory for now.
604629 type = SourceKind::Indirect;
605630 breakFromLoop = true ;
0 commit comments