[clang] 36278b7 - [Flang][RISCV] Emit target features for RISC-V
Shao-Ce SUN via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 15 04:39:23 PDT 2023
Author: Shao-Ce SUN
Date: 2023-03-15T19:39:13+08:00
New Revision: 36278b735fa193c954bf38c82ca81a5608bc5187
URL: https://github.com/llvm/llvm-project/commit/36278b735fa193c954bf38c82ca81a5608bc5187
DIFF: https://github.com/llvm/llvm-project/commit/36278b735fa193c954bf38c82ca81a5608bc5187.diff
LOG: [Flang][RISCV] Emit target features for RISC-V
Fix the issue of .o file generated by `Flang`
with `Flags` info is 0x0 under RISC-V.
Reviewed By: awarzynski, kiranchandramohan
Differential Revision: https://reviews.llvm.org/D145883
Added:
flang/test/Driver/code-gen-rv64.f90
flang/test/Driver/target-cpu-features-invalid.f90
Modified:
clang/lib/Driver/ToolChains/Flang.cpp
flang/test/Driver/target-cpu-features.f90
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index 84d93f56a4419..10a518c34351d 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -105,7 +105,7 @@ void Flang::addTargetOptions(const ArgList &Args,
default:
break;
case llvm::Triple::aarch64:
- [[fallthrough]];
+ case llvm::Triple::riscv64:
case llvm::Triple::x86_64:
getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ false);
break;
diff --git a/flang/test/Driver/code-gen-rv64.f90 b/flang/test/Driver/code-gen-rv64.f90
new file mode 100644
index 0000000000000..69d08b28c94ae
--- /dev/null
+++ b/flang/test/Driver/code-gen-rv64.f90
@@ -0,0 +1,17 @@
+! Test -emit-obj (RISC-V 64)
+
+! REQUIRES: riscv-registered-target
+
+! RUN: rm -f %t.o
+! RUN: %flang_fc1 -triple riscv64-unknown-linux-gnu \
+! RUN: -target-feature +d -target-feature +c -emit-obj %s -o %t.o
+! RUN: llvm-readelf -h %t.o | FileCheck %s
+
+! RUN: rm -f %t.o
+! RUN: %flang --target=riscv64-unknown-linux-gnu -c %s -o %t.o
+! RUN: llvm-readelf -h %t.o | FileCheck %s
+
+! If Flang failed to emit target-feature info, then Flags will be 0x0.
+! 0x5 means set EF_RISCV_RVC (0x1) and EF_RISCV_FLOAT_ABI_DOUBLE (0x4)
+! CHECK: Flags: 0x5, RVC, double-float ABI
+end program
diff --git a/flang/test/Driver/target-cpu-features-invalid.f90 b/flang/test/Driver/target-cpu-features-invalid.f90
new file mode 100644
index 0000000000000..7ecbe597637c6
--- /dev/null
+++ b/flang/test/Driver/target-cpu-features-invalid.f90
@@ -0,0 +1,13 @@
+! REQUIRES: aarch64-registered-target
+
+! Test that invalid cpu and features are ignored.
+
+! RUN: %flang_fc1 -triple aarch64-linux-gnu -target-cpu supercpu \
+! RUN: -o /dev/null -S %s 2>&1 | FileCheck %s -check-prefix=CHECK-INVALID-CPU
+
+! RUN: %flang_fc1 -triple aarch64-linux-gnu -target-feature +superspeed \
+! RUN: -o /dev/null -S %s 2>&1 | FileCheck %s -check-prefix=CHECK-INVALID-FEATURE
+
+
+! CHECK-INVALID-CPU: 'supercpu' is not a recognized processor for this target (ignoring processor)
+! CHECK-INVALID-FEATURE: '+superspeed' is not a recognized feature for this target (ignoring feature)
diff --git a/flang/test/Driver/target-cpu-features.f90 b/flang/test/Driver/target-cpu-features.f90
index 1ce416f0cf533..ca2ed274a6b6e 100644
--- a/flang/test/Driver/target-cpu-features.f90
+++ b/flang/test/Driver/target-cpu-features.f90
@@ -1,5 +1,3 @@
-! REQUIRES: aarch64-registered-target, x86-registered-target
-
! Test that -mcpu/march are used and that the -target-cpu and -target-features
! are also added to the fc1 command.
@@ -22,14 +20,8 @@
! RUN: %flang --target=x86_64h-linux-gnu -c %s -### 2>&1 \
! RUN: | FileCheck %s -check-prefix=CHECK-X86_64H
-
-! Test that invalid cpu and features are ignored.
-
-! RUN: %flang_fc1 -triple aarch64-linux-gnu -target-cpu supercpu \
-! RUN: -o /dev/null -S %s 2>&1 | FileCheck %s -check-prefix=CHECK-INVALID-CPU
-
-! RUN: %flang_fc1 -triple aarch64-linux-gnu -target-feature +superspeed \
-! RUN: -o /dev/null -S %s 2>&1 | FileCheck %s -check-prefix=CHECK-INVALID-FEATURE
+! RUN: %flang --target=riscv64-linux-gnu -c %s -### 2>&1 \
+! RUN: | FileCheck %s -check-prefix=CHECK-RV64
! CHECK-A57: "-fc1" "-triple" "aarch64-unknown-linux-gnu"
@@ -52,5 +44,5 @@
! CHECK-X86_64H: "-fc1" "-triple" "x86_64h-unknown-linux-gnu"
! CHECK-X86_64H-SAME: "-target-cpu" "x86-64" "-target-feature" "-rdrnd" "-target-feature" "-aes" "-target-feature" "-pclmul" "-target-feature" "-rtm" "-target-feature" "-fsgsbase"
-! CHECK-INVALID-CPU: 'supercpu' is not a recognized processor for this target (ignoring processor)
-! CHECK-INVALID-FEATURE: '+superspeed' is not a recognized feature for this target (ignoring feature)
+! CHECK-RV64: "-fc1" "-triple" "riscv64-unknown-linux-gnu"
+! CHECK-RV64-SAME: "-target-cpu" "generic-rv64" "-target-feature" "+m" "-target-feature" "+a" "-target-feature" "+f" "-target-feature" "+d" "-target-feature" "+c"
More information about the cfe-commits
mailing list