24#include "llvm/Config/llvm-config.h"
54#include "llvm/IR/IntrinsicsAArch64.h"
55#include "llvm/IR/IntrinsicsARM.h"
88#include <system_error>
98 "Print the global id for each value when reading the module summary"));
103 "Expand constant expressions to instructions for testing purposes"));
110 "load-bitcode-into-experimental-debuginfo-iterators",
cl::Hidden,
111 cl::desc(
"Load bitcode directly into the new debug info format (regardless "
112 "of input format)"));
121 SWITCH_INST_MAGIC = 0x4B5
127 return make_error<StringError>(
134 "file too small to contain bitcode header");
135 for (
unsigned C : {
'B',
'C'})
139 "file doesn't start with bitcode header");
141 return Res.takeError();
142 for (
unsigned C : {0x0, 0xC, 0xE, 0xD})
146 "file doesn't start with bitcode header");
148 return Res.takeError();
153 const unsigned char *BufPtr = (
const unsigned char *)Buffer.
getBufferStart();
154 const unsigned char *BufEnd = BufPtr + Buffer.
getBufferSize();
157 return error(
"Invalid bitcode signature");
163 return error(
"Invalid bitcode wrapper header");
167 return std::move(Err);
169 return std::move(Stream);
173template <
typename StrTy>
186 if (
F.isMaterializable())
189 I.setMetadata(LLVMContext::MD_tbaa,
nullptr);
197 return std::move(Err);
202 std::string ProducerIdentification;
209 switch (Entry.Kind) {
212 return error(
"Malformed block");
214 return ProducerIdentification;
225 switch (MaybeBitCode.
get()) {
227 return error(
"Invalid value");
235 Twine(
"Incompatible epoch: Bitcode '") +
Twine(epoch) +
254 switch (Entry.Kind) {
257 return error(
"Malformed block");
265 return std::move(Err);
277 return std::move(Err);
288 switch (Entry.Kind) {
291 return error(
"Malformed block");
303 switch (MaybeRecord.
get()) {
309 return error(
"Invalid section name record");
311 if (S.find(
"__DATA,__objc_catlist") != std::string::npos ||
312 S.find(
"__OBJC,__category") != std::string::npos ||
313 S.find(
"__TEXT,__swift") != std::string::npos)
331 switch (Entry.Kind) {
333 return error(
"Malformed block");
343 return std::move(Err);
356 return std::move(Err);
369 switch (Entry.Kind) {
372 return error(
"Malformed block");
384 switch (MaybeRecord.
get()) {
389 return error(
"Invalid triple record");
408 switch (Entry.Kind) {
410 return error(
"Malformed block");
420 return std::move(Err);
427 return Skipped.takeError();
434class BitcodeReaderBase {
437 : Stream(
std::
move(Stream)), Strtab(Strtab) {
447 bool UseStrtab =
false;
454 std::pair<StringRef, ArrayRef<uint64_t>>
457 Error readBlockInfo();
460 std::string ProducerIdentification;
467Error BitcodeReaderBase::error(
const Twine &Message) {
468 std::string FullMsg = Message.
str();
469 if (!ProducerIdentification.empty())
470 FullMsg +=
" (Producer: '" + ProducerIdentification +
"' Reader: 'LLVM " +
471 LLVM_VERSION_STRING
"')";
472 return ::error(FullMsg);
478 return error(
"Invalid version record");
479 unsigned ModuleVersion =
Record[0];
480 if (ModuleVersion > 2)
481 return error(
"Invalid value");
482 UseStrtab = ModuleVersion >= 2;
483 return ModuleVersion;
486std::pair<StringRef, ArrayRef<uint64_t>>
504class BitcodeConstant final :
public Value,
509 static constexpr uint8_t SubclassID = 255;
517 static constexpr uint8_t ConstantStructOpcode = 255;
518 static constexpr uint8_t ConstantArrayOpcode = 254;
519 static constexpr uint8_t ConstantVectorOpcode = 253;
520 static constexpr uint8_t NoCFIOpcode = 252;
521 static constexpr uint8_t DSOLocalEquivalentOpcode = 251;
522 static constexpr uint8_t BlockAddressOpcode = 250;
523 static constexpr uint8_t ConstantPtrAuthOpcode = 249;
524 static constexpr uint8_t FirstSpecialOpcode = ConstantPtrAuthOpcode;
531 unsigned BlockAddressBB = 0;
532 Type *SrcElemTy =
nullptr;
533 std::optional<ConstantRange> InRange;
535 ExtraInfo(uint8_t Opcode, uint8_t Flags = 0,
Type *SrcElemTy =
nullptr,
536 std::optional<ConstantRange> InRange = std::nullopt)
537 : Opcode(Opcode),
Flags(
Flags), SrcElemTy(SrcElemTy),
540 ExtraInfo(uint8_t Opcode, uint8_t Flags,
unsigned BlockAddressBB)
541 : Opcode(Opcode),
Flags(
Flags), BlockAddressBB(BlockAddressBB) {}
546 unsigned NumOperands;
547 unsigned BlockAddressBB;
549 std::optional<ConstantRange>
InRange;
554 NumOperands(OpIDs.
size()), BlockAddressBB(
Info.BlockAddressBB),
555 SrcElemTy(
Info.SrcElemTy), InRange(
Info.InRange) {
556 std::uninitialized_copy(OpIDs.
begin(), OpIDs.
end(),
557 getTrailingObjects<unsigned>());
560 BitcodeConstant &
operator=(
const BitcodeConstant &) =
delete;
564 const ExtraInfo &Info,
566 void *Mem =
A.Allocate(totalSizeToAlloc<unsigned>(OpIDs.
size()),
567 alignof(BitcodeConstant));
568 return new (Mem) BitcodeConstant(Ty, Info, OpIDs);
571 static bool classof(
const Value *V) {
return V->getValueID() == SubclassID; }
574 return ArrayRef(getTrailingObjects<unsigned>(), NumOperands);
577 std::optional<ConstantRange> getInRange()
const {
578 assert(Opcode == Instruction::GetElementPtr);
587class BitcodeReader :
public BitcodeReaderBase,
public GVMaterializer {
589 Module *TheModule =
nullptr;
594 bool SeenValueSymbolTable =
false;
597 std::vector<std::string> SectionTable;
598 std::vector<std::string> GCTable;
600 std::vector<Type *> TypeList;
618 std::optional<MetadataLoader> MDLoader;
619 std::vector<Comdat *> ComdatList;
623 std::vector<std::pair<GlobalVariable *, unsigned>> GlobalInits;
624 std::vector<std::pair<GlobalValue *, unsigned>> IndirectSymbolInits;
626 struct FunctionOperandInfo {
628 unsigned PersonalityFn;
632 std::vector<FunctionOperandInfo> FunctionOperands;
636 std::vector<AttributeList> MAttributes;
639 std::map<unsigned, AttributeList> MAttributeGroups;
643 std::vector<BasicBlock*> FunctionBBs;
647 std::vector<Function*> FunctionsWithBodies;
652 UpdatedIntrinsicMap UpgradedIntrinsics;
657 bool SeenFirstFunctionBody =
false;
666 std::vector<uint64_t> DeferredMetadataInfo;
672 std::deque<Function *> BasicBlockFwdRefQueue;
679 std::vector<Function *> BackwardRefFunctions;
687 bool UseRelativeIDs =
false;
691 bool WillMaterializeAllForwardRefs =
false;
695 bool SeenDebugIntrinsic =
false;
696 bool SeenDebugRecord =
false;
701 std::vector<std::string> BundleTags;
704 std::optional<ValueTypeCallbackTy> ValueTypeCallback;
710 Error materializeForwardReferencedFunctions();
718 Error parseBitcodeInto(
Module *M,
bool ShouldLazyLoadMetadata,
729 std::vector<StructType *> IdentifiedStructTypes;
733 static constexpr unsigned InvalidTypeID = ~0
u;
735 Type *getTypeByID(
unsigned ID);
736 Type *getPtrElementTypeByID(
unsigned ID);
737 unsigned getContainedTypeID(
unsigned ID,
unsigned Idx = 0);
744 Value *getFnValueByID(
unsigned ID,
Type *Ty,
unsigned TyID,
752 return MDLoader->getMetadataFwdRefOrLoad(
ID);
756 if (
ID >= FunctionBBs.size())
return nullptr;
757 return FunctionBBs[
ID];
761 if (i-1 < MAttributes.size())
762 return MAttributes[i-1];
770 unsigned InstNum,
Value *&ResVal,
unsigned &
TypeID,
772 if (Slot ==
Record.size())
return true;
776 ValNo = InstNum - ValNo;
777 if (ValNo < InstNum) {
781 ResVal = getFnValueByID(ValNo,
nullptr,
TypeID, ConstExprInsertBB);
783 "Incorrect type ID stored for value");
784 return ResVal ==
nullptr;
786 if (Slot ==
Record.size())
790 ResVal = getFnValueByID(ValNo, getTypeByID(
TypeID),
TypeID,
792 return ResVal ==
nullptr;
799 unsigned InstNum,
Type *Ty,
unsigned TyID,
Value *&ResVal,
801 if (getValue(
Record, Slot, InstNum, Ty, TyID, ResVal, ConstExprInsertBB))
810 unsigned InstNum,
Type *Ty,
unsigned TyID,
Value *&ResVal,
812 ResVal = getValue(
Record, Slot, InstNum, Ty, TyID, ConstExprInsertBB);
813 return ResVal ==
nullptr;
819 unsigned InstNum,
Type *Ty,
unsigned TyID,
821 if (Slot ==
Record.size())
return nullptr;
825 ValNo = InstNum - ValNo;
826 return getFnValueByID(ValNo, Ty, TyID, ConstExprInsertBB);
831 unsigned InstNum,
Type *Ty,
unsigned TyID,
833 if (Slot ==
Record.size())
return nullptr;
837 ValNo = InstNum - ValNo;
838 return getFnValueByID(ValNo, Ty, TyID, ConstExprInsertBB);
844 if (
Record.size() - OpNum < 2)
845 return error(
"Too few records for range");
847 unsigned LowerActiveWords =
Record[OpNum];
848 unsigned UpperActiveWords =
Record[OpNum++] >> 32;
849 if (
Record.size() - OpNum < LowerActiveWords + UpperActiveWords)
850 return error(
"Too few records for range");
853 OpNum += LowerActiveWords;
856 OpNum += UpperActiveWords;
859 int64_t Start = BitcodeReader::decodeSignRotatedValue(
Record[OpNum++]);
860 int64_t
End = BitcodeReader::decodeSignRotatedValue(
Record[OpNum++]);
867 if (
Record.size() - OpNum < 1)
868 return error(
"Too few records for range");
889 Error parseGlobalIndirectSymbolRecord(
unsigned BitCode,
892 Error parseAttributeBlock();
893 Error parseAttributeGroupBlock();
894 Error parseTypeTable();
895 Error parseTypeTableBody();
896 Error parseOperandBundleTags();
897 Error parseSyncScopeNames();
900 unsigned NameIndex,
Triple &TT);
901 void setDeferredFunctionInfo(
unsigned FuncBitcodeOffsetDelta,
Function *
F,
904 Error parseGlobalValueSymbolTable();
905 Error parseConstants();
906 Error rememberAndSkipFunctionBodies();
907 Error rememberAndSkipFunctionBody();
909 Error rememberAndSkipMetadata();
912 Error globalCleanup();
913 Error resolveGlobalAndIndirectSymbolInits();
914 Error parseUseLists();
915 Error findFunctionInStream(
924class ModuleSummaryIndexBitcodeReader :
public BitcodeReaderBase {
930 bool SeenGlobalValSummary =
false;
933 bool SeenValueSymbolTable =
false;
949 std::tuple<ValueInfo, GlobalValue::GUID, GlobalValue::GUID>>
950 ValueIdToValueInfoMap;
959 std::string SourceFileName;
971 std::vector<uint64_t> StackIds;
974 ModuleSummaryIndexBitcodeReader(
985 Error parseValueSymbolTable(
990 bool IsOldProfileFormat,
993 Error parseEntireSummary(
unsigned ID);
994 Error parseModuleStringTable();
998 std::vector<FunctionSummary::ParamAccess>
1001 template <
bool AllowNullValueInfo = false>
1002 std::tuple<ValueInfo, GlobalValue::GUID, GlobalValue::GUID>
1003 getValueInfoFromValueId(
unsigned ValueId);
1005 void addThisModule();
1021 return std::error_code();
1027 : BitcodeReaderBase(
std::
move(Stream), Strtab), Context(Context),
1028 ValueList(this->Stream.SizeInBytes(),
1030 return materializeValue(
ValID, InsertBB);
1032 this->ProducerIdentification = std::string(ProducerIdentification);
1035Error BitcodeReader::materializeForwardReferencedFunctions() {
1036 if (WillMaterializeAllForwardRefs)
1040 WillMaterializeAllForwardRefs =
true;
1042 while (!BasicBlockFwdRefQueue.empty()) {
1043 Function *
F = BasicBlockFwdRefQueue.front();
1044 BasicBlockFwdRefQueue.pop_front();
1045 assert(
F &&
"Expected valid function");
1046 if (!BasicBlockFwdRefs.
count(
F))
1054 if (!
F->isMaterializable())
1055 return error(
"Never resolved function from blockaddress");
1058 if (
Error Err = materialize(
F))
1061 assert(BasicBlockFwdRefs.
empty() &&
"Function missing from queue");
1063 for (
Function *
F : BackwardRefFunctions)
1064 if (
Error Err = materialize(
F))
1066 BackwardRefFunctions.clear();
1069 WillMaterializeAllForwardRefs =
false;
1133 Flags.ReadNone = RawFlags & 0x1;
1134 Flags.ReadOnly = (RawFlags >> 1) & 0x1;
1135 Flags.NoRecurse = (RawFlags >> 2) & 0x1;
1136 Flags.ReturnDoesNotAlias = (RawFlags >> 3) & 0x1;
1137 Flags.NoInline = (RawFlags >> 4) & 0x1;
1138 Flags.AlwaysInline = (RawFlags >> 5) & 0x1;
1139 Flags.NoUnwind = (RawFlags >> 6) & 0x1;
1140 Flags.MayThrow = (RawFlags >> 7) & 0x1;
1141 Flags.HasUnknownCall = (RawFlags >> 8) & 0x1;
1142 Flags.MustBeUnreachable = (RawFlags >> 9) & 0x1;
1158 RawFlags = RawFlags >> 4;
1159 bool NotEligibleToImport = (RawFlags & 0x1) || Version < 3;
1163 bool Live = (RawFlags & 0x2) || Version < 3;
1164 bool Local = (RawFlags & 0x4);
1165 bool AutoHide = (RawFlags & 0x8);
1168 Live, Local, AutoHide, IK);
1174 (RawFlags & 0x1) ?
true :
false, (RawFlags & 0x2) ?
true :
false,
1175 (RawFlags & 0x4) ?
true :
false,
1179static std::pair<CalleeInfo::HotnessType, bool>
1183 bool HasTailCall = (RawFlags & 0x8);
1184 return {Hotness, HasTailCall};
1188 bool &HasTailCall) {
1189 static constexpr uint64_t RelBlockFreqMask =
1191 RelBF = RawFlags & RelBlockFreqMask;
1217 case 0:
return false;
1218 case 1:
return true;
1241 case 0:
return GlobalVariable::NotThreadLocal;
1243 case 1:
return GlobalVariable::GeneralDynamicTLSModel;
1244 case 2:
return GlobalVariable::LocalDynamicTLSModel;
1245 case 3:
return GlobalVariable::InitialExecTLSModel;
1246 case 4:
return GlobalVariable::LocalExecTLSModel;
1253 case 0:
return GlobalVariable::UnnamedAddr::None;
1254 case 1:
return GlobalVariable::UnnamedAddr::Global;
1255 case 2:
return GlobalVariable::UnnamedAddr::Local;
1288 return IsFP ? Instruction::FNeg : -1;
1302 return IsFP ? Instruction::FAdd : Instruction::Add;
1304 return IsFP ? Instruction::FSub : Instruction::Sub;
1306 return IsFP ? Instruction::FMul : Instruction::Mul;
1308 return IsFP ? -1 : Instruction::UDiv;
1310 return IsFP ? Instruction::FDiv : Instruction::SDiv;
1312 return IsFP ? -1 : Instruction::URem;
1314 return IsFP ? Instruction::FRem : Instruction::SRem;
1316 return IsFP ? -1 : Instruction::Shl;
1318 return IsFP ? -1 : Instruction::LShr;
1320 return IsFP ? -1 : Instruction::AShr;
1322 return IsFP ? -1 : Instruction::And;
1324 return IsFP ? -1 : Instruction::Or;
1326 return IsFP ? -1 : Instruction::Xor;
1415Type *BitcodeReader::getTypeByID(
unsigned ID) {
1417 if (
ID >= TypeList.size())
1420 if (
Type *Ty = TypeList[
ID])
1425 return TypeList[
ID] = createIdentifiedStructType(Context);
1428unsigned BitcodeReader::getContainedTypeID(
unsigned ID,
unsigned Idx) {
1429 auto It = ContainedTypeIDs.
find(
ID);
1430 if (It == ContainedTypeIDs.
end())
1431 return InvalidTypeID;
1433 if (
Idx >= It->second.size())
1434 return InvalidTypeID;
1436 return It->second[
Idx];
1439Type *BitcodeReader::getPtrElementTypeByID(
unsigned ID) {
1440 if (
ID >= TypeList.size())
1447 return getTypeByID(getContainedTypeID(
ID, 0));
1450unsigned BitcodeReader::getVirtualTypeID(
Type *Ty,
1452 unsigned ChildTypeID = ChildTypeIDs.
empty() ? InvalidTypeID : ChildTypeIDs[0];
1453 auto CacheKey = std::make_pair(Ty, ChildTypeID);
1454 auto It = VirtualTypeIDs.
find(CacheKey);
1455 if (It != VirtualTypeIDs.
end()) {
1461 ContainedTypeIDs[It->second] == ChildTypeIDs) &&
1462 "Incorrect cached contained type IDs");
1466 unsigned TypeID = TypeList.size();
1467 TypeList.push_back(Ty);
1468 if (!ChildTypeIDs.
empty())
1486 uint8_t Opcode = BC->Opcode;
1489 if (Opcode >= BitcodeConstant::FirstSpecialOpcode)
1503 if (Opcode == Instruction::GetElementPtr)
1507 case Instruction::FNeg:
1508 case Instruction::Select:
1509 case Instruction::ICmp:
1510 case Instruction::FCmp:
1520 if (StartValID < ValueList.
size() && ValueList[StartValID] &&
1521 !isa<BitcodeConstant>(ValueList[StartValID]))
1522 return ValueList[StartValID];
1527 while (!Worklist.
empty()) {
1536 return error(
"Invalid value ID");
1539 auto *BC = dyn_cast<BitcodeConstant>(V);
1549 for (
unsigned OpID :
reverse(BC->getOperandIDs())) {
1550 auto It = MaterializedValues.
find(OpID);
1551 if (It != MaterializedValues.
end())
1559 if (Ops.
size() != BC->getOperandIDs().size())
1561 std::reverse(Ops.
begin(), Ops.
end());
1565 if (
auto *
C = dyn_cast<Constant>(
Op))
1578 switch (BC->Opcode) {
1579 case BitcodeConstant::ConstantPtrAuthOpcode: {
1580 auto *
Key = dyn_cast<ConstantInt>(ConstOps[1]);
1582 return error(
"ptrauth key operand must be ConstantInt");
1584 auto *Disc = dyn_cast<ConstantInt>(ConstOps[2]);
1586 return error(
"ptrauth disc operand must be ConstantInt");
1591 case BitcodeConstant::NoCFIOpcode: {
1592 auto *GV = dyn_cast<GlobalValue>(ConstOps[0]);
1594 return error(
"no_cfi operand must be GlobalValue");
1598 case BitcodeConstant::DSOLocalEquivalentOpcode: {
1599 auto *GV = dyn_cast<GlobalValue>(ConstOps[0]);
1601 return error(
"dso_local operand must be GlobalValue");
1605 case BitcodeConstant::BlockAddressOpcode: {
1606 Function *Fn = dyn_cast<Function>(ConstOps[0]);
1608 return error(
"blockaddress operand must be a function");
1613 unsigned BBID = BC->BlockAddressBB;
1616 return error(
"Invalid ID");
1619 for (
size_t I = 0, E = BBID;
I != E; ++
I) {
1621 return error(
"Invalid ID");
1628 auto &FwdBBs = BasicBlockFwdRefs[Fn];
1630 BasicBlockFwdRefQueue.push_back(Fn);
1631 if (FwdBBs.size() < BBID + 1)
1632 FwdBBs.resize(BBID + 1);
1640 case BitcodeConstant::ConstantStructOpcode:
1643 case BitcodeConstant::ConstantArrayOpcode:
1646 case BitcodeConstant::ConstantVectorOpcode:
1649 case Instruction::GetElementPtr:
1651 BC->SrcElemTy, ConstOps[0],
ArrayRef(ConstOps).drop_front(),
1654 case Instruction::ExtractElement:
1657 case Instruction::InsertElement:
1661 case Instruction::ShuffleVector: {
1680 return error(
Twine(
"Value referenced by initializer is an unsupported "
1681 "constant expression of type ") +
1682 BC->getOpcodeName());
1688 BC->getType(),
"constexpr", InsertBB);
1691 "constexpr", InsertBB);
1694 Ops[1],
"constexpr", InsertBB);
1695 if (isa<OverflowingBinaryOperator>(
I)) {
1697 I->setHasNoSignedWrap();
1699 I->setHasNoUnsignedWrap();
1701 if (isa<PossiblyExactOperator>(
I) &&
1705 switch (BC->Opcode) {
1706 case BitcodeConstant::ConstantVectorOpcode: {
1710 Value *
Idx = ConstantInt::get(IdxTy, Pair.index());
1714 I = cast<Instruction>(V);
1717 case BitcodeConstant::ConstantStructOpcode:
1718 case BitcodeConstant::ConstantArrayOpcode: {
1722 "constexpr.ins", InsertBB);
1723 I = cast<Instruction>(V);
1726 case Instruction::ICmp:
1727 case Instruction::FCmp:
1730 "constexpr", InsertBB);
1732 case Instruction::GetElementPtr:
1734 ArrayRef(Ops).drop_front(),
"constexpr",
1738 case Instruction::Select:
1741 case Instruction::ExtractElement:
1744 case Instruction::InsertElement:
1748 case Instruction::ShuffleVector:
1761 return MaterializedValues[StartValID];
1770 return cast<Constant>(MaybeV.
get());
1776 IdentifiedStructTypes.push_back(Ret);
1782 IdentifiedStructTypes.push_back(Ret);
1798 case Attribute::ZExt:
return 1 << 0;
1799 case Attribute::SExt:
return 1 << 1;
1800 case Attribute::NoReturn:
return 1 << 2;
1801 case Attribute::InReg:
return 1 << 3;
1802 case Attribute::StructRet:
return 1 << 4;
1803 case Attribute::NoUnwind:
return 1 << 5;
1804 case Attribute::NoAlias:
return 1 << 6;
1805 case Attribute::ByVal:
return 1 << 7;
1806 case Attribute::Nest:
return 1 << 8;
1807 case Attribute::ReadNone:
return 1 << 9;
1808 case Attribute::ReadOnly:
return 1 << 10;
1809 case Attribute::NoInline:
return 1 << 11;
1810 case Attribute::AlwaysInline:
return 1 << 12;
1811 case Attribute::OptimizeForSize:
return 1 << 13;
1812 case Attribute::StackProtect:
return 1 << 14;
1813 case Attribute::StackProtectReq:
return 1 << 15;
1814 case Attribute::Alignment:
return 31 << 16;
1815 case Attribute::NoCapture:
return 1 << 21;
1816 case Attribute::NoRedZone:
return 1 << 22;
1817 case Attribute::NoImplicitFloat:
return 1 << 23;
1818 case Attribute::Naked:
return 1 << 24;
1819 case Attribute::InlineHint:
return 1 << 25;
1820 case Attribute::StackAlignment:
return 7 << 26;
1821 case Attribute::ReturnsTwice:
return 1 << 29;
1822 case Attribute::UWTable:
return 1 << 30;
1823 case Attribute::NonLazyBind:
return 1U << 31;
1824 case Attribute::SanitizeAddress:
return 1ULL << 32;
1825 case Attribute::MinSize:
return 1ULL << 33;
1826 case Attribute::NoDuplicate:
return 1ULL << 34;
1827 case Attribute::StackProtectStrong:
return 1ULL << 35;
1828 case Attribute::SanitizeThread:
return 1ULL << 36;
1829 case Attribute::SanitizeMemory:
return 1ULL << 37;
1830 case Attribute::NoBuiltin:
return 1ULL << 38;
1831 case Attribute::Returned:
return 1ULL << 39;
1832 case Attribute::Cold:
return 1ULL << 40;
1833 case Attribute::Builtin:
return 1ULL << 41;
1834 case Attribute::OptimizeNone:
return 1ULL << 42;
1835 case Attribute::InAlloca:
return 1ULL << 43;
1836 case Attribute::NonNull:
return 1ULL << 44;
1837 case Attribute::JumpTable:
return 1ULL << 45;
1838 case Attribute::Convergent:
return 1ULL << 46;
1839 case Attribute::SafeStack:
return 1ULL << 47;
1840 case Attribute::NoRecurse:
return 1ULL << 48;
1843 case Attribute::SwiftSelf:
return 1ULL << 51;
1844 case Attribute::SwiftError:
return 1ULL << 52;
1845 case Attribute::WriteOnly:
return 1ULL << 53;
1846 case Attribute::Speculatable:
return 1ULL << 54;
1847 case Attribute::StrictFP:
return 1ULL << 55;
1848 case Attribute::SanitizeHWAddress:
return 1ULL << 56;
1849 case Attribute::NoCfCheck:
return 1ULL << 57;
1850 case Attribute::OptForFuzzing:
return 1ULL << 58;
1851 case Attribute::ShadowCallStack:
return 1ULL << 59;
1852 case Attribute::SpeculativeLoadHardening:
1854 case Attribute::ImmArg:
1856 case Attribute::WillReturn:
1858 case Attribute::NoFree:
1874 if (
I == Attribute::Alignment)
1875 B.addAlignmentAttr(1ULL << ((
A >> 16) - 1));
1876 else if (
I == Attribute::StackAlignment)
1877 B.addStackAlignmentAttr(1ULL << ((
A >> 26)-1));
1879 B.addTypeAttr(
I,
nullptr);
1894 unsigned Alignment = (EncodedAttrs & (0xffffULL << 16)) >> 16;
1896 "Alignment must be a power of two.");
1899 B.addAlignmentAttr(Alignment);
1901 uint64_t Attrs = ((EncodedAttrs & (0xfffffULL << 32)) >> 11) |
1902 (EncodedAttrs & 0xffff);
1907 if (Attrs & (1ULL << 9)) {
1909 Attrs &= ~(1ULL << 9);
1912 if (Attrs & (1ULL << 10)) {
1914 Attrs &= ~(1ULL << 10);
1917 if (Attrs & (1ULL << 49)) {
1919 Attrs &= ~(1ULL << 49);
1922 if (Attrs & (1ULL << 50)) {
1924 Attrs &= ~(1ULL << 50);
1927 if (Attrs & (1ULL << 53)) {
1929 Attrs &= ~(1ULL << 53);
1933 B.addMemoryAttr(ME);
1939Error BitcodeReader::parseAttributeBlock() {
1943 if (!MAttributes.empty())
1944 return error(
"Invalid multiple blocks");
1957 switch (
Entry.Kind) {
1960 return error(
"Malformed block");
1973 switch (MaybeRecord.
get()) {
1979 return error(
"Invalid parameter attribute record");
1981 for (
unsigned i = 0, e =
Record.size(); i != e; i += 2) {
1991 for (
unsigned i = 0, e =
Record.size(); i != e; ++i)
2007 return Attribute::Alignment;
2009 return Attribute::AlwaysInline;
2011 return Attribute::Builtin;
2013 return Attribute::ByVal;
2015 return Attribute::InAlloca;
2017 return Attribute::Cold;
2019 return Attribute::Convergent;
2021 return Attribute::DisableSanitizerInstrumentation;
2023 return Attribute::ElementType;
2025 return Attribute::FnRetThunkExtern;
2027 return Attribute::InlineHint;
2029 return Attribute::InReg;
2031 return Attribute::JumpTable;
2033 return Attribute::Memory;
2035 return Attribute::NoFPClass;
2037 return Attribute::MinSize;
2039 return Attribute::Naked;
2041 return Attribute::Nest;
2043 return Attribute::NoAlias;
2045 return Attribute::NoBuiltin;
2047 return Attribute::NoCallback;
2049 return Attribute::NoCapture;
2051 return Attribute::NoDuplicate;
2053 return Attribute::NoFree;
2055 return Attribute::NoImplicitFloat;
2057 return Attribute::NoInline;
2059 return Attribute::NoRecurse;
2061 return Attribute::NoMerge;
2063 return Attribute::NonLazyBind;
2065 return Attribute::NonNull;
2067 return Attribute::Dereferenceable;
2069 return Attribute::DereferenceableOrNull;
2071 return Attribute::AllocAlign;
2073 return Attribute::AllocKind;
2075 return Attribute::AllocSize;
2077 return Attribute::AllocatedPointer;
2079 return Attribute::NoRedZone;
2081 return Attribute::NoReturn;
2083 return Attribute::NoSync;
2085 return Attribute::NoCfCheck;
2087 return Attribute::NoProfile;
2089 return Attribute::SkipProfile;
2091 return Attribute::NoUnwind;
2093 return Attribute::NoSanitizeBounds;
2095 return Attribute::NoSanitizeCoverage;
2097 return Attribute::NullPointerIsValid;
2099 return Attribute::OptimizeForDebugging;
2101 return Attribute::OptForFuzzing;
2103 return Attribute::OptimizeForSize;
2105 return Attribute::OptimizeNone;
2107 return Attribute::ReadNone;
2109 return Attribute::ReadOnly;
2111 return Attribute::Returned;
2113 return Attribute::ReturnsTwice;
2115 return Attribute::SExt;
2117 return Attribute::Speculatable;
2119 return Attribute::StackAlignment;
2121 return Attribute::StackProtect;
2123 return Attribute::StackProtectReq;
2125 return Attribute::StackProtectStrong;
2127 return Attribute::SafeStack;
2129 return Attribute::ShadowCallStack;
2131 return Attribute::StrictFP;
2133 return Attribute::StructRet;
2135 return Attribute::SanitizeAddress;
2137 return Attribute::SanitizeHWAddress;
2139 return Attribute::SanitizeThread;
2141 return Attribute::SanitizeMemory;
2143 return Attribute::SanitizeNumericalStability;
2145 return Attribute::SpeculativeLoadHardening;
2147 return Attribute::SwiftError;
2149 return Attribute::SwiftSelf;
2151 return Attribute::SwiftAsync;
2153 return Attribute::UWTable;
2155 return Attribute::VScaleRange;
2157 return Attribute::WillReturn;
2159 return Attribute::WriteOnly;
2161 return Attribute::ZExt;
2163 return Attribute::ImmArg;
2165 return Attribute::SanitizeMemTag;
2167 return Attribute::Preallocated;
2169 return Attribute::NoUndef;
2171 return Attribute::ByRef;
2173 return Attribute::MustProgress;
2175 return Attribute::Hot;
2177 return Attribute::PresplitCoroutine;
2179 return Attribute::Writable;
2181 return Attribute::CoroDestroyOnlyWhenComplete;
2183 return Attribute::DeadOnUnwind;
2185 return Attribute::Range;
2187 return Attribute::Initializes;
2196 return error(
"Invalid alignment value");
2204 return error(
"Unknown attribute kind (" +
Twine(Code) +
")");
2209 switch (EncodedKind) {
2233Error BitcodeReader::parseAttributeGroupBlock() {
2237 if (!MAttributeGroups.empty())
2238 return error(
"Invalid multiple blocks");
2249 switch (
Entry.Kind) {
2252 return error(
"Malformed block");
2265 switch (MaybeRecord.
get()) {
2270 return error(
"Invalid grp record");
2277 for (
unsigned i = 2, e =
Record.size(); i != e; ++i) {
2285 if (
Error Err = parseAttrKind(EncodedKind, &Kind))
2291 if (Kind == Attribute::ByVal)
2292 B.addByValAttr(
nullptr);
2293 else if (Kind == Attribute::StructRet)
2294 B.addStructRetAttr(
nullptr);
2295 else if (Kind == Attribute::InAlloca)
2296 B.addInAllocaAttr(
nullptr);
2297 else if (Kind == Attribute::UWTable)
2298 B.addUWTableAttr(UWTableKind::Default);
2300 B.addAttribute(Kind);
2302 return error(
"Not an enum attribute");
2303 }
else if (
Record[i] == 1) {
2305 if (
Error Err = parseAttrKind(
Record[++i], &Kind))
2308 return error(
"Not an int attribute");
2309 if (Kind == Attribute::Alignment)
2310 B.addAlignmentAttr(
Record[++i]);
2311 else if (Kind == Attribute::StackAlignment)
2312 B.addStackAlignmentAttr(
Record[++i]);
2313 else if (Kind == Attribute::Dereferenceable)
2314 B.addDereferenceableAttr(
Record[++i]);
2315 else if (Kind == Attribute::DereferenceableOrNull)
2316 B.addDereferenceableOrNullAttr(
Record[++i]);
2317 else if (Kind == Attribute::AllocSize)
2318 B.addAllocSizeAttrFromRawRepr(
Record[++i]);
2319 else if (Kind == Attribute::VScaleRange)
2320 B.addVScaleRangeAttrFromRawRepr(
Record[++i]);
2321 else if (Kind == Attribute::UWTable)
2323 else if (Kind == Attribute::AllocKind)
2325 else if (Kind == Attribute::Memory)
2327 else if (Kind == Attribute::NoFPClass)
2335 while (
Record[i] != 0 && i != e)
2337 assert(
Record[i] == 0 &&
"Kind string not null terminated");
2342 while (
Record[i] != 0 && i != e)
2344 assert(
Record[i] == 0 &&
"Value string not null terminated");
2347 B.addAttribute(KindStr.
str(), ValStr.
str());
2349 bool HasType =
Record[i] == 6;
2351 if (
Error Err = parseAttrKind(
Record[++i], &Kind))
2354 return error(
"Not a type attribute");
2356 B.addTypeAttr(Kind, HasType ? getTypeByID(
Record[++i]) :
nullptr);
2357 }
else if (
Record[i] == 7) {
2361 if (
Error Err = parseAttrKind(
Record[i++], &Kind))
2364 return error(
"Not a ConstantRange attribute");
2367 readBitWidthAndConstantRange(
Record, i);
2372 B.addConstantRangeAttr(Kind, MaybeCR.
get());
2373 }
else if (
Record[i] == 8) {
2377 if (
Error Err = parseAttrKind(
Record[i++], &Kind))
2380 return error(
"Not a constant range list attribute");
2384 return error(
"Too few records for constant range list");
2385 unsigned RangeSize =
Record[i++];
2387 for (
unsigned Idx = 0;
Idx < RangeSize; ++
Idx) {
2397 return error(
"Invalid (unordered or overlapping) range list");
2398 B.addConstantRangeListAttr(Kind, Val);
2400 return error(
"Invalid attribute group entry");
2405 B.addMemoryAttr(ME);
2415Error BitcodeReader::parseTypeTable() {
2419 return parseTypeTableBody();
2422Error BitcodeReader::parseTypeTableBody() {
2423 if (!TypeList.empty())
2424 return error(
"Invalid multiple blocks");
2427 unsigned NumRecords = 0;
2438 switch (
Entry.Kind) {
2441 return error(
"Malformed block");
2443 if (NumRecords != TypeList.size())
2444 return error(
"Malformed block");
2453 Type *ResultTy =
nullptr;
2458 switch (MaybeRecord.
get()) {
2460 return error(
"Invalid value");
2465 return error(
"Invalid numentry record");
2466 TypeList.resize(
Record[0]);
2509 return error(
"Invalid integer record");
2514 return error(
"Bitwidth for integer type out of range");
2521 return error(
"Invalid pointer record");
2525 ResultTy = getTypeByID(
Record[0]);
2527 !PointerType::isValidElementType(ResultTy))
2528 return error(
"Invalid type");
2535 return error(
"Invalid opaque pointer record");
2544 return error(
"Invalid function record");
2546 for (
unsigned i = 3, e =
Record.size(); i != e; ++i) {
2553 ResultTy = getTypeByID(
Record[2]);
2554 if (!ResultTy || ArgTys.
size() <
Record.size()-3)
2555 return error(
"Invalid type");
2558 ResultTy = FunctionType::get(ResultTy, ArgTys,
Record[0]);
2564 return error(
"Invalid function record");
2566 for (
unsigned i = 2, e =
Record.size(); i != e; ++i) {
2568 if (!FunctionType::isValidArgumentType(
T))
2569 return error(
"Invalid function argument type");
2576 ResultTy = getTypeByID(
Record[1]);
2577 if (!ResultTy || ArgTys.
size() <
Record.size()-2)
2578 return error(
"Invalid type");
2581 ResultTy = FunctionType::get(ResultTy, ArgTys,
Record[0]);
2586 return error(
"Invalid anon struct record");
2588 for (
unsigned i = 1, e =
Record.size(); i != e; ++i) {
2595 return error(
"Invalid type");
2602 return error(
"Invalid struct name record");
2607 return error(
"Invalid named struct record");
2609 if (NumRecords >= TypeList.size())
2610 return error(
"Invalid TYPE table");
2613 StructType *Res = cast_or_null<StructType>(TypeList[NumRecords]);
2616 TypeList[NumRecords] =
nullptr;
2618 Res = createIdentifiedStructType(Context, TypeName);
2622 for (
unsigned i = 1, e =
Record.size(); i != e; ++i) {
2629 return error(
"Invalid named struct record");
2637 return error(
"Invalid opaque type record");
2639 if (NumRecords >= TypeList.size())
2640 return error(
"Invalid TYPE table");
2643 StructType *Res = cast_or_null<StructType>(TypeList[NumRecords]);
2646 TypeList[NumRecords] =
nullptr;
2648 Res = createIdentifiedStructType(Context, TypeName);
2655 return error(
"Invalid target extension type record");
2657 if (NumRecords >= TypeList.size())
2658 return error(
"Invalid TYPE table");
2661 return error(
"Too many type parameters");
2663 unsigned NumTys =
Record[0];
2666 for (
unsigned i = 0; i < NumTys; i++) {
2670 return error(
"Invalid type");
2673 for (
unsigned i = NumTys + 1, e =
Record.size(); i < e; i++) {
2674 if (
Record[i] > UINT_MAX)
2675 return error(
"Integer parameter too large");
2684 return error(
"Invalid array type record");
2685 ResultTy = getTypeByID(
Record[1]);
2686 if (!ResultTy || !ArrayType::isValidElementType(ResultTy))
2687 return error(
"Invalid type");
2689 ResultTy = ArrayType::get(ResultTy,
Record[0]);
2694 return error(
"Invalid vector type record");
2696 return error(
"Invalid vector length");
2697 ResultTy = getTypeByID(
Record[1]);
2698 if (!ResultTy || !VectorType::isValidElementType(ResultTy))
2699 return error(
"Invalid type");
2702 ResultTy = VectorType::get(ResultTy,
Record[0], Scalable);
2706 if (NumRecords >= TypeList.size())
2707 return error(
"Invalid TYPE table");
2708 if (TypeList[NumRecords])
2710 "Invalid TYPE table: Only named structs can be forward referenced");
2711 assert(ResultTy &&
"Didn't read a type?");
2712 TypeList[NumRecords] = ResultTy;
2713 if (!ContainedIDs.
empty())
2714 ContainedTypeIDs[NumRecords] = std::move(ContainedIDs);
2719Error BitcodeReader::parseOperandBundleTags() {
2723 if (!BundleTags.empty())
2724 return error(
"Invalid multiple blocks");
2734 switch (
Entry.Kind) {
2737 return error(
"Malformed block");
2751 return error(
"Invalid operand bundle record");
2754 BundleTags.emplace_back();
2756 return error(
"Invalid operand bundle record");
2761Error BitcodeReader::parseSyncScopeNames() {
2766 return error(
"Invalid multiple synchronization scope names blocks");
2775 switch (
Entry.Kind) {
2778 return error(
"Malformed block");
2781 return error(
"Invalid empty synchronization scope names block");
2795 return error(
"Invalid sync scope record");
2799 return error(
"Invalid sync scope record");
2808 unsigned NameIndex,
Triple &TT) {
2811 return error(
"Invalid record");
2812 unsigned ValueID =
Record[0];
2813 if (ValueID >= ValueList.
size() || !ValueList[ValueID])
2814 return error(
"Invalid record");
2815 Value *
V = ValueList[ValueID];
2818 if (NameStr.contains(0))
2819 return error(
"Invalid value name");
2820 V->setName(NameStr);
2821 auto *GO = dyn_cast<GlobalObject>(V);
2822 if (GO && ImplicitComdatObjects.
contains(GO) &&
TT.supportsCOMDAT())
2835 return std::move(JumpFailed);
2841 return error(
"Expected value symbol table subblock");
2845void BitcodeReader::setDeferredFunctionInfo(
unsigned FuncBitcodeOffsetDelta,
2852 uint64_t FuncBitOffset = FuncWordOffset * 32;
2853 DeferredFunctionInfo[
F] = FuncBitOffset + FuncBitcodeOffsetDelta;
2857 if (FuncBitOffset > LastFunctionBlockBit)
2858 LastFunctionBlockBit = FuncBitOffset;
2862Error BitcodeReader::parseGlobalValueSymbolTable() {
2863 unsigned FuncBitcodeOffsetDelta =
2876 switch (
Entry.Kind) {
2879 return error(
"Malformed block");
2890 switch (MaybeRecord.
get()) {
2892 unsigned ValueID =
Record[0];
2893 if (ValueID >= ValueList.
size() || !ValueList[ValueID])
2894 return error(
"Invalid value reference in symbol table");
2895 setDeferredFunctionInfo(FuncBitcodeOffsetDelta,
2896 cast<Function>(ValueList[ValueID]),
Record);
2912 if (!MaybeCurrentBit)
2914 CurrentBit = MaybeCurrentBit.
get();
2917 if (
Error Err = parseGlobalValueSymbolTable())
2919 if (
Error JumpFailed = Stream.JumpToBit(CurrentBit))
2938 unsigned FuncBitcodeOffsetDelta =
2957 switch (
Entry.Kind) {
2960 return error(
"Malformed block");
2963 if (
Error JumpFailed = Stream.JumpToBit(CurrentBit))
2976 switch (MaybeRecord.
get()) {
2995 if (
auto *
F = dyn_cast<Function>(V))
2996 setDeferredFunctionInfo(FuncBitcodeOffsetDelta,
F,
Record);
3001 return error(
"Invalid bbentry record");
3004 return error(
"Invalid bbentry record");
3026Error BitcodeReader::resolveGlobalAndIndirectSymbolInits() {
3027 std::vector<std::pair<GlobalVariable *, unsigned>> GlobalInitWorklist;
3028 std::vector<std::pair<GlobalValue *, unsigned>> IndirectSymbolInitWorklist;
3029 std::vector<FunctionOperandInfo> FunctionOperandWorklist;
3031 GlobalInitWorklist.swap(GlobalInits);
3032 IndirectSymbolInitWorklist.swap(IndirectSymbolInits);
3033 FunctionOperandWorklist.swap(FunctionOperands);
3035 while (!GlobalInitWorklist.empty()) {
3036 unsigned ValID = GlobalInitWorklist.back().second;
3039 GlobalInits.push_back(GlobalInitWorklist.back());
3044 GlobalInitWorklist.back().first->setInitializer(MaybeC.
get());
3046 GlobalInitWorklist.pop_back();
3049 while (!IndirectSymbolInitWorklist.empty()) {
3050 unsigned ValID = IndirectSymbolInitWorklist.back().second;
3052 IndirectSymbolInits.push_back(IndirectSymbolInitWorklist.back());
3058 GlobalValue *GV = IndirectSymbolInitWorklist.back().first;
3059 if (
auto *GA = dyn_cast<GlobalAlias>(GV)) {
3061 return error(
"Alias and aliasee types don't match");
3063 }
else if (
auto *GI = dyn_cast<GlobalIFunc>(GV)) {
3066 return error(
"Expected an alias or an ifunc");
3069 IndirectSymbolInitWorklist.pop_back();
3072 while (!FunctionOperandWorklist.empty()) {
3073 FunctionOperandInfo &
Info = FunctionOperandWorklist.back();
3074 if (
Info.PersonalityFn) {
3075 unsigned ValID =
Info.PersonalityFn - 1;
3080 Info.F->setPersonalityFn(MaybeC.
get());
3081 Info.PersonalityFn = 0;
3090 Info.F->setPrefixData(MaybeC.
get());
3094 if (
Info.Prologue) {
3100 Info.F->setPrologueData(MaybeC.
get());
3104 if (
Info.PersonalityFn ||
Info.Prefix ||
Info.Prologue)
3105 FunctionOperands.push_back(Info);
3106 FunctionOperandWorklist.pop_back();
3115 BitcodeReader::decodeSignRotatedValue);
3117 return APInt(TypeBits, Words);
3120Error BitcodeReader::parseConstants() {
3128 unsigned Int32TyID = getVirtualTypeID(CurTy);
3129 unsigned CurTyID = Int32TyID;
3130 Type *CurElemTy =
nullptr;
3131 unsigned NextCstNo = ValueList.
size();
3139 switch (Entry.Kind) {
3142 return error(
"Malformed block");
3144 if (NextCstNo != ValueList.
size())
3145 return error(
"Invalid constant reference");
3159 switch (
unsigned BitCode = MaybeBitCode.
get()) {
3169 return error(
"Invalid settype record");
3170 if (
Record[0] >= TypeList.size() || !TypeList[
Record[0]])
3171 return error(
"Invalid settype record");
3172 if (TypeList[
Record[0]] == VoidType)
3173 return error(
"Invalid constant type");
3175 CurTy = TypeList[CurTyID];
3176 CurElemTy = getPtrElementTypeByID(CurTyID);
3180 return error(
"Invalid type for a constant null value");
3181 if (
auto *TETy = dyn_cast<TargetExtType>(CurTy))
3183 return error(
"Invalid type for a constant null value");
3188 return error(
"Invalid integer const record");
3193 return error(
"Invalid wide integer const record");
3197 V = ConstantInt::get(CurTy, VInt);
3202 return error(
"Invalid float const record");
3205 if (ScalarTy->isHalfTy())
3206 V = ConstantFP::get(CurTy,
APFloat(APFloat::IEEEhalf(),
3208 else if (ScalarTy->isBFloatTy())
3209 V = ConstantFP::get(
3211 else if (ScalarTy->isFloatTy())
3212 V = ConstantFP::get(CurTy,
APFloat(APFloat::IEEEsingle(),
3214 else if (ScalarTy->isDoubleTy())
3215 V = ConstantFP::get(
3217 else if (ScalarTy->isX86_FP80Ty()) {
3220 Rearrange[0] = (
Record[1] & 0xffffLL) | (
Record[0] << 16);
3221 Rearrange[1] =
Record[0] >> 48;
3222 V = ConstantFP::get(
3223 CurTy,
APFloat(APFloat::x87DoubleExtended(),
APInt(80, Rearrange)));
3224 }
else if (ScalarTy->isFP128Ty())
3225 V = ConstantFP::get(CurTy,
3227 else if (ScalarTy->isPPC_FP128Ty())
3228 V = ConstantFP::get(
3237 return error(
"Invalid aggregate record");
3241 for (
unsigned i = 0; i !=
Size; ++i)
3244 if (isa<StructType>(CurTy)) {
3245 V = BitcodeConstant::create(
3246 Alloc, CurTy, BitcodeConstant::ConstantStructOpcode, Elts);
3247 }
else if (isa<ArrayType>(CurTy)) {
3248 V = BitcodeConstant::create(Alloc, CurTy,
3249 BitcodeConstant::ConstantArrayOpcode, Elts);
3250 }
else if (isa<VectorType>(CurTy)) {
3251 V = BitcodeConstant::create(
3252 Alloc, CurTy, BitcodeConstant::ConstantVectorOpcode, Elts);
3261 return error(
"Invalid string record");
3270 return error(
"Invalid data record");
3273 if (
auto *Array = dyn_cast<ArrayType>(CurTy))
3274 EltTy =
Array->getElementType();
3276 EltTy = cast<VectorType>(CurTy)->getElementType();
3279 if (isa<VectorType>(CurTy))
3285 if (isa<VectorType>(CurTy))
3291 if (isa<VectorType>(CurTy))
3297 if (isa<VectorType>(CurTy))
3303 if (isa<VectorType>(CurTy))
3309 if (isa<VectorType>(CurTy))
3315 if (isa<VectorType>(CurTy))
3321 if (isa<VectorType>(CurTy))
3326 return error(
"Invalid type for value");
3332 return error(
"Invalid unary op constexpr record");
3337 V = BitcodeConstant::create(Alloc, CurTy, Opc, (
unsigned)
Record[1]);
3343 return error(
"Invalid binary op constexpr record");
3349 if (
Record.size() >= 4) {
3350 if (Opc == Instruction::Add ||
3351 Opc == Instruction::Sub ||
3352 Opc == Instruction::Mul ||
3353 Opc == Instruction::Shl) {
3358 }
else if (Opc == Instruction::SDiv ||
3359 Opc == Instruction::UDiv ||
3360 Opc == Instruction::LShr ||
3361 Opc == Instruction::AShr) {
3366 V = BitcodeConstant::create(Alloc, CurTy, {(uint8_t)Opc, Flags},
3373 return error(
"Invalid cast constexpr record");
3378 unsigned OpTyID =
Record[1];
3379 Type *OpTy = getTypeByID(OpTyID);
3381 return error(
"Invalid cast constexpr record");
3382 V = BitcodeConstant::create(Alloc, CurTy, Opc, (
unsigned)
Record[2]);
3394 return error(
"Constant GEP record must have at least two elements");
3396 Type *PointeeType =
nullptr;
3400 PointeeType = getTypeByID(
Record[OpNum++]);
3403 std::optional<ConstantRange>
InRange;
3407 unsigned InRangeIndex =
Op >> 1;
3414 readBitWidthAndConstantRange(
Record, OpNum);
3424 unsigned BaseTypeID =
Record[OpNum];
3425 while (OpNum !=
Record.size()) {
3426 unsigned ElTyID =
Record[OpNum++];
3427 Type *ElTy = getTypeByID(ElTyID);
3429 return error(
"Invalid getelementptr constexpr record");
3433 if (Elts.
size() < 1)
3434 return error(
"Invalid gep with no operands");
3438 BaseTypeID = getContainedTypeID(BaseTypeID, 0);
3439 BaseType = getTypeByID(BaseTypeID);
3444 return error(
"GEP base operand must be pointer or vector of pointer");
3447 PointeeType = getPtrElementTypeByID(BaseTypeID);
3449 return error(
"Missing element type for old-style constant GEP");
3452 V = BitcodeConstant::create(
3454 {Instruction::GetElementPtr, uint8_t(Flags), PointeeType,
InRange},
3460 return error(
"Invalid select constexpr record");
3462 V = BitcodeConstant::create(
3463 Alloc, CurTy, Instruction::Select,
3470 return error(
"Invalid extractelement constexpr record");
3471 unsigned OpTyID =
Record[0];
3473 dyn_cast_or_null<VectorType>(getTypeByID(OpTyID));
3475 return error(
"Invalid extractelement constexpr record");
3477 if (
Record.size() == 4) {
3478 unsigned IdxTyID =
Record[2];
3479 Type *IdxTy = getTypeByID(IdxTyID);
3481 return error(
"Invalid extractelement constexpr record");
3487 V = BitcodeConstant::create(Alloc, CurTy, Instruction::ExtractElement,
3493 VectorType *OpTy = dyn_cast<VectorType>(CurTy);
3494 if (
Record.size() < 3 || !OpTy)
3495 return error(
"Invalid insertelement constexpr record");
3497 if (
Record.size() == 4) {
3498 unsigned IdxTyID =
Record[2];
3499 Type *IdxTy = getTypeByID(IdxTyID);
3501 return error(
"Invalid insertelement constexpr record");
3507 V = BitcodeConstant::create(
3508 Alloc, CurTy, Instruction::InsertElement,
3513 VectorType *OpTy = dyn_cast<VectorType>(CurTy);
3514 if (
Record.size() < 3 || !OpTy)
3515 return error(
"Invalid shufflevector constexpr record");
3516 V = BitcodeConstant::create(
3517 Alloc, CurTy, Instruction::ShuffleVector,
3522 VectorType *RTy = dyn_cast<VectorType>(CurTy);
3524 dyn_cast_or_null<VectorType>(getTypeByID(
Record[0]));
3525 if (
Record.size() < 4 || !RTy || !OpTy)
3526 return error(
"Invalid shufflevector constexpr record");
3527 V = BitcodeConstant::create(
3528 Alloc, CurTy, Instruction::ShuffleVector,
3534 return error(
"Invalid cmp constexpt record");
3535 unsigned OpTyID =
Record[0];
3536 Type *OpTy = getTypeByID(OpTyID);
3538 return error(
"Invalid cmp constexpr record");
3539 V = BitcodeConstant::create(
3542 : Instruction::ICmp),
3551 return error(
"Invalid inlineasm record");
3552 std::string AsmStr, ConstrStr;
3553 bool HasSideEffects =
Record[0] & 1;
3554 bool IsAlignStack =
Record[0] >> 1;
3555 unsigned AsmStrSize =
Record[1];
3556 if (2+AsmStrSize >=
Record.size())
3557 return error(
"Invalid inlineasm record");
3558 unsigned ConstStrSize =
Record[2+AsmStrSize];
3559 if (3+AsmStrSize+ConstStrSize >
Record.size())
3560 return error(
"Invalid inlineasm record");
3562 for (
unsigned i = 0; i != AsmStrSize; ++i)
3563 AsmStr += (
char)
Record[2+i];
3564 for (
unsigned i = 0; i != ConstStrSize; ++i)
3565 ConstrStr += (
char)
Record[3+AsmStrSize+i];
3568 return error(
"Missing element type for old-style inlineasm");
3570 HasSideEffects, IsAlignStack);
3577 return error(
"Invalid inlineasm record");
3578 std::string AsmStr, ConstrStr;
3579 bool HasSideEffects =
Record[0] & 1;
3580 bool IsAlignStack = (
Record[0] >> 1) & 1;
3581 unsigned AsmDialect =
Record[0] >> 2;
3582 unsigned AsmStrSize =
Record[1];
3583 if (2+AsmStrSize >=
Record.size())
3584 return error(
"Invalid inlineasm record");
3585 unsigned ConstStrSize =
Record[2+AsmStrSize];
3586 if (3+AsmStrSize+ConstStrSize >
Record.size())
3587 return error(
"Invalid inlineasm record");
3589 for (
unsigned i = 0; i != AsmStrSize; ++i)
3590 AsmStr += (
char)
Record[2+i];
3591 for (
unsigned i = 0; i != ConstStrSize; ++i)
3592 ConstrStr += (
char)
Record[3+AsmStrSize+i];
3595 return error(
"Missing element type for old-style inlineasm");
3597 HasSideEffects, IsAlignStack,
3604 return error(
"Invalid inlineasm record");
3606 std::string AsmStr, ConstrStr;
3607 bool HasSideEffects =
Record[OpNum] & 1;
3608 bool IsAlignStack = (
Record[OpNum] >> 1) & 1;
3609 unsigned AsmDialect = (
Record[OpNum] >> 2) & 1;
3610 bool CanThrow = (
Record[OpNum] >> 3) & 1;
3612 unsigned AsmStrSize =
Record[OpNum];
3614 if (OpNum + AsmStrSize >=
Record.size())
3615 return error(
"Invalid inlineasm record");
3616 unsigned ConstStrSize =
Record[OpNum + AsmStrSize];
3617 if (OpNum + 1 + AsmStrSize + ConstStrSize >
Record.size())
3618 return error(
"Invalid inlineasm record");
3620 for (
unsigned i = 0; i != AsmStrSize; ++i)
3621 AsmStr += (
char)
Record[OpNum + i];
3623 for (
unsigned i = 0; i != ConstStrSize; ++i)
3624 ConstrStr += (
char)
Record[OpNum + AsmStrSize + i];
3627 return error(
"Missing element type for old-style inlineasm");
3629 HasSideEffects, IsAlignStack,
3636 return error(
"Invalid inlineasm record");
3638 auto *FnTy = dyn_cast_or_null<FunctionType>(getTypeByID(
Record[OpNum]));
3641 return error(
"Invalid inlineasm record");
3642 std::string AsmStr, ConstrStr;
3643 bool HasSideEffects =
Record[OpNum] & 1;
3644 bool IsAlignStack = (
Record[OpNum] >> 1) & 1;
3645 unsigned AsmDialect = (
Record[OpNum] >> 2) & 1;
3646 bool CanThrow = (
Record[OpNum] >> 3) & 1;
3648 unsigned AsmStrSize =
Record[OpNum];
3650 if (OpNum + AsmStrSize >=
Record.size())
3651 return error(
"Invalid inlineasm record");
3652 unsigned ConstStrSize =
Record[OpNum + AsmStrSize];
3653 if (OpNum + 1 + AsmStrSize + ConstStrSize >
Record.size())
3654 return error(
"Invalid inlineasm record");
3656 for (
unsigned i = 0; i != AsmStrSize; ++i)
3657 AsmStr += (
char)
Record[OpNum + i];
3659 for (
unsigned i = 0; i != ConstStrSize; ++i)
3660 ConstrStr += (
char)
Record[OpNum + AsmStrSize + i];
3662 V =
InlineAsm::get(FnTy, AsmStr, ConstrStr, HasSideEffects, IsAlignStack,
3668 return error(
"Invalid blockaddress record");
3669 unsigned FnTyID =
Record[0];
3670 Type *FnTy = getTypeByID(FnTyID);
3672 return error(
"Invalid blockaddress record");
3673 V = BitcodeConstant::create(
3681 return error(
"Invalid dso_local record");
3682 unsigned GVTyID =
Record[0];
3683 Type *GVTy = getTypeByID(GVTyID);
3685 return error(
"Invalid dso_local record");
3686 V = BitcodeConstant::create(
3687 Alloc, CurTy, BitcodeConstant::DSOLocalEquivalentOpcode,
Record[1]);
3692 return error(
"Invalid no_cfi record");
3693 unsigned GVTyID =
Record[0];
3694 Type *GVTy = getTypeByID(GVTyID);
3696 return error(
"Invalid no_cfi record");
3697 V = BitcodeConstant::create(Alloc, CurTy, BitcodeConstant::NoCFIOpcode,
3703 return error(
"Invalid ptrauth record");
3705 V = BitcodeConstant::create(Alloc, CurTy,
3706 BitcodeConstant::ConstantPtrAuthOpcode,
3713 assert(
V->getType() == getTypeByID(CurTyID) &&
"Incorrect result type ID");
3720Error BitcodeReader::parseUseLists() {
3733 switch (
Entry.Kind) {
3736 return error(
"Malformed block");
3750 switch (MaybeRecord.
get()) {
3758 if (RecordLength < 3)
3760 return error(
"Invalid record");
3761 unsigned ID =
Record.pop_back_val();
3765 assert(
ID < FunctionBBs.size() &&
"Basic block not found");
3766 V = FunctionBBs[
ID];
3769 unsigned NumUses = 0;
3771 for (
const Use &U :
V->materialized_uses()) {
3772 if (++NumUses >
Record.size())
3774 Order[&
U] =
Record[NumUses - 1];
3781 V->sortUseList([&](
const Use &L,
const Use &R) {
3792Error BitcodeReader::rememberAndSkipMetadata() {
3794 uint64_t CurBit = Stream.GetCurrentBitNo();
3795 DeferredMetadataInfo.push_back(CurBit);
3798 if (
Error Err = Stream.SkipBlock())
3803Error BitcodeReader::materializeMetadata() {
3804 for (
uint64_t BitPos : DeferredMetadataInfo) {
3806 if (
Error JumpFailed = Stream.JumpToBit(BitPos))
3808 if (
Error Err = MDLoader->parseModuleMetadata())
3819 for (
const MDOperand &MDOptions : cast<MDNode>(Val)->operands())
3820 LinkerOpts->
addOperand(cast<MDNode>(MDOptions));
3824 DeferredMetadataInfo.clear();
3828void BitcodeReader::setStripDebugInfo() {
StripDebugInfo =
true; }
3832Error BitcodeReader::rememberAndSkipFunctionBody() {
3834 if (FunctionsWithBodies.empty())
3835 return error(
"Insufficient function protos");
3838 FunctionsWithBodies.pop_back();
3841 uint64_t CurBit = Stream.GetCurrentBitNo();
3843 (DeferredFunctionInfo[Fn] == 0 || DeferredFunctionInfo[Fn] == CurBit) &&
3844 "Mismatch between VST and scanned function offsets");
3845 DeferredFunctionInfo[Fn] = CurBit;
3848 if (
Error Err = Stream.SkipBlock())
3853Error BitcodeReader::globalCleanup() {
3855 if (
Error Err = resolveGlobalAndIndirectSymbolInits())
3857 if (!GlobalInits.empty() || !IndirectSymbolInits.empty())
3858 return error(
"Malformed global initializer set");
3863 MDLoader->upgradeDebugIntrinsics(
F);
3870 UpgradedIntrinsics[&
F] = NewFn;
3876 std::vector<std::pair<GlobalVariable *, GlobalVariable *>> UpgradedVariables;
3879 UpgradedVariables.emplace_back(&GV, Upgraded);
3880 for (
auto &Pair : UpgradedVariables) {
3881 Pair.first->eraseFromParent();
3882 TheModule->insertGlobalVariable(Pair.second);
3887 std::vector<std::pair<GlobalVariable *, unsigned>>().
swap(GlobalInits);
3888 std::vector<std::pair<GlobalValue *, unsigned>>().
swap(IndirectSymbolInits);
3896Error BitcodeReader::rememberAndSkipFunctionBodies() {
3897 if (
Error JumpFailed = Stream.JumpToBit(NextUnreadBit))
3900 if (Stream.AtEndOfStream())
3901 return error(
"Could not find function in stream");
3903 if (!SeenFirstFunctionBody)
3904 return error(
"Trying to materialize functions before seeing function blocks");
3908 assert(SeenValueSymbolTable);
3918 switch (
Entry.Kind) {
3920 return error(
"Expect SubBlock");
3924 return error(
"Expect function block");
3926 if (
Error Err = rememberAndSkipFunctionBody())
3928 NextUnreadBit = Stream.GetCurrentBitNo();
3935Error BitcodeReaderBase::readBlockInfo() {
3937 Stream.ReadBlockInfoBlock();
3938 if (!MaybeNewBlockInfo)
3940 std::optional<BitstreamBlockInfo> NewBlockInfo =
3941 std::move(MaybeNewBlockInfo.
get());
3943 return error(
"Malformed block");
3944 BlockInfo = std::move(*NewBlockInfo);
3955 return error(
"Invalid record");
3957 std::string OldFormatName;
3960 return error(
"Invalid record");
3961 unsigned ComdatNameSize =
Record[1];
3962 if (ComdatNameSize >
Record.size() - 2)
3963 return error(
"Comdat name size too large");
3964 OldFormatName.reserve(ComdatNameSize);
3965 for (
unsigned i = 0; i != ComdatNameSize; ++i)
3966 OldFormatName += (
char)
Record[2 + i];
3967 Name = OldFormatName;
3970 C->setSelectionKind(SK);
3971 ComdatList.push_back(
C);
3985 Meta.NoAddress =
true;
3987 Meta.NoHWAddress =
true;
3991 Meta.IsDynInit =
true;
4006 return error(
"Invalid record");
4007 unsigned TyID =
Record[0];
4008 Type *Ty = getTypeByID(TyID);
4010 return error(
"Invalid record");
4012 bool explicitType =
Record[1] & 2;
4018 return error(
"Invalid type for value");
4019 AddressSpace = cast<PointerType>(Ty)->getAddressSpace();
4020 TyID = getContainedTypeID(TyID);
4021 Ty = getTypeByID(TyID);
4023 return error(
"Missing element type for old-style global");
4029 if (
Error Err = parseAlignmentValue(
Record[4], Alignment))
4033 if (
Record[5] - 1 >= SectionTable.size())
4034 return error(
"Invalid ID");
4051 bool ExternallyInitialized =
false;
4053 ExternallyInitialized =
Record[9];
4065 if (
Record.size() > 10) {
4077 if (
unsigned InitID =
Record[2])
4078 GlobalInits.push_back(std::make_pair(NewGV, InitID - 1));
4080 if (
Record.size() > 11) {
4081 if (
unsigned ComdatID =
Record[11]) {
4082 if (ComdatID > ComdatList.size())
4083 return error(
"Invalid global variable comdat ID");
4084 NewGV->
setComdat(ComdatList[ComdatID - 1]);
4087 ImplicitComdatObjects.
insert(NewGV);
4090 if (
Record.size() > 12) {
4095 if (
Record.size() > 13) {
4114 return error(
"Invalid global variable code model");
4120void BitcodeReader::callValueTypeCallback(
Value *
F,
unsigned TypeID) {
4121 if (ValueTypeCallback) {
4122 (*ValueTypeCallback)(
4123 F,
TypeID, [
this](
unsigned I) {
return getTypeByID(
I); },
4124 [
this](
unsigned I,
unsigned J) {
return getContainedTypeID(
I, J); });
4137 return error(
"Invalid record");
4138 unsigned FTyID =
Record[0];
4139 Type *FTy = getTypeByID(FTyID);
4141 return error(
"Invalid record");
4142 if (isa<PointerType>(FTy)) {
4143 FTyID = getContainedTypeID(FTyID, 0);
4144 FTy = getTypeByID(FTyID);
4146 return error(
"Missing element type for old-style function");
4149 if (!isa<FunctionType>(FTy))
4150 return error(
"Invalid type for value");
4153 return error(
"Invalid calling convention ID");
4155 unsigned AddrSpace = TheModule->getDataLayout().getProgramAddressSpace();
4161 AddrSpace,
Name, TheModule);
4164 "Incorrect fully specified type provided for function");
4165 FunctionTypeIDs[
Func] = FTyID;
4167 Func->setCallingConv(
CC);
4168 bool isProto =
Record[2];
4172 callValueTypeCallback(Func, FTyID);
4177 for (
unsigned i = 0; i !=
Func->arg_size(); ++i) {
4179 Attribute::InAlloca}) {
4180 if (!
Func->hasParamAttribute(i, Kind))
4183 if (
Func->getParamAttribute(i, Kind).getValueAsType())
4186 Func->removeParamAttr(i, Kind);
4188 unsigned ParamTypeID = getContainedTypeID(FTyID, i + 1);
4189 Type *PtrEltTy = getPtrElementTypeByID(ParamTypeID);
4191 return error(
"Missing param element type for attribute upgrade");
4195 case Attribute::ByVal:
4198 case Attribute::StructRet:
4201 case Attribute::InAlloca:
4208 Func->addParamAttr(i, NewAttr);
4213 !
Func->arg_empty() && !
Func->hasParamAttribute(0, Attribute::ByVal)) {
4214 unsigned ParamTypeID = getContainedTypeID(FTyID, 1);
4215 Type *ByValTy = getPtrElementTypeByID(ParamTypeID);
4217 return error(
"Missing param element type for x86_intrcc upgrade");
4219 Func->addParamAttr(0, NewAttr);
4223 if (
Error Err = parseAlignmentValue(
Record[5], Alignment))
4226 Func->setAlignment(*Alignment);
4228 if (
Record[6] - 1 >= SectionTable.size())
4229 return error(
"Invalid ID");
4230 Func->setSection(SectionTable[
Record[6] - 1]);
4234 if (!
Func->hasLocalLinkage())
4237 if (
Record[8] - 1 >= GCTable.size())
4238 return error(
"Invalid ID");
4244 Func->setUnnamedAddr(UnnamedAddr);
4246 FunctionOperandInfo OperandInfo = {
Func, 0, 0, 0};
4248 OperandInfo.Prologue =
Record[10];
4250 if (
Record.size() > 11) {
4252 if (!
Func->hasLocalLinkage()) {
4259 if (
Record.size() > 12) {
4260 if (
unsigned ComdatID =
Record[12]) {
4261 if (ComdatID > ComdatList.size())
4262 return error(
"Invalid function comdat ID");
4263 Func->setComdat(ComdatList[ComdatID - 1]);
4266 ImplicitComdatObjects.
insert(Func);
4270 OperandInfo.Prefix =
Record[13];
4273 OperandInfo.PersonalityFn =
Record[14];
4275 if (
Record.size() > 15) {
4284 if (
Record.size() > 18 && Strtab.data() &&
4289 ValueList.
push_back(Func, getVirtualTypeID(
Func->getType(), FTyID));
4291 if (OperandInfo.PersonalityFn || OperandInfo.Prefix || OperandInfo.Prologue)
4292 FunctionOperands.push_back(OperandInfo);
4297 Func->setIsMaterializable(
true);
4298 FunctionsWithBodies.push_back(Func);
4299 DeferredFunctionInfo[
Func] = 0;
4304Error BitcodeReader::parseGlobalIndirectSymbolRecord(
4318 if (
Record.size() < (3 + (
unsigned)NewRecord))
4319 return error(
"Invalid record");
4324 return error(
"Invalid record");
4328 auto *PTy = dyn_cast<PointerType>(Ty);
4330 return error(
"Invalid type for value");
4331 AddrSpace = PTy->getAddressSpace();
4333 Ty = getTypeByID(
TypeID);
4335 return error(
"Missing element type for old-style indirect symbol");
4337 AddrSpace =
Record[OpNum++];
4340 auto Val =
Record[OpNum++];
4349 nullptr, TheModule);
4353 if (OpNum !=
Record.size()) {
4354 auto VisInd = OpNum++;
4360 if (OpNum !=
Record.size()) {
4361 auto S =
Record[OpNum++];
4368 if (OpNum !=
Record.size())
4370 if (OpNum !=
Record.size())
4373 if (OpNum !=
Record.size())
4378 if (OpNum + 1 <
Record.size()) {
4381 return error(
"Malformed partition, too large.");
4388 IndirectSymbolInits.push_back(std::make_pair(NewGA, Val));
4393 bool ShouldLazyLoadMetadata,
4399 TheModule->IsNewDbgInfoFormat =
4404 this->ValueTypeCallback = std::move(Callbacks.
ValueType);
4406 if (
Error JumpFailed = Stream.JumpToBit(ResumeBit))
4415 bool ResolvedDataLayout =
false;
4420 std::string TentativeDataLayoutStr = TheModule->getDataLayoutStr();
4422 auto ResolveDataLayout = [&]() ->
Error {
4423 if (ResolvedDataLayout)
4427 ResolvedDataLayout =
true;
4431 TentativeDataLayoutStr, TheModule->getTargetTriple());
4435 if (
auto LayoutOverride = (*Callbacks.
DataLayout)(
4436 TheModule->getTargetTriple(), TentativeDataLayoutStr))
4437 TentativeDataLayoutStr = *LayoutOverride;
4445 TheModule->setDataLayout(MaybeDL.
get());
4456 switch (
Entry.Kind) {
4458 return error(
"Malformed block");
4460 if (
Error Err = ResolveDataLayout())
4462 return globalCleanup();
4467 if (
Error Err = Stream.SkipBlock())
4471 if (
Error Err = readBlockInfo())
4475 if (
Error Err = parseAttributeBlock())
4479 if (
Error Err = parseAttributeGroupBlock())
4483 if (
Error Err = parseTypeTable())
4487 if (!SeenValueSymbolTable) {
4493 assert(VSTOffset == 0 || FunctionsWithBodies.empty());
4494 if (
Error Err = parseValueSymbolTable())
4496 SeenValueSymbolTable =
true;
4501 if (
Error Err = Stream.SkipBlock())
4506 if (
Error Err = parseConstants())
4508 if (
Error Err = resolveGlobalAndIndirectSymbolInits())
4512 if (ShouldLazyLoadMetadata) {
4513 if (
Error Err = rememberAndSkipMetadata())
4517 assert(DeferredMetadataInfo.empty() &&
"Unexpected deferred metadata");
4518 if (
Error Err = MDLoader->parseModuleMetadata())
4522 if (
Error Err = MDLoader->parseMetadataKinds())
4526 if (
Error Err = ResolveDataLayout())
4531 if (!SeenFirstFunctionBody) {
4532 std::reverse(FunctionsWithBodies.begin(), FunctionsWithBodies.end());
4533 if (
Error Err = globalCleanup())
4535 SeenFirstFunctionBody =
true;
4538 if (VSTOffset > 0) {
4542 if (!SeenValueSymbolTable) {
4543 if (
Error Err = BitcodeReader::parseValueSymbolTable(VSTOffset))
4545 SeenValueSymbolTable =
true;
4557 if (
Error Err = Stream.SkipBlock())
4567 if (
Error Err = rememberAndSkipFunctionBody())
4574 if (SeenValueSymbolTable) {
4575 NextUnreadBit = Stream.GetCurrentBitNo();
4578 return globalCleanup();
4582 if (
Error Err = parseUseLists())
4586 if (
Error Err = parseOperandBundleTags())
4590 if (
Error Err = parseSyncScopeNames())
4605 switch (
unsigned BitCode = MaybeBitCode.
get()) {
4611 UseRelativeIDs = *VersionOrErr >= 1;
4615 if (ResolvedDataLayout)
4616 return error(
"target triple too late in module");
4619 return error(
"Invalid record");
4620 TheModule->setTargetTriple(S);
4624 if (ResolvedDataLayout)
4625 return error(
"datalayout too late in module");
4627 return error(
"Invalid record");
4633 return error(
"Invalid record");
4634 TheModule->setModuleInlineAsm(S);
4641 return error(
"Invalid record");
4648 return error(
"Invalid record");
4649 SectionTable.push_back(S);
4655 return error(
"Invalid record");
4656 GCTable.push_back(S);
4673 if (
Error Err = ResolveDataLayout())
4681 if (
Error Err = parseGlobalIndirectSymbolRecord(BitCode,
Record))
4687 return error(
"Invalid record");
4691 VSTOffset =
Record[0] - 1;
4697 return error(
"Invalid record");
4698 TheModule->setSourceFileName(
ValueName);
4703 this->ValueTypeCallback = std::nullopt;
4707Error BitcodeReader::parseBitcodeInto(
Module *M,
bool ShouldLazyLoadMetadata,
4712 MDCallbacks.
GetTypeByID = [&](
unsigned ID) {
return getTypeByID(
ID); };
4714 return getContainedTypeID(
I, J);
4717 MDLoader =
MetadataLoader(Stream, *M, ValueList, IsImporting, MDCallbacks);
4718 return parseModule(0, ShouldLazyLoadMetadata, Callbacks);
4721Error BitcodeReader::typeCheckLoadStoreInst(
Type *ValType,
Type *PtrType) {
4722 if (!isa<PointerType>(PtrType))
4723 return error(
"Load/Store operand is not a pointer type");
4724 if (!PointerType::isLoadableOrStorableType(ValType))
4725 return error(
"Cannot load/store from pointer");
4732 for (
unsigned i = 0; i != CB->
arg_size(); ++i) {
4734 Attribute::InAlloca}) {
4735 if (!
Attrs.hasParamAttr(i, Kind) ||
4736 Attrs.getParamAttr(i, Kind).getValueAsType())
4739 Type *PtrEltTy = getPtrElementTypeByID(ArgTyIDs[i]);
4741 return error(
"Missing element type for typed attribute upgrade");
4745 case Attribute::ByVal:
4748 case Attribute::StructRet:
4751 case Attribute::InAlloca:
4758 Attrs =
Attrs.addParamAttribute(Context, i, NewAttr);
4769 if (CI.isIndirect && !
Attrs.getParamElementType(ArgNo)) {
4770 Type *ElemTy = getPtrElementTypeByID(ArgTyIDs[ArgNo]);
4772 return error(
"Missing element type for inline asm upgrade");
4783 case Intrinsic::preserve_array_access_index:
4784 case Intrinsic::preserve_struct_access_index:
4785 case Intrinsic::aarch64_ldaxr:
4786 case Intrinsic::aarch64_ldxr:
4787 case Intrinsic::aarch64_stlxr:
4788 case Intrinsic::aarch64_stxr:
4789 case Intrinsic::arm_ldaex:
4790 case Intrinsic::arm_ldrex:
4791 case Intrinsic::arm_stlex:
4792 case Intrinsic::arm_strex: {
4795 case Intrinsic::aarch64_stlxr:
4796 case Intrinsic::aarch64_stxr:
4797 case Intrinsic::arm_stlex:
4798 case Intrinsic::arm_strex:
4805 if (!
Attrs.getParamElementType(ArgNo)) {
4806 Type *ElTy = getPtrElementTypeByID(ArgTyIDs[ArgNo]);
4808 return error(
"Missing element type for elementtype upgrade");
4810 Attrs =
Attrs.addParamAttribute(Context, ArgNo, NewAttr);
4828 if (MDLoader->hasFwdRefs())
4829 return error(
"Invalid function metadata: incoming forward references");
4831 InstructionList.
clear();
4832 unsigned ModuleValueListSize = ValueList.
size();
4833 unsigned ModuleMDLoaderSize = MDLoader->size();
4837 unsigned FTyID = FunctionTypeIDs[
F];
4839 unsigned ArgTyID = getContainedTypeID(FTyID, ArgNo + 1);
4840 assert(
I.getType() == getTypeByID(ArgTyID) &&
4841 "Incorrect fully specified type for Function Argument");
4845 unsigned NextValueNo = ValueList.
size();
4847 unsigned CurBBNo = 0;
4856 auto getLastInstruction = [&]() ->
Instruction * {
4857 if (CurBB && !CurBB->
empty())
4858 return &CurBB->
back();
4859 else if (CurBBNo && FunctionBBs[CurBBNo - 1] &&
4860 !FunctionBBs[CurBBNo - 1]->empty())
4861 return &FunctionBBs[CurBBNo - 1]->back();
4865 std::vector<OperandBundleDef> OperandBundles;
4876 switch (
Entry.Kind) {
4878 return error(
"Malformed block");
4880 goto OutOfRecordLoop;
4885 if (
Error Err = Stream.SkipBlock())
4889 if (
Error Err = parseConstants())
4891 NextValueNo = ValueList.
size();
4894 if (
Error Err = parseValueSymbolTable())
4898 if (
Error Err = MDLoader->parseMetadataAttachment(*
F, InstructionList))
4902 assert(DeferredMetadataInfo.empty() &&
4903 "Must read all module-level metadata before function-level");
4904 if (
Error Err = MDLoader->parseFunctionMetadata())
4908 if (
Error Err = parseUseLists())
4922 unsigned ResTypeID = InvalidTypeID;
4926 switch (
unsigned BitCode = MaybeBitCode.
get()) {
4928 return error(
"Invalid value");
4931 return error(
"Invalid record");
4933 FunctionBBs.resize(
Record[0]);
4936 auto BBFRI = BasicBlockFwdRefs.
find(
F);
4937 if (BBFRI == BasicBlockFwdRefs.
end()) {
4941 auto &BBRefs = BBFRI->second;
4943 if (BBRefs.size() > FunctionBBs.size())
4944 return error(
"Invalid ID");
4945 assert(!BBRefs.empty() &&
"Unexpected empty array");
4946 assert(!BBRefs.front() &&
"Invalid reference to entry block");
4947 for (
unsigned I = 0, E = FunctionBBs.size(), RE = BBRefs.size();
I != E;
4949 if (
I < RE && BBRefs[
I]) {
4950 BBRefs[
I]->insertInto(
F);
4951 FunctionBBs[
I] = BBRefs[
I];
4957 BasicBlockFwdRefs.
erase(BBFRI);
4960 CurBB = FunctionBBs[0];
4967 return error(
"Invalid record");
4982 if (
auto *
F = dyn_cast<Function>(ValueList[
ValID]))
4983 BackwardRefFunctions.push_back(
F);
4985 return error(
"Invalid record");
4992 I = getLastInstruction();
4995 return error(
"Invalid record");
4996 I->setDebugLoc(LastLoc);
5001 I = getLastInstruction();
5003 return error(
"Invalid record");
5011 Scope = dyn_cast_or_null<MDNode>(
5012 MDLoader->getMetadataFwdRefOrLoad(ScopeID - 1));
5014 return error(
"Invalid record");
5017 IA = dyn_cast_or_null<MDNode>(
5018 MDLoader->getMetadataFwdRefOrLoad(IAID - 1));
5020 return error(
"Invalid record");
5022 LastLoc = DILocation::get(
Scope->getContext(), Line, Col, Scope, IA,
5024 I->setDebugLoc(LastLoc);
5032 if (getValueTypePair(
Record, OpNum, NextValueNo, LHS,
TypeID, CurBB) ||
5034 return error(
"Invalid record");
5038 return error(
"Invalid record");
5042 if (OpNum <
Record.size()) {
5043 if (isa<FPMathOperator>(
I)) {
5046 I->setFastMathFlags(FMF);
5055 if (getValueTypePair(
Record, OpNum, NextValueNo, LHS,
TypeID, CurBB) ||
5059 return error(
"Invalid record");
5063 return error(
"Invalid record");
5067 if (OpNum <
Record.size()) {
5068 if (Opc == Instruction::Add ||
5069 Opc == Instruction::Sub ||
5070 Opc == Instruction::Mul ||
5071 Opc == Instruction::Shl) {
5073 cast<BinaryOperator>(
I)->setHasNoSignedWrap(
true);
5075 cast<BinaryOperator>(
I)->setHasNoUnsignedWrap(
true);
5076 }
else if (Opc == Instruction::SDiv ||
5077 Opc == Instruction::UDiv ||
5078 Opc == Instruction::LShr ||
5079 Opc == Instruction::AShr) {
5081 cast<BinaryOperator>(
I)->setIsExact(
true);
5082 }
else if (Opc == Instruction::Or) {
5084 cast<PossiblyDisjointInst>(
I)->setIsDisjoint(
true);
5085 }
else if (isa<FPMathOperator>(
I)) {
5088 I->setFastMathFlags(FMF);
5097 if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB) ||
5098 OpNum + 1 >
Record.size())
5099 return error(
"Invalid record");
5101 ResTypeID =
Record[OpNum++];
5102 Type *ResTy = getTypeByID(ResTypeID);
5105 if (Opc == -1 || !ResTy)
5106 return error(
"Invalid record");
5111 assert(CurBB &&
"No current BB?");
5117 return error(
"Invalid cast");
5121 if (OpNum <
Record.size()) {
5122 if (Opc == Instruction::ZExt || Opc == Instruction::UIToFP) {
5124 cast<PossiblyNonNegInst>(
I)->setNonNeg(
true);
5125 }
else if (Opc == Instruction::Trunc) {
5127 cast<TruncInst>(
I)->setHasNoUnsignedWrap(
true);
5129 cast<TruncInst>(
I)->setHasNoSignedWrap(
true);
5148 Ty = getTypeByID(TyID);
5152 TyID = InvalidTypeID;
5157 unsigned BasePtrTypeID;
5158 if (getValueTypePair(
Record, OpNum, NextValueNo, BasePtr, BasePtrTypeID,
5160 return error(
"Invalid record");
5163 TyID = getContainedTypeID(BasePtrTypeID);
5164 if (
BasePtr->getType()->isVectorTy())
5165 TyID = getContainedTypeID(TyID);
5166 Ty = getTypeByID(TyID);
5170 while (OpNum !=
Record.size()) {
5173 if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB))
5174 return error(
"Invalid record");
5182 if (cast<GEPOperator>(
I)->getNumIndices() != 0) {
5185 unsigned SubType = 0;
5186 if (GTI.isStruct()) {
5188 Idx->getType()->isVectorTy()
5193 ResTypeID = getContainedTypeID(ResTypeID, SubType);
5200 ResTypeID = getVirtualTypeID(
I->getType()->getScalarType(), ResTypeID);
5201 if (
I->getType()->isVectorTy())
5202 ResTypeID = getVirtualTypeID(
I->getType(), ResTypeID);
5205 GEP->setNoWrapFlags(NW);
5214 if (getValueTypePair(
Record, OpNum, NextValueNo, Agg, AggTypeID, CurBB))
5215 return error(
"Invalid record");
5218 unsigned RecSize =
Record.size();
5219 if (OpNum == RecSize)
5220 return error(
"EXTRACTVAL: Invalid instruction with 0 indices");
5223 ResTypeID = AggTypeID;
5224 for (; OpNum != RecSize; ++OpNum) {
5229 if (!IsStruct && !IsArray)
5230 return error(
"EXTRACTVAL: Invalid type");
5232 return error(
"Invalid value");
5234 return error(
"EXTRACTVAL: Invalid struct index");
5236 return error(
"EXTRACTVAL: Invalid array index");
5241 ResTypeID = getContainedTypeID(ResTypeID,
Index);
5244 ResTypeID = getContainedTypeID(ResTypeID);
5258 if (getValueTypePair(
Record, OpNum, NextValueNo, Agg, AggTypeID, CurBB))
5259 return error(
"Invalid record");
5262 if (getValueTypePair(
Record, OpNum, NextValueNo, Val, ValTypeID, CurBB))
5263 return error(
"Invalid record");
5265 unsigned RecSize =
Record.size();
5266 if (OpNum == RecSize)
5267 return error(
"INSERTVAL: Invalid instruction with 0 indices");
5271 for (; OpNum != RecSize; ++OpNum) {
5276 if (!IsStruct && !IsArray)
5277 return error(
"INSERTVAL: Invalid type");
5279 return error(
"Invalid value");
5281 return error(
"INSERTVAL: Invalid struct index");
5283 return error(
"INSERTVAL: Invalid array index");
5293 return error(
"Inserted value type doesn't match aggregate type");
5296 ResTypeID = AggTypeID;
5308 if (getValueTypePair(
Record, OpNum, NextValueNo, TrueVal,
TypeID,
5312 popValue(
Record, OpNum, NextValueNo, CondType,
5313 getVirtualTypeID(CondType),
Cond, CurBB))
5314 return error(
"Invalid record");
5327 unsigned ValTypeID, CondTypeID;
5328 if (getValueTypePair(
Record, OpNum, NextValueNo, TrueVal, ValTypeID,
5330 popValue(
Record, OpNum, NextValueNo,
TrueVal->getType(), ValTypeID,
5332 getValueTypePair(
Record, OpNum, NextValueNo,
Cond, CondTypeID, CurBB))
5333 return error(
"Invalid record");
5337 dyn_cast<VectorType>(
Cond->getType())) {
5340 return error(
"Invalid type for value");
5344 return error(
"Invalid type for value");
5348 ResTypeID = ValTypeID;
5350 if (OpNum <
Record.size() && isa<FPMathOperator>(
I)) {
5353 I->setFastMathFlags(FMF);
5361 unsigned VecTypeID, IdxTypeID;
5362 if (getValueTypePair(
Record, OpNum, NextValueNo, Vec, VecTypeID, CurBB) ||
5363 getValueTypePair(
Record, OpNum, NextValueNo,
Idx, IdxTypeID, CurBB))
5364 return error(
"Invalid record");
5366 return error(
"Invalid type for value");
5368 ResTypeID = getContainedTypeID(VecTypeID);
5376 unsigned VecTypeID, IdxTypeID;
5377 if (getValueTypePair(
Record, OpNum, NextValueNo, Vec, VecTypeID, CurBB))
5378 return error(
"Invalid record");
5380 return error(
"Invalid type for value");
5381 if (popValue(
Record, OpNum, NextValueNo,
5382 cast<VectorType>(Vec->
getType())->getElementType(),
5383 getContainedTypeID(VecTypeID), Elt, CurBB) ||
5384 getValueTypePair(
Record, OpNum, NextValueNo,
Idx, IdxTypeID, CurBB))
5385 return error(
"Invalid record");
5387 ResTypeID = VecTypeID;
5395 unsigned Vec1TypeID;
5396 if (getValueTypePair(
Record, OpNum, NextValueNo, Vec1, Vec1TypeID,
5398 popValue(
Record, OpNum, NextValueNo, Vec1->
getType(), Vec1TypeID,
5400 return error(
"Invalid record");
5402 unsigned MaskTypeID;
5403 if (getValueTypePair(
Record, OpNum, NextValueNo, Mask, MaskTypeID, CurBB))
5404 return error(
"Invalid record");
5406 return error(
"Invalid type for value");
5410 getVirtualTypeID(
I->getType(), getContainedTypeID(Vec1TypeID));
5425 if (getValueTypePair(
Record, OpNum, NextValueNo, LHS, LHSTypeID, CurBB) ||
5428 return error(
"Invalid record");
5430 if (OpNum >=
Record.size())
5432 "Invalid record: operand number exceeded available operands");
5437 if (IsFP &&
Record.size() > OpNum+1)
5440 if (OpNum+1 !=
Record.size())
5441 return error(
"Invalid record");
5445 return error(
"Invalid fcmp predicate");
5449 return error(
"Invalid icmp predicate");
5453 ResTypeID = getVirtualTypeID(
I->getType()->getScalarType());
5455 ResTypeID = getVirtualTypeID(
I->getType(), ResTypeID);
5458 I->setFastMathFlags(FMF);
5475 if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB))
5476 return error(
"Invalid record");
5477 if (OpNum !=
Record.size())
5478 return error(
"Invalid record");
5486 return error(
"Invalid record");
5489 return error(
"Invalid record");
5491 if (
Record.size() == 1) {
5499 getVirtualTypeID(CondType), CurBB);
5500 if (!FalseDest || !
Cond)
5501 return error(
"Invalid record");
5509 return error(
"Invalid record");
5512 Value *CleanupPad = getValue(
Record,
Idx++, NextValueNo, TokenTy,
5513 getVirtualTypeID(TokenTy), CurBB);
5515 return error(
"Invalid record");
5517 if (
Record.size() == 2) {
5518 UnwindDest = getBasicBlock(
Record[
Idx++]);
5520 return error(
"Invalid record");
5529 return error(
"Invalid record");
5533 getVirtualTypeID(TokenTy), CurBB);
5535 return error(
"Invalid record");
5538 return error(
"Invalid record");
5547 return error(
"Invalid record");
5553 getVirtualTypeID(TokenTy), CurBB);
5555 return error(
"Invalid record");
5560 for (
unsigned Op = 0;
Op != NumHandlers; ++
Op) {
5563 return error(
"Invalid record");
5569 UnwindDest = getBasicBlock(
Record[
Idx++]);
5571 return error(
"Invalid record");
5575 return error(
"Invalid record");
5580 CatchSwitch->addHandler(Handler);
5582 ResTypeID = getVirtualTypeID(
I->getType());
5590 return error(
"Invalid record");
5596 getVirtualTypeID(TokenTy), CurBB);
5598 return error(
"Invald record");
5600 unsigned NumArgOperands =
Record[
Idx++];
5603 for (
unsigned Op = 0;
Op != NumArgOperands; ++
Op) {
5606 if (getValueTypePair(
Record,
Idx, NextValueNo, Val, ValTypeID,
nullptr))
5607 return error(
"Invalid record");
5608 Args.push_back(Val);
5612 return error(
"Invalid record");
5618 ResTypeID = getVirtualTypeID(
I->getType());
5624 if ((
Record[0] >> 16) == SWITCH_INST_MAGIC) {
5630 unsigned OpTyID =
Record[1];
5631 Type *OpTy = getTypeByID(OpTyID);
5632 unsigned ValueBitWidth = cast<IntegerType>(OpTy)->getBitWidth();
5637 return error(
"Invalid record");
5639 unsigned NumCases =
Record[4];
5644 unsigned CurIdx = 5;
5645 for (
unsigned i = 0; i != NumCases; ++i) {
5647 unsigned NumItems =
Record[CurIdx++];
5648 for (
unsigned ci = 0; ci != NumItems; ++ci) {
5649 bool isSingleNumber =
Record[CurIdx++];
5652 unsigned ActiveWords = 1;
5653 if (ValueBitWidth > 64)
5654 ActiveWords =
Record[CurIdx++];
5657 CurIdx += ActiveWords;
5659 if (!isSingleNumber) {
5661 if (ValueBitWidth > 64)
5662 ActiveWords =
Record[CurIdx++];
5665 CurIdx += ActiveWords;
5678 SI->addCase(Cst, DestBB);
5687 return error(
"Invalid record");
5688 unsigned OpTyID =
Record[0];
5689 Type *OpTy = getTypeByID(OpTyID);
5693 return error(
"Invalid record");
5694 unsigned NumCases = (
Record.size()-3)/2;
5697 for (
unsigned i = 0, e = NumCases; i !=
e; ++i) {
5698 ConstantInt *CaseVal = dyn_cast_or_null<ConstantInt>(
5699 getFnValueByID(
Record[3+i*2], OpTy, OpTyID,
nullptr));
5701 if (!CaseVal || !DestBB) {
5703 return error(
"Invalid record");
5705 SI->addCase(CaseVal, DestBB);
5712 return error(
"Invalid record");
5713 unsigned OpTyID =
Record[0];
5714 Type *OpTy = getTypeByID(OpTyID);
5716 if (!OpTy || !Address)
5717 return error(
"Invalid record");
5718 unsigned NumDests =
Record.size()-2;
5721 for (
unsigned i = 0, e = NumDests; i !=
e; ++i) {
5726 return error(
"Invalid record");
5736 return error(
"Invalid record");
5739 unsigned CCInfo =
Record[OpNum++];
5743 unsigned FTyID = InvalidTypeID;
5745 if ((CCInfo >> 13) & 1) {
5747 FTy = dyn_cast<FunctionType>(getTypeByID(FTyID));
5749 return error(
"Explicit invoke type is not a function type");
5753 unsigned CalleeTypeID;
5754 if (getValueTypePair(
Record, OpNum, NextValueNo, Callee, CalleeTypeID,
5756 return error(
"Invalid record");
5760 return error(
"Callee is not a pointer");
5762 FTyID = getContainedTypeID(CalleeTypeID);
5763 FTy = dyn_cast_or_null<FunctionType>(getTypeByID(FTyID));
5765 return error(
"Callee is not of pointer to function type");
5767 if (
Record.size() < FTy->getNumParams() + OpNum)
5768 return error(
"Insufficient operands to call");
5772 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i, ++OpNum) {
5773 unsigned ArgTyID = getContainedTypeID(FTyID, i + 1);
5774 Ops.
push_back(getValue(
Record, OpNum, NextValueNo, FTy->getParamType(i),
5778 return error(
"Invalid record");
5781 if (!FTy->isVarArg()) {
5782 if (
Record.size() != OpNum)
5783 return error(
"Invalid record");
5786 while (OpNum !=
Record.size()) {
5789 if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB))
5790 return error(
"Invalid record");
5797 if (!OperandBundles.empty())
5802 ResTypeID = getContainedTypeID(FTyID);
5803 OperandBundles.clear();
5805 cast<InvokeInst>(
I)->setCallingConv(
5807 cast<InvokeInst>(
I)->setAttributes(PAL);
5808 if (
Error Err = propagateAttributeTypes(cast<CallBase>(
I), ArgTyIDs)) {
5817 Value *Val =
nullptr;
5819 if (getValueTypePair(
Record,
Idx, NextValueNo, Val, ValTypeID, CurBB))
5820 return error(
"Invalid record");
5829 unsigned CCInfo =
Record[OpNum++];
5832 unsigned NumIndirectDests =
Record[OpNum++];
5834 for (
unsigned i = 0, e = NumIndirectDests; i !=
e; ++i)
5837 unsigned FTyID = InvalidTypeID;
5841 FTy = dyn_cast_or_null<FunctionType>(getTypeByID(FTyID));
5843 return error(
"Explicit call type is not a function type");
5847 unsigned CalleeTypeID;
5848 if (getValueTypePair(
Record, OpNum, NextValueNo, Callee, CalleeTypeID,
5850 return error(
"Invalid record");
5854 return error(
"Callee is not a pointer type");
5856 FTyID = getContainedTypeID(CalleeTypeID);
5857 FTy = dyn_cast_or_null<FunctionType>(getTypeByID(FTyID));
5859 return error(
"Callee is not of pointer to function type");
5861 if (
Record.size() < FTy->getNumParams() + OpNum)
5862 return error(
"Insufficient operands to call");
5867 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i, ++OpNum) {
5869 unsigned ArgTyID = getContainedTypeID(FTyID, i + 1);
5870 if (FTy->getParamType(i)->isLabelTy())
5871 Arg = getBasicBlock(
Record[OpNum]);
5873 Arg = getValue(
Record, OpNum, NextValueNo, FTy->getParamType(i),
5876 return error(
"Invalid record");
5877 Args.push_back(Arg);
5882 if (!FTy->isVarArg()) {
5883 if (OpNum !=
Record.size())
5884 return error(
"Invalid record");
5886 while (OpNum !=
Record.size()) {
5889 if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB))
5890 return error(
"Invalid record");
5897 if (!OperandBundles.empty())
5900 if (
auto *IA = dyn_cast<InlineAsm>(Callee)) {
5905 if (
none_of(ConstraintInfo, IsLabelConstraint)) {
5910 unsigned FirstBlockArg =
Args.size() - IndirectDests.
size();
5911 for (
unsigned ArgNo = FirstBlockArg; ArgNo <
Args.size(); ++ArgNo) {
5912 unsigned LabelNo = ArgNo - FirstBlockArg;
5913 auto *BA = dyn_cast<BlockAddress>(Args[ArgNo]);
5914 if (!BA || BA->getFunction() !=
F ||
5915 LabelNo > IndirectDests.
size() ||
5916 BA->getBasicBlock() != IndirectDests[LabelNo])
5917 return error(
"callbr argument does not match indirect dest");
5922 ArgTyIDs.
erase(ArgTyIDs.
begin() + FirstBlockArg, ArgTyIDs.
end());
5926 for (
Value *Arg : Args)
5929 FunctionType::get(FTy->getReturnType(), ArgTys, FTy->isVarArg());
5932 std::string Constraints =
IA->getConstraintString();
5935 for (
const auto &CI : ConstraintInfo) {
5937 if (ArgNo >= FirstBlockArg)
5938 Constraints.insert(Pos,
"!");
5943 Pos = Constraints.find(
',', Pos);
5944 if (Pos == std::string::npos)
5950 IA->hasSideEffects(),
IA->isAlignStack(),
5951 IA->getDialect(),
IA->canThrow());
5957 ResTypeID = getContainedTypeID(FTyID);
5958 OperandBundles.clear();
5960 cast<CallBrInst>(
I)->setCallingConv(
5962 cast<CallBrInst>(
I)->setAttributes(PAL);
5963 if (
Error Err = propagateAttributeTypes(cast<CallBase>(
I), ArgTyIDs)) {
5975 return error(
"Invalid phi record");
5977 unsigned TyID =
Record[0];
5978 Type *Ty = getTypeByID(TyID);
5980 return error(
"Invalid phi record");
5985 size_t NumArgs = (
Record.size() - 1) / 2;
5987 if ((
Record.size() - 1) % 2 == 1 && !isa<FPMathOperator>(PN)) {
5989 return error(
"Invalid phi record");
5994 for (
unsigned i = 0; i != NumArgs; i++) {
5998 return error(
"Invalid phi BB");
6005 auto It =
Args.find(BB);
6006 if (It !=
Args.end()) {
6017 if (!PhiConstExprBB)
6019 EdgeBB = PhiConstExprBB;
6027 V = getValueSigned(
Record, i * 2 + 1, NextValueNo, Ty, TyID, EdgeBB);
6029 V = getValue(
Record, i * 2 + 1, NextValueNo, Ty, TyID, EdgeBB);
6033 return error(
"Invalid phi record");
6036 if (EdgeBB == PhiConstExprBB && !EdgeBB->
empty()) {
6037 ConstExprEdgeBBs.
insert({{BB, CurBB}, EdgeBB});
6038 PhiConstExprBB =
nullptr;
6041 Args.insert({BB,
V});
6047 if (
Record.size() % 2 == 0) {
6048 assert(isa<FPMathOperator>(
I) &&
"Unexpected phi type");
6051 I->setFastMathFlags(FMF);
6063 return error(
"Invalid record");
6067 return error(
"Invalid record");
6070 Type *Ty = getTypeByID(ResTypeID);
6072 return error(
"Invalid record");
6074 Value *PersFn =
nullptr;
6075 unsigned PersFnTypeID;
6076 if (getValueTypePair(
Record,
Idx, NextValueNo, PersFn, PersFnTypeID,
6078 return error(
"Invalid record");
6080 if (!
F->hasPersonalityFn())
6081 F->setPersonalityFn(cast<Constant>(PersFn));
6082 else if (
F->getPersonalityFn() != cast<Constant>(PersFn))
6083 return error(
"Personality function mismatch");
6090 for (
unsigned J = 0; J != NumClauses; ++J) {
6096 if (getValueTypePair(
Record,
Idx, NextValueNo, Val, ValTypeID,
6099 return error(
"Invalid record");
6103 !isa<ArrayType>(Val->
getType())) &&
6104 "Catch clause has a invalid type!");
6106 isa<ArrayType>(Val->
getType())) &&
6107 "Filter clause has invalid type!");
6118 return error(
"Invalid record");
6121 const bool InAlloca = Bitfield::get<APV::UsedWithInAlloca>(Rec);
6122 const bool SwiftError = Bitfield::get<APV::SwiftError>(Rec);
6123 unsigned TyID =
Record[0];
6124 Type *Ty = getTypeByID(TyID);
6125 if (!Bitfield::get<APV::ExplicitType>(Rec)) {
6126 TyID = getContainedTypeID(TyID);
6127 Ty = getTypeByID(TyID);
6129 return error(
"Missing element type for old-style alloca");
6131 unsigned OpTyID =
Record[1];
6132 Type *OpTy = getTypeByID(OpTyID);
6136 Bitfield::get<APV::AlignLower>(Rec) |
6137 (Bitfield::get<APV::AlignUpper>(Rec) << APV::AlignLower::Bits);
6138 if (
Error Err = parseAlignmentValue(AlignExp,
Align)) {
6142 return error(
"Invalid record");
6145 unsigned AS =
Record.size() == 5 ?
Record[4] :
DL.getAllocaAddrSpace();
6149 return error(
"alloca of unsized type");
6151 Align =
DL.getPrefTypeAlign(Ty);
6153 if (!
Size->getType()->isIntegerTy())
6154 return error(
"alloca element count must have integer type");
6160 ResTypeID = getVirtualTypeID(AI->
getType(), TyID);
6168 if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB) ||
6169 (OpNum + 2 !=
Record.size() && OpNum + 3 !=
Record.size()))
6170 return error(
"Invalid record");
6172 if (!isa<PointerType>(
Op->getType()))
6173 return error(
"Load operand is not a pointer type");
6176 if (OpNum + 3 ==
Record.size()) {
6177 ResTypeID =
Record[OpNum++];
6178 Ty = getTypeByID(ResTypeID);
6180 ResTypeID = getContainedTypeID(OpTypeID);
6181 Ty = getTypeByID(ResTypeID);
6185 return error(
"Missing load type");
6187 if (
Error Err = typeCheckLoadStoreInst(Ty,
Op->getType()))
6195 return error(
"load of unsized type");
6197 Align = TheModule->getDataLayout().getABITypeAlign(Ty);
6207 if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB) ||
6208 (OpNum + 4 !=
Record.size() && OpNum + 5 !=
Record.size()))
6209 return error(
"Invalid record");
6211 if (!isa<PointerType>(
Op->getType()))
6212 return error(
"Load operand is not a pointer type");
6215 if (OpNum + 5 ==
Record.size()) {
6216 ResTypeID =
Record[OpNum++];
6217 Ty = getTypeByID(ResTypeID);
6219 ResTypeID = getContainedTypeID(OpTypeID);
6220 Ty = getTypeByID(ResTypeID);
6224 return error(
"Missing atomic load type");
6226 if (
Error Err = typeCheckLoadStoreInst(Ty,
Op->getType()))
6230 if (Ordering == AtomicOrdering::NotAtomic ||
6231 Ordering == AtomicOrdering::Release ||
6232 Ordering == AtomicOrdering::AcquireRelease)
6233 return error(
"Invalid record");
6234 if (Ordering != AtomicOrdering::NotAtomic &&
Record[OpNum] == 0)
6235 return error(
"Invalid record");
6242 return error(
"Alignment missing from atomic load");
6251 unsigned PtrTypeID, ValTypeID;
6252 if (getValueTypePair(
Record, OpNum, NextValueNo,
Ptr, PtrTypeID, CurBB))
6253 return error(
"Invalid record");
6256 if (getValueTypePair(
Record, OpNum, NextValueNo, Val, ValTypeID, CurBB))
6257 return error(
"Invalid record");
6259 ValTypeID = getContainedTypeID(PtrTypeID);
6260 if (popValue(
Record, OpNum, NextValueNo, getTypeByID(ValTypeID),
6261 ValTypeID, Val, CurBB))
6262 return error(
"Invalid record");
6265 if (OpNum + 2 !=
Record.size())
6266 return error(
"Invalid record");
6268 if (
Error Err = typeCheckLoadStoreInst(Val->
getType(),
Ptr->getType()))
6275 return error(
"store of unsized type");
6277 Align = TheModule->getDataLayout().getABITypeAlign(Val->
getType());
6287 unsigned PtrTypeID, ValTypeID;
6288 if (getValueTypePair(
Record, OpNum, NextValueNo,
Ptr, PtrTypeID, CurBB) ||
6289 !isa<PointerType>(
Ptr->getType()))
6290 return error(
"Invalid record");
6292 if (getValueTypePair(
Record, OpNum, NextValueNo, Val, ValTypeID, CurBB))
6293 return error(
"Invalid record");
6295 ValTypeID = getContainedTypeID(PtrTypeID);
6296 if (popValue(
Record, OpNum, NextValueNo, getTypeByID(ValTypeID),
6297 ValTypeID, Val, CurBB))
6298 return error(
"Invalid record");
6301 if (OpNum + 4 !=
Record.size())
6302 return error(
"Invalid record");
6304 if (
Error Err = typeCheckLoadStoreInst(Val->
getType(),
Ptr->getType()))
6307 if (Ordering == AtomicOrdering::NotAtomic ||
6308 Ordering == AtomicOrdering::Acquire ||
6309 Ordering == AtomicOrdering::AcquireRelease)
6310 return error(
"Invalid record");
6312 if (Ordering != AtomicOrdering::NotAtomic &&
Record[OpNum] == 0)
6313 return error(
"Invalid record");
6319 return error(
"Alignment missing from atomic store");
6327 const size_t NumRecords =
Record.size();
6331 if (getValueTypePair(
Record, OpNum, NextValueNo,
Ptr, PtrTypeID, CurBB))
6332 return error(
"Invalid record");
6334 if (!isa<PointerType>(
Ptr->getType()))
6335 return error(
"Cmpxchg operand is not a pointer type");
6338 unsigned CmpTypeID = getContainedTypeID(PtrTypeID);
6339 if (popValue(
Record, OpNum, NextValueNo, getTypeByID(CmpTypeID),
6340 CmpTypeID, Cmp, CurBB))
6341 return error(
"Invalid record");
6344 if (popValue(
Record, OpNum, NextValueNo,
Cmp->getType(), CmpTypeID,
6346 NumRecords < OpNum + 3 || NumRecords > OpNum + 5)
6347 return error(
"Invalid record");
6351 if (SuccessOrdering == AtomicOrdering::NotAtomic ||
6352 SuccessOrdering == AtomicOrdering::Unordered)
6353 return error(
"Invalid record");
6357 if (
Error Err = typeCheckLoadStoreInst(
Cmp->getType(),
Ptr->getType()))
6365 if (FailureOrdering == AtomicOrdering::NotAtomic ||
6366 FailureOrdering == AtomicOrdering::Unordered)
6367 return error(
"Invalid record");
6369 const Align Alignment(
6370 TheModule->getDataLayout().getTypeStoreSize(
Cmp->getType()));
6373 FailureOrdering, SSID);
6374 cast<AtomicCmpXchgInst>(
I)->setVolatile(
Record[OpNum]);
6376 if (NumRecords < 8) {
6380 I->insertInto(CurBB, CurBB->
end());
6382 ResTypeID = CmpTypeID;
6384 cast<AtomicCmpXchgInst>(
I)->setWeak(
Record[OpNum + 4]);
6386 ResTypeID = getVirtualTypeID(
I->getType(), {CmpTypeID, I1TypeID});
6395 const size_t NumRecords =
Record.size();
6399 if (getValueTypePair(
Record, OpNum, NextValueNo,
Ptr, PtrTypeID, CurBB))
6400 return error(
"Invalid record");
6402 if (!isa<PointerType>(
Ptr->getType()))
6403 return error(
"Cmpxchg operand is not a pointer type");
6407 if (getValueTypePair(
Record, OpNum, NextValueNo, Cmp, CmpTypeID, CurBB))
6408 return error(
"Invalid record");
6410 Value *Val =
nullptr;
6411 if (popValue(
Record, OpNum, NextValueNo,
Cmp->getType(), CmpTypeID, Val,
6413 return error(
"Invalid record");
6415 if (NumRecords < OpNum + 3 || NumRecords > OpNum + 6)
6416 return error(
"Invalid record");
6418 const bool IsVol =
Record[OpNum];
6423 return error(
"Invalid cmpxchg success ordering");
6427 if (
Error Err = typeCheckLoadStoreInst(
Cmp->getType(),
Ptr->getType()))
6433 return error(
"Invalid cmpxchg failure ordering");
6435 const bool IsWeak =
Record[OpNum + 4];
6439 if (NumRecords == (OpNum + 6)) {
6440 if (
Error Err = parseAlignmentValue(
Record[OpNum + 5], Alignment))
6445 Align(TheModule->getDataLayout().getTypeStoreSize(
Cmp->getType()));
6448 FailureOrdering, SSID);
6449 cast<AtomicCmpXchgInst>(
I)->setVolatile(IsVol);
6450 cast<AtomicCmpXchgInst>(
I)->setWeak(IsWeak);
6453 ResTypeID = getVirtualTypeID(
I->getType(), {CmpTypeID, I1TypeID});
6462 const size_t NumRecords =
Record.size();
6467 if (getValueTypePair(
Record, OpNum, NextValueNo,
Ptr, PtrTypeID, CurBB))
6468 return error(
"Invalid record");
6470 if (!isa<PointerType>(
Ptr->getType()))
6471 return error(
"Invalid record");
6473 Value *Val =
nullptr;
6474 unsigned ValTypeID = InvalidTypeID;
6476 ValTypeID = getContainedTypeID(PtrTypeID);
6477 if (popValue(
Record, OpNum, NextValueNo,
6478 getTypeByID(ValTypeID), ValTypeID, Val, CurBB))
6479 return error(
"Invalid record");
6481 if (getValueTypePair(
Record, OpNum, NextValueNo, Val, ValTypeID, CurBB))
6482 return error(
"Invalid record");
6485 if (!(NumRecords == (OpNum + 4) || NumRecords == (OpNum + 5)))
6486 return error(
"Invalid record");
6492 return error(
"Invalid record");
6494 const bool IsVol =
Record[OpNum + 1];
6497 if (Ordering == AtomicOrdering::NotAtomic ||
6498 Ordering == AtomicOrdering::Unordered)
6499 return error(
"Invalid record");
6505 if (NumRecords == (OpNum + 5)) {
6506 if (
Error Err = parseAlignmentValue(
Record[OpNum + 4], Alignment))
6512 Align(TheModule->getDataLayout().getTypeStoreSize(Val->
getType()));
6515 ResTypeID = ValTypeID;
6516 cast<AtomicRMWInst>(
I)->setVolatile(IsVol);
6523 return error(
"Invalid record");
6525 if (Ordering == AtomicOrdering::NotAtomic ||
6526 Ordering == AtomicOrdering::Unordered ||
6527 Ordering == AtomicOrdering::Monotonic)
6528 return error(
"Invalid record");
6537 SeenDebugRecord =
true;
6540 return error(
"Invalid dbg record: missing instruction");
6543 Inst->
getParent()->insertDbgRecordBefore(
6553 SeenDebugRecord =
true;
6556 return error(
"Invalid dbg record: missing instruction");
6572 cast<DILocalVariable>(getFnMetadataByID(
Record[Slot++]));
6574 cast<DIExpression>(getFnMetadataByID(
Record[Slot++]));
6586 unsigned SlotBefore =
Slot;
6587 if (getValueTypePair(
Record, Slot, NextValueNo, V, TyID, CurBB))
6588 return error(
"Invalid dbg record: invalid value");
6590 assert((SlotBefore == Slot - 1) &&
"unexpected fwd ref");
6593 RawLocation = getFnMetadataByID(
Record[Slot++]);
6601 DbgVariableRecord::LocationType::Value);
6605 DbgVariableRecord::LocationType::Declare);
6610 cast<DIExpression>(getFnMetadataByID(
Record[Slot++]));
6625 return error(
"Invalid record");
6629 unsigned CCInfo =
Record[OpNum++];
6635 return error(
"Fast math flags indicator set for call with no FMF");
6638 unsigned FTyID = InvalidTypeID;
6642 FTy = dyn_cast_or_null<FunctionType>(getTypeByID(FTyID));
6644 return error(
"Explicit call type is not a function type");
6648 unsigned CalleeTypeID;
6649 if (getValueTypePair(
Record, OpNum, NextValueNo, Callee, CalleeTypeID,
6651 return error(
"Invalid record");
6655 return error(
"Callee is not a pointer type");
6657 FTyID = getContainedTypeID(CalleeTypeID);
6658 FTy = dyn_cast_or_null<FunctionType>(getTypeByID(FTyID));
6660 return error(
"Callee is not of pointer to function type");
6662 if (
Record.size() < FTy->getNumParams() + OpNum)
6663 return error(
"Insufficient operands to call");
6668 for (
unsigned i = 0, e = FTy->getNumParams(); i != e; ++i, ++OpNum) {
6669 unsigned ArgTyID = getContainedTypeID(FTyID, i + 1);
6670 if (FTy->getParamType(i)->isLabelTy())
6671 Args.push_back(getBasicBlock(
Record[OpNum]));
6673 Args.push_back(getValue(
Record, OpNum, NextValueNo,
6674 FTy->getParamType(i), ArgTyID, CurBB));
6677 return error(
"Invalid record");
6681 if (!FTy->isVarArg()) {
6682 if (OpNum !=
Record.size())
6683 return error(
"Invalid record");
6685 while (OpNum !=
Record.size()) {
6688 if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB))
6689 return error(
"Invalid record");
6696 if (!OperandBundles.empty())
6700 ResTypeID = getContainedTypeID(FTyID);
6701 OperandBundles.clear();
6703 cast<CallInst>(
I)->setCallingConv(
6712 cast<CallInst>(
I)->setTailCallKind(TCK);
6713 cast<CallInst>(
I)->setAttributes(PAL);
6714 if (isa<DbgInfoIntrinsic>(
I))
6715 SeenDebugIntrinsic =
true;
6716 if (
Error Err = propagateAttributeTypes(cast<CallBase>(
I), ArgTyIDs)) {
6721 if (!isa<FPMathOperator>(
I))
6722 return error(
"Fast-math-flags specified for call without "
6723 "floating-point scalar or vector return type");
6724 I->setFastMathFlags(FMF);
6730 return error(
"Invalid record");
6731 unsigned OpTyID =
Record[0];
6732 Type *OpTy = getTypeByID(OpTyID);
6733 Value *
Op = getValue(
Record, 1, NextValueNo, OpTy, OpTyID, CurBB);
6735 Type *ResTy = getTypeByID(ResTypeID);
6736 if (!OpTy || !
Op || !ResTy)
6737 return error(
"Invalid record");
6749 return error(
"Invalid record");
6751 std::vector<Value *> Inputs;
6754 while (OpNum !=
Record.size()) {
6757 if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB))
6758 return error(
"Invalid record");
6759 Inputs.push_back(
Op);
6762 OperandBundles.emplace_back(BundleTags[
Record[0]], std::move(Inputs));
6770 if (getValueTypePair(
Record, OpNum, NextValueNo,
Op, OpTypeID, CurBB))
6771 return error(
"Invalid record");
6772 if (OpNum !=
Record.size())
6773 return error(
"Invalid record");
6776 ResTypeID = OpTypeID;
6786 return error(
"Invalid instruction with no BB");
6788 if (!OperandBundles.empty()) {
6790 return error(
"Operand bundles found with no consumer");
6792 I->insertInto(CurBB, CurBB->
end());
6795 if (
I->isTerminator()) {
6797 CurBB = CurBBNo < FunctionBBs.size() ? FunctionBBs[CurBBNo] :
nullptr;
6801 if (!
I->getType()->isVoidTy()) {
6802 assert(
I->getType() == getTypeByID(ResTypeID) &&
6803 "Incorrect result type ID");
6811 if (!OperandBundles.empty())
6812 return error(
"Operand bundles found with no consumer");
6816 if (!
A->getParent()) {
6818 for (
unsigned i = ModuleValueListSize, e = ValueList.
size(); i != e; ++i){
6819 if ((
A = dyn_cast_or_null<Argument>(ValueList[i])) && !
A->getParent()) {
6824 return error(
"Never resolved value found in function");
6829 if (MDLoader->hasFwdRefs())
6830 return error(
"Invalid function metadata: outgoing forward refs");
6835 for (
const auto &Pair : ConstExprEdgeBBs) {
6840 From->getTerminator()->replaceSuccessorWith(To, EdgeBB);
6846 ValueList.
shrinkTo(ModuleValueListSize);
6847 MDLoader->shrinkTo(ModuleMDLoaderSize);
6848 std::vector<BasicBlock*>().swap(FunctionBBs);
6853Error BitcodeReader::findFunctionInStream(
6856 while (DeferredFunctionInfoIterator->second == 0) {
6861 assert(VSTOffset == 0 || !
F->hasName());
6864 if (
Error Err = rememberAndSkipFunctionBodies())
6870SyncScope::ID BitcodeReader::getDecodedSyncScopeID(
unsigned Val) {
6873 if (Val >= SSIDs.
size())
6885 if (!
F || !
F->isMaterializable())
6889 assert(DFII != DeferredFunctionInfo.
end() &&
"Deferred function not found!");
6892 if (DFII->second == 0)
6893 if (
Error Err = findFunctionInStream(
F, DFII))
6897 if (
Error Err = materializeMetadata())
6901 if (
Error JumpFailed = Stream.JumpToBit(DFII->second))
6906 F->IsNewDbgInfoFormat =
true;
6908 if (
Error Err = parseFunctionBody(
F))
6910 F->setIsMaterializable(
false);
6914 if (SeenDebugIntrinsic && SeenDebugRecord)
6915 return error(
"Mixed debug intrinsics and debug records in bitcode module!");
6917 bool SeenAnyDebugInfo = SeenDebugIntrinsic || SeenDebugRecord;
6918 bool NewDbgInfoFormatDesired =
6919 SeenAnyDebugInfo ? SeenDebugRecord :
F->getParent()->IsNewDbgInfoFormat;
6920 if (SeenAnyDebugInfo) {
6929 if (NewDbgInfoFormatDesired !=
F->getParent()->IsNewDbgInfoFormat)
6930 F->getParent()->setNewDbgInfoFormatFlag(NewDbgInfoFormatDesired);
6932 F->setNewDbgInfoFormatFlag(NewDbgInfoFormatDesired);
6940 bool ModuleIsNewDbgInfoFormat =
F->getParent()->IsNewDbgInfoFormat;
6941 if (ModuleIsNewDbgInfoFormat || !SeenDebugRecord)
6942 F->setNewDbgInfoFormatFlag(ModuleIsNewDbgInfoFormat);
6944 F->setIsNewDbgInfoFormat(ModuleIsNewDbgInfoFormat);
6951 for (
auto &
I : UpgradedIntrinsics) {
6953 if (
CallInst *CI = dyn_cast<CallInst>(U))
6958 if (
DISubprogram *SP = MDLoader->lookupSubprogramForFunction(
F))
6959 F->setSubprogram(SP);
6962 if (!MDLoader->isStrippingTBAA()) {
6964 MDNode *TBAA =
I.getMetadata(LLVMContext::MD_tbaa);
6967 MDLoader->setStripTBAA(
true);
6974 if (
auto *MD =
I.getMetadata(LLVMContext::MD_prof)) {
6975 if (MD->getOperand(0) !=
nullptr && isa<MDString>(MD->getOperand(0))) {
6976 MDString *MDS = cast<MDString>(MD->getOperand(0));
6979 if (ProfName !=
"branch_weights")
6981 unsigned ExpectedNumOperands = 0;
6983 ExpectedNumOperands = BI->getNumSuccessors();
6984 else if (
SwitchInst *SI = dyn_cast<SwitchInst>(&
I))
6985 ExpectedNumOperands =
SI->getNumSuccessors();
6986 else if (isa<CallInst>(&
I))
6987 ExpectedNumOperands = 1;
6990 else if (isa<SelectInst>(&
I))
6991 ExpectedNumOperands = 2;
6998 if (MD->getNumOperands() !=
Offset + ExpectedNumOperands)
6999 I.setMetadata(LLVMContext::MD_prof,
nullptr);
7004 if (
auto *CI = dyn_cast<CallBase>(&
I)) {
7006 CI->getFunctionType()->getReturnType()));
7008 for (
unsigned ArgNo = 0; ArgNo < CI->arg_size(); ++ArgNo)
7010 CI->getArgOperand(ArgNo)->getType()));
7019 return materializeForwardReferencedFunctions();
7022Error BitcodeReader::materializeModule() {
7023 if (
Error Err = materializeMetadata())
7027 WillMaterializeAllForwardRefs =
true;
7032 if (
Error Err = materialize(&
F))
7038 if (LastFunctionBlockBit || NextUnreadBit)
7040 ? LastFunctionBlockBit
7046 if (!BasicBlockFwdRefs.
empty())
7047 return error(
"Never resolved function from blockaddress");
7053 for (
auto &
I : UpgradedIntrinsics) {
7054 for (
auto *U :
I.first->users()) {
7055 if (
CallInst *CI = dyn_cast<CallInst>(U))
7058 if (!
I.first->use_empty())
7059 I.first->replaceAllUsesWith(
I.second);
7060 I.first->eraseFromParent();
7062 UpgradedIntrinsics.clear();
7073std::vector<StructType *> BitcodeReader::getIdentifiedStructTypes()
const {
7074 return IdentifiedStructTypes;
7077ModuleSummaryIndexBitcodeReader::ModuleSummaryIndexBitcodeReader(
7080 : BitcodeReaderBase(
std::
move(Cursor), Strtab), TheIndex(TheIndex),
7081 ModulePath(ModulePath), IsPrevailing(IsPrevailing) {}
7083void ModuleSummaryIndexBitcodeReader::addThisModule() {
7088ModuleSummaryIndexBitcodeReader::getThisModule() {
7092template <
bool AllowNullValueInfo>
7093std::tuple<ValueInfo, GlobalValue::GUID, GlobalValue::GUID>
7094ModuleSummaryIndexBitcodeReader::getValueInfoFromValueId(
unsigned ValueId) {
7095 auto VGI = ValueIdToValueInfoMap[ValueId];
7100 assert(AllowNullValueInfo || std::get<0>(VGI));
7104void ModuleSummaryIndexBitcodeReader::setValueGUID(
7107 std::string GlobalId =
7110 auto OriginalNameID = ValueGUID;
7114 dbgs() <<
"GUID " << ValueGUID <<
"(" << OriginalNameID <<
") is "
7120 ValueIdToValueInfoMap[ValueID] = std::make_tuple(
7123 OriginalNameID, ValueGUID);
7129Error ModuleSummaryIndexBitcodeReader::parseValueSymbolTable(
7138 if (!MaybeCurrentBit)
7156 switch (
Entry.Kind) {
7159 return error(
"Malformed block");
7162 if (
Error JumpFailed = Stream.JumpToBit(CurrentBit))
7175 switch (MaybeRecord.
get()) {
7180 return error(
"Invalid record");
7181 unsigned ValueID =
Record[0];
7183 auto VLI = ValueIdToLinkageMap.
find(ValueID);
7184 assert(VLI != ValueIdToLinkageMap.
end() &&
7185 "No linkage found for VST entry?");
7187 setValueGUID(ValueID,
ValueName, Linkage, SourceFileName);
7194 return error(
"Invalid record");
7195 unsigned ValueID =
Record[0];
7197 auto VLI = ValueIdToLinkageMap.
find(ValueID);
7198 assert(VLI != ValueIdToLinkageMap.
end() &&
7199 "No linkage found for VST entry?");
7201 setValueGUID(ValueID,
ValueName, Linkage, SourceFileName);
7207 unsigned ValueID =
Record[0];
7211 ValueIdToValueInfoMap[ValueID] = std::make_tuple(
7222Error ModuleSummaryIndexBitcodeReader::parseModule() {
7228 unsigned ValueId = 0;
7237 switch (
Entry.Kind) {
7239 return error(
"Malformed block");
7246 if (
Error Err = Stream.SkipBlock())
7251 if (
Error Err = readBlockInfo())
7257 assert(((SeenValueSymbolTable && VSTOffset > 0) ||
7258 !SeenGlobalValSummary) &&
7259 "Expected early VST parse via VSTOffset record");
7260 if (
Error Err = Stream.SkipBlock())
7266 if (!SourceFileName.
empty())
7268 assert(!SeenValueSymbolTable &&
7269 "Already read VST when parsing summary block?");
7274 if (VSTOffset > 0) {
7275 if (
Error Err = parseValueSymbolTable(VSTOffset, ValueIdToLinkageMap))
7277 SeenValueSymbolTable =
true;
7279 SeenGlobalValSummary =
true;
7280 if (
Error Err = parseEntireSummary(
Entry.ID))
7284 if (
Error Err = parseModuleStringTable())
7295 switch (MaybeBitCode.
get()) {
7299 if (
Error Err = parseVersionRecord(
Record).takeError())
7307 return error(
"Invalid record");
7315 auto &Hash = getThisModule()->second;
7317 for (
auto &Val :
Record) {
7318 assert(!(Val >> 32) &&
"Unexpected high bits set");
7326 return error(
"Invalid record");
7330 VSTOffset =
Record[0] - 1;
7341 std::tie(
Name, GVRecord) = readNameFromStrtab(
Record);
7342 if (GVRecord.
size() <= 3)
7343 return error(
"Invalid record");
7347 ValueIdToLinkageMap[ValueId++] =
Linkage;
7351 setValueGUID(ValueId++,
Name, Linkage, SourceFileName);
7361std::vector<ValueInfo>
7363 std::vector<ValueInfo>
Ret;
7366 Ret.push_back(std::get<0>(getValueInfoFromValueId(RefValueId)));
7370std::vector<FunctionSummary::EdgeTy>
7372 bool IsOldProfileFormat,
7373 bool HasProfile,
bool HasRelBF) {
7374 std::vector<FunctionSummary::EdgeTy>
Ret;
7377 if (!IsOldProfileFormat && (HasProfile || HasRelBF))
7382 for (
unsigned I = 0, E =
Record.size();
I != E; ++
I) {
7384 bool HasTailCall =
false;
7387 if (IsOldProfileFormat) {
7391 }
else if (HasProfile)
7392 std::tie(Hotness, HasTailCall) =
7425 static_cast<size_t>(
Record[Slot + 1])};
7448 while (Slot <
Record.size())
7452std::vector<FunctionSummary::ParamAccess>
7454 auto ReadRange = [&]() {
7456 BitcodeReader::decodeSignRotatedValue(
Record.front()));
7459 BitcodeReader::decodeSignRotatedValue(
Record.front()));
7467 std::vector<FunctionSummary::ParamAccess> PendingParamAccesses;
7468 while (!
Record.empty()) {
7469 PendingParamAccesses.emplace_back();
7473 ParamAccess.
Use = ReadRange();
7476 for (
auto &Call : ParamAccess.
Calls) {
7479 Call.Callee = std::get<0>(getValueInfoFromValueId(
Record.front()));
7481 Call.Offsets = ReadRange();
7484 return PendingParamAccesses;
7487void ModuleSummaryIndexBitcodeReader::parseTypeIdCompatibleVtableInfo(
7495void ModuleSummaryIndexBitcodeReader::parseTypeIdCompatibleVtableSummaryRecord(
7501 static_cast<size_t>(
Record[Slot + 1])});
7504 while (Slot <
Record.size())
7505 parseTypeIdCompatibleVtableInfo(
Record, Slot, TypeId);
7511 assert(ROCnt + WOCnt <= Refs.size());
7512 unsigned FirstWORef = Refs.size() - WOCnt;
7513 unsigned RefNo = FirstWORef - ROCnt;
7514 for (; RefNo < FirstWORef; ++RefNo)
7515 Refs[RefNo].setReadOnly();
7516 for (; RefNo < Refs.size(); ++RefNo)
7517 Refs[RefNo].setWriteOnly();
7522Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(
unsigned ID) {
7523 if (
Error Err = Stream.EnterSubBlock(
ID))
7535 return error(
"Invalid Summary Block: record for version expected");
7540 return error(
"Invalid Summary Block: version expected");
7543 const bool IsOldProfileFormat =
Version == 1;
7545 return error(
"Invalid summary version " +
Twine(Version) +
7546 ". Version should be in the range [1-" +
7559 std::vector<GlobalValue::GUID> PendingTypeTests;
7560 std::vector<FunctionSummary::VFuncId> PendingTypeTestAssumeVCalls,
7561 PendingTypeCheckedLoadVCalls;
7562 std::vector<FunctionSummary::ConstVCall> PendingTypeTestAssumeConstVCalls,
7563 PendingTypeCheckedLoadConstVCalls;
7564 std::vector<FunctionSummary::ParamAccess> PendingParamAccesses;
7566 std::vector<CallsiteInfo> PendingCallsites;
7567 std::vector<AllocInfo> PendingAllocs;
7575 switch (
Entry.Kind) {
7578 return error(
"Malformed block");
7597 switch (
unsigned BitCode = MaybeBitCode.
get()) {
7607 ValueIdToValueInfoMap[ValueID] = std::make_tuple(
7623 unsigned ValueID =
Record[0];
7625 unsigned InstCount =
Record[2];
7627 unsigned NumRefs =
Record[3];
7628 unsigned NumRORefs = 0, NumWORefs = 0;
7629 int RefListStartIndex = 4;
7633 RefListStartIndex = 5;
7636 RefListStartIndex = 6;
7639 RefListStartIndex = 7;
7650 int CallGraphEdgeStartIndex = RefListStartIndex + NumRefs;
7652 "Record size inconsistent with number of references");
7653 std::vector<ValueInfo> Refs = makeRefList(
7657 std::vector<FunctionSummary::EdgeTy> Calls = makeCallList(
7659 IsOldProfileFormat, HasProfile, HasRelBF);
7661 auto VIAndOriginalGUID = getValueInfoFromValueId(ValueID);
7668 !IsPrevailing(std::get<2>(VIAndOriginalGUID))) {
7669 PendingCallsites.clear();
7670 PendingAllocs.clear();
7672 auto FS = std::make_unique<FunctionSummary>(
7674 std::move(Refs), std::move(Calls), std::move(PendingTypeTests),
7675 std::move(PendingTypeTestAssumeVCalls),
7676 std::move(PendingTypeCheckedLoadVCalls),
7677 std::move(PendingTypeTestAssumeConstVCalls),
7678 std::move(PendingTypeCheckedLoadConstVCalls),
7679 std::move(PendingParamAccesses), std::move(PendingCallsites),
7680 std::move(PendingAllocs));
7681 FS->setModulePath(getThisModule()->first());
7682 FS->setOriginalName(std::get<1>(VIAndOriginalGUID));
7691 unsigned ValueID =
Record[0];
7693 unsigned AliaseeID =
Record[2];
7695 auto AS = std::make_unique<AliasSummary>(Flags);
7701 AS->setModulePath(getThisModule()->first());
7703 auto AliaseeVI = std::get<0>(getValueInfoFromValueId(AliaseeID));
7705 if (!AliaseeInModule)
7706 return error(
"Alias expects aliasee summary to be parsed");
7707 AS->setAliasee(AliaseeVI, AliaseeInModule);
7709 auto GUID = getValueInfoFromValueId(ValueID);
7710 AS->setOriginalName(std::get<1>(GUID));
7716 unsigned ValueID =
Record[0];
7718 unsigned RefArrayStart = 2;
7728 std::vector<ValueInfo> Refs =
7731 std::make_unique<GlobalVarSummary>(Flags, GVF, std::move(Refs));
7732 FS->setModulePath(getThisModule()->first());
7733 auto GUID = getValueInfoFromValueId(ValueID);
7734 FS->setOriginalName(std::get<1>(GUID));
7742 unsigned ValueID =
Record[0];
7745 unsigned NumRefs =
Record[3];
7746 unsigned RefListStartIndex = 4;
7747 unsigned VTableListStartIndex = RefListStartIndex + NumRefs;
7749 std::vector<ValueInfo> Refs = makeRefList(
7752 for (
unsigned I = VTableListStartIndex, E =
Record.size();
I != E; ++
I) {
7758 std::make_unique<GlobalVarSummary>(Flags, GVF, std::move(Refs));
7759 VS->setModulePath(getThisModule()->first());
7760 VS->setVTableFuncs(VTableFuncs);
7761 auto GUID = getValueInfoFromValueId(ValueID);
7762 VS->setOriginalName(std::get<1>(GUID));
7774 unsigned ValueID =
Record[0];
7777 unsigned InstCount =
Record[3];
7780 unsigned NumRefs =
Record[4];
7781 unsigned NumRORefs = 0, NumWORefs = 0;
7782 int RefListStartIndex = 5;
7786 RefListStartIndex = 6;
7787 size_t NumRefsIndex = 5;
7789 unsigned NumRORefsOffset = 1;
7790 RefListStartIndex = 7;
7794 RefListStartIndex = 8;
7796 RefListStartIndex = 9;
7798 NumRORefsOffset = 2;
7801 NumRORefs =
Record[RefListStartIndex - NumRORefsOffset];
7803 NumRefs =
Record[NumRefsIndex];
7807 int CallGraphEdgeStartIndex = RefListStartIndex + NumRefs;
7809 "Record size inconsistent with number of references");
7810 std::vector<ValueInfo> Refs = makeRefList(
7813 std::vector<FunctionSummary::EdgeTy> Edges = makeCallList(
7815 IsOldProfileFormat, HasProfile,
false);
7816 ValueInfo VI = std::get<0>(getValueInfoFromValueId(ValueID));
7818 auto FS = std::make_unique<FunctionSummary>(
7820 std::move(Refs), std::move(Edges), std::move(PendingTypeTests),
7821 std::move(PendingTypeTestAssumeVCalls),
7822 std::move(PendingTypeCheckedLoadVCalls),
7823 std::move(PendingTypeTestAssumeConstVCalls),
7824 std::move(PendingTypeCheckedLoadConstVCalls),
7825 std::move(PendingParamAccesses), std::move(PendingCallsites),
7826 std::move(PendingAllocs));
7827 LastSeenSummary =
FS.get();
7828 LastSeenGUID =
VI.getGUID();
7829 FS->setModulePath(ModuleIdMap[ModuleId]);
7837 unsigned ValueID =
Record[0];
7840 unsigned AliaseeValueId =
Record[3];
7842 auto AS = std::make_unique<AliasSummary>(Flags);
7843 LastSeenSummary = AS.get();
7844 AS->setModulePath(ModuleIdMap[ModuleId]);
7846 auto AliaseeVI = std::get<0>(getValueInfoFromValueId(AliaseeValueId));
7848 AS->setAliasee(AliaseeVI, AliaseeInModule);
7850 ValueInfo VI = std::get<0>(getValueInfoFromValueId(ValueID));
7851 LastSeenGUID =
VI.getGUID();
7857 unsigned ValueID =
Record[0];
7860 unsigned RefArrayStart = 3;
7870 std::vector<ValueInfo> Refs =
7873 std::make_unique<GlobalVarSummary>(Flags, GVF, std::move(Refs));
7874 LastSeenSummary =
FS.get();
7875 FS->setModulePath(ModuleIdMap[ModuleId]);
7876 ValueInfo VI = std::get<0>(getValueInfoFromValueId(ValueID));
7877 LastSeenGUID =
VI.getGUID();
7884 if (!LastSeenSummary)
7885 return error(
"Name attachment that does not follow a combined record");
7889 LastSeenSummary =
nullptr;
7894 assert(PendingTypeTests.empty());
7899 assert(PendingTypeTestAssumeVCalls.empty());
7900 for (
unsigned I = 0;
I !=
Record.size();
I += 2)
7901 PendingTypeTestAssumeVCalls.push_back({Record[I], Record[I+1]});
7905 assert(PendingTypeCheckedLoadVCalls.empty());
7906 for (
unsigned I = 0;
I !=
Record.size();
I += 2)
7907 PendingTypeCheckedLoadVCalls.push_back({Record[I], Record[I+1]});
7911 PendingTypeTestAssumeConstVCalls.push_back(
7916 PendingTypeCheckedLoadConstVCalls.push_back(
7922 for (
unsigned I = 0;
I !=
Record.size();
I += 2)
7923 CfiFunctionDefs.insert(
7924 {Strtab.data() + Record[I], static_cast<size_t>(Record[I + 1])});
7930 for (
unsigned I = 0;
I !=
Record.size();
I += 2)
7931 CfiFunctionDecls.insert(
7932 {Strtab.data() + Record[I], static_cast<size_t>(Record[I + 1])});
7941 parseTypeIdCompatibleVtableSummaryRecord(
Record);
7949 PendingParamAccesses = parseParamAccesses(
Record);
7961 unsigned ValueID =
Record[0];
7963 for (
auto R =
Record.begin() + 1; R !=
Record.end(); R++) {
7964 assert(*R < StackIds.size());
7967 ValueInfo VI = std::get<0>(getValueInfoFromValueId(ValueID));
7968 PendingCallsites.push_back(
CallsiteInfo({
VI, std::move(StackIdList)}));
7973 auto RecordIter =
Record.begin();
7974 unsigned ValueID = *RecordIter++;
7975 unsigned NumStackIds = *RecordIter++;
7976 unsigned NumVersions = *RecordIter++;
7977 assert(
Record.size() == 3 + NumStackIds + NumVersions);
7979 for (
unsigned J = 0; J < NumStackIds; J++) {
7980 assert(*RecordIter < StackIds.size());
7985 for (
unsigned J = 0; J < NumVersions; J++)
7988 getValueInfoFromValueId</*AllowNullValueInfo*/ true>(ValueID));
7989 PendingCallsites.push_back(
7990 CallsiteInfo({
VI, std::move(Versions), std::move(StackIdList)}));
7996 std::vector<MIBInfo> MIBs;
8000 unsigned NumStackEntries =
Record[
I++];
8003 for (
unsigned J = 0; J < NumStackEntries; J++) {
8010 PendingAllocs.push_back(
AllocInfo(std::move(MIBs)));
8016 std::vector<MIBInfo> MIBs;
8017 unsigned NumMIBs =
Record[
I++];
8018 unsigned NumVersions =
Record[
I++];
8019 unsigned MIBsRead = 0;
8020 while (MIBsRead++ < NumMIBs) {
8023 unsigned NumStackEntries =
Record[
I++];
8026 for (
unsigned J = 0; J < NumStackEntries; J++) {
8035 for (
unsigned J = 0; J < NumVersions; J++)
8037 PendingAllocs.push_back(
8038 AllocInfo(std::move(Versions), std::move(MIBs)));
8048Error ModuleSummaryIndexBitcodeReader::parseModuleStringTable() {
8063 switch (
Entry.Kind) {
8066 return error(
"Malformed block");
8078 switch (MaybeRecord.
get()) {
8086 return error(
"Invalid record");
8088 LastSeenModule = TheIndex.
addModule(ModulePath);
8089 ModuleIdMap[ModuleId] = LastSeenModule->
first();
8098 if (!LastSeenModule)
8099 return error(
"Invalid hash that does not follow a module path");
8101 for (
auto &Val :
Record) {
8102 assert(!(Val >> 32) &&
"Unexpected high bits set");
8103 LastSeenModule->
second[Pos++] = Val;
8106 LastSeenModule =
nullptr;
8119class BitcodeErrorCategoryType :
public std::error_category {
8120 const char *
name()
const noexcept
override {
8121 return "llvm.bitcode";
8124 std::string message(
int IE)
const override {
8127 case BitcodeError::CorruptedBitcode:
8128 return "Corrupted bitcode";
8137 static BitcodeErrorCategoryType ErrorCategory;
8138 return ErrorCategory;
8142 unsigned Block,
unsigned RecordID) {
8144 return std::move(Err);
8153 switch (Entry.Kind) {
8158 return error(
"Malformed block");
8162 return std::move(Err);
8172 if (MaybeRecord.
get() == RecordID)
8187 return FOrErr.takeError();
8188 return std::move(FOrErr->Mods);
8213 switch (Entry.Kind) {
8216 return error(
"Malformed block");
8219 uint64_t IdentificationBit = -1ull;
8223 return std::move(Err);
8229 Entry = MaybeEntry.
get();
8234 return error(
"Malformed block");
8240 return std::move(Err);
8259 if (!
I.Strtab.empty())
8266 if (!
F.Symtab.empty() &&
F.StrtabForSymtab.empty())
8267 F.StrtabForSymtab = *Strtab;
8283 if (
F.Symtab.empty())
8284 F.Symtab = *SymtabOrErr;
8289 return std::move(Err);
8294 return std::move(E);
8309BitcodeModule::getModuleImpl(
LLVMContext &Context,
bool MaterializeAll,
8310 bool ShouldLazyLoadMetadata,
bool IsImporting,
8314 std::string ProducerIdentification;
8315 if (IdentificationBit != -1ull) {
8316 if (
Error JumpFailed = Stream.JumpToBit(IdentificationBit))
8317 return std::move(JumpFailed);
8320 return std::move(E);
8323 if (
Error JumpFailed = Stream.JumpToBit(ModuleBit))
8324 return std::move(JumpFailed);
8325 auto *
R =
new BitcodeReader(std::move(Stream), Strtab, ProducerIdentification,
8328 std::unique_ptr<Module>
M =
8329 std::make_unique<Module>(ModuleIdentifier, Context);
8330 M->setMaterializer(R);
8333 if (
Error Err =
R->parseBitcodeInto(
M.get(), ShouldLazyLoadMetadata,
8334 IsImporting, Callbacks))
8335 return std::move(Err);
8337 if (MaterializeAll) {
8339 if (
Error Err =
M->materializeAll())
8340 return std::move(Err);
8343 if (
Error Err =
R->materializeForwardReferencedFunctions())
8344 return std::move(Err);
8347 return std::move(M);
8353 return getModuleImpl(Context,
false, ShouldLazyLoadMetadata, IsImporting,
8368 ModuleSummaryIndexBitcodeReader R(std::move(Stream), Strtab, CombinedIndex,
8369 ModulePath, IsPrevailing);
8370 return R.parseModule();
8377 return std::move(JumpFailed);
8379 auto Index = std::make_unique<ModuleSummaryIndex>(
false);
8380 ModuleSummaryIndexBitcodeReader R(std::move(Stream), Strtab, *
Index,
8381 ModuleIdentifier, 0);
8383 if (
Error Err = R.parseModule())
8384 return std::move(Err);
8386 return std::move(
Index);
8394 return std::move(Err);
8399 std::pair<bool, bool> Result = {
false,
false};
8401 return std::move(E);
8403 switch (Entry.Kind) {
8406 return error(
"Malformed block");
8421 switch (MaybeBitCode.
get()) {
8427 assert(Flags <= 0x2ff &&
"Unexpected bits in flag");
8429 bool EnableSplitLTOUnit = Flags & 0x8;
8430 bool UnifiedLTO = Flags & 0x200;
8431 Result = {EnableSplitLTOUnit, UnifiedLTO};
8444 return std::move(JumpFailed);
8447 return std::move(Err);
8452 return std::move(E);
8454 switch (Entry.Kind) {
8456 return error(
"Malformed block");
8467 return Flags.takeError();
8479 return Flags.takeError();
8488 return std::move(Err);
8495 return StreamFailed.takeError();
8505 if (MsOrErr->size() != 1)
8506 return error(
"Expected a single module");
8508 return (*MsOrErr)[0];
8513 bool ShouldLazyLoadMetadata,
bool IsImporting,
8519 return BM->getLazyModule(Context, ShouldLazyLoadMetadata, IsImporting,
8524 std::unique_ptr<MemoryBuffer> &&Buffer,
LLVMContext &Context,
8525 bool ShouldLazyLoadMetadata,
bool IsImporting,
ParserCallbacks Callbacks) {
8527 IsImporting, Callbacks);
8529 (*MOrErr)->setOwnedMemoryBuffer(std::move(Buffer));
8535 return getModuleImpl(Context,
true,
false,
false, Callbacks);
8547 return BM->parseModule(Context, Callbacks);
8580 return BM->readSummary(CombinedIndex, BM->getModuleIdentifier());
8589 return BM->getSummary();
8597 return BM->getLTOInfo();
8602 bool IgnoreEmptyThinLTOIndexFile) {
8607 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 GEPNoWrapFlags toGEPNoWrapFlags(uint64_t Flags)
static void decodeLLVMAttributesForBitcode(AttrBuilder &B, uint64_t EncodedAttrs, uint64_t AttrIdx)
This fills an AttrBuilder object with the LLVM attributes that have been decoded from the given integ...
cl::opt< bool > WriteNewDbgInfoFormat
static void parseTypeIdSummaryRecord(ArrayRef< uint64_t > Record, StringRef Strtab, ModuleSummaryIndex &TheIndex)
cl::opt< cl::boolOrDefault > LoadBitcodeIntoNewDbgInfoFormat("load-bitcode-into-experimental-debuginfo-iterators", cl::Hidden, cl::desc("Load bitcode directly into the new debug info format (regardless " "of input format)"))
Load bitcode directly into RemoveDIs format (use debug records instead of debug intrinsics).
static void addRawAttributeValue(AttrBuilder &B, uint64_t Val)
bool WriteNewDbgInfoFormatToBitcode
static Comdat::SelectionKind getDecodedComdatSelectionKind(unsigned Val)
static bool hasImplicitComdat(size_t Val)
static GlobalValue::LinkageTypes getDecodedLinkage(unsigned Val)
static Error hasInvalidBitcodeHeader(BitstreamCursor &Stream)
static Expected< std::string > readIdentificationCode(BitstreamCursor &Stream)
static int getDecodedBinaryOpcode(unsigned Val, Type *Ty)
static AtomicRMWInst::BinOp getDecodedRMWOperation(unsigned Val)
static Expected< BitcodeModule > getSingleModule(MemoryBufferRef Buffer)
static Expected< bool > hasObjCCategory(BitstreamCursor &Stream)
static GlobalVariable::ThreadLocalMode getDecodedThreadLocalMode(unsigned Val)
static void parseWholeProgramDevirtResolution(ArrayRef< uint64_t > Record, StringRef Strtab, size_t &Slot, TypeIdSummary &TypeId)
static void inferDSOLocal(GlobalValue *GV)
static FastMathFlags getDecodedFastMathFlags(unsigned Val)
GlobalValue::SanitizerMetadata deserializeSanitizerMetadata(unsigned V)
static Expected< BitstreamCursor > initStream(MemoryBufferRef Buffer)
static cl::opt< bool > ExpandConstantExprs("expand-constant-exprs", cl::Hidden, cl::desc("Expand constant expressions to instructions for testing purposes"))
static bool upgradeOldMemoryAttribute(MemoryEffects &ME, uint64_t EncodedKind)
static Expected< StringRef > readBlobInRecord(BitstreamCursor &Stream, unsigned Block, unsigned RecordID)
static Expected< std::string > readIdentificationBlock(BitstreamCursor &Stream)
Read the "IDENTIFICATION_BLOCK_ID" block, do some basic enforcement on the "epoch" encoded in the bit...
static bool isConstExprSupported(const BitcodeConstant *BC)
static int getDecodedCastOpcode(unsigned Val)
cl::opt< bool > UseNewDbgInfoFormat
static Expected< std::string > readModuleTriple(BitstreamCursor &Stream)
static GlobalValue::VisibilityTypes getDecodedVisibility(unsigned Val)
BlockVerifier::State From
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
Analysis containing CSE Info
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static StringRef getOpcodeName(uint8_t Opcode, uint8_t OpcodeBase)
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
Looks at all the uses of the given value Returns the Liveness deduced from the uses of this value Adds all uses that cause the result to be MaybeLive to MaybeLiveRetUses If the result is Live
This file defines the DenseMap class.
Provides ErrorOr<T> smart pointer.
This file contains the declaration of the GlobalIFunc class, which represents a single indirect funct...
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.
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
PowerPC Reduce CR logical Operation
This file contains the declarations for profiling metadata utility functions.
const SmallVectorImpl< MachineOperand > & Cond
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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 bool isConstantRangeListAttrKind(AttrKind Kind)
static Attribute getWithByValType(LLVMContext &Context, Type *Ty)
static bool isEnumAttrKind(AttrKind Kind)
LLVM Basic Block Representation.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
void replacePhiUsesWith(BasicBlock *Old, BasicBlock *New)
Update all phi nodes in this basic block to refer to basic block New instead of basic block Old.
SymbolTableList< BasicBlock >::iterator eraseFromParent()
Unlink 'this' from the containing function and delete it.
void moveBefore(BasicBlock *MovePos)
Unlink this basic block from its current function and insert it into the function that MovePos lives ...
const Instruction & back() const
static BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name=Twine(), InsertPosition InsertBefore=nullptr)
Construct a binary instruction, given the opcode and the two operands.
Represents a module in a bitcode file.
Expected< std::unique_ptr< ModuleSummaryIndex > > getSummary()
Parse the specified bitcode buffer, returning the module summary index.
Expected< BitcodeLTOInfo > getLTOInfo()
Returns information about the module to be used for LTO: whether to compile with ThinLTO,...
Error readSummary(ModuleSummaryIndex &CombinedIndex, StringRef ModulePath, std::function< bool(GlobalValue::GUID)> IsPrevailing=nullptr)
Parse the specified bitcode buffer and merge its module summary index into CombinedIndex.
Expected< std::unique_ptr< Module > > parseModule(LLVMContext &Context, ParserCallbacks Callbacks={})
Read the entire bitcode module and return it.
Expected< std::unique_ptr< Module > > getLazyModule(LLVMContext &Context, bool ShouldLazyLoadMetadata, bool IsImporting, ParserCallbacks Callbacks={})
Read the bitcode module and prepare for lazy deserialization of function bodies.
Value * getValueFwdRef(unsigned Idx, Type *Ty, unsigned TyID, BasicBlock *ConstExprInsertBB)
void push_back(Value *V, unsigned TypeID)
void replaceValueWithoutRAUW(unsigned ValNo, Value *NewV)
Error assignValue(unsigned Idx, Value *V, unsigned TypeID)
void shrinkTo(unsigned N)
unsigned getTypeID(unsigned ValNo) const
This class maintains the abbreviations read from a block info block.
This represents a position within a bitcode file, implemented on top of a SimpleBitstreamCursor.
Error JumpToBit(uint64_t BitNo)
Reset the stream to the specified bit number.
uint64_t GetCurrentBitNo() const
Return the bit # of the bit we are reading.
ArrayRef< uint8_t > getBitcodeBytes() const
Expected< word_t > Read(unsigned NumBits)
Expected< BitstreamEntry > advance(unsigned Flags=0)
Advance the current bitstream, returning the next entry in the stream.
Expected< BitstreamEntry > advanceSkippingSubblocks(unsigned Flags=0)
This is a convenience function for clients that don't expect any subblocks.
void setBlockInfo(BitstreamBlockInfo *BI)
Set the block info to be used by this BitstreamCursor to interpret abbreviated records.
Expected< unsigned > readRecord(unsigned AbbrevID, SmallVectorImpl< uint64_t > &Vals, StringRef *Blob=nullptr)
Error EnterSubBlock(unsigned BlockID, unsigned *NumWordsP=nullptr)
Having read the ENTER_SUBBLOCK abbrevid, and enter the block.
Error SkipBlock()
Having read the ENTER_SUBBLOCK abbrevid and a BlockID, skip over the body of this block.
Expected< unsigned > skipRecord(unsigned AbbrevID)
Read the current record and discard it, returning the code for the record.
uint64_t getCurrentByteNo() const
bool canSkipToPos(size_t pos) const
static BlockAddress * get(Function *F, BasicBlock *BB)
Return a BlockAddress for the specified function and basic block.
Conditional or Unconditional Branch instruction.
static BranchInst * Create(BasicBlock *IfTrue, InsertPosition InsertBefore=nullptr)
Allocate memory in an ever growing pool, as if by bump-pointer.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
bool isInlineAsm() const
Check if this call is an inline asm statement.
Value * getCalledOperand() const
void setAttributes(AttributeList A)
Set the 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, InsertPosition InsertBefore=nullptr)
This class represents a function call, abstracting a target machine's calling convention.
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
static bool castIsValid(Instruction::CastOps op, Type *SrcTy, Type *DstTy)
This method can be used to determine if a cast from SrcTy to DstTy using Opcode op is valid or not.
static CatchPadInst * Create(Value *CatchSwitch, ArrayRef< Value * > Args, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static CatchReturnInst * Create(Value *CatchPad, BasicBlock *BB, InsertPosition InsertBefore=nullptr)
static CatchSwitchInst * Create(Value *ParentPad, BasicBlock *UnwindDest, unsigned NumHandlers, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static CleanupPadInst * Create(Value *ParentPad, ArrayRef< Value * > Args=std::nullopt, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static CleanupReturnInst * Create(Value *CleanupPad, BasicBlock *UnwindBB=nullptr, InsertPosition InsertBefore=nullptr)
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
static CmpInst * Create(OtherOps Op, Predicate Pred, Value *S1, Value *S2, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Construct a compare instruction, given the opcode, the predicate and the two operands.
bool isFPPredicate() const
bool isIntPredicate() const
@ Largest
The linker will choose the largest COMDAT.
@ SameSize
The data referenced by the COMDAT must be the same size.
@ Any
The linker may choose any COMDAT.
@ NoDeduplicate
No deduplication is performed.
@ ExactMatch
The data referenced by the COMDAT must be the same.
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
static Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true)
This method constructs a CDS and initializes it with a text string.
static Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
static Constant * getFP(Type *ElementType, ArrayRef< uint16_t > Elts)
getFP() constructors - Return a constant of array type with a float element type taken from argument ...
static Constant * get(LLVMContext &Context, ArrayRef< uint8_t > Elts)
get() constructors - Return a constant with vector type with an element count and element type matchi...
static Constant * getFP(Type *ElementType, ArrayRef< uint16_t > Elts)
getFP() constructors - Return a constant of vector type with a float element type taken from argument...
static Constant * getExtractElement(Constant *Vec, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
static Constant * getInsertElement(Constant *Vec, Constant *Elt, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
static Constant * getShuffleVector(Constant *V1, Constant *V2, ArrayRef< int > Mask, Type *OnlyIfReducedTy=nullptr)
static bool isSupportedGetElementPtr(const Type *SrcElemTy)
Whether creating a constant expression for this getelementptr type is supported.
static Constant * get(unsigned Opcode, Constant *C1, Constant *C2, unsigned Flags=0, Type *OnlyIfReducedTy=nullptr)
get - Return a binary or shift operator constant expression, folding if possible.
static bool isSupportedBinOp(unsigned Opcode)
Whether creating a constant expression for this binary operator is supported.
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList, GEPNoWrapFlags NW=GEPNoWrapFlags::none(), std::optional< ConstantRange > InRange=std::nullopt, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
static bool isSupportedCastOp(unsigned Opcode)
Whether creating a constant expression for this cast is supported.
This is the shared class of boolean and integer constants.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
static ConstantPtrAuth * get(Constant *Ptr, ConstantInt *Key, ConstantInt *Disc, Constant *AddrDisc)
Return a pointer signed with the specified parameters.
static bool isOrderedRanges(ArrayRef< ConstantRange > RangesRef)
This class represents a range of values.
bool isUpperSignWrapped() const
Return true if the (exclusive) upper bound wraps around the signed domain.
bool isFullSet() const
Return true if this set contains all of the elements possible for this data-type.
static Constant * get(StructType *T, ArrayRef< Constant * > V)
static Constant * get(ArrayRef< Constant * > V)
This is an important base class in LLVM.
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
static DSOLocalEquivalent * get(GlobalValue *GV)
Return a DSOLocalEquivalent for the specified global value.
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
static Expected< DataLayout > parse(StringRef 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
Represents flags for the getelementptr instruction/expression.
static GEPNoWrapFlags inBounds()
static GEPNoWrapFlags noUnsignedWrap()
static GEPNoWrapFlags noUnsignedSignedWrap()
virtual void setStripDebugInfo()=0
virtual Error materializeModule()=0
Make sure the entire Module has been completely read.
virtual Error materializeMetadata()=0
virtual Error materialize(GlobalValue *GV)=0
Make sure the given GlobalValue is fully read.
virtual std::vector< StructType * > getIdentifiedStructTypes() const =0
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static GlobalAlias * create(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name, Constant *Aliasee, Module *Parent)
If a parent module is specified, the alias is automatically inserted into the end of the specified mo...
static GlobalIFunc * create(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name, Constant *Resolver, Module *Parent)
If a parent module is specified, the ifunc is automatically inserted into the end of the specified mo...
void setAlignment(Align Align)
Sets the alignment attribute of the GlobalObject.
void setComdat(Comdat *C)
void setSection(StringRef S)
Change the section for this global.
Function and variable summary information to aid decisions and implementation of importing.
void setOriginalName(GlobalValue::GUID Name)
Initialize the original name hash in this summary.
static bool isLocalLinkage(LinkageTypes Linkage)
void setUnnamedAddr(UnnamedAddr Val)
bool hasLocalLinkage() const
bool hasDefaultVisibility() const
void setDLLStorageClass(DLLStorageClassTypes C)
void setThreadLocalMode(ThreadLocalMode Val)
bool hasExternalWeakLinkage() const
DLLStorageClassTypes
Storage classes of global values for PE targets.
@ DLLExportStorageClass
Function to be accessible from DLL.
@ DLLImportStorageClass
Function to be imported from DLL.
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
void setDSOLocal(bool Local)
PointerType * getType() const
Global values are always pointers.
VisibilityTypes
An enumeration for the kinds of visibility of global values.
@ DefaultVisibility
The GV is visible.
@ HiddenVisibility
The GV is hidden.
@ ProtectedVisibility
The GV is protected.
void setVisibility(VisibilityTypes V)
void setSanitizerMetadata(SanitizerMetadata Meta)
std::string getGlobalIdentifier() const
Return the modified name for this global value suitable to be used as the key for a global lookup (e....
LinkageTypes
An enumeration for the kinds of linkage for global values.
@ PrivateLinkage
Like Internal, but omit from symbol table.
@ CommonLinkage
Tentative definitions.
@ InternalLinkage
Rename collisions when linking (static functions).
@ LinkOnceAnyLinkage
Keep one copy of function when linking (inline)
@ WeakODRLinkage
Same, but only replaced by something equivalent.
@ ExternalLinkage
Externally visible function.
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
@ AppendingLinkage
Special purpose, only applies to global arrays.
@ AvailableExternallyLinkage
Available for inspection, not emission.
@ ExternalWeakLinkage
ExternalWeak linkage description.
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
void setPartition(StringRef Part)
void setAttributes(AttributeSet A)
Set attribute list for this global.
void setCodeModel(CodeModel::Model CM)
Change the code model for this global.
This instruction compares its operands according to the predicate given to the constructor.
Indirect Branch Instruction.
void addDestination(BasicBlock *Dest)
Add a destination.
static IndirectBrInst * Create(Value *Address, unsigned NumDests, InsertPosition InsertBefore=nullptr)
unsigned getNumDestinations() const
return the number of possible destinations in this indirectbr instruction.
static InlineAsm * get(FunctionType *Ty, StringRef AsmString, StringRef Constraints, bool hasSideEffects, bool isAlignStack=false, AsmDialect asmDialect=AD_ATT, bool canThrow=false)
InlineAsm::get - Return the specified uniqued inline asm string.
std::vector< ConstraintInfo > ConstraintInfoVector
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static InsertValueInst * Create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
const char * getOpcodeName() const
InstListType::iterator insertInto(BasicBlock *ParentBB, InstListType::iterator It)
Inserts an unlinked instruction into ParentBB at position It and returns the iterator of the inserted...
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
@ MIN_INT_BITS
Minimum number of bits that can be specified.
@ MAX_INT_BITS
Maximum number of bits that can be specified.
static InvokeInst * Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, const Twine &NameStr, InsertPosition InsertBefore=nullptr)
This is an important class for using LLVM in a threaded context.
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...
static LandingPadInst * Create(Type *RetTy, unsigned NumReservedClauses, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructors - NumReservedClauses is a hint for the number of incoming clauses that this landingpad w...
void addClause(Constant *ClauseVal)
Add a catch or filter clause to the landing pad.
void setCleanup(bool V)
Indicate that this landingpad instruction is a cleanup.
An instruction for reading from memory.
Tracking metadata reference owned by Metadata.
StringRef getString() const
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
ValueT lookup(const KeyT &Key) const
size_t getBufferSize() const
StringRef getBufferIdentifier() const
const char * getBufferStart() const
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFileOrSTDIN(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, std::optional< Align > Alignment=std::nullopt)
Open the specified file as a MemoryBuffer, or open stdin if the Filename is "-".
static MemoryEffectsBase readOnly()
Create MemoryEffectsBase that can read any memory.
static MemoryEffectsBase argMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
Create MemoryEffectsBase that can only access argument memory.
static MemoryEffectsBase inaccessibleMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
Create MemoryEffectsBase that can only access inaccessible memory.
static MemoryEffectsBase createFromIntValue(uint32_t Data)
Create MemoryEffectsBase from an encoded integer value (used by memory attribute).
static MemoryEffectsBase writeOnly()
Create MemoryEffectsBase that can write any memory.
static MemoryEffectsBase inaccessibleOrArgMemOnly(ModRefInfo MR=ModRefInfo::ModRef)
Create MemoryEffectsBase that can only access inaccessible or argument memory.
static MemoryEffectsBase none()
Create MemoryEffectsBase that cannot read or write any memory.
static MemoryEffectsBase unknown()
Create MemoryEffectsBase that can read and write any memory.
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="", InsertPosition InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
static ResumeInst * Create(Value *Exn, InsertPosition InsertBefore=nullptr)
static ReturnInst * Create(LLVMContext &C, Value *retVal=nullptr, InsertPosition InsertBefore=nullptr)
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", InsertPosition InsertBefore=nullptr, Instruction *MDFrom=nullptr)
This instruction constructs a fixed permutation of two input vectors.
ArrayRef< int > getShuffleMask() const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
StringRef str() const
Explicit conversion to StringRef.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
iterator erase(const_iterator CI)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Class to represent struct types.
static StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
void setBody(ArrayRef< Type * > Elements, bool isPacked=false)
Specify a body for an opaque identified type.
static StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
void setName(StringRef Name)
Change the name of this type to the specified name, or to a name with a suffix if there is a collisio...
static SwitchInst * Create(Value *Value, BasicBlock *Default, unsigned NumCases, InsertPosition InsertBefore=nullptr)
Verify that the TBAA Metadatas are valid.
bool visitTBAAMetadata(Instruction &I, const MDNode *MD)
Visit an instruction and return true if it is valid, return false if an invalid TBAA is attached.
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=Twine(), InsertPosition InsertBefore=nullptr)
Construct a unary instruction, given the opcode and an operand.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
This function has undefined behavior.
A Use represents the edge between a Value definition and its users.
This class represents the va_arg llvm instruction, which returns an argument of the specified type gi...
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
void setName(const Twine &Name)
Change the name of the value.
void deleteValue()
Delete a pointer to a generic Value.
static constexpr unsigned MaxAlignmentExponent
The maximum alignment for instructions.
Value & operator=(const Value &)=delete
std::pair< iterator, bool > insert(const ValueT &V)
bool contains(const_arg_type_t< ValueT > V) const
Check if the set contains the given element.
const ParentTy * getParent() const
self_iterator getIterator()
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char TypeName[]
Key for Kernel::Arg::Metadata::mTypeName.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
AttributeMask typeIncompatible(Type *Ty, 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_SANITIZE_NUMERICAL_STABILITY
@ 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.
unsigned getBranchWeightOffset(const MDNode *ProfileData)
Return the offset to the first branch weight data.
void UpgradeInlineAsmString(std::string *AsmStr)
Upgrade comment in call to inline asm that represents an objc retain release marker.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are 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