LLVM: include/llvm/Bitcode/BitcodeConvenience.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30#ifndef LLVM_BITCODE_BITCODECONVENIENCE_H
31#define LLVM_BITCODE_BITCODECONVENIENCE_H
32
35#include
36#include
37
38namespace llvm {
40
41
42
44public:
46
47
48 template static void assertValid(const T &data) {}
49
50
51
52 template static T convert(T rawValue) { return rawValue; }
53};
54}
55
56
57
58
59
60
61
62
63
65public:
68 }
69
70 template static void assertValid(const T &data) {
71 assert(data == Value && "data value does not match declared literal value");
72 }
73};
74
75
76
77
79public:
80 static_assert(Width <= 64, "fixed-width field is too large");
81
84 }
85
87 assert(llvm::isUInt(data) &&
88 "data value does not fit in the given bit width");
89 }
90
91 template static void assertValid(const T &data) {
92 assert(data >= 0 && "cannot encode signed integers");
93 assert(llvm::isUInt(data) &&
94 "data value does not fit in the given bit width");
95 }
96};
97
98
99
100
101
102
104 static_assert(Width >= 2, "width does not have room for continuation bit");
105
106public:
109 }
110
111 template static void assertValid(const T &data) {
112 assert(data >= 0 && "cannot encode signed integers");
113 }
114};
115
116
117
118
119
120
121
123public:
126 }
127
128 template static void assertValid(const T &data) {
130 }
131
132 template char convert(T rawValue) {
133 return static_cast<char>(rawValue);
134 }
135};
136
137
138
139
141public:
144 }
145};
146
147
148
149
151 static_assert(!ElementTy::IsCompound, "arrays can only contain scalar types");
152
153public:
156 ElementTy::emitOp(abbrev);
157 }
158};
159
161
162
163
164
165
167 FieldTy::emitOp(abbrev);
168}
169
170
171
172
173
174
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);
181}
182
183
184
185
186template <typename ElementTy, typename... Fields> class BCRecordCoding {
187public:
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(data)...);
197 }
198
199 template <typename T, typename ElementDataTy, typename... DataTy>
201 DataTy &&...data) {
202 assert(!buffer.empty() && "too few elements in buffer");
203 element = ElementTy::convert(buffer.front());
205 std::forward(data)...);
206 }
207
208 template <typename T, typename... DataTy>
209 static void read(ArrayRef buffer, std::nullopt_t, DataTy &&...data) {
210 assert(!buffer.empty() && "too few elements in buffer");
212 std::forward(data)...);
213 }
214};
215
216
217
218
219
220
221
222
224public:
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);
233 }
234
235 template <typename T, typename DataTy>
237 assert(buffer.size() == 1 && "record data does not match layout");
238 data = ElementTy::convert(buffer.front());
239 }
240
241 template static void read(ArrayRef buffer, std::nullopt_t) {
242 assert(buffer.size() == 1 && "record data does not match layout");
243 (void)buffer;
244 }
245
247};
248
249
250
251
253public:
254 template
257
259 }
260
261 template <typename BufferTy, typename ArrayTy>
263 unsigned code, const ArrayTy &array) {
264#ifndef NDEBUG
265 for (auto &element : array)
266 ElementTy::assertValid(element);
267#endif
268 buffer.reserve(buffer.size() + std::distance(array.begin(), array.end()));
269 std::copy(array.begin(), array.end(), std::back_inserter(buffer));
271 }
272
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);
278 }
279
280 template
282 unsigned code, std::nullopt_t) {
284 }
285
286 template
288 rawData = Buffer;
289 }
290
291 template <typename T, typename ArrayTy>
295 }
296
297 template static void read(ArrayRef buffer, std::nullopt_t) {
298 (void)buffer;
299 }
300
302};
303
304
305
306
308public:
309 template
313 }
314
315 template static void read(ArrayRef buffer) { (void)buffer; }
316
317
318
319 template <typename T, typename DataTy>
321};
322
323
326};
327
328template struct last_type { using type = Head; };
329
330
331template <typename... Types>
333
334
335
337private:
338 template static bool check(BCArray *);
339 static int check(...);
340
341public:
343 static constexpr bool value = !std::is_same<decltype(check((T *)nullptr)),
344 decltype(check(false))>::value;
345};
346
347
348
349template <typename... Types>
351}
352
353
354
355
356
359
360public:
361
362
363
364
366
367
370
371
372
373
374
375 template <typename BufferTy, typename... Data>
376 void emit(BufferTy &buffer, unsigned id, Data &&...data) const {
378 }
379
380
381
382
384 auto Abbrev = std::make_sharedllvm::BitCodeAbbrev();
386 return Stream.EmitAbbrev(std::move(Abbrev));
387 }
388
389
390
391
392
393
394
395
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");
404 buffer.clear();
406 Stream, buffer, abbrCode, recordID, std::forward(data)...);
407 }
408
409
410
411
412
413
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)...);
423 }
424
425
426
427
428
429
430 template <typename BufferTy, typename... Data>
433 }
434};
435
436
437template <unsigned RecordCode, typename... Fields>
441
442public:
443 enum : unsigned {
444
445 Code = RecordCode
447
448
450
451
452
453
454
455 template <typename BufferTy, typename... Data>
456 void emit(BufferTy &buffer, Data &&...data) const {
457 Base::emit(buffer, RecordCode, std::forward(data)...);
458 }
459
460
461
462
463
464
465 template <typename BufferTy, typename... Data>
467 unsigned abbrCode, Data &&...data) {
469 std::forward(data)...);
470 }
471};
472
473
476
477public:
479 : Stream(Stream) {
481 }
482
484};
485}
486
487#endif
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