diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h --- a/clang/lib/Basic/Targets/RISCV.h +++ b/clang/lib/Basic/Targets/RISCV.h @@ -31,11 +31,12 @@ bool HasD; bool HasC; bool HasB; + bool HasZfh; public: RISCVTargetInfo(const llvm::Triple &Triple, const TargetOptions &) - : TargetInfo(Triple), HasM(false), HasA(false), HasF(false), - HasD(false), HasC(false), HasB(false) { + : TargetInfo(Triple), HasM(false), HasA(false), HasF(false), HasD(false), + HasC(false), HasB(false), HasZfh(false) { LongDoubleWidth = 128; LongDoubleAlign = 128; LongDoubleFormat = &llvm::APFloat::IEEEquad(); diff --git a/clang/lib/Basic/Targets/RISCV.cpp b/clang/lib/Basic/Targets/RISCV.cpp --- a/clang/lib/Basic/Targets/RISCV.cpp +++ b/clang/lib/Basic/Targets/RISCV.cpp @@ -129,6 +129,9 @@ if (HasB) Builder.defineMacro("__riscv_bitmanip"); + + if (HasZfh) + Builder.defineMacro("__riscv_zfh"); } /// Return true if has this feature, need to sync with handleTargetFeatures. @@ -144,6 +147,7 @@ .Case("d", HasD) .Case("c", HasC) .Case("experimental-b", HasB) + .Case("experimental-zfh", HasZfh) .Default(false); } @@ -163,6 +167,8 @@ HasC = true; else if (Feature == "+experimental-b") HasB = true; + else if (Feature == "+experimental-zfh") + HasZfh = true; } return true; diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp --- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp +++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp @@ -64,6 +64,8 @@ return RISCVExtensionVersion{"0", "92"}; if (Ext == "v") return RISCVExtensionVersion{"0", "9"}; + if (Ext == "zfh") + return RISCVExtensionVersion{"0", "1"}; return None; } diff --git a/clang/test/Driver/riscv-arch.c b/clang/test/Driver/riscv-arch.c --- a/clang/test/Driver/riscv-arch.c +++ b/clang/test/Driver/riscv-arch.c @@ -383,3 +383,12 @@ // RUN: %clang -target riscv32-unknown-elf -march=rv32iv0p9 -menable-experimental-extensions -### %s -c 2>&1 | \ // RUN: FileCheck -check-prefix=RV32-EXPERIMENTAL-V-GOODVERS %s // RV32-EXPERIMENTAL-V-GOODVERS: "-target-feature" "+experimental-v" + +// RUN: %clang -target riscv32-unknown-elf -march=rv32izfh -### %s \ +// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-ZFH-NOFLAG %s +// RV32-EXPERIMENTAL-ZFH-NOFLAG: error: invalid arch name 'rv32izfh' +// RV32-EXPERIMENTAL-ZFH-NOFLAG: requires '-menable-experimental-extensions' + +// RUN: %clang -target riscv32-unknown-elf -march=rv32izfh0p1 -menable-experimental-extensions -### %s \ +// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-ZFH %s +// RV32-EXPERIMENTAL-ZFH: "-target-feature" "+experimental-zfh" diff --git a/clang/test/Preprocessor/riscv-target-features.c b/clang/test/Preprocessor/riscv-target-features.c --- a/clang/test/Preprocessor/riscv-target-features.c +++ b/clang/test/Preprocessor/riscv-target-features.c @@ -78,3 +78,9 @@ // CHECK-DOUBLE: __riscv_float_abi_double 1 // CHECK-DOUBLE-NOT: __riscv_float_abi_soft // CHECK-DOUBLE-NOT: __riscv_float_abi_single + +// RUN: %clang -target riscv32-unknown-linux-gnu -menable-experimental-extensions -march=rv32izfh0p1 -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZFH-EXT %s +// RUN: %clang -target riscv64-unknown-linux-gnu -menable-experimental-extensions -march=rv64izfh0p1 -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZFH-EXT %s +// CHECK-ZFH-EXT: __riscv_zfh 1