Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions flang/include/flang/Optimizer/Analysis/AliasAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,14 @@ struct AliasAnalysis {
fir::AliasAnalysis::Source getSource(mlir::Value,
bool getLastInstantiationPoint = false);

/// Return true, if `ty` is a reference type to a boxed
/// POINTER object or a raw fir::PointerType.
static bool isPointerReference(mlir::Type ty);

private:
/// Return true, if `ty` is a reference type to an object of derived type
/// that contains a component with POINTER attribute.
static bool isRecordWithPointerComponent(mlir::Type ty);

/// Return true, if `ty` is a reference type to a boxed
/// POINTER object or a raw fir::PointerType.
static bool isPointerReference(mlir::Type ty);
};

inline bool operator==(const AliasAnalysis::Source::SourceOrigin &lhs,
Expand Down
18 changes: 16 additions & 2 deletions flang/lib/Optimizer/Analysis/AliasAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ static bool hasGlobalOpTargetAttr(mlir::Value v, fir::AddrOfOp op) {
static mlir::Value
getOriginalDef(mlir::Value v,
fir::AliasAnalysis::Source::Attributes &attributes,
bool &isCapturedInInternalProcedure) {
bool &isCapturedInInternalProcedure, bool &approximateSource) {
mlir::Operation *defOp;
bool breakFromLoop = false;
while (!breakFromLoop && (defOp = v.getDefiningOp())) {
mlir::Type ty = defOp->getResultTypes()[0];
llvm::TypeSwitch<Operation *>(defOp)
.Case<fir::ConvertOp>([&](fir::ConvertOp op) { v = op.getValue(); })
.Case<fir::DeclareOp, hlfir::DeclareOp>([&](auto op) {
Expand All @@ -67,6 +68,18 @@ getOriginalDef(mlir::Value v,
isCapturedInInternalProcedure |=
varIf.isCapturedInInternalProcedure();
})
.Case<fir::CoordinateOp>([&](auto op) {
if (fir::AliasAnalysis::isPointerReference(ty))
attributes.set(fir::AliasAnalysis::Attribute::Pointer);
v = op->getOperand(0);
approximateSource = true;
})
.Case<hlfir::DesignateOp>([&](hlfir::DesignateOp op) {
auto varIf = llvm::cast<fir::FortranVariableOpInterface>(defOp);
attributes |= getAttrsFromVariable(varIf);
v = op.getMemref();
approximateSource = true;
})
.Default([&](auto op) { breakFromLoop = true; });
}
return v;
Expand Down Expand Up @@ -609,7 +622,8 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v,
attributes.set(Attribute::Pointer);

auto def = getOriginalDef(op.getMemref(), attributes,
isCapturedInInternalProcedure);
isCapturedInInternalProcedure,
approximateSource);
if (auto addrOfOp = def.template getDefiningOp<fir::AddrOfOp>()) {
global = addrOfOp.getSymbol();

Expand Down
Loading