LLVM  15.0.0git
DXContainer.h
Go to the documentation of this file.
1 //===- DXContainer.h - DXContainer file implementation ----------*- C++ -*-===//
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 //
9 // This file declares the DXContainerFile class, which implements the ObjectFile
10 // interface for DXContainer files.
11 //
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_OBJECT_DXCONTAINER_H
16 #define LLVM_OBJECT_DXCONTAINER_H
17 
18 #include "llvm/ADT/Optional.h"
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/ADT/StringRef.h"
22 #include "llvm/Support/Error.h"
24 
25 namespace llvm {
26 namespace object {
27 class DXContainer {
28 public:
29  using DXILData = std::pair<dxbc::ProgramHeader, const char *>;
30 
31 private:
33 
34  MemoryBufferRef Data;
35  dxbc::Header Header;
36  SmallVector<uint32_t, 4> PartOffsets;
37  Optional<DXILData> DXIL;
38 
39  Error parseHeader();
40  Error parsePartOffsets();
41  Error parseDXILHeader(uint32_t Offset);
42  friend class PartIterator;
43 
44 public:
45  // The PartIterator is a wrapper around the iterator for the PartOffsets
46  // member of the DXContainer. It contains a refernce to the container, and the
47  // current iterator value, as well as storage for a parsed part header.
48  class PartIterator {
49  const DXContainer &Container;
51  struct PartData {
52  dxbc::PartHeader Part;
53  uint32_t Offset;
55  } IteratorState;
56 
57  friend class DXContainer;
58 
59  PartIterator(const DXContainer &C,
61  : Container(C), OffsetIt(It) {
62  if (OffsetIt == Container.PartOffsets.end())
63  updateIteratorImpl(Container.PartOffsets.back());
64  else
65  updateIterator();
66  }
67 
68  // Updates the iterator's state data. This results in copying the part
69  // header into the iterator and handling any required byte swapping. This is
70  // called when incrementing or decrementing the iterator.
71  void updateIterator() {
72  if (OffsetIt != Container.PartOffsets.end())
73  updateIteratorImpl(*OffsetIt);
74  }
75 
76  // Implementation for updating the iterator state based on a specified
77  // offest.
78  void updateIteratorImpl(const uint32_t Offset);
79 
80  public:
82  if (OffsetIt == Container.PartOffsets.end())
83  return *this;
84  ++OffsetIt;
85  updateIterator();
86  return *this;
87  }
88 
90  PartIterator Tmp = *this;
91  ++(*this);
92  return Tmp;
93  }
94 
95  bool operator==(const PartIterator &RHS) const {
96  return OffsetIt == RHS.OffsetIt;
97  }
98 
99  bool operator!=(const PartIterator &RHS) const {
100  return OffsetIt != RHS.OffsetIt;
101  }
102 
103  const PartData &operator*() { return IteratorState; }
104  const PartData *operator->() { return &IteratorState; }
105  };
106 
107  PartIterator begin() const {
108  return PartIterator(*this, PartOffsets.begin());
109  }
110 
111  PartIterator end() const { return PartIterator(*this, PartOffsets.end()); }
112 
113  StringRef getData() const { return Data.getBuffer(); }
115 
116  const dxbc::Header &getHeader() const { return Header; }
117 
118  Optional<DXILData> getDXIL() const { return DXIL; }
119 };
120 
121 } // namespace object
122 } // namespace llvm
123 
124 #endif // LLVM_OBJECT_DXCONTAINER_H
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
Optional.h
llvm::object::DXContainer::PartIterator
Definition: DXContainer.h:48
StringRef.h
llvm::SmallVector< uint32_t, 4 >
Error.h
MemoryBufferRef.h
llvm::object::DXContainer::PartIterator
friend class PartIterator
Definition: DXContainer.h:42
llvm::Optional< DXILData >
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:79
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
RHS
Value * RHS
Definition: X86PartialReduction.cpp:76
llvm::object::DXContainer::getHeader
const dxbc::Header & getHeader() const
Definition: DXContainer.h:116
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::MemoryBufferRef
Definition: MemoryBufferRef.h:22
llvm::object::DXContainer::PartIterator::operator==
bool operator==(const PartIterator &RHS) const
Definition: DXContainer.h:95
llvm::object::DXContainer::PartIterator::operator++
PartIterator & operator++()
Definition: DXContainer.h:81
llvm::dxbc::PartHeader
Use this type to describe the size and type of a DXIL container part.
Definition: DXContainer.h:83
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::object::DXContainer::create
static Expected< DXContainer > create(MemoryBufferRef Object)
Definition: DXContainer.cpp:93
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:240
object
bar al al movzbl eax ret Missed when stored in a memory object
Definition: README.txt:1411
llvm::object::DXContainer::DXILData
std::pair< dxbc::ProgramHeader, const char * > DXILData
Definition: DXContainer.h:29
DXContainer.h
llvm::object::DXContainer::end
PartIterator end() const
Definition: DXContainer.h:111
llvm::object::DXContainer::PartIterator::operator++
PartIterator operator++(int)
Definition: DXContainer.h:89
llvm::object::DXContainer::PartIterator::operator*
const PartData & operator*()
Definition: DXContainer.h:103
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::object::DXContainer::getDXIL
Optional< DXILData > getDXIL() const
Definition: DXContainer.h:118
uint32_t
llvm::object::DXContainer::PartIterator::operator->
const PartData * operator->()
Definition: DXContainer.h:104
llvm::object::DXContainer::PartIterator::operator!=
bool operator!=(const PartIterator &RHS) const
Definition: DXContainer.h:99
llvm::object::DXContainer
Definition: DXContainer.h:27
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::object::DXContainer::getData
StringRef getData() const
Definition: DXContainer.h:113
SmallVector.h
llvm::object::DXContainer::begin
PartIterator begin() const
Definition: DXContainer.h:107
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
llvm::dxbc::Header
Definition: DXContainer.h:66