Skip to content

Commit b1d66da

Browse files
Handle nowait and use it to add an if clause when creating an outer task around offloading ops like target"rgett
1 parent dc4f90d commit b1d66da

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

flang/lib/Lower/OpenMP/ClauseProcessor.cpp

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -780,19 +780,38 @@ bool ClauseProcessor::processTargetDepend(
780780
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
781781

782782
// Create the new omp.task op.
783-
// As per the OpenMP Spec a target directive creates a mergeable 'target
784-
// task'
783+
// Whether we create a mergeable task or not depends upon the presence of the
784+
// nowait clause on the target construct.
785+
// If the nowait clause is not present on the target construct, then as per
786+
// the spec, the target task is an included task. We add if(0) clause to the
787+
// task that we create. A task with an if clause that evaluates to false is
788+
// undeferred and because this value is known at compile time, it is an
789+
// included task. And an included task is also mergeable. So, we don't bother
790+
// with the mergeable clause here. If the nowait clause is present on the
791+
// target construct, then as per the spec, the execution of the target task
792+
// may be deferred. This makes it trivially not mergeable.
793+
mlir::omp::NowaitClauseOps nowaitClauseOp;
794+
markClauseOccurrence<omp::clause::Nowait>(nowaitClauseOp.nowaitAttr);
795+
785796
mlir::omp::TaskOp taskOp = firOpBuilder.create<mlir::omp::TaskOp>(
786-
currentLocation, /*if_expr*/ mlir::Value(),
797+
currentLocation,
798+
/*if_expr*/ nowaitClauseOp.nowaitAttr
799+
? firOpBuilder.createBool(currentLocation, true)
800+
: firOpBuilder.createBool(currentLocation, false),
787801
/*final_expr*/ mlir::Value(), /*untied*/ mlir::UnitAttr(),
788-
/*mergeable*/ firOpBuilder.getUnitAttr(),
802+
/*mergeable*/ mlir::UnitAttr(),
789803
/*in_reduction_vars*/ mlir::ValueRange(), /*in_reductions*/ nullptr,
790804
/*priority*/ mlir::Value(),
791805
mlir::ArrayAttr::get(converter.getFirOpBuilder().getContext(),
792806
clauseOps.dependTypeAttrs),
793807
clauseOps.dependVars, /*allocate_vars*/ mlir::ValueRange(),
794808
/*allocate_vars*/ mlir::ValueRange());
795809

810+
// Clear the dependencies so that the subsequent omp.target op doesn't have
811+
// dependencies
812+
clauseOps.dependTypeAttrs.clear();
813+
clauseOps.dependVars.clear();
814+
796815
firOpBuilder.createBlock(&taskOp.getRegion());
797816
firOpBuilder.create<mlir::omp::TerminatorOp>(currentLocation);
798817
firOpBuilder.setInsertionPointToStart(&taskOp.getRegion().front());

0 commit comments

Comments
 (0)