@@ -31,9 +31,27 @@ using namespace mlir;
31
31
// AliasAnalysis: alias
32
32
// ===----------------------------------------------------------------------===//
33
33
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) {
37
55
mlir::Operation *defOp;
38
56
bool breakFromLoop = false ;
39
57
while (!breakFromLoop && (defOp = v.getDefiningOp ())) {
@@ -46,6 +64,27 @@ static mlir::Value getOriginalDef(mlir::Value v) {
46
64
return v;
47
65
}
48
66
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
+
49
88
namespace fir {
50
89
51
90
void AliasAnalysis::Source::print (llvm::raw_ostream &os) const {
@@ -91,13 +130,6 @@ bool AliasAnalysis::Source::isDummyArgument() const {
91
130
return false ;
92
131
}
93
132
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
-
101
133
bool AliasAnalysis::Source::isData () const { return origin.isData ; }
102
134
bool AliasAnalysis::Source::isBoxData () const {
103
135
return mlir::isa<fir::BaseBoxType>(fir::unwrapRefType (valueType)) &&
@@ -491,33 +523,6 @@ ModRefResult AliasAnalysis::getModRef(mlir::Region ®ion,
491
523
return result;
492
524
}
493
525
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
-
521
526
AliasAnalysis::Source AliasAnalysis::getSource (mlir::Value v,
522
527
bool getLastInstantiationPoint) {
523
528
auto *defOp = v.getDefiningOp ();
@@ -604,10 +609,7 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v,
604
609
ty = v.getType ();
605
610
type = SourceKind::Global;
606
611
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))
611
613
attributes.set (Attribute::Target);
612
614
613
615
// TODO: Take followBoxData into account when setting the pointer
0 commit comments