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"));
110 "load-bitcode-into-experimental-debuginfo-iterators",
cl::Hidden,
111 cl::desc(
"Load bitcode directly into the new debug info format (regardless "
112 "of input format)"));
121 SWITCH_INST_MAGIC = 0x4B5
127 return make_error<StringError>(
134 "file too small to contain bitcode header");
135 for (
unsigned C : {
'B',
'C'})
139 "file doesn't start with bitcode header");
141 return Res.takeError();
142 for (
unsigned C : {0x0, 0xC, 0xE, 0xD})
146 "file doesn't start with bitcode header");
148 return Res.takeError();
153 const unsigned char *BufPtr = (
const unsigned char *)Buffer.
getBufferStart();
154 const unsigned char *BufEnd = BufPtr + Buffer.
getBufferSize();
157 return error(
"Invalid bitcode signature");
163 return error(
"Invalid bitcode wrapper header");
167 return std::move(Err);
169 return std::move(Stream);
173template <
typename StrTy>
186 if (
F.isMaterializable())
189 I.setMetadata(LLVMContext::MD_tbaa,
nullptr);
197 return std::move(Err);
202 std::string ProducerIdentification;
209 switch (Entry.Kind) {
212 return error(
"Malformed block");
214 return ProducerIdentification;
225 switch (MaybeBitCode.
get()) {
227 return error(
"Invalid value");
235 Twine(
"Incompatible epoch: Bitcode '") +
Twine(epoch) +
254 switch (Entry.Kind) {
257 return error(
"Malformed block");
265 return std::move(Err);
277 return std::move(Err);
288 switch (Entry.Kind) {
291 return error(
"Malformed block");
303 switch (MaybeRecord.
get()) {
309 return error(
"Invalid section name record");
311 if (S.find(
"__DATA,__objc_catlist") != std::string::npos ||
312 S.find(
"__OBJC,__category") != std::string::npos ||
313 S.find(
"__TEXT,__swift") != std::string::npos)
331 switch (Entry.Kind) {
333 return error(
"Malformed block");
343 return std::move(Err);
356 return std::move(Err);
369 switch (Entry.Kind) {
372 return error(
"Malformed block");
384 switch (MaybeRecord.
get()) {
389 return error(
"Invalid triple record");
408 switch (Entry.Kind) {
410 return error(
"Malformed block");
420 return std::move(Err);
427 return Skipped.takeError();
434class BitcodeReaderBase {
437 : Stream(
std::
move(Stream)), Strtab(Strtab) {
447 bool UseStrtab =
false;
454 std::pair<StringRef, ArrayRef<uint64_t>>
457 Error readBlockInfo();
460 std::string ProducerIdentification;
467Error BitcodeReaderBase::error(
const Twine &Message) {
468 std::string FullMsg = Message.
str();
469 if (!ProducerIdentification.empty())
470 FullMsg +=
" (Producer: '" + ProducerIdentification +
"' Reader: 'LLVM " +
471 LLVM_VERSION_STRING
"')";
472 return ::error(FullMsg);
478 return error(
"Invalid version record");
479 unsigned ModuleVersion =
Record[0];
480 if (ModuleVersion > 2)
481 return error(
"Invalid value");
482 UseStrtab = ModuleVersion >= 2;
483 return ModuleVersion;
486std::pair<StringRef, ArrayRef<uint64_t>>
504class BitcodeConstant final :
public Value,
509 static constexpr uint8_t SubclassID = 255;
517 static constexpr uint8_t ConstantStructOpcode = 255;
518 static constexpr uint8_t ConstantArrayOpcode = 254;
519 static constexpr uint8_t ConstantVectorOpcode = 253;
520 static constexpr uint8_t NoCFIOpcode = 252;
521 static constexpr uint8_t DSOLocalEquivalentOpcode = 251;
522 static constexpr uint8_t BlockAddressOpcode = 250;
523 static constexpr uint8_t ConstantPtrAuthOpcode = 249;
524 static constexpr uint8_t FirstSpecialOpcode = ConstantPtrAuthOpcode;
531 unsigned BlockAddressBB = 0;
532 Type *SrcElemTy =
nullptr;
533 std::optional<ConstantRange> InRange;
535 ExtraInfo(uint8_t Opcode, uint8_t Flags = 0,
Type *SrcElemTy =
nullptr,
536 std::optional<ConstantRange> InRange = std::nullopt)
537 : Opcode(Opcode),
Flags(
Flags), SrcElemTy(SrcElemTy),
540 ExtraInfo(uint8_t Opcode, uint8_t Flags,
unsigned BlockAddressBB)
541 : Opcode(Opcode),
Flags(
Flags), BlockAddressBB(BlockAddressBB) {}
546 unsigned NumOperands;
547 unsigned BlockAddressBB;
549 std::optional<ConstantRange>
InRange;
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;
564 const ExtraInfo &Info,
566 void *Mem =
A.Allocate(totalSizeToAlloc<unsigned>(OpIDs.
size()),
567 alignof(BitcodeConstant));
568 return new (Mem) BitcodeConstant(Ty, Info, OpIDs);
571 static bool classof(
const Value *V) {
return V->getValueID() == SubclassID; }
574 return ArrayRef(getTrailingObjects<unsigned>(), NumOperands);
577 std::optional<ConstantRange> getInRange()
const {
578 assert(Opcode == Instruction::GetElementPtr);
587class BitcodeReader :
public BitcodeReaderBase,
public GVMaterializer {
589 Module *TheModule =
nullptr;
594 bool SeenValueSymbolTable =
false;
597 std::vector<std::string> SectionTable;
598 std::vector<std::string> GCTable;
600 std::vector<Type *> TypeList;
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;
626 struct FunctionOperandInfo {
628 unsigned PersonalityFn;
632 std::vector<FunctionOperandInfo> FunctionOperands;
636 std::vector<AttributeList> MAttributes;
639 std::map<unsigned, AttributeList> MAttributeGroups;
643 std::vector<BasicBlock*> FunctionBBs;
647 std::vector<Function*> FunctionsWithBodies;
652 UpdatedIntrinsicMap UpgradedIntrinsics;
657 bool SeenFirstFunctionBody =
false;
666 std::vector<uint64_t> DeferredMetadataInfo;
672 std::deque<Function *> BasicBlockFwdRefQueue;
679 std::vector<Function *> BackwardRefFunctions;
687 bool UseRelativeIDs =
false;
691 bool WillMaterializeAllForwardRefs =
false;
695 bool SeenDebugIntrinsic =
false;
696 bool SeenDebugRecord =
false;
701 std::vector<std::string> BundleTags;
704 std::optional<ValueTypeCallbackTy> ValueTypeCallback;
710 Error materializeForwardReferencedFunctions();
718 Error parseBitcodeInto(
Module *M,
bool ShouldLazyLoadMetadata,
729 std::vector<StructType *> IdentifiedStructTypes;
733 static constexpr unsigned InvalidTypeID = ~0
u;
735 Type *getTypeByID(
unsigned ID);
736 Type *getPtrElementTypeByID(
unsigned ID);
737 unsigned getContainedTypeID(
unsigned ID,
unsigned Idx = 0);
744 Value *getFnValueByID(
unsigned ID,
Type *Ty,
unsigned TyID,
752 return MDLoader->getMetadataFwdRefOrLoad(
ID);
756 if (
ID >= FunctionBBs.size())
return nullptr;
757 return FunctionBBs[
ID];
761 if (i-1 < MAttributes.size())
762 return MAttributes[i-1];
770 unsigned InstNum,
Value *&ResVal,
unsigned &
TypeID,
772 if (Slot ==
Record.size())
return true;
776 ValNo = InstNum - ValNo;
777 if (ValNo < InstNum) {
781 ResVal = getFnValueByID(ValNo,
nullptr,
TypeID, ConstExprInsertBB);
783 "Incorrect type ID stored for value");
784 return ResVal ==
nullptr;
786 if (Slot ==
Record.size())
790 ResVal = getFnValueByID(ValNo, getTypeByID(
TypeID),
TypeID,
792 return ResVal ==
nullptr;
799 unsigned InstNum,
Type *Ty,
unsigned TyID,
Value *&ResVal,
801 if (getValue(
Record, Slot, InstNum, Ty, TyID, ResVal, ConstExprInsertBB))
810 unsigned InstNum,
Type *Ty,
unsigned TyID,
Value *&ResVal,
812 ResVal = getValue(
Record, Slot, InstNum, Ty, TyID, ConstExprInsertBB);
813 return ResVal ==
nullptr;
819 unsigned InstNum,
Type *Ty,
unsigned TyID,
821 if (Slot ==
Record.size())
return nullptr;
825 ValNo = InstNum - ValNo;
826 return getFnValueByID(ValNo, Ty, TyID, ConstExprInsertBB);
831 unsigned InstNum,
Type *Ty,
unsigned TyID,
833 if (Slot ==
Record.size())
return nullptr;
837 ValNo = InstNum - ValNo;
838 return getFnValueByID(ValNo, Ty, TyID, ConstExprInsertBB);
844 if (
Record.size() - OpNum < 2)
845 return error(
"Too few records for range");
847 unsigned LowerActiveWords =
Record[OpNum];
848 unsigned UpperActiveWords =
Record[OpNum++] >> 32;
849 if (
Record.size() - OpNum < LowerActiveWords + UpperActiveWords)
850 return error(
"Too few records for range");
853 OpNum += LowerActiveWords;
856 OpNum += UpperActiveWords;
859 int64_t Start = BitcodeReader::decodeSignRotatedValue(
Record[OpNum++]);
860 int64_t
End = BitcodeReader::decodeSignRotatedValue(
Record[OpNum++]);
867 if (
Record.size() - OpNum < 1)
868 return error(
"Too few records for range");
889 Error parseGlobalIndirectSymbolRecord(
unsigned BitCode,
892 Error parseAttributeBlock();
893 Error parseAttributeGroupBlock();
894 Error parseTypeTable();
895 Error parseTypeTableBody();
896 Error parseOperandBundleTags();
897 Error parseSyncScopeNames();
900 unsigned NameIndex,
Triple &TT);
901 void setDeferredFunctionInfo(
unsigned FuncBitcodeOffsetDelta,
Function *
F,
904 Error parseGlobalValueSymbolTable();
905 Error parseConstants();
906 Error rememberAndSkipFunctionBodies();
907 Error rememberAndSkipFunctionBody();
909 Error rememberAndSkipMetadata();
912 Error globalCleanup();
913 Error resolveGlobalAndIndirectSymbolInits();
914 Error parseUseLists();
915 Error findFunctionInStream(
924class ModuleSummaryIndexBitcodeReader :
public BitcodeReaderBase {
930 bool SeenGlobalValSummary =
false;
933 bool SeenValueSymbolTable =
false;
949 std::tuple<ValueInfo, GlobalValue::GUID, GlobalValue::GUID>>
950 ValueIdToValueInfoMap;
959 std::string SourceFileName;
971 std::vector<uint64_t> StackIds;
974 ModuleSummaryIndexBitcodeReader(
985 Error parseValueSymbolTable(
990 bool IsOldProfileFormat,
993 Error parseEntireSummary(
unsigned ID);
994 Error parseModuleStringTable();
998 std::vector<FunctionSummary::ParamAccess>
1001 template <
bool AllowNullValueInfo = false>
1002 std::tuple<ValueInfo, GlobalValue::GUID, GlobalValue::GUID>
1003 getValueInfoFromValueId(
unsigned ValueId);
1005 void addThisModule();
1021 return std::error_code();
1027 : BitcodeReaderBase(
std::
move(Stream), Strtab), Context(Context),
1028 ValueList(this->Stream.SizeInBytes(),
1030 return materializeValue(
ValID, InsertBB);
1032 this->ProducerIdentification = std::string(ProducerIdentification);
1035Error BitcodeReader::materializeForwardReferencedFunctions() {
1036 if (WillMaterializeAllForwardRefs)
1040 WillMaterializeAllForwardRefs =
true;
1042 while (!BasicBlockFwdRefQueue.empty()) {
1043 Function *
F = BasicBlockFwdRefQueue.front();
1044 BasicBlockFwdRefQueue.pop_front();
1045 assert(
F &&
"Expected valid function");
1046 if (!BasicBlockFwdRefs.
count(
F))
1054 if (!
F->isMaterializable())
1055 return error(
"Never resolved function from blockaddress");
1058 if (
Error Err = materialize(
F))
1061 assert(BasicBlockFwdRefs.
empty() &&
"Function missing from queue");
1063 for (
Function *
F : BackwardRefFunctions)
1064 if (
Error Err = materialize(
F))
1066 BackwardRefFunctions.clear();
1069 WillMaterializeAllForwardRefs =
false;
1133 Flags.ReadNone = RawFlags & 0x1;
1134 Flags.ReadOnly = (RawFlags >> 1) & 0x1;
1135 Flags.NoRecurse = (RawFlags >> 2) & 0x1;
1136 Flags.ReturnDoesNotAlias = (RawFlags >> 3) & 0x1;
1137 Flags.NoInline = (RawFlags >> 4) & 0x1;
1138 Flags.AlwaysInline = (RawFlags >> 5) & 0x1;
1139 Flags.NoUnwind = (RawFlags >> 6) & 0x1;
1140 Flags.MayThrow = (RawFlags >> 7) & 0x1;
1141 Flags.HasUnknownCall = (RawFlags >> 8) & 0x1;
1142 Flags.MustBeUnreachable = (RawFlags >> 9) & 0x1;
1158 RawFlags = RawFlags >> 4;
1159 bool NotEligibleToImport = (RawFlags & 0x1) || Version < 3;
1163 bool Live = (RawFlags & 0x2) || Version < 3;
1164 bool Local = (RawFlags & 0x4);
1165 bool AutoHide = (RawFlags & 0x8);
1168 Live, Local, AutoHide, IK);
1174 (RawFlags & 0x1) ?
true :
false, (RawFlags & 0x2) ?
true :
false,
1175 (RawFlags & 0x4) ?
true :
false,
1179static std::pair<CalleeInfo::HotnessType, bool>
1183 bool HasTailCall = (RawFlags & 0x8);
1184 return {Hotness, HasTailCall};
1188 bool &HasTailCall) {
1189 static constexpr uint64_t RelBlockFreqMask =
1191 RelBF = RawFlags & RelBlockFreqMask;
1217 case 0:
return false;
1218 case 1:
return true;
1241 case 0:
return GlobalVariable::NotThreadLocal;
1243 case 1:
return GlobalVariable::GeneralDynamicTLSModel;
1244 case 2:
return GlobalVariable::LocalDynamicTLSModel;
1245 case 3:
return GlobalVariable::InitialExecTLSModel;
1246 case 4:
return GlobalVariable::LocalExecTLSModel;
1253 case 0:
return GlobalVariable::UnnamedAddr::None;
1254 case 1:
return GlobalVariable::UnnamedAddr::Global;
1255 case 2:
return GlobalVariable::UnnamedAddr::Local;
1288 return IsFP ? Instruction::FNeg : -1;
1302 return IsFP ? Instruction::FAdd : Instruction::Add;
1304 return IsFP ? Instruction::FSub : Instruction::Sub;
1306 return IsFP ? Instruction::FMul : Instruction::Mul;
1308 return IsFP ? -1 : Instruction::UDiv;
1310 return IsFP ? Instruction::FDiv : Instruction::SDiv;
1312 return IsFP ? -1 : Instruction::URem;
1314 return IsFP ? Instruction::FRem : Instruction::SRem;
1316 return IsFP ? -1 : Instruction::Shl;
1318 return IsFP ? -1 : Instruction::LShr;
1320 return IsFP ? -1 : Instruction::AShr;
1322 return IsFP ? -1 : Instruction::And;
1324 return IsFP ? -1 : Instruction::Or;
1326 return IsFP ? -1 : Instruction::Xor;
1415Type *BitcodeReader::getTypeByID(
unsigned ID) {
1417 if (
ID >= TypeList.size())
1420 if (
Type *Ty = TypeList[
ID])
1425 return TypeList[
ID] = createIdentifiedStructType(Context);
1428unsigned BitcodeReader::getContainedTypeID(
unsigned ID,
unsigned Idx) {
1429 auto It = ContainedTypeIDs.
find(
ID);
1430 if (It == ContainedTypeIDs.
end())
1431 return InvalidTypeID;
1433 if (
Idx >= It->second.size())
1434 return InvalidTypeID;
1436 return It->second[
Idx];
1439Type *BitcodeReader::getPtrElementTypeByID(
unsigned ID) {
1440 if (
ID >= TypeList.size())
1447 return getTypeByID(getContainedTypeID(
ID, 0));
1450unsigned BitcodeReader::getVirtualTypeID(
Type *Ty,
1452 unsigned ChildTypeID = ChildTypeIDs.
empty() ? InvalidTypeID : ChildTypeIDs[0];
1453 auto CacheKey = std::make_pair(Ty, ChildTypeID);
1454 auto It = VirtualTypeIDs.
find(CacheKey);
1455 if (It != VirtualTypeIDs.
end()) {
1461 ContainedTypeIDs[It->second] == ChildTypeIDs) &&
1462 "Incorrect cached contained type IDs");
1466 unsigned TypeID = TypeList.size();
1467 TypeList.push_back(Ty);
1468 if (!ChildTypeIDs.
empty())
1486 uint8_t Opcode = BC->Opcode;
1489 if (Opcode >= BitcodeConstant::FirstSpecialOpcode)
1503 if (Opcode == Instruction::GetElementPtr)
1507 case Instruction::FNeg:
1508 case Instruction::Select:
1509 case Instruction::ICmp:
1510 case Instruction::FCmp:
1520 if (StartValID < ValueList.
size() && ValueList[StartValID] &&
1521 !isa<BitcodeConstant>(ValueList[StartValID]))
1522 return ValueList[StartValID];
1527 while (!Worklist.
empty()) {
1536 return error(
"Invalid value ID");
1539 auto *BC = dyn_cast<BitcodeConstant>(V);
1549 for (
unsigned OpID :
reverse(BC->getOperandIDs())) {
1550 auto It = MaterializedValues.
find(OpID);
1551 if (It != MaterializedValues.
end())
1559 if (Ops.
size() != BC->getOperandIDs().size())
1561 std::reverse(Ops.
begin(), Ops.
end());
1565 if (
auto *
C = dyn_cast<Constant>(
Op))
1578 switch (BC->Opcode) {
1579 case BitcodeConstant::ConstantPtrAuthOpcode: {
1580 auto *
Key = dyn_cast<ConstantInt>(ConstOps[1]);
1582 return error(
"ptrauth key operand must be ConstantInt");
1584 auto *Disc = dyn_cast<ConstantInt>(ConstOps[2]);
1586 return error(
"ptrauth disc operand must be ConstantInt");
1591 case BitcodeConstant::NoCFIOpcode: {
1592 auto *GV = dyn_cast<GlobalValue>(ConstOps[0]);
1594 return error(
"no_cfi operand must be GlobalValue");
1598 case BitcodeConstant::DSOLocalEquivalentOpcode: {
1599 auto *GV = dyn_cast<GlobalValue>(ConstOps[0]);
1601 return error(
"dso_local operand must be GlobalValue");
1605 case BitcodeConstant::BlockAddressOpcode: {
1606 Function *Fn = dyn_cast<Function>(ConstOps[0]);
1608 return error(
"blockaddress operand must be a function");
1613 unsigned BBID = BC->BlockAddressBB;
1616 return error(
"Invalid ID");
1619 for (
size_t I = 0, E = BBID;
I != E; ++
I) {
1621 return error(
"Invalid ID");
1628 auto &FwdBBs = BasicBlockFwdRefs[Fn];
1630 BasicBlockFwdRefQueue.push_back(Fn);
1631 if (FwdBBs.size() < BBID + 1)
1632 FwdBBs.resize(BBID + 1);
1640 case BitcodeConstant::ConstantStructOpcode:
1643 case BitcodeConstant::ConstantArrayOpcode:
1646 case BitcodeConstant::ConstantVectorOpcode:
1649 case Instruction::GetElementPtr:
1651 BC->SrcElemTy, ConstOps[0],
ArrayRef(ConstOps).drop_front(),
1654 case Instruction::ExtractElement:
1657 case Instruction::InsertElement:
1661 case Instruction::ShuffleVector: {
1680 return error(
Twine(
"Value referenced by initializer is an unsupported "
1681 "constant expression of type ") +
1682 BC->getOpcodeName());
1688 BC->getType(),
"constexpr", InsertBB);
1691 "constexpr", InsertBB);
1694 Ops[1],
"constexpr", InsertBB);
1695 if (isa<OverflowingBinaryOperator>(
I)) {
1697 I->setHasNoSignedWrap();
1699 I->setHasNoUnsignedWrap();
1701 if (isa<PossiblyExactOperator>(
I) &&
1705 switch (BC->Opcode) {
1706 case BitcodeConstant::ConstantVectorOpcode: {
1710 Value *
Idx = ConstantInt::get(IdxTy, Pair.index());
1714 I = cast<Instruction>(V);
1717 case BitcodeConstant::ConstantStructOpcode:
1718 case BitcodeConstant::ConstantArrayOpcode: {
1722 "constexpr.ins", InsertBB);
1723 I = cast<Instruction>(V);
1726 case Instruction::ICmp:
1727 case Instruction::FCmp:
1730 "constexpr", InsertBB);
1732 case Instruction::GetElementPtr:
1734 ArrayRef(Ops).drop_front(),
"constexpr",
1738 case Instruction::Select:
1741 case Instruction::ExtractElement:
1744 case Instruction::InsertElement:
1748 case Instruction::ShuffleVector:
1761 return MaterializedValues[StartValID];
1770 return cast<Constant>(MaybeV.
get());
1776 IdentifiedStructTypes.push_back(Ret);
1782 IdentifiedStructTypes.push_back(Ret);
1798 case Attribute::ZExt:
return 1 << 0;
1799 case Attribute::SExt:
return 1 << 1;
1800 case Attribute::NoReturn:
return 1 << 2;
1801 case Attribute::InReg:
return 1 << 3;
1802 case Attribute::StructRet:
return 1 << 4;
1803 case Attribute::NoUnwind:
return 1 << 5;
1804 case Attribute::NoAlias:
return 1 << 6;
1805 case Attribute::ByVal:
return 1 << 7;
1806 case Attribute::Nest:
return 1 << 8;
1807 case Attribute::ReadNone:
return 1 << 9;
1808 case Attribute::ReadOnly:
return 1 << 10;
1809 case Attribute::NoInline:
return 1 << 11;
1810 case Attribute::AlwaysInline:
return 1 << 12;
1811 case Attribute::OptimizeForSize:
return 1 << 13;
1812 case Attribute::StackProtect:
return 1 << 14;
1813 case Attribute::StackProtectReq:
return 1 << 15;
1814 case Attribute::Alignment:
return 31 << 16;
1815 case Attribute::NoCapture:
return 1 << 21;
1816 case Attribute::NoRedZone:
return 1 << 22;
1817 case Attribute::NoImplicitFloat:
return 1 << 23;
1818 case Attribute::Naked:
return 1 << 24;
1819 case Attribute::InlineHint:
return 1 << 25;
1820 case Attribute::StackAlignment:
return 7 << 26;
1821 case Attribute::ReturnsTwice:
return 1 << 29;
1822 case Attribute::UWTable:
return 1 << 30;
1823 case Attribute::NonLazyBind:
return 1U << 31;
1824 case Attribute::SanitizeAddress:
return 1ULL << 32;
1825 case Attribute::MinSize:
return 1ULL << 33;
1826 case Attribute::NoDuplicate:
return 1ULL << 34;
1827 case Attribute::StackProtectStrong:
return 1ULL << 35;
1828 case Attribute::SanitizeThread:
return 1ULL << 36;
1829 case Attribute::SanitizeMemory:
return 1ULL << 37;
1830 case Attribute::NoBuiltin:
return 1ULL << 38;
1831 case Attribute::Returned:
return 1ULL << 39;
1832 case Attribute::Cold:
return 1ULL << 40;
1833 case Attribute::Builtin:
return 1ULL << 41;
1834 case Attribute::OptimizeNone:
return 1ULL << 42;
1835 case Attribute::InAlloca:
return 1ULL << 43;
1836 case Attribute::NonNull:
return 1ULL << 44;
1837 case Attribute::JumpTable:
return 1ULL << 45;
1838 case Attribute::Convergent:
return 1ULL << 46;
1839 case Attribute::SafeStack:
return 1ULL << 47;
1840 case Attribute::NoRecurse:
return 1ULL << 48;
1843 case Attribute::SwiftSelf:
return 1ULL << 51;
1844 case Attribute::SwiftError:
return 1ULL << 52;
1845 case Attribute::WriteOnly:
return 1ULL << 53;
1846 case Attribute::Speculatable:
return 1ULL << 54;
1847 case Attribute::StrictFP:
return 1ULL << 55;
1848 case Attribute::SanitizeHWAddress:
return 1ULL << 56;
1849 case Attribute::NoCfCheck:
return 1ULL << 57;
1850 case Attribute::OptForFuzzing:
return 1ULL << 58;
1851 case Attribute::ShadowCallStack:
return 1ULL << 59;
1852 case Attribute::SpeculativeLoadHardening:
1854 case Attribute::ImmArg:
1856 case Attribute::WillReturn:
1858 case Attribute::NoFree:
1874 if (
I == Attribute::Alignment)
1875 B.addAlignmentAttr(1ULL << ((
A >> 16) - 1));
1876 else if (
I == Attribute::StackAlignment)
1877 B.addStackAlignmentAttr(1ULL << ((
A >> 26)-1));
1879 B.addTypeAttr(
I,
nullptr);
1894 unsigned Alignment = (EncodedAttrs & (0xffffULL << 16)) >> 16;
1896 "Alignment must be a power of two.");
1899 B.addAlignmentAttr(Alignment);
1901 uint64_t Attrs = ((EncodedAttrs & (0xfffffULL << 32)) >> 11) |
1902 (EncodedAttrs & 0xffff);
1907 if (Attrs & (1ULL << 9)) {
1909 Attrs &= ~(1ULL << 9);
1912 if (Attrs & (1ULL << 10)) {
1914 Attrs &= ~(1ULL << 10);
1917 if (Attrs & (1ULL << 49)) {
1919 Attrs &= ~(1ULL << 49);
1922 if (Attrs & (1ULL << 50)) {
1924 Attrs &= ~(1ULL << 50);
1927 if (Attrs & (1ULL << 53)) {
1929 Attrs &= ~(1ULL << 53);
1933 B.addMemoryAttr(ME);
1939Error BitcodeReader::parseAttributeBlock() {
1943 if (!MAttributes.empty())
1944 return error(
"Invalid multiple blocks");
1957 switch (
Entry.Kind) {
1960 return error(
"Malformed block");
1973 switch (MaybeRecord.
get()) {
1979 return error(
"Invalid parameter attribute record");
1981 for (
unsigned i = 0, e =
Record.size(); i != e; i += 2) {
1992 Attrs.push_back(MAttributeGroups[Val]);
2007 return Attribute::Alignment;
2009 return Attribute::AlwaysInline;
2011 return Attribute::Builtin;
2013 return Attribute::ByVal;
2015 return Attribute::InAlloca;
2017 return Attribute::Cold;
2019 return Attribute::Convergent;
2021 return Attribute::DisableSanitizerInstrumentation;
2023 return Attribute::ElementType;
2025 return Attribute::FnRetThunkExtern;
2027 return Attribute::InlineHint;
2029 return Attribute::InReg;
2031 return Attribute::JumpTable;
2033 return Attribute::Memory;
2035 return Attribute::NoFPClass;
2037 return Attribute::MinSize;
2039 return Attribute::Naked;
2041 return Attribute::Nest;
2043 return Attribute::NoAlias;
2045 return Attribute::NoBuiltin;
2047 return Attribute::NoCallback;
2049 return Attribute::NoCapture;
2051 return Attribute::NoDuplicate;
2053 return Attribute::NoFree;
2055 return Attribute::NoImplicitFloat;
2057 return Attribute::NoInline;
2059 return Attribute::NoRecurse;
2061 return Attribute::NoMerge;
2063 return Attribute::NonLazyBind;
2065 return Attribute::NonNull;
2067 return Attribute::Dereferenceable;
2069 return Attribute::DereferenceableOrNull;
2071 return Attribute::AllocAlign;
2073 return Attribute::AllocKind;
2075 return Attribute::AllocSize;
2077 return Attribute::AllocatedPointer;
2079 return Attribute::NoRedZone;
2081 return Attribute::NoReturn;
2083 return Attribute::NoSync;
2085 return Attribute::NoCfCheck;
2087 return Attribute::NoProfile;
2089 return Attribute::SkipProfile;
2091 return Attribute::NoUnwind;
2093 return Attribute::NoSanitizeBounds;
2095 return Attribute::NoSanitizeCoverage;
2097 return Attribute::NullPointerIsValid;
2099 return Attribute::OptimizeForDebugging;
2101 return Attribute::OptForFuzzing;
2103 return Attribute::OptimizeForSize;
2105 return Attribute::OptimizeNone;
2107 return Attribute::ReadNone;
2109 return Attribute::ReadOnly;
2111 return Attribute::Returned;
2113 return Attribute::ReturnsTwice;
2115 return Attribute::SExt;
2117 return Attribute::Speculatable;
2119 return Attribute::StackAlignment;
2121 return Attribute::StackProtect;
2123 return Attribute::StackProtectReq;
2125 return Attribute::StackProtectStrong;
2127 return Attribute::SafeStack;
2129 return Attribute::ShadowCallStack;
2131 return Attribute::StrictFP;
2133 return Attribute::StructRet;
2135 return Attribute::SanitizeAddress;
2137 return Attribute::SanitizeHWAddress;
2139 return Attribute::SanitizeThread;
2141 return Attribute::SanitizeMemory;
2143 return Attribute::SanitizeNumericalStability;
2145 return Attribute::SanitizeRealtime;
2147 return Attribute::SpeculativeLoadHardening;
2149 return Attribute::SwiftError;
2151 return Attribute::SwiftSelf;
2153 return Attribute::SwiftAsync;
2155 return Attribute::UWTable;
2157 return Attribute::VScaleRange;
2159 return Attribute::WillReturn;
2161 return Attribute::WriteOnly;
2163 return Attribute::ZExt;
2165 return Attribute::ImmArg;
2167 return Attribute::SanitizeMemTag;
2169 return Attribute::Preallocated;
2171 return Attribute::NoUndef;
2173 return Attribute::ByRef;
2175 return Attribute::MustProgress;
2177 return Attribute::Hot;
2179 return Attribute::PresplitCoroutine;
2181 return Attribute::Writable;
2183 return Attribute::CoroDestroyOnlyWhenComplete;
2185 return Attribute::DeadOnUnwind;
2187 return Attribute::Range;
2189 return Attribute::Initializes;
2198 return error(
"Invalid alignment value");
2206 return error(
"Unknown attribute kind (" +
Twine(Code) +
")");
2211 switch (EncodedKind) {
2235Error BitcodeReader::parseAttributeGroupBlock() {
2239 if (!MAttributeGroups.empty())
2240 return error(
"Invalid multiple blocks");
2251 switch (
Entry.Kind) {
2254 return error(
"Malformed block");
2267 switch (MaybeRecord.
get()) {
2272 return error(
"Invalid grp record");
2279 for (
unsigned i = 2, e =
Record.size(); i != e; ++i) {
2287 if (
Error Err = parseAttrKind(EncodedKind, &Kind))
2293 if (Kind == Attribute::ByVal)
2294 B.addByValAttr(
nullptr);
2295 else if (Kind == Attribute::StructRet)
2296 B.addStructRetAttr(
nullptr);
2297 else if (Kind == Attribute::InAlloca)
2298 B.addInAllocaAttr(
nullptr);
2299 else if (Kind == Attribute::UWTable)
2300 B.addUWTableAttr(UWTableKind::Default);
2302 B.addAttribute(Kind);
2304 return error(
"Not an enum attribute");
2305 }
else if (
Record[i] == 1) {
2307 if (
Error Err = parseAttrKind(
Record[++i], &Kind))
2310 return error(
"Not an int attribute");
2311 if (Kind == Attribute::Alignment)
2312 B.addAlignmentAttr(
Record[++i]);
2313 else if (Kind == Attribute::StackAlignment)
2314 B.addStackAlignmentAttr(
Record[++i]);
2315 else if (Kind == Attribute::Dereferenceable)
2316 B.addDereferenceableAttr(
Record[++i]);
2317 else if (Kind == Attribute::DereferenceableOrNull)
2318 B.addDereferenceableOrNullAttr(
Record[++i]);
2319 else if (Kind == Attribute::AllocSize)
2320 B.addAllocSizeAttrFromRawRepr(
Record[++i]);
2321 else if (Kind == Attribute::VScaleRange)
2322 B.addVScaleRangeAttrFromRawRepr(
Record[++i]);
2323 else if (Kind == Attribute::UWTable)
2325 else if (Kind == Attribute::AllocKind)
2327 else if (Kind == Attribute::Memory)
2329 else if (Kind == Attribute::NoFPClass)
2337 while (
Record[i] != 0 && i != e)
2339 assert(
Record[i] == 0 &&
"Kind string not null terminated");
2344 while (
Record[i] != 0 && i != e)
2346 assert(
Record[i] == 0 &&
"Value string not null terminated");
2349 B.addAttribute(KindStr.
str(), ValStr.
str());
2351 bool HasType =
Record[i] == 6;
2353 if (
Error Err = parseAttrKind(
Record[++i], &Kind))
2356 return error(
"Not a type attribute");
2358 B.addTypeAttr(Kind, HasType ? getTypeByID(
Record[++i]) :
nullptr);
2359 }
else if (
Record[i] == 7) {
2363 if (
Error Err = parseAttrKind(
Record[i++], &Kind))
2366 return error(
"Not a ConstantRange attribute");
2369 readBitWidthAndConstantRange(
Record, i);
2374 B.addConstantRangeAttr(Kind, MaybeCR.
get());
2375 }
else if (
Record[i] == 8) {
2379 if (
Error Err = parseAttrKind(
Record[i++], &Kind))
2382 return error(
"Not a constant range list attribute");
2386 return error(
"Too few records for constant range list");
2387 unsigned RangeSize =
Record[i++];
2389 for (
unsigned Idx = 0;
Idx < RangeSize; ++
Idx) {
2399 return error(
"Invalid (unordered or overlapping) range list");
2400 B.addConstantRangeListAttr(Kind, Val);
2402 return error(
"Invalid attribute group entry");
2407 B.addMemoryAttr(ME);
2417Error BitcodeReader::parseTypeTable() {
2421 return parseTypeTableBody();
2424Error BitcodeReader::parseTypeTableBody() {
2425 if (!TypeList.empty())
2426 return error(
"Invalid multiple blocks");
2429 unsigned NumRecords = 0;
2440 switch (
Entry.Kind) {
2443 return error(
"Malformed block");
2445 if (NumRecords != TypeList.size())
2446 return error(
"Malformed block");
2455 Type *ResultTy =
nullptr;
2460 switch (MaybeRecord.
get()) {
2462 return error(
"Invalid value");
2467 return error(
"Invalid numentry record");
2468 TypeList.resize(
Record[0]);
2513 return error(
"Invalid integer record");
2518 return error(
"Bitwidth for integer type out of range");
2525 return error(
"Invalid pointer record");
2529 ResultTy = getTypeByID(
Record[0]);
2531 !PointerType::isValidElementType(ResultTy))
2532 return error(
"Invalid type");
2539 return error(
"Invalid opaque pointer record");
2548 return error(
"Invalid function record");
2550 for (
unsigned i = 3, e =
Record.size(); i != e; ++i) {
2557 ResultTy = getTypeByID(
Record[2]);
2558 if (!ResultTy || ArgTys.
size() <
Record.size()-3)
2559 return error(
"Invalid type");
2562 ResultTy = FunctionType::get(ResultTy, ArgTys,
Record[0]);
2568 return error(
"Invalid function record");
2570 for (
unsigned i = 2, e =
Record.size(); i != e; ++i) {
2572 if (!FunctionType::isValidArgumentType(
T))
2573 return error(
"Invalid function argument type");
2580 ResultTy = getTypeByID(
Record[1]);
2581 if (!ResultTy || ArgTys.
size() <
Record.size()-2)
2582 return error(
"Invalid type");
2585 ResultTy = FunctionType::get(ResultTy, ArgTys,
Record[0]);
2590 return error(
"Invalid anon struct record");
2592 for (
unsigned i = 1, e =
Record.size(); i != e; ++i) {
2599 return error(
"Invalid type");
2606 return error(
"Invalid struct name record");
2611 return error(
"Invalid named struct record");
2613 if (NumRecords >= TypeList.size())
2614 return error(
"Invalid TYPE table");
2617 StructType *Res = cast_or_null<StructType>(TypeList[NumRecords]);
2620 TypeList[NumRecords] =
nullptr;
2622 Res = createIdentifiedStructType(Context, TypeName);
2626 for (
unsigned i = 1, e =
Record.size(); i != e; ++i) {
2633 return error(
"Invalid named struct record");
2641 return error(
"Invalid opaque type record");
2643 if (NumRecords >= TypeList.size())
2644 return error(
"Invalid TYPE table");
2647 StructType *Res = cast_or_null<StructType>(TypeList[NumRecords]);
2650 TypeList[NumRecords] =
nullptr;
2652 Res = createIdentifiedStructType(Context, TypeName);
2659 return error(
"Invalid target extension type record");
2661 if (NumRecords >= TypeList.size())
2662 return error(
"Invalid TYPE table");
2665 return error(
"Too many type parameters");
2667 unsigned NumTys =
Record[0];
2670 for (
unsigned i = 0; i < NumTys; i++) {
2674 return error(
"Invalid type");
2677 for (
unsigned i = NumTys + 1, e =
Record.size(); i < e; i++) {
2678 if (
Record[i] > UINT_MAX)
2679 return error(
"Integer parameter too large");
2688 return error(
"Invalid array type record");
2689 ResultTy = getTypeByID(
Record[1]);
2690 if (!ResultTy || !ArrayType::isValidElementType(ResultTy))
2691 return error(
"Invalid type");
2693 ResultTy = ArrayType::get(ResultTy,
Record[0]);
2698 return error(
"Invalid vector type record");
2700 return error(
"Invalid vector length");
2701 ResultTy = getTypeByID(
Record[1]);
2702 if (!ResultTy || !VectorType::isValidElementType(ResultTy))
2703 return error(
"Invalid type");
2706 ResultTy = VectorType::get(ResultTy,
Record[0], Scalable);
2710 if (NumRecords >= TypeList.size())
2711 return error(
"Invalid TYPE table");
2712 if (TypeList[NumRecords])
2714 "Invalid TYPE table: Only named structs can be forward referenced");
2715 assert(ResultTy &&
"Didn't read a type?");
2716 TypeList[NumRecords] = ResultTy;
2717 if (!ContainedIDs.
empty())
2718 ContainedTypeIDs[NumRecords] = std::move(ContainedIDs);
2723Error BitcodeReader::parseOperandBundleTags() {
2727 if (!BundleTags.empty())
2728 return error(
"Invalid multiple blocks");
2738 switch (
Entry.Kind) {
2741 return error(
"Malformed block");
2755 return error(
"Invalid operand bundle record");
2758 BundleTags.emplace_back();
2760 return error(
"Invalid operand bundle record");
2765Error BitcodeReader::parseSyncScopeNames() {
2770 return error(
"Invalid multiple synchronization scope names blocks");
2779 switch (
Entry.Kind) {
2782 return error(
"Malformed block");
2785 return error(
"Invalid empty synchronization scope names block");
2799 return error(
"Invalid sync scope record");
2803 return error(
"Invalid sync scope record");
2812 unsigned NameIndex,
Triple &TT) {
2815 return error(
"Invalid record");
2816 unsigned ValueID =
Record[0];
2817 if (ValueID >= ValueList.
size() || !ValueList[ValueID])
2818 return error(
"Invalid record");
2819 Value *
V = ValueList[ValueID];
2822 if (NameStr.contains(0))
2823 return error(
"Invalid value name");
2824 V->setName(NameStr);
2825 auto *GO = dyn_cast<GlobalObject>(V);
2826 if (GO && ImplicitComdatObjects.
contains(GO) &&
TT.supportsCOMDAT())
2839 return std::move(JumpFailed);
2845 return error(
"Expected value symbol table subblock");
2849void BitcodeReader::setDeferredFunctionInfo(
unsigned FuncBitcodeOffsetDelta,
2856 uint64_t FuncBitOffset = FuncWordOffset * 32;
2857 DeferredFunctionInfo[
F] = FuncBitOffset + FuncBitcodeOffsetDelta;
2861 if (FuncBitOffset > LastFunctionBlockBit)
2862 LastFunctionBlockBit = FuncBitOffset;
2866Error BitcodeReader::parseGlobalValueSymbolTable() {
2867 unsigned FuncBitcodeOffsetDelta =
2880 switch (
Entry.Kind) {
2883 return error(
"Malformed block");
2894 switch (MaybeRecord.
get()) {
2896 unsigned ValueID =
Record[0];
2897 if (ValueID >= ValueList.
size() || !ValueList[ValueID])
2898 return error(
"Invalid value reference in symbol table");
2899 setDeferredFunctionInfo(FuncBitcodeOffsetDelta,
2900 cast<Function>(ValueList[ValueID]),
Record);
2916 if (!MaybeCurrentBit)
2918 CurrentBit = MaybeCurrentBit.
get();
2921 if (
Error Err = parseGlobalValueSymbolTable())
2923 if (
Error JumpFailed = Stream.JumpToBit(CurrentBit))
2942 unsigned FuncBitcodeOffsetDelta =
2961 switch (
Entry.Kind) {
2964 return error(
"Malformed block");
2967 if (
Error JumpFailed = Stream.JumpToBit(CurrentBit))
2980 switch (MaybeRecord.
get()) {
2999 if (
auto *
F = dyn_cast<Function>(V))
3000 setDeferredFunctionInfo(FuncBitcodeOffsetDelta,
F,
Record);
3005 return error(
"Invalid bbentry record");
3008 return error(
"Invalid bbentry record");
3030Error BitcodeReader::resolveGlobalAndIndirectSymbolInits() {
3031 std::vector<std::pair<GlobalVariable *, unsigned>> GlobalInitWorklist;
3032 std::vector<std::pair<GlobalValue *, unsigned>> IndirectSymbolInitWorklist;
3033 std::vector<FunctionOperandInfo> FunctionOperandWorklist;
3035 GlobalInitWorklist.swap(GlobalInits);
3036 IndirectSymbolInitWorklist.swap(IndirectSymbolInits);
3037 FunctionOperandWorklist.swap(FunctionOperands);
3039 while (!GlobalInitWorklist.empty()) {
3040 unsigned ValID = GlobalInitWorklist.back().second;
3043 GlobalInits.push_back(GlobalInitWorklist.back());
3048 GlobalInitWorklist.back().first->setInitializer(MaybeC.
get());
3050 GlobalInitWorklist.pop_back();
3053 while (!IndirectSymbolInitWorklist.empty()) {
3054 unsigned ValID = IndirectSymbolInitWorklist.back().second;
3056 IndirectSymbolInits.push_back(IndirectSymbolInitWorklist.back());
3062 GlobalValue *GV = IndirectSymbolInitWorklist.back().first;
3063 if (
auto *GA = dyn_cast<GlobalAlias>(GV)) {
3065 return error(
"Alias and aliasee types don't match");
3067 }
else if (
auto *GI = dyn_cast<GlobalIFunc>(GV)) {
3070 return error(
"Expected an alias or an ifunc");
3073 IndirectSymbolInitWorklist.pop_back();
3076 while (!FunctionOperandWorklist.empty()) {
3077 FunctionOperandInfo &
Info = FunctionOperandWorklist.back();
3078 if (
Info.PersonalityFn) {
3079 unsigned ValID =
Info.PersonalityFn - 1;
3084 Info.F->setPersonalityFn(MaybeC.
get());
3085 Info.PersonalityFn = 0;
3094 Info.F->setPrefixData(MaybeC.
get());
3098 if (
Info.Prologue) {
3104 Info.F->setPrologueData(MaybeC.
get());
3108 if (
Info.PersonalityFn ||
Info.Prefix ||
Info.Prologue)
3109 FunctionOperands.push_back(Info);
3110 FunctionOperandWorklist.pop_back();
3119 BitcodeReader::decodeSignRotatedValue);
3121 return APInt(TypeBits, Words);
3124Error BitcodeReader::parseConstants() {
3132 unsigned Int32TyID = getVirtualTypeID(CurTy);
3133 unsigned CurTyID = Int32TyID;
3134 Type *CurElemTy =
nullptr;
3135 unsigned NextCstNo = ValueList.
size();
3143 switch (Entry.Kind) {
3146 return error(
"Malformed block");
3148 if (NextCstNo != ValueList.
size())
3149 return error(
"Invalid constant reference");
3163 switch (
unsigned BitCode = MaybeBitCode.
get()) {
3173 return error(
"Invalid settype record");
3174 if (
Record[0] >= TypeList.size() || !TypeList[
Record[0]])
3175 return error(
"Invalid settype record");
3176 if (TypeList[
Record[0]] == VoidType)
3177 return error(
"Invalid constant type");
3179 CurTy = TypeList[CurTyID];
3180 CurElemTy = getPtrElementTypeByID(CurTyID);
3184 return error(
"Invalid type for a constant null value");
3185 if (
auto *TETy = dyn_cast<TargetExtType>(CurTy))
3187 return error(
"Invalid type for a constant null value");
3192 return error(
"Invalid integer const record");
3197 return error(
"Invalid wide integer const record");
3201 V = ConstantInt::get(CurTy, VInt);
3206 return error(
"Invalid float const record");
3209 if (ScalarTy->isHalfTy())
3210 V = ConstantFP::get(CurTy,
APFloat(APFloat::IEEEhalf(),
3212 else if (ScalarTy->isBFloatTy())
3213 V = ConstantFP::get(
3215 else if (ScalarTy->isFloatTy())
3216 V = ConstantFP::get(CurTy,
APFloat(APFloat::IEEEsingle(),
3218 else if (ScalarTy->isDoubleTy())
3219 V = ConstantFP::get(
3221 else if (ScalarTy->isX86_FP80Ty()) {
3224 Rearrange[0] = (
Record[1] & 0xffffLL) | (
Record[0] << 16);
3225 Rearrange[1] =
Record[0] >> 48;
3226 V = ConstantFP::get(
3227 CurTy,
APFloat(APFloat::x87DoubleExtended(),
APInt(80, Rearrange)));
3228 }
else if (ScalarTy->isFP128Ty())
3229 V = ConstantFP::get(CurTy,
3231 else if (ScalarTy->isPPC_FP128Ty())
3232 V = ConstantFP::get(
3241 return error(
"Invalid aggregate record");
3245 for (
unsigned i = 0; i !=
Size; ++i)
3248 if (isa<StructType>(CurTy)) {
3249 V = BitcodeConstant::create(
3250 Alloc, CurTy, BitcodeConstant::ConstantStructOpcode, Elts);
3251 }
else if (isa<ArrayType>(CurTy)) {
3252 V = BitcodeConstant::create(Alloc, CurTy,
3253 BitcodeConstant::ConstantArrayOpcode, Elts);
3254 }
else if (isa<VectorType>(CurTy)) {
3255 V = BitcodeConstant::create(
3256 Alloc, CurTy, BitcodeConstant::ConstantVectorOpcode, Elts);
3265 return error(
"Invalid string record");
3274 return error(
"Invalid data record");
3277 if (
auto *Array = dyn_cast<ArrayType>(CurTy))
3278 EltTy =
Array->getElementType();
3280 EltTy = cast<VectorType>(CurTy)->getElementType();
3283 if (isa<VectorType>(CurTy))
3289 if (isa<VectorType>(CurTy))
3295 if (isa<VectorType>(CurTy))
3301 if (isa<VectorType>(CurTy))
3307 if (isa<VectorType>(CurTy))
3313 if (isa<VectorType>(CurTy))
3319 if (isa<VectorType>(CurTy))
3325 if (isa<VectorType>(CurTy))
3330 return error(
"Invalid type for value");
3336 return error(
"Invalid unary op constexpr record");
3341 V = BitcodeConstant::create(Alloc, CurTy, Opc, (
unsigned)
Record[1]);
3347 return error(
"Invalid binary op constexpr record");
3353 if (
Record.size() >= 4) {
3354 if (Opc == Instruction::Add ||
3355 Opc == Instruction::Sub ||
3356 Opc == Instruction::Mul ||
3357 Opc == Instruction::Shl) {
3362 }
else if (Opc == Instruction::SDiv ||
3363 Opc == Instruction::UDiv ||
3364 Opc == Instruction::LShr ||
3365 Opc == Instruction::AShr) {
3370 V = BitcodeConstant::create(Alloc, CurTy, {(uint8_t)Opc, Flags},
3377 return error(
"Invalid cast constexpr record");
3382 unsigned OpTyID =
Record[1];
3383 Type *OpTy = getTypeByID(OpTyID);
3385 return error(
"Invalid cast constexpr record");
3386 V = BitcodeConstant::create(Alloc, CurTy, Opc, (
unsigned)
Record[2]);
3398 return error(
"Constant GEP record must have at least two elements");
3400 Type *PointeeType =
nullptr;
3404 PointeeType = getTypeByID(
Record[OpNum++]);
3407 std::optional<ConstantRange>
InRange;
3411 unsigned InRangeIndex =
Op >> 1;
3418 readBitWidthAndConstantRange(
Record, OpNum);
3428 unsigned BaseTypeID =
Record[OpNum];
3429 while (OpNum !=
Record.size()) {
3430 unsigned ElTyID =
Record[OpNum++];
3431 Type *ElTy = getTypeByID(ElTyID);
3433 return error(
"Invalid getelementptr constexpr record");
3437 if (Elts.
size() < 1)
3438 return error(
"Invalid gep with no operands");
3442 BaseTypeID = getContainedTypeID(BaseTypeID, 0);
3443 BaseType = getTypeByID(BaseTypeID);
3448 return error(
"GEP base operand must be pointer or vector of pointer");
3451 PointeeType = getPtrElementTypeByID(BaseTypeID);
3453 return error(
"Missing element type for old-style constant GEP");
3456 V = BitcodeConstant::create(
3458 {Instruction::GetElementPtr, uint8_t(Flags), PointeeType,
InRange},
3464 return error(
"Invalid select constexpr record");
3466 V = BitcodeConstant::create(
3467 Alloc, CurTy, Instruction::Select,
3474 return error(
"Invalid extractelement constexpr record");
3475 unsigned OpTyID =
Record[0];
3477 dyn_cast_or_null<VectorType>(getTypeByID(OpTyID));
3479 return error(
"Invalid extractelement constexpr record");
3481 if (
Record.size() == 4) {
3482 unsigned IdxTyID =
Record[2];
3483 Type *IdxTy = getTypeByID(IdxTyID);
3485 return error(
"Invalid extractelement constexpr record");
3491 V = BitcodeConstant::create(Alloc, CurTy, Instruction::ExtractElement,
3497 VectorType *OpTy = dyn_cast<VectorType>(CurTy);
3498 if (
Record.size() < 3 || !OpTy)
3499 return error(
"Invalid insertelement constexpr record");
3501 if (
Record.size() == 4) {
3502 unsigned IdxTyID =
Record[2];
3503 Type *IdxTy = getTypeByID(IdxTyID);
3505 return error(
"Invalid insertelement constexpr record");
3511 V = BitcodeConstant::create(
3512 Alloc, CurTy, Instruction::InsertElement,
3517 VectorType *OpTy = dyn_cast<VectorType>(CurTy);
3518 if (
Record.size() < 3 || !OpTy)
3519 return error(
"Invalid shufflevector constexpr record");
3520 V = BitcodeConstant::create(
3521 Alloc, CurTy, Instruction::ShuffleVector,
3526 VectorType *RTy = dyn_cast<VectorType>(CurTy);
3528 dyn_cast_or_null<VectorType>(getTypeByID(
Record[0]));
3529 if (
Record.size() < 4 || !RTy || !OpTy)
3530 return error(
"Invalid shufflevector constexpr record");
3531 V = BitcodeConstant::create(
3532 Alloc, CurTy, Instruction::ShuffleVector,
3538 return error(
"Invalid cmp constexpt record");
3539 unsigned OpTyID =
Record[0];
3540 Type *OpTy = getTypeByID(OpTyID);
3542 return error(
"Invalid cmp constexpr record");
3543 V = BitcodeConstant::create(
3546 : Instruction::ICmp),
3555 return error(
"Invalid inlineasm record");
3556 std::string AsmStr, ConstrStr;
3557 bool HasSideEffects =
Record[0] & 1;
3558 bool IsAlignStack =
Record[0] >> 1;
3559 unsigned AsmStrSize =
Record[1];
3560 if (2+AsmStrSize >=
Record.size())
3561 return error(
"Invalid inlineasm record");
3562 unsigned ConstStrSize =
Record[2+AsmStrSize];
3563 if (3+AsmStrSize+ConstStrSize >
Record.size())
3564 return error(
"Invalid inlineasm record");
3566 for (
unsigned i = 0; i != AsmStrSize; ++i)
3567 AsmStr += (
char)
Record[2+i];
3568 for (
unsigned i = 0; i != ConstStrSize; ++i)
3569 ConstrStr += (
char)
Record[3+AsmStrSize+i];
3572 return error(
"Missing element type for old-style inlineasm");
3574 HasSideEffects, IsAlignStack);
3581 return error(
"Invalid inlineasm record");
3582 std::string AsmStr, ConstrStr;
3583 bool HasSideEffects =
Record[0] & 1;
3584 bool IsAlignStack = (
Record[0] >> 1) & 1;
3585 unsigned AsmDialect =
Record[0] >> 2;
3586 unsigned AsmStrSize =
Record[1];
3587 if (2+AsmStrSize >=
Record.size())
3588 return error(
"Invalid inlineasm record");
3589 unsigned ConstStrSize =
Record[2+AsmStrSize];
3590 if (3+AsmStrSize+ConstStrSize >
Record.size())
3591 return error(
"Invalid inlineasm record");
3593 for (
unsigned i = 0; i != AsmStrSize; ++i)
3594 AsmStr += (
char)
Record[2+i];
3595 for (
unsigned i = 0; i != ConstStrSize; ++i)
3596 ConstrStr += (
char)
Record[3+AsmStrSize+i];
3599 return error(
"Missing element type for old-style inlineasm");
3601 HasSideEffects, IsAlignStack,
3608 return error(
"Invalid inlineasm record");
3610 std::string AsmStr, ConstrStr;
3611 bool HasSideEffects =
Record[OpNum] & 1;
3612 bool IsAlignStack = (
Record[OpNum] >> 1) & 1;
3613 unsigned AsmDialect = (
Record[OpNum] >> 2) & 1;
3614 bool CanThrow = (
Record[OpNum] >> 3) & 1;
3616 unsigned AsmStrSize =
Record[OpNum];
3618 if (OpNum + AsmStrSize >=
Record.size())
3619 return error(
"Invalid inlineasm record");
3620 unsigned ConstStrSize =
Record[OpNum + AsmStrSize];
3621 if (OpNum + 1 + AsmStrSize + ConstStrSize >
Record.size())
3622 return error(
"Invalid inlineasm record");
3624 for (
unsigned i = 0; i != AsmStrSize; ++i)
3625 AsmStr += (
char)
Record[OpNum + i];
3627 for (
unsigned i = 0; i != ConstStrSize; ++i)
3628 ConstrStr += (
char)
Record[OpNum + AsmStrSize + i];
3631 return error(
"Missing element type for old-style inlineasm");
3633 HasSideEffects, IsAlignStack,
3640 return error(
"Invalid inlineasm record");
3642 auto *FnTy = dyn_cast_or_null<FunctionType>(getTypeByID(
Record[OpNum]));
3645 return error(
"Invalid inlineasm record");
3646 std::string AsmStr, ConstrStr;
3647 bool HasSideEffects =
Record[OpNum] & 1;
3648 bool IsAlignStack = (
Record[OpNum] >> 1) & 1;
3649 unsigned AsmDialect = (
Record[OpNum] >> 2) & 1;
3650 bool CanThrow = (
Record[OpNum] >> 3) & 1;
3652 unsigned AsmStrSize =
Record[OpNum];
3654 if (OpNum + AsmStrSize >=
Record.size())
3655 return error(
"Invalid inlineasm record");
3656 unsigned ConstStrSize =
Record[OpNum + AsmStrSize];
3657 if (OpNum + 1 + AsmStrSize + ConstStrSize >
Record.size())
3658 return error(
"Invalid inlineasm record");
3660 for (
unsigned i = 0; i != AsmStrSize; ++i)
3661 AsmStr += (
char)
Record[OpNum + i];
3663 for (
unsigned i = 0; i != ConstStrSize; ++i)
3664 ConstrStr += (
char)
Record[OpNum + AsmStrSize + i];
3666 V =
InlineAsm::get(FnTy, AsmStr, ConstrStr, HasSideEffects, IsAlignStack,
3672 return error(
"Invalid blockaddress record");
3673 unsigned FnTyID =
Record[0];
3674 Type *FnTy = getTypeByID(FnTyID);
3676 return error(
"Invalid blockaddress record");
3677 V = BitcodeConstant::create(
3685 return error(
"Invalid dso_local record");
3686 unsigned GVTyID =
Record[0];
3687 Type *GVTy = getTypeByID(GVTyID);
3689 return error(
"Invalid dso_local record");
3690 V = BitcodeConstant::create(
3691 Alloc, CurTy, BitcodeConstant::DSOLocalEquivalentOpcode,
Record[1]);
3696 return error(
"Invalid no_cfi record");
3697 unsigned GVTyID =
Record[0];
3698 Type *GVTy = getTypeByID(GVTyID);
3700 return error(
"Invalid no_cfi record");
3701 V = BitcodeConstant::create(Alloc, CurTy, BitcodeConstant::NoCFIOpcode,
3707 return error(
"Invalid ptrauth record");
3709 V = BitcodeConstant::create(Alloc, CurTy,
3710 BitcodeConstant::ConstantPtrAuthOpcode,
3717 assert(
V->getType() == getTypeByID(CurTyID) &&
"Incorrect result type ID");
3724Error BitcodeReader::parseUseLists() {
3737 switch (
Entry.Kind) {
3740 return error(
"Malformed block");
3754 switch (MaybeRecord.
get()) {
3762 if (RecordLength < 3)
3764 return error(
"Invalid record");
3765 unsigned ID =
Record.pop_back_val();
3769 assert(
ID < FunctionBBs.size() &&
"Basic block not found");
3770 V = FunctionBBs[
ID];
3773 unsigned NumUses = 0;
3775 for (
const Use &U :
V->materialized_uses()) {
3776 if (++NumUses >
Record.size())
3778 Order[&
U] =
Record[NumUses - 1];
3785 V->sortUseList([&](
const Use &L,
const Use &R) {
3796Error BitcodeReader::rememberAndSkipMetadata() {
3798 uint64_t CurBit = Stream.GetCurrentBitNo();
3799 DeferredMetadataInfo.push_back(CurBit);
3802 if (
Error Err = Stream.SkipBlock())
3807Error BitcodeReader::materializeMetadata() {
3808 for (
uint64_t BitPos : DeferredMetadataInfo) {
3810 if (
Error JumpFailed = Stream.JumpToBit(BitPos))
3812 if (
Error Err = MDLoader->parseModuleMetadata())
3823 for (
const MDOperand &MDOptions : cast<MDNode>(Val)->operands())
3824 LinkerOpts->
addOperand(cast<MDNode>(MDOptions));
3828 DeferredMetadataInfo.clear();
3832void BitcodeReader::setStripDebugInfo() {
StripDebugInfo =
true; }
3836Error BitcodeReader::rememberAndSkipFunctionBody() {
3838 if (FunctionsWithBodies.empty())
3839 return error(
"Insufficient function protos");
3842 FunctionsWithBodies.pop_back();
3845 uint64_t CurBit = Stream.GetCurrentBitNo();
3847 (DeferredFunctionInfo[Fn] == 0 || DeferredFunctionInfo[Fn] == CurBit) &&
3848 "Mismatch between VST and scanned function offsets");
3849 DeferredFunctionInfo[Fn] = CurBit;
3852 if (
Error Err = Stream.SkipBlock())
3857Error BitcodeReader::globalCleanup() {
3859 if (
Error Err = resolveGlobalAndIndirectSymbolInits())
3861 if (!GlobalInits.empty() || !IndirectSymbolInits.empty())
3862 return error(
"Malformed global initializer set");
3867 MDLoader->upgradeDebugIntrinsics(
F);
3874 UpgradedIntrinsics[&
F] = NewFn;
3880 std::vector<std::pair<GlobalVariable *, GlobalVariable *>> UpgradedVariables;
3883 UpgradedVariables.emplace_back(&GV, Upgraded);
3884 for (
auto &Pair : UpgradedVariables) {
3885 Pair.first->eraseFromParent();
3886 TheModule->insertGlobalVariable(Pair.second);
3891 std::vector<std::pair<GlobalVariable *, unsigned>>().
swap(GlobalInits);
3892 std::vector<std::pair<GlobalValue *, unsigned>>().
swap(IndirectSymbolInits);
3900Error BitcodeReader::rememberAndSkipFunctionBodies() {
3901 if (
Error JumpFailed = Stream.JumpToBit(NextUnreadBit))
3904 if (Stream.AtEndOfStream())
3905 return error(
"Could not find function in stream");
3907 if (!SeenFirstFunctionBody)
3908 return error(
"Trying to materialize functions before seeing function blocks");
3912 assert(SeenValueSymbolTable);
3922 switch (
Entry.Kind) {
3924 return error(
"Expect SubBlock");
3928 return error(
"Expect function block");
3930 if (
Error Err = rememberAndSkipFunctionBody())
3932 NextUnreadBit = Stream.GetCurrentBitNo();
3939Error BitcodeReaderBase::readBlockInfo() {
3941 Stream.ReadBlockInfoBlock();
3942 if (!MaybeNewBlockInfo)
3944 std::optional<BitstreamBlockInfo> NewBlockInfo =
3945 std::move(MaybeNewBlockInfo.
get());
3947 return error(
"Malformed block");
3948 BlockInfo = std::move(*NewBlockInfo);
3959 return error(
"Invalid record");
3961 std::string OldFormatName;
3964 return error(
"Invalid record");
3965 unsigned ComdatNameSize =
Record[1];
3966 if (ComdatNameSize >
Record.size() - 2)
3967 return error(
"Comdat name size too large");
3968 OldFormatName.reserve(ComdatNameSize);
3969 for (
unsigned i = 0; i != ComdatNameSize; ++i)
3970 OldFormatName += (
char)
Record[2 + i];
3971 Name = OldFormatName;
3974 C->setSelectionKind(SK);
3975 ComdatList.push_back(
C);
3989 Meta.NoAddress =
true;
3991 Meta.NoHWAddress =
true;
3995 Meta.IsDynInit =
true;
4010 return error(
"Invalid record");
4011 unsigned TyID =
Record[0];
4012 Type *Ty = getTypeByID(TyID);
4014 return error(
"Invalid record");
4016 bool explicitType =
Record[1] & 2;
4022 return error(
"Invalid type for value");
4023 AddressSpace = cast<PointerType>(Ty)->getAddressSpace();
4024 TyID = getContainedTypeID(TyID);
4025 Ty = getTypeByID(TyID);
4027 return error(
"Missing element type for old-style global");
4033 if (
Error Err = parseAlignmentValue(
Record[4], Alignment))
4037 if (
Record[5] - 1 >= SectionTable.size())
4038 return error(
"Invalid ID");
4055 bool ExternallyInitialized =
false;
4057 ExternallyInitialized =
Record[9];
4069 if (
Record.size() > 10) {
4081 if (
unsigned InitID =
Record[2])
4082 GlobalInits.push_back(std::make_pair(NewGV, InitID - 1));
4084 if (
Record.size() > 11) {
4085 if (
unsigned ComdatID =
Record[11]) {
4086 if (ComdatID > ComdatList.size())
4087 return error(
"Invalid global variable comdat ID");
4088 NewGV->
setComdat(ComdatList[ComdatID - 1]);
4091 ImplicitComdatObjects.
insert(NewGV);
4094 if (
Record.size() > 12) {
4099 if (
Record.size() > 13) {
4118 return error(
"Invalid global variable code model");
4124void BitcodeReader::callValueTypeCallback(
Value *
F,
unsigned TypeID) {
4125 if (ValueTypeCallback) {
4126 (*ValueTypeCallback)(
4127 F,
TypeID, [
this](
unsigned I) {
return getTypeByID(
I); },
4128 [
this](
unsigned I,
unsigned J) {
return getContainedTypeID(
I, J); });
4141 return error(
"Invalid record");
4142 unsigned FTyID =
Record[0];
4143 Type *FTy = getTypeByID(FTyID);
4145 return error(
"Invalid record");
4146 if (isa<PointerType>(FTy)) {
4147 FTyID = getContainedTypeID(FTyID, 0);
4148 FTy = getTypeByID(FTyID);
4150 return error(
"Missing element type for old-style function");
4153 if (!isa<FunctionType>(FTy))
4154 return error(
"Invalid type for value");
4157 return error(
"Invalid calling convention ID");
4159 unsigned AddrSpace = TheModule->getDataLayout().getProgramAddressSpace();
4165 AddrSpace,
Name, TheModule);
4168 "Incorrect fully specified type provided for function");
4169 FunctionTypeIDs[
Func] = FTyID;
4171 Func->setCallingConv(
CC);
4172 bool isProto =
Record[2];
4176 callValueTypeCallback(Func, FTyID);
4181 for (
unsigned i = 0; i !=
Func->arg_size(); ++i) {
4183 Attribute::InAlloca}) {
4184 if (!
Func->hasParamAttribute(i, Kind))
4187 if (
Func->getParamAttribute(i, Kind).getValueAsType())
4190 Func->removeParamAttr(i, Kind);
4192 unsigned ParamTypeID = getContainedTypeID(FTyID, i + 1);
4193 Type *PtrEltTy = getPtrElementTypeByID(ParamTypeID);
4195 return error(
"Missing param element type for attribute upgrade");
4199 case Attribute::ByVal:
4202 case Attribute::StructRet:
4205 case Attribute::InAlloca:
4212 Func->addParamAttr(i, NewAttr);
4217 !
Func->arg_empty() && !
Func->hasParamAttribute(0, Attribute::ByVal)) {
4218 unsigned ParamTypeID = getContainedTypeID(FTyID, 1);
4219 Type *ByValTy = getPtrElementTypeByID(ParamTypeID);
4221 return error(
"Missing param element type for x86_intrcc upgrade");
4223 Func->addParamAttr(0, NewAttr);
4227 if (
Error Err = parseAlignmentValue(
Record[5], Alignment))
4230 Func->setAlignment(*Alignment);
4232 if (
Record[6] - 1 >= SectionTable.size())
4233 return error(
"Invalid ID");
4234 Func->setSection(SectionTable[
Record[6] - 1]);
4238 if (!
Func->hasLocalLinkage())
4241 if (
Record[8] - 1 >= GCTable.size())
4242 return error(
"Invalid ID");
4248 Func->setUnnamedAddr(UnnamedAddr);
4250 FunctionOperandInfo OperandInfo = {
Func, 0, 0, 0};
4252 OperandInfo.Prologue =
Record[10];
4254 if (
Record.size() > 11) {
4256 if (!
Func->hasLocalLinkage()) {
4263 if (
Record.size() > 12) {
4264 if (
unsigned ComdatID =
Record[12]) {
4265 if (ComdatID > ComdatList.size())
4266 return error(
"Invalid function comdat ID");
4267 Func->setComdat(ComdatList[ComdatID - 1]);
4270 ImplicitComdatObjects.
insert(Func);
4274 OperandInfo.Prefix =
Record[13];
4277 OperandInfo.PersonalityFn =
Record[14];
4279 if (
Record.size() > 15) {
4288 if (
Record.size() > 18 && Strtab.data() &&
4293 ValueList.
push_back(Func, getVirtualTypeID(
Func->getType(), FTyID));
4295 if (OperandInfo.PersonalityFn || OperandInfo.Prefix || OperandInfo.Prologue)
4296 FunctionOperands.push_back(OperandInfo);
4301 Func->setIsMaterializable(
true);
4302 FunctionsWithBodies.push_back(Func);
4303 DeferredFunctionInfo[
Func] = 0;
4308Error BitcodeReader::parseGlobalIndirectSymbolRecord(
4322 if (
Record.size() < (3 + (
unsigned)NewRecord))
4323 return error(
"Invalid record");
4328 return error(
"Invalid record");
4332 auto *PTy = dyn_cast<PointerType>(Ty);
4334 return error(
"Invalid type for value");
4335 AddrSpace = PTy->getAddressSpace();
4337 Ty = getTypeByID(
TypeID);
4339 return error(
"Missing element type for old-style indirect symbol");
4341 AddrSpace =
Record[OpNum++];
4344 auto Val =
Record[OpNum++];
4353 nullptr, TheModule);
4357 if (OpNum !=
Record.size()) {
4358 auto VisInd = OpNum++;
4364 if (OpNum !=
Record.size()) {
4365 auto S =
Record[OpNum++];
4372 if (OpNum !=
Record.size())
4374 if (OpNum !=
Record.size())
4377 if (OpNum !=
Record.size())
4382 if (OpNum + 1 <
Record.size()) {
4385 return error(
"Malformed partition, too large.");
4391 IndirectSymbolInits.push_back(std::make_pair(NewGA, Val));
4396 bool ShouldLazyLoadMetadata,
4402 TheModule->IsNewDbgInfoFormat =
4407 this->ValueTypeCallback = std::move(Callbacks.
ValueType);
4409 if (
Error JumpFailed = Stream.JumpToBit(ResumeBit))
4418 bool ResolvedDataLayout =
false;
4423 std::string TentativeDataLayoutStr = TheModule->getDataLayoutStr();
4425 auto ResolveDataLayout = [&]() ->
Error {
4426 if (ResolvedDataLayout)
4430 ResolvedDataLayout =
true;
4434 TentativeDataLayoutStr, TheModule->getTargetTriple());
4438 if (
auto LayoutOverride = (*Callbacks.
DataLayout)(
4439 TheModule->getTargetTriple(), TentativeDataLayoutStr))
4440 TentativeDataLayoutStr = *LayoutOverride;
4448 TheModule->setDataLayout(MaybeDL.
get());
4459 switch (
Entry.Kind) {
4461 return error(
"Malformed block");
4463 if (
Error Err = ResolveDataLayout())
4465 return globalCleanup();
4470 if (
Error Err = Stream.SkipBlock())
4474 if (
Error Err = readBlockInfo())
4478 if (
Error Err = parseAttributeBlock())
4482 if (
Error Err = parseAttributeGroupBlock())
4486 if (
Error Err = parseTypeTable())
4490 if (!SeenValueSymbolTable) {
4496 assert(VSTOffset == 0 || FunctionsWithBodies.empty());
4497 if (
Error Err = parseValueSymbolTable())
4499 SeenValueSymbolTable =
true;
4504 if (
Error Err = Stream.SkipBlock())
4509 if (
Error Err = parseConstants())
4511 if (
Error Err = resolveGlobalAndIndirectSymbolInits())
4515 if (ShouldLazyLoadMetadata) {
4516 if (
Error Err = rememberAndSkipMetadata())
4520 assert(DeferredMetadataInfo.empty() &&
"Unexpected deferred metadata");
4521 if (
Error Err = MDLoader->parseModuleMetadata())
4525 if (
Error Err = MDLoader->parseMetadataKinds())
4529 if (
Error Err = ResolveDataLayout())
4534 if (!SeenFirstFunctionBody) {
4535 std::reverse(FunctionsWithBodies.begin(), FunctionsWithBodies.end());
4536 if (
Error Err = globalCleanup())
4538 SeenFirstFunctionBody =
true;
4541 if (VSTOffset > 0) {
4545 if (!SeenValueSymbolTable) {
4546 if (
Error Err = BitcodeReader::parseValueSymbolTable(VSTOffset))
4548 SeenValueSymbolTable =
true;
4560 if (
Error Err = Stream.SkipBlock())
4570 if (
Error Err = rememberAndSkipFunctionBody())
4577 if (SeenValueSymbolTable) {
4578 NextUnreadBit = Stream.GetCurrentBitNo();
4581 return globalCleanup();
4585 if (
Error Err = parseUseLists())
4589 if (
Error Err = parseOperandBundleTags())
4593 if (
Error Err = parseSyncScopeNames())
4608 switch (
unsigned BitCode = MaybeBitCode.
get()) {
4614 UseRelativeIDs = *VersionOrErr >= 1;
4618 if (ResolvedDataLayout)
4619 return error(
"target triple too late in module");
4622 return error(
"Invalid record");
4623 TheModule->setTargetTriple(S);
4627 if (ResolvedDataLayout)
4628 return error(
"datalayout too late in module");
4630 return error(
"Invalid record");
4636 return error(
"Invalid record");
4637 TheModule->setModuleInlineAsm(S);
4644 return error(
"Invalid record");
4651 return error(
"Invalid record");
4652 SectionTable.push_back(S);
4658 return error(
"Invalid record");
4659 GCTable.push_back(S);
4676 if (
Error Err = ResolveDataLayout())
4684 if (
Error Err = parseGlobalIndirectSymbolRecord(BitCode,
Record))
4690 return error(
"Invalid record");
4694 VSTOffset =
Record[0] - 1;
4700 return error(
"Invalid record");
4701 TheModule->setSourceFileName(
ValueName);
4706 this->ValueTypeCallback = std::nullopt;
4710Error BitcodeReader::parseBitcodeInto(
Module *M,
bool ShouldLazyLoadMetadata,
4715 MDCallbacks.
GetTypeByID = [&](
unsigned ID) {
return getTypeByID(
ID); };
4717 return getContainedTypeID(
I, J);
4720 MDLoader =
MetadataLoader(Stream, *M, ValueList, IsImporting, MDCallbacks);
4721 return parseModule(0, ShouldLazyLoadMetadata, Callbacks);
4724Error BitcodeReader::typeCheckLoadStoreInst(
Type *ValType,
Type *PtrType) {
4725 if (!isa<PointerType>(PtrType))
4726 return error(
"Load/Store operand is not a pointer type");
4727 if (!PointerType::isLoadableOrStorableType(ValType))
4728 return error(
"Cannot load/store from pointer");
4735 for (
unsigned i = 0; i != CB->
arg_size(); ++i) {
4737 Attribute::InAlloca}) {
4738 if (!
Attrs.hasParamAttr(i, Kind) ||
4739 Attrs.getParamAttr(i, Kind).getValueAsType())
4742 Type *PtrEltTy = getPtrElementTypeByID(ArgTyIDs[i]);
4744 return error(
"Missing element type for typed attribute upgrade");
4748 case Attribute::ByVal:
4751 case Attribute::StructRet:
4754 case Attribute::InAlloca:
4761 Attrs =
Attrs.addParamAttribute(Context, i, NewAttr);
4772 if (CI.isIndirect && !
Attrs.getParamElementType(ArgNo)) {
4773 Type *ElemTy = getPtrElementTypeByID(ArgTyIDs[ArgNo]);
4775 return error(
"Missing element type for inline asm upgrade");
4786 case Intrinsic::preserve_array_access_index:
4787 case Intrinsic::preserve_struct_access_index:
4788 case Intrinsic::aarch64_ldaxr:
4789 case Intrinsic::aarch64_ldxr:
4790 case Intrinsic::aarch64_stlxr:
4791 case Intrinsic::aarch64_stxr:
4792 case Intrinsic::arm_ldaex:
4793 case Intrinsic::arm_ldrex:
4794 case Intrinsic::arm_stlex:
4795 case Intrinsic::arm_strex: {
4798 case Intrinsic::aarch64_stlxr:
4799 case Intrinsic::aarch64_stxr:
4800 case Intrinsic::arm_stlex:
4801 case Intrinsic::arm_strex:
4808 if (!
Attrs.getParamElementType(ArgNo)) {
4809 Type *ElTy = getPtrElementTypeByID(ArgTyIDs[ArgNo]);
4811 return error(
"Missing element type for elementtype upgrade");
4813 Attrs =
Attrs.addParamAttribute(Context, ArgNo, NewAttr);
4831 if (MDLoader->hasFwdRefs())
4832 return error(
"Invalid function metadata: incoming forward references");
4834 InstructionList.
clear();
4835 unsigned ModuleValueListSize = ValueList.
size();
4836 unsigned ModuleMDLoaderSize = MDLoader->size();
4840 unsigned FTyID = FunctionTypeIDs[
F];
4842 unsigned ArgTyID = getContainedTypeID(FTyID, ArgNo + 1);
4843 assert(
I.getType() == getTypeByID(ArgTyID) &&
4844 "Incorrect fully specified type for Function Argument");
4848 unsigned NextValueNo = ValueList.
size();
4850 unsigned CurBBNo = 0;
4859 auto getLastInstruction = [&]() ->
Instruction * {
4860 if (CurBB && !CurBB->
empty())
4861 return &CurBB->
back();
4862 else if (CurBBNo && FunctionBBs[CurBBNo - 1] &&
4863 !FunctionBBs[CurBBNo - 1]->empty())
4864 return &FunctionBBs[CurBBNo - 1]->back();
4868 std::vector<OperandBundleDef> OperandBundles;
4879 switch (
Entry.Kind) {
4881 return error(
"Malformed block");