24#include "llvm/Config/llvm-config.h"
53#include "llvm/IR/IntrinsicsAArch64.h"
54#include "llvm/IR/IntrinsicsARM.h"
86#include <system_error>
96 "Print the global id for each value when reading the module summary"));
101 "Expand constant expressions to instructions for testing purposes"));
108 "load-bitcode-into-experimental-debuginfo-iterators",
cl::Hidden,
109 cl::desc(
"Load bitcode directly into the new debug info format (regardless "
110 "of input format)"));
118 SWITCH_INST_MAGIC = 0x4B5
124 return make_error<StringError>(
131 "file too small to contain bitcode header");
132 for (
unsigned C : {
'B',
'C'})
136 "file doesn't start with bitcode header");
138 return Res.takeError();
139 for (
unsigned C : {0x0, 0xC, 0xE, 0xD})
143 "file doesn't start with bitcode header");
145 return Res.takeError();
150 const unsigned char *BufPtr = (
const unsigned char *)Buffer.
getBufferStart();
151 const unsigned char *BufEnd = BufPtr + Buffer.
getBufferSize();
154 return error(
"Invalid bitcode signature");
160 return error(
"Invalid bitcode wrapper header");
164 return std::move(Err);
166 return std::move(Stream);
170template <
typename StrTy>
183 if (
F.isMaterializable())
186 I.setMetadata(LLVMContext::MD_tbaa,
nullptr);
194 return std::move(Err);
199 std::string ProducerIdentification;
206 switch (Entry.Kind) {
209 return error(
"Malformed block");
211 return ProducerIdentification;
222 switch (MaybeBitCode.
get()) {
224 return error(
"Invalid value");
232 Twine(
"Incompatible epoch: Bitcode '") +
Twine(epoch) +
251 switch (Entry.Kind) {
254 return error(
"Malformed block");
262 return std::move(Err);
274 return std::move(Err);
285 switch (Entry.Kind) {
288 return error(
"Malformed block");
300 switch (MaybeRecord.
get()) {
306 return error(
"Invalid section name record");
308 if (S.find(
"__DATA,__objc_catlist") != std::string::npos ||
309 S.find(
"__OBJC,__category") != std::string::npos ||
310 S.find(
"__TEXT,__swift") != std::string::npos)
328 switch (Entry.Kind) {
330 return error(
"Malformed block");
340 return std::move(Err);
353 return std::move(Err);
366 switch (Entry.Kind) {
369 return error(
"Malformed block");
381 switch (MaybeRecord.
get()) {
386 return error(
"Invalid triple record");
405 switch (Entry.Kind) {
407 return error(
"Malformed block");
417 return std::move(Err);
424 return Skipped.takeError();
431class BitcodeReaderBase {
434 : Stream(
std::
move(Stream)), Strtab(Strtab) {
444 bool UseStrtab =
false;
451 std::pair<StringRef, ArrayRef<uint64_t>>
454 Error readBlockInfo();
457 std::string ProducerIdentification;
464Error BitcodeReaderBase::error(
const Twine &Message) {
465 std::string FullMsg = Message.
str();
466 if (!ProducerIdentification.empty())
467 FullMsg +=
" (Producer: '" + ProducerIdentification +
"' Reader: 'LLVM " +
468 LLVM_VERSION_STRING
"')";
469 return ::error(FullMsg);
475 return error(
"Invalid version record");
476 unsigned ModuleVersion =
Record[0];
477 if (ModuleVersion > 2)
478 return error(
"Invalid value");
479 UseStrtab = ModuleVersion >= 2;
480 return ModuleVersion;
483std::pair<StringRef, ArrayRef<uint64_t>>
501class BitcodeConstant final :
public Value,
506 static constexpr uint8_t SubclassID = 255;
514 static constexpr uint8_t ConstantStructOpcode = 255;
515 static constexpr uint8_t ConstantArrayOpcode = 254;
516 static constexpr uint8_t ConstantVectorOpcode = 253;
517 static constexpr uint8_t NoCFIOpcode = 252;
518 static constexpr uint8_t DSOLocalEquivalentOpcode = 251;
519 static constexpr uint8_t BlockAddressOpcode = 250;
520 static constexpr uint8_t FirstSpecialOpcode = BlockAddressOpcode;
527 unsigned BlockAddressBB = 0;
528 Type *SrcElemTy =
nullptr;
529 std::optional<ConstantRange> InRange;
531 ExtraInfo(uint8_t Opcode, uint8_t Flags = 0,
Type *SrcElemTy =
nullptr,
532 std::optional<ConstantRange> InRange = std::nullopt)
533 : Opcode(Opcode),
Flags(
Flags), SrcElemTy(SrcElemTy),
536 ExtraInfo(uint8_t Opcode, uint8_t Flags,
unsigned BlockAddressBB)
537 : Opcode(Opcode),
Flags(
Flags), BlockAddressBB(BlockAddressBB) {}
542 unsigned NumOperands;
543 unsigned BlockAddressBB;
545 std::optional<ConstantRange>
InRange;
550 NumOperands(OpIDs.
size()), BlockAddressBB(
Info.BlockAddressBB),
551 SrcElemTy(
Info.SrcElemTy), InRange(
Info.InRange) {
552 std::uninitialized_copy(OpIDs.
begin(), OpIDs.
end(),
553 getTrailingObjects<unsigned>());
556 BitcodeConstant &
operator=(
const BitcodeConstant &) =
delete;
560 const ExtraInfo &Info,
562 void *Mem =
A.Allocate(totalSizeToAlloc<unsigned>(OpIDs.
size()),
563 alignof(BitcodeConstant));
564 return new (Mem) BitcodeConstant(Ty, Info, OpIDs);
567 static bool classof(
const Value *V) {
return V->getValueID() == SubclassID; }
570 return ArrayRef(getTrailingObjects<unsigned>(), NumOperands);
573 std::optional<ConstantRange> getInRange()
const {
574 assert(Opcode == Instruction::GetElementPtr);
583class BitcodeReader :
public BitcodeReaderBase,
public GVMaterializer {
585 Module *TheModule =
nullptr;
590 bool SeenValueSymbolTable =
false;
593 std::vector<std::string> SectionTable;
594 std::vector<std::string> GCTable;
596 std::vector<Type *> TypeList;
614 std::optional<MetadataLoader> MDLoader;
615 std::vector<Comdat *> ComdatList;
619 std::vector<std::pair<GlobalVariable *, unsigned>> GlobalInits;
620 std::vector<std::pair<GlobalValue *, unsigned>> IndirectSymbolInits;
622 struct FunctionOperandInfo {
624 unsigned PersonalityFn;
628 std::vector<FunctionOperandInfo> FunctionOperands;
632 std::vector<AttributeList> MAttributes;
635 std::map<unsigned, AttributeList> MAttributeGroups;
639 std::vector<BasicBlock*> FunctionBBs;
643 std::vector<Function*> FunctionsWithBodies;
648 UpdatedIntrinsicMap UpgradedIntrinsics;
653 bool SeenFirstFunctionBody =
false;
662 std::vector<uint64_t> DeferredMetadataInfo;
668 std::deque<Function *> BasicBlockFwdRefQueue;
675 std::vector<Function *> BackwardRefFunctions;
683 bool UseRelativeIDs =
false;
687 bool WillMaterializeAllForwardRefs =
false;
691 bool SeenDebugIntrinsic =
false;
692 bool SeenDebugRecord =
false;
697 std::vector<std::string> BundleTags;
700 std::optional<ValueTypeCallbackTy> ValueTypeCallback;
706 Error materializeForwardReferencedFunctions();
714 Error parseBitcodeInto(
Module *M,
bool ShouldLazyLoadMetadata,
725 std::vector<StructType *> IdentifiedStructTypes;
729 static constexpr unsigned InvalidTypeID = ~0
u;
731 Type *getTypeByID(
unsigned ID);
732 Type *getPtrElementTypeByID(
unsigned ID);
733 unsigned getContainedTypeID(
unsigned ID,
unsigned Idx = 0);
740 Value *getFnValueByID(
unsigned ID,
Type *Ty,
unsigned TyID,
748 return MDLoader->getMetadataFwdRefOrLoad(
ID);
752 if (
ID >= FunctionBBs.size())
return nullptr;
753 return FunctionBBs[
ID];
757 if (i-1 < MAttributes.size())
758 return MAttributes[i-1];
766 unsigned InstNum,
Value *&ResVal,
unsigned &
TypeID,
768 if (Slot ==
Record.size())
return true;
772 ValNo = InstNum - ValNo;
773 if (ValNo < InstNum) {
777 ResVal = getFnValueByID(ValNo,
nullptr,
TypeID, ConstExprInsertBB);
779 "Incorrect type ID stored for value");
780 return ResVal ==
nullptr;
782 if (Slot ==
Record.size())
786 ResVal = getFnValueByID(ValNo, getTypeByID(
TypeID),
TypeID,
788 return ResVal ==
nullptr;
795 unsigned InstNum,
Type *Ty,
unsigned TyID,
Value *&ResVal,
797 if (getValue(
Record, Slot, InstNum, Ty, TyID, ResVal, ConstExprInsertBB))
806 unsigned InstNum,
Type *Ty,
unsigned TyID,
Value *&ResVal,
808 ResVal = getValue(
Record, Slot, InstNum, Ty, TyID, ConstExprInsertBB);
809 return ResVal ==
nullptr;
815 unsigned InstNum,
Type *Ty,
unsigned TyID,
817 if (Slot ==
Record.size())
return nullptr;
821 ValNo = InstNum - ValNo;
822 return getFnValueByID(ValNo, Ty, TyID, ConstExprInsertBB);
827 unsigned InstNum,
Type *Ty,
unsigned TyID,
829 if (Slot ==
Record.size())
return nullptr;
833 ValNo = InstNum - ValNo;
834 return getFnValueByID(ValNo, Ty, TyID, ConstExprInsertBB);
839 if (
Record.size() - OpNum < 3)
840 return error(
"Too few records for range");
843 unsigned LowerActiveWords =
Record[OpNum];
844 unsigned UpperActiveWords =
Record[OpNum++] >> 32;
845 if (
Record.size() - OpNum < LowerActiveWords + UpperActiveWords)
846 return error(
"Too few records for range");
849 OpNum += LowerActiveWords;
852 OpNum += UpperActiveWords;
855 int64_t Start = BitcodeReader::decodeSignRotatedValue(
Record[OpNum++]);
856 int64_t
End = BitcodeReader::decodeSignRotatedValue(
Record[OpNum++]);
877 Error parseGlobalIndirectSymbolRecord(
unsigned BitCode,
880 Error parseAttributeBlock();
881 Error parseAttributeGroupBlock();
882 Error parseTypeTable();
883 Error parseTypeTableBody();
884 Error parseOperandBundleTags();
885 Error parseSyncScopeNames();
888 unsigned NameIndex,
Triple &TT);
889 void setDeferredFunctionInfo(
unsigned FuncBitcodeOffsetDelta,
Function *
F,
892 Error parseGlobalValueSymbolTable();
893 Error parseConstants();
894 Error rememberAndSkipFunctionBodies();
895 Error rememberAndSkipFunctionBody();
897 Error rememberAndSkipMetadata();
900 Error globalCleanup();
901 Error resolveGlobalAndIndirectSymbolInits();
902 Error parseUseLists();
903 Error findFunctionInStream(
912class ModuleSummaryIndexBitcodeReader :
public BitcodeReaderBase {
918 bool SeenGlobalValSummary =
false;
921 bool SeenValueSymbolTable =
false;
937 std::tuple<ValueInfo, GlobalValue::GUID, GlobalValue::GUID>>
938 ValueIdToValueInfoMap;
947 std::string SourceFileName;
959 std::vector<uint64_t> StackIds;
962 ModuleSummaryIndexBitcodeReader(
973 Error parseValueSymbolTable(
978 bool IsOldProfileFormat,
981 Error parseEntireSummary(
unsigned ID);
982 Error parseModuleStringTable();
986 std::vector<FunctionSummary::ParamAccess>
989 template <
bool AllowNullValueInfo = false>
990 std::tuple<ValueInfo, GlobalValue::GUID, GlobalValue::GUID>
991 getValueInfoFromValueId(
unsigned ValueId);
993 void addThisModule();
1009 return std::error_code();
1016 ValueList(this->Stream.SizeInBytes(),
1018 return materializeValue(
ValID, InsertBB);
1020 this->ProducerIdentification = std::string(ProducerIdentification);
1023Error BitcodeReader::materializeForwardReferencedFunctions() {
1024 if (WillMaterializeAllForwardRefs)
1028 WillMaterializeAllForwardRefs =
true;
1030 while (!BasicBlockFwdRefQueue.empty()) {
1031 Function *
F = BasicBlockFwdRefQueue.front();
1032 BasicBlockFwdRefQueue.pop_front();
1033 assert(
F &&
"Expected valid function");
1034 if (!BasicBlockFwdRefs.
count(
F))
1042 if (!
F->isMaterializable())
1043 return error(
"Never resolved function from blockaddress");
1046 if (
Error Err = materialize(
F))
1049 assert(BasicBlockFwdRefs.
empty() &&
"Function missing from queue");
1051 for (
Function *
F : BackwardRefFunctions)
1052 if (
Error Err = materialize(
F))
1054 BackwardRefFunctions.clear();
1057 WillMaterializeAllForwardRefs =
false;
1121 Flags.ReadNone = RawFlags & 0x1;
1122 Flags.ReadOnly = (RawFlags >> 1) & 0x1;
1123 Flags.NoRecurse = (RawFlags >> 2) & 0x1;
1124 Flags.ReturnDoesNotAlias = (RawFlags >> 3) & 0x1;
1125 Flags.NoInline = (RawFlags >> 4) & 0x1;
1126 Flags.AlwaysInline = (RawFlags >> 5) & 0x1;
1127 Flags.NoUnwind = (RawFlags >> 6) & 0x1;
1128 Flags.MayThrow = (RawFlags >> 7) & 0x1;
1129 Flags.HasUnknownCall = (RawFlags >> 8) & 0x1;
1130 Flags.MustBeUnreachable = (RawFlags >> 9) & 0x1;
1146 RawFlags = RawFlags >> 4;
1147 bool NotEligibleToImport = (RawFlags & 0x1) || Version < 3;
1151 bool Live = (RawFlags & 0x2) || Version < 3;
1152 bool Local = (RawFlags & 0x4);
1153 bool AutoHide = (RawFlags & 0x8);
1156 Live, Local, AutoHide, IK);
1162 (RawFlags & 0x1) ?
true :
false, (RawFlags & 0x2) ?
true :
false,
1163 (RawFlags & 0x4) ?
true :
false,
1167static std::pair<CalleeInfo::HotnessType, bool>
1171 bool HasTailCall = (RawFlags & 0x8);
1172 return {Hotness, HasTailCall};
1176 bool &HasTailCall) {
1177 static constexpr uint64_t RelBlockFreqMask =
1179 RelBF = RawFlags & RelBlockFreqMask;
1205 case 0:
return false;
1206 case 1:
return true;
1229 case 0:
return GlobalVariable::NotThreadLocal;
1231 case 1:
return GlobalVariable::GeneralDynamicTLSModel;
1232 case 2:
return GlobalVariable::LocalDynamicTLSModel;
1233 case 3:
return GlobalVariable::InitialExecTLSModel;
1234 case 4:
return GlobalVariable::LocalExecTLSModel;
1241 case 0:
return GlobalVariable::UnnamedAddr::None;
1242 case 1:
return GlobalVariable::UnnamedAddr::Global;
1243 case 2:
return GlobalVariable::UnnamedAddr::Local;
1276 return IsFP ? Instruction::FNeg : -1;
1290 return IsFP ? Instruction::FAdd : Instruction::Add;
1292 return IsFP ? Instruction::FSub : Instruction::Sub;
1294 return IsFP ? Instruction::FMul : Instruction::Mul;
1296 return IsFP ? -1 : Instruction::UDiv;
1298 return IsFP ? Instruction::FDiv : Instruction::SDiv;
1300 return IsFP ? -1 : Instruction::URem;
1302 return IsFP ? Instruction::FRem : Instruction::SRem;
1304 return IsFP ? -1 : Instruction::Shl;
1306 return IsFP ? -1 : Instruction::LShr;
1308 return IsFP ? -1 : Instruction::AShr;
1310 return IsFP ? -1 : Instruction::And;
1312 return IsFP ? -1 : Instruction::Or;
1314 return IsFP ? -1 : Instruction::Xor;
1403Type *BitcodeReader::getTypeByID(
unsigned ID) {
1405 if (
ID >= TypeList.size())
1408 if (
Type *Ty = TypeList[
ID])
1413 return TypeList[
ID] = createIdentifiedStructType(Context);
1416unsigned BitcodeReader::getContainedTypeID(
unsigned ID,
unsigned Idx) {
1417 auto It = ContainedTypeIDs.
find(
ID);
1418 if (It == ContainedTypeIDs.
end())
1419 return InvalidTypeID;
1421 if (
Idx >= It->second.size())
1422 return InvalidTypeID;
1424 return It->second[
Idx];
1427Type *BitcodeReader::getPtrElementTypeByID(
unsigned ID) {
1428 if (
ID >= TypeList.size())
1435 return getTypeByID(getContainedTypeID(
ID, 0));
1438unsigned BitcodeReader::getVirtualTypeID(
Type *Ty,
1440 unsigned ChildTypeID = ChildTypeIDs.
empty() ? InvalidTypeID : ChildTypeIDs[0];
1441 auto CacheKey = std::make_pair(Ty, ChildTypeID);
1442 auto It = VirtualTypeIDs.
find(CacheKey);
1443 if (It != VirtualTypeIDs.
end()) {
1449 ContainedTypeIDs[It->second] == ChildTypeIDs) &&
1450 "Incorrect cached contained type IDs");
1454 unsigned TypeID = TypeList.size();
1455 TypeList.push_back(Ty);
1456 if (!ChildTypeIDs.
empty())
1463 uint8_t Opcode = BC->Opcode;
1466 if (Opcode >= BitcodeConstant::FirstSpecialOpcode)
1480 if (Opcode == Instruction::GetElementPtr)
1484 case Instruction::FNeg:
1485 case Instruction::Select:
1495 if (StartValID < ValueList.
size() && ValueList[StartValID] &&
1496 !isa<BitcodeConstant>(ValueList[StartValID]))
1497 return ValueList[StartValID];
1502 while (!Worklist.
empty()) {
1511 return error(
"Invalid value ID");
1514 auto *BC = dyn_cast<BitcodeConstant>(V);
1524 for (
unsigned OpID :
reverse(BC->getOperandIDs())) {
1525 auto It = MaterializedValues.
find(OpID);
1526 if (It != MaterializedValues.
end())
1534 if (Ops.
size() != BC->getOperandIDs().size())
1536 std::reverse(Ops.
begin(), Ops.
end());
1540 if (
auto *
C = dyn_cast<Constant>(
Op))
1553 switch (BC->Opcode) {
1554 case BitcodeConstant::NoCFIOpcode: {
1555 auto *GV = dyn_cast<GlobalValue>(ConstOps[0]);
1557 return error(
"no_cfi operand must be GlobalValue");
1561 case BitcodeConstant::DSOLocalEquivalentOpcode: {
1562 auto *GV = dyn_cast<GlobalValue>(ConstOps[0]);
1564 return error(
"dso_local operand must be GlobalValue");
1568 case BitcodeConstant::BlockAddressOpcode: {
1569 Function *Fn = dyn_cast<Function>(ConstOps[0]);
1571 return error(
"blockaddress operand must be a function");
1576 unsigned BBID = BC->BlockAddressBB;
1579 return error(
"Invalid ID");
1582 for (
size_t I = 0, E = BBID;
I != E; ++
I) {
1584 return error(
"Invalid ID");
1591 auto &FwdBBs = BasicBlockFwdRefs[Fn];
1593 BasicBlockFwdRefQueue.push_back(Fn);
1594 if (FwdBBs.size() < BBID + 1)
1595 FwdBBs.resize(BBID + 1);
1603 case BitcodeConstant::ConstantStructOpcode:
1606 case BitcodeConstant::ConstantArrayOpcode:
1609 case BitcodeConstant::ConstantVectorOpcode:
1612 case Instruction::ICmp:
1613 case Instruction::FCmp:
1616 case Instruction::GetElementPtr:
1619 BC->Flags, BC->getInRange());
1621 case Instruction::ExtractElement:
1624 case Instruction::InsertElement:
1628 case Instruction::ShuffleVector: {
1647 return error(
Twine(
"Value referenced by initializer is an unsupported "
1648 "constant expression of type ") +
1649 BC->getOpcodeName());
1655 BC->getType(),
"constexpr", InsertBB);
1658 "constexpr", InsertBB);
1661 Ops[1],
"constexpr", InsertBB);
1662 if (isa<OverflowingBinaryOperator>(
I)) {
1664 I->setHasNoSignedWrap();
1666 I->setHasNoUnsignedWrap();
1668 if (isa<PossiblyExactOperator>(
I) &&
1672 switch (BC->Opcode) {
1673 case BitcodeConstant::ConstantVectorOpcode: {
1677 Value *
Idx = ConstantInt::get(IdxTy, Pair.index());
1681 I = cast<Instruction>(V);
1684 case BitcodeConstant::ConstantStructOpcode:
1685 case BitcodeConstant::ConstantArrayOpcode: {
1689 "constexpr.ins", InsertBB);
1690 I = cast<Instruction>(V);
1693 case Instruction::ICmp:
1694 case Instruction::FCmp:
1697 "constexpr", InsertBB);
1699 case Instruction::GetElementPtr:
1701 ArrayRef(Ops).drop_front(),
"constexpr",
1704 cast<GetElementPtrInst>(
I)->setIsInBounds();
1706 case Instruction::Select:
1709 case Instruction::ExtractElement:
1712 case Instruction::InsertElement:
1716 case Instruction::ShuffleVector:
1729 return MaterializedValues[StartValID];
1738 return cast<Constant>(MaybeV.
get());
1744 IdentifiedStructTypes.push_back(Ret);
1750 IdentifiedStructTypes.push_back(Ret);
1766 case Attribute::ZExt:
return 1 << 0;
1767 case Attribute::SExt:
return 1 << 1;
1768 case Attribute::NoReturn:
return 1 << 2;
1769 case Attribute::InReg:
return 1 << 3;
1770 case Attribute::StructRet:
return 1 << 4;
1771 case Attribute::NoUnwind:
return 1 << 5;
1772 case Attribute::NoAlias:
return 1 << 6;
1773 case Attribute::ByVal:
return 1 << 7;
1774 case Attribute::Nest:
return 1 << 8;
1775 case Attribute::ReadNone:
return 1 << 9;
1776 case Attribute::ReadOnly:
return 1 << 10;
1777 case Attribute::NoInline:
return 1 << 11;
1778 case Attribute::AlwaysInline:
return 1 << 12;
1779 case Attribute::OptimizeForSize:
return 1 << 13;
1780 case Attribute::StackProtect:
return 1 << 14;
1781 case Attribute::StackProtectReq:
return 1 << 15;
1782 case Attribute::Alignment:
return 31 << 16;
1783 case Attribute::NoCapture:
return 1 << 21;
1784 case Attribute::NoRedZone:
return 1 << 22;
1785 case Attribute::NoImplicitFloat:
return 1 << 23;
1786 case Attribute::Naked:
return 1 << 24;
1787 case Attribute::InlineHint:
return 1 << 25;
1788 case Attribute::StackAlignment:
return 7 << 26;
1789 case Attribute::ReturnsTwice:
return 1 << 29;
1790 case Attribute::UWTable:
return 1 << 30;
1791 case Attribute::NonLazyBind:
return 1U << 31;
1792 case Attribute::SanitizeAddress:
return 1ULL << 32;
1793 case Attribute::MinSize:
return 1ULL << 33;
1794 case Attribute::NoDuplicate:
return 1ULL << 34;
1795 case Attribute::StackProtectStrong:
return 1ULL << 35;
1796 case Attribute::SanitizeThread:
return 1ULL << 36;
1797 case Attribute::SanitizeMemory:
return 1ULL << 37;
1798 case Attribute::NoBuiltin:
return 1ULL << 38;
1799 case Attribute::Returned:
return 1ULL << 39;
1800 case Attribute::Cold:
return 1ULL << 40;
1801 case Attribute::Builtin:
return 1ULL << 41;
1802 case Attribute::OptimizeNone:
return 1ULL << 42;
1803 case Attribute::InAlloca:
return 1ULL << 43;
1804 case Attribute::NonNull:
return 1ULL << 44;
1805 case Attribute::JumpTable:
return 1ULL << 45;
1806 case Attribute::Convergent:
return 1ULL << 46;
1807 case Attribute::SafeStack:
return 1ULL << 47;
1808 case Attribute::NoRecurse:
return 1ULL << 48;
1811 case Attribute::SwiftSelf:
return 1ULL << 51;
1812 case Attribute::SwiftError:
return 1ULL << 52;
1813 case Attribute::WriteOnly:
return 1ULL << 53;
1814 case Attribute::Speculatable:
return 1ULL << 54;
1815 case Attribute::StrictFP:
return 1ULL << 55;
1816 case Attribute::SanitizeHWAddress:
return 1ULL << 56;
1817 case Attribute::NoCfCheck:
return 1ULL << 57;
1818 case Attribute::OptForFuzzing:
return 1ULL << 58;
1819 case Attribute::ShadowCallStack:
return 1ULL << 59;
1820 case Attribute::SpeculativeLoadHardening:
1822 case Attribute::ImmArg:
1824 case Attribute::WillReturn:
1826 case Attribute::NoFree:
1842 if (
I == Attribute::Alignment)
1843 B.addAlignmentAttr(1ULL << ((
A >> 16) - 1));
1844 else if (
I == Attribute::StackAlignment)
1845 B.addStackAlignmentAttr(1ULL << ((
A >> 26)-1));
1847 B.addTypeAttr(
I,
nullptr);
1862 unsigned Alignment = (EncodedAttrs & (0xffffULL << 16)) >> 16;
1864 "Alignment must be a power of two.");
1867 B.addAlignmentAttr(Alignment);
1869 uint64_t Attrs = ((EncodedAttrs & (0xfffffULL << 32)) >> 11) |
1870 (EncodedAttrs & 0xffff);
1875 if (Attrs & (1ULL << 9)) {
1877 Attrs &= ~(1ULL << 9);
1880 if (Attrs & (1ULL << 10)) {
1882 Attrs &= ~(1ULL << 10);
1885 if (Attrs & (1ULL << 49)) {
1887 Attrs &= ~(1ULL << 49);
1890 if (Attrs & (1ULL << 50)) {
1892 Attrs &= ~(1ULL << 50);
1895 if (Attrs & (1ULL << 53)) {
1897 Attrs &= ~(1ULL << 53);
1901 B.addMemoryAttr(ME);
1907Error BitcodeReader::parseAttributeBlock() {
1911 if (!MAttributes.empty())
1912 return error(
"Invalid multiple blocks");
1925 switch (Entry.Kind) {
1928 return error(
"Malformed block");
1941 switch (MaybeRecord.
get()) {
1947 return error(
"Invalid parameter attribute record");
1949 for (
unsigned i = 0, e =
Record.size(); i != e; i += 2) {
1959 for (
unsigned i = 0, e =
Record.size(); i != e; ++i)
1975 return Attribute::Alignment;
1977 return Attribute::AlwaysInline;
1979 return Attribute::Builtin;
1981 return Attribute::ByVal;
1983 return Attribute::InAlloca;
1985 return Attribute::Cold;
1987 return Attribute::Convergent;
1989 return Attribute::DisableSanitizerInstrumentation;
1991 return Attribute::ElementType;
1993 return Attribute::FnRetThunkExtern;
1995 return Attribute::InlineHint;
1997 return Attribute::InReg;
1999 return Attribute::JumpTable;
2001 return Attribute::Memory;
2003 return Attribute::NoFPClass;
2005 return Attribute::MinSize;
2007 return Attribute::Naked;
2009 return Attribute::Nest;
2011 return Attribute::NoAlias;
2013 return Attribute::NoBuiltin;
2015 return Attribute::NoCallback;
2017 return Attribute::NoCapture;
2019 return Attribute::NoDuplicate;
2021 return Attribute::NoFree;
2023 return Attribute::NoImplicitFloat;
2025 return Attribute::NoInline;
2027 return Attribute::NoRecurse;
2029 return Attribute::NoMerge;
2031 return Attribute::NonLazyBind;
2033 return Attribute::NonNull;
2035 return Attribute::Dereferenceable;
2037 return Attribute::DereferenceableOrNull;
2039 return Attribute::AllocAlign;
2041 return Attribute::AllocKind;
2043 return Attribute::AllocSize;
2045 return Attribute::AllocatedPointer;
2047 return Attribute::NoRedZone;
2049 return Attribute::NoReturn;
2051 return Attribute::NoSync;
2053 return Attribute::NoCfCheck;
2055 return Attribute::NoProfile;
2057 return Attribute::SkipProfile;
2059 return Attribute::NoUnwind;
2061 return Attribute::NoSanitizeBounds;
2063 return Attribute::NoSanitizeCoverage;
2065 return Attribute::NullPointerIsValid;
2067 return Attribute::OptimizeForDebugging;
2069 return Attribute::OptForFuzzing;
2071 return Attribute::OptimizeForSize;
2073 return Attribute::OptimizeNone;
2075 return Attribute::ReadNone;
2077 return Attribute::ReadOnly;
2079 return Attribute::Returned;
2081 return Attribute::ReturnsTwice;
2083 return Attribute::SExt;
2085 return Attribute::Speculatable;
2087 return Attribute::StackAlignment;
2089 return Attribute::StackProtect;
2091 return Attribute::StackProtectReq;
2093 return Attribute::StackProtectStrong;
2095 return Attribute::SafeStack;
2097 return Attribute::ShadowCallStack;
2099 return Attribute::StrictFP;
2101 return Attribute::StructRet;
2103 return Attribute::SanitizeAddress;
2105 return Attribute::SanitizeHWAddress;
2107 return Attribute::SanitizeThread;
2109 return Attribute::SanitizeMemory;
2111 return Attribute::SpeculativeLoadHardening;
2113 return Attribute::SwiftError;
2115 return Attribute::SwiftSelf;
2117 return Attribute::SwiftAsync;
2119 return Attribute::UWTable;
2121 return Attribute::VScaleRange;
2123 return Attribute::WillReturn;
2125 return Attribute::WriteOnly;
2127 return Attribute::ZExt;
2129 return Attribute::ImmArg;
2131 return Attribute::SanitizeMemTag;
2133 return Attribute::Preallocated;
2135 return Attribute::NoUndef;
2137 return Attribute::ByRef;
2139 return Attribute::MustProgress;
2141 return Attribute::Hot;
2143 return Attribute::PresplitCoroutine;
2145 return Attribute::Writable;
2147 return Attribute::CoroDestroyOnlyWhenComplete;
2149 return Attribute::DeadOnUnwind;
2151 return Attribute::Range;
2160 return error(
"Invalid alignment value");
2168 return error(
"Unknown attribute kind (" +
Twine(Code) +
")");
2173 switch (EncodedKind) {
2197Error BitcodeReader::parseAttributeGroupBlock() {
2201 if (!MAttributeGroups.empty())
2202 return error(
"Invalid multiple blocks");
2213 switch (Entry.Kind) {
2216 return error(
"Malformed block");
2229 switch (MaybeRecord.
get()) {
2234 return error(
"Invalid grp record");
2241 for (
unsigned i = 2, e =
Record.size(); i != e; ++i) {
2249 if (
Error Err = parseAttrKind(EncodedKind, &Kind))
2255 if (Kind == Attribute::ByVal)
2256 B.addByValAttr(
nullptr);
2257 else if (Kind == Attribute::StructRet)
2258 B.addStructRetAttr(
nullptr);
2259 else if (Kind == Attribute::InAlloca)
2260 B.addInAllocaAttr(
nullptr);
2261 else if (Kind == Attribute::UWTable)
2262 B.addUWTableAttr(UWTableKind::Default);
2264 B.addAttribute(Kind);
2266 return error(
"Not an enum attribute");
2267 }
else if (
Record[i] == 1) {
2269 if (
Error Err = parseAttrKind(
Record[++i], &Kind))
2272 return error(
"Not an int attribute");
2273 if (Kind == Attribute::Alignment)
2274 B.addAlignmentAttr(
Record[++i]);
2275 else if (Kind == Attribute::StackAlignment)
2276 B.addStackAlignmentAttr(
Record[++i]);
2277 else if (Kind == Attribute::Dereferenceable)
2278 B.addDereferenceableAttr(
Record[++i]);
2279 else if (Kind == Attribute::DereferenceableOrNull)
2280 B.addDereferenceableOrNullAttr(
Record[++i]);
2281 else if (Kind == Attribute::AllocSize)
2282 B.addAllocSizeAttrFromRawRepr(
Record[++i]);
2283 else if (Kind == Attribute::VScaleRange)
2284 B.addVScaleRangeAttrFromRawRepr(
Record[++i]);
2285 else if (Kind == Attribute::UWTable)
2287 else if (Kind == Attribute::AllocKind)
2289 else if (Kind == Attribute::Memory)
2291 else if (Kind == Attribute::NoFPClass)
2299 while (
Record[i] != 0 && i != e)
2301 assert(
Record[i] == 0 &&
"Kind string not null terminated");
2306 while (
Record[i] != 0 && i != e)
2308 assert(
Record[i] == 0 &&
"Value string not null terminated");
2311 B.addAttribute(KindStr.
str(), ValStr.
str());
2313 bool HasType =
Record[i] == 6;
2315 if (
Error Err = parseAttrKind(
Record[++i], &Kind))
2318 return error(
"Not a type attribute");
2320 B.addTypeAttr(Kind, HasType ? getTypeByID(
Record[++i]) :
nullptr);
2321 }
else if (
Record[i] == 7) {
2325 if (
Error Err = parseAttrKind(
Record[i++], &Kind))
2328 return error(
"Not a ConstantRange attribute");
2335 B.addConstantRangeAttr(Kind, MaybeCR.
get());
2337 return error(
"Invalid attribute group entry");
2342 B.addMemoryAttr(ME);
2352Error BitcodeReader::parseTypeTable() {
2356 return parseTypeTableBody();
2359Error BitcodeReader::parseTypeTableBody() {
2360 if (!TypeList.empty())
2361 return error(
"Invalid multiple blocks");
2364 unsigned NumRecords = 0;
2375 switch (Entry.Kind) {
2378 return error(
"Malformed block");
2380 if (NumRecords != TypeList.size())
2381 return error(
"Malformed block");
2390 Type *ResultTy =
nullptr;
2395 switch (MaybeRecord.
get()) {
2397 return error(
"Invalid value");
2402 return error(
"Invalid numentry record");
2403 TypeList.resize(
Record[0]);
2446 return error(
"Invalid integer record");
2451 return error(
"Bitwidth for integer type out of range");
2458 return error(
"Invalid pointer record");
2462 ResultTy = getTypeByID(
Record[0]);
2464 !PointerType::isValidElementType(ResultTy))
2465 return error(
"Invalid type");
2472 return error(
"Invalid opaque pointer record");
2481 return error(
"Invalid function record");
2483 for (
unsigned i = 3, e =
Record.size(); i != e; ++i) {
2490 ResultTy = getTypeByID(
Record[2]);
2491 if (!ResultTy || ArgTys.
size() <
Record.size()-3)
2492 return error(
"Invalid type");
2495 ResultTy = FunctionType::get(ResultTy, ArgTys,
Record[0]);
2501 return error(
"Invalid function record");
2503 for (
unsigned i = 2, e =
Record.size(); i != e; ++i) {
2505 if (!FunctionType::isValidArgumentType(
T))
2506 return error(
"Invalid function argument type");
2513 ResultTy = getTypeByID(
Record[1]);
2514 if (!ResultTy || ArgTys.
size() <
Record.size()-2)
2515 return error(
"Invalid type");
2518 ResultTy = FunctionType::get(ResultTy, ArgTys,
Record[0]);
2523 return error(
"Invalid anon struct record");
2525 for (
unsigned i = 1, e =
Record.size(); i != e; ++i) {
2532 return error(
"Invalid type");
2539 return error(
"Invalid struct name record");
2544 return error(
"Invalid named struct record");
2546 if (NumRecords >= TypeList.size())
2547 return error(
"Invalid TYPE table");
2550 StructType *Res = cast_or_null<StructType>(TypeList[NumRecords]);
2553 TypeList[NumRecords] =
nullptr;
2555 Res = createIdentifiedStructType(Context, TypeName);
2559 for (
unsigned i = 1, e =
Record.size(); i != e; ++i) {
2566 return error(
"Invalid named struct record");
2574 return error(
"Invalid opaque type record");
2576 if (NumRecords >= TypeList.size())
2577 return error(
"Invalid TYPE table");
2580 StructType *Res = cast_or_null<StructType>(TypeList[NumRecords]);
2583 TypeList[NumRecords] =
nullptr;
2585 Res = createIdentifiedStructType(Context, TypeName);
2592 return error(
"Invalid target extension type record");
2594 if (NumRecords >= TypeList.size())
2595 return error(
"Invalid TYPE table");
2598 return error(
"Too many type parameters");
2600 unsigned NumTys =
Record[0];
2603 for (
unsigned i = 0; i < NumTys; i++) {
2607 return error(
"Invalid type");
2610 for (
unsigned i = NumTys + 1, e =
Record.size(); i < e; i++) {
2611 if (
Record[i] > UINT_MAX)
2612 return error(
"Integer parameter too large");
2621 return error(
"Invalid array type record");
2622 ResultTy = getTypeByID(
Record[1]);
2623 if (!ResultTy || !ArrayType::isValidElementType(ResultTy))
2624 return error(
"Invalid type");
2626 ResultTy = ArrayType::get(ResultTy,
Record[0]);
2631 return error(
"Invalid vector type record");
2633 return error(
"Invalid vector length");
2634 ResultTy = getTypeByID(
Record[1]);
2635 if (!ResultTy || !VectorType::isValidElementType(ResultTy))
2636 return error(
"Invalid type");
2639 ResultTy = VectorType::get(ResultTy,
Record[0], Scalable);
2643 if (NumRecords >= TypeList.size())
2644 return error(
"Invalid TYPE table");
2645 if (TypeList[NumRecords])
2647 "Invalid TYPE table: Only named structs can be forward referenced");
2648 assert(ResultTy &&
"Didn't read a type?");
2649 TypeList[NumRecords] = ResultTy;
2650 if (!ContainedIDs.
empty())
2651 ContainedTypeIDs[NumRecords] = std::move(ContainedIDs);
2656Error BitcodeReader::parseOperandBundleTags() {
2660 if (!BundleTags.empty())
2661 return error(
"Invalid multiple blocks");
2671 switch (Entry.Kind) {
2674 return error(
"Malformed block");
2688 return error(
"Invalid operand bundle record");
2691 BundleTags.emplace_back();
2693 return error(
"Invalid operand bundle record");
2698Error BitcodeReader::parseSyncScopeNames() {
2703 return error(
"Invalid multiple synchronization scope names blocks");
2712 switch (Entry.Kind) {
2715 return error(
"Malformed block");
2718 return error(
"Invalid empty synchronization scope names block");
2732 return error(
"Invalid sync scope record");
2736 return error(
"Invalid sync scope record");
2745 unsigned NameIndex,
Triple &TT) {
2748 return error(
"Invalid record");
2749 unsigned ValueID =
Record[0];
2750 if (ValueID >= ValueList.
size() || !ValueList[ValueID])
2751 return error(
"Invalid record");
2752 Value *
V = ValueList[ValueID];
2755 if (NameStr.contains(0))
2756 return error(
"Invalid value name");
2757 V->setName(NameStr);
2758 auto *GO = dyn_cast<GlobalObject>(V);
2759 if (GO && ImplicitComdatObjects.
contains(GO) &&
TT.supportsCOMDAT())
2772 return std::move(JumpFailed);
2778 return error(
"Expected value symbol table subblock");
2782void BitcodeReader::setDeferredFunctionInfo(
unsigned FuncBitcodeOffsetDelta,
2789 uint64_t FuncBitOffset = FuncWordOffset * 32;
2790 DeferredFunctionInfo[
F] = FuncBitOffset + FuncBitcodeOffsetDelta;
2794 if (FuncBitOffset > LastFunctionBlockBit)
2795 LastFunctionBlockBit = FuncBitOffset;
2799Error BitcodeReader::parseGlobalValueSymbolTable() {
2800 unsigned FuncBitcodeOffsetDelta =
2813 switch (Entry.Kind) {
2816 return error(
"Malformed block");
2827 switch (MaybeRecord.
get()) {
2829 unsigned ValueID =
Record[0];
2830 if (ValueID >= ValueList.
size() || !ValueList[ValueID])
2831 return error(
"Invalid value reference in symbol table");
2832 setDeferredFunctionInfo(FuncBitcodeOffsetDelta,
2833 cast<Function>(ValueList[ValueID]),
Record);
2849 if (!MaybeCurrentBit)
2851 CurrentBit = MaybeCurrentBit.
get();
2854 if (
Error Err = parseGlobalValueSymbolTable())
2856 if (
Error JumpFailed = Stream.JumpToBit(CurrentBit))
2875 unsigned FuncBitcodeOffsetDelta =
2894 switch (Entry.Kind) {
2897 return error(
"Malformed block");
2900 if (
Error JumpFailed = Stream.JumpToBit(CurrentBit))
2913 switch (MaybeRecord.
get()) {
2932 if (
auto *
F = dyn_cast<Function>(V))
2933 setDeferredFunctionInfo(FuncBitcodeOffsetDelta,
F,
Record);
2938 return error(
"Invalid bbentry record");
2941 return error(
"Invalid bbentry record");
2963Error BitcodeReader::resolveGlobalAndIndirectSymbolInits() {
2964 std::vector<std::pair<GlobalVariable *, unsigned>> GlobalInitWorklist;
2965 std::vector<std::pair<GlobalValue *, unsigned>> IndirectSymbolInitWorklist;
2966 std::vector<FunctionOperandInfo> FunctionOperandWorklist;
2968 GlobalInitWorklist.swap(GlobalInits);
2969 IndirectSymbolInitWorklist.swap(IndirectSymbolInits);
2970 FunctionOperandWorklist.swap(FunctionOperands);
2972 while (!GlobalInitWorklist.empty()) {
2973 unsigned ValID = GlobalInitWorklist.back().second;
2976 GlobalInits.push_back(GlobalInitWorklist.back());
2981 GlobalInitWorklist.back().first->setInitializer(MaybeC.
get());
2983 GlobalInitWorklist.pop_back();
2986 while (!IndirectSymbolInitWorklist.empty()) {
2987 unsigned ValID = IndirectSymbolInitWorklist.back().second;
2989 IndirectSymbolInits.push_back(IndirectSymbolInitWorklist.back());
2995 GlobalValue *GV = IndirectSymbolInitWorklist.back().first;
2996 if (
auto *GA = dyn_cast<GlobalAlias>(GV)) {
2998 return error(
"Alias and aliasee types don't match");
3000 }
else if (
auto *GI = dyn_cast<GlobalIFunc>(GV)) {
3003 return error(
"Expected an alias or an ifunc");
3006 IndirectSymbolInitWorklist.pop_back();
3009 while (!FunctionOperandWorklist.empty()) {
3010 FunctionOperandInfo &
Info = FunctionOperandWorklist.back();
3011 if (
Info.PersonalityFn) {
3012 unsigned ValID =
Info.PersonalityFn - 1;
3017 Info.F->setPersonalityFn(MaybeC.
get());
3018 Info.PersonalityFn = 0;
3027 Info.F->setPrefixData(MaybeC.
get());
3031 if (
Info.Prologue) {
3037 Info.F->setPrologueData(MaybeC.
get());
3041 if (
Info.PersonalityFn ||
Info.Prefix ||
Info.Prologue)
3042 FunctionOperands.push_back(Info);
3043 FunctionOperandWorklist.pop_back();
3052 BitcodeReader::decodeSignRotatedValue);
3054 return APInt(TypeBits, Words);
3057Error BitcodeReader::parseConstants() {
3065 unsigned Int32TyID = getVirtualTypeID(CurTy);
3066 unsigned CurTyID = Int32TyID;
3067 Type *CurElemTy =
nullptr;
3068 unsigned NextCstNo = ValueList.
size();
3076 switch (Entry.Kind) {
3079 return error(
"Malformed block");
3081 if (NextCstNo != ValueList.
size())
3082 return error(
"Invalid constant reference");
3096 switch (
unsigned BitCode = MaybeBitCode.
get()) {
3106 return error(
"Invalid settype record");
3107 if (
Record[0] >= TypeList.size() || !TypeList[
Record[0]])
3108 return error(
"Invalid settype record");
3109 if (TypeList[
Record[0]] == VoidType)
3110 return error(
"Invalid constant type");
3112 CurTy = TypeList[CurTyID];
3113 CurElemTy = getPtrElementTypeByID(CurTyID);
3117 return error(
"Invalid type for a constant null value");
3118 if (
auto *TETy = dyn_cast<TargetExtType>(CurTy))
3120 return error(
"Invalid type for a constant null value");
3125 return error(
"Invalid integer const record");
3130 return error(
"Invalid wide integer const record");
3134 V = ConstantInt::get(CurTy, VInt);
3139 return error(
"Invalid float const record");
3142 if (ScalarTy->isHalfTy())
3143 V = ConstantFP::get(CurTy,
APFloat(APFloat::IEEEhalf(),
3145 else if (ScalarTy->isBFloatTy())
3146 V = ConstantFP::get(
3148 else if (ScalarTy->isFloatTy())
3149 V = ConstantFP::get(CurTy,
APFloat(APFloat::IEEEsingle(),
3151 else if (ScalarTy->isDoubleTy())
3152 V = ConstantFP::get(
3154 else if (ScalarTy->isX86_FP80Ty()) {
3157 Rearrange[0] = (
Record[1] & 0xffffLL) | (
Record[0] << 16);
3158 Rearrange[1] =
Record[0] >> 48;
3159 V = ConstantFP::get(
3160 CurTy,
APFloat(APFloat::x87DoubleExtended(),
APInt(80, Rearrange)));
3161 }
else if (ScalarTy->isFP128Ty())
3162 V = ConstantFP::get(CurTy,
3164 else if (ScalarTy->isPPC_FP128Ty())
3165 V = ConstantFP::get(
3174 return error(
"Invalid aggregate record");
3178 for (
unsigned i = 0; i !=
Size; ++i)
3181 if (isa<StructType>(CurTy)) {
3182 V = BitcodeConstant::create(
3183 Alloc, CurTy, BitcodeConstant::ConstantStructOpcode, Elts);
3184 }
else if (isa<ArrayType>(CurTy)) {
3185 V = BitcodeConstant::create(Alloc, CurTy,
3186 BitcodeConstant::ConstantArrayOpcode, Elts);
3187 }
else if (isa<VectorType>(CurTy)) {
3188 V = BitcodeConstant::create(
3189 Alloc, CurTy, BitcodeConstant::ConstantVectorOpcode, Elts);
3198 return error(
"Invalid string record");
3207 return error(
"Invalid data record");
3210 if (
auto *Array = dyn_cast<ArrayType>(CurTy))
3211 EltTy =
Array->getElementType();
3213 EltTy = cast<VectorType>(CurTy)->getElementType();
3216 if (isa<VectorType>(CurTy))
3222 if (isa<VectorType>(CurTy))
3228 if (isa<VectorType>(CurTy))
3234 if (isa<VectorType>(CurTy))
3240 if (isa<VectorType>(CurTy))
3246 if (isa<VectorType>(CurTy))
3252 if (isa<VectorType>(CurTy))
3258 if (isa<VectorType>(CurTy))
3263 return error(
"Invalid type for value");
3269 return error(
"Invalid unary op constexpr record");
3274 V = BitcodeConstant::create(Alloc, CurTy, Opc, (
unsigned)
Record[1]);
3280 return error(
"Invalid binary op constexpr record");
3286 if (
Record.size() >= 4) {
3287 if (Opc == Instruction::Add ||
3288 Opc == Instruction::Sub ||
3289 Opc == Instruction::Mul ||
3290 Opc == Instruction::Shl) {
3295 }
else if (Opc == Instruction::SDiv ||
3296 Opc == Instruction::UDiv ||
3297 Opc == Instruction::LShr ||
3298 Opc == Instruction::AShr) {
3303 V = BitcodeConstant::create(Alloc, CurTy, {(uint8_t)Opc, Flags},
3310 return error(
"Invalid cast constexpr record");
3315 unsigned OpTyID =
Record[1];
3316 Type *OpTy = getTypeByID(OpTyID);
3318 return error(
"Invalid cast constexpr record");
3319 V = BitcodeConstant::create(Alloc, CurTy, Opc, (
unsigned)
Record[2]);
3330 return error(
"Constant GEP record must have at least two elements");
3332 Type *PointeeType =
nullptr;
3335 PointeeType = getTypeByID(
Record[OpNum++]);
3337 bool InBounds =
false;
3338 std::optional<ConstantRange>
InRange;
3342 unsigned InRangeIndex =
Op >> 1;
3357 unsigned BaseTypeID =
Record[OpNum];
3358 while (OpNum !=
Record.size()) {
3359 unsigned ElTyID =
Record[OpNum++];
3360 Type *ElTy = getTypeByID(ElTyID);
3362 return error(
"Invalid getelementptr constexpr record");
3366 if (Elts.
size() < 1)
3367 return error(
"Invalid gep with no operands");
3371 BaseTypeID = getContainedTypeID(BaseTypeID, 0);
3372 BaseType = getTypeByID(BaseTypeID);
3377 return error(
"GEP base operand must be pointer or vector of pointer");
3380 PointeeType = getPtrElementTypeByID(BaseTypeID);
3382 return error(
"Missing element type for old-style constant GEP");
3385 V = BitcodeConstant::create(
3387 {Instruction::GetElementPtr, InBounds, PointeeType,
InRange}, Elts);
3392 return error(
"Invalid select constexpr record");
3394 V = BitcodeConstant::create(
3395 Alloc, CurTy, Instruction::Select,
3402 return error(
"Invalid extractelement constexpr record");
3403 unsigned OpTyID =
Record[0];
3405 dyn_cast_or_null<VectorType>(getTypeByID(OpTyID));
3407 return error(
"Invalid extractelement constexpr record");
3409 if (
Record.size() == 4) {
3410 unsigned IdxTyID =
Record[2];
3411 Type *IdxTy = getTypeByID(IdxTyID);
3413 return error(
"Invalid extractelement constexpr record");
3419 V = BitcodeConstant::create(Alloc, CurTy, Instruction::ExtractElement,
3425 VectorType *OpTy = dyn_cast<VectorType>(CurTy);
3426 if (
Record.size() < 3 || !OpTy)
3427 return error(
"Invalid insertelement constexpr record");
3429 if (
Record.size() == 4) {
3430 unsigned IdxTyID =
Record[2];
3431 Type *IdxTy = getTypeByID(IdxTyID);
3433 return error(
"Invalid insertelement constexpr record");
3439 V = BitcodeConstant::create(
3440 Alloc, CurTy, Instruction::InsertElement,
3445 VectorType *OpTy = dyn_cast<VectorType>(CurTy);
3446 if (
Record.size() < 3 || !OpTy)
3447 return error(
"Invalid shufflevector constexpr record");
3448 V = BitcodeConstant::create(
3449 Alloc, CurTy, Instruction::ShuffleVector,
3454 VectorType *RTy = dyn_cast<VectorType>(CurTy);
3456 dyn_cast_or_null<VectorType>(getTypeByID(
Record[0]));
3457 if (
Record.size() < 4 || !RTy || !OpTy)
3458 return error(
"Invalid shufflevector constexpr record");
3459 V = BitcodeConstant::create(
3460 Alloc, CurTy, Instruction::ShuffleVector,
3466 return error(
"Invalid cmp constexpt record");
3467 unsigned OpTyID =
Record[0];
3468 Type *OpTy = getTypeByID(OpTyID);
3470 return error(
"Invalid cmp constexpr record");
3471 V = BitcodeConstant::create(
3474 : Instruction::ICmp),
3483 return error(
"Invalid inlineasm record");
3484 std::string AsmStr, ConstrStr;
3485 bool HasSideEffects =
Record[0] & 1;
3486 bool IsAlignStack =
Record[0] >> 1;
3487 unsigned AsmStrSize =
Record[1];
3488 if (2+AsmStrSize >=
Record.size())
3489 return error(
"Invalid inlineasm record");
3490 unsigned ConstStrSize =
Record[2+AsmStrSize];
3491 if (3+AsmStrSize+ConstStrSize >
Record.size())
3492 return error(
"Invalid inlineasm record");
3494 for (
unsigned i = 0; i != AsmStrSize; ++i)
3495 AsmStr += (
char)
Record[2+i];
3496 for (
unsigned i = 0; i != ConstStrSize; ++i)
3497 ConstrStr += (
char)
Record[3+AsmStrSize+i];
3500 return error(
"Missing element type for old-style inlineasm");
3502 HasSideEffects, IsAlignStack);
3509 return error(
"Invalid inlineasm record");
3510 std::string AsmStr, ConstrStr;
3511 bool HasSideEffects =
Record[0] & 1;
3512 bool IsAlignStack = (
Record[0] >> 1) & 1;
3513 unsigned AsmDialect =
Record[0] >> 2;
3514 unsigned AsmStrSize =
Record[1];
3515 if (2+AsmStrSize >=
Record.size())
3516 return error(
"Invalid inlineasm record");
3517 unsigned ConstStrSize =
Record[2+AsmStrSize];
3518 if (3+AsmStrSize+ConstStrSize >
Record.size())
3519 return error(
"Invalid inlineasm record");
3521 for (
unsigned i = 0; i != AsmStrSize; ++i)
3522 AsmStr += (
char)
Record[2+i];
3523 for (
unsigned i = 0; i != ConstStrSize; ++i)
3524 ConstrStr += (
char)
Record[3+AsmStrSize+i];
3527 return error(
"Missing element type for old-style inlineasm");
3529 HasSideEffects, IsAlignStack,
3536 return error(
"Invalid inlineasm record");
3538 std::string AsmStr, ConstrStr;
3539 bool HasSideEffects =
Record[OpNum] & 1;
3540 bool IsAlignStack = (
Record[OpNum] >> 1) & 1;
3541 unsigned AsmDialect = (
Record[OpNum] >> 2) & 1;
3542 bool CanThrow = (
Record[OpNum] >> 3) & 1;
3544 unsigned AsmStrSize =
Record[OpNum];
3546 if (OpNum + AsmStrSize >=
Record.size())
3547 return error(
"Invalid inlineasm record");
3548 unsigned ConstStrSize =
Record[OpNum + AsmStrSize];
3549 if (OpNum + 1 + AsmStrSize + ConstStrSize >
Record.size())
3550 return error(
"Invalid inlineasm record");
3552 for (
unsigned i = 0; i != AsmStrSize; ++i)
3553 AsmStr += (
char)
Record[OpNum + i];
3555 for (
unsigned i = 0; i != ConstStrSize; ++i)
3556 ConstrStr += (
char)
Record[OpNum + AsmStrSize + i];
3559 return error(
"Missing element type for old-style inlineasm");
3561 HasSideEffects, IsAlignStack,
3568 return error(
"Invalid inlineasm record");
3570 auto *FnTy = dyn_cast_or_null<FunctionType>(getTypeByID(
Record[OpNum]));
3573 return error(
"Invalid inlineasm record");
3574 std::string AsmStr, ConstrStr;
3575 bool HasSideEffects =
Record[OpNum] & 1;
3576 bool IsAlignStack = (
Record[OpNum] >> 1) & 1;
3577 unsigned AsmDialect = (
Record[OpNum] >> 2) & 1;
3578 bool CanThrow = (
Record[OpNum] >> 3) & 1;
3580 unsigned AsmStrSize =
Record[OpNum];
3582 if (OpNum + AsmStrSize >=
Record.size())
3583 return error(
"Invalid inlineasm record");
3584 unsigned ConstStrSize =
Record[OpNum + AsmStrSize];
3585 if (OpNum + 1 + AsmStrSize + ConstStrSize >
Record.size())
3586 return error(
"Invalid inlineasm record");
3588 for (
unsigned i = 0; i != AsmStrSize; ++i)
3589 AsmStr += (
char)
Record[OpNum + i];
3591 for (
unsigned i = 0; i != ConstStrSize; ++i)
3592 ConstrStr += (
char)
Record[OpNum + AsmStrSize + i];
3594 V =
InlineAsm::get(FnTy, AsmStr, ConstrStr, HasSideEffects, IsAlignStack,
3600 return error(
"Invalid blockaddress record");
3601 unsigned FnTyID =
Record[0];
3602 Type *FnTy = getTypeByID(FnTyID);
3604 return error(
"Invalid blockaddress record");
3605 V = BitcodeConstant::create(
3613 return error(
"Invalid dso_local record");
3614 unsigned GVTyID =
Record[0];
3615 Type *GVTy = getTypeByID(GVTyID);
3617 return error(
"Invalid dso_local record");
3618 V = BitcodeConstant::create(
3619 Alloc, CurTy, BitcodeConstant::DSOLocalEquivalentOpcode,
Record[1]);
3624 return error(
"Invalid no_cfi record");
3625 unsigned GVTyID =
Record[0];
3626 Type *GVTy = getTypeByID(GVTyID);
3628 return error(
"Invalid no_cfi record");
3629 V = BitcodeConstant::create(Alloc, CurTy, BitcodeConstant::NoCFIOpcode,
3635 assert(
V->getType() == getTypeByID(CurTyID) &&
"Incorrect result type ID");
3642Error BitcodeReader::parseUseLists() {
3655 switch (Entry.Kind) {
3658 return error(
"Malformed block");
3672 switch (MaybeRecord.
get()) {
3680 if (RecordLength < 3)
3682 return error(
"Invalid record");
3683 unsigned ID =
Record.pop_back_val();
3687 assert(
ID < FunctionBBs.size() &&
"Basic block not found");
3688 V = FunctionBBs[
ID];
3691 unsigned NumUses = 0;
3693 for (
const Use &U :
V->materialized_uses()) {
3694 if (++NumUses >
Record.size())
3696 Order[&
U] =
Record[NumUses - 1];
3703 V->sortUseList([&](
const Use &L,
const Use &R) {
3714Error BitcodeReader::rememberAndSkipMetadata() {
3716 uint64_t CurBit = Stream.GetCurrentBitNo();
3717 DeferredMetadataInfo.push_back(CurBit);
3720 if (
Error Err = Stream.SkipBlock())
3725Error BitcodeReader::materializeMetadata() {
3726 for (
uint64_t BitPos : DeferredMetadataInfo) {
3728 if (
Error JumpFailed = Stream.JumpToBit(BitPos))
3730 if (
Error Err = MDLoader->parseModuleMetadata())
3741 for (
const MDOperand &MDOptions : cast<MDNode>(Val)->operands())
3742 LinkerOpts->
addOperand(cast<MDNode>(MDOptions));
3746 DeferredMetadataInfo.clear();
3750void BitcodeReader::setStripDebugInfo() {
StripDebugInfo =
true; }
3754Error BitcodeReader::rememberAndSkipFunctionBody() {
3756 if (FunctionsWithBodies.empty())
3757 return error(
"Insufficient function protos");
3760 FunctionsWithBodies.pop_back();
3763 uint64_t CurBit = Stream.GetCurrentBitNo();
3765 (DeferredFunctionInfo[Fn] == 0 || DeferredFunctionInfo[Fn] == CurBit) &&
3766 "Mismatch between VST and scanned function offsets");
3767 DeferredFunctionInfo[Fn] = CurBit;
3770 if (
Error Err = Stream.SkipBlock())
3775Error BitcodeReader::globalCleanup() {
3777 if (
Error Err = resolveGlobalAndIndirectSymbolInits())
3779 if (!GlobalInits.empty() || !IndirectSymbolInits.empty())
3780 return error(
"Malformed global initializer set");
3785 MDLoader->upgradeDebugIntrinsics(
F);
3792 UpgradedIntrinsics[&
F] = NewFn;
3798 std::vector<std::pair<GlobalVariable *, GlobalVariable *>> UpgradedVariables;
3801 UpgradedVariables.emplace_back(&GV, Upgraded);
3802 for (
auto &Pair : UpgradedVariables) {
3803 Pair.first->eraseFromParent();
3804 TheModule->insertGlobalVariable(Pair.second);
3809 std::vector<std::pair<GlobalVariable *, unsigned>>().
swap(GlobalInits);
3810 std::vector<std::pair<GlobalValue *, unsigned>>().
swap(IndirectSymbolInits);
3818Error BitcodeReader::rememberAndSkipFunctionBodies() {
3819 if (
Error JumpFailed = Stream.JumpToBit(NextUnreadBit))
3822 if (Stream.AtEndOfStream())
3823 return error(
"Could not find function in stream");
3825 if (!SeenFirstFunctionBody)
3826 return error(
"Trying to materialize functions before seeing function blocks");
3830 assert(SeenValueSymbolTable);
3840 switch (Entry.Kind) {
3842 return error(
"Expect SubBlock");
3846 return error(
"Expect function block");
3848 if (
Error Err = rememberAndSkipFunctionBody())
3850 NextUnreadBit = Stream.GetCurrentBitNo();
3857Error BitcodeReaderBase::readBlockInfo() {
3859 Stream.ReadBlockInfoBlock();
3860 if (!MaybeNewBlockInfo)
3862 std::optional<BitstreamBlockInfo> NewBlockInfo =
3863 std::move(MaybeNewBlockInfo.
get());
3865 return error(
"Malformed block");
3866 BlockInfo = std::move(*NewBlockInfo);
3877 return error(
"Invalid record");
3879 std::string OldFormatName;
3882 return error(
"Invalid record");
3883 unsigned ComdatNameSize =
Record[1];
3884 if (ComdatNameSize >
Record.size() - 2)
3885 return error(
"Comdat name size too large");
3886 OldFormatName.reserve(ComdatNameSize);
3887 for (
unsigned i = 0; i != ComdatNameSize; ++i)
3888 OldFormatName += (
char)
Record[2 + i];
3889 Name = OldFormatName;
3892 C->setSelectionKind(SK);
3893 ComdatList.push_back(
C);
3907 Meta.NoAddress =
true;
3909 Meta.NoHWAddress =
true;
3913 Meta.IsDynInit =
true;
3928 return error(
"Invalid record");
3929 unsigned TyID =
Record[0];
3930 Type *Ty = getTypeByID(TyID);
3932 return error(
"Invalid record");
3934 bool explicitType =
Record[1] & 2;
3940 return error(
"Invalid type for value");
3941 AddressSpace = cast<PointerType>(Ty)->getAddressSpace();
3942 TyID = getContainedTypeID(TyID);
3943 Ty = getTypeByID(TyID);
3945 return error(
"Missing element type for old-style global");
3951 if (
Error Err = parseAlignmentValue(
Record[4], Alignment))
3955 if (
Record[5] - 1 >= SectionTable.size())
3956 return error(
"Invalid ID");
3973 bool ExternallyInitialized =
false;
3975 ExternallyInitialized =
Record[9];
3987 if (
Record.size() > 10) {
3999 if (
unsigned InitID =
Record[2])
4000 GlobalInits.push_back(std::make_pair(NewGV, InitID - 1));
4002 if (
Record.size() > 11) {
4003 if (
unsigned ComdatID =
Record[11]) {
4004 if (ComdatID > ComdatList.size())
4005 return error(
"Invalid global variable comdat ID");
4006 NewGV->
setComdat(ComdatList[ComdatID - 1]);
4009 ImplicitComdatObjects.
insert(NewGV);
4012 if (
Record.size() > 12) {
4017 if (
Record.size() > 13) {
4036 return error(
"Invalid global variable code model");
4042void BitcodeReader::callValueTypeCallback(
Value *
F,
unsigned TypeID) {
4043 if (ValueTypeCallback) {
4044 (*ValueTypeCallback)(
4045 F,
TypeID, [
this](
unsigned I) {
return getTypeByID(
I); },
4046 [
this](
unsigned I,
unsigned J) {
return getContainedTypeID(
I, J); });
4059 return error(
"Invalid record");
4060 unsigned FTyID =
Record[0];
4061 Type *FTy = getTypeByID(FTyID);
4063 return error(
"Invalid record");
4064 if (isa<PointerType>(FTy)) {
4065 FTyID = getContainedTypeID(FTyID, 0);
4066 FTy = getTypeByID(FTyID);
4068 return error(
"Missing element type for old-style function");
4071 if (!isa<FunctionType>(FTy))
4072 return error(
"Invalid type for value");
4075 return error(
"Invalid calling convention ID");
4077 unsigned AddrSpace = TheModule->getDataLayout().getProgramAddressSpace();
4083 AddrSpace,
Name, TheModule);
4086 "Incorrect fully specified type provided for function");
4087 FunctionTypeIDs[
Func] = FTyID;
4089 Func->setCallingConv(
CC);
4090 bool isProto =
Record[2];
4094 callValueTypeCallback(Func, FTyID);
4099 for (
unsigned i = 0; i !=
Func->arg_size(); ++i) {
4101 Attribute::InAlloca}) {
4102 if (!
Func->hasParamAttribute(i, Kind))
4105 if (
Func->getParamAttribute(i, Kind).getValueAsType())
4108 Func->removeParamAttr(i, Kind);
4110 unsigned ParamTypeID = getContainedTypeID(FTyID, i + 1);
4111 Type *PtrEltTy = getPtrElementTypeByID(ParamTypeID);
4113 return error(
"Missing param element type for attribute upgrade");
4117 case Attribute::ByVal:
4120 case Attribute::StructRet:
4123 case Attribute::InAlloca:
4130 Func->addParamAttr(i, NewAttr);
4135 !
Func->arg_empty() && !
Func->hasParamAttribute(0, Attribute::ByVal)) {
4136 unsigned ParamTypeID = getContainedTypeID(FTyID, 1);
4137 Type *ByValTy = getPtrElementTypeByID(ParamTypeID);
4139 return error(
"Missing param element type for x86_intrcc upgrade");
4141 Func->addParamAttr(0, NewAttr);
4145 if (
Error Err = parseAlignmentValue(
Record[5], Alignment))
4148 Func->setAlignment(*Alignment);
4150 if (
Record[6] - 1 >= SectionTable.size())
4151 return error(
"Invalid ID");
4152 Func->setSection(SectionTable[
Record[6] - 1]);
4156 if (!
Func->hasLocalLinkage())
4159 if (
Record[8] - 1 >= GCTable.size())
4160 return error(
"Invalid ID");
4166 Func->setUnnamedAddr(UnnamedAddr);
4168 FunctionOperandInfo OperandInfo = {
Func, 0, 0, 0};
4170 OperandInfo.Prologue =
Record[10];
4172 if (
Record.size() > 11) {
4174 if (!
Func->hasLocalLinkage()) {
4181 if (
Record.size() > 12) {
4182 if (
unsigned ComdatID =
Record[12]) {
4183 if (ComdatID > ComdatList.size())
4184 return error(
"Invalid function comdat ID");
4185 Func->setComdat(ComdatList[ComdatID - 1]);
4188 ImplicitComdatObjects.
insert(Func);
4192 OperandInfo.Prefix =
Record[13];
4195 OperandInfo.PersonalityFn =
Record[14];
4197 if (
Record.size() > 15) {
4206 if (
Record.size() > 18 && Strtab.data() &&
4211 ValueList.
push_back(Func, getVirtualTypeID(
Func->getType(), FTyID));
4213 if (OperandInfo.PersonalityFn || OperandInfo.Prefix || OperandInfo.Prologue)
4214 FunctionOperands.push_back(OperandInfo);
4219 Func->setIsMaterializable(
true);
4220 FunctionsWithBodies.push_back(Func);
4221 DeferredFunctionInfo[
Func] = 0;
4226Error BitcodeReader::parseGlobalIndirectSymbolRecord(
4240 if (
Record.size() < (3 + (
unsigned)NewRecord))
4241 return error(
"Invalid record");
4246 return error(
"Invalid record");
4250 auto *PTy = dyn_cast<PointerType>(Ty);
4252 return error(
"Invalid type for value");
4253 AddrSpace = PTy->getAddressSpace();
4255 Ty = getTypeByID(
TypeID);
4257 return error(
"Missing element type for old-style indirect symbol");
4259 AddrSpace =
Record[OpNum++];
4262 auto Val =
Record[OpNum++];
4271 nullptr, TheModule);
4275 if (OpNum !=
Record.size()) {
4276 auto VisInd = OpNum++;
4282 if (OpNum !=
Record.size()) {
4283 auto S =
Record[OpNum++];
4290 if (OpNum !=
Record.size())
4292 if (OpNum !=
Record.size())
4295 if (OpNum !=
Record.size())
4300 if (OpNum + 1 <
Record.size()) {
4303 return error(
"Malformed partition, too large.");
4310 IndirectSymbolInits.push_back(std::make_pair(NewGA, Val));
4315 bool ShouldLazyLoadMetadata,
4321 TheModule->IsNewDbgInfoFormat =
4326 this->ValueTypeCallback = std::move(Callbacks.
ValueType);
4328 if (
Error JumpFailed = Stream.JumpToBit(ResumeBit))
4337 bool ResolvedDataLayout =
false;
4342 std::string TentativeDataLayoutStr = TheModule->getDataLayoutStr();
4344 auto ResolveDataLayout = [&]() ->
Error {
4345 if (ResolvedDataLayout)
4349 ResolvedDataLayout =
true;
4353 TentativeDataLayoutStr, TheModule->getTargetTriple());
4357 if (
auto LayoutOverride = (*Callbacks.
DataLayout)(
4358 TheModule->getTargetTriple(), TentativeDataLayoutStr))
4359 TentativeDataLayoutStr = *LayoutOverride;
4367 TheModule->setDataLayout(MaybeDL.
get());
4378 switch (Entry.Kind) {
4380 return error(
"Malformed block");
4382 if (
Error Err = ResolveDataLayout())
4384 return globalCleanup();
4389 if (
Error Err = Stream.SkipBlock())
4393 if (
Error Err = readBlockInfo())
4397 if (
Error Err = parseAttributeBlock())
4401 if (
Error Err = parseAttributeGroupBlock())
4405 if (
Error Err = parseTypeTable())
4409 if (!SeenValueSymbolTable) {
4415 assert(VSTOffset == 0 || FunctionsWithBodies.empty());
4416 if (
Error Err = parseValueSymbolTable())
4418 SeenValueSymbolTable =
true;
4423 if (
Error Err = Stream.SkipBlock())
4428 if (
Error Err = parseConstants())
4430 if (
Error Err = resolveGlobalAndIndirectSymbolInits())
4434 if (ShouldLazyLoadMetadata) {
4435 if (
Error Err = rememberAndSkipMetadata())
4439 assert(DeferredMetadataInfo.empty() &&
"Unexpected deferred metadata");
4440 if (
Error Err = MDLoader->parseModuleMetadata())
4444 if (
Error Err = MDLoader->parseMetadataKinds())
4448 if (
Error Err = ResolveDataLayout())
4453 if (!SeenFirstFunctionBody) {
4454 std::reverse(FunctionsWithBodies.begin(), FunctionsWithBodies.end());
4455 if (
Error Err = globalCleanup())
4457 SeenFirstFunctionBody =
true;
4460 if (VSTOffset > 0) {
4464 if (!SeenValueSymbolTable) {
4465 if (
Error Err = BitcodeReader::parseValueSymbolTable(VSTOffset))
4467 SeenValueSymbolTable =
true;
4479 if (
Error Err = Stream.SkipBlock())
4489 if (
Error Err = rememberAndSkipFunctionBody())
4496 if (SeenValueSymbolTable) {
4497 NextUnreadBit = Stream.GetCurrentBitNo();
4500 return globalCleanup();
4504 if (
Error Err = parseUseLists())
4508 if (
Error Err = parseOperandBundleTags())
4512 if (
Error Err = parseSyncScopeNames())
4527 switch (
unsigned BitCode = MaybeBitCode.
get()) {
4533 UseRelativeIDs = *VersionOrErr >= 1;
4537 if (ResolvedDataLayout)
4538 return error(
"target triple too late in module");
4541 return error(
"Invalid record");
4542 TheModule->setTargetTriple(S);
4546 if (ResolvedDataLayout)
4547 return error(
"datalayout too late in module");
4549 return error(
"Invalid record");
4555 return error(
"Invalid record");
4556 TheModule->setModuleInlineAsm(S);
4563 return error(
"Invalid record");
4570 return error(
"Invalid record");
4571 SectionTable.push_back(S);
4577 return error(
"Invalid record");
4578 GCTable.push_back(S);
4595 if (
Error Err = ResolveDataLayout())
4603 if (
Error Err = parseGlobalIndirectSymbolRecord(BitCode,
Record))
4609 return error(
"Invalid record");
4613 VSTOffset =
Record[0] - 1;
4619 return error(
"Invalid record");
4620 TheModule->setSourceFileName(
ValueName);
4625 this->ValueTypeCallback = std::nullopt;
4629Error BitcodeReader::parseBitcodeInto(
Module *M,
bool ShouldLazyLoadMetadata,
4634 MDCallbacks.
GetTypeByID = [&](
unsigned ID) {
return getTypeByID(
ID); };
4636 return getContainedTypeID(
I, J);
4639 MDLoader =
MetadataLoader(Stream, *M, ValueList, IsImporting, MDCallbacks);
4640 return parseModule(0, ShouldLazyLoadMetadata, Callbacks);
4643Error BitcodeReader::typeCheckLoadStoreInst(
Type *ValType,
Type *PtrType) {
4644 if (!isa<PointerType>(PtrType))
4645 return error(
"Load/Store operand is not a pointer type");
4646 if (!PointerType::isLoadableOrStorableType(ValType))
4647 return error(
"Cannot load/store from pointer");
4654 for (
unsigned i = 0; i != CB->
arg_size(); ++i) {
4656 Attribute::InAlloca}) {
4657 if (!
Attrs.hasParamAttr(i, Kind) ||
4658 Attrs.getParamAttr(i, Kind).getValueAsType())
4661 Type *PtrEltTy = getPtrElementTypeByID(ArgTyIDs[i]);
4663 return error(
"Missing element type for typed attribute upgrade");
4667 case Attribute::ByVal:
4670 case Attribute::StructRet:
4673 case Attribute::InAlloca:
4680 Attrs =
Attrs.addParamAttribute(Context, i, NewAttr);
4691 if (CI.isIndirect && !
Attrs.getParamElementType(ArgNo)) {
4692 Type *ElemTy = getPtrElementTypeByID(ArgTyIDs[ArgNo]);
4694 return error(
"Missing element type for inline asm upgrade");
4705 case Intrinsic::preserve_array_access_index:
4706 case Intrinsic::preserve_struct_access_index:
4707 case Intrinsic::aarch64_ldaxr:
4708 case Intrinsic::aarch64_ldxr:
4709 case Intrinsic::aarch64_stlxr:
4710 case Intrinsic::aarch64_stxr:
4711 case Intrinsic::arm_ldaex:
4712 case Intrinsic::arm_ldrex:
4713 case Intrinsic::arm_stlex:
4714 case Intrinsic::arm_strex: {
4717 case Intrinsic::aarch64_stlxr:
4718 case Intrinsic::aarch64_stxr:
4719 case Intrinsic::arm_stlex:
4720 case Intrinsic::arm_strex:
4727 if (!
Attrs.getParamElementType(ArgNo)) {
4728 Type *ElTy = getPtrElementTypeByID(ArgTyIDs[ArgNo]);
4730 return error(
"Missing element type for elementtype upgrade");
4732 Attrs =
Attrs.addParamAttribute(Context, ArgNo, NewAttr);
4750 if (MDLoader->hasFwdRefs())
4751 return error(
"Invalid function metadata: incoming forward references");
4753 InstructionList.
clear();
4754 unsigned ModuleValueListSize = ValueList.
size();
4755 unsigned ModuleMDLoaderSize = MDLoader->size();
4759 unsigned FTyID = FunctionTypeIDs[
F];
4761 unsigned ArgTyID = getContainedTypeID(FTyID, ArgNo + 1);
4762 assert(
I.getType() == getTypeByID(ArgTyID) &&
4763 "Incorrect fully specified type for Function Argument");
4767 unsigned NextValueNo = ValueList.
size();
4769 unsigned CurBBNo = 0;
4778 auto getLastInstruction = [&]() ->
Instruction * {
4779 if (CurBB && !CurBB->
empty())
4780 return &CurBB->
back();
4781 else if (CurBBNo && FunctionBBs[CurBBNo - 1] &&
4782 !FunctionBBs[CurBBNo - 1]->empty())
4783 return &FunctionBBs[CurBBNo - 1]->back();
4787 std::vector<OperandBundleDef> OperandBundles;
4798 switch (Entry.Kind) {
4800 return error(
"Malformed block");
4802 goto OutOfRecordLoop;
4807 if (
Error Err = Stream.SkipBlock())
4811 if (
Error Err = parseConstants())
4813 NextValueNo = ValueList.
size();
4816 if (
Error Err = parseValueSymbolTable())
4820 if (
Error Err = MDLoader->parseMetadataAttachment(*
F, InstructionList))
4824 assert(DeferredMetadataInfo.empty() &&
4825 "Must read all module-level metadata before function-level");
4826 if (
Error Err = MDLoader->parseFunctionMetadata())
4830 if (
Error Err = parseUseLists())
4844 unsigned ResTypeID = InvalidTypeID;
4848 switch (
unsigned BitCode = MaybeBitCode.
get()) {
4850 return error(
"Invalid value");
4853 return error(
"Invalid record");
4855 FunctionBBs.resize(
Record[0]);
4858 auto BBFRI = BasicBlockFwdRefs.
find(
F);
4859 if (BBFRI == BasicBlockFwdRefs.
end()) {
4863 auto &BBRefs = BBFRI->second;
4865 if (BBRefs.size() > FunctionBBs.size())
4866 return error(
"Invalid ID");
4867 assert(!BBRefs.empty() &&
"Unexpected empty array");
4868 assert(!BBRefs.front() &&
"Invalid reference to entry block");
4869 for (
unsigned I = 0, E = FunctionBBs.size(), RE = BBRefs.size();
I != E;
4871 if (
I < RE && BBRefs[
I]) {
4872 BBRefs[
I]->insertInto(
F);
4873 FunctionBBs[
I] = BBRefs[
I];
4879 BasicBlockFwdRefs.
erase(BBFRI);
4882 CurBB = FunctionBBs[0];
4889 return error(
"Invalid record");
4904 if (
auto *
F = dyn_cast<Function>(ValueList[
ValID]))
4905 BackwardRefFunctions.push_back(
F);
4907 return error(
"Invalid record");
4914 I = getLastInstruction();
4917 return error(
"Invalid record");
4918 I->setDebugLoc(LastLoc);
4923 I = getLastInstruction();
4925 return error(
"Invalid record");
4933 Scope = dyn_cast_or_null<MDNode>(
4934 MDLoader->getMetadataFwdRefOrLoad(ScopeID - 1));
4936 return error(
"Invalid record");
4939 IA = dyn_cast_or_null<MDNode>(
4940 MDLoader->getMetadataFwdRefOrLoad(IAID - 1));
4942 return error(
"Invalid record");
4944 LastLoc = DILocation::get(
Scope->getContext(), Line, Col, Scope, IA,
4946 I->setDebugLoc(LastLoc);
4954 if (getValueTypePair(
Record, OpNum, NextValueNo, LHS,
TypeID, CurBB) ||
4956 return error(
"Invalid record");
4960 return error(
"Invalid record");
4964 if (OpNum <
Record.size()) {
4965 if (isa<FPMathOperator>(
I)) {
4968 I->setFastMathFlags(FMF);
4977 if (getValueTypePair(
Record, OpNum, NextValueNo, LHS,
TypeID, CurBB) ||
4981 return error(
"Invalid record");
4985 return error(
"Invalid record");
4989 if (OpNum <
Record.size()) {
4990 if (Opc == Instruction::Add ||
4991 Opc == Instruction::Sub ||
4992 Opc == Instruction::Mul ||
4993 Opc == Instruction::Shl) {
4995 cast<BinaryOperator>(
I)->setHasNoSignedWrap(
true);
4997 cast<BinaryOperator>(
I)->setHasNoUnsignedWrap(
true);
4998 }
else if (Opc == Instruction::SDiv ||
4999 Opc == Instruction::UDiv ||
5000 Opc == Instruction::LShr ||
5001 Opc == Instruction::AShr) {
5003 cast<BinaryOperator>(
I)->setIsExact(
true);
5004 }
else if (Opc == Instruction::Or) {
5006 cast<PossiblyDisjointInst>(
I)->setIsDisjoint(
true);
5007 }
else if (isa<FPMathOperator>(
I)) {
5010 I->setFastMathFlags(FMF);
5019 if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB) ||
5020 OpNum + 1 >
Record.size())
5021 return error(
"Invalid record");
5023 ResTypeID =
Record[OpNum++];
5024 Type *ResTy = getTypeByID(ResTypeID);
5027 if (Opc == -1 || !ResTy)
5028 return error(
"Invalid record");
5033 assert(CurBB &&
"No current BB?");
5039 return error(
"Invalid cast");
5043 if (OpNum <
Record.size()) {
5044 if (Opc == Instruction::ZExt || Opc == Instruction::UIToFP) {
5046 cast<PossiblyNonNegInst>(
I)->setNonNeg(
true);
5047 }
else if (Opc == Instruction::Trunc) {
5049 cast<TruncInst>(
I)->setHasNoUnsignedWrap(
true);
5051 cast<TruncInst>(
I)->setHasNoSignedWrap(
true);
5068 InBounds =
Record[OpNum++];
5070 Ty = getTypeByID(TyID);
5073 TyID = InvalidTypeID;
5078 unsigned BasePtrTypeID;
5079 if (getValueTypePair(
Record, OpNum, NextValueNo, BasePtr, BasePtrTypeID,
5081 return error(
"Invalid record");
5084 TyID = getContainedTypeID(BasePtrTypeID);
5085 if (
BasePtr->getType()->isVectorTy())
5086 TyID = getContainedTypeID(TyID);
5087 Ty = getTypeByID(TyID);
5091 while (OpNum !=
Record.size()) {
5094 if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB))
5095 return error(
"Invalid record");
5102 if (cast<GEPOperator>(
I)->getNumIndices() != 0) {
5105 unsigned SubType = 0;
5106 if (GTI.isStruct()) {
5108 Idx->getType()->isVectorTy()
5113 ResTypeID = getContainedTypeID(ResTypeID, SubType);
5120 ResTypeID = getVirtualTypeID(
I->getType()->getScalarType(), ResTypeID);
5121 if (
I->getType()->isVectorTy())
5122 ResTypeID = getVirtualTypeID(
I->getType(), ResTypeID);
5126 cast<GetElementPtrInst>(
I)->setIsInBounds(
true);
5135 if (getValueTypePair(
Record, OpNum, NextValueNo, Agg, AggTypeID, CurBB))
5136 return error(
"Invalid record");
5139 unsigned RecSize =
Record.size();
5140 if (OpNum == RecSize)
5141 return error(
"EXTRACTVAL: Invalid instruction with 0 indices");
5144 ResTypeID = AggTypeID;
5145 for (; OpNum != RecSize; ++OpNum) {
5150 if (!IsStruct && !IsArray)
5151 return error(
"EXTRACTVAL: Invalid type");
5153 return error(
"Invalid value");
5155 return error(
"EXTRACTVAL: Invalid struct index");
5157 return error(
"EXTRACTVAL: Invalid array index");
5162 ResTypeID = getContainedTypeID(ResTypeID,
Index);
5165 ResTypeID = getContainedTypeID(ResTypeID);
5179 if (getValueTypePair(
Record, OpNum, NextValueNo, Agg, AggTypeID, CurBB))
5180 return error(
"Invalid record");
5183 if (getValueTypePair(
Record, OpNum, NextValueNo, Val, ValTypeID, CurBB))
5184 return error(
"Invalid record");
5186 unsigned RecSize =
Record.size();
5187 if (OpNum == RecSize)
5188 return error(
"INSERTVAL: Invalid instruction with 0 indices");
5192 for (; OpNum != RecSize; ++OpNum) {
5197 if (!IsStruct && !IsArray)
5198 return error(
"INSERTVAL: Invalid type");
5200 return error(
"Invalid value");
5202 return error(
"INSERTVAL: Invalid struct index");
5204 return error(
"INSERTVAL: Invalid array index");
5214 return error(
"Inserted value type doesn't match aggregate type");
5217 ResTypeID = AggTypeID;
5229 if (getValueTypePair(
Record, OpNum, NextValueNo, TrueVal,
TypeID,
5233 popValue(
Record, OpNum, NextValueNo, CondType,
5234 getVirtualTypeID(CondType),
Cond, CurBB))
5235 return error(
"Invalid record");
5248 unsigned ValTypeID, CondTypeID;
5249 if (getValueTypePair(
Record, OpNum, NextValueNo, TrueVal, ValTypeID,
5251 popValue(
Record, OpNum, NextValueNo,
TrueVal->getType(), ValTypeID,
5253 getValueTypePair(
Record, OpNum, NextValueNo,
Cond, CondTypeID, CurBB))
5254 return error(
"Invalid record");
5258 dyn_cast<VectorType>(
Cond->getType())) {
5261 return error(
"Invalid type for value");
5265 return error(
"Invalid type for value");
5269 ResTypeID = ValTypeID;
5271 if (OpNum <
Record.size() && isa<FPMathOperator>(
I)) {
5274 I->setFastMathFlags(FMF);
5282 unsigned VecTypeID, IdxTypeID;
5283 if (getValueTypePair(
Record, OpNum, NextValueNo, Vec, VecTypeID, CurBB) ||
5284 getValueTypePair(
Record, OpNum, NextValueNo,
Idx, IdxTypeID, CurBB))
5285 return error(
"Invalid record");
5287 return error(
"Invalid type for value");
5289 ResTypeID = getContainedTypeID(VecTypeID);
5297 unsigned VecTypeID, IdxTypeID;
5298 if (getValueTypePair(
Record, OpNum, NextValueNo, Vec, VecTypeID, CurBB))
5299 return error(
"Invalid record");
5301 return error(
"Invalid type for value");
5302 if (popValue(
Record, OpNum, NextValueNo,
5303 cast<VectorType>(Vec->
getType())->getElementType(),
5304 getContainedTypeID(VecTypeID), Elt, CurBB) ||
5305 getValueTypePair(
Record, OpNum, NextValueNo,
Idx, IdxTypeID, CurBB))
5306 return error(
"Invalid record");
5308 ResTypeID = VecTypeID;
5316 unsigned Vec1TypeID;
5317 if (getValueTypePair(
Record, OpNum, NextValueNo, Vec1, Vec1TypeID,
5319 popValue(
Record, OpNum, NextValueNo, Vec1->
getType(), Vec1TypeID,
5321 return error(
"Invalid record");
5323 unsigned MaskTypeID;
5324 if (getValueTypePair(
Record, OpNum, NextValueNo, Mask, MaskTypeID, CurBB))
5325 return error(
"Invalid record");
5327 return error(
"Invalid type for value");
5331 getVirtualTypeID(
I->getType(), getContainedTypeID(Vec1TypeID));
5346 if (getValueTypePair(
Record, OpNum, NextValueNo, LHS, LHSTypeID, CurBB) ||
5349 return error(
"Invalid record");
5351 if (OpNum >=
Record.size())
5353 "Invalid record: operand number exceeded available operands");
5358 if (IsFP &&
Record.size() > OpNum+1)
5361 if (OpNum+1 !=
Record.size())
5362 return error(
"Invalid record");
5366 return error(
"Invalid fcmp predicate");
5370 return error(
"Invalid icmp predicate");
5374 ResTypeID = getVirtualTypeID(
I->getType()->getScalarType());
5376 ResTypeID = getVirtualTypeID(
I->getType(), ResTypeID);
5379 I->setFastMathFlags(FMF);
5396 if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB))
5397 return error(
"Invalid record");
5398 if (OpNum !=
Record.size())
5399 return error(
"Invalid record");
5407 return error(
"Invalid record");
5410 return error(
"Invalid record");
5412 if (
Record.size() == 1) {
5420 getVirtualTypeID(CondType), CurBB);
5421 if (!FalseDest || !
Cond)
5422 return error(
"Invalid record");
5430 return error(
"Invalid record");
5433 Value *CleanupPad = getValue(
Record,
Idx++, NextValueNo, TokenTy,
5434 getVirtualTypeID(TokenTy), CurBB);
5436 return error(
"Invalid record");
5438 if (
Record.size() == 2) {
5439 UnwindDest = getBasicBlock(
Record[
Idx++]);
5441 return error(
"Invalid record");
5450 return error(
"Invalid record");
5454 getVirtualTypeID(TokenTy), CurBB);
5456 return error(
"Invalid record");
5459 return error(
"Invalid record");
5468 return error(
"Invalid record");
5474 getVirtualTypeID(TokenTy), CurBB);
5476 return error(
"Invalid record");
5481 for (
unsigned Op = 0;
Op != NumHandlers; ++
Op) {
5484 return error(
"Invalid record");
5490 UnwindDest = getBasicBlock(
Record[
Idx++]);
5492 return error(
"Invalid record");
5496 return error(
"Invalid record");
5501 CatchSwitch->addHandler(Handler);
5503 ResTypeID = getVirtualTypeID(
I->getType());
5511 return error(
"Invalid record");
5517 getVirtualTypeID(TokenTy), CurBB);
5519 return error(
"Invald record");
5521 unsigned NumArgOperands =
Record[
Idx++];
5524 for (
unsigned Op = 0;
Op != NumArgOperands; ++
Op) {
5527 if (getValueTypePair(
Record,
Idx, NextValueNo, Val, ValTypeID,
nullptr))
5528 return error(
"Invalid record");
5529 Args.push_back(Val);
5533 return error(
"Invalid record");
5539 ResTypeID = getVirtualTypeID(
I->getType());
5545 if ((
Record[0] >> 16) == SWITCH_INST_MAGIC) {
5551 unsigned OpTyID =
Record[1];
5552 Type *OpTy = getTypeByID(OpTyID);
5553 unsigned ValueBitWidth = cast<IntegerType>(OpTy)->getBitWidth();
5558 return error(
"Invalid record");
5560 unsigned NumCases =
Record[4];
5565 unsigned CurIdx = 5;
5566 for (
unsigned i = 0; i != NumCases; ++i) {
5568 unsigned NumItems =
Record[CurIdx++];
5569 for (
unsigned ci = 0; ci != NumItems; ++ci) {
5570 bool isSingleNumber =
Record[CurIdx++];
5573 unsigned ActiveWords = 1;
5574 if (ValueBitWidth > 64)
5575 ActiveWords =
Record[CurIdx++];
5578 CurIdx += ActiveWords;
5580 if (!isSingleNumber) {
5582 if (ValueBitWidth > 64)
5583 ActiveWords =
Record[CurIdx++];
5586 CurIdx += ActiveWords;
5599 SI->addCase(Cst, DestBB);
5608 return error(
"Invalid record");
5609 unsigned OpTyID =
Record[0];
5610 Type *OpTy = getTypeByID(OpTyID);
5614 return error(
"Invalid record");
5615 unsigned NumCases = (
Record.size()-3)/2;
5618 for (
unsigned i = 0, e = NumCases; i !=
e; ++i) {
5619 ConstantInt *CaseVal = dyn_cast_or_null<ConstantInt>(
5620 getFnValueByID(
Record[3+i*2], OpTy, OpTyID,
nullptr));
5622 if (!CaseVal || !DestBB) {
5624 return error(
"Invalid record");
5626 SI->addCase(CaseVal, DestBB);
5633 return error(
"Invalid record");
5634 unsigned OpTyID =
Record[0];
5635 Type *OpTy = getTypeByID(OpTyID);
5637 if (!OpTy || !Address)
5638 return error(
"Invalid record");
5639 unsigned NumDests =
Record.size()-2;
5642 for (
unsigned i = 0, e = NumDests; i !=
e; ++i) {
5647 return error(
"Invalid record");
5657 return error(
"Invalid record");
5660 unsigned CCInfo =
Record[OpNum++];
5664 unsigned FTyID = InvalidTypeID;
5666 if ((CCInfo >> 13) & 1) {
5668 FTy = dyn_cast<FunctionType>(getTypeByID(FTyID));
5670 return error(
"Explicit invoke type is not a function type");
5674 unsigned CalleeTypeID;
5675 if (getValueTypePair(
Record, OpNum, NextValueNo, Callee, CalleeTypeID,
5677 return error(
"Invalid record");
5681 return error(
"Callee is not a pointer");
5683 FTyID = getContainedTypeID(CalleeTypeID);
5684 FTy = dyn_cast_or_null<FunctionType>(getTypeByID(FTyID));
5686 return error(
"Callee is not of pointer to function type");
5688 if (
Record.size() < FTy->getNumParams() + OpNum)
5689 return error(
"Insufficient operands to call");
5693 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i, ++OpNum) {
5694 unsigned ArgTyID = getContainedTypeID(FTyID, i + 1);
5695 Ops.
push_back(getValue(
Record, OpNum, NextValueNo, FTy->getParamType(i),
5699 return error(
"Invalid record");
5702 if (!FTy->isVarArg()) {
5703 if (
Record.size() != OpNum)
5704 return error(
"Invalid record");
5707 while (OpNum !=
Record.size()) {
5710 if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB))
5711 return error(
"Invalid record");
5718 if (!OperandBundles.empty())
5723 ResTypeID = getContainedTypeID(FTyID);
5724 OperandBundles.clear();
5726 cast<InvokeInst>(
I)->setCallingConv(
5728 cast<InvokeInst>(
I)->setAttributes(PAL);
5729 if (
Error Err = propagateAttributeTypes(cast<CallBase>(
I), ArgTyIDs)) {
5738 Value *Val =
nullptr;
5740 if (getValueTypePair(
Record,
Idx, NextValueNo, Val, ValTypeID, CurBB))
5741 return error(
"Invalid record");
5750 unsigned CCInfo =
Record[OpNum++];
5753 unsigned NumIndirectDests =
Record[OpNum++];
5755 for (
unsigned i = 0, e = NumIndirectDests; i !=
e; ++i)
5758 unsigned FTyID = InvalidTypeID;
5762 FTy = dyn_cast_or_null<FunctionType>(getTypeByID(FTyID));
5764 return error(
"Explicit call type is not a function type");
5768 unsigned CalleeTypeID;
5769 if (getValueTypePair(
Record, OpNum, NextValueNo, Callee, CalleeTypeID,
5771 return error(
"Invalid record");
5775 return error(
"Callee is not a pointer type");
5777 FTyID = getContainedTypeID(CalleeTypeID);
5778 FTy = dyn_cast_or_null<FunctionType>(getTypeByID(FTyID));
5780 return error(
"Callee is not of pointer to function type");
5782 if (
Record.size() < FTy->getNumParams() + OpNum)
5783 return error(
"Insufficient operands to call");
5788 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i, ++OpNum) {
5790 unsigned ArgTyID = getContainedTypeID(FTyID, i + 1);
5791 if (FTy->getParamType(i)->isLabelTy())
5792 Arg = getBasicBlock(
Record[OpNum]);
5794 Arg = getValue(
Record, OpNum, NextValueNo, FTy->getParamType(i),
5797 return error(
"Invalid record");
5798 Args.push_back(Arg);
5803 if (!FTy->isVarArg()) {
5804 if (OpNum !=
Record.size())
5805 return error(
"Invalid record");
5807 while (OpNum !=
Record.size()) {
5810 if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB))
5811 return error(
"Invalid record");
5818 if (!OperandBundles.empty())
5821 if (
auto *IA = dyn_cast<InlineAsm>(Callee)) {
5826 if (
none_of(ConstraintInfo, IsLabelConstraint)) {
5831 unsigned FirstBlockArg =
Args.size() - IndirectDests.
size();
5832 for (
unsigned ArgNo = FirstBlockArg; ArgNo <
Args.size(); ++ArgNo) {
5833 unsigned LabelNo = ArgNo - FirstBlockArg;
5834 auto *BA = dyn_cast<BlockAddress>(Args[ArgNo]);
5835 if (!BA || BA->getFunction() !=
F ||
5836 LabelNo > IndirectDests.
size() ||
5837 BA->getBasicBlock() != IndirectDests[LabelNo])
5838 return error(
"callbr argument does not match indirect dest");
5843 ArgTyIDs.
erase(ArgTyIDs.
begin() + FirstBlockArg, ArgTyIDs.
end());
5847 for (
Value *Arg : Args)
5850 FunctionType::get(FTy->getReturnType(), ArgTys, FTy->isVarArg());
5853 std::string Constraints =
IA->getConstraintString();
5856 for (
const auto &CI : ConstraintInfo) {
5858 if (ArgNo >= FirstBlockArg)
5859 Constraints.insert(Pos,
"!");
5864 Pos = Constraints.find(
',', Pos);
5865 if (Pos == std::string::npos)
5871 IA->hasSideEffects(),
IA->isAlignStack(),
5872 IA->getDialect(),
IA->canThrow());
5878 ResTypeID = getContainedTypeID(FTyID);
5879 OperandBundles.clear();
5881 cast<CallBrInst>(
I)->setCallingConv(
5883 cast<CallBrInst>(
I)->setAttributes(PAL);
5884 if (
Error Err = propagateAttributeTypes(cast<CallBase>(
I), ArgTyIDs)) {
5896 return error(
"Invalid phi record");
5898 unsigned TyID =
Record[0];
5899 Type *Ty = getTypeByID(TyID);
5901 return error(
"Invalid phi record");
5906 size_t NumArgs = (
Record.size() - 1) / 2;
5908 if ((
Record.size() - 1) % 2 == 1 && !isa<FPMathOperator>(PN)) {
5910 return error(
"Invalid phi record");
5915 for (
unsigned i = 0; i != NumArgs; i++) {
5919 return error(
"Invalid phi BB");
5926 auto It =
Args.find(BB);
5927 if (It !=
Args.end()) {
5938 if (!PhiConstExprBB)
5940 EdgeBB = PhiConstExprBB;
5948 V = getValueSigned(
Record, i * 2 + 1, NextValueNo, Ty, TyID, EdgeBB);
5950 V = getValue(
Record, i * 2 + 1, NextValueNo, Ty, TyID, EdgeBB);
5954 return error(
"Invalid phi record");
5957 if (EdgeBB == PhiConstExprBB && !EdgeBB->
empty()) {
5958 ConstExprEdgeBBs.
insert({{BB, CurBB}, EdgeBB});
5959 PhiConstExprBB =
nullptr;
5962 Args.insert({BB,
V});
5968 if (
Record.size() % 2 == 0) {
5969 assert(isa<FPMathOperator>(
I) &&
"Unexpected phi type");
5972 I->setFastMathFlags(FMF);
5984 return error(
"Invalid record");
5988 return error(
"Invalid record");
5991 Type *Ty = getTypeByID(ResTypeID);
5993 return error(
"Invalid record");
5995 Value *PersFn =
nullptr;
5996 unsigned PersFnTypeID;
5997 if (getValueTypePair(
Record,
Idx, NextValueNo, PersFn, PersFnTypeID,
5999 return error(
"Invalid record");
6001 if (!
F->hasPersonalityFn())
6002 F->setPersonalityFn(cast<Constant>(PersFn));
6003 else if (
F->getPersonalityFn() != cast<Constant>(PersFn))
6004 return error(
"Personality function mismatch");
6011 for (
unsigned J = 0; J != NumClauses; ++J) {
6017 if (getValueTypePair(
Record,
Idx, NextValueNo, Val, ValTypeID,
6020 return error(
"Invalid record");
6024 !isa<ArrayType>(Val->
getType())) &&
6025 "Catch clause has a invalid type!");
6027 isa<ArrayType>(Val->
getType())) &&
6028 "Filter clause has invalid type!");
6039 return error(
"Invalid record");
6042 const bool InAlloca = Bitfield::get<APV::UsedWithInAlloca>(Rec);
6043 const bool SwiftError = Bitfield::get<APV::SwiftError>(Rec);
6044 unsigned TyID =
Record[0];
6045 Type *Ty = getTypeByID(TyID);
6046 if (!Bitfield::get<APV::ExplicitType>(Rec)) {
6047 TyID = getContainedTypeID(TyID);
6048 Ty = getTypeByID(TyID);
6050 return error(
"Missing element type for old-style alloca");
6052 unsigned OpTyID =
Record[1];
6053 Type *OpTy = getTypeByID(OpTyID);
6057 Bitfield::get<APV::AlignLower>(Rec) |
6058 (Bitfield::get<APV::AlignUpper>(Rec) << APV::AlignLower::Bits);
6059 if (
Error Err = parseAlignmentValue(AlignExp,
Align)) {
6063 return error(
"Invalid record");
6066 unsigned AS =
Record.size() == 5 ?
Record[4] :
DL.getAllocaAddrSpace();
6070 return error(
"alloca of unsized type");
6072 Align =
DL.getPrefTypeAlign(Ty);
6074 if (!
Size->getType()->isIntegerTy())
6075 return error(
"alloca element count must have integer type");
6081 ResTypeID = getVirtualTypeID(AI->
getType(), TyID);
6089 if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB) ||
6090 (OpNum + 2 !=
Record.size() && OpNum + 3 !=
Record.size()))
6091 return error(
"Invalid record");
6093 if (!isa<PointerType>(
Op->getType()))
6094 return error(
"Load operand is not a pointer type");
6097 if (OpNum + 3 ==
Record.size()) {
6098 ResTypeID =
Record[OpNum++];
6099 Ty = getTypeByID(ResTypeID);
6101 ResTypeID = getContainedTypeID(OpTypeID);
6102 Ty = getTypeByID(ResTypeID);
6106 return error(
"Missing load type");
6108 if (
Error Err = typeCheckLoadStoreInst(Ty,
Op->getType()))
6116 return error(
"load of unsized type");
6118 Align = TheModule->getDataLayout().getABITypeAlign(Ty);
6128 if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB) ||
6129 (OpNum + 4 !=
Record.size() && OpNum + 5 !=
Record.size()))
6130 return error(
"Invalid record");
6132 if (!isa<PointerType>(
Op->getType()))
6133 return error(
"Load operand is not a pointer type");
6136 if (OpNum + 5 ==
Record.size()) {
6137 ResTypeID =
Record[OpNum++];
6138 Ty = getTypeByID(ResTypeID);
6140 ResTypeID = getContainedTypeID(OpTypeID);
6141 Ty = getTypeByID(ResTypeID);
6145 return error(
"Missing atomic load type");
6147 if (
Error Err = typeCheckLoadStoreInst(Ty,
Op->getType()))
6151 if (Ordering == AtomicOrdering::NotAtomic ||
6152 Ordering == AtomicOrdering::Release ||
6153 Ordering == AtomicOrdering::AcquireRelease)
6154 return error(
"Invalid record");
6155 if (Ordering != AtomicOrdering::NotAtomic &&
Record[OpNum] == 0)
6156 return error(
"Invalid record");
6163 return error(
"Alignment missing from atomic load");
6172 unsigned PtrTypeID, ValTypeID;
6173 if (getValueTypePair(
Record, OpNum, NextValueNo,
Ptr, PtrTypeID, CurBB))
6174 return error(
"Invalid record");
6177 if (getValueTypePair(
Record, OpNum, NextValueNo, Val, ValTypeID, CurBB))
6178 return error(
"Invalid record");
6180 ValTypeID = getContainedTypeID(PtrTypeID);
6181 if (popValue(
Record, OpNum, NextValueNo, getTypeByID(ValTypeID),
6182 ValTypeID, Val, CurBB))
6183 return error(
"Invalid record");
6186 if (OpNum + 2 !=
Record.size())
6187 return error(
"Invalid record");
6189 if (
Error Err = typeCheckLoadStoreInst(Val->
getType(),
Ptr->getType()))
6196 return error(
"store of unsized type");
6198 Align = TheModule->getDataLayout().getABITypeAlign(Val->
getType());
6208 unsigned PtrTypeID, ValTypeID;
6209 if (getValueTypePair(
Record, OpNum, NextValueNo,
Ptr, PtrTypeID, CurBB) ||
6210 !isa<PointerType>(
Ptr->getType()))
6211 return error(
"Invalid record");
6213 if (getValueTypePair(
Record, OpNum, NextValueNo, Val, ValTypeID, CurBB))
6214 return error(
"Invalid record");
6216 ValTypeID = getContainedTypeID(PtrTypeID);
6217 if (popValue(
Record, OpNum, NextValueNo, getTypeByID(ValTypeID),
6218 ValTypeID, Val, CurBB))
6219 return error(
"Invalid record");
6222 if (OpNum + 4 !=
Record.size())
6223 return error(
"Invalid record");
6225 if (
Error Err = typeCheckLoadStoreInst(Val->
getType(),
Ptr->getType()))
6228 if (Ordering == AtomicOrdering::NotAtomic ||
6229 Ordering == AtomicOrdering::Acquire ||
6230 Ordering == AtomicOrdering::AcquireRelease)
6231 return error(
"Invalid record");
6233 if (Ordering != AtomicOrdering::NotAtomic &&
Record[OpNum] == 0)
6234 return error(
"Invalid record");
6240 return error(
"Alignment missing from atomic store");
6248 const size_t NumRecords =
Record.size();
6252 if (getValueTypePair(
Record, OpNum, NextValueNo,
Ptr, PtrTypeID, CurBB))
6253 return error(
"Invalid record");
6255 if (!isa<PointerType>(
Ptr->getType()))
6256 return error(
"Cmpxchg operand is not a pointer type");
6259 unsigned CmpTypeID = getContainedTypeID(PtrTypeID);
6260 if (popValue(
Record, OpNum, NextValueNo, getTypeByID(CmpTypeID),
6261 CmpTypeID, Cmp, CurBB))
6262 return error(
"Invalid record");
6265 if (popValue(
Record, OpNum, NextValueNo,
Cmp->getType(), CmpTypeID,
6267 NumRecords < OpNum + 3 || NumRecords > OpNum + 5)
6268 return error(
"Invalid record");
6272 if (SuccessOrdering == AtomicOrdering::NotAtomic ||
6273 SuccessOrdering == AtomicOrdering::Unordered)
6274 return error(
"Invalid record");
6278 if (
Error Err = typeCheckLoadStoreInst(
Cmp->getType(),
Ptr->getType()))
6286 if (FailureOrdering == AtomicOrdering::NotAtomic ||
6287 FailureOrdering == AtomicOrdering::Unordered)
6288 return error(
"Invalid record");
6290 const Align Alignment(
6291 TheModule->getDataLayout().getTypeStoreSize(
Cmp->getType()));
6294 FailureOrdering, SSID);
6295 cast<AtomicCmpXchgInst>(
I)->setVolatile(
Record[OpNum]);
6297 if (NumRecords < 8) {
6301 I->insertInto(CurBB, CurBB->
end());
6303 ResTypeID = CmpTypeID;
6305 cast<AtomicCmpXchgInst>(
I)->setWeak(
Record[OpNum + 4]);
6307 ResTypeID = getVirtualTypeID(
I->getType(), {CmpTypeID, I1TypeID});
6316 const size_t NumRecords =
Record.size();
6320 if (getValueTypePair(
Record, OpNum, NextValueNo,
Ptr, PtrTypeID, CurBB))
6321 return error(
"Invalid record");
6323 if (!isa<PointerType>(
Ptr->getType()))
6324 return error(
"Cmpxchg operand is not a pointer type");
6328 if (getValueTypePair(
Record, OpNum, NextValueNo, Cmp, CmpTypeID, CurBB))
6329 return error(
"Invalid record");
6331 Value *Val =
nullptr;
6332 if (popValue(
Record, OpNum, NextValueNo,
Cmp->getType(), CmpTypeID, Val,
6334 return error(
"Invalid record");
6336 if (NumRecords < OpNum + 3 || NumRecords > OpNum + 6)
6337 return error(
"Invalid record");
6339 const bool IsVol =
Record[OpNum];
6344 return error(
"Invalid cmpxchg success ordering");
6348 if (
Error Err = typeCheckLoadStoreInst(
Cmp->getType(),
Ptr->getType()))
6354 return error(
"Invalid cmpxchg failure ordering");
6356 const bool IsWeak =
Record[OpNum + 4];
6360 if (NumRecords == (OpNum + 6)) {
6361 if (
Error Err = parseAlignmentValue(
Record[OpNum + 5], Alignment))
6366 Align(TheModule->getDataLayout().getTypeStoreSize(
Cmp->getType()));
6369 FailureOrdering, SSID);
6370 cast<AtomicCmpXchgInst>(
I)->setVolatile(IsVol);
6371 cast<AtomicCmpXchgInst>(
I)->setWeak(IsWeak);
6374 ResTypeID = getVirtualTypeID(
I->getType(), {CmpTypeID, I1TypeID});
6383 const size_t NumRecords =
Record.size();
6388 if (getValueTypePair(
Record, OpNum, NextValueNo,
Ptr, PtrTypeID, CurBB))
6389 return error(
"Invalid record");
6391 if (!isa<PointerType>(
Ptr->getType()))
6392 return error(
"Invalid record");
6394 Value *Val =
nullptr;
6395 unsigned ValTypeID = InvalidTypeID;
6397 ValTypeID = getContainedTypeID(PtrTypeID);
6398 if (popValue(
Record, OpNum, NextValueNo,
6399 getTypeByID(ValTypeID), ValTypeID, Val, CurBB))
6400 return error(
"Invalid record");
6402 if (getValueTypePair(
Record, OpNum, NextValueNo, Val, ValTypeID, CurBB))
6403 return error(
"Invalid record");
6406 if (!(NumRecords == (OpNum + 4) || NumRecords == (OpNum + 5)))
6407 return error(
"Invalid record");
6413 return error(
"Invalid record");
6415 const bool IsVol =
Record[OpNum + 1];
6418 if (Ordering == AtomicOrdering::NotAtomic ||
6419 Ordering == AtomicOrdering::Unordered)
6420 return error(
"Invalid record");
6426 if (NumRecords == (OpNum + 5)) {
6427 if (
Error Err = parseAlignmentValue(
Record[OpNum + 4], Alignment))
6433 Align(TheModule->getDataLayout().getTypeStoreSize(Val->
getType()));
6436 ResTypeID = ValTypeID;
6437 cast<AtomicRMWInst>(
I)->setVolatile(IsVol);
6444 return error(
"Invalid record");
6446 if (Ordering == AtomicOrdering::NotAtomic ||
6447 Ordering == AtomicOrdering::Unordered ||
6448 Ordering == AtomicOrdering::Monotonic)
6449 return error(
"Invalid record");
6458 SeenDebugRecord =
true;
6461 return error(
"Invalid dbg record: missing instruction");
6474 SeenDebugRecord =
true;
6477 return error(
"Invalid dbg record: missing instruction");
6493 cast<DILocalVariable>(getFnMetadataByID(
Record[Slot++]));
6495 cast<DIExpression>(getFnMetadataByID(
Record[Slot++]));
6507 unsigned SlotBefore =
Slot;
6508 if (getValueTypePair(
Record, Slot, NextValueNo, V, TyID, CurBB))
6509 return error(
"Invalid dbg record: invalid value");
6511 assert((SlotBefore == Slot - 1) &&
"unexpected fwd ref");
6514 RawLocation = getFnMetadataByID(
Record[Slot++]);
6522 DbgVariableRecord::LocationType::Value);
6526 DbgVariableRecord::LocationType::Declare);
6531 cast<DIExpression>(getFnMetadataByID(
Record[Slot++]));
6546 return error(
"Invalid record");
6550 unsigned CCInfo =
Record[OpNum++];
6556 return error(
"Fast math flags indicator set for call with no FMF");
6559 unsigned FTyID = InvalidTypeID;
6563 FTy = dyn_cast_or_null<FunctionType>(getTypeByID(FTyID));
6565 return error(
"Explicit call type is not a function type");
6569 unsigned CalleeTypeID;
6570 if (getValueTypePair(
Record, OpNum, NextValueNo, Callee, CalleeTypeID,
6572 return error(
"Invalid record");
6576 return error(
"Callee is not a pointer type");
6578 FTyID = getContainedTypeID(CalleeTypeID);
6579 FTy = dyn_cast_or_null<FunctionType>(getTypeByID(FTyID));
6581 return error(
"Callee is not of pointer to function type");
6583 if (
Record.size() < FTy->getNumParams() + OpNum)
6584 return error(
"Insufficient operands to call");
6589 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i, ++OpNum) {
6590 unsigned ArgTyID = getContainedTypeID(FTyID, i + 1);
6591 if (FTy->getParamType(i)->isLabelTy())
6592 Args.push_back(getBasicBlock(
Record[OpNum]));
6594 Args.push_back(getValue(
Record, OpNum, NextValueNo,
6595 FTy->getParamType(i), ArgTyID, CurBB));
6598 return error(
"Invalid record");
6602 if (!FTy->isVarArg()) {
6603 if (OpNum !=
Record.size())
6604 return error(
"Invalid record");
6606 while (OpNum !=
Record.size()) {
6609 if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB))
6610 return error(
"Invalid record");
6617 if (!OperandBundles.empty())
6621 ResTypeID = getContainedTypeID(FTyID);
6622 OperandBundles.clear();
6624 cast<CallInst>(
I)->setCallingConv(
6633 cast<CallInst>(
I)->setTailCallKind(TCK);
6634 cast<CallInst>(
I)->setAttributes(PAL);
6635 if (isa<DbgInfoIntrinsic>(
I))
6636 SeenDebugIntrinsic =
true;
6637 if (
Error Err = propagateAttributeTypes(cast<CallBase>(
I), ArgTyIDs)) {
6642 if (!isa<FPMathOperator>(
I))
6643 return error(
"Fast-math-flags specified for call without "
6644 "floating-point scalar or vector return type");
6645 I->setFastMathFlags(FMF);
6651 return error(
"Invalid record");
6652 unsigned OpTyID =
Record[0];
6653 Type *OpTy = getTypeByID(OpTyID);
6654 Value *
Op = getValue(
Record, 1, NextValueNo, OpTy, OpTyID, CurBB);
6656 Type *ResTy = getTypeByID(ResTypeID);
6657 if (!OpTy || !
Op || !ResTy)
6658 return error(
"Invalid record");
6670 return error(
"Invalid record");
6672 std::vector<Value *> Inputs;
6675 while (OpNum !=
Record.size()) {
6678 if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB))
6679 return error(
"Invalid record");
6680 Inputs.push_back(
Op);
6683 OperandBundles.emplace_back(BundleTags[
Record[0]], std::move(Inputs));
6691 if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB))
6692 return error(
"Invalid record");
6693 if (OpNum !=
Record.size())
6694 return error(
"Invalid record");
6697 ResTypeID = OpTypeID;
6707 return error(
"Invalid instruction with no BB");
6709 if (!OperandBundles.empty()) {
6711 return error(
"Operand bundles found with no consumer");
6713 I->insertInto(CurBB, CurBB->
end());
6716 if (
I->isTerminator()) {
6718 CurBB = CurBBNo < FunctionBBs.size() ? FunctionBBs[CurBBNo] :
nullptr;
6722 if (!
I->getType()->isVoidTy()) {
6723 assert(
I->getType() == getTypeByID(ResTypeID) &&
6724 "Incorrect result type ID");
6732 if (!OperandBundles.empty())
6733 return error(
"Operand bundles found with no consumer");
6737 if (!
A->getParent()) {
6739 for (
unsigned i = ModuleValueListSize, e = ValueList.
size(); i != e; ++i){
6740 if ((
A = dyn_cast_or_null<Argument>(ValueList[i])) && !
A->getParent()) {
6745 return error(
"Never resolved value found in function");
6750 if (MDLoader->hasFwdRefs())
6751 return error(
"Invalid function metadata: outgoing forward refs");
6756 for (
const auto &Pair : ConstExprEdgeBBs) {
6761 From->getTerminator()->replaceSuccessorWith(To, EdgeBB);
6767 ValueList.
shrinkTo(ModuleValueListSize);
6768 MDLoader->shrinkTo(ModuleMDLoaderSize);
6769 std::vector<BasicBlock*>().swap(FunctionBBs);
6774Error BitcodeReader::findFunctionInStream(
6777 while (DeferredFunctionInfoIterator->second == 0) {
6782 assert(VSTOffset == 0 || !
F->hasName());
6785 if (
Error Err = rememberAndSkipFunctionBodies())
6791SyncScope::ID BitcodeReader::getDecodedSyncScopeID(
unsigned Val) {
6794 if (Val >= SSIDs.
size())
6806 if (!
F || !
F->isMaterializable())
6810 assert(DFII != DeferredFunctionInfo.
end() &&
"Deferred function not found!");
6813 if (DFII->second == 0)
6814 if (
Error Err = findFunctionInStream(
F, DFII))
6818 if (
Error Err = materializeMetadata())
6822 if (
Error JumpFailed = Stream.JumpToBit(DFII->second))
6827 F->IsNewDbgInfoFormat =
true;
6829 if (
Error Err = parseFunctionBody(
F))
6831 F->setIsMaterializable(
false);
6835 if (SeenDebugIntrinsic && SeenDebugRecord)
6836 return error(
"Mixed debug intrinsics and debug records in bitcode module!");
6838 bool SeenAnyDebugInfo = SeenDebugIntrinsic || SeenDebugRecord;
6839 bool NewDbgInfoFormatDesired =
6840 SeenAnyDebugInfo ? SeenDebugRecord :
F->getParent()->IsNewDbgInfoFormat;
6841 if (SeenAnyDebugInfo) {
6850 if (NewDbgInfoFormatDesired !=
F->getParent()->IsNewDbgInfoFormat)
6851 F->getParent()->setNewDbgInfoFormatFlag(NewDbgInfoFormatDesired);
6853 F->setNewDbgInfoFormatFlag(NewDbgInfoFormatDesired);
6861 bool ModuleIsNewDbgInfoFormat =
F->getParent()->IsNewDbgInfoFormat;
6862 if (ModuleIsNewDbgInfoFormat || !SeenDebugRecord)
6863 F->setNewDbgInfoFormatFlag(ModuleIsNewDbgInfoFormat);
6865 F->setIsNewDbgInfoFormat(ModuleIsNewDbgInfoFormat);
6872 for (
auto &
I : UpgradedIntrinsics) {
6874 if (
CallInst *CI = dyn_cast<CallInst>(U))
6879 if (
DISubprogram *SP = MDLoader->lookupSubprogramForFunction(
F))
6880 F->setSubprogram(SP);
6883 if (!MDLoader->isStrippingTBAA()) {
6885 MDNode *TBAA =
I.getMetadata(LLVMContext::MD_tbaa);
6888 MDLoader->setStripTBAA(
true);
6895 if (
auto *MD =
I.getMetadata(LLVMContext::MD_prof)) {
6896 if (MD->getOperand(0) !=
nullptr && isa<MDString>(MD->getOperand(0))) {
6897 MDString *MDS = cast<MDString>(MD->getOperand(0));
6900 if (ProfName !=
"branch_weights")
6902 unsigned ExpectedNumOperands = 0;
6904 ExpectedNumOperands = BI->getNumSuccessors();
6905 else if (
SwitchInst *SI = dyn_cast<SwitchInst>(&
I))
6906 ExpectedNumOperands =
SI->getNumSuccessors();
6907 else if (isa<CallInst>(&
I))
6908 ExpectedNumOperands = 1;
6911 else if (isa<SelectInst>(&
I))
6912 ExpectedNumOperands = 2;
6917 if (MD->getNumOperands() != 1 + ExpectedNumOperands)
6918 I.setMetadata(LLVMContext::MD_prof,
nullptr);
6923 if (
auto *CI = dyn_cast<CallBase>(&
I)) {
6925 CI->getFunctionType()->getReturnType()));
6927 for (
unsigned ArgNo = 0; ArgNo < CI->arg_size(); ++ArgNo)
6929 CI->getArgOperand(ArgNo)->getType()));
6938 return materializeForwardReferencedFunctions();
6941Error BitcodeReader::materializeModule() {
6942 if (
Error Err = materializeMetadata())
6946 WillMaterializeAllForwardRefs =
true;
6951 if (
Error Err = materialize(&
F))
6957 if (LastFunctionBlockBit || NextUnreadBit)
6959 ? LastFunctionBlockBit
6965 if (!BasicBlockFwdRefs.
empty())
6966 return error(
"Never resolved function from blockaddress");
6972 for (
auto &
I : UpgradedIntrinsics) {
6973 for (
auto *U :
I.first->users()) {
6974 if (
CallInst *CI = dyn_cast<CallInst>(U))
6977 if (!
I.first->use_empty())
6978 I.first->replaceAllUsesWith(
I.second);
6979 I.first->eraseFromParent();
6981 UpgradedIntrinsics.clear();
6992std::vector<StructType *> BitcodeReader::getIdentifiedStructTypes()
const {
6993 return IdentifiedStructTypes;
6996ModuleSummaryIndexBitcodeReader::ModuleSummaryIndexBitcodeReader(
6999 : BitcodeReaderBase(
std::
move(Cursor), Strtab), TheIndex(TheIndex),
7000 ModulePath(ModulePath), IsPrevailing(IsPrevailing) {}
7002void ModuleSummaryIndexBitcodeReader::addThisModule() {
7007ModuleSummaryIndexBitcodeReader::getThisModule() {
7011template <
bool AllowNullValueInfo>
7012std::tuple<ValueInfo, GlobalValue::GUID, GlobalValue::GUID>
7013ModuleSummaryIndexBitcodeReader::getValueInfoFromValueId(
unsigned ValueId) {
7014 auto VGI = ValueIdToValueInfoMap[ValueId];
7019 assert(AllowNullValueInfo || std::get<0>(VGI));
7023void ModuleSummaryIndexBitcodeReader::setValueGUID(
7026 std::string GlobalId =
7029 auto OriginalNameID = ValueGUID;
7033 dbgs() <<
"GUID " << ValueGUID <<
"(" << OriginalNameID <<
") is "
7039 ValueIdToValueInfoMap[ValueID] = std::make_tuple(
7042 OriginalNameID, ValueGUID);
7048Error ModuleSummaryIndexBitcodeReader::parseValueSymbolTable(
7057 if (!MaybeCurrentBit)
7075 switch (Entry.Kind) {
7078 return error(
"Malformed block");
7081 if (
Error JumpFailed = Stream.JumpToBit(CurrentBit))
7094 switch (MaybeRecord.
get()) {
7099 return error(
"Invalid record");
7100 unsigned ValueID =
Record[0];
7102 auto VLI = ValueIdToLinkageMap.
find(ValueID);
7103 assert(VLI != ValueIdToLinkageMap.
end() &&
7104 "No linkage found for VST entry?");
7106 setValueGUID(ValueID,
ValueName, Linkage, SourceFileName);
7113 return error(
"Invalid record");
7114 unsigned ValueID =
Record[0];
7116 auto VLI = ValueIdToLinkageMap.
find(ValueID);
7117 assert(VLI != ValueIdToLinkageMap.
end() &&
7118 "No linkage found for VST entry?");
7120 setValueGUID(ValueID,
ValueName, Linkage, SourceFileName);
7126 unsigned ValueID =
Record[0];
7130 ValueIdToValueInfoMap[ValueID] = std::make_tuple(
7141Error ModuleSummaryIndexBitcodeReader::parseModule() {
7147 unsigned ValueId = 0;
7156 switch (Entry.Kind) {
7158 return error(
"Malformed block");
7165 if (
Error Err = Stream.SkipBlock())
7170 if (
Error Err = readBlockInfo())
7176 assert(((SeenValueSymbolTable && VSTOffset > 0) ||
7177 !SeenGlobalValSummary) &&
7178 "Expected early VST parse via VSTOffset record");
7179 if (
Error Err = Stream.SkipBlock())
7185 if (!SourceFileName.
empty())
7187 assert(!SeenValueSymbolTable &&
7188 "Already read VST when parsing summary block?");
7193 if (VSTOffset > 0) {
7194 if (
Error Err = parseValueSymbolTable(VSTOffset, ValueIdToLinkageMap))
7196 SeenValueSymbolTable =
true;
7198 SeenGlobalValSummary =
true;
7199 if (
Error Err = parseEntireSummary(Entry.ID))
7203 if (
Error Err = parseModuleStringTable())
7214 switch (MaybeBitCode.
get()) {
7218 if (
Error Err = parseVersionRecord(
Record).takeError())
7226 return error(
"Invalid record");
7234 auto &Hash = getThisModule()->second;
7236 for (
auto &Val :
Record) {
7237 assert(!(Val >> 32) &&
"Unexpected high bits set");
7245 return error(
"Invalid record");
7249 VSTOffset =
Record[0] - 1;
7260 std::tie(
Name, GVRecord) = readNameFromStrtab(
Record);
7261 if (GVRecord.
size() <= 3)
7262 return error(
"Invalid record");
7266 ValueIdToLinkageMap[ValueId++] =
Linkage;
7270 setValueGUID(ValueId++,
Name, Linkage, SourceFileName);
7280std::vector<ValueInfo>
7282 std::vector<ValueInfo>
Ret;
7285 Ret.push_back(std::get<0>(getValueInfoFromValueId(RefValueId)));
7289std::vector<FunctionSummary::EdgeTy>
7291 bool IsOldProfileFormat,
7292 bool HasProfile,
bool HasRelBF) {
7293 std::vector<FunctionSummary::EdgeTy>
Ret;
7295 for (
unsigned I = 0, E =
Record.size();
I != E; ++
I) {
7297 bool HasTailCall =
false;
7300 if (IsOldProfileFormat) {
7304 }
else if (HasProfile)
7305 std::tie(Hotness, HasTailCall) =
7338 static_cast<size_t>(
Record[Slot + 1])};
7361 while (Slot <
Record.size())
7365std::vector<FunctionSummary::ParamAccess>
7367 auto ReadRange = [&]() {
7369 BitcodeReader::decodeSignRotatedValue(
Record.front()));
7372 BitcodeReader::decodeSignRotatedValue(
Record.front()));
7380 std::vector<FunctionSummary::ParamAccess> PendingParamAccesses;
7381 while (!
Record.empty()) {
7382 PendingParamAccesses.emplace_back();
7386 ParamAccess.
Use = ReadRange();
7389 for (
auto &Call : ParamAccess.
Calls) {
7392 Call.Callee = std::get<0>(getValueInfoFromValueId(
Record.front()));
7394 Call.Offsets = ReadRange();
7397 return PendingParamAccesses;
7400void ModuleSummaryIndexBitcodeReader::parseTypeIdCompatibleVtableInfo(
7408void ModuleSummaryIndexBitcodeReader::parseTypeIdCompatibleVtableSummaryRecord(
7414 static_cast<size_t>(
Record[Slot + 1])});
7417 while (Slot <
Record.size())
7418 parseTypeIdCompatibleVtableInfo(
Record, Slot, TypeId);
7424 assert(ROCnt + WOCnt <= Refs.size());
7425 unsigned FirstWORef = Refs.size() - WOCnt;
7426 unsigned RefNo = FirstWORef - ROCnt;
7427 for (; RefNo < FirstWORef; ++RefNo)
7428 Refs[RefNo].setReadOnly();
7429 for (; RefNo < Refs.size(); ++RefNo)
7430 Refs[RefNo].setWriteOnly();
7435Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(
unsigned ID) {
7436 if (
Error Err = Stream.EnterSubBlock(
ID))
7448 return error(
"Invalid Summary Block: record for version expected");
7453 return error(
"Invalid Summary Block: version expected");
7456 const bool IsOldProfileFormat =
Version == 1;
7458 return error(
"Invalid summary version " +
Twine(Version) +
7459 ". Version should be in the range [1-" +
7472 std::vector<GlobalValue::GUID> PendingTypeTests;
7473 std::vector<FunctionSummary::VFuncId> PendingTypeTestAssumeVCalls,
7474 PendingTypeCheckedLoadVCalls;
7475 std::vector<FunctionSummary::ConstVCall> PendingTypeTestAssumeConstVCalls,
7476 PendingTypeCheckedLoadConstVCalls;
7477 std::vector<FunctionSummary::ParamAccess> PendingParamAccesses;
7479 std::vector<CallsiteInfo> PendingCallsites;
7480 std::vector<AllocInfo> PendingAllocs;
7488 switch (Entry.Kind) {
7491 return error(
"Malformed block");
7510 switch (
unsigned BitCode = MaybeBitCode.
get()) {
7520 ValueIdToValueInfoMap[ValueID] = std::make_tuple(
7536 unsigned ValueID =
Record[0];
7538 unsigned InstCount =
Record[2];
7540 unsigned NumRefs =
Record[3];
7541 unsigned NumRORefs = 0, NumWORefs = 0;
7542 int RefListStartIndex = 4;
7546 RefListStartIndex = 5;
7549 RefListStartIndex = 6;
7552 RefListStartIndex = 7;
7563 int CallGraphEdgeStartIndex = RefListStartIndex + NumRefs;
7565 "Record size inconsistent with number of references");
7566 std::vector<ValueInfo> Refs = makeRefList(
7570 std::vector<FunctionSummary::EdgeTy> Calls = makeCallList(
7572 IsOldProfileFormat, HasProfile, HasRelBF);
7574 auto VIAndOriginalGUID = getValueInfoFromValueId(ValueID);
7581 !IsPrevailing(std::get<2>(VIAndOriginalGUID))) {
7582 PendingCallsites.clear();
7583 PendingAllocs.clear();
7585 auto FS = std::make_unique<FunctionSummary>(
7587 std::move(Refs), std::move(Calls), std::move(PendingTypeTests),
7588 std::move(PendingTypeTestAssumeVCalls),
7589 std::move(PendingTypeCheckedLoadVCalls),
7590 std::move(PendingTypeTestAssumeConstVCalls),
7591 std::move(PendingTypeCheckedLoadConstVCalls),
7592 std::move(PendingParamAccesses), std::move(PendingCallsites),
7593 std::move(PendingAllocs));
7594 FS->setModulePath(getThisModule()->first());
7595 FS->setOriginalName(std::get<1>(VIAndOriginalGUID));
7604 unsigned ValueID =
Record[0];
7606 unsigned AliaseeID =
Record[2];
7608 auto AS = std::make_unique<AliasSummary>(Flags);
7614 AS->setModulePath(getThisModule()->first());
7616 auto AliaseeVI = std::get<0>(getValueInfoFromValueId(AliaseeID));
7618 if (!AliaseeInModule)
7619 return error(
"Alias expects aliasee summary to be parsed");
7620 AS->setAliasee(AliaseeVI, AliaseeInModule);
7622 auto GUID = getValueInfoFromValueId(ValueID);
7623 AS->setOriginalName(std::get<1>(GUID));
7629 unsigned ValueID =
Record[0];
7631 unsigned RefArrayStart = 2;
7641 std::vector<ValueInfo> Refs =
7644 std::make_unique<GlobalVarSummary>(Flags, GVF, std::move(Refs));
7645 FS->setModulePath(getThisModule()->first());
7646 auto GUID = getValueInfoFromValueId(ValueID);
7647 FS->setOriginalName(std::get<1>(GUID));
7655 unsigned ValueID =
Record[0];
7658 unsigned NumRefs =
Record[3];
7659 unsigned RefListStartIndex = 4;
7660 unsigned VTableListStartIndex = RefListStartIndex + NumRefs;
7662 std::vector<ValueInfo> Refs = makeRefList(
7665 for (
unsigned I = VTableListStartIndex, E =
Record.size();
I != E; ++
I) {
7671 std::make_unique<GlobalVarSummary>(Flags, GVF, std::move(Refs));
7672 VS->setModulePath(getThisModule()->first());
7673 VS->setVTableFuncs(VTableFuncs);
7674 auto GUID = getValueInfoFromValueId(ValueID);
7675 VS->setOriginalName(std::get<1>(GUID));
7687 unsigned ValueID =
Record[0];
7690 unsigned InstCount =
Record[3];
7693 unsigned NumRefs =
Record[4];
7694 unsigned NumRORefs = 0, NumWORefs = 0;
7695 int RefListStartIndex = 5;
7699 RefListStartIndex = 6;
7700 size_t NumRefsIndex = 5;
7702 unsigned NumRORefsOffset = 1;
7703 RefListStartIndex = 7;
7707 RefListStartIndex = 8;
7709 RefListStartIndex = 9;
7711 NumRORefsOffset = 2;
7714 NumRORefs =
Record[RefListStartIndex - NumRORefsOffset];
7716 NumRefs =
Record[NumRefsIndex];
7720 int CallGraphEdgeStartIndex = RefListStartIndex + NumRefs;
7722 "Record size inconsistent with number of references");
7723 std::vector<ValueInfo> Refs = makeRefList(
7726 std::vector<FunctionSummary::EdgeTy> Edges = makeCallList(
7728 IsOldProfileFormat, HasProfile,
false);
7729 ValueInfo VI = std::get<0>(getValueInfoFromValueId(ValueID));
7731 auto FS = std::make_unique<FunctionSummary>(
7733 std::move(Refs), std::move(Edges), std::move(PendingTypeTests),
7734 std::move(PendingTypeTestAssumeVCalls),
7735 std::move(PendingTypeCheckedLoadVCalls),
7736 std::move(PendingTypeTestAssumeConstVCalls),
7737 std::move(PendingTypeCheckedLoadConstVCalls),
7738 std::move(PendingParamAccesses), std::move(PendingCallsites),
7739 std::move(PendingAllocs));
7740 LastSeenSummary =
FS.get();
7741 LastSeenGUID =
VI.getGUID();
7742 FS->setModulePath(ModuleIdMap[ModuleId]);
7750 unsigned ValueID =
Record[0];
7753 unsigned AliaseeValueId =
Record[3];
7755 auto AS = std::make_unique<AliasSummary>(Flags);
7756 LastSeenSummary = AS.get();
7757 AS->setModulePath(ModuleIdMap[ModuleId]);
7759 auto AliaseeVI = std::get<0>(getValueInfoFromValueId(AliaseeValueId));
7761 AS->setAliasee(AliaseeVI, AliaseeInModule);
7763 ValueInfo VI = std::get<0>(getValueInfoFromValueId(ValueID));
7764 LastSeenGUID =
VI.getGUID();
7770 unsigned ValueID =
Record[0];
7773 unsigned RefArrayStart = 3;
7783 std::vector<ValueInfo> Refs =
7786 std::make_unique<GlobalVarSummary>(Flags, GVF, std::move(Refs));
7787 LastSeenSummary =
FS.get();
7788 FS->setModulePath(ModuleIdMap[ModuleId]);
7789 ValueInfo VI = std::get<0>(getValueInfoFromValueId(ValueID));
7790 LastSeenGUID =
VI.getGUID();
7797 if (!LastSeenSummary)
7798 return error(
"Name attachment that does not follow a combined record");
7802 LastSeenSummary =
nullptr;
7807 assert(PendingTypeTests.empty());
7812 assert(PendingTypeTestAssumeVCalls.empty());
7813 for (
unsigned I = 0;
I !=
Record.size();
I += 2)
7814 PendingTypeTestAssumeVCalls.push_back({Record[I], Record[I+1]});
7818 assert(PendingTypeCheckedLoadVCalls.empty());
7819 for (
unsigned I = 0;
I !=
Record.size();
I += 2)
7820 PendingTypeCheckedLoadVCalls.push_back({Record[I], Record[I+1]});
7824 PendingTypeTestAssumeConstVCalls.push_back(
7829 PendingTypeCheckedLoadConstVCalls.push_back(
7835 for (
unsigned I = 0;
I !=
Record.size();
I += 2)
7836 CfiFunctionDefs.insert(
7837 {Strtab.data() + Record[I], static_cast<size_t>(Record[I + 1])});
7843 for (
unsigned I = 0;
I !=
Record.size();
I += 2)
7844 CfiFunctionDecls.insert(
7845 {Strtab.data() + Record[I], static_cast<size_t>(Record[I + 1])});
7854 parseTypeIdCompatibleVtableSummaryRecord(
Record);
7862 PendingParamAccesses = parseParamAccesses(
Record);
7874 unsigned ValueID =
Record[0];
7876 for (
auto R =
Record.begin() + 1; R !=
Record.end(); R++) {
7877 assert(*R < StackIds.size());
7880 ValueInfo VI = std::get<0>(getValueInfoFromValueId(ValueID));
7881 PendingCallsites.push_back(
CallsiteInfo({
VI, std::move(StackIdList)}));
7886 auto RecordIter =
Record.begin();
7887 unsigned ValueID = *RecordIter++;
7888 unsigned NumStackIds = *RecordIter++;
7889 unsigned NumVersions = *RecordIter++;
7890 assert(
Record.size() == 3 + NumStackIds + NumVersions);
7892 for (
unsigned J = 0; J < NumStackIds; J++) {
7893 assert(*RecordIter < StackIds.size());
7898 for (
unsigned J = 0; J < NumVersions; J++)
7901 getValueInfoFromValueId</*AllowNullValueInfo*/ true>(ValueID));
7902 PendingCallsites.push_back(
7903 CallsiteInfo({
VI, std::move(Versions), std::move(StackIdList)}));
7909 std::vector<MIBInfo> MIBs;
7913 unsigned NumStackEntries =
Record[
I++];
7916 for (
unsigned J = 0; J < NumStackEntries; J++) {
7923 PendingAllocs.push_back(
AllocInfo(std::move(MIBs)));
7929 std::vector<MIBInfo> MIBs;
7930 unsigned NumMIBs =
Record[
I++];
7931 unsigned NumVersions =
Record[
I++];
7932 unsigned MIBsRead = 0;
7933 while (MIBsRead++ < NumMIBs) {
7936 unsigned NumStackEntries =
Record[
I++];
7939 for (
unsigned J = 0; J < NumStackEntries; J++) {
7948 for (
unsigned J = 0; J < NumVersions; J++)
7950 PendingAllocs.push_back(
7951 AllocInfo(std::move(Versions), std::move(MIBs)));
7961Error ModuleSummaryIndexBitcodeReader::parseModuleStringTable() {
7976 switch (Entry.Kind) {
7979 return error(
"Malformed block");
7991 switch (MaybeRecord.
get()) {
7999 return error(
"Invalid record");
8001 LastSeenModule = TheIndex.
addModule(ModulePath);
8002 ModuleIdMap[ModuleId] = LastSeenModule->
first();
8011 if (!LastSeenModule)
8012 return error(
"Invalid hash that does not follow a module path");
8014 for (
auto &Val :
Record) {
8015 assert(!(Val >> 32) &&
"Unexpected high bits set");
8016 LastSeenModule->
second[Pos++] = Val;
8019 LastSeenModule =
nullptr;
8032class BitcodeErrorCategoryType :
public std::error_category {
8033 const char *
name()
const noexcept
override {
8034 return "llvm.bitcode";
8037 std::string message(
int IE)
const override {
8040 case BitcodeError::CorruptedBitcode:
8041 return "Corrupted bitcode";
8050 static BitcodeErrorCategoryType ErrorCategory;
8051 return ErrorCategory;
8055 unsigned Block,
unsigned RecordID) {
8057 return std::move(Err);
8066 switch (Entry.Kind) {
8071 return error(
"Malformed block");
8075 return std::move(Err);
8085 if (MaybeRecord.
get() == RecordID)
8100 return FOrErr.takeError();
8101 return std::move(FOrErr->Mods);
8126 switch (Entry.Kind) {
8129 return error(
"Malformed block");
8132 uint64_t IdentificationBit = -1ull;
8136 return std::move(Err);
8142 Entry = MaybeEntry.
get();
8147 return error(
"Malformed block");
8153 return std::move(Err);
8172 if (!
I.Strtab.empty())
8179 if (!
F.Symtab.empty() &&
F.StrtabForSymtab.empty())
8180 F.StrtabForSymtab = *Strtab;
8196 if (
F.Symtab.empty())
8197 F.Symtab = *SymtabOrErr;
8202 return std::move(Err);
8207 return std::move(E);
8222BitcodeModule::getModuleImpl(
LLVMContext &Context,
bool MaterializeAll,
8223 bool ShouldLazyLoadMetadata,
bool IsImporting,
8227 std::string ProducerIdentification;
8228 if (IdentificationBit != -1ull) {
8229 if (
Error JumpFailed = Stream.JumpToBit(IdentificationBit))
8230 return std::move(JumpFailed);
8233 return std::move(E);
8236 if (
Error JumpFailed = Stream.JumpToBit(ModuleBit))
8237 return std::move(JumpFailed);
8238 auto *
R =
new BitcodeReader(std::move(Stream), Strtab, ProducerIdentification,
8241 std::unique_ptr<Module>
M =
8242 std::make_unique<Module>(ModuleIdentifier, Context);
8243 M->setMaterializer(R);
8246 if (
Error Err =
R->parseBitcodeInto(
M.get(), ShouldLazyLoadMetadata,
8247 IsImporting, Callbacks))
8248 return std::move(Err);
8250 if (MaterializeAll) {
8252 if (
Error Err =
M->materializeAll())
8253 return std::move(Err);
8256 if (
Error Err =
R->materializeForwardReferencedFunctions())
8257 return std::move(Err);
8260 return std::move(M);
8266 return getModuleImpl(
Context,
false, ShouldLazyLoadMetadata, IsImporting,
8281 ModuleSummaryIndexBitcodeReader R(std::move(Stream), Strtab, CombinedIndex,
8282 ModulePath, IsPrevailing);
8283 return R.parseModule();
8290 return std::move(JumpFailed);
8292 auto Index = std::make_unique<ModuleSummaryIndex>(
false);
8293 ModuleSummaryIndexBitcodeReader R(std::move(Stream), Strtab, *
Index,
8294 ModuleIdentifier, 0);
8296 if (
Error Err = R.parseModule())
8297 return std::move(Err);
8299 return std::move(
Index);
8307 return std::move(Err);
8312 std::pair<bool, bool> Result = {
false,
false};
8314 return std::move(E);
8316 switch (Entry.Kind) {
8319 return error(
"Malformed block");
8334 switch (MaybeBitCode.
get()) {
8340 assert(Flags <= 0x2ff &&
"Unexpected bits in flag");
8342 bool EnableSplitLTOUnit = Flags & 0x8;
8343 bool UnifiedLTO = Flags & 0x200;
8344 Result = {EnableSplitLTOUnit, UnifiedLTO};
8357 return std::move(JumpFailed);
8360 return std::move(Err);
8365 return std::move(E);
8367 switch (Entry.Kind) {
8369 return error(
"Malformed block");
8380 return Flags.takeError();
8392 return Flags.takeError();
8401 return std::move(Err);
8408 return StreamFailed.takeError();
8418 if (MsOrErr->size() != 1)
8419 return error(
"Expected a single module");
8421 return (*MsOrErr)[0];
8426 bool ShouldLazyLoadMetadata,
bool IsImporting,
8432 return BM->getLazyModule(
Context, ShouldLazyLoadMetadata, IsImporting,
8437 std::unique_ptr<MemoryBuffer> &&Buffer,
LLVMContext &Context,
8438 bool ShouldLazyLoadMetadata,
bool IsImporting,
ParserCallbacks Callbacks) {
8440 IsImporting, Callbacks);
8442 (*MOrErr)->setOwnedMemoryBuffer(std::move(Buffer));
8448 return getModuleImpl(
Context,
true,
false,
false, Callbacks);
8460 return BM->parseModule(
Context, Callbacks);
8493 return BM->readSummary(CombinedIndex, BM->getModuleIdentifier());
8502 return BM->getSummary();
8510 return BM->getLTOInfo();
8515 bool IgnoreEmptyThinLTOIndexFile) {
8520 if (IgnoreEmptyThinLTOIndexFile && !(*FileOrErr)->getBufferSize())
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static bool isConstant(const MachineInstr &MI)
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
Expand Atomic instructions
Atomic ordering constants.
This file contains the simple types necessary to represent the attributes associated with functions a...
static void getDecodedRelBFCallEdgeInfo(uint64_t RawFlags, uint64_t &RelBF, bool &HasTailCall)
static void upgradeDLLImportExportLinkage(GlobalValue *GV, unsigned Val)
static cl::opt< bool > PrintSummaryGUIDs("print-summary-global-ids", cl::init(false), cl::Hidden, cl::desc("Print the global id for each value when reading the module summary"))
static AtomicOrdering getDecodedOrdering(unsigned Val)
static std::pair< CalleeInfo::HotnessType, bool > getDecodedHotnessCallEdgeInfo(uint64_t RawFlags)
static FunctionSummary::FFlags getDecodedFFlags(uint64_t RawFlags)
static std::optional< CodeModel::Model > getDecodedCodeModel(unsigned Val)
cl::opt< cl::boolOrDefault > PreserveInputDbgFormat
static bool getDecodedDSOLocal(unsigned Val)
static bool convertToString(ArrayRef< uint64_t > Record, unsigned Idx, StrTy &Result)
Convert a string from a record into an std::string, return true on failure.
static GlobalVariable::UnnamedAddr getDecodedUnnamedAddrType(unsigned Val)
static void stripTBAA(Module *M)
static Expected< std::pair< bool, bool > > getEnableSplitLTOUnitAndUnifiedFlag(BitstreamCursor &Stream, unsigned ID, BitcodeLTOInfo <OInfo)
static int getDecodedUnaryOpcode(unsigned Val, Type *Ty)
static Expected< std::string > readTriple(BitstreamCursor &Stream)
static void parseWholeProgramDevirtResolutionByArg(ArrayRef< uint64_t > Record, size_t &Slot, WholeProgramDevirtResolution &Wpd)
static uint64_t getRawAttributeMask(Attribute::AttrKind Val)
static GlobalValueSummary::GVFlags getDecodedGVSummaryFlags(uint64_t RawFlags, uint64_t Version)
static void setSpecialRefs(std::vector< ValueInfo > &Refs, unsigned ROCnt, unsigned WOCnt)
static GlobalVarSummary::GVarFlags getDecodedGVarFlags(uint64_t RawFlags)
static Attribute::AttrKind getAttrFromCode(uint64_t Code)
static Expected< uint64_t > jumpToValueSymbolTable(uint64_t Offset, BitstreamCursor &Stream)
Helper to note and return the current location, and jump to the given offset.
static Expected< bool > hasObjCCategoryInModule(BitstreamCursor &Stream)
static GlobalValue::DLLStorageClassTypes getDecodedDLLStorageClass(unsigned Val)
static void decodeLLVMAttributesForBitcode(AttrBuilder &B, uint64_t EncodedAttrs, uint64_t AttrIdx)
This fills an AttrBuilder object with the LLVM attributes that have been decoded from the given integ...
cl::opt< bool > WriteNewDbgInfoFormat
static void parseTypeIdSummaryRecord(ArrayRef< uint64_t > Record, StringRef Strtab, ModuleSummaryIndex &TheIndex)
cl::opt< cl::boolOrDefault > LoadBitcodeIntoNewDbgInfoFormat("load-bitcode-into-experimental-debuginfo-iterators", cl::Hidden, cl::desc("Load bitcode directly into the new debug info format (regardless " "of input format)"))
Load bitcode directly into RemoveDIs format (use debug records instead of debug intrinsics).
static void addRawAttributeValue(AttrBuilder &B, uint64_t Val)
bool WriteNewDbgInfoFormatToBitcode
static Comdat::SelectionKind getDecodedComdatSelectionKind(unsigned Val)
static bool hasImplicitComdat(size_t Val)
static GlobalValue::LinkageTypes getDecodedLinkage(unsigned Val)
static Error hasInvalidBitcodeHeader(BitstreamCursor &Stream)
static Expected< std::string > readIdentificationCode(BitstreamCursor &Stream)
static int getDecodedBinaryOpcode(unsigned Val, Type *Ty)
static AtomicRMWInst::BinOp getDecodedRMWOperation(unsigned Val)
static Expected< BitcodeModule > getSingleModule(MemoryBufferRef Buffer)
static Expected< bool > hasObjCCategory(BitstreamCursor &Stream)
static GlobalVariable::ThreadLocalMode getDecodedThreadLocalMode(unsigned Val)
static void parseWholeProgramDevirtResolution(ArrayRef< uint64_t > Record, StringRef Strtab, size_t &Slot, TypeIdSummary &TypeId)
static void inferDSOLocal(GlobalValue *GV)
static FastMathFlags getDecodedFastMathFlags(unsigned Val)
GlobalValue::SanitizerMetadata deserializeSanitizerMetadata(unsigned V)
static Expected< BitstreamCursor > initStream(MemoryBufferRef Buffer)
static cl::opt< bool > ExpandConstantExprs("expand-constant-exprs", cl::Hidden, cl::desc("Expand constant expressions to instructions for testing purposes"))
static bool upgradeOldMemoryAttribute(MemoryEffects &ME, uint64_t EncodedKind)
static Expected< StringRef > readBlobInRecord(BitstreamCursor &Stream, unsigned Block, unsigned RecordID)
static Expected< std::string > readIdentificationBlock(BitstreamCursor &Stream)
Read the "IDENTIFICATION_BLOCK_ID" block, do some basic enforcement on the "epoch" encoded in the bit...
static bool isConstExprSupported(const BitcodeConstant *BC)
static int getDecodedCastOpcode(unsigned Val)
static Expected< std::string > readModuleTriple(BitstreamCursor &Stream)
static GlobalValue::VisibilityTypes getDecodedVisibility(unsigned Val)
BlockVerifier::State From
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
Analysis containing CSE Info
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static StringRef getOpcodeName(uint8_t Opcode, uint8_t OpcodeBase)
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
Looks at all the uses of the given value Returns the Liveness deduced from the uses of this value Adds all uses that cause the result to be MaybeLive to MaybeLiveRetUses If the result is Live
This file defines the DenseMap class.
Provides ErrorOr<T> smart pointer.
This file contains the declaration of the GlobalIFunc class, which represents a single indirect funct...
static bool InRange(int64_t Value, unsigned short Shift, int LBound, int HBound)
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
Module.h This file contains the declarations for the Module class.
PowerPC Reduce CR logical Operation
llvm::cl::opt< bool > UseNewDbgInfoFormat
const SmallVectorImpl< MachineOperand > & Cond
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static uint64_t decodeSignRotatedValue(uint64_t V)
Decode a signed value stored with the sign bit in the LSB for dense VBR encoding.
This file defines the SmallString class.
This file defines the SmallVector class.
Class for arbitrary precision integers.
an instruction to allocate memory on the stack
void setSwiftError(bool V)
Specify whether this alloca is used to represent a swifterror.
PointerType * getType() const
Overload to return most specific pointer type.
void setUsedWithInAlloca(bool V)
Specify whether this alloca is used to represent the arguments to a call.
This class represents an incoming formal argument to a Function.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
An instruction that atomically checks whether a specified value is in a memory location,...
static bool isValidFailureOrdering(AtomicOrdering Ordering)
static AtomicOrdering getStrongestFailureOrdering(AtomicOrdering SuccessOrdering)
Returns the strongest permitted ordering on failure, given the desired ordering on success.
static bool isValidSuccessOrdering(AtomicOrdering Ordering)
an instruction that atomically reads a memory location, combines it with another value,...
BinOp
This enumeration lists the possible modifications atomicrmw can make.
@ Min
*p = old <signed v ? old : v
@ UIncWrap
Increment one up to a maximum value.
@ Max
*p = old >signed v ? old : v
@ UMin
*p = old <unsigned v ? old : v
@ FMin
*p = minnum(old, v) minnum matches the behavior of llvm.minnum.
@ UMax
*p = old >unsigned v ? old : v
@ FMax
*p = maxnum(old, v) maxnum matches the behavior of llvm.maxnum.
@ UDecWrap
Decrement one until a minimum value or zero.
AttributeSet getFnAttrs() const
The function attributes are returned.
static AttributeList get(LLVMContext &C, ArrayRef< std::pair< unsigned, Attribute > > Attrs)
Create an AttributeList with the specified parameters in it.
static Attribute getWithStructRetType(LLVMContext &Context, Type *Ty)
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
static bool isTypeAttrKind(AttrKind Kind)
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
@ TombstoneKey
Use as Tombstone key for DenseMap of AttrKind.
@ None
No attributes have been set.
@ EmptyKey
Use as Empty key for DenseMap of AttrKind.
@ EndAttrKinds
Sentinel value useful for loops.
static bool isConstantRangeAttrKind(AttrKind Kind)
static Attribute getWithInAllocaType(LLVMContext &Context, Type *Ty)
static bool isIntAttrKind(AttrKind Kind)
static Attribute getWithByValType(LLVMContext &Context, Type *Ty)
static bool isEnumAttrKind(AttrKind Kind)
LLVM Basic Block Representation.
void insertDbgRecordBefore(DbgRecord *DR, InstListType::iterator Here)
Insert a DbgRecord into a block at the position given by Here.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
void replacePhiUsesWith(BasicBlock *Old, BasicBlock *New)
Update all phi nodes in this basic block to refer to basic block New instead of basic block Old.
SymbolTableList< BasicBlock >::iterator eraseFromParent()
Unlink 'this' from the containing function and delete it.
void moveBefore(BasicBlock *MovePos)
Unlink this basic block from its current function and insert it into the function that MovePos lives ...
const Instruction & back() const
static BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name, BasicBlock::iterator InsertBefore)
Construct a binary instruction, given the opcode and the two operands.
Represents a module in a bitcode file.
Expected< std::unique_ptr< ModuleSummaryIndex > > getSummary()
Parse the specified bitcode buffer, returning the module summary index.
Expected< BitcodeLTOInfo > getLTOInfo()
Returns information about the module to be used for LTO: whether to compile with ThinLTO,...
Error readSummary(ModuleSummaryIndex &CombinedIndex, StringRef ModulePath, std::function< bool(GlobalValue::GUID)> IsPrevailing=nullptr)
Parse the specified bitcode buffer and merge its module summary index into CombinedIndex.
Expected< std::unique_ptr< Module > > parseModule(LLVMContext &Context, ParserCallbacks Callbacks={})
Read the entire bitcode module and return it.
Expected< std::unique_ptr< Module > > getLazyModule(LLVMContext &Context, bool ShouldLazyLoadMetadata, bool IsImporting, ParserCallbacks Callbacks={})
Read the bitcode module and prepare for lazy deserialization of function bodies.
Value * getValueFwdRef(unsigned Idx, Type *Ty, unsigned TyID, BasicBlock *ConstExprInsertBB)
void push_back(Value *V, unsigned TypeID)
void replaceValueWithoutRAUW(unsigned ValNo, Value *NewV)
Error assignValue(unsigned Idx, Value *V, unsigned TypeID)
void shrinkTo(unsigned N)
unsigned getTypeID(unsigned ValNo) const
This class maintains the abbreviations read from a block info block.
This represents a position within a bitcode file, implemented on top of a SimpleBitstreamCursor.
Error JumpToBit(uint64_t BitNo)
Reset the stream to the specified bit number.
uint64_t GetCurrentBitNo() const
Return the bit # of the bit we are reading.
ArrayRef< uint8_t > getBitcodeBytes() const
Expected< word_t > Read(unsigned NumBits)
Expected< BitstreamEntry > advance(unsigned Flags=0)
Advance the current bitstream, returning the next entry in the stream.
Expected< BitstreamEntry > advanceSkippingSubblocks(unsigned Flags=0)
This is a convenience function for clients that don't expect any subblocks.
void setBlockInfo(BitstreamBlockInfo *BI)
Set the block info to be used by this BitstreamCursor to interpret abbreviated records.
Expected< unsigned > readRecord(unsigned AbbrevID, SmallVectorImpl< uint64_t > &Vals, StringRef *Blob=nullptr)
Error EnterSubBlock(unsigned BlockID, unsigned *NumWordsP=nullptr)
Having read the ENTER_SUBBLOCK abbrevid, and enter the block.
Error SkipBlock()
Having read the ENTER_SUBBLOCK abbrevid and a BlockID, skip over the body of this block.
Expected< unsigned > skipRecord(unsigned AbbrevID)
Read the current record and discard it, returning the code for the record.
uint64_t getCurrentByteNo() const
bool canSkipToPos(size_t pos) const
static BlockAddress * get(Function *F, BasicBlock *BB)
Return a BlockAddress for the specified function and basic block.
Conditional or Unconditional Branch instruction.
static BranchInst * Create(BasicBlock *IfTrue, BasicBlock::iterator InsertBefore)
Allocate memory in an ever growing pool, as if by bump-pointer.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
bool isInlineAsm() const
Check if this call is an inline asm statement.
Value * getCalledOperand() const
void setAttributes(AttributeList A)
Set the parameter attributes for this call.
Intrinsic::ID getIntrinsicID() const
Returns the intrinsic ID of the intrinsic called or Intrinsic::not_intrinsic if the called function i...
unsigned arg_size() const
AttributeList getAttributes() const
Return the parameter attributes for this call.
static CallBrInst * Create(FunctionType *Ty, Value *Func, BasicBlock *DefaultDest, ArrayRef< BasicBlock * > IndirectDests, ArrayRef< Value * > Args, const Twine &NameStr, BasicBlock::iterator InsertBefore)
This class represents a function call, abstracting a target machine's calling convention.
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr, BasicBlock::iterator InsertBefore)
static CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name, BasicBlock::iterator InsertBefore)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
static bool castIsValid(Instruction::CastOps op, Type *SrcTy, Type *DstTy)
This method can be used to determine if a cast from SrcTy to DstTy using Opcode op is valid or not.
static CatchPadInst * Create(Value *CatchSwitch, ArrayRef< Value * > Args, const Twine &NameStr, BasicBlock::iterator InsertBefore)
static CatchReturnInst * Create(Value *CatchPad, BasicBlock *BB, BasicBlock::iterator InsertBefore)
static CatchSwitchInst * Create(Value *ParentPad, BasicBlock *UnwindDest, unsigned NumHandlers, const Twine &NameStr, BasicBlock::iterator InsertBefore)
static CleanupPadInst * Create(Value *ParentPad, ArrayRef< Value * > Args, const Twine &NameStr, BasicBlock::iterator InsertBefore)
static CleanupReturnInst * Create(Value *CleanupPad, BasicBlock *UnwindBB, BasicBlock::iterator InsertBefore)
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
bool isFPPredicate() const
static CmpInst * Create(OtherOps Op, Predicate Pred, Value *S1, Value *S2, const Twine &Name, BasicBlock::iterator InsertBefore)
Construct a compare instruction, given the opcode, the predicate and the two operands.
bool isIntPredicate() const
@ Largest
The linker will choose the largest COMDAT.
@ SameSize
The data referenced by the COMDAT must be the same size.
@ Any
The linker may choose any COMDAT.
@ NoDeduplicate
No deduplication is performed.
@ ExactMatch
The data referenced by the COMDAT must be the same.
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
static Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true)
This method constructs a CDS and initializes it with a text string.
static Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
static Constant * getFP(Type *ElementType, ArrayRef< uint16_t > Elts)
getFP() constructors - Return a constant of array type with a float element type taken from argument ...
static Constant * get(LLVMContext &Context, ArrayRef< uint8_t > Elts)
get() constructors - Return a constant with vector type with an element count and element type matchi...
static Constant * getFP(Type *ElementType, ArrayRef< uint16_t > Elts)
getFP() constructors - Return a constant of vector type with a float element type taken from argument...
static Constant * getExtractElement(Constant *Vec, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
static Constant * getInsertElement(Constant *Vec, Constant *Elt, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList, bool InBounds=false, std::optional< ConstantRange > InRange=std::nullopt, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
static Constant * getShuffleVector(Constant *V1, Constant *V2, ArrayRef< int > Mask, Type *OnlyIfReducedTy=nullptr)
static bool isSupportedGetElementPtr(const Type *SrcElemTy)
Whether creating a constant expression for this getelementptr type is supported.
static Constant * get(unsigned Opcode, Constant *C1, Constant *C2, unsigned Flags=0, Type *OnlyIfReducedTy=nullptr)
get - Return a binary or shift operator constant expression, folding if possible.
static bool isSupportedBinOp(unsigned Opcode)
Whether creating a constant expression for this binary operator is supported.
static bool isSupportedCastOp(unsigned Opcode)
Whether creating a constant expression for this cast is supported.
static Constant * getCompare(unsigned short pred, Constant *C1, Constant *C2, bool OnlyIfReduced=false)
Return an ICmp or FCmp comparison operator constant expression.
This is the shared class of boolean and integer constants.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
This class represents a range of values.
static Constant * get(StructType *T, ArrayRef< Constant * > V)
static Constant * get(ArrayRef< Constant * > V)
This is an important base class in LLVM.
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
static DSOLocalEquivalent * get(GlobalValue *GV)
Return a DSOLocalEquivalent for the specified global value.
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
static Expected< DataLayout > parse(StringRef LayoutDescription)
Parse a data layout string and return the layout.
Records a position in IR for a source label (DILabel).
Record of a variable value-assignment, aka a non instruction representation of the dbg....
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
iterator find(const_arg_type_t< KeyT > Val)
bool erase(const KeyT &Val)
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Implements a dense probed hash-table based set.
Base class for error info classes.
virtual std::string message() const
Return the error message as a string.
virtual std::error_code convertToErrorCode() const =0
Convert this error to a std::error_code.
Represents either an error or a value T.
std::error_code getError() const
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
reference get()
Returns a reference to the stored T value.
This instruction compares its operands according to the predicate given to the constructor.
Convenience struct for specifying and reasoning about fast-math flags.
void setFast(bool B=true)
void setAllowContract(bool B=true)
void setAllowReciprocal(bool B=true)
void setNoSignedZeros(bool B=true)
void setNoNaNs(bool B=true)
void setAllowReassoc(bool B=true)
Flag setters.
void setApproxFunc(bool B=true)
void setNoInfs(bool B=true)
An instruction for ordering other memory operations.
This class represents a freeze function that returns random concrete value if an operand is either a ...
std::pair< ValueInfo, CalleeInfo > EdgeTy
<CalleeValueInfo, CalleeInfo> call edge pair.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
BasicBlockListType::iterator iterator
const BasicBlock & back() const
virtual void setStripDebugInfo()=0
virtual Error materializeModule()=0
Make sure the entire Module has been completely read.
virtual Error materializeMetadata()=0
virtual Error materialize(GlobalValue *GV)=0
Make sure the given GlobalValue is fully read.
virtual std::vector< StructType * > getIdentifiedStructTypes() const =0
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr, BasicBlock::iterator InsertBefore)
static GlobalAlias * create(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name, Constant *Aliasee, Module *Parent)
If a parent module is specified, the alias is automatically inserted into the end of the specified mo...
static GlobalIFunc * create(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name, Constant *Resolver, Module *Parent)
If a parent module is specified, the ifunc is automatically inserted into the end of the specified mo...
void setAlignment(Align Align)
Sets the alignment attribute of the GlobalObject.
void setComdat(Comdat *C)
void setSection(StringRef S)
Change the section for this global.
Function and variable summary information to aid decisions and implementation of importing.
void setOriginalName(GlobalValue::GUID Name)
Initialize the original name hash in this summary.
static bool isLocalLinkage(LinkageTypes Linkage)
void setUnnamedAddr(UnnamedAddr Val)
bool hasLocalLinkage() const
bool hasDefaultVisibility() const
void setDLLStorageClass(DLLStorageClassTypes C)
void setThreadLocalMode(ThreadLocalMode Val)
bool hasExternalWeakLinkage() const
DLLStorageClassTypes
Storage classes of global values for PE targets.
@ DLLExportStorageClass
Function to be accessible from DLL.
@ DLLImportStorageClass
Function to be imported from DLL.
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
void setDSOLocal(bool Local)
PointerType * getType() const
Global values are always pointers.
VisibilityTypes
An enumeration for the kinds of visibility of global values.
@ DefaultVisibility
The GV is visible.
@ HiddenVisibility
The GV is hidden.
@ ProtectedVisibility
The GV is protected.
void setVisibility(VisibilityTypes V)
void setSanitizerMetadata(SanitizerMetadata Meta)
std::string getGlobalIdentifier() const
Return the modified name for this global value suitable to be used as the key for a global lookup (e....
LinkageTypes
An enumeration for the kinds of linkage for global values.
@ PrivateLinkage
Like Internal, but omit from symbol table.
@ CommonLinkage
Tentative definitions.
@ InternalLinkage
Rename collisions when linking (static functions).
@ LinkOnceAnyLinkage
Keep one copy of function when linking (inline)
@ WeakODRLinkage
Same, but only replaced by something equivalent.
@ ExternalLinkage
Externally visible function.
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
@ AppendingLinkage
Special purpose, only applies to global arrays.
@ AvailableExternallyLinkage
Available for inspection, not emission.
@ ExternalWeakLinkage
ExternalWeak linkage description.
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
void setPartition(StringRef Part)
void setAttributes(AttributeSet A)
Set attribute list for this global.
void setCodeModel(CodeModel::Model CM)
Change the code model for this global.
This instruction compares its operands according to the predicate given to the constructor.
Indirect Branch Instruction.
void addDestination(BasicBlock *Dest)
Add a destination.
static IndirectBrInst * Create(Value *Address, unsigned NumDests, BasicBlock::iterator InsertBefore)
unsigned getNumDestinations() const
return the number of possible destinations in this indirectbr instruction.
static InlineAsm * get(FunctionType *Ty, StringRef AsmString, StringRef Constraints, bool hasSideEffects, bool isAlignStack=false, AsmDialect asmDialect=AD_ATT, bool canThrow=false)
InlineAsm::get - Return the specified uniqued inline asm string.
std::vector< ConstraintInfo > ConstraintInfoVector
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr, BasicBlock::iterator InsertBefore)
static InsertValueInst * Create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &NameStr, BasicBlock::iterator InsertBefore)
const BasicBlock * getParent() const
const char * getOpcodeName() const
InstListType::iterator insertInto(BasicBlock *ParentBB, InstListType::iterator It)
Inserts an unlinked instruction into ParentBB at position It and returns the iterator of the inserted...
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
@ MIN_INT_BITS
Minimum number of bits that can be specified.
@ MAX_INT_BITS
Maximum number of bits that can be specified.
static InvokeInst * Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, const Twine &NameStr, BasicBlock::iterator InsertBefore)
This is an important class for using LLVM in a threaded context.
SyncScope::ID getOrInsertSyncScopeID(StringRef SSN)
getOrInsertSyncScopeID - Maps synchronization scope name to synchronization scope ID.
void emitError(uint64_t LocCookie, const Twine &ErrorStr)
emitError - Emit an error message to the currently installed error handler with optional location inf...
The landingpad instruction holds all of the information necessary to generate correct exception handl...
void addClause(Constant *ClauseVal)
Add a catch or filter clause to the landing pad.
void setCleanup(bool V)
Indicate that this landingpad instruction is a cleanup.
static LandingPadInst * Create(Type *RetTy, unsigned NumReservedClauses, const Twine &NameStr, BasicBlock::iterator InsertBefore)
Constructors - NumReservedClauses is a hint for the number of incoming clauses that this landingpad w...
An instruction for reading from memory.
Tracking metadata reference owned by Metadata.
StringRef getString() const
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
ValueT lookup(const KeyT &Key) const
size_t getBufferSize() const
StringRef getBufferIdentifier() const
const char * getBufferStart() const
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFileOrSTDIN(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, std::optional< Align > Alignment=std::nullopt)
Open the specified file as a MemoryBuffer, or open stdin if the Filename is "-".
static MemoryEffectsBase readOnly()
Create MemoryEffectsBase that can read any memory.
static MemoryEffectsBase argMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
Create MemoryEffectsBase that can only access argument memory.
static MemoryEffectsBase inaccessibleMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
Create MemoryEffectsBase that can only access inaccessible memory.
static MemoryEffectsBase createFromIntValue(uint32_t Data)
Create MemoryEffectsBase from an encoded integer value (used by memory attribute).
static MemoryEffectsBase writeOnly()
Create MemoryEffectsBase that can write any memory.
static MemoryEffectsBase inaccessibleOrArgMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
Create MemoryEffectsBase that can only access inaccessible or argument memory.
static MemoryEffectsBase none()
Create MemoryEffectsBase that cannot read or write any memory.
static MemoryEffectsBase unknown()
Create MemoryEffectsBase that can read and write any memory.
Class to hold module path string table and global value map, and encapsulate methods for operating on...
std::set< std::string > & cfiFunctionDecls()
TypeIdSummary & getOrInsertTypeIdSummary(StringRef TypeId)
Return an existing or new TypeIdSummary entry for TypeId.
ValueInfo getOrInsertValueInfo(GlobalValue::GUID GUID)
Return a ValueInfo for GUID.
StringRef saveString(StringRef String)
void setFlags(uint64_t Flags)
void addBlockCount(uint64_t C)
ModuleInfo * addModule(StringRef ModPath, ModuleHash Hash=ModuleHash{{0}})
Add a new module with the given Hash, mapped to the given ModID, and return a reference to the module...
void addGlobalValueSummary(const GlobalValue &GV, std::unique_ptr< GlobalValueSummary > Summary)
Add a global value summary for a value.
static constexpr uint64_t BitcodeSummaryVersion
GlobalValueSummary * findSummaryInModule(ValueInfo VI, StringRef ModuleId) const
Find the summary for ValueInfo VI in module ModuleId, or nullptr if not found.
unsigned addOrGetStackIdIndex(uint64_t StackId)
std::set< std::string > & cfiFunctionDefs()
ModuleInfo * getModule(StringRef ModPath)
Return module entry for module with the given ModPath.
void addOriginalName(GlobalValue::GUID ValueGUID, GlobalValue::GUID OrigGUID)
Add an original name for the value of the given GUID.
TypeIdCompatibleVtableInfo & getOrInsertTypeIdCompatibleVtableSummary(StringRef TypeId)
Return an existing or new TypeIdCompatibleVtableMap entry for TypeId.
A Module instance is used to store all the information related to an LLVM module.
NamedMDNode * getNamedMetadata(const Twine &Name) const
Return the first NamedMDNode in the module with the specified name.
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
NamedMDNode * getOrInsertNamedMetadata(StringRef Name)
Return the named MDNode in the module with the specified name.
Comdat * getOrInsertComdat(StringRef Name)
Return the Comdat in the module with the specified name.
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
void addOperand(MDNode *M)
static NoCFIValue * get(GlobalValue *GV)
Return a NoCFIValue for the specified function.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr, BasicBlock::iterator InsertBefore)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
static ResumeInst * Create(Value *Exn, BasicBlock::iterator InsertBefore)
static ReturnInst * Create(LLVMContext &C, Value *retVal, BasicBlock::iterator InsertBefore)
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr, BasicBlock::iterator InsertBefore, Instruction *MDFrom=nullptr)
This instruction constructs a fixed permutation of two input vectors.
ArrayRef< int > getShuffleMask() const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
StringRef str() const
Explicit conversion to StringRef.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
iterator erase(const_iterator CI)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Class to represent struct types.
static StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
void setBody(ArrayRef< Type * > Elements, bool isPacked=false)
Specify a body for an opaque identified type.
static StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
void setName(StringRef Name)
Change the name of this type to the specified name, or to a name with a suffix if there is a collisio...
static SwitchInst * Create(Value *Value, BasicBlock *Default, unsigned NumCases, BasicBlock::iterator InsertBefore)
Verify that the TBAA Metadatas are valid.
bool visitTBAAMetadata(Instruction &I, const MDNode *MD)
Visit an instruction and return true if it is valid, return false if an invalid TBAA is attached.
static TargetExtType * get(LLVMContext &Context, StringRef Name, ArrayRef< Type * > Types=std::nullopt, ArrayRef< unsigned > Ints=std::nullopt)
Return a target extension type having the specified name and optional type and integer parameters.
@ HasZeroInit
zeroinitializer is valid for this target extension type.
See the file comment for details on the usage of the TrailingObjects type.
TrailingObjects()=default
Triple - Helper class for working with autoconf configuration names.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
std::string str() const
Return the twine contents as a std::string.
The instances of the Type class are immutable: once they are created, they are never changed.
static Type * getHalfTy(LLVMContext &C)
Type * getStructElementType(unsigned N) const
static Type * getDoubleTy(LLVMContext &C)
bool isVectorTy() const
True if this is an instance of VectorType.
bool isArrayTy() const
True if this is an instance of ArrayType.
static Type * getX86_FP80Ty(LLVMContext &C)
bool isLabelTy() const
Return true if this is 'label'.
static Type * getBFloatTy(LLVMContext &C)
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
bool isPointerTy() const
True if this is an instance of PointerType.
static IntegerType * getInt1Ty(LLVMContext &C)
Type * getArrayElementType() const
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
static Type * getX86_AMXTy(LLVMContext &C)
bool isBFloatTy() const
Return true if this is 'bfloat', a 16-bit bfloat type.
static Type * getMetadataTy(LLVMContext &C)
unsigned getStructNumElements() const
uint64_t getArrayNumElements() const
TypeID
Definitions of all of the base types for the Type system.
static Type * getX86_MMXTy(LLVMContext &C)
static Type * getVoidTy(LLVMContext &C)
static Type * getLabelTy(LLVMContext &C)
bool isStructTy() const
True if this is an instance of StructType.
static Type * getFP128Ty(LLVMContext &C)
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
static Type * getTokenTy(LLVMContext &C)
bool isFunctionTy() const
True if this is an instance of FunctionType.
static IntegerType * getInt32Ty(LLVMContext &C)
static Type * getFloatTy(LLVMContext &C)
bool isIntegerTy() const
True if this is an instance of IntegerType.
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
static Type * getPPC_FP128Ty(LLVMContext &C)
bool isVoidTy() const
Return true if this is 'void'.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
bool isMetadataTy() const
Return true if this is 'metadata'.
static UnaryOperator * Create(UnaryOps Op, Value *S, const Twine &Name, BasicBlock::iterator InsertBefore)
Construct a unary instruction, given the opcode and an operand.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
This function has undefined behavior.
A Use represents the edge between a Value definition and its users.
This class represents the va_arg llvm instruction, which returns an argument of the specified type gi...
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
void setName(const Twine &Name)
Change the name of the value.
void deleteValue()
Delete a pointer to a generic Value.
static constexpr unsigned MaxAlignmentExponent
The maximum alignment for instructions.
Value & operator=(const Value &)=delete
std::pair< iterator, bool > insert(const ValueT &V)
bool contains(const_arg_type_t< ValueT > V) const
Check if the set contains the given element.
self_iterator getIterator()
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char TypeName[]
Key for Kernel::Arg::Metadata::mTypeName.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
AttributeMask typeIncompatible(Type *Ty, AttributeSafetyKind ASK=ASK_ALL)
Which attributes cannot be applied to a type.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ MaxID
The highest possible ID. Must be some 2^k - 1.
@ X86_INTR
x86 hardware interrupt context.
@ C
The default llvm calling convention, compatible with C.
constexpr uint8_t RecordLength
Length of the parts of a physical GOFF record.
AttributeList getAttributes(LLVMContext &C, ID id)
Return the attributes for an intrinsic.
@ SingleThread
Synchronized with respect to signal handlers executing in the same thread.
@ System
Synchronized with respect to all concurrently executing threads.
@ TYPE_CODE_OPAQUE_POINTER
@ FS_COMBINED_GLOBALVAR_INIT_REFS
@ FS_TYPE_CHECKED_LOAD_VCALLS
@ FS_COMBINED_ORIGINAL_NAME
@ FS_PERMODULE_VTABLE_GLOBALVAR_INIT_REFS
@ FS_TYPE_TEST_ASSUME_CONST_VCALL
@ FS_PERMODULE_GLOBALVAR_INIT_REFS
@ FS_TYPE_TEST_ASSUME_VCALLS
@ FS_COMBINED_CALLSITE_INFO
@ FS_PERMODULE_CALLSITE_INFO
@ FS_PERMODULE_ALLOC_INFO
@ FS_TYPE_CHECKED_LOAD_CONST_VCALL
@ IDENTIFICATION_CODE_EPOCH
@ IDENTIFICATION_CODE_STRING
@ CST_CODE_CE_INBOUNDS_GEP
@ CST_CODE_INLINEASM_OLD3
@ CST_CODE_CE_GEP_WITH_INRANGE_INDEX_OLD
@ CST_CODE_DSO_LOCAL_EQUIVALENT
@ CST_CODE_INLINEASM_OLD2
@ CST_CODE_CE_GEP_WITH_INRANGE
@ VST_CODE_COMBINED_ENTRY
@ COMDAT_SELECTION_KIND_LARGEST
@ COMDAT_SELECTION_KIND_ANY
@ COMDAT_SELECTION_KIND_SAME_SIZE
@ COMDAT_SELECTION_KIND_EXACT_MATCH
@ COMDAT_SELECTION_KIND_NO_DUPLICATES
@ ATTR_KIND_STACK_PROTECT
@ ATTR_KIND_STACK_PROTECT_STRONG
@ ATTR_KIND_SANITIZE_MEMORY
@ ATTR_KIND_OPTIMIZE_FOR_SIZE
@ ATTR_KIND_INACCESSIBLEMEM_ONLY
@ ATTR_KIND_FNRETTHUNK_EXTERN
@ ATTR_KIND_SANITIZE_ADDRESS
@ ATTR_KIND_NO_IMPLICIT_FLOAT
@ ATTR_KIND_DEAD_ON_UNWIND
@ ATTR_KIND_STACK_ALIGNMENT
@ ATTR_KIND_INACCESSIBLEMEM_OR_ARGMEMONLY
@ ATTR_KIND_STACK_PROTECT_REQ
@ ATTR_KIND_NULL_POINTER_IS_VALID
@ ATTR_KIND_SANITIZE_HWADDRESS
@ ATTR_KIND_RETURNS_TWICE
@ ATTR_KIND_SHADOWCALLSTACK
@ ATTR_KIND_OPT_FOR_FUZZING
@ ATTR_KIND_ALLOCATED_POINTER
@ ATTR_KIND_DISABLE_SANITIZER_INSTRUMENTATION
@ ATTR_KIND_NON_LAZY_BIND
@ ATTR_KIND_DEREFERENCEABLE
@ ATTR_KIND_OPTIMIZE_NONE
@ ATTR_KIND_DEREFERENCEABLE_OR_NULL
@ ATTR_KIND_SPECULATIVE_LOAD_HARDENING
@ ATTR_KIND_ALWAYS_INLINE
@ ATTR_KIND_PRESPLIT_COROUTINE
@ ATTR_KIND_NO_SANITIZE_COVERAGE
@ ATTR_KIND_NO_SANITIZE_BOUNDS
@ ATTR_KIND_SANITIZE_MEMTAG
@ ATTR_KIND_CORO_ONLY_DESTROY_WHEN_COMPLETE
@ ATTR_KIND_SANITIZE_THREAD
@ ATTR_KIND_OPTIMIZE_FOR_DEBUGGING
@ SYNC_SCOPE_NAMES_BLOCK_ID
@ PARAMATTR_GROUP_BLOCK_ID
@ IDENTIFICATION_BLOCK_ID
@ GLOBALVAL_SUMMARY_BLOCK_ID
@ FULL_LTO_GLOBALVAL_SUMMARY_BLOCK_ID
@ OPERAND_BUNDLE_TAGS_BLOCK_ID
@ BLOCKINFO_BLOCK_ID
BLOCKINFO_BLOCK is used to define metadata about blocks, for example, standard abbrevs that should be...
@ MODULE_CODE_SOURCE_FILENAME
@ MODULE_CODE_SECTIONNAME
@ FUNC_CODE_INST_ATOMICRMW_OLD
@ FUNC_CODE_INST_CATCHRET
@ FUNC_CODE_INST_LANDINGPAD
@ FUNC_CODE_INST_EXTRACTVAL
@ FUNC_CODE_INST_CATCHPAD
@ FUNC_CODE_INST_CATCHSWITCH
@ FUNC_CODE_INST_INBOUNDS_GEP_OLD
@ FUNC_CODE_INST_STOREATOMIC_OLD
@ FUNC_CODE_INST_CLEANUPRET
@ FUNC_CODE_INST_LANDINGPAD_OLD
@ FUNC_CODE_DEBUG_RECORD_VALUE
@ FUNC_CODE_INST_LOADATOMIC
@ FUNC_CODE_DEBUG_RECORD_ASSIGN
@ FUNC_CODE_INST_STOREATOMIC
@ FUNC_CODE_INST_ATOMICRMW
@ FUNC_CODE_DEBUG_LOC_AGAIN
@ FUNC_CODE_INST_EXTRACTELT
@ FUNC_CODE_INST_INDIRECTBR
@ FUNC_CODE_DEBUG_RECORD_VALUE_SIMPLE
@ FUNC_CODE_INST_INSERTVAL
@ FUNC_CODE_DECLAREBLOCKS
@ FUNC_CODE_DEBUG_RECORD_LABEL
@ FUNC_CODE_INST_INSERTELT
@ FUNC_CODE_BLOCKADDR_USERS
@ FUNC_CODE_INST_CLEANUPPAD
@ FUNC_CODE_INST_SHUFFLEVEC
@ FUNC_CODE_INST_STORE_OLD
@ FUNC_CODE_INST_UNREACHABLE
@ FUNC_CODE_INST_CMPXCHG_OLD
@ FUNC_CODE_DEBUG_RECORD_DECLARE
@ FUNC_CODE_OPERAND_BUNDLE
@ PARAMATTR_CODE_ENTRY_OLD
@ PARAMATTR_GRP_CODE_ENTRY
initializer< Ty > init(const Ty &Val)
Linkage
Describes symbol linkage. This can be used to resolve definition clashes.
Scope
Defines the scope in which this symbol should be visible: Default – Visible in the public interface o...
NodeAddr< FuncNode * > Func
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
@ Low
Lower the current thread's priority such that it does not affect foreground tasks significantly.
void UpgradeIntrinsicCall(CallBase *CB, Function *NewFn)
This is the complement to the above, replacing a specific call to an intrinsic function with a call t...
const std::error_category & BitcodeErrorCategory()
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Expected< std::unique_ptr< Module > > parseBitcodeFile(MemoryBufferRef Buffer, LLVMContext &Context, ParserCallbacks Callbacks={})
Read the specified bitcode file, returning the module.
void UpgradeInlineAsmString(std::string *AsmStr)
Upgrade comment in call to inline asm that represents an objc retain release marker.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are are tuples (A,...
std::error_code make_error_code(BitcodeError E)
bool stripDebugInfo(Function &F)
Expected< bool > isBitcodeContainingObjCCategory(MemoryBufferRef Buffer)
Return true if Buffer contains a bitcode file with ObjC code (category or class) in it.
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
bool UpgradeIntrinsicFunction(Function *F, Function *&NewFn, bool CanUpgradeDebugIntrinsicsToRecords=true)
This is a more granular function that simply checks an intrinsic function for upgrading,...
void UpgradeAttributes(AttrBuilder &B)
Upgrade attributes that changed format or kind.
Expected< std::string > getBitcodeTargetTriple(MemoryBufferRef Buffer)
Read the header of the specified bitcode buffer and extract just the triple information.
std::unique_ptr< Module > parseModule(const uint8_t *Data, size_t Size, LLVMContext &Context)
Fuzzer friendly interface for the llvm bitcode parser.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Expected< BitcodeFileContents > getBitcodeFileContents(MemoryBufferRef Buffer)
Returns the contents of a bitcode file.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
bool UpgradeModuleFlags(Module &M)
This checks for module flags which should be upgraded.
Value * getSplatValue(const Value *V)
Get splat value if the input is a splat vector or return nullptr.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
void UpgradeOperandBundles(std::vector< OperandBundleDef > &OperandBundles)
Upgrade operand bundles (without knowing about their user instruction).
std::vector< VirtFuncOffset > VTableFuncList
List of functions referenced by a particular vtable definition.
Constant * UpgradeBitCastExpr(unsigned Opc, Constant *C, Type *DestTy)
This is an auto-upgrade for bitcast constant expression between pointers with different address space...
Expected< std::unique_ptr< ModuleSummaryIndex > > getModuleSummaryIndex(MemoryBufferRef Buffer)
Parse the specified bitcode buffer, returning the module summary index.
StringMapEntry< Value * > ValueName
OutputIt transform(R &&Range, OutputIt d_first, UnaryFunction F)
Wrapper function around std::transform to apply a function to a range and store the result elsewhere.
Expected< std::string > getBitcodeProducerString(MemoryBufferRef Buffer)
Read the header of the specified bitcode buffer and extract just the producer string information.
auto reverse(ContainerTy &&C)
Expected< std::unique_ptr< Module > > getLazyBitcodeModule(MemoryBufferRef Buffer, LLVMContext &Context, bool ShouldLazyLoadMetadata=false, bool IsImporting=false, ParserCallbacks Callbacks={})
Read the header of the specified bitcode buffer and prepare for lazy deserialization of function bodi...
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
FPClassTest
Floating-point class tests, supported by 'is_fpclass' intrinsic.
detail::ValueMatchesPoly< M > HasValue(M Matcher)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
std::string UpgradeDataLayoutString(StringRef DL, StringRef Triple)
Upgrade the datalayout string by adding a section for address space pointers.
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
Expected< std::vector< BitcodeModule > > getBitcodeModuleList(MemoryBufferRef Buffer)
Returns a list of modules in the specified bitcode buffer.
Expected< BitcodeLTOInfo > getBitcodeLTOInfo(MemoryBufferRef Buffer)
Returns LTO information for the specified bitcode file.
GlobalVariable * UpgradeGlobalVariable(GlobalVariable *GV)
This checks for global variables which should be upgraded.
bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
AtomicOrdering
Atomic ordering for LLVM's memory model.
Instruction * UpgradeBitCastInst(unsigned Opc, Value *V, Type *DestTy, Instruction *&Temp)
This is an auto-upgrade for bitcast between pointers with different address spaces: the instruction i...
MaybeAlign decodeMaybeAlign(unsigned Value)
Dual operation of the encode function above.
DWARFExpression::Operation Op
constexpr unsigned BitWidth
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
bool SkipBitcodeWrapperHeader(const unsigned char *&BufPtr, const unsigned char *&BufEnd, bool VerifyBufferSize)
SkipBitcodeWrapperHeader - Some systems wrap bc files with a special header for padding or other reas...
bool isBitcodeWrapper(const unsigned char *BufPtr, const unsigned char *BufEnd)
isBitcodeWrapper - Return true if the given bytes are the magic bytes for an LLVM IR bitcode wrapper.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
gep_type_iterator gep_type_begin(const User *GEP)
APInt readWideAPInt(ArrayRef< uint64_t > Vals, unsigned TypeBits)
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
bool UpgradeDebugInfo(Module &M)
Check the debug info version number, if it is out-dated, drop the debug info.
void UpgradeFunctionAttributes(Function &F)
Correct any IR that is relying on old function attribute behavior.
Error readModuleSummaryIndex(MemoryBufferRef Buffer, ModuleSummaryIndex &CombinedIndex)
Parse the specified bitcode buffer and merge the index into CombinedIndex.
std::vector< TypeIdOffsetVtableInfo > TypeIdCompatibleVtableInfo
List of vtable definitions decorated by a particular type identifier, and their corresponding offsets...
void UpgradeARCRuntime(Module &M)
Convert calls to ARC runtime functions to intrinsic calls and upgrade the old retain release marker t...
Expected< std::unique_ptr< ModuleSummaryIndex > > getModuleSummaryIndexForFile(StringRef Path, bool IgnoreEmptyThinLTOIndexFile=false)
Parse the module summary index out of an IR file and return the module summary index object if found,...
Expected< std::unique_ptr< Module > > getOwningLazyBitcodeModule(std::unique_ptr< MemoryBuffer > &&Buffer, LLVMContext &Context, bool ShouldLazyLoadMetadata=false, bool IsImporting=false, ParserCallbacks Callbacks={})
Like getLazyBitcodeModule, except that the module takes ownership of the memory buffer if successful.
std::error_code errorToErrorCodeAndEmitErrors(LLVMContext &Ctx, Error Err)
Implement std::hash so that hash_code can be used in STL containers.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Summary of memprof metadata on allocations.
Basic information extracted from a bitcode module to be used for LTO.
When advancing through a bitstream cursor, each advance can discover a few different kinds of entries...
Class to accumulate and hold information about a callee.
static constexpr unsigned RelBlockFreqBits
The value stored in RelBlockFreq has to be interpreted as the digits of a scaled number with a scale ...
Summary of memprof callsite metadata.
Flags specific to function summaries.
Describes the uses of a parameter by the function.
std::vector< Call > Calls
In the per-module summary, it summarizes the byte offset applied to each pointer parameter before pas...
ConstantRange Use
The range contains byte offsets from the parameter pointer which accessed by the function.
static constexpr uint32_t RangeWidth
Group flags (Linkage, NotEligibleToImport, etc.) as a bitfield.
Summary of a single MIB in a memprof metadata on allocations.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
std::optional< ValueTypeCallbackTy > ValueType
The ValueType callback is called for every function definition or declaration and allows accessing th...
std::optional< DataLayoutCallbackFuncTy > DataLayout
std::optional< MDTypeCallbackTy > MDType
The MDType callback is called for every value in metadata.
A MapVector that performs no allocations if smaller than a certain size.
std::map< uint64_t, WholeProgramDevirtResolution > WPDRes
Mapping from byte offset to whole-program devirt resolution for that (typeid, byte offset) pair.
Kind
Specifies which kind of type check we should emit for this byte array.
unsigned SizeM1BitWidth
Range of size-1 expressed as a bit width.
enum llvm::TypeTestResolution::Kind TheKind
ValID - Represents a reference of a definition of some sort with no type.
Struct that holds a reference to a particular GUID in a global value summary.
enum llvm::WholeProgramDevirtResolution::Kind TheKind
std::map< std::vector< uint64_t >, ByArg > ResByArg
Resolutions for calls with all constant integer arguments (excluding the first argument,...
std::string SingleImplName