LLVM 24.0.0git
BitcodeAnalyzer.cpp
Go to the documentation of this file.
1//===- BitcodeAnalyzer.cpp - Internal BitcodeAnalyzer 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
14#include "llvm/Support/Format.h"
15#include "llvm/Support/SHA1.h"
16#include <optional>
17
18using namespace llvm;
19
20static Error reportError(StringRef Message) {
21 return createStringError(std::errc::illegal_byte_sequence, Message.data());
22}
23
24/// Return a symbolic block name if known, otherwise return null.
25static std::optional<const char *>
26GetBlockName(unsigned BlockID, const BitstreamBlockInfo &BlockInfo,
27 CurStreamTypeType CurStreamType) {
28 // Standard blocks for all bitcode files.
29 if (BlockID < bitc::FIRST_APPLICATION_BLOCKID) {
30 if (BlockID == bitc::BLOCKINFO_BLOCK_ID)
31 return "BLOCKINFO_BLOCK";
32 return std::nullopt;
33 }
34
35 // Check to see if we have a blockinfo record for this block, with a name.
36 if (const BitstreamBlockInfo::BlockInfo *Info =
37 BlockInfo.getBlockInfo(BlockID)) {
38 if (!Info->Name.empty())
39 return Info->Name.c_str();
40 }
41
42 if (CurStreamType != LLVMIRBitstream)
43 return std::nullopt;
44
45 switch (BlockID) {
46 default:
47 return std::nullopt;
49 return "OPERAND_BUNDLE_TAGS_BLOCK";
51 return "MODULE_BLOCK";
53 return "PARAMATTR_BLOCK";
55 return "PARAMATTR_GROUP_BLOCK_ID";
57 return "TYPE_BLOCK_ID";
59 return "CONSTANTS_BLOCK";
61 return "FUNCTION_BLOCK";
63 return "IDENTIFICATION_BLOCK_ID";
65 return "VALUE_SYMTAB";
67 return "METADATA_BLOCK";
69 return "METADATA_KIND_BLOCK";
71 return "METADATA_ATTACHMENT_BLOCK";
73 return "USELIST_BLOCK_ID";
75 return "GLOBALVAL_SUMMARY_BLOCK";
77 return "FULL_LTO_GLOBALVAL_SUMMARY_BLOCK";
79 return "MODULE_STRTAB_BLOCK";
81 return "STRTAB_BLOCK";
83 return "SYMTAB_BLOCK";
84 }
85}
86
87/// Return a symbolic code name if known, otherwise return null.
88static std::optional<const char *>
89GetCodeName(unsigned CodeID, unsigned BlockID,
90 const BitstreamBlockInfo &BlockInfo,
91 CurStreamTypeType CurStreamType) {
92 // Standard blocks for all bitcode files.
93 if (BlockID < bitc::FIRST_APPLICATION_BLOCKID) {
94 if (BlockID == bitc::BLOCKINFO_BLOCK_ID) {
95 switch (CodeID) {
96 default:
97 return std::nullopt;
99 return "SETBID";
101 return "BLOCKNAME";
103 return "SETRECORDNAME";
104 }
105 }
106 return std::nullopt;
107 }
108
109 // Check to see if we have a blockinfo record for this record, with a name.
110 if (const BitstreamBlockInfo::BlockInfo *Info =
111 BlockInfo.getBlockInfo(BlockID)) {
112 for (const std::pair<unsigned, std::string> &RN : Info->RecordNames)
113 if (RN.first == CodeID)
114 return RN.second.c_str();
115 }
116
117 if (CurStreamType != LLVMIRBitstream)
118 return std::nullopt;
119
120#define STRINGIFY_CODE(PREFIX, CODE) \
121 case bitc::PREFIX##_##CODE: \
122 return #CODE;
123 switch (BlockID) {
124 default:
125 return std::nullopt;
127 switch (CodeID) {
128 default:
129 return std::nullopt;
130 STRINGIFY_CODE(MODULE_CODE, VERSION)
131 STRINGIFY_CODE(MODULE_CODE, TRIPLE)
132 STRINGIFY_CODE(MODULE_CODE, DATALAYOUT)
133 STRINGIFY_CODE(MODULE_CODE, ASM)
134 STRINGIFY_CODE(MODULE_CODE, SECTIONNAME)
135 STRINGIFY_CODE(MODULE_CODE, DEPLIB) // Deprecated, present in old bitcode
136 STRINGIFY_CODE(MODULE_CODE, GLOBALVAR)
137 STRINGIFY_CODE(MODULE_CODE, FUNCTION)
138 STRINGIFY_CODE(MODULE_CODE, ALIAS)
139 STRINGIFY_CODE(MODULE_CODE, GCNAME)
140 STRINGIFY_CODE(MODULE_CODE, COMDAT)
141 STRINGIFY_CODE(MODULE_CODE, VSTOFFSET)
142 STRINGIFY_CODE(MODULE_CODE, METADATA_VALUES_UNUSED)
143 STRINGIFY_CODE(MODULE_CODE, SOURCE_FILENAME)
144 STRINGIFY_CODE(MODULE_CODE, HASH)
145 STRINGIFY_CODE(MODULE_CODE, GUIDLIST)
146 }
148 switch (CodeID) {
149 default:
150 return std::nullopt;
151 STRINGIFY_CODE(IDENTIFICATION_CODE, STRING)
152 STRINGIFY_CODE(IDENTIFICATION_CODE, EPOCH)
153 }
155 switch (CodeID) {
156 default:
157 return std::nullopt;
158 // FIXME: Should these be different?
160 return "ENTRY";
162 return "ENTRY";
163 }
165 switch (CodeID) {
166 default:
167 return std::nullopt;
169 return "ENTRY";
170 }
172 switch (CodeID) {
173 default:
174 return std::nullopt;
175 STRINGIFY_CODE(TYPE_CODE, NUMENTRY)
176 STRINGIFY_CODE(TYPE_CODE, VOID)
177 STRINGIFY_CODE(TYPE_CODE, FLOAT)
178 STRINGIFY_CODE(TYPE_CODE, DOUBLE)
179 STRINGIFY_CODE(TYPE_CODE, LABEL)
180 STRINGIFY_CODE(TYPE_CODE, OPAQUE)
181 STRINGIFY_CODE(TYPE_CODE, INTEGER)
182 STRINGIFY_CODE(TYPE_CODE, POINTER)
183 STRINGIFY_CODE(TYPE_CODE, HALF)
184 STRINGIFY_CODE(TYPE_CODE, ARRAY)
185 STRINGIFY_CODE(TYPE_CODE, VECTOR)
186 STRINGIFY_CODE(TYPE_CODE, X86_FP80)
187 STRINGIFY_CODE(TYPE_CODE, FP128)
188 STRINGIFY_CODE(TYPE_CODE, PPC_FP128)
189 STRINGIFY_CODE(TYPE_CODE, METADATA)
190 STRINGIFY_CODE(TYPE_CODE, X86_MMX)
191 STRINGIFY_CODE(TYPE_CODE, STRUCT_ANON)
192 STRINGIFY_CODE(TYPE_CODE, STRUCT_NAME)
193 STRINGIFY_CODE(TYPE_CODE, STRUCT_NAMED)
194 STRINGIFY_CODE(TYPE_CODE, FUNCTION)
195 STRINGIFY_CODE(TYPE_CODE, TOKEN)
196 STRINGIFY_CODE(TYPE_CODE, BFLOAT)
197 }
198
200 switch (CodeID) {
201 default:
202 return std::nullopt;
203 STRINGIFY_CODE(CST_CODE, SETTYPE)
204 STRINGIFY_CODE(CST_CODE, NULL)
205 STRINGIFY_CODE(CST_CODE, UNDEF)
206 STRINGIFY_CODE(CST_CODE, INTEGER)
207 STRINGIFY_CODE(CST_CODE, WIDE_INTEGER)
208 STRINGIFY_CODE(CST_CODE, FLOAT)
209 STRINGIFY_CODE(CST_CODE, AGGREGATE)
210 STRINGIFY_CODE(CST_CODE, STRING)
211 STRINGIFY_CODE(CST_CODE, CSTRING)
212 STRINGIFY_CODE(CST_CODE, CE_BINOP)
213 STRINGIFY_CODE(CST_CODE, CE_CAST)
214 STRINGIFY_CODE(CST_CODE, CE_GEP)
215 STRINGIFY_CODE(CST_CODE, CE_INBOUNDS_GEP)
216 STRINGIFY_CODE(CST_CODE, CE_SELECT)
217 STRINGIFY_CODE(CST_CODE, CE_EXTRACTELT)
218 STRINGIFY_CODE(CST_CODE, CE_INSERTELT)
219 STRINGIFY_CODE(CST_CODE, CE_SHUFFLEVEC)
220 STRINGIFY_CODE(CST_CODE, CE_CMP)
221 STRINGIFY_CODE(CST_CODE, INLINEASM)
222 STRINGIFY_CODE(CST_CODE, CE_SHUFVEC_EX)
223 STRINGIFY_CODE(CST_CODE, CE_UNOP)
224 STRINGIFY_CODE(CST_CODE, DSO_LOCAL_EQUIVALENT)
225 STRINGIFY_CODE(CST_CODE, NO_CFI_VALUE)
226 STRINGIFY_CODE(CST_CODE, PTRAUTH)
228 return "CST_CODE_BLOCKADDRESS";
229 STRINGIFY_CODE(CST_CODE, DATA)
230 }
232 switch (CodeID) {
233 default:
234 return std::nullopt;
235 STRINGIFY_CODE(FUNC_CODE, DECLAREBLOCKS)
236 STRINGIFY_CODE(FUNC_CODE, INST_BINOP)
237 STRINGIFY_CODE(FUNC_CODE, INST_CAST)
238 STRINGIFY_CODE(FUNC_CODE, INST_GEP_OLD)
239 STRINGIFY_CODE(FUNC_CODE, INST_INBOUNDS_GEP_OLD)
240 STRINGIFY_CODE(FUNC_CODE, INST_SELECT)
241 STRINGIFY_CODE(FUNC_CODE, INST_EXTRACTELT)
242 STRINGIFY_CODE(FUNC_CODE, INST_INSERTELT)
243 STRINGIFY_CODE(FUNC_CODE, INST_SHUFFLEVEC)
244 STRINGIFY_CODE(FUNC_CODE, INST_CMP)
245 STRINGIFY_CODE(FUNC_CODE, INST_RET)
246 STRINGIFY_CODE(FUNC_CODE, INST_BR)
247 STRINGIFY_CODE(FUNC_CODE, INST_SWITCH)
248 STRINGIFY_CODE(FUNC_CODE, INST_INVOKE)
249 STRINGIFY_CODE(FUNC_CODE, INST_UNOP)
250 STRINGIFY_CODE(FUNC_CODE, INST_UNREACHABLE)
251 STRINGIFY_CODE(FUNC_CODE, INST_CLEANUPRET)
252 STRINGIFY_CODE(FUNC_CODE, INST_CATCHRET)
253 STRINGIFY_CODE(FUNC_CODE, INST_CATCHPAD)
254 STRINGIFY_CODE(FUNC_CODE, INST_PHI)
255 STRINGIFY_CODE(FUNC_CODE, INST_ALLOCA)
256 STRINGIFY_CODE(FUNC_CODE, INST_LOAD)
257 STRINGIFY_CODE(FUNC_CODE, INST_VAARG)
258 STRINGIFY_CODE(FUNC_CODE, INST_STORE)
259 STRINGIFY_CODE(FUNC_CODE, INST_EXTRACTVAL)
260 STRINGIFY_CODE(FUNC_CODE, INST_INSERTVAL)
261 STRINGIFY_CODE(FUNC_CODE, INST_CMP2)
262 STRINGIFY_CODE(FUNC_CODE, INST_VSELECT)
263 STRINGIFY_CODE(FUNC_CODE, DEBUG_LOC_AGAIN)
264 STRINGIFY_CODE(FUNC_CODE, INST_CALL)
265 STRINGIFY_CODE(FUNC_CODE, DEBUG_LOC)
266 STRINGIFY_CODE(FUNC_CODE, INST_GEP)
267 STRINGIFY_CODE(FUNC_CODE, OPERAND_BUNDLE)
268 STRINGIFY_CODE(FUNC_CODE, INST_FENCE)
269 STRINGIFY_CODE(FUNC_CODE, INST_ATOMICRMW_OLD)
270 STRINGIFY_CODE(FUNC_CODE, INST_ATOMICRMW)
271 STRINGIFY_CODE(FUNC_CODE, INST_LOADATOMIC)
272 STRINGIFY_CODE(FUNC_CODE, INST_STOREATOMIC)
273 STRINGIFY_CODE(FUNC_CODE, INST_CMPXCHG)
274 STRINGIFY_CODE(FUNC_CODE, INST_CALLBR)
275 STRINGIFY_CODE(FUNC_CODE, BLOCKADDR_USERS)
276 STRINGIFY_CODE(FUNC_CODE, DEBUG_RECORD_DECLARE)
277 STRINGIFY_CODE(FUNC_CODE, DEBUG_RECORD_DECLARE_VALUE)
278 STRINGIFY_CODE(FUNC_CODE, DEBUG_RECORD_VALUE)
279 STRINGIFY_CODE(FUNC_CODE, DEBUG_RECORD_ASSIGN)
280 STRINGIFY_CODE(FUNC_CODE, DEBUG_RECORD_VALUE_SIMPLE)
281 STRINGIFY_CODE(FUNC_CODE, DEBUG_RECORD_LABEL)
282 }
284 switch (CodeID) {
285 default:
286 return std::nullopt;
287 STRINGIFY_CODE(VST_CODE, ENTRY)
288 STRINGIFY_CODE(VST_CODE, BBENTRY)
289 STRINGIFY_CODE(VST_CODE, FNENTRY)
290 STRINGIFY_CODE(VST_CODE, COMBINED_ENTRY)
291 }
293 switch (CodeID) {
294 default:
295 return std::nullopt;
296 STRINGIFY_CODE(MST_CODE, ENTRY)
297 STRINGIFY_CODE(MST_CODE, HASH)
298 }
301 switch (CodeID) {
302 default:
303 return std::nullopt;
304 STRINGIFY_CODE(FS, PERMODULE)
305 STRINGIFY_CODE(FS, PERMODULE_PROFILE)
306 STRINGIFY_CODE(FS, PERMODULE_RELBF)
307 STRINGIFY_CODE(FS, PERMODULE_GLOBALVAR_INIT_REFS)
308 STRINGIFY_CODE(FS, PERMODULE_VTABLE_GLOBALVAR_INIT_REFS)
309 STRINGIFY_CODE(FS, COMBINED)
310 STRINGIFY_CODE(FS, COMBINED_PROFILE)
311 STRINGIFY_CODE(FS, COMBINED_GLOBALVAR_INIT_REFS)
312 STRINGIFY_CODE(FS, ALIAS)
313 STRINGIFY_CODE(FS, COMBINED_ALIAS)
314 STRINGIFY_CODE(FS, COMBINED_ORIGINAL_NAME)
315 STRINGIFY_CODE(FS, VERSION)
316 STRINGIFY_CODE(FS, FLAGS)
317 STRINGIFY_CODE(FS, TYPE_TESTS)
318 STRINGIFY_CODE(FS, TYPE_TEST_ASSUME_VCALLS)
319 STRINGIFY_CODE(FS, TYPE_CHECKED_LOAD_VCALLS)
320 STRINGIFY_CODE(FS, TYPE_TEST_ASSUME_CONST_VCALL)
321 STRINGIFY_CODE(FS, TYPE_CHECKED_LOAD_CONST_VCALL)
322 STRINGIFY_CODE(FS, VALUE_GUID)
323 STRINGIFY_CODE(FS, CFI_FUNCTION_DEFS)
324 STRINGIFY_CODE(FS, CFI_FUNCTION_DECLS)
325 STRINGIFY_CODE(FS, TYPE_ID)
326 STRINGIFY_CODE(FS, TYPE_ID_METADATA)
327 STRINGIFY_CODE(FS, BLOCK_COUNT)
328 STRINGIFY_CODE(FS, PARAM_ACCESS)
329 STRINGIFY_CODE(FS, PERMODULE_CALLSITE_INFO)
330 STRINGIFY_CODE(FS, PERMODULE_ALLOC_INFO)
331 STRINGIFY_CODE(FS, COMBINED_CALLSITE_INFO)
332 STRINGIFY_CODE(FS, COMBINED_ALLOC_INFO)
333 STRINGIFY_CODE(FS, STACK_IDS)
334 STRINGIFY_CODE(FS, ALLOC_CONTEXT_IDS)
335 STRINGIFY_CODE(FS, CONTEXT_RADIX_TREE_ARRAY)
336 STRINGIFY_CODE(FS, COMBINED_ALLOC_INFO_NO_CONTEXT)
337 }
339 switch (CodeID) {
340 default:
341 return std::nullopt;
342 STRINGIFY_CODE(METADATA, ATTACHMENT)
343 }
345 switch (CodeID) {
346 default:
347 return std::nullopt;
348 STRINGIFY_CODE(METADATA, STRING_OLD)
349 STRINGIFY_CODE(METADATA, VALUE)
350 STRINGIFY_CODE(METADATA, NODE)
351 STRINGIFY_CODE(METADATA, NAME)
352 STRINGIFY_CODE(METADATA, DISTINCT_NODE)
353 STRINGIFY_CODE(METADATA, KIND) // Older bitcode has it in a MODULE_BLOCK
354 STRINGIFY_CODE(METADATA, LOCATION)
355 STRINGIFY_CODE(METADATA, OLD_NODE)
356 STRINGIFY_CODE(METADATA, OLD_FN_NODE)
357 STRINGIFY_CODE(METADATA, NAMED_NODE)
358 STRINGIFY_CODE(METADATA, GENERIC_DEBUG)
359 STRINGIFY_CODE(METADATA, SUBRANGE)
360 STRINGIFY_CODE(METADATA, ENUMERATOR)
361 STRINGIFY_CODE(METADATA, BASIC_TYPE)
362 STRINGIFY_CODE(METADATA, FILE)
363 STRINGIFY_CODE(METADATA, DERIVED_TYPE)
364 STRINGIFY_CODE(METADATA, COMPOSITE_TYPE)
365 STRINGIFY_CODE(METADATA, SUBROUTINE_TYPE)
366 STRINGIFY_CODE(METADATA, COMPILE_UNIT)
367 STRINGIFY_CODE(METADATA, SUBPROGRAM)
368 STRINGIFY_CODE(METADATA, LEXICAL_BLOCK)
369 STRINGIFY_CODE(METADATA, LEXICAL_BLOCK_FILE)
370 STRINGIFY_CODE(METADATA, NAMESPACE)
371 STRINGIFY_CODE(METADATA, TEMPLATE_TYPE)
372 STRINGIFY_CODE(METADATA, TEMPLATE_VALUE)
373 STRINGIFY_CODE(METADATA, GLOBAL_VAR)
374 STRINGIFY_CODE(METADATA, LOCAL_VAR)
375 STRINGIFY_CODE(METADATA, EXPRESSION)
376 STRINGIFY_CODE(METADATA, OBJC_PROPERTY)
377 STRINGIFY_CODE(METADATA, IMPORTED_ENTITY)
378 STRINGIFY_CODE(METADATA, MODULE)
379 STRINGIFY_CODE(METADATA, MACRO)
380 STRINGIFY_CODE(METADATA, MACRO_FILE)
381 STRINGIFY_CODE(METADATA, STRINGS)
382 STRINGIFY_CODE(METADATA, GLOBAL_DECL_ATTACHMENT)
383 STRINGIFY_CODE(METADATA, GLOBAL_VAR_EXPR)
384 STRINGIFY_CODE(METADATA, INDEX_OFFSET)
385 STRINGIFY_CODE(METADATA, INDEX)
386 STRINGIFY_CODE(METADATA, ARG_LIST)
387 }
389 switch (CodeID) {
390 default:
391 return std::nullopt;
392 STRINGIFY_CODE(METADATA, KIND)
393 }
395 switch (CodeID) {
396 default:
397 return std::nullopt;
399 return "USELIST_CODE_DEFAULT";
401 return "USELIST_CODE_BB";
402 }
403
405 switch (CodeID) {
406 default:
407 return std::nullopt;
409 return "OPERAND_BUNDLE_TAG";
410 }
412 switch (CodeID) {
413 default:
414 return std::nullopt;
416 return "BLOB";
417 }
419 switch (CodeID) {
420 default:
421 return std::nullopt;
423 return "BLOB";
424 }
425 }
426#undef STRINGIFY_CODE
427}
428
429static void printSize(raw_ostream &OS, double Bits) {
430 OS << format("%.2f/%.2fB/%luW", Bits, Bits / 8, (unsigned long)(Bits / 32));
431}
432static void printSize(raw_ostream &OS, uint64_t Bits) {
433 OS << format("%lub/%.2fB/%luW", (unsigned long)Bits, (double)Bits / 8,
434 (unsigned long)(Bits / 32));
435}
436
438 auto tryRead = [&Stream](char &Dest, size_t size) -> Error {
439 if (Expected<SimpleBitstreamCursor::word_t> MaybeWord = Stream.Read(size))
440 Dest = MaybeWord.get();
441 else
442 return MaybeWord.takeError();
443 return Error::success();
444 };
445
446 char Signature[6];
447 if (Error Err = tryRead(Signature[0], 8))
448 return std::move(Err);
449 if (Error Err = tryRead(Signature[1], 8))
450 return std::move(Err);
451
452 // Autodetect the file contents, if it is one we know.
453 if (Signature[0] == 'C' && Signature[1] == 'P') {
454 if (Error Err = tryRead(Signature[2], 8))
455 return std::move(Err);
456 if (Error Err = tryRead(Signature[3], 8))
457 return std::move(Err);
458 if (Signature[2] == 'C' && Signature[3] == 'H')
460 } else if (Signature[0] == 'D' && Signature[1] == 'I') {
461 if (Error Err = tryRead(Signature[2], 8))
462 return std::move(Err);
463 if (Error Err = tryRead(Signature[3], 8))
464 return std::move(Err);
465 if (Signature[2] == 'A' && Signature[3] == 'G')
467 } else if (Signature[0] == 'R' && Signature[1] == 'M') {
468 if (Error Err = tryRead(Signature[2], 8))
469 return std::move(Err);
470 if (Error Err = tryRead(Signature[3], 8))
471 return std::move(Err);
472 if (Signature[2] == 'R' && Signature[3] == 'K')
474 } else {
475 if (Error Err = tryRead(Signature[2], 4))
476 return std::move(Err);
477 if (Error Err = tryRead(Signature[3], 4))
478 return std::move(Err);
479 if (Error Err = tryRead(Signature[4], 4))
480 return std::move(Err);
481 if (Error Err = tryRead(Signature[5], 4))
482 return std::move(Err);
483 if (Signature[0] == 'B' && Signature[1] == 'C' && Signature[2] == 0x0 &&
484 Signature[3] == 0xC && Signature[4] == 0xE && Signature[5] == 0xD)
485 return LLVMIRBitstream;
486 }
487 return UnknownBitstream;
488}
489
490static Expected<CurStreamTypeType> analyzeHeader(std::optional<BCDumpOptions> O,
491 BitstreamCursor &Stream) {
492 ArrayRef<uint8_t> Bytes = Stream.getBitcodeBytes();
493 const unsigned char *BufPtr = (const unsigned char *)Bytes.data();
494 const unsigned char *EndBufPtr = BufPtr + Bytes.size();
495
496 // If we have a wrapper header, parse it and ignore the non-bc file
497 // contents. The magic number is 0x0B17C0DE stored in little endian.
498 if (isBitcodeWrapper(BufPtr, EndBufPtr)) {
499 if (Bytes.size() < BWH_HeaderSize)
500 return reportError("Invalid bitcode wrapper header");
501
502 if (O) {
503 unsigned Magic = support::endian::read32le(&BufPtr[BWH_MagicField]);
504 unsigned Version = support::endian::read32le(&BufPtr[BWH_VersionField]);
506 unsigned Size = support::endian::read32le(&BufPtr[BWH_SizeField]);
507 unsigned CPUType = support::endian::read32le(&BufPtr[BWH_CPUTypeField]);
508
509 O->OS << "<BITCODE_WRAPPER_HEADER"
510 << " Magic=" << format_hex(Magic, 10)
511 << " Version=" << format_hex(Version, 10)
512 << " Offset=" << format_hex(Offset, 10)
513 << " Size=" << format_hex(Size, 10)
514 << " CPUType=" << format_hex(CPUType, 10) << "/>\n";
515 }
516
517 if (SkipBitcodeWrapperHeader(BufPtr, EndBufPtr, true))
518 return reportError("Invalid bitcode wrapper header");
519 }
520
521 // Use the cursor modified by skipping the wrapper header.
522 Stream = BitstreamCursor(ArrayRef<uint8_t>(BufPtr, EndBufPtr));
523
524 return ReadSignature(Stream);
525}
526
527static bool canDecodeBlob(unsigned Code, unsigned BlockID) {
528 return BlockID == bitc::METADATA_BLOCK_ID && Code == bitc::METADATA_STRINGS;
529}
530
531Error BitcodeAnalyzer::decodeMetadataStringsBlob(StringRef Indent,
533 StringRef Blob,
534 raw_ostream &OS) {
535 if (Blob.empty())
536 return reportError("Cannot decode empty blob.");
537
538 if (Record.size() != 2)
539 return reportError(
540 "Decoding metadata strings blob needs two record entries.");
541
542 unsigned NumStrings = Record[0];
543 unsigned StringsOffset = Record[1];
544 OS << " num-strings = " << NumStrings << " {\n";
545
546 StringRef Lengths = Blob.slice(0, StringsOffset);
547 SimpleBitstreamCursor R(Lengths);
548 StringRef Strings = Blob.drop_front(StringsOffset);
549 do {
550 if (R.AtEndOfStream())
551 return reportError("bad length");
552
553 uint32_t Size;
554 if (Error E = R.ReadVBR(6).moveInto(Size))
555 return E;
556 if (Strings.size() < Size)
557 return reportError("truncated chars");
558
559 OS << Indent << " '";
560 OS.write_escaped(Strings.slice(0, Size), /*hex=*/true);
561 OS << "'\n";
562 Strings = Strings.drop_front(Size);
563 } while (--NumStrings);
564
565 OS << Indent << " }";
566 return Error::success();
567}
568
570 std::optional<StringRef> BlockInfoBuffer)
571 : Stream(Buffer) {
572 if (BlockInfoBuffer)
573 BlockInfoStream.emplace(*BlockInfoBuffer);
574}
575
576Error BitcodeAnalyzer::analyze(std::optional<BCDumpOptions> O,
577 std::optional<StringRef> CheckHash) {
578 if (Error E = analyzeHeader(O, Stream).moveInto(CurStreamType))
579 return E;
580
581 Stream.setBlockInfo(&BlockInfo);
582
583 // Read block info from BlockInfoStream, if specified.
584 // The block info must be a top-level block.
585 if (BlockInfoStream) {
586 BitstreamCursor BlockInfoCursor(*BlockInfoStream);
587 if (Error E = analyzeHeader(O, BlockInfoCursor).takeError())
588 return E;
589
590 while (!BlockInfoCursor.AtEndOfStream()) {
591 Expected<unsigned> MaybeCode = BlockInfoCursor.ReadCode();
592 if (!MaybeCode)
593 return MaybeCode.takeError();
594 if (MaybeCode.get() != bitc::ENTER_SUBBLOCK)
595 return reportError("Invalid record at top-level in block info file");
596
597 Expected<unsigned> MaybeBlockID = BlockInfoCursor.ReadSubBlockID();
598 if (!MaybeBlockID)
599 return MaybeBlockID.takeError();
600 if (MaybeBlockID.get() == bitc::BLOCKINFO_BLOCK_ID) {
601 std::optional<BitstreamBlockInfo> NewBlockInfo;
602 if (Error E =
603 BlockInfoCursor.ReadBlockInfoBlock(/*ReadBlockInfoNames=*/true)
604 .moveInto(NewBlockInfo))
605 return E;
606 if (!NewBlockInfo)
607 return reportError("Malformed BlockInfoBlock in block info file");
608 BlockInfo = std::move(*NewBlockInfo);
609 break;
610 }
611
612 if (Error Err = BlockInfoCursor.SkipBlock())
613 return Err;
614 }
615 }
616
617 // Parse the top-level structure. We only allow blocks at the top-level.
618 while (!Stream.AtEndOfStream()) {
619 Expected<unsigned> MaybeCode = Stream.ReadCode();
620 if (!MaybeCode)
621 return MaybeCode.takeError();
622 if (MaybeCode.get() != bitc::ENTER_SUBBLOCK)
623 return reportError("Invalid record at top-level");
624
625 Expected<unsigned> MaybeBlockID = Stream.ReadSubBlockID();
626 if (!MaybeBlockID)
627 return MaybeBlockID.takeError();
628
629 if (Error E = parseBlock(MaybeBlockID.get(), 0, O, CheckHash))
630 return E;
631 ++NumTopBlocks;
632 }
633
634 return Error::success();
635}
636
638 std::optional<StringRef> Filename) {
639 uint64_t BufferSizeBits = Stream.getBitcodeBytes().size() * CHAR_BIT;
640 // Print a summary of the read file.
641 O.OS << "Summary ";
642 if (Filename)
643 O.OS << "of " << Filename->data() << ":\n";
644 O.OS << " Total size: ";
645 printSize(O.OS, BufferSizeBits);
646 O.OS << "\n";
647 O.OS << " Stream type: ";
648 switch (CurStreamType) {
649 case UnknownBitstream:
650 O.OS << "unknown\n";
651 break;
652 case LLVMIRBitstream:
653 O.OS << "LLVM IR\n";
654 break;
656 O.OS << "Clang Serialized AST\n";
657 break;
659 O.OS << "Clang Serialized Diagnostics\n";
660 break;
662 O.OS << "LLVM Remarks\n";
663 break;
664 }
665 O.OS << " # Toplevel Blocks: " << NumTopBlocks << "\n";
666 O.OS << "\n";
667
668 // Emit per-block stats.
669 O.OS << "Per-block Summary:\n";
670 for (const auto &Stat : BlockIDStats) {
671 O.OS << " Block ID #" << Stat.first;
672 if (std::optional<const char *> BlockName =
673 GetBlockName(Stat.first, BlockInfo, CurStreamType))
674 O.OS << " (" << *BlockName << ")";
675 O.OS << ":\n";
676
677 const PerBlockIDStats &Stats = Stat.second;
678 O.OS << " Num Instances: " << Stats.NumInstances << "\n";
679 O.OS << " Total Size: ";
680 printSize(O.OS, Stats.NumBits);
681 O.OS << "\n";
682 double pct = (Stats.NumBits * 100.0) / BufferSizeBits;
683 O.OS << " Percent of file: " << format("%2.4f%%", pct) << "\n";
684 if (Stats.NumInstances > 1) {
685 O.OS << " Average Size: ";
686 printSize(O.OS, Stats.NumBits / (double)Stats.NumInstances);
687 O.OS << "\n";
688 O.OS << " Tot/Avg SubBlocks: " << Stats.NumSubBlocks << "/"
689 << Stats.NumSubBlocks / (double)Stats.NumInstances << "\n";
690 O.OS << " Tot/Avg Abbrevs: " << Stats.NumAbbrevs << "/"
691 << Stats.NumAbbrevs / (double)Stats.NumInstances << "\n";
692 O.OS << " Tot/Avg Records: " << Stats.NumRecords << "/"
693 << Stats.NumRecords / (double)Stats.NumInstances << "\n";
694 } else {
695 O.OS << " Num SubBlocks: " << Stats.NumSubBlocks << "\n";
696 O.OS << " Num Abbrevs: " << Stats.NumAbbrevs << "\n";
697 O.OS << " Num Records: " << Stats.NumRecords << "\n";
698 }
699 if (Stats.NumRecords) {
700 double pct = (Stats.NumAbbreviatedRecords * 100.0) / Stats.NumRecords;
701 O.OS << " Percent Abbrevs: " << format("%2.4f%%", pct) << "\n";
702 }
703 O.OS << "\n";
704
705 // Print a histogram of the codes we see.
706 if (O.Histogram && !Stats.CodeFreq.empty()) {
707 std::vector<std::pair<unsigned, unsigned>> FreqPairs; // <freq,code>
708 for (unsigned i = 0, e = Stats.CodeFreq.size(); i != e; ++i)
709 if (unsigned Freq = Stats.CodeFreq[i].NumInstances)
710 FreqPairs.push_back(std::make_pair(Freq, i));
711 llvm::stable_sort(FreqPairs);
712 std::reverse(FreqPairs.begin(), FreqPairs.end());
713
714 O.OS << "\tRecord Histogram:\n";
715 O.OS << "\t\t Count # Bits b/Rec % Abv Record Kind\n";
716 for (const auto &FreqPair : FreqPairs) {
717 const PerRecordStats &RecStats = Stats.CodeFreq[FreqPair.second];
718
719 O.OS << format("\t\t%7d %9lu", RecStats.NumInstances,
720 (unsigned long)RecStats.TotalBits);
721
722 if (RecStats.NumInstances > 1)
723 O.OS << format(" %9.1f",
724 (double)RecStats.TotalBits / RecStats.NumInstances);
725 else
726 O.OS << " ";
727
728 if (RecStats.NumAbbrev)
729 O.OS << format(" %7.2f", (double)RecStats.NumAbbrev /
730 RecStats.NumInstances * 100);
731 else
732 O.OS << " ";
733
734 O.OS << " ";
735 if (std::optional<const char *> CodeName = GetCodeName(
736 FreqPair.second, Stat.first, BlockInfo, CurStreamType))
737 O.OS << *CodeName << "\n";
738 else
739 O.OS << "UnknownCode" << FreqPair.second << "\n";
740 }
741 O.OS << "\n";
742 }
743 }
744}
745
746Error BitcodeAnalyzer::parseBlock(unsigned BlockID, unsigned IndentLevel,
747 std::optional<BCDumpOptions> O,
748 std::optional<StringRef> CheckHash) {
749 std::string Indent(IndentLevel * 2, ' ');
750 uint64_t BlockBitStart = Stream.GetCurrentBitNo();
751
752 // Get the statistics for this BlockID.
753 PerBlockIDStats &BlockStats = BlockIDStats[BlockID];
754
755 BlockStats.NumInstances++;
756
757 // BLOCKINFO is a special part of the stream.
758 bool DumpRecords = O.has_value();
759 if (BlockID == bitc::BLOCKINFO_BLOCK_ID) {
760 if (O && !O->DumpBlockinfo)
761 O->OS << Indent << "<BLOCKINFO_BLOCK/>\n";
762 std::optional<BitstreamBlockInfo> NewBlockInfo;
763 if (Error E = Stream.ReadBlockInfoBlock(/*ReadBlockInfoNames=*/true)
764 .moveInto(NewBlockInfo))
765 return E;
766 if (!NewBlockInfo)
767 return reportError("Malformed BlockInfoBlock");
768 BlockInfo = std::move(*NewBlockInfo);
769 if (Error Err = Stream.JumpToBit(BlockBitStart))
770 return Err;
771 // It's not really interesting to dump the contents of the blockinfo
772 // block, so only do it if the user explicitly requests it.
773 DumpRecords = O && O->DumpBlockinfo;
774 }
775
776 unsigned NumWords = 0;
777 if (Error Err = Stream.EnterSubBlock(BlockID, &NumWords))
778 return Err;
779
780 // Keep it for later, when we see a MODULE_HASH record
781 uint64_t BlockEntryPos = Stream.getCurrentByteNo();
782
783 std::optional<const char *> BlockName;
784 if (DumpRecords) {
785 O->OS << Indent << "<";
786 if ((BlockName = GetBlockName(BlockID, BlockInfo, CurStreamType)))
787 O->OS << *BlockName;
788 else
789 O->OS << "UnknownBlock" << BlockID;
790
791 if (!O->Symbolic && BlockName)
792 O->OS << " BlockID=" << BlockID;
793
794 O->OS << " NumWords=" << NumWords
795 << " BlockCodeSize=" << Stream.getAbbrevIDWidth() << ">\n";
796 }
797
798 SmallVector<uint64_t, 64> Record;
799
800 // Keep the offset to the metadata index if seen.
801 uint64_t MetadataIndexOffset = 0;
802
803 // Read all the records for this block.
804 while (true) {
805 if (Stream.AtEndOfStream())
806 return reportError("Premature end of bitstream");
807
808 uint64_t RecordStartBit = Stream.GetCurrentBitNo();
809
810 BitstreamEntry Entry;
812 .moveInto(Entry))
813 return E;
814
815 switch (Entry.Kind) {
817 return reportError("malformed bitcode file");
819 uint64_t BlockBitEnd = Stream.GetCurrentBitNo();
820 BlockStats.NumBits += BlockBitEnd - BlockBitStart;
821 if (DumpRecords) {
822 O->OS << Indent << "</";
823 if (BlockName)
824 O->OS << *BlockName << ">\n";
825 else
826 O->OS << "UnknownBlock" << BlockID << ">\n";
827 }
828 return Error::success();
829 }
830
832 uint64_t SubBlockBitStart = Stream.GetCurrentBitNo();
833 if (Error E = parseBlock(Entry.ID, IndentLevel + 1, O, CheckHash))
834 return E;
835 ++BlockStats.NumSubBlocks;
836 uint64_t SubBlockBitEnd = Stream.GetCurrentBitNo();
837
838 // Don't include subblock sizes in the size of this block.
839 BlockBitStart += SubBlockBitEnd - SubBlockBitStart;
840 continue;
841 }
843 // The interesting case.
844 break;
845 }
846
847 if (Entry.ID == bitc::DEFINE_ABBREV) {
848 if (Error Err = Stream.ReadAbbrevRecord())
849 return Err;
850 ++BlockStats.NumAbbrevs;
851 continue;
852 }
853
854 Record.clear();
855
856 ++BlockStats.NumRecords;
857
858 StringRef Blob;
859 uint64_t CurrentRecordPos = Stream.GetCurrentBitNo();
860 unsigned Code;
861 if (Error E = Stream.readRecord(Entry.ID, Record, &Blob).moveInto(Code))
862 return E;
863
864 // Increment the # occurrences of this code.
865 if (BlockStats.CodeFreq.size() <= Code)
866 BlockStats.CodeFreq.resize(Code + 1);
867 BlockStats.CodeFreq[Code].NumInstances++;
868 BlockStats.CodeFreq[Code].TotalBits +=
869 Stream.GetCurrentBitNo() - RecordStartBit;
870 if (Entry.ID != bitc::UNABBREV_RECORD) {
871 BlockStats.CodeFreq[Code].NumAbbrev++;
872 ++BlockStats.NumAbbreviatedRecords;
873 }
874
875 if (DumpRecords) {
876 O->OS << Indent << " <";
877 std::optional<const char *> CodeName =
878 GetCodeName(Code, BlockID, BlockInfo, CurStreamType);
879 if (CodeName)
880 O->OS << *CodeName;
881 else
882 O->OS << "UnknownCode" << Code;
883 if (!O->Symbolic && CodeName)
884 O->OS << " codeid=" << Code;
885 const BitCodeAbbrev *Abbv = nullptr;
886 if (Entry.ID != bitc::UNABBREV_RECORD) {
887 Expected<const BitCodeAbbrev *> MaybeAbbv = Stream.getAbbrev(Entry.ID);
888 if (!MaybeAbbv)
889 return MaybeAbbv.takeError();
890 Abbv = MaybeAbbv.get();
891 O->OS << " abbrevid=" << Entry.ID;
892 }
893
894 for (unsigned i = 0, e = Record.size(); i != e; ++i)
895 O->OS << " op" << i << "=" << (int64_t)Record[i];
896
897 // If we found a metadata index, let's verify that we had an offset
898 // before and validate its forward reference offset was correct!
899 if (BlockID == bitc::METADATA_BLOCK_ID) {
900 if (Code == bitc::METADATA_INDEX_OFFSET) {
901 if (Record.size() != 2)
902 O->OS << "(Invalid record)";
903 else {
904 auto Offset = Record[0] + (Record[1] << 32);
905 MetadataIndexOffset = Stream.GetCurrentBitNo() + Offset;
906 }
907 }
908 if (Code == bitc::METADATA_INDEX) {
909 O->OS << " (offset ";
910 if (MetadataIndexOffset == RecordStartBit)
911 O->OS << "match)";
912 else
913 O->OS << "mismatch: " << MetadataIndexOffset << " vs "
914 << RecordStartBit << ")";
915 }
916 }
917
918 // If we found a module hash, let's verify that it matches!
919 if (BlockID == bitc::MODULE_BLOCK_ID && Code == bitc::MODULE_CODE_HASH &&
920 CheckHash) {
921 if (Record.size() != 5)
922 O->OS << " (invalid)";
923 else {
924 // Recompute the hash and compare it to the one in the bitcode
925 SHA1 Hasher;
926 std::array<uint8_t, 20> Hash;
927 Hasher.update(*CheckHash);
928 {
929 int BlockSize = (CurrentRecordPos / 8) - BlockEntryPos;
930 auto Ptr = Stream.getPointerToByte(BlockEntryPos, BlockSize);
931 Hasher.update(ArrayRef<uint8_t>(Ptr, BlockSize));
932 Hash = Hasher.result();
933 }
934 std::array<uint8_t, 20> RecordedHash;
935 int Pos = 0;
936 for (auto &Val : Record) {
937 assert(!(Val >> 32) && "Unexpected high bits set");
938 support::endian::write32be(&RecordedHash[Pos], Val);
939 Pos += 4;
940 }
941 if (Hash == RecordedHash)
942 O->OS << " (match)";
943 else
944 O->OS << " (!mismatch!)";
945 }
946 }
947
948 O->OS << "/>";
949
950 if (Abbv) {
951 for (unsigned i = 1, e = Abbv->getNumOperandInfos(); i != e; ++i) {
952 const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
953 if (!Op.isEncoding() || Op.getEncoding() != BitCodeAbbrevOp::Array)
954 continue;
955 assert(i + 2 == e && "Array op not second to last");
956 std::string Str;
957 bool ArrayIsPrintable = true;
958 for (unsigned j = i - 1, je = Record.size(); j != je; ++j) {
959 if (!isPrint(static_cast<unsigned char>(Record[j]))) {
960 ArrayIsPrintable = false;
961 break;
962 }
963 Str += (char)Record[j];
964 }
965 if (ArrayIsPrintable)
966 O->OS << " record string = '" << Str << "'";
967 break;
968 }
969 }
970
971 if (Blob.data()) {
972 if (canDecodeBlob(Code, BlockID)) {
973 if (Error E = decodeMetadataStringsBlob(Indent, Record, Blob, O->OS))
974 return E;
975 } else {
976 O->OS << " blob data = ";
977 if (O->ShowBinaryBlobs) {
978 O->OS << "'";
979 O->OS.write_escaped(Blob, /*hex=*/true) << "'";
980 } else {
981 bool BlobIsPrintable = true;
982 for (char C : Blob)
983 if (!isPrint(static_cast<unsigned char>(C))) {
984 BlobIsPrintable = false;
985 break;
986 }
987
988 if (BlobIsPrintable)
989 O->OS << "'" << Blob << "'";
990 else
991 O->OS << "unprintable, " << Blob.size() << " bytes.";
992 }
993 }
994 }
995
996 O->OS << "\n";
997 }
998
999 // Make sure that we can skip the current record.
1000 if (Error Err = Stream.JumpToBit(CurrentRecordPos))
1001 return Err;
1002 if (Expected<unsigned> Skipped = Stream.skipRecord(Entry.ID))
1003 ; // Do nothing.
1004 else
1005 return Skipped.takeError();
1006 }
1007}
1008
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
unsigned uint64_t
#define STRINGIFY_CODE(PREFIX, CODE)
static bool canDecodeBlob(unsigned Code, unsigned BlockID)
static std::optional< const char * > GetBlockName(unsigned BlockID, const BitstreamBlockInfo &BlockInfo, CurStreamTypeType CurStreamType)
Return a symbolic block name if known, otherwise return null.
static Expected< CurStreamTypeType > ReadSignature(BitstreamCursor &Stream)
static std::optional< const char * > GetCodeName(unsigned CodeID, unsigned BlockID, const BitstreamBlockInfo &BlockInfo, CurStreamTypeType CurStreamType)
Return a symbolic code name if known, otherwise return null.
static void printSize(raw_ostream &OS, double Bits)
static Expected< CurStreamTypeType > analyzeHeader(std::optional< BCDumpOptions > O, BitstreamCursor &Stream)
static Error reportError(StringRef Message)
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define FUNCTION(NAME, NARG, ROUND_MODE, INTRINSIC)
#define NODE(NodeKind)
#define KIND(ENUM, FIELD)
Definition LVSupport.h:116
#define ENTRY(ASMNAME, ENUM)
block placement Basic Block Placement Stats
static constexpr StringLiteral Filename
static const int BlockSize
Definition TarWriter.cpp:33
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
const T * data() const
Definition ArrayRef.h:138
unsigned getNumOperandInfos() const
Definition BitCodes.h:118
const BitCodeAbbrevOp & getOperandInfo(unsigned N) const
Definition BitCodes.h:121
LLVM_ABI BitcodeAnalyzer(StringRef Buffer, std::optional< StringRef > BlockInfoBuffer=std::nullopt)
LLVM_ABI Error analyze(std::optional< BCDumpOptions > O=std::nullopt, std::optional< StringRef > CheckHash=std::nullopt)
Analyze the bitcode file.
LLVM_ABI void printStats(BCDumpOptions O, std::optional< StringRef > Filename=std::nullopt)
Print stats about the bitcode file.
This class maintains the abbreviations read from a block info block.
This represents a position within a bitcode file, implemented on top of a SimpleBitstreamCursor.
Error JumpToBit(uint64_t BitNo)
Reset the stream to the specified bit number.
uint64_t GetCurrentBitNo() const
Return the bit # of the bit we are reading.
Expected< unsigned > ReadSubBlockID()
Having read the ENTER_SUBBLOCK code, read the BlockID for the block.
ArrayRef< uint8_t > getBitcodeBytes() const
Expected< word_t > Read(unsigned NumBits)
LLVM_ABI Error EnterSubBlock(unsigned BlockID, unsigned *NumWordsP=nullptr)
Having read the ENTER_SUBBLOCK abbrevid, and enter the block.
Error SkipBlock()
Having read the ENTER_SUBBLOCK abbrevid and a BlockID, skip over the body of this block.
uint64_t getCurrentByteNo() const
@ AF_DontAutoprocessAbbrevs
If this flag is used, abbrev entries are returned just like normal records.
Expected< unsigned > ReadCode()
LLVM_ABI Expected< std::optional< BitstreamBlockInfo > > ReadBlockInfoBlock(bool ReadBlockInfoNames=false)
Read and return a block info block from the bitstream.
unsigned getAbbrevIDWidth() const
Return the number of bits used to encode an abbrev #.
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
Error takeError()
Take ownership of the stored error.
Definition Error.h:612
reference get()
Returns a reference to the stored T value.
Definition Error.h:582
LLVM_ABI void update(ArrayRef< uint8_t > Data)
Digest more data.
Definition SHA1.cpp:208
LLVM_ABI std::array< uint8_t, 20 > result()
Return the current raw 160-bits SHA1 for the digested data since the last call to init().
Definition SHA1.cpp:288
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
Definition StringRef.h:635
StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
Definition StringRef.h:720
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
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
raw_ostream & write_escaped(StringRef Str, bool UseHexEscapes=false)
Output Str, turning '\', '\t', ' ', '"', and anything that doesn't satisfy llvm::isPrint into an esca...
@ Entry
Definition COFF.h:862
@ METADATA_INDEX_OFFSET
@ CST_CODE_BLOCKADDRESS
@ BLOCKINFO_CODE_BLOCKNAME
@ BLOCKINFO_CODE_SETRECORDNAME
@ BLOCKINFO_CODE_SETBID
@ PARAMATTR_GROUP_BLOCK_ID
@ METADATA_KIND_BLOCK_ID
@ IDENTIFICATION_BLOCK_ID
@ GLOBALVAL_SUMMARY_BLOCK_ID
@ METADATA_ATTACHMENT_ID
@ FULL_LTO_GLOBALVAL_SUMMARY_BLOCK_ID
@ MODULE_STRTAB_BLOCK_ID
@ VALUE_SYMTAB_BLOCK_ID
@ OPERAND_BUNDLE_TAGS_BLOCK_ID
@ BLOCKINFO_BLOCK_ID
BLOCKINFO_BLOCK is used to define metadata about blocks, for example, standard abbrevs that should be...
@ FIRST_APPLICATION_BLOCKID
@ DEFINE_ABBREV
DEFINE_ABBREV - Defines an abbrev for the current block.
@ PARAMATTR_CODE_ENTRY_OLD
@ PARAMATTR_GRP_CODE_ENTRY
@ Skipped
Validation was skipped, as it was not needed.
NodeAddr< CodeNode * > Code
Definition RDFGraph.h:388
void write32be(void *P, uint32_t V)
Definition Endian.h:464
uint32_t read32le(const void *P)
Definition Endian.h:412
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
void stable_sort(R &&Range)
Definition STLExtras.h:2116
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition STLExtras.h:1669
@ BWH_OffsetField
@ BWH_VersionField
@ BWH_MagicField
@ BWH_HeaderSize
@ BWH_CPUTypeField
@ BWH_SizeField
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition Error.h:1321
FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
format_hex - Output N as a fixed width hexadecimal.
Definition Format.h:164
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition Format.h:102
CurStreamTypeType
CurStreamTypeType - A type for CurStreamType.
@ UnknownBitstream
@ ClangSerializedDiagnosticsBitstream
@ LLVMIRBitstream
@ ClangSerializedASTBitstream
@ LLVMBitstreamRemarks
DWARFExpression::Operation Op
bool SkipBitcodeWrapperHeader(const unsigned char *&BufPtr, const unsigned char *&BufEnd, bool VerifyBufferSize)
SkipBitcodeWrapperHeader - Some systems wrap bc files with a special header for padding or other reas...
bool isPrint(char C)
Checks whether character C is printable.
bool isBitcodeWrapper(const unsigned char *BufPtr, const unsigned char *BufEnd)
isBitcodeWrapper - Return true if the given bytes are the magic bytes for an LLVM IR bitcode wrapper.
This contains information emitted to BLOCKINFO_BLOCK blocks.