|
7 | 7 | //===----------------------------------------------------------------------===//
|
8 | 8 |
|
9 | 9 | #include "flang/Optimizer/Analysis/AliasAnalysis.h"
|
| 10 | +#include "flang/Optimizer/CodeGen/CGOps.h" |
10 | 11 | #include "flang/Optimizer/Dialect/FIROps.h"
|
11 | 12 | #include "flang/Optimizer/Dialect/FIROpsSupport.h"
|
12 | 13 | #include "flang/Optimizer/Dialect/FIRType.h"
|
@@ -61,13 +62,17 @@ getOriginalDef(mlir::Value v,
|
61 | 62 | mlir::Type ty = defOp->getResultTypes()[0];
|
62 | 63 | llvm::TypeSwitch<Operation *>(defOp)
|
63 | 64 | .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 |
| - }) |
| 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 | + }) |
71 | 76 | .Case<fir::CoordinateOp>([&](auto op) {
|
72 | 77 | if (fir::AliasAnalysis::isPointerReference(ty))
|
73 | 78 | attributes.set(fir::AliasAnalysis::Attribute::Pointer);
|
@@ -591,19 +596,21 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v,
|
591 | 596 | followBoxData = true;
|
592 | 597 | approximateSource = true;
|
593 | 598 | })
|
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 |
| - }) |
| 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 | + }) |
601 | 607 | .Case<fir::LoadOp>([&](auto op) {
|
602 | 608 | // If load is inside target and it points to mapped item,
|
603 | 609 | // continue tracking.
|
604 | 610 | Operation *loadMemrefOp = op.getMemref().getDefiningOp();
|
605 | 611 | bool isDeclareOp =
|
606 | 612 | llvm::isa_and_present<fir::DeclareOp>(loadMemrefOp) ||
|
| 613 | + llvm::isa_and_present<fir::cg::XDeclareOp>(loadMemrefOp) || |
607 | 614 | llvm::isa_and_present<hlfir::DeclareOp>(loadMemrefOp);
|
608 | 615 | if (isDeclareOp &&
|
609 | 616 | llvm::isa<omp::TargetOp>(loadMemrefOp->getParentOp())) {
|
@@ -666,7 +673,8 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v,
|
666 | 673 | global = llvm::cast<fir::AddrOfOp>(op).getSymbol();
|
667 | 674 | breakFromLoop = true;
|
668 | 675 | })
|
669 |
| - .Case<hlfir::DeclareOp, fir::DeclareOp>([&](auto op) { |
| 676 | + .Case<hlfir::DeclareOp, fir::DeclareOp, |
| 677 | + fir::cg::XDeclareOp>([&](auto op) { |
670 | 678 | bool isPrivateItem = false;
|
671 | 679 | if (omp::BlockArgOpenMPOpInterface argIface =
|
672 | 680 | dyn_cast<omp::BlockArgOpenMPOpInterface>(op->getParentOp())) {
|
@@ -700,30 +708,33 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v,
|
700 | 708 | return;
|
701 | 709 | }
|
702 | 710 | }
|
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; |
| 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 | + } |
727 | 738 | }
|
728 | 739 | if (getLastInstantiationPoint) {
|
729 | 740 | // Fetch only the innermost instantiation point.
|
|
0 commit comments