@@ -51,40 +51,6 @@ static bool hasGlobalOpTargetAttr(mlir::Value v, fir::AddrOfOp op) {
51
51
v, fir::GlobalOp::getTargetAttrName (globalOpName));
52
52
}
53
53
54
- static mlir::Value
55
- getOriginalDef (mlir::Value v,
56
- fir::AliasAnalysis::Source::Attributes &attributes,
57
- bool &isCapturedInInternalProcedure, bool &approximateSource) {
58
- mlir::Operation *defOp;
59
- bool breakFromLoop = false ;
60
- while (!breakFromLoop && (defOp = v.getDefiningOp ())) {
61
- mlir::Type ty = defOp->getResultTypes ()[0 ];
62
- llvm::TypeSwitch<Operation *>(defOp)
63
- .Case <fir::ConvertOp>([&](fir::ConvertOp op) { v = op.getValue (); })
64
- .Case <fir::DeclareOp, hlfir::DeclareOp>([&](auto op) {
65
- v = op.getMemref ();
66
- auto varIf = llvm::cast<fir::FortranVariableOpInterface>(defOp);
67
- attributes |= getAttrsFromVariable (varIf);
68
- isCapturedInInternalProcedure |=
69
- varIf.isCapturedInInternalProcedure ();
70
- })
71
- .Case <fir::CoordinateOp>([&](auto op) {
72
- if (fir::AliasAnalysis::isPointerReference (ty))
73
- attributes.set (fir::AliasAnalysis::Attribute::Pointer);
74
- v = op->getOperand (0 );
75
- approximateSource = true ;
76
- })
77
- .Case <hlfir::DesignateOp>([&](hlfir::DesignateOp op) {
78
- auto varIf = llvm::cast<fir::FortranVariableOpInterface>(defOp);
79
- attributes |= getAttrsFromVariable (varIf);
80
- v = op.getMemref ();
81
- approximateSource = true ;
82
- })
83
- .Default ([&](auto op) { breakFromLoop = true ; });
84
- }
85
- return v;
86
- }
87
-
88
54
static bool isEvaluateInMemoryBlockArg (mlir::Value v) {
89
55
if (auto evalInMem = llvm::dyn_cast_or_null<hlfir::EvaluateInMemoryOp>(
90
56
v.getParentRegion ()->getParentOp ()))
@@ -621,38 +587,34 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v,
621
587
if (mlir::isa<fir::PointerType>(boxTy.getEleTy ()))
622
588
attributes.set (Attribute::Pointer);
623
589
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);
590
+ auto boxSrc = getSource (op.getMemref ());
591
+ attributes |= boxSrc.attributes ;
592
+ approximateSource |= boxSrc.approximateSource ;
593
+ isCapturedInInternalProcedure |=
594
+ boxSrc.isCapturedInInternalProcedure ;
632
595
596
+ global = llvm::dyn_cast<mlir::SymbolRefAttr>(boxSrc.origin .u );
597
+ if (global) {
633
598
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
599
} else {
645
- type = SourceKind::Indirect;
600
+ auto def = llvm::cast<mlir::Value>(boxSrc.origin .u );
601
+ // TODO: Add support to fir.allocmem
602
+ if (auto allocOp = def.template getDefiningOp <fir::AllocaOp>()) {
603
+ v = def;
604
+ defOp = v.getDefiningOp ();
605
+ type = SourceKind::Allocate;
606
+ } else if (isDummyArgument (def)) {
607
+ defOp = nullptr ;
608
+ v = def;
609
+ } else {
610
+ type = SourceKind::Indirect;
611
+ }
646
612
}
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
613
breakFromLoop = true ;
652
- } else {
653
- // No further tracking for addresses loaded from memory for now.
654
- type = SourceKind::Indirect;
614
+ return ;
655
615
}
616
+ // No further tracking for addresses loaded from memory for now.
617
+ type = SourceKind::Indirect;
656
618
breakFromLoop = true ;
657
619
})
658
620
.Case <fir::AddrOfOp>([&](auto op) {
0 commit comments