|
7 | 7 | //===----------------------------------------------------------------------===// |
8 | 8 |
|
9 | 9 | #include "flang/Optimizer/Analysis/AliasAnalysis.h" |
10 | | -#include "flang/Optimizer/CodeGen/CGOps.h" |
11 | 10 | #include "flang/Optimizer/Dialect/FIROps.h" |
12 | 11 | #include "flang/Optimizer/Dialect/FIROpsSupport.h" |
13 | 12 | #include "flang/Optimizer/Dialect/FIRType.h" |
@@ -62,17 +61,13 @@ getOriginalDef(mlir::Value v, |
62 | 61 | mlir::Type ty = defOp->getResultTypes()[0]; |
63 | 62 | llvm::TypeSwitch<Operation *>(defOp) |
64 | 63 | .Case<fir::ConvertOp>([&](fir::ConvertOp op) { v = op.getValue(); }) |
65 | | - .Case<fir::DeclareOp, hlfir::DeclareOp, fir::cg::XDeclareOp>( |
66 | | - [&](auto op) { |
67 | | - v = op.getMemref(); |
68 | | - auto varIf = |
69 | | - llvm::dyn_cast<fir::FortranVariableOpInterface>(defOp); |
70 | | - if (varIf) { |
71 | | - attributes |= getAttrsFromVariable(varIf); |
72 | | - isCapturedInInternalProcedure |= |
73 | | - varIf.isCapturedInInternalProcedure(); |
74 | | - } |
75 | | - }) |
| 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 | + }) |
76 | 71 | .Case<fir::CoordinateOp>([&](auto op) { |
77 | 72 | if (fir::AliasAnalysis::isPointerReference(ty)) |
78 | 73 | attributes.set(fir::AliasAnalysis::Attribute::Pointer); |
@@ -596,21 +591,19 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v, |
596 | 591 | followBoxData = true; |
597 | 592 | approximateSource = true; |
598 | 593 | }) |
599 | | - .Case<fir::EmboxOp, fir::ReboxOp, fir::cg::XEmboxOp, fir::cg::XReboxOp>( |
600 | | - [&](auto op) { |
601 | | - if (followBoxData) { |
602 | | - v = op->getOperand(0); |
603 | | - defOp = v.getDefiningOp(); |
604 | | - } else |
605 | | - breakFromLoop = true; |
606 | | - }) |
| 594 | + .Case<fir::EmboxOp, fir::ReboxOp>([&](auto op) { |
| 595 | + if (followBoxData) { |
| 596 | + v = op->getOperand(0); |
| 597 | + defOp = v.getDefiningOp(); |
| 598 | + } else |
| 599 | + breakFromLoop = true; |
| 600 | + }) |
607 | 601 | .Case<fir::LoadOp>([&](auto op) { |
608 | 602 | // If load is inside target and it points to mapped item, |
609 | 603 | // continue tracking. |
610 | 604 | Operation *loadMemrefOp = op.getMemref().getDefiningOp(); |
611 | 605 | bool isDeclareOp = |
612 | 606 | llvm::isa_and_present<fir::DeclareOp>(loadMemrefOp) || |
613 | | - llvm::isa_and_present<fir::cg::XDeclareOp>(loadMemrefOp) || |
614 | 607 | llvm::isa_and_present<hlfir::DeclareOp>(loadMemrefOp); |
615 | 608 | if (isDeclareOp && |
616 | 609 | llvm::isa<omp::TargetOp>(loadMemrefOp->getParentOp())) { |
@@ -673,8 +666,7 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v, |
673 | 666 | global = llvm::cast<fir::AddrOfOp>(op).getSymbol(); |
674 | 667 | breakFromLoop = true; |
675 | 668 | }) |
676 | | - .Case<hlfir::DeclareOp, fir::DeclareOp, |
677 | | - fir::cg::XDeclareOp>([&](auto op) { |
| 669 | + .Case<hlfir::DeclareOp, fir::DeclareOp>([&](auto op) { |
678 | 670 | bool isPrivateItem = false; |
679 | 671 | if (omp::BlockArgOpenMPOpInterface argIface = |
680 | 672 | dyn_cast<omp::BlockArgOpenMPOpInterface>(op->getParentOp())) { |
@@ -708,33 +700,30 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v, |
708 | 700 | return; |
709 | 701 | } |
710 | 702 | } |
711 | | - auto varIf = llvm::dyn_cast<fir::FortranVariableOpInterface>(defOp); |
712 | | - if (varIf) { |
713 | | - // While going through a declare operation collect |
714 | | - // the variable attributes from it. Right now, some |
715 | | - // of the attributes are duplicated, e.g. a TARGET dummy |
716 | | - // argument has the target attribute both on its declare |
717 | | - // operation and on the entry block argument. |
718 | | - // In case of host associated use, the declare operation |
719 | | - // is the only carrier of the variable attributes, |
720 | | - // so we have to collect them here. |
721 | | - attributes |= getAttrsFromVariable(varIf); |
722 | | - isCapturedInInternalProcedure |= |
723 | | - varIf.isCapturedInInternalProcedure(); |
724 | | - if (varIf.isHostAssoc()) { |
725 | | - // Do not track past such DeclareOp, because it does not |
726 | | - // currently provide any useful information. The host associated |
727 | | - // access will end up dereferencing the host association tuple, |
728 | | - // so we may as well stop right now. |
729 | | - v = defOp->getResult(0); |
730 | | - // TODO: if the host associated variable is a dummy argument |
731 | | - // of the host, I think, we can treat it as SourceKind::Argument |
732 | | - // for the purpose of alias analysis inside the internal |
733 | | - // procedure. |
734 | | - type = SourceKind::HostAssoc; |
735 | | - breakFromLoop = true; |
736 | | - return; |
737 | | - } |
| 703 | + auto varIf = llvm::cast<fir::FortranVariableOpInterface>(defOp); |
| 704 | + // While going through a declare operation collect |
| 705 | + // the variable attributes from it. Right now, some |
| 706 | + // of the attributes are duplicated, e.g. a TARGET dummy |
| 707 | + // argument has the target attribute both on its declare |
| 708 | + // operation and on the entry block argument. |
| 709 | + // In case of host associated use, the declare operation |
| 710 | + // is the only carrier of the variable attributes, |
| 711 | + // so we have to collect them here. |
| 712 | + attributes |= getAttrsFromVariable(varIf); |
| 713 | + isCapturedInInternalProcedure |= |
| 714 | + varIf.isCapturedInInternalProcedure(); |
| 715 | + if (varIf.isHostAssoc()) { |
| 716 | + // Do not track past such DeclareOp, because it does not |
| 717 | + // currently provide any useful information. The host associated |
| 718 | + // access will end up dereferencing the host association tuple, |
| 719 | + // so we may as well stop right now. |
| 720 | + v = defOp->getResult(0); |
| 721 | + // TODO: if the host associated variable is a dummy argument |
| 722 | + // of the host, I think, we can treat it as SourceKind::Argument |
| 723 | + // for the purpose of alias analysis inside the internal procedure. |
| 724 | + type = SourceKind::HostAssoc; |
| 725 | + breakFromLoop = true; |
| 726 | + return; |
738 | 727 | } |
739 | 728 | if (getLastInstantiationPoint) { |
740 | 729 | // Fetch only the innermost instantiation point. |
|
0 commit comments