[flang-commits] [flang] [flang] Support -mvscale-min and mvscale-max on all targets (PR #74633)
Philip Reames via flang-commits
flang-commits at lists.llvm.org
Wed Dec 6 09:56:10 PST 2023
https://github.com/preames updated https://github.com/llvm/llvm-project/pull/74633
>From d2dfaf4b956ae80871d7b7963546748828c70635 Mon Sep 17 00:00:00 2001
From: Philip Reames <preames at rivosinc.com>
Date: Wed, 6 Dec 2023 09:36:39 -0800
Subject: [PATCH 1/2] [flang] Support -mvscale-min and mvscale-max on all
targets
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.
---
flang/lib/Frontend/FrontendActions.cpp | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index 1be95cc27f42c..a9eaae6dd1c49 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -824,8 +824,8 @@ void CodeGenAction::lowerHLFIRToFIR() {
// TODO: We should get this from TargetInfo. However, that depends on
// too much of clang, so for now, replicate the functionality.
static std::optional<std::pair<unsigned, unsigned>>
-getVScaleRange(CompilerInstance &ci,
- const Fortran::frontend::LangOptions &langOpts) {
+getVScaleRange(CompilerInstance &ci) {
+ const auto &langOpts = ci.getInvocation().getLangOpts();
if (langOpts.VScaleMin || langOpts.VScaleMax)
return std::pair<unsigned, unsigned>(
langOpts.VScaleMin ? langOpts.VScaleMin : 1, langOpts.VScaleMax);
@@ -860,13 +860,9 @@ void CodeGenAction::generateLLVMIR() {
const auto targetOpts = ci.getInvocation().getTargetOpts();
const llvm::Triple triple(targetOpts.triple);
- // Only get the vscale range if AArch64.
- if (triple.isAArch64()) {
- auto langOpts = ci.getInvocation().getLangOpts();
- if (auto vsr = getVScaleRange(ci, langOpts)) {
- config.VScaleMin = vsr->first;
- config.VScaleMax = vsr->second;
- }
+ if (auto vsr = getVScaleRange(ci)) {
+ config.VScaleMin = vsr->first;
+ config.VScaleMax = vsr->second;
}
// Create the pass pipeline
>From 685bed101379b38bf56ee9e1e9b952a2e99c68a5 Mon Sep 17 00:00:00 2001
From: Philip Reames <preames at rivosinc.com>
Date: Wed, 6 Dec 2023 09:54:15 -0800
Subject: [PATCH 2/2] Add a RISC-V test to exercise -mvscale-min/max
---
.../RISCV/riscv-vector-bits-vscale-range.f90 | 21 +++++++++++++++++++
1 file changed, 21 insertions(+)
create mode 100644 flang/test/Lower/RISCV/riscv-vector-bits-vscale-range.f90
diff --git a/flang/test/Lower/RISCV/riscv-vector-bits-vscale-range.f90 b/flang/test/Lower/RISCV/riscv-vector-bits-vscale-range.f90
new file mode 100644
index 0000000000000..b08ad91feb388
--- /dev/null
+++ b/flang/test/Lower/RISCV/riscv-vector-bits-vscale-range.f90
@@ -0,0 +1,21 @@
+! REQUIRES: riscv-registered-target
+! 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
+! 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
+! 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
+! 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
+! 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
+! 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
+! 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
+! 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
+! 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
+! 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
+! 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
+! RUN: %flang_fc1 -triple riscv64-none-linux-gnu -target-feature +v -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-NONE
+
+! CHECK-LABEL: @func_() #0
+! CHECK: attributes #0 = {{{.*}} vscale_range([[#VBITS]],[[#VBITS]]) {{.*}}}
+! CHECK-NOMAX: attributes #0 = {{{.*}} vscale_range([[#VBITS]],0) {{.*}}}
+! CHECK-UNBOUNDED: attributes #0 = {{{.*}} vscale_range(1,0) {{.*}}}
+! CHECK-NONE-NOT: vscale_range
+subroutine func
+end subroutine func
More information about the flang-commits
mailing list