Skip to content

Commit a5a2093

Browse files
author
joaosaffran
committed
addressing pr comments
1 parent f64c608 commit a5a2093

File tree

5 files changed

+36
-28
lines changed

5 files changed

+36
-28
lines changed

llvm/lib/Object/DXContainer.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "llvm/Object/DXContainer.h"
10+
#include "llvm/ADT/Twine.h"
1011
#include "llvm/BinaryFormat/DXContainer.h"
1112
#include "llvm/Object/Error.h"
1213
#include "llvm/Support/Alignment.h"
1314
#include "llvm/Support/Endian.h"
15+
#include "llvm/Support/Error.h"
1416
#include "llvm/Support/FormatVariadic.h"
1517

1618
using namespace llvm;
@@ -20,6 +22,10 @@ static Error parseFailed(const Twine &Msg) {
2022
return make_error<GenericBinaryError>(Msg.str(), object_error::parse_failed);
2123
}
2224

25+
static Error validationFailed(const Twine &Msg) {
26+
return make_error<StringError>(Msg.str(), inconvertibleErrorCode());
27+
}
28+
2329
template <typename T>
2430
static Error readStruct(StringRef Buffer, const char *Src, T &Struct) {
2531
// Don't read before the beginning or past the end of the file
@@ -255,7 +261,8 @@ Error DirectX::RootSignature::parse(StringRef Data) {
255261
Current += sizeof(uint32_t);
256262

257263
if (!dxbc::RootSignatureValidations::isValidVersion(VValue))
258-
return make_error<GenericBinaryError>("Invalid Root Signature Version");
264+
return validationFailed("unsupported root signature version read: " +
265+
llvm::Twine(VValue));
259266
Version = VValue;
260267

261268
NumParameters =
@@ -279,7 +286,8 @@ Error DirectX::RootSignature::parse(StringRef Data) {
279286
Current += sizeof(uint32_t);
280287

281288
if (!dxbc::RootSignatureValidations::isValidRootFlag(FValue))
282-
return make_error<GenericBinaryError>("Invalid Root Signature flag");
289+
return validationFailed("unsupported root signature flag value read: " +
290+
llvm::Twine(FValue));
283291
Flags = FValue;
284292

285293
return Error::success();

llvm/lib/Target/DirectX/DXILRootSignature.cpp

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===- DXILRootSignature.cpp - DXIL Root Signature helper objects ----===//
1+
//===- DXILRootSignature.cpp - DXIL Root Signature helper objects -------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -68,8 +68,8 @@ static bool parseRootSignatureElement(LLVMContext *Ctx,
6868
case RootSignatureElementKind::RootFlags:
6969
return parseRootFlags(Ctx, MRS, Element);
7070
case RootSignatureElementKind::None:
71-
return reportError(Ctx,
72-
"Invalid Root Element: " + ElementText->getString());
71+
return reportError(Ctx, "Invalid Root Signature Element: " +
72+
ElementText->getString());
7373
}
7474

7575
llvm_unreachable("Root signature element kind not expected.");
@@ -78,20 +78,6 @@ static bool parseRootSignatureElement(LLVMContext *Ctx,
7878
static bool parse(LLVMContext *Ctx, ModuleRootSignature &MRS, MDNode *Node) {
7979
bool HasError = false;
8080

81-
/** Root Signature are specified as following in the metadata:
82-
83-
!dx.rootsignatures = !{!2} ; list of function/root signature pairs
84-
!2 = !{ ptr @main, !3 } ; function, root signature
85-
!3 = !{ !4, !5, !6, !7 } ; list of root signature elements
86-
87-
So for each MDNode inside dx.rootsignatures NamedMDNode
88-
(the Root parameter of this function), the parsing process needs
89-
to loop through each of its operands and process the function,
90-
signature pair.
91-
*/
92-
93-
// Get the Root Signature Description from the function signature pair.
94-
9581
// Loop through the Root Elements of the root signature.
9682
for (const auto &Operand : Node->operands()) {
9783
MDNode *Element = dyn_cast<MDNode>(Operand);
@@ -114,6 +100,18 @@ static bool validate(LLVMContext *Ctx, const ModuleRootSignature &MRS) {
114100
static SmallDenseMap<const Function *, ModuleRootSignature>
115101
analyzeModule(Module &M) {
116102

103+
/** Root Signature are specified as following in the metadata:
104+
105+
!dx.rootsignatures = !{!2} ; list of function/root signature pairs
106+
!2 = !{ ptr @main, !3 } ; function, root signature
107+
!3 = !{ !4, !5, !6, !7 } ; list of root signature elements
108+
109+
So for each MDNode inside dx.rootsignatures NamedMDNode
110+
(the Root parameter of this function), the parsing process needs
111+
to loop through each of its operands and process the function,
112+
signature pair.
113+
*/
114+
117115
LLVMContext *Ctx = &M.getContext();
118116

119117
SmallDenseMap<const Function *, ModuleRootSignature> MRSMap;
@@ -129,22 +127,22 @@ analyzeModule(Module &M) {
129127
continue;
130128
}
131129

130+
// Function was pruned during compilation.
132131
const MDOperand &FunctionPointerMdNode = RSDefNode->getOperand(0);
133132
if (FunctionPointerMdNode == nullptr) {
134-
// Function was pruned during compilation.
135133
continue;
136134
}
137135

138136
ValueAsMetadata *VAM =
139137
llvm::dyn_cast<ValueAsMetadata>(FunctionPointerMdNode.get());
140138
if (VAM == nullptr) {
141-
reportError(Ctx, "First element of root signature is not a value");
139+
reportError(Ctx, "First element of root signature is not a Value");
142140
continue;
143141
}
144142

145143
Function *F = dyn_cast<Function>(VAM->getValue());
146144
if (F == nullptr) {
147-
reportError(Ctx, "First element of root signature is not a function");
145+
reportError(Ctx, "First element of root signature is not a Function");
148146
continue;
149147
}
150148

llvm/lib/Target/DirectX/DXILRootSignature.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "llvm/IR/Module.h"
1919
#include "llvm/IR/PassManager.h"
2020
#include "llvm/Pass.h"
21-
#include <optional>
2221

2322
namespace llvm {
2423
namespace dxil {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
target triple = "dxil-unknown-shadermodel6.0-compute"
44

5-
; CHECK: error: Invalid Root Element: NOTRootFlags
5+
; CHECK: error: Invalid Root Signature Element: NOTRootFlags
66
; CHECK-NO: Root Signature Definitions
77

88

llvm/unittests/Object/DXContainerTest.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -870,8 +870,9 @@ TEST(RootSignature, ParseRootFlags) {
870870
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
871871
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
872872
};
873-
EXPECT_THAT_EXPECTED(DXContainer::create(getMemoryBuffer<68>(Buffer)),
874-
FailedWithMessage("Invalid Root Signature Version"));
873+
EXPECT_THAT_EXPECTED(
874+
DXContainer::create(getMemoryBuffer<100>(Buffer)),
875+
FailedWithMessage("unsupported root signature version read: 3"));
875876
}
876877
{
877878
// Flag has been set to an invalid value
@@ -883,7 +884,9 @@ TEST(RootSignature, ParseRootFlags) {
883884
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
884885
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xFF,
885886
};
886-
EXPECT_THAT_EXPECTED(DXContainer::create(getMemoryBuffer<68>(Buffer)),
887-
FailedWithMessage("Invalid Root Signature flag"));
887+
EXPECT_THAT_EXPECTED(
888+
DXContainer::create(getMemoryBuffer<100>(Buffer)),
889+
FailedWithMessage(
890+
"unsupported root signature flag value read: 4278190081"));
888891
}
889892
}

0 commit comments

Comments
 (0)