[flang-commits] [flang] Support for lowering task_reduction and in_reduction to MLIR (PR #111155)
via flang-commits
flang-commits at lists.llvm.org
Fri Oct 4 06:51:35 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff dec4cfdb09596f34f17a653ad405ab2551b09039 b9dc55f8226baf5a6e00a5b0a7f84bb1a9ef0fa8 --extensions cpp,h -- flang/lib/Lower/OpenMP/ClauseProcessor.cpp flang/lib/Lower/OpenMP/ClauseProcessor.h flang/lib/Lower/OpenMP/OpenMP.cpp flang/lib/Lower/OpenMP/ReductionProcessor.cpp flang/lib/Lower/OpenMP/ReductionProcessor.h
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
index 95ab51809d..6a97b32d80 100644
--- a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
+++ b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
@@ -1097,19 +1097,23 @@ bool ClauseProcessor::processTaskReduction(
llvm::SmallVector<const semantics::Symbol *> taskReductionSyms;
ReductionProcessor rp;
rp.addDeclareReduction<omp::clause::TaskReduction>(
- currentLocation, converter, clause, taskReductionVars, taskReductionByref,
- taskReductionDeclSymbols, outReductionSyms ? &taskReductionSyms : nullptr);
+ currentLocation, converter, clause, taskReductionVars,
+ taskReductionByref, taskReductionDeclSymbols,
+ outReductionSyms ? &taskReductionSyms : nullptr);
// Copy local lists into the output.
- llvm::copy(taskReductionVars, std::back_inserter(result.taskReductionVars));
- llvm::copy(taskReductionByref, std::back_inserter(result.taskReductionByref));
+ llvm::copy(taskReductionVars,
+ std::back_inserter(result.taskReductionVars));
+ llvm::copy(taskReductionByref,
+ std::back_inserter(result.taskReductionByref));
llvm::copy(taskReductionDeclSymbols,
std::back_inserter(result.taskReductionSyms));
if (outReductionTypes) {
outReductionTypes->reserve(outReductionTypes->size() +
taskReductionVars.size());
- llvm::transform(taskReductionVars, std::back_inserter(*outReductionTypes),
+ llvm::transform(taskReductionVars,
+ std::back_inserter(*outReductionTypes),
[](mlir::Value v) { return v.getType(); });
}
@@ -1137,7 +1141,8 @@ bool ClauseProcessor::processInReduction(
// Copy local lists into the output.
llvm::copy(inReductionVars, std::back_inserter(result.inReductionVars));
- llvm::copy(inReductionByref, std::back_inserter(result.inReductionByref));
+ llvm::copy(inReductionByref,
+ std::back_inserter(result.inReductionByref));
llvm::copy(inReductionDeclSymbols,
std::back_inserter(result.inReductionSyms));
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp
index 850f32ff0b..28e13ef5dc 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -1240,20 +1240,18 @@ static void genTargetEnterExitUpdateDataClauses(
cp.processNowait(clauseOps);
}
-static void genTaskClauses(lower::AbstractConverter &converter,
- semantics::SemanticsContext &semaCtx,
- lower::StatementContext &stmtCtx,
- const List<Clause> &clauses, mlir::Location loc,
- mlir::omp::TaskOperands &clauseOps,
- llvm::SmallVectorImpl<mlir::Type> &inReductionTypes,
- llvm::SmallVectorImpl<const semantics::Symbol *> &inReductionSyms) {
+static void genTaskClauses(
+ lower::AbstractConverter &converter, semantics::SemanticsContext &semaCtx,
+ lower::StatementContext &stmtCtx, const List<Clause> &clauses,
+ mlir::Location loc, mlir::omp::TaskOperands &clauseOps,
+ llvm::SmallVectorImpl<mlir::Type> &inReductionTypes,
+ llvm::SmallVectorImpl<const semantics::Symbol *> &inReductionSyms) {
ClauseProcessor cp(converter, semaCtx, clauses);
cp.processAllocate(clauseOps);
cp.processDepend(clauseOps);
cp.processFinal(stmtCtx, clauseOps);
cp.processIf(llvm::omp::Directive::OMPD_task, clauseOps);
- cp.processInReduction(loc, clauseOps, &inReductionTypes,
- &inReductionSyms);
+ cp.processInReduction(loc, clauseOps, &inReductionTypes, &inReductionSyms);
cp.processMergeable(clauseOps);
cp.processPriority(stmtCtx, clauseOps);
cp.processUntied(clauseOps);
@@ -1263,15 +1261,16 @@ static void genTaskClauses(lower::AbstractConverter &converter,
loc, llvm::omp::Directive::OMPD_task);
}
-static void genTaskgroupClauses(lower::AbstractConverter &converter,
- semantics::SemanticsContext &semaCtx,
+static void genTaskgroupClauses(
+ lower::AbstractConverter &converter, semantics::SemanticsContext &semaCtx,
const List<Clause> &clauses, mlir::Location loc,
mlir::omp::TaskgroupOperands &clauseOps,
llvm::SmallVectorImpl<mlir::Type> &taskReductionTypes,
llvm::SmallVectorImpl<const semantics::Symbol *> &taskReductionSyms) {
ClauseProcessor cp(converter, semaCtx, clauses);
cp.processAllocate(clauseOps);
- cp.processTaskReduction(loc, clauseOps, &taskReductionTypes, &taskReductionSyms);
+ cp.processTaskReduction(loc, clauseOps, &taskReductionTypes,
+ &taskReductionSyms);
}
static void genTaskwaitClauses(lower::AbstractConverter &converter,
diff --git a/flang/lib/Lower/OpenMP/ReductionProcessor.cpp b/flang/lib/Lower/OpenMP/ReductionProcessor.cpp
index deb25b4fff..66853aa121 100644
--- a/flang/lib/Lower/OpenMP/ReductionProcessor.cpp
+++ b/flang/lib/Lower/OpenMP/ReductionProcessor.cpp
@@ -37,35 +37,29 @@ namespace omp {
// explicit template declarations
template void ReductionProcessor::addDeclareReduction<omp::clause::Reduction>(
- mlir::Location currentLocation,
- lower::AbstractConverter &converter,
- const omp::clause::Reduction &reduction,
- llvm::SmallVectorImpl<mlir::Value> &reductionVars,
- llvm::SmallVectorImpl<bool> &reduceVarByRef,
- llvm::SmallVectorImpl<mlir::Attribute> &reductionDeclSymbols,
- llvm::SmallVectorImpl<const semantics::Symbol *> *reductionSymbols
- );
-
-template void ReductionProcessor::addDeclareReduction<omp::clause::TaskReduction>(
- mlir::Location currentLocation,
- lower::AbstractConverter &converter,
- const omp::clause::TaskReduction &reduction,
- llvm::SmallVectorImpl<mlir::Value> &reductionVars,
- llvm::SmallVectorImpl<bool> &reduceVarByRef,
- llvm::SmallVectorImpl<mlir::Attribute> &reductionDeclSymbols,
- llvm::SmallVectorImpl<const semantics::Symbol *> *reductionSymbols
- );
+ mlir::Location currentLocation, lower::AbstractConverter &converter,
+ const omp::clause::Reduction &reduction,
+ llvm::SmallVectorImpl<mlir::Value> &reductionVars,
+ llvm::SmallVectorImpl<bool> &reduceVarByRef,
+ llvm::SmallVectorImpl<mlir::Attribute> &reductionDeclSymbols,
+ llvm::SmallVectorImpl<const semantics::Symbol *> *reductionSymbols);
-template void ReductionProcessor::addDeclareReduction<omp::clause::InReduction>(
- mlir::Location currentLocation,
- lower::AbstractConverter &converter,
- const omp::clause::InReduction &reduction,
- llvm::SmallVectorImpl<mlir::Value> &reductionVars,
- llvm::SmallVectorImpl<bool> &reduceVarByRef,
- llvm::SmallVectorImpl<mlir::Attribute> &reductionDeclSymbols,
- llvm::SmallVectorImpl<const semantics::Symbol *> *reductionSymbols
- );
+template void
+ReductionProcessor::addDeclareReduction<omp::clause::TaskReduction>(
+ mlir::Location currentLocation, lower::AbstractConverter &converter,
+ const omp::clause::TaskReduction &reduction,
+ llvm::SmallVectorImpl<mlir::Value> &reductionVars,
+ llvm::SmallVectorImpl<bool> &reduceVarByRef,
+ llvm::SmallVectorImpl<mlir::Attribute> &reductionDeclSymbols,
+ llvm::SmallVectorImpl<const semantics::Symbol *> *reductionSymbols);
+template void ReductionProcessor::addDeclareReduction<omp::clause::InReduction>(
+ mlir::Location currentLocation, lower::AbstractConverter &converter,
+ const omp::clause::InReduction &reduction,
+ llvm::SmallVectorImpl<mlir::Value> &reductionVars,
+ llvm::SmallVectorImpl<bool> &reduceVarByRef,
+ llvm::SmallVectorImpl<mlir::Attribute> &reductionDeclSymbols,
+ llvm::SmallVectorImpl<const semantics::Symbol *> *reductionSymbols);
ReductionProcessor::ReductionIdentifier ReductionProcessor::getReductionType(
const omp::clause::ProcedureDesignator &pd) {
@@ -750,25 +744,23 @@ static bool doReductionByRef(mlir::Value reductionVar) {
}
template <class T>
-void ReductionProcessor::addDeclareReduction(mlir::Location currentLocation,
- lower::AbstractConverter &converter,
- const T &reduction,
- llvm::SmallVectorImpl<mlir::Value> &reductionVars,
+void ReductionProcessor::addDeclareReduction(
+ mlir::Location currentLocation, lower::AbstractConverter &converter,
+ const T &reduction, llvm::SmallVectorImpl<mlir::Value> &reductionVars,
llvm::SmallVectorImpl<bool> &reduceVarByRef,
llvm::SmallVectorImpl<mlir::Attribute> &reductionDeclSymbols,
llvm::SmallVectorImpl<const semantics::Symbol *> *reductionSymbols) {
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
if constexpr (std::is_same<T, omp::clause::Reduction>::value) {
- if (std::get<std::optional<typename T::ReductionModifier>>(
- reduction.t))
+ if (std::get<std::optional<typename T::ReductionModifier>>(reduction.t))
TODO(currentLocation, "Reduction modifiers are not supported");
- }
+ }
mlir::omp::DeclareReductionOp decl;
- const auto &redOperatorList{
+ const auto &redOperatorList{
std::get<typename T::ReductionIdentifiers>(reduction.t)};
- assert(redOperatorList.size() == 1 && "Expecting single operator");
- const auto &redOperator = redOperatorList.front();
+ assert(redOperatorList.size() == 1 && "Expecting single operator");
+ const auto &redOperator = redOperatorList.front();
const auto &objectList{std::get<omp::ObjectList>(reduction.t)};
if (!std::holds_alternative<omp::clause::DefinedOperator>(redOperator.u)) {
diff --git a/flang/lib/Lower/OpenMP/ReductionProcessor.h b/flang/lib/Lower/OpenMP/ReductionProcessor.h
index d34db0618c..d71fde93de 100644
--- a/flang/lib/Lower/OpenMP/ReductionProcessor.h
+++ b/flang/lib/Lower/OpenMP/ReductionProcessor.h
@@ -123,8 +123,7 @@ public:
template <class T>
static void addDeclareReduction(
mlir::Location currentLocation, lower::AbstractConverter &converter,
- const T &reduction,
- llvm::SmallVectorImpl<mlir::Value> &reductionVars,
+ const T &reduction, llvm::SmallVectorImpl<mlir::Value> &reductionVars,
llvm::SmallVectorImpl<bool> &reduceVarByRef,
llvm::SmallVectorImpl<mlir::Attribute> &reductionDeclSymbols,
llvm::SmallVectorImpl<const semantics::Symbol *> *reductionSymbols =
``````````
</details>
https://github.com/llvm/llvm-project/pull/111155
More information about the flang-commits
mailing list