@@ -51,14 +51,22 @@ static bool hasGlobalOpTargetAttr(mlir::Value v, fir::AddrOfOp op) {
51
51
v, fir::GlobalOp::getTargetAttrName (globalOpName));
52
52
}
53
53
54
- static mlir::Value getOriginalDef (mlir::Value v) {
54
+ static mlir::Value
55
+ getOriginalDef (mlir::Value v,
56
+ fir::AliasAnalysis::Source::Attributes &attributes,
57
+ bool &isCapturedInInternalProcedure) {
55
58
mlir::Operation *defOp;
56
59
bool breakFromLoop = false ;
57
60
while (!breakFromLoop && (defOp = v.getDefiningOp ())) {
58
61
llvm::TypeSwitch<Operation *>(defOp)
59
62
.Case <fir::ConvertOp>([&](fir::ConvertOp op) { v = op.getValue (); })
60
- .Case <fir::DeclareOp, hlfir::DeclareOp>(
61
- [&](auto op) { v = op.getMemref (); })
63
+ .Case <fir::DeclareOp, hlfir::DeclareOp>([&](auto op) {
64
+ v = op.getMemref ();
65
+ auto varIf = llvm::cast<fir::FortranVariableOpInterface>(defOp);
66
+ attributes |= getAttrsFromVariable (varIf);
67
+ isCapturedInInternalProcedure |=
68
+ varIf.isCapturedInInternalProcedure ();
69
+ })
62
70
.Default ([&](auto op) { breakFromLoop = true ; });
63
71
}
64
72
return v;
@@ -600,7 +608,8 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v,
600
608
if (mlir::isa<fir::PointerType>(boxTy.getEleTy ()))
601
609
attributes.set (Attribute::Pointer);
602
610
603
- auto def = getOriginalDef (op.getMemref ());
611
+ auto def = getOriginalDef (op.getMemref (), attributes,
612
+ isCapturedInInternalProcedure);
604
613
if (auto addrOfOp = def.template getDefiningOp <fir::AddrOfOp>()) {
605
614
global = addrOfOp.getSymbol ();
606
615
@@ -609,13 +618,13 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v,
609
618
610
619
type = SourceKind::Global;
611
620
}
612
-
613
- // TODO: Add support to fir.alloca and fir.allocmem
614
- // if (auto allocOp = def.template getDefiningOp<fir::AllocaOp>()) {
615
- // ...
616
- // }
617
-
618
- if (isDummyArgument (def)) {
621
+ // TODO: Add support to fir.allocmem
622
+ else if ( auto allocOp =
623
+ def.template getDefiningOp <fir::AllocaOp>()) {
624
+ v = def;
625
+ defOp = v. getDefiningOp ();
626
+ type = SourceKind::Allocate;
627
+ } else if (isDummyArgument (def)) {
619
628
defOp = nullptr ;
620
629
v = def;
621
630
}
0 commit comments