mirror of
https://github.com/intel/llvm.git
synced 2026-01-16 13:35:38 +08:00
[flang][OpenMP] Add MLIR lowering for loop ... bind (#114219)
Extends MLIR lowering support for the `loop` directive by adding lowering support for the `bind` clause. Parent PR: https://github.com/llvm/llvm-project/pull/114199, only the latest commit is relevant to this PR.
This commit is contained in:
@@ -98,6 +98,25 @@ genAllocateClause(lower::AbstractConverter &converter,
|
||||
genObjectList(objects, converter, allocateOperands);
|
||||
}
|
||||
|
||||
static mlir::omp::ClauseBindKindAttr
|
||||
genBindKindAttr(fir::FirOpBuilder &firOpBuilder,
|
||||
const omp::clause::Bind &clause) {
|
||||
mlir::omp::ClauseBindKind bindKind;
|
||||
switch (clause.v) {
|
||||
case omp::clause::Bind::Binding::Teams:
|
||||
bindKind = mlir::omp::ClauseBindKind::Teams;
|
||||
break;
|
||||
case omp::clause::Bind::Binding::Parallel:
|
||||
bindKind = mlir::omp::ClauseBindKind::Parallel;
|
||||
break;
|
||||
case omp::clause::Bind::Binding::Thread:
|
||||
bindKind = mlir::omp::ClauseBindKind::Thread;
|
||||
break;
|
||||
}
|
||||
return mlir::omp::ClauseBindKindAttr::get(firOpBuilder.getContext(),
|
||||
bindKind);
|
||||
}
|
||||
|
||||
static mlir::omp::ClauseProcBindKindAttr
|
||||
genProcBindKindAttr(fir::FirOpBuilder &firOpBuilder,
|
||||
const omp::clause::ProcBind &clause) {
|
||||
@@ -204,6 +223,15 @@ static void convertLoopBounds(lower::AbstractConverter &converter,
|
||||
// ClauseProcessor unique clauses
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
bool ClauseProcessor::processBind(mlir::omp::BindClauseOps &result) const {
|
||||
if (auto *clause = findUniqueClause<omp::clause::Bind>()) {
|
||||
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
|
||||
result.bindKind = genBindKindAttr(firOpBuilder, *clause);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ClauseProcessor::processCollapse(
|
||||
mlir::Location currentLocation, lower::pft::Evaluation &eval,
|
||||
mlir::omp::LoopRelatedClauseOps &result,
|
||||
|
||||
@@ -53,6 +53,7 @@ public:
|
||||
: converter(converter), semaCtx(semaCtx), clauses(clauses) {}
|
||||
|
||||
// 'Unique' clauses: They can appear at most once in the clause list.
|
||||
bool processBind(mlir::omp::BindClauseOps &result) const;
|
||||
bool
|
||||
processCollapse(mlir::Location currentLocation, lower::pft::Evaluation &eval,
|
||||
mlir::omp::LoopRelatedClauseOps &result,
|
||||
|
||||
@@ -489,8 +489,19 @@ AtomicDefaultMemOrder make(const parser::OmpClause::AtomicDefaultMemOrder &inp,
|
||||
|
||||
Bind make(const parser::OmpClause::Bind &inp,
|
||||
semantics::SemanticsContext &semaCtx) {
|
||||
// inp -> empty
|
||||
llvm_unreachable("Empty: bind");
|
||||
// inp.v -> parser::OmpBindClause
|
||||
using wrapped = parser::OmpBindClause;
|
||||
|
||||
CLAUSET_ENUM_CONVERT( //
|
||||
convert, wrapped::Type, Bind::Binding,
|
||||
// clang-format off
|
||||
MS(Teams, Teams)
|
||||
MS(Parallel, Parallel)
|
||||
MS(Thread, Thread)
|
||||
// clang-format on
|
||||
);
|
||||
|
||||
return Bind{/*Binding=*/convert(inp.v.v)};
|
||||
}
|
||||
|
||||
// CancellationConstructType: empty
|
||||
|
||||
@@ -1182,10 +1182,10 @@ static void genLoopClauses(
|
||||
mlir::omp::LoopOperands &clauseOps,
|
||||
llvm::SmallVectorImpl<const semantics::Symbol *> &reductionSyms) {
|
||||
ClauseProcessor cp(converter, semaCtx, clauses);
|
||||
cp.processBind(clauseOps);
|
||||
cp.processOrder(clauseOps);
|
||||
cp.processReduction(loc, clauseOps, reductionSyms);
|
||||
cp.processTODO<clause::Bind, clause::Lastprivate>(
|
||||
loc, llvm::omp::Directive::OMPD_loop);
|
||||
cp.processTODO<clause::Lastprivate>(loc, llvm::omp::Directive::OMPD_loop);
|
||||
}
|
||||
|
||||
static void genMaskedClauses(lower::AbstractConverter &converter,
|
||||
|
||||
@@ -88,3 +88,15 @@ subroutine test_reduction()
|
||||
end do
|
||||
!$omp end loop
|
||||
end subroutine
|
||||
|
||||
! CHECK-LABEL: func.func @_QPtest_bind
|
||||
subroutine test_bind()
|
||||
integer :: i, dummy = 1
|
||||
! CHECK: omp.loop bind(thread) private(@{{.*}} %{{.*}}#0 -> %{{.*}} : {{.*}}) {
|
||||
! CHECK: }
|
||||
!$omp loop bind(thread)
|
||||
do i=1,10
|
||||
dummy = dummy + 1
|
||||
end do
|
||||
!$omp end loop
|
||||
end subroutine
|
||||
|
||||
Reference in New Issue
Block a user