diff --git a/llvm/include/llvm/ADT/Triple.h b/llvm/include/llvm/ADT/Triple.h --- a/llvm/include/llvm/ADT/Triple.h +++ b/llvm/include/llvm/ADT/Triple.h @@ -56,6 +56,7 @@ bpfel, // eBPF or extended BPF or 64-bit BPF (little endian) bpfeb, // eBPF or extended BPF or 64-bit BPF (big endian) csky, // CSKY: csky + dxil, // DXIL 32-bit DirectX bytecode hexagon, // Hexagon: hexagon loongarch32, // LoongArch (32-bit): loongarch32 loongarch64, // LoongArch (64-bit): loongarch64 @@ -208,7 +209,8 @@ Hurd, // GNU/Hurd WASI, // Experimental WebAssembly OS Emscripten, - LastOSType = Emscripten + ShaderModel, // DirectX ShaderModel + LastOSType = ShaderModel }; enum EnvironmentType { UnknownEnvironment, @@ -235,7 +237,19 @@ CoreCLR, Simulator, // Simulator variants of other systems, e.g., Apple's iOS MacABI, // Mac Catalyst variant of Apple's iOS deployment target. - LastEnvironmentType = MacABI + + // Shader Stages + Pixel, + Vertex, + Geometry, + Hull, + Domain, + Compute, + Library, + Mesh, + Amplification, + + LastEnvironmentType = Amplification }; enum ObjectFormatType { UnknownObjectFormat, @@ -679,6 +693,11 @@ getEnvironment() == Triple::MuslX32; } + /// Tests whether the target is DXIL. + bool isDXIL() const { + return getArch() == Triple::dxil; + } + /// Tests whether the target is SPIR (32- or 64-bit). bool isSPIR() const { return getArch() == Triple::spir || getArch() == Triple::spir64; diff --git a/llvm/lib/Support/Triple.cpp b/llvm/lib/Support/Triple.cpp --- a/llvm/lib/Support/Triple.cpp +++ b/llvm/lib/Support/Triple.cpp @@ -37,6 +37,7 @@ case bpfeb: return "bpfeb"; case bpfel: return "bpfel"; case csky: return "csky"; + case dxil: return "dxil"; case hexagon: return "hexagon"; case hsail64: return "hsail64"; case hsail: return "hsail"; @@ -169,6 +170,8 @@ case loongarch32: case loongarch64: return "loongarch"; + + case dxil: return "dx"; } } @@ -235,6 +238,7 @@ case WatchOS: return "watchos"; case Win32: return "windows"; case ZOS: return "zos"; + case ShaderModel: return "shadermodel"; } llvm_unreachable("Invalid OSType"); @@ -264,6 +268,15 @@ case MuslEABIHF: return "musleabihf"; case MuslX32: return "muslx32"; case Simulator: return "simulator"; + case Pixel: return "pixel"; + case Vertex: return "vertex"; + case Geometry: return "geometry"; + case Hull: return "hull"; + case Domain: return "domain"; + case Compute: return "compute"; + case Library: return "library"; + case Mesh: return "mesh"; + case Amplification: return "amplification"; } llvm_unreachable("Invalid EnvironmentType!"); @@ -348,6 +361,7 @@ .Case("csky", csky) .Case("loongarch32", loongarch32) .Case("loongarch64", loongarch64) + .Case("dxil", dxil) .Default(UnknownArch); } @@ -485,6 +499,7 @@ .Case("csky", Triple::csky) .Case("loongarch32", Triple::loongarch32) .Case("loongarch64", Triple::loongarch64) + .Case("dxil", Triple::dxil) .Default(Triple::UnknownArch); // Some architectures require special parsing logic just to compute the @@ -559,6 +574,7 @@ .StartsWith("hurd", Triple::Hurd) .StartsWith("wasi", Triple::WASI) .StartsWith("emscripten", Triple::Emscripten) + .StartsWith("shadermodel", Triple::ShaderModel) .Default(Triple::UnknownOS); } @@ -585,6 +601,15 @@ .StartsWith("coreclr", Triple::CoreCLR) .StartsWith("simulator", Triple::Simulator) .StartsWith("macabi", Triple::MacABI) + .StartsWith("pixel", Triple::Pixel) + .StartsWith("vertex", Triple::Vertex) + .StartsWith("geometry", Triple::Geometry) + .StartsWith("hull", Triple::Hull) + .StartsWith("domain", Triple::Domain) + .StartsWith("compute", Triple::Compute) + .StartsWith("library", Triple::Library) + .StartsWith("mesh", Triple::Mesh) + .StartsWith("amplification", Triple::Amplification) .Default(Triple::UnknownEnvironment); } @@ -791,6 +816,9 @@ case Triple::spirv64: // TODO: In future this will be Triple::SPIRV. return Triple::UnknownObjectFormat; + + case Triple::dxil: + return Triple::UnknownObjectFormat; } llvm_unreachable("unknown architecture"); } @@ -1316,6 +1344,7 @@ case llvm::Triple::arm: case llvm::Triple::armeb: case llvm::Triple::csky: + case llvm::Triple::dxil: case llvm::Triple::hexagon: case llvm::Triple::hsail: case llvm::Triple::kalimba: @@ -1405,6 +1434,7 @@ case Triple::arm: case Triple::armeb: case Triple::csky: + case Triple::dxil: case Triple::hexagon: case Triple::hsail: case Triple::kalimba: @@ -1468,6 +1498,7 @@ case Triple::arc: case Triple::avr: case Triple::csky: + case Triple::dxil: case Triple::hexagon: case Triple::kalimba: case Triple::lanai: @@ -1548,6 +1579,7 @@ case Triple::amdil64: case Triple::amdil: case Triple::avr: + case Triple::dxil: case Triple::hexagon: case Triple::hsail64: case Triple::hsail: @@ -1650,6 +1682,7 @@ case Triple::avr: case Triple::bpfel: case Triple::csky: + case Triple::dxil: case Triple::hexagon: case Triple::hsail64: case Triple::hsail: diff --git a/llvm/unittests/ADT/TripleTest.cpp b/llvm/unittests/ADT/TripleTest.cpp --- a/llvm/unittests/ADT/TripleTest.cpp +++ b/llvm/unittests/ADT/TripleTest.cpp @@ -620,6 +620,61 @@ EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment()); EXPECT_TRUE(T.isArch32Bit()); + T = Triple("dxil-unknown-shadermodel-pixel"); + EXPECT_EQ(Triple::dxil, T.getArch()); + EXPECT_EQ(Triple::UnknownVendor, T.getVendor()); + EXPECT_EQ(Triple::ShaderModel, T.getOS()); + EXPECT_EQ(Triple::Pixel, T.getEnvironment()); + + T = Triple("dxil-unknown-shadermodel-vertex"); + EXPECT_EQ(Triple::dxil, T.getArch()); + EXPECT_EQ(Triple::UnknownVendor, T.getVendor()); + EXPECT_EQ(Triple::ShaderModel, T.getOS()); + EXPECT_EQ(Triple::Vertex, T.getEnvironment()); + + T = Triple("dxil-unknown-shadermodel-geometry"); + EXPECT_EQ(Triple::dxil, T.getArch()); + EXPECT_EQ(Triple::UnknownVendor, T.getVendor()); + EXPECT_EQ(Triple::ShaderModel, T.getOS()); + EXPECT_EQ(Triple::Geometry, T.getEnvironment()); + + + T = Triple("dxil-unknown-shadermodel-hull"); + EXPECT_EQ(Triple::dxil, T.getArch()); + EXPECT_EQ(Triple::UnknownVendor, T.getVendor()); + EXPECT_EQ(Triple::ShaderModel, T.getOS()); + EXPECT_EQ(Triple::Hull, T.getEnvironment()); + + T = Triple("dxil-unknown-shadermodel-domain"); + EXPECT_EQ(Triple::dxil, T.getArch()); + EXPECT_EQ(Triple::UnknownVendor, T.getVendor()); + EXPECT_EQ(Triple::ShaderModel, T.getOS()); + EXPECT_EQ(Triple::Domain, T.getEnvironment()); + + T = Triple("dxil-unknown-shadermodel-compute"); + EXPECT_EQ(Triple::dxil, T.getArch()); + EXPECT_EQ(Triple::UnknownVendor, T.getVendor()); + EXPECT_EQ(Triple::ShaderModel, T.getOS()); + EXPECT_EQ(Triple::Compute, T.getEnvironment()); + + T = Triple("dxil-unknown-shadermodel-library"); + EXPECT_EQ(Triple::dxil, T.getArch()); + EXPECT_EQ(Triple::UnknownVendor, T.getVendor()); + EXPECT_EQ(Triple::ShaderModel, T.getOS()); + EXPECT_EQ(Triple::Library, T.getEnvironment()); + + T = Triple("dxil-unknown-shadermodel-mesh"); + EXPECT_EQ(Triple::dxil, T.getArch()); + EXPECT_EQ(Triple::UnknownVendor, T.getVendor()); + EXPECT_EQ(Triple::ShaderModel, T.getOS()); + EXPECT_EQ(Triple::Mesh, T.getEnvironment()); + + T = Triple("dxil-unknown-shadermodel-amplification"); + EXPECT_EQ(Triple::dxil, T.getArch()); + EXPECT_EQ(Triple::UnknownVendor, T.getVendor()); + EXPECT_EQ(Triple::ShaderModel, T.getOS()); + EXPECT_EQ(Triple::Amplification, T.getEnvironment()); + T = Triple("huh"); EXPECT_EQ(Triple::UnknownArch, T.getArch()); } @@ -973,6 +1028,12 @@ EXPECT_FALSE(T.isArch32Bit()); EXPECT_TRUE(T.isArch64Bit()); EXPECT_TRUE(T.isLoongArch()); + + T.setArch(Triple::dxil); + EXPECT_FALSE(T.isArch16Bit()); + EXPECT_TRUE(T.isArch32Bit()); + EXPECT_FALSE(T.isArch64Bit()); + EXPECT_TRUE(T.isDXIL()); } TEST(TripleTest, BitWidthArchVariants) { @@ -1163,6 +1224,10 @@ T.setArch(Triple::xcore); EXPECT_EQ(Triple::xcore, T.get32BitArchVariant().getArch()); EXPECT_EQ(Triple::UnknownArch, T.get64BitArchVariant().getArch()); + + T.setArch(Triple::dxil); + EXPECT_EQ(Triple::dxil, T.get32BitArchVariant().getArch()); + EXPECT_EQ(Triple::UnknownArch, T.get64BitArchVariant().getArch()); } TEST(TripleTest, EndianArchVariants) { @@ -1311,6 +1376,11 @@ EXPECT_TRUE(T.isLittleEndian()); EXPECT_EQ(Triple::UnknownArch, T.getBigEndianArchVariant().getArch()); EXPECT_EQ(Triple::loongarch64, T.getLittleEndianArchVariant().getArch()); + + T.setArch(Triple::dxil); + EXPECT_TRUE(T.isLittleEndian()); + EXPECT_EQ(Triple::UnknownArch, T.getBigEndianArchVariant().getArch()); + EXPECT_EQ(Triple::dxil, T.getLittleEndianArchVariant().getArch()); } TEST(TripleTest, getOSVersion) { @@ -1451,6 +1521,22 @@ T = Triple("x86_64-apple-driverkit"); Version = T.getDriverKitVersion(); EXPECT_EQ(VersionTuple(19, 0), Version); + + T = Triple("dxil-unknown-shadermodel6.6-pixel"); + EXPECT_EQ(Triple::dxil, T.getArch()); + EXPECT_EQ(Triple::UnknownVendor, T.getVendor()); + EXPECT_EQ(Triple::ShaderModel, T.getOS()); + Version = T.getOSVersion(); + EXPECT_EQ(VersionTuple(6,6), Version); + EXPECT_EQ(Triple::Pixel, T.getEnvironment()); + + T = Triple("dxil-unknown-shadermodel6.0-pixel"); + EXPECT_EQ(Triple::dxil, T.getArch()); + EXPECT_EQ(Triple::UnknownVendor, T.getVendor()); + EXPECT_EQ(Triple::ShaderModel, T.getOS()); + Version = T.getOSVersion(); + EXPECT_EQ(VersionTuple(6,0), Version); + EXPECT_EQ(Triple::Pixel, T.getEnvironment()); } TEST(TripleTest, getEnvironmentVersion) {