@@ -31,9 +31,27 @@ 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+ static fir::AliasAnalysis::Source::Attributes
35+ getAttrsFromVariable (fir::FortranVariableOpInterface var) {
36+ fir::AliasAnalysis::Source::Attributes attrs;
37+ if (var.isTarget ())
38+ attrs.set (fir::AliasAnalysis::Attribute::Target);
39+ if (var.isPointer ())
40+ attrs.set (fir::AliasAnalysis::Attribute::Pointer);
41+ if (var.isIntentIn ())
42+ attrs.set (fir::AliasAnalysis::Attribute::IntentIn);
43+
44+ return attrs;
45+ }
46+
47+ static bool hasGlobalOpTargetAttr (mlir::Value v, fir::AddrOfOp op) {
48+ auto globalOpName =
49+ mlir::OperationName (fir::GlobalOp::getOperationName (), op->getContext ());
50+ return fir::valueHasFirAttribute (
51+ v, fir::GlobalOp::getTargetAttrName (globalOpName));
52+ }
53+
54+ mlir::Value getOriginalDef (mlir::Value v) {
3755 mlir::Operation *defOp;
3856 bool breakFromLoop = false ;
3957 while (!breakFromLoop && (defOp = v.getDefiningOp ())) {
@@ -46,6 +64,27 @@ static mlir::Value getOriginalDef(mlir::Value v) {
4664 return v;
4765}
4866
67+ static bool isEvaluateInMemoryBlockArg (mlir::Value v) {
68+ if (auto evalInMem = llvm::dyn_cast_or_null<hlfir::EvaluateInMemoryOp>(
69+ v.getParentRegion ()->getParentOp ()))
70+ return evalInMem.getMemory () == v;
71+ return false ;
72+ }
73+
74+ template <typename OMPTypeOp, typename DeclTypeOp>
75+ static bool isPrivateArg (omp::BlockArgOpenMPOpInterface &argIface,
76+ OMPTypeOp &op, DeclTypeOp &declOp) {
77+ if (!op.getPrivateSyms ().has_value ())
78+ return false ;
79+ for (auto [opSym, blockArg] :
80+ llvm::zip_equal (*op.getPrivateSyms (), argIface.getPrivateBlockArgs ())) {
81+ if (blockArg == declOp.getMemref ()) {
82+ return true ;
83+ }
84+ }
85+ return false ;
86+ }
87+
4988namespace fir {
5089
5190void AliasAnalysis::Source::print (llvm::raw_ostream &os) const {
@@ -91,13 +130,6 @@ bool AliasAnalysis::Source::isDummyArgument() const {
91130 return false ;
92131}
93132
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-
101133bool AliasAnalysis::Source::isData () const { return origin.isData ; }
102134bool AliasAnalysis::Source::isBoxData () const {
103135 return mlir::isa<fir::BaseBoxType>(fir::unwrapRefType (valueType)) &&
@@ -491,33 +523,6 @@ ModRefResult AliasAnalysis::getModRef(mlir::Region ®ion,
491523 return result;
492524}
493525
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-
521526AliasAnalysis::Source AliasAnalysis::getSource (mlir::Value v,
522527 bool getLastInstantiationPoint) {
523528 auto *defOp = v.getDefiningOp ();
@@ -604,10 +609,7 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v,
604609 ty = v.getType ();
605610 type = SourceKind::Global;
606611
607- auto globalOpName = mlir::OperationName (
608- fir::GlobalOp::getOperationName (), defOp->getContext ());
609- if (fir::valueHasFirAttribute (
610- v, fir::GlobalOp::getTargetAttrName (globalOpName)))
612+ if (hasGlobalOpTargetAttr (v, op))
611613 attributes.set (Attribute::Target);
612614
613615 // TODO: Take followBoxData into account when setting the pointer
0 commit comments