diff --git a/flang/lib/Optimizer/Analysis/AliasAnalysis.cpp b/flang/lib/Optimizer/Analysis/AliasAnalysis.cpp index e33d8fa333e7a..01f3a0326db21 100644 --- a/flang/lib/Optimizer/Analysis/AliasAnalysis.cpp +++ b/flang/lib/Optimizer/Analysis/AliasAnalysis.cpp @@ -31,9 +31,27 @@ using namespace mlir; // AliasAnalysis: alias //===----------------------------------------------------------------------===// -/// Temporary function to skip through all the no op operations -/// TODO: Generalize support of fir.load -static mlir::Value getOriginalDef(mlir::Value v) { +static fir::AliasAnalysis::Source::Attributes +getAttrsFromVariable(fir::FortranVariableOpInterface var) { + fir::AliasAnalysis::Source::Attributes attrs; + if (var.isTarget()) + attrs.set(fir::AliasAnalysis::Attribute::Target); + if (var.isPointer()) + attrs.set(fir::AliasAnalysis::Attribute::Pointer); + if (var.isIntentIn()) + attrs.set(fir::AliasAnalysis::Attribute::IntentIn); + + return attrs; +} + +static bool hasGlobalOpTargetAttr(mlir::Value v, fir::AddrOfOp op) { + auto globalOpName = + mlir::OperationName(fir::GlobalOp::getOperationName(), op->getContext()); + return fir::valueHasFirAttribute( + v, fir::GlobalOp::getTargetAttrName(globalOpName)); +} + +mlir::Value getOriginalDef(mlir::Value v) { mlir::Operation *defOp; bool breakFromLoop = false; while (!breakFromLoop && (defOp = v.getDefiningOp())) { @@ -46,6 +64,27 @@ static mlir::Value getOriginalDef(mlir::Value v) { return v; } +static bool isEvaluateInMemoryBlockArg(mlir::Value v) { + if (auto evalInMem = llvm::dyn_cast_or_null( + v.getParentRegion()->getParentOp())) + return evalInMem.getMemory() == v; + return false; +} + +template +static bool isPrivateArg(omp::BlockArgOpenMPOpInterface &argIface, + OMPTypeOp &op, DeclTypeOp &declOp) { + if (!op.getPrivateSyms().has_value()) + return false; + for (auto [opSym, blockArg] : + llvm::zip_equal(*op.getPrivateSyms(), argIface.getPrivateBlockArgs())) { + if (blockArg == declOp.getMemref()) { + return true; + } + } + return false; +} + namespace fir { void AliasAnalysis::Source::print(llvm::raw_ostream &os) const { @@ -91,13 +130,6 @@ bool AliasAnalysis::Source::isDummyArgument() const { return false; } -static bool isEvaluateInMemoryBlockArg(mlir::Value v) { - if (auto evalInMem = llvm::dyn_cast_or_null( - v.getParentRegion()->getParentOp())) - return evalInMem.getMemory() == v; - return false; -} - bool AliasAnalysis::Source::isData() const { return origin.isData; } bool AliasAnalysis::Source::isBoxData() const { return mlir::isa(fir::unwrapRefType(valueType)) && @@ -491,33 +523,6 @@ ModRefResult AliasAnalysis::getModRef(mlir::Region ®ion, return result; } -AliasAnalysis::Source::Attributes -getAttrsFromVariable(fir::FortranVariableOpInterface var) { - AliasAnalysis::Source::Attributes attrs; - if (var.isTarget()) - attrs.set(AliasAnalysis::Attribute::Target); - if (var.isPointer()) - attrs.set(AliasAnalysis::Attribute::Pointer); - if (var.isIntentIn()) - attrs.set(AliasAnalysis::Attribute::IntentIn); - - return attrs; -} - -template -static bool isPrivateArg(omp::BlockArgOpenMPOpInterface &argIface, - OMPTypeOp &op, DeclTypeOp &declOp) { - if (!op.getPrivateSyms().has_value()) - return false; - for (auto [opSym, blockArg] : - llvm::zip_equal(*op.getPrivateSyms(), argIface.getPrivateBlockArgs())) { - if (blockArg == declOp.getMemref()) { - return true; - } - } - return false; -} - AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v, bool getLastInstantiationPoint) { auto *defOp = v.getDefiningOp(); @@ -604,10 +609,7 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v, ty = v.getType(); type = SourceKind::Global; - auto globalOpName = mlir::OperationName( - fir::GlobalOp::getOperationName(), defOp->getContext()); - if (fir::valueHasFirAttribute( - v, fir::GlobalOp::getTargetAttrName(globalOpName))) + if (hasGlobalOpTargetAttr(v, op)) attributes.set(Attribute::Target); // TODO: Take followBoxData into account when setting the pointer