Skip to content

Commit 385768a

Browse files
committed
Handle review comments.
1 parent e4d6564 commit 385768a

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

flang/include/flang/Optimizer/Transforms/Passes.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ def FunctionAttr : Pass<"function-attr", "mlir::func::FuncOp"> {
400400
def DoConcurrentConversionPass : Pass<"fopenmp-do-concurrent-conversion", "mlir::func::FuncOp"> {
401401
let summary = "Map `DO CONCURRENT` loops to OpenMP worksharing loops.";
402402

403-
let description = [{ This is an experimental pass to map `DO CONCURRENR` loops
403+
let description = [{ This is an experimental pass to map `DO CONCURRENT` loops
404404
to their correspnding equivalent OpenMP worksharing constructs.
405405

406406
For now the following is supported:

flang/lib/Optimizer/Transforms/DoConcurrentConversion.cpp

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,39 @@ class DoConcurrentConversion : public mlir::OpConversionPattern<fir::DoLoopOp> {
7070
// loop header preparation/allocation operations.
7171

7272
// 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+
73102
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));
80106
// ==== TODO (1) End ====
81107

82108
auto wsLoopOp = rewriter.create<mlir::omp::WsLoopOp>(
@@ -127,7 +153,7 @@ class DoConcurrentConversion : public mlir::OpConversionPattern<fir::DoLoopOp> {
127153
workList.remove(item);
128154
}
129155

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
131157
// declare ops.
132158
llvm::SmallSetVector<mlir::Operation *, 4> declareAndAllocasToClone;
133159
for (auto storeOp : inductionVarTargetStores) {

0 commit comments

Comments
 (0)