@@ -31,9 +31,29 @@ using namespace mlir;
3131// AliasAnalysis: alias
3232// ===----------------------------------------------------------------------===//
3333
34- // / Temporary function to skip through all the no op operations
35- // / TODO: Generalize support of fir.load
36- static mlir::Value getOriginalDef (mlir::Value v) {
34+ namespace {
35+
36+ fir::AliasAnalysis::Source::Attributes
37+ getAttrsFromVariable (fir::FortranVariableOpInterface var) {
38+ fir::AliasAnalysis::Source::Attributes attrs;
39+ if (var.isTarget ())
40+ attrs.set (fir::AliasAnalysis::Attribute::Target);
41+ if (var.isPointer ())
42+ attrs.set (fir::AliasAnalysis::Attribute::Pointer);
43+ if (var.isIntentIn ())
44+ attrs.set (fir::AliasAnalysis::Attribute::IntentIn);
45+
46+ return attrs;
47+ }
48+
49+ bool hasGlobalOpTargetAttr (mlir::Value v, fir::AddrOfOp op) {
50+ auto globalOpName =
51+ mlir::OperationName (fir::GlobalOp::getOperationName (), op->getContext ());
52+ return fir::valueHasFirAttribute (
53+ v, fir::GlobalOp::getTargetAttrName (globalOpName));
54+ }
55+
56+ mlir::Value getOriginalDef (mlir::Value v) {
3757 mlir::Operation *defOp;
3858 bool breakFromLoop = false ;
3959 while (!breakFromLoop && (defOp = v.getDefiningOp ())) {
@@ -46,6 +66,29 @@ static mlir::Value getOriginalDef(mlir::Value v) {
4666 return v;
4767}
4868
69+ bool isEvaluateInMemoryBlockArg (mlir::Value v) {
70+ if (auto evalInMem = llvm::dyn_cast_or_null<hlfir::EvaluateInMemoryOp>(
71+ v.getParentRegion ()->getParentOp ()))
72+ return evalInMem.getMemory () == v;
73+ return false ;
74+ }
75+
76+ template <typename OMPTypeOp, typename DeclTypeOp>
77+ bool isPrivateArg (omp::BlockArgOpenMPOpInterface &argIface, OMPTypeOp &op,
78+ DeclTypeOp &declOp) {
79+ if (!op.getPrivateSyms ().has_value ())
80+ return false ;
81+ for (auto [opSym, blockArg] :
82+ llvm::zip_equal (*op.getPrivateSyms (), argIface.getPrivateBlockArgs ())) {
83+ if (blockArg == declOp.getMemref ()) {
84+ return true ;
85+ }
86+ }
87+ return false ;
88+ }
89+
90+ } // namespace
91+
4992namespace fir {
5093
5194void AliasAnalysis::Source::print (llvm::raw_ostream &os) const {
@@ -91,13 +134,6 @@ bool AliasAnalysis::Source::isDummyArgument() const {
91134 return false ;
92135}
93136
94- static bool isEvaluateInMemoryBlockArg (mlir::Value v) {
95- if (auto evalInMem = llvm::dyn_cast_or_null<hlfir::EvaluateInMemoryOp>(
96- v.getParentRegion ()->getParentOp ()))
97- return evalInMem.getMemory () == v;
98- return false ;
99- }
100-
101137bool AliasAnalysis::Source::isData () const { return origin.isData ; }
102138bool AliasAnalysis::Source::isBoxData () const {
103139 return mlir::isa<fir::BaseBoxType>(fir::unwrapRefType (valueType)) &&
@@ -348,7 +384,9 @@ AliasResult AliasAnalysis::alias(Source lhsSrc, Source rhsSrc, mlir::Value lhs,
348384// AliasAnalysis: getModRef
349385// ===----------------------------------------------------------------------===//
350386
351- static bool isSavedLocal (const fir::AliasAnalysis::Source &src) {
387+ namespace {
388+
389+ bool isSavedLocal (const fir::AliasAnalysis::Source &src) {
352390 if (auto symRef = llvm::dyn_cast<mlir::SymbolRefAttr>(src.origin .u )) {
353391 auto [nameKind, deconstruct] =
354392 fir::NameUniquer::deconstruct (symRef.getLeafReference ().getValue ());
@@ -358,7 +396,7 @@ static bool isSavedLocal(const fir::AliasAnalysis::Source &src) {
358396 return false ;
359397}
360398
361- static bool isCallToFortranUserProcedure (fir::CallOp call) {
399+ bool isCallToFortranUserProcedure (fir::CallOp call) {
362400 // TODO: indirect calls are excluded by these checks. Maybe some attribute is
363401 // needed to flag user calls in this case.
364402 if (fir::hasBindcAttr (call))
@@ -369,7 +407,7 @@ static bool isCallToFortranUserProcedure(fir::CallOp call) {
369407 return false ;
370408}
371409
372- static ModRefResult getCallModRef (fir::CallOp call, mlir::Value var) {
410+ ModRefResult getCallModRef (fir::CallOp call, mlir::Value var) {
373411 // TODO: limit to Fortran functions??
374412 // 1. Detect variables that can be accessed indirectly.
375413 fir::AliasAnalysis aliasAnalysis;
@@ -423,6 +461,8 @@ static ModRefResult getCallModRef(fir::CallOp call, mlir::Value var) {
423461 return ModRefResult::getNoModRef ();
424462}
425463
464+ } // namespace
465+
426466// / This is mostly inspired by MLIR::LocalAliasAnalysis with 2 notable
427467// / differences 1) Regions are not handled here but will be handled by a data
428468// / flow analysis to come 2) Allocate and Free effects are considered
@@ -491,33 +531,6 @@ ModRefResult AliasAnalysis::getModRef(mlir::Region ®ion,
491531 return result;
492532}
493533
494- AliasAnalysis::Source::Attributes
495- getAttrsFromVariable (fir::FortranVariableOpInterface var) {
496- AliasAnalysis::Source::Attributes attrs;
497- if (var.isTarget ())
498- attrs.set (AliasAnalysis::Attribute::Target);
499- if (var.isPointer ())
500- attrs.set (AliasAnalysis::Attribute::Pointer);
501- if (var.isIntentIn ())
502- attrs.set (AliasAnalysis::Attribute::IntentIn);
503-
504- return attrs;
505- }
506-
507- template <typename OMPTypeOp, typename DeclTypeOp>
508- static bool isPrivateArg (omp::BlockArgOpenMPOpInterface &argIface,
509- OMPTypeOp &op, DeclTypeOp &declOp) {
510- if (!op.getPrivateSyms ().has_value ())
511- return false ;
512- for (auto [opSym, blockArg] :
513- llvm::zip_equal (*op.getPrivateSyms (), argIface.getPrivateBlockArgs ())) {
514- if (blockArg == declOp.getMemref ()) {
515- return true ;
516- }
517- }
518- return false ;
519- }
520-
521534AliasAnalysis::Source AliasAnalysis::getSource (mlir::Value v,
522535 bool getLastInstantiationPoint) {
523536 auto *defOp = v.getDefiningOp ();
@@ -604,10 +617,7 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v,
604617 ty = v.getType ();
605618 type = SourceKind::Global;
606619
607- auto globalOpName = mlir::OperationName (
608- fir::GlobalOp::getOperationName (), defOp->getContext ());
609- if (fir::valueHasFirAttribute (
610- v, fir::GlobalOp::getTargetAttrName (globalOpName)))
620+ if (hasGlobalOpTargetAttr (v, op))
611621 attributes.set (Attribute::Target);
612622
613623 // TODO: Take followBoxData into account when setting the pointer
0 commit comments