1//===- BitcodeReader.cpp - Internal BitcodeReader implementation ----------===// 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 7//===----------------------------------------------------------------------===// 24#include "llvm/Config/llvm-config.h" 54#include "llvm/IR/IntrinsicsAArch64.h" 55#include "llvm/IR/IntrinsicsARM.h" 88#include <system_error> 98"Print the global id for each value when reading the module summary"));
103"Expand constant expressions to instructions for testing purposes"));
105/// Load bitcode directly into RemoveDIs format (use debug records instead 106/// of debug intrinsics). UNSET is treated as FALSE, so the default action 107/// is to do nothing. Individual tools can override this to incrementally add 108/// support for the RemoveDIs format. 110"load-bitcode-into-experimental-debuginfo-iterators",
cl::Hidden,
111cl::desc(
"Load bitcode directly into the new debug info format (regardless " 121 SWITCH_INST_MAGIC = 0x4B5
// May 2012 => 1205 => Hex 124}
// end anonymous namespace 127return make_error<StringError>(
134"file too small to contain bitcode header");
135for (
unsignedC : {
'B',
'C'})
139"file doesn't start with bitcode header");
141return Res.takeError();
142for (
unsignedC : {0x0, 0xC, 0xE, 0xD})
146"file doesn't start with bitcode header");
148return Res.takeError();
153constunsignedchar *BufPtr = (
constunsignedchar *)Buffer.
getBufferStart();
157returnerror(
"Invalid bitcode signature");
159// If we have a wrapper header, parse it and ignore the non-bc file contents. 160// The magic number is 0x0B17C0DE stored in little endian. 163returnerror(
"Invalid bitcode wrapper header");
167return std::move(Err);
169return std::move(Stream);
172/// Convert a string from a record into an std::string, return true on failure. 173template <
typename StrTy>
183// Strip all the TBAA attachment for the module. 186if (
F.isMaterializable())
189I.setMetadata(LLVMContext::MD_tbaa,
nullptr);
193/// Read the "IDENTIFICATION_BLOCK_ID" block, do some basic enforcement on the 194/// "epoch" encoded in the bitcode, and return the producer name if any. 197return std::move(Err);
199// Read all the records. 202 std::string ProducerIdentification;
212returnerror(
"Malformed block");
214return ProducerIdentification;
216// The interesting case. 225switch (MaybeBitCode.
get()) {
226default:
// Default behavior: reject 227returnerror(
"Invalid value");
235Twine(
"Incompatible epoch: Bitcode '") +
Twine(epoch) +
244// We expect a number of well-defined blocks, though we don't necessarily 245// need to understand them all. 257returnerror(
"Malformed block");
263// Ignore other sub-blocks. 265return std::move(Err);
277return std::move(Err);
280// Read all the records for this module. 291returnerror(
"Malformed block");
295// The interesting case. 303switch (MaybeRecord.
get()) {
305break;
// Default behavior, ignore unknown content. 309returnerror(
"Invalid section name record");
310// Check for the i386 and other (x86_64, ARM) conventions 311if (S.find(
"__DATA,__objc_catlist") != std::string::npos ||
312 S.find(
"__OBJC,__category") != std::string::npos ||
313 S.find(
"__TEXT,__swift") != std::string::npos)
324// We expect a number of well-defined blocks, though we don't necessarily 325// need to understand them all. 333returnerror(
"Malformed block");
341// Ignore other sub-blocks. 343return std::move(Err);
356return std::move(Err);
362// Read all the records for this module. 372returnerror(
"Malformed block");
376// The interesting case. 384switch (MaybeRecord.
get()) {
385default:
break;
// Default behavior, ignore unknown content. 389returnerror(
"Invalid triple record");
400// We expect a number of well-defined blocks, though we don't necessarily 401// need to understand them all. 410returnerror(
"Malformed block");
418// Ignore other sub-blocks. 420return std::move(Err);
427return Skipped.takeError();
434classBitcodeReaderBase {
437 : Stream(
std::
move(Stream)), Strtab(Strtab) {
445 /// In version 2 of the bitcode we store names of global values and comdats in 446 /// a string table rather than in the VST. 447bool UseStrtab =
false;
451 /// If this module uses a string table, pop the reference to the string table 452 /// and return the referenced string and the rest of the record. Otherwise 453 /// just return the record itself. 454 std::pair<StringRef, ArrayRef<uint64_t>>
457Error readBlockInfo();
459// Contains an arbitrary and optional string identifying the bitcode producer 460 std::string ProducerIdentification;
465}
// end anonymous namespace 467Error BitcodeReaderBase::error(
constTwine &Message) {
468 std::string FullMsg = Message.
str();
469if (!ProducerIdentification.empty())
470 FullMsg +=
" (Producer: '" + ProducerIdentification +
"' Reader: 'LLVM " +
471 LLVM_VERSION_STRING
"')";
472 return ::error(FullMsg);
478returnerror(
"Invalid version record");
479unsigned ModuleVersion =
Record[0];
480if (ModuleVersion > 2)
481returnerror(
"Invalid value");
482 UseStrtab = ModuleVersion >= 2;
486std::pair<StringRef, ArrayRef<uint64_t>>
490// Invalid reference. Let the caller complain about the record being empty. 498/// This represents a constant expression or constant aggregate using a custom 499/// structure internal to the bitcode reader. Later, this structure will be 500/// expanded by materializeValue() either into a constant expression/aggregate, 501/// or into an instruction sequence at the point of use. This allows us to 502/// upgrade bitcode using constant expressions even if this kind of constant 503/// expression is no longer supported. 504classBitcodeConstant final :
publicValue,
508// Value subclass ID: Pick largest possible value to avoid any clashes. 509staticconstexpruint8_t SubclassID = 255;
512// Opcodes used for non-expressions. This includes constant aggregates 513// (struct, array, vector) that might need expansion, as well as non-leaf 514// constants that don't need expansion (no_cfi, dso_local, blockaddress), 515// but still go through BitcodeConstant to avoid different uselist orders 516// between the two cases. 517staticconstexpruint8_t ConstantStructOpcode = 255;
518staticconstexpruint8_t ConstantArrayOpcode = 254;
519staticconstexpruint8_t ConstantVectorOpcode = 253;
520staticconstexpruint8_t NoCFIOpcode = 252;
521staticconstexpruint8_t DSOLocalEquivalentOpcode = 251;
522staticconstexpruint8_t BlockAddressOpcode = 250;
523staticconstexpruint8_t ConstantPtrAuthOpcode = 249;
524staticconstexpruint8_t FirstSpecialOpcode = ConstantPtrAuthOpcode;
526// Separate struct to make passing different number of parameters to 527// BitcodeConstant::create() more convenient. 531unsigned BlockAddressBB = 0;
532Type *SrcElemTy =
nullptr;
533 std::optional<ConstantRange> InRange;
536 std::optional<ConstantRange> InRange = std::nullopt)
537 : Opcode(Opcode),
Flags(
Flags), SrcElemTy(SrcElemTy),
541 : Opcode(Opcode),
Flags(
Flags), BlockAddressBB(BlockAddressBB) {}
547unsigned BlockAddressBB;
548Type *SrcElemTy;
// GEP source element type. 549 std::optional<ConstantRange>
InRange;
// GEP inrange attribute. 554 NumOperands(OpIDs.
size()), BlockAddressBB(
Info.BlockAddressBB),
555 SrcElemTy(
Info.SrcElemTy), InRange(
Info.InRange) {
556 std::uninitialized_copy(OpIDs.
begin(), OpIDs.
end(),
557 getTrailingObjects<unsigned>());
560 BitcodeConstant &
operator=(
const BitcodeConstant &) =
delete;
564const ExtraInfo &Info,
566void *Mem =
A.Allocate(totalSizeToAlloc<unsigned>(OpIDs.
size()),
567alignof(BitcodeConstant));
568returnnew (Mem) BitcodeConstant(Ty, Info, OpIDs);
571staticbool classof(
constValue *V) {
returnV->getValueID() == SubclassID; }
574returnArrayRef(getTrailingObjects<unsigned>(), NumOperands);
577 std::optional<ConstantRange> getInRange()
const{
578assert(Opcode == Instruction::GetElementPtr);
587classBitcodeReader :
public BitcodeReaderBase,
publicGVMaterializer {
589Module *TheModule =
nullptr;
590// Next offset to start scanning for lazy parsing of function bodies. 592// Last function offset found in the VST. 594bool SeenValueSymbolTable =
false;
597 std::vector<std::string> SectionTable;
598 std::vector<std::string> GCTable;
600 std::vector<Type *> TypeList;
601 /// Track type IDs of contained types. Order is the same as the contained 602 /// types of a Type*. This is used during upgrades of typed pointer IR in 603 /// opaque pointer mode. 605 /// In some cases, we need to create a type ID for a type that was not 606 /// explicitly encoded in the bitcode, or we don't know about at the current 607 /// point. For example, a global may explicitly encode the value type ID, but 608 /// not have a type ID for the pointer to value type, for which we create a 609 /// virtual type ID instead. This map stores the new type ID that was created 610 /// for the given pair of Type and contained type ID. 613 /// Allocator for BitcodeConstants. This should come before ValueList, 614 /// because the ValueList might hold ValueHandles to these constants, so 615 /// ValueList must be destroyed before Alloc. 618 std::optional<MetadataLoader> MDLoader;
619 std::vector<Comdat *> ComdatList;
623 std::vector<std::pair<GlobalVariable *, unsigned>> GlobalInits;
624 std::vector<std::pair<GlobalValue *, unsigned>> IndirectSymbolInits;
626structFunctionOperandInfo {
628unsigned PersonalityFn;
632 std::vector<FunctionOperandInfo> FunctionOperands;
634 /// The set of attributes by index. Index zero in the file is for null, and 635 /// is thus not represented here. As such all indices are off by one. 636 std::vector<AttributeList> MAttributes;
638 /// The set of attribute groups. 639 std::map<unsigned, AttributeList> MAttributeGroups;
641 /// While parsing a function body, this is a list of the basic blocks for the 643 std::vector<BasicBlock*> FunctionBBs;
645// When reading the module header, this list is populated with functions that 646// have bodies later in the file. 647 std::vector<Function*> FunctionsWithBodies;
649// When intrinsic functions are encountered which require upgrading they are 650// stored here with their replacement function. 652 UpdatedIntrinsicMap UpgradedIntrinsics;
654// Several operations happen after the module header has been read, but 655// before function bodies are processed. This keeps track of whether 656// we've done this yet. 657bool SeenFirstFunctionBody =
false;
659 /// When function bodies are initially scanned, this map contains info about 660 /// where to find deferred function body in the stream. 663 /// When Metadata block is initially scanned when parsing the module, we may 664 /// choose to defer parsing of the metadata. This vector contains info about 665 /// which Metadata blocks are deferred. 666 std::vector<uint64_t> DeferredMetadataInfo;
668 /// These are basic blocks forward-referenced by block addresses. They are 669 /// inserted lazily into functions when they're loaded. The basic block ID is 670 /// its index into the vector. 672 std::deque<Function *> BasicBlockFwdRefQueue;
674 /// These are Functions that contain BlockAddresses which refer a different 675 /// Function. When parsing the different Function, queue Functions that refer 676 /// to the different Function. Those Functions must be materialized in order 677 /// to resolve their BlockAddress constants before the different Function 678 /// gets moved into another Module. 679 std::vector<Function *> BackwardRefFunctions;
681 /// Indicates that we are using a new encoding for instruction operands where 682 /// most operands in the current FUNCTION_BLOCK are encoded relative to the 683 /// instruction number, for a more compact encoding. Some instruction 684 /// operands are not relative to the instruction ID: basic block numbers, and 685 /// types. Once the old style function blocks have been phased out, we would 686 /// not need this flag. 687bool UseRelativeIDs =
false;
689 /// True if all functions will be materialized, negating the need to process 690 /// (e.g.) blockaddress forward references. 691bool WillMaterializeAllForwardRefs =
false;
693 /// Tracks whether we have seen debug intrinsics or records in this bitcode; 694 /// seeing both in a single module is currently a fatal error. 695bool SeenDebugIntrinsic =
false;
696bool SeenDebugRecord =
false;
701 std::vector<std::string> BundleTags;
704 std::optional<ValueTypeCallbackTy> ValueTypeCallback;
710Error materializeForwardReferencedFunctions();
716 /// Main interface to parsing a bitcode buffer. 717 /// \returns true if an error occurred. 718Error parseBitcodeInto(
Module *M,
bool ShouldLazyLoadMetadata,
723 /// Materialize any deferred Metadata block. 729 std::vector<StructType *> IdentifiedStructTypes;
733staticconstexprunsigned InvalidTypeID = ~0
u;
735Type *getTypeByID(
unsignedID);
736Type *getPtrElementTypeByID(
unsignedID);
737unsigned getContainedTypeID(
unsignedID,
unsignedIdx = 0);
744Value *getFnValueByID(
unsignedID,
Type *Ty,
unsigned TyID,
752return MDLoader->getMetadataFwdRefOrLoad(
ID);
756if (
ID >= FunctionBBs.size())
returnnullptr;
// Invalid ID 757return FunctionBBs[
ID];
761if (i-1 < MAttributes.size())
762return MAttributes[i-1];
766 /// Read a value/type pair out of the specified record from slot 'Slot'. 767 /// Increment Slot past the number of slots used in the record. Return true on 772if (Slot ==
Record.size())
returntrue;
774// Adjust the ValNo, if it was encoded relative to the InstNum. 776 ValNo = InstNum - ValNo;
777if (ValNo < InstNum) {
778// If this is not a forward reference, just return the value we already 781 ResVal = getFnValueByID(ValNo,
nullptr,
TypeID, ConstExprInsertBB);
783"Incorrect type ID stored for value");
784return ResVal ==
nullptr;
790 ResVal = getFnValueByID(ValNo, getTypeByID(
TypeID),
TypeID,
792return ResVal ==
nullptr;
796unsigned &Slot,
unsigned InstNum,
Value *&ResVal,
803return getValueTypePair(
Record, --Slot, InstNum, ResVal, TypeId,
813 /// Read a value out of the specified record from slot 'Slot'. Increment Slot 814 /// past the number of slots used by the value in the record. Return true if 815 /// there is an error. 817unsigned InstNum,
Type *Ty,
unsigned TyID,
Value *&ResVal,
819if (getValue(
Record, Slot, InstNum, Ty, TyID, ResVal, ConstExprInsertBB))
821// All values currently take a single record slot. 826 /// Like popValue, but does not increment the Slot number. 828unsigned InstNum,
Type *Ty,
unsigned TyID,
Value *&ResVal,
830 ResVal = getValue(
Record, Slot, InstNum, Ty, TyID, ConstExprInsertBB);
831return ResVal ==
nullptr;
834 /// Version of getValue that returns ResVal directly, or 0 if there is an 837unsigned InstNum,
Type *Ty,
unsigned TyID,
839if (Slot ==
Record.size())
returnnullptr;
841// Adjust the ValNo, if it was encoded relative to the InstNum. 843 ValNo = InstNum - ValNo;
844return getFnValueByID(ValNo, Ty, TyID, ConstExprInsertBB);
847 /// Like getValue, but decodes signed VBRs. 849unsigned InstNum,
Type *Ty,
unsigned TyID,
851if (Slot ==
Record.size())
returnnullptr;
853// Adjust the ValNo, if it was encoded relative to the InstNum. 855 ValNo = InstNum - ValNo;
856return getFnValueByID(ValNo, Ty, TyID, ConstExprInsertBB);
862if (
Record.size() - OpNum < 2)
863returnerror(
"Too few records for range");
865unsigned LowerActiveWords =
Record[OpNum];
866unsigned UpperActiveWords =
Record[OpNum++] >> 32;
867if (
Record.size() - OpNum < LowerActiveWords + UpperActiveWords)
868returnerror(
"Too few records for range");
871 OpNum += LowerActiveWords;
874 OpNum += UpperActiveWords;
877 int64_t Start = BitcodeReader::decodeSignRotatedValue(
Record[OpNum++]);
878 int64_t
End = BitcodeReader::decodeSignRotatedValue(
Record[OpNum++]);
886if (
Record.size() - OpNum < 1)
887returnerror(
"Too few records for range");
892 /// Upgrades old-style typeless byval/sret/inalloca attributes by adding the 893 /// corresponding argument's pointee type. Also upgrades intrinsics that now 894 /// require an elementtype attribute. 897 /// Converts alignment exponent (i.e. power of two (or zero)) to the 898 /// corresponding alignment to use. If alignment is too large, returns 899 /// a corresponding error code. 908Error parseGlobalIndirectSymbolRecord(
unsigned BitCode,
911Error parseAttributeBlock();
912Error parseAttributeGroupBlock();
913Error parseTypeTable();
914Error parseTypeTableBody();
915Error parseOperandBundleTags();
916Error parseSyncScopeNames();
919unsigned NameIndex,
Triple &TT);
920void setDeferredFunctionInfo(
unsigned FuncBitcodeOffsetDelta,
Function *
F,
923Error parseGlobalValueSymbolTable();
924Error parseConstants();
925Error rememberAndSkipFunctionBodies();
926Error rememberAndSkipFunctionBody();
927 /// Save the positions of the Metadata blocks and skip parsing the blocks. 928Error rememberAndSkipMetadata();
931Error globalCleanup();
932Error resolveGlobalAndIndirectSymbolInits();
933Error parseUseLists();
934Error findFunctionInStream(
941/// Class to manage reading and parsing function summary index bitcode 943classModuleSummaryIndexBitcodeReader :
public BitcodeReaderBase {
944 /// The module index built during parsing. 947 /// Indicates whether we have encountered a global value summary section 948 /// yet during parsing. 949bool SeenGlobalValSummary =
false;
951 /// Indicates whether we have already parsed the VST, used for error checking. 952bool SeenValueSymbolTable =
false;
954 /// Set to the offset of the VST recorded in the MODULE_CODE_VSTOFFSET record. 955 /// Used to enable on-demand parsing of the VST. 958// Map to save ValueId to ValueInfo association that was recorded in the 959// ValueSymbolTable. It is used after the VST is parsed to convert 960// call graph edges read from the function summary from referencing 961// callees by their ValueId to using the ValueInfo instead, which is how 962// they are recorded in the summary index being built. 963// We save a GUID which refers to the same global as the ValueInfo, but 964// ignoring the linkage, i.e. for values other than local linkage they are 965// identical (this is the second member). ValueInfo has the real GUID. 967 ValueIdToValueInfoMap;
969 /// Map populated during module path string table parsing, from the 970 /// module ID to a string reference owned by the index's module 971 /// path string table, used to correlate with combined index 975 /// Original source file name recorded in a bitcode record. 976 std::string SourceFileName;
978 /// The string identifier given to this module by the client, normally the 979 /// path to the bitcode file. 982 /// Callback to ask whether a symbol is the prevailing copy when invoked 983 /// during combined index building. 986 /// Saves the stack ids from the STACK_IDS record to consult when adding stack 987 /// ids from the lists in the callsite and alloc entries to the index. 988 std::vector<uint64_t> StackIds;
990 /// Linearized radix tree of allocation contexts. See the description above 991 /// the CallStackRadixTreeBuilder class in ProfileData/MemProf.h for format. 992 std::vector<uint64_t> RadixArray;
995 ModuleSummaryIndexBitcodeReader(
1006Error parseValueSymbolTable(
1012bool HasProfile,
bool HasRelBF);
1013Error parseEntireSummary(
unsignedID);
1014Error parseModuleStringTable();
1018 std::vector<FunctionSummary::ParamAccess>
1023template <
bool AllowNullValueInfo = false>
1024 std::pair<ValueInfo, GlobalValue::GUID>
1025 getValueInfoFromValueId(
unsigned ValueId);
1027void addThisModule();
1031}
// end anonymous namespace 1043return std::error_code();
1049 : BitcodeReaderBase(
std::
move(Stream), Strtab), Context(Context),
1050 ValueList(this->Stream.SizeInBytes(),
1052return materializeValue(
ValID, InsertBB);
1054 this->ProducerIdentification = std::string(ProducerIdentification);
1057Error BitcodeReader::materializeForwardReferencedFunctions() {
1058if (WillMaterializeAllForwardRefs)
1061// Prevent recursion. 1062 WillMaterializeAllForwardRefs =
true;
1064while (!BasicBlockFwdRefQueue.empty()) {
1065Function *
F = BasicBlockFwdRefQueue.front();
1066 BasicBlockFwdRefQueue.pop_front();
1067assert(
F &&
"Expected valid function");
1068if (!BasicBlockFwdRefs.
count(
F))
1069// Already materialized. 1072// Check for a function that isn't materializable to prevent an infinite 1073// loop. When parsing a blockaddress stored in a global variable, there 1074// isn't a trivial way to check if a function will have a body without a 1075// linear search through FunctionsWithBodies, so just check it here. 1076if (!
F->isMaterializable())
1077returnerror(
"Never resolved function from blockaddress");
1079// Try to materialize F. 1080if (
Error Err = materialize(
F))
1083assert(BasicBlockFwdRefs.
empty() &&
"Function missing from queue");
1086if (
Error Err = materialize(
F))
1088 BackwardRefFunctions.clear();
1091 WillMaterializeAllForwardRefs =
false;
1095//===----------------------------------------------------------------------===// 1096// Helper functions to implement forward reference resolution, etc. 1097//===----------------------------------------------------------------------===// 1103case 1:
// Old WeakAnyLinkage 1104case 4:
// Old LinkOnceAnyLinkage 1105case 10:
// Old WeakODRLinkage 1106case 11:
// Old LinkOnceODRLinkage 1113default:
// Map unknown/new linkages to external 1138case 1:
// Old value with implicit comdat. 1141case 10:
// Old value with implicit comdat. 1144case 4:
// Old value with implicit comdat. 1147case 11:
// Old value with implicit comdat. 1155 Flags.ReadNone = RawFlags & 0x1;
1156 Flags.ReadOnly = (RawFlags >> 1) & 0x1;
1157 Flags.NoRecurse = (RawFlags >> 2) & 0x1;
1158 Flags.ReturnDoesNotAlias = (RawFlags >> 3) & 0x1;
1159 Flags.NoInline = (RawFlags >> 4) & 0x1;
1160 Flags.AlwaysInline = (RawFlags >> 5) & 0x1;
1161 Flags.NoUnwind = (RawFlags >> 6) & 0x1;
1162 Flags.MayThrow = (RawFlags >> 7) & 0x1;
1163 Flags.HasUnknownCall = (RawFlags >> 8) & 0x1;
1164 Flags.MustBeUnreachable = (RawFlags >> 9) & 0x1;
1168// Decode the flags for GlobalValue in the summary. The bits for each attribute: 1170// linkage: [0,4), notEligibleToImport: 4, live: 5, local: 6, canAutoHide: 7, 1171// visibility: [8, 10). 1174// Summary were not emitted before LLVM 3.9, we don't need to upgrade Linkage 1175// like getDecodedLinkage() above. Any future change to the linkage enum and 1176// to getDecodedLinkage() will need to be taken into account here as above. 1180 RawFlags = RawFlags >> 4;
1181bool NotEligibleToImport = (RawFlags & 0x1) || Version < 3;
1182// The Live flag wasn't introduced until version 3. For dead stripping 1183// to work correctly on earlier versions, we must conservatively treat all 1185boolLive = (RawFlags & 0x2) || Version < 3;
1186boolLocal = (RawFlags & 0x4);
1187bool AutoHide = (RawFlags & 0x8);
1193// Decode the flags for GlobalVariable in the summary 1196 (RawFlags & 0x1) ?
true :
false, (RawFlags & 0x2) ?
true :
false,
1197 (RawFlags & 0x4) ?
true :
false,
1201static std::pair<CalleeInfo::HotnessType, bool>
1205bool HasTailCall = (RawFlags & 0x8);
// 1 bit 1206return {Hotness, HasTailCall};
1211staticconstexpruint64_t RelBlockFreqMask =
1213 RelBF = RawFlags & RelBlockFreqMask;
// RelBlockFreqBits bits 1219default:
// Map unknown visibilities to default. 1229default:
// Map unknown values to default. 1238default:
// Map unknown values to preemptable. 1263case 0:
return GlobalVariable::NotThreadLocal;
1264default:
// Map unknown non-zero value to general dynamic. 1265case 1:
return GlobalVariable::GeneralDynamicTLSModel;
1266case 2:
return GlobalVariable::LocalDynamicTLSModel;
1267case 3:
return GlobalVariable::InitialExecTLSModel;
1268case 4:
return GlobalVariable::LocalExecTLSModel;
1274default:
// Map unknown to UnnamedAddr::None. 1275case 0:
return GlobalVariable::UnnamedAddr::None;
1276case 1:
return GlobalVariable::UnnamedAddr::Global;
1277case 2:
return GlobalVariable::UnnamedAddr::Local;
1302// UnOps are only valid for int/fp or vector of int/fp types 1310return IsFP ? Instruction::FNeg : -1;
1316// BinOps are only valid for int/fp or vector of int/fp types 1324return IsFP ? Instruction::FAdd : Instruction::Add;
1326return IsFP ? Instruction::FSub : Instruction::Sub;
1328return IsFP ? Instruction::FMul : Instruction::Mul;
1330return IsFP ? -1 : Instruction::UDiv;
1332return IsFP ? Instruction::FDiv : Instruction::SDiv;
1334return IsFP ? -1 : Instruction::URem;
1336return IsFP ? Instruction::FRem : Instruction::SRem;
1338return IsFP ? -1 : Instruction::Shl;
1340return IsFP ? -1 : Instruction::LShr;
1342return IsFP ? -1 : Instruction::AShr;
1344return IsFP ? -1 : Instruction::And;
1346return IsFP ? -1 : Instruction::Or;
1348return IsFP ? -1 : Instruction::Xor;
1389default:
// Map unknown orderings to sequentially-consistent. 1396default:
// Map unknown selection kinds to any. 1432// A GlobalValue with local linkage cannot have a DLL storage class. 1441Type *BitcodeReader::getTypeByID(
unsignedID) {
1442// The type table size is always specified correctly. 1443if (
ID >= TypeList.size())
1446if (
Type *Ty = TypeList[
ID])
1449// If we have a forward reference, the only possible case is when it is to a 1450// named struct. Just create a placeholder for now. 1451return TypeList[
ID] = createIdentifiedStructType(Context);
1454unsigned BitcodeReader::getContainedTypeID(
unsignedID,
unsignedIdx) {
1455auto It = ContainedTypeIDs.
find(
ID);
1456if (It == ContainedTypeIDs.
end())
1457return InvalidTypeID;
1459if (
Idx >= It->second.size())
1460return InvalidTypeID;
1462return It->second[
Idx];
1465Type *BitcodeReader::getPtrElementTypeByID(
unsignedID) {
1466if (
ID >= TypeList.size())
1473return getTypeByID(getContainedTypeID(
ID, 0));
1476unsigned BitcodeReader::getVirtualTypeID(
Type *Ty,
1478unsigned ChildTypeID = ChildTypeIDs.
empty() ? InvalidTypeID : ChildTypeIDs[0];
1479auto CacheKey = std::make_pair(Ty, ChildTypeID);
1480auto It = VirtualTypeIDs.
find(CacheKey);
1481if (It != VirtualTypeIDs.
end()) {
1482// The cmpxchg return value is the only place we need more than one 1483// contained type ID, however the second one will always be the same (i1), 1484// so we don't need to include it in the cache key. This asserts that the 1485// contained types are indeed as expected and there are no collisions. 1487 ContainedTypeIDs[It->second] == ChildTypeIDs) &&
1488"Incorrect cached contained type IDs");
1492unsignedTypeID = TypeList.size();
1493 TypeList.push_back(Ty);
1494if (!ChildTypeIDs.
empty())
1514// These are not real constant expressions, always consider them supported. 1515if (Opcode >= BitcodeConstant::FirstSpecialOpcode)
1518// If -expand-constant-exprs is set, we want to consider all expressions 1529if (Opcode == Instruction::GetElementPtr)
1533case Instruction::FNeg:
1534case Instruction::Select:
1535case Instruction::ICmp:
1536case Instruction::FCmp:
1545// Quickly handle the case where there is no BitcodeConstant to resolve. 1546if (StartValID < ValueList.
size() && ValueList[StartValID] &&
1547 !isa<BitcodeConstant>(ValueList[StartValID]))
1548return ValueList[StartValID];
1553while (!Worklist.
empty()) {
1556// Duplicate expression that was already handled. 1562returnerror(
"Invalid value ID");
1565auto *BC = dyn_cast<BitcodeConstant>(V);
1572// Iterate in reverse, so values will get popped from the worklist in 1575for (
unsigned OpID :
reverse(BC->getOperandIDs())) {
1576auto It = MaterializedValues.
find(OpID);
1577if (It != MaterializedValues.
end())
1583// Some expressions have not been resolved yet, handle them first and then 1585if (Ops.
size() != BC->getOperandIDs().size())
1587 std::reverse(Ops.
begin(), Ops.
end());
1591if (
auto *
C = dyn_cast<Constant>(
Op))
1594// Materialize as constant expression if possible. 1604switch (BC->Opcode) {
1605case BitcodeConstant::ConstantPtrAuthOpcode: {
1606auto *
Key = dyn_cast<ConstantInt>(ConstOps[1]);
1608returnerror(
"ptrauth key operand must be ConstantInt");
1610auto *Disc = dyn_cast<ConstantInt>(ConstOps[2]);
1612returnerror(
"ptrauth disc operand must be ConstantInt");
1617case BitcodeConstant::NoCFIOpcode: {
1618auto *GV = dyn_cast<GlobalValue>(ConstOps[0]);
1620returnerror(
"no_cfi operand must be GlobalValue");
1624case BitcodeConstant::DSOLocalEquivalentOpcode: {
1625auto *GV = dyn_cast<GlobalValue>(ConstOps[0]);
1627returnerror(
"dso_local operand must be GlobalValue");
1631case BitcodeConstant::BlockAddressOpcode: {
1632Function *Fn = dyn_cast<Function>(ConstOps[0]);
1634returnerror(
"blockaddress operand must be a function");
1636// If the function is already parsed we can insert the block address 1639unsigned BBID = BC->BlockAddressBB;
1641// Invalid reference to entry block. 1642returnerror(
"Invalid ID");
1645for (
size_tI = 0, E = BBID;
I != E; ++
I) {
1647returnerror(
"Invalid ID");
1652// Otherwise insert a placeholder and remember it so it can be 1653// inserted when the function is parsed. 1654auto &FwdBBs = BasicBlockFwdRefs[Fn];
1656 BasicBlockFwdRefQueue.push_back(Fn);
1657if (FwdBBs.size() < BBID + 1)
1658 FwdBBs.resize(BBID + 1);
1666case BitcodeConstant::ConstantStructOpcode: {
1667auto *
ST = cast<StructType>(BC->getType());
1668if (
ST->getNumElements() != ConstOps.
size())
1669returnerror(
"Invalid number of elements in struct initializer");
1671for (
constauto [Ty,
Op] :
zip(
ST->elements(), ConstOps))
1672if (
Op->getType() != Ty)
1673returnerror(
"Incorrect type in struct initializer");
1678case BitcodeConstant::ConstantArrayOpcode: {
1679auto *AT = cast<ArrayType>(BC->getType());
1680if (AT->getNumElements() != ConstOps.
size())
1681returnerror(
"Invalid number of elements in array initializer");
1684if (
Op->getType() != AT->getElementType())
1685returnerror(
"Incorrect type in array initializer");
1690case BitcodeConstant::ConstantVectorOpcode: {
1691auto *VT = cast<FixedVectorType>(BC->getType());
1692if (VT->getNumElements() != ConstOps.size())
1693returnerror(
"Invalid number of elements in vector initializer");
1696if (
Op->getType() != VT->getElementType())
1697returnerror(
"Incorrect type in vector initializer");
1702case Instruction::GetElementPtr:
1704 BC->SrcElemTy, ConstOps[0],
ArrayRef(ConstOps).drop_front(),
1707case Instruction::ExtractElement:
1710case Instruction::InsertElement:
1714case Instruction::ShuffleVector: {
1725// Cache resolved constant. 1733returnerror(
Twine(
"Value referenced by initializer is an unsupported " 1734"constant expression of type ") +
1735 BC->getOpcodeName());
1737// Materialize as instructions if necessary. 1741 BC->getType(),
"constexpr", InsertBB);
1744"constexpr", InsertBB);
1747 Ops[1],
"constexpr", InsertBB);
1748if (isa<OverflowingBinaryOperator>(
I)) {
1750I->setHasNoSignedWrap();
1752I->setHasNoUnsignedWrap();
1754if (isa<PossiblyExactOperator>(
I) &&
1758switch (BC->Opcode) {
1759case BitcodeConstant::ConstantVectorOpcode: {
1763Value *
Idx = ConstantInt::get(IdxTy, Pair.index());
1767I = cast<Instruction>(V);
1770case BitcodeConstant::ConstantStructOpcode:
1771case BitcodeConstant::ConstantArrayOpcode: {
1775"constexpr.ins", InsertBB);
1776I = cast<Instruction>(V);
1779case Instruction::ICmp:
1780case Instruction::FCmp:
1783"constexpr", InsertBB);
1785case Instruction::GetElementPtr:
1787ArrayRef(Ops).drop_front(),
"constexpr",
1791case Instruction::Select:
1794case Instruction::ExtractElement:
1797case Instruction::InsertElement:
1801case Instruction::ShuffleVector:
1814return MaterializedValues[StartValID];
1822// Result must be Constant if InsertBB is nullptr. 1823return cast<Constant>(MaybeV.
get());
1829 IdentifiedStructTypes.push_back(Ret);
1835 IdentifiedStructTypes.push_back(Ret);
1839//===----------------------------------------------------------------------===// 1840// Functions for parsing blocks from the bitcode file 1841//===----------------------------------------------------------------------===// 1851case Attribute::ZExt:
return 1 << 0;
1852case Attribute::SExt:
return 1 << 1;
1853case Attribute::NoReturn:
return 1 << 2;
1854case Attribute::InReg:
return 1 << 3;
1855case Attribute::StructRet:
return 1 << 4;
1856case Attribute::NoUnwind:
return 1 << 5;
1857case Attribute::NoAlias:
return 1 << 6;
1858case Attribute::ByVal:
return 1 << 7;
1859case Attribute::Nest:
return 1 << 8;
1860case Attribute::ReadNone:
return 1 << 9;
1861case Attribute::ReadOnly:
return 1 << 10;
1862case Attribute::NoInline:
return 1 << 11;
1863case Attribute::AlwaysInline:
return 1 << 12;
1864case Attribute::OptimizeForSize:
return 1 << 13;
1865case Attribute::StackProtect:
return 1 << 14;
1866case Attribute::StackProtectReq:
return 1 << 15;
1867case Attribute::Alignment:
return 31 << 16;
1868case Attribute::NoCapture:
return 1 << 21;
1869case Attribute::NoRedZone:
return 1 << 22;
1870case Attribute::NoImplicitFloat:
return 1 << 23;
1871case Attribute::Naked:
return 1 << 24;
1872case Attribute::InlineHint:
return 1 << 25;
1873case Attribute::StackAlignment:
return 7 << 26;
1874case Attribute::ReturnsTwice:
return 1 << 29;
1875case Attribute::UWTable:
return 1 << 30;
1876case Attribute::NonLazyBind:
return 1U << 31;
1877case Attribute::SanitizeAddress:
return 1ULL << 32;
1878case Attribute::MinSize:
return 1ULL << 33;
1879case Attribute::NoDuplicate:
return 1ULL << 34;
1880case Attribute::StackProtectStrong:
return 1ULL << 35;
1881case Attribute::SanitizeThread:
return 1ULL << 36;
1882case Attribute::SanitizeMemory:
return 1ULL << 37;
1883case Attribute::NoBuiltin:
return 1ULL << 38;
1884case Attribute::Returned:
return 1ULL << 39;
1885case Attribute::Cold:
return 1ULL << 40;
1886case Attribute::Builtin:
return 1ULL << 41;
1887case Attribute::OptimizeNone:
return 1ULL << 42;
1888case Attribute::InAlloca:
return 1ULL << 43;
1889case Attribute::NonNull:
return 1ULL << 44;
1890case Attribute::JumpTable:
return 1ULL << 45;
1891case Attribute::Convergent:
return 1ULL << 46;
1892case Attribute::SafeStack:
return 1ULL << 47;
1893case Attribute::NoRecurse:
return 1ULL << 48;
1894// 1ULL << 49 is InaccessibleMemOnly, which is upgraded separately. 1895// 1ULL << 50 is InaccessibleMemOrArgMemOnly, which is upgraded separately. 1896case Attribute::SwiftSelf:
return 1ULL << 51;
1897case Attribute::SwiftError:
return 1ULL << 52;
1898case Attribute::WriteOnly:
return 1ULL << 53;
1899case Attribute::Speculatable:
return 1ULL << 54;
1900case Attribute::StrictFP:
return 1ULL << 55;
1901case Attribute::SanitizeHWAddress:
return 1ULL << 56;
1902case Attribute::NoCfCheck:
return 1ULL << 57;
1903case Attribute::OptForFuzzing:
return 1ULL << 58;
1904case Attribute::ShadowCallStack:
return 1ULL << 59;
1905case Attribute::SpeculativeLoadHardening:
1907case Attribute::ImmArg:
1909case Attribute::WillReturn:
1911case Attribute::NoFree:
1914// Other attributes are not supported in the raw format, 1915// as we ran out of space. 1927if (
I == Attribute::Alignment)
1928B.addAlignmentAttr(1ULL << ((
A >> 16) - 1));
1929elseif (
I == Attribute::StackAlignment)
1930B.addStackAlignmentAttr(1ULL << ((
A >> 26)-1));
1932B.addTypeAttr(
I,
nullptr);
// Type will be auto-upgraded. 1939/// This fills an AttrBuilder object with the LLVM attributes that have 1940/// been decoded from the given integer. This function must stay in sync with 1941/// 'encodeLLVMAttributesForBitcode'. 1945// The alignment is stored as a 16-bit raw value from bits 31--16. We shift 1946// the bits above 31 down by 11 bits. 1947unsigned Alignment = (EncodedAttrs & (0xffffULL << 16)) >> 16;
1949"Alignment must be a power of two.");
1952B.addAlignmentAttr(Alignment);
1954uint64_t Attrs = ((EncodedAttrs & (0xfffffULL << 32)) >> 11) |
1955 (EncodedAttrs & 0xffff);
1958// Upgrade old memory attributes. 1960if (Attrs & (1ULL << 9)) {
1962 Attrs &= ~(1ULL << 9);
1965if (Attrs & (1ULL << 10)) {
1967 Attrs &= ~(1ULL << 10);
1970if (Attrs & (1ULL << 49)) {
1971// InaccessibleMemOnly 1972 Attrs &= ~(1ULL << 49);
1975if (Attrs & (1ULL << 50)) {
1976// InaccessibleMemOrArgMemOnly 1977 Attrs &= ~(1ULL << 50);
1980if (Attrs & (1ULL << 53)) {
1982 Attrs &= ~(1ULL << 53);
1992Error BitcodeReader::parseAttributeBlock() {
1996if (!MAttributes.empty())
1997returnerror(
"Invalid multiple blocks");
2003// Read all the records. 2010switch (
Entry.Kind) {
2013returnerror(
"Malformed block");
2017// The interesting case. 2026switch (MaybeRecord.
get()) {
2027default:
// Default behavior: ignore. 2030// Deprecated, but still needed to read old bitcode files. 2032returnerror(
"Invalid parameter attribute record");
2034for (
unsigned i = 0, e =
Record.size(); i != e; i += 2) {
2045Attrs.push_back(MAttributeGroups[Val]);
2054// Returns Attribute::None on unrecognized codes. 2060return Attribute::Alignment;
2062return Attribute::AlwaysInline;
2064return Attribute::Builtin;
2066return Attribute::ByVal;
2068return Attribute::InAlloca;
2070return Attribute::Cold;
2072return Attribute::Convergent;
2074return Attribute::DisableSanitizerInstrumentation;
2076return Attribute::ElementType;
2078return Attribute::FnRetThunkExtern;
2080return Attribute::InlineHint;
2082return Attribute::InReg;
2084return Attribute::JumpTable;
2086return Attribute::Memory;
2088return Attribute::NoFPClass;
2090return Attribute::MinSize;
2092return Attribute::Naked;
2094return Attribute::Nest;
2096return Attribute::NoAlias;
2098return Attribute::NoBuiltin;
2100return Attribute::NoCallback;
2102return Attribute::NoCapture;
2104return Attribute::NoDivergenceSource;
2106return Attribute::NoDuplicate;
2108return Attribute::NoFree;
2110return Attribute::NoImplicitFloat;
2112return Attribute::NoInline;
2114return Attribute::NoRecurse;
2116return Attribute::NoMerge;
2118return Attribute::NonLazyBind;
2120return Attribute::NonNull;
2122return Attribute::Dereferenceable;
2124return Attribute::DereferenceableOrNull;
2126return Attribute::AllocAlign;
2128return Attribute::AllocKind;
2130return Attribute::AllocSize;
2132return Attribute::AllocatedPointer;
2134return Attribute::NoRedZone;
2136return Attribute::NoReturn;
2138return Attribute::NoSync;
2140return Attribute::NoCfCheck;
2142return Attribute::NoProfile;
2144return Attribute::SkipProfile;
2146return Attribute::NoUnwind;
2148return Attribute::NoSanitizeBounds;
2150return Attribute::NoSanitizeCoverage;
2152return Attribute::NullPointerIsValid;
2154return Attribute::OptimizeForDebugging;
2156return Attribute::OptForFuzzing;
2158return Attribute::OptimizeForSize;
2160return Attribute::OptimizeNone;
2162return Attribute::ReadNone;
2164return Attribute::ReadOnly;
2166return Attribute::Returned;
2168return Attribute::ReturnsTwice;
2170return Attribute::SExt;
2172return Attribute::Speculatable;
2174return Attribute::StackAlignment;
2176return Attribute::StackProtect;
2178return Attribute::StackProtectReq;
2180return Attribute::StackProtectStrong;
2182return Attribute::SafeStack;
2184return Attribute::ShadowCallStack;
2186return Attribute::StrictFP;
2188return Attribute::StructRet;
2190return Attribute::SanitizeAddress;
2192return Attribute::SanitizeHWAddress;
2194return Attribute::SanitizeThread;
2196return Attribute::SanitizeType;
2198return Attribute::SanitizeMemory;
2200return Attribute::SanitizeNumericalStability;
2202return Attribute::SanitizeRealtime;
2204return Attribute::SanitizeRealtimeBlocking;
2206return Attribute::SpeculativeLoadHardening;
2208return Attribute::SwiftError;
2210return Attribute::SwiftSelf;
2212return Attribute::SwiftAsync;
2214return Attribute::UWTable;
2216return Attribute::VScaleRange;
2218return Attribute::WillReturn;
2220return Attribute::WriteOnly;
2222return Attribute::ZExt;
2224return Attribute::ImmArg;
2226return Attribute::SanitizeMemTag;
2228return Attribute::Preallocated;
2230return Attribute::NoUndef;
2232return Attribute::ByRef;
2234return Attribute::MustProgress;
2236return Attribute::Hot;
2238return Attribute::PresplitCoroutine;
2240return Attribute::Writable;
2242return Attribute::CoroDestroyOnlyWhenComplete;
2244return Attribute::DeadOnUnwind;
2246return Attribute::Range;
2248return Attribute::Initializes;
2250return Attribute::CoroElideSafe;
2252return Attribute::NoExt;
2254return Attribute::Captures;
2260// Note: Alignment in bitcode files is incremented by 1, so that zero 2261// can be used for default alignment. 2263returnerror(
"Invalid alignment value");
2271returnerror(
"Unknown attribute kind (" +
Twine(Code) +
")");
2276switch (EncodedKind) {
2300Error BitcodeReader::parseAttributeGroupBlock() {
2304if (!MAttributeGroups.empty())
2305returnerror(
"Invalid multiple blocks");
2309// Read all the records. 2316switch (
Entry.Kind) {
2319returnerror(
"Malformed block");
2323// The interesting case. 2332switch (MaybeRecord.
get()) {
2333default:
// Default behavior: ignore. 2337returnerror(
"Invalid grp record");
2344for (
unsigned i = 2, e =
Record.size(); i != e; ++i) {
2345if (
Record[i] == 0) {
// Enum attribute 2352if (
Error Err = parseAttrKind(EncodedKind, &Kind))
2355// Upgrade old-style byval attribute to one with a type, even if it's 2356// nullptr. We will have to insert the real type when we associate 2357// this AttributeList with a function. 2358if (Kind == Attribute::ByVal)
2359B.addByValAttr(
nullptr);
2360elseif (Kind == Attribute::StructRet)
2361B.addStructRetAttr(
nullptr);
2362elseif (Kind == Attribute::InAlloca)
2363B.addInAllocaAttr(
nullptr);
2364elseif (Kind == Attribute::UWTable)
2365B.addUWTableAttr(UWTableKind::Default);
2367B.addAttribute(Kind);
2369returnerror(
"Not an enum attribute");
2370 }
elseif (
Record[i] == 1) {
// Integer attribute 2375returnerror(
"Not an int attribute");
2376if (Kind == Attribute::Alignment)
2377B.addAlignmentAttr(
Record[++i]);
2378elseif (Kind == Attribute::StackAlignment)
2379B.addStackAlignmentAttr(
Record[++i]);
2380elseif (Kind == Attribute::Dereferenceable)
2381B.addDereferenceableAttr(
Record[++i]);
2382elseif (Kind == Attribute::DereferenceableOrNull)
2383B.addDereferenceableOrNullAttr(
Record[++i]);
2384elseif (Kind == Attribute::AllocSize)
2385B.addAllocSizeAttrFromRawRepr(
Record[++i]);
2386elseif (Kind == Attribute::VScaleRange)
2387B.addVScaleRangeAttrFromRawRepr(
Record[++i]);
2388elseif (Kind == Attribute::UWTable)
2390elseif (Kind == Attribute::AllocKind)
2392elseif (Kind == Attribute::Memory)
2394elseif (Kind == Attribute::Captures)
2396elseif (Kind == Attribute::NoFPClass)
2399 }
elseif (
Record[i] == 3 ||
Record[i] == 4) {
// String attribute 2404while (
Record[i] != 0 && i != e)
2406assert(
Record[i] == 0 &&
"Kind string not null terminated");
2409// Has a value associated with it. 2410 ++i;
// Skip the '0' that terminates the "kind" string. 2411while (
Record[i] != 0 && i != e)
2413assert(
Record[i] == 0 &&
"Value string not null terminated");
2416B.addAttribute(KindStr.
str(), ValStr.
str());
2418bool HasType =
Record[i] == 6;
2423returnerror(
"Not a type attribute");
2425B.addTypeAttr(Kind, HasType ? getTypeByID(
Record[++i]) :
nullptr);
2426 }
elseif (
Record[i] == 7) {
2433returnerror(
"Not a ConstantRange attribute");
2436 readBitWidthAndConstantRange(
Record, i);
2441B.addConstantRangeAttr(Kind, MaybeCR.
get());
2442 }
elseif (
Record[i] == 8) {
2449returnerror(
"Not a constant range list attribute");
2453returnerror(
"Too few records for constant range list");
2454unsigned RangeSize =
Record[i++];
2456for (
unsignedIdx = 0;
Idx < RangeSize; ++
Idx) {
2466returnerror(
"Invalid (unordered or overlapping) range list");
2467B.addConstantRangeListAttr(Kind, Val);
2469returnerror(
"Invalid attribute group entry");
2484Error BitcodeReader::parseTypeTable() {
2488return parseTypeTableBody();
2491Error BitcodeReader::parseTypeTableBody() {
2492if (!TypeList.empty())
2493returnerror(
"Invalid multiple blocks");
2496unsigned NumRecords = 0;
2500// Read all the records for this type table. 2507switch (
Entry.Kind) {
2510returnerror(
"Malformed block");
2512if (NumRecords != TypeList.size())
2513returnerror(
"Malformed block");
2516// The interesting case. 2522Type *ResultTy =
nullptr;
2527switch (MaybeRecord.
get()) {
2529returnerror(
"Invalid value");
2531// TYPE_CODE_NUMENTRY contains a count of the number of types in the 2532// type list. This allows us to reserve space. 2534returnerror(
"Invalid numentry record");
2535 TypeList.resize(
Record[0]);
2568// Deprecated: decodes as <1 x i64> 2580returnerror(
"Invalid integer record");
2585returnerror(
"Bitwidth for integer type out of range");
2590// [pointee type, address space] 2592returnerror(
"Invalid pointer record");
2596 ResultTy = getTypeByID(
Record[0]);
2598 !PointerType::isValidElementType(ResultTy))
2599returnerror(
"Invalid type");
2606returnerror(
"Invalid opaque pointer record");
2612// Deprecated, but still needed to read old bitcode files. 2613// FUNCTION: [vararg, attrid, retty, paramty x N] 2615returnerror(
"Invalid function record");
2617for (
unsigned i = 3, e =
Record.size(); i != e; ++i) {
2624 ResultTy = getTypeByID(
Record[2]);
2625if (!ResultTy || ArgTys.
size() <
Record.size()-3)
2626returnerror(
"Invalid type");
2629 ResultTy = FunctionType::get(ResultTy, ArgTys,
Record[0]);
2633// FUNCTION: [vararg, retty, paramty x N] 2635returnerror(
"Invalid function record");
2637for (
unsigned i = 2, e =
Record.size(); i != e; ++i) {
2639if (!FunctionType::isValidArgumentType(
T))
2640returnerror(
"Invalid function argument type");
2647 ResultTy = getTypeByID(
Record[1]);
2648if (!ResultTy || ArgTys.
size() <
Record.size()-2)
2649returnerror(
"Invalid type");
2652 ResultTy = FunctionType::get(ResultTy, ArgTys,
Record[0]);
2657returnerror(
"Invalid anon struct record");
2659for (
unsigned i = 1, e =
Record.size(); i != e; ++i) {
2666returnerror(
"Invalid type");
2673returnerror(
"Invalid struct name record");
2678returnerror(
"Invalid named struct record");
2680if (NumRecords >= TypeList.size())
2681returnerror(
"Invalid TYPE table");
2683// Check to see if this was forward referenced, if so fill in the temp. 2684StructType *Res = cast_or_null<StructType>(TypeList[NumRecords]);
2687 TypeList[NumRecords] =
nullptr;
2688 }
else// Otherwise, create a new struct. 2689 Res = createIdentifiedStructType(Context, TypeName);
2693for (
unsigned i = 1, e =
Record.size(); i != e; ++i) {
2700returnerror(
"Invalid named struct record");
2709returnerror(
"Invalid opaque type record");
2711if (NumRecords >= TypeList.size())
2712returnerror(
"Invalid TYPE table");
2714// Check to see if this was forward referenced, if so fill in the temp. 2715StructType *Res = cast_or_null<StructType>(TypeList[NumRecords]);
2718 TypeList[NumRecords] =
nullptr;
2719 }
else// Otherwise, create a new struct with no body. 2720 Res = createIdentifiedStructType(Context, TypeName);
2727returnerror(
"Invalid target extension type record");
2729if (NumRecords >= TypeList.size())
2730returnerror(
"Invalid TYPE table");
2733returnerror(
"Too many type parameters");
2735unsigned NumTys =
Record[0];
2738for (
unsigned i = 0; i < NumTys; i++) {
2742returnerror(
"Invalid type");
2745for (
unsigned i = NumTys + 1, e =
Record.size(); i < e; i++) {
2747returnerror(
"Integer parameter too large");
2752if (
auto E = TTy.takeError())
2760returnerror(
"Invalid array type record");
2761 ResultTy = getTypeByID(
Record[1]);
2762if (!ResultTy || !ArrayType::isValidElementType(ResultTy))
2763returnerror(
"Invalid type");
2765 ResultTy = ArrayType::get(ResultTy,
Record[0]);
2768// [numelts, eltty, scalable] 2770returnerror(
"Invalid vector type record");
2772returnerror(
"Invalid vector length");
2773 ResultTy = getTypeByID(
Record[1]);
2774if (!ResultTy || !VectorType::isValidElementType(ResultTy))
2775returnerror(
"Invalid type");
2778 ResultTy = VectorType::get(ResultTy,
Record[0], Scalable);
2782if (NumRecords >= TypeList.size())
2783returnerror(
"Invalid TYPE table");
2784if (TypeList[NumRecords])
2786"Invalid TYPE table: Only named structs can be forward referenced");
2787assert(ResultTy &&
"Didn't read a type?");
2788 TypeList[NumRecords] = ResultTy;
2789if (!ContainedIDs.
empty())
2790 ContainedTypeIDs[NumRecords] = std::move(ContainedIDs);
2795Error BitcodeReader::parseOperandBundleTags() {
2799if (!BundleTags.empty())
2800returnerror(
"Invalid multiple blocks");
2810switch (
Entry.Kind) {
2813returnerror(
"Malformed block");
2817// The interesting case. 2821// Tags are implicitly mapped to integers by their order. 2827returnerror(
"Invalid operand bundle record");
2829// OPERAND_BUNDLE_TAG: [strchr x N] 2830 BundleTags.emplace_back();
2832returnerror(
"Invalid operand bundle record");
2837Error BitcodeReader::parseSyncScopeNames() {
2842returnerror(
"Invalid multiple synchronization scope names blocks");
2851switch (
Entry.Kind) {
2854returnerror(
"Malformed block");
2857returnerror(
"Invalid empty synchronization scope names block");
2860// The interesting case. 2864// Synchronization scope names are implicitly mapped to synchronization 2865// scope IDs by their order. 2871returnerror(
"Invalid sync scope record");
2875returnerror(
"Invalid sync scope record");
2882/// Associate a value with its name from the given index in the provided record. 2884unsigned NameIndex,
Triple &TT) {
2887returnerror(
"Invalid record");
2888unsigned ValueID =
Record[0];
2889if (ValueID >= ValueList.
size() || !ValueList[ValueID])
2890returnerror(
"Invalid record");
2891Value *
V = ValueList[ValueID];
2894if (NameStr.contains(0))
2895returnerror(
"Invalid value name");
2897auto *GO = dyn_cast<GlobalObject>(V);
2898if (GO && ImplicitComdatObjects.
contains(GO) &&
TT.supportsCOMDAT())
2903/// Helper to note and return the current location, and jump to the given 2907// Save the current parsing location so we can jump back at the end 2911return std::move(JumpFailed);
2917returnerror(
"Expected value symbol table subblock");
2921void BitcodeReader::setDeferredFunctionInfo(
unsigned FuncBitcodeOffsetDelta,
2924// Note that we subtract 1 here because the offset is relative to one word 2925// before the start of the identification or module block, which was 2926// historically always the start of the regular bitcode header. 2928uint64_t FuncBitOffset = FuncWordOffset * 32;
2929 DeferredFunctionInfo[
F] = FuncBitOffset + FuncBitcodeOffsetDelta;
2930// Set the LastFunctionBlockBit to point to the last function block. 2931// Later when parsing is resumed after function materialization, 2932// we can simply skip that last function block. 2933if (FuncBitOffset > LastFunctionBlockBit)
2934 LastFunctionBlockBit = FuncBitOffset;
2937/// Read a new-style GlobalValue symbol table. 2938Error BitcodeReader::parseGlobalValueSymbolTable() {
2939unsigned FuncBitcodeOffsetDelta =
2952switch (
Entry.Kind) {
2955returnerror(
"Malformed block");
2966switch (MaybeRecord.
get()) {
2968unsigned ValueID =
Record[0];
2969if (ValueID >= ValueList.
size() || !ValueList[ValueID])
2970returnerror(
"Invalid value reference in symbol table");
2971 setDeferredFunctionInfo(FuncBitcodeOffsetDelta,
2972 cast<Function>(ValueList[ValueID]),
Record);
2979/// Parse the value symbol table at either the current parsing location or 2980/// at the given bit offset if provided. 2983// Pass in the Offset to distinguish between calling for the module-level 2984// VST (where we want to jump to the VST offset) and the function-level 2985// VST (where we don't). 2988if (!MaybeCurrentBit)
2990 CurrentBit = MaybeCurrentBit.
get();
2991// If this module uses a string table, read this as a module-level VST. 2993if (
Error Err = parseGlobalValueSymbolTable())
2995if (
Error JumpFailed = Stream.JumpToBit(CurrentBit))
2999// Otherwise, the VST will be in a similar format to a function-level VST, 3000// and will contain symbol names. 3003// Compute the delta between the bitcode indices in the VST (the word offset 3004// to the word-aligned ENTER_SUBBLOCK for the function block, and that 3005// expected by the lazy reader. The reader's EnterSubBlock expects to have 3006// already read the ENTER_SUBBLOCK code (size getAbbrevIDWidth) and BlockID 3007// (size BlockIDWidth). Note that we access the stream's AbbrevID width here 3008// just before entering the VST subblock because: 1) the EnterSubBlock 3009// changes the AbbrevID width; 2) the VST block is nested within the same 3010// outer MODULE_BLOCK as the FUNCTION_BLOCKs and therefore have the same 3011// AbbrevID width before calling EnterSubBlock; and 3) when we want to 3012// jump to the FUNCTION_BLOCK using this offset later, we don't want 3013// to rely on the stream's AbbrevID width being that of the MODULE_BLOCK. 3014unsigned FuncBitcodeOffsetDelta =
3024// Read all the records for this value table. 3033switch (
Entry.Kind) {
3036returnerror(
"Malformed block");
3039if (
Error JumpFailed = Stream.JumpToBit(CurrentBit))
3043// The interesting case. 3052switch (MaybeRecord.
get()) {
3053default:
// Default behavior: unknown type. 3063// VST_CODE_FNENTRY: [valueid, offset, namechar x N] 3069// Ignore function offsets emitted for aliases of functions in older 3071if (
auto *
F = dyn_cast<Function>(V))
3072 setDeferredFunctionInfo(FuncBitcodeOffsetDelta,
F,
Record);
3077returnerror(
"Invalid bbentry record");
3080returnerror(
"Invalid bbentry record");
3090/// Decode a signed value stored with the sign bit in the LSB for dense VBR 3097// There is no such thing as -0 with integers. "-0" really means MININT. 3101/// Resolve all of the initializers for global values and aliases that we can. 3102Error BitcodeReader::resolveGlobalAndIndirectSymbolInits() {
3103 std::vector<std::pair<GlobalVariable *, unsigned>> GlobalInitWorklist;
3104 std::vector<std::pair<GlobalValue *, unsigned>> IndirectSymbolInitWorklist;
3105 std::vector<FunctionOperandInfo> FunctionOperandWorklist;
3107 GlobalInitWorklist.swap(GlobalInits);
3108 IndirectSymbolInitWorklist.swap(IndirectSymbolInits);
3109 FunctionOperandWorklist.swap(FunctionOperands);
3111while (!GlobalInitWorklist.empty()) {
3112unsignedValID = GlobalInitWorklist.back().second;
3114// Not ready to resolve this yet, it requires something later in the file. 3115 GlobalInits.push_back(GlobalInitWorklist.back());
3120 GlobalInitWorklist.back().first->setInitializer(MaybeC.
get());
3122 GlobalInitWorklist.pop_back();
3125while (!IndirectSymbolInitWorklist.empty()) {
3126unsignedValID = IndirectSymbolInitWorklist.back().second;
3128 IndirectSymbolInits.push_back(IndirectSymbolInitWorklist.back());
3134GlobalValue *GV = IndirectSymbolInitWorklist.back().first;
3135if (
auto *GA = dyn_cast<GlobalAlias>(GV)) {
3137returnerror(
"Alias and aliasee types don't match");
3139 }
elseif (
auto *GI = dyn_cast<GlobalIFunc>(GV)) {
3142returnerror(
"Expected an alias or an ifunc");
3145 IndirectSymbolInitWorklist.pop_back();
3148while (!FunctionOperandWorklist.empty()) {
3149 FunctionOperandInfo &
Info = FunctionOperandWorklist.back();
3150if (
Info.PersonalityFn) {
3156Info.F->setPersonalityFn(MaybeC.
get());
3157Info.PersonalityFn = 0;
3166Info.F->setPrefixData(MaybeC.
get());
3176Info.F->setPrologueData(MaybeC.
get());
3181 FunctionOperands.push_back(Info);
3182 FunctionOperandWorklist.pop_back();
3191 BitcodeReader::decodeSignRotatedValue);
3193returnAPInt(TypeBits, Words);
3196Error BitcodeReader::parseConstants() {
3202// Read all the records for this value table. 3204unsigned Int32TyID = getVirtualTypeID(CurTy);
3205unsigned CurTyID = Int32TyID;
3206Type *CurElemTy =
nullptr;
3207unsigned NextCstNo = ValueList.
size();
3215switch (Entry.Kind) {
3218returnerror(
"Malformed block");
3220if (NextCstNo != ValueList.
size())
3221returnerror(
"Invalid constant reference");
3224// The interesting case. 3235switch (
unsigned BitCode = MaybeBitCode.
get()) {
3236default:
// Default behavior: unknown constant 3245returnerror(
"Invalid settype record");
3246if (
Record[0] >= TypeList.size() || !TypeList[
Record[0]])
3247returnerror(
"Invalid settype record");
3248if (TypeList[
Record[0]] == VoidType)
3249returnerror(
"Invalid constant type");
3251 CurTy = TypeList[CurTyID];
3252 CurElemTy = getPtrElementTypeByID(CurTyID);
3253continue;
// Skip the ValueList manipulation. 3256returnerror(
"Invalid type for a constant null value");
3257if (
auto *TETy = dyn_cast<TargetExtType>(CurTy))
3259returnerror(
"Invalid type for a constant null value");
3264returnerror(
"Invalid integer const record");
3269returnerror(
"Invalid wide integer const record");
3273V = ConstantInt::get(CurTy, VInt);
3278returnerror(
"Invalid float const record");
3281if (ScalarTy->isHalfTy())
3282V = ConstantFP::get(CurTy,
APFloat(APFloat::IEEEhalf(),
3284elseif (ScalarTy->isBFloatTy())
3287elseif (ScalarTy->isFloatTy())
3288V = ConstantFP::get(CurTy,
APFloat(APFloat::IEEEsingle(),
3290elseif (ScalarTy->isDoubleTy())
3293elseif (ScalarTy->isX86_FP80Ty()) {
3294// Bits are not stored the same way as a normal i80 APInt, compensate. 3296 Rearrange[0] = (
Record[1] & 0xffffLL) | (
Record[0] << 16);
3297 Rearrange[1] =
Record[0] >> 48;
3299 CurTy,
APFloat(APFloat::x87DoubleExtended(),
APInt(80, Rearrange)));
3300 }
elseif (ScalarTy->isFP128Ty())
3301V = ConstantFP::get(CurTy,
3303elseif (ScalarTy->isPPC_FP128Ty())
3313returnerror(
"Invalid aggregate record");
3317for (
unsigned i = 0; i !=
Size; ++i)
3320if (isa<StructType>(CurTy)) {
3321V = BitcodeConstant::create(
3322 Alloc, CurTy, BitcodeConstant::ConstantStructOpcode, Elts);
3323 }
elseif (isa<ArrayType>(CurTy)) {
3324V = BitcodeConstant::create(Alloc, CurTy,
3325 BitcodeConstant::ConstantArrayOpcode, Elts);
3326 }
elseif (isa<VectorType>(CurTy)) {
3327V = BitcodeConstant::create(
3328 Alloc, CurTy, BitcodeConstant::ConstantVectorOpcode, Elts);
3337returnerror(
"Invalid string record");
3346returnerror(
"Invalid data record");
3349if (
auto *Array = dyn_cast<ArrayType>(CurTy))
3350 EltTy =
Array->getElementType();
3352 EltTy = cast<VectorType>(CurTy)->getElementType();
3355if (isa<VectorType>(CurTy))
3361if (isa<VectorType>(CurTy))
3367if (isa<VectorType>(CurTy))
3373if (isa<VectorType>(CurTy))
3379if (isa<VectorType>(CurTy))
3385if (isa<VectorType>(CurTy))
3391if (isa<VectorType>(CurTy))
3397if (isa<VectorType>(CurTy))
3402returnerror(
"Invalid type for value");
3408returnerror(
"Invalid unary op constexpr record");
3413V = BitcodeConstant::create(Alloc, CurTy, Opc, (
unsigned)
Record[1]);
3419returnerror(
"Invalid binary op constexpr record");
3426if (Opc == Instruction::Add ||
3427 Opc == Instruction::Sub ||
3428 Opc == Instruction::Mul ||
3429 Opc == Instruction::Shl) {
3434 }
elseif (Opc == Instruction::SDiv ||
3435 Opc == Instruction::UDiv ||
3436 Opc == Instruction::LShr ||
3437 Opc == Instruction::AShr) {
3442V = BitcodeConstant::create(Alloc, CurTy, {(
uint8_t)Opc, Flags},
3449returnerror(
"Invalid cast constexpr record");
3454unsigned OpTyID =
Record[1];
3455Type *OpTy = getTypeByID(OpTyID);
3457returnerror(
"Invalid cast constexpr record");
3458V = BitcodeConstant::create(Alloc, CurTy, Opc, (
unsigned)
Record[2]);
3470returnerror(
"Constant GEP record must have at least two elements");
3472Type *PointeeType =
nullptr;
3476 PointeeType = getTypeByID(
Record[OpNum++]);
3479 std::optional<ConstantRange>
InRange;
3483unsigned InRangeIndex =
Op >> 1;
3484// "Upgrade" inrange by dropping it. The feature is too niche to 3490 readBitWidthAndConstantRange(
Record, OpNum);
3500unsigned BaseTypeID =
Record[OpNum];
3501while (OpNum !=
Record.size()) {
3502unsigned ElTyID =
Record[OpNum++];
3503Type *ElTy = getTypeByID(ElTyID);
3505returnerror(
"Invalid getelementptr constexpr record");
3510returnerror(
"Invalid gep with no operands");
3514 BaseTypeID = getContainedTypeID(BaseTypeID, 0);
3520returnerror(
"GEP base operand must be pointer or vector of pointer");
3523 PointeeType = getPtrElementTypeByID(BaseTypeID);
3525returnerror(
"Missing element type for old-style constant GEP");
3528V = BitcodeConstant::create(
3530 {Instruction::GetElementPtr,
uint8_t(Flags), PointeeType,
InRange},
3536returnerror(
"Invalid select constexpr record");
3538V = BitcodeConstant::create(
3539 Alloc, CurTy, Instruction::Select,
3544 : {
// CE_EXTRACTELT: [opty, opval, opty, opval] 3546returnerror(
"Invalid extractelement constexpr record");
3547unsigned OpTyID =
Record[0];
3549 dyn_cast_or_null<VectorType>(getTypeByID(OpTyID));
3551returnerror(
"Invalid extractelement constexpr record");
3554unsigned IdxTyID =
Record[2];
3555Type *IdxTy = getTypeByID(IdxTyID);
3557returnerror(
"Invalid extractelement constexpr record");
3560// Deprecated, but still needed to read old bitcode files. 3563V = BitcodeConstant::create(Alloc, CurTy, Instruction::ExtractElement,
3568 : {
// CE_INSERTELT: [opval, opval, opty, opval] 3569VectorType *OpTy = dyn_cast<VectorType>(CurTy);
3570if (
Record.size() < 3 || !OpTy)
3571returnerror(
"Invalid insertelement constexpr record");
3574unsigned IdxTyID =
Record[2];
3575Type *IdxTy = getTypeByID(IdxTyID);
3577returnerror(
"Invalid insertelement constexpr record");
3580// Deprecated, but still needed to read old bitcode files. 3583V = BitcodeConstant::create(
3584 Alloc, CurTy, Instruction::InsertElement,
3589VectorType *OpTy = dyn_cast<VectorType>(CurTy);
3590if (
Record.size() < 3 || !OpTy)
3591returnerror(
"Invalid shufflevector constexpr record");
3592V = BitcodeConstant::create(
3593 Alloc, CurTy, Instruction::ShuffleVector,
3598VectorType *RTy = dyn_cast<VectorType>(CurTy);
3600 dyn_cast_or_null<VectorType>(getTypeByID(
Record[0]));
3601if (
Record.size() < 4 || !RTy || !OpTy)
3602returnerror(
"Invalid shufflevector constexpr record");
3603V = BitcodeConstant::create(
3604 Alloc, CurTy, Instruction::ShuffleVector,
3610returnerror(
"Invalid cmp constexpt record");
3611unsigned OpTyID =
Record[0];
3612Type *OpTy = getTypeByID(OpTyID);
3614returnerror(
"Invalid cmp constexpr record");
3615V = BitcodeConstant::create(
3618 : Instruction::ICmp),
3623// This maintains backward compatibility, pre-asm dialect keywords. 3624// Deprecated, but still needed to read old bitcode files. 3627returnerror(
"Invalid inlineasm record");
3628 std::string AsmStr, ConstrStr;
3629bool HasSideEffects =
Record[0] & 1;
3630bool IsAlignStack =
Record[0] >> 1;
3631unsigned AsmStrSize =
Record[1];
3632if (2+AsmStrSize >=
Record.size())
3633returnerror(
"Invalid inlineasm record");
3634unsigned ConstStrSize =
Record[2+AsmStrSize];
3635if (3+AsmStrSize+ConstStrSize >
Record.size())
3636returnerror(
"Invalid inlineasm record");
3638for (
unsigned i = 0; i != AsmStrSize; ++i)
3639 AsmStr += (
char)
Record[2+i];
3640for (
unsigned i = 0; i != ConstStrSize; ++i)
3641 ConstrStr += (
char)
Record[3+AsmStrSize+i];
3644returnerror(
"Missing element type for old-style inlineasm");
3646 HasSideEffects, IsAlignStack);
3649// This version adds support for the asm dialect keywords (e.g., 3653returnerror(
"Invalid inlineasm record");
3654 std::string AsmStr, ConstrStr;
3655bool HasSideEffects =
Record[0] & 1;
3656bool IsAlignStack = (
Record[0] >> 1) & 1;
3657unsigned AsmDialect =
Record[0] >> 2;
3658unsigned AsmStrSize =
Record[1];
3659if (2+AsmStrSize >=
Record.size())
3660returnerror(
"Invalid inlineasm record");
3661unsigned ConstStrSize =
Record[2+AsmStrSize];
3662if (3+AsmStrSize+ConstStrSize >
Record.size())
3663returnerror(
"Invalid inlineasm record");
3665for (
unsigned i = 0; i != AsmStrSize; ++i)
3666 AsmStr += (
char)
Record[2+i];
3667for (
unsigned i = 0; i != ConstStrSize; ++i)
3668 ConstrStr += (
char)
Record[3+AsmStrSize+i];
3671returnerror(
"Missing element type for old-style inlineasm");
3673 HasSideEffects, IsAlignStack,
3677// This version adds support for the unwind keyword. 3680returnerror(
"Invalid inlineasm record");
3682 std::string AsmStr, ConstrStr;
3683bool HasSideEffects =
Record[OpNum] & 1;
3684bool IsAlignStack = (
Record[OpNum] >> 1) & 1;
3685unsigned AsmDialect = (
Record[OpNum] >> 2) & 1;
3686bool CanThrow = (
Record[OpNum] >> 3) & 1;
3688unsigned AsmStrSize =
Record[OpNum];
3690if (OpNum + AsmStrSize >=
Record.size())
3691returnerror(
"Invalid inlineasm record");
3692unsigned ConstStrSize =
Record[OpNum + AsmStrSize];
3693if (OpNum + 1 + AsmStrSize + ConstStrSize >
Record.size())
3694returnerror(
"Invalid inlineasm record");
3696for (
unsigned i = 0; i != AsmStrSize; ++i)
3697 AsmStr += (
char)
Record[OpNum + i];
3699for (
unsigned i = 0; i != ConstStrSize; ++i)
3700 ConstrStr += (
char)
Record[OpNum + AsmStrSize + i];
3703returnerror(
"Missing element type for old-style inlineasm");
3705 HasSideEffects, IsAlignStack,
3709// This version adds explicit function type. 3712returnerror(
"Invalid inlineasm record");
3714auto *FnTy = dyn_cast_or_null<FunctionType>(getTypeByID(
Record[OpNum]));
3717returnerror(
"Invalid inlineasm record");
3718 std::string AsmStr, ConstrStr;
3719bool HasSideEffects =
Record[OpNum] & 1;
3720bool IsAlignStack = (
Record[OpNum] >> 1) & 1;
3721unsigned AsmDialect = (
Record[OpNum] >> 2) & 1;
3722bool CanThrow = (
Record[OpNum] >> 3) & 1;
3724unsigned AsmStrSize =
Record[OpNum];
3726if (OpNum + AsmStrSize >=
Record.size())
3727returnerror(
"Invalid inlineasm record");
3728unsigned ConstStrSize =
Record[OpNum + AsmStrSize];
3729if (OpNum + 1 + AsmStrSize + ConstStrSize >
Record.size())
3730returnerror(
"Invalid inlineasm record");
3732for (
unsigned i = 0; i != AsmStrSize; ++i)
3733 AsmStr += (
char)
Record[OpNum + i];
3735for (
unsigned i = 0; i != ConstStrSize; ++i)
3736 ConstrStr += (
char)
Record[OpNum + AsmStrSize + i];
3738V =
InlineAsm::get(FnTy, AsmStr, ConstrStr, HasSideEffects, IsAlignStack,
3744returnerror(
"Invalid blockaddress record");
3745unsigned FnTyID =
Record[0];
3746Type *FnTy = getTypeByID(FnTyID);
3748returnerror(
"Invalid blockaddress record");
3749V = BitcodeConstant::create(
3757returnerror(
"Invalid dso_local record");
3758unsigned GVTyID =
Record[0];
3759Type *GVTy = getTypeByID(GVTyID);
3761returnerror(
"Invalid dso_local record");
3762V = BitcodeConstant::create(
3763 Alloc, CurTy, BitcodeConstant::DSOLocalEquivalentOpcode,
Record[1]);
3768returnerror(
"Invalid no_cfi record");
3769unsigned GVTyID =
Record[0];
3770Type *GVTy = getTypeByID(GVTyID);
3772returnerror(
"Invalid no_cfi record");
3773V = BitcodeConstant::create(Alloc, CurTy, BitcodeConstant::NoCFIOpcode,
3779returnerror(
"Invalid ptrauth record");
3780// Ptr, Key, Disc, AddrDisc 3781V = BitcodeConstant::create(Alloc, CurTy,
3782 BitcodeConstant::ConstantPtrAuthOpcode,
3789assert(
V->getType() == getTypeByID(CurTyID) &&
"Incorrect result type ID");
3796Error BitcodeReader::parseUseLists() {
3800// Read all the records. 3809switch (
Entry.Kind) {
3812returnerror(
"Malformed block");
3816// The interesting case. 3820// Read a use list record. 3826switch (MaybeRecord.
get()) {
3827default:
// Default behavior: unknown type. 3834if (RecordLength < 3)
3835// Records should have at least an ID and two indexes. 3836returnerror(
"Invalid record");
3841assert(
ID < FunctionBBs.size() &&
"Basic block not found");
3845unsigned NumUses = 0;
3847for (
constUse &U :
V->materialized_uses()) {
3848if (++NumUses >
Record.size())
3850 Order[&
U] =
Record[NumUses - 1];
3853// Mismatches can happen if the functions are being materialized lazily 3854// (out-of-order), or a value has been upgraded. 3857V->sortUseList([&](
constUse &L,
constUse &R) {
3866/// When we see the block for metadata, remember where it is and then skip it. 3867/// This lets us lazily deserialize the metadata. 3868Error BitcodeReader::rememberAndSkipMetadata() {
3869// Save the current stream state. 3870uint64_t CurBit = Stream.GetCurrentBitNo();
3871 DeferredMetadataInfo.push_back(CurBit);
3873// Skip over the block for now. 3874if (
Error Err = Stream.SkipBlock())
3879Error BitcodeReader::materializeMetadata() {
3880for (
uint64_t BitPos : DeferredMetadataInfo) {
3881// Move the bit stream to the saved position. 3882if (
Error JumpFailed = Stream.JumpToBit(BitPos))
3884if (
Error Err = MDLoader->parseModuleMetadata())
3888// Upgrade "Linker Options" module flag to "llvm.linker.options" module-level 3889// metadata. Only upgrade if the new option doesn't exist to avoid upgrade 3895for (
constMDOperand &MDOptions : cast<MDNode>(Val)->operands())
3896 LinkerOpts->
addOperand(cast<MDNode>(MDOptions));
3900 DeferredMetadataInfo.clear();
3906/// When we see the block for a function body, remember where it is and then 3907/// skip it. This lets us lazily deserialize the functions. 3908Error BitcodeReader::rememberAndSkipFunctionBody() {
3909// Get the function we are talking about. 3910if (FunctionsWithBodies.empty())
3911returnerror(
"Insufficient function protos");
3914 FunctionsWithBodies.pop_back();
3916// Save the current stream state. 3917uint64_t CurBit = Stream.GetCurrentBitNo();
3919 (DeferredFunctionInfo[Fn] == 0 || DeferredFunctionInfo[Fn] == CurBit) &&
3920"Mismatch between VST and scanned function offsets");
3921 DeferredFunctionInfo[Fn] = CurBit;
3923// Skip over the function block for now. 3924if (
Error Err = Stream.SkipBlock())
3929Error BitcodeReader::globalCleanup() {
3930// Patch the initializers for globals and aliases up. 3931if (
Error Err = resolveGlobalAndIndirectSymbolInits())
3933if (!GlobalInits.empty() || !IndirectSymbolInits.empty())
3934returnerror(
"Malformed global initializer set");
3936// Look for intrinsic functions which need to be upgraded at some point 3937// and functions that need to have their function attributes upgraded. 3939 MDLoader->upgradeDebugIntrinsics(
F);
3941// If PreserveInputDbgFormat=true, then we don't know whether we want 3942// intrinsics or records, and we won't perform any conversions in either 3943// case, so don't upgrade intrinsics to records. 3946 UpgradedIntrinsics[&
F] = NewFn;
3947// Look for functions that rely on old function attribute behavior. 3951// Look for global variables which need to be renamed. 3952 std::vector<std::pair<GlobalVariable *, GlobalVariable *>> UpgradedVariables;
3955 UpgradedVariables.emplace_back(&GV, Upgraded);
3956for (
auto &Pair : UpgradedVariables) {
3957 Pair.first->eraseFromParent();
3958 TheModule->insertGlobalVariable(Pair.second);
3961// Force deallocation of memory for these vectors to favor the client that 3962// want lazy deserialization. 3963 std::vector<std::pair<GlobalVariable *, unsigned>>().
swap(GlobalInits);
3964 std::vector<std::pair<GlobalValue *, unsigned>>().
swap(IndirectSymbolInits);
3968/// Support for lazy parsing of function bodies. This is required if we 3969/// either have an old bitcode file without a VST forward declaration record, 3970/// or if we have an anonymous function being materialized, since anonymous 3971/// functions do not have a name and are therefore not in the VST. 3972Error BitcodeReader::rememberAndSkipFunctionBodies() {
3973if (
Error JumpFailed = Stream.JumpToBit(NextUnreadBit))
3976if (Stream.AtEndOfStream())
3977returnerror(
"Could not find function in stream");
3979if (!SeenFirstFunctionBody)
3980returnerror(
"Trying to materialize functions before seeing function blocks");
3982// An old bitcode file with the symbol table at the end would have 3983// finished the parse greedily. 3984assert(SeenValueSymbolTable);
3994switch (
Entry.Kind) {
3996returnerror(
"Expect SubBlock");
4000returnerror(
"Expect function block");
4002if (
Error Err = rememberAndSkipFunctionBody())
4004 NextUnreadBit = Stream.GetCurrentBitNo();
4011Error BitcodeReaderBase::readBlockInfo() {
4013 Stream.ReadBlockInfoBlock();
4014if (!MaybeNewBlockInfo)
4016 std::optional<BitstreamBlockInfo> NewBlockInfo =
4017 std::move(MaybeNewBlockInfo.
get());
4019returnerror(
"Malformed block");
4020 BlockInfo = std::move(*NewBlockInfo);
4025// v1: [selection_kind, name] 4026// v2: [strtab_offset, strtab_size, selection_kind] 4031returnerror(
"Invalid record");
4033 std::string OldFormatName;
4036returnerror(
"Invalid record");
4037unsigned ComdatNameSize =
Record[1];
4038if (ComdatNameSize >
Record.size() - 2)
4039returnerror(
"Comdat name size too large");
4040 OldFormatName.reserve(ComdatNameSize);
4041for (
unsigned i = 0; i != ComdatNameSize; ++i)
4042 OldFormatName += (
char)
Record[2 + i];
4043Name = OldFormatName;
4046C->setSelectionKind(SK);
4047 ComdatList.push_back(
C);
4052// infer dso_local from linkage and visibility if it is not encoded. 4061 Meta.NoAddress =
true;
4063 Meta.NoHWAddress =
true;
4067 Meta.IsDynInit =
true;
4072// v1: [pointer type, isconst, initid, linkage, alignment, section, 4073// visibility, threadlocal, unnamed_addr, externally_initialized, 4074// dllstorageclass, comdat, attributes, preemption specifier, 4075// partition strtab offset, partition strtab size] (name in VST) 4076// v2: [strtab_offset, strtab_size, v1] 4077// v3: [v2, code_model] 4082returnerror(
"Invalid record");
4084Type *Ty = getTypeByID(TyID);
4086returnerror(
"Invalid record");
4088bool explicitType =
Record[1] & 2;
4094returnerror(
"Invalid type for value");
4095AddressSpace = cast<PointerType>(Ty)->getAddressSpace();
4096 TyID = getContainedTypeID(TyID);
4097 Ty = getTypeByID(TyID);
4099returnerror(
"Missing element type for old-style global");
4105if (
Error Err = parseAlignmentValue(
Record[4], Alignment))
4109if (
Record[5] - 1 >= SectionTable.size())
4110returnerror(
"Invalid ID");
4114// Local linkage must have default visibility. 4115// auto-upgrade `hidden` and `protected` for old bitcode. 4127bool ExternallyInitialized =
false;
4129 ExternallyInitialized =
Record[9];
4142// A GlobalValue with local linkage cannot have a DLL storage class. 4152// Remember which value to use for the global initializer. 4153if (
unsigned InitID =
Record[2])
4154 GlobalInits.push_back(std::make_pair(NewGV, InitID - 1));
4157if (
unsigned ComdatID =
Record[11]) {
4158if (ComdatID > ComdatList.size())
4159returnerror(
"Invalid global variable comdat ID");
4160 NewGV->
setComdat(ComdatList[ComdatID - 1]);
4163 ImplicitComdatObjects.
insert(NewGV);
4176// Check whether we have enough values to read a partition name. 4190returnerror(
"Invalid global variable code model");
4196void BitcodeReader::callValueTypeCallback(
Value *
F,
unsignedTypeID) {
4197if (ValueTypeCallback) {
4198 (*ValueTypeCallback)(
4199F,
TypeID, [
this](
unsignedI) {
return getTypeByID(
I); },
4200 [
this](
unsignedI,
unsigned J) {
return getContainedTypeID(
I, J); });
4205// v1: [type, callingconv, isproto, linkage, paramattr, alignment, section, 4206// visibility, gc, unnamed_addr, prologuedata, dllstorageclass, comdat, 4207// prefixdata, personalityfn, preemption specifier, addrspace] (name in VST) 4208// v2: [strtab_offset, strtab_size, v1] 4213returnerror(
"Invalid record");
4214unsigned FTyID =
Record[0];
4215Type *FTy = getTypeByID(FTyID);
4217returnerror(
"Invalid record");
4218if (isa<PointerType>(FTy)) {
4219 FTyID = getContainedTypeID(FTyID, 0);
4220 FTy = getTypeByID(FTyID);
4222returnerror(
"Missing element type for old-style function");
4225if (!isa<FunctionType>(FTy))
4226returnerror(
"Invalid type for value");
4229returnerror(
"Invalid calling convention ID");
4231unsigned AddrSpace = TheModule->getDataLayout().getProgramAddressSpace();
4237 AddrSpace,
Name, TheModule);
4240"Incorrect fully specified type provided for function");
4241 FunctionTypeIDs[
Func] = FTyID;
4248 callValueTypeCallback(Func, FTyID);
4250// Upgrade any old-style byval or sret without a type by propagating the 4251// argument's pointee type. There should be no opaque pointers where the byval 4253for (
unsigned i = 0; i !=
Func->arg_size(); ++i) {
4255 Attribute::InAlloca}) {
4256if (!
Func->hasParamAttribute(i, Kind))
4259if (
Func->getParamAttribute(i, Kind).getValueAsType())
4262Func->removeParamAttr(i, Kind);
4264unsigned ParamTypeID = getContainedTypeID(FTyID, i + 1);
4265Type *PtrEltTy = getPtrElementTypeByID(ParamTypeID);
4267returnerror(
"Missing param element type for attribute upgrade");
4271case Attribute::ByVal:
4274case Attribute::StructRet:
4277case Attribute::InAlloca:
4284Func->addParamAttr(i, NewAttr);
4289 !
Func->arg_empty() && !
Func->hasParamAttribute(0, Attribute::ByVal)) {
4290unsigned ParamTypeID = getContainedTypeID(FTyID, 1);
4291Type *ByValTy = getPtrElementTypeByID(ParamTypeID);
4293returnerror(
"Missing param element type for x86_intrcc upgrade");
4295Func->addParamAttr(0, NewAttr);
4299if (
Error Err = parseAlignmentValue(
Record[5], Alignment))
4302Func->setAlignment(*Alignment);
4304if (
Record[6] - 1 >= SectionTable.size())
4305returnerror(
"Invalid ID");
4306Func->setSection(SectionTable[
Record[6] - 1]);
4308// Local linkage must have default visibility. 4309// auto-upgrade `hidden` and `protected` for old bitcode. 4310if (!
Func->hasLocalLinkage())
4313if (
Record[8] - 1 >= GCTable.size())
4314returnerror(
"Invalid ID");
4320Func->setUnnamedAddr(UnnamedAddr);
4327// A GlobalValue with local linkage cannot have a DLL storage class. 4328if (!
Func->hasLocalLinkage()) {
4336if (
unsigned ComdatID =
Record[12]) {
4337if (ComdatID > ComdatList.size())
4338returnerror(
"Invalid function comdat ID");
4339Func->setComdat(ComdatList[ComdatID - 1]);
4342 ImplicitComdatObjects.
insert(Func);
4356// Record[16] is the address space number. 4358// Check whether we have enough values to read a partition name. Also make 4359// sure Strtab has enough values. 4360if (
Record.size() > 18 && Strtab.data() &&
4365 ValueList.
push_back(Func, getVirtualTypeID(
Func->getType(), FTyID));
4370// If this is a function with a body, remember the prototype we are 4371// creating now, so that we can match up the body with them later. 4373Func->setIsMaterializable(
true);
4374 FunctionsWithBodies.push_back(Func);
4375 DeferredFunctionInfo[
Func] = 0;
4380Error BitcodeReader::parseGlobalIndirectSymbolRecord(
4382// v1 ALIAS_OLD: [alias type, aliasee val#, linkage] (name in VST) 4383// v1 ALIAS: [alias type, addrspace, aliasee val#, linkage, visibility, 4384// dllstorageclass, threadlocal, unnamed_addr, 4385// preemption specifier] (name in VST) 4386// v1 IFUNC: [alias type, addrspace, aliasee val#, linkage, 4387// visibility, dllstorageclass, threadlocal, unnamed_addr, 4388// preemption specifier] (name in VST) 4389// v2: [strtab_offset, strtab_size, v1] 4394if (
Record.size() < (3 + (
unsigned)NewRecord))
4395returnerror(
"Invalid record");
4400returnerror(
"Invalid record");
4404auto *PTy = dyn_cast<PointerType>(Ty);
4406returnerror(
"Invalid type for value");
4407 AddrSpace = PTy->getAddressSpace();
4409 Ty = getTypeByID(
TypeID);
4411returnerror(
"Missing element type for old-style indirect symbol");
4413 AddrSpace =
Record[OpNum++];
4416auto Val =
Record[OpNum++];
4427// Local linkage must have default visibility. 4428// auto-upgrade `hidden` and `protected` for old bitcode. 4429if (OpNum !=
Record.size()) {
4430auto VisInd = OpNum++;
4436if (OpNum !=
Record.size()) {
4438// A GlobalValue with local linkage cannot have a DLL storage class. 4444if (OpNum !=
Record.size())
4446if (OpNum !=
Record.size())
4449if (OpNum !=
Record.size())
4453// Check whether we have enough values to read a partition name. 4454if (OpNum + 1 <
Record.size()) {
4455// Check Strtab has enough values for the partition. 4457returnerror(
"Malformed partition, too large.");
4463 IndirectSymbolInits.push_back(std::make_pair(NewGA, Val));
4468bool ShouldLazyLoadMetadata,
4470// Load directly into RemoveDIs format if LoadBitcodeIntoNewDbgInfoFormat 4471// has been set to true and we aren't attempting to preserve the existing 4472// format in the bitcode (default action: load into the old debug format). 4474 TheModule->IsNewDbgInfoFormat =
4479 this->ValueTypeCallback = std::move(Callbacks.
ValueType);
4481if (
Error JumpFailed = Stream.JumpToBit(ResumeBit))
4488// Parts of bitcode parsing depend on the datalayout. Make sure we 4489// finalize the datalayout before we run any of that code. 4490bool ResolvedDataLayout =
false;
4491// In order to support importing modules with illegal data layout strings, 4492// delay parsing the data layout string until after upgrades and overrides 4493// have been applied, allowing to fix illegal data layout strings. 4494// Initialize to the current module's layout string in case none is specified. 4495 std::string TentativeDataLayoutStr = TheModule->getDataLayoutStr();
4497auto ResolveDataLayout = [&]() ->
Error {
4498if (ResolvedDataLayout)
4501// Datalayout and triple can't be parsed after this point. 4502 ResolvedDataLayout =
true;
4504// Auto-upgrade the layout string 4506 TentativeDataLayoutStr, TheModule->getTargetTriple());
4510if (
auto LayoutOverride = (*Callbacks.
DataLayout)(
4511 TheModule->getTargetTriple(), TentativeDataLayoutStr))
4512 TentativeDataLayoutStr = *LayoutOverride;
4515// Now the layout string is finalized in TentativeDataLayoutStr. Parse it. 4520 TheModule->setDataLayout(MaybeDL.
get());
4524// Read all the records for this module. 4531switch (
Entry.Kind) {
4533returnerror(
"Malformed block");
4535if (
Error Err = ResolveDataLayout())
4537return globalCleanup();
4541default:
// Skip unknown content. 4542if (
Error Err = Stream.SkipBlock())
4546if (
Error Err = readBlockInfo())
4550if (
Error Err = parseAttributeBlock())
4554if (
Error Err = parseAttributeGroupBlock())
4558if (
Error Err = parseTypeTable())
4562if (!SeenValueSymbolTable) {
4563// Either this is an old form VST without function index and an 4564// associated VST forward declaration record (which would have caused 4565// the VST to be jumped to and parsed before it was encountered 4566// normally in the stream), or there were no function blocks to 4567// trigger an earlier parsing of the VST. 4568assert(VSTOffset == 0 || FunctionsWithBodies.empty());
4569if (
Error Err = parseValueSymbolTable())
4571 SeenValueSymbolTable =
true;
4573// We must have had a VST forward declaration record, which caused 4574// the parser to jump to and parse the VST earlier. 4576if (
Error Err = Stream.SkipBlock())
4581if (
Error Err = parseConstants())
4583if (
Error Err = resolveGlobalAndIndirectSymbolInits())
4587if (ShouldLazyLoadMetadata) {
4588if (
Error Err = rememberAndSkipMetadata())
4592assert(DeferredMetadataInfo.empty() &&
"Unexpected deferred metadata");
4593if (
Error Err = MDLoader->parseModuleMetadata())
4597if (
Error Err = MDLoader->parseMetadataKinds())
4601if (
Error Err = ResolveDataLayout())
4604// If this is the first function body we've seen, reverse the 4605// FunctionsWithBodies list. 4606if (!SeenFirstFunctionBody) {
4607 std::reverse(FunctionsWithBodies.begin(), FunctionsWithBodies.end());
4608if (
Error Err = globalCleanup())
4610 SeenFirstFunctionBody =
true;
4614// If we have a VST forward declaration record, make sure we 4615// parse the VST now if we haven't already. It is needed to 4616// set up the DeferredFunctionInfo vector for lazy reading. 4617if (!SeenValueSymbolTable) {
4618if (
Error Err = BitcodeReader::parseValueSymbolTable(VSTOffset))
4620 SeenValueSymbolTable =
true;
4621// Fall through so that we record the NextUnreadBit below. 4622// This is necessary in case we have an anonymous function that 4623// is later materialized. Since it will not have a VST entry we 4624// need to fall back to the lazy parse to find its offset. 4626// If we have a VST forward declaration record, but have already 4627// parsed the VST (just above, when the first function body was 4628// encountered here), then we are resuming the parse after 4629// materializing functions. The ResumeBit points to the 4630// start of the last function block recorded in the 4631// DeferredFunctionInfo map. Skip it. 4632if (
Error Err = Stream.SkipBlock())
4638// Support older bitcode files that did not have the function 4639// index in the VST, nor a VST forward declaration record, as 4640// well as anonymous functions that do not have VST entries. 4641// Build the DeferredFunctionInfo vector on the fly. 4642if (
Error Err = rememberAndSkipFunctionBody())
4645// Suspend parsing when we reach the function bodies. Subsequent 4646// materialization calls will resume it when necessary. If the bitcode 4647// file is old, the symbol table will be at the end instead and will not 4648// have been seen yet. In this case, just finish the parse now. 4649if (SeenValueSymbolTable) {
4650 NextUnreadBit = Stream.GetCurrentBitNo();
4651// After the VST has been parsed, we need to make sure intrinsic name 4652// are auto-upgraded. 4653return globalCleanup();
4657if (
Error Err = parseUseLists())
4661if (
Error Err = parseOperandBundleTags())
4665if (
Error Err = parseSyncScopeNames())
4672// The interesting case. 4680switch (
unsigned BitCode = MaybeBitCode.
get()) {
4681default:
break;
// Default behavior, ignore unknown content. 4686 UseRelativeIDs = *VersionOrErr >= 1;
4690if (ResolvedDataLayout)
4691returnerror(
"target triple too late in module");
4694returnerror(
"Invalid record");
4695 TheModule->setTargetTriple(S);
4699if (ResolvedDataLayout)
4700returnerror(
"datalayout too late in module");
4702returnerror(
"Invalid record");
4708returnerror(
"Invalid record");
4709 TheModule->setModuleInlineAsm(S);
4713// Deprecated, but still needed to read old bitcode files. 4716returnerror(
"Invalid record");
4723returnerror(
"Invalid record");
4724 SectionTable.push_back(S);
4730returnerror(
"Invalid record");
4731 GCTable.push_back(S);
4738// FIXME: BitcodeReader should handle {GLOBALVAR, FUNCTION, ALIAS, IFUNC} 4739// written by ThinLinkBitcodeWriter. See 4740// `ThinLinkBitcodeWriter::writeSimplifiedModuleInfo` for the format of each 4742// (https://github.com/llvm/llvm-project/blob/b6a93967d9c11e79802b5e75cec1584d6c8aa472/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp#L4714) 4748if (
Error Err = ResolveDataLayout())
4756if (
Error Err = parseGlobalIndirectSymbolRecord(BitCode,
Record))
4759 /// MODULE_CODE_VSTOFFSET: [offset] 4762returnerror(
"Invalid record");
4763// Note that we subtract 1 here because the offset is relative to one word 4764// before the start of the identification or module block, which was 4765// historically always the start of the regular bitcode header. 4766 VSTOffset =
Record[0] - 1;
4768 /// MODULE_CODE_SOURCE_FILENAME: [namechar x N] 4772returnerror(
"Invalid record");
4773 TheModule->setSourceFileName(
ValueName);
4778 this->ValueTypeCallback = std::nullopt;
4782Error BitcodeReader::parseBitcodeInto(
Module *M,
bool ShouldLazyLoadMetadata,
4789return getContainedTypeID(
I, J);
4792 MDLoader =
MetadataLoader(Stream, *M, ValueList, IsImporting, MDCallbacks);
4793returnparseModule(0, ShouldLazyLoadMetadata, Callbacks);
4796Error BitcodeReader::typeCheckLoadStoreInst(
Type *ValType,
Type *PtrType) {
4797if (!isa<PointerType>(PtrType))
4798returnerror(
"Load/Store operand is not a pointer type");
4799if (!PointerType::isLoadableOrStorableType(ValType))
4800returnerror(
"Cannot load/store from pointer");
4807for (
unsigned i = 0; i != CB->
arg_size(); ++i) {
4809 Attribute::InAlloca}) {
4810if (!
Attrs.hasParamAttr(i, Kind) ||
4811Attrs.getParamAttr(i, Kind).getValueAsType())
4814Type *PtrEltTy = getPtrElementTypeByID(ArgTyIDs[i]);
4816returnerror(
"Missing element type for typed attribute upgrade");
4820case Attribute::ByVal:
4823case Attribute::StructRet:
4826case Attribute::InAlloca:
4833Attrs =
Attrs.addParamAttribute(Context, i, NewAttr);
4844if (CI.isIndirect && !
Attrs.getParamElementType(ArgNo)) {
4845Type *ElemTy = getPtrElementTypeByID(ArgTyIDs[ArgNo]);
4847returnerror(
"Missing element type for inline asm upgrade");
4858case Intrinsic::preserve_array_access_index:
4859case Intrinsic::preserve_struct_access_index:
4860case Intrinsic::aarch64_ldaxr:
4861case Intrinsic::aarch64_ldxr:
4862case Intrinsic::aarch64_stlxr:
4863case Intrinsic::aarch64_stxr:
4864case Intrinsic::arm_ldaex:
4865case Intrinsic::arm_ldrex:
4866case Intrinsic::arm_stlex:
4867case Intrinsic::arm_strex: {
4870case Intrinsic::aarch64_stlxr:
4871case Intrinsic::aarch64_stxr:
4872case Intrinsic::arm_stlex:
4873case Intrinsic::arm_strex:
4880if (!
Attrs.getParamElementType(ArgNo)) {
4881Type *ElTy = getPtrElementTypeByID(ArgTyIDs[ArgNo]);
4883returnerror(
"Missing element type for elementtype upgrade");
4885Attrs =
Attrs.addParamAttribute(Context, ArgNo, NewAttr);
4897/// Lazily parse the specified function body block. 4902// Unexpected unresolved metadata when parsing function. 4903if (MDLoader->hasFwdRefs())
4904returnerror(
"Invalid function metadata: incoming forward references");
4906 InstructionList.
clear();
4907unsigned ModuleValueListSize = ValueList.
size();
4908unsigned ModuleMDLoaderSize = MDLoader->size();
4910// Add all the function arguments to the value table. 4912unsigned FTyID = FunctionTypeIDs[
F];
4914unsigned ArgTyID = getContainedTypeID(FTyID, ArgNo + 1);
4915assert(
I.getType() == getTypeByID(ArgTyID) &&
4916"Incorrect fully specified type for Function Argument");
4920unsigned NextValueNo = ValueList.
size();
4922unsigned CurBBNo = 0;
4923// Block into which constant expressions from phi nodes are materialized. 4925// Edge blocks for phi nodes into which constant expressions have been 4932if (CurBB && !CurBB->
empty())
4933return &CurBB->
back();
4934elseif (CurBBNo && FunctionBBs[CurBBNo - 1] &&
4935 !FunctionBBs[CurBBNo - 1]->empty())
4936return &FunctionBBs[CurBBNo - 1]->back();
4940 std::vector<OperandBundleDef> OperandBundles;
4942// Read all the records. 4951switch (
Entry.Kind) {
4953returnerror(
"Malformed block");
4955goto OutOfRecordLoop;
4959default:
// Skip unknown content. 4960if (
Error Err = Stream.SkipBlock())
4964if (
Error Err = parseConstants())
4966 NextValueNo = ValueList.
size();
4969if (
Error Err = parseValueSymbolTable())
4973if (
Error Err = MDLoader->parseMetadataAttachment(*
F, InstructionList))
4977assert(DeferredMetadataInfo.empty() &&
4978"Must read all module-level metadata before function-level");
4979if (
Error Err = MDLoader->parseFunctionMetadata())
4983if (
Error Err = parseUseLists())
4990// The interesting case. 4997unsigned ResTypeID = InvalidTypeID;
5001switch (
unsigned BitCode = MaybeBitCode.
get()) {
5002default:
// Default behavior: reject 5003returnerror(
"Invalid value");
5006returnerror(
"Invalid record");
5007// Create all the basic blocks for the function. 5008 FunctionBBs.resize(
Record[0]);
5010// See if anything took the address of blocks in this function. 5011auto BBFRI = BasicBlockFwdRefs.
find(
F);
5012if (BBFRI == BasicBlockFwdRefs.
end()) {
5016auto &BBRefs = BBFRI->second;
5017// Check for invalid basic block references. 5018if (BBRefs.size() > FunctionBBs.size())
5019returnerror(
"Invalid ID");
5020assert(!BBRefs.empty() &&
"Unexpected empty array");
5021assert(!BBRefs.front() &&
"Invalid reference to entry block");
5022for (
unsignedI = 0, E = FunctionBBs.size(), RE = BBRefs.size();
I != E;
5024if (
I < RE && BBRefs[
I]) {
5025 BBRefs[
I]->insertInto(
F);
5026 FunctionBBs[
I] = BBRefs[
I];
5031// Erase from the table. 5032 BasicBlockFwdRefs.
erase(BBFRI);
5035 CurBB = FunctionBBs[0];
5040// The record should not be emitted if it's an empty list. 5042returnerror(
"Invalid record");
5043// When we have the RARE case of a BlockAddress Constant that is not 5044// scoped to the Function it refers to, we need to conservatively 5045// materialize the referred to Function, regardless of whether or not 5046// that Function will ultimately be linked, otherwise users of 5047// BitcodeReader might start splicing out Function bodies such that we 5048// might no longer be able to materialize the BlockAddress since the 5049// BasicBlock (and entire body of the Function) the BlockAddress refers 5050// to may have been moved. In the case that the user of BitcodeReader 5051// decides ultimately not to link the Function body, materializing here 5052// could be considered wasteful, but it's better than a deserialization 5053// failure as described. This keeps BitcodeReader unaware of complex 5054// linkage policy decisions such as those use by LTO, leaving those 5055// decisions "one layer up." 5057if (
auto *
F = dyn_cast<Function>(ValueList[
ValID]))
5058 BackwardRefFunctions.push_back(
F);
5060returnerror(
"Invalid record");
5065// This record indicates that the last instruction is at the same 5066// location as the previous instruction with a location. 5067I = getLastInstruction();
5070returnerror(
"Invalid record");
5071I->setDebugLoc(LastLoc);
5076I = getLastInstruction();
5078returnerror(
"Invalid record");
5086Scope = dyn_cast_or_null<MDNode>(
5087 MDLoader->getMetadataFwdRefOrLoad(ScopeID - 1));
5089returnerror(
"Invalid record");
5092IA = dyn_cast_or_null<MDNode>(
5093 MDLoader->getMetadataFwdRefOrLoad(IAID - 1));
5095returnerror(
"Invalid record");
5097 LastLoc = DILocation::get(
Scope->getContext(), Line, Col, Scope, IA,
5099I->setDebugLoc(LastLoc);
5107if (getValueTypePair(
Record, OpNum, NextValueNo, LHS,
TypeID, CurBB) ||
5109returnerror(
"Invalid record");
5113returnerror(
"Invalid record");
5117if (OpNum <
Record.size()) {
5118if (isa<FPMathOperator>(
I)) {
5121I->setFastMathFlags(FMF);
5130if (getValueTypePair(
Record, OpNum, NextValueNo, LHS,
TypeID, CurBB) ||
5134returnerror(
"Invalid record");
5138returnerror(
"Invalid record");
5142if (OpNum <
Record.size()) {
5143if (Opc == Instruction::Add ||
5144 Opc == Instruction::Sub ||
5145 Opc == Instruction::Mul ||
5146 Opc == Instruction::Shl) {
5148 cast<BinaryOperator>(
I)->setHasNoSignedWrap(
true);
5150 cast<BinaryOperator>(
I)->setHasNoUnsignedWrap(
true);
5151 }
elseif (Opc == Instruction::SDiv ||
5152 Opc == Instruction::UDiv ||
5153 Opc == Instruction::LShr ||
5154 Opc == Instruction::AShr) {
5156 cast<BinaryOperator>(
I)->setIsExact(
true);
5157 }
elseif (Opc == Instruction::Or) {
5159 cast<PossiblyDisjointInst>(
I)->setIsDisjoint(
true);
5160 }
elseif (isa<FPMathOperator>(
I)) {
5163I->setFastMathFlags(FMF);
5172if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB) ||
5173 OpNum + 1 >
Record.size())
5174returnerror(
"Invalid record");
5176 ResTypeID =
Record[OpNum++];
5177Type *ResTy = getTypeByID(ResTypeID);
5180if (Opc == -1 || !ResTy)
5181returnerror(
"Invalid record");
5186assert(CurBB &&
"No current BB?");
5192returnerror(
"Invalid cast");
5196if (OpNum <
Record.size()) {
5197if (Opc == Instruction::ZExt || Opc == Instruction::UIToFP) {
5199 cast<PossiblyNonNegInst>(
I)->setNonNeg(
true);
5200 }
elseif (Opc == Instruction::Trunc) {
5202 cast<TruncInst>(
I)->setHasNoUnsignedWrap(
true);
5204 cast<TruncInst>(
I)->setHasNoSignedWrap(
true);
5206if (isa<FPMathOperator>(
I)) {
5209I->setFastMathFlags(FMF);
5228 Ty = getTypeByID(TyID);
5232 TyID = InvalidTypeID;
5237unsigned BasePtrTypeID;
5238if (getValueTypePair(
Record, OpNum, NextValueNo, BasePtr, BasePtrTypeID,
5240returnerror(
"Invalid record");
5243 TyID = getContainedTypeID(BasePtrTypeID);
5244if (
BasePtr->getType()->isVectorTy())
5245 TyID = getContainedTypeID(TyID);
5246 Ty = getTypeByID(TyID);
5250while (OpNum !=
Record.size()) {
5253if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB))
5254returnerror(
"Invalid record");
5262if (cast<GEPOperator>(
I)->getNumIndices() != 0) {
5265unsigned SubType = 0;
5266if (GTI.isStruct()) {
5268Idx->getType()->isVectorTy()
5273 ResTypeID = getContainedTypeID(ResTypeID, SubType);
5278// At this point ResTypeID is the result element type. We need a pointer 5279// or vector of pointer to it. 5280 ResTypeID = getVirtualTypeID(
I->getType()->getScalarType(), ResTypeID);
5281if (
I->getType()->isVectorTy())
5282 ResTypeID = getVirtualTypeID(
I->getType(), ResTypeID);
5285GEP->setNoWrapFlags(NW);
5290// EXTRACTVAL: [opty, opval, n x indices] 5294if (getValueTypePair(
Record, OpNum, NextValueNo, Agg, AggTypeID, CurBB))
5295returnerror(
"Invalid record");
5298unsigned RecSize =
Record.size();
5299if (OpNum == RecSize)
5300returnerror(
"EXTRACTVAL: Invalid instruction with 0 indices");
5303 ResTypeID = AggTypeID;
5304for (; OpNum != RecSize; ++OpNum) {
5309if (!IsStruct && !IsArray)
5310returnerror(
"EXTRACTVAL: Invalid type");
5311if ((
unsigned)Index != Index)
5312returnerror(
"Invalid value");
5314returnerror(
"EXTRACTVAL: Invalid struct index");
5316returnerror(
"EXTRACTVAL: Invalid array index");
5317 EXTRACTVALIdx.
push_back((
unsigned)Index);
5321 ResTypeID = getContainedTypeID(ResTypeID, Index);
5324 ResTypeID = getContainedTypeID(ResTypeID);
5334// INSERTVAL: [opty, opval, opty, opval, n x indices] 5338if (getValueTypePair(
Record, OpNum, NextValueNo, Agg, AggTypeID, CurBB))
5339returnerror(
"Invalid record");
5342if (getValueTypePair(
Record, OpNum, NextValueNo, Val, ValTypeID, CurBB))
5343returnerror(
"Invalid record");
5345unsigned RecSize =
Record.size();
5346if (OpNum == RecSize)
5347returnerror(
"INSERTVAL: Invalid instruction with 0 indices");
5351for (; OpNum != RecSize; ++OpNum) {
5356if (!IsStruct && !IsArray)
5357returnerror(
"INSERTVAL: Invalid type");
5358if ((
unsigned)Index != Index)
5359returnerror(
"Invalid value");
5361returnerror(
"INSERTVAL: Invalid struct index");
5363returnerror(
"INSERTVAL: Invalid array index");
5365 INSERTVALIdx.
push_back((
unsigned)Index);
5373returnerror(
"Inserted value type doesn't match aggregate type");
5376 ResTypeID = AggTypeID;
5382// obsolete form of select 5383// handles select i1 ... in old bitcode 5388if (getValueTypePair(
Record, OpNum, NextValueNo, TrueVal,
TypeID,
5392 popValue(
Record, OpNum, NextValueNo, CondType,
5393 getVirtualTypeID(CondType),
Cond, CurBB))
5394returnerror(
"Invalid record");
5403// new form of select 5404// handles select i1 or select [N x i1] 5407unsigned ValTypeID, CondTypeID;
5408if (getValueTypePair(
Record, OpNum, NextValueNo, TrueVal, ValTypeID,
5410 popValue(
Record, OpNum, NextValueNo,
TrueVal->getType(), ValTypeID,
5412 getValueTypePair(
Record, OpNum, NextValueNo,
Cond, CondTypeID, CurBB))
5413returnerror(
"Invalid record");
5415// select condition can be either i1 or [N x i1] 5417 dyn_cast<VectorType>(
Cond->getType())) {
5420returnerror(
"Invalid type for value");
5424returnerror(
"Invalid type for value");
5428 ResTypeID = ValTypeID;
5430if (OpNum <
Record.size() && isa<FPMathOperator>(
I)) {
5433I->setFastMathFlags(FMF);
5441unsigned VecTypeID, IdxTypeID;
5442if (getValueTypePair(
Record, OpNum, NextValueNo, Vec, VecTypeID, CurBB) ||
5443 getValueTypePair(
Record, OpNum, NextValueNo,
Idx, IdxTypeID, CurBB))
5444returnerror(
"Invalid record");
5446returnerror(
"Invalid type for value");
5448 ResTypeID = getContainedTypeID(VecTypeID);
5456unsigned VecTypeID, IdxTypeID;
5457if (getValueTypePair(
Record, OpNum, NextValueNo, Vec, VecTypeID, CurBB))
5458returnerror(
"Invalid record");
5460returnerror(
"Invalid type for value");
5461if (popValue(
Record, OpNum, NextValueNo,
5462 cast<VectorType>(Vec->
getType())->getElementType(),
5463 getContainedTypeID(VecTypeID), Elt, CurBB) ||
5464 getValueTypePair(
Record, OpNum, NextValueNo,
Idx, IdxTypeID, CurBB))
5465returnerror(
"Invalid record");
5467 ResTypeID = VecTypeID;
5476if (getValueTypePair(
Record, OpNum, NextValueNo, Vec1, Vec1TypeID,
5478 popValue(
Record, OpNum, NextValueNo, Vec1->
getType(), Vec1TypeID,
5480returnerror(
"Invalid record");
5483if (getValueTypePair(
Record, OpNum, NextValueNo, Mask, MaskTypeID, CurBB))
5484returnerror(
"Invalid record");
5486returnerror(
"Invalid type for value");
5490 getVirtualTypeID(
I->getType(), getContainedTypeID(Vec1TypeID));
5496// Old form of ICmp/FCmp returning bool 5497// Existed to differentiate between icmp/fcmp and vicmp/vfcmp which were 5498// both legal on vectors but had different behaviour. 5500// FCmp/ICmp returning bool or vector of bool 5505if (getValueTypePair(
Record, OpNum, NextValueNo, LHS, LHSTypeID, CurBB) ||
5508returnerror(
"Invalid record");
5510if (OpNum >=
Record.size())
5512"Invalid record: operand number exceeded available operands");
5517if (IsFP &&
Record.size() > OpNum+1)
5522returnerror(
"Invalid fcmp predicate");
5526returnerror(
"Invalid icmp predicate");
5528if (
Record.size() > OpNum + 1 &&
5530 cast<ICmpInst>(
I)->setSameSign();
5533if (OpNum + 1 !=
Record.size())
5534returnerror(
"Invalid record");
5536 ResTypeID = getVirtualTypeID(
I->getType()->getScalarType());
5538 ResTypeID = getVirtualTypeID(
I->getType(), ResTypeID);
5541I->setFastMathFlags(FMF);
5558if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB))
5559returnerror(
"Invalid record");
5560if (OpNum !=
Record.size())
5561returnerror(
"Invalid record");
5569returnerror(
"Invalid record");
5572returnerror(
"Invalid record");
5582 getVirtualTypeID(CondType), CurBB);
5583if (!FalseDest || !
Cond)
5584returnerror(
"Invalid record");
5592returnerror(
"Invalid record");
5596 getVirtualTypeID(TokenTy), CurBB);
5598returnerror(
"Invalid record");
5601 UnwindDest = getBasicBlock(
Record[
Idx++]);
5603returnerror(
"Invalid record");
5612returnerror(
"Invalid record");
5616 getVirtualTypeID(TokenTy), CurBB);
5618returnerror(
"Invalid record");
5621returnerror(
"Invalid record");
5628// We must have, at minimum, the outer scope and the number of arguments. 5630returnerror(
"Invalid record");
5636 getVirtualTypeID(TokenTy), CurBB);
5638returnerror(
"Invalid record");
5643for (
unsignedOp = 0;
Op != NumHandlers; ++
Op) {
5646returnerror(
"Invalid record");
5652 UnwindDest = getBasicBlock(
Record[
Idx++]);
5654returnerror(
"Invalid record");
5658returnerror(
"Invalid record");
5663 CatchSwitch->addHandler(Handler);
5665 ResTypeID = getVirtualTypeID(
I->getType());
5671// We must have, at minimum, the outer scope and the number of arguments. 5673returnerror(
"Invalid record");
5679 getVirtualTypeID(TokenTy), CurBB);
5681returnerror(
"Invald record");
5686for (
unsignedOp = 0;
Op != NumArgOperands; ++
Op) {
5689if (getValueTypePair(
Record,
Idx, NextValueNo, Val, ValTypeID,
nullptr))
5690returnerror(
"Invalid record");
5695returnerror(
"Invalid record");
5701 ResTypeID = getVirtualTypeID(
I->getType());
5707if ((
Record[0] >> 16) == SWITCH_INST_MAGIC) {
5708// "New" SwitchInst format with case ranges. The changes to write this 5709// format were reverted but we still recognize bitcode that uses it. 5710// Hopefully someday we will have support for case ranges and can use 5711// this format again. 5713unsigned OpTyID =
Record[1];
5714Type *OpTy = getTypeByID(OpTyID);
5715unsigned ValueBitWidth = cast<IntegerType>(OpTy)->getBitWidth();
5720returnerror(
"Invalid record");
5722unsigned NumCases =
Record[4];
5728for (
unsigned i = 0; i != NumCases; ++i) {
5730unsigned NumItems =
Record[CurIdx++];
5731for (
unsigned ci = 0; ci != NumItems; ++ci) {
5732bool isSingleNumber =
Record[CurIdx++];
5735unsigned ActiveWords = 1;
5736if (ValueBitWidth > 64)
5737 ActiveWords =
Record[CurIdx++];
5740 CurIdx += ActiveWords;
5742if (!isSingleNumber) {
5744if (ValueBitWidth > 64)
5745 ActiveWords =
Record[CurIdx++];
5748 CurIdx += ActiveWords;
5750// FIXME: It is not clear whether values in the range should be 5751// compared as signed or unsigned values. The partially 5752// implemented changes that used this format in the past used 5753// unsigned comparisons. 5761SI->addCase(Cst, DestBB);
5767// Old SwitchInst format without case ranges. 5770returnerror(
"Invalid record");
5771unsigned OpTyID =
Record[0];
5772Type *OpTy = getTypeByID(OpTyID);
5776returnerror(
"Invalid record");
5777unsigned NumCases = (
Record.size()-3)/2;
5780for (
unsigned i = 0, e = NumCases; i !=
e; ++i) {
5781ConstantInt *CaseVal = dyn_cast_or_null<ConstantInt>(
5782 getFnValueByID(
Record[3+i*2], OpTy, OpTyID,
nullptr));
5784if (!CaseVal || !DestBB) {
5786returnerror(
"Invalid record");
5788SI->addCase(CaseVal, DestBB);
5795returnerror(
"Invalid record");
5796unsigned OpTyID =
Record[0];
5797Type *OpTy = getTypeByID(OpTyID);
5799if (!OpTy || !Address)
5800returnerror(
"Invalid record");
5801unsigned NumDests =
Record.size()-2;
5804for (
unsigned i = 0, e = NumDests; i !=
e; ++i) {
5809returnerror(
"Invalid record");
5817// INVOKE: [attrs, cc, normBB, unwindBB, fnty, op0,op1,op2, ...] 5819returnerror(
"Invalid record");
5822unsigned CCInfo =
Record[OpNum++];
5826unsigned FTyID = InvalidTypeID;
5828if ((CCInfo >> 13) & 1) {
5830 FTy = dyn_cast<FunctionType>(getTypeByID(FTyID));
5832returnerror(
"Explicit invoke type is not a function type");
5836unsigned CalleeTypeID;
5837if (getValueTypePair(
Record, OpNum, NextValueNo, Callee, CalleeTypeID,
5839returnerror(
"Invalid record");
5843returnerror(
"Callee is not a pointer");
5845 FTyID = getContainedTypeID(CalleeTypeID);
5846 FTy = dyn_cast_or_null<FunctionType>(getTypeByID(FTyID));
5848returnerror(
"Callee is not of pointer to function type");
5850if (
Record.size() < FTy->getNumParams() + OpNum)
5851returnerror(
"Insufficient operands to call");
5855for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i, ++OpNum) {
5856unsigned ArgTyID = getContainedTypeID(FTyID, i + 1);
5857 Ops.
push_back(getValue(
Record, OpNum, NextValueNo, FTy->getParamType(i),
5861returnerror(
"Invalid record");
5864if (!FTy->isVarArg()) {
5865if (
Record.size() != OpNum)
5866returnerror(
"Invalid record");
5868// Read type/value pairs for varargs params. 5869while (OpNum !=
Record.size()) {
5872if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB))
5873returnerror(
"Invalid record");
5879// Upgrade the bundles if needed. 5880if (!OperandBundles.empty())
5885 ResTypeID = getContainedTypeID(FTyID);
5886 OperandBundles.clear();
5888 cast<InvokeInst>(
I)->setCallingConv(
5890 cast<InvokeInst>(
I)->setAttributes(PAL);
5891if (
Error Err = propagateAttributeTypes(cast<CallBase>(
I), ArgTyIDs)) {
5902if (getValueTypePair(
Record,
Idx, NextValueNo, Val, ValTypeID, CurBB))
5903returnerror(
"Invalid record");
5909// CALLBR: [attr, cc, norm, transfs, fty, fnid, args] 5912unsigned CCInfo =
Record[OpNum++];
5915unsigned NumIndirectDests =
Record[OpNum++];
5917for (
unsigned i = 0, e = NumIndirectDests; i !=
e; ++i)
5920unsigned FTyID = InvalidTypeID;
5924 FTy = dyn_cast_or_null<FunctionType>(getTypeByID(FTyID));
5926returnerror(
"Explicit call type is not a function type");
5930unsigned CalleeTypeID;
5931if (getValueTypePair(
Record, OpNum, NextValueNo, Callee, CalleeTypeID,
5933returnerror(
"Invalid record");
5937returnerror(
"Callee is not a pointer type");
5939 FTyID = getContainedTypeID(CalleeTypeID);
5940 FTy = dyn_cast_or_null<FunctionType>(getTypeByID(FTyID));
5942returnerror(
"Callee is not of pointer to function type");
5944if (
Record.size() < FTy->getNumParams() + OpNum)
5945returnerror(
"Insufficient operands to call");
5949// Read the fixed params. 5950for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i, ++OpNum) {
5952unsigned ArgTyID = getContainedTypeID(FTyID, i + 1);
5953if (FTy->getParamType(i)->isLabelTy())
5954 Arg = getBasicBlock(
Record[OpNum]);
5956 Arg = getValue(
Record, OpNum, NextValueNo, FTy->getParamType(i),
5959returnerror(
"Invalid record");
5964// Read type/value pairs for varargs params. 5965if (!FTy->isVarArg()) {
5966if (OpNum !=
Record.size())
5967returnerror(
"Invalid record");
5969while (OpNum !=
Record.size()) {
5972if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB))
5973returnerror(
"Invalid record");
5979// Upgrade the bundles if needed. 5980if (!OperandBundles.empty())
5983if (
auto *IA = dyn_cast<InlineAsm>(Callee)) {
5988if (
none_of(ConstraintInfo, IsLabelConstraint)) {
5989// Upgrade explicit blockaddress arguments to label constraints. 5990// Verify that the last arguments are blockaddress arguments that 5991// match the indirect destinations. Clang always generates callbr 5992// in this form. We could support reordering with more effort. 5993unsigned FirstBlockArg =
Args.size() - IndirectDests.
size();
5994for (
unsigned ArgNo = FirstBlockArg; ArgNo <
Args.size(); ++ArgNo) {
5995unsigned LabelNo = ArgNo - FirstBlockArg;
5996auto *BA = dyn_cast<BlockAddress>(Args[ArgNo]);
5997if (!BA || BA->getFunction() !=
F ||
5998 LabelNo > IndirectDests.
size() ||
5999 BA->getBasicBlock() != IndirectDests[LabelNo])
6000returnerror(
"callbr argument does not match indirect dest");
6003// Remove blockaddress arguments. 6005 ArgTyIDs.
erase(ArgTyIDs.
begin() + FirstBlockArg, ArgTyIDs.
end());
6007// Recreate the function type with less arguments. 6009for (
Value *Arg : Args)
6012 FunctionType::get(FTy->getReturnType(), ArgTys, FTy->isVarArg());
6014// Update constraint string to use label constraints. 6015 std::string Constraints =
IA->getConstraintString();
6018for (
constauto &CI : ConstraintInfo) {
6020if (ArgNo >= FirstBlockArg)
6021 Constraints.insert(Pos,
"!");
6025// Go to next constraint in string. 6026 Pos = Constraints.find(
',', Pos);
6027if (Pos == std::string::npos)
6033IA->hasSideEffects(),
IA->isAlignStack(),
6034IA->getDialect(),
IA->canThrow());
6040 ResTypeID = getContainedTypeID(FTyID);
6041 OperandBundles.clear();
6043 cast<CallBrInst>(
I)->setCallingConv(
6045 cast<CallBrInst>(
I)->setAttributes(PAL);
6046if (
Error Err = propagateAttributeTypes(cast<CallBase>(
I), ArgTyIDs)) {
6058returnerror(
"Invalid phi record");
6059// The first record specifies the type. 6061Type *Ty = getTypeByID(TyID);
6063returnerror(
"Invalid phi record");
6065// Phi arguments are pairs of records of [value, basic block]. 6066// There is an optional final record for fast-math-flags if this phi has a 6067// floating-point type. 6068size_t NumArgs = (
Record.size() - 1) / 2;
6070if ((
Record.size() - 1) % 2 == 1 && !isa<FPMathOperator>(PN)) {
6072returnerror(
"Invalid phi record");
6077for (
unsigned i = 0; i != NumArgs; i++) {
6081returnerror(
"Invalid phi BB");
6084// Phi nodes may contain the same predecessor multiple times, in which 6085// case the incoming value must be identical. Directly reuse the already 6086// seen value here, to avoid expanding a constant expression multiple 6088auto It =
Args.find(BB);
6089if (It !=
Args.end()) {
6094// If there already is a block for this edge (from a different phi), 6098// Otherwise, use a temporary block (that we will discard if it 6099// turns out to be unnecessary). 6102 EdgeBB = PhiConstExprBB;
6105// With the new function encoding, it is possible that operands have 6106// negative IDs (for forward references). Use a signed VBR 6107// representation to keep the encoding small. 6110V = getValueSigned(
Record, i * 2 + 1, NextValueNo, Ty, TyID, EdgeBB);
6112V = getValue(
Record, i * 2 + 1, NextValueNo, Ty, TyID, EdgeBB);
6116returnerror(
"Invalid phi record");
6119if (EdgeBB == PhiConstExprBB && !EdgeBB->
empty()) {
6120 ConstExprEdgeBBs.
insert({{BB, CurBB}, EdgeBB});
6121 PhiConstExprBB =
nullptr;
6129// If there are an even number of records, the final record must be FMF. 6130if (
Record.size() % 2 == 0) {
6131assert(isa<FPMathOperator>(
I) &&
"Unexpected phi type");
6134I->setFastMathFlags(FMF);
6142// LANDINGPAD: [ty, val, val, num, (id0,val0 ...)?] 6146returnerror(
"Invalid record");
6150returnerror(
"Invalid record");
6153Type *Ty = getTypeByID(ResTypeID);
6155returnerror(
"Invalid record");
6157Value *PersFn =
nullptr;
6158unsigned PersFnTypeID;
6159if (getValueTypePair(
Record,
Idx, NextValueNo, PersFn, PersFnTypeID,
6161returnerror(
"Invalid record");
6163if (!
F->hasPersonalityFn())
6164F->setPersonalityFn(cast<Constant>(PersFn));
6165elseif (
F->getPersonalityFn() != cast<Constant>(PersFn))
6166returnerror(
"Personality function mismatch");
6173for (
unsigned J = 0; J != NumClauses; ++J) {
6179if (getValueTypePair(
Record,
Idx, NextValueNo, Val, ValTypeID,
6182returnerror(
"Invalid record");
6186 !isa<ArrayType>(Val->
getType())) &&
6187"Catch clause has a invalid type!");
6189 isa<ArrayType>(Val->
getType())) &&
6190"Filter clause has invalid type!");
6201returnerror(
"Invalid record");
6204constbool InAlloca = Bitfield::get<APV::UsedWithInAlloca>(Rec);
6205constbool SwiftError = Bitfield::get<APV::SwiftError>(Rec);
6207Type *Ty = getTypeByID(TyID);
6208if (!Bitfield::get<APV::ExplicitType>(Rec)) {
6209 TyID = getContainedTypeID(TyID);
6210 Ty = getTypeByID(TyID);
6212returnerror(
"Missing element type for old-style alloca");
6214unsigned OpTyID =
Record[1];
6215Type *OpTy = getTypeByID(OpTyID);
6219 Bitfield::get<APV::AlignLower>(Rec) |
6220 (Bitfield::get<APV::AlignUpper>(Rec) << APV::AlignLower::Bits);
6221if (
Error Err = parseAlignmentValue(AlignExp,
Align)) {
6225returnerror(
"Invalid record");
6228unsigned AS =
Record.size() == 5 ?
Record[4] :
DL.getAllocaAddrSpace();
6232returnerror(
"alloca of unsized type");
6234Align =
DL.getPrefTypeAlign(Ty);
6236if (!
Size->getType()->isIntegerTy())
6237returnerror(
"alloca element count must have integer type");
6243 ResTypeID = getVirtualTypeID(AI->
getType(), TyID);
6251if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB) ||
6252 (OpNum + 2 !=
Record.size() && OpNum + 3 !=
Record.size()))
6253returnerror(
"Invalid record");
6255if (!isa<PointerType>(
Op->getType()))
6256returnerror(
"Load operand is not a pointer type");
6259if (OpNum + 3 ==
Record.size()) {
6260 ResTypeID =
Record[OpNum++];
6261 Ty = getTypeByID(ResTypeID);
6263 ResTypeID = getContainedTypeID(OpTypeID);
6264 Ty = getTypeByID(ResTypeID);
6268returnerror(
"Missing load type");
6270if (
Error Err = typeCheckLoadStoreInst(Ty,
Op->getType()))
6278returnerror(
"load of unsized type");
6280Align = TheModule->getDataLayout().getABITypeAlign(Ty);
6286// LOADATOMIC: [opty, op, align, vol, ordering, ssid] 6290if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB) ||
6291 (OpNum + 4 !=
Record.size() && OpNum + 5 !=
Record.size()))
6292returnerror(
"Invalid record");
6294if (!isa<PointerType>(
Op->getType()))
6295returnerror(
"Load operand is not a pointer type");
6298if (OpNum + 5 ==
Record.size()) {
6299 ResTypeID =
Record[OpNum++];
6300 Ty = getTypeByID(ResTypeID);
6302 ResTypeID = getContainedTypeID(OpTypeID);
6303 Ty = getTypeByID(ResTypeID);
6307returnerror(
"Missing atomic load type");
6309if (
Error Err = typeCheckLoadStoreInst(Ty,
Op->getType()))
6313if (Ordering == AtomicOrdering::NotAtomic ||
6314 Ordering == AtomicOrdering::Release ||
6315 Ordering == AtomicOrdering::AcquireRelease)
6316returnerror(
"Invalid record");
6317if (Ordering != AtomicOrdering::NotAtomic &&
Record[OpNum] == 0)
6318returnerror(
"Invalid record");
6325returnerror(
"Alignment missing from atomic load");
6334unsigned PtrTypeID, ValTypeID;
6335if (getValueTypePair(
Record, OpNum, NextValueNo,
Ptr, PtrTypeID, CurBB))
6336returnerror(
"Invalid record");
6339if (getValueTypePair(
Record, OpNum, NextValueNo, Val, ValTypeID, CurBB))
6340returnerror(
"Invalid record");
6342 ValTypeID = getContainedTypeID(PtrTypeID);
6343if (popValue(
Record, OpNum, NextValueNo, getTypeByID(ValTypeID),
6344 ValTypeID, Val, CurBB))
6345returnerror(
"Invalid record");
6348if (OpNum + 2 !=
Record.size())
6349returnerror(
"Invalid record");
6358returnerror(
"store of unsized type");
6360Align = TheModule->getDataLayout().getABITypeAlign(Val->
getType());
6367// STOREATOMIC: [ptrty, ptr, val, align, vol, ordering, ssid] 6370unsigned PtrTypeID, ValTypeID;
6371if (getValueTypePair(
Record, OpNum, NextValueNo,
Ptr, PtrTypeID, CurBB) ||
6372 !isa<PointerType>(
Ptr->getType()))
6373returnerror(
"Invalid record");
6375if (getValueTypePair(
Record, OpNum, NextValueNo, Val, ValTypeID, CurBB))
6376returnerror(
"Invalid record");
6378 ValTypeID = getContainedTypeID(PtrTypeID);
6379if (popValue(
Record, OpNum, NextValueNo, getTypeByID(ValTypeID),
6380 ValTypeID, Val, CurBB))
6381returnerror(
"Invalid record");
6384if (OpNum + 4 !=
Record.size())
6385returnerror(
"Invalid record");
6390if (Ordering == AtomicOrdering::NotAtomic ||
6391 Ordering == AtomicOrdering::Acquire ||
6392 Ordering == AtomicOrdering::AcquireRelease)
6393returnerror(
"Invalid record");
6395if (Ordering != AtomicOrdering::NotAtomic &&
Record[OpNum] == 0)
6396returnerror(
"Invalid record");
6402returnerror(
"Alignment missing from atomic store");
6408// CMPXCHG_OLD: [ptrty, ptr, cmp, val, vol, ordering, synchscope, 6409// failure_ordering?, weak?] 6410constsize_t NumRecords =
Record.size();
6414if (getValueTypePair(
Record, OpNum, NextValueNo,
Ptr, PtrTypeID, CurBB))
6415returnerror(
"Invalid record");
6417if (!isa<PointerType>(
Ptr->getType()))
6418returnerror(
"Cmpxchg operand is not a pointer type");
6421unsigned CmpTypeID = getContainedTypeID(PtrTypeID);
6422if (popValue(
Record, OpNum, NextValueNo, getTypeByID(CmpTypeID),
6423 CmpTypeID, Cmp, CurBB))
6424returnerror(
"Invalid record");
6427if (popValue(
Record, OpNum, NextValueNo,
Cmp->getType(), CmpTypeID,
6429 NumRecords < OpNum + 3 || NumRecords > OpNum + 5)
6430returnerror(
"Invalid record");
6434if (SuccessOrdering == AtomicOrdering::NotAtomic ||
6435 SuccessOrdering == AtomicOrdering::Unordered)
6436returnerror(
"Invalid record");
6440if (
Error Err = typeCheckLoadStoreInst(
Cmp->getType(),
Ptr->getType()))
6448if (FailureOrdering == AtomicOrdering::NotAtomic ||
6449 FailureOrdering == AtomicOrdering::Unordered)
6450returnerror(
"Invalid record");
6452constAlign Alignment(
6453 TheModule->getDataLayout().getTypeStoreSize(
Cmp->getType()));
6456 FailureOrdering, SSID);
6457 cast<AtomicCmpXchgInst>(
I)->setVolatile(
Record[OpNum]);
6459if (NumRecords < 8) {
6460// Before weak cmpxchgs existed, the instruction simply returned the 6461// value loaded from memory, so bitcode files from that era will be 6462// expecting the first component of a modern cmpxchg. 6463I->insertInto(CurBB, CurBB->
end());
6465 ResTypeID = CmpTypeID;
6467 cast<AtomicCmpXchgInst>(
I)->setWeak(
Record[OpNum + 4]);
6469 ResTypeID = getVirtualTypeID(
I->getType(), {CmpTypeID, I1TypeID});
6476// CMPXCHG: [ptrty, ptr, cmp, val, vol, success_ordering, synchscope, 6477// failure_ordering, weak, align?] 6478constsize_t NumRecords =
Record.size();
6482if (getValueTypePair(
Record, OpNum, NextValueNo,
Ptr, PtrTypeID, CurBB))
6483returnerror(
"Invalid record");
6485if (!isa<PointerType>(
Ptr->getType()))
6486returnerror(
"Cmpxchg operand is not a pointer type");
6490if (getValueTypePair(
Record, OpNum, NextValueNo, Cmp, CmpTypeID, CurBB))
6491returnerror(
"Invalid record");
6494if (popValue(
Record, OpNum, NextValueNo,
Cmp->getType(), CmpTypeID, Val,
6496returnerror(
"Invalid record");
6498if (NumRecords < OpNum + 3 || NumRecords > OpNum + 6)
6499returnerror(
"Invalid record");
6501constbool IsVol =
Record[OpNum];
6506returnerror(
"Invalid cmpxchg success ordering");
6510if (
Error Err = typeCheckLoadStoreInst(
Cmp->getType(),
Ptr->getType()))
6516returnerror(
"Invalid cmpxchg failure ordering");
6518constbool IsWeak =
Record[OpNum + 4];
6522if (NumRecords == (OpNum + 6)) {
6523if (
Error Err = parseAlignmentValue(
Record[OpNum + 5], Alignment))
6528Align(TheModule->getDataLayout().getTypeStoreSize(
Cmp->getType()));
6531 FailureOrdering, SSID);
6532 cast<AtomicCmpXchgInst>(
I)->setVolatile(IsVol);
6533 cast<AtomicCmpXchgInst>(
I)->setWeak(IsWeak);
6536 ResTypeID = getVirtualTypeID(
I->getType(), {CmpTypeID, I1TypeID});
6543// ATOMICRMW_OLD: [ptrty, ptr, val, op, vol, ordering, ssid, align?] 6544// ATOMICRMW: [ptrty, ptr, valty, val, op, vol, ordering, ssid, align?] 6545constsize_t NumRecords =
Record.size();
6550if (getValueTypePair(
Record, OpNum, NextValueNo,
Ptr, PtrTypeID, CurBB))
6551returnerror(
"Invalid record");
6553if (!isa<PointerType>(
Ptr->getType()))
6554returnerror(
"Invalid record");
6557unsigned ValTypeID = InvalidTypeID;
6559 ValTypeID = getContainedTypeID(PtrTypeID);
6560if (popValue(
Record, OpNum, NextValueNo,
6561 getTypeByID(ValTypeID), ValTypeID, Val, CurBB))
6562returnerror(
"Invalid record");
6564if (getValueTypePair(
Record, OpNum, NextValueNo, Val, ValTypeID, CurBB))
6565returnerror(
"Invalid record");
6568if (!(NumRecords == (OpNum + 4) || NumRecords == (OpNum + 5)))
6569returnerror(
"Invalid record");
6575returnerror(
"Invalid record");
6577constbool IsVol =
Record[OpNum + 1];
6580if (Ordering == AtomicOrdering::NotAtomic ||
6581 Ordering == AtomicOrdering::Unordered)
6582returnerror(
"Invalid record");
6588if (NumRecords == (OpNum + 5)) {
6589if (
Error Err = parseAlignmentValue(
Record[OpNum + 4], Alignment))
6595Align(TheModule->getDataLayout().getTypeStoreSize(Val->
getType()));
6598 ResTypeID = ValTypeID;
6599 cast<AtomicRMWInst>(
I)->setVolatile(IsVol);
6606returnerror(
"Invalid record");
6608if (Ordering == AtomicOrdering::NotAtomic ||
6609 Ordering == AtomicOrdering::Unordered ||
6610 Ordering == AtomicOrdering::Monotonic)
6611returnerror(
"Invalid record");
6618// DbgLabelRecords are placed after the Instructions that they are 6620 SeenDebugRecord =
true;
6623returnerror(
"Invalid dbg record: missing instruction");
6626 Inst->
getParent()->insertDbgRecordBefore(
6628continue;
// This isn't an instruction. 6634// DbgVariableRecords are placed after the Instructions that they are 6636 SeenDebugRecord =
true;
6639returnerror(
"Invalid dbg record: missing instruction");
6641// First 3 fields are common to all kinds: 6642// DILocation, DILocalVariable, DIExpression 6643// dbg_value (FUNC_CODE_DEBUG_RECORD_VALUE) 6644// ..., LocationMetadata 6645// dbg_value (FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE - abbrev'd) 6647// dbg_declare (FUNC_CODE_DEBUG_RECORD_DECLARE) 6648// ..., LocationMetadata 6649// dbg_assign (FUNC_CODE_DEBUG_RECORD_ASSIGN) 6650// ..., LocationMetadata, DIAssignID, DIExpression, LocationMetadata 6652// Common fields (0-2). 6655 cast<DILocalVariable>(getFnMetadataByID(
Record[Slot++]));
6657 cast<DIExpression>(getFnMetadataByID(
Record[Slot++]));
6659// Union field (3: LocationMetadata | Value). 6664// We never expect to see a fwd reference value here because 6665// use-before-defs are encoded with the standard non-abbrev record 6666// type (they'd require encoding the type too, and they're rare). As a 6667// result, getValueTypePair only ever increments Slot by one here (once 6668// for the value, never twice for value and type). 6669unsigned SlotBefore =
Slot;
6670if (getValueTypePair(
Record, Slot, NextValueNo, V, TyID, CurBB))
6671returnerror(
"Invalid dbg record: invalid value");
6673assert((SlotBefore == Slot - 1) &&
"unexpected fwd ref");
6676 RawLocation = getFnMetadataByID(
Record[Slot++]);
6684 DbgVariableRecord::LocationType::Value);
6688 DbgVariableRecord::LocationType::Declare);
6693 cast<DIExpression>(getFnMetadataByID(
Record[Slot++]));
6703continue;
// This isn't an instruction. 6706// CALL: [paramattrs, cc, fmf, fnty, fnid, arg0, arg1...] 6708returnerror(
"Invalid record");
6712unsigned CCInfo =
Record[OpNum++];
6718returnerror(
"Fast math flags indicator set for call with no FMF");
6721unsigned FTyID = InvalidTypeID;
6725 FTy = dyn_cast_or_null<FunctionType>(getTypeByID(FTyID));
6727returnerror(
"Explicit call type is not a function type");
6731unsigned CalleeTypeID;
6732if (getValueTypePair(
Record, OpNum, NextValueNo, Callee, CalleeTypeID,
6734returnerror(
"Invalid record");
6738returnerror(
"Callee is not a pointer type");
6740 FTyID = getContainedTypeID(CalleeTypeID);
6741 FTy = dyn_cast_or_null<FunctionType>(getTypeByID(FTyID));
6743returnerror(
"Callee is not of pointer to function type");
6745if (
Record.size() < FTy->getNumParams() + OpNum)
6746returnerror(
"Insufficient operands to call");
6750// Read the fixed params. 6751for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i, ++OpNum) {
6752unsigned ArgTyID = getContainedTypeID(FTyID, i + 1);
6753if (FTy->getParamType(i)->isLabelTy())
6756Args.push_back(getValue(
Record, OpNum, NextValueNo,
6757 FTy->getParamType(i), ArgTyID, CurBB));
6760returnerror(
"Invalid record");
6763// Read type/value pairs for varargs params. 6764if (!FTy->isVarArg()) {
6765if (OpNum !=
Record.size())
6766returnerror(
"Invalid record");
6768while (OpNum !=
Record.size()) {
6771if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB))
6772returnerror(
"Invalid record");
6778// Upgrade the bundles if needed. 6779if (!OperandBundles.empty())
6783 ResTypeID = getContainedTypeID(FTyID);
6784 OperandBundles.clear();
6786 cast<CallInst>(
I)->setCallingConv(
6795 cast<CallInst>(
I)->setTailCallKind(TCK);
6796 cast<CallInst>(
I)->setAttributes(PAL);
6797if (isa<DbgInfoIntrinsic>(
I))
6798 SeenDebugIntrinsic =
true;
6799if (
Error Err = propagateAttributeTypes(cast<CallBase>(
I), ArgTyIDs)) {
6804if (!isa<FPMathOperator>(
I))
6805returnerror(
"Fast-math-flags specified for call without " 6806"floating-point scalar or vector return type");
6807I->setFastMathFlags(FMF);
6813returnerror(
"Invalid record");
6814unsigned OpTyID =
Record[0];
6815Type *OpTy = getTypeByID(OpTyID);
6816Value *
Op = getValue(
Record, 1, NextValueNo, OpTy, OpTyID, CurBB);
6818Type *ResTy = getTypeByID(ResTypeID);
6819if (!OpTy || !
Op || !ResTy)
6820returnerror(
"Invalid record");
6827// A call or an invoke can be optionally prefixed with some variable 6828// number of operand bundle blocks. These blocks are read into 6829// OperandBundles and consumed at the next call or invoke instruction. 6832returnerror(
"Invalid record");
6834 std::vector<Value *> Inputs;
6837while (OpNum !=
Record.size()) {
6839if (getValueOrMetadata(
Record, OpNum, NextValueNo,
Op, CurBB))
6840returnerror(
"Invalid record");
6841 Inputs.push_back(
Op);
6844 OperandBundles.emplace_back(BundleTags[
Record[0]], std::move(Inputs));
6852if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB))
6853returnerror(
"Invalid record");
6854if (OpNum !=
Record.size())
6855returnerror(
"Invalid record");
6858 ResTypeID = OpTypeID;
6864// Add instruction to end of current BB. If there is no current BB, reject 6868returnerror(
"Invalid instruction with no BB");
6870if (!OperandBundles.empty()) {
6872returnerror(
"Operand bundles found with no consumer");
6874I->insertInto(CurBB, CurBB->
end());
6876// If this was a terminator instruction, move to the next block. 6877if (
I->isTerminator()) {
6879 CurBB = CurBBNo < FunctionBBs.size() ? FunctionBBs[CurBBNo] :
nullptr;
6882// Non-void values get registered in the value table for future use. 6883if (!
I->getType()->isVoidTy()) {
6884assert(
I->getType() == getTypeByID(ResTypeID) &&
6885"Incorrect result type ID");
6893if (!OperandBundles.empty())
6894returnerror(
"Operand bundles found with no consumer");
6896// Check the function list for unresolved values. 6898if (!
A->getParent()) {
6899// We found at least one unresolved value. Nuke them all to avoid leaks. 6900for (
unsigned i = ModuleValueListSize, e = ValueList.
size(); i != e; ++i){
6901if ((
A = dyn_cast_or_null<Argument>(ValueList[i])) && !
A->getParent()) {
6906returnerror(
"Never resolved value found in function");
6910// Unexpected unresolved metadata about to be dropped. 6911if (MDLoader->hasFwdRefs())
6912returnerror(
"Invalid function metadata: outgoing forward refs");
6917for (
constauto &Pair : ConstExprEdgeBBs) {
6922From->getTerminator()->replaceSuccessorWith(To, EdgeBB);
6927// Trim the value list down to the size it was before we parsed this function. 6928 ValueList.
shrinkTo(ModuleValueListSize);
6929 MDLoader->shrinkTo(ModuleMDLoaderSize);
6930 std::vector<BasicBlock*>().swap(FunctionBBs);
6934/// Find the function body in the bitcode stream 6935Error BitcodeReader::findFunctionInStream(
6938while (DeferredFunctionInfoIterator->second == 0) {
6939// This is the fallback handling for the old format bitcode that 6940// didn't contain the function index in the VST, or when we have 6941// an anonymous function which would not have a VST entry. 6942// Assert that we have one of those two cases. 6943assert(VSTOffset == 0 || !
F->hasName());
6944// Parse the next body in the stream and set its position in the 6945// DeferredFunctionInfo map. 6946if (
Error Err = rememberAndSkipFunctionBodies())
6952SyncScope::ID BitcodeReader::getDecodedSyncScopeID(
unsigned Val) {
6955if (Val >= SSIDs.
size())
6960//===----------------------------------------------------------------------===// 6961// GVMaterializer implementation 6962//===----------------------------------------------------------------------===// 6966// If it's not a function or is already material, ignore the request. 6967if (!
F || !
F->isMaterializable())
6971assert(DFII != DeferredFunctionInfo.
end() &&
"Deferred function not found!");
6972// If its position is recorded as 0, its body is somewhere in the stream 6973// but we haven't seen it yet. 6974if (DFII->second == 0)
6975if (
Error Err = findFunctionInStream(
F, DFII))
6978// Materialize metadata before parsing any function bodies. 6979if (
Error Err = materializeMetadata())
6982// Move the bit stream to the saved position of the deferred function body. 6983if (
Error JumpFailed = Stream.JumpToBit(DFII->second))
6986// Regardless of the debug info format we want to end up in, we need 6987// IsNewDbgInfoFormat=true to construct any debug records seen in the bitcode. 6988F->IsNewDbgInfoFormat =
true;
6990if (
Error Err = parseFunctionBody(
F))
6992F->setIsMaterializable(
false);
6994// All parsed Functions should load into the debug info format dictated by the 6995// Module, unless we're attempting to preserve the input debug info format. 6996if (SeenDebugIntrinsic && SeenDebugRecord)
6997returnerror(
"Mixed debug intrinsics and debug records in bitcode module!");
6999bool SeenAnyDebugInfo = SeenDebugIntrinsic || SeenDebugRecord;
7000bool NewDbgInfoFormatDesired =
7001 SeenAnyDebugInfo ? SeenDebugRecord :
F->getParent()->IsNewDbgInfoFormat;
7002if (SeenAnyDebugInfo) {
7007// If the module's debug info format doesn't match the observed input 7008// format, then set its format now; we don't need to call the conversion 7009// function because there must be no existing intrinsics to convert. 7010// Otherwise, just set the format on this function now. 7011if (NewDbgInfoFormatDesired !=
F->getParent()->IsNewDbgInfoFormat)
7012F->getParent()->setNewDbgInfoFormatFlag(NewDbgInfoFormatDesired);
7014F->setNewDbgInfoFormatFlag(NewDbgInfoFormatDesired);
7016// If we aren't preserving formats, we use the Module flag to get our 7017// desired format instead of reading flags, in case we are lazy-loading and 7018// the format of the module has been changed since it was set by the flags. 7019// We only need to convert debug info here if we have debug records but 7020// desire the intrinsic format; everything else is a no-op or handled by the 7022bool ModuleIsNewDbgInfoFormat =
F->getParent()->IsNewDbgInfoFormat;
7023if (ModuleIsNewDbgInfoFormat || !SeenDebugRecord)
7024F->setNewDbgInfoFormatFlag(ModuleIsNewDbgInfoFormat);
7026F->setIsNewDbgInfoFormat(ModuleIsNewDbgInfoFormat);
7032// Upgrade any old intrinsic calls in the function. 7033for (
auto &
I : UpgradedIntrinsics) {
7035if (
CallInst *CI = dyn_cast<CallInst>(U))
7039// Finish fn->subprogram upgrade for materialized functions. 7040if (
DISubprogram *SP = MDLoader->lookupSubprogramForFunction(
F))
7041F->setSubprogram(SP);
7043// Check if the TBAA Metadata are valid, otherwise we will need to strip them. 7044if (!MDLoader->isStrippingTBAA()) {
7046MDNode *TBAA =
I.getMetadata(LLVMContext::MD_tbaa);
7049 MDLoader->setStripTBAA(
true);
7055// "Upgrade" older incorrect branch weights by dropping them. 7056if (
auto *MD =
I.getMetadata(LLVMContext::MD_prof)) {
7057if (MD->getOperand(0) !=
nullptr && isa<MDString>(MD->getOperand(0))) {
7058MDString *MDS = cast<MDString>(MD->getOperand(0));
7060// Check consistency of !prof branch_weights metadata. 7061if (ProfName !=
"branch_weights")
7063unsigned ExpectedNumOperands = 0;
7065 ExpectedNumOperands = BI->getNumSuccessors();
7067 ExpectedNumOperands =
SI->getNumSuccessors();
7068elseif (isa<CallInst>(&
I))
7069 ExpectedNumOperands = 1;
7072elseif (isa<SelectInst>(&
I))
7073 ExpectedNumOperands = 2;
7075continue;
// ignore and continue. 7079// If branch weight doesn't match, just strip branch weight. 7080if (MD->getNumOperands() !=
Offset + ExpectedNumOperands)
7081I.setMetadata(LLVMContext::MD_prof,
nullptr);
7085// Remove incompatible attributes on function calls. 7086if (
auto *CI = dyn_cast<CallBase>(&
I)) {
7088 CI->getFunctionType()->getReturnType(), CI->getRetAttributes()));
7090for (
unsigned ArgNo = 0; ArgNo < CI->arg_size(); ++ArgNo)
7092 CI->getArgOperand(ArgNo)->getType(),
7093 CI->getParamAttributes(ArgNo)));
7097// Look for functions that rely on old function attribute behavior. 7100// Bring in any functions that this function forward-referenced via 7102return materializeForwardReferencedFunctions();
7105Error BitcodeReader::materializeModule() {
7106if (
Error Err = materializeMetadata())
7109// Promise to materialize all forward references. 7110 WillMaterializeAllForwardRefs =
true;
7112// Iterate over the module, deserializing any functions that are still on 7115if (
Error Err = materialize(&
F))
7118// At this point, if there are any function bodies, parse the rest of 7119// the bits in the module past the last function block we have recorded 7120// through either lazy scanning or the VST. 7121if (LastFunctionBlockBit || NextUnreadBit)
7123 ? LastFunctionBlockBit
7127// Check that all block address forward references got resolved (as we 7129if (!BasicBlockFwdRefs.
empty())
7130returnerror(
"Never resolved function from blockaddress");
7132// Upgrade any intrinsic calls that slipped through (should not happen!) and 7133// delete the old functions to clean up. We can't do this unless the entire 7134// module is materialized because there could always be another function body 7135// with calls to the old function. 7136for (
auto &
I : UpgradedIntrinsics) {
7137for (
auto *U :
I.first->users()) {
7138if (
CallInst *CI = dyn_cast<CallInst>(U))
7141if (!
I.first->use_empty())
7142I.first->replaceAllUsesWith(
I.second);
7143I.first->eraseFromParent();
7145 UpgradedIntrinsics.clear();
7156std::vector<StructType *> BitcodeReader::getIdentifiedStructTypes()
const{
7157return IdentifiedStructTypes;
7160ModuleSummaryIndexBitcodeReader::ModuleSummaryIndexBitcodeReader(
7163 : BitcodeReaderBase(
std::
move(Cursor), Strtab), TheIndex(TheIndex),
7164 ModulePath(ModulePath), IsPrevailing(IsPrevailing) {}
7166void ModuleSummaryIndexBitcodeReader::addThisModule() {
7171ModuleSummaryIndexBitcodeReader::getThisModule() {
7175template <
bool AllowNullValueInfo>
7176std::pair<ValueInfo, GlobalValue::GUID>
7177ModuleSummaryIndexBitcodeReader::getValueInfoFromValueId(
unsigned ValueId) {
7178auto VGI = ValueIdToValueInfoMap[ValueId];
7179// We can have a null value info for memprof callsite info records in 7180// distributed ThinLTO index files when the callee function summary is not 7181// included in the index. The bitcode writer records 0 in that case, 7182// and the caller of this helper will set AllowNullValueInfo to true. 7183assert(AllowNullValueInfo || std::get<0>(VGI));
7187void ModuleSummaryIndexBitcodeReader::setValueGUID(
7190 std::string GlobalId =
7193auto OriginalNameID = ValueGUID;
7197dbgs() <<
"GUID " << ValueGUID <<
"(" << OriginalNameID <<
") is " 7200// UseStrtab is false for legacy summary formats and value names are 7201// created on stack. In that case we save the name in a string saver in 7202// the index so that the value name can be recorded. 7203 ValueIdToValueInfoMap[ValueID] = std::make_pair(
7209// Specialized value symbol table parser used when reading module index 7210// blocks where we don't actually create global values. The parsed information 7211// is saved in the bitcode reader for use when later parsing summaries. 7212Error ModuleSummaryIndexBitcodeReader::parseValueSymbolTable(
7215// With a strtab the VST is not required to parse the summary. 7221if (!MaybeCurrentBit)
7230// Read all the records for this value table. 7239switch (
Entry.Kind) {
7242returnerror(
"Malformed block");
7244// Done parsing VST, jump back to wherever we came from. 7245if (
Error JumpFailed = Stream.JumpToBit(CurrentBit))
7249// The interesting case. 7258switch (MaybeRecord.
get()) {
7259default:
// Default behavior: ignore (e.g. VST_CODE_BBENTRY records). 7263returnerror(
"Invalid record");
7264unsigned ValueID =
Record[0];
7266auto VLI = ValueIdToLinkageMap.
find(ValueID);
7267assert(VLI != ValueIdToLinkageMap.
end() &&
7268"No linkage found for VST entry?");
7270 setValueGUID(ValueID,
ValueName, Linkage, SourceFileName);
7275// VST_CODE_FNENTRY: [valueid, offset, namechar x N] 7277returnerror(
"Invalid record");
7278unsigned ValueID =
Record[0];
7280auto VLI = ValueIdToLinkageMap.
find(ValueID);
7281assert(VLI != ValueIdToLinkageMap.
end() &&
7282"No linkage found for VST entry?");
7284 setValueGUID(ValueID,
ValueName, Linkage, SourceFileName);
7289// VST_CODE_COMBINED_ENTRY: [valueid, refguid] 7290unsigned ValueID =
Record[0];
7292// The "original name", which is the second value of the pair will be 7293// overriden later by a FS_COMBINED_ORIGINAL_NAME in the combined index. 7294 ValueIdToValueInfoMap[ValueID] =
7302// Parse just the blocks needed for building the index out of the module. 7303// At the end of this routine the module Index is populated with a map 7304// from global value id to GlobalValueSummary objects. 7305Error ModuleSummaryIndexBitcodeReader::parseModule() {
7311unsigned ValueId = 0;
7313// Read the index for this module. 7320switch (
Entry.Kind) {
7322returnerror(
"Malformed block");
7328default:
// Skip unknown content. 7329if (
Error Err = Stream.SkipBlock())
7333// Need to parse these to get abbrev ids (e.g. for VST) 7334if (
Error Err = readBlockInfo())
7338// Should have been parsed earlier via VSTOffset, unless there 7339// is no summary section. 7340assert(((SeenValueSymbolTable && VSTOffset > 0) ||
7341 !SeenGlobalValSummary) &&
7342"Expected early VST parse via VSTOffset record");
7343if (
Error Err = Stream.SkipBlock())
7348// Add the module if it is a per-module index (has a source file name). 7349if (!SourceFileName.
empty())
7351assert(!SeenValueSymbolTable &&
7352"Already read VST when parsing summary block?");
7353// We might not have a VST if there were no values in the 7354// summary. An empty summary block generated when we are 7355// performing ThinLTO compiles so we don't later invoke 7356// the regular LTO process on them. 7358if (
Error Err = parseValueSymbolTable(VSTOffset, ValueIdToLinkageMap))
7360 SeenValueSymbolTable =
true;
7362 SeenGlobalValSummary =
true;
7367if (
Error Err = parseModuleStringTable())
7378switch (MaybeBitCode.
get()) {
7380break;
// Default behavior, ignore unknown content. 7382if (
Error Err = parseVersionRecord(
Record).takeError())
7386 /// MODULE_CODE_SOURCE_FILENAME: [namechar x N] 7390returnerror(
"Invalid record");
7394 /// MODULE_CODE_HASH: [5*i32] 7398auto &Hash = getThisModule()->second;
7401assert(!(Val >> 32) &&
"Unexpected high bits set");
7406 /// MODULE_CODE_VSTOFFSET: [offset] 7409returnerror(
"Invalid record");
7410// Note that we subtract 1 here because the offset is relative to one 7411// word before the start of the identification or module block, which 7412// was historically always the start of the regular bitcode header. 7413 VSTOffset =
Record[0] - 1;
7415// v1 GLOBALVAR: [pointer type, isconst, initid, linkage, ...] 7416// v1 FUNCTION: [type, callingconv, isproto, linkage, ...] 7417// v1 ALIAS: [alias type, addrspace, aliasee val#, linkage, ...] 7418// v2: [strtab offset, strtab size, v1] 7424 std::tie(
Name, GVRecord) = readNameFromStrtab(
Record);
7425if (GVRecord.
size() <= 3)
7426returnerror(
"Invalid record");
7430 ValueIdToLinkageMap[ValueId++] =
Linkage;
7434 setValueGUID(ValueId++,
Name, Linkage, SourceFileName);
7449Ret.push_back(std::get<0>(getValueInfoFromValueId(RefValueId)));
7455bool IsOldProfileFormat,
7456bool HasProfile,
bool HasRelBF) {
7458// In the case of new profile formats, there are two Record entries per 7459// Edge. Otherwise, conservatively reserve up to Record.size. 7460if (!IsOldProfileFormat && (HasProfile || HasRelBF))
7465for (
unsignedI = 0, E =
Record.size();
I != E; ++
I) {
7467bool HasTailCall =
false;
7470if (IsOldProfileFormat) {
7471I += 1;
// Skip old callsitecount field 7473I += 1;
// Skip old profilecount field 7474 }
elseif (HasProfile)
7475 std::tie(Hotness, HasTailCall) =
7508static_cast<size_t>(
Record[Slot + 1])};
7531while (Slot <
Record.size())
7535std::vector<FunctionSummary::ParamAccess>
7537auto ReadRange = [&]() {
7539 BitcodeReader::decodeSignRotatedValue(
Record.front()));
7542 BitcodeReader::decodeSignRotatedValue(
Record.front()));
7550 std::vector<FunctionSummary::ParamAccess> PendingParamAccesses;
7552 PendingParamAccesses.emplace_back();
7556 ParamAccess.
Use = ReadRange();
7559for (
auto &Call : ParamAccess.
Calls) {
7562Call.Callee = std::get<0>(getValueInfoFromValueId(
Record.front()));
7564Call.Offsets = ReadRange();
7567return PendingParamAccesses;
7570void ModuleSummaryIndexBitcodeReader::parseTypeIdCompatibleVtableInfo(
7578void ModuleSummaryIndexBitcodeReader::parseTypeIdCompatibleVtableSummaryRecord(
7584static_cast<size_t>(
Record[Slot + 1])});
7587while (Slot <
Record.size())
7588 parseTypeIdCompatibleVtableInfo(
Record, Slot, TypeId);
7594// For backwards compatibility with old format before radix tree was 7595// used, simply see if we found a radix tree array record (and thus if 7596// the RadixArray is non-empty). 7597if (RadixArray.empty()) {
7598unsigned NumStackEntries =
Record[
I++];
7600 StackIdList.
reserve(NumStackEntries);
7601for (
unsigned J = 0; J < NumStackEntries; J++) {
7607unsigned RadixIndex =
Record[
I++];
7608// See the comments above CallStackRadixTreeBuilder in ProfileData/MemProf.h 7609// for a detailed description of the radix tree array format. Briefly, the 7610// first entry will be the number of frames, any negative values are the 7611// negative of the offset of the next frame, and otherwise the frames are in 7612// increasing linear order. 7613assert(RadixIndex < RadixArray.size());
7614unsigned NumStackIds = RadixArray[RadixIndex++];
7615 StackIdList.
reserve(NumStackIds);
7616while (NumStackIds--) {
7617assert(RadixIndex < RadixArray.size());
7618unsigned Elem = RadixArray[RadixIndex];
7619if (
static_cast<std::make_signed_t<unsigned>
>(Elem) < 0) {
7620 RadixIndex = RadixIndex - Elem;
7621assert(RadixIndex < RadixArray.size());
7622 Elem = RadixArray[RadixIndex];
7623// We shouldn't encounter a second offset in a row. 7624assert(
static_cast<std::make_signed_t<unsigned>
>(Elem) >= 0);
7635// Readonly and writeonly refs are in the end of the refs list. 7637unsigned FirstWORef = Refs.
size() - WOCnt;
7638unsigned RefNo = FirstWORef - ROCnt;
7639for (; RefNo < FirstWORef; ++RefNo)
7640 Refs[RefNo].setReadOnly();
7641for (; RefNo < Refs.
size(); ++RefNo)
7642 Refs[RefNo].setWriteOnly();
7645// Eagerly parse the entire summary block. This populates the GlobalValueSummary 7646// objects in the index. 7647Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(
unsignedID) {
7648if (
Error Err = Stream.EnterSubBlock(
ID))
7660returnerror(
"Invalid Summary Block: record for version expected");
7665returnerror(
"Invalid Summary Block: version expected");
7668constbool IsOldProfileFormat =
Version == 1;
7670returnerror(
"Invalid summary version " +
Twine(Version) +
7671". Version should be in the range [1-" +
7676// Keep around the last seen summary to be used when we see an optional 7677// "OriginalName" attachement. 7681// We can expect to see any number of type ID information records before 7682// each function summary records; these variables store the information 7683// collected so far so that it can be used to create the summary object. 7684 std::vector<GlobalValue::GUID> PendingTypeTests;
7685 std::vector<FunctionSummary::VFuncId> PendingTypeTestAssumeVCalls,
7686 PendingTypeCheckedLoadVCalls;
7687 std::vector<FunctionSummary::ConstVCall> PendingTypeTestAssumeConstVCalls,
7688 PendingTypeCheckedLoadConstVCalls;
7689 std::vector<FunctionSummary::ParamAccess> PendingParamAccesses;
7691 std::vector<CallsiteInfo> PendingCallsites;
7692 std::vector<AllocInfo> PendingAllocs;
7693 std::vector<uint64_t> PendingContextIds;
7701switch (
Entry.Kind) {
7704returnerror(
"Malformed block");
7708// The interesting case. 7712// Read a record. The record format depends on whether this 7713// is a per-module index or a combined index file. In the per-module 7714// case the records contain the associated value's ID for correlation 7715// with VST entries. In the combined index the correlation is done 7716// via the bitcode offset of the summary records (which were saved 7717// in the combined index VST entries). The records also contain 7718// information used for ThinLTO renaming and importing. 7723switch (
unsigned BitCode = MaybeBitCode.
get()) {
7724default:
// Default behavior: ignore. 7738 ValueIdToValueInfoMap[ValueID] =
7742// FS_PERMODULE is legacy and does not have support for the tail call flag. 7743// FS_PERMODULE: [valueid, flags, instcount, fflags, numrefs, 7744// numrefs x valueid, n x (valueid)] 7745// FS_PERMODULE_PROFILE: [valueid, flags, instcount, fflags, numrefs, 7746// numrefs x valueid, 7747// n x (valueid, hotness+tailcall flags)] 7748// FS_PERMODULE_RELBF: [valueid, flags, instcount, fflags, numrefs, 7749// numrefs x valueid, 7750// n x (valueid, relblockfreq+tailcall)] 7754unsigned ValueID =
Record[0];
7756unsigned InstCount =
Record[2];
7758unsigned NumRefs =
Record[3];
7759unsigned NumRORefs = 0, NumWORefs = 0;
7760int RefListStartIndex = 4;
7764 RefListStartIndex = 5;
7767 RefListStartIndex = 6;
7770 RefListStartIndex = 7;
7776// The module path string ref set in the summary must be owned by the 7777// index's module string table. Since we don't have a module path 7778// string table section in the per-module index, we create a single 7779// module path string table entry with an empty (0) ID to take 7781int CallGraphEdgeStartIndex = RefListStartIndex + NumRefs;
7783"Record size inconsistent with number of references");
7790 IsOldProfileFormat, HasProfile, HasRelBF);
7792auto VIAndOriginalGUID = getValueInfoFromValueId(ValueID);
7793// In order to save memory, only record the memprof summaries if this is 7794// the prevailing copy of a symbol. The linker doesn't resolve local 7795// linkage values so don't check whether those are prevailing. 7798 !IsPrevailing(VIAndOriginalGUID.first.getGUID())) {
7799 PendingCallsites.clear();
7800 PendingAllocs.clear();
7802autoFS = std::make_unique<FunctionSummary>(
7804 std::move(Calls), std::move(PendingTypeTests),
7805 std::move(PendingTypeTestAssumeVCalls),
7806 std::move(PendingTypeCheckedLoadVCalls),
7807 std::move(PendingTypeTestAssumeConstVCalls),
7808 std::move(PendingTypeCheckedLoadConstVCalls),
7809 std::move(PendingParamAccesses), std::move(PendingCallsites),
7810 std::move(PendingAllocs));
7811FS->setModulePath(getThisModule()->first());
7812FS->setOriginalName(std::get<1>(VIAndOriginalGUID));
7817// FS_ALIAS: [valueid, flags, valueid] 7818// Aliases must be emitted (and parsed) after all FS_PERMODULE entries, as 7819// they expect all aliasee summaries to be available. 7821unsigned ValueID =
Record[0];
7823unsigned AliaseeID =
Record[2];
7825auto AS = std::make_unique<AliasSummary>(Flags);
7826// The module path string ref set in the summary must be owned by the 7827// index's module string table. Since we don't have a module path 7828// string table section in the per-module index, we create a single 7829// module path string table entry with an empty (0) ID to take 7831 AS->setModulePath(getThisModule()->first());
7833auto AliaseeVI = std::get<0>(getValueInfoFromValueId(AliaseeID));
7835if (!AliaseeInModule)
7836returnerror(
"Alias expects aliasee summary to be parsed");
7837 AS->setAliasee(AliaseeVI, AliaseeInModule);
7839autoGUID = getValueInfoFromValueId(ValueID);
7840 AS->setOriginalName(std::get<1>(GUID));
7844// FS_PERMODULE_GLOBALVAR_INIT_REFS: [valueid, flags, varflags, n x valueid] 7846unsigned ValueID =
Record[0];
7848unsigned RefArrayStart = 2;
7850/* WriteOnly */false,
7861 std::make_unique<GlobalVarSummary>(Flags, GVF, std::move(Refs));
7862FS->setModulePath(getThisModule()->first());
7863autoGUID = getValueInfoFromValueId(ValueID);
7864FS->setOriginalName(std::get<1>(GUID));
7868// FS_PERMODULE_VTABLE_GLOBALVAR_INIT_REFS: [valueid, flags, varflags, 7869// numrefs, numrefs x valueid, 7870// n x (valueid, offset)] 7872unsigned ValueID =
Record[0];
7875unsigned NumRefs =
Record[3];
7876unsigned RefListStartIndex = 4;
7877unsigned VTableListStartIndex = RefListStartIndex + NumRefs;
7882for (
unsignedI = VTableListStartIndex, E =
Record.size();
I != E; ++
I) {
7888 std::make_unique<GlobalVarSummary>(Flags, GVF, std::move(Refs));
7889VS->setModulePath(getThisModule()->first());
7890VS->setVTableFuncs(VTableFuncs);
7891autoGUID = getValueInfoFromValueId(ValueID);
7892VS->setOriginalName(std::get<1>(GUID));
7896// FS_COMBINED is legacy and does not have support for the tail call flag. 7897// FS_COMBINED: [valueid, modid, flags, instcount, fflags, numrefs, 7898// numrefs x valueid, n x (valueid)] 7899// FS_COMBINED_PROFILE: [valueid, modid, flags, instcount, fflags, numrefs, 7900// numrefs x valueid, 7901// n x (valueid, hotness+tailcall flags)] 7904unsigned ValueID =
Record[0];
7907unsigned InstCount =
Record[3];
7909unsigned NumRefs =
Record[4];
7910unsigned NumRORefs = 0, NumWORefs = 0;
7911int RefListStartIndex = 5;
7915 RefListStartIndex = 6;
7916size_t NumRefsIndex = 5;
7918unsigned NumRORefsOffset = 1;
7919 RefListStartIndex = 7;
7922 RefListStartIndex = 8;
7924 RefListStartIndex = 9;
7926 NumRORefsOffset = 2;
7929 NumRORefs =
Record[RefListStartIndex - NumRORefsOffset];
7931 NumRefs =
Record[NumRefsIndex];
7935int CallGraphEdgeStartIndex = RefListStartIndex + NumRefs;
7937"Record size inconsistent with number of references");
7943 IsOldProfileFormat, HasProfile,
false);
7944ValueInfoVI = std::get<0>(getValueInfoFromValueId(ValueID));
7946autoFS = std::make_unique<FunctionSummary>(
7948 std::move(Edges), std::move(PendingTypeTests),
7949 std::move(PendingTypeTestAssumeVCalls),
7950 std::move(PendingTypeCheckedLoadVCalls),
7951 std::move(PendingTypeTestAssumeConstVCalls),
7952 std::move(PendingTypeCheckedLoadConstVCalls),
7953 std::move(PendingParamAccesses), std::move(PendingCallsites),
7954 std::move(PendingAllocs));
7955 LastSeenSummary =
FS.get();
7956 LastSeenGUID =
VI.getGUID();
7957FS->setModulePath(ModuleIdMap[ModuleId]);
7961// FS_COMBINED_ALIAS: [valueid, modid, flags, valueid] 7962// Aliases must be emitted (and parsed) after all FS_COMBINED entries, as 7963// they expect all aliasee summaries to be available. 7965unsigned ValueID =
Record[0];
7968unsigned AliaseeValueId =
Record[3];
7970auto AS = std::make_unique<AliasSummary>(Flags);
7971 LastSeenSummary = AS.get();
7972 AS->setModulePath(ModuleIdMap[ModuleId]);
7974auto AliaseeVI = std::get<0>(getValueInfoFromValueId(AliaseeValueId));
7976 AS->setAliasee(AliaseeVI, AliaseeInModule);
7978ValueInfoVI = std::get<0>(getValueInfoFromValueId(ValueID));
7979 LastSeenGUID =
VI.getGUID();
7983// FS_COMBINED_GLOBALVAR_INIT_REFS: [valueid, modid, flags, n x valueid] 7985unsigned ValueID =
Record[0];
7988unsigned RefArrayStart = 3;
7990/* WriteOnly */false,
8001 std::make_unique<GlobalVarSummary>(Flags, GVF, std::move(Refs));
8002 LastSeenSummary =
FS.get();
8003FS->setModulePath(ModuleIdMap[ModuleId]);
8004ValueInfoVI = std::get<0>(getValueInfoFromValueId(ValueID));
8005 LastSeenGUID =
VI.getGUID();
8009// FS_COMBINED_ORIGINAL_NAME: [original_name] 8012if (!LastSeenSummary)
8013returnerror(
"Name attachment that does not follow a combined record");
8016// Reset the LastSeenSummary 8017 LastSeenSummary =
nullptr;
8022assert(PendingTypeTests.empty());
8027assert(PendingTypeTestAssumeVCalls.empty());
8028for (
unsignedI = 0;
I !=
Record.size();
I += 2)
8029 PendingTypeTestAssumeVCalls.push_back({Record[I], Record[I+1]});
8033assert(PendingTypeCheckedLoadVCalls.empty());
8034for (
unsignedI = 0;
I !=
Record.size();
I += 2)
8035 PendingTypeCheckedLoadVCalls.push_back({Record[I], Record[I+1]});
8039 PendingTypeTestAssumeConstVCalls.push_back(
8044 PendingTypeCheckedLoadConstVCalls.push_back(
8049 std::set<std::string, std::less<>> &CfiFunctionDefs =
8051for (
unsignedI = 0;
I !=
Record.size();
I += 2)
8052 CfiFunctionDefs.insert(
8053 {Strtab.data() + Record[I], static_cast<size_t>(Record[I + 1])});
8058 std::set<std::string, std::less<>> &CfiFunctionDecls =
8060for (
unsignedI = 0;
I !=
Record.size();
I += 2)
8061 CfiFunctionDecls.insert(
8062 {Strtab.data() + Record[I], static_cast<size_t>(Record[I + 1])});
8071 parseTypeIdCompatibleVtableSummaryRecord(
Record);
8079 PendingParamAccesses = parseParamAccesses(
Record);
8084// Save stack ids in the reader to consult when adding stack ids from the 8085// lists in the stack node and alloc node entries. 8090// This is an array of 32-bit fixed-width values, holding each 64-bit 8091// context id as a pair of adjacent (most significant first) 32-bit words. 8093 StackIds.reserve(
Record.size() / 2);
8095 StackIds.push_back(*R << 32 | *(R + 1));
8105unsigned ValueID =
Record[0];
8107for (
auto R =
Record.begin() + 1; R !=
Record.end(); R++) {
8108assert(*R < StackIds.size());
8111ValueInfoVI = std::get<0>(getValueInfoFromValueId(ValueID));
8112 PendingCallsites.push_back(
CallsiteInfo({
VI, std::move(StackIdList)}));
8117auto RecordIter =
Record.begin();
8118unsigned ValueID = *RecordIter++;
8119unsigned NumStackIds = *RecordIter++;
8120unsigned NumVersions = *RecordIter++;
8123for (
unsigned J = 0; J < NumStackIds; J++) {
8124assert(*RecordIter < StackIds.size());
8129for (
unsigned J = 0; J < NumVersions; J++)
8132 getValueInfoFromValueId</*AllowNullValueInfo*/ true>(ValueID));
8133 PendingCallsites.push_back(
8139// This is an array of 32-bit fixed-width values, holding each 64-bit 8140// context id as a pair of adjacent (most significant first) 32-bit words. 8142 PendingContextIds.reserve(
Record.size() / 2);
8144 PendingContextIds.push_back(*R << 32 | *(R + 1));
8150 std::vector<MIBInfo> MIBs;
8151unsigned NumMIBs = 0;
8154unsigned MIBsRead = 0;
8155while ((Version >= 10 && MIBsRead++ < NumMIBs) ||
8156 (Version < 10 &&
I <
Record.size())) {
8159auto StackIdList = parseAllocInfoContext(
Record,
I);
8162// We either have nothing left or at least NumMIBs context size info 8163// indices left (for the total sizes included when reporting of hinted 8164// bytes is enabled). 8166 std::vector<std::vector<ContextTotalSize>> AllContextSizes;
8168assert(!PendingContextIds.empty() &&
8169"Missing context ids for alloc sizes");
8170unsigned ContextIdIndex = 0;
8172// The sizes are a linearized array of sizes, where for each MIB there 8173// is 1 or more sizes (due to context trimming, each MIB in the metadata 8174// and summarized here can correspond to more than one original context 8175// from the profile). 8176while (MIBsRead++ < NumMIBs) {
8177// First read the number of contexts recorded for this MIB. 8178unsigned NumContextSizeInfoEntries =
Record[
I++];
8180 std::vector<ContextTotalSize> ContextSizes;
8181 ContextSizes.reserve(NumContextSizeInfoEntries);
8182for (
unsigned J = 0; J < NumContextSizeInfoEntries; J++) {
8183assert(ContextIdIndex < PendingContextIds.size());
8184// PendingContextIds read from the preceding FS_ALLOC_CONTEXT_IDS 8185// should be in the same order as the total sizes. 8186 ContextSizes.push_back(
8187 {PendingContextIds[ContextIdIndex++],
Record[
I++]});
8189 AllContextSizes.push_back(std::move(ContextSizes));
8191 PendingContextIds.clear();
8193 PendingAllocs.push_back(
AllocInfo(std::move(MIBs)));
8194if (!AllContextSizes.empty()) {
8195assert(PendingAllocs.back().MIBs.size() == AllContextSizes.size());
8196 PendingAllocs.back().ContextSizeInfos = std::move(AllContextSizes);
8203 std::vector<MIBInfo> MIBs;
8205unsigned NumVersions =
Record[
I++];
8206unsigned MIBsRead = 0;
8207while (MIBsRead++ < NumMIBs) {
8210auto StackIdList = parseAllocInfoContext(
Record,
I);
8215for (
unsigned J = 0; J < NumVersions; J++)
8218 PendingAllocs.push_back(
AllocInfo(std::move(Versions), std::move(MIBs)));
8226// Parse the module string table block into the Index. 8227// This populates the ModulePathStringTable map in the index. 8228Error ModuleSummaryIndexBitcodeReader::parseModuleStringTable() {
8243switch (
Entry.Kind) {
8246returnerror(
"Malformed block");
8250// The interesting case. 8258switch (MaybeRecord.
get()) {
8259default:
// Default behavior: ignore. 8262// MST_ENTRY: [modid, namechar x N] 8266returnerror(
"Invalid record");
8268 LastSeenModule = TheIndex.
addModule(ModulePath);
8269 ModuleIdMap[ModuleId] = LastSeenModule->
first();
8274 /// MST_CODE_HASH: [5*i32] 8279returnerror(
"Invalid hash that does not follow a module path");
8282assert(!(Val >> 32) &&
"Unexpected high bits set");
8283 LastSeenModule->
second[Pos++] = Val;
8285// Reset LastSeenModule to avoid overriding the hash unexpectedly. 8286 LastSeenModule =
nullptr;
8296// FIXME: This class is only here to support the transition to llvm::Error. It 8297// will be removed once this transition is complete. Clients should prefer to 8298// deal with the Error value directly, rather than converting to error_code. 8299classBitcodeErrorCategoryType :
public std::error_category {
8300constchar *
name()
const noexcept
override{
8301return"llvm.bitcode";
8304 std::string message(
int IE)
const override{
8307case BitcodeError::CorruptedBitcode:
8308return"Corrupted bitcode";
8314}
// end anonymous namespace 8317static BitcodeErrorCategoryType ErrorCategory;
8318return ErrorCategory;
8322unsignedBlock,
unsigned RecordID) {
8324return std::move(Err);
8333switch (Entry.Kind) {
8338returnerror(
"Malformed block");
8342return std::move(Err);
8352if (MaybeRecord.
get() == RecordID)
8359//===----------------------------------------------------------------------===// 8360// External interface 8361//===----------------------------------------------------------------------===// 8367return FOrErr.takeError();
8368return std::move(FOrErr->Mods);
8382// We may be consuming bitcode from a client that leaves garbage at the end 8383// of the bitcode stream (e.g. Apple's ar tool). If we are close enough to 8384// the end that there cannot possibly be another module, stop looking. 8393switch (Entry.Kind) {
8396returnerror(
"Malformed block");
8403return std::move(Err);
8409 Entry = MaybeEntry.
get();
8414returnerror(
"Malformed block");
8420return std::move(Err);
8434// This string table is used by every preceding bitcode module that does 8435// not have its own string table. A bitcode file may have multiple 8436// string tables if it was created by binary concatenation, for example 8437// with "llvm-cat -b". 8439if (!
I.Strtab.empty())
8443// Similarly, the string table is used by every preceding symbol table; 8444// normally there will be just one unless the bitcode file was created 8445// by binary concatenation. 8446if (!
F.Symtab.empty() &&
F.StrtabForSymtab.empty())
8447F.StrtabForSymtab = *Strtab;
8457// We can expect the bitcode file to have multiple symbol tables if it 8458// was created by binary concatenation. In that case we silently 8459// ignore any subsequent symbol tables, which is fine because this is a 8460// low level function. The client is expected to notice that the number 8461// of modules in the symbol table does not match the number of modules 8462// in the input file and regenerate the symbol table. 8463if (
F.Symtab.empty())
8464F.Symtab = *SymtabOrErr;
8469return std::move(Err);
8480/// Get a lazy one-at-time loading module from bitcode. 8482/// This isn't always used in a lazy context. In particular, it's also used by 8483/// \a parseModule(). If this is truly lazy, then we need to eagerly pull 8484/// in forward-referenced functions from block address references. 8486/// \param[in] MaterializeAll Set to \c true if we should materialize 8489BitcodeModule::getModuleImpl(
LLVMContext &Context,
bool MaterializeAll,
8490bool ShouldLazyLoadMetadata,
bool IsImporting,
8494 std::string ProducerIdentification;
8495if (IdentificationBit != -1ull) {
8496if (
Error JumpFailed = Stream.JumpToBit(IdentificationBit))
8497return std::move(JumpFailed);
8503if (
Error JumpFailed = Stream.JumpToBit(ModuleBit))
8504return std::move(JumpFailed);
8505auto *
R =
new BitcodeReader(std::move(Stream), Strtab, ProducerIdentification,
8508 std::unique_ptr<Module>
M =
8509 std::make_unique<Module>(ModuleIdentifier, Context);
8510M->setMaterializer(R);
8512// Delay parsing Metadata if ShouldLazyLoadMetadata is true. 8513if (
Error Err =
R->parseBitcodeInto(
M.get(), ShouldLazyLoadMetadata,
8514 IsImporting, Callbacks))
8515return std::move(Err);
8517if (MaterializeAll) {
8518// Read in the entire module, and destroy the BitcodeReader. 8519if (
Error Err =
M->materializeAll())
8520return std::move(Err);
8522// Resolve forward references from blockaddresses. 8523if (
Error Err =
R->materializeForwardReferencedFunctions())
8524return std::move(Err);
8533return getModuleImpl(Context,
false, ShouldLazyLoadMetadata, IsImporting,
8537// Parse the specified bitcode buffer and merge the index into CombinedIndex. 8538// We don't use ModuleIdentifier here because the client may need to control the 8539// module path used in the combined summary (e.g. when reading summaries for 8540// regular LTO modules). 8548 ModuleSummaryIndexBitcodeReader R(std::move(Stream), Strtab, CombinedIndex,
8549 ModulePath, IsPrevailing);
8550return R.parseModule();
8553// Parse the specified bitcode buffer, returning the function info index. 8557return std::move(JumpFailed);
8559auto Index = std::make_unique<ModuleSummaryIndex>(
/*HaveGVs=*/false);
8560 ModuleSummaryIndexBitcodeReader R(std::move(Stream), Strtab, *Index,
8561 ModuleIdentifier, 0);
8563if (
Error Err = R.parseModule())
8564return std::move(Err);
8566return std::move(Index);
8574return std::move(Err);
8579 std::pair<bool, bool> Result = {
false,
false};
8583switch (Entry.Kind) {
8586returnerror(
"Malformed block");
8588// If no flags record found, set both flags to false. 8592// The interesting case. 8596// Look for the FS_FLAGS record. 8601switch (MaybeBitCode.
get()) {
8602default:
// Default behavior: ignore. 8607assert(Flags <= 0x2ff &&
"Unexpected bits in flag");
8609bool EnableSplitLTOUnit = Flags & 0x8;
8610bool UnifiedLTO = Flags & 0x200;
8611 Result = {EnableSplitLTOUnit, UnifiedLTO};
8620// Check if the given bitcode buffer contains a global value summary block. 8624return std::move(JumpFailed);
8627return std::move(Err);
8634switch (Entry.Kind) {
8636returnerror(
"Malformed block");
8639/*EnableSplitLTOUnit=*/false,
/*UnifiedLTO=*/false};
8647return Flags.takeError();
8659return Flags.takeError();
8666// Ignore other sub-blocks. 8668return std::move(Err);
8675return StreamFailed.takeError();
8685if (MsOrErr->size() != 1)
8686returnerror(
"Expected a single module");
8688return (*MsOrErr)[0];
8693bool ShouldLazyLoadMetadata,
bool IsImporting,
8699return BM->getLazyModule(Context, ShouldLazyLoadMetadata, IsImporting,
8704 std::unique_ptr<MemoryBuffer> &&Buffer,
LLVMContext &Context,
8705bool ShouldLazyLoadMetadata,
bool IsImporting,
ParserCallbacks Callbacks) {
8707 IsImporting, Callbacks);
8709 (*MOrErr)->setOwnedMemoryBuffer(std::move(Buffer));
8715return getModuleImpl(Context,
true,
false,
false, Callbacks);
8716// TODO: Restore the use-lists to the in-memory state when the bitcode was 8717// written. We must defer until the Module has been fully materialized. 8727return BM->parseModule(Context, Callbacks);
8760return BM->readSummary(CombinedIndex, BM->getModuleIdentifier());
8769return BM->getSummary();
8777return BM->getLTOInfo();
8782bool IgnoreEmptyThinLTOIndexFile) {
8787if (IgnoreEmptyThinLTOIndexFile && !(*FileOrErr)->getBufferSize())
static bool isConstant(const MachineInstr &MI)
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Expand Atomic instructions
Atomic ordering constants.
This file contains the simple types necessary to represent the attributes associated with functions a...
static void getDecodedRelBFCallEdgeInfo(uint64_t RawFlags, uint64_t &RelBF, bool &HasTailCall)
static void upgradeDLLImportExportLinkage(GlobalValue *GV, unsigned Val)
static cl::opt< bool > PrintSummaryGUIDs("print-summary-global-ids", cl::init(false), cl::Hidden, cl::desc("Print the global id for each value when reading the module summary"))
static AtomicOrdering getDecodedOrdering(unsigned Val)
static std::pair< CalleeInfo::HotnessType, bool > getDecodedHotnessCallEdgeInfo(uint64_t RawFlags)
static FunctionSummary::FFlags getDecodedFFlags(uint64_t RawFlags)
static std::optional< CodeModel::Model > getDecodedCodeModel(unsigned Val)
static void setSpecialRefs(SmallVectorImpl< ValueInfo > &Refs, unsigned ROCnt, unsigned WOCnt)
cl::opt< cl::boolOrDefault > PreserveInputDbgFormat
static bool getDecodedDSOLocal(unsigned Val)
static bool convertToString(ArrayRef< uint64_t > Record, unsigned Idx, StrTy &Result)
Convert a string from a record into an std::string, return true on failure.
static GlobalVariable::UnnamedAddr getDecodedUnnamedAddrType(unsigned Val)
static void stripTBAA(Module *M)
static Expected< std::pair< bool, bool > > getEnableSplitLTOUnitAndUnifiedFlag(BitstreamCursor &Stream, unsigned ID, BitcodeLTOInfo <OInfo)
static int getDecodedUnaryOpcode(unsigned Val, Type *Ty)
static Expected< std::string > readTriple(BitstreamCursor &Stream)
static void parseWholeProgramDevirtResolutionByArg(ArrayRef< uint64_t > Record, size_t &Slot, WholeProgramDevirtResolution &Wpd)
static uint64_t getRawAttributeMask(Attribute::AttrKind Val)
static GlobalValueSummary::GVFlags getDecodedGVSummaryFlags(uint64_t RawFlags, uint64_t Version)
static GlobalVarSummary::GVarFlags getDecodedGVarFlags(uint64_t RawFlags)
static Attribute::AttrKind getAttrFromCode(uint64_t Code)
static Expected< uint64_t > jumpToValueSymbolTable(uint64_t Offset, BitstreamCursor &Stream)
Helper to note and return the current location, and jump to the given offset.
static Expected< bool > hasObjCCategoryInModule(BitstreamCursor &Stream)
static GlobalValue::DLLStorageClassTypes getDecodedDLLStorageClass(unsigned Val)
static GEPNoWrapFlags toGEPNoWrapFlags(uint64_t Flags)
static void decodeLLVMAttributesForBitcode(AttrBuilder &B, uint64_t EncodedAttrs, uint64_t AttrIdx)
This fills an AttrBuilder object with the LLVM attributes that have been decoded from the given integ...
cl::opt< bool > WriteNewDbgInfoFormat
static void parseTypeIdSummaryRecord(ArrayRef< uint64_t > Record, StringRef Strtab, ModuleSummaryIndex &TheIndex)
cl::opt< cl::boolOrDefault > LoadBitcodeIntoNewDbgInfoFormat("load-bitcode-into-experimental-debuginfo-iterators", cl::Hidden, cl::desc("Load bitcode directly into the new debug info format (regardless " "of input format)"))
Load bitcode directly into RemoveDIs format (use debug records instead of debug intrinsics).
static void addRawAttributeValue(AttrBuilder &B, uint64_t Val)
bool WriteNewDbgInfoFormatToBitcode
static Comdat::SelectionKind getDecodedComdatSelectionKind(unsigned Val)
static bool hasImplicitComdat(size_t Val)
static GlobalValue::LinkageTypes getDecodedLinkage(unsigned Val)
static Error hasInvalidBitcodeHeader(BitstreamCursor &Stream)
static Expected< std::string > readIdentificationCode(BitstreamCursor &Stream)
static int getDecodedBinaryOpcode(unsigned Val, Type *Ty)
static AtomicRMWInst::BinOp getDecodedRMWOperation(unsigned Val)
static Expected< BitcodeModule > getSingleModule(MemoryBufferRef Buffer)
static Expected< bool > hasObjCCategory(BitstreamCursor &Stream)
static GlobalVariable::ThreadLocalMode getDecodedThreadLocalMode(unsigned Val)
static void parseWholeProgramDevirtResolution(ArrayRef< uint64_t > Record, StringRef Strtab, size_t &Slot, TypeIdSummary &TypeId)
static void inferDSOLocal(GlobalValue *GV)
static FastMathFlags getDecodedFastMathFlags(unsigned Val)
GlobalValue::SanitizerMetadata deserializeSanitizerMetadata(unsigned V)
static Expected< BitstreamCursor > initStream(MemoryBufferRef Buffer)
static cl::opt< bool > ExpandConstantExprs("expand-constant-exprs", cl::Hidden, cl::desc("Expand constant expressions to instructions for testing purposes"))
static bool upgradeOldMemoryAttribute(MemoryEffects &ME, uint64_t EncodedKind)
static Expected< StringRef > readBlobInRecord(BitstreamCursor &Stream, unsigned Block, unsigned RecordID)
static Expected< std::string > readIdentificationBlock(BitstreamCursor &Stream)
Read the "IDENTIFICATION_BLOCK_ID" block, do some basic enforcement on the "epoch" encoded in the bit...
static bool isConstExprSupported(const BitcodeConstant *BC)
static int getDecodedCastOpcode(unsigned Val)
cl::opt< bool > UseNewDbgInfoFormat
static Expected< std::string > readModuleTriple(BitstreamCursor &Stream)
static GlobalValue::VisibilityTypes getDecodedVisibility(unsigned Val)
BlockVerifier::State From
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
Analysis containing CSE Info
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static StringRef getOpcodeName(uint8_t Opcode, uint8_t OpcodeBase)
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
Looks at all the uses of the given value Returns the Liveness deduced from the uses of this value Adds all uses that cause the result to be MaybeLive to MaybeLiveRetUses If the result is Live
This file defines the DenseMap class.
Provides ErrorOr<T> smart pointer.
This file contains the declaration of the GlobalIFunc class, which represents a single indirect funct...
Module.h This file contains the declarations for the Module class.
This file contains the declarations for metadata subclasses.
static bool InRange(int64_t Value, unsigned short Shift, int LBound, int HBound)
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
PowerPC Reduce CR logical Operation
This file contains the declarations for profiling metadata utility functions.
const SmallVectorImpl< MachineOperand > & Cond
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file contains some templates that are useful if you are working with the STL at all.
static uint64_t decodeSignRotatedValue(uint64_t V)
Decode a signed value stored with the sign bit in the LSB for dense VBR encoding.
This file defines the SmallString class.
This file defines the SmallVector class.
Class for arbitrary precision integers.
an instruction to allocate memory on the stack
void setSwiftError(bool V)
Specify whether this alloca is used to represent a swifterror.
PointerType * getType() const
Overload to return most specific pointer type.
void setUsedWithInAlloca(bool V)
Specify whether this alloca is used to represent the arguments to a call.
This class represents an incoming formal argument to a Function.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
An instruction that atomically checks whether a specified value is in a memory location,...
static bool isValidFailureOrdering(AtomicOrdering Ordering)
static AtomicOrdering getStrongestFailureOrdering(AtomicOrdering SuccessOrdering)
Returns the strongest permitted ordering on failure, given the desired ordering on success.
static bool isValidSuccessOrdering(AtomicOrdering Ordering)
an instruction that atomically reads a memory location, combines it with another value,...
BinOp
This enumeration lists the possible modifications atomicrmw can make.
@ USubCond
Subtract only if no unsigned overflow.
@ Min
*p = old <signed v ? old : v
@ USubSat
*p = usub.sat(old, v) usub.sat matches the behavior of llvm.usub.sat.
@ UIncWrap
Increment one up to a maximum value.
@ Max
*p = old >signed v ? old : v
@ UMin
*p = old <unsigned v ? old : v
@ FMin
*p = minnum(old, v) minnum matches the behavior of llvm.minnum.
@ UMax
*p = old >unsigned v ? old : v
@ FMax
*p = maxnum(old, v) maxnum matches the behavior of llvm.maxnum.
@ UDecWrap
Decrement one until a minimum value or zero.
AttributeSet getFnAttrs() const
The function attributes are returned.
static AttributeList get(LLVMContext &C, ArrayRef< std::pair< unsigned, Attribute > > Attrs)
Create an AttributeList with the specified parameters in it.
static Attribute getWithStructRetType(LLVMContext &Context, Type *Ty)
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
static bool isTypeAttrKind(AttrKind Kind)
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
@ TombstoneKey
Use as Tombstone key for DenseMap of AttrKind.
@ None
No attributes have been set.
@ EmptyKey
Use as Empty key for DenseMap of AttrKind.
@ EndAttrKinds
Sentinel value useful for loops.
static bool isConstantRangeAttrKind(AttrKind Kind)
static Attribute getWithInAllocaType(LLVMContext &Context, Type *Ty)
static bool isIntAttrKind(AttrKind Kind)
static bool isConstantRangeListAttrKind(AttrKind Kind)
static Attribute getWithByValType(LLVMContext &Context, Type *Ty)
static bool isEnumAttrKind(AttrKind Kind)
LLVM Basic Block Representation.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
void replacePhiUsesWith(BasicBlock *Old, BasicBlock *New)
Update all phi nodes in this basic block to refer to basic block New instead of basic block Old.
SymbolTableList< BasicBlock >::iterator eraseFromParent()
Unlink 'this' from the containing function and delete it.
void moveBefore(BasicBlock *MovePos)
Unlink this basic block from its current function and insert it into the function that MovePos lives ...
const Instruction & back() const
static BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name=Twine(), InsertPosition InsertBefore=nullptr)
Construct a binary instruction, given the opcode and the two operands.
Represents a module in a bitcode file.
Expected< std::unique_ptr< ModuleSummaryIndex > > getSummary()
Parse the specified bitcode buffer, returning the module summary index.
Expected< BitcodeLTOInfo > getLTOInfo()
Returns information about the module to be used for LTO: whether to compile with ThinLTO,...
Error readSummary(ModuleSummaryIndex &CombinedIndex, StringRef ModulePath, std::function< bool(GlobalValue::GUID)> IsPrevailing=nullptr)
Parse the specified bitcode buffer and merge its module summary index into CombinedIndex.
Expected< std::unique_ptr< Module > > parseModule(LLVMContext &Context, ParserCallbacks Callbacks={})
Read the entire bitcode module and return it.
Expected< std::unique_ptr< Module > > getLazyModule(LLVMContext &Context, bool ShouldLazyLoadMetadata, bool IsImporting, ParserCallbacks Callbacks={})
Read the bitcode module and prepare for lazy deserialization of function bodies.
Value * getValueFwdRef(unsigned Idx, Type *Ty, unsigned TyID, BasicBlock *ConstExprInsertBB)
void push_back(Value *V, unsigned TypeID)
void replaceValueWithoutRAUW(unsigned ValNo, Value *NewV)
Error assignValue(unsigned Idx, Value *V, unsigned TypeID)
void shrinkTo(unsigned N)
unsigned getTypeID(unsigned ValNo) const
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.
ArrayRef< uint8_t > getBitcodeBytes() const
Expected< word_t > Read(unsigned NumBits)
Expected< BitstreamEntry > advance(unsigned Flags=0)
Advance the current bitstream, returning the next entry in the stream.
Expected< BitstreamEntry > advanceSkippingSubblocks(unsigned Flags=0)
This is a convenience function for clients that don't expect any subblocks.
void setBlockInfo(BitstreamBlockInfo *BI)
Set the block info to be used by this BitstreamCursor to interpret abbreviated records.
Expected< unsigned > readRecord(unsigned AbbrevID, SmallVectorImpl< uint64_t > &Vals, StringRef *Blob=nullptr)
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.
Expected< unsigned > skipRecord(unsigned AbbrevID)
Read the current record and discard it, returning the code for the record.
uint64_t getCurrentByteNo() const
bool canSkipToPos(size_t pos) const
static BlockAddress * get(Function *F, BasicBlock *BB)
Return a BlockAddress for the specified function and basic block.
Conditional or Unconditional Branch instruction.
static BranchInst * Create(BasicBlock *IfTrue, InsertPosition InsertBefore=nullptr)
Allocate memory in an ever growing pool, as if by bump-pointer.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
bool isInlineAsm() const
Check if this call is an inline asm statement.
Value * getCalledOperand() const
void setAttributes(AttributeList A)
Set the attributes for this call.
Intrinsic::ID getIntrinsicID() const
Returns the intrinsic ID of the intrinsic called or Intrinsic::not_intrinsic if the called function i...
unsigned arg_size() const
AttributeList getAttributes() const
Return the attributes for this call.
static CallBrInst * Create(FunctionType *Ty, Value *Func, BasicBlock *DefaultDest, ArrayRef< BasicBlock * > IndirectDests, ArrayRef< Value * > Args, const Twine &NameStr, InsertPosition InsertBefore=nullptr)
This class represents a function call, abstracting a target machine's calling convention.
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static CaptureInfo createFromIntValue(uint32_t Data)
static CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
static bool castIsValid(Instruction::CastOps op, Type *SrcTy, Type *DstTy)
This method can be used to determine if a cast from SrcTy to DstTy using Opcode op is valid or not.
static CatchPadInst * Create(Value *CatchSwitch, ArrayRef< Value * > Args, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static CatchReturnInst * Create(Value *CatchPad, BasicBlock *BB, InsertPosition InsertBefore=nullptr)
static CatchSwitchInst * Create(Value *ParentPad, BasicBlock *UnwindDest, unsigned NumHandlers, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static CleanupPadInst * Create(Value *ParentPad, ArrayRef< Value * > Args={}, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static CleanupReturnInst * Create(Value *CleanupPad, BasicBlock *UnwindBB=nullptr, InsertPosition InsertBefore=nullptr)
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
static CmpInst * Create(OtherOps Op, Predicate Pred, Value *S1, Value *S2, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Construct a compare instruction, given the opcode, the predicate and the two operands.
bool isFPPredicate() const
bool isIntPredicate() const
@ Largest
The linker will choose the largest COMDAT.
@ SameSize
The data referenced by the COMDAT must be the same size.
@ Any
The linker may choose any COMDAT.
@ NoDeduplicate
No deduplication is performed.
@ ExactMatch
The data referenced by the COMDAT must be the same.
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
static Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true)
This method constructs a CDS and initializes it with a text string.
static Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
static Constant * getFP(Type *ElementType, ArrayRef< uint16_t > Elts)
getFP() constructors - Return a constant of array type with a float element type taken from argument ...
static Constant * get(LLVMContext &Context, ArrayRef< uint8_t > Elts)
get() constructors - Return a constant with vector type with an element count and element type matchi...
static Constant * getFP(Type *ElementType, ArrayRef< uint16_t > Elts)
getFP() constructors - Return a constant of vector type with a float element type taken from argument...
static Constant * getExtractElement(Constant *Vec, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
static Constant * getInsertElement(Constant *Vec, Constant *Elt, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
static Constant * getShuffleVector(Constant *V1, Constant *V2, ArrayRef< int > Mask, Type *OnlyIfReducedTy=nullptr)
static bool isSupportedGetElementPtr(const Type *SrcElemTy)
Whether creating a constant expression for this getelementptr type is supported.
static Constant * get(unsigned Opcode, Constant *C1, Constant *C2, unsigned Flags=0, Type *OnlyIfReducedTy=nullptr)
get - Return a binary or shift operator constant expression, folding if possible.
static bool isSupportedBinOp(unsigned Opcode)
Whether creating a constant expression for this binary operator is supported.
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList, GEPNoWrapFlags NW=GEPNoWrapFlags::none(), std::optional< ConstantRange > InRange=std::nullopt, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
static bool isSupportedCastOp(unsigned Opcode)
Whether creating a constant expression for this cast is supported.
This is the shared class of boolean and integer constants.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
static ConstantPtrAuth * get(Constant *Ptr, ConstantInt *Key, ConstantInt *Disc, Constant *AddrDisc)
Return a pointer signed with the specified parameters.
static bool isOrderedRanges(ArrayRef< ConstantRange > RangesRef)
This class represents a range of values.
bool isUpperSignWrapped() const
Return true if the (exclusive) upper bound wraps around the signed domain.
bool isFullSet() const
Return true if this set contains all of the elements possible for this data-type.
static Constant * get(StructType *T, ArrayRef< Constant * > V)
static Constant * get(ArrayRef< Constant * > V)
This is an important base class in LLVM.
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
static DSOLocalEquivalent * get(GlobalValue *GV)
Return a DSOLocalEquivalent for the specified global value.
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
static Expected< DataLayout > parse(StringRef LayoutString)
Parse a data layout string and return the layout.
Records a position in IR for a source label (DILabel).
Record of a variable value-assignment, aka a non instruction representation of the dbg....
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
iterator find(const_arg_type_t< KeyT > Val)
bool erase(const KeyT &Val)
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Implements a dense probed hash-table based set.
Base class for error info classes.
virtual std::string message() const
Return the error message as a string.
virtual std::error_code convertToErrorCode() const =0
Convert this error to a std::error_code.
Represents either an error or a value T.
std::error_code getError() const
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
reference get()
Returns a reference to the stored T value.
static ExtractElementInst * Create(Value *Vec, Value *Idx, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static ExtractValueInst * Create(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
This instruction compares its operands according to the predicate given to the constructor.
Convenience struct for specifying and reasoning about fast-math flags.
void setFast(bool B=true)
void setAllowContract(bool B=true)
void setAllowReciprocal(bool B=true)
void setNoSignedZeros(bool B=true)
void setNoNaNs(bool B=true)
void setAllowReassoc(bool B=true)
Flag setters.
void setApproxFunc(bool B=true)
void setNoInfs(bool B=true)
An instruction for ordering other memory operations.
static FixedVectorType * get(Type *ElementType, unsigned NumElts)
This class represents a freeze function that returns random concrete value if an operand is either a ...
std::pair< ValueInfo, CalleeInfo > EdgeTy
<CalleeValueInfo, CalleeInfo> call edge pair.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
BasicBlockListType::iterator iterator
const BasicBlock & back() const
Represents flags for the getelementptr instruction/expression.
static GEPNoWrapFlags inBounds()
static GEPNoWrapFlags noUnsignedWrap()
static GEPNoWrapFlags noUnsignedSignedWrap()
virtual void setStripDebugInfo()=0
virtual Error materializeModule()=0
Make sure the entire Module has been completely read.
virtual Error materializeMetadata()=0
virtual Error materialize(GlobalValue *GV)=0
Make sure the given GlobalValue is fully read.
virtual std::vector< StructType * > getIdentifiedStructTypes() const =0
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static GlobalAlias * create(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name, Constant *Aliasee, Module *Parent)
If a parent module is specified, the alias is automatically inserted into the end of the specified mo...
static GlobalIFunc * create(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name, Constant *Resolver, Module *Parent)
If a parent module is specified, the ifunc is automatically inserted into the end of the specified mo...
void setAlignment(Align Align)
Sets the alignment attribute of the GlobalObject.
void setComdat(Comdat *C)
void setSection(StringRef S)
Change the section for this global.
Function and variable summary information to aid decisions and implementation of importing.
void setOriginalName(GlobalValue::GUID Name)
Initialize the original name hash in this summary.
static bool isLocalLinkage(LinkageTypes Linkage)
void setUnnamedAddr(UnnamedAddr Val)
bool hasLocalLinkage() const
bool hasDefaultVisibility() const
void setDLLStorageClass(DLLStorageClassTypes C)
void setThreadLocalMode(ThreadLocalMode Val)
bool hasExternalWeakLinkage() const
DLLStorageClassTypes
Storage classes of global values for PE targets.
@ DLLExportStorageClass
Function to be accessible from DLL.
@ DLLImportStorageClass
Function to be imported from DLL.
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
void setDSOLocal(bool Local)
PointerType * getType() const
Global values are always pointers.
VisibilityTypes
An enumeration for the kinds of visibility of global values.
@ DefaultVisibility
The GV is visible.
@ HiddenVisibility
The GV is hidden.
@ ProtectedVisibility
The GV is protected.
void setVisibility(VisibilityTypes V)
void setSanitizerMetadata(SanitizerMetadata Meta)
std::string getGlobalIdentifier() const
Return the modified name for this global value suitable to be used as the key for a global lookup (e....
LinkageTypes
An enumeration for the kinds of linkage for global values.
@ PrivateLinkage
Like Internal, but omit from symbol table.
@ CommonLinkage
Tentative definitions.
@ InternalLinkage
Rename collisions when linking (static functions).
@ LinkOnceAnyLinkage
Keep one copy of function when linking (inline)
@ WeakODRLinkage
Same, but only replaced by something equivalent.
@ ExternalLinkage
Externally visible function.
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
@ AppendingLinkage
Special purpose, only applies to global arrays.
@ AvailableExternallyLinkage
Available for inspection, not emission.
@ ExternalWeakLinkage
ExternalWeak linkage description.
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
void setPartition(StringRef Part)
void setAttributes(AttributeSet A)
Set attribute list for this global.
void setCodeModel(CodeModel::Model CM)
Change the code model for this global.
This instruction compares its operands according to the predicate given to the constructor.
Indirect Branch Instruction.
void addDestination(BasicBlock *Dest)
Add a destination.
static IndirectBrInst * Create(Value *Address, unsigned NumDests, InsertPosition InsertBefore=nullptr)
unsigned getNumDestinations() const
return the number of possible destinations in this indirectbr instruction.
static InlineAsm * get(FunctionType *Ty, StringRef AsmString, StringRef Constraints, bool hasSideEffects, bool isAlignStack=false, AsmDialect asmDialect=AD_ATT, bool canThrow=false)
InlineAsm::get - Return the specified uniqued inline asm string.
std::vector< ConstraintInfo > ConstraintInfoVector
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static InsertValueInst * Create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
const char * getOpcodeName() const
InstListType::iterator insertInto(BasicBlock *ParentBB, InstListType::iterator It)
Inserts an unlinked instruction into ParentBB at position It and returns the iterator of the inserted...
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
@ MIN_INT_BITS
Minimum number of bits that can be specified.
@ MAX_INT_BITS
Maximum number of bits that can be specified.
static InvokeInst * Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, const Twine &NameStr, InsertPosition InsertBefore=nullptr)
This is an important class for using LLVM in a threaded context.
void emitError(const Instruction *I, const Twine &ErrorStr)
emitError - Emit an error message to the currently installed error handler with optional location inf...
SyncScope::ID getOrInsertSyncScopeID(StringRef SSN)
getOrInsertSyncScopeID - Maps synchronization scope name to synchronization scope ID.
The landingpad instruction holds all of the information necessary to generate correct exception handl...
static LandingPadInst * Create(Type *RetTy, unsigned NumReservedClauses, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructors - NumReservedClauses is a hint for the number of incoming clauses that this landingpad w...
void addClause(Constant *ClauseVal)
Add a catch or filter clause to the landing pad.
void setCleanup(bool V)
Indicate that this landingpad instruction is a cleanup.
An instruction for reading from memory.
Tracking metadata reference owned by Metadata.
StringRef getString() const
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
ValueT lookup(const KeyT &Key) const
size_t getBufferSize() const
StringRef getBufferIdentifier() const
const char * getBufferStart() const
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFileOrSTDIN(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, std::optional< Align > Alignment=std::nullopt)
Open the specified file as a MemoryBuffer, or open stdin if the Filename is "-".
static MemoryEffectsBase readOnly()
Create MemoryEffectsBase that can read any memory.
static MemoryEffectsBase argMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
Create MemoryEffectsBase that can only access argument memory.
static MemoryEffectsBase inaccessibleMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
Create MemoryEffectsBase that can only access inaccessible memory.
static MemoryEffectsBase createFromIntValue(uint32_t Data)
Create MemoryEffectsBase from an encoded integer value (used by memory attribute).
static MemoryEffectsBase writeOnly()
Create MemoryEffectsBase that can write any memory.
static MemoryEffectsBase inaccessibleOrArgMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
Create MemoryEffectsBase that can only access inaccessible or argument memory.
static MemoryEffectsBase none()
Create MemoryEffectsBase that cannot read or write any memory.
static MemoryEffectsBase unknown()
Create MemoryEffectsBase that can read and write any memory.
static MetadataAsValue * get(LLVMContext &Context, Metadata *MD)
Helper class that handles loading Metadatas and keeping them available.
Root of the metadata hierarchy.
Class to hold module path string table and global value map, and encapsulate methods for operating on...
TypeIdSummary & getOrInsertTypeIdSummary(StringRef TypeId)
Return an existing or new TypeIdSummary entry for TypeId.
ValueInfo getOrInsertValueInfo(GlobalValue::GUID GUID)
Return a ValueInfo for GUID.
StringRef saveString(StringRef String)
void setFlags(uint64_t Flags)
void addBlockCount(uint64_t C)
ModuleInfo * addModule(StringRef ModPath, ModuleHash Hash=ModuleHash{{0}})
Add a new module with the given Hash, mapped to the given ModID, and return a reference to the module...
void addGlobalValueSummary(const GlobalValue &GV, std::unique_ptr< GlobalValueSummary > Summary)
Add a global value summary for a value.
std::set< std::string, std::less<> > & cfiFunctionDefs()
static constexpr uint64_t BitcodeSummaryVersion
std::set< std::string, std::less<> > & cfiFunctionDecls()
GlobalValueSummary * findSummaryInModule(ValueInfo VI, StringRef ModuleId) const
Find the summary for ValueInfo VI in module ModuleId, or nullptr if not found.
unsigned addOrGetStackIdIndex(uint64_t StackId)
ModuleInfo * getModule(StringRef ModPath)
Return module entry for module with the given ModPath.
void addOriginalName(GlobalValue::GUID ValueGUID, GlobalValue::GUID OrigGUID)
Add an original name for the value of the given GUID.
TypeIdCompatibleVtableInfo & getOrInsertTypeIdCompatibleVtableSummary(StringRef TypeId)
Return an existing or new TypeIdCompatibleVtableMap entry for TypeId.
A Module instance is used to store all the information related to an LLVM module.
NamedMDNode * getNamedMetadata(StringRef Name) const
Return the first NamedMDNode in the module with the specified name.
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
NamedMDNode * getOrInsertNamedMetadata(StringRef Name)
Return the named MDNode in the module with the specified name.
Comdat * getOrInsertComdat(StringRef Name)
Return the Comdat in the module with the specified name.
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
void addOperand(MDNode *M)
static NoCFIValue * get(GlobalValue *GV)
Return a NoCFIValue for the specified function.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
static ResumeInst * Create(Value *Exn, InsertPosition InsertBefore=nullptr)
static ReturnInst * Create(LLVMContext &C, Value *retVal=nullptr, InsertPosition InsertBefore=nullptr)
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", InsertPosition InsertBefore=nullptr, Instruction *MDFrom=nullptr)
This instruction constructs a fixed permutation of two input vectors.
ArrayRef< int > getShuffleMask() const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
StringRef str() const
Explicit conversion to StringRef.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void reserve(size_type N)
iterator erase(const_iterator CI)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Class to represent struct types.
static StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
static StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
void setName(StringRef Name)
Change the name of this type to the specified name, or to a name with a suffix if there is a collisio...
Error setBodyOrError(ArrayRef< Type * > Elements, bool isPacked=false)
Specify a body for an opaque identified type or return an error if it would make the type recursive.
static SwitchInst * Create(Value *Value, BasicBlock *Default, unsigned NumCases, InsertPosition InsertBefore=nullptr)
Verify that the TBAA Metadatas are valid.
bool visitTBAAMetadata(Instruction &I, const MDNode *MD)
Visit an instruction and return true if it is valid, return false if an invalid TBAA is attached.
@ HasZeroInit
zeroinitializer is valid for this target extension type.
static Expected< TargetExtType * > getOrError(LLVMContext &Context, StringRef Name, ArrayRef< Type * > Types={}, ArrayRef< unsigned > Ints={})
Return a target extension type having the specified name and optional type and integer parameters,...
See the file comment for details on the usage of the TrailingObjects type.
TrailingObjects()=default
Triple - Helper class for working with autoconf configuration names.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
std::string str() const
Return the twine contents as a std::string.
The instances of the Type class are immutable: once they are created, they are never changed.
static Type * getHalfTy(LLVMContext &C)
Type * getStructElementType(unsigned N) const
static Type * getDoubleTy(LLVMContext &C)
bool isVectorTy() const
True if this is an instance of VectorType.
bool isArrayTy() const
True if this is an instance of ArrayType.
static Type * getX86_FP80Ty(LLVMContext &C)
bool isLabelTy() const
Return true if this is 'label'.
static Type * getBFloatTy(LLVMContext &C)
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
bool isPointerTy() const
True if this is an instance of PointerType.
static IntegerType * getInt1Ty(LLVMContext &C)
Type * getArrayElementType() const
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
static Type * getX86_AMXTy(LLVMContext &C)
bool isBFloatTy() const
Return true if this is 'bfloat', a 16-bit bfloat type.
static Type * getMetadataTy(LLVMContext &C)
unsigned getStructNumElements() const
uint64_t getArrayNumElements() const
TypeID
Definitions of all of the base types for the Type system.
static Type * getVoidTy(LLVMContext &C)
static Type * getLabelTy(LLVMContext &C)
bool isStructTy() const
True if this is an instance of StructType.
static Type * getFP128Ty(LLVMContext &C)
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
static Type * getTokenTy(LLVMContext &C)
bool isFunctionTy() const
True if this is an instance of FunctionType.
static IntegerType * getInt32Ty(LLVMContext &C)
static Type * getFloatTy(LLVMContext &C)
bool isIntegerTy() const
True if this is an instance of IntegerType.
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
static Type * getPPC_FP128Ty(LLVMContext &C)
bool isVoidTy() const
Return true if this is 'void'.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
bool isMetadataTy() const
Return true if this is 'metadata'.
static UnaryOperator * Create(UnaryOps Op, Value *S, const Twine &Name=Twine(), InsertPosition InsertBefore=nullptr)
Construct a unary instruction, given the opcode and an operand.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
This function has undefined behavior.
A Use represents the edge between a Value definition and its users.
This class represents the va_arg llvm instruction, which returns an argument of the specified type gi...
static ValueAsMetadata * get(Value *V)
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
void setName(const Twine &Name)
Change the name of the value.
void deleteValue()
Delete a pointer to a generic Value.
static constexpr unsigned MaxAlignmentExponent
The maximum alignment for instructions.
Value & operator=(const Value &)=delete
std::pair< iterator, bool > insert(const ValueT &V)
bool contains(const_arg_type_t< ValueT > V) const
Check if the set contains the given element.
const ParentTy * getParent() const
self_iterator getIterator()
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char TypeName[]
Key for Kernel::Arg::Metadata::mTypeName.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
AttributeMask typeIncompatible(Type *Ty, AttributeSet AS, AttributeSafetyKind ASK=ASK_ALL)
Which attributes cannot be applied to a type.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
@ MaxID
The highest possible ID. Must be some 2^k - 1.
@ X86_INTR
x86 hardware interrupt context.
@ C
The default llvm calling convention, compatible with C.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
constexpr uint8_t RecordLength
Length of the parts of a physical GOFF record.
AttributeList getAttributes(LLVMContext &C, ID id)
Return the attributes for an intrinsic.
@ SingleThread
Synchronized with respect to signal handlers executing in the same thread.
@ System
Synchronized with respect to all concurrently executing threads.
@ TYPE_CODE_OPAQUE_POINTER
@ FS_CONTEXT_RADIX_TREE_ARRAY
@ FS_COMBINED_GLOBALVAR_INIT_REFS
@ FS_TYPE_CHECKED_LOAD_VCALLS
@ FS_COMBINED_ORIGINAL_NAME
@ FS_PERMODULE_VTABLE_GLOBALVAR_INIT_REFS
@ FS_TYPE_TEST_ASSUME_CONST_VCALL
@ FS_PERMODULE_GLOBALVAR_INIT_REFS
@ FS_TYPE_TEST_ASSUME_VCALLS
@ FS_COMBINED_CALLSITE_INFO
@ FS_PERMODULE_CALLSITE_INFO
@ FS_PERMODULE_ALLOC_INFO
@ FS_TYPE_CHECKED_LOAD_CONST_VCALL
@ IDENTIFICATION_CODE_EPOCH
@ IDENTIFICATION_CODE_STRING
@ CST_CODE_CE_INBOUNDS_GEP
@ CST_CODE_INLINEASM_OLD3
@ CST_CODE_CE_GEP_WITH_INRANGE_INDEX_OLD
@ CST_CODE_DSO_LOCAL_EQUIVALENT
@ CST_CODE_INLINEASM_OLD2
@ CST_CODE_CE_GEP_WITH_INRANGE
@ VST_CODE_COMBINED_ENTRY
@ COMDAT_SELECTION_KIND_LARGEST
@ COMDAT_SELECTION_KIND_ANY
@ COMDAT_SELECTION_KIND_SAME_SIZE
@ COMDAT_SELECTION_KIND_EXACT_MATCH
@ COMDAT_SELECTION_KIND_NO_DUPLICATES
@ ATTR_KIND_STACK_PROTECT
@ ATTR_KIND_STACK_PROTECT_STRONG
@ ATTR_KIND_SANITIZE_MEMORY
@ ATTR_KIND_OPTIMIZE_FOR_SIZE
@ ATTR_KIND_INACCESSIBLEMEM_ONLY
@ ATTR_KIND_FNRETTHUNK_EXTERN
@ ATTR_KIND_NO_DIVERGENCE_SOURCE
@ ATTR_KIND_SANITIZE_ADDRESS
@ ATTR_KIND_NO_IMPLICIT_FLOAT
@ ATTR_KIND_DEAD_ON_UNWIND
@ ATTR_KIND_STACK_ALIGNMENT
@ ATTR_KIND_INACCESSIBLEMEM_OR_ARGMEMONLY
@ ATTR_KIND_STACK_PROTECT_REQ
@ ATTR_KIND_NULL_POINTER_IS_VALID
@ ATTR_KIND_SANITIZE_HWADDRESS
@ ATTR_KIND_RETURNS_TWICE
@ ATTR_KIND_SHADOWCALLSTACK
@ ATTR_KIND_OPT_FOR_FUZZING
@ ATTR_KIND_SANITIZE_NUMERICAL_STABILITY
@ ATTR_KIND_ALLOCATED_POINTER
@ ATTR_KIND_DISABLE_SANITIZER_INSTRUMENTATION
@ ATTR_KIND_CORO_ELIDE_SAFE
@ ATTR_KIND_NON_LAZY_BIND
@ ATTR_KIND_DEREFERENCEABLE
@ ATTR_KIND_OPTIMIZE_NONE
@ ATTR_KIND_DEREFERENCEABLE_OR_NULL
@ ATTR_KIND_SANITIZE_REALTIME
@ ATTR_KIND_SPECULATIVE_LOAD_HARDENING
@ ATTR_KIND_ALWAYS_INLINE
@ ATTR_KIND_SANITIZE_TYPE
@ ATTR_KIND_PRESPLIT_COROUTINE
@ ATTR_KIND_NO_SANITIZE_COVERAGE
@ ATTR_KIND_SANITIZE_REALTIME_BLOCKING
@ ATTR_KIND_NO_SANITIZE_BOUNDS
@ ATTR_KIND_SANITIZE_MEMTAG
@ ATTR_KIND_CORO_ONLY_DESTROY_WHEN_COMPLETE
@ ATTR_KIND_SANITIZE_THREAD
@ ATTR_KIND_OPTIMIZE_FOR_DEBUGGING
@ SYNC_SCOPE_NAMES_BLOCK_ID
@ PARAMATTR_GROUP_BLOCK_ID
@ IDENTIFICATION_BLOCK_ID
@ GLOBALVAL_SUMMARY_BLOCK_ID
@ FULL_LTO_GLOBALVAL_SUMMARY_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...
@ MODULE_CODE_SOURCE_FILENAME
@ MODULE_CODE_SECTIONNAME
@ FUNC_CODE_INST_ATOMICRMW_OLD
@ FUNC_CODE_INST_CATCHRET
@ FUNC_CODE_INST_LANDINGPAD
@ FUNC_CODE_INST_EXTRACTVAL
@ FUNC_CODE_INST_CATCHPAD
@ FUNC_CODE_INST_CATCHSWITCH
@ FUNC_CODE_INST_INBOUNDS_GEP_OLD
@ FUNC_CODE_INST_STOREATOMIC_OLD
@ FUNC_CODE_INST_CLEANUPRET
@ FUNC_CODE_INST_LANDINGPAD_OLD
@ FUNC_CODE_DEBUG_RECORD_VALUE
@ FUNC_CODE_INST_LOADATOMIC
@ FUNC_CODE_DEBUG_RECORD_ASSIGN
@ FUNC_CODE_INST_STOREATOMIC
@ FUNC_CODE_INST_ATOMICRMW
@ FUNC_CODE_DEBUG_LOC_AGAIN
@ FUNC_CODE_INST_EXTRACTELT
@ FUNC_CODE_INST_INDIRECTBR
@ FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE
@ FUNC_CODE_INST_INSERTVAL
@ FUNC_CODE_DECLAREBLOCKS
@ FUNC_CODE_DEBUG_RECORD_LABEL
@ FUNC_CODE_INST_INSERTELT
@ FUNC_CODE_BLOCKADDR_USERS
@ FUNC_CODE_INST_CLEANUPPAD
@ FUNC_CODE_INST_SHUFFLEVEC
@ FUNC_CODE_INST_STORE_OLD
@ FUNC_CODE_INST_UNREACHABLE
@ FUNC_CODE_INST_CMPXCHG_OLD
@ FUNC_CODE_DEBUG_RECORD_DECLARE
@ FUNC_CODE_OPERAND_BUNDLE
@ PARAMATTR_CODE_ENTRY_OLD
@ PARAMATTR_GRP_CODE_ENTRY
initializer< Ty > init(const Ty &Val)
Linkage
Describes symbol linkage. This can be used to resolve definition clashes.
Scope
Defines the scope in which this symbol should be visible: Default – Visible in the public interface o...
NodeAddr< FuncNode * > Func
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
@ Low
Lower the current thread's priority such that it does not affect foreground tasks significantly.
detail::zippy< detail::zip_shortest, T, U, Args... > zip(T &&t, U &&u, Args &&...args)
zip iterator for two or more iteratable types.
void UpgradeIntrinsicCall(CallBase *CB, Function *NewFn)
This is the complement to the above, replacing a specific call to an intrinsic function with a call t...
const std::error_category & BitcodeErrorCategory()
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.
Expected< std::unique_ptr< Module > > parseBitcodeFile(MemoryBufferRef Buffer, LLVMContext &Context, ParserCallbacks Callbacks={})
Read the specified bitcode file, returning the module.
unsigned getBranchWeightOffset(const MDNode *ProfileData)
Return the offset to the first branch weight data.
void UpgradeInlineAsmString(std::string *AsmStr)
Upgrade comment in call to inline asm that represents an objc retain release marker.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
std::error_code make_error_code(BitcodeError E)
bool stripDebugInfo(Function &F)
Expected< bool > isBitcodeContainingObjCCategory(MemoryBufferRef Buffer)
Return true if Buffer contains a bitcode file with ObjC code (category or class) in it.
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
bool UpgradeIntrinsicFunction(Function *F, Function *&NewFn, bool CanUpgradeDebugIntrinsicsToRecords=true)
This is a more granular function that simply checks an intrinsic function for upgrading,...
void UpgradeAttributes(AttrBuilder &B)
Upgrade attributes that changed format or kind.
Expected< std::string > getBitcodeTargetTriple(MemoryBufferRef Buffer)
Read the header of the specified bitcode buffer and extract just the triple information.
std::unique_ptr< Module > parseModule(const uint8_t *Data, size_t Size, LLVMContext &Context)
Fuzzer friendly interface for the llvm bitcode parser.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Expected< BitcodeFileContents > getBitcodeFileContents(MemoryBufferRef Buffer)
Returns the contents of a bitcode file.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
bool UpgradeModuleFlags(Module &M)
This checks for module flags which should be upgraded.
Value * getSplatValue(const Value *V)
Get splat value if the input is a splat vector or return nullptr.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
void UpgradeOperandBundles(std::vector< OperandBundleDef > &OperandBundles)
Upgrade operand bundles (without knowing about their user instruction).
std::vector< VirtFuncOffset > VTableFuncList
List of functions referenced by a particular vtable definition.
Constant * UpgradeBitCastExpr(unsigned Opc, Constant *C, Type *DestTy)
This is an auto-upgrade for bitcast constant expression between pointers with different address space...
Expected< std::unique_ptr< ModuleSummaryIndex > > getModuleSummaryIndex(MemoryBufferRef Buffer)
Parse the specified bitcode buffer, returning the module summary index.
StringMapEntry< Value * > ValueName
OutputIt transform(R &&Range, OutputIt d_first, UnaryFunction F)
Wrapper function around std::transform to apply a function to a range and store the result elsewhere.
Expected< std::string > getBitcodeProducerString(MemoryBufferRef Buffer)
Read the header of the specified bitcode buffer and extract just the producer string information.
auto reverse(ContainerTy &&C)
Expected< std::unique_ptr< Module > > getLazyBitcodeModule(MemoryBufferRef Buffer, LLVMContext &Context, bool ShouldLazyLoadMetadata=false, bool IsImporting=false, ParserCallbacks Callbacks={})
Read the header of the specified bitcode buffer and prepare for lazy deserialization of function bodi...
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
FPClassTest
Floating-point class tests, supported by 'is_fpclass' intrinsic.
detail::ValueMatchesPoly< M > HasValue(M Matcher)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
std::string UpgradeDataLayoutString(StringRef DL, StringRef Triple)
Upgrade the datalayout string by adding a section for address space pointers.
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
Expected< std::vector< BitcodeModule > > getBitcodeModuleList(MemoryBufferRef Buffer)
Returns a list of modules in the specified bitcode buffer.
Expected< BitcodeLTOInfo > getBitcodeLTOInfo(MemoryBufferRef Buffer)
Returns LTO information for the specified bitcode file.
GlobalVariable * UpgradeGlobalVariable(GlobalVariable *GV)
This checks for global variables which should be upgraded.
bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
AtomicOrdering
Atomic ordering for LLVM's memory model.
Instruction * UpgradeBitCastInst(unsigned Opc, Value *V, Type *DestTy, Instruction *&Temp)
This is an auto-upgrade for bitcast between pointers with different address spaces: the instruction i...
MaybeAlign decodeMaybeAlign(unsigned Value)
Dual operation of the encode function above.
DWARFExpression::Operation Op
constexpr unsigned BitWidth
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
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 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.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
gep_type_iterator gep_type_begin(const User *GEP)
APInt readWideAPInt(ArrayRef< uint64_t > Vals, unsigned TypeBits)
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
bool UpgradeDebugInfo(Module &M)
Check the debug info version number, if it is out-dated, drop the debug info.
void UpgradeFunctionAttributes(Function &F)
Correct any IR that is relying on old function attribute behavior.
Error readModuleSummaryIndex(MemoryBufferRef Buffer, ModuleSummaryIndex &CombinedIndex)
Parse the specified bitcode buffer and merge the index into CombinedIndex.
std::vector< TypeIdOffsetVtableInfo > TypeIdCompatibleVtableInfo
List of vtable definitions decorated by a particular type identifier, and their corresponding offsets...
void UpgradeARCRuntime(Module &M)
Convert calls to ARC runtime functions to intrinsic calls and upgrade the old retain release marker t...
Expected< std::unique_ptr< ModuleSummaryIndex > > getModuleSummaryIndexForFile(StringRef Path, bool IgnoreEmptyThinLTOIndexFile=false)
Parse the module summary index out of an IR file and return the module summary index object if found,...
Expected< std::unique_ptr< Module > > getOwningLazyBitcodeModule(std::unique_ptr< MemoryBuffer > &&Buffer, LLVMContext &Context, bool ShouldLazyLoadMetadata=false, bool IsImporting=false, ParserCallbacks Callbacks={})
Like getLazyBitcodeModule, except that the module takes ownership of the memory buffer if successful.
std::error_code errorToErrorCodeAndEmitErrors(LLVMContext &Ctx, Error Err)
Implement std::hash so that hash_code can be used in STL containers.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Represents the EMUL and EEW of a MachineOperand.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Summary of memprof metadata on allocations.
Basic information extracted from a bitcode module to be used for LTO.
When advancing through a bitstream cursor, each advance can discover a few different kinds of entries...
Class to accumulate and hold information about a callee.
static constexpr unsigned RelBlockFreqBits
The value stored in RelBlockFreq has to be interpreted as the digits of a scaled number with a scale ...
Summary of memprof callsite metadata.
Flags specific to function summaries.
Describes the uses of a parameter by the function.
std::vector< Call > Calls
In the per-module summary, it summarizes the byte offset applied to each pointer parameter before pas...
ConstantRange Use
The range contains byte offsets from the parameter pointer which accessed by the function.
static constexpr uint32_t RangeWidth
Group flags (Linkage, NotEligibleToImport, etc.) as a bitfield.
Summary of a single MIB in a memprof metadata on allocations.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
GetTypeByIDTy GetTypeByID
GetContainedTypeIDTy GetContainedTypeID
std::optional< MDTypeCallbackTy > MDType
std::optional< ValueTypeCallbackTy > ValueType
The ValueType callback is called for every function definition or declaration and allows accessing th...
std::optional< DataLayoutCallbackFuncTy > DataLayout
std::optional< MDTypeCallbackTy > MDType
The MDType callback is called for every value in metadata.
A MapVector that performs no allocations if smaller than a certain size.
std::map< uint64_t, WholeProgramDevirtResolution > WPDRes
Mapping from byte offset to whole-program devirt resolution for that (typeid, byte offset) pair.
Kind
Specifies which kind of type check we should emit for this byte array.
unsigned SizeM1BitWidth
Range of size-1 expressed as a bit width.
enum llvm::TypeTestResolution::Kind TheKind
ValID - Represents a reference of a definition of some sort with no type.
Struct that holds a reference to a particular GUID in a global value summary.
enum llvm::WholeProgramDevirtResolution::Kind TheKind
std::map< std::vector< uint64_t >, ByArg > ResByArg
Resolutions for calls with all constant integer arguments (excluding the first argument,...
std::string SingleImplName