30#ifndef LLVM_BITCODE_BITCODECONVENIENCE_H
31#define LLVM_BITCODE_BITCODECONVENIENCE_H
43template <
bool Compound = false>
class BCField {
52 template <
typename T>
static T convert(
T rawValue) {
return rawValue; }
71 assert(data ==
Value &&
"data value does not match declared literal value");
80 static_assert(Width <= 64,
"fixed-width field is too large");
87 assert(llvm::isUInt<Width>(data) &&
88 "data value does not fit in the given bit width");
92 assert(data >= 0 &&
"cannot encode signed integers");
93 assert(llvm::isUInt<Width>(data) &&
94 "data value does not fit in the given bit width");
104 static_assert(Width >= 2,
"width does not have room for continuation bit");
112 assert(data >= 0 &&
"cannot encode signed integers");
133 return static_cast<char>(rawValue);
151 static_assert(!ElementTy::IsCompound,
"arrays can only contain scalar types");
156 ElementTy::emitOp(abbrev);
167 FieldTy::emitOp(abbrev);
175template <
typename FieldTy,
typename Next,
typename... Rest>
177 static_assert(!FieldTy::IsCompound,
178 "arrays and blobs may not appear in the middle of a record");
179 FieldTy::emitOp(abbrev);
180 emitOps<Next, Rest...>(abbrev);
188 template <
typename BufferTy,
typename ElementDataTy,
typename... DataTy>
190 unsigned code, ElementDataTy element, DataTy &&...data) {
191 static_assert(!ElementTy::IsCompound,
192 "arrays and blobs may not appear in the middle of a record");
193 ElementTy::assertValid(element);
194 buffer.push_back(element);
196 std::forward<DataTy>(data)...);
199 template <
typename T,
typename ElementDataTy,
typename... DataTy>
202 assert(!buffer.
empty() &&
"too few elements in buffer");
203 element = ElementTy::convert(buffer.
front());
205 std::forward<DataTy>(data)...);
208 template <
typename T,
typename... DataTy>
210 assert(!buffer.
empty() &&
"too few elements in buffer");
212 std::forward<DataTy>(data)...);
225 template <
typename BufferTy,
typename DataTy>
227 unsigned code,
const DataTy &data) {
228 static_assert(!ElementTy::IsCompound,
229 "arrays and blobs need special handling");
230 ElementTy::assertValid(data);
231 buffer.push_back(data);
235 template <
typename T,
typename DataTy>
237 assert(buffer.
size() == 1 &&
"record data does not match layout");
238 data = ElementTy::convert(buffer.
front());
242 assert(buffer.
size() == 1 &&
"record data does not match layout");
254 template <
typename BufferTy>
261 template <
typename BufferTy,
typename ArrayTy>
263 unsigned code,
const ArrayTy &array) {
265 for (
auto &element : array)
266 ElementTy::assertValid(element);
268 buffer.reserve(buffer.size() + std::distance(array.begin(), array.end()));
269 std::copy(array.begin(), array.end(), std::back_inserter(buffer));
273 template <
typename BufferTy,
typename ElementDataTy,
typename... DataTy>
275 unsigned code, ElementDataTy element, DataTy... data) {
276 std::array<ElementDataTy, 1 +
sizeof...(data)> array{{element, data...}};
277 emit(Stream, buffer, code, array);
280 template <
typename BufferTy>
282 unsigned code, std::nullopt_t) {
286 template <
typename T>
291 template <
typename T,
typename ArrayTy>
309 template <
typename BufferTy>
319 template <
typename T,
typename DataTy>
331template <
typename... Types>
338 template <
typename E>
static bool check(
BCArray<E> *);
339 static int check(...);
343 static constexpr bool value = !std::is_same<
decltype(check((
T *)
nullptr)),
344 decltype(check(
false))>
::value;
349template <
typename... Types>
375 template <
typename BufferTy,
typename...
Data>
376 void emit(BufferTy &buffer,
unsigned id,
Data &&...data)
const {
384 auto Abbrev = std::make_shared<llvm::BitCodeAbbrev>();
396 template <
typename BufferTy,
typename...
Data>
398 unsigned abbrCode,
unsigned recordID,
Data &&...data) {
399 static_assert(
sizeof...(data) <=
sizeof...(Fields) ||
401 "Too many record elements");
402 static_assert(
sizeof...(data) >=
sizeof...(Fields),
403 "Too few record elements");
406 Stream, buffer, abbrCode, recordID, std::forward<Data>(data)...);
414 template <
typename ElementTy,
typename...
Data>
416 static_assert(
sizeof...(data) <=
sizeof...(Fields),
417 "Too many record elements");
418 static_assert(
sizeof...(Fields) <=
420 "Too few record elements");
422 std::forward<Data>(data)...);
430 template <
typename BufferTy,
typename...
Data>
437template <
unsigned RecordCode,
typename... Fields>
455 template <
typename BufferTy,
typename...
Data>
456 void emit(BufferTy &buffer,
Data &&...data)
const {
457 Base::emit(buffer, RecordCode, std::forward<Data>(data)...);
465 template <
typename BufferTy,
typename...
Data>
467 unsigned abbrCode,
Data &&...data) {
469 std::forward<Data>(data)...);
Given that RA is a live value
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unify loop Fixup each natural loop to have a single exit block
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
const T & front() const
front - Get the first element.
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.
Represents an array of some other type.
static void emitOp(llvm::BitCodeAbbrev &abbrev)
Represents an untyped blob of bytes.
static void emitOp(llvm::BitCodeAbbrev &abbrev)
RAII object to pair entering and exiting a sub-block.
BCBlockRAII(llvm::BitstreamWriter &Stream, unsigned block, unsigned abbrev)
Represents a character encoded in LLVM's Char6 encoding.
static void assertValid(const T &data)
static void emitOp(llvm::BitCodeAbbrev &abbrev)
Represents a fixed-width value in a bitcode record.
static void emitOp(llvm::BitCodeAbbrev &abbrev)
static void assertValid(const bool &data)
static void assertValid(const T &data)
Represents a single bitcode record type.
static void readRecord(BufferTy &buffer, Data &&...data)
Extract record data from buffer into the given data fields.
static unsigned emitAbbrev(llvm::BitstreamWriter &Stream)
Registers this record's layout with the bitstream reader.
BCGenericRecordLayout(llvm::BitstreamWriter &Stream)
Create a layout and register it with the given bitstream writer.
static void readRecord(ArrayRef< ElementTy > buffer, Data &&...data)
Extract record data from buffer into the given data fields.
const unsigned AbbrevCode
The abbreviation code used for this record in the current block.
static void emitRecord(llvm::BitstreamWriter &Stream, BufferTy &buffer, unsigned abbrCode, unsigned recordID, Data &&...data)
Emit a record identified by abbrCode to bitstream reader Stream, using buffer for scratch space.
void emit(BufferTy &buffer, unsigned id, Data &&...data) const
Emit a record to the bitstream writer, using the given buffer for scratch space.
Represents a literal operand in a bitcode record.
static void emitOp(llvm::BitCodeAbbrev &abbrev)
static void assertValid(const T &data)
A record with a fixed record code.
void emit(BufferTy &buffer, Data &&...data) const
Emit a record to the bitstream writer, using the given buffer for scratch space.
BCRecordLayout(llvm::BitstreamWriter &Stream)
Create a layout and register it with the given bitstream writer.
static void emitRecord(llvm::BitstreamWriter &Stream, BufferTy &buffer, unsigned abbrCode, Data &&...data)
Emit a record identified by abbrCode to bitstream reader Stream, using buffer for scratch space.
@ Code
The record code associated with this layout.
Represents a variable-width value in a bitcode record.
static void assertValid(const T &data)
static void emitOp(llvm::BitCodeAbbrev &abbrev)
BitCodeAbbrevOp - This describes one or more operands in an abbreviation.
static bool isChar6(char C)
isChar6 - Return true if this character is legal in the Char6 encoding.
BitCodeAbbrev - This class represents an abbreviation record.
void Add(const BitCodeAbbrevOp &OpInfo)
unsigned EmitAbbrev(std::shared_ptr< BitCodeAbbrev > Abbv)
Emits the abbreviation Abbv to the stream.
void EmitRecordWithBlob(unsigned Abbrev, const Container &Vals, StringRef Blob)
EmitRecordWithBlob - Emit the specified record to the stream, using an abbrev that includes a blob at...
void EmitRecordWithArray(unsigned Abbrev, const Container &Vals, StringRef Array)
EmitRecordWithArray - Just like EmitRecordWithBlob, works with records that end with an array.
void EnterSubblock(unsigned BlockID, unsigned CodeLen)
void EmitRecordWithAbbrev(unsigned Abbrev, const Container &Vals)
EmitRecordWithAbbrev - Emit a record with the specified abbreviation.
StringRef - Represent a constant reference to a string, i.e.
LLVM Value Representation.
Convenience base for all kinds of bitcode abbreviation fields.
static const bool IsCompound
static void assertValid(const T &data)
Asserts that the given data is a valid value for this field.
static T convert(T rawValue)
Converts a raw numeric representation of this value to its preferred type.
static void emit(llvm::BitstreamWriter &Stream, BufferTy &buffer, unsigned code, StringRef data)
static void read(ArrayRef< T > buffer, std::nullopt_t)
static void read(ArrayRef< T > buffer)=delete
static void emit(llvm::BitstreamWriter &Stream, BufferTy &Buffer, unsigned code, std::nullopt_t)
static void emit(llvm::BitstreamWriter &Stream, BufferTy &buffer, unsigned code, ElementDataTy element, DataTy... data)
static void read(ArrayRef< T > buffer, ArrayTy &array)
static void read(ArrayRef< T > Buffer, ArrayRef< T > &rawData)
static void emit(llvm::BitstreamWriter &Stream, BufferTy &buffer, unsigned code, const ArrayTy &array)
static void emit(llvm::BitstreamWriter &Stream, BufferTy &buffer, unsigned code, StringRef data)
static void read(ArrayRef< T > buffer, DataTy &data)=delete
Blob data is not stored in the buffer if you are using the correct accessor; this method should not b...
static void read(ArrayRef< T > buffer)
static void emit(llvm::BitstreamWriter &Stream, BufferTy &buffer, unsigned code, const DataTy &data)
static void read(ArrayRef< T > buffer, std::nullopt_t)
static void read(ArrayRef< T > buffer)=delete
static void read(ArrayRef< T > buffer, DataTy &data)
Helper class for dealing with a scalar element in the middle of a record.
static void read(ArrayRef< T > buffer, ElementDataTy &element, DataTy &&...data)
static void emit(llvm::BitstreamWriter &Stream, BufferTy &buffer, unsigned code, ElementDataTy element, DataTy &&...data)
static void read(ArrayRef< T > buffer, std::nullopt_t, DataTy &&...data)
@ Tail
Attemps to make calls as fast as possible while guaranteeing that tail call optimization can always b...
static void emitOps(llvm::BitCodeAbbrev &abbrev)
Attaches the last field to an abbreviation.
std::is_same< BCBlob, typename last_type< int, Types... >::type > has_blob
A type trait whose value field is true if the last type is BCBlob.
This is an optimization pass for GlobalISel generic memory operations.
mapped_iterator< ItTy, FuncTy > map_iterator(ItTy I, FuncTy F)
A type trait whose value field is true if the given type is a BCArray (of any element kind).
static constexpr bool value
A type trait whose type field is the last of its template parameters.
typename last_type< Tail... >::type type