Skip to content

Commit 898db11

Browse files
authored
[flang] Support -mvscale-min and mvscale-max on all targets (#74633)
We have other targets with scalable vectors (e.g.RISC-V), and there doesn't seem to be any particular reason these options can't be used on those targets.
1 parent 07056c2 commit 898db11

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

flang/lib/Frontend/FrontendActions.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -710,8 +710,8 @@ void CodeGenAction::lowerHLFIRToFIR() {
710710
// TODO: We should get this from TargetInfo. However, that depends on
711711
// too much of clang, so for now, replicate the functionality.
712712
static std::optional<std::pair<unsigned, unsigned>>
713-
getVScaleRange(CompilerInstance &ci,
714-
const Fortran::frontend::LangOptions &langOpts) {
713+
getVScaleRange(CompilerInstance &ci) {
714+
const auto &langOpts = ci.getInvocation().getLangOpts();
715715
if (langOpts.VScaleMin || langOpts.VScaleMax)
716716
return std::pair<unsigned, unsigned>(
717717
langOpts.VScaleMin ? langOpts.VScaleMin : 1, langOpts.VScaleMax);
@@ -746,13 +746,9 @@ void CodeGenAction::generateLLVMIR() {
746746
const auto targetOpts = ci.getInvocation().getTargetOpts();
747747
const llvm::Triple triple(targetOpts.triple);
748748

749-
// Only get the vscale range if AArch64.
750-
if (triple.isAArch64()) {
751-
auto langOpts = ci.getInvocation().getLangOpts();
752-
if (auto vsr = getVScaleRange(ci, langOpts)) {
753-
config.VScaleMin = vsr->first;
754-
config.VScaleMax = vsr->second;
755-
}
749+
if (auto vsr = getVScaleRange(ci)) {
750+
config.VScaleMin = vsr->first;
751+
config.VScaleMax = vsr->second;
756752
}
757753

758754
// Create the pass pipeline
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
! REQUIRES: riscv-registered-target
2+
! RUN: %flang_fc1 -triple riscv64-none-linux-gnu -target-feature +v -mvscale-min=1 -mvscale-max=1 -emit-llvm -o - %s | FileCheck %s -D#VBITS=1
3+
! RUN: %flang_fc1 -triple riscv64-none-linux-gnu -target-feature +v -mvscale-min=2 -mvscale-max=2 -emit-llvm -o - %s | FileCheck %s -D#VBITS=2
4+
! RUN: %flang_fc1 -triple riscv64-none-linux-gnu -target-feature +v -mvscale-min=4 -mvscale-max=4 -emit-llvm -o - %s | FileCheck %s -D#VBITS=4
5+
! RUN: %flang_fc1 -triple riscv64-none-linux-gnu -target-feature +v -mvscale-min=8 -mvscale-max=8 -emit-llvm -o - %s | FileCheck %s -D#VBITS=8
6+
! RUN: %flang_fc1 -triple riscv64-none-linux-gnu -target-feature +v -mvscale-min=16 -mvscale-max=16 -emit-llvm -o - %s | FileCheck %s -D#VBITS=16
7+
! RUN: %flang_fc1 -triple riscv64-none-linux-gnu -target-feature +v -mvscale-min=1 -emit-llvm -o - %s | FileCheck %s -D#VBITS=1 --check-prefix=CHECK-NOMAX
8+
! RUN: %flang_fc1 -triple riscv64-none-linux-gnu -target-feature +v -mvscale-min=2 -emit-llvm -o - %s | FileCheck %s -D#VBITS=2 --check-prefix=CHECK-NOMAX
9+
! RUN: %flang_fc1 -triple riscv64-none-linux-gnu -target-feature +v -mvscale-min=4 -emit-llvm -o - %s | FileCheck %s -D#VBITS=4 --check-prefix=CHECK-NOMAX
10+
! RUN: %flang_fc1 -triple riscv64-none-linux-gnu -target-feature +v -mvscale-min=8 -emit-llvm -o - %s | FileCheck %s -D#VBITS=8 --check-prefix=CHECK-NOMAX
11+
! RUN: %flang_fc1 -triple riscv64-none-linux-gnu -target-feature +v -mvscale-min=16 -emit-llvm -o - %s | FileCheck %s -D#VBITS=16 --check-prefix=CHECK-NOMAX
12+
! RUN: %flang_fc1 -triple riscv64-none-linux-gnu -target-feature +v -mvscale-min=1 -mvscale-max=0 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-UNBOUNDED
13+
! RUN: %flang_fc1 -triple riscv64-none-linux-gnu -target-feature +v -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-NONE
14+
15+
! CHECK-LABEL: @func_() #0
16+
! CHECK: attributes #0 = {{{.*}} vscale_range([[#VBITS]],[[#VBITS]]) {{.*}}}
17+
! CHECK-NOMAX: attributes #0 = {{{.*}} vscale_range([[#VBITS]],0) {{.*}}}
18+
! CHECK-UNBOUNDED: attributes #0 = {{{.*}} vscale_range(1,0) {{.*}}}
19+
! CHECK-NONE-NOT: vscale_range
20+
subroutine func
21+
end subroutine func

0 commit comments

Comments
 (0)