LLVM 23.0.0git
DXContainer.cpp
Go to the documentation of this file.
1//===- DXContainer.cpp - DXContainer object file implementation -----------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
11#include "llvm/Object/Error.h"
12#include "llvm/Support/Endian.h"
15
16using namespace llvm;
17using namespace llvm::object;
18
22
23static bool readIsOutOfBounds(StringRef Buffer, const char *Src, size_t Size) {
24 return Src < Buffer.begin() || Src + Size > Buffer.end();
25}
26
27template <typename T>
28static Error readStruct(StringRef Buffer, const char *Src, T &Struct) {
29 // Don't read before the beginning or past the end of the file
30 if (readIsOutOfBounds(Buffer, Src, sizeof(T)))
31 return parseFailed("Reading structure out of file bounds");
32
33 memcpy(&Struct, Src, sizeof(T));
34 // DXContainer is always little endian
36 Struct.swapBytes();
37 return Error::success();
38}
39
40template <typename T>
41static Error readInteger(StringRef Buffer, const char *Src, T &Val,
42 Twine Str = "structure") {
43 static_assert(std::is_integral_v<T>,
44 "Cannot call readInteger on non-integral type.");
45 // Don't read before the beginning or past the end of the file
46 if (readIsOutOfBounds(Buffer, Src, sizeof(T)))
47 return parseFailed(Twine("Reading ") + Str + " out of file bounds");
48
49 // The DXContainer offset table is comprised of uint32_t values but not padded
50 // to a 64-bit boundary. So Parts may start unaligned if there is an odd
51 // number of parts and part data itself is not required to be padded.
52 if (reinterpret_cast<uintptr_t>(Src) % alignof(T) != 0)
53 memcpy(reinterpret_cast<char *>(&Val), Src, sizeof(T));
54 else
55 Val = *reinterpret_cast<const T *>(Src);
56 // DXContainer is always little endian
59 return Error::success();
60}
61
62static Error readString(StringRef Buffer, const char *&Src, size_t MaxSize,
63 StringRef &Val, Twine Desc) {
64 if (readIsOutOfBounds(Buffer, Src, MaxSize))
65 return parseFailed(Desc + " is out of file bounds");
66
67 // Ensure that the null-terminator is somewhere within MaxSize bytes.
68 Buffer = Buffer.substr(Src - Buffer.data(), MaxSize);
69 size_t Length = Buffer.find('\0');
70 if (Length == Buffer.npos)
71 return parseFailed(Desc + " does not end with null-terminator");
72
73 Val = StringRef(Buffer.data(), Length);
74 Src += Length + 1;
75 return Error::success();
76}
77
78DXContainer::DXContainer(MemoryBufferRef O) : Data(O) {}
79
80Error DXContainer::parseHeader() {
81 return readStruct(Data.getBuffer(), Data.getBuffer().data(), Header);
82}
83
84Error DXContainer::parseDXILHeader(dxbc::PartType PT, StringRef Part) {
85 bool IsDebug = dxbc::isDebugProgramPart(PT);
86 std::optional<DXILData> &DXIL = IsDebug ? this->DebugDXIL : this->DXIL;
87
88 if (DXIL)
89 return parseFailed(formatv("more than one {0} part is present in the file",
90 dxbc::getProgramPartName(IsDebug)));
91 const char *Current = Part.begin();
92 dxbc::ProgramHeader Header;
93 if (Error Err = readStruct(Part, Current, Header))
94 return Err;
95 Current += offsetof(dxbc::ProgramHeader, Bitcode) + Header.Bitcode.Offset;
96 DXIL.emplace(std::make_pair(Header, Current));
97 return Error::success();
98}
99
100Error DXContainer::parseDebugName(StringRef Part) {
101 if (DebugName)
102 return parseFailed("more than one ILDN part is present in the file");
103 const char *Current = Part.begin();
104 dxbc::DebugNameHeader Header;
105 if (Error Err = readStruct(Part, Current, Header))
106 return Err;
107 Current += sizeof(Header);
108
109 StringRef Name;
110 if (Error Err = readString(Part, Current, Header.NameLength + 1, Name,
111 "debug file name"))
112 return Err;
113 if (Name.size() != Header.NameLength)
114 return parseFailed("debug file name length mismatch");
115 DebugName.emplace(Header, Name.data());
116
117 return Error::success();
118}
119
120Error DXContainer::parseShaderFeatureFlags(StringRef Part) {
121 if (ShaderFeatureFlags)
122 return parseFailed("More than one SFI0 part is present in the file");
123 uint64_t FlagValue = 0;
124 if (Error Err = readInteger(Part, Part.begin(), FlagValue))
125 return Err;
126 ShaderFeatureFlags = FlagValue;
127 return Error::success();
128}
129
130Error DXContainer::parseHash(StringRef Part) {
131 if (Hash)
132 return parseFailed("More than one HASH part is present in the file");
133 dxbc::ShaderHash ReadHash;
134 if (Error Err = readStruct(Part, Part.begin(), ReadHash))
135 return Err;
136 Hash = ReadHash;
137 return Error::success();
138}
139
140Error DXContainer::parseRootSignature(StringRef Part) {
141 if (RootSignature)
142 return parseFailed("More than one RTS0 part is present in the file");
143 RootSignature = DirectX::RootSignature(Part);
144 if (Error Err = RootSignature->parse())
145 return Err;
146 return Error::success();
147}
148
149Error DXContainer::parsePSVInfo(StringRef Part) {
150 if (PSVInfo)
151 return parseFailed("More than one PSV0 part is present in the file");
152 PSVInfo = DirectX::PSVRuntimeInfo(Part);
153 // Parsing the PSVRuntime info occurs late because we need to read data from
154 // other parts first.
155 return Error::success();
156}
157
160 if (Error Err = readStruct(Part, Part.begin(), SigHeader))
161 return Err;
162 size_t Size = sizeof(dxbc::ProgramSignatureElement) * SigHeader.ParamCount;
163
164 if (Part.size() < Size + SigHeader.FirstParamOffset)
165 return parseFailed("Signature parameters extend beyond the part boundary");
166
167 Parameters.Data = Part.substr(SigHeader.FirstParamOffset, Size);
168
169 StringTableOffset = SigHeader.FirstParamOffset + static_cast<uint32_t>(Size);
170 StringTable = Part.substr(SigHeader.FirstParamOffset + Size);
171
172 for (const auto &Param : Parameters) {
173 if (Param.NameOffset < StringTableOffset)
174 return parseFailed("Invalid parameter name offset: name starts before "
175 "the first name offset");
176 if (Param.NameOffset - StringTableOffset > StringTable.size())
177 return parseFailed("Invalid parameter name offset: name starts after the "
178 "end of the part data");
179 }
180 return Error::success();
181}
182
183Error DXContainer::parsePartOffsets() {
184 uint32_t LastOffset =
185 sizeof(dxbc::Header) + (Header.PartCount * sizeof(uint32_t));
186 const char *Current = Data.getBuffer().data() + sizeof(dxbc::Header);
187 for (uint32_t Part = 0; Part < Header.PartCount; ++Part) {
188 uint32_t PartOffset;
189 if (Error Err = readInteger(Data.getBuffer(), Current, PartOffset))
190 return Err;
191 if (PartOffset < LastOffset)
192 return parseFailed(
193 formatv(
194 "Part offset for part {0} begins before the previous part ends",
195 Part)
196 .str());
197 Current += sizeof(uint32_t);
198 if (PartOffset >= Data.getBufferSize())
199 return parseFailed("Part offset points beyond boundary of the file");
200 // To prevent overflow when reading the part name, we subtract the part name
201 // size from the buffer size, rather than adding to the offset. Since the
202 // file header is larger than the part header we can't reach this code
203 // unless the buffer is at least as large as a part header, so this
204 // subtraction can't underflow.
205 if (PartOffset >= Data.getBufferSize() - sizeof(dxbc::PartHeader::Name))
206 return parseFailed("File not large enough to read part name");
207 PartOffsets.push_back(PartOffset);
208
209 dxbc::PartType PT =
210 dxbc::parsePartType(Data.getBuffer().substr(PartOffset, 4));
211 uint32_t PartDataStart = PartOffset + sizeof(dxbc::PartHeader);
212 uint32_t PartSize;
213 if (Error Err = readInteger(Data.getBuffer(),
214 Data.getBufferStart() + PartOffset + 4,
215 PartSize, "part size"))
216 return Err;
217 StringRef PartData = Data.getBuffer().substr(PartDataStart, PartSize);
218 LastOffset = PartOffset + PartSize;
219 switch (PT) {
220 case dxbc::PartType::DXIL:
221 case dxbc::PartType::ILDB:
222 if (Error Err = parseDXILHeader(PT, PartData))
223 return Err;
224 break;
225 case dxbc::PartType::ILDN:
226 if (Error Err = parseDebugName(PartData))
227 return Err;
228 break;
229 case dxbc::PartType::SFI0:
230 if (Error Err = parseShaderFeatureFlags(PartData))
231 return Err;
232 break;
233 case dxbc::PartType::HASH:
234 if (Error Err = parseHash(PartData))
235 return Err;
236 break;
237 case dxbc::PartType::PSV0:
238 if (Error Err = parsePSVInfo(PartData))
239 return Err;
240 break;
241 case dxbc::PartType::ISG1:
242 if (Error Err = InputSignature.initialize(PartData))
243 return Err;
244 break;
245 case dxbc::PartType::OSG1:
246 if (Error Err = OutputSignature.initialize(PartData))
247 return Err;
248 break;
249 case dxbc::PartType::PSG1:
250 if (Error Err = PatchConstantSignature.initialize(PartData))
251 return Err;
252 break;
254 break;
255 case dxbc::PartType::RTS0:
256 if (Error Err = parseRootSignature(PartData))
257 return Err;
258 break;
259 }
260 }
261
262 if (DXIL && DebugDXIL &&
263 DXIL->first.ShaderKind != DebugDXIL->first.ShaderKind)
264 return parseFailed(
265 "ILDB part shader kind does not match DXIL part shader kind");
266
267 // Fully parsing the PSVInfo requires knowing the shader kind which we read
268 // out of the program header in the DXIL part.
269 if (PSVInfo) {
270 std::optional<uint16_t> ShaderKind = getShaderKind();
271 if (!ShaderKind)
272 return parseFailed("cannot fully parse pipeline state validation "
273 "information without DXIL or ILDB part");
274 if (Error Err = PSVInfo->parse(*ShaderKind))
275 return Err;
276 }
277 return Error::success();
278}
279
281 DXContainer Container(Object);
282 if (Error Err = Container.parseHeader())
283 return std::move(Err);
284 if (Error Err = Container.parsePartOffsets())
285 return std::move(Err);
286 return Container;
287}
288
289void DXContainer::PartIterator::updateIteratorImpl(const uint32_t Offset) {
290 StringRef Buffer = Container.Data.getBuffer();
291 const char *Current = Buffer.data() + Offset;
292 // Offsets are validated during parsing, so all offsets in the container are
293 // valid and contain enough readable data to read a header.
294 cantFail(readStruct(Buffer, Current, IteratorState.Part));
295 IteratorState.Data =
296 StringRef(Current + sizeof(dxbc::PartHeader), IteratorState.Part.Size);
297 IteratorState.Offset = Offset;
298}
299
301 const char *Current = PartData.begin();
302
303 // Root Signature headers expects 6 integers to be present.
304 if (PartData.size() < 6 * sizeof(uint32_t))
305 return parseFailed(
306 "Invalid root signature, insufficient space for header.");
307
309 Current += sizeof(uint32_t);
310
311 NumParameters =
313 Current += sizeof(uint32_t);
314
315 RootParametersOffset =
317 Current += sizeof(uint32_t);
318
319 NumStaticSamplers =
321 Current += sizeof(uint32_t);
322
323 StaticSamplersOffset =
325 Current += sizeof(uint32_t);
326
328 Current += sizeof(uint32_t);
329
330 ParametersHeaders.Data = PartData.substr(
331 RootParametersOffset,
332 NumParameters * sizeof(dxbc::RTS0::v1::RootParameterHeader));
333
334 StaticSamplers.Stride = (Version <= 2)
337
338 StaticSamplers.Data = PartData.substr(StaticSamplersOffset,
339 static_cast<size_t>(NumStaticSamplers) *
340 StaticSamplers.Stride);
341
342 return Error::success();
343}
344
346 Triple::EnvironmentType ShaderStage = dxbc::getShaderStage(ShaderKind);
347
348 const char *Current = Data.begin();
349 if (Error Err = readInteger(Data, Current, Size))
350 return Err;
351 Current += sizeof(uint32_t);
352
353 StringRef PSVInfoData = Data.substr(sizeof(uint32_t), Size);
354
355 if (PSVInfoData.size() < Size)
356 return parseFailed(
357 "Pipeline state data extends beyond the bounds of the part");
358
359 using namespace dxbc::PSV;
360
361 const uint32_t PSVVersion = getVersion();
362
363 // Detect the PSVVersion by looking at the size field.
364 if (PSVVersion == 3) {
365 v3::RuntimeInfo Info;
366 if (Error Err = readStruct(PSVInfoData, Current, Info))
367 return Err;
369 Info.swapBytes(ShaderStage);
370 BasicInfo = Info;
371 } else if (PSVVersion == 2) {
372 v2::RuntimeInfo Info;
373 if (Error Err = readStruct(PSVInfoData, Current, Info))
374 return Err;
376 Info.swapBytes(ShaderStage);
377 BasicInfo = Info;
378 } else if (PSVVersion == 1) {
379 v1::RuntimeInfo Info;
380 if (Error Err = readStruct(PSVInfoData, Current, Info))
381 return Err;
383 Info.swapBytes(ShaderStage);
384 BasicInfo = Info;
385 } else if (PSVVersion == 0) {
386 v0::RuntimeInfo Info;
387 if (Error Err = readStruct(PSVInfoData, Current, Info))
388 return Err;
390 Info.swapBytes(ShaderStage);
391 BasicInfo = Info;
392 } else
393 return parseFailed(
394 "Cannot read PSV Runtime Info, unsupported PSV version.");
395
396 Current += Size;
397
398 uint32_t ResourceCount = 0;
399 if (Error Err = readInteger(Data, Current, ResourceCount))
400 return Err;
401 Current += sizeof(uint32_t);
402
403 if (ResourceCount > 0) {
404 if (Error Err = readInteger(Data, Current, Resources.Stride))
405 return Err;
406 Current += sizeof(uint32_t);
407
408 size_t BindingDataSize = Resources.Stride * ResourceCount;
409 Resources.Data = Data.substr(Current - Data.begin(), BindingDataSize);
410
411 if (Resources.Data.size() < BindingDataSize)
412 return parseFailed(
413 "Resource binding data extends beyond the bounds of the part");
414
415 Current += BindingDataSize;
416 } else
417 Resources.Stride = sizeof(v2::ResourceBindInfo);
418
419 // PSV version 0 ends after the resource bindings.
420 if (PSVVersion == 0)
421 return Error::success();
422
423 // String table starts at a 4-byte offset.
424 Current = reinterpret_cast<const char *>(
425 alignTo<4>(reinterpret_cast<uintptr_t>(Current)));
426
427 uint32_t StringTableSize = 0;
428 if (Error Err = readInteger(Data, Current, StringTableSize))
429 return Err;
430 if (StringTableSize % 4 != 0)
431 return parseFailed("String table misaligned");
432 Current += sizeof(uint32_t);
433 StringTable = StringRef(Current, StringTableSize);
434
435 Current += StringTableSize;
436
437 uint32_t SemanticIndexTableSize = 0;
438 if (Error Err = readInteger(Data, Current, SemanticIndexTableSize))
439 return Err;
440 Current += sizeof(uint32_t);
441
442 SemanticIndexTable.reserve(SemanticIndexTableSize);
443 for (uint32_t I = 0; I < SemanticIndexTableSize; ++I) {
444 uint32_t Index = 0;
445 if (Error Err = readInteger(Data, Current, Index))
446 return Err;
447 Current += sizeof(uint32_t);
448 SemanticIndexTable.push_back(Index);
449 }
450
451 uint8_t InputCount = getSigInputCount();
452 uint8_t OutputCount = getSigOutputCount();
453 uint8_t PatchOrPrimCount = getSigPatchOrPrimCount();
454
455 uint32_t ElementCount = InputCount + OutputCount + PatchOrPrimCount;
456
457 if (ElementCount > 0) {
458 if (Error Err = readInteger(Data, Current, SigInputElements.Stride))
459 return Err;
460 Current += sizeof(uint32_t);
461 // Assign the stride to all the arrays.
462 SigOutputElements.Stride = SigPatchOrPrimElements.Stride =
463 SigInputElements.Stride;
464
465 if (Data.end() - Current <
466 (ptrdiff_t)(ElementCount * SigInputElements.Stride))
467 return parseFailed(
468 "Signature elements extend beyond the size of the part");
469
470 size_t InputSize = SigInputElements.Stride * InputCount;
471 SigInputElements.Data = Data.substr(Current - Data.begin(), InputSize);
472 Current += InputSize;
473
474 size_t OutputSize = SigOutputElements.Stride * OutputCount;
475 SigOutputElements.Data = Data.substr(Current - Data.begin(), OutputSize);
476 Current += OutputSize;
477
478 size_t PSize = SigPatchOrPrimElements.Stride * PatchOrPrimCount;
479 SigPatchOrPrimElements.Data = Data.substr(Current - Data.begin(), PSize);
480 Current += PSize;
481 }
482
483 ArrayRef<uint8_t> OutputVectorCounts = getOutputVectorCounts();
484 uint8_t PatchConstOrPrimVectorCount = getPatchConstOrPrimVectorCount();
485 uint8_t InputVectorCount = getInputVectorCount();
486
487 auto maskDwordSize = [](uint8_t Vector) {
488 return (static_cast<uint32_t>(Vector) + 7) >> 3;
489 };
490
491 auto mapTableSize = [maskDwordSize](uint8_t X, uint8_t Y) {
492 return maskDwordSize(Y) * X * 4;
493 };
494
495 if (usesViewID()) {
496 for (uint32_t I = 0; I < OutputVectorCounts.size(); ++I) {
497 // The vector mask is one bit per component and 4 components per vector.
498 // We can compute the number of dwords required by rounding up to the next
499 // multiple of 8.
500 uint32_t NumDwords =
501 maskDwordSize(static_cast<uint32_t>(OutputVectorCounts[I]));
502 size_t NumBytes = NumDwords * sizeof(uint32_t);
503 OutputVectorMasks[I].Data = Data.substr(Current - Data.begin(), NumBytes);
504 Current += NumBytes;
505 }
506
507 if (ShaderStage == Triple::Hull && PatchConstOrPrimVectorCount > 0) {
508 uint32_t NumDwords = maskDwordSize(PatchConstOrPrimVectorCount);
509 size_t NumBytes = NumDwords * sizeof(uint32_t);
510 PatchOrPrimMasks.Data = Data.substr(Current - Data.begin(), NumBytes);
511 Current += NumBytes;
512 }
513 }
514
515 // Input/Output mapping table
516 for (uint32_t I = 0; I < OutputVectorCounts.size(); ++I) {
517 if (InputVectorCount == 0 || OutputVectorCounts[I] == 0)
518 continue;
519 uint32_t NumDwords = mapTableSize(InputVectorCount, OutputVectorCounts[I]);
520 size_t NumBytes = NumDwords * sizeof(uint32_t);
521 InputOutputMap[I].Data = Data.substr(Current - Data.begin(), NumBytes);
522 Current += NumBytes;
523 }
524
525 // Hull shader: Input/Patch mapping table
526 if (ShaderStage == Triple::Hull && PatchConstOrPrimVectorCount > 0 &&
527 InputVectorCount > 0) {
528 uint32_t NumDwords =
529 mapTableSize(InputVectorCount, PatchConstOrPrimVectorCount);
530 size_t NumBytes = NumDwords * sizeof(uint32_t);
531 InputPatchMap.Data = Data.substr(Current - Data.begin(), NumBytes);
532 Current += NumBytes;
533 }
534
535 // Domain Shader: Patch/Output mapping table
536 if (ShaderStage == Triple::Domain && PatchConstOrPrimVectorCount > 0 &&
537 OutputVectorCounts[0] > 0) {
538 uint32_t NumDwords =
539 mapTableSize(PatchConstOrPrimVectorCount, OutputVectorCounts[0]);
540 size_t NumBytes = NumDwords * sizeof(uint32_t);
541 PatchOutputMap.Data = Data.substr(Current - Data.begin(), NumBytes);
542 Current += NumBytes;
543 }
544
545 return Error::success();
546}
547
549 if (const auto *P = std::get_if<dxbc::PSV::v3::RuntimeInfo>(&BasicInfo))
550 return P->SigInputElements;
551 if (const auto *P = std::get_if<dxbc::PSV::v2::RuntimeInfo>(&BasicInfo))
552 return P->SigInputElements;
553 if (const auto *P = std::get_if<dxbc::PSV::v1::RuntimeInfo>(&BasicInfo))
554 return P->SigInputElements;
555 return 0;
556}
557
559 if (const auto *P = std::get_if<dxbc::PSV::v3::RuntimeInfo>(&BasicInfo))
560 return P->SigOutputElements;
561 if (const auto *P = std::get_if<dxbc::PSV::v2::RuntimeInfo>(&BasicInfo))
562 return P->SigOutputElements;
563 if (const auto *P = std::get_if<dxbc::PSV::v1::RuntimeInfo>(&BasicInfo))
564 return P->SigOutputElements;
565 return 0;
566}
567
569 if (const auto *P = std::get_if<dxbc::PSV::v3::RuntimeInfo>(&BasicInfo))
570 return P->SigPatchOrPrimElements;
571 if (const auto *P = std::get_if<dxbc::PSV::v2::RuntimeInfo>(&BasicInfo))
572 return P->SigPatchOrPrimElements;
573 if (const auto *P = std::get_if<dxbc::PSV::v1::RuntimeInfo>(&BasicInfo))
574 return P->SigPatchOrPrimElements;
575 return 0;
576}
577
578class DXNotSupportedError : public ErrorInfo<DXNotSupportedError> {
579public:
580 static char ID;
581
582 DXNotSupportedError(StringRef S) : FeatureString(S) {}
583
584 void log(raw_ostream &OS) const override {
585 OS << "DXContainer does not support " << FeatureString;
586 }
587
588 std::error_code convertToErrorCode() const override {
589 return inconvertibleErrorCode();
590 }
591
592private:
593 StringRef FeatureString;
594};
595
597
598Expected<section_iterator>
602
606
611
613 llvm_unreachable("DXContainer does not support symbols");
614}
617 llvm_unreachable("DXContainer does not support symbols");
618}
619
624
626 PartIterator It = reinterpret_cast<PartIterator>(Sec.p);
627 if (It == Parts.end())
628 return;
629
630 ++It;
631 Sec.p = reinterpret_cast<uintptr_t>(It);
632}
633
636 PartIterator It = reinterpret_cast<PartIterator>(Sec.p);
637 return StringRef(It->Part.getName());
638}
639
641 PartIterator It = reinterpret_cast<PartIterator>(Sec.p);
642 return It->Offset;
643}
644
646 return (Sec.p - reinterpret_cast<uintptr_t>(Parts.begin())) /
647 sizeof(PartIterator);
648}
649
651 PartIterator It = reinterpret_cast<PartIterator>(Sec.p);
652 return It->Data.size();
653}
656 PartIterator It = reinterpret_cast<PartIterator>(Sec.p);
657 return ArrayRef<uint8_t>(It->Data.bytes_begin(), It->Data.size());
658}
659
663
665 return false;
666}
667
669 return false;
670}
671
673 return false;
674}
675
677 return false;
678}
679
681 return false;
682}
683
688
693
695 llvm_unreachable("DXContainer does not support relocations");
696}
697
699 llvm_unreachable("DXContainer does not support relocations");
700}
701
706
708 llvm_unreachable("DXContainer does not support relocations");
709}
710
712 DataRefImpl Rel, SmallVectorImpl<char> &Result) const {
713 llvm_unreachable("DXContainer does not support relocations");
714}
715
717 DataRefImpl Sec;
718 Sec.p = reinterpret_cast<uintptr_t>(Parts.begin());
719 return section_iterator(SectionRef(Sec, this));
720}
722 DataRefImpl Sec;
723 Sec.p = reinterpret_cast<uintptr_t>(Parts.end());
724 return section_iterator(SectionRef(Sec, this));
725}
726
728
730 return "DirectX Container";
731}
732
734
738
743
748
751 auto ExC = DXContainer::create(Object);
752 if (!ExC)
753 return ExC.takeError();
754 std::unique_ptr<DXContainerObjectFile> Obj(new DXContainerObjectFile(*ExC));
755 return std::move(Obj);
756}
#define X(NUM, ENUM, NAME)
Definition ELF.h:853
write Write Bitcode
#define offsetof(TYPE, MEMBER)
#define I(x, y, z)
Definition MD5.cpp:57
#define T
static Error readString(StringRef Buffer, const char *&Src, size_t MaxSize, StringRef &Val, Twine Desc)
static Error parseFailed(const Twine &Msg)
static Error readStruct(StringRef Buffer, const char *Src, T &Struct)
static bool readIsOutOfBounds(StringRef Buffer, const char *Src, size_t Size)
static Error readInteger(StringRef Buffer, const char *Src, T &Val, Twine Str="structure")
#define P(N)
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
DXNotSupportedError(StringRef S)
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
size_t size() const
Get the array size.
Definition ArrayRef.h:141
Base class for user error types.
Definition Error.h:354
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
static ErrorSuccess success()
Create a success value.
Definition Error.h:336
Tagged union holding either a T or a Error.
Definition Error.h:485
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
static constexpr size_t npos
Definition StringRef.h:58
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition StringRef.h:591
iterator begin() const
Definition StringRef.h:114
constexpr size_t size() const
Get the string size.
Definition StringRef.h:144
constexpr const char * data() const
Get a pointer to the start of the string (which may not be null terminated).
Definition StringRef.h:138
iterator end() const
Definition StringRef.h:116
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
Definition StringRef.h:290
Manages the enabling and disabling of subtarget specific features.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
LLVM_ABI std::string str() const
Return the twine contents as a std::string.
Definition Twine.cpp:17
Expected< SymbolRef::Type > getSymbolType(DataRefImpl Symb) const override
uint64_t getRelocationOffset(DataRefImpl Rel) const override
uint64_t getSectionSize(DataRefImpl Sec) const override
relocation_iterator section_rel_begin(DataRefImpl Sec) const override
Triple::ArchType getArch() const override
bool isSectionCompressed(DataRefImpl Sec) const override
section_iterator section_end() const override
void getRelocationTypeName(DataRefImpl Rel, SmallVectorImpl< char > &Result) const override
uint64_t getSectionIndex(DataRefImpl Sec) const override
Expected< section_iterator > getSymbolSection(DataRefImpl Symb) const override
Expected< StringRef > getSectionName(DataRefImpl Sec) const override
uint64_t getSectionAddress(DataRefImpl Sec) const override
Expected< ArrayRef< uint8_t > > getSectionContents(DataRefImpl Sec) const override
section_iterator section_begin() const override
bool isSectionVirtual(DataRefImpl Sec) const override
void moveRelocationNext(DataRefImpl &Rel) const override
relocation_iterator section_rel_end(DataRefImpl Sec) const override
void moveSectionNext(DataRefImpl &Sec) const override
bool isSectionData(DataRefImpl Sec) const override
symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override
StringRef getFileFormatName() const override
uint64_t getSectionAlignment(DataRefImpl Sec) const override
Error printSymbolName(raw_ostream &OS, DataRefImpl Symb) const override
uint8_t getBytesInAddress() const override
The number of bytes used to represent an address in this object file format.
uint64_t getRelocationType(DataRefImpl Rel) const override
Expected< uint64_t > getSymbolAddress(DataRefImpl Symb) const override
bool isSectionBSS(DataRefImpl Sec) const override
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override
uint64_t getSymbolValueImpl(DataRefImpl Symb) const override
Expected< uint32_t > getSymbolFlags(DataRefImpl Symb) const override
bool isSectionText(DataRefImpl Sec) const override
Expected< SubtargetFeatures > getFeatures() const override
Expected< StringRef > getSymbolName(DataRefImpl) const override
static LLVM_ABI Expected< DXContainer > create(MemoryBufferRef Object)
ArrayRef< uint8_t > getOutputVectorCounts() const
LLVM_ABI uint8_t getSigInputCount() const
LLVM_ABI uint8_t getSigPatchOrPrimCount() const
LLVM_ABI Error parse(uint16_t ShaderKind)
LLVM_ABI uint8_t getSigOutputCount() const
LLVM_ABI Error initialize(StringRef Part)
static Expected< std::unique_ptr< DXContainerObjectFile > > createDXContainerObjectFile(MemoryBufferRef Object)
friend class RelocationRef
Definition ObjectFile.h:289
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVM_ABI PartType parsePartType(StringRef S)
Triple::EnvironmentType getShaderStage(uint32_t Kind)
Definition DXContainer.h:47
bool isDebugProgramPart(PartType PT)
const char * getProgramPartName(bool IsDebug)
static Error parseFailed(const Twine &Msg)
content_iterator< SectionRef > section_iterator
Definition ObjectFile.h:49
content_iterator< RelocationRef > relocation_iterator
Definition ObjectFile.h:79
value_type read(const void *memory, endianness endian)
Read a value of a particular endianness from memory.
Definition Endian.h:60
constexpr bool IsBigEndianHost
void swapByteOrder(T &Value)
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:557
@ Length
Definition DWP.cpp:557
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition Error.cpp:94
Op::Description Desc
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition Alignment.h:144
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
Definition Error.h:340
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition Error.h:769
FunctionAddr VTableAddr uintptr_t uintptr_t Data
Definition InstrProf.h:221
Use this type to describe the size and type of a DXIL container part.
Definition DXContainer.h:99