Skip to content

Commit 2809c2f

Browse files
author
joaosaffran
committed
adding more tests
1 parent 7bba9d3 commit 2809c2f

File tree

5 files changed

+88
-37
lines changed

5 files changed

+88
-37
lines changed

llvm/lib/Target/DirectX/DXILRootSignature.cpp

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "llvm/IR/DiagnosticInfo.h"
2121
#include "llvm/IR/Function.h"
2222
#include "llvm/IR/LLVMContext.h"
23+
#include "llvm/IR/Metadata.h"
2324
#include "llvm/IR/Module.h"
2425
#include "llvm/InitializePasses.h"
2526
#include "llvm/Pass.h"
@@ -63,9 +64,6 @@ static bool parseRootSignatureElement(LLVMContext *Ctx,
6364

6465
case RootSignatureElementKind::RootFlags:
6566
return parseRootFlags(Ctx, MRS, Element);
66-
default:
67-
return reportError(Ctx,
68-
"Invalid Root Element: " + ElementText->getString());
6967
}
7068

7169
return true;
@@ -95,8 +93,14 @@ static bool parse(LLVMContext *Ctx, ModuleRootSignature *MRS, NamedMDNode *Root,
9593
continue;
9694
}
9795

96+
const MDOperand &FunctionPointerMdNode = Node->getOperand(0);
97+
if (FunctionPointerMdNode == nullptr) {
98+
// Function was pruned during compilation.
99+
continue;
100+
}
101+
98102
ValueAsMetadata *VAM =
99-
llvm::dyn_cast<ValueAsMetadata>(Node->getOperand(0).get());
103+
llvm::dyn_cast<ValueAsMetadata>(FunctionPointerMdNode.get());
100104
if (VAM == nullptr) {
101105
HasError =
102106
reportError(Ctx, "First element of root signature is not a value");
@@ -140,24 +144,26 @@ static bool validate(LLVMContext *Ctx, ModuleRootSignature *MRS) {
140144
return false;
141145
}
142146

143-
std::optional<ModuleRootSignature>
144-
ModuleRootSignature::analyzeModule(Module &M, ModuleMetadataInfo MMI) {
145-
if (MMI.ShaderProfile == Triple::Library)
146-
return std::nullopt;
147+
static const Function *getEntryFunction(Module &M, ModuleMetadataInfo MMI) {
147148

148149
LLVMContext *Ctx = &M.getContext();
149-
150150
if (MMI.EntryPropertyVec.size() != 1) {
151151
reportError(Ctx, "More than one entry function defined.");
152-
return std::nullopt;
152+
return nullptr;
153153
}
154+
return MMI.EntryPropertyVec[0].Entry;
155+
}
156+
157+
std::optional<ModuleRootSignature>
158+
ModuleRootSignature::analyzeModule(Module &M, const Function *F) {
159+
160+
LLVMContext *Ctx = &M.getContext();
154161

155162
ModuleRootSignature MRS;
156-
const Function *EntryFunction = MMI.EntryPropertyVec[0].Entry;
157163

158164
NamedMDNode *RootSignatureNode = M.getNamedMetadata("dx.rootsignatures");
159-
if (RootSignatureNode == nullptr ||
160-
parse(Ctx, &MRS, RootSignatureNode, EntryFunction) || validate(Ctx, &MRS))
165+
if (RootSignatureNode == nullptr || parse(Ctx, &MRS, RootSignatureNode, F) ||
166+
validate(Ctx, &MRS))
161167
return std::nullopt;
162168

163169
return MRS;
@@ -168,15 +174,18 @@ AnalysisKey RootSignatureAnalysis::Key;
168174
std::optional<ModuleRootSignature>
169175
RootSignatureAnalysis::run(Module &M, ModuleAnalysisManager &AM) {
170176
ModuleMetadataInfo MMI = AM.getResult<DXILMetadataAnalysis>(M);
171-
return ModuleRootSignature::analyzeModule(M, MMI);
177+
if (MMI.ShaderProfile == Triple::Library)
178+
return std::nullopt;
179+
return ModuleRootSignature::analyzeModule(M, getEntryFunction(M, MMI));
172180
}
173181

174182
//===----------------------------------------------------------------------===//
175183
bool RootSignatureAnalysisWrapper::runOnModule(Module &M) {
176-
177184
dxil::ModuleMetadataInfo &MMI =
178185
getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
179-
MRS = ModuleRootSignature::analyzeModule(M, MMI);
186+
if (MMI.ShaderProfile == Triple::Library)
187+
return false;
188+
MRS = ModuleRootSignature::analyzeModule(M, getEntryFunction(M, MMI));
180189
return false;
181190
}
182191

llvm/lib/Target/DirectX/DXILRootSignature.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ enum class RootSignatureElementKind { None = 0, RootFlags = 1 };
2626

2727
struct ModuleRootSignature {
2828
uint32_t Flags = 0;
29-
static std::optional<ModuleRootSignature>
30-
analyzeModule(Module &M, ModuleMetadataInfo MMI);
29+
static std::optional<ModuleRootSignature> analyzeModule(Module &M,
30+
const Function *F);
3131
};
3232

3333
class RootSignatureAnalysis : public AnalysisInfoMixin<RootSignatureAnalysis> {

llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags-Error.ll

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
; RUN: not --crash llc %s --filetype=obj -o - 2>&1 | FileCheck %s
2+
; CHECK: error: More than one entry function defined
3+
4+
target triple = "dxil-unknown-shadermodel6.0-compute"
5+
6+
7+
define void @main() #0 {
8+
entry:
9+
ret void
10+
}
11+
12+
define void @anotherMain() #1 {
13+
entry:
14+
ret void
15+
}
16+
17+
attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
18+
attributes #1 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
19+
20+
!dx.rootsignatures = !{!2, !5} ; list of function/root signature pairs
21+
!2 = !{ ptr @main, !3 } ; function, root signature
22+
!3 = !{ !4 } ; list of root signature elements
23+
!4 = !{ !"RootFlags", i32 1 } ; 1 = allow_input_assembler_input_layout
24+
!5 = !{ ptr @anotherMain, !6 } ; function, root signature
25+
!6 = !{ !7 } ; list of root signature elements
26+
!7 = !{ !"RootFlags", i32 2 } ; 1 = allow_input_assembler_input_layout
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
; RUN: llc %s --filetype=obj -o - | obj2yaml | FileCheck %s
2+
3+
target triple = "dxil-unknown-shadermodel6.0-compute"
4+
5+
6+
define void @main() {
7+
entry:
8+
ret void
9+
}
10+
11+
define void @anotherMain() #0 {
12+
entry:
13+
ret void
14+
}
15+
16+
attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
17+
18+
!dx.rootsignatures = !{!2, !5} ; list of function/root signature pairs
19+
!2 = !{ ptr @main, !3 } ; function, root signature
20+
!3 = !{ !4 } ; list of root signature elements
21+
!4 = !{ !"RootFlags", i32 1 } ; 1 = allow_input_assembler_input_layout
22+
!5 = !{ ptr @anotherMain, !6 } ; function, root signature
23+
!6 = !{ !7 } ; list of root signature elements
24+
!7 = !{ !"RootFlags", i32 2 } ; 1 = allow_input_assembler_input_layout
25+
26+
27+
; CHECK: - Name: RTS0
28+
; CHECK-NEXT: Size: 24
29+
; CHECK-NEXT: RootSignature:
30+
; CHECK-NEXT: Version: 2
31+
; CHECK-NEXT: NumParameters: 0
32+
; CHECK-NEXT: RootParametersOffset: 0
33+
; CHECK-NEXT: NumStaticSamplers: 0
34+
; CHECK-NEXT: StaticSamplersOffset: 0
35+
; CHECK-NEXT: DenyVertexShaderRootAccess: true

0 commit comments

Comments
 (0)