@@ -599,15 +599,13 @@ static void convertLoopBounds(lower::AbstractConverter &converter,
599599 }
600600}
601601
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 (
605605 const parser::OpenMPConstruct *ompCons,
606- llvm::SmallVectorImpl<int64_t > &tileSizes,
607- Fortran::semantics::SemanticsContext &semaCtx) {
606+ std::function<void (const parser::OmpClause::Sizes *)> processFun) {
608607 if (!ompCons)
609608 return ;
610-
611609 if (auto *ompLoop{std::get_if<parser::OpenMPLoopConstruct>(&ompCons->u )}) {
612610 const auto &nestedOptional =
613611 std::get<std::optional<parser::NestedConstruct>>(ompLoop->t );
@@ -624,16 +622,13 @@ void collectTileSizesFromOpenMPConstruct(
624622 std::get<parser::OmpLoopDirective>(innerBegin.t ).v ;
625623
626624 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.
628626 const auto &innerClauseList{
629627 std::get<parser::OmpClauseList>(innerBegin.t )};
630628 for (const auto &clause : innerClauseList.v ) {
631629 if (const auto tclause{
632630 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);
637632 break ;
638633 }
639634 }
@@ -642,6 +637,20 @@ void collectTileSizesFromOpenMPConstruct(
642637 }
643638}
644639
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+
645654int64_t collectLoopRelatedInfo (
646655 lower::AbstractConverter &converter, mlir::Location currentLocation,
647656 lower::pft::Evaluation &eval, const omp::List<omp::Clause> &clauses,
@@ -663,37 +672,13 @@ int64_t collectLoopRelatedInfo(
663672 numCollapse = collapseValue;
664673 }
665674
666- // Collect sizes from tile directive if present
675+ // Collect sizes from tile directive if present.
667676 std::int64_t sizesLengthValue = 0l ;
668677 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+ });
697682 }
698683
699684 collapseValue = std::max (collapseValue, sizesLengthValue);
0 commit comments