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)
327 switch (Entry.Kind) {
329 return error(
"Malformed block");
339 return std::move(Err);
352 return std::move(Err);
365 switch (Entry.Kind) {
368 return error(
"Malformed block");
380 switch (MaybeRecord.
get()) {
385 return error(
"Invalid triple record");
404 switch (Entry.Kind) {
406 return error(
"Malformed block");
416 return std::move(Err);
423 return Skipped.takeError();
430class BitcodeReaderBase {
433 : Stream(
std::
move(Stream)), Strtab(Strtab) {
443 bool UseStrtab =
false;
450 std::pair<StringRef, ArrayRef<uint64_t>>
453 Error readBlockInfo();
456 std::string ProducerIdentification;
463Error BitcodeReaderBase::error(
const Twine &Message) {
464 std::string FullMsg = Message.
str();
465 if (!ProducerIdentification.empty())
466 FullMsg +=
" (Producer: '" + ProducerIdentification +
"' Reader: 'LLVM " +
467 LLVM_VERSION_STRING
"')";
468 return ::error(FullMsg);
474 return error(
"Invalid version record");
475 unsigned ModuleVersion =
Record[0];
476 if (ModuleVersion > 2)
477 return error(
"Invalid value");
478 UseStrtab = ModuleVersion >= 2;
479 return ModuleVersion;
482std::pair<StringRef, ArrayRef<uint64_t>>
500class BitcodeConstant final :
public Value,
505 static constexpr uint8_t SubclassID = 255;
513 static constexpr uint8_t ConstantStructOpcode = 255;
514 static constexpr uint8_t ConstantArrayOpcode = 254;
515 static constexpr uint8_t ConstantVectorOpcode = 253;
516 static constexpr uint8_t NoCFIOpcode = 252;
517 static constexpr uint8_t DSOLocalEquivalentOpcode = 251;
518 static constexpr uint8_t BlockAddressOpcode = 250;
519 static constexpr uint8_t FirstSpecialOpcode = BlockAddressOpcode;
526 unsigned BlockAddressBB = 0;
527 Type *SrcElemTy =
nullptr;
528 std::optional<ConstantRange> InRange;
530 ExtraInfo(uint8_t Opcode, uint8_t Flags = 0,
Type *SrcElemTy =
nullptr,
531 std::optional<ConstantRange> InRange = std::nullopt)
532 : Opcode(Opcode),
Flags(
Flags), SrcElemTy(SrcElemTy),
535 ExtraInfo(uint8_t Opcode, uint8_t Flags,
unsigned BlockAddressBB)
536 : Opcode(Opcode),
Flags(
Flags), BlockAddressBB(BlockAddressBB) {}
541 unsigned NumOperands;
542 unsigned BlockAddressBB;
544 std::optional<ConstantRange>
InRange;
549 NumOperands(OpIDs.
size()), BlockAddressBB(
Info.BlockAddressBB),
550 SrcElemTy(
Info.SrcElemTy), InRange(
Info.InRange) {
551 std::uninitialized_copy(OpIDs.
begin(), OpIDs.
end(),
552 getTrailingObjects<unsigned>());
555 BitcodeConstant &
operator=(
const BitcodeConstant &) =
delete;
559 const ExtraInfo &Info,
561 void *Mem =
A.Allocate(totalSizeToAlloc<unsigned>(OpIDs.
size()),
562 alignof(BitcodeConstant));
563 return new (Mem) BitcodeConstant(Ty, Info, OpIDs);
566 static bool classof(
const Value *V) {
return V->getValueID() == SubclassID; }
569 return ArrayRef(getTrailingObjects<unsigned>(), NumOperands);
572 std::optional<ConstantRange> getInRange()
const {
573 assert(Opcode == Instruction::GetElementPtr);
582class BitcodeReader :
public BitcodeReaderBase,
public GVMaterializer {
584 Module *TheModule =
nullptr;
589 bool SeenValueSymbolTable =
false;
592 std::vector<std::string> SectionTable;
593 std::vector<std::string> GCTable;
595 std::vector<Type *> TypeList;
613 std::optional<MetadataLoader> MDLoader;
614 std::vector<Comdat *> ComdatList;
618 std::vector<std::pair<GlobalVariable *, unsigned>> GlobalInits;
619 std::vector<std::pair<GlobalValue *, unsigned>> IndirectSymbolInits;
621 struct FunctionOperandInfo {
623 unsigned PersonalityFn;
627 std::vector<FunctionOperandInfo> FunctionOperands;
631 std::vector<AttributeList> MAttributes;
634 std::map<unsigned, AttributeList> MAttributeGroups;
638 std::vector<BasicBlock*> FunctionBBs;
642 std::vector<Function*> FunctionsWithBodies;
647 UpdatedIntrinsicMap UpgradedIntrinsics;
652 bool SeenFirstFunctionBody =
false;
661 std::vector<uint64_t> DeferredMetadataInfo;
667 std::deque<Function *> BasicBlockFwdRefQueue;
674 std::vector<Function *> BackwardRefFunctions;
682 bool UseRelativeIDs =
false;
686 bool WillMaterializeAllForwardRefs =
false;
690 bool SeenDebugIntrinsic =
false;
691 bool SeenDebugRecord =
false;
696 std::vector<std::string> BundleTags;
699 std::optional<ValueTypeCallbackTy> ValueTypeCallback;
705 Error materializeForwardReferencedFunctions();
713 Error parseBitcodeInto(
Module *M,
bool ShouldLazyLoadMetadata,
724 std::vector<StructType *> IdentifiedStructTypes;
728 static constexpr unsigned InvalidTypeID = ~0
u;
730 Type *getTypeByID(
unsigned ID);
731 Type *getPtrElementTypeByID(
unsigned ID);
732 unsigned getContainedTypeID(
unsigned ID,
unsigned Idx = 0);
739 Value *getFnValueByID(
unsigned ID,
Type *Ty,
unsigned TyID,
747 return MDLoader->getMetadataFwdRefOrLoad(
ID);
751 if (
ID >= FunctionBBs.size())
return nullptr;
752 return FunctionBBs[
ID];
756 if (i-1 < MAttributes.size())
757 return MAttributes[i-1];
765 unsigned InstNum,
Value *&ResVal,
unsigned &
TypeID,
767 if (Slot ==
Record.size())
return true;
771 ValNo = InstNum - ValNo;
772 if (ValNo < InstNum) {
776 ResVal = getFnValueByID(ValNo,
nullptr,
TypeID, ConstExprInsertBB);
778 "Incorrect type ID stored for value");
779 return ResVal ==
nullptr;
781 if (Slot ==
Record.size())
785 ResVal = getFnValueByID(ValNo, getTypeByID(
TypeID),
TypeID,
787 return ResVal ==
nullptr;
794 unsigned InstNum,
Type *Ty,
unsigned TyID,
Value *&ResVal,
796 if (getValue(
Record, Slot, InstNum, Ty, TyID, ResVal, ConstExprInsertBB))
805 unsigned InstNum,
Type *Ty,
unsigned TyID,
Value *&ResVal,
807 ResVal = getValue(
Record, Slot, InstNum, Ty, TyID, ConstExprInsertBB);
808 return ResVal ==
nullptr;
814 unsigned InstNum,
Type *Ty,
unsigned TyID,
816 if (Slot ==
Record.size())
return nullptr;
820 ValNo = InstNum - ValNo;
821 return getFnValueByID(ValNo, Ty, TyID, ConstExprInsertBB);
826 unsigned InstNum,
Type *Ty,
unsigned TyID,
828 if (Slot ==
Record.size())
return nullptr;
832 ValNo = InstNum - ValNo;
833 return getFnValueByID(ValNo, Ty, TyID, ConstExprInsertBB);
838 if (
Record.size() - OpNum < 3)
839 return error(
"Too few records for range");
842 unsigned LowerActiveWords =
Record[OpNum];
843 unsigned UpperActiveWords =
Record[OpNum++] >> 32;
844 if (
Record.size() - OpNum < LowerActiveWords + UpperActiveWords)
845 return error(
"Too few records for range");
848 OpNum += LowerActiveWords;
851 OpNum += UpperActiveWords;
854 int64_t Start = BitcodeReader::decodeSignRotatedValue(
Record[OpNum++]);
855 int64_t
End = BitcodeReader::decodeSignRotatedValue(
Record[OpNum++]);
876 Error parseGlobalIndirectSymbolRecord(
unsigned BitCode,
879 Error parseAttributeBlock();
880 Error parseAttributeGroupBlock();
881 Error parseTypeTable();
882 Error parseTypeTableBody();
883 Error parseOperandBundleTags();
884 Error parseSyncScopeNames();
887 unsigned NameIndex,
Triple &TT);
888 void setDeferredFunctionInfo(
unsigned FuncBitcodeOffsetDelta,
Function *
F,
891 Error parseGlobalValueSymbolTable();
892 Error parseConstants();
893 Error rememberAndSkipFunctionBodies();
894 Error rememberAndSkipFunctionBody();
896 Error rememberAndSkipMetadata();
899 Error globalCleanup();
900 Error resolveGlobalAndIndirectSymbolInits();
901 Error parseUseLists();
902 Error findFunctionInStream(
911class ModuleSummaryIndexBitcodeReader :
public BitcodeReaderBase {
917 bool SeenGlobalValSummary =
false;
920 bool SeenValueSymbolTable =
false;
936 std::tuple<ValueInfo, GlobalValue::GUID, GlobalValue::GUID>>
937 ValueIdToValueInfoMap;
946 std::string SourceFileName;
958 std::vector<uint64_t> StackIds;
961 ModuleSummaryIndexBitcodeReader(
972 Error parseValueSymbolTable(
977 bool IsOldProfileFormat,
980 Error parseEntireSummary(
unsigned ID);
981 Error parseModuleStringTable();
985 std::vector<FunctionSummary::ParamAccess>
988 template <
bool AllowNullValueInfo = false>
989 std::tuple<ValueInfo, GlobalValue::GUID, GlobalValue::GUID>
990 getValueInfoFromValueId(
unsigned ValueId);
992 void addThisModule();
1008 return std::error_code();
1015 ValueList(this->Stream.SizeInBytes(),
1017 return materializeValue(
ValID, InsertBB);
1019 this->ProducerIdentification = std::string(ProducerIdentification);
1022Error BitcodeReader::materializeForwardReferencedFunctions() {
1023 if (WillMaterializeAllForwardRefs)
1027 WillMaterializeAllForwardRefs =
true;
1029 while (!BasicBlockFwdRefQueue.empty()) {
1030 Function *
F = BasicBlockFwdRefQueue.front();
1031 BasicBlockFwdRefQueue.pop_front();
1032 assert(
F &&
"Expected valid function");
1033 if (!BasicBlockFwdRefs.
count(
F))
1041 if (!
F->isMaterializable())
1042 return error(
"Never resolved function from blockaddress");
1045 if (
Error Err = materialize(
F))
1048 assert(BasicBlockFwdRefs.
empty() &&
"Function missing from queue");
1050 for (
Function *
F : BackwardRefFunctions)
1051 if (
Error Err = materialize(
F))
1053 BackwardRefFunctions.clear();
1056 WillMaterializeAllForwardRefs =
false;
1120 Flags.ReadNone = RawFlags & 0x1;
1121 Flags.ReadOnly = (RawFlags >> 1) & 0x1;
1122 Flags.NoRecurse = (RawFlags >> 2) & 0x1;
1123 Flags.ReturnDoesNotAlias = (RawFlags >> 3) & 0x1;
1124 Flags.NoInline = (RawFlags >> 4) & 0x1;
1125 Flags.AlwaysInline = (RawFlags >> 5) & 0x1;
1126 Flags.NoUnwind = (RawFlags >> 6) & 0x1;
1127 Flags.MayThrow = (RawFlags >> 7) & 0x1;
1128 Flags.HasUnknownCall = (RawFlags >> 8) & 0x1;
1129 Flags.MustBeUnreachable = (RawFlags >> 9) & 0x1;
1145 RawFlags = RawFlags >> 4;
1146 bool NotEligibleToImport = (RawFlags & 0x1) || Version < 3;
1150 bool Live = (RawFlags & 0x2) || Version < 3;
1151 bool Local = (RawFlags & 0x4);
1152 bool AutoHide = (RawFlags & 0x8);
1155 Live, Local, AutoHide, IK);
1161 (RawFlags & 0x1) ?
true :
false, (RawFlags & 0x2) ?
true :
false,
1162 (RawFlags & 0x4) ?
true :
false,
1166static std::pair<CalleeInfo::HotnessType, bool>
1170 bool HasTailCall = (RawFlags & 0x8);
1171 return {Hotness, HasTailCall};
1175 bool &HasTailCall) {
1176 static constexpr uint64_t RelBlockFreqMask =
1178 RelBF = RawFlags & RelBlockFreqMask;
1204 case 0:
return false;
1205 case 1:
return true;
1228 case 0:
return GlobalVariable::NotThreadLocal;
1230 case 1:
return GlobalVariable::GeneralDynamicTLSModel;
1231 case 2:
return GlobalVariable::LocalDynamicTLSModel;
1232 case 3:
return GlobalVariable::InitialExecTLSModel;
1233 case 4:
return GlobalVariable::LocalExecTLSModel;
1240 case 0:
return GlobalVariable::UnnamedAddr::None;
1241 case 1:
return GlobalVariable::UnnamedAddr::Global;
1242 case 2:
return GlobalVariable::UnnamedAddr::Local;
1275 return IsFP ? Instruction::FNeg : -1;
1289 return IsFP ? Instruction::FAdd : Instruction::Add;
1291 return IsFP ? Instruction::FSub : Instruction::Sub;
1293 return IsFP ? Instruction::FMul : Instruction::Mul;
1295 return IsFP ? -1 : Instruction::UDiv;
1297 return IsFP ? Instruction::FDiv : Instruction::SDiv;
1299 return IsFP ? -1 : Instruction::URem;
1301 return IsFP ? Instruction::FRem : Instruction::SRem;
1303 return IsFP ? -1 : Instruction::Shl;
1305 return IsFP ? -1 : Instruction::LShr;
1307 return IsFP ? -1 : Instruction::AShr;
1309 return IsFP ? -1 : Instruction::And;
1311 return IsFP ? -1 : Instruction::Or;
1313 return IsFP ? -1 : Instruction::Xor;
1402Type *BitcodeReader::getTypeByID(
unsigned ID) {
1404 if (
ID >= TypeList.size())
1407 if (
Type *Ty = TypeList[
ID])
1412 return TypeList[
ID] = createIdentifiedStructType(Context);
1415unsigned BitcodeReader::getContainedTypeID(
unsigned ID,
unsigned Idx) {
1416 auto It = ContainedTypeIDs.
find(
ID);
1417 if (It == ContainedTypeIDs.
end())
1418 return InvalidTypeID;
1420 if (
Idx >= It->second.size())
1421 return InvalidTypeID;
1423 return It->second[
Idx];
1426Type *BitcodeReader::getPtrElementTypeByID(
unsigned ID) {
1427 if (
ID >= TypeList.size())
1434 return getTypeByID(getContainedTypeID(
ID, 0));
1437unsigned BitcodeReader::getVirtualTypeID(
Type *Ty,
1439 unsigned ChildTypeID = ChildTypeIDs.
empty() ? InvalidTypeID : ChildTypeIDs[0];
1440 auto CacheKey = std::make_pair(Ty, ChildTypeID);
1441 auto It = VirtualTypeIDs.
find(CacheKey);
1442 if (It != VirtualTypeIDs.
end()) {
1448 ContainedTypeIDs[It->second] == ChildTypeIDs) &&
1449 "Incorrect cached contained type IDs");
1453 unsigned TypeID = TypeList.size();
1454 TypeList.push_back(Ty);
1455 if (!ChildTypeIDs.
empty())
1462 uint8_t Opcode = BC->Opcode;
1465 if (Opcode >= BitcodeConstant::FirstSpecialOpcode)
1479 if (Opcode == Instruction::GetElementPtr)
1483 case Instruction::FNeg:
1484 case Instruction::Select:
1494 if (StartValID < ValueList.
size() && ValueList[StartValID] &&
1495 !isa<BitcodeConstant>(ValueList[StartValID]))
1496 return ValueList[StartValID];
1501 while (!Worklist.
empty()) {
1510 return error(
"Invalid value ID");
1513 auto *BC = dyn_cast<BitcodeConstant>(V);
1523 for (
unsigned OpID :
reverse(BC->getOperandIDs())) {
1524 auto It = MaterializedValues.
find(OpID);
1525 if (It != MaterializedValues.
end())
1533 if (Ops.
size() != BC->getOperandIDs().size())
1535 std::reverse(Ops.
begin(), Ops.
end());
1539 if (
auto *
C = dyn_cast<Constant>(
Op))
1552 switch (BC->Opcode) {
1553 case BitcodeConstant::NoCFIOpcode: {
1554 auto *GV = dyn_cast<GlobalValue>(ConstOps[0]);
1556 return error(
"no_cfi operand must be GlobalValue");
1560 case BitcodeConstant::DSOLocalEquivalentOpcode: {
1561 auto *GV = dyn_cast<GlobalValue>(ConstOps[0]);
1563 return error(
"dso_local operand must be GlobalValue");
1567 case BitcodeConstant::BlockAddressOpcode: {
1568 Function *Fn = dyn_cast<Function>(ConstOps[0]);
1570 return error(
"blockaddress operand must be a function");
1575 unsigned BBID = BC->BlockAddressBB;
1578 return error(
"Invalid ID");
1581 for (
size_t I = 0, E = BBID;
I != E; ++
I) {
1583 return error(
"Invalid ID");
1590 auto &FwdBBs = BasicBlockFwdRefs[Fn];
1592 BasicBlockFwdRefQueue.push_back(Fn);
1593 if (FwdBBs.size() < BBID + 1)
1594 FwdBBs.resize(BBID + 1);
1602 case BitcodeConstant::ConstantStructOpcode:
1605 case BitcodeConstant::ConstantArrayOpcode:
1608 case BitcodeConstant::ConstantVectorOpcode:
1611 case Instruction::ICmp:
1612 case Instruction::FCmp:
1615 case Instruction::GetElementPtr:
1618 BC->Flags, BC->getInRange());
1620 case Instruction::ExtractElement:
1623 case Instruction::InsertElement:
1627 case Instruction::ShuffleVector: {
1646 return error(
Twine(
"Value referenced by initializer is an unsupported "
1647 "constant expression of type ") +
1648 BC->getOpcodeName());
1654 BC->getType(),
"constexpr", InsertBB);
1657 "constexpr", InsertBB);
1660 Ops[1],
"constexpr", InsertBB);
1661 if (isa<OverflowingBinaryOperator>(
I)) {
1663 I->setHasNoSignedWrap();
1665 I->setHasNoUnsignedWrap();
1667 if (isa<PossiblyExactOperator>(
I) &&
1671 switch (BC->Opcode) {
1672 case BitcodeConstant::ConstantVectorOpcode: {
1676 Value *
Idx = ConstantInt::get(IdxTy, Pair.index());
1680 I = cast<Instruction>(V);
1683 case BitcodeConstant::ConstantStructOpcode:
1684 case BitcodeConstant::ConstantArrayOpcode: {
1688 "constexpr.ins", InsertBB);
1689 I = cast<Instruction>(V);
1692 case Instruction::ICmp:
1693 case Instruction::FCmp:
1696 "constexpr", InsertBB);
1698 case Instruction::GetElementPtr:
1700 ArrayRef(Ops).drop_front(),
"constexpr",
1703 cast<GetElementPtrInst>(
I)->setIsInBounds();
1705 case Instruction::Select:
1708 case Instruction::ExtractElement:
1711 case Instruction::InsertElement:
1715 case Instruction::ShuffleVector:
1728 return MaterializedValues[StartValID];
1737 return cast<Constant>(MaybeV.
get());
1743 IdentifiedStructTypes.push_back(Ret);
1749 IdentifiedStructTypes.push_back(Ret);
1765 case Attribute::ZExt:
return 1 << 0;
1766 case Attribute::SExt:
return 1 << 1;
1767 case Attribute::NoReturn:
return 1 << 2;
1768 case Attribute::InReg:
return 1 << 3;
1769 case Attribute::StructRet:
return 1 << 4;
1770 case Attribute::NoUnwind:
return 1 << 5;
1771 case Attribute::NoAlias:
return 1 << 6;
1772 case Attribute::ByVal:
return 1 << 7;
1773 case Attribute::Nest:
return 1 << 8;
1774 case Attribute::ReadNone:
return 1 << 9;
1775 case Attribute::ReadOnly:
return 1 << 10;
1776 case Attribute::NoInline:
return 1 << 11;
1777 case Attribute::AlwaysInline:
return 1 << 12;
1778 case Attribute::OptimizeForSize:
return 1 << 13;
1779 case Attribute::StackProtect:
return 1 << 14;
1780 case Attribute::StackProtectReq:
return 1 << 15;
1781 case Attribute::Alignment:
return 31 << 16;
1782 case Attribute::NoCapture:
return 1 << 21;
1783 case Attribute::NoRedZone:
return 1 << 22;
1784 case Attribute::NoImplicitFloat:
return 1 << 23;
1785 case Attribute::Naked:
return 1 << 24;
1786 case Attribute::InlineHint:
return 1 << 25;
1787 case Attribute::StackAlignment:
return 7 << 26;
1788 case Attribute::ReturnsTwice:
return 1 << 29;
1789 case Attribute::UWTable:
return 1 << 30;
1790 case Attribute::NonLazyBind:
return 1U << 31;
1791 case Attribute::SanitizeAddress:
return 1ULL << 32;
1792 case Attribute::MinSize:
return 1ULL << 33;
1793 case Attribute::NoDuplicate:
return 1ULL << 34;
1794 case Attribute::StackProtectStrong:
return 1ULL << 35;
1795 case Attribute::SanitizeThread:
return 1ULL << 36;
1796 case Attribute::SanitizeMemory:
return 1ULL << 37;
1797 case Attribute::NoBuiltin:
return 1ULL << 38;
1798 case Attribute::Returned:
return 1ULL << 39;
1799 case Attribute::Cold:
return 1ULL << 40;
1800 case Attribute::Builtin:
return 1ULL << 41;
1801 case Attribute::OptimizeNone:
return 1ULL << 42;
1802 case Attribute::InAlloca:
return 1ULL << 43;
1803 case Attribute::NonNull:
return 1ULL << 44;
1804 case Attribute::JumpTable:
return 1ULL << 45;
1805 case Attribute::Convergent:
return 1ULL << 46;
1806 case Attribute::SafeStack:
return 1ULL << 47;
1807 case Attribute::NoRecurse:
return 1ULL << 48;
1810 case Attribute::SwiftSelf:
return 1ULL << 51;
1811 case Attribute::SwiftError:
return 1ULL << 52;
1812 case Attribute::WriteOnly:
return 1ULL << 53;
1813 case Attribute::Speculatable:
return 1ULL << 54;
1814 case Attribute::StrictFP:
return 1ULL << 55;
1815 case Attribute::SanitizeHWAddress:
return 1ULL << 56;
1816 case Attribute::NoCfCheck:
return 1ULL << 57;
1817 case Attribute::OptForFuzzing:
return 1ULL << 58;
1818 case Attribute::ShadowCallStack:
return 1ULL << 59;
1819 case Attribute::SpeculativeLoadHardening:
1821 case Attribute::ImmArg:
1823 case Attribute::WillReturn:
1825 case Attribute::NoFree:
1841 if (
I == Attribute::Alignment)
1842 B.addAlignmentAttr(1ULL << ((
A >> 16) - 1));
1843 else if (
I == Attribute::StackAlignment)
1844 B.addStackAlignmentAttr(1ULL << ((
A >> 26)-1));
1846 B.addTypeAttr(
I,
nullptr);
1861 unsigned Alignment = (EncodedAttrs & (0xffffULL << 16)) >> 16;
1863 "Alignment must be a power of two.");
1866 B.addAlignmentAttr(Alignment);
1868 uint64_t Attrs = ((EncodedAttrs & (0xfffffULL << 32)) >> 11) |
1869 (EncodedAttrs & 0xffff);
1874 if (Attrs & (1ULL << 9)) {
1876 Attrs &= ~(1ULL << 9);
1879 if (Attrs & (1ULL << 10)) {
1881 Attrs &= ~(1ULL << 10);
1884 if (Attrs & (1ULL << 49)) {
1886 Attrs &= ~(1ULL << 49);
1889 if (Attrs & (1ULL << 50)) {
1891 Attrs &= ~(1ULL << 50);
1894 if (Attrs & (1ULL << 53)) {
1896 Attrs &= ~(1ULL << 53);
1900 B.addMemoryAttr(ME);
1906Error BitcodeReader::parseAttributeBlock() {
1910 if (!MAttributes.empty())
1911 return error(
"Invalid multiple blocks");
1924 switch (Entry.Kind) {
1927 return error(
"Malformed block");
1940 switch (MaybeRecord.
get()) {
1946 return error(
"Invalid parameter attribute record");
1948 for (
unsigned i = 0, e =
Record.size(); i != e; i += 2) {
1958 for (
unsigned i = 0, e =
Record.size(); i != e; ++i)
1974 return Attribute::Alignment;
1976 return Attribute::AlwaysInline;
1978 return Attribute::Builtin;
1980 return Attribute::ByVal;
1982 return Attribute::InAlloca;
1984 return Attribute::Cold;
1986 return Attribute::Convergent;
1988 return Attribute::DisableSanitizerInstrumentation;
1990 return Attribute::ElementType;
1992 return Attribute::FnRetThunkExtern;
1994 return Attribute::InlineHint;
1996 return Attribute::InReg;
1998 return Attribute::JumpTable;
2000 return Attribute::Memory;
2002 return Attribute::NoFPClass;
2004 return Attribute::MinSize;
2006 return Attribute::Naked;
2008 return Attribute::Nest;
2010 return Attribute::NoAlias;
2012 return Attribute::NoBuiltin;
2014 return Attribute::NoCallback;
2016 return Attribute::NoCapture;
2018 return Attribute::NoDuplicate;
2020 return Attribute::NoFree;
2022 return Attribute::NoImplicitFloat;
2024 return Attribute::NoInline;
2026 return Attribute::NoRecurse;
2028 return Attribute::NoMerge;
2030 return Attribute::NonLazyBind;
2032 return Attribute::NonNull;
2034 return Attribute::Dereferenceable;
2036 return Attribute::DereferenceableOrNull;
2038 return Attribute::AllocAlign;
2040 return Attribute::AllocKind;
2042 return Attribute::AllocSize;
2044 return Attribute::AllocatedPointer;
2046 return Attribute::NoRedZone;
2048 return Attribute::NoReturn;
2050 return Attribute::NoSync;
2052 return Attribute::NoCfCheck;
2054 return Attribute::NoProfile;
2056 return Attribute::SkipProfile;
2058 return Attribute::NoUnwind;
2060 return Attribute::NoSanitizeBounds;
2062 return Attribute::NoSanitizeCoverage;
2064 return Attribute::NullPointerIsValid;
2066 return Attribute::OptimizeForDebugging;
2068 return Attribute::OptForFuzzing;
2070 return Attribute::OptimizeForSize;
2072 return Attribute::OptimizeNone;
2074 return Attribute::ReadNone;
2076 return Attribute::ReadOnly;
2078 return Attribute::Returned;
2080 return Attribute::ReturnsTwice;
2082 return Attribute::SExt;
2084 return Attribute::Speculatable;
2086 return Attribute::StackAlignment;
2088 return Attribute::StackProtect;
2090 return Attribute::StackProtectReq;
2092 return Attribute::StackProtectStrong;
2094 return Attribute::SafeStack;
2096 return Attribute::ShadowCallStack;
2098 return Attribute::StrictFP;
2100 return Attribute::StructRet;
2102 return Attribute::SanitizeAddress;
2104 return Attribute::SanitizeHWAddress;
2106 return Attribute::SanitizeThread;
2108 return Attribute::SanitizeMemory;
2110 return Attribute::SpeculativeLoadHardening;
2112 return Attribute::SwiftError;
2114 return Attribute::SwiftSelf;
2116 return Attribute::SwiftAsync;
2118 return Attribute::UWTable;
2120 return Attribute::VScaleRange;
2122 return Attribute::WillReturn;
2124 return Attribute::WriteOnly;
2126 return Attribute::ZExt;
2128 return Attribute::ImmArg;
2130 return Attribute::SanitizeMemTag;
2132 return Attribute::Preallocated;
2134 return Attribute::NoUndef;
2136 return Attribute::ByRef;
2138 return Attribute::MustProgress;
2140 return Attribute::Hot;
2142 return Attribute::PresplitCoroutine;
2144 return Attribute::Writable;
2146 return Attribute::CoroDestroyOnlyWhenComplete;
2148 return Attribute::DeadOnUnwind;
2150 return Attribute::Range;
2159 return error(
"Invalid alignment value");
2167 return error(
"Unknown attribute kind (" +
Twine(Code) +
")");
2172 switch (EncodedKind) {
2196Error BitcodeReader::parseAttributeGroupBlock() {
2200 if (!MAttributeGroups.empty())
2201 return error(
"Invalid multiple blocks");
2212 switch (Entry.Kind) {
2215 return error(
"Malformed block");
2228 switch (MaybeRecord.
get()) {
2233 return error(
"Invalid grp record");
2240 for (
unsigned i = 2, e =
Record.size(); i != e; ++i) {
2248 if (
Error Err = parseAttrKind(EncodedKind, &Kind))
2254 if (Kind == Attribute::ByVal)
2255 B.addByValAttr(
nullptr);
2256 else if (Kind == Attribute::StructRet)
2257 B.addStructRetAttr(
nullptr);
2258 else if (Kind == Attribute::InAlloca)
2259 B.addInAllocaAttr(
nullptr);
2260 else if (Kind == Attribute::UWTable)
2261 B.addUWTableAttr(UWTableKind::Default);
2263 B.addAttribute(Kind);
2265 return error(
"Not an enum attribute");
2266 }
else if (
Record[i] == 1) {
2268 if (
Error Err = parseAttrKind(
Record[++i], &Kind))
2271 return error(
"Not an int attribute");
2272 if (Kind == Attribute::Alignment)
2273 B.addAlignmentAttr(
Record[++i]);
2274 else if (Kind == Attribute::StackAlignment)
2275 B.addStackAlignmentAttr(
Record[++i]);
2276 else if (Kind == Attribute::Dereferenceable)
2277 B.addDereferenceableAttr(
Record[++i]);
2278 else if (Kind == Attribute::DereferenceableOrNull)
2279 B.addDereferenceableOrNullAttr(
Record[++i]);
2280 else if (Kind == Attribute::AllocSize)
2281 B.addAllocSizeAttrFromRawRepr(
Record[++i]);
2282 else if (Kind == Attribute::VScaleRange)
2283 B.addVScaleRangeAttrFromRawRepr(
Record[++i]);
2284 else if (Kind == Attribute::UWTable)
2286 else if (Kind == Attribute::AllocKind)
2288 else if (Kind == Attribute::Memory)
2290 else if (Kind == Attribute::NoFPClass)
2298 while (
Record[i] != 0 && i != e)
2300 assert(
Record[i] == 0 &&
"Kind string not null terminated");
2305 while (
Record[i] != 0 && i != e)
2307 assert(
Record[i] == 0 &&
"Value string not null terminated");
2310 B.addAttribute(KindStr.
str(), ValStr.
str());
2312 bool HasType =
Record[i] == 6;
2314 if (
Error Err = parseAttrKind(
Record[++i], &Kind))
2317 return error(
"Not a type attribute");
2319 B.addTypeAttr(Kind, HasType ? getTypeByID(
Record[++i]) :
nullptr);
2320 }
else if (
Record[i] == 7) {
2324 if (
Error Err = parseAttrKind(
Record[i++], &Kind))
2327 return error(
"Not a ConstantRange attribute");
2334 B.addConstantRangeAttr(Kind, MaybeCR.
get());
2336 return error(
"Invalid attribute group entry");
2341 B.addMemoryAttr(ME);
2351Error BitcodeReader::parseTypeTable() {
2355 return parseTypeTableBody();
2358Error BitcodeReader::parseTypeTableBody() {
2359 if (!TypeList.empty())
2360 return error(
"Invalid multiple blocks");
2363 unsigned NumRecords = 0;
2374 switch (Entry.Kind) {
2377 return error(
"Malformed block");
2379 if (NumRecords != TypeList.size())
2380 return error(
"Malformed block");
2389 Type *ResultTy =
nullptr;
2394 switch (MaybeRecord.
get()) {
2396 return error(
"Invalid value");
2401 return error(
"Invalid numentry record");
2402 TypeList.resize(
Record[0]);
2445 return error(
"Invalid integer record");
2450 return error(
"Bitwidth for integer type out of range");
2457 return error(
"Invalid pointer record");
2461 ResultTy = getTypeByID(
Record[0]);
2463 !PointerType::isValidElementType(ResultTy))
2464 return error(
"Invalid type");
2471 return error(
"Invalid opaque pointer record");
2480 return error(
"Invalid function record");
2482 for (
unsigned i = 3, e =
Record.size(); i != e; ++i) {
2489 ResultTy = getTypeByID(
Record[2]);
2490 if (!ResultTy || ArgTys.
size() <
Record.size()-3)
2491 return error(
"Invalid type");
2494 ResultTy = FunctionType::get(ResultTy, ArgTys,
Record[0]);
2500 return error(
"Invalid function record");
2502 for (
unsigned i = 2, e =
Record.size(); i != e; ++i) {
2504 if (!FunctionType::isValidArgumentType(
T))
2505 return error(
"Invalid function argument type");
2512 ResultTy = getTypeByID(
Record[1]);
2513 if (!ResultTy || ArgTys.
size() <
Record.size()-2)
2514 return error(
"Invalid type");
2517 ResultTy = FunctionType::get(ResultTy, ArgTys,
Record[0]);
2522 return error(
"Invalid anon struct record");
2524 for (
unsigned i = 1, e =
Record.size(); i != e; ++i) {
2531 return error(
"Invalid type");
2538 return error(
"Invalid struct name record");
2543 return error(
"Invalid named struct record");
2545 if (NumRecords >= TypeList.size())
2546 return error(
"Invalid TYPE table");
2549 StructType *Res = cast_or_null<StructType>(TypeList[NumRecords]);
2552 TypeList[NumRecords] =
nullptr;
2554 Res = createIdentifiedStructType(Context, TypeName);
2558 for (
unsigned i = 1, e =
Record.size(); i != e; ++i) {
2565 return error(
"Invalid named struct record");
2573 return error(
"Invalid opaque type record");
2575 if (NumRecords >= TypeList.size())
2576 return error(
"Invalid TYPE table");
2579 StructType *Res = cast_or_null<StructType>(TypeList[NumRecords]);
2582 TypeList[NumRecords] =
nullptr;
2584 Res = createIdentifiedStructType(Context, TypeName);
2591 return error(
"Invalid target extension type record");
2593 if (NumRecords >= TypeList.size())
2594 return error(
"Invalid TYPE table");
2597 return error(
"Too many type parameters");
2599 unsigned NumTys =
Record[0];
2602 for (
unsigned i = 0; i < NumTys; i++) {
2606 return error(
"Invalid type");
2609 for (
unsigned i = NumTys + 1, e =
Record.size(); i < e; i++) {
2610 if (
Record[i] > UINT_MAX)
2611 return error(
"Integer parameter too large");
2620 return error(
"Invalid array type record");
2621 ResultTy = getTypeByID(
Record[1]);
2622 if (!ResultTy || !ArrayType::isValidElementType(ResultTy))
2623 return error(
"Invalid type");
2625 ResultTy = ArrayType::get(ResultTy,
Record[0]);
2630 return error(
"Invalid vector type record");
2632 return error(
"Invalid vector length");
2633 ResultTy = getTypeByID(
Record[1]);
2634 if (!ResultTy || !VectorType::isValidElementType(ResultTy))
2635 return error(
"Invalid type");
2638 ResultTy = VectorType::get(ResultTy,
Record[0], Scalable);
2642 if (NumRecords >= TypeList.size())
2643 return error(
"Invalid TYPE table");
2644 if (TypeList[NumRecords])
2646 "Invalid TYPE table: Only named structs can be forward referenced");
2647 assert(ResultTy &&
"Didn't read a type?");
2648 TypeList[NumRecords] = ResultTy;
2649 if (!ContainedIDs.
empty())
2650 ContainedTypeIDs[NumRecords] = std::move(ContainedIDs);
2655Error BitcodeReader::parseOperandBundleTags() {
2659 if (!BundleTags.empty())
2660 return error(
"Invalid multiple blocks");
2670 switch (Entry.Kind) {
2673 return error(
"Malformed block");
2687 return error(
"Invalid operand bundle record");
2690 BundleTags.emplace_back();
2692 return error(
"Invalid operand bundle record");
2697Error BitcodeReader::parseSyncScopeNames() {
2702 return error(
"Invalid multiple synchronization scope names blocks");
2711 switch (Entry.Kind) {
2714 return error(
"Malformed block");
2717 return error(
"Invalid empty synchronization scope names block");
2731 return error(
"Invalid sync scope record");
2735 return error(
"Invalid sync scope record");
2744 unsigned NameIndex,
Triple &TT) {
2747 return error(
"Invalid record");
2748 unsigned ValueID =
Record[0];
2749 if (ValueID >= ValueList.
size() || !ValueList[ValueID])
2750 return error(
"Invalid record");
2751 Value *
V = ValueList[ValueID];
2754 if (NameStr.contains(0))
2755 return error(
"Invalid value name");
2756 V->setName(NameStr);
2757 auto *GO = dyn_cast<GlobalObject>(V);
2758 if (GO && ImplicitComdatObjects.
contains(GO) &&
TT.supportsCOMDAT())
2771 return std::move(JumpFailed);
2777 return error(
"Expected value symbol table subblock");
2781void BitcodeReader::setDeferredFunctionInfo(
unsigned FuncBitcodeOffsetDelta,
2788 uint64_t FuncBitOffset = FuncWordOffset * 32;
2789 DeferredFunctionInfo[
F] = FuncBitOffset + FuncBitcodeOffsetDelta;
2793 if (FuncBitOffset > LastFunctionBlockBit)
2794 LastFunctionBlockBit = FuncBitOffset;
2798Error BitcodeReader::parseGlobalValueSymbolTable() {
2799 unsigned FuncBitcodeOffsetDelta =
2812 switch (Entry.Kind) {
2815 return error(
"Malformed block");
2826 switch (MaybeRecord.
get()) {
2828 unsigned ValueID =
Record[0];
2829 if (ValueID >= ValueList.
size() || !ValueList[ValueID])
2830 return error(
"Invalid value reference in symbol table");
2831 setDeferredFunctionInfo(FuncBitcodeOffsetDelta,
2832 cast<Function>(ValueList[ValueID]),
Record);
2848 if (!MaybeCurrentBit)
2850 CurrentBit = MaybeCurrentBit.
get();
2853 if (
Error Err = parseGlobalValueSymbolTable())
2855 if (
Error JumpFailed = Stream.JumpToBit(CurrentBit))
2874 unsigned FuncBitcodeOffsetDelta =
2893 switch (Entry.Kind) {
2896 return error(
"Malformed block");
2899 if (
Error JumpFailed = Stream.JumpToBit(CurrentBit))
2912 switch (MaybeRecord.
get()) {
2931 if (
auto *
F = dyn_cast<Function>(V))
2932 setDeferredFunctionInfo(FuncBitcodeOffsetDelta,
F,
Record);
2937 return error(
"Invalid bbentry record");
2940 return error(
"Invalid bbentry record");
2962Error BitcodeReader::resolveGlobalAndIndirectSymbolInits() {
2963 std::vector<std::pair<GlobalVariable *, unsigned>> GlobalInitWorklist;
2964 std::vector<std::pair<GlobalValue *, unsigned>> IndirectSymbolInitWorklist;
2965 std::vector<FunctionOperandInfo> FunctionOperandWorklist;
2967 GlobalInitWorklist.swap(GlobalInits);
2968 IndirectSymbolInitWorklist.swap(IndirectSymbolInits);
2969 FunctionOperandWorklist.swap(FunctionOperands);
2971 while (!GlobalInitWorklist.empty()) {
2972 unsigned ValID = GlobalInitWorklist.back().second;
2975 GlobalInits.push_back(GlobalInitWorklist.back());
2980 GlobalInitWorklist.back().first->setInitializer(MaybeC.
get());
2982 GlobalInitWorklist.pop_back();
2985 while (!IndirectSymbolInitWorklist.empty()) {
2986 unsigned ValID = IndirectSymbolInitWorklist.back().second;
2988 IndirectSymbolInits.push_back(IndirectSymbolInitWorklist.back());
2994 GlobalValue *GV = IndirectSymbolInitWorklist.back().first;
2995 if (
auto *GA = dyn_cast<GlobalAlias>(GV)) {
2997 return error(
"Alias and aliasee types don't match");
2999 }
else if (
auto *GI = dyn_cast<GlobalIFunc>(GV)) {
3002 return error(
"Expected an alias or an ifunc");
3005 IndirectSymbolInitWorklist.pop_back();
3008 while (!FunctionOperandWorklist.empty()) {
3009 FunctionOperandInfo &
Info = FunctionOperandWorklist.back();
3010 if (
Info.PersonalityFn) {
3011 unsigned ValID =
Info.PersonalityFn - 1;
3016 Info.F->setPersonalityFn(MaybeC.
get());
3017 Info.PersonalityFn = 0;
3026 Info.F->setPrefixData(MaybeC.
get());
3030 if (
Info.Prologue) {
3036 Info.F->setPrologueData(MaybeC.
get());
3040 if (
Info.PersonalityFn ||
Info.Prefix ||
Info.Prologue)
3041 FunctionOperands.push_back(Info);
3042 FunctionOperandWorklist.pop_back();
3051 BitcodeReader::decodeSignRotatedValue);
3053 return APInt(TypeBits, Words);
3056Error BitcodeReader::parseConstants() {
3064 unsigned Int32TyID = getVirtualTypeID(CurTy);
3065 unsigned CurTyID = Int32TyID;
3066 Type *CurElemTy =
nullptr;
3067 unsigned NextCstNo = ValueList.
size();
3075 switch (Entry.Kind) {
3078 return error(
"Malformed block");
3080 if (NextCstNo != ValueList.
size())
3081 return error(
"Invalid constant reference");
3095 switch (
unsigned BitCode = MaybeBitCode.
get()) {
3105 return error(
"Invalid settype record");
3106 if (
Record[0] >= TypeList.size() || !TypeList[
Record[0]])
3107 return error(
"Invalid settype record");
3108 if (TypeList[
Record[0]] == VoidType)
3109 return error(
"Invalid constant type");
3111 CurTy = TypeList[CurTyID];
3112 CurElemTy = getPtrElementTypeByID(CurTyID);
3116 return error(
"Invalid type for a constant null value");
3117 if (
auto *TETy = dyn_cast<TargetExtType>(CurTy))
3119 return error(
"Invalid type for a constant null value");
3124 return error(
"Invalid integer const record");
3129 return error(
"Invalid wide integer const record");
3133 V = ConstantInt::get(CurTy, VInt);
3138 return error(
"Invalid float const record");
3141 if (ScalarTy->isHalfTy())
3142 V = ConstantFP::get(CurTy,
APFloat(APFloat::IEEEhalf(),
3144 else if (ScalarTy->isBFloatTy())
3145 V = ConstantFP::get(
3147 else if (ScalarTy->isFloatTy())
3148 V = ConstantFP::get(CurTy,
APFloat(APFloat::IEEEsingle(),
3150 else if (ScalarTy->isDoubleTy())
3151 V = ConstantFP::get(
3153 else if (ScalarTy->isX86_FP80Ty()) {
3156 Rearrange[0] = (
Record[1] & 0xffffLL) | (
Record[0] << 16);
3157 Rearrange[1] =
Record[0] >> 48;
3158 V = ConstantFP::get(
3159 CurTy,
APFloat(APFloat::x87DoubleExtended(),
APInt(80, Rearrange)));
3160 }
else if (ScalarTy->isFP128Ty())
3161 V = ConstantFP::get(CurTy,
3163 else if (ScalarTy->isPPC_FP128Ty())
3164 V = ConstantFP::get(
3173 return error(
"Invalid aggregate record");
3177 for (
unsigned i = 0; i !=
Size; ++i)
3180 if (isa<StructType>(CurTy)) {
3181 V = BitcodeConstant::create(
3182 Alloc, CurTy, BitcodeConstant::ConstantStructOpcode, Elts);
3183 }
else if (isa<ArrayType>(CurTy)) {
3184 V = BitcodeConstant::create(Alloc, CurTy,
3185 BitcodeConstant::ConstantArrayOpcode, Elts);
3186 }
else if (isa<VectorType>(CurTy)) {
3187 V = BitcodeConstant::create(
3188 Alloc, CurTy, BitcodeConstant::ConstantVectorOpcode, Elts);
3197 return error(
"Invalid string record");
3206 return error(
"Invalid data record");
3209 if (
auto *Array = dyn_cast<ArrayType>(CurTy))
3210 EltTy =
Array->getElementType();
3212 EltTy = cast<VectorType>(CurTy)->getElementType();
3215 if (isa<VectorType>(CurTy))
3221 if (isa<VectorType>(CurTy))
3227 if (isa<VectorType>(CurTy))
3233 if (isa<VectorType>(CurTy))
3239 if (isa<VectorType>(CurTy))
3245 if (isa<VectorType>(CurTy))
3251 if (isa<VectorType>(CurTy))
3257 if (isa<VectorType>(CurTy))
3262 return error(
"Invalid type for value");
3268 return error(
"Invalid unary op constexpr record");
3273 V = BitcodeConstant::create(Alloc, CurTy, Opc, (
unsigned)
Record[1]);
3279 return error(
"Invalid binary op constexpr record");
3285 if (
Record.size() >= 4) {
3286 if (Opc == Instruction::Add ||
3287 Opc == Instruction::Sub ||
3288 Opc == Instruction::Mul ||
3289 Opc == Instruction::Shl) {
3294 }
else if (Opc == Instruction::SDiv ||
3295 Opc == Instruction::UDiv ||
3296 Opc == Instruction::LShr ||
3297 Opc == Instruction::AShr) {
3302 V = BitcodeConstant::create(Alloc, CurTy, {(uint8_t)Opc, Flags},
3309 return error(
"Invalid cast constexpr record");
3314 unsigned OpTyID =
Record[1];
3315 Type *OpTy = getTypeByID(OpTyID);
3317 return error(
"Invalid cast constexpr record");
3318 V = BitcodeConstant::create(Alloc, CurTy, Opc, (
unsigned)
Record[2]);
3329 return error(
"Constant GEP record must have at least two elements");
3331 Type *PointeeType =
nullptr;
3334 PointeeType = getTypeByID(
Record[OpNum++]);
3336 bool InBounds =
false;
3337 std::optional<ConstantRange>
InRange;
3341 unsigned InRangeIndex =
Op >> 1;
3356 unsigned BaseTypeID =
Record[OpNum];
3357 while (OpNum !=
Record.size()) {
3358 unsigned ElTyID =
Record[OpNum++];
3359 Type *ElTy = getTypeByID(ElTyID);
3361 return error(
"Invalid getelementptr constexpr record");
3365 if (Elts.
size() < 1)
3366 return error(
"Invalid gep with no operands");
3370 BaseTypeID = getContainedTypeID(BaseTypeID, 0);
3371 BaseType = getTypeByID(BaseTypeID);
3376 return error(
"GEP base operand must be pointer or vector of pointer");
3379 PointeeType = getPtrElementTypeByID(BaseTypeID);
3381 return error(
"Missing element type for old-style constant GEP");
3384 V = BitcodeConstant::create(
3386 {Instruction::GetElementPtr, InBounds, PointeeType,
InRange}, Elts);
3391 return error(
"Invalid select constexpr record");
3393 V = BitcodeConstant::create(
3394 Alloc, CurTy, Instruction::Select,
3401 return error(
"Invalid extractelement constexpr record");
3402 unsigned OpTyID =
Record[0];
3404 dyn_cast_or_null<VectorType>(getTypeByID(OpTyID));
3406 return error(
"Invalid extractelement constexpr record");
3408 if (
Record.size() == 4) {
3409 unsigned IdxTyID =
Record[2];
3410 Type *IdxTy = getTypeByID(IdxTyID);
3412 return error(
"Invalid extractelement constexpr record");
3418 V = BitcodeConstant::create(Alloc, CurTy, Instruction::ExtractElement,
3424 VectorType *OpTy = dyn_cast<VectorType>(CurTy);
3425 if (
Record.size() < 3 || !OpTy)
3426 return error(
"Invalid insertelement constexpr record");
3428 if (
Record.size() == 4) {
3429 unsigned IdxTyID =
Record[2];
3430 Type *IdxTy = getTypeByID(IdxTyID);
3432 return error(
"Invalid insertelement constexpr record");
3438 V = BitcodeConstant::create(
3439 Alloc, CurTy, Instruction::InsertElement,
3444 VectorType *OpTy = dyn_cast<VectorType>(CurTy);
3445 if (
Record.size() < 3 || !OpTy)
3446 return error(
"Invalid shufflevector constexpr record");
3447 V = BitcodeConstant::create(
3448 Alloc, CurTy, Instruction::ShuffleVector,
3453 VectorType *RTy = dyn_cast<VectorType>(CurTy);
3455 dyn_cast_or_null<VectorType>(getTypeByID(
Record[0]));
3456 if (
Record.size() < 4 || !RTy || !OpTy)
3457 return error(
"Invalid shufflevector constexpr record");
3458 V = BitcodeConstant::create(
3459 Alloc, CurTy, Instruction::ShuffleVector,
3465 return error(
"Invalid cmp constexpt record");
3466 unsigned OpTyID =
Record[0];
3467 Type *OpTy = getTypeByID(OpTyID);
3469 return error(
"Invalid cmp constexpr record");
3470 V = BitcodeConstant::create(
3473 : Instruction::ICmp),
3482 return error(
"Invalid inlineasm record");
3483 std::string AsmStr, ConstrStr;
3484 bool HasSideEffects =
Record[0] & 1;
3485 bool IsAlignStack =
Record[0] >> 1;
3486 unsigned AsmStrSize =
Record[1];
3487 if (2+AsmStrSize >=
Record.size())
3488 return error(
"Invalid inlineasm record");
3489 unsigned ConstStrSize =
Record[2+AsmStrSize];
3490 if (3+AsmStrSize+ConstStrSize >
Record.size())
3491 return error(
"Invalid inlineasm record");
3493 for (
unsigned i = 0; i != AsmStrSize; ++i)
3494 AsmStr += (
char)
Record[2+i];
3495 for (
unsigned i = 0; i != ConstStrSize; ++i)
3496 ConstrStr += (
char)
Record[3+AsmStrSize+i];
3499 return error(
"Missing element type for old-style inlineasm");
3501 HasSideEffects, IsAlignStack);
3508 return error(
"Invalid inlineasm record");
3509 std::string AsmStr, ConstrStr;
3510 bool HasSideEffects =
Record[0] & 1;
3511 bool IsAlignStack = (
Record[0] >> 1) & 1;
3512 unsigned AsmDialect =
Record[0] >> 2;
3513 unsigned AsmStrSize =
Record[1];
3514 if (2+AsmStrSize >=
Record.size())
3515 return error(
"Invalid inlineasm record");
3516 unsigned ConstStrSize =
Record[2+AsmStrSize];
3517 if (3+AsmStrSize+ConstStrSize >
Record.size())
3518 return error(
"Invalid inlineasm record");
3520 for (
unsigned i = 0; i != AsmStrSize; ++i)
3521 AsmStr += (
char)
Record[2+i];
3522 for (
unsigned i = 0; i != ConstStrSize; ++i)
3523 ConstrStr += (
char)
Record[3+AsmStrSize+i];
3526 return error(
"Missing element type for old-style inlineasm");
3528 HasSideEffects, IsAlignStack,
3535 return error(
"Invalid inlineasm record");
3537 std::string AsmStr, ConstrStr;
3538 bool HasSideEffects =
Record[OpNum] & 1;
3539 bool IsAlignStack = (
Record[OpNum] >> 1) & 1;
3540 unsigned AsmDialect = (
Record[OpNum] >> 2) & 1;
3541 bool CanThrow = (
Record[OpNum] >> 3) & 1;
3543 unsigned AsmStrSize =
Record[OpNum];
3545 if (OpNum + AsmStrSize >=
Record.size())
3546 return error(
"Invalid inlineasm record");
3547 unsigned ConstStrSize =
Record[OpNum + AsmStrSize];
3548 if (OpNum + 1 + AsmStrSize + ConstStrSize >
Record.size())
3549 return error(
"Invalid inlineasm record");
3551 for (
unsigned i = 0; i != AsmStrSize; ++i)
3552 AsmStr += (
char)
Record[OpNum + i];
3554 for (
unsigned i = 0; i != ConstStrSize; ++i)
3555 ConstrStr += (
char)
Record[OpNum + AsmStrSize + i];
3558 return error(
"Missing element type for old-style inlineasm");
3560 HasSideEffects, IsAlignStack,
3567 return error(
"Invalid inlineasm record");
3569 auto *FnTy = dyn_cast_or_null<FunctionType>(getTypeByID(
Record[OpNum]));
3572 return error(
"Invalid inlineasm record");
3573 std::string AsmStr, ConstrStr;
3574 bool HasSideEffects =
Record[OpNum] & 1;
3575 bool IsAlignStack = (
Record[OpNum] >> 1) & 1;
3576 unsigned AsmDialect = (
Record[OpNum] >> 2) & 1;
3577 bool CanThrow = (
Record[OpNum] >> 3) & 1;
3579 unsigned AsmStrSize =
Record[OpNum];
3581 if (OpNum + AsmStrSize >=
Record.size())
3582 return error(
"Invalid inlineasm record");
3583 unsigned ConstStrSize =
Record[OpNum + AsmStrSize];
3584 if (OpNum + 1 + AsmStrSize + ConstStrSize >
Record.size())
3585 return error(
"Invalid inlineasm record");
3587 for (
unsigned i = 0; i != AsmStrSize; ++i)
3588 AsmStr += (
char)
Record[OpNum + i];
3590 for (
unsigned i = 0; i != ConstStrSize; ++i)
3591 ConstrStr += (
char)
Record[OpNum + AsmStrSize + i];
3593 V =
InlineAsm::get(FnTy, AsmStr, ConstrStr, HasSideEffects, IsAlignStack,
3599 return error(
"Invalid blockaddress record");
3600 unsigned FnTyID =
Record[0];
3601 Type *FnTy = getTypeByID(FnTyID);
3603 return error(
"Invalid blockaddress record");
3604 V = BitcodeConstant::create(
3612 return error(
"Invalid dso_local record");
3613 unsigned GVTyID =
Record[0];
3614 Type *GVTy = getTypeByID(GVTyID);
3616 return error(
"Invalid dso_local record");
3617 V = BitcodeConstant::create(
3618 Alloc, CurTy, BitcodeConstant::DSOLocalEquivalentOpcode,
Record[1]);
3623 return error(
"Invalid no_cfi record");
3624 unsigned GVTyID =
Record[0];
3625 Type *GVTy = getTypeByID(GVTyID);
3627 return error(
"Invalid no_cfi record");
3628 V = BitcodeConstant::create(Alloc, CurTy, BitcodeConstant::NoCFIOpcode,
3634 assert(
V->getType() == getTypeByID(CurTyID) &&
"Incorrect result type ID");
3641Error BitcodeReader::parseUseLists() {
3654 switch (Entry.Kind) {
3657 return error(
"Malformed block");
3671 switch (MaybeRecord.
get()) {
3679 if (RecordLength < 3)
3681 return error(
"Invalid record");
3682 unsigned ID =
Record.pop_back_val();
3686 assert(
ID < FunctionBBs.size() &&
"Basic block not found");
3687 V = FunctionBBs[
ID];
3690 unsigned NumUses = 0;
3692 for (
const Use &U :
V->materialized_uses()) {
3693 if (++NumUses >
Record.size())
3695 Order[&
U] =
Record[NumUses - 1];
3702 V->sortUseList([&](
const Use &L,
const Use &R) {
3713Error BitcodeReader::rememberAndSkipMetadata() {
3715 uint64_t CurBit = Stream.GetCurrentBitNo();
3716 DeferredMetadataInfo.push_back(CurBit);
3719 if (
Error Err = Stream.SkipBlock())
3724Error BitcodeReader::materializeMetadata() {
3725 for (
uint64_t BitPos : DeferredMetadataInfo) {
3727 if (
Error JumpFailed = Stream.JumpToBit(BitPos))
3729 if (
Error Err = MDLoader->parseModuleMetadata())
3740 for (
const MDOperand &MDOptions : cast<MDNode>(Val)->operands())
3741 LinkerOpts->
addOperand(cast<MDNode>(MDOptions));
3745 DeferredMetadataInfo.clear();
3749void BitcodeReader::setStripDebugInfo() {
StripDebugInfo =
true; }
3753Error BitcodeReader::rememberAndSkipFunctionBody() {
3755 if (FunctionsWithBodies.empty())
3756 return error(
"Insufficient function protos");
3759 FunctionsWithBodies.pop_back();
3762 uint64_t CurBit = Stream.GetCurrentBitNo();
3764 (DeferredFunctionInfo[Fn] == 0 || DeferredFunctionInfo[Fn] == CurBit) &&
3765 "Mismatch between VST and scanned function offsets");
3766 DeferredFunctionInfo[Fn] = CurBit;
3769 if (
Error Err = Stream.SkipBlock())
3774Error BitcodeReader::globalCleanup() {
3776 if (
Error Err = resolveGlobalAndIndirectSymbolInits())
3778 if (!GlobalInits.empty() || !IndirectSymbolInits.empty())
3779 return error(
"Malformed global initializer set");
3784 MDLoader->upgradeDebugIntrinsics(
F);
3791 UpgradedIntrinsics[&
F] = NewFn;
3797 std::vector<std::pair<GlobalVariable *, GlobalVariable *>> UpgradedVariables;
3800 UpgradedVariables.emplace_back(&GV, Upgraded);
3801 for (
auto &Pair : UpgradedVariables) {
3802 Pair.first->eraseFromParent();
3803 TheModule->insertGlobalVariable(Pair.second);
3808 std::vector<std::pair<GlobalVariable *, unsigned>>().
swap(GlobalInits);
3809 std::vector<std::pair<GlobalValue *, unsigned>>().
swap(IndirectSymbolInits);
3817Error BitcodeReader::rememberAndSkipFunctionBodies() {
3818 if (
Error JumpFailed = Stream.JumpToBit(NextUnreadBit))
3821 if (Stream.AtEndOfStream())
3822 return error(
"Could not find function in stream");
3824 if (!SeenFirstFunctionBody)
3825 return error(
"Trying to materialize functions before seeing function blocks");
3829 assert(SeenValueSymbolTable);
3839 switch (Entry.Kind) {
3841 return error(
"Expect SubBlock");
3845 return error(
"Expect function block");
3847 if (
Error Err = rememberAndSkipFunctionBody())
3849 NextUnreadBit = Stream.GetCurrentBitNo();
3856Error BitcodeReaderBase::readBlockInfo() {
3858 Stream.ReadBlockInfoBlock();
3859 if (!MaybeNewBlockInfo)
3861 std::optional<BitstreamBlockInfo> NewBlockInfo =
3862 std::move(MaybeNewBlockInfo.
get());
3864 return error(
"Malformed block");
3865 BlockInfo = std::move(*NewBlockInfo);
3876 return error(
"Invalid record");
3878 std::string OldFormatName;
3881 return error(
"Invalid record");
3882 unsigned ComdatNameSize =
Record[1];
3883 if (ComdatNameSize >
Record.size() - 2)
3884 return error(
"Comdat name size too large");
3885 OldFormatName.reserve(ComdatNameSize);
3886 for (
unsigned i = 0; i != ComdatNameSize; ++i)
3887 OldFormatName += (
char)
Record[2 + i];
3888 Name = OldFormatName;
3891 C->setSelectionKind(SK);
3892 ComdatList.push_back(
C);
3906 Meta.NoAddress =
true;
3908 Meta.NoHWAddress =
true;
3912 Meta.IsDynInit =
true;
3927 return error(
"Invalid record");
3928 unsigned TyID =
Record[0];
3929 Type *Ty = getTypeByID(TyID);
3931 return error(
"Invalid record");
3933 bool explicitType =
Record[1] & 2;
3939 return error(
"Invalid type for value");
3940 AddressSpace = cast<PointerType>(Ty)->getAddressSpace();
3941 TyID = getContainedTypeID(TyID);
3942 Ty = getTypeByID(TyID);
3944 return error(
"Missing element type for old-style global");
3950 if (
Error Err = parseAlignmentValue(
Record[4], Alignment))
3954 if (
Record[5] - 1 >= SectionTable.size())
3955 return error(
"Invalid ID");
3972 bool ExternallyInitialized =
false;
3974 ExternallyInitialized =
Record[9];
3986 if (
Record.size() > 10) {
3998 if (
unsigned InitID =
Record[2])
3999 GlobalInits.push_back(std::make_pair(NewGV, InitID - 1));
4001 if (
Record.size() > 11) {
4002 if (
unsigned ComdatID =
Record[11]) {
4003 if (ComdatID > ComdatList.size())
4004 return error(
"Invalid global variable comdat ID");
4005 NewGV->
setComdat(ComdatList[ComdatID - 1]);
4008 ImplicitComdatObjects.
insert(NewGV);
4011 if (
Record.size() > 12) {
4016 if (
Record.size() > 13) {
4035 return error(
"Invalid global variable code model");
4041void BitcodeReader::callValueTypeCallback(
Value *
F,
unsigned TypeID) {
4042 if (ValueTypeCallback) {
4043 (*ValueTypeCallback)(
4044 F,
TypeID, [
this](
unsigned I) {
return getTypeByID(
I); },
4045 [
this](
unsigned I,
unsigned J) {
return getContainedTypeID(
I, J); });
4058 return error(
"Invalid record");
4059 unsigned FTyID =
Record[0];
4060 Type *FTy = getTypeByID(FTyID);
4062 return error(
"Invalid record");
4063 if (isa<PointerType>(FTy)) {
4064 FTyID = getContainedTypeID(FTyID, 0);
4065 FTy = getTypeByID(FTyID);
4067 return error(
"Missing element type for old-style function");
4070 if (!isa<FunctionType>(FTy))
4071 return error(
"Invalid type for value");
4074 return error(
"Invalid calling convention ID");
4076 unsigned AddrSpace = TheModule->getDataLayout().getProgramAddressSpace();
4082 AddrSpace,
Name, TheModule);
4085 "Incorrect fully specified type provided for function");
4086 FunctionTypeIDs[
Func] = FTyID;
4088 Func->setCallingConv(
CC);
4089 bool isProto =
Record[2];
4093 callValueTypeCallback(Func, FTyID);
4098 for (
unsigned i = 0; i !=
Func->arg_size(); ++i) {
4100 Attribute::InAlloca}) {
4101 if (!
Func->hasParamAttribute(i, Kind))
4104 if (
Func->getParamAttribute(i, Kind).getValueAsType())
4107 Func->removeParamAttr(i, Kind);
4109 unsigned ParamTypeID = getContainedTypeID(FTyID, i + 1);
4110 Type *PtrEltTy = getPtrElementTypeByID(ParamTypeID);
4112 return error(
"Missing param element type for attribute upgrade");
4116 case Attribute::ByVal:
4119 case Attribute::StructRet:
4122 case Attribute::InAlloca:
4129 Func->addParamAttr(i, NewAttr);
4134 !
Func->arg_empty() && !
Func->hasParamAttribute(0, Attribute::ByVal)) {
4135 unsigned ParamTypeID = getContainedTypeID(FTyID, 1);
4136 Type *ByValTy = getPtrElementTypeByID(ParamTypeID);
4138 return error(
"Missing param element type for x86_intrcc upgrade");
4140 Func->addParamAttr(0, NewAttr);
4144 if (
Error Err = parseAlignmentValue(
Record[5], Alignment))
4147 Func->setAlignment(*Alignment);
4149 if (
Record[6] - 1 >= SectionTable.size())
4150 return error(
"Invalid ID");
4151 Func->setSection(SectionTable[
Record[6] - 1]);
4155 if (!
Func->hasLocalLinkage())
4158 if (
Record[8] - 1 >= GCTable.size())
4159 return error(
"Invalid ID");
4165 Func->setUnnamedAddr(UnnamedAddr);
4167 FunctionOperandInfo OperandInfo = {
Func, 0, 0, 0};
4169 OperandInfo.Prologue =
Record[10];
4171 if (
Record.size() > 11) {
4173 if (!
Func->hasLocalLinkage()) {
4180 if (
Record.size() > 12) {
4181 if (
unsigned ComdatID =
Record[12]) {
4182 if (ComdatID > ComdatList.size())
4183 return error(
"Invalid function comdat ID");
4184 Func->setComdat(ComdatList[ComdatID - 1]);
4187 ImplicitComdatObjects.
insert(Func);
4191 OperandInfo.Prefix =
Record[13];
4194 OperandInfo.PersonalityFn =
Record[14];
4196 if (
Record.size() > 15) {
4205 if (
Record.size() > 18 && Strtab.data() &&
4210 ValueList.
push_back(Func, getVirtualTypeID(
Func->getType(), FTyID));
4212 if (OperandInfo.PersonalityFn || OperandInfo.Prefix || OperandInfo.Prologue)
4213 FunctionOperands.push_back(OperandInfo);
4218 Func->setIsMaterializable(
true);
4219 FunctionsWithBodies.push_back(Func);
4220 DeferredFunctionInfo[
Func] = 0;
4225Error BitcodeReader::parseGlobalIndirectSymbolRecord(
4239 if (
Record.size() < (3 + (
unsigned)NewRecord))
4240 return error(
"Invalid record");
4245 return error(
"Invalid record");
4249 auto *PTy = dyn_cast<PointerType>(Ty);
4251 return error(
"Invalid type for value");
4252 AddrSpace = PTy->getAddressSpace();
4254 Ty = getTypeByID(
TypeID);
4256 return error(
"Missing element type for old-style indirect symbol");
4258 AddrSpace =
Record[OpNum++];
4261 auto Val =
Record[OpNum++];
4270 nullptr, TheModule);
4274 if (OpNum !=
Record.size()) {
4275 auto VisInd = OpNum++;
4281 if (OpNum !=
Record.size()) {
4282 auto S =
Record[OpNum++];
4289 if (OpNum !=
Record.size())
4291 if (OpNum !=
Record.size())
4294 if (OpNum !=
Record.size())
4299 if (OpNum + 1 <
Record.size()) {
4302 return error(
"Malformed partition, too large.");
4309 IndirectSymbolInits.push_back(std::make_pair(NewGA, Val));
4314 bool ShouldLazyLoadMetadata,
4320 TheModule->IsNewDbgInfoFormat =
4325 this->ValueTypeCallback = std::move(Callbacks.
ValueType);
4327 if (
Error JumpFailed = Stream.JumpToBit(ResumeBit))
4336 bool ResolvedDataLayout =
false;
4341 std::string TentativeDataLayoutStr = TheModule->getDataLayoutStr();
4343 auto ResolveDataLayout = [&]() ->
Error {
4344 if (ResolvedDataLayout)
4348 ResolvedDataLayout =
true;
4352 TentativeDataLayoutStr, TheModule->getTargetTriple());
4356 if (
auto LayoutOverride = (*Callbacks.
DataLayout)(
4357 TheModule->getTargetTriple(), TentativeDataLayoutStr))
4358 TentativeDataLayoutStr = *LayoutOverride;
4366 TheModule->setDataLayout(MaybeDL.
get());
4377 switch (Entry.Kind) {
4379 return error(
"Malformed block");
4381 if (
Error Err = ResolveDataLayout())
4383 return globalCleanup();
4388 if (
Error Err = Stream.SkipBlock())
4392 if (
Error Err = readBlockInfo())
4396 if (
Error Err = parseAttributeBlock())
4400 if (
Error Err = parseAttributeGroupBlock())
4404 if (
Error Err = parseTypeTable())
4408 if (!SeenValueSymbolTable) {
4414 assert(VSTOffset == 0 || FunctionsWithBodies.empty());
4415 if (
Error Err = parseValueSymbolTable())
4417 SeenValueSymbolTable =
true;
4422 if (
Error Err = Stream.SkipBlock())
4427 if (
Error Err = parseConstants())
4429 if (
Error Err = resolveGlobalAndIndirectSymbolInits())
4433 if (ShouldLazyLoadMetadata) {
4434 if (
Error Err = rememberAndSkipMetadata())
4438 assert(DeferredMetadataInfo.empty() &&
"Unexpected deferred metadata");
4439 if (
Error Err = MDLoader->parseModuleMetadata())
4443 if (
Error Err = MDLoader->parseMetadataKinds())
4447 if (
Error Err = ResolveDataLayout())
4452 if (!SeenFirstFunctionBody) {
4453 std::reverse(FunctionsWithBodies.begin(), FunctionsWithBodies.end());
4454 if (
Error Err = globalCleanup())
4456 SeenFirstFunctionBody =
true;
4459 if (VSTOffset > 0) {
4463 if (!SeenValueSymbolTable) {
4464 if (
Error Err = BitcodeReader::parseValueSymbolTable(VSTOffset))
4466 SeenValueSymbolTable =
true;
4478 if (
Error Err = Stream.SkipBlock())
4488 if (
Error Err = rememberAndSkipFunctionBody())
4495 if (SeenValueSymbolTable) {
4496 NextUnreadBit = Stream.GetCurrentBitNo();
4499 return globalCleanup();
4503 if (
Error Err = parseUseLists())
4507 if (
Error Err = parseOperandBundleTags())
4511 if (
Error Err = parseSyncScopeNames())
4526 switch (
unsigned BitCode = MaybeBitCode.
get()) {
4532 UseRelativeIDs = *VersionOrErr >= 1;
4536 if (ResolvedDataLayout)
4537 return error(
"target triple too late in module");
4540 return error(
"Invalid record");
4541 TheModule->setTargetTriple(S);
4545 if (ResolvedDataLayout)
4546 return error(
"datalayout too late in module");
4548 return error(
"Invalid record");
4554 return error(
"Invalid record");
4555 TheModule->setModuleInlineAsm(S);
4562 return error(
"Invalid record");
4569 return error(
"Invalid record");
4570 SectionTable.push_back(S);
4576 return error(
"Invalid record");
4577 GCTable.push_back(S);
4594 if (
Error Err = ResolveDataLayout())
4602 if (
Error Err = parseGlobalIndirectSymbolRecord(BitCode,
Record))
4608 return error(
"Invalid record");
4612 VSTOffset =
Record[0] - 1;
4618 return error(
"Invalid record");
4619 TheModule->setSourceFileName(
ValueName);
4624 this->ValueTypeCallback = std::nullopt;
4628Error BitcodeReader::parseBitcodeInto(
Module *M,
bool ShouldLazyLoadMetadata,
4633 MDCallbacks.
GetTypeByID = [&](
unsigned ID) {
return getTypeByID(
ID); };
4635 return getContainedTypeID(
I, J);
4638 MDLoader =
MetadataLoader(Stream, *M, ValueList, IsImporting, MDCallbacks);
4639 return parseModule(0, ShouldLazyLoadMetadata, Callbacks);
4642Error BitcodeReader::typeCheckLoadStoreInst(
Type *ValType,
Type *PtrType) {
4643 if (!isa<PointerType>(PtrType))
4644 return error(
"Load/Store operand is not a pointer type");
4645 if (!PointerType::isLoadableOrStorableType(ValType))
4646 return error(
"Cannot load/store from pointer");
4653 for (
unsigned i = 0; i != CB->
arg_size(); ++i) {
4655 Attribute::InAlloca}) {
4656 if (!
Attrs.hasParamAttr(i, Kind) ||
4657 Attrs.getParamAttr(i, Kind).getValueAsType())
4660 Type *PtrEltTy = getPtrElementTypeByID(ArgTyIDs[i]);
4662 return error(
"Missing element type for typed attribute upgrade");
4666 case Attribute::ByVal:
4669 case Attribute::StructRet:
4672 case Attribute::InAlloca:
4679 Attrs =
Attrs.addParamAttribute(Context, i, NewAttr);
4690 if (CI.isIndirect && !
Attrs.getParamElementType(ArgNo)) {
4691 Type *ElemTy = getPtrElementTypeByID(ArgTyIDs[ArgNo]);
4693 return error(
"Missing element type for inline asm upgrade");
4704 case Intrinsic::preserve_array_access_index:
4705 case Intrinsic::preserve_struct_access_index:
4706 case Intrinsic::aarch64_ldaxr:
4707 case Intrinsic::aarch64_ldxr:
4708 case Intrinsic::aarch64_stlxr:
4709 case Intrinsic::aarch64_stxr:
4710 case Intrinsic::arm_ldaex:
4711 case Intrinsic::arm_ldrex:
4712 case Intrinsic::arm_stlex:
4713 case Intrinsic::arm_strex: {
4716 case Intrinsic::aarch64_stlxr:
4717 case Intrinsic::aarch64_stxr:
4718 case Intrinsic::arm_stlex:
4719 case Intrinsic::arm_strex:
4726 if (!
Attrs.getParamElementType(ArgNo)) {
4727 Type *ElTy = getPtrElementTypeByID(ArgTyIDs[ArgNo]);
4729 return error(
"Missing element type for elementtype upgrade");
4731 Attrs =
Attrs.addParamAttribute(Context, ArgNo, NewAttr);
4749 if (MDLoader->hasFwdRefs())
4750 return error(
"Invalid function metadata: incoming forward references");
4752 InstructionList.
clear();
4753 unsigned ModuleValueListSize = ValueList.
size();
4754 unsigned ModuleMDLoaderSize = MDLoader->size();
4758 unsigned FTyID = FunctionTypeIDs[
F];
4760 unsigned ArgTyID = getContainedTypeID(FTyID, ArgNo + 1);
4761 assert(
I.getType() == getTypeByID(ArgTyID) &&
4762 "Incorrect fully specified type for Function Argument");
4766 unsigned NextValueNo = ValueList.
size();
4768 unsigned CurBBNo = 0;
4777 auto getLastInstruction = [&]() ->
Instruction * {
4778 if (CurBB && !CurBB->
empty())
4779 return &CurBB->
back();
4780 else if (CurBBNo && FunctionBBs[CurBBNo - 1] &&
4781 !FunctionBBs[CurBBNo - 1]->empty())
4782 return &FunctionBBs[CurBBNo - 1]->back();
4786 std::vector<OperandBundleDef> OperandBundles;
4797 switch (Entry.Kind) {
4799 return error(
"Malformed block");
4801 goto OutOfRecordLoop;
4806 if (
Error Err = Stream.SkipBlock())
4810 if (
Error Err = parseConstants())
4812 NextValueNo = ValueList.
size();
4815 if (
Error Err = parseValueSymbolTable())
4819 if (
Error Err = MDLoader->parseMetadataAttachment(*
F, InstructionList))
4823 assert(DeferredMetadataInfo.empty() &&
4824 "Must read all module-level metadata before function-level");
4825 if (
Error Err = MDLoader->parseFunctionMetadata())
4829 if (
Error Err = parseUseLists())
4843 unsigned ResTypeID = InvalidTypeID;
4847 switch (
unsigned BitCode = MaybeBitCode.
get()) {
4849 return error(
"Invalid value");
4852 return error(
"Invalid record");
4854 FunctionBBs.resize(
Record[0]);
4857 auto BBFRI = BasicBlockFwdRefs.
find(
F);
4858 if (BBFRI == BasicBlockFwdRefs.
end()) {
4862 auto &BBRefs = BBFRI->second;
4864 if (BBRefs.size() > FunctionBBs.size())
4865 return error(
"Invalid ID");
4866 assert(!BBRefs.empty() &&
"Unexpected empty array");
4867 assert(!BBRefs.front() &&
"Invalid reference to entry block");
4868 for (
unsigned I = 0, E = FunctionBBs.size(), RE = BBRefs.size();
I != E;
4870 if (
I < RE && BBRefs[
I]) {
4871 BBRefs[
I]->insertInto(
F);
4872 FunctionBBs[
I] = BBRefs[
I];
4878 BasicBlockFwdRefs.
erase(BBFRI);
4881 CurBB = FunctionBBs[0];
4888 return error(
"Invalid record");
4903 if (
auto *
F = dyn_cast<Function>(ValueList[
ValID]))
4904 BackwardRefFunctions.push_back(
F);
4906 return error(
"Invalid record");
4913 I = getLastInstruction();
4916 return error(
"Invalid record");
4917 I->setDebugLoc(LastLoc);
4922 I = getLastInstruction();
4924 return error(
"Invalid record");
4932 Scope = dyn_cast_or_null<MDNode>(
4933 MDLoader->getMetadataFwdRefOrLoad(ScopeID - 1));
4935 return error(
"Invalid record");
4938 IA = dyn_cast_or_null<MDNode>(
4939 MDLoader->getMetadataFwdRefOrLoad(IAID - 1));
4941 return error(
"Invalid record");
4943 LastLoc = DILocation::get(
Scope->getContext(), Line, Col, Scope, IA,
4945 I->setDebugLoc(LastLoc);
4953 if (getValueTypePair(
Record, OpNum, NextValueNo, LHS,
TypeID, CurBB) ||
4955 return error(
"Invalid record");
4959 return error(
"Invalid record");
4963 if (OpNum <
Record.size()) {
4964 if (isa<FPMathOperator>(
I)) {
4967 I->setFastMathFlags(FMF);
4976 if (getValueTypePair(
Record, OpNum, NextValueNo, LHS,
TypeID, CurBB) ||
4980 return error(
"Invalid record");
4984 return error(
"Invalid record");
4988 if (OpNum <
Record.size()) {
4989 if (Opc == Instruction::Add ||
4990 Opc == Instruction::Sub ||
4991 Opc == Instruction::Mul ||
4992 Opc == Instruction::Shl) {
4994 cast<BinaryOperator>(
I)->setHasNoSignedWrap(
true);
4996 cast<BinaryOperator>(
I)->setHasNoUnsignedWrap(
true);
4997 }
else if (Opc == Instruction::SDiv ||
4998 Opc == Instruction::UDiv ||
4999 Opc == Instruction::LShr ||
5000 Opc == Instruction::AShr) {
5002 cast<BinaryOperator>(
I)->setIsExact(
true);
5003 }
else if (Opc == Instruction::Or) {
5005 cast<PossiblyDisjointInst>(
I)->setIsDisjoint(
true);
5006 }
else if (isa<FPMathOperator>(
I)) {
5009 I->setFastMathFlags(FMF);
5018 if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB) ||
5019 OpNum + 1 >
Record.size())
5020 return error(
"Invalid record");
5022 ResTypeID =
Record[OpNum++];
5023 Type *ResTy = getTypeByID(ResTypeID);
5026 if (Opc == -1 || !ResTy)
5027 return error(
"Invalid record");
5032 assert(CurBB &&
"No current BB?");
5038 return error(
"Invalid cast");
5042 if (OpNum <
Record.size()) {
5043 if (Opc == Instruction::ZExt || Opc == Instruction::UIToFP) {
5045 cast<PossiblyNonNegInst>(
I)->setNonNeg(
true);
5046 }
else if (Opc == Instruction::Trunc) {
5048 cast<TruncInst>(
I)->setHasNoUnsignedWrap(
true);
5050 cast<TruncInst>(
I)->setHasNoSignedWrap(
true);
5067 InBounds =
Record[OpNum++];
5069 Ty = getTypeByID(TyID);
5072 TyID = InvalidTypeID;
5077 unsigned BasePtrTypeID;
5078 if (getValueTypePair(
Record, OpNum, NextValueNo, BasePtr, BasePtrTypeID,
5080 return error(
"Invalid record");
5083 TyID = getContainedTypeID(BasePtrTypeID);
5084 if (
BasePtr->getType()->isVectorTy())
5085 TyID = getContainedTypeID(TyID);
5086 Ty = getTypeByID(TyID);
5090 while (OpNum !=
Record.size()) {
5093 if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB))
5094 return error(
"Invalid record");
5101 if (cast<GEPOperator>(
I)->getNumIndices() != 0) {
5104 unsigned SubType = 0;
5105 if (GTI.isStruct()) {
5107 Idx->getType()->isVectorTy()
5112 ResTypeID = getContainedTypeID(ResTypeID, SubType);
5119 ResTypeID = getVirtualTypeID(
I->getType()->getScalarType(), ResTypeID);
5120 if (
I->getType()->isVectorTy())
5121 ResTypeID = getVirtualTypeID(
I->getType(), ResTypeID);
5125 cast<GetElementPtrInst>(
I)->setIsInBounds(
true);
5134 if (getValueTypePair(
Record, OpNum, NextValueNo, Agg, AggTypeID, CurBB))
5135 return error(
"Invalid record");
5138 unsigned RecSize =
Record.size();
5139 if (OpNum == RecSize)
5140 return error(
"EXTRACTVAL: Invalid instruction with 0 indices");
5143 ResTypeID = AggTypeID;
5144 for (; OpNum != RecSize; ++OpNum) {
5149 if (!IsStruct && !IsArray)
5150 return error(
"EXTRACTVAL: Invalid type");
5152 return error(
"Invalid value");
5154 return error(
"EXTRACTVAL: Invalid struct index");
5156 return error(
"EXTRACTVAL: Invalid array index");
5161 ResTypeID = getContainedTypeID(ResTypeID,
Index);
5164 ResTypeID = getContainedTypeID(ResTypeID);
5178 if (getValueTypePair(
Record, OpNum, NextValueNo, Agg, AggTypeID, CurBB))
5179 return error(
"Invalid record");
5182 if (getValueTypePair(
Record, OpNum, NextValueNo, Val, ValTypeID, CurBB))
5183 return error(
"Invalid record");
5185 unsigned RecSize =
Record.size();
5186 if (OpNum == RecSize)
5187 return error(
"INSERTVAL: Invalid instruction with 0 indices");
5191 for (; OpNum != RecSize; ++OpNum) {
5196 if (!IsStruct && !IsArray)
5197 return error(
"INSERTVAL: Invalid type");
5199 return error(
"Invalid value");
5201 return error(
"INSERTVAL: Invalid struct index");
5203 return error(
"INSERTVAL: Invalid array index");
5213 return error(
"Inserted value type doesn't match aggregate type");
5216 ResTypeID = AggTypeID;
5228 if (getValueTypePair(
Record, OpNum, NextValueNo, TrueVal,
TypeID,
5232 popValue(
Record, OpNum, NextValueNo, CondType,
5233 getVirtualTypeID(CondType),
Cond, CurBB))
5234 return error(
"Invalid record");
5247 unsigned ValTypeID, CondTypeID;
5248 if (getValueTypePair(
Record, OpNum, NextValueNo, TrueVal, ValTypeID,
5250 popValue(
Record, OpNum, NextValueNo,
TrueVal->getType(), ValTypeID,
5252 getValueTypePair(
Record, OpNum, NextValueNo,
Cond, CondTypeID, CurBB))
5253 return error(
"Invalid record");
5257 dyn_cast<VectorType>(
Cond->getType())) {
5260 return error(
"Invalid type for value");
5264 return error(
"Invalid type for value");
5268 ResTypeID = ValTypeID;
5270 if (OpNum <
Record.size() && isa<FPMathOperator>(
I)) {
5273 I->setFastMathFlags(FMF);
5281 unsigned VecTypeID, IdxTypeID;
5282 if (getValueTypePair(
Record, OpNum, NextValueNo, Vec, VecTypeID, CurBB) ||
5283 getValueTypePair(
Record, OpNum, NextValueNo,
Idx, IdxTypeID, CurBB))
5284 return error(
"Invalid record");
5286 return error(
"Invalid type for value");
5288 ResTypeID = getContainedTypeID(VecTypeID);
5296 unsigned VecTypeID, IdxTypeID;
5297 if (getValueTypePair(
Record, OpNum, NextValueNo, Vec, VecTypeID, CurBB))
5298 return error(
"Invalid record");
5300 return error(
"Invalid type for value");
5301 if (popValue(
Record, OpNum, NextValueNo,
5302 cast<VectorType>(Vec->
getType())->getElementType(),
5303 getContainedTypeID(VecTypeID), Elt, CurBB) ||
5304 getValueTypePair(
Record, OpNum, NextValueNo,
Idx, IdxTypeID, CurBB))
5305 return error(
"Invalid record");
5307 ResTypeID = VecTypeID;
5315 unsigned Vec1TypeID;
5316 if (getValueTypePair(
Record, OpNum, NextValueNo, Vec1, Vec1TypeID,
5318 popValue(
Record, OpNum, NextValueNo, Vec1->
getType(), Vec1TypeID,
5320 return error(
"Invalid record");
5322 unsigned MaskTypeID;
5323 if (getValueTypePair(
Record, OpNum, NextValueNo, Mask, MaskTypeID, CurBB))
5324 return error(
"Invalid record");
5326 return error(
"Invalid type for value");
5330 getVirtualTypeID(
I->getType(), getContainedTypeID(Vec1TypeID));
5345 if (getValueTypePair(
Record, OpNum, NextValueNo, LHS, LHSTypeID, CurBB) ||
5348 return error(
"Invalid record");
5350 if (OpNum >=
Record.size())
5352 "Invalid record: operand number exceeded available operands");
5357 if (IsFP &&
Record.size() > OpNum+1)
5360 if (OpNum+1 !=
Record.size())
5361 return error(
"Invalid record");
5365 return error(
"Invalid fcmp predicate");
5369 return error(
"Invalid icmp predicate");
5373 ResTypeID = getVirtualTypeID(
I->getType()->getScalarType());
5375 ResTypeID = getVirtualTypeID(
I->getType(), ResTypeID);
5378 I->setFastMathFlags(FMF);
5395 if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB))
5396 return error(
"Invalid record");
5397 if (OpNum !=
Record.size())
5398 return error(
"Invalid record");
5406 return error(
"Invalid record");
5409 return error(
"Invalid record");
5411 if (
Record.size() == 1) {
5419 getVirtualTypeID(CondType), CurBB);
5420 if (!FalseDest || !
Cond)
5421 return error(
"Invalid record");
5429 return error(
"Invalid record");
5432 Value *CleanupPad = getValue(
Record,
Idx++, NextValueNo, TokenTy,
5433 getVirtualTypeID(TokenTy), CurBB);
5435 return error(
"Invalid record");
5437 if (
Record.size() == 2) {
5438 UnwindDest = getBasicBlock(
Record[
Idx++]);
5440 return error(
"Invalid record");
5449 return error(
"Invalid record");
5453 getVirtualTypeID(TokenTy), CurBB);
5455 return error(
"Invalid record");
5458 return error(
"Invalid record");
5467 return error(
"Invalid record");
5473 getVirtualTypeID(TokenTy), CurBB);
5475 return error(
"Invalid record");
5480 for (
unsigned Op = 0;
Op != NumHandlers; ++
Op) {
5483 return error(
"Invalid record");
5489 UnwindDest = getBasicBlock(
Record[
Idx++]);
5491 return error(
"Invalid record");
5495 return error(
"Invalid record");
5500 CatchSwitch->addHandler(Handler);
5502 ResTypeID = getVirtualTypeID(
I->getType());
5510 return error(
"Invalid record");
5516 getVirtualTypeID(TokenTy), CurBB);
5518 return error(
"Invald record");
5520 unsigned NumArgOperands =
Record[
Idx++];
5523 for (
unsigned Op = 0;
Op != NumArgOperands; ++
Op) {
5526 if (getValueTypePair(
Record,
Idx, NextValueNo, Val, ValTypeID,
nullptr))
5527 return error(
"Invalid record");
5528 Args.push_back(Val);
5532 return error(
"Invalid record");
5538 ResTypeID = getVirtualTypeID(
I->getType());
5544 if ((
Record[0] >> 16) == SWITCH_INST_MAGIC) {
5550 unsigned OpTyID =
Record[1];
5551 Type *OpTy = getTypeByID(OpTyID);
5552 unsigned ValueBitWidth = cast<IntegerType>(OpTy)->getBitWidth();
5557 return error(
"Invalid record");
5559 unsigned NumCases =
Record[4];
5564 unsigned CurIdx = 5;
5565 for (
unsigned i = 0; i != NumCases; ++i) {
5567 unsigned NumItems =
Record[CurIdx++];
5568 for (
unsigned ci = 0; ci != NumItems; ++ci) {
5569 bool isSingleNumber =
Record[CurIdx++];
5572 unsigned ActiveWords = 1;
5573 if (ValueBitWidth > 64)
5574 ActiveWords =
Record[CurIdx++];
5577 CurIdx += ActiveWords;
5579 if (!isSingleNumber) {
5581 if (ValueBitWidth > 64)
5582 ActiveWords =
Record[CurIdx++];
5585 CurIdx += ActiveWords;
5598 SI->addCase(Cst, DestBB);
5607 return error(
"Invalid record");
5608 unsigned OpTyID =
Record[0];
5609 Type *OpTy = getTypeByID(OpTyID);
5613 return error(
"Invalid record");
5614 unsigned NumCases = (
Record.size()-3)/2;
5617 for (
unsigned i = 0, e = NumCases; i !=
e; ++i) {
5618 ConstantInt *CaseVal = dyn_cast_or_null<ConstantInt>(
5619 getFnValueByID(
Record[3+i*2], OpTy, OpTyID,
nullptr));
5621 if (!CaseVal || !DestBB) {
5623 return error(
"Invalid record");
5625 SI->addCase(CaseVal, DestBB);
5632 return error(
"Invalid record");
5633 unsigned OpTyID =
Record[0];
5634 Type *OpTy = getTypeByID(OpTyID);
5636 if (!OpTy || !Address)
5637 return error(
"Invalid record");
5638 unsigned NumDests =
Record.size()-2;
5641 for (
unsigned i = 0, e = NumDests; i !=
e; ++i) {
5646 return error(
"Invalid record");
5656 return error(
"Invalid record");
5659 unsigned CCInfo =
Record[OpNum++];
5663 unsigned FTyID = InvalidTypeID;
5665 if ((CCInfo >> 13) & 1) {
5667 FTy = dyn_cast<FunctionType>(getTypeByID(FTyID));
5669 return error(
"Explicit invoke type is not a function type");
5673 unsigned CalleeTypeID;
5674 if (getValueTypePair(
Record, OpNum, NextValueNo, Callee, CalleeTypeID,
5676 return error(
"Invalid record");
5680 return error(
"Callee is not a pointer");
5682 FTyID = getContainedTypeID(CalleeTypeID);
5683 FTy = dyn_cast_or_null<FunctionType>(getTypeByID(FTyID));
5685 return error(
"Callee is not of pointer to function type");
5687 if (
Record.size() < FTy->getNumParams() + OpNum)
5688 return error(
"Insufficient operands to call");
5692 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i, ++OpNum) {
5693 unsigned ArgTyID = getContainedTypeID(FTyID, i + 1);
5694 Ops.
push_back(getValue(
Record, OpNum, NextValueNo, FTy->getParamType(i),
5698 return error(
"Invalid record");
5701 if (!FTy->isVarArg()) {
5702 if (
Record.size() != OpNum)
5703 return error(
"Invalid record");
5706 while (OpNum !=
Record.size()) {
5709 if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB))
5710 return error(
"Invalid record");
5717 if (!OperandBundles.empty())
5722 ResTypeID = getContainedTypeID(FTyID);
5723 OperandBundles.clear();
5725 cast<InvokeInst>(
I)->setCallingConv(
5727 cast<InvokeInst>(
I)->setAttributes(PAL);
5728 if (
Error Err = propagateAttributeTypes(cast<CallBase>(
I), ArgTyIDs)) {
5737 Value *Val =
nullptr;
5739 if (getValueTypePair(
Record,
Idx, NextValueNo, Val, ValTypeID, CurBB))
5740 return error(
"Invalid record");
5749 unsigned CCInfo =
Record[OpNum++];
5752 unsigned NumIndirectDests =
Record[OpNum++];
5754 for (
unsigned i = 0, e = NumIndirectDests; i !=
e; ++i)
5757 unsigned FTyID = InvalidTypeID;
5761 FTy = dyn_cast_or_null<FunctionType>(getTypeByID(FTyID));
5763 return error(
"Explicit call type is not a function type");
5767 unsigned CalleeTypeID;
5768 if (getValueTypePair(
Record, OpNum, NextValueNo, Callee, CalleeTypeID,
5770 return error(
"Invalid record");
5774 return error(
"Callee is not a pointer type");
5776 FTyID = getContainedTypeID(CalleeTypeID);
5777 FTy = dyn_cast_or_null<FunctionType>(getTypeByID(FTyID));
5779 return error(
"Callee is not of pointer to function type");
5781 if (
Record.size() < FTy->getNumParams() + OpNum)
5782 return error(
"Insufficient operands to call");
5787 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i, ++OpNum) {
5789 unsigned ArgTyID = getContainedTypeID(FTyID, i + 1);
5790 if (FTy->getParamType(i)->isLabelTy())
5791 Arg = getBasicBlock(
Record[OpNum]);
5793 Arg = getValue(
Record, OpNum, NextValueNo, FTy->getParamType(i),
5796 return error(
"Invalid record");
5797 Args.push_back(Arg);
5802 if (!FTy->isVarArg()) {
5803 if (OpNum !=
Record.size())
5804 return error(
"Invalid record");
5806 while (OpNum !=
Record.size()) {
5809 if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB))
5810 return error(
"Invalid record");
5817 if (!OperandBundles.empty())
5820 if (
auto *IA = dyn_cast<InlineAsm>(Callee)) {
5825 if (
none_of(ConstraintInfo, IsLabelConstraint)) {
5830 unsigned FirstBlockArg =
Args.size() - IndirectDests.
size();
5831 for (
unsigned ArgNo = FirstBlockArg; ArgNo <
Args.size(); ++ArgNo) {
5832 unsigned LabelNo = ArgNo - FirstBlockArg;
5833 auto *BA = dyn_cast<BlockAddress>(Args[ArgNo]);
5834 if (!BA || BA->getFunction() !=
F ||
5835 LabelNo > IndirectDests.
size() ||
5836 BA->getBasicBlock() != IndirectDests[LabelNo])
5837 return error(
"callbr argument does not match indirect dest");
5842 ArgTyIDs.
erase(ArgTyIDs.
begin() + FirstBlockArg, ArgTyIDs.
end());
5846 for (
Value *Arg : Args)
5849 FunctionType::get(FTy->getReturnType(), ArgTys, FTy->isVarArg());
5852 std::string Constraints =
IA->getConstraintString();
5855 for (
const auto &CI : ConstraintInfo) {
5857 if (ArgNo >= FirstBlockArg)
5858 Constraints.insert(Pos,
"!");
5863 Pos = Constraints.find(
',', Pos);
5864 if (Pos == std::string::npos)
5870 IA->hasSideEffects(),
IA->isAlignStack(),
5871 IA->getDialect(),
IA->canThrow());
5877 ResTypeID = getContainedTypeID(FTyID);
5878 OperandBundles.clear();
5880 cast<CallBrInst>(
I)->setCallingConv(
5882 cast<CallBrInst>(
I)->setAttributes(PAL);
5883 if (
Error Err = propagateAttributeTypes(cast<CallBase>(
I), ArgTyIDs)) {
5895 return error(
"Invalid phi record");
5897 unsigned TyID =
Record[0];
5898 Type *Ty = getTypeByID(TyID);
5900 return error(
"Invalid phi record");
5905 size_t NumArgs = (
Record.size() - 1) / 2;
5907 if ((
Record.size() - 1) % 2 == 1 && !isa<FPMathOperator>(PN)) {
5909 return error(
"Invalid phi record");
5914 for (
unsigned i = 0; i != NumArgs; i++) {
5918 return error(
"Invalid phi BB");
5925 auto It =
Args.find(BB);
5926 if (It !=
Args.end()) {
5937 if (!PhiConstExprBB)
5939 EdgeBB = PhiConstExprBB;
5947 V = getValueSigned(
Record, i * 2 + 1, NextValueNo, Ty, TyID, EdgeBB);
5949 V = getValue(
Record, i * 2 + 1, NextValueNo, Ty, TyID, EdgeBB);
5953 return error(
"Invalid phi record");
5956 if (EdgeBB == PhiConstExprBB && !EdgeBB->
empty()) {
5957 ConstExprEdgeBBs.
insert({{BB, CurBB}, EdgeBB});
5958 PhiConstExprBB =
nullptr;
5961 Args.insert({BB,
V});
5967 if (
Record.size() % 2 == 0) {
5968 assert(isa<FPMathOperator>(
I) &&
"Unexpected phi type");
5971 I->setFastMathFlags(FMF);
5983 return error(
"Invalid record");
5987 return error(
"Invalid record");
5990 Type *Ty = getTypeByID(ResTypeID);
5992 return error(
"Invalid record");
5994 Value *PersFn =
nullptr;
5995 unsigned PersFnTypeID;
5996 if (getValueTypePair(
Record,
Idx, NextValueNo, PersFn, PersFnTypeID,
5998 return error(
"Invalid record");
6000 if (!
F->hasPersonalityFn())
6001 F->setPersonalityFn(cast<Constant>(PersFn));
6002 else if (
F->getPersonalityFn() != cast<Constant>(PersFn))
6003 return error(
"Personality function mismatch");
6010 for (
unsigned J = 0; J != NumClauses; ++J) {
6016 if (getValueTypePair(
Record,
Idx, NextValueNo, Val, ValTypeID,
6019 return error(
"Invalid record");
6023 !isa<ArrayType>(Val->
getType())) &&
6024 "Catch clause has a invalid type!");
6026 isa<ArrayType>(Val->
getType())) &&
6027 "Filter clause has invalid type!");
6038 return error(
"Invalid record");
6041 const bool InAlloca = Bitfield::get<APV::UsedWithInAlloca>(Rec);
6042 const bool SwiftError = Bitfield::get<APV::SwiftError>(Rec);
6043 unsigned TyID =
Record[0];
6044 Type *Ty = getTypeByID(TyID);
6045 if (!Bitfield::get<APV::ExplicitType>(Rec)) {
6046 TyID = getContainedTypeID(TyID);
6047 Ty = getTypeByID(TyID);
6049 return error(
"Missing element type for old-style alloca");
6051 unsigned OpTyID =
Record[1];
6052 Type *OpTy = getTypeByID(OpTyID);
6056 Bitfield::get<APV::AlignLower>(Rec) |
6057 (Bitfield::get<APV::AlignUpper>(Rec) << APV::AlignLower::Bits);
6058 if (
Error Err = parseAlignmentValue(AlignExp,
Align)) {
6062 return error(
"Invalid record");
6065 unsigned AS =
Record.size() == 5 ?
Record[4] :
DL.getAllocaAddrSpace();
6069 return error(
"alloca of unsized type");
6071 Align =
DL.getPrefTypeAlign(Ty);
6073 if (!
Size->getType()->isIntegerTy())
6074 return error(
"alloca element count must have integer type");
6080 ResTypeID = getVirtualTypeID(AI->
getType(), TyID);
6088 if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB) ||
6089 (OpNum + 2 !=
Record.size() && OpNum + 3 !=
Record.size()))
6090 return error(
"Invalid record");
6092 if (!isa<PointerType>(
Op->getType()))
6093 return error(
"Load operand is not a pointer type");
6096 if (OpNum + 3 ==
Record.size()) {
6097 ResTypeID =
Record[OpNum++];
6098 Ty = getTypeByID(ResTypeID);
6100 ResTypeID = getContainedTypeID(OpTypeID);
6101 Ty = getTypeByID(ResTypeID);
6105 return error(
"Missing load type");
6107 if (
Error Err = typeCheckLoadStoreInst(Ty,
Op->getType()))
6115 return error(
"load of unsized type");
6117 Align = TheModule->getDataLayout().getABITypeAlign(Ty);
6127 if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB) ||
6128 (OpNum + 4 !=
Record.size() && OpNum + 5 !=
Record.size()))
6129 return error(
"Invalid record");
6131 if (!isa<PointerType>(
Op->getType()))
6132 return error(
"Load operand is not a pointer type");
6135 if (OpNum + 5 ==
Record.size()) {
6136 ResTypeID =
Record[OpNum++];
6137 Ty = getTypeByID(ResTypeID);
6139 ResTypeID = getContainedTypeID(OpTypeID);
6140 Ty = getTypeByID(ResTypeID);
6144 return error(
"Missing atomic load type");
6146 if (
Error Err = typeCheckLoadStoreInst(Ty,
Op->getType()))
6150 if (Ordering == AtomicOrdering::NotAtomic ||
6151 Ordering == AtomicOrdering::Release ||
6152 Ordering == AtomicOrdering::AcquireRelease)
6153 return error(
"Invalid record");
6154 if (Ordering != AtomicOrdering::NotAtomic &&
Record[OpNum] == 0)
6155 return error(
"Invalid record");
6162 return error(
"Alignment missing from atomic load");
6171 unsigned PtrTypeID, ValTypeID;
6172 if (getValueTypePair(
Record, OpNum, NextValueNo,
Ptr, PtrTypeID, CurBB))
6173 return error(
"Invalid record");
6176 if (getValueTypePair(
Record, OpNum, NextValueNo, Val, ValTypeID, CurBB))
6177 return error(
"Invalid record");
6179 ValTypeID = getContainedTypeID(PtrTypeID);
6180 if (popValue(
Record, OpNum, NextValueNo, getTypeByID(ValTypeID),
6181 ValTypeID, Val, CurBB))
6182 return error(
"Invalid record");
6185 if (OpNum + 2 !=
Record.size())
6186 return error(
"Invalid record");
6188 if (
Error Err = typeCheckLoadStoreInst(Val->
getType(),
Ptr->getType()))
6195 return error(
"store of unsized type");
6197 Align = TheModule->getDataLayout().getABITypeAlign(Val->
getType());
6207 unsigned PtrTypeID, ValTypeID;
6208 if (getValueTypePair(
Record, OpNum, NextValueNo,
Ptr, PtrTypeID, CurBB) ||
6209 !isa<PointerType>(
Ptr->getType()))
6210 return error(
"Invalid record");
6212 if (getValueTypePair(
Record, OpNum, NextValueNo, Val, ValTypeID, CurBB))
6213 return error(
"Invalid record");
6215 ValTypeID = getContainedTypeID(PtrTypeID);
6216 if (popValue(
Record, OpNum, NextValueNo, getTypeByID(ValTypeID),
6217 ValTypeID, Val, CurBB))
6218 return error(
"Invalid record");
6221 if (OpNum + 4 !=
Record.size())
6222 return error(
"Invalid record");
6224 if (
Error Err = typeCheckLoadStoreInst(Val->
getType(),
Ptr->getType()))
6227 if (Ordering == AtomicOrdering::NotAtomic ||
6228 Ordering == AtomicOrdering::Acquire ||
6229 Ordering == AtomicOrdering::AcquireRelease)
6230 return error(
"Invalid record");
6232 if (Ordering != AtomicOrdering::NotAtomic &&
Record[OpNum] == 0)
6233 return error(
"Invalid record");
6239 return error(
"Alignment missing from atomic store");
6247 const size_t NumRecords =
Record.size();
6251 if (getValueTypePair(
Record, OpNum, NextValueNo,
Ptr, PtrTypeID, CurBB))
6252 return error(
"Invalid record");
6254 if (!isa<PointerType>(
Ptr->getType()))
6255 return error(
"Cmpxchg operand is not a pointer type");
6258 unsigned CmpTypeID = getContainedTypeID(PtrTypeID);
6259 if (popValue(
Record, OpNum, NextValueNo, getTypeByID(CmpTypeID),
6260 CmpTypeID, Cmp, CurBB))
6261 return error(
"Invalid record");
6264 if (popValue(
Record, OpNum, NextValueNo,
Cmp->getType(), CmpTypeID,
6266 NumRecords < OpNum + 3 || NumRecords > OpNum + 5)
6267 return error(
"Invalid record");
6271 if (SuccessOrdering == AtomicOrdering::NotAtomic ||
6272 SuccessOrdering == AtomicOrdering::Unordered)
6273 return error(
"Invalid record");
6277 if (
Error Err = typeCheckLoadStoreInst(
Cmp->getType(),
Ptr->getType()))
6285 if (FailureOrdering == AtomicOrdering::NotAtomic ||
6286 FailureOrdering == AtomicOrdering::Unordered)
6287 return error(
"Invalid record");
6289 const Align Alignment(
6290 TheModule->getDataLayout().getTypeStoreSize(
Cmp->getType()));
6293 FailureOrdering, SSID);
6294 cast<AtomicCmpXchgInst>(
I)->setVolatile(
Record[OpNum]);
6296 if (NumRecords < 8) {
6300 I->insertInto(CurBB, CurBB->
end());
6302 ResTypeID = CmpTypeID;
6304 cast<AtomicCmpXchgInst>(
I)->setWeak(
Record[OpNum + 4]);
6306 ResTypeID = getVirtualTypeID(
I->getType(), {CmpTypeID, I1TypeID});
6315 const size_t NumRecords =
Record.size();
6319 if (getValueTypePair(
Record, OpNum, NextValueNo,
Ptr, PtrTypeID, CurBB))
6320 return error(
"Invalid record");
6322 if (!isa<PointerType>(
Ptr->getType()))
6323 return error(
"Cmpxchg operand is not a pointer type");
6327 if (getValueTypePair(
Record, OpNum, NextValueNo, Cmp, CmpTypeID, CurBB))
6328 return error(
"Invalid record");
6330 Value *Val =
nullptr;
6331 if (popValue(
Record, OpNum, NextValueNo,
Cmp->getType(), CmpTypeID, Val,
6333 return error(
"Invalid record");
6335 if (NumRecords < OpNum + 3 || NumRecords > OpNum + 6)
6336 return error(
"Invalid record");
6338 const bool IsVol =
Record[OpNum];
6343 return error(
"Invalid cmpxchg success ordering");
6347 if (
Error Err = typeCheckLoadStoreInst(
Cmp->getType(),
Ptr->getType()))
6353 return error(
"Invalid cmpxchg failure ordering");
6355 const bool IsWeak =
Record[OpNum + 4];
6359 if (NumRecords == (OpNum + 6)) {
6360 if (
Error Err = parseAlignmentValue(
Record[OpNum + 5], Alignment))
6365 Align(TheModule->getDataLayout().getTypeStoreSize(
Cmp->getType()));
6368 FailureOrdering, SSID);
6369 cast<AtomicCmpXchgInst>(
I)->setVolatile(IsVol);
6370 cast<AtomicCmpXchgInst>(
I)->setWeak(IsWeak);
6373 ResTypeID = getVirtualTypeID(
I->getType(), {CmpTypeID, I1TypeID});
6382 const size_t NumRecords =
Record.size();
6387 if (getValueTypePair(
Record, OpNum, NextValueNo,
Ptr, PtrTypeID, CurBB))
6388 return error(
"Invalid record");
6390 if (!isa<PointerType>(
Ptr->getType()))
6391 return error(
"Invalid record");
6393 Value *Val =
nullptr;
6394 unsigned ValTypeID = InvalidTypeID;
6396 ValTypeID = getContainedTypeID(PtrTypeID);
6397 if (popValue(
Record, OpNum, NextValueNo,
6398 getTypeByID(ValTypeID), ValTypeID, Val, CurBB))
6399 return error(
"Invalid record");
6401 if (getValueTypePair(
Record, OpNum, NextValueNo, Val, ValTypeID, CurBB))
6402 return error(
"Invalid record");
6405 if (!(NumRecords == (OpNum + 4) || NumRecords == (OpNum + 5)))
6406 return error(
"Invalid record");
6412 return error(
"Invalid record");
6414 const bool IsVol =
Record[OpNum + 1];
6417 if (Ordering == AtomicOrdering::NotAtomic ||
6418 Ordering == AtomicOrdering::Unordered)
6419 return error(
"Invalid record");
6425 if (NumRecords == (OpNum + 5)) {
6426 if (
Error Err = parseAlignmentValue(
Record[OpNum + 4], Alignment))
6432 Align(TheModule->getDataLayout().getTypeStoreSize(Val->
getType()));
6435 ResTypeID = ValTypeID;
6436 cast<AtomicRMWInst>(
I)->setVolatile(IsVol);
6443 return error(
"Invalid record");
6445 if (Ordering == AtomicOrdering::NotAtomic ||
6446 Ordering == AtomicOrdering::Unordered ||
6447 Ordering == AtomicOrdering::Monotonic)
6448 return error(
"Invalid record");
6457 SeenDebugRecord =
true;
6460 return error(
"Invalid dbg record: missing instruction");
6473 SeenDebugRecord =
true;
6476 return error(
"Invalid dbg record: missing instruction");
6492 cast<DILocalVariable>(getFnMetadataByID(
Record[Slot++]));
6494 cast<DIExpression>(getFnMetadataByID(
Record[Slot++]));
6506 unsigned SlotBefore =
Slot;
6507 if (getValueTypePair(
Record, Slot, NextValueNo, V, TyID, CurBB))
6508 return error(
"Invalid dbg record: invalid value");
6510 assert((SlotBefore == Slot - 1) &&
"unexpected fwd ref");
6513 RawLocation = getFnMetadataByID(
Record[Slot++]);
6521 DbgVariableRecord::LocationType::Value);
6525 DbgVariableRecord::LocationType::Declare);
6530 cast<DIExpression>(getFnMetadataByID(
Record[Slot++]));
6545 return error(
"Invalid record");
6549 unsigned CCInfo =
Record[OpNum++];
6555 return error(
"Fast math flags indicator set for call with no FMF");
6558 unsigned FTyID = InvalidTypeID;
6562 FTy = dyn_cast_or_null<FunctionType>(getTypeByID(FTyID));
6564 return error(
"Explicit call type is not a function type");
6568 unsigned CalleeTypeID;
6569 if (getValueTypePair(
Record, OpNum, NextValueNo, Callee, CalleeTypeID,
6571 return error(
"Invalid record");
6575 return error(
"Callee is not a pointer type");
6577 FTyID = getContainedTypeID(CalleeTypeID);
6578 FTy = dyn_cast_or_null<FunctionType>(getTypeByID(FTyID));
6580 return error(
"Callee is not of pointer to function type");
6582 if (
Record.size() < FTy->getNumParams() + OpNum)
6583 return error(
"Insufficient operands to call");
6588 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i, ++OpNum) {
6589 unsigned ArgTyID = getContainedTypeID(FTyID, i + 1);
6590 if (FTy->getParamType(i)->isLabelTy())
6591 Args.push_back(getBasicBlock(
Record[OpNum]));
6593 Args.push_back(getValue(
Record, OpNum, NextValueNo,
6594 FTy->getParamType(i), ArgTyID, CurBB));
6597 return error(
"Invalid record");
6601 if (!FTy->isVarArg()) {
6602 if (OpNum !=
Record.size())
6603 return error(
"Invalid record");
6605 while (OpNum !=
Record.size()) {
6608 if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB))
6609 return error(
"Invalid record");
6616 if (!OperandBundles.empty())
6620 ResTypeID = getContainedTypeID(FTyID);
6621 OperandBundles.clear();
6623 cast<CallInst>(
I)->setCallingConv(
6632 cast<CallInst>(
I)->setTailCallKind(TCK);
6633 cast<CallInst>(
I)->setAttributes(PAL);
6634 if (isa<DbgInfoIntrinsic>(
I))
6635 SeenDebugIntrinsic =
true;
6636 if (
Error Err = propagateAttributeTypes(cast<CallBase>(
I), ArgTyIDs)) {
6641 if (!isa<FPMathOperator>(
I))
6642 return error(
"Fast-math-flags specified for call without "
6643 "floating-point scalar or vector return type");
6644 I->setFastMathFlags(FMF);
6650 return error(
"Invalid record");
6651 unsigned OpTyID =
Record[0];
6652 Type *OpTy = getTypeByID(OpTyID);
6653 Value *
Op = getValue(
Record, 1, NextValueNo, OpTy, OpTyID, CurBB);
6655 Type *ResTy = getTypeByID(ResTypeID);
6656 if (!OpTy || !
Op || !ResTy)
6657 return error(
"Invalid record");
6669 return error(
"Invalid record");
6671 std::vector<Value *> Inputs;
6674 while (OpNum !=
Record.size()) {
6677 if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB))
6678 return error(
"Invalid record");
6679 Inputs.push_back(
Op);
6682 OperandBundles.emplace_back(BundleTags[
Record[0]], std::move(Inputs));
6690 if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB))
6691 return error(
"Invalid record");
6692 if (OpNum !=
Record.size())
6693 return error(
"Invalid record");
6696 ResTypeID = OpTypeID;
6706 return error(
"Invalid instruction with no BB");
6708 if (!OperandBundles.empty()) {
6710 return error(
"Operand bundles found with no consumer");
6712 I->insertInto(CurBB, CurBB->
end());
6715 if (
I->isTerminator()) {
6717 CurBB = CurBBNo < FunctionBBs.size() ? FunctionBBs[CurBBNo] :
nullptr;
6721 if (!
I->getType()->isVoidTy()) {
6722 assert(
I->getType() == getTypeByID(ResTypeID) &&
6723 "Incorrect result type ID");
6731 if (!OperandBundles.empty())
6732 return error(
"Operand bundles found with no consumer");
6736 if (!
A->getParent()) {
6738 for (
unsigned i = ModuleValueListSize, e = ValueList.
size(); i != e; ++i){
6739 if ((
A = dyn_cast_or_null<Argument>(ValueList[i])) && !
A->getParent()) {
6744 return error(
"Never resolved value found in function");
6749 if (MDLoader->hasFwdRefs())
6750 return error(
"Invalid function metadata: outgoing forward refs");
6755 for (
const auto &Pair : ConstExprEdgeBBs) {
6760 From->getTerminator()->replaceSuccessorWith(To, EdgeBB);
6766 ValueList.
shrinkTo(ModuleValueListSize);
6767 MDLoader->shrinkTo(ModuleMDLoaderSize);
6768 std::vector<BasicBlock*>().swap(FunctionBBs);
6773Error BitcodeReader::findFunctionInStream(
6776 while (DeferredFunctionInfoIterator->second == 0) {
6781 assert(VSTOffset == 0 || !
F->hasName());
6784 if (
Error Err = rememberAndSkipFunctionBodies())
6790SyncScope::ID BitcodeReader::getDecodedSyncScopeID(
unsigned Val) {
6793 if (Val >= SSIDs.
size())
6805 if (!
F || !
F->isMaterializable())
6809 assert(DFII != DeferredFunctionInfo.
end() &&
"Deferred function not found!");
6812 if (DFII->second == 0)
6813 if (
Error Err = findFunctionInStream(
F, DFII))
6817 if (
Error Err = materializeMetadata())
6821 if (
Error JumpFailed = Stream.JumpToBit(DFII->second))
6826 F->IsNewDbgInfoFormat =
true;
6828 if (
Error Err = parseFunctionBody(
F))
6830 F->setIsMaterializable(
false);
6834 if (SeenDebugIntrinsic && SeenDebugRecord)
6835 return error(
"Mixed debug intrinsics and debug records in bitcode module!");
6837 bool SeenAnyDebugInfo = SeenDebugIntrinsic || SeenDebugRecord;
6838 bool NewDbgInfoFormatDesired =
6839 SeenAnyDebugInfo ? SeenDebugRecord :
F->getParent()->IsNewDbgInfoFormat;
6840 if (SeenAnyDebugInfo) {
6849 if (NewDbgInfoFormatDesired !=
F->getParent()->IsNewDbgInfoFormat)
6850 F->getParent()->setNewDbgInfoFormatFlag(NewDbgInfoFormatDesired);
6852 F->setNewDbgInfoFormatFlag(NewDbgInfoFormatDesired);
6860 bool ModuleIsNewDbgInfoFormat =
F->getParent()->IsNewDbgInfoFormat;
6861 if (ModuleIsNewDbgInfoFormat || !SeenDebugRecord)
6862 F->setNewDbgInfoFormatFlag(ModuleIsNewDbgInfoFormat);
6864 F->setIsNewDbgInfoFormat(ModuleIsNewDbgInfoFormat);
6871 for (
auto &
I : UpgradedIntrinsics) {
6873 if (
CallInst *CI = dyn_cast<CallInst>(U))
6878 if (
DISubprogram *SP = MDLoader->lookupSubprogramForFunction(
F))
6879 F->setSubprogram(SP);
6882 if (!MDLoader->isStrippingTBAA()) {
6884 MDNode *TBAA =
I.getMetadata(LLVMContext::MD_tbaa);
6887 MDLoader->setStripTBAA(
true);
6894 if (
auto *MD =
I.getMetadata(LLVMContext::MD_prof)) {
6895 if (MD->getOperand(0) !=
nullptr && isa<MDString>(MD->getOperand(0))) {
6896 MDString *MDS = cast<MDString>(MD->getOperand(0));
6899 if (!ProfName.
equals(
"branch_weights"))
6901 unsigned ExpectedNumOperands = 0;
6903 ExpectedNumOperands = BI->getNumSuccessors();
6904 else if (
SwitchInst *SI = dyn_cast<SwitchInst>(&
I))
6905 ExpectedNumOperands =
SI->getNumSuccessors();
6906 else if (isa<CallInst>(&
I))
6907 ExpectedNumOperands = 1;
6910 else if (isa<SelectInst>(&
I))
6911 ExpectedNumOperands = 2;
6916 if (MD->getNumOperands() != 1 + ExpectedNumOperands)
6917 I.setMetadata(LLVMContext::MD_prof,
nullptr);
6922 if (
auto *CI = dyn_cast<CallBase>(&
I)) {
6924 CI->getFunctionType()->getReturnType()));
6926 for (
unsigned ArgNo = 0; ArgNo < CI->arg_size(); ++ArgNo)
6928 CI->getArgOperand(ArgNo)->getType()));
6937 return materializeForwardReferencedFunctions();
6940Error BitcodeReader::materializeModule() {
6941 if (
Error Err = materializeMetadata())
6945 WillMaterializeAllForwardRefs =
true;
6950 if (
Error Err = materialize(&
F))
6956 if (LastFunctionBlockBit || NextUnreadBit)
6958 ? LastFunctionBlockBit
6964 if (!BasicBlockFwdRefs.
empty())
6965 return error(
"Never resolved function from blockaddress");
6971 for (
auto &
I : UpgradedIntrinsics) {
6972 for (
auto *U :
I.first->users()) {
6973 if (
CallInst *CI = dyn_cast<CallInst>(U))
6976 if (!
I.first->use_empty())
6977 I.first->replaceAllUsesWith(
I.second);
6978 I.first->eraseFromParent();
6980 UpgradedIntrinsics.clear();
6991std::vector<StructType *> BitcodeReader::getIdentifiedStructTypes()
const {
6992 return IdentifiedStructTypes;
6995ModuleSummaryIndexBitcodeReader::ModuleSummaryIndexBitcodeReader(
6998 : BitcodeReaderBase(
std::
move(Cursor), Strtab), TheIndex(TheIndex),
6999 ModulePath(ModulePath), IsPrevailing(IsPrevailing) {}
7001void ModuleSummaryIndexBitcodeReader::addThisModule() {
7006ModuleSummaryIndexBitcodeReader::getThisModule() {
7010template <
bool AllowNullValueInfo>
7011std::tuple<ValueInfo, GlobalValue::GUID, GlobalValue::GUID>
7012ModuleSummaryIndexBitcodeReader::getValueInfoFromValueId(
unsigned ValueId) {
7013 auto VGI = ValueIdToValueInfoMap[ValueId];
7018 assert(AllowNullValueInfo || std::get<0>(VGI));
7022void ModuleSummaryIndexBitcodeReader::setValueGUID(
7025 std::string GlobalId =
7028 auto OriginalNameID = ValueGUID;
7032 dbgs() <<
"GUID " << ValueGUID <<
"(" << OriginalNameID <<
") is "
7038 ValueIdToValueInfoMap[ValueID] = std::make_tuple(
7041 OriginalNameID, ValueGUID);
7047Error ModuleSummaryIndexBitcodeReader::parseValueSymbolTable(
7056 if (!MaybeCurrentBit)
7074 switch (Entry.Kind) {
7077 return error(
"Malformed block");
7080 if (
Error JumpFailed = Stream.JumpToBit(CurrentBit))
7093 switch (MaybeRecord.
get()) {
7098 return error(
"Invalid record");
7099 unsigned ValueID =
Record[0];
7101 auto VLI = ValueIdToLinkageMap.
find(ValueID);
7102 assert(VLI != ValueIdToLinkageMap.
end() &&
7103 "No linkage found for VST entry?");
7105 setValueGUID(ValueID,
ValueName, Linkage, SourceFileName);
7112 return error(
"Invalid record");
7113 unsigned ValueID =
Record[0];
7115 auto VLI = ValueIdToLinkageMap.
find(ValueID);
7116 assert(VLI != ValueIdToLinkageMap.
end() &&
7117 "No linkage found for VST entry?");
7119 setValueGUID(ValueID,
ValueName, Linkage, SourceFileName);
7125 unsigned ValueID =
Record[0];
7129 ValueIdToValueInfoMap[ValueID] = std::make_tuple(
7140Error ModuleSummaryIndexBitcodeReader::parseModule() {
7146 unsigned ValueId = 0;
7155 switch (Entry.Kind) {
7157 return error(
"Malformed block");
7164 if (
Error Err = Stream.SkipBlock())
7169 if (
Error Err = readBlockInfo())
7175 assert(((SeenValueSymbolTable && VSTOffset > 0) ||
7176 !SeenGlobalValSummary) &&
7177 "Expected early VST parse via VSTOffset record");
7178 if (
Error Err = Stream.SkipBlock())
7184 if (!SourceFileName.
empty())
7186 assert(!SeenValueSymbolTable &&
7187 "Already read VST when parsing summary block?");
7192 if (VSTOffset > 0) {
7193 if (
Error Err = parseValueSymbolTable(VSTOffset, ValueIdToLinkageMap))
7195 SeenValueSymbolTable =
true;
7197 SeenGlobalValSummary =
true;
7198 if (
Error Err = parseEntireSummary(Entry.ID))
7202 if (
Error Err = parseModuleStringTable())
7213 switch (MaybeBitCode.
get()) {
7217 if (
Error Err = parseVersionRecord(
Record).takeError())
7225 return error(
"Invalid record");
7233 auto &Hash = getThisModule()->second;
7235 for (
auto &Val :
Record) {
7236 assert(!(Val >> 32) &&
"Unexpected high bits set");
7244 return error(
"Invalid record");
7248 VSTOffset =
Record[0] - 1;
7259 std::tie(
Name, GVRecord) = readNameFromStrtab(
Record);
7260 if (GVRecord.
size() <= 3)
7261 return error(
"Invalid record");
7265 ValueIdToLinkageMap[ValueId++] =
Linkage;
7269 setValueGUID(ValueId++,
Name, Linkage, SourceFileName);
7279std::vector<ValueInfo>
7281 std::vector<ValueInfo>
Ret;
7284 Ret.push_back(std::get<0>(getValueInfoFromValueId(RefValueId)));
7288std::vector<FunctionSummary::EdgeTy>
7290 bool IsOldProfileFormat,
7291 bool HasProfile,
bool HasRelBF) {
7292 std::vector<FunctionSummary::EdgeTy>
Ret;
7294 for (
unsigned I = 0, E =
Record.size();
I != E; ++
I) {
7296 bool HasTailCall =
false;
7299 if (IsOldProfileFormat) {
7303 }
else if (HasProfile)
7304 std::tie(Hotness, HasTailCall) =
7337 static_cast<size_t>(
Record[Slot + 1])};
7360 while (Slot <
Record.size())
7364std::vector<FunctionSummary::ParamAccess>
7366 auto ReadRange = [&]() {
7368 BitcodeReader::decodeSignRotatedValue(
Record.front()));
7371 BitcodeReader::decodeSignRotatedValue(
Record.front()));
7379 std::vector<FunctionSummary::ParamAccess> PendingParamAccesses;
7380 while (!
Record.empty()) {
7381 PendingParamAccesses.emplace_back();
7385 ParamAccess.
Use = ReadRange();
7388 for (
auto &Call : ParamAccess.
Calls) {
7391 Call.Callee = std::get<0>(getValueInfoFromValueId(
Record.front()));
7393 Call.Offsets = ReadRange();
7396 return PendingParamAccesses;
7399void ModuleSummaryIndexBitcodeReader::parseTypeIdCompatibleVtableInfo(
7407void ModuleSummaryIndexBitcodeReader::parseTypeIdCompatibleVtableSummaryRecord(
7413 static_cast<size_t>(
Record[Slot + 1])});
7416 while (Slot <
Record.size())
7417 parseTypeIdCompatibleVtableInfo(
Record, Slot, TypeId);
7423 assert(ROCnt + WOCnt <= Refs.size());
7424 unsigned FirstWORef = Refs.size() - WOCnt;
7425 unsigned RefNo = FirstWORef - ROCnt;
7426 for (; RefNo < FirstWORef; ++RefNo)
7427 Refs[RefNo].setReadOnly();
7428 for (; RefNo < Refs.size(); ++RefNo)
7429 Refs[RefNo].setWriteOnly();
7434Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(
unsigned ID) {
7435 if (
Error Err = Stream.EnterSubBlock(
ID))
7447 return error(
"Invalid Summary Block: record for version expected");
7452 return error(
"Invalid Summary Block: version expected");
7455 const bool IsOldProfileFormat =
Version == 1;
7457 return error(
"Invalid summary version " +
Twine(Version) +
7458 ". Version should be in the range [1-" +
7471 std::vector<GlobalValue::GUID> PendingTypeTests;
7472 std::vector<FunctionSummary::VFuncId> PendingTypeTestAssumeVCalls,
7473 PendingTypeCheckedLoadVCalls;
7474 std::vector<FunctionSummary::ConstVCall> PendingTypeTestAssumeConstVCalls,
7475 PendingTypeCheckedLoadConstVCalls;
7476 std::vector<FunctionSummary::ParamAccess> PendingParamAccesses;
7478 std::vector<CallsiteInfo> PendingCallsites;
7479 std::vector<AllocInfo> PendingAllocs;
7487 switch (Entry.Kind) {
7490 return error(
"Malformed block");
7509 switch (
unsigned BitCode = MaybeBitCode.
get()) {
7519 ValueIdToValueInfoMap[ValueID] = std::make_tuple(
7535 unsigned ValueID =
Record[0];
7537 unsigned InstCount =
Record[2];
7539 unsigned NumRefs =
Record[3];
7540 unsigned NumRORefs = 0, NumWORefs = 0;
7541 int RefListStartIndex = 4;
7545 RefListStartIndex = 5;
7548 RefListStartIndex = 6;
7551 RefListStartIndex = 7;
7562 int CallGraphEdgeStartIndex = RefListStartIndex + NumRefs;
7564 "Record size inconsistent with number of references");
7565 std::vector<ValueInfo> Refs = makeRefList(
7569 std::vector<FunctionSummary::EdgeTy> Calls = makeCallList(
7571 IsOldProfileFormat, HasProfile, HasRelBF);
7573 auto VIAndOriginalGUID = getValueInfoFromValueId(ValueID);
7580 !IsPrevailing(std::get<2>(VIAndOriginalGUID))) {
7581 PendingCallsites.clear();
7582 PendingAllocs.clear();
7584 auto FS = std::make_unique<FunctionSummary>(
7586 std::move(Refs), std::move(Calls), std::move(PendingTypeTests),
7587 std::move(PendingTypeTestAssumeVCalls),
7588 std::move(PendingTypeCheckedLoadVCalls),
7589 std::move(PendingTypeTestAssumeConstVCalls),
7590 std::move(PendingTypeCheckedLoadConstVCalls),
7591 std::move(PendingParamAccesses), std::move(PendingCallsites),
7592 std::move(PendingAllocs));
7593 FS->setModulePath(getThisModule()->first());
7594 FS->setOriginalName(std::get<1>(VIAndOriginalGUID));
7603 unsigned ValueID =
Record[0];
7605 unsigned AliaseeID =
Record[2];
7607 auto AS = std::make_unique<AliasSummary>(Flags);
7613 AS->setModulePath(getThisModule()->first());
7615 auto AliaseeVI = std::get<0>(getValueInfoFromValueId(AliaseeID));
7617 if (!AliaseeInModule)
7618 return error(
"Alias expects aliasee summary to be parsed");
7619 AS->setAliasee(AliaseeVI, AliaseeInModule);
7621 auto GUID = getValueInfoFromValueId(ValueID);
7622 AS->setOriginalName(std::get<1>(GUID));
7628 unsigned ValueID =
Record[0];
7630 unsigned RefArrayStart = 2;
7640 std::vector<ValueInfo> Refs =
7643 std::make_unique<GlobalVarSummary>(Flags, GVF, std::move(Refs));
7644 FS->setModulePath(getThisModule()->first());
7645 auto GUID = getValueInfoFromValueId(ValueID);
7646 FS->setOriginalName(std::get<1>(GUID));
7654 unsigned ValueID =
Record[0];
7657 unsigned NumRefs =
Record[3];
7658 unsigned RefListStartIndex = 4;
7659 unsigned VTableListStartIndex = RefListStartIndex + NumRefs;
7661 std::vector<ValueInfo> Refs = makeRefList(
7664 for (
unsigned I = VTableListStartIndex, E =
Record.size();
I != E; ++
I) {
7670 std::make_unique<GlobalVarSummary>(Flags, GVF, std::move(Refs));
7671 VS->setModulePath(getThisModule()->first());
7672 VS->setVTableFuncs(VTableFuncs);
7673 auto GUID = getValueInfoFromValueId(ValueID);
7674 VS->setOriginalName(std::get<1>(GUID));
7686 unsigned ValueID =
Record[0];
7689 unsigned InstCount =
Record[3];
7692 unsigned NumRefs =
Record[4];
7693 unsigned NumRORefs = 0, NumWORefs = 0;
7694 int RefListStartIndex = 5;
7698 RefListStartIndex = 6;
7699 size_t NumRefsIndex = 5;
7701 unsigned NumRORefsOffset = 1;
7702 RefListStartIndex = 7;
7706 RefListStartIndex = 8;
7708 RefListStartIndex = 9;
7710 NumRORefsOffset = 2;
7713 NumRORefs =
Record[RefListStartIndex - NumRORefsOffset];
7715 NumRefs =
Record[NumRefsIndex];
7719 int CallGraphEdgeStartIndex = RefListStartIndex + NumRefs;
7721 "Record size inconsistent with number of references");
7722 std::vector<ValueInfo> Refs = makeRefList(
7725 std::vector<FunctionSummary::EdgeTy> Edges = makeCallList(
7727 IsOldProfileFormat, HasProfile,
false);
7728 ValueInfo VI = std::get<0>(getValueInfoFromValueId(ValueID));
7730 auto FS = std::make_unique<FunctionSummary>(
7732 std::move(Refs), std::move(Edges), std::move(PendingTypeTests),
7733 std::move(PendingTypeTestAssumeVCalls),
7734 std::move(PendingTypeCheckedLoadVCalls),
7735 std::move(PendingTypeTestAssumeConstVCalls),
7736 std::move(PendingTypeCheckedLoadConstVCalls),
7737 std::move(PendingParamAccesses), std::move(PendingCallsites),
7738 std::move(PendingAllocs));
7739 LastSeenSummary =
FS.get();
7740 LastSeenGUID =
VI.getGUID();
7741 FS->setModulePath(ModuleIdMap[ModuleId]);
7749 unsigned ValueID =
Record[0];
7752 unsigned AliaseeValueId =
Record[3];
7754 auto AS = std::make_unique<AliasSummary>(Flags);
7755 LastSeenSummary = AS.get();
7756 AS->setModulePath(ModuleIdMap[ModuleId]);
7758 auto AliaseeVI = std::get<0>(getValueInfoFromValueId(AliaseeValueId));
7760 AS->setAliasee(AliaseeVI, AliaseeInModule);
7762 ValueInfo VI = std::get<0>(getValueInfoFromValueId(ValueID));
7763 LastSeenGUID =
VI.getGUID();
7769 unsigned ValueID =
Record[0];
7772 unsigned RefArrayStart = 3;
7782 std::vector<ValueInfo> Refs =
7785 std::make_unique<GlobalVarSummary>(Flags, GVF, std::move(Refs));
7786 LastSeenSummary =
FS.get();
7787 FS->setModulePath(ModuleIdMap[ModuleId]);
7788 ValueInfo VI = std::get<0>(getValueInfoFromValueId(ValueID));
7789 LastSeenGUID =
VI.getGUID();
7796 if (!LastSeenSummary)
7797 return error(
"Name attachment that does not follow a combined record");
7801 LastSeenSummary =
nullptr;
7806 assert(PendingTypeTests.empty());
7811 assert(PendingTypeTestAssumeVCalls.empty());
7812 for (
unsigned I = 0;
I !=
Record.size();
I += 2)
7813 PendingTypeTestAssumeVCalls.push_back({Record[I], Record[I+1]});
7817 assert(PendingTypeCheckedLoadVCalls.empty());
7818 for (
unsigned I = 0;
I !=
Record.size();
I += 2)
7819 PendingTypeCheckedLoadVCalls.push_back({Record[I], Record[I+1]});
7823 PendingTypeTestAssumeConstVCalls.push_back(
7828 PendingTypeCheckedLoadConstVCalls.push_back(
7834 for (
unsigned I = 0;
I !=
Record.size();
I += 2)
7835 CfiFunctionDefs.insert(
7836 {Strtab.data() + Record[I], static_cast<size_t>(Record[I + 1])});
7842 for (
unsigned I = 0;
I !=
Record.size();
I += 2)
7843 CfiFunctionDecls.insert(
7844 {Strtab.data() + Record[I], static_cast<size_t>(Record[I + 1])});
7853 parseTypeIdCompatibleVtableSummaryRecord(
Record);
7861 PendingParamAccesses = parseParamAccesses(
Record);
7873 unsigned ValueID =
Record[0];
7875 for (
auto R =
Record.begin() + 1; R !=
Record.end(); R++) {
7876 assert(*R < StackIds.size());
7879 ValueInfo VI = std::get<0>(getValueInfoFromValueId(ValueID));
7880 PendingCallsites.push_back(
CallsiteInfo({
VI, std::move(StackIdList)}));
7885 auto RecordIter =
Record.begin();
7886 unsigned ValueID = *RecordIter++;
7887 unsigned NumStackIds = *RecordIter++;
7888 unsigned NumVersions = *RecordIter++;
7889 assert(
Record.size() == 3 + NumStackIds + NumVersions);
7891 for (
unsigned J = 0; J < NumStackIds; J++) {
7892 assert(*RecordIter < StackIds.size());
7897 for (
unsigned J = 0; J < NumVersions; J++)
7900 getValueInfoFromValueId</*AllowNullValueInfo*/ true>(ValueID));
7901 PendingCallsites.push_back(
7902 CallsiteInfo({
VI, std::move(Versions), std::move(StackIdList)}));
7908 std::vector<MIBInfo> MIBs;
7912 unsigned NumStackEntries =
Record[
I++];
7915 for (
unsigned J = 0; J < NumStackEntries; J++) {
7922 PendingAllocs.push_back(
AllocInfo(std::move(MIBs)));
7928 std::vector<MIBInfo> MIBs;
7929 unsigned NumMIBs =
Record[
I++];
7930 unsigned NumVersions =
Record[
I++];
7931 unsigned MIBsRead = 0;
7932 while (MIBsRead++ < NumMIBs) {
7935 unsigned NumStackEntries =
Record[
I++];
7938 for (
unsigned J = 0; J < NumStackEntries; J++) {
7947 for (
unsigned J = 0; J < NumVersions; J++)
7949 PendingAllocs.push_back(
7950 AllocInfo(std::move(Versions), std::move(MIBs)));
7960Error ModuleSummaryIndexBitcodeReader::parseModuleStringTable() {
7975 switch (Entry.Kind) {
7978 return error(
"Malformed block");
7990 switch (MaybeRecord.
get()) {
7998 return error(
"Invalid record");
8000 LastSeenModule = TheIndex.
addModule(ModulePath);
8001 ModuleIdMap[ModuleId] = LastSeenModule->
first();
8010 if (!LastSeenModule)
8011 return error(
"Invalid hash that does not follow a module path");
8013 for (
auto &Val :
Record) {
8014 assert(!(Val >> 32) &&
"Unexpected high bits set");
8015 LastSeenModule->
second[Pos++] = Val;
8018 LastSeenModule =
nullptr;
8031class BitcodeErrorCategoryType :
public std::error_category {
8032 const char *
name()
const noexcept
override {
8033 return "llvm.bitcode";
8036 std::string message(
int IE)
const override {
8039 case BitcodeError::CorruptedBitcode:
8040 return "Corrupted bitcode";
8049 static BitcodeErrorCategoryType ErrorCategory;
8050 return ErrorCategory;
8054 unsigned Block,
unsigned RecordID) {
8056 return std::move(Err);
8065 switch (Entry.Kind) {
8070 return error(
"Malformed block");
8074 return std::move(Err);
8084 if (MaybeRecord.
get() == RecordID)
8099 return FOrErr.takeError();
8100 return std::move(FOrErr->Mods);
8125 switch (Entry.Kind) {
8128 return error(
"Malformed block");
8131 uint64_t IdentificationBit = -1ull;
8135 return std::move(Err);
8141 Entry = MaybeEntry.
get();
8146 return error(
"Malformed block");
8152 return std::move(Err);
8171 if (!
I.Strtab.empty())
8178 if (!
F.Symtab.empty() &&
F.StrtabForSymtab.empty())
8179 F.StrtabForSymtab = *Strtab;
8195 if (
F.Symtab.empty())
8196 F.Symtab = *SymtabOrErr;
8201 return std::move(Err);
8206 return std::move(E);
8221BitcodeModule::getModuleImpl(
LLVMContext &Context,
bool MaterializeAll,
8222 bool ShouldLazyLoadMetadata,
bool IsImporting,
8226 std::string ProducerIdentification;
8227 if (IdentificationBit != -1ull) {
8228 if (
Error JumpFailed = Stream.JumpToBit(IdentificationBit))
8229 return std::move(JumpFailed);
8232 return std::move(E);
8235 if (
Error JumpFailed = Stream.JumpToBit(ModuleBit))
8236 return std::move(JumpFailed);
8237 auto *
R =
new BitcodeReader(std::move(Stream), Strtab, ProducerIdentification,
8240 std::unique_ptr<Module>
M =
8241 std::make_unique<Module>(ModuleIdentifier, Context);
8242 M->setMaterializer(R);
8245 if (
Error Err =
R->parseBitcodeInto(
M.get(), ShouldLazyLoadMetadata,
8246 IsImporting, Callbacks))
8247 return std::move(Err);
8249 if (MaterializeAll) {
8251 if (
Error Err =
M->materializeAll())
8252 return std::move(Err);
8255 if (
Error Err =
R->materializeForwardReferencedFunctions())
8256 return std::move(Err);
8259 return std::move(M);
8265 return getModuleImpl(
Context,
false, ShouldLazyLoadMetadata, IsImporting,
8280 ModuleSummaryIndexBitcodeReader R(std::move(Stream), Strtab, CombinedIndex,
8281 ModulePath, IsPrevailing);
8282 return R.parseModule();
8289 return std::move(JumpFailed);
8291 auto Index = std::make_unique<ModuleSummaryIndex>(
false);
8292 ModuleSummaryIndexBitcodeReader R(std::move(Stream), Strtab, *
Index,
8293 ModuleIdentifier, 0);
8295 if (
Error Err = R.parseModule())
8296 return std::move(Err);
8298 return std::move(
Index);
8306 return std::move(Err);
8311 std::pair<bool, bool> Result = {
false,
false};
8313 return std::move(E);
8315 switch (Entry.Kind) {
8318 return error(
"Malformed block");
8333 switch (MaybeBitCode.
get()) {
8339 assert(Flags <= 0x2ff &&
"Unexpected bits in flag");
8341 bool EnableSplitLTOUnit = Flags & 0x8;
8342 bool UnifiedLTO = Flags & 0x200;
8343 Result = {EnableSplitLTOUnit, UnifiedLTO};
8356 return std::move(JumpFailed);
8359 return std::move(Err);
8364 return std::move(E);
8366 switch (Entry.Kind) {
8368 return error(
"Malformed block");
8379 return Flags.takeError();
8391 return Flags.takeError();
8400 return std::move(Err);
8407 return StreamFailed.takeError();
8417 if (MsOrErr->size() != 1)
8418 return error(
"Expected a single module");
8420 return (*MsOrErr)[0];
8425 bool ShouldLazyLoadMetadata,
bool IsImporting,
8431 return BM->getLazyModule(
Context, ShouldLazyLoadMetadata, IsImporting,
8436 std::unique_ptr<MemoryBuffer> &&Buffer,
LLVMContext &Context,
8437 bool ShouldLazyLoadMetadata,
bool IsImporting,
ParserCallbacks Callbacks) {
8439 IsImporting, Callbacks);
8441 (*MOrErr)->setOwnedMemoryBuffer(std::move(Buffer));
8447 return getModuleImpl(
Context,
true,
false,
false, Callbacks);
8459 return BM->parseModule(
Context, Callbacks);
8492 return BM->readSummary(CombinedIndex, BM->getModuleIdentifier());
8501 return BM->getSummary();
8509 return BM->getLTOInfo();
8514 bool IgnoreEmptyThinLTOIndexFile) {
8519 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).
bool equals(StringRef RHS) const
equals - Check for string equality, this is more efficient than compare() when the relative ordering ...
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