Skip to content

Commit 1b86576

Browse files
committed
add support to fir::cg
1 parent ee76861 commit 1b86576

File tree

1 file changed

+30
-26
lines changed

1 file changed

+30
-26
lines changed

flang/lib/Optimizer/Analysis/AliasAnalysis.cpp

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "mlir/IR/BuiltinOps.h"
2020
#include "mlir/IR/Value.h"
2121
#include "mlir/Interfaces/SideEffectInterfaces.h"
22+
#include "flang/Optimizer/CodeGen/CGOps.h"
2223
#include "llvm/ADT/TypeSwitch.h"
2324
#include "llvm/Support/Casting.h"
2425
#include "llvm/Support/Debug.h"
@@ -578,7 +579,7 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v,
578579
followBoxData = true;
579580
approximateSource = true;
580581
})
581-
.Case<fir::EmboxOp, fir::ReboxOp>([&](auto op) {
582+
.Case<fir::EmboxOp, fir::ReboxOp, fir::cg::XEmboxOp, fir::cg::XReboxOp>([&](auto op) {
582583
if (followBoxData) {
583584
v = op->getOperand(0);
584585
defOp = v.getDefiningOp();
@@ -591,6 +592,7 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v,
591592
Operation *loadMemrefOp = op.getMemref().getDefiningOp();
592593
bool isDeclareOp =
593594
llvm::isa_and_present<fir::DeclareOp>(loadMemrefOp) ||
595+
llvm::isa_and_present<fir::cg::XDeclareOp>(loadMemrefOp) ||
594596
llvm::isa_and_present<hlfir::DeclareOp>(loadMemrefOp);
595597
if (isDeclareOp &&
596598
llvm::isa<omp::TargetOp>(loadMemrefOp->getParentOp())) {
@@ -652,7 +654,7 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v,
652654
global = llvm::cast<fir::AddrOfOp>(op).getSymbol();
653655
breakFromLoop = true;
654656
})
655-
.Case<hlfir::DeclareOp, fir::DeclareOp>([&](auto op) {
657+
.Case<hlfir::DeclareOp, fir::DeclareOp, fir::cg::XDeclareOp>([&](auto op) {
656658
bool isPrivateItem = false;
657659
if (omp::BlockArgOpenMPOpInterface argIface =
658660
dyn_cast<omp::BlockArgOpenMPOpInterface>(op->getParentOp())) {
@@ -686,30 +688,32 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v,
686688
return;
687689
}
688690
}
689-
auto varIf = llvm::cast<fir::FortranVariableOpInterface>(defOp);
690-
// While going through a declare operation collect
691-
// the variable attributes from it. Right now, some
692-
// of the attributes are duplicated, e.g. a TARGET dummy
693-
// argument has the target attribute both on its declare
694-
// operation and on the entry block argument.
695-
// In case of host associated use, the declare operation
696-
// is the only carrier of the variable attributes,
697-
// so we have to collect them here.
698-
attributes |= getAttrsFromVariable(varIf);
699-
isCapturedInInternalProcedure |=
700-
varIf.isCapturedInInternalProcedure();
701-
if (varIf.isHostAssoc()) {
702-
// Do not track past such DeclareOp, because it does not
703-
// currently provide any useful information. The host associated
704-
// access will end up dereferencing the host association tuple,
705-
// so we may as well stop right now.
706-
v = defOp->getResult(0);
707-
// TODO: if the host associated variable is a dummy argument
708-
// of the host, I think, we can treat it as SourceKind::Argument
709-
// for the purpose of alias analysis inside the internal procedure.
710-
type = SourceKind::HostAssoc;
711-
breakFromLoop = true;
712-
return;
691+
auto varIf = llvm::dyn_cast<fir::FortranVariableOpInterface>(defOp);
692+
if(varIf){
693+
// While going through a declare operation collect
694+
// the variable attributes from it. Right now, some
695+
// of the attributes are duplicated, e.g. a TARGET dummy
696+
// argument has the target attribute both on its declare
697+
// operation and on the entry block argument.
698+
// In case of host associated use, the declare operation
699+
// is the only carrier of the variable attributes,
700+
// so we have to collect them here.
701+
attributes |= getAttrsFromVariable(varIf);
702+
isCapturedInInternalProcedure |=
703+
varIf.isCapturedInInternalProcedure();
704+
if (varIf.isHostAssoc()) {
705+
// Do not track past such DeclareOp, because it does not
706+
// currently provide any useful information. The host associated
707+
// access will end up dereferencing the host association tuple,
708+
// so we may as well stop right now.
709+
v = defOp->getResult(0);
710+
// TODO: if the host associated variable is a dummy argument
711+
// of the host, I think, we can treat it as SourceKind::Argument
712+
// for the purpose of alias analysis inside the internal procedure.
713+
type = SourceKind::HostAssoc;
714+
breakFromLoop = true;
715+
return;
716+
}
713717
}
714718
if (getLastInstantiationPoint) {
715719
// Fetch only the innermost instantiation point.

0 commit comments

Comments
 (0)