@@ -70,13 +70,39 @@ class DoConcurrentConversion : public mlir::OpConversionPattern<fir::DoLoopOp> {
70
70
// loop header preparation/allocation operations.
71
71
72
72
// Clone the LB, UB, step defining ops inside the parallel region.
73
+ mlir::Operation* lbOp = doLoop.getLowerBound ().getDefiningOp ();
74
+ mlir::Operation* ubOp = doLoop.getUpperBound ().getDefiningOp ();
75
+ mlir::Operation* stepOp = doLoop.getStep ().getDefiningOp ();
76
+
77
+ if (lbOp == nullptr || ubOp == nullptr || stepOp == nullptr ) {
78
+ return rewriter.notifyMatchFailure (
79
+ doLoop, " At least one of the loop's LB, UB, or step doesn't have a "
80
+ " defining operation." );
81
+ }
82
+
83
+ std::function<bool (mlir::Operation *)> isOpUltimatelyConstant =
84
+ [&](mlir::Operation *operation) {
85
+ if (mlir::isa_and_present<mlir::arith::ConstantOp>(operation))
86
+ return true ;
87
+
88
+ if (fir::ConvertOp convertOp =
89
+ mlir::dyn_cast_if_present<fir::ConvertOp>(operation))
90
+ return isOpUltimatelyConstant (convertOp.getValue ().getDefiningOp ());
91
+
92
+ return false ;
93
+ };
94
+
95
+ if (!isOpUltimatelyConstant (lbOp) || !isOpUltimatelyConstant (ubOp) ||
96
+ !isOpUltimatelyConstant (stepOp)) {
97
+ return rewriter.notifyMatchFailure (
98
+ doLoop, " `do concurrent` conversion is currently only supported for "
99
+ " constant LB, UB, and step values." );
100
+ }
101
+
73
102
llvm::SmallVector<mlir::Value> lowerBound, upperBound, step;
74
- lowerBound.push_back (
75
- rewriter.clone (*doLoop.getLowerBound ().getDefiningOp ())->getResult (0 ));
76
- upperBound.push_back (
77
- rewriter.clone (*doLoop.getUpperBound ().getDefiningOp ())->getResult (0 ));
78
- step.push_back (
79
- rewriter.clone (*doLoop.getStep ().getDefiningOp ())->getResult (0 ));
103
+ lowerBound.push_back (rewriter.clone (*lbOp)->getResult (0 ));
104
+ upperBound.push_back (rewriter.clone (*ubOp)->getResult (0 ));
105
+ step.push_back (rewriter.clone (*stepOp)->getResult (0 ));
80
106
// ==== TODO (1) End ====
81
107
82
108
auto wsLoopOp = rewriter.create <mlir::omp::WsLoopOp>(
@@ -127,7 +153,7 @@ class DoConcurrentConversion : public mlir::OpConversionPattern<fir::DoLoopOp> {
127
153
workList.remove (item);
128
154
}
129
155
130
- // For each collected `fir.sotre `, find the target memref's alloca's and
156
+ // For each collected `fir.store `, find the target memref's alloca's and
131
157
// declare ops.
132
158
llvm::SmallSetVector<mlir::Operation *, 4 > declareAndAllocasToClone;
133
159
for (auto storeOp : inductionVarTargetStores) {
0 commit comments