@@ -2584,19 +2584,25 @@ class FirConverter : public Fortran::lower::AbstractConverter {
25842584
25852585 // Enabling loop vectorization attribute.
25862586 mlir::LLVM::LoopVectorizeAttr
2587- genLoopVectorizeAttr (mlir::BoolAttr disableAttr) {
2587+ genLoopVectorizeAttr (mlir::BoolAttr disableAttr,
2588+ mlir::BoolAttr scalableEnable,
2589+ mlir::IntegerAttr vectorWidth) {
25882590 mlir::LLVM::LoopVectorizeAttr va;
25892591 if (disableAttr)
2590- va = mlir::LLVM::LoopVectorizeAttr::get (builder->getContext (),
2591- /* disable=*/ disableAttr, {}, {},
2592- {}, {}, {}, {});
2592+ va = mlir::LLVM::LoopVectorizeAttr::get (
2593+ builder->getContext (),
2594+ /* disable=*/ disableAttr, /* predicate=*/ {},
2595+ /* scalableEnable=*/ scalableEnable,
2596+ /* vectorWidth=*/ vectorWidth, {}, {}, {});
25932597 return va;
25942598 }
25952599
25962600 void addLoopAnnotationAttr (
25972601 IncrementLoopInfo &info,
25982602 llvm::SmallVectorImpl<const Fortran::parser::CompilerDirective *> &dirs) {
25992603 mlir::BoolAttr disableVecAttr;
2604+ mlir::BoolAttr scalableEnable;
2605+ mlir::IntegerAttr vectorWidth;
26002606 mlir::LLVM::LoopUnrollAttr ua;
26012607 mlir::LLVM::LoopUnrollAndJamAttr uja;
26022608 llvm::SmallVector<mlir::LLVM::AccessGroupAttr> aga;
@@ -2609,6 +2615,30 @@ class FirConverter : public Fortran::lower::AbstractConverter {
26092615 mlir::BoolAttr::get (builder->getContext (), false );
26102616 has_attrs = true ;
26112617 },
2618+ [&](const Fortran::parser::CompilerDirective::VectorLength &vl) {
2619+ using Kind =
2620+ Fortran::parser::CompilerDirective::VectorLength::Kind;
2621+ Kind kind = std::get<Kind>(vl.t );
2622+ uint64_t length = std::get<uint64_t >(vl.t );
2623+ disableVecAttr =
2624+ mlir::BoolAttr::get (builder->getContext (), false );
2625+ if (length != 0 )
2626+ vectorWidth =
2627+ builder->getIntegerAttr (builder->getI64Type (), length);
2628+ switch (kind) {
2629+ case Kind::Scalable:
2630+ scalableEnable =
2631+ mlir::BoolAttr::get (builder->getContext (), true );
2632+ break ;
2633+ case Kind::Fixed:
2634+ scalableEnable =
2635+ mlir::BoolAttr::get (builder->getContext (), false );
2636+ break ;
2637+ case Kind::Auto:
2638+ break ;
2639+ }
2640+ has_attrs = true ;
2641+ },
26122642 [&](const Fortran::parser::CompilerDirective::Unroll &u) {
26132643 ua = genLoopUnrollAttr (u.v );
26142644 has_attrs = true ;
@@ -2640,7 +2670,8 @@ class FirConverter : public Fortran::lower::AbstractConverter {
26402670 [&](const auto &) {}},
26412671 dir->u );
26422672 }
2643- mlir::LLVM::LoopVectorizeAttr va = genLoopVectorizeAttr (disableVecAttr);
2673+ mlir::LLVM::LoopVectorizeAttr va =
2674+ genLoopVectorizeAttr (disableVecAttr, scalableEnable, vectorWidth);
26442675 mlir::LLVM::LoopAnnotationAttr la = mlir::LLVM::LoopAnnotationAttr::get (
26452676 builder->getContext (), {}, /* vectorize=*/ va, {}, /* unroll*/ ua,
26462677 /* unroll_and_jam*/ uja, {}, {}, {}, {}, {}, {}, {}, {}, {},
@@ -3347,6 +3378,9 @@ class FirConverter : public Fortran::lower::AbstractConverter {
33473378 [&](const Fortran::parser::CompilerDirective::VectorAlways &) {
33483379 attachDirectiveToLoop (dir, &eval);
33493380 },
3381+ [&](const Fortran::parser::CompilerDirective::VectorLength &) {
3382+ attachDirectiveToLoop (dir, &eval);
3383+ },
33503384 [&](const Fortran::parser::CompilerDirective::Unroll &) {
33513385 attachDirectiveToLoop (dir, &eval);
33523386 },
0 commit comments