Skip to content

[llvm] Introduce XROS platform #77707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions llvm/include/llvm/BinaryFormat/MachO.def
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions llvm/include/llvm/TargetParser/Triple.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ class Triple {
TvOS, // Apple tvOS
WatchOS, // Apple watchOS
DriverKit, // Apple DriverKit
XROS, // Apple XROS
Mesa3D,
AMDPAL, // AMD PAL Runtime
HermitCore, // HermitCore Unikernel/Multikernel
Expand Down Expand Up @@ -514,14 +515,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 {
Expand Down
14 changes: 14 additions & 0 deletions llvm/lib/TargetParser/Triple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -1265,6 +1270,8 @@ bool Triple::getMacOSXVersion(VersionTuple &Version) const {
// IOS.
Version = VersionTuple(10, 4);
break;
case XROS:
llvm_unreachable("OSX version isn't relevant for xrOS");
case DriverKit:
llvm_unreachable("OSX version isn't relevant for DriverKit");
}
Expand All @@ -1289,6 +1296,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:
Expand All @@ -1314,6 +1326,8 @@ VersionTuple Triple::getWatchOSVersion() const {
}
case IOS:
llvm_unreachable("conflicting triple info");
case XROS:
llvm_unreachable("watchOS version isn't relevant for xrOS");
case DriverKit:
llvm_unreachable("DriverKit doesn't have a WatchOS version");
}
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/TextAPI/Platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
36 changes: 36 additions & 0 deletions llvm/unittests/TargetParser/TripleTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down