24#include "llvm/Config/llvm-config.h"
52#include "llvm/IR/IntrinsicsAArch64.h"
53#include "llvm/IR/IntrinsicsARM.h"
85#include <system_error>
95 "Print the global id for each value when reading the module summary"));
100 "Expand constant expressions to instructions for testing purposes"));
105 SWITCH_INST_MAGIC = 0x4B5
111 return make_error<StringError>(
118 "file too small to contain bitcode header");
119 for (
unsigned C : {
'B',
'C'})
123 "file doesn't start with bitcode header");
125 return Res.takeError();
126 for (
unsigned C : {0x0, 0xC, 0xE, 0xD})
130 "file doesn't start with bitcode header");
132 return Res.takeError();
137 const unsigned char *BufPtr = (
const unsigned char *)Buffer.
getBufferStart();
138 const unsigned char *BufEnd = BufPtr + Buffer.
getBufferSize();
141 return error(
"Invalid bitcode signature");
147 return error(
"Invalid bitcode wrapper header");
151 return std::move(Err);
153 return std::move(Stream);
157template <
typename StrTy>
170 if (
F.isMaterializable())
173 I.setMetadata(LLVMContext::MD_tbaa,
nullptr);
181 return std::move(Err);
186 std::string ProducerIdentification;
193 switch (Entry.Kind) {
196 return error(
"Malformed block");
198 return ProducerIdentification;
209 switch (MaybeBitCode.
get()) {
211 return error(
"Invalid value");
219 Twine(
"Incompatible epoch: Bitcode '") +
Twine(epoch) +
238 switch (Entry.Kind) {
241 return error(
"Malformed block");
249 return std::move(Err);
261 return std::move(Err);
272 switch (Entry.Kind) {
275 return error(
"Malformed block");
287 switch (MaybeRecord.
get()) {
293 return error(
"Invalid section name record");
295 if (S.find(
"__DATA,__objc_catlist") != std::string::npos ||
296 S.find(
"__OBJC,__category") != std::string::npos)
314 switch (Entry.Kind) {
316 return error(
"Malformed block");
326 return std::move(Err);
339 return std::move(Err);
352 switch (Entry.Kind) {
355 return error(
"Malformed block");
367 switch (MaybeRecord.
get()) {
372 return error(
"Invalid triple record");
391 switch (Entry.Kind) {
393 return error(
"Malformed block");
403 return std::move(Err);
410 return Skipped.takeError();
417class BitcodeReaderBase {
420 : Stream(
std::
move(Stream)), Strtab(Strtab) {
430 bool UseStrtab =
false;
437 std::pair<StringRef, ArrayRef<uint64_t>>
440 Error readBlockInfo();
443 std::string ProducerIdentification;
450Error BitcodeReaderBase::error(
const Twine &Message) {
451 std::string FullMsg = Message.
str();
452 if (!ProducerIdentification.empty())
453 FullMsg +=
" (Producer: '" + ProducerIdentification +
"' Reader: 'LLVM " +
454 LLVM_VERSION_STRING
"')";
455 return ::error(FullMsg);
461 return error(
"Invalid version record");
462 unsigned ModuleVersion =
Record[0];
463 if (ModuleVersion > 2)
464 return error(
"Invalid value");
465 UseStrtab = ModuleVersion >= 2;
466 return ModuleVersion;
469std::pair<StringRef, ArrayRef<uint64_t>>
487class BitcodeConstant final :
public Value,
492 static constexpr uint8_t SubclassID = 255;
500 static constexpr uint8_t ConstantStructOpcode = 255;
501 static constexpr uint8_t ConstantArrayOpcode = 254;
502 static constexpr uint8_t ConstantVectorOpcode = 253;
503 static constexpr uint8_t NoCFIOpcode = 252;
504 static constexpr uint8_t DSOLocalEquivalentOpcode = 251;
505 static constexpr uint8_t BlockAddressOpcode = 250;
506 static constexpr uint8_t FirstSpecialOpcode = BlockAddressOpcode;
516 ExtraInfo(uint8_t Opcode, uint8_t Flags = 0,
unsigned Extra = 0,
517 Type *SrcElemTy =
nullptr)
518 : Opcode(Opcode),
Flags(
Flags), Extra(Extra), SrcElemTy(SrcElemTy) {}
523 unsigned NumOperands;
530 NumOperands(OpIDs.
size()), Extra(
Info.Extra),
531 SrcElemTy(
Info.SrcElemTy) {
532 std::uninitialized_copy(OpIDs.
begin(), OpIDs.
end(),
533 getTrailingObjects<unsigned>());
536 BitcodeConstant &
operator=(
const BitcodeConstant &) =
delete;
540 const ExtraInfo &Info,
542 void *Mem =
A.Allocate(totalSizeToAlloc<unsigned>(OpIDs.
size()),
543 alignof(BitcodeConstant));
544 return new (Mem) BitcodeConstant(Ty, Info, OpIDs);
547 static bool classof(
const Value *V) {
return V->getValueID() == SubclassID; }
550 return ArrayRef(getTrailingObjects<unsigned>(), NumOperands);
553 std::optional<unsigned> getInRangeIndex()
const {
554 assert(Opcode == Instruction::GetElementPtr);
555 if (Extra == (
unsigned)-1)
565class BitcodeReader :
public BitcodeReaderBase,
public GVMaterializer {
567 Module *TheModule =
nullptr;
572 bool SeenValueSymbolTable =
false;
575 std::vector<std::string> SectionTable;
576 std::vector<std::string> GCTable;
578 std::vector<Type *> TypeList;
596 std::optional<MetadataLoader> MDLoader;
597 std::vector<Comdat *> ComdatList;
601 std::vector<std::pair<GlobalVariable *, unsigned>> GlobalInits;
602 std::vector<std::pair<GlobalValue *, unsigned>> IndirectSymbolInits;
604 struct FunctionOperandInfo {
606 unsigned PersonalityFn;
610 std::vector<FunctionOperandInfo> FunctionOperands;
614 std::vector<AttributeList> MAttributes;
617 std::map<unsigned, AttributeList> MAttributeGroups;
621 std::vector<BasicBlock*> FunctionBBs;
625 std::vector<Function*> FunctionsWithBodies;
630 UpdatedIntrinsicMap UpgradedIntrinsics;
635 bool SeenFirstFunctionBody =
false;
644 std::vector<uint64_t> DeferredMetadataInfo;
650 std::deque<Function *> BasicBlockFwdRefQueue;
657 std::vector<Function *> BackwardRefFunctions;
665 bool UseRelativeIDs =
false;
669 bool WillMaterializeAllForwardRefs =
false;
674 std::vector<std::string> BundleTags;
677 std::optional<ValueTypeCallbackTy> ValueTypeCallback;
683 Error materializeForwardReferencedFunctions();
691 Error parseBitcodeInto(
Module *M,
bool ShouldLazyLoadMetadata,
702 std::vector<StructType *> IdentifiedStructTypes;
706 static constexpr unsigned InvalidTypeID = ~0
u;
708 Type *getTypeByID(
unsigned ID);
709 Type *getPtrElementTypeByID(
unsigned ID);
710 unsigned getContainedTypeID(
unsigned ID,
unsigned Idx = 0);
717 Value *getFnValueByID(
unsigned ID,
Type *Ty,
unsigned TyID,
725 return MDLoader->getMetadataFwdRefOrLoad(
ID);
729 if (
ID >= FunctionBBs.size())
return nullptr;
730 return FunctionBBs[
ID];
734 if (i-1 < MAttributes.size())
735 return MAttributes[i-1];
743 unsigned InstNum,
Value *&ResVal,
unsigned &
TypeID,
745 if (Slot ==
Record.size())
return true;
749 ValNo = InstNum - ValNo;
750 if (ValNo < InstNum) {
754 ResVal = getFnValueByID(ValNo,
nullptr,
TypeID, ConstExprInsertBB);
756 "Incorrect type ID stored for value");
757 return ResVal ==
nullptr;
759 if (Slot ==
Record.size())
763 ResVal = getFnValueByID(ValNo, getTypeByID(
TypeID),
TypeID,
765 return ResVal ==
nullptr;
772 unsigned InstNum,
Type *Ty,
unsigned TyID,
Value *&ResVal,
774 if (getValue(
Record, Slot, InstNum, Ty, TyID, ResVal, ConstExprInsertBB))
783 unsigned InstNum,
Type *Ty,
unsigned TyID,
Value *&ResVal,
785 ResVal = getValue(
Record, Slot, InstNum, Ty, TyID, ConstExprInsertBB);
786 return ResVal ==
nullptr;
792 unsigned InstNum,
Type *Ty,
unsigned TyID,
794 if (Slot ==
Record.size())
return nullptr;
798 ValNo = InstNum - ValNo;
799 return getFnValueByID(ValNo, Ty, TyID, ConstExprInsertBB);
804 unsigned InstNum,
Type *Ty,
unsigned TyID,
806 if (Slot ==
Record.size())
return nullptr;
810 ValNo = InstNum - ValNo;
811 return getFnValueByID(ValNo, Ty, TyID, ConstExprInsertBB);
830 Error parseGlobalIndirectSymbolRecord(
unsigned BitCode,
833 Error parseAttributeBlock();
834 Error parseAttributeGroupBlock();
835 Error parseTypeTable();
836 Error parseTypeTableBody();
837 Error parseOperandBundleTags();
838 Error parseSyncScopeNames();
841 unsigned NameIndex,
Triple &TT);
842 void setDeferredFunctionInfo(
unsigned FuncBitcodeOffsetDelta,
Function *
F,
845 Error parseGlobalValueSymbolTable();
846 Error parseConstants();
847 Error rememberAndSkipFunctionBodies();
848 Error rememberAndSkipFunctionBody();
850 Error rememberAndSkipMetadata();
853 Error globalCleanup();
854 Error resolveGlobalAndIndirectSymbolInits();
855 Error parseUseLists();
856 Error findFunctionInStream(
865class ModuleSummaryIndexBitcodeReader :
public BitcodeReaderBase {
871 bool SeenGlobalValSummary =
false;
874 bool SeenValueSymbolTable =
false;
890 std::tuple<ValueInfo, GlobalValue::GUID, GlobalValue::GUID>>
891 ValueIdToValueInfoMap;
900 std::string SourceFileName;
916 std::vector<uint64_t> StackIds;
919 ModuleSummaryIndexBitcodeReader(
930 Error parseValueSymbolTable(
935 bool IsOldProfileFormat,
938 Error parseEntireSummary(
unsigned ID);
939 Error parseModuleStringTable();
943 std::vector<FunctionSummary::ParamAccess>
946 template <
bool AllowNullValueInfo = false>
947 std::tuple<ValueInfo, GlobalValue::GUID, GlobalValue::GUID>
948 getValueInfoFromValueId(
unsigned ValueId);
950 void addThisModule();
966 return std::error_code();
973 ValueList(this->Stream.SizeInBytes(),
975 return materializeValue(
ValID, InsertBB);
977 this->ProducerIdentification = std::string(ProducerIdentification);
980Error BitcodeReader::materializeForwardReferencedFunctions() {
981 if (WillMaterializeAllForwardRefs)
985 WillMaterializeAllForwardRefs =
true;
987 while (!BasicBlockFwdRefQueue.empty()) {
988 Function *
F = BasicBlockFwdRefQueue.front();
989 BasicBlockFwdRefQueue.pop_front();
990 assert(
F &&
"Expected valid function");
991 if (!BasicBlockFwdRefs.
count(
F))
999 if (!
F->isMaterializable())
1000 return error(
"Never resolved function from blockaddress");
1003 if (
Error Err = materialize(
F))
1006 assert(BasicBlockFwdRefs.
empty() &&
"Function missing from queue");
1008 for (
Function *
F : BackwardRefFunctions)
1009 if (
Error Err = materialize(
F))
1011 BackwardRefFunctions.clear();
1014 WillMaterializeAllForwardRefs =
false;
1078 Flags.ReadNone = RawFlags & 0x1;
1079 Flags.ReadOnly = (RawFlags >> 1) & 0x1;
1080 Flags.NoRecurse = (RawFlags >> 2) & 0x1;
1081 Flags.ReturnDoesNotAlias = (RawFlags >> 3) & 0x1;
1082 Flags.NoInline = (RawFlags >> 4) & 0x1;
1083 Flags.AlwaysInline = (RawFlags >> 5) & 0x1;
1084 Flags.NoUnwind = (RawFlags >> 6) & 0x1;
1085 Flags.MayThrow = (RawFlags >> 7) & 0x1;
1086 Flags.HasUnknownCall = (RawFlags >> 8) & 0x1;
1087 Flags.MustBeUnreachable = (RawFlags >> 9) & 0x1;
1102 RawFlags = RawFlags >> 4;
1103 bool NotEligibleToImport = (RawFlags & 0x1) || Version < 3;
1107 bool Live = (RawFlags & 0x2) || Version < 3;
1108 bool Local = (RawFlags & 0x4);
1109 bool AutoHide = (RawFlags & 0x8);
1112 Live, Local, AutoHide);
1118 (RawFlags & 0x1) ?
true :
false, (RawFlags & 0x2) ?
true :
false,
1119 (RawFlags & 0x4) ?
true :
false,
1145 case 0:
return false;
1146 case 1:
return true;
1152 case 0:
return GlobalVariable::NotThreadLocal;
1154 case 1:
return GlobalVariable::GeneralDynamicTLSModel;
1155 case 2:
return GlobalVariable::LocalDynamicTLSModel;
1156 case 3:
return GlobalVariable::InitialExecTLSModel;
1157 case 4:
return GlobalVariable::LocalExecTLSModel;
1164 case 0:
return GlobalVariable::UnnamedAddr::None;
1165 case 1:
return GlobalVariable::UnnamedAddr::Global;
1166 case 2:
return GlobalVariable::UnnamedAddr::Local;
1199 return IsFP ? Instruction::FNeg : -1;
1213 return IsFP ? Instruction::FAdd : Instruction::Add;
1215 return IsFP ? Instruction::FSub : Instruction::Sub;
1217 return IsFP ? Instruction::FMul : Instruction::Mul;
1219 return IsFP ? -1 : Instruction::UDiv;
1221 return IsFP ? Instruction::FDiv : Instruction::SDiv;
1223 return IsFP ? -1 : Instruction::URem;
1225 return IsFP ? Instruction::FRem : Instruction::SRem;
1227 return IsFP ? -1 : Instruction::Shl;
1229 return IsFP ? -1 : Instruction::LShr;
1231 return IsFP ? -1 : Instruction::AShr;
1233 return IsFP ? -1 : Instruction::And;
1235 return IsFP ? -1 : Instruction::Or;
1237 return IsFP ? -1 : Instruction::Xor;
1326Type *BitcodeReader::getTypeByID(
unsigned ID) {
1328 if (
ID >= TypeList.size())
1331 if (
Type *Ty = TypeList[
ID])
1336 return TypeList[
ID] = createIdentifiedStructType(Context);
1339unsigned BitcodeReader::getContainedTypeID(
unsigned ID,
unsigned Idx) {
1340 auto It = ContainedTypeIDs.
find(
ID);
1341 if (It == ContainedTypeIDs.
end())
1342 return InvalidTypeID;
1344 if (
Idx >= It->second.size())
1345 return InvalidTypeID;
1347 return It->second[
Idx];
1350Type *BitcodeReader::getPtrElementTypeByID(
unsigned ID) {
1351 if (
ID >= TypeList.size())
1358 Type *ElemTy = getTypeByID(getContainedTypeID(
ID, 0));
1362 assert(cast<PointerType>(Ty)->isOpaqueOrPointeeTypeMatches(ElemTy) &&
1363 "Incorrect element type");
1367unsigned BitcodeReader::getVirtualTypeID(
Type *Ty,
1369 unsigned ChildTypeID = ChildTypeIDs.
empty() ? InvalidTypeID : ChildTypeIDs[0];
1370 auto CacheKey = std::make_pair(Ty, ChildTypeID);
1371 auto It = VirtualTypeIDs.
find(CacheKey);
1372 if (It != VirtualTypeIDs.
end()) {
1378 ContainedTypeIDs[It->second] == ChildTypeIDs) &&
1379 "Incorrect cached contained type IDs");
1386 "Wrong number of contained types");
1387 for (
auto Pair :
zip(Ty->
subtypes(), ChildTypeIDs)) {
1388 assert(std::get<0>(Pair) == getTypeByID(std::get<1>(Pair)) &&
1389 "Incorrect contained type ID");
1394 unsigned TypeID = TypeList.size();
1395 TypeList.push_back(Ty);
1396 if (!ChildTypeIDs.
empty())
1403 uint8_t Opcode = BC->Opcode;
1406 if (Opcode >= BitcodeConstant::FirstSpecialOpcode)
1417 if (Opcode == Instruction::GetElementPtr)
1421 case Instruction::FNeg:
1422 case Instruction::Select:
1432 if (StartValID < ValueList.
size() && ValueList[StartValID] &&
1433 !isa<BitcodeConstant>(ValueList[StartValID]))
1434 return ValueList[StartValID];
1439 while (!Worklist.
empty()) {
1448 return error(
"Invalid value ID");
1451 auto *BC = dyn_cast<BitcodeConstant>(V);
1461 for (
unsigned OpID :
reverse(BC->getOperandIDs())) {
1462 auto It = MaterializedValues.
find(OpID);
1463 if (It != MaterializedValues.
end())
1471 if (Ops.
size() != BC->getOperandIDs().size())
1473 std::reverse(Ops.
begin(), Ops.
end());
1476 for (
Value *Op : Ops)
1477 if (
auto *
C = dyn_cast<Constant>(Op))
1490 switch (BC->Opcode) {
1491 case BitcodeConstant::NoCFIOpcode: {
1492 auto *GV = dyn_cast<GlobalValue>(ConstOps[0]);
1494 return error(
"no_cfi operand must be GlobalValue");
1498 case BitcodeConstant::DSOLocalEquivalentOpcode: {
1499 auto *GV = dyn_cast<GlobalValue>(ConstOps[0]);
1501 return error(
"dso_local operand must be GlobalValue");
1505 case BitcodeConstant::BlockAddressOpcode: {
1506 Function *Fn = dyn_cast<Function>(ConstOps[0]);
1508 return error(
"blockaddress operand must be a function");
1513 unsigned BBID = BC->Extra;
1516 return error(
"Invalid ID");
1519 for (
size_t I = 0,
E = BBID;
I !=
E; ++
I) {
1521 return error(
"Invalid ID");
1528 auto &FwdBBs = BasicBlockFwdRefs[Fn];
1530 BasicBlockFwdRefQueue.push_back(Fn);
1531 if (FwdBBs.size() < BBID + 1)
1532 FwdBBs.resize(BBID + 1);
1540 case BitcodeConstant::ConstantStructOpcode:
1543 case BitcodeConstant::ConstantArrayOpcode:
1546 case BitcodeConstant::ConstantVectorOpcode:
1549 case Instruction::ICmp:
1550 case Instruction::FCmp:
1553 case Instruction::GetElementPtr:
1556 BC->Flags, BC->getInRangeIndex());
1558 case Instruction::ExtractElement:
1561 case Instruction::InsertElement:
1565 case Instruction::ShuffleVector: {
1584 return error(
Twine(
"Value referenced by initializer is an unsupported "
1585 "constant expression of type ") +
1586 BC->getOpcodeName());
1592 BC->getType(),
"constexpr", InsertBB);
1595 "constexpr", InsertBB);
1598 Ops[1],
"constexpr", InsertBB);
1599 if (isa<OverflowingBinaryOperator>(
I)) {
1601 I->setHasNoSignedWrap();
1603 I->setHasNoUnsignedWrap();
1605 if (isa<PossiblyExactOperator>(
I) &&
1609 switch (BC->Opcode) {
1610 case BitcodeConstant::ConstantVectorOpcode: {
1618 I = cast<Instruction>(V);
1621 case BitcodeConstant::ConstantStructOpcode:
1622 case BitcodeConstant::ConstantArrayOpcode: {
1626 "constexpr.ins", InsertBB);
1627 I = cast<Instruction>(V);
1630 case Instruction::ICmp:
1631 case Instruction::FCmp:
1634 "constexpr", InsertBB);
1636 case Instruction::GetElementPtr:
1638 ArrayRef(Ops).drop_front(),
"constexpr",
1641 cast<GetElementPtrInst>(
I)->setIsInBounds();
1643 case Instruction::Select:
1646 case Instruction::ExtractElement:
1649 case Instruction::InsertElement:
1653 case Instruction::ShuffleVector:
1666 return MaterializedValues[StartValID];
1675 return cast<Constant>(MaybeV.
get());
1681 IdentifiedStructTypes.push_back(Ret);
1687 IdentifiedStructTypes.push_back(Ret);
1703 case Attribute::ZExt:
return 1 << 0;
1704 case Attribute::SExt:
return 1 << 1;
1705 case Attribute::NoReturn:
return 1 << 2;
1706 case Attribute::InReg:
return 1 << 3;
1707 case Attribute::StructRet:
return 1 << 4;
1708 case Attribute::NoUnwind:
return 1 << 5;
1709 case Attribute::NoAlias:
return 1 << 6;
1710 case Attribute::ByVal:
return 1 << 7;
1711 case Attribute::Nest:
return 1 << 8;
1712 case Attribute::ReadNone:
return 1 << 9;
1713 case Attribute::ReadOnly:
return 1 << 10;
1714 case Attribute::NoInline:
return 1 << 11;
1715 case Attribute::AlwaysInline:
return 1 << 12;
1716 case Attribute::OptimizeForSize:
return 1 << 13;
1717 case Attribute::StackProtect:
return 1 << 14;
1718 case Attribute::StackProtectReq:
return 1 << 15;
1719 case Attribute::Alignment:
return 31 << 16;
1720 case Attribute::NoCapture:
return 1 << 21;
1721 case Attribute::NoRedZone:
return 1 << 22;
1722 case Attribute::NoImplicitFloat:
return 1 << 23;
1723 case Attribute::Naked:
return 1 << 24;
1724 case Attribute::InlineHint:
return 1 << 25;
1725 case Attribute::StackAlignment:
return 7 << 26;
1726 case Attribute::ReturnsTwice:
return 1 << 29;
1727 case Attribute::UWTable:
return 1 << 30;
1728 case Attribute::NonLazyBind:
return 1U << 31;
1729 case Attribute::SanitizeAddress:
return 1ULL << 32;
1730 case Attribute::MinSize:
return 1ULL << 33;
1731 case Attribute::NoDuplicate:
return 1ULL << 34;
1732 case Attribute::StackProtectStrong:
return 1ULL << 35;
1733 case Attribute::SanitizeThread:
return 1ULL << 36;
1734 case Attribute::SanitizeMemory:
return 1ULL << 37;
1735 case Attribute::NoBuiltin:
return 1ULL << 38;
1736 case Attribute::Returned:
return 1ULL << 39;
1737 case Attribute::Cold:
return 1ULL << 40;
1738 case Attribute::Builtin:
return 1ULL << 41;
1739 case Attribute::OptimizeNone:
return 1ULL << 42;
1740 case Attribute::InAlloca:
return 1ULL << 43;
1741 case Attribute::NonNull:
return 1ULL << 44;
1742 case Attribute::JumpTable:
return 1ULL << 45;
1743 case Attribute::Convergent:
return 1ULL << 46;
1744 case Attribute::SafeStack:
return 1ULL << 47;
1745 case Attribute::NoRecurse:
return 1ULL << 48;
1748 case Attribute::SwiftSelf:
return 1ULL << 51;
1749 case Attribute::SwiftError:
return 1ULL << 52;
1750 case Attribute::WriteOnly:
return 1ULL << 53;
1751 case Attribute::Speculatable:
return 1ULL << 54;
1752 case Attribute::StrictFP:
return 1ULL << 55;
1753 case Attribute::SanitizeHWAddress:
return 1ULL << 56;
1754 case Attribute::NoCfCheck:
return 1ULL << 57;
1755 case Attribute::OptForFuzzing:
return 1ULL << 58;
1756 case Attribute::ShadowCallStack:
return 1ULL << 59;
1757 case Attribute::SpeculativeLoadHardening:
1759 case Attribute::ImmArg:
1761 case Attribute::WillReturn:
1763 case Attribute::NoFree:
1779 if (
I == Attribute::Alignment)
1780 B.addAlignmentAttr(1ULL << ((
A >> 16) - 1));
1781 else if (
I == Attribute::StackAlignment)
1782 B.addStackAlignmentAttr(1ULL << ((
A >> 26)-1));
1784 B.addTypeAttr(
I,
nullptr);
1799 unsigned Alignment = (EncodedAttrs & (0xffffULL << 16)) >> 16;
1801 "Alignment must be a power of two.");
1804 B.addAlignmentAttr(Alignment);
1806 uint64_t Attrs = ((EncodedAttrs & (0xfffffULL << 32)) >> 11) |
1807 (EncodedAttrs & 0xffff);
1812 if (Attrs & (1ULL << 9)) {
1814 Attrs &= ~(1ULL << 9);
1817 if (Attrs & (1ULL << 10)) {
1819 Attrs &= ~(1ULL << 10);
1822 if (Attrs & (1ULL << 49)) {
1824 Attrs &= ~(1ULL << 49);
1827 if (Attrs & (1ULL << 50)) {
1829 Attrs &= ~(1ULL << 50);
1832 if (Attrs & (1ULL << 53)) {
1834 Attrs &= ~(1ULL << 53);
1838 B.addMemoryAttr(ME);
1844Error BitcodeReader::parseAttributeBlock() {
1848 if (!MAttributes.empty())
1849 return error(
"Invalid multiple blocks");
1862 switch (Entry.Kind) {
1865 return error(
"Malformed block");
1878 switch (MaybeRecord.
get()) {
1884 return error(
"Invalid parameter attribute record");
1886 for (
unsigned i = 0, e =
Record.size(); i != e; i += 2) {
1896 for (
unsigned i = 0, e =
Record.size(); i != e; ++i)
1912 return Attribute::Alignment;
1914 return Attribute::AlwaysInline;
1916 return Attribute::Builtin;
1918 return Attribute::ByVal;
1920 return Attribute::InAlloca;
1922 return Attribute::Cold;
1924 return Attribute::Convergent;
1926 return Attribute::DisableSanitizerInstrumentation;
1928 return Attribute::ElementType;
1930 return Attribute::FnRetThunkExtern;
1932 return Attribute::InlineHint;
1934 return Attribute::InReg;
1936 return Attribute::JumpTable;
1938 return Attribute::Memory;
1940 return Attribute::NoFPClass;
1942 return Attribute::MinSize;
1944 return Attribute::Naked;
1946 return Attribute::Nest;
1948 return Attribute::NoAlias;
1950 return Attribute::NoBuiltin;
1952 return Attribute::NoCallback;
1954 return Attribute::NoCapture;
1956 return Attribute::NoDuplicate;
1958 return Attribute::NoFree;
1960 return Attribute::NoImplicitFloat;
1962 return Attribute::NoInline;
1964 return Attribute::NoRecurse;
1966 return Attribute::NoMerge;
1968 return Attribute::NonLazyBind;
1970 return Attribute::NonNull;
1972 return Attribute::Dereferenceable;
1974 return Attribute::DereferenceableOrNull;
1976 return Attribute::AllocAlign;
1978 return Attribute::AllocKind;
1980 return Attribute::AllocSize;
1982 return Attribute::AllocatedPointer;
1984 return Attribute::NoRedZone;
1986 return Attribute::NoReturn;
1988 return Attribute::NoSync;
1990 return Attribute::NoCfCheck;
1992 return Attribute::NoProfile;
1994 return Attribute::SkipProfile;
1996 return Attribute::NoUnwind;
1998 return Attribute::NoSanitizeBounds;
2000 return Attribute::NoSanitizeCoverage;
2002 return Attribute::NullPointerIsValid;
2004 return Attribute::OptForFuzzing;
2006 return Attribute::OptimizeForSize;
2008 return Attribute::OptimizeNone;
2010 return Attribute::ReadNone;
2012 return Attribute::ReadOnly;
2014 return Attribute::Returned;
2016 return Attribute::ReturnsTwice;
2018 return Attribute::SExt;
2020 return Attribute::Speculatable;
2022 return Attribute::StackAlignment;
2024 return Attribute::StackProtect;
2026 return Attribute::StackProtectReq;
2028 return Attribute::StackProtectStrong;
2030 return Attribute::SafeStack;
2032 return Attribute::ShadowCallStack;
2034 return Attribute::StrictFP;
2036 return Attribute::StructRet;
2038 return Attribute::SanitizeAddress;
2040 return Attribute::SanitizeHWAddress;
2042 return Attribute::SanitizeThread;
2044 return Attribute::SanitizeMemory;
2046 return Attribute::SpeculativeLoadHardening;
2048 return Attribute::SwiftError;
2050 return Attribute::SwiftSelf;
2052 return Attribute::SwiftAsync;
2054 return Attribute::UWTable;
2056 return Attribute::VScaleRange;
2058 return Attribute::WillReturn;
2060 return Attribute::WriteOnly;
2062 return Attribute::ZExt;
2064 return Attribute::ImmArg;
2066 return Attribute::SanitizeMemTag;
2068 return Attribute::Preallocated;
2070 return Attribute::NoUndef;
2072 return Attribute::ByRef;
2074 return Attribute::MustProgress;
2076 return Attribute::Hot;
2078 return Attribute::PresplitCoroutine;
2087 return error(
"Invalid alignment value");
2095 return error(
"Unknown attribute kind (" +
Twine(Code) +
")");
2100 switch (EncodedKind) {
2124Error BitcodeReader::parseAttributeGroupBlock() {
2128 if (!MAttributeGroups.empty())
2129 return error(
"Invalid multiple blocks");
2140 switch (Entry.Kind) {
2143 return error(
"Malformed block");
2156 switch (MaybeRecord.
get()) {
2161 return error(
"Invalid grp record");
2168 for (
unsigned i = 2, e =
Record.size(); i != e; ++i) {
2176 if (
Error Err = parseAttrKind(EncodedKind, &Kind))
2182 if (Kind == Attribute::ByVal)
2183 B.addByValAttr(
nullptr);
2184 else if (Kind == Attribute::StructRet)
2185 B.addStructRetAttr(
nullptr);
2186 else if (Kind == Attribute::InAlloca)
2187 B.addInAllocaAttr(
nullptr);
2188 else if (Kind == Attribute::UWTable)
2189 B.addUWTableAttr(UWTableKind::Default);
2191 B.addAttribute(Kind);
2193 return error(
"Not an enum attribute");
2194 }
else if (
Record[i] == 1) {
2196 if (
Error Err = parseAttrKind(
Record[++i], &Kind))
2199 return error(
"Not an int attribute");
2200 if (Kind == Attribute::Alignment)
2201 B.addAlignmentAttr(
Record[++i]);
2202 else if (Kind == Attribute::StackAlignment)
2203 B.addStackAlignmentAttr(
Record[++i]);
2204 else if (Kind == Attribute::Dereferenceable)
2205 B.addDereferenceableAttr(
Record[++i]);
2206 else if (Kind == Attribute::DereferenceableOrNull)
2207 B.addDereferenceableOrNullAttr(
Record[++i]);
2208 else if (Kind == Attribute::AllocSize)
2209 B.addAllocSizeAttrFromRawRepr(
Record[++i]);
2210 else if (Kind == Attribute::VScaleRange)
2211 B.addVScaleRangeAttrFromRawRepr(
Record[++i]);
2212 else if (Kind == Attribute::UWTable)
2214 else if (Kind == Attribute::AllocKind)
2216 else if (Kind == Attribute::Memory)
2218 else if (Kind == Attribute::NoFPClass)
2226 while (
Record[i] != 0 && i != e)
2228 assert(
Record[i] == 0 &&
"Kind string not null terminated");
2233 while (
Record[i] != 0 && i != e)
2235 assert(
Record[i] == 0 &&
"Value string not null terminated");
2238 B.addAttribute(KindStr.
str(), ValStr.
str());
2240 bool HasType =
Record[i] == 6;
2242 if (
Error Err = parseAttrKind(
Record[++i], &Kind))
2245 return error(
"Not a type attribute");
2247 B.addTypeAttr(Kind, HasType ? getTypeByID(
Record[++i]) :
nullptr);
2249 return error(
"Invalid attribute group entry");
2254 B.addMemoryAttr(ME);
2264Error BitcodeReader::parseTypeTable() {
2268 return parseTypeTableBody();
2271Error BitcodeReader::parseTypeTableBody() {
2272 if (!TypeList.empty())
2273 return error(
"Invalid multiple blocks");
2276 unsigned NumRecords = 0;
2287 switch (Entry.Kind) {
2290 return error(
"Malformed block");
2292 if (NumRecords != TypeList.size())
2293 return error(
"Malformed block");
2302 Type *ResultTy =
nullptr;
2307 switch (MaybeRecord.
get()) {
2309 return error(
"Invalid value");
2314 return error(
"Invalid numentry record");
2315 TypeList.resize(
Record[0]);
2358 return error(
"Invalid integer record");
2363 return error(
"Bitwidth for integer type out of range");
2370 return error(
"Invalid pointer record");
2374 ResultTy = getTypeByID(
Record[0]);
2376 !PointerType::isValidElementType(ResultTy))
2377 return error(
"Invalid type");
2384 return error(
"Invalid opaque pointer record");
2387 "Opaque pointers are only supported in -opaque-pointers mode");
2396 return error(
"Invalid function record");
2398 for (
unsigned i = 3, e =
Record.size(); i != e; ++i) {
2405 ResultTy = getTypeByID(
Record[2]);
2406 if (!ResultTy || ArgTys.
size() <
Record.size()-3)
2407 return error(
"Invalid type");
2410 ResultTy = FunctionType::get(ResultTy, ArgTys,
Record[0]);
2416 return error(
"Invalid function record");
2418 for (
unsigned i = 2, e =
Record.size(); i != e; ++i) {
2420 if (!FunctionType::isValidArgumentType(
T))
2421 return error(
"Invalid function argument type");
2428 ResultTy = getTypeByID(
Record[1]);
2429 if (!ResultTy || ArgTys.
size() <
Record.size()-2)
2430 return error(
"Invalid type");
2433 ResultTy = FunctionType::get(ResultTy, ArgTys,
Record[0]);
2438 return error(
"Invalid anon struct record");
2440 for (
unsigned i = 1, e =
Record.size(); i != e; ++i) {
2447 return error(
"Invalid type");
2454 return error(
"Invalid struct name record");
2459 return error(
"Invalid named struct record");
2461 if (NumRecords >= TypeList.size())
2462 return error(
"Invalid TYPE table");
2465 StructType *Res = cast_or_null<StructType>(TypeList[NumRecords]);
2468 TypeList[NumRecords] =
nullptr;
2470 Res = createIdentifiedStructType(Context, TypeName);
2474 for (
unsigned i = 1, e =
Record.size(); i != e; ++i) {
2481 return error(
"Invalid named struct record");
2489 return error(
"Invalid opaque type record");
2491 if (NumRecords >= TypeList.size())
2492 return error(
"Invalid TYPE table");
2495 StructType *Res = cast_or_null<StructType>(TypeList[NumRecords]);
2498 TypeList[NumRecords] =
nullptr;
2500 Res = createIdentifiedStructType(Context, TypeName);
2507 return error(
"Invalid target extension type record");
2509 if (NumRecords >= TypeList.size())
2510 return error(
"Invalid TYPE table");
2513 return error(
"Too many type parameters");
2515 unsigned NumTys =
Record[0];
2518 for (
unsigned i = 0; i < NumTys; i++) {
2522 return error(
"Invalid type");
2525 for (
unsigned i = NumTys + 1, e =
Record.size(); i < e; i++) {
2526 if (
Record[i] > UINT_MAX)
2527 return error(
"Integer parameter too large");
2536 return error(
"Invalid array type record");
2537 ResultTy = getTypeByID(
Record[1]);
2538 if (!ResultTy || !ArrayType::isValidElementType(ResultTy))
2539 return error(
"Invalid type");
2541 ResultTy = ArrayType::get(ResultTy,
Record[0]);
2546 return error(
"Invalid vector type record");
2548 return error(
"Invalid vector length");
2549 ResultTy = getTypeByID(
Record[1]);
2550 if (!ResultTy || !VectorType::isValidElementType(ResultTy))
2551 return error(
"Invalid type");
2554 ResultTy = VectorType::get(ResultTy,
Record[0], Scalable);
2558 if (NumRecords >= TypeList.size())
2559 return error(
"Invalid TYPE table");
2560 if (TypeList[NumRecords])
2562 "Invalid TYPE table: Only named structs can be forward referenced");
2563 assert(ResultTy &&
"Didn't read a type?");
2564 TypeList[NumRecords] = ResultTy;
2565 if (!ContainedIDs.
empty())
2566 ContainedTypeIDs[NumRecords] = std::move(ContainedIDs);
2571Error BitcodeReader::parseOperandBundleTags() {
2575 if (!BundleTags.empty())
2576 return error(
"Invalid multiple blocks");
2586 switch (Entry.Kind) {
2589 return error(
"Malformed block");
2603 return error(
"Invalid operand bundle record");
2606 BundleTags.emplace_back();
2608 return error(
"Invalid operand bundle record");
2613Error BitcodeReader::parseSyncScopeNames() {
2618 return error(
"Invalid multiple synchronization scope names blocks");
2627 switch (Entry.Kind) {
2630 return error(
"Malformed block");
2633 return error(
"Invalid empty synchronization scope names block");
2647 return error(
"Invalid sync scope record");
2651 return error(
"Invalid sync scope record");
2660 unsigned NameIndex,
Triple &TT) {
2663 return error(
"Invalid record");
2664 unsigned ValueID =
Record[0];
2665 if (ValueID >= ValueList.
size() || !ValueList[ValueID])
2666 return error(
"Invalid record");
2667 Value *
V = ValueList[ValueID];
2671 return error(
"Invalid value name");
2672 V->setName(NameStr);
2673 auto *GO = dyn_cast<GlobalObject>(V);
2674 if (GO && ImplicitComdatObjects.
contains(GO) &&
TT.supportsCOMDAT())
2687 return std::move(JumpFailed);
2693 return error(
"Expected value symbol table subblock");
2697void BitcodeReader::setDeferredFunctionInfo(
unsigned FuncBitcodeOffsetDelta,
2704 uint64_t FuncBitOffset = FuncWordOffset * 32;
2705 DeferredFunctionInfo[
F] = FuncBitOffset + FuncBitcodeOffsetDelta;
2709 if (FuncBitOffset > LastFunctionBlockBit)
2710 LastFunctionBlockBit = FuncBitOffset;
2714Error BitcodeReader::parseGlobalValueSymbolTable() {
2715 unsigned FuncBitcodeOffsetDelta =
2728 switch (Entry.Kind) {
2731 return error(
"Malformed block");
2742 switch (MaybeRecord.
get()) {
2744 unsigned ValueID =
Record[0];
2745 if (ValueID >= ValueList.
size() || !ValueList[ValueID])
2746 return error(
"Invalid value reference in symbol table");
2747 setDeferredFunctionInfo(FuncBitcodeOffsetDelta,
2748 cast<Function>(ValueList[ValueID]),
Record);
2764 if (!MaybeCurrentBit)
2766 CurrentBit = MaybeCurrentBit.
get();
2769 if (
Error Err = parseGlobalValueSymbolTable())
2771 if (
Error JumpFailed = Stream.JumpToBit(CurrentBit))
2790 unsigned FuncBitcodeOffsetDelta =
2809 switch (Entry.Kind) {
2812 return error(
"Malformed block");
2815 if (
Error JumpFailed = Stream.JumpToBit(CurrentBit))
2828 switch (MaybeRecord.
get()) {
2847 if (
auto *
F = dyn_cast<Function>(V))
2848 setDeferredFunctionInfo(FuncBitcodeOffsetDelta,
F,
Record);
2853 return error(
"Invalid bbentry record");
2856 return error(
"Invalid bbentry record");
2878Error BitcodeReader::resolveGlobalAndIndirectSymbolInits() {
2879 std::vector<std::pair<GlobalVariable *, unsigned>> GlobalInitWorklist;
2880 std::vector<std::pair<GlobalValue *, unsigned>> IndirectSymbolInitWorklist;
2881 std::vector<FunctionOperandInfo> FunctionOperandWorklist;
2883 GlobalInitWorklist.swap(GlobalInits);
2884 IndirectSymbolInitWorklist.swap(IndirectSymbolInits);
2885 FunctionOperandWorklist.swap(FunctionOperands);
2887 while (!GlobalInitWorklist.empty()) {
2888 unsigned ValID = GlobalInitWorklist.back().second;
2891 GlobalInits.push_back(GlobalInitWorklist.back());
2896 GlobalInitWorklist.back().first->setInitializer(MaybeC.
get());
2898 GlobalInitWorklist.pop_back();
2901 while (!IndirectSymbolInitWorklist.empty()) {
2902 unsigned ValID = IndirectSymbolInitWorklist.back().second;
2904 IndirectSymbolInits.push_back(IndirectSymbolInitWorklist.back());
2910 GlobalValue *GV = IndirectSymbolInitWorklist.back().first;
2911 if (
auto *GA = dyn_cast<GlobalAlias>(GV)) {
2913 return error(
"Alias and aliasee types don't match");
2915 }
else if (
auto *GI = dyn_cast<GlobalIFunc>(GV)) {
2922 return error(
"Expected an alias or an ifunc");
2925 IndirectSymbolInitWorklist.pop_back();
2928 while (!FunctionOperandWorklist.empty()) {
2929 FunctionOperandInfo &
Info = FunctionOperandWorklist.back();
2930 if (
Info.PersonalityFn) {
2931 unsigned ValID =
Info.PersonalityFn - 1;
2936 Info.F->setPersonalityFn(MaybeC.
get());
2937 Info.PersonalityFn = 0;
2946 Info.F->setPrefixData(MaybeC.
get());
2950 if (
Info.Prologue) {
2956 Info.F->setPrologueData(MaybeC.
get());
2960 if (
Info.PersonalityFn ||
Info.Prefix ||
Info.Prologue)
2961 FunctionOperands.push_back(Info);
2962 FunctionOperandWorklist.pop_back();
2971 BitcodeReader::decodeSignRotatedValue);
2973 return APInt(TypeBits, Words);
2976Error BitcodeReader::parseConstants() {
2984 unsigned Int32TyID = getVirtualTypeID(CurTy);
2985 unsigned CurTyID = Int32TyID;
2986 Type *CurElemTy =
nullptr;
2987 unsigned NextCstNo = ValueList.
size();
2995 switch (Entry.Kind) {
2998 return error(
"Malformed block");
3000 if (NextCstNo != ValueList.
size())
3001 return error(
"Invalid constant reference");
3015 switch (
unsigned BitCode = MaybeBitCode.
get()) {
3025 return error(
"Invalid settype record");
3026 if (
Record[0] >= TypeList.size() || !TypeList[
Record[0]])
3027 return error(
"Invalid settype record");
3028 if (TypeList[
Record[0]] == VoidType)
3029 return error(
"Invalid constant type");
3031 CurTy = TypeList[CurTyID];
3032 CurElemTy = getPtrElementTypeByID(CurTyID);
3036 return error(
"Invalid type for a constant null value");
3037 if (
auto *TETy = dyn_cast<TargetExtType>(CurTy))
3039 return error(
"Invalid type for a constant null value");
3044 return error(
"Invalid integer const record");
3049 return error(
"Invalid wide integer const record");
3059 return error(
"Invalid float const record");
3075 Rearrange[0] = (
Record[1] & 0xffffLL) | (
Record[0] << 16);
3076 Rearrange[1] =
Record[0] >> 48;
3078 APInt(80, Rearrange)));
3092 return error(
"Invalid aggregate record");
3096 for (
unsigned i = 0; i !=
Size; ++i)
3099 if (isa<StructType>(CurTy)) {
3100 V = BitcodeConstant::create(
3101 Alloc, CurTy, BitcodeConstant::ConstantStructOpcode, Elts);
3102 }
else if (isa<ArrayType>(CurTy)) {
3103 V = BitcodeConstant::create(Alloc, CurTy,
3104 BitcodeConstant::ConstantArrayOpcode, Elts);
3105 }
else if (isa<VectorType>(CurTy)) {
3106 V = BitcodeConstant::create(
3107 Alloc, CurTy, BitcodeConstant::ConstantVectorOpcode, Elts);
3116 return error(
"Invalid string record");
3125 return error(
"Invalid data record");
3128 if (
auto *Array = dyn_cast<ArrayType>(CurTy))
3129 EltTy =
Array->getElementType();
3131 EltTy = cast<VectorType>(CurTy)->getElementType();
3134 if (isa<VectorType>(CurTy))
3140 if (isa<VectorType>(CurTy))
3146 if (isa<VectorType>(CurTy))
3152 if (isa<VectorType>(CurTy))
3158 if (isa<VectorType>(CurTy))
3164 if (isa<VectorType>(CurTy))
3170 if (isa<VectorType>(CurTy))
3176 if (isa<VectorType>(CurTy))
3181 return error(
"Invalid type for value");
3187 return error(
"Invalid unary op constexpr record");
3192 V = BitcodeConstant::create(Alloc, CurTy, Opc, (
unsigned)
Record[1]);
3198 return error(
"Invalid binary op constexpr record");
3204 if (
Record.size() >= 4) {
3205 if (Opc == Instruction::Add ||
3206 Opc == Instruction::Sub ||
3207 Opc == Instruction::Mul ||
3208 Opc == Instruction::Shl) {
3213 }
else if (Opc == Instruction::SDiv ||
3214 Opc == Instruction::UDiv ||
3215 Opc == Instruction::LShr ||
3216 Opc == Instruction::AShr) {
3218 Flags |= SDivOperator::IsExact;
3221 V = BitcodeConstant::create(Alloc, CurTy, {(uint8_t)Opc, Flags},
3228 return error(
"Invalid cast constexpr record");
3233 unsigned OpTyID =
Record[1];
3234 Type *OpTy = getTypeByID(OpTyID);
3236 return error(
"Invalid cast constexpr record");
3237 V = BitcodeConstant::create(Alloc, CurTy, Opc, (
unsigned)
Record[2]);
3246 return error(
"Constant GEP record must have at least two elements");
3248 Type *PointeeType =
nullptr;
3251 PointeeType = getTypeByID(
Record[OpNum++]);
3253 bool InBounds =
false;
3254 std::optional<unsigned> InRangeIndex;
3258 InRangeIndex =
Op >> 1;
3263 unsigned BaseTypeID =
Record[OpNum];
3264 while (OpNum !=
Record.size()) {
3265 unsigned ElTyID =
Record[OpNum++];
3266 Type *ElTy = getTypeByID(ElTyID);
3268 return error(
"Invalid getelementptr constexpr record");
3272 if (Elts.
size() < 1)
3273 return error(
"Invalid gep with no operands");
3277 BaseTypeID = getContainedTypeID(BaseTypeID, 0);
3278 BaseType = getTypeByID(BaseTypeID);
3283 return error(
"GEP base operand must be pointer or vector of pointer");
3286 PointeeType = getPtrElementTypeByID(BaseTypeID);
3288 return error(
"Missing element type for old-style constant GEP");
3289 }
else if (!OrigPtrTy->isOpaqueOrPointeeTypeMatches(PointeeType))
3290 return error(
"Explicit gep operator type does not match pointee type "
3291 "of pointer operand");
3293 V = BitcodeConstant::create(Alloc, CurTy,
3294 {Instruction::GetElementPtr, InBounds,
3295 InRangeIndex.value_or(-1), PointeeType},
3301 return error(
"Invalid select constexpr record");
3303 V = BitcodeConstant::create(
3304 Alloc, CurTy, Instruction::Select,
3311 return error(
"Invalid extractelement constexpr record");
3312 unsigned OpTyID =
Record[0];
3314 dyn_cast_or_null<VectorType>(getTypeByID(OpTyID));
3316 return error(
"Invalid extractelement constexpr record");
3318 if (
Record.size() == 4) {
3319 unsigned IdxTyID =
Record[2];
3320 Type *IdxTy = getTypeByID(IdxTyID);
3322 return error(
"Invalid extractelement constexpr record");
3328 V = BitcodeConstant::create(Alloc, CurTy, Instruction::ExtractElement,
3334 VectorType *OpTy = dyn_cast<VectorType>(CurTy);
3335 if (
Record.size() < 3 || !OpTy)
3336 return error(
"Invalid insertelement constexpr record");
3338 if (
Record.size() == 4) {
3339 unsigned IdxTyID =
Record[2];
3340 Type *IdxTy = getTypeByID(IdxTyID);
3342 return error(
"Invalid insertelement constexpr record");
3348 V = BitcodeConstant::create(
3349 Alloc, CurTy, Instruction::InsertElement,
3354 VectorType *OpTy = dyn_cast<VectorType>(CurTy);
3355 if (
Record.size() < 3 || !OpTy)
3356 return error(
"Invalid shufflevector constexpr record");
3357 V = BitcodeConstant::create(
3358 Alloc, CurTy, Instruction::ShuffleVector,
3363 VectorType *RTy = dyn_cast<VectorType>(CurTy);
3365 dyn_cast_or_null<VectorType>(getTypeByID(
Record[0]));
3366 if (
Record.size() < 4 || !RTy || !OpTy)
3367 return error(
"Invalid shufflevector constexpr record");
3368 V = BitcodeConstant::create(
3369 Alloc, CurTy, Instruction::ShuffleVector,
3375 return error(
"Invalid cmp constexpt record");
3376 unsigned OpTyID =
Record[0];
3377 Type *OpTy = getTypeByID(OpTyID);
3379 return error(
"Invalid cmp constexpr record");
3380 V = BitcodeConstant::create(
3383 : Instruction::ICmp),
3392 return error(
"Invalid inlineasm record");
3393 std::string AsmStr, ConstrStr;
3394 bool HasSideEffects =
Record[0] & 1;
3395 bool IsAlignStack =
Record[0] >> 1;
3396 unsigned AsmStrSize =
Record[1];
3397 if (2+AsmStrSize >=
Record.size())
3398 return error(
"Invalid inlineasm record");
3399 unsigned ConstStrSize =
Record[2+AsmStrSize];
3400 if (3+AsmStrSize+ConstStrSize >
Record.size())
3401 return error(
"Invalid inlineasm record");
3403 for (
unsigned i = 0; i != AsmStrSize; ++i)
3404 AsmStr += (
char)
Record[2+i];
3405 for (
unsigned i = 0; i != ConstStrSize; ++i)
3406 ConstrStr += (
char)
Record[3+AsmStrSize+i];
3409 return error(
"Missing element type for old-style inlineasm");
3411 HasSideEffects, IsAlignStack);
3418 return error(
"Invalid inlineasm record");
3419 std::string AsmStr, ConstrStr;
3420 bool HasSideEffects =
Record[0] & 1;
3421 bool IsAlignStack = (
Record[0] >> 1) & 1;
3422 unsigned AsmDialect =
Record[0] >> 2;
3423 unsigned AsmStrSize =
Record[1];
3424 if (2+AsmStrSize >=
Record.size())
3425 return error(
"Invalid inlineasm record");
3426 unsigned ConstStrSize =
Record[2+AsmStrSize];
3427 if (3+AsmStrSize+ConstStrSize >
Record.size())
3428 return error(
"Invalid inlineasm record");
3430 for (
unsigned i = 0; i != AsmStrSize; ++i)
3431 AsmStr += (
char)
Record[2+i];
3432 for (
unsigned i = 0; i != ConstStrSize; ++i)
3433 ConstrStr += (
char)
Record[3+AsmStrSize+i];
3436 return error(
"Missing element type for old-style inlineasm");
3438 HasSideEffects, IsAlignStack,
3445 return error(
"Invalid inlineasm record");
3447 std::string AsmStr, ConstrStr;
3448 bool HasSideEffects =
Record[OpNum] & 1;
3449 bool IsAlignStack = (
Record[OpNum] >> 1) & 1;
3450 unsigned AsmDialect = (
Record[OpNum] >> 2) & 1;
3451 bool CanThrow = (
Record[OpNum] >> 3) & 1;
3453 unsigned AsmStrSize =
Record[OpNum];
3455 if (OpNum + AsmStrSize >=
Record.size())
3456 return error(
"Invalid inlineasm record");
3457 unsigned ConstStrSize =
Record[OpNum + AsmStrSize];
3458 if (OpNum + 1 + AsmStrSize + ConstStrSize >
Record.size())
3459 return error(
"Invalid inlineasm record");
3461 for (
unsigned i = 0; i != AsmStrSize; ++i)
3462 AsmStr += (
char)
Record[OpNum + i];
3464 for (
unsigned i = 0; i != ConstStrSize; ++i)
3465 ConstrStr += (
char)
Record[OpNum + AsmStrSize + i];
3468 return error(
"Missing element type for old-style inlineasm");
3470 HasSideEffects, IsAlignStack,
3477 return error(
"Invalid inlineasm record");
3479 auto *FnTy = dyn_cast_or_null<FunctionType>(getTypeByID(
Record[OpNum]));
3482 return error(
"Invalid inlineasm record");
3483 std::string AsmStr, ConstrStr;
3484 bool HasSideEffects =
Record[OpNum] & 1;
3485 bool IsAlignStack = (
Record[OpNum] >> 1) & 1;
3486 unsigned AsmDialect = (
Record[OpNum] >> 2) & 1;
3487 bool CanThrow = (
Record[OpNum] >> 3) & 1;
3489 unsigned AsmStrSize =
Record[OpNum];
3491 if (OpNum + AsmStrSize >=
Record.size())
3492 return error(
"Invalid inlineasm record");
3493 unsigned ConstStrSize =
Record[OpNum + AsmStrSize];
3494 if (OpNum + 1 + AsmStrSize + ConstStrSize >
Record.size())
3495 return error(
"Invalid inlineasm record");
3497 for (
unsigned i = 0; i != AsmStrSize; ++i)
3498 AsmStr += (
char)
Record[OpNum + i];
3500 for (
unsigned i = 0; i != ConstStrSize; ++i)
3501 ConstrStr += (
char)
Record[OpNum + AsmStrSize + i];
3503 V =
InlineAsm::get(FnTy, AsmStr, ConstrStr, HasSideEffects, IsAlignStack,
3509 return error(
"Invalid blockaddress record");
3510 unsigned FnTyID =
Record[0];
3511 Type *FnTy = getTypeByID(FnTyID);
3513 return error(
"Invalid blockaddress record");
3514 V = BitcodeConstant::create(
3522 return error(
"Invalid dso_local record");
3523 unsigned GVTyID =
Record[0];
3524 Type *GVTy = getTypeByID(GVTyID);
3526 return error(
"Invalid dso_local record");
3527 V = BitcodeConstant::create(
3528 Alloc, CurTy, BitcodeConstant::DSOLocalEquivalentOpcode,
Record[1]);
3533 return error(
"Invalid no_cfi record");
3534 unsigned GVTyID =
Record[0];
3535 Type *GVTy = getTypeByID(GVTyID);
3537 return error(
"Invalid no_cfi record");
3538 V = BitcodeConstant::create(Alloc, CurTy, BitcodeConstant::NoCFIOpcode,
3544 assert(
V->getType() == getTypeByID(CurTyID) &&
"Incorrect result type ID");
3551Error BitcodeReader::parseUseLists() {
3564 switch (Entry.Kind) {
3567 return error(
"Malformed block");
3581 switch (MaybeRecord.
get()) {
3589 if (RecordLength < 3)
3591 return error(
"Invalid record");
3592 unsigned ID =
Record.pop_back_val();
3596 assert(
ID < FunctionBBs.size() &&
"Basic block not found");
3597 V = FunctionBBs[
ID];
3600 unsigned NumUses = 0;
3602 for (
const Use &U :
V->materialized_uses()) {
3603 if (++NumUses >
Record.size())
3605 Order[&
U] =
Record[NumUses - 1];
3612 V->sortUseList([&](
const Use &L,
const Use &R) {
3623Error BitcodeReader::rememberAndSkipMetadata() {
3625 uint64_t CurBit = Stream.GetCurrentBitNo();
3626 DeferredMetadataInfo.push_back(CurBit);
3629 if (
Error Err = Stream.SkipBlock())
3634Error BitcodeReader::materializeMetadata() {
3635 for (
uint64_t BitPos : DeferredMetadataInfo) {
3637 if (
Error JumpFailed = Stream.JumpToBit(BitPos))
3639 if (
Error Err = MDLoader->parseModuleMetadata())
3650 for (
const MDOperand &MDOptions : cast<MDNode>(Val)->operands())
3651 LinkerOpts->
addOperand(cast<MDNode>(MDOptions));
3655 DeferredMetadataInfo.clear();
3659void BitcodeReader::setStripDebugInfo() {
StripDebugInfo =
true; }
3663Error BitcodeReader::rememberAndSkipFunctionBody() {
3665 if (FunctionsWithBodies.empty())
3666 return error(
"Insufficient function protos");
3669 FunctionsWithBodies.pop_back();
3672 uint64_t CurBit = Stream.GetCurrentBitNo();
3674 (DeferredFunctionInfo[Fn] == 0 || DeferredFunctionInfo[Fn] == CurBit) &&
3675 "Mismatch between VST and scanned function offsets");
3676 DeferredFunctionInfo[Fn] = CurBit;
3679 if (
Error Err = Stream.SkipBlock())
3684Error BitcodeReader::globalCleanup() {
3686 if (
Error Err = resolveGlobalAndIndirectSymbolInits())
3688 if (!GlobalInits.empty() || !IndirectSymbolInits.empty())
3689 return error(
"Malformed global initializer set");
3694 MDLoader->upgradeDebugIntrinsics(
F);
3697 UpgradedIntrinsics[&
F] = NewFn;
3703 std::vector<std::pair<GlobalVariable *, GlobalVariable *>> UpgradedVariables;
3706 UpgradedVariables.emplace_back(&GV, Upgraded);
3707 for (
auto &Pair : UpgradedVariables) {
3708 Pair.first->eraseFromParent();
3709 TheModule->insertGlobalVariable(Pair.second);
3714 std::vector<std::pair<GlobalVariable *, unsigned>>().
swap(GlobalInits);
3715 std::vector<std::pair<GlobalValue *, unsigned>>().
swap(IndirectSymbolInits);
3723Error BitcodeReader::rememberAndSkipFunctionBodies() {
3724 if (
Error JumpFailed = Stream.JumpToBit(NextUnreadBit))
3727 if (Stream.AtEndOfStream())
3728 return error(
"Could not find function in stream");
3730 if (!SeenFirstFunctionBody)
3731 return error(
"Trying to materialize functions before seeing function blocks");
3735 assert(SeenValueSymbolTable);
3745 switch (Entry.Kind) {
3747 return error(
"Expect SubBlock");
3751 return error(
"Expect function block");
3753 if (
Error Err = rememberAndSkipFunctionBody())
3755 NextUnreadBit = Stream.GetCurrentBitNo();
3762Error BitcodeReaderBase::readBlockInfo() {
3764 Stream.ReadBlockInfoBlock();
3765 if (!MaybeNewBlockInfo)
3767 std::optional<BitstreamBlockInfo> NewBlockInfo =
3768 std::move(MaybeNewBlockInfo.
get());
3770 return error(
"Malformed block");
3771 BlockInfo = std::move(*NewBlockInfo);
3782 return error(
"Invalid record");
3784 std::string OldFormatName;
3787 return error(
"Invalid record");
3788 unsigned ComdatNameSize =
Record[1];
3789 if (ComdatNameSize >
Record.size() - 2)
3790 return error(
"Comdat name size too large");
3791 OldFormatName.reserve(ComdatNameSize);
3792 for (
unsigned i = 0; i != ComdatNameSize; ++i)
3793 OldFormatName += (
char)
Record[2 + i];
3794 Name = OldFormatName;
3797 C->setSelectionKind(SK);
3798 ComdatList.push_back(
C);
3812 Meta.NoAddress =
true;
3814 Meta.NoHWAddress =
true;
3818 Meta.IsDynInit =
true;
3832 return error(
"Invalid record");
3833 unsigned TyID =
Record[0];
3834 Type *Ty = getTypeByID(TyID);
3836 return error(
"Invalid record");
3838 bool explicitType =
Record[1] & 2;
3844 return error(
"Invalid type for value");
3845 AddressSpace = cast<PointerType>(Ty)->getAddressSpace();
3846 TyID = getContainedTypeID(TyID);
3847 Ty = getTypeByID(TyID);
3849 return error(
"Missing element type for old-style global");
3855 if (
Error Err = parseAlignmentValue(
Record[4], Alignment))
3859 if (
Record[5] - 1 >= SectionTable.size())
3860 return error(
"Invalid ID");
3877 bool ExternallyInitialized =
false;
3879 ExternallyInitialized =
Record[9];
3891 if (
Record.size() > 10) {
3903 if (
unsigned InitID =
Record[2])
3904 GlobalInits.push_back(std::make_pair(NewGV, InitID - 1));
3906 if (
Record.size() > 11) {
3907 if (
unsigned ComdatID =
Record[11]) {
3908 if (ComdatID > ComdatList.size())
3909 return error(
"Invalid global variable comdat ID");
3910 NewGV->
setComdat(ComdatList[ComdatID - 1]);
3913 ImplicitComdatObjects.
insert(NewGV);
3916 if (
Record.size() > 12) {
3921 if (
Record.size() > 13) {
3939void BitcodeReader::callValueTypeCallback(
Value *
F,
unsigned TypeID) {
3940 if (ValueTypeCallback) {
3941 (*ValueTypeCallback)(
3942 F,
TypeID, [
this](
unsigned I) {
return getTypeByID(
I); },
3943 [
this](
unsigned I,
unsigned J) {
return getContainedTypeID(
I, J); });
3956 return error(
"Invalid record");
3957 unsigned FTyID =
Record[0];
3958 Type *FTy = getTypeByID(FTyID);
3960 return error(
"Invalid record");
3961 if (isa<PointerType>(FTy)) {
3962 FTyID = getContainedTypeID(FTyID, 0);
3963 FTy = getTypeByID(FTyID);
3965 return error(
"Missing element type for old-style function");
3968 if (!isa<FunctionType>(FTy))
3969 return error(
"Invalid type for value");
3972 return error(
"Invalid calling convention ID");
3974 unsigned AddrSpace = TheModule->getDataLayout().getProgramAddressSpace();
3980 AddrSpace,
Name, TheModule);
3983 "Incorrect fully specified type provided for function");
3984 FunctionTypeIDs[
Func] = FTyID;
3986 Func->setCallingConv(
CC);
3987 bool isProto =
Record[2];
3991 callValueTypeCallback(Func, FTyID);
3996 for (
unsigned i = 0; i !=
Func->arg_size(); ++i) {
3998 Attribute::InAlloca}) {
3999 if (!
Func->hasParamAttribute(i, Kind))
4002 if (
Func->getParamAttribute(i, Kind).getValueAsType())
4005 Func->removeParamAttr(i, Kind);
4007 unsigned ParamTypeID = getContainedTypeID(FTyID, i + 1);
4008 Type *PtrEltTy = getPtrElementTypeByID(ParamTypeID);
4010 return error(
"Missing param element type for attribute upgrade");
4014 case Attribute::ByVal:
4017 case Attribute::StructRet:
4020 case Attribute::InAlloca:
4027 Func->addParamAttr(i, NewAttr);
4032 !
Func->arg_empty() && !
Func->hasParamAttribute(0, Attribute::ByVal)) {
4033 unsigned ParamTypeID = getContainedTypeID(FTyID, 1);
4034 Type *ByValTy = getPtrElementTypeByID(ParamTypeID);
4036 return error(
"Missing param element type for x86_intrcc upgrade");
4038 Func->addParamAttr(0, NewAttr);
4042 if (
Error Err = parseAlignmentValue(
Record[5], Alignment))
4045 Func->setAlignment(*Alignment);
4047 if (
Record[6] - 1 >= SectionTable.size())
4048 return error(
"Invalid ID");
4049 Func->setSection(SectionTable[
Record[6] - 1]);
4053 if (!
Func->hasLocalLinkage())
4056 if (
Record[8] - 1 >= GCTable.size())
4057 return error(
"Invalid ID");
4063 Func->setUnnamedAddr(UnnamedAddr);
4065 FunctionOperandInfo OperandInfo = {
Func, 0, 0, 0};
4067 OperandInfo.Prologue =
Record[10];
4069 if (
Record.size() > 11) {
4071 if (!
Func->hasLocalLinkage()) {
4078 if (
Record.size() > 12) {
4079 if (
unsigned ComdatID =
Record[12]) {
4080 if (ComdatID > ComdatList.size())
4081 return error(
"Invalid function comdat ID");
4082 Func->setComdat(ComdatList[ComdatID - 1]);
4085 ImplicitComdatObjects.
insert(Func);
4089 OperandInfo.Prefix =
Record[13];
4092 OperandInfo.PersonalityFn =
Record[14];
4094 if (
Record.size() > 15) {
4103 if (
Record.size() > 18 && Strtab.data() &&
4108 ValueList.
push_back(Func, getVirtualTypeID(
Func->getType(), FTyID));
4110 if (OperandInfo.PersonalityFn || OperandInfo.Prefix || OperandInfo.Prologue)
4111 FunctionOperands.push_back(OperandInfo);
4116 Func->setIsMaterializable(
true);
4117 FunctionsWithBodies.push_back(Func);
4118 DeferredFunctionInfo[
Func] = 0;
4123Error BitcodeReader::parseGlobalIndirectSymbolRecord(
4137 if (
Record.size() < (3 + (
unsigned)NewRecord))
4138 return error(
"Invalid record");
4143 return error(
"Invalid record");
4147 auto *PTy = dyn_cast<PointerType>(Ty);
4149 return error(
"Invalid type for value");
4150 AddrSpace = PTy->getAddressSpace();
4152 Ty = getTypeByID(
TypeID);
4154 return error(
"Missing element type for old-style indirect symbol");
4156 AddrSpace =
Record[OpNum++];
4159 auto Val =
Record[OpNum++];
4168 nullptr, TheModule);
4172 if (OpNum !=
Record.size()) {
4173 auto VisInd = OpNum++;
4179 if (OpNum !=
Record.size()) {
4180 auto S =
Record[OpNum++];
4187 if (OpNum !=
Record.size())
4189 if (OpNum !=
Record.size())
4192 if (OpNum !=
Record.size())
4197 if (OpNum + 1 <
Record.size()) {
4204 IndirectSymbolInits.push_back(std::make_pair(NewGA, Val));
4209 bool ShouldLazyLoadMetadata,
4211 this->ValueTypeCallback = std::move(Callbacks.
ValueType);
4213 if (
Error JumpFailed = Stream.JumpToBit(ResumeBit))
4222 bool ResolvedDataLayout =
false;
4227 std::string TentativeDataLayoutStr = TheModule->getDataLayoutStr();
4229 auto ResolveDataLayout = [&]() ->
Error {
4230 if (ResolvedDataLayout)
4234 ResolvedDataLayout =
true;
4238 TentativeDataLayoutStr, TheModule->getTargetTriple());
4242 if (
auto LayoutOverride = (*Callbacks.
DataLayout)(
4243 TheModule->getTargetTriple(), TentativeDataLayoutStr))
4244 TentativeDataLayoutStr = *LayoutOverride;
4252 TheModule->setDataLayout(MaybeDL.
get());
4263 switch (Entry.Kind) {
4265 return error(
"Malformed block");
4267 if (
Error Err = ResolveDataLayout())
4269 return globalCleanup();
4274 if (
Error Err = Stream.SkipBlock())
4278 if (
Error Err = readBlockInfo())
4282 if (
Error Err = parseAttributeBlock())
4286 if (
Error Err = parseAttributeGroupBlock())
4290 if (
Error Err = parseTypeTable())
4294 if (!SeenValueSymbolTable) {
4300 assert(VSTOffset == 0 || FunctionsWithBodies.empty());
4301 if (
Error Err = parseValueSymbolTable())
4303 SeenValueSymbolTable =
true;
4308 if (
Error Err = Stream.SkipBlock())
4313 if (
Error Err = parseConstants())
4315 if (
Error Err = resolveGlobalAndIndirectSymbolInits())
4319 if (ShouldLazyLoadMetadata) {
4320 if (
Error Err = rememberAndSkipMetadata())
4324 assert(DeferredMetadataInfo.empty() &&
"Unexpected deferred metadata");
4325 if (
Error Err = MDLoader->parseModuleMetadata())
4329 if (
Error Err = MDLoader->parseMetadataKinds())
4333 if (
Error Err = ResolveDataLayout())
4338 if (!SeenFirstFunctionBody) {
4339 std::reverse(FunctionsWithBodies.begin(), FunctionsWithBodies.end());
4340 if (
Error Err = globalCleanup())
4342 SeenFirstFunctionBody =
true;
4345 if (VSTOffset > 0) {
4349 if (!SeenValueSymbolTable) {
4350 if (
Error Err = BitcodeReader::parseValueSymbolTable(VSTOffset))
4352 SeenValueSymbolTable =
true;
4364 if (
Error Err = Stream.SkipBlock())
4374 if (
Error Err = rememberAndSkipFunctionBody())
4381 if (SeenValueSymbolTable) {
4382 NextUnreadBit = Stream.GetCurrentBitNo();
4385 return globalCleanup();
4389 if (
Error Err = parseUseLists())
4393 if (
Error Err = parseOperandBundleTags())
4397 if (
Error Err = parseSyncScopeNames())
4412 switch (
unsigned BitCode = MaybeBitCode.
get()) {
4418 UseRelativeIDs = *VersionOrErr >= 1;
4422 if (ResolvedDataLayout)
4423 return error(
"target triple too late in module");
4426 return error(
"Invalid record");
4427 TheModule->setTargetTriple(S);
4431 if (ResolvedDataLayout)
4432 return error(
"datalayout too late in module");
4434 return error(
"Invalid record");
4440 return error(
"Invalid record");
4441 TheModule->setModuleInlineAsm(S);
4448 return error(
"Invalid record");
4455 return error(
"Invalid record");
4456 SectionTable.push_back(S);
4462 return error(
"Invalid record");
4463 GCTable.push_back(S);
4480 if (
Error Err = ResolveDataLayout())
4488 if (
Error Err = parseGlobalIndirectSymbolRecord(BitCode,
Record))
4494 return error(
"Invalid record");
4498 VSTOffset =
Record[0] - 1;
4504 return error(
"Invalid record");
4505 TheModule->setSourceFileName(
ValueName);
4510 this->ValueTypeCallback = std::nullopt;
4514Error BitcodeReader::parseBitcodeInto(
Module *M,
bool ShouldLazyLoadMetadata,
4519 MDCallbacks.
GetTypeByID = [&](
unsigned ID) {
return getTypeByID(
ID); };
4521 return getContainedTypeID(
I, J);
4524 MDLoader =
MetadataLoader(Stream, *M, ValueList, IsImporting, MDCallbacks);
4525 return parseModule(0, ShouldLazyLoadMetadata, Callbacks);
4528Error BitcodeReader::typeCheckLoadStoreInst(
Type *ValType,
Type *PtrType) {
4529 if (!isa<PointerType>(PtrType))
4530 return error(
"Load/Store operand is not a pointer type");
4532 if (!cast<PointerType>(PtrType)->isOpaqueOrPointeeTypeMatches(ValType))
4533 return error(
"Explicit load/store type does not match pointee "
4534 "type of pointer operand");
4535 if (!PointerType::isLoadableOrStorableType(ValType))
4536 return error(
"Cannot load/store from pointer");
4543 for (
unsigned i = 0; i != CB->
arg_size(); ++i) {
4545 Attribute::InAlloca}) {
4546 if (!
Attrs.hasParamAttr(i, Kind) ||
4547 Attrs.getParamAttr(i, Kind).getValueAsType())
4550 Type *PtrEltTy = getPtrElementTypeByID(ArgTyIDs[i]);
4552 return error(
"Missing element type for typed attribute upgrade");
4556 case Attribute::ByVal:
4559 case Attribute::StructRet:
4562 case Attribute::InAlloca:
4569 Attrs =
Attrs.addParamAttribute(Context, i, NewAttr);
4580 if (CI.isIndirect && !
Attrs.getParamElementType(ArgNo)) {
4581 Type *ElemTy = getPtrElementTypeByID(ArgTyIDs[ArgNo]);
4583 return error(
"Missing element type for inline asm upgrade");
4594 case Intrinsic::preserve_array_access_index:
4595 case Intrinsic::preserve_struct_access_index:
4596 case Intrinsic::aarch64_ldaxr:
4597 case Intrinsic::aarch64_ldxr:
4598 case Intrinsic::aarch64_stlxr:
4599 case Intrinsic::aarch64_stxr:
4600 case Intrinsic::arm_ldaex:
4601 case Intrinsic::arm_ldrex:
4602 case Intrinsic::arm_stlex:
4603 case Intrinsic::arm_strex: {
4606 case Intrinsic::aarch64_stlxr:
4607 case Intrinsic::aarch64_stxr:
4608 case Intrinsic::arm_stlex:
4609 case Intrinsic::arm_strex:
4616 if (!
Attrs.getParamElementType(ArgNo)) {
4617 Type *ElTy = getPtrElementTypeByID(ArgTyIDs[ArgNo]);
4619 return error(
"Missing element type for elementtype upgrade");
4621 Attrs =
Attrs.addParamAttribute(Context, ArgNo, NewAttr);
4639 if (MDLoader->hasFwdRefs())
4640 return error(
"Invalid function metadata: incoming forward references");
4642 InstructionList.
clear();
4643 unsigned ModuleValueListSize = ValueList.
size();
4644 unsigned ModuleMDLoaderSize = MDLoader->size();
4648 unsigned FTyID = FunctionTypeIDs[
F];
4650 unsigned ArgTyID = getContainedTypeID(FTyID, ArgNo + 1);
4651 assert(
I.getType() == getTypeByID(ArgTyID) &&
4652 "Incorrect fully specified type for Function Argument");
4656 unsigned NextValueNo = ValueList.
size();
4658 unsigned CurBBNo = 0;
4667 auto getLastInstruction = [&]() ->
Instruction * {
4668 if (CurBB && !CurBB->
empty())
4669 return &CurBB->
back();
4670 else if (CurBBNo && FunctionBBs[CurBBNo - 1] &&
4671 !FunctionBBs[CurBBNo - 1]->empty())
4672 return &FunctionBBs[CurBBNo - 1]->back();
4676 std::vector<OperandBundleDef> OperandBundles;
4687 switch (Entry.Kind) {
4689 return error(
"Malformed block");
4691 goto OutOfRecordLoop;
4696 if (
Error Err = Stream.SkipBlock())
4700 if (
Error Err = parseConstants())
4702 NextValueNo = ValueList.
size();
4705 if (
Error Err = parseValueSymbolTable())
4709 if (
Error Err = MDLoader->parseMetadataAttachment(*
F, InstructionList))
4713 assert(DeferredMetadataInfo.empty() &&
4714 "Must read all module-level metadata before function-level");
4715 if (
Error Err = MDLoader->parseFunctionMetadata())
4719 if (
Error Err = parseUseLists())
4733 unsigned ResTypeID = InvalidTypeID;
4737 switch (
unsigned BitCode = MaybeBitCode.
get()) {
4739 return error(
"Invalid value");
4742 return error(
"Invalid record");
4744 FunctionBBs.resize(
Record[0]);
4747 auto BBFRI = BasicBlockFwdRefs.
find(
F);
4748 if (BBFRI == BasicBlockFwdRefs.
end()) {
4752 auto &BBRefs = BBFRI->second;
4754 if (BBRefs.size() > FunctionBBs.size())
4755 return error(
"Invalid ID");
4756 assert(!BBRefs.empty() &&
"Unexpected empty array");
4757 assert(!BBRefs.front() &&
"Invalid reference to entry block");
4758 for (
unsigned I = 0,
E = FunctionBBs.size(), RE = BBRefs.size();
I !=
E;
4760 if (
I < RE && BBRefs[
I]) {
4761 BBRefs[
I]->insertInto(
F);
4762 FunctionBBs[
I] = BBRefs[
I];
4768 BasicBlockFwdRefs.
erase(BBFRI);
4771 CurBB = FunctionBBs[0];
4778 return error(
"Invalid record");
4793 if (
auto *
F = dyn_cast<Function>(ValueList[
ValID]))
4794 BackwardRefFunctions.push_back(
F);
4796 return error(
"Invalid record");
4803 I = getLastInstruction();
4806 return error(
"Invalid record");
4807 I->setDebugLoc(LastLoc);
4812 I = getLastInstruction();
4814 return error(
"Invalid record");
4822 Scope = dyn_cast_or_null<MDNode>(
4823 MDLoader->getMetadataFwdRefOrLoad(ScopeID - 1));
4825 return error(
"Invalid record");
4828 IA = dyn_cast_or_null<MDNode>(
4829 MDLoader->getMetadataFwdRefOrLoad(IAID - 1));
4831 return error(
"Invalid record");
4833 LastLoc = DILocation::get(
Scope->getContext(), Line, Col, Scope, IA,
4835 I->setDebugLoc(LastLoc);
4843 if (getValueTypePair(
Record, OpNum, NextValueNo, LHS,
TypeID, CurBB) ||
4845 return error(
"Invalid record");
4849 return error(
"Invalid record");
4853 if (OpNum <
Record.size()) {
4854 if (isa<FPMathOperator>(
I)) {
4857 I->setFastMathFlags(FMF);
4866 if (getValueTypePair(
Record, OpNum, NextValueNo, LHS,
TypeID, CurBB) ||
4870 return error(
"Invalid record");
4874 return error(
"Invalid record");
4878 if (OpNum <
Record.size()) {
4879 if (Opc == Instruction::Add ||
4880 Opc == Instruction::Sub ||
4881 Opc == Instruction::Mul ||
4882 Opc == Instruction::Shl) {
4884 cast<BinaryOperator>(
I)->setHasNoSignedWrap(
true);
4886 cast<BinaryOperator>(
I)->setHasNoUnsignedWrap(
true);
4887 }
else if (Opc == Instruction::SDiv ||
4888 Opc == Instruction::UDiv ||
4889 Opc == Instruction::LShr ||
4890 Opc == Instruction::AShr) {