Author: Steven Perron
Date: 2025-06-26T13:28:57-04:00
New Revision: 1d60d91bf3ae9e2b92c9a6e3abd2076f755e79e1

URL: 
https://github.com/llvm/llvm-project/commit/1d60d91bf3ae9e2b92c9a6e3abd2076f755e79e1
DIFF: 
https://github.com/llvm/llvm-project/commit/1d60d91bf3ae9e2b92c9a6e3abd2076f755e79e1.diff

LOG: [HLSL][SPIRV] Add option to add all KHR extensions (#145536)

In DXC, there is an option to enable all KHR extension. This is added by
passing the KHR option to the SPIR-V backend, which will enable all of
the appropriate extensions.

Part of https://github.com/llvm/llvm-project/issues/137650.

Added: 
    

Modified: 
    clang/lib/Driver/ToolChains/HLSL.cpp
    clang/test/Driver/dxc_fspv_extension.hlsl

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index 68c32ccdbb7cd..2b83f408b4c07 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -182,13 +182,15 @@ std::string getSpirvExtArg(ArrayRef<std::string> 
SpvExtensionArgs) {
       (Twine("-spirv-ext=+") + SpvExtensionArgs.front()).str();
   SpvExtensionArgs = SpvExtensionArgs.slice(1);
   for (auto Extension : SpvExtensionArgs) {
-    LlvmOption = (Twine(LlvmOption) + ",+" + Extension).str();
+    if (Extension != "KHR")
+      Extension = (Twine("+") + Extension).str();
+    LlvmOption = (Twine(LlvmOption) + "," + Extension).str();
   }
   return LlvmOption;
 }
 
 bool isValidSPIRVExtensionName(const std::string &str) {
-  std::regex pattern("SPV_[a-zA-Z0-9_]+");
+  std::regex pattern("KHR|SPV_[a-zA-Z0-9_]+");
   return std::regex_match(str, pattern);
 }
 

diff  --git a/clang/test/Driver/dxc_fspv_extension.hlsl 
b/clang/test/Driver/dxc_fspv_extension.hlsl
index ff414ab6c0a6e..f09f21e8a72c9 100644
--- a/clang/test/Driver/dxc_fspv_extension.hlsl
+++ b/clang/test/Driver/dxc_fspv_extension.hlsl
@@ -10,8 +10,13 @@
 // RUN: %clang_dxc -spirv -Tlib_6_7 -### %s -fspv-extension=SPV_TEST1 
-fspv-extension=SPV_TEST2 2>&1 | FileCheck %s -check-prefix=TEST2
 // TEST2: "-spirv-ext=+SPV_TEST1,+SPV_TEST2"
 
+// Merge KHR with other extensions.
+// RUN: %clang_dxc -spirv -Tlib_6_7 -### %s -fspv-extension=SPV_TEST1 
-fspv-extension=KHR -fspv-extension=SPV_TEST2 2>&1 | FileCheck %s 
-check-prefix=TEST3
+// TEST3: "-spirv-ext=+SPV_TEST1,KHR,+SPV_TEST2"
+
 // Check for the error message if the extension name is not properly formed.
-// RUN: not %clang_dxc -spirv -Tlib_6_7 -### %s -fspv-extension=TEST1 
-fspv-extension=SPV_GOOD -fspv-extension=TEST2 2>&1 | FileCheck %s 
-check-prefix=FAIL
+// RUN: not %clang_dxc -spirv -Tlib_6_7 -### %s -fspv-extension=KHR_BAD 
-fspv-extension=TEST1 -fspv-extension=SPV_GOOD -fspv-extension=TEST2 2>&1 | 
FileCheck %s -check-prefix=FAIL
+// FAIL: invalid value 'KHR_BAD' in '-fspv-extension'
 // FAIL: invalid value 'TEST1' in '-fspv-extension'
 // FAIL: invalid value 'TEST2' in '-fspv-extension'
 


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to