Skip to content

Commit b9be921

Browse files
author
joaosaffran
committed
changing variant to host pointers
1 parent 62c0de2 commit b9be921

File tree

3 files changed

+31
-31
lines changed

3 files changed

+31
-31
lines changed

llvm/include/llvm/MC/DXContainerRootSignature.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
#include "llvm/ADT/STLForwardCompat.h"
1010
#include "llvm/BinaryFormat/DXContainer.h"
11-
#include "llvm/Support/ErrorHandling.h"
1211
#include <cstddef>
1312
#include <cstdint>
1413
#include <optional>
14+
#include <utility>
1515
#include <variant>
1616

1717
namespace llvm {
@@ -29,11 +29,11 @@ struct RootParameterInfo {
2929
: Header(H), Location(L) {}
3030
};
3131

32-
using RootDescriptor = std::variant<dxbc::RST0::v0::RootDescriptor,
33-
dxbc::RST0::v1::RootDescriptor>;
32+
using RootDescriptor = std::variant<dxbc::RST0::v0::RootDescriptor*,
33+
dxbc::RST0::v1::RootDescriptor*>;
3434
using ParametersView =
35-
std::variant<dxbc::RootConstants, dxbc::RST0::v0::RootDescriptor,
36-
dxbc::RST0::v1::RootDescriptor>;
35+
std::variant<const dxbc::RootConstants*, const dxbc::RST0::v0::RootDescriptor*,
36+
const dxbc::RST0::v1::RootDescriptor*>;
3737
struct RootParametersContainer {
3838
SmallVector<RootParameterInfo> ParametersInfo;
3939

@@ -52,27 +52,27 @@ struct RootParametersContainer {
5252
void addParameter(dxbc::RootParameterHeader H,
5353
dxbc::RST0::v0::RootDescriptor D) {
5454
addInfo(H, Descriptors.size());
55-
Descriptors.push_back(D);
55+
Descriptors.push_back(std::move(&D));
5656
}
5757

5858
void addParameter(dxbc::RootParameterHeader H,
5959
dxbc::RST0::v1::RootDescriptor D) {
6060
addInfo(H, Descriptors.size());
61-
Descriptors.push_back(D);
61+
Descriptors.push_back(std::move(&D));
6262
}
6363

6464
std::optional<ParametersView> getParameter(const RootParameterInfo *H) const {
6565
switch (H->Header.ParameterType) {
6666
case llvm::to_underlying(dxbc::RootParameterType::Constants32Bit):
67-
return Constants[H->Location];
67+
return &Constants[H->Location];
6868
case llvm::to_underlying(dxbc::RootParameterType::CBV):
6969
case llvm::to_underlying(dxbc::RootParameterType::SRV):
7070
case llvm::to_underlying(dxbc::RootParameterType::UAV):
7171
RootDescriptor VersionedParam = Descriptors[H->Location];
72-
if (std::holds_alternative<dxbc::RST0::v0::RootDescriptor>(
72+
if (std::holds_alternative<dxbc::RST0::v0::RootDescriptor*>(
7373
VersionedParam))
74-
return std::get<dxbc::RST0::v0::RootDescriptor>(VersionedParam);
75-
return std::get<dxbc::RST0::v1::RootDescriptor>(VersionedParam);
74+
return std::get<dxbc::RST0::v0::RootDescriptor*>(VersionedParam);
75+
return std::get<dxbc::RST0::v1::RootDescriptor*>(VersionedParam);
7676
}
7777

7878
return std::nullopt;

llvm/lib/MC/DXContainerRootSignature.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ size_t RootSignatureDesc::getSize() const {
4040
continue;
4141
std::visit(
4242
[&Size](auto &Value) -> void {
43-
using T = std::decay_t<decltype(Value)>;
43+
using T = std::decay_t<decltype(*Value)>;
4444
Size += sizeof(T);
4545
},
4646
*P);
@@ -80,28 +80,28 @@ void RootSignatureDesc::write(raw_ostream &OS) const {
8080
auto P = ParametersContainer.getParameter(H);
8181
if (!P)
8282
continue;
83-
if (std::holds_alternative<dxbc::RootConstants>(*P)) {
84-
auto Constants = std::get<dxbc::RootConstants>(*P);
85-
support::endian::write(BOS, Constants.ShaderRegister,
83+
if (std::holds_alternative<const dxbc::RootConstants*>(*P)) {
84+
auto* Constants = std::get<const dxbc::RootConstants*>(*P);
85+
support::endian::write(BOS, Constants->ShaderRegister,
8686
llvm::endianness::little);
87-
support::endian::write(BOS, Constants.RegisterSpace,
87+
support::endian::write(BOS, Constants->RegisterSpace,
8888
llvm::endianness::little);
89-
support::endian::write(BOS, Constants.Num32BitValues,
89+
support::endian::write(BOS, Constants->Num32BitValues,
9090
llvm::endianness::little);
91-
} else if (std::holds_alternative<dxbc::RST0::v0::RootDescriptor>(*P)) {
92-
auto Descriptor = std::get<dxbc::RST0::v0::RootDescriptor>(*P);
93-
support::endian::write(BOS, Descriptor.ShaderRegister,
91+
} else if (std::holds_alternative<const dxbc::RST0::v0::RootDescriptor*>(*P)) {
92+
auto* Descriptor = std::get<const dxbc::RST0::v0::RootDescriptor*>(*P);
93+
support::endian::write(BOS, Descriptor->ShaderRegister,
9494
llvm::endianness::little);
95-
support::endian::write(BOS, Descriptor.RegisterSpace,
95+
support::endian::write(BOS, Descriptor->RegisterSpace,
9696
llvm::endianness::little);
97-
} else if (std::holds_alternative<dxbc::RST0::v1::RootDescriptor>(*P)) {
98-
auto Descriptor = std::get<dxbc::RST0::v1::RootDescriptor>(*P);
97+
} else if (std::holds_alternative<const dxbc::RST0::v1::RootDescriptor*>(*P)) {
98+
auto* Descriptor = std::get<const dxbc::RST0::v1::RootDescriptor*>(*P);
9999

100-
support::endian::write(BOS, Descriptor.ShaderRegister,
100+
support::endian::write(BOS, Descriptor->ShaderRegister,
101101
llvm::endianness::little);
102-
support::endian::write(BOS, Descriptor.RegisterSpace,
102+
support::endian::write(BOS, Descriptor->RegisterSpace,
103103
llvm::endianness::little);
104-
support::endian::write(BOS, Descriptor.Flags, llvm::endianness::little);
104+
support::endian::write(BOS, Descriptor->Flags, llvm::endianness::little);
105105
}
106106
}
107107
assert(Storage.size() == getSize());

llvm/lib/Target/DirectX/DXILRootSignature.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,14 +301,14 @@ PreservedAnalyses RootSignatureAnalysisPrinter::run(Module &M,
301301
RS.ParametersContainer.getParameter(&Info);
302302
if (!P)
303303
continue;
304-
if (std::holds_alternative<dxbc::RootConstants>(*P)) {
305-
auto Constants = std::get<dxbc::RootConstants>(*P);
306-
OS << indent(Space + 2) << "Register Space: " << Constants.RegisterSpace
304+
if (std::holds_alternative<const dxbc::RootConstants*>(*P)) {
305+
auto* Constants = std::get<const dxbc::RootConstants*>(*P);
306+
OS << indent(Space + 2) << "Register Space: " << Constants->RegisterSpace
307307
<< "\n";
308308
OS << indent(Space + 2)
309-
<< "Shader Register: " << Constants.ShaderRegister << "\n";
309+
<< "Shader Register: " << Constants->ShaderRegister << "\n";
310310
OS << indent(Space + 2)
311-
<< "Num 32 Bit Values: " << Constants.Num32BitValues << "\n";
311+
<< "Num 32 Bit Values: " << Constants->Num32BitValues << "\n";
312312
}
313313
}
314314
Space--;

0 commit comments

Comments
 (0)