[llvm] [llvm] Introduce XROS platform (PR #77707)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 10 16:15:34 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-binary-utilities
@llvm/pr-subscribers-mc
Author: Cyndy Ishida (cyndyishida)
<details>
<summary>Changes</summary>
Accepts but otherwise ignores visionOS/XROS target triples as Darwin based platform.
https://developer.apple.com/documentation/visionos
---
Full diff: https://github.com/llvm/llvm-project/pull/77707.diff
6 Files Affected:
- (modified) llvm/include/llvm/BinaryFormat/MachO.def (+2)
- (modified) llvm/include/llvm/TargetParser/Triple.h (+7-2)
- (modified) llvm/lib/MC/MCParser/DarwinAsmParser.cpp (+2)
- (modified) llvm/lib/TargetParser/Triple.cpp (+10)
- (modified) llvm/lib/TextAPI/Platform.cpp (+4)
- (modified) llvm/unittests/TargetParser/TripleTest.cpp (+36)
``````````diff
diff --git a/llvm/include/llvm/BinaryFormat/MachO.def b/llvm/include/llvm/BinaryFormat/MachO.def
index df527b4a8ab7c3..4124c723ec021f 100644
--- a/llvm/include/llvm/BinaryFormat/MachO.def
+++ b/llvm/include/llvm/BinaryFormat/MachO.def
@@ -133,6 +133,8 @@ PLATFORM(IOSSIMULATOR, 7, iossimulator, iossimulator, ios-simulator, ios-simulat
PLATFORM(TVOSSIMULATOR, 8, tvossimulator, tvossimulator, tvos-simulator, tvos-simulator, tvOS Simulator)
PLATFORM(WATCHOSSIMULATOR, 9, watchossimulator, watchossimulator, watchos-simulator, watchos-simulator, watchOS Simulator)
PLATFORM(DRIVERKIT, 10, driverkit, driverkit, driverkit, driverkit, DriverKit)
+PLATFORM(XROS, 11, xros, xros, xros, xros, xrOS)
+PLATFORM(XROS_SIMULATOR, 12, xrsimulator, xrsimulator, xrsimulator, xros-simulator, xrOS Simulator)
#endif
#undef HANDLE_LOAD_COMMAND
diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h
index 95014a546f7245..34ff7a8ccc43d7 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -214,6 +214,8 @@ class Triple {
TvOS, // Apple tvOS
WatchOS, // Apple watchOS
DriverKit, // Apple DriverKit
+ XROS, // Apple XROS
+
Mesa3D,
AMDPAL, // AMD PAL Runtime
HermitCore, // HermitCore Unikernel/Multikernel
@@ -514,14 +516,17 @@ class Triple {
return getSubArch() == Triple::ARMSubArch_v7k;
}
+ /// Is this an Apple XROS triple.
+ bool isXROS() const { return getOS() == Triple::XROS; }
+
/// Is this an Apple DriverKit triple.
bool isDriverKit() const { return getOS() == Triple::DriverKit; }
bool isOSzOS() const { return getOS() == Triple::ZOS; }
- /// Is this a "Darwin" OS (macOS, iOS, tvOS, watchOS, or DriverKit).
+ /// Is this a "Darwin" OS (macOS, iOS, tvOS, watchOS, XROS, or DriverKit).
bool isOSDarwin() const {
- return isMacOSX() || isiOS() || isWatchOS() || isDriverKit();
+ return isMacOSX() || isiOS() || isWatchOS() || isDriverKit() || isXROS();
}
bool isSimulatorEnvironment() const {
diff --git a/llvm/lib/MC/MCParser/DarwinAsmParser.cpp b/llvm/lib/MC/MCParser/DarwinAsmParser.cpp
index edea5a56bec3d3..3cd44e7195be62 100644
--- a/llvm/lib/MC/MCParser/DarwinAsmParser.cpp
+++ b/llvm/lib/MC/MCParser/DarwinAsmParser.cpp
@@ -1147,6 +1147,7 @@ static Triple::OSType getOSTypeFromPlatform(MachO::PlatformType Type) {
case MachO::PLATFORM_IOS: return Triple::IOS;
case MachO::PLATFORM_TVOS: return Triple::TvOS;
case MachO::PLATFORM_WATCHOS: return Triple::WatchOS;
+ case MachO::PLATFORM_XROS: return Triple::XROS;
case MachO::PLATFORM_BRIDGEOS: /* silence warning */ break;
case MachO::PLATFORM_DRIVERKIT:
return Triple::DriverKit;
@@ -1154,6 +1155,7 @@ static Triple::OSType getOSTypeFromPlatform(MachO::PlatformType Type) {
case MachO::PLATFORM_IOSSIMULATOR: /* silence warning */ break;
case MachO::PLATFORM_TVOSSIMULATOR: /* silence warning */ break;
case MachO::PLATFORM_WATCHOSSIMULATOR: /* silence warning */ break;
+ case MachO::PLATFORM_XROS_SIMULATOR: /* silence warning */ break;
}
llvm_unreachable("Invalid mach-o platform type");
}
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index b9971c25af71f3..cc696745c7dd5e 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -273,6 +273,7 @@ StringRef Triple::getOSTypeName(OSType Kind) {
case ZOS: return "zos";
case ShaderModel: return "shadermodel";
case LiteOS: return "liteos";
+ case XROS: return "xros";
}
llvm_unreachable("Invalid OSType");
@@ -634,6 +635,8 @@ static Triple::OSType parseOS(StringRef OSName) {
.StartsWith("tvos", Triple::TvOS)
.StartsWith("watchos", Triple::WatchOS)
.StartsWith("driverkit", Triple::DriverKit)
+ .StartsWith("xros", Triple::XROS)
+ .StartsWith("visionos", Triple::XROS)
.StartsWith("mesa3d", Triple::Mesa3D)
.StartsWith("amdpal", Triple::AMDPAL)
.StartsWith("hermit", Triple::HermitCore)
@@ -1224,6 +1227,8 @@ VersionTuple Triple::getOSVersion() const {
OSName = OSName.substr(OSTypeName.size());
else if (getOS() == MacOSX)
OSName.consume_front("macos");
+ else if (OSName.starts_with("visionos"))
+ OSName.consume_front("visionos");
return parseVersionFromName(OSName);
}
@@ -1289,6 +1294,11 @@ VersionTuple Triple::getiOSVersion() const {
return (getArch() == aarch64) ? VersionTuple(7) : VersionTuple(5);
return Version;
}
+ case XROS: {
+ // xrOS 1 is aligned with iOS 17.
+ VersionTuple Version = getOSVersion();
+ return Version.withMajorReplaced(Version.getMajor() + 16);
+ }
case WatchOS:
llvm_unreachable("conflicting triple info");
case DriverKit:
diff --git a/llvm/lib/TextAPI/Platform.cpp b/llvm/lib/TextAPI/Platform.cpp
index ed041af40aa5b7..e891594300c2e4 100644
--- a/llvm/lib/TextAPI/Platform.cpp
+++ b/llvm/lib/TextAPI/Platform.cpp
@@ -106,6 +106,10 @@ std::string getOSAndEnvironmentName(PlatformType Platform,
return "watchos" + Version + "-simulator";
case PLATFORM_DRIVERKIT:
return "driverkit" + Version;
+ case PLATFORM_XROS:
+ return "xros" + Version;
+ case PLATFORM_XROS_SIMULATOR:
+ return "xros" + Version + "-simulator";
}
llvm_unreachable("Unknown llvm::MachO::PlatformType enum");
}
diff --git a/llvm/unittests/TargetParser/TripleTest.cpp b/llvm/unittests/TargetParser/TripleTest.cpp
index d3bde2986ea2cd..1b0e6c456c046e 100644
--- a/llvm/unittests/TargetParser/TripleTest.cpp
+++ b/llvm/unittests/TargetParser/TripleTest.cpp
@@ -1746,6 +1746,42 @@ TEST(TripleTest, EndianArchVariants) {
EXPECT_EQ(Triple::dxil, T.getLittleEndianArchVariant().getArch());
}
+TEST(TripleTest, XROS) {
+ Triple T;
+ VersionTuple Version;
+
+ T = Triple("arm64-apple-xros");
+ EXPECT_TRUE(T.isXROS());
+ EXPECT_TRUE(T.isOSDarwin());
+ EXPECT_FALSE(T.isiOS());
+ EXPECT_FALSE(T.isMacOSX());
+ EXPECT_FALSE(T.isSimulatorEnvironment());
+ EXPECT_EQ(T.getOSName(), "xros");
+ Version = T.getOSVersion();
+ EXPECT_EQ(VersionTuple(0), Version);
+
+ T = Triple("arm64-apple-visionos1.2");
+ EXPECT_TRUE(T.isXROS());
+ EXPECT_TRUE(T.isOSDarwin());
+ EXPECT_FALSE(T.isiOS());
+ EXPECT_FALSE(T.isMacOSX());
+ EXPECT_FALSE(T.isSimulatorEnvironment());
+ EXPECT_EQ(T.getOSName(), "visionos1.2");
+ Version = T.getOSVersion();
+ EXPECT_EQ(VersionTuple(1, 2), Version);
+
+ T = Triple("arm64-apple-xros1-simulator");
+ EXPECT_TRUE(T.isXROS());
+ EXPECT_TRUE(T.isOSDarwin());
+ EXPECT_FALSE(T.isiOS());
+ EXPECT_FALSE(T.isMacOSX());
+ EXPECT_TRUE(T.isSimulatorEnvironment());
+ Version = T.getOSVersion();
+ EXPECT_EQ(VersionTuple(1), Version);
+ Version = T.getiOSVersion();
+ EXPECT_EQ(VersionTuple(17), Version);
+}
+
TEST(TripleTest, getOSVersion) {
Triple T;
VersionTuple Version;
``````````
</details>
https://github.com/llvm/llvm-project/pull/77707
More information about the llvm-commits
mailing list