@@ -599,15 +599,13 @@ static void convertLoopBounds(lower::AbstractConverter &converter,
599
599
}
600
600
}
601
601
602
- // / Populates the sizes vector with values if the given OpenMPConstruct
603
- // / contains a loop construct with an inner tiling construct .
604
- void collectTileSizesFromOpenMPConstruct (
602
+ // Helper function that finds the sizes clause in a inner OMPD_tile directive
603
+ // and passes the sizes clause to the callback function if found .
604
+ static void processTileSizesFromOpenMPConstruct (
605
605
const parser::OpenMPConstruct *ompCons,
606
- llvm::SmallVectorImpl<int64_t > &tileSizes,
607
- Fortran::semantics::SemanticsContext &semaCtx) {
606
+ std::function<void (const parser::OmpClause::Sizes *)> processFun) {
608
607
if (!ompCons)
609
608
return ;
610
-
611
609
if (auto *ompLoop{std::get_if<parser::OpenMPLoopConstruct>(&ompCons->u )}) {
612
610
const auto &nestedOptional =
613
611
std::get<std::optional<parser::NestedConstruct>>(ompLoop->t );
@@ -624,16 +622,13 @@ void collectTileSizesFromOpenMPConstruct(
624
622
std::get<parser::OmpLoopDirective>(innerBegin.t ).v ;
625
623
626
624
if (innerDirective == llvm::omp::Directive::OMPD_tile) {
627
- // Get the size values from parse tree and convert to a vector
625
+ // Get the size values from parse tree and convert to a vector.
628
626
const auto &innerClauseList{
629
627
std::get<parser::OmpClauseList>(innerBegin.t )};
630
628
for (const auto &clause : innerClauseList.v ) {
631
629
if (const auto tclause{
632
630
std::get_if<parser::OmpClause::Sizes>(&clause.u )}) {
633
- for (auto &tval : tclause->v ) {
634
- if (const auto v{EvaluateInt64 (semaCtx, tval)})
635
- tileSizes.push_back (*v);
636
- }
631
+ processFun (tclause);
637
632
break ;
638
633
}
639
634
}
@@ -642,6 +637,20 @@ void collectTileSizesFromOpenMPConstruct(
642
637
}
643
638
}
644
639
640
+ // / Populates the sizes vector with values if the given OpenMPConstruct
641
+ // / contains a loop construct with an inner tiling construct.
642
+ void collectTileSizesFromOpenMPConstruct (
643
+ const parser::OpenMPConstruct *ompCons,
644
+ llvm::SmallVectorImpl<int64_t > &tileSizes,
645
+ Fortran::semantics::SemanticsContext &semaCtx) {
646
+ processTileSizesFromOpenMPConstruct (
647
+ ompCons, [&](const parser::OmpClause::Sizes *tclause) {
648
+ for (auto &tval : tclause->v )
649
+ if (const auto v{EvaluateInt64 (semaCtx, tval)})
650
+ tileSizes.push_back (*v);
651
+ });
652
+ }
653
+
645
654
int64_t collectLoopRelatedInfo (
646
655
lower::AbstractConverter &converter, mlir::Location currentLocation,
647
656
lower::pft::Evaluation &eval, const omp::List<omp::Clause> &clauses,
@@ -663,37 +672,13 @@ int64_t collectLoopRelatedInfo(
663
672
numCollapse = collapseValue;
664
673
}
665
674
666
- // Collect sizes from tile directive if present
675
+ // Collect sizes from tile directive if present.
667
676
std::int64_t sizesLengthValue = 0l ;
668
677
if (auto *ompCons{eval.getIf <parser::OpenMPConstruct>()}) {
669
- if (auto *ompLoop{std::get_if<parser::OpenMPLoopConstruct>(&ompCons->u )}) {
670
- const auto &nestedOptional =
671
- std::get<std::optional<parser::NestedConstruct>>(ompLoop->t );
672
- assert (nestedOptional.has_value () &&
673
- " Expected a DoConstruct or OpenMPLoopConstruct" );
674
- const auto *innerConstruct =
675
- std::get_if<common::Indirection<parser::OpenMPLoopConstruct>>(
676
- &(nestedOptional.value ()));
677
- if (innerConstruct) {
678
- const auto &innerLoopDirective = innerConstruct->value ();
679
- const auto &innerBegin =
680
- std::get<parser::OmpBeginLoopDirective>(innerLoopDirective.t );
681
- const auto &innerDirective =
682
- std::get<parser::OmpLoopDirective>(innerBegin.t ).v ;
683
-
684
- if (innerDirective == llvm::omp::Directive::OMPD_tile) {
685
- // Get the size values from parse tree and convert to a vector
686
- const auto &innerClauseList{
687
- std::get<parser::OmpClauseList>(innerBegin.t )};
688
- for (const auto &clause : innerClauseList.v )
689
- if (const auto tclause{
690
- std::get_if<parser::OmpClause::Sizes>(&clause.u )}) {
691
- sizesLengthValue = tclause->v .size ();
692
- break ;
693
- }
694
- }
695
- }
696
- }
678
+ processTileSizesFromOpenMPConstruct (
679
+ ompCons, [&](const parser::OmpClause::Sizes *tclause) {
680
+ sizesLengthValue = tclause->v .size ();
681
+ });
697
682
}
698
683
699
684
collapseValue = std::max (collapseValue, sizesLengthValue);
0 commit comments