[flang-commits] [flang] [flang][OpenMP] Pass semantics context to all generating functions in… (PR #81269)
via flang-commits
flang-commits at lists.llvm.org
Fri Feb 9 08:33:26 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-openmp
@llvm/pr-subscribers-flang-fir-hlfir
Author: Krzysztof Parzyszek (kparzysz)
<details>
<summary>Changes</summary>
… lower
The convention is to pass it after "symTable" if present, otherwise after "converter":
- converter, symTable, semaCtx
- converter, semaCtx
This makes the interfaces more uniform---some of these functions were already taking the semantics context, while others were not.
The context will be used in future patches.
---
Patch is 49.51 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/81269.diff
3 Files Affected:
- (modified) flang/include/flang/Lower/OpenMP.h (+2)
- (modified) flang/lib/Lower/Bridge.cpp (+2-1)
- (modified) flang/lib/Lower/OpenMP.cpp (+145-130)
``````````diff
diff --git a/flang/include/flang/Lower/OpenMP.h b/flang/include/flang/Lower/OpenMP.h
index d2b7a423d77810..e6fe7fb2276dea 100644
--- a/flang/include/flang/Lower/OpenMP.h
+++ b/flang/include/flang/Lower/OpenMP.h
@@ -72,6 +72,7 @@ int64_t getCollapseValue(const Fortran::parser::OmpClauseList &clauseList);
void genThreadprivateOp(AbstractConverter &, const pft::Variable &);
void genDeclareTargetIntGlobal(AbstractConverter &, const pft::Variable &);
void genOpenMPReduction(AbstractConverter &,
+ Fortran::semantics::SemanticsContext &,
const Fortran::parser::OmpClauseList &clauseList);
mlir::Operation *findReductionChain(mlir::Value, mlir::Value * = nullptr);
@@ -82,6 +83,7 @@ void removeStoreOp(mlir::Operation *, mlir::Value);
bool isOpenMPTargetConstruct(const parser::OpenMPConstruct &);
bool isOpenMPDeviceDeclareTarget(Fortran::lower::AbstractConverter &,
+ Fortran::semantics::SemanticsContext &,
Fortran::lower::pft::Evaluation &,
const parser::OpenMPDeclarativeConstruct &);
void genOpenMPRequires(mlir::Operation *, const Fortran::semantics::Symbol *);
diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index 579f94ba756841..dc0e1f91168dc2 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -2470,7 +2470,8 @@ class FirConverter : public Fortran::lower::AbstractConverter {
// found
ompDeviceCodeFound =
ompDeviceCodeFound ||
- Fortran::lower::isOpenMPDeviceDeclareTarget(*this, getEval(), ompDecl);
+ Fortran::lower::isOpenMPDeviceDeclareTarget(
+ *this, bridge.getSemanticsContext(), getEval(), ompDecl);
genOpenMPDeclarativeConstruct(
*this, localSymbols, bridge.getSemanticsContext(), getEval(), ompDecl);
builder->restoreInsertionPoint(insertPt);
diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index ad4cffc707535f..3baee2bb714d6c 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -552,8 +552,9 @@ class ClauseProcessor {
public:
ClauseProcessor(Fortran::lower::AbstractConverter &converter,
+ Fortran::semantics::SemanticsContext &semaCtx,
const Fortran::parser::OmpClauseList &clauses)
- : converter(converter), clauses(clauses) {}
+ : converter(converter), semaCtx(semaCtx), clauses(clauses) {}
// 'Unique' clauses: They can appear at most once in the clause list.
bool
@@ -614,7 +615,6 @@ class ClauseProcessor {
// target directives that require it.
bool processMap(mlir::Location currentLocation,
const llvm::omp::Directive &directive,
- Fortran::semantics::SemanticsContext &semanticsContext,
Fortran::lower::StatementContext &stmtCtx,
llvm::SmallVectorImpl<mlir::Value> &mapOperands,
llvm::SmallVectorImpl<mlir::Type> *mapSymTypes = nullptr,
@@ -641,10 +641,8 @@ class ClauseProcessor {
&useDeviceSymbols) const;
template <typename T>
- bool
- processMotionClauses(Fortran::semantics::SemanticsContext &semanticsContext,
- Fortran::lower::StatementContext &stmtCtx,
- llvm::SmallVectorImpl<mlir::Value> &mapOperands);
+ bool processMotionClauses(Fortran::lower::StatementContext &stmtCtx,
+ llvm::SmallVectorImpl<mlir::Value> &mapOperands);
// Call this method for these clauses that should be supported but are not
// implemented yet. It triggers a compilation error if any of the given
@@ -713,6 +711,7 @@ class ClauseProcessor {
}
Fortran::lower::AbstractConverter &converter;
+ Fortran::semantics::SemanticsContext &semaCtx;
const Fortran::parser::OmpClauseList &clauses;
};
@@ -1845,7 +1844,6 @@ createMapInfoOp(fir::FirOpBuilder &builder, mlir::Location loc,
bool ClauseProcessor::processMap(
mlir::Location currentLocation, const llvm::omp::Directive &directive,
- Fortran::semantics::SemanticsContext &semanticsContext,
Fortran::lower::StatementContext &stmtCtx,
llvm::SmallVectorImpl<mlir::Value> &mapOperands,
llvm::SmallVectorImpl<mlir::Type> *mapSymTypes,
@@ -1907,7 +1905,7 @@ bool ClauseProcessor::processMap(
Fortran::lower::gatherDataOperandAddrAndBounds<
Fortran::parser::OmpObject, mlir::omp::DataBoundsOp,
mlir::omp::DataBoundsType>(
- converter, firOpBuilder, semanticsContext, stmtCtx, ompObject,
+ converter, firOpBuilder, semaCtx, stmtCtx, ompObject,
clauseLocation, asFortran, bounds, treatIndexAsSection);
auto origSymbol =
@@ -2012,7 +2010,6 @@ bool ClauseProcessor::processUseDevicePtr(
template <typename T>
bool ClauseProcessor::processMotionClauses(
- Fortran::semantics::SemanticsContext &semanticsContext,
Fortran::lower::StatementContext &stmtCtx,
llvm::SmallVectorImpl<mlir::Value> &mapOperands) {
return findRepeatableClause<T>(
@@ -2036,7 +2033,7 @@ bool ClauseProcessor::processMotionClauses(
Fortran::lower::gatherDataOperandAddrAndBounds<
Fortran::parser::OmpObject, mlir::omp::DataBoundsOp,
mlir::omp::DataBoundsType>(
- converter, firOpBuilder, semanticsContext, stmtCtx, ompObject,
+ converter, firOpBuilder, semaCtx, stmtCtx, ompObject,
clauseLocation, asFortran, bounds, treatIndexAsSection);
auto origSymbol =
@@ -2275,8 +2272,9 @@ struct OpWithBodyGenInfo {
mlir::Operation *)>;
OpWithBodyGenInfo(Fortran::lower::AbstractConverter &converter,
+ Fortran::semantics::SemanticsContext &semaCtx,
mlir::Location loc, Fortran::lower::pft::Evaluation &eval)
- : converter(converter), loc(loc), eval(eval) {}
+ : converter(converter), semaCtx(semaCtx), loc(loc), eval(eval) {}
OpWithBodyGenInfo &setGenNested(bool value) {
genNested = value;
@@ -2305,6 +2303,8 @@ struct OpWithBodyGenInfo {
/// [inout] converter to use for the clauses.
Fortran::lower::AbstractConverter &converter;
+ /// [in] Semantics context
+ Fortran::semantics::SemanticsContext &semaCtx;
/// [in] location in source code.
mlir::Location loc;
/// [in] current PFT node/evaluation.
@@ -2378,7 +2378,8 @@ static void createBodyOfOp(Op &op, OpWithBodyGenInfo &info) {
threadPrivatizeVars(info.converter, info.eval);
if (info.clauses) {
firOpBuilder.setInsertionPoint(marker);
- ClauseProcessor(info.converter, *info.clauses).processCopyin();
+ ClauseProcessor(info.converter, info.semaCtx, *info.clauses)
+ .processCopyin();
}
}
@@ -2458,6 +2459,7 @@ static void createBodyOfOp(Op &op, OpWithBodyGenInfo &info) {
static void genBodyOfTargetDataOp(
Fortran::lower::AbstractConverter &converter,
+ Fortran::semantics::SemanticsContext &semaCtx,
Fortran::lower::pft::Evaluation &eval, bool genNested,
mlir::omp::DataOp &dataOp,
const llvm::SmallVector<mlir::Type> &useDeviceTypes,
@@ -2531,26 +2533,29 @@ static OpTy genOpWithBody(OpWithBodyGenInfo &info, Args &&...args) {
static mlir::omp::MasterOp
genMasterOp(Fortran::lower::AbstractConverter &converter,
+ Fortran::semantics::SemanticsContext &semaCtx,
Fortran::lower::pft::Evaluation &eval, bool genNested,
mlir::Location currentLocation) {
return genOpWithBody<mlir::omp::MasterOp>(
- OpWithBodyGenInfo(converter, currentLocation, eval)
+ OpWithBodyGenInfo(converter, semaCtx, currentLocation, eval)
.setGenNested(genNested),
/*resultTypes=*/mlir::TypeRange());
}
static mlir::omp::OrderedRegionOp
genOrderedRegionOp(Fortran::lower::AbstractConverter &converter,
+ Fortran::semantics::SemanticsContext &semaCtx,
Fortran::lower::pft::Evaluation &eval, bool genNested,
mlir::Location currentLocation) {
return genOpWithBody<mlir::omp::OrderedRegionOp>(
- OpWithBodyGenInfo(converter, currentLocation, eval)
+ OpWithBodyGenInfo(converter, semaCtx, currentLocation, eval)
.setGenNested(genNested),
/*simd=*/false);
}
static mlir::omp::ParallelOp
genParallelOp(Fortran::lower::AbstractConverter &converter,
+ Fortran::semantics::SemanticsContext &semaCtx,
Fortran::lower::pft::Evaluation &eval, bool genNested,
mlir::Location currentLocation,
const Fortran::parser::OmpClauseList &clauseList,
@@ -2562,7 +2567,7 @@ genParallelOp(Fortran::lower::AbstractConverter &converter,
reductionVars;
llvm::SmallVector<mlir::Attribute> reductionDeclSymbols;
- ClauseProcessor cp(converter, clauseList);
+ ClauseProcessor cp(converter, semaCtx, clauseList);
cp.processIf(Fortran::parser::OmpIfClause::DirectiveNameModifier::Parallel,
ifClauseOperand);
cp.processNumThreads(stmtCtx, numThreadsClauseOperand);
@@ -2573,7 +2578,7 @@ genParallelOp(Fortran::lower::AbstractConverter &converter,
cp.processReduction(currentLocation, reductionVars, reductionDeclSymbols);
return genOpWithBody<mlir::omp::ParallelOp>(
- OpWithBodyGenInfo(converter, currentLocation, eval)
+ OpWithBodyGenInfo(converter, semaCtx, currentLocation, eval)
.setGenNested(genNested)
.setOuterCombined(outerCombined)
.setClauses(&clauseList),
@@ -2589,19 +2594,21 @@ genParallelOp(Fortran::lower::AbstractConverter &converter,
static mlir::omp::SectionOp
genSectionOp(Fortran::lower::AbstractConverter &converter,
+ Fortran::semantics::SemanticsContext &semaCtx,
Fortran::lower::pft::Evaluation &eval, bool genNested,
mlir::Location currentLocation,
const Fortran::parser::OmpClauseList §ionsClauseList) {
// Currently only private/firstprivate clause is handled, and
// all privatization is done within `omp.section` operations.
return genOpWithBody<mlir::omp::SectionOp>(
- OpWithBodyGenInfo(converter, currentLocation, eval)
+ OpWithBodyGenInfo(converter, semaCtx, currentLocation, eval)
.setGenNested(genNested)
.setClauses(§ionsClauseList));
}
static mlir::omp::SingleOp
genSingleOp(Fortran::lower::AbstractConverter &converter,
+ Fortran::semantics::SemanticsContext &semaCtx,
Fortran::lower::pft::Evaluation &eval, bool genNested,
mlir::Location currentLocation,
const Fortran::parser::OmpClauseList &beginClauseList,
@@ -2609,15 +2616,15 @@ genSingleOp(Fortran::lower::AbstractConverter &converter,
llvm::SmallVector<mlir::Value> allocateOperands, allocatorOperands;
mlir::UnitAttr nowaitAttr;
- ClauseProcessor cp(converter, beginClauseList);
+ ClauseProcessor cp(converter, semaCtx, beginClauseList);
cp.processAllocate(allocatorOperands, allocateOperands);
cp.processTODO<Fortran::parser::OmpClause::Copyprivate>(
currentLocation, llvm::omp::Directive::OMPD_single);
- ClauseProcessor(converter, endClauseList).processNowait(nowaitAttr);
+ ClauseProcessor(converter, semaCtx, endClauseList).processNowait(nowaitAttr);
return genOpWithBody<mlir::omp::SingleOp>(
- OpWithBodyGenInfo(converter, currentLocation, eval)
+ OpWithBodyGenInfo(converter, semaCtx, currentLocation, eval)
.setGenNested(genNested)
.setClauses(&beginClauseList),
allocateOperands, allocatorOperands, nowaitAttr);
@@ -2625,6 +2632,7 @@ genSingleOp(Fortran::lower::AbstractConverter &converter,
static mlir::omp::TaskOp
genTaskOp(Fortran::lower::AbstractConverter &converter,
+ Fortran::semantics::SemanticsContext &semaCtx,
Fortran::lower::pft::Evaluation &eval, bool genNested,
mlir::Location currentLocation,
const Fortran::parser::OmpClauseList &clauseList) {
@@ -2635,7 +2643,7 @@ genTaskOp(Fortran::lower::AbstractConverter &converter,
llvm::SmallVector<mlir::Value> allocateOperands, allocatorOperands,
dependOperands;
- ClauseProcessor cp(converter, clauseList);
+ ClauseProcessor cp(converter, semaCtx, clauseList);
cp.processIf(Fortran::parser::OmpIfClause::DirectiveNameModifier::Task,
ifClauseOperand);
cp.processAllocate(allocatorOperands, allocateOperands);
@@ -2651,7 +2659,7 @@ genTaskOp(Fortran::lower::AbstractConverter &converter,
currentLocation, llvm::omp::Directive::OMPD_task);
return genOpWithBody<mlir::omp::TaskOp>(
- OpWithBodyGenInfo(converter, currentLocation, eval)
+ OpWithBodyGenInfo(converter, semaCtx, currentLocation, eval)
.setGenNested(genNested)
.setClauses(&clauseList),
ifClauseOperand, finalClauseOperand, untiedAttr, mergeableAttr,
@@ -2666,16 +2674,17 @@ genTaskOp(Fortran::lower::AbstractConverter &converter,
static mlir::omp::TaskGroupOp
genTaskGroupOp(Fortran::lower::AbstractConverter &converter,
+ Fortran::semantics::SemanticsContext &semaCtx,
Fortran::lower::pft::Evaluation &eval, bool genNested,
mlir::Location currentLocation,
const Fortran::parser::OmpClauseList &clauseList) {
llvm::SmallVector<mlir::Value> allocateOperands, allocatorOperands;
- ClauseProcessor cp(converter, clauseList);
+ ClauseProcessor cp(converter, semaCtx, clauseList);
cp.processAllocate(allocatorOperands, allocateOperands);
cp.processTODO<Fortran::parser::OmpClause::TaskReduction>(
currentLocation, llvm::omp::Directive::OMPD_taskgroup);
return genOpWithBody<mlir::omp::TaskGroupOp>(
- OpWithBodyGenInfo(converter, currentLocation, eval)
+ OpWithBodyGenInfo(converter, semaCtx, currentLocation, eval)
.setGenNested(genNested)
.setClauses(&clauseList),
/*task_reduction_vars=*/mlir::ValueRange(),
@@ -2684,9 +2693,9 @@ genTaskGroupOp(Fortran::lower::AbstractConverter &converter,
static mlir::omp::DataOp
genDataOp(Fortran::lower::AbstractConverter &converter,
- Fortran::lower::pft::Evaluation &eval,
- Fortran::semantics::SemanticsContext &semanticsContext,
- bool genNested, mlir::Location currentLocation,
+ Fortran::semantics::SemanticsContext &semaCtx,
+ Fortran::lower::pft::Evaluation &eval, bool genNested,
+ mlir::Location currentLocation,
const Fortran::parser::OmpClauseList &clauseList) {
Fortran::lower::StatementContext stmtCtx;
mlir::Value ifClauseOperand, deviceOperand;
@@ -2696,7 +2705,7 @@ genDataOp(Fortran::lower::AbstractConverter &converter,
llvm::SmallVector<mlir::Location> useDeviceLocs;
llvm::SmallVector<const Fortran::semantics::Symbol *> useDeviceSymbols;
- ClauseProcessor cp(converter, clauseList);
+ ClauseProcessor cp(converter, semaCtx, clauseList);
cp.processIf(Fortran::parser::OmpIfClause::DirectiveNameModifier::TargetData,
ifClauseOperand);
cp.processDevice(stmtCtx, deviceOperand);
@@ -2705,20 +2714,21 @@ genDataOp(Fortran::lower::AbstractConverter &converter,
cp.processUseDeviceAddr(deviceAddrOperands, useDeviceTypes, useDeviceLocs,
useDeviceSymbols);
cp.processMap(currentLocation, llvm::omp::Directive::OMPD_target_data,
- semanticsContext, stmtCtx, mapOperands);
+ stmtCtx, mapOperands);
auto dataOp = converter.getFirOpBuilder().create<mlir::omp::DataOp>(
currentLocation, ifClauseOperand, deviceOperand, devicePtrOperands,
deviceAddrOperands, mapOperands);
- genBodyOfTargetDataOp(converter, eval, genNested, dataOp, useDeviceTypes,
- useDeviceLocs, useDeviceSymbols, currentLocation);
+ genBodyOfTargetDataOp(converter, semaCtx, eval, genNested, dataOp,
+ useDeviceTypes, useDeviceLocs, useDeviceSymbols,
+ currentLocation);
return dataOp;
}
template <typename OpTy>
static OpTy
genEnterExitUpdateDataOp(Fortran::lower::AbstractConverter &converter,
- Fortran::semantics::SemanticsContext &semanticsContext,
+ Fortran::semantics::SemanticsContext &semaCtx,
mlir::Location currentLocation,
const Fortran::parser::OmpClauseList &clauseList) {
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
@@ -2745,20 +2755,19 @@ genEnterExitUpdateDataOp(Fortran::lower::AbstractConverter &converter,
return nullptr;
}
- ClauseProcessor cp(converter, clauseList);
+ ClauseProcessor cp(converter, semaCtx, clauseList);
cp.processIf(directiveName, ifClauseOperand);
cp.processDevice(stmtCtx, deviceOperand);
cp.processNowait(nowaitAttr);
if constexpr (std::is_same_v<OpTy, mlir::omp::UpdateDataOp>) {
- cp.processMotionClauses<Fortran::parser::OmpClause::To>(
- semanticsContext, stmtCtx, mapOperands);
- cp.processMotionClauses<Fortran::parser::OmpClause::From>(
- semanticsContext, stmtCtx, mapOperands);
+ cp.processMotionClauses<Fortran::parser::OmpClause::To>(stmtCtx,
+ mapOperands);
+ cp.processMotionClauses<Fortran::parser::OmpClause::From>(stmtCtx,
+ mapOperands);
} else {
- cp.processMap(currentLocation, directive, semanticsContext, stmtCtx,
- mapOperands);
+ cp.processMap(currentLocation, directive, stmtCtx, mapOperands);
}
cp.processTODO<Fortran::parser::OmpClause::Depend>(currentLocation,
@@ -2772,6 +2781,7 @@ genEnterExitUpdateDataOp(Fortran::lower::AbstractConverter &converter,
// all the symbols present in mapSymbols as block arguments to this block.
static void genBodyOfTargetOp(
Fortran::lower::AbstractConverter &converter,
+ Fortran::semantics::SemanticsContext &semaCtx,
Fortran::lower::pft::Evaluation &eval, bool genNested,
mlir::omp::TargetOp &targetOp,
const llvm::SmallVector<mlir::Type> &mapSymTypes,
@@ -2923,9 +2933,9 @@ static void genBodyOfTargetOp(
static mlir::omp::TargetOp
genTargetOp(Fortran::lower::AbstractConverter &converter,
- Fortran::lower::pft::Evaluation &eval,
- Fortran::semantics::SemanticsContext &semanticsContext,
- bool genNested, mlir::Location currentLocation,
+ Fortran::semantics::SemanticsContext &semaCtx,
+ Fortran::lower::pft::Evaluation &eval, bool genNested,
+ mlir::Location currentLocation,
const Fortran::parser::OmpClauseList &clauseList,
llvm::omp::Directive directive, bool outerCombined = false) {
Fortran::lower::StatementContext stmtCtx;
@@ -2936,14 +2946,14 @@ genTargetOp(Fortran::lower::AbstractConverter &converter,
llvm::SmallVector<mlir::Location> mapSymLocs;
llvm::SmallVector<const Fortran::semantics::Symbol *> mapSymbols;
- ClauseProcessor cp(converter, clauseList);
+ ClauseProcessor cp(converter, semaCtx, clauseList);
cp.processIf(Fortran::parser::OmpIfClause::DirectiveNameModifier::Target,
ifClauseOperand);
cp.processDevice(stmtCtx, deviceOperand);
cp.processThreadLimit(stmtCtx, threadLimitOperand);
cp.processNowait(nowaitAttr);
- cp.processMap(currentLocation, directive, semanticsContext, stmtCtx,
- mapOperands, &mapSymTypes, &mapSymLocs, &mapSymbols);
+ cp.processMap(currentLocation, directive, stmtCtx, mapOperands, &mapSymTypes,
+ &mapSymLocs, &mapSymbols);
cp.processTODO<Fortran::parser::OmpClause::Private,
Fortran::parser::OmpClause::Depend,
Fortran::parser::OmpClause::Firstprivate,
@@ -3031,7 +3041,7 @@ genTargetOp(Fortran::lower::AbstractConverter &converter,
currentLocation, ifClauseOperand, deviceOperand, threadLimitOperand,
nowaitAttr, mapOperands);
- genBodyOfTargetOp(converter, eval, genNested, targetOp, mapSymTypes,
+ genBodyOfTargetOp(converter, semaCtx, eval, genNested, targetOp, mapSymTypes,
mapSymLocs, mapSymbols, currentLocation);
return targetOp;
@@ -3039,6 +3049,7 @@ genTargetOp(Fortran::lower::AbstractConverter &converter,
...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/81269
More information about the flang-commits
mailing list