Index: include/llvm/ADT/Triple.h =================================================================== --- include/llvm/ADT/Triple.h +++ include/llvm/ADT/Triple.h @@ -64,6 +64,8 @@ ppc64le, // PPC64LE: powerpc64le r600, // R600: AMD GPUs HD2XXX - HD6XXX amdgcn, // AMDGCN: AMD GCN GPUs + riscv32, // RISC-V (32-bit): riscv32 + riscv64, // RISC-V (64-bit): riscv64 sparc, // Sparc: sparc sparcv9, // Sparcv9: Sparcv9 sparcel, // Sparc: (endianness = little). NB: 'Sparcle' is a CPU variant Index: lib/Support/Triple.cpp =================================================================== --- lib/Support/Triple.cpp +++ lib/Support/Triple.cpp @@ -39,6 +39,8 @@ case ppc: return "powerpc"; case r600: return "r600"; case amdgcn: return "amdgcn"; + case riscv32: return "riscv32"; + case riscv64: return "riscv64"; case sparc: return "sparc"; case sparcv9: return "sparcv9"; case sparcel: return "sparcel"; @@ -134,6 +136,9 @@ case shave: return "shave"; case wasm32: case wasm64: return "wasm"; + + case riscv32: + case riscv64: return "riscv"; } } @@ -258,6 +263,8 @@ .Case("ppc64le", ppc64le) .Case("r600", r600) .Case("amdgcn", amdgcn) + .Case("riscv32", riscv32) + .Case("riscv64", riscv64) .Case("hexagon", hexagon) .Case("sparc", sparc) .Case("sparcel", sparcel) @@ -373,6 +380,8 @@ .Case("mips64el", Triple::mips64el) .Case("r600", Triple::r600) .Case("amdgcn", Triple::amdgcn) + .Case("riscv32", Triple::riscv32) + .Case("riscv64", Triple::riscv64) .Case("hexagon", Triple::hexagon) .Cases("s390x", "systemz", Triple::systemz) .Case("sparc", Triple::sparc) @@ -606,6 +615,8 @@ case Triple::renderscript32: case Triple::renderscript64: case Triple::shave: + case Triple::riscv32: + case Triple::riscv64: case Triple::sparc: case Triple::sparcel: case Triple::sparcv9: @@ -1132,6 +1143,7 @@ case llvm::Triple::nvptx: case llvm::Triple::ppc: case llvm::Triple::r600: + case llvm::Triple::riscv32: case llvm::Triple::sparc: case llvm::Triple::sparcel: case llvm::Triple::tce: @@ -1160,6 +1172,7 @@ case llvm::Triple::nvptx64: case llvm::Triple::ppc64: case llvm::Triple::ppc64le: + case llvm::Triple::riscv64: case llvm::Triple::sparcv9: case llvm::Triple::systemz: case llvm::Triple::x86_64: @@ -1212,6 +1225,7 @@ case Triple::nvptx: case Triple::ppc: case Triple::r600: + case Triple::riscv32: case Triple::sparc: case Triple::sparcel: case Triple::tce: @@ -1234,6 +1248,7 @@ case Triple::nvptx64: T.setArch(Triple::nvptx); break; case Triple::ppc64: T.setArch(Triple::ppc); break; case Triple::sparcv9: T.setArch(Triple::sparc); break; + case Triple::riscv64: T.setArch(Triple::riscv32); break; case Triple::x86_64: T.setArch(Triple::x86); break; case Triple::amdil64: T.setArch(Triple::amdil); break; case Triple::hsail64: T.setArch(Triple::hsail); break; @@ -1275,6 +1290,7 @@ case Triple::nvptx64: case Triple::ppc64: case Triple::ppc64le: + case Triple::riscv64: case Triple::sparcv9: case Triple::systemz: case Triple::x86_64: @@ -1291,6 +1307,7 @@ case Triple::nvptx: T.setArch(Triple::nvptx64); break; case Triple::ppc: T.setArch(Triple::ppc64); break; case Triple::sparc: T.setArch(Triple::sparcv9); break; + case Triple::riscv32: T.setArch(Triple::riscv64); break; case Triple::x86: T.setArch(Triple::x86_64); break; case Triple::amdil: T.setArch(Triple::amdil64); break; case Triple::hsail: T.setArch(Triple::hsail64); break; @@ -1324,6 +1341,8 @@ case Triple::nvptx64: case Triple::nvptx: case Triple::r600: + case Triple::riscv32: + case Triple::riscv64: case Triple::shave: case Triple::spir64: case Triple::spir: @@ -1408,6 +1427,8 @@ case Triple::nvptx: case Triple::ppc64le: case Triple::r600: + case Triple::riscv32: + case Triple::riscv64: case Triple::shave: case Triple::sparcel: case Triple::spir64: Index: unittests/ADT/TripleTest.cpp =================================================================== --- unittests/ADT/TripleTest.cpp +++ unittests/ADT/TripleTest.cpp @@ -248,6 +248,24 @@ EXPECT_EQ(Triple::AMDHSA, T.getOS()); EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment()); + T = Triple("riscv32-unknown-unknown"); + EXPECT_EQ(Triple::riscv32, T.getArch()); + EXPECT_EQ(Triple::UnknownVendor, T.getVendor()); + EXPECT_EQ(Triple::UnknownOS, T.getOS()); + EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment()); + + T = Triple("riscv64-unknown-linux"); + EXPECT_EQ(Triple::riscv64, T.getArch()); + EXPECT_EQ(Triple::UnknownVendor, T.getVendor()); + EXPECT_EQ(Triple::Linux, T.getOS()); + EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment()); + + T = Triple("riscv64-unknown-freebsd"); + EXPECT_EQ(Triple::riscv64, T.getArch()); + EXPECT_EQ(Triple::UnknownVendor, T.getVendor()); + EXPECT_EQ(Triple::FreeBSD, T.getOS()); + EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment()); + T = Triple("huh"); EXPECT_EQ(Triple::UnknownArch, T.getArch()); } @@ -541,6 +559,16 @@ EXPECT_FALSE(T.isArch16Bit()); EXPECT_TRUE(T.isArch32Bit()); EXPECT_FALSE(T.isArch64Bit()); + + T.setArch(Triple::riscv32); + EXPECT_FALSE(T.isArch16Bit()); + EXPECT_TRUE(T.isArch32Bit()); + EXPECT_FALSE(T.isArch64Bit()); + + T.setArch(Triple::riscv64); + EXPECT_FALSE(T.isArch16Bit()); + EXPECT_FALSE(T.isArch32Bit()); + EXPECT_TRUE(T.isArch64Bit()); } TEST(TripleTest, BitWidthArchVariants) { @@ -631,6 +659,14 @@ T.setArch(Triple::wasm64); EXPECT_EQ(Triple::wasm32, T.get32BitArchVariant().getArch()); EXPECT_EQ(Triple::wasm64, T.get64BitArchVariant().getArch()); + + T.setArch(Triple::riscv32); + EXPECT_EQ(Triple::riscv32, T.get32BitArchVariant().getArch()); + EXPECT_EQ(Triple::riscv64, T.get64BitArchVariant().getArch()); + + T.setArch(Triple::riscv64); + EXPECT_EQ(Triple::riscv32, T.get32BitArchVariant().getArch()); + EXPECT_EQ(Triple::riscv64, T.get64BitArchVariant().getArch()); } TEST(TripleTest, EndianArchVariants) {