[llvm] d480271 - [ADT][Triple] Add environment kinds for LoongArch GNU multiarch tuples
Weining Lu via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 9 23:05:23 PST 2022
Author: WANG Xuerui
Date: 2022-11-10T15:05:04+08:00
New Revision: d480271729236fa194ceddde420f37527a466270
URL: https://github.com/llvm/llvm-project/commit/d480271729236fa194ceddde420f37527a466270
DIFF: https://github.com/llvm/llvm-project/commit/d480271729236fa194ceddde420f37527a466270.diff
LOG: [ADT][Triple] Add environment kinds for LoongArch GNU multiarch tuples
The canonical multiarch tuples for LoongArch are defined in [the
LoongArch toolchain conventions][1] document. As the musl port is still
WIP, only the GNU triples are added for now.
The spec mentions `loongarch64-linux-gnuf64`, which is functionally the
same as the existing `loongarch64-linux-gnu` triple, only with the
floating-point ABI part explicitly spelled out. Both forms are
supported, but normalization of one into another is not implemented in
this patch, to give the ecosystem some time to experiment and discuss.
[1]: https://loongson.github.io/LoongArch-Documentation/LoongArch-toolchain-conventions-EN.html
Reviewed By: MaskRay
Differential Revision: https://reviews.llvm.org/D135751
Added:
Modified:
llvm/include/llvm/ADT/Triple.h
llvm/lib/Support/Triple.cpp
llvm/unittests/ADT/TripleTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ADT/Triple.h b/llvm/include/llvm/ADT/Triple.h
index 5aba2730c5a8b..8fc14781d34cf 100644
--- a/llvm/include/llvm/ADT/Triple.h
+++ b/llvm/include/llvm/ADT/Triple.h
@@ -230,6 +230,9 @@ class Triple {
GNUABI64,
GNUEABI,
GNUEABIHF,
+ GNUF32,
+ GNUF64,
+ GNUSF,
GNUX32,
GNUILP32,
CODE16,
@@ -559,7 +562,9 @@ class Triple {
EnvironmentType Env = getEnvironment();
return Env == Triple::GNU || Env == Triple::GNUABIN32 ||
Env == Triple::GNUABI64 || Env == Triple::GNUEABI ||
- Env == Triple::GNUEABIHF || Env == Triple::GNUX32;
+ Env == Triple::GNUEABIHF || Env == Triple::GNUF32 ||
+ Env == Triple::GNUF64 || Env == Triple::GNUSF ||
+ Env == Triple::GNUX32;
}
bool isOSContiki() const {
diff --git a/llvm/lib/Support/Triple.cpp b/llvm/lib/Support/Triple.cpp
index d24bca84b79f2..f91b7e9273fbc 100644
--- a/llvm/lib/Support/Triple.cpp
+++ b/llvm/lib/Support/Triple.cpp
@@ -258,6 +258,9 @@ StringRef Triple::getEnvironmentTypeName(EnvironmentType Kind) {
case GNUABIN32: return "gnuabin32";
case GNUEABI: return "gnueabi";
case GNUEABIHF: return "gnueabihf";
+ case GNUF32: return "gnuf32";
+ case GNUF64: return "gnuf64";
+ case GNUSF: return "gnusf";
case GNUX32: return "gnux32";
case GNUILP32: return "gnu_ilp32";
case Itanium: return "itanium";
@@ -598,6 +601,9 @@ static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) {
.StartsWith("gnuabi64", Triple::GNUABI64)
.StartsWith("gnueabihf", Triple::GNUEABIHF)
.StartsWith("gnueabi", Triple::GNUEABI)
+ .StartsWith("gnuf32", Triple::GNUF32)
+ .StartsWith("gnuf64", Triple::GNUF64)
+ .StartsWith("gnusf", Triple::GNUSF)
.StartsWith("gnux32", Triple::GNUX32)
.StartsWith("gnu_ilp32", Triple::GNUILP32)
.StartsWith("code16", Triple::CODE16)
diff --git a/llvm/unittests/ADT/TripleTest.cpp b/llvm/unittests/ADT/TripleTest.cpp
index 2a11648b85c91..a74c0c51f5a27 100644
--- a/llvm/unittests/ADT/TripleTest.cpp
+++ b/llvm/unittests/ADT/TripleTest.cpp
@@ -439,12 +439,72 @@ TEST(TripleTest, ParsedIDs) {
EXPECT_EQ(Triple::UnknownOS, T.getOS());
EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
+ T = Triple("loongarch32-unknown-linux-gnu");
+ EXPECT_EQ(Triple::loongarch32, T.getArch());
+ EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+ EXPECT_EQ(Triple::Linux, T.getOS());
+ EXPECT_EQ(Triple::GNU, T.getEnvironment());
+
+ T = Triple("loongarch32-unknown-linux-gnuf32");
+ EXPECT_EQ(Triple::loongarch32, T.getArch());
+ EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+ EXPECT_EQ(Triple::Linux, T.getOS());
+ EXPECT_EQ(Triple::GNUF32, T.getEnvironment());
+
+ T = Triple("loongarch32-unknown-linux-gnuf64");
+ EXPECT_EQ(Triple::loongarch32, T.getArch());
+ EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+ EXPECT_EQ(Triple::Linux, T.getOS());
+ EXPECT_EQ(Triple::GNUF64, T.getEnvironment());
+
+ T = Triple("loongarch32-unknown-linux-gnusf");
+ EXPECT_EQ(Triple::loongarch32, T.getArch());
+ EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+ EXPECT_EQ(Triple::Linux, T.getOS());
+ EXPECT_EQ(Triple::GNUSF, T.getEnvironment());
+
+ T = Triple("loongarch32-unknown-linux-musl");
+ EXPECT_EQ(Triple::loongarch32, T.getArch());
+ EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+ EXPECT_EQ(Triple::Linux, T.getOS());
+ EXPECT_EQ(Triple::Musl, T.getEnvironment());
+
T = Triple("loongarch64-unknown-linux");
EXPECT_EQ(Triple::loongarch64, T.getArch());
EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
EXPECT_EQ(Triple::Linux, T.getOS());
EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
+ T = Triple("loongarch64-unknown-linux-gnu");
+ EXPECT_EQ(Triple::loongarch64, T.getArch());
+ EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+ EXPECT_EQ(Triple::Linux, T.getOS());
+ EXPECT_EQ(Triple::GNU, T.getEnvironment());
+
+ T = Triple("loongarch64-unknown-linux-gnuf32");
+ EXPECT_EQ(Triple::loongarch64, T.getArch());
+ EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+ EXPECT_EQ(Triple::Linux, T.getOS());
+ EXPECT_EQ(Triple::GNUF32, T.getEnvironment());
+
+ T = Triple("loongarch64-unknown-linux-gnuf64");
+ EXPECT_EQ(Triple::loongarch64, T.getArch());
+ EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+ EXPECT_EQ(Triple::Linux, T.getOS());
+ EXPECT_EQ(Triple::GNUF64, T.getEnvironment());
+
+ T = Triple("loongarch64-unknown-linux-gnusf");
+ EXPECT_EQ(Triple::loongarch64, T.getArch());
+ EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+ EXPECT_EQ(Triple::Linux, T.getOS());
+ EXPECT_EQ(Triple::GNUSF, T.getEnvironment());
+
+ T = Triple("loongarch64-unknown-linux-musl");
+ EXPECT_EQ(Triple::loongarch64, T.getArch());
+ EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+ EXPECT_EQ(Triple::Linux, T.getOS());
+ EXPECT_EQ(Triple::Musl, T.getEnvironment());
+
T = Triple("riscv32-unknown-unknown");
EXPECT_EQ(Triple::riscv32, T.getArch());
EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
More information about the llvm-commits
mailing list