[llvm] 9587118 - Add DXIL triple
Chris Bieneman via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 18 22:18:24 PDT 2022
Author: Chris Bieneman
Date: 2022-03-19T00:17:43-05:00
New Revision: 95871187bfbc809a15a9ac914bd6ef320c891592
URL: https://github.com/llvm/llvm-project/commit/95871187bfbc809a15a9ac914bd6ef320c891592
DIFF: https://github.com/llvm/llvm-project/commit/95871187bfbc809a15a9ac914bd6ef320c891592.diff
LOG: Add DXIL triple
This patch adds triple support for:
* dxil architecture
* shadermodel OS (with version parsing)
* shader stages as environment
Reviewed By: MaskRay, pete
Differential Revision: https://reviews.llvm.org/D122031
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 a5f74df92209e..99ddfca897e63 100644
--- a/llvm/include/llvm/ADT/Triple.h
+++ b/llvm/include/llvm/ADT/Triple.h
@@ -56,6 +56,7 @@ class Triple {
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 @@ class Triple {
Hurd, // GNU/Hurd
WASI, // Experimental WebAssembly OS
Emscripten,
- LastOSType = Emscripten
+ ShaderModel, // DirectX ShaderModel
+ LastOSType = ShaderModel
};
enum EnvironmentType {
UnknownEnvironment,
@@ -235,7 +237,19 @@ class Triple {
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 @@ class Triple {
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
index 978545a1ba144..6d954da2461d3 100644
--- a/llvm/lib/Support/Triple.cpp
+++ b/llvm/lib/Support/Triple.cpp
@@ -37,6 +37,7 @@ StringRef Triple::getArchTypeName(ArchType Kind) {
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 @@ StringRef Triple::getArchTypePrefix(ArchType Kind) {
case loongarch32:
case loongarch64: return "loongarch";
+
+ case dxil: return "dx";
}
}
@@ -235,6 +238,7 @@ StringRef Triple::getOSTypeName(OSType Kind) {
case WatchOS: return "watchos";
case Win32: return "windows";
case ZOS: return "zos";
+ case ShaderModel: return "shadermodel";
}
llvm_unreachable("Invalid OSType");
@@ -264,6 +268,15 @@ StringRef Triple::getEnvironmentTypeName(EnvironmentType Kind) {
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 @@ Triple::ArchType Triple::getArchTypeForLLVMName(StringRef Name) {
.Case("csky", csky)
.Case("loongarch32", loongarch32)
.Case("loongarch64", loongarch64)
+ .Case("dxil", dxil)
.Default(UnknownArch);
}
@@ -485,6 +499,7 @@ static Triple::ArchType parseArch(StringRef ArchName) {
.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 @@ static Triple::OSType parseOS(StringRef OSName) {
.StartsWith("hurd", Triple::Hurd)
.StartsWith("wasi", Triple::WASI)
.StartsWith("emscripten", Triple::Emscripten)
+ .StartsWith("shadermodel", Triple::ShaderModel)
.Default(Triple::UnknownOS);
}
@@ -585,6 +601,15 @@ static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) {
.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 @@ static Triple::ObjectFormatType getDefaultFormat(const Triple &T) {
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 @@ static unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch) {
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 @@ Triple Triple::get32BitArchVariant() const {
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 @@ Triple Triple::get64BitArchVariant() const {
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 @@ Triple Triple::getBigEndianArchVariant() const {
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 @@ bool Triple::isLittleEndian() const {
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
index f4715e8558983..3824769a823ab 100644
--- a/llvm/unittests/ADT/TripleTest.cpp
+++ b/llvm/unittests/ADT/TripleTest.cpp
@@ -620,6 +620,61 @@ TEST(TripleTest, ParsedIDs) {
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 @@ TEST(TripleTest, BitWidthPredicates) {
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 @@ TEST(TripleTest, BitWidthArchVariants) {
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 @@ TEST(TripleTest, EndianArchVariants) {
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 @@ TEST(TripleTest, getOSVersion) {
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) {
More information about the llvm-commits
mailing list