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 @@ -417,6 +417,82 @@ // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-ZBA %s // RV32-EXPERIMENTAL-ZBA: "-target-feature" "+experimental-zba" +// RUN: %clang -target riscv32-unknown-elf -march=rv32ip -### %s -c 2>&1 | \ +// RUN: FileCheck -check-prefix=RV32-EXPERIMENTAL-P-NOFLAG %s +// RV32-EXPERIMENTAL-P-NOFLAG: error: invalid arch name 'rv32ip' +// RV32-EXPERIMENTAL-P-NOFLAG: requires '-menable-experimental-extensions' + +// RUN: %clang -target riscv32-unknown-elf -march=rv32ip -menable-experimental-extensions -### %s -c 2>&1 | \ +// RUN: FileCheck -check-prefix=RV32-EXPERIMENTAL-P-NOVERS %s +// RV32-EXPERIMENTAL-P-NOVERS: error: invalid arch name 'rv32ip' +// RV32-EXPERIMENTAL-P-NOVERS: experimental extension requires explicit version number + +// RUN: %clang -target riscv32-unknown-elf -march=rv32ip0p1 -menable-experimental-extensions -### %s -c 2>&1 | \ +// RUN: FileCheck -check-prefix=RV32-EXPERIMENTAL-P-BADVERS %s +// RV32-EXPERIMENTAL-P-BADVERS: error: invalid arch name 'rv32ip0p1' +// RV32-EXPERIMENTAL-P-BADVERS: unsupported version number 0.1 for experimental extension + +// RUN: %clang -target riscv32-unknown-elf -march=rv32ip0p93 -menable-experimental-extensions -### %s -c 2>&1 | \ +// RUN: FileCheck -check-prefix=RV32-EXPERIMENTAL-P-GOODVERS %s +// RV32-EXPERIMENTAL-P-GOODVERS: "-target-feature" "+experimental-p" + +// RUN: %clang -target riscv32-unknown-elf -march=rv32izpn -### %s -c 2>&1 | \ +// RUN: FileCheck -check-prefix=RV32-EXPERIMENTAL-ZPN-NOFLAG %s +// RV32-EXPERIMENTAL-ZPN-NOFLAG: error: invalid arch name 'rv32izpn' +// RV32-EXPERIMENTAL-ZPN-NOFLAG: requires '-menable-experimental-extensions' + +// RUN: %clang -target riscv32-unknown-elf -march=rv32izpn -menable-experimental-extensions -### %s -c 2>&1 | \ +// RUN: FileCheck -check-prefix=RV32-EXPERIMENTAL-ZPN-NOVERS %s +// RV32-EXPERIMENTAL-ZPN-NOVERS: error: invalid arch name 'rv32izpn' +// RV32-EXPERIMENTAL-ZPN-NOVERS: experimental extension requires explicit version number + +// RUN: %clang -target riscv32-unknown-elf -march=rv32izpn0p1 -menable-experimental-extensions -### %s -c 2>&1 | \ +// RUN: FileCheck -check-prefix=RV32-EXPERIMENTAL-ZPN-BADVERS %s +// RV32-EXPERIMENTAL-ZPN-BADVERS: error: invalid arch name 'rv32izpn0p1' +// RV32-EXPERIMENTAL-ZPN-BADVERS: unsupported version number 0.1 for experimental extension + +// RUN: %clang -target riscv32-unknown-elf -march=rv32izpn0p93 -menable-experimental-extensions -### %s -c 2>&1 | \ +// RUN: FileCheck -check-prefix=RV32-EXPERIMENTAL-ZPN-GOODVERS %s +// RV32-EXPERIMENTAL-ZPN-GOODVERS: "-target-feature" "+experimental-zpn" + +// RUN: %clang -target riscv32-unknown-elf -march=rv32izpsfoperand -### %s -c 2>&1 | \ +// RUN: FileCheck -check-prefix=RV32-EXPERIMENTAL-ZPSFOPERAND-NOFLAG %s +// RV32-EXPERIMENTAL-ZPSFOPERAND-NOFLAG: error: invalid arch name 'rv32izpsfoperand' +// RV32-EXPERIMENTAL-ZPSFOPERAND-NOFLAG: requires '-menable-experimental-extensions' + +// RUN: %clang -target riscv32-unknown-elf -march=rv32izpsfoperand -menable-experimental-extensions -### %s -c 2>&1 | \ +// RUN: FileCheck -check-prefix=RV32-EXPERIMENTAL-ZPSFOPERAND-NOVERS %s +// RV32-EXPERIMENTAL-ZPSFOPERAND-NOVERS: error: invalid arch name 'rv32izpsfoperand' +// RV32-EXPERIMENTAL-ZPSFOPERAND-NOVERS: experimental extension requires explicit version number + +// RUN: %clang -target riscv32-unknown-elf -march=rv32izpsfoperand0p1 -menable-experimental-extensions -### %s -c 2>&1 | \ +// RUN: FileCheck -check-prefix=RV32-EXPERIMENTAL-ZPSFOPERAND-BADVERS %s +// RV32-EXPERIMENTAL-ZPSFOPERAND-BADVERS: error: invalid arch name 'rv32izpsfoperand0p1' +// RV32-EXPERIMENTAL-ZPSFOPERAND-BADVERS: unsupported version number 0.1 for experimental extension + +// RUN: %clang -target riscv32-unknown-elf -march=rv32izpsfoperand0p93 -menable-experimental-extensions -### %s -c 2>&1 | \ +// RUN: FileCheck -check-prefix=RV32-EXPERIMENTAL-ZPSFOPERAND-GOODVERS %s +// RV32-EXPERIMENTAL-ZPSFOPERAND-GOODVERS: "-target-feature" "+experimental-zpsfoperand" + +// RUN: %clang -target riscv64-unknown-elf -march=rv64izprvsfextra -### %s -c 2>&1 | \ +// RUN: FileCheck -check-prefix=RV64-EXPERIMENTAL-ZPRVSFEXTRA-NOFLAG %s +// RV64-EXPERIMENTAL-ZPRVSFEXTRA-NOFLAG: error: invalid arch name 'rv64izprvsfextra' +// RV64-EXPERIMENTAL-ZPRVSFEXTRA-NOFLAG: requires '-menable-experimental-extensions' + +// RUN: %clang -target riscv64-unknown-elf -march=rv64izprvsfextra -menable-experimental-extensions -### %s -c 2>&1 | \ +// RUN: FileCheck -check-prefix=RV64-EXPERIMENTAL-ZPRVSFEXTRA-NOVERS %s +// RV64-EXPERIMENTAL-ZPRVSFEXTRA-NOVERS: error: invalid arch name 'rv64izprvsfextra' +// RV64-EXPERIMENTAL-ZPRVSFEXTRA-NOVERS: experimental extension requires explicit version number + +// RUN: %clang -target riscv64-unknown-elf -march=rv64izprvsfextra0p1 -menable-experimental-extensions -### %s -c 2>&1 | \ +// RUN: FileCheck -check-prefix=RV64-EXPERIMENTAL-ZPRVSFEXTRA-BADVERS %s +// RV64-EXPERIMENTAL-ZPRVSFEXTRA-BADVERS: error: invalid arch name 'rv64izprvsfextra0p1' +// RV64-EXPERIMENTAL-ZPRVSFEXTRA-BADVERS: unsupported version number 0.1 for experimental extension + +// RUN: %clang -target riscv64-unknown-elf -march=rv64izprvsfextra0p93 -menable-experimental-extensions -### %s -c 2>&1 | \ +// RUN: FileCheck -check-prefix=RV64-EXPERIMENTAL-ZPRVSFEXTRA-GOODVERS %s +// RV64-EXPERIMENTAL-ZPRVSFEXTRA-GOODVERS: "-target-feature" "+experimental-zprvsfextra" + // RUN: %clang -target riscv32-unknown-elf -march=rv32iv -### %s -c 2>&1 | \ // RUN: FileCheck -check-prefix=RV32-EXPERIMENTAL-V-NOFLAG %s // RV32-EXPERIMENTAL-V-NOFLAG: error: invalid arch name 'rv32iv' 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 @@ -218,6 +218,46 @@ // CHECK-ZBT-NOT: __riscv_b // CHECK-ZBT-EXT: __riscv_zbt 93000 +// RUN: %clang -target riscv32-unknown-linux-gnu -menable-experimental-extensions \ +// RUN: -march=rv32ip0p93 -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-32P-EXT %s +// CHECK-32P-EXT: __riscv_p 93000 +// CHECK-32P-EXT: __riscv_zpn 93000 +// CHECK-32P-EXT: __riscv_zpsfoperand 93000 +// CHECK-32P-NOT: __riscv_zprvsfextra + +// RUN: %clang -target riscv64-unknown-linux-gnu -menable-experimental-extensions \ +// RUN: -march=rv64ip0p93 -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-64P-EXT %s +// CHECK-64P-EXT: __riscv_p 93000 +// CHECK-64P-EXT: __riscv_zpn 93000 +// CHECK-64P-EXT: __riscv_zprvsfextra 93000 +// CHECK-64P-EXT: __riscv_zpsfoperand 93000 + +// RUN: %clang -target riscv32-unknown-linux-gnu -menable-experimental-extensions \ +// RUN: -march=rv32izpn0p93 -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZPN-EXT %s +// RUN: %clang -target riscv64-unknown-linux-gnu -menable-experimental-extensions \ +// RUN: -march=rv64izpn0p93 -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZPN-EXT %s +// CHECK-ZPN-NOT: __riscv_p +// CHECK-ZPN-EXT: __riscv_zpn 93000 + +// RUN: %clang -target riscv32-unknown-linux-gnu -menable-experimental-extensions \ +// RUN: -march=rv32izpsfoperand0p93 -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZPSFOPERAND-EXT %s +// RUN: %clang -target riscv64-unknown-linux-gnu -menable-experimental-extensions \ +// RUN: -march=rv64izpsfoperand0p93 -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZPSFOPERAND-EXT %s +// CHECK-ZPSFOPERAND-NOT: __riscv_p +// CHECK-ZPSFOPERAND-EXT: __riscv_zpsfoperand 93000 + +// RUN: %clang -target riscv64-unknown-linux-gnu -menable-experimental-extensions \ +// RUN: -march=rv64izprvsfextra0p93 -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZPRVSFEXTRA-EXT %s +// CHECK-ZPRVSFEXTRA-NOT: __riscv_p +// CHECK-ZPRVSFEXTRA-EXT: __riscv_zprvsfextra 93000 + // RUN: %clang -target riscv32-unknown-linux-gnu -menable-experimental-extensions \ // RUN: -march=rv32iv0p10 -x c -E -dM %s \ // RUN: -o - | FileCheck --check-prefix=CHECK-V-EXT %s diff --git a/llvm/lib/Support/RISCVISAInfo.cpp b/llvm/lib/Support/RISCVISAInfo.cpp --- a/llvm/lib/Support/RISCVISAInfo.cpp +++ b/llvm/lib/Support/RISCVISAInfo.cpp @@ -50,6 +50,7 @@ static const RISCVSupportedExtension SupportedExperimentalExtensions[] = { {"b", RISCVExtensionVersion{0, 93}}, + {"p", RISCVExtensionVersion{0, 93}}, {"v", RISCVExtensionVersion{0, 10}}, {"zba", RISCVExtensionVersion{0, 93}}, {"zbb", RISCVExtensionVersion{0, 93}}, @@ -63,6 +64,10 @@ {"zbt", RISCVExtensionVersion{0, 93}}, {"zbproposedc", RISCVExtensionVersion{0, 93}}, + {"zpn", RISCVExtensionVersion{0, 93}}, + {"zpsfoperand", RISCVExtensionVersion{0, 93}}, + {"zprvsfextra", RISCVExtensionVersion{0, 93}}, + {"zvamo", RISCVExtensionVersion{0, 10}}, {"zvlsseg", RISCVExtensionVersion{0, 10}}, @@ -411,6 +416,10 @@ continue; if (Add) { + // RV32 + zprvsfextra is a invalid combination. + if (ExtName == "zprvsfextra" && XLen != 64) + continue; + ISAInfo->addExtension(ExtName, ExtensionInfoIterator->Version.Major, ExtensionInfoIterator->Version.Minor); if (ExtName == "e") { @@ -600,6 +609,13 @@ ISAInfo->addExtension("zbs", Major, Minor); ISAInfo->addExtension("zbt", Major, Minor); break; + case 'p': + ISAInfo->addExtension("p", Major, Minor); + ISAInfo->addExtension("zpn", Major, Minor); + ISAInfo->addExtension("zpsfoperand", Major, Minor); + if (HasRV64) + ISAInfo->addExtension("zprvsfextra", Major, Minor); + break; case 'v': ISAInfo->addExtension("v", Major, Minor); ISAInfo->addExtension("zvlsseg", Major, Minor); @@ -701,6 +717,12 @@ return createStringError(errc::invalid_argument, "unsupported %s '%s'", Desc.str().c_str(), Ext.str().c_str()); } + + // RV32 + zprvsfextra is a invalid combination. + if (Ext == "zprvsfextra" && !HasRV64) + return createStringError( + errc::invalid_argument, + "standard user-level extension 'zprvsfextra' requires 'rv64'"); } ISAInfo->updateFLen(); diff --git a/llvm/test/CodeGen/RISCV/attributes.ll b/llvm/test/CodeGen/RISCV/attributes.ll --- a/llvm/test/CodeGen/RISCV/attributes.ll +++ b/llvm/test/CodeGen/RISCV/attributes.ll @@ -20,6 +20,9 @@ ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbs %s -o - | FileCheck --check-prefix=RV32ZBS %s ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbt %s -o - | FileCheck --check-prefix=RV32ZBT %s ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbb,+experimental-zfh,+experimental-zvamo,+experimental-v,+f,+experimental-zvlsseg %s -o - | FileCheck --check-prefix=RV32COMBINED %s +; RUN: llc -mtriple=riscv32 -mattr=+experimental-p %s -o - | FileCheck --check-prefix=RV32P %s +; RUN: llc -mtriple=riscv32 -mattr=+experimental-zpn %s -o - | FileCheck --check-prefix=RV32ZPN %s +; RUN: llc -mtriple=riscv32 -mattr=+experimental-zpsfoperand %s -o - | FileCheck --check-prefix=RV32ZPSFOPERAND %s ; RUN: llc -mtriple=riscv64 -mattr=+m %s -o - | FileCheck --check-prefix=RV64M %s ; RUN: llc -mtriple=riscv64 -mattr=+a %s -o - | FileCheck --check-prefix=RV64A %s ; RUN: llc -mtriple=riscv64 -mattr=+f %s -o - | FileCheck --check-prefix=RV64F %s @@ -40,6 +43,10 @@ ; RUN: llc -mtriple=riscv64 -mattr=+experimental-zbs %s -o - | FileCheck --check-prefix=RV64ZBS %s ; RUN: llc -mtriple=riscv64 -mattr=+experimental-zbt %s -o - | FileCheck --check-prefix=RV64ZBT %s ; RUN: llc -mtriple=riscv64 -mattr=+experimental-zbb,+experimental-zfh,+experimental-zvamo,+experimental-v,+f,+experimental-zvlsseg %s -o - | FileCheck --check-prefix=RV64COMBINED %s +; RUN: llc -mtriple=riscv64 -mattr=+experimental-p %s -o - | FileCheck --check-prefix=RV64P %s +; RUN: llc -mtriple=riscv64 -mattr=+experimental-zpn %s -o - | FileCheck --check-prefix=RV64ZPN %s +; RUN: llc -mtriple=riscv64 -mattr=+experimental-zpsfoperand %s -o - | FileCheck --check-prefix=RV64ZPSFOPERAND %s +; RUN: llc -mtriple=riscv64 -mattr=+experimental-zprvsfextra %s -o - | FileCheck --check-prefix=RV64ZPRVSFEXTRA %s ; RV32M: .attribute 5, "rv32i2p0_m2p0" ; RV32A: .attribute 5, "rv32i2p0_a2p0" @@ -61,6 +68,9 @@ ; RV32ZBS: .attribute 5, "rv32i2p0_zbs0p93" ; RV32ZBT: .attribute 5, "rv32i2p0_zbt0p93" ; RV32COMBINED: .attribute 5, "rv32i2p0_f2p0_v0p10_zfh0p1_zbb0p93_zvamo0p10_zvlsseg0p10" +; RV32P: .attribute 5, "rv32i2p0_p0p93_zpn0p93_zpsfoperand0p93" +; RV32ZPN: .attribute 5, "rv32i2p0_zpn0p93" +; RV32ZPSFOPERAND: .attribute 5, "rv32i2p0_zpsfoperand0p93" ; RV64M: .attribute 5, "rv64i2p0_m2p0" ; RV64A: .attribute 5, "rv64i2p0_a2p0" @@ -82,6 +92,10 @@ ; RV64ZBT: .attribute 5, "rv64i2p0_zbt0p93" ; RV64V: .attribute 5, "rv64i2p0_v0p10_zvamo0p10_zvlsseg0p10" ; RV64COMBINED: .attribute 5, "rv64i2p0_f2p0_v0p10_zfh0p1_zbb0p93_zvamo0p10_zvlsseg0p10" +; RV64P: .attribute 5, "rv64i2p0_p0p93_zpn0p93_zprvsfextra0p93_zpsfoperand0p93" +; RV64ZPN: .attribute 5, "rv64i2p0_zpn0p93" +; RV64ZPSFOPERAND: .attribute 5, "rv64i2p0_zpsfoperand0p93" +; RV64ZPRVSFEXTRA: .attribute 5, "rv64i2p0_zprvsfextra0p93" define i32 @addi(i32 %a) { diff --git a/llvm/test/MC/RISCV/attribute-arch-invalid.s b/llvm/test/MC/RISCV/attribute-arch-invalid.s new file mode 100644 --- /dev/null +++ b/llvm/test/MC/RISCV/attribute-arch-invalid.s @@ -0,0 +1,3 @@ +# RUN: not llvm-mc %s -triple=riscv32 -filetype=asm 2>&1 | FileCheck %s + +.attribute arch, "rv32izprvsfextra" # CHECK: :[[@LINE]]:18: error: invalid arch name 'rv32izprvsfextra', standard user-level extension 'zprvsfextra' requires 'rv64' diff --git a/llvm/test/MC/RISCV/attribute-arch.s b/llvm/test/MC/RISCV/attribute-arch.s --- a/llvm/test/MC/RISCV/attribute-arch.s +++ b/llvm/test/MC/RISCV/attribute-arch.s @@ -36,6 +36,12 @@ .attribute arch, "rv32ib" # CHECK: attribute 5, "rv32i2p0_b0p93_zba0p93_zbb0p93_zbc0p93_zbe0p93_zbf0p93_zbm0p93_zbp0p93_zbr0p93_zbs0p93_zbt0p93" +.attribute arch, "rv32ip" +# CHECK: attribute 5, "rv32i2p0_p0p93_zpn0p93_zpsfoperand0p93" + +.attribute arch, "rv64ip" +# CHECK: attribute 5, "rv64i2p0_p0p93_zpn0p93_zprvsfextra0p93_zpsfoperand0p93" + .attribute arch, "rv32iv" # CHECK: attribute 5, "rv32i2p0_v0p10_zvlsseg0p10" @@ -72,6 +78,15 @@ .attribute arch, "rv32izbt" # CHECK: attribute 5, "rv32i2p0_zbt0p93" +.attribute arch, "rv32izpn" +# CHECK: attribute 5, "rv32i2p0_zpn0p93" + +.attribute arch, "rv32izpsfoperand" +# CHECK: attribute 5, "rv32i2p0_zpsfoperand0p93" + +.attribute arch, "rv64izprvsfextra" +# CHECK: attribute 5, "rv64i2p0_zprvsfextra0p93" + .attribute arch, "rv32ifzfh" # CHECK: attribute 5, "rv32i2p0_f2p0_zfh0p1"