[llvm] dbbe548 - [DirectX] Not print invalid root signature definitions. (#196444)
via llvm-commits
llvm-commits at lists.llvm.org
Fri May 8 16:06:15 PDT 2026
Author: joaosaffran
Date: 2026-05-08T16:06:10-07:00
New Revision: dbbe548ed5dd3e3f47da7592179538b618fff926
URL: https://github.com/llvm/llvm-project/commit/dbbe548ed5dd3e3f47da7592179538b618fff926
DIFF: https://github.com/llvm/llvm-project/commit/dbbe548ed5dd3e3f47da7592179538b618fff926.diff
LOG: [DirectX] Not print invalid root signature definitions. (#196444)
This patch adds a check during root signature printing pass, that makes
sure we have valid root signature before starting printing. This is
required after https://github.com/llvm/llvm-project/pull/194858 changed
reportError to not stop after emitting the first error.
Fix: https://github.com/llvm/llvm-project/issues/196430
Added:
llvm/test/CodeGen/DirectX/ContainerData/RootSignature-PrintOnlyValid.ll
Modified:
llvm/lib/Target/DirectX/DXILRootSignature.cpp
llvm/lib/Target/DirectX/DXILRootSignature.h
llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Error-is-not-function.ll
llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Error-is-not-value.ll
llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Invalid-Version.ll
llvm/test/CodeGen/DirectX/ContainerData/RootSignature-NullFunction-Error.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
index ac3c7dde6b892..bd36334a16eac 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
@@ -169,6 +169,8 @@ PreservedAnalyses RootSignatureAnalysisPrinter::run(Module &M,
ModuleAnalysisManager &AM) {
RootSignatureBindingInfo &RSDMap = AM.getResult<RootSignatureAnalysis>(M);
+ if (RSDMap.empty())
+ return PreservedAnalyses::all();
OS << "Root Signature Definitions"
<< "\n";
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.h b/llvm/lib/Target/DirectX/DXILRootSignature.h
index 1bc9e7ccbddf3..947cf6e79f0ef 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.h
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.h
@@ -42,6 +42,8 @@ class RootSignatureBindingInfo {
iterator end() { return FuncToRsMap.end(); }
+ bool empty() const { return FuncToRsMap.empty(); }
+
mcdxbc::RootSignatureDesc *getDescForFunction(const Function *F) {
const auto FuncRs = find(F);
if (FuncRs == end())
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Error-is-not-function.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Error-is-not-function.ll
index fbda7561cecad..bca00c0bc007d 100644
--- a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Error-is-not-function.ll
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Error-is-not-function.ll
@@ -3,24 +3,17 @@
target triple = "dxil-unknown-shadermodel6.0-compute"
; CHECK: error: First element of root signature is not a Function
-; CHECK-NOT: Root Signature Definitions
+; CHECK-NOT: Definition for 'main':
-define void @main() #0 {
-entry:
- ret void
-}
-define void @anotherMain() #0 {
+define void @main() #0 {
entry:
ret void
}
attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
-!dx.rootsignatures = !{!2, !5} ; list of function/root signature pairs
-!2 = !{ ptr @main, !3, i32 2 } ; function, root signature
-!3 = !{ !4 } ; list of root signature elements
-!4 = !{ !"RootFlags", i32 1 } ; 1 = allow_input_assembler_input_layout
+!dx.rootsignatures = !{!5} ; list of function/root signature pairs
!5 = !{ i32 -1, !6, i32 2 } ; function, root signature
!6 = !{ !7 } ; list of root signature elements
!7 = !{ !"RootFlags", i32 2 } ; 1 = allow_input_assembler_input_layout
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Error-is-not-value.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Error-is-not-value.ll
index 94ab52e1f29c0..e46a293ee340a 100644
--- a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Error-is-not-value.ll
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Error-is-not-value.ll
@@ -3,24 +3,17 @@
target triple = "dxil-unknown-shadermodel6.0-compute"
; CHECK: error: First element of root signature is not a Value
-; CHECK-NOT: Root Signature Definitions
+; CHECK-NOT: Definition for 'main'
-define void @main() #0 {
-entry:
- ret void
-}
-define void @anotherMain() #0 {
+define void @main() #0 {
entry:
ret void
}
attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
-!dx.rootsignatures = !{!2, !5} ; list of function/root signature pairs
-!2 = !{ ptr @main, !3, i32 2 } ; function, root signature
-!3 = !{ !4 } ; list of root signature elements
-!4 = !{ !"RootFlags", i32 1 } ; 1 = allow_input_assembler_input_layout
-!5 = !{ !3, !6, i32 2 } ; function, root signature
+!dx.rootsignatures = !{!5} ; list of function/root signature pairs
+!5 = !{ !6, !6, i32 2 } ; function, root signature
!6 = !{ !7 } ; list of root signature elements
!7 = !{ !"RootFlags", i32 2 } ; 1 = allow_input_assembler_input_layout
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Invalid-Version.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Invalid-Version.ll
index 26867e6d7ec25..452d0d386f731 100644
--- a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Invalid-Version.ll
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Invalid-Version.ll
@@ -4,7 +4,7 @@ target triple = "dxil-unknown-shadermodel6.0-compute"
; CHECK: error: Invalid value for Version: 4
-; CHECK-NOT: Root Signature Definitions
+
define void @main() #0 {
entry:
ret void
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-NullFunction-Error.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-NullFunction-Error.ll
index c6b57ee31c87a..583eef780ecb6 100644
--- a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-NullFunction-Error.ll
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-NullFunction-Error.ll
@@ -1,7 +1,6 @@
; RUN: not opt -passes='print<dxil-root-signature>' %s -S -o - 2>&1 | FileCheck %s
; CHECK: error: Function associated with Root Signature definition is null
-; CHECK-NOT: Root Signature Definitions
target triple = "dxil-unknown-shadermodel6.0-compute"
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-PrintOnlyValid.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-PrintOnlyValid.ll
new file mode 100644
index 0000000000000..212c72615f6e0
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-PrintOnlyValid.ll
@@ -0,0 +1,26 @@
+; RUN: not opt -passes='print<dxil-root-signature>' %s -S -o - 2>&1 | FileCheck %s
+
+target triple = "dxil-unknown-shadermodel6.0-compute"
+
+; CHECK: Root Signature Definitions
+; CHECK: Definition for 'main':
+; CHECK-NOT: Definition for 'anotherMain':
+define void @main() #0 {
+entry:
+ ret void
+}
+
+define void @anotherMain() #0 {
+entry:
+ ret void
+}
+
+attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
+
+!dx.rootsignatures = !{!2, !5} ; list of function/root signature pairs
+!2 = !{ ptr @main, !3, i32 2 } ; function, root signature
+!3 = !{ !4 } ; list of root signature elements
+!4 = !{ !"RootFlags", i32 1 } ; 1 = allow_input_assembler_input_layout
+!5 = !{ i32 -1, !6, i32 2 } ; function, root signature
+!6 = !{ !7 } ; list of root signature elements
+!7 = !{ !"RootFlags", i32 2 } ; 1 = allow_input_assembler_input_layout
More information about the llvm-commits
mailing list