25 #include "llvm/Config/llvm-config.h" 83 #include <system_error> 93 "Print the global id for each value when reading the module summary"));
98 SWITCH_INST_MAGIC = 0x4B5
104 return make_error<StringError>(
111 "file too small to contain bitcode header");
112 for (
unsigned C : {
'B',
'C'})
116 "file doesn't start with bitcode header");
118 return Res.takeError();
119 for (
unsigned C : {0x0, 0xC, 0xE, 0xD})
123 "file doesn't start with bitcode header");
125 return Res.takeError();
130 const unsigned char *BufPtr = (
const unsigned char *)Buffer.
getBufferStart();
131 const unsigned char *BufEnd = BufPtr + Buffer.
getBufferSize();
134 return error(
"Invalid bitcode signature");
140 return error(
"Invalid bitcode wrapper header");
144 return std::move(Err);
146 return std::move(Stream);
150 template <
typename StrTy>
153 if (Idx > Record.
size())
156 for (
unsigned i = Idx,
e = Record.
size(); i !=
e; ++i)
157 Result += (
char)Record[i];
164 if (
F.isMaterializable())
167 I.setMetadata(LLVMContext::MD_tbaa,
nullptr);
175 return std::move(Err);
180 std::string ProducerIdentification;
187 return Res.takeError();
189 switch (Entry.
Kind) {
192 return error(
"Malformed block");
194 return ProducerIdentification;
205 switch (MaybeBitCode.
get()) {
207 return error(
"Invalid value");
212 unsigned epoch = (
unsigned)Record[0];
215 Twine(
"Incompatible epoch: Bitcode '") +
Twine(epoch) +
232 Entry = std::move(Res.get());
234 return Res.takeError();
236 switch (Entry.
Kind) {
239 return error(
"Malformed block");
247 return std::move(Err);
253 return Skipped.takeError();
260 return std::move(Err);
271 switch (Entry.
Kind) {
274 return error(
"Malformed block");
286 switch (MaybeRecord.
get()) {
292 return error(
"Invalid record");
294 if (S.find(
"__DATA,__objc_catlist") != std::string::npos ||
295 S.find(
"__OBJC,__category") != std::string::npos)
311 Entry = std::move(Res.get());
313 return Res.takeError();
315 switch (Entry.
Kind) {
317 return error(
"Malformed block");
327 return std::move(Err);
334 return Skipped.takeError();
341 return std::move(Err);
354 switch (Entry.
Kind) {
357 return error(
"Malformed block");
369 switch (MaybeRecord.
get()) {
374 return error(
"Invalid record");
393 switch (Entry.
Kind) {
395 return error(
"Malformed block");
405 return std::move(Err);
412 return Skipped.takeError();
419 class BitcodeReaderBase {
422 : Stream(std::move(Stream)), Strtab(Strtab) {
432 bool UseStrtab =
false;
439 std::pair<StringRef, ArrayRef<uint64_t>>
442 bool readBlockInfo();
445 std::string ProducerIdentification;
453 std::string FullMsg = Message.
str();
454 if (!ProducerIdentification.empty())
455 FullMsg +=
" (Producer: '" + ProducerIdentification +
"' Reader: 'LLVM " +
456 LLVM_VERSION_STRING
"')";
463 return error(
"Invalid record");
464 unsigned ModuleVersion = Record[0];
465 if (ModuleVersion > 2)
466 return error(
"Invalid value");
467 UseStrtab = ModuleVersion >= 2;
468 return ModuleVersion;
471 std::pair<StringRef, ArrayRef<uint64_t>>
476 if (Record[0] + Record[1] > Strtab.
size())
478 return {
StringRef(Strtab.data() + Record[0], Record[1]), Record.
slice(2)};
483 class BitcodeReader :
public BitcodeReaderBase,
public GVMaterializer {
485 Module *TheModule =
nullptr;
487 uint64_t NextUnreadBit = 0;
489 uint64_t LastFunctionBlockBit = 0;
490 bool SeenValueSymbolTable =
false;
491 uint64_t VSTOffset = 0;
493 std::vector<std::string> SectionTable;
494 std::vector<std::string> GCTable;
496 std::vector<Type*> TypeList;
500 std::vector<Comdat *> ComdatList;
503 std::vector<std::pair<GlobalVariable *, unsigned>> GlobalInits;
504 std::vector<std::pair<GlobalIndirectSymbol *, unsigned>> IndirectSymbolInits;
505 std::vector<std::pair<Function *, unsigned>> FunctionPrefixes;
506 std::vector<std::pair<Function *, unsigned>> FunctionPrologues;
507 std::vector<std::pair<Function *, unsigned>> FunctionPersonalityFns;
511 std::vector<AttributeList> MAttributes;
514 std::map<unsigned, AttributeList> MAttributeGroups;
518 std::vector<BasicBlock*> FunctionBBs;
522 std::vector<Function*> FunctionsWithBodies;
527 UpdatedIntrinsicMap UpgradedIntrinsics;
529 UpdatedIntrinsicMap RemangledIntrinsics;
534 bool SeenFirstFunctionBody =
false;
543 std::vector<uint64_t> DeferredMetadataInfo;
549 std::deque<Function *> BasicBlockFwdRefQueue;
557 bool UseRelativeIDs =
false;
561 bool WillMaterializeAllForwardRefs =
false;
566 std::vector<std::string> BundleTags;
573 Error materializeForwardReferencedFunctions();
576 Error materializeModule()
override;
577 std::vector<StructType *> getIdentifiedStructTypes()
const override;
581 Error parseBitcodeInto(
Module *M,
bool ShouldLazyLoadMetadata =
false,
582 bool IsImporting =
false);
584 static uint64_t decodeSignRotatedValue(uint64_t V);
587 Error materializeMetadata()
override;
589 void setStripDebugInfo()
override;
592 std::vector<StructType *> IdentifiedStructTypes;
600 Type *flattenPointerTypes(
Type *Ty) {
606 Type *getPointerElementFlatType(
Type *Ty) {
607 return flattenPointerTypes(cast<PointerType>(Ty)->getElementType());
613 std::pair<Type *, Type *> getPointerElementTypes(
Type *FullTy) {
614 Type *ElTy = cast<PointerType>(FullTy)->getElementType();
615 return std::make_pair(ElTy, flattenPointerTypes(ElTy));
620 Type *getTypeByID(
unsigned ID) {
621 return flattenPointerTypes(getFullyStructuredTypeByID(ID));
626 Type *getFullyStructuredTypeByID(
unsigned ID);
628 Value *getFnValueByID(
unsigned ID,
Type *Ty,
Type **FullTy =
nullptr) {
634 Metadata *getFnMetadataByID(
unsigned ID) {
638 BasicBlock *getBasicBlock(
unsigned ID)
const {
639 if (ID >= FunctionBBs.size())
return nullptr;
640 return FunctionBBs[
ID];
644 if (i-1 < MAttributes.size())
645 return MAttributes[i-1];
653 unsigned InstNum,
Value *&ResVal,
654 Type **FullTy =
nullptr) {
655 if (Slot == Record.
size())
return true;
656 unsigned ValNo = (
unsigned)Record[Slot++];
659 ValNo = InstNum - ValNo;
660 if (ValNo < InstNum) {
663 ResVal = getFnValueByID(ValNo,
nullptr, FullTy);
664 return ResVal ==
nullptr;
666 if (Slot == Record.
size())
669 unsigned TypeNo = (
unsigned)Record[Slot++];
670 ResVal = getFnValueByID(ValNo, getTypeByID(TypeNo));
672 *FullTy = getFullyStructuredTypeByID(TypeNo);
673 return ResVal ==
nullptr;
680 unsigned InstNum,
Type *Ty,
Value *&ResVal) {
681 if (getValue(Record, Slot, InstNum, Ty, ResVal))
690 unsigned InstNum,
Type *Ty,
Value *&ResVal) {
691 ResVal = getValue(Record, Slot, InstNum, Ty);
692 return ResVal ==
nullptr;
698 unsigned InstNum,
Type *Ty) {
699 if (Slot == Record.
size())
return nullptr;
700 unsigned ValNo = (
unsigned)Record[Slot];
703 ValNo = InstNum - ValNo;
704 return getFnValueByID(ValNo, Ty);
709 unsigned InstNum,
Type *Ty) {
710 if (Slot == Record.
size())
return nullptr;
711 unsigned ValNo = (
unsigned)decodeSignRotatedValue(Record[Slot]);
714 ValNo = InstNum - ValNo;
715 return getFnValueByID(ValNo, Ty);
732 Error parseGlobalIndirectSymbolRecord(
unsigned BitCode,
735 Error parseAttributeBlock();
736 Error parseAttributeGroupBlock();
737 Error parseTypeTable();
738 Error parseTypeTableBody();
739 Error parseOperandBundleTags();
740 Error parseSyncScopeNames();
744 void setDeferredFunctionInfo(
unsigned FuncBitcodeOffsetDelta,
Function *
F,
747 Error parseGlobalValueSymbolTable();
748 Error parseConstants();
749 Error rememberAndSkipFunctionBodies();
750 Error rememberAndSkipFunctionBody();
752 Error rememberAndSkipMetadata();
755 Error globalCleanup();
756 Error resolveGlobalAndIndirectSymbolInits();
757 Error parseUseLists();
758 Error findFunctionInStream(
767 class ModuleSummaryIndexBitcodeReader :
public BitcodeReaderBase {
773 bool SeenGlobalValSummary =
false;
776 bool SeenValueSymbolTable =
false;
780 uint64_t VSTOffset = 0;
791 ValueIdToValueInfoMap;
800 std::string SourceFileName;
813 StringRef ModulePath,
unsigned ModuleId);
821 Error parseValueSymbolTable(
826 bool IsOldProfileFormat,
829 Error parseEntireSummary(
unsigned ID);
830 Error parseModuleStringTable();
835 std::pair<ValueInfo, GlobalValue::GUID>
836 getValueInfoFromValueId(
unsigned ValueId);
838 void addThisModule();
854 return std::error_code();
860 : BitcodeReaderBase(std::move(Stream), Strtab),
Context(Context),
862 this->ProducerIdentification = ProducerIdentification;
865 Error BitcodeReader::materializeForwardReferencedFunctions() {
866 if (WillMaterializeAllForwardRefs)
870 WillMaterializeAllForwardRefs =
true;
872 while (!BasicBlockFwdRefQueue.empty()) {
873 Function *
F = BasicBlockFwdRefQueue.front();
874 BasicBlockFwdRefQueue.pop_front();
875 assert(F &&
"Expected valid function");
876 if (!BasicBlockFwdRefs.count(F))
885 return error(
"Never resolved function from blockaddress");
888 if (
Error Err = materialize(F))
891 assert(BasicBlockFwdRefs.empty() &&
"Function missing from queue");
894 WillMaterializeAllForwardRefs =
false;
959 Flags.
ReadOnly = (RawFlags >> 1) & 0x1;
962 Flags.
NoInline = (RawFlags >> 4) & 0x1;
974 RawFlags = RawFlags >> 4;
975 bool NotEligibleToImport = (RawFlags & 0x1) || Version < 3;
979 bool Live = (RawFlags & 0x2) || Version < 3;
980 bool Local = (RawFlags & 0x4);
981 bool AutoHide = (RawFlags & 0x8);
989 (RawFlags & 0x2) ?
true :
false);
1014 case 0:
return false;
1015 case 1:
return true;
1068 return IsFP ? Instruction::FNeg : -1;
1084 return IsFP ? Instruction::FSub : Instruction::Sub;
1086 return IsFP ? Instruction::FMul : Instruction::Mul;
1088 return IsFP ? -1 : Instruction::UDiv;
1090 return IsFP ? Instruction::FDiv : Instruction::SDiv;
1092 return IsFP ? -1 : Instruction::URem;
1094 return IsFP ? Instruction::FRem : Instruction::SRem;
1096 return IsFP ? -1 : Instruction::Shl;
1098 return IsFP ? -1 : Instruction::LShr;
1100 return IsFP ? -1 : Instruction::AShr;
1102 return IsFP ? -1 : Instruction::And;
1104 return IsFP ? -1 : Instruction::Or;
1106 return IsFP ? -1 : Instruction::Xor;
1186 Type *BitcodeReader::getFullyStructuredTypeByID(
unsigned ID) {
1188 if (ID >= TypeList.size())
1191 if (
Type *Ty = TypeList[ID])
1196 return TypeList[
ID] = createIdentifiedStructType(Context);
1202 IdentifiedStructTypes.push_back(
Ret);
1208 IdentifiedStructTypes.push_back(
Ret);
1222 case Attribute::ZExt:
return 1 << 0;
1223 case Attribute::SExt:
return 1 << 1;
1224 case Attribute::NoReturn:
return 1 << 2;
1225 case Attribute::InReg:
return 1 << 3;
1226 case Attribute::StructRet:
return 1 << 4;
1227 case Attribute::NoUnwind:
return 1 << 5;
1229 case Attribute::ByVal:
return 1 << 7;
1230 case Attribute::Nest:
return 1 << 8;
1231 case Attribute::ReadNone:
return 1 << 9;
1232 case Attribute::ReadOnly:
return 1 << 10;
1233 case Attribute::NoInline:
return 1 << 11;
1234 case Attribute::AlwaysInline:
return 1 << 12;
1235 case Attribute::OptimizeForSize:
return 1 << 13;
1236 case Attribute::StackProtect:
return 1 << 14;
1237 case Attribute::StackProtectReq:
return 1 << 15;
1238 case Attribute::Alignment:
return 31 << 16;
1239 case Attribute::NoCapture:
return 1 << 21;
1240 case Attribute::NoRedZone:
return 1 << 22;
1241 case Attribute::NoImplicitFloat:
return 1 << 23;
1242 case Attribute::Naked:
return 1 << 24;
1243 case Attribute::InlineHint:
return 1 << 25;
1244 case Attribute::StackAlignment:
return 7 << 26;
1245 case Attribute::ReturnsTwice:
return 1 << 29;
1246 case Attribute::UWTable:
return 1 << 30;
1247 case Attribute::NonLazyBind:
return 1U << 31;
1248 case Attribute::SanitizeAddress:
return 1ULL << 32;
1249 case Attribute::MinSize:
return 1ULL << 33;
1250 case Attribute::NoDuplicate:
return 1ULL << 34;
1251 case Attribute::StackProtectStrong:
return 1ULL << 35;
1252 case Attribute::SanitizeThread:
return 1ULL << 36;
1253 case Attribute::SanitizeMemory:
return 1ULL << 37;
1254 case Attribute::NoBuiltin:
return 1ULL << 38;
1255 case Attribute::Returned:
return 1ULL << 39;
1257 case Attribute::Builtin:
return 1ULL << 41;
1258 case Attribute::OptimizeNone:
return 1ULL << 42;
1259 case Attribute::InAlloca:
return 1ULL << 43;
1260 case Attribute::NonNull:
return 1ULL << 44;
1263 case Attribute::SafeStack:
return 1ULL << 47;
1264 case Attribute::NoRecurse:
return 1ULL << 48;
1265 case Attribute::InaccessibleMemOnly:
return 1ULL << 49;
1266 case Attribute::InaccessibleMemOrArgMemOnly:
return 1ULL << 50;
1267 case Attribute::SwiftSelf:
return 1ULL << 51;
1268 case Attribute::SwiftError:
return 1ULL << 52;
1269 case Attribute::WriteOnly:
return 1ULL << 53;
1270 case Attribute::Speculatable:
return 1ULL << 54;
1271 case Attribute::StrictFP:
return 1ULL << 55;
1272 case Attribute::SanitizeHWAddress:
return 1ULL << 56;
1273 case Attribute::NoCfCheck:
return 1ULL << 57;
1274 case Attribute::OptForFuzzing:
return 1ULL << 58;
1275 case Attribute::ShadowCallStack:
return 1ULL << 59;
1276 case Attribute::SpeculativeLoadHardening:
1278 case Attribute::ImmArg:
1280 case Attribute::WillReturn:
1282 case Attribute::NoFree:
1284 case Attribute::NoSync:
1287 case Attribute::Dereferenceable:
1290 case Attribute::DereferenceableOrNull:
1294 case Attribute::ArgMemOnly:
1297 case Attribute::AllocSize:
1300 case Attribute::SanitizeMemTag:
1312 if (
I == Attribute::SanitizeMemTag ||
1313 I == Attribute::Dereferenceable ||
1314 I == Attribute::DereferenceableOrNull ||
1315 I == Attribute::ArgMemOnly ||
1316 I == Attribute::AllocSize ||
1317 I == Attribute::NoSync)
1320 if (
I == Attribute::Alignment)
1322 else if (
I == Attribute::StackAlignment)
1334 uint64_t EncodedAttrs) {
1339 unsigned Alignment = (EncodedAttrs & (0xffffULL << 16)) >> 16;
1341 "Alignment must be a power of two.");
1346 (EncodedAttrs & 0xffff));
1349 Error BitcodeReader::parseAttributeBlock() {
1353 if (!MAttributes.empty())
1354 return error(
"Invalid multiple blocks");
1367 switch (Entry.
Kind) {
1370 return error(
"Malformed block");
1383 switch (MaybeRecord.
get()) {
1388 if (Record.
size() & 1)
1389 return error(
"Invalid record");
1391 for (
unsigned i = 0,
e = Record.
size(); i !=
e; i += 2) {
1401 for (
unsigned i = 0,
e = Record.
size(); i !=
e; ++i)
1402 Attrs.
push_back(MAttributeGroups[Record[i]]);
1417 return Attribute::Alignment;
1419 return Attribute::AlwaysInline;
1421 return Attribute::ArgMemOnly;
1423 return Attribute::Builtin;
1425 return Attribute::ByVal;
1427 return Attribute::InAlloca;
1433 return Attribute::InaccessibleMemOnly;
1435 return Attribute::InaccessibleMemOrArgMemOnly;
1437 return Attribute::InlineHint;
1439 return Attribute::InReg;
1443 return Attribute::MinSize;
1445 return Attribute::Naked;
1447 return Attribute::Nest;
1451 return Attribute::NoBuiltin;
1453 return Attribute::NoCapture;
1455 return Attribute::NoDuplicate;
1457 return Attribute::NoFree;
1459 return Attribute::NoImplicitFloat;
1461 return Attribute::NoInline;
1463 return Attribute::NoRecurse;
1465 return Attribute::NonLazyBind;
1467 return Attribute::NonNull;
1469 return Attribute::Dereferenceable;
1471 return Attribute::DereferenceableOrNull;
1473 return Attribute::AllocSize;
1475 return Attribute::NoRedZone;
1477 return Attribute::NoReturn;
1479 return Attribute::NoSync;
1481 return Attribute::NoCfCheck;
1483 return Attribute::NoUnwind;
1485 return Attribute::OptForFuzzing;
1487 return Attribute::OptimizeForSize;
1489 return Attribute::OptimizeNone;
1491 return Attribute::ReadNone;
1493 return Attribute::ReadOnly;
1495 return Attribute::Returned;
1497 return Attribute::ReturnsTwice;
1499 return Attribute::SExt;
1501 return Attribute::Speculatable;
1503 return Attribute::StackAlignment;
1505 return Attribute::StackProtect;
1507 return Attribute::StackProtectReq;
1509 return Attribute::StackProtectStrong;
1511 return Attribute::SafeStack;
1513 return Attribute::ShadowCallStack;
1515 return Attribute::StrictFP;
1517 return Attribute::StructRet;
1519 return Attribute::SanitizeAddress;
1521 return Attribute::SanitizeHWAddress;
1523 return Attribute::SanitizeThread;
1525 return Attribute::SanitizeMemory;
1527 return Attribute::SpeculativeLoadHardening;
1529 return Attribute::SwiftError;
1531 return Attribute::SwiftSelf;
1533 return Attribute::UWTable;
1535 return Attribute::WillReturn;
1537 return Attribute::WriteOnly;
1539 return Attribute::ZExt;
1541 return Attribute::ImmArg;
1543 return Attribute::SanitizeMemTag;
1552 return error(
"Invalid alignment value");
1560 return error(
"Unknown attribute kind (" +
Twine(Code) +
")");
1564 Error BitcodeReader::parseAttributeGroupBlock() {
1568 if (!MAttributeGroups.empty())
1569 return error(
"Invalid multiple blocks");
1580 switch (Entry.
Kind) {
1583 return error(
"Malformed block");
1596 switch (MaybeRecord.
get()) {
1600 if (Record.
size() < 3)
1601 return error(
"Invalid record");
1603 uint64_t GrpID = Record[0];
1604 uint64_t Idx = Record[1];
1607 for (
unsigned i = 2,
e = Record.
size(); i !=
e; ++i) {
1608 if (Record[i] == 0) {
1616 if (Kind == Attribute::ByVal)
1620 }
else if (Record[i] == 1) {
1624 if (Kind == Attribute::Alignment)
1626 else if (Kind == Attribute::StackAlignment)
1628 else if (Kind == Attribute::Dereferenceable)
1630 else if (Kind == Attribute::DereferenceableOrNull)
1632 else if (Kind == Attribute::AllocSize)
1634 }
else if (Record[i] == 3 || Record[i] == 4) {
1635 bool HasValue = (Record[i++] == 4);
1639 while (Record[i] != 0 && i !=
e)
1640 KindStr += Record[i++];
1641 assert(Record[i] == 0 &&
"Kind string not null terminated");
1646 while (Record[i] != 0 && i !=
e)
1647 ValStr += Record[i++];
1648 assert(Record[i] == 0 &&
"Value string not null terminated");
1653 assert((Record[i] == 5 || Record[i] == 6) &&
1654 "Invalid attribute group entry");
1655 bool HasType = Record[i] == 6;
1659 if (Kind == Attribute::ByVal)
1660 B.
addByValAttr(HasType ? getTypeByID(Record[++i]) :
nullptr);
1672 Error BitcodeReader::parseTypeTable() {
1676 return parseTypeTableBody();
1679 Error BitcodeReader::parseTypeTableBody() {
1680 if (!TypeList.empty())
1681 return error(
"Invalid multiple blocks");
1684 unsigned NumRecords = 0;
1695 switch (Entry.
Kind) {
1698 return error(
"Malformed block");
1700 if (NumRecords != TypeList.size())
1701 return error(
"Malformed block");
1710 Type *ResultTy =
nullptr;
1714 switch (MaybeRecord.
get()) {
1716 return error(
"Invalid value");
1720 if (Record.
size() < 1)
1721 return error(
"Invalid record");
1722 TypeList.resize(Record[0]);
1758 if (Record.
size() < 1)
1759 return error(
"Invalid record");
1761 uint64_t NumBits = Record[0];
1764 return error(
"Bitwidth for integer type out of range");
1770 if (Record.
size() < 1)
1771 return error(
"Invalid record");
1773 if (Record.
size() == 2)
1774 AddressSpace = Record[1];
1775 ResultTy = getTypeByID(Record[0]);
1778 return error(
"Invalid type");
1785 if (Record.
size() < 3)
1786 return error(
"Invalid record");
1788 for (
unsigned i = 3,
e = Record.
size(); i !=
e; ++i) {
1789 if (
Type *
T = getTypeByID(Record[i]))
1795 ResultTy = getTypeByID(Record[2]);
1796 if (!ResultTy || ArgTys.
size() < Record.
size()-3)
1797 return error(
"Invalid type");
1804 if (Record.
size() < 2)
1805 return error(
"Invalid record");
1807 for (
unsigned i = 2,
e = Record.
size(); i !=
e; ++i) {
1808 if (
Type *
T = getTypeByID(Record[i])) {
1810 return error(
"Invalid function argument type");
1817 ResultTy = getTypeByID(Record[1]);
1818 if (!ResultTy || ArgTys.
size() < Record.
size()-2)
1819 return error(
"Invalid type");
1825 if (Record.
size() < 1)
1826 return error(
"Invalid record");
1828 for (
unsigned i = 1,
e = Record.
size(); i !=
e; ++i) {
1829 if (
Type *
T = getTypeByID(Record[i]))
1834 if (EltTys.
size() != Record.
size()-1)
1835 return error(
"Invalid type");
1841 return error(
"Invalid record");
1845 if (Record.
size() < 1)
1846 return error(
"Invalid record");
1848 if (NumRecords >= TypeList.size())
1849 return error(
"Invalid TYPE table");
1852 StructType *Res = cast_or_null<StructType>(TypeList[NumRecords]);
1855 TypeList[NumRecords] =
nullptr;
1857 Res = createIdentifiedStructType(Context, TypeName);
1861 for (
unsigned i = 1,
e = Record.
size(); i !=
e; ++i) {
1862 if (
Type *
T = getTypeByID(Record[i]))
1867 if (EltTys.
size() != Record.
size()-1)
1868 return error(
"Invalid record");
1869 Res->
setBody(EltTys, Record[0]);
1874 if (Record.
size() != 1)
1875 return error(
"Invalid record");
1877 if (NumRecords >= TypeList.size())
1878 return error(
"Invalid TYPE table");
1881 StructType *Res = cast_or_null<StructType>(TypeList[NumRecords]);
1884 TypeList[NumRecords] =
nullptr;
1886 Res = createIdentifiedStructType(Context, TypeName);
1892 if (Record.
size() < 2)
1893 return error(
"Invalid record");
1894 ResultTy = getTypeByID(Record[1]);
1896 return error(
"Invalid type");
1901 if (Record.
size() < 2)
1902 return error(
"Invalid record");
1904 return error(
"Invalid vector length");
1905 ResultTy = getTypeByID(Record[1]);
1907 return error(
"Invalid type");
1908 bool Scalable = Record.
size() > 2 ? Record[2] :
false;
1913 if (NumRecords >= TypeList.size())
1914 return error(
"Invalid TYPE table");
1915 if (TypeList[NumRecords])
1917 "Invalid TYPE table: Only named structs can be forward referenced");
1918 assert(ResultTy &&
"Didn't read a type?");
1919 TypeList[NumRecords++] = ResultTy;
1923 Error BitcodeReader::parseOperandBundleTags() {
1927 if (!BundleTags.empty())
1928 return error(
"Invalid multiple blocks");
1938 switch (Entry.
Kind) {
1941 return error(
"Malformed block");
1955 return error(
"Invalid record");
1958 BundleTags.emplace_back();
1960 return error(
"Invalid record");
1965 Error BitcodeReader::parseSyncScopeNames() {
1970 return error(
"Invalid multiple synchronization scope names blocks");
1979 switch (Entry.
Kind) {
1982 return error(
"Malformed block");
1985 return error(
"Invalid empty synchronization scope names block");
1999 return error(
"Invalid record");
2003 return error(
"Invalid record");
2015 return error(
"Invalid record");
2016 unsigned ValueID = Record[0];
2017 if (ValueID >= ValueList.size() || !ValueList[ValueID])
2018 return error(
"Invalid record");
2019 Value *V = ValueList[ValueID];
2023 return error(
"Invalid value name");
2027 if (GO->getComdat() ==
reinterpret_cast<Comdat *
>(1)) {
2031 GO->setComdat(
nullptr);
2045 return std::move(JumpFailed);
2054 void BitcodeReader::setDeferredFunctionInfo(
unsigned FuncBitcodeOffsetDelta,
2060 uint64_t FuncWordOffset = Record[1] - 1;
2061 uint64_t FuncBitOffset = FuncWordOffset * 32;
2062 DeferredFunctionInfo[
F] = FuncBitOffset + FuncBitcodeOffsetDelta;
2066 if (FuncBitOffset > LastFunctionBlockBit)
2067 LastFunctionBlockBit = FuncBitOffset;
2071 Error BitcodeReader::parseGlobalValueSymbolTable() {
2072 unsigned FuncBitcodeOffsetDelta =
2085 switch (Entry.
Kind) {
2088 return error(
"Malformed block");
2099 switch (MaybeRecord.
get()) {
2101 setDeferredFunctionInfo(FuncBitcodeOffsetDelta,
2102 cast<Function>(ValueList[Record[0]]), Record);
2110 Error BitcodeReader::parseValueSymbolTable(uint64_t
Offset) {
2111 uint64_t CurrentBit;
2117 if (!MaybeCurrentBit)
2119 CurrentBit = MaybeCurrentBit.
get();
2122 if (
Error Err = parseGlobalValueSymbolTable())
2143 unsigned FuncBitcodeOffsetDelta =
2151 Triple TT(TheModule->getTargetTriple());
2162 switch (Entry.
Kind) {
2165 return error(
"Malformed block");
2181 switch (MaybeRecord.
get()) {
2200 if (
auto *F = dyn_cast<Function>(V))
2201 setDeferredFunctionInfo(FuncBitcodeOffsetDelta, F, Record);
2206 return error(
"Invalid record");
2209 return error(
"Invalid record");
2221 uint64_t BitcodeReader::decodeSignRotatedValue(uint64_t V) {
2231 Error BitcodeReader::resolveGlobalAndIndirectSymbolInits() {
2232 std::vector<std::pair<GlobalVariable *, unsigned>> GlobalInitWorklist;
2233 std::vector<std::pair<GlobalIndirectSymbol *, unsigned>>
2234 IndirectSymbolInitWorklist;
2235 std::vector<std::pair<Function *, unsigned>> FunctionPrefixWorklist;
2236 std::vector<std::pair<Function *, unsigned>> FunctionPrologueWorklist;
2237 std::vector<std::pair<Function *, unsigned>> FunctionPersonalityFnWorklist;
2239 GlobalInitWorklist.swap(GlobalInits);
2240 IndirectSymbolInitWorklist.swap(IndirectSymbolInits);
2241 FunctionPrefixWorklist.swap(FunctionPrefixes);
2242 FunctionPrologueWorklist.swap(FunctionPrologues);
2243 FunctionPersonalityFnWorklist.swap(FunctionPersonalityFns);
2245 while (!GlobalInitWorklist.empty()) {
2246 unsigned ValID = GlobalInitWorklist.back().second;
2247 if (ValID >= ValueList.size()) {
2249 GlobalInits.push_back(GlobalInitWorklist.back());
2251 if (
Constant *
C = dyn_cast_or_null<Constant>(ValueList[ValID]))
2252 GlobalInitWorklist.back().first->setInitializer(
C);
2254 return error(
"Expected a constant");
2256 GlobalInitWorklist.pop_back();
2259 while (!IndirectSymbolInitWorklist.empty()) {
2260 unsigned ValID = IndirectSymbolInitWorklist.back().second;
2261 if (ValID >= ValueList.size()) {
2262 IndirectSymbolInits.push_back(IndirectSymbolInitWorklist.back());
2264 Constant *
C = dyn_cast_or_null<Constant>(ValueList[ValID]);
2266 return error(
"Expected a constant");
2269 return error(
"Alias and aliasee types don't match");
2272 IndirectSymbolInitWorklist.pop_back();
2275 while (!FunctionPrefixWorklist.empty()) {
2276 unsigned ValID = FunctionPrefixWorklist.back().second;
2277 if (ValID >= ValueList.size()) {
2278 FunctionPrefixes.push_back(FunctionPrefixWorklist.back());
2280 if (
Constant *
C = dyn_cast_or_null<Constant>(ValueList[ValID]))
2281 FunctionPrefixWorklist.back().first->setPrefixData(
C);
2283 return error(
"Expected a constant");
2285 FunctionPrefixWorklist.pop_back();
2288 while (!FunctionPrologueWorklist.empty()) {
2289 unsigned ValID = FunctionPrologueWorklist.back().second;
2290 if (ValID >= ValueList.size()) {
2291 FunctionPrologues.push_back(FunctionPrologueWorklist.back());
2293 if (
Constant *
C = dyn_cast_or_null<Constant>(ValueList[ValID]))
2294 FunctionPrologueWorklist.back().first->setPrologueData(
C);
2296 return error(
"Expected a constant");
2298 FunctionPrologueWorklist.pop_back();
2301 while (!FunctionPersonalityFnWorklist.empty()) {
2302 unsigned ValID = FunctionPersonalityFnWorklist.back().second;
2303 if (ValID >= ValueList.size()) {
2304 FunctionPersonalityFns.push_back(FunctionPersonalityFnWorklist.back());
2306 if (
Constant *
C = dyn_cast_or_null<Constant>(ValueList[ValID]))
2307 FunctionPersonalityFnWorklist.back().first->setPersonalityFn(
C);
2309 return error(
"Expected a constant");
2311 FunctionPersonalityFnWorklist.pop_back();
2320 BitcodeReader::decodeSignRotatedValue);
2322 return APInt(TypeBits, Words);
2325 Error BitcodeReader::parseConstants() {
2334 unsigned NextCstNo = ValueList.size();
2342 switch (Entry.
Kind) {
2345 return error(
"Malformed block");
2347 if (NextCstNo != ValueList.size())
2348 return error(
"Invalid constant reference");
2352 ValueList.resolveConstantForwardRefs();
2366 switch (
unsigned BitCode = MaybeBitCode.
get()) {
2373 return error(
"Invalid record");
2374 if (Record[0] >= TypeList.
size() || !TypeList[Record[0]])
2375 return error(
"Invalid record");
2376 if (TypeList[Record[0]] == VoidType)
2377 return error(
"Invalid constant type");
2378 CurFullTy = TypeList[Record[0]];
2379 CurTy = flattenPointerTypes(CurFullTy);
2383 return error(
"Invalid type for a constant null value");
2388 return error(
"Invalid record");
2393 return error(
"Invalid record");
2403 return error(
"Invalid record");
2412 APInt(64, Record[0])));
2415 uint64_t Rearrange[2];
2416 Rearrange[0] = (Record[1] & 0xffffLL) | (Record[0] << 16);
2417 Rearrange[1] = Record[0] >> 48;
2419 APInt(80, Rearrange)));
2422 APInt(128, Record)));
2425 APInt(128, Record)));
2433 return error(
"Invalid record");
2435 unsigned Size = Record.size();
2438 if (
StructType *STy = dyn_cast<StructType>(CurTy)) {
2439 for (
unsigned i = 0; i !=
Size; ++i)
2440 Elts.
push_back(ValueList.getConstantFwdRef(Record[i],
2441 STy->getElementType(i)));
2443 }
else if (
ArrayType *ATy = dyn_cast<ArrayType>(CurTy)) {
2444 Type *EltTy = ATy->getElementType();
2445 for (
unsigned i = 0; i !=
Size; ++i)
2446 Elts.
push_back(ValueList.getConstantFwdRef(Record[i], EltTy));
2448 }
else if (
VectorType *VTy = dyn_cast<VectorType>(CurTy)) {
2449 Type *EltTy = VTy->getElementType();
2450 for (
unsigned i = 0; i !=
Size; ++i)
2451 Elts.
push_back(ValueList.getConstantFwdRef(Record[i], EltTy));
2461 return error(
"Invalid record");
2470 return error(
"Invalid record");
2472 Type *EltTy = cast<SequentialType>(CurTy)->getElementType();
2475 if (isa<VectorType>(CurTy))
2481 if (isa<VectorType>(CurTy))
2487 if (isa<VectorType>(CurTy))
2493 if (isa<VectorType>(CurTy))
2499 if (isa<VectorType>(CurTy))
2505 if (isa<VectorType>(CurTy))
2511 if (isa<VectorType>(CurTy))
2516 return error(
"Invalid type for value");
2521 if (Record.size() < 2)
2522 return error(
"Invalid record");
2527 Constant *LHS = ValueList.getConstantFwdRef(Record[1], CurTy);
2534 if (Record.size() < 3)
2535 return error(
"Invalid record");
2540 Constant *LHS = ValueList.getConstantFwdRef(Record[1], CurTy);
2541 Constant *RHS = ValueList.getConstantFwdRef(Record[2], CurTy);
2543 if (Record.size() >= 4) {
2545 Opc == Instruction::Sub ||
2546 Opc == Instruction::Mul ||
2547 Opc == Instruction::Shl) {
2552 }
else if (Opc == Instruction::SDiv ||
2553 Opc == Instruction::UDiv ||
2554 Opc == Instruction::LShr ||
2555 Opc == Instruction::AShr) {
2565 if (Record.size() < 3)
2566 return error(
"Invalid record");
2571 Type *OpTy = getTypeByID(Record[1]);
2573 return error(
"Invalid record");
2574 Constant *
Op = ValueList.getConstantFwdRef(Record[2], OpTy);
2585 Type *PointeeType =
nullptr;
2588 PointeeType = getTypeByID(Record[OpNum++]);
2590 bool InBounds =
false;
2593 uint64_t
Op = Record[OpNum++];
2595 InRangeIndex = Op >> 1;
2600 Type *Elt0FullTy =
nullptr;
2601 while (OpNum != Record.size()) {
2603 Elt0FullTy = getFullyStructuredTypeByID(Record[OpNum]);
2604 Type *ElTy = getTypeByID(Record[OpNum++]);
2606 return error(
"Invalid record");
2607 Elts.
push_back(ValueList.getConstantFwdRef(Record[OpNum++], ElTy));
2610 if (Elts.
size() < 1)
2611 return error(
"Invalid gep with no operands");
2613 Type *ImplicitPointeeType =
2616 PointeeType = ImplicitPointeeType;
2617 else if (PointeeType != ImplicitPointeeType)
2618 return error(
"Explicit gep operator type does not match pointee type " 2619 "of pointer operand");
2623 InBounds, InRangeIndex);
2627 if (Record.size() < 3)
2628 return error(
"Invalid record");
2634 if (
VectorType *VTy = dyn_cast<VectorType>(CurTy))
2635 if (
Value *V = ValueList[Record[0]])
2636 if (SelectorTy != V->
getType())
2641 ValueList.getConstantFwdRef(Record[1],CurTy),
2642 ValueList.getConstantFwdRef(Record[2],CurTy));
2647 if (Record.size() < 3)
2648 return error(
"Invalid record");
2650 dyn_cast_or_null<VectorType>(getTypeByID(Record[0]));
2652 return error(
"Invalid record");
2653 Constant *Op0 = ValueList.getConstantFwdRef(Record[1], OpTy);
2655 if (Record.size() == 4) {
2656 Type *IdxTy = getTypeByID(Record[2]);
2658 return error(
"Invalid record");
2659 Op1 = ValueList.getConstantFwdRef(Record[3], IdxTy);
2663 return error(
"Invalid record");
2670 if (Record.size() < 3 || !OpTy)
2671 return error(
"Invalid record");
2672 Constant *Op0 = ValueList.getConstantFwdRef(Record[0], OpTy);
2673 Constant *Op1 = ValueList.getConstantFwdRef(Record[1],
2676 if (Record.size() == 4) {
2677 Type *IdxTy = getTypeByID(Record[2]);
2679 return error(
"Invalid record");
2680 Op2 = ValueList.getConstantFwdRef(Record[3], IdxTy);
2684 return error(
"Invalid record");
2690 if (Record.size() < 3 || !OpTy)
2691 return error(
"Invalid record");
2692 Constant *Op0 = ValueList.getConstantFwdRef(Record[0], OpTy);
2693 Constant *Op1 = ValueList.getConstantFwdRef(Record[1], OpTy);
2696 Constant *Op2 = ValueList.getConstantFwdRef(Record[2], ShufTy);
2703 dyn_cast_or_null<VectorType>(getTypeByID(Record[0]));
2704 if (Record.size() < 4 || !RTy || !OpTy)
2705 return error(
"Invalid record");
2706 Constant *Op0 = ValueList.getConstantFwdRef(Record[1], OpTy);
2707 Constant *Op1 = ValueList.getConstantFwdRef(Record[2], OpTy);
2710 Constant *Op2 = ValueList.getConstantFwdRef(Record[3], ShufTy);
2715 if (Record.size() < 4)
2716 return error(
"Invalid record");
2717 Type *OpTy = getTypeByID(Record[0]);
2719 return error(
"Invalid record");
2720 Constant *Op0 = ValueList.getConstantFwdRef(Record[1], OpTy);
2721 Constant *Op1 = ValueList.getConstantFwdRef(Record[2], OpTy);
2732 if (Record.size() < 2)
2733 return error(
"Invalid record");
2734 std::string AsmStr, ConstrStr;
2735 bool HasSideEffects = Record[0] & 1;
2736 bool IsAlignStack = Record[0] >> 1;
2737 unsigned AsmStrSize = Record[1];
2738 if (2+AsmStrSize >= Record.size())
2739 return error(
"Invalid record");
2740 unsigned ConstStrSize = Record[2+AsmStrSize];
2741 if (3+AsmStrSize+ConstStrSize > Record.size())
2742 return error(
"Invalid record");
2744 for (
unsigned i = 0; i != AsmStrSize; ++i)
2745 AsmStr += (
char)Record[2+i];
2746 for (
unsigned i = 0; i != ConstStrSize; ++i)
2747 ConstrStr += (
char)Record[3+AsmStrSize+i];
2750 cast<FunctionType>(getPointerElementFlatType(CurFullTy)), AsmStr,
2751 ConstrStr, HasSideEffects, IsAlignStack);
2757 if (Record.size() < 2)
2758 return error(
"Invalid record");
2759 std::string AsmStr, ConstrStr;
2760 bool HasSideEffects = Record[0] & 1;
2761 bool IsAlignStack = (Record[0] >> 1) & 1;
2762 unsigned AsmDialect = Record[0] >> 2;
2763 unsigned AsmStrSize = Record[1];
2764 if (2+AsmStrSize >= Record.size())
2765 return error(
"Invalid record");
2766 unsigned ConstStrSize = Record[2+AsmStrSize];
2767 if (3+AsmStrSize+ConstStrSize > Record.size())
2768 return error(
"Invalid record");
2770 for (
unsigned i = 0; i != AsmStrSize; ++i)
2771 AsmStr += (
char)Record[2+i];
2772 for (
unsigned i = 0; i != ConstStrSize; ++i)
2773 ConstrStr += (
char)Record[3+AsmStrSize+i];
2776 cast<FunctionType>(getPointerElementFlatType(CurFullTy)), AsmStr,
2777 ConstrStr, HasSideEffects, IsAlignStack,
2782 if (Record.size() < 3)
2783 return error(
"Invalid record");
2784 Type *FnTy = getTypeByID(Record[0]);
2786 return error(
"Invalid record");
2788 dyn_cast_or_null<Function>(ValueList.getConstantFwdRef(Record[1],FnTy));
2790 return error(
"Invalid record");
2795 unsigned BBID = Record[2];
2798 return error(
"Invalid ID");
2801 for (
size_t I = 0,
E = BBID;
I !=
E; ++
I) {
2803 return error(
"Invalid ID");
2810 auto &FwdBBs = BasicBlockFwdRefs[Fn];
2812 BasicBlockFwdRefQueue.push_back(Fn);
2813 if (FwdBBs.size() < BBID + 1)
2814 FwdBBs.resize(BBID + 1);
2825 "Incorrect fully structured type provided for Constant");
2826 ValueList.assignValue(V, NextCstNo, CurFullTy);
2831 Error BitcodeReader::parseUseLists() {
2844 switch (Entry.
Kind) {
2847 return error(
"Malformed block");
2861 switch (MaybeRecord.
get()) {
2868 unsigned RecordLength = Record.
size();
2869 if (RecordLength < 3)
2871 return error(
"Invalid record");
2872 unsigned ID = Record.
back();
2877 assert(ID < FunctionBBs.size() &&
"Basic block not found");
2878 V = FunctionBBs[
ID];
2881 unsigned NumUses = 0;
2884 if (++NumUses > Record.
size())
2886 Order[&U] = Record[NumUses - 1];
2888 if (Order.
size() != Record.
size() || NumUses > Record.
size())
2904 Error BitcodeReader::rememberAndSkipMetadata() {
2907 DeferredMetadataInfo.push_back(CurBit);
2915 Error BitcodeReader::materializeMetadata() {
2916 for (uint64_t BitPos : DeferredMetadataInfo) {
2920 if (
Error Err = MDLoader->parseModuleMetadata())
2926 if (
Metadata *Val = TheModule->getModuleFlag(
"Linker Options")) {
2928 TheModule->getOrInsertNamedMetadata(
"llvm.linker.options");
2929 for (
const MDOperand &MDOptions : cast<MDNode>(Val)->operands())
2930 LinkerOpts->
addOperand(cast<MDNode>(MDOptions));
2933 DeferredMetadataInfo.clear();
2937 void BitcodeReader::setStripDebugInfo() {
StripDebugInfo =
true; }
2941 Error BitcodeReader::rememberAndSkipFunctionBody() {
2943 if (FunctionsWithBodies.empty())
2944 return error(
"Insufficient function protos");
2947 FunctionsWithBodies.pop_back();
2952 (DeferredFunctionInfo[Fn] == 0 || DeferredFunctionInfo[Fn] == CurBit) &&
2953 "Mismatch between VST and scanned function offsets");
2954 DeferredFunctionInfo[Fn] = CurBit;
2962 Error BitcodeReader::globalCleanup() {
2964 if (
Error Err = resolveGlobalAndIndirectSymbolInits())
2966 if (!GlobalInits.empty() || !IndirectSymbolInits.empty())
2967 return error(
"Malformed global initializer set");
2971 MDLoader->upgradeDebugIntrinsics(F);
2974 UpgradedIntrinsics[&
F] = NewFn;
2979 RemangledIntrinsics[&
F] = Remangled.getValue();
2983 std::vector<std::pair<GlobalVariable *, GlobalVariable *>> UpgradedVariables;
2986 UpgradedVariables.emplace_back(&GV, Upgraded);
2987 for (
auto &Pair : UpgradedVariables) {
2989 TheModule->getGlobalList().push_back(Pair.second);
2994 std::vector<std::pair<GlobalVariable *, unsigned>>().
swap(GlobalInits);
2995 std::vector<std::pair<GlobalIndirectSymbol *, unsigned>>().
swap(
2996 IndirectSymbolInits);
3004 Error BitcodeReader::rememberAndSkipFunctionBodies() {
3009 return error(
"Could not find function in stream");
3011 if (!SeenFirstFunctionBody)
3012 return error(
"Trying to materialize functions before seeing function blocks");
3016 assert(SeenValueSymbolTable);
3026 switch (Entry.
Kind) {
3028 return error(
"Expect SubBlock");
3032 return error(
"Expect function block");
3034 if (
Error Err = rememberAndSkipFunctionBody())
3043 bool BitcodeReaderBase::readBlockInfo() {
3046 if (!MaybeNewBlockInfo)
3049 std::move(MaybeNewBlockInfo.
get());
3052 BlockInfo = std::move(*NewBlockInfo);
3060 std::tie(Name, Record) = readNameFromStrtab(Record);
3063 return error(
"Invalid record");
3065 std::string OldFormatName;
3067 if (Record.
size() < 2)
3068 return error(
"Invalid record");
3069 unsigned ComdatNameSize = Record[1];
3070 OldFormatName.reserve(ComdatNameSize);
3071 for (
unsigned i = 0; i != ComdatNameSize; ++i)
3072 OldFormatName += (
char)Record[2 + i];
3073 Name = OldFormatName;
3075 Comdat *
C = TheModule->getOrInsertComdat(Name);
3077 ComdatList.push_back(C);
3095 std::tie(Name, Record) = readNameFromStrtab(Record);
3097 if (Record.
size() < 6)
3098 return error(
"Invalid record");
3099 Type *FullTy = getFullyStructuredTypeByID(Record[0]);
3100 Type *Ty = flattenPointerTypes(FullTy);
3102 return error(
"Invalid record");
3104 bool explicitType = Record[1] & 2;
3107 AddressSpace = Record[1] >> 2;
3110 return error(
"Invalid type for value");
3111 AddressSpace = cast<PointerType>(Ty)->getAddressSpace();
3112 std::tie(FullTy, Ty) = getPointerElementTypes(FullTy);
3115 uint64_t RawLinkage = Record[3];
3118 if (
Error Err = parseAlignmentValue(Record[4], Alignment))
3122 if (Record[5] - 1 >= SectionTable.
size())
3123 return error(
"Invalid ID");
3124 Section = SectionTable[Record[5] - 1];
3133 if (Record.
size() > 7)
3137 if (Record.
size() > 8)
3140 bool ExternallyInitialized =
false;
3141 if (Record.
size() > 9)
3142 ExternallyInitialized = Record[9];
3145 new GlobalVariable(*TheModule, Ty, isConstant, Linkage,
nullptr, Name,
3146 nullptr, TLM, AddressSpace, ExternallyInitialized);
3148 if (!Section.empty())
3153 if (Record.
size() > 10)
3160 "Incorrect fully specified type for GlobalVariable");
3161 ValueList.push_back(NewGV, FullTy);
3164 if (
unsigned InitID = Record[2])
3165 GlobalInits.push_back(std::make_pair(NewGV, InitID - 1));
3167 if (Record.
size() > 11) {
3168 if (
unsigned ComdatID = Record[11]) {
3169 if (ComdatID > ComdatList.size())
3170 return error(
"Invalid global variable comdat ID");
3171 NewGV->
setComdat(ComdatList[ComdatID - 1]);
3174 NewGV->
setComdat(reinterpret_cast<Comdat *>(1));
3177 if (Record.
size() > 12) {
3182 if (Record.
size() > 13) {
3188 if (Record.
size() > 15)
3200 std::tie(Name, Record) = readNameFromStrtab(Record);
3202 if (Record.
size() < 8)
3203 return error(
"Invalid record");
3204 Type *FullFTy = getFullyStructuredTypeByID(Record[0]);
3205 Type *FTy = flattenPointerTypes(FullFTy);
3207 return error(
"Invalid record");
3208 if (isa<PointerType>(FTy))
3209 std::tie(FullFTy, FTy) = getPointerElementTypes(FullFTy);
3211 if (!isa<FunctionType>(FTy))
3212 return error(
"Invalid type for value");
3215 return error(
"Invalid calling convention ID");
3217 unsigned AddrSpace = TheModule->getDataLayout().getProgramAddressSpace();
3218 if (Record.
size() > 16)
3219 AddrSpace = Record[16];
3223 AddrSpace, Name, TheModule);
3226 "Incorrect fully specified type provided for function");
3227 FunctionTypes[Func] = cast<FunctionType>(FullFTy);
3230 bool isProto = Record[2];
3231 uint64_t RawLinkage = Record[3];
3238 for (
unsigned i = 0; i != Func->
arg_size(); ++i) {
3242 Type *PTy = cast<FunctionType>(FullFTy)->getParamType(i);
3245 Context, getPointerElementFlatType(PTy)));
3249 if (
Error Err = parseAlignmentValue(Record[5], Alignment))
3253 if (Record[6] - 1 >= SectionTable.
size())
3254 return error(
"Invalid ID");
3255 Func->
setSection(SectionTable[Record[6] - 1]);
3261 if (Record.
size() > 8 && Record[8]) {
3262 if (Record[8] - 1 >= GCTable.
size())
3263 return error(
"Invalid ID");
3264 Func->
setGC(GCTable[Record[8] - 1]);
3267 if (Record.
size() > 9)
3270 if (Record.
size() > 10 && Record[10] != 0)
3271 FunctionPrologues.push_back(std::make_pair(Func, Record[10] - 1));
3273 if (Record.
size() > 11)
3278 if (Record.
size() > 12) {
3279 if (
unsigned ComdatID = Record[12]) {
3280 if (ComdatID > ComdatList.size())
3281 return error(
"Invalid function comdat ID");
3282 Func->
setComdat(ComdatList[ComdatID - 1]);
3285 Func->
setComdat(reinterpret_cast<Comdat *>(1));
3288 if (Record.
size() > 13 && Record[13] != 0)
3289 FunctionPrefixes.push_back(std::make_pair(Func, Record[13] - 1));
3291 if (Record.
size() > 14 && Record[14] != 0)
3292 FunctionPersonalityFns.push_back(std::make_pair(Func, Record[14] - 1));
3294 if (Record.
size() > 15) {
3302 if (Record.
size() > 18)
3307 "Incorrect fully specified type provided for Function");
3308 ValueList.push_back(Func, FullTy);
3314 FunctionsWithBodies.push_back(Func);
3315 DeferredFunctionInfo[Func] = 0;
3320 Error BitcodeReader::parseGlobalIndirectSymbolRecord(
3331 std::tie(Name, Record) = readNameFromStrtab(Record);
3335 return error(
"Invalid record");
3337 Type *FullTy = getFullyStructuredTypeByID(Record[OpNum++]);
3338 Type *Ty = flattenPointerTypes(FullTy);
3340 return error(
"Invalid record");
3346 return error(
"Invalid type for value");
3347 std::tie(FullTy, Ty) = getPointerElementTypes(FullTy);
3348 AddrSpace = PTy->getAddressSpace();
3350 AddrSpace = Record[OpNum++];
3353 auto Val = Record[OpNum++];
3354 auto Linkage = Record[OpNum++];
3362 nullptr, TheModule);
3365 "Incorrect fully structured type provided for GlobalIndirectSymbol");
3368 if (OpNum != Record.
size()) {
3369 auto VisInd = OpNum++;
3376 if (OpNum != Record.
size())
3380 if (OpNum != Record.
size())
3382 if (OpNum != Record.
size())
3385 if (OpNum != Record.
size())
3390 if (OpNum + 1 < Record.
size()) {
3392 StringRef(Strtab.
data() + Record[OpNum], Record[OpNum + 1]));
3398 "Incorrect fully structured type provided for GlobalIndirectSymbol");
3399 ValueList.push_back(NewGA, FullTy);
3400 IndirectSymbolInits.push_back(std::make_pair(NewGA, Val));
3405 bool ShouldLazyLoadMetadata) {
3421 switch (Entry.
Kind) {
3423 return error(
"Malformed block");
3425 return globalCleanup();
3434 if (readBlockInfo())
3435 return error(
"Malformed block");
3438 if (
Error Err = parseAttributeBlock())
3442 if (
Error Err = parseAttributeGroupBlock())
3446 if (
Error Err = parseTypeTable())
3450 if (!SeenValueSymbolTable) {
3456 assert(VSTOffset == 0 || FunctionsWithBodies.empty());
3457 if (
Error Err = parseValueSymbolTable())
3459 SeenValueSymbolTable =
true;
3469 if (
Error Err = parseConstants())
3471 if (
Error Err = resolveGlobalAndIndirectSymbolInits())
3475 if (ShouldLazyLoadMetadata) {
3476 if (
Error Err = rememberAndSkipMetadata())
3480 assert(DeferredMetadataInfo.empty() &&
"Unexpected deferred metadata");
3481 if (
Error Err = MDLoader->parseModuleMetadata())
3485 if (
Error Err = MDLoader->parseMetadataKinds())
3491 if (!SeenFirstFunctionBody) {
3492 std::reverse(FunctionsWithBodies.begin(), FunctionsWithBodies.end());
3493 if (
Error Err = globalCleanup())
3495 SeenFirstFunctionBody =
true;
3498 if (VSTOffset > 0) {
3502 if (!SeenValueSymbolTable) {
3503 if (
Error Err = BitcodeReader::parseValueSymbolTable(VSTOffset))
3505 SeenValueSymbolTable =
true;
3527 if (
Error Err = rememberAndSkipFunctionBody())
3534 if (SeenValueSymbolTable) {
3538 return globalCleanup();
3542 if (
Error Err = parseUseLists())
3546 if (
Error Err = parseOperandBundleTags())
3550 if (
Error Err = parseSyncScopeNames())
3565 switch (
unsigned BitCode = MaybeBitCode.
get()) {
3571 UseRelativeIDs = *VersionOrErr >= 1;
3577 return error(
"Invalid record");
3578 TheModule->setTargetTriple(S);
3584 return error(
"Invalid record");
3585 TheModule->setDataLayout(S);
3591 return error(
"Invalid record");
3592 TheModule->setModuleInlineAsm(S);
3599 return error(
"Invalid record");
3606 return error(
"Invalid record");
3607 SectionTable.push_back(S);
3613 return error(
"Invalid record");
3614 GCTable.push_back(S);
3618 if (
Error Err = parseComdatRecord(Record))
3622 if (
Error Err = parseGlobalVarRecord(Record))
3626 if (
Error Err = parseFunctionRecord(Record))
3632 if (
Error Err = parseGlobalIndirectSymbolRecord(BitCode, Record))
3637 if (Record.
size() < 1)
3638 return error(
"Invalid record");
3642 VSTOffset = Record[0] - 1;
3648 return error(
"Invalid record");
3649 TheModule->setSourceFileName(ValueName);
3656 TheModule->getDataLayoutStr(), TheModule->getTargetTriple());
3657 TheModule->setDataLayout(DL);
3661 Error BitcodeReader::parseBitcodeInto(
Module *M,
bool ShouldLazyLoadMetadata,
3665 [&](
unsigned ID) {
return getTypeByID(ID); });
3670 if (!isa<PointerType>(PtrType))
3671 return error(
"Load/Store operand is not a pointer type");
3672 Type *ElemType = cast<PointerType>(PtrType)->getElementType();
3674 if (ValType && ValType != ElemType)
3675 return error(
"Explicit load/store type does not match pointee " 3676 "type of pointer operand");
3678 return error(
"Cannot load/store from pointer");
3682 void BitcodeReader::propagateByValTypes(
CallBase *CB,
3684 for (
unsigned i = 0; i != CB->
arg_size(); ++i) {
3691 Context, getPointerElementFlatType(ArgsFullTys[i])));
3701 if (MDLoader->hasFwdRefs())
3702 return error(
"Invalid function metadata: incoming forward references");
3704 InstructionList.clear();
3705 unsigned ModuleValueListSize = ValueList.size();
3706 unsigned ModuleMDLoaderSize = MDLoader->size();
3713 "Incorrect fully specified type for Function Argument");
3716 unsigned NextValueNo = ValueList.size();
3718 unsigned CurBBNo = 0;
3721 auto getLastInstruction = [&]() ->
Instruction * {
3722 if (CurBB && !CurBB->
empty())
3723 return &CurBB->
back();
3724 else if (CurBBNo && FunctionBBs[CurBBNo - 1] &&
3725 !FunctionBBs[CurBBNo - 1]->
empty())
3726 return &FunctionBBs[CurBBNo - 1]->back();
3730 std::vector<OperandBundleDef> OperandBundles;
3741 switch (Entry.
Kind) {
3743 return error(
"Malformed block");
3745 goto OutOfRecordLoop;
3754 if (
Error Err = parseConstants())
3756 NextValueNo = ValueList.size();
3759 if (
Error Err = parseValueSymbolTable())
3763 if (
Error Err = MDLoader->parseMetadataAttachment(*F, InstructionList))
3767 assert(DeferredMetadataInfo.empty() &&
3768 "Must read all module-level metadata before function-level");
3769 if (
Error Err = MDLoader->parseFunctionMetadata())
3773 if (
Error Err = parseUseLists())
3787 Type *FullTy =
nullptr;
3791 switch (
unsigned BitCode = MaybeBitCode.
get()) {
3793 return error(
"Invalid value");
3795 if (Record.
size() < 1 || Record[0] == 0)
3796 return error(
"Invalid record");
3798 FunctionBBs.resize(Record[0]);
3801 auto BBFRI = BasicBlockFwdRefs.find(F);
3802 if (BBFRI == BasicBlockFwdRefs.end()) {
3803 for (
unsigned i = 0,
e = FunctionBBs.size(); i !=
e; ++i)
3806 auto &BBRefs = BBFRI->second;
3808 if (BBRefs.size() > FunctionBBs.size())
3809 return error(
"Invalid ID");
3810 assert(!BBRefs.empty() &&
"Unexpected empty array");
3811 assert(!BBRefs.front() &&
"Invalid reference to entry block");
3812 for (
unsigned I = 0,
E = FunctionBBs.size(), RE = BBRefs.size(); I !=
E;
3814 if (I < RE && BBRefs[I]) {
3815 BBRefs[
I]->insertInto(F);
3816 FunctionBBs[
I] = BBRefs[
I];
3822 BasicBlockFwdRefs.erase(BBFRI);
3825 CurBB = FunctionBBs[0];
3832 I = getLastInstruction();
3835 return error(
"Invalid record");
3841 I = getLastInstruction();
3842 if (!I || Record.
size() < 4)
3843 return error(
"Invalid record");
3845 unsigned Line = Record[0], Col = Record[1];
3846 unsigned ScopeID = Record[2], IAID = Record[3];
3847 bool isImplicitCode = Record.
size() == 5 && Record[4];
3851 Scope = dyn_cast_or_null<MDNode>(
3852 MDLoader->getMetadataFwdRefOrLoad(ScopeID - 1));
3854 return error(
"Invalid record");
3857 IA = dyn_cast_or_null<MDNode>(
3858 MDLoader->getMetadataFwdRefOrLoad(IAID - 1));
3860 return error(
"Invalid record");
3862 LastLoc =
DebugLoc::get(Line, Col, Scope, IA, isImplicitCode);
3870 if (getValueTypePair(Record, OpNum, NextValueNo, LHS) ||
3871 OpNum+1 > Record.
size())
3872 return error(
"Invalid record");
3876 return error(
"Invalid record");
3878 InstructionList.push_back(I);
3879 if (OpNum < Record.
size()) {
3880 if (isa<FPMathOperator>(I)) {
3891 if (getValueTypePair(Record, OpNum, NextValueNo, LHS) ||
3892 popValue(Record, OpNum, NextValueNo, LHS->
getType(), RHS) ||
3893 OpNum+1 > Record.
size())
3894 return error(
"Invalid record");
3898 return error(
"Invalid record");
3900 InstructionList.push_back(I);
3901 if (OpNum < Record.
size()) {
3903 Opc == Instruction::Sub ||
3904 Opc == Instruction::Mul ||
3905 Opc == Instruction::Shl) {
3907 cast<BinaryOperator>(I)->setHasNoSignedWrap(
true);
3909 cast<BinaryOperator>(
I)->setHasNoUnsignedWrap(
true);
3910 }
else if (Opc == Instruction::SDiv ||
3911 Opc == Instruction::UDiv ||
3912 Opc == Instruction::LShr ||
3913 Opc == Instruction::AShr) {
3915 cast<BinaryOperator>(
I)->setIsExact(
true);
3916 }
else if (isa<FPMathOperator>(I)) {
3928 if (getValueTypePair(Record, OpNum, NextValueNo, Op) ||
3929 OpNum+2 != Record.
size())
3930 return error(
"Invalid record");
3932 FullTy = getFullyStructuredTypeByID(Record[OpNum]);
3933 Type *ResTy = flattenPointerTypes(FullTy);
3935 if (Opc == -1 || !ResTy)
3936 return error(
"Invalid record");
3940 InstructionList.push_back(Temp);
3941 assert(CurBB &&
"No current BB?");
3947 return error(
"Invalid cast");
3950 InstructionList.push_back(I);
3962 InBounds = Record[OpNum++];
3963 FullTy = getFullyStructuredTypeByID(Record[OpNum++]);
3964 Ty = flattenPointerTypes(FullTy);
3971 Type *FullBaseTy =
nullptr;
3972 if (getValueTypePair(Record, OpNum, NextValueNo, BasePtr, &FullBaseTy))
3973 return error(
"Invalid record");
3976 std::tie(FullTy, Ty) =
3978 }
else if (Ty != getPointerElementFlatType(FullBaseTy->
getScalarType()))
3980 "Explicit gep type does not match pointee type of pointer operand");
3983 while (OpNum != Record.
size()) {
3985 if (getValueTypePair(Record, OpNum, NextValueNo, Op))
3986 return error(
"Invalid record");
3993 InstructionList.push_back(I);
3995 cast<GetElementPtrInst>(
I)->setIsInBounds(
true);
4003 if (getValueTypePair(Record, OpNum, NextValueNo, Agg, &FullTy))
4004 return error(
"Invalid record");
4006 unsigned RecSize = Record.
size();
4007 if (OpNum == RecSize)
4008 return error(
"EXTRACTVAL: Invalid instruction with 0 indices");
4011 for (; OpNum != RecSize; ++OpNum) {
4014 uint64_t
Index = Record[OpNum];
4016 if (!IsStruct && !IsArray)
4017 return error(
"EXTRACTVAL: Invalid type");
4018 if ((
unsigned)Index != Index)
4019 return error(
"Invalid value");
4021 return error(
"EXTRACTVAL: Invalid struct index");
4023 return error(
"EXTRACTVAL: Invalid array index");
4024 EXTRACTVALIdx.
push_back((
unsigned)Index);
4033 InstructionList.push_back(I);
4041 if (getValueTypePair(Record, OpNum, NextValueNo, Agg, &FullTy))
4042 return error(
"Invalid record");
4044 if (getValueTypePair(Record, OpNum, NextValueNo, Val))
4045 return error(
"Invalid record");
4047 unsigned RecSize = Record.
size();
4048 if (OpNum == RecSize)
4049 return error(
"INSERTVAL: Invalid instruction with 0 indices");
4053 for (; OpNum != RecSize; ++OpNum) {
4056 uint64_t
Index = Record[OpNum];
4058 if (!IsStruct && !IsArray)
4059 return error(
"INSERTVAL: Invalid type");
4060 if ((
unsigned)Index != Index)
4061 return error(
"Invalid value");
4063 return error(
"INSERTVAL: Invalid struct index");
4065 return error(
"INSERTVAL: Invalid array index");
4067 INSERTVALIdx.
push_back((
unsigned)Index);
4075 return error(
"Inserted value type doesn't match aggregate type");
4078 InstructionList.push_back(I);
4086 Value *TrueVal, *FalseVal, *Cond;
4087 if (getValueTypePair(Record, OpNum, NextValueNo, TrueVal, &FullTy) ||
4088 popValue(Record, OpNum, NextValueNo, TrueVal->
getType(), FalseVal) ||
4090 return error(
"Invalid record");
4093 InstructionList.push_back(I);
4101 Value *TrueVal, *FalseVal, *Cond;
4102 if (getValueTypePair(Record, OpNum, NextValueNo, TrueVal, &FullTy) ||
4103 popValue(Record, OpNum, NextValueNo, TrueVal->
getType(), FalseVal) ||
4104 getValueTypePair(Record, OpNum, NextValueNo, Cond))
4105 return error(
"Invalid record");
4109 dyn_cast<VectorType>(Cond->
getType())) {
4112 return error(
"Invalid type for value");
4116 return error(
"Invalid type for value");
4120 InstructionList.push_back(I);
4121 if (OpNum < Record.
size() && isa<FPMathOperator>(
I)) {
4132 if (getValueTypePair(Record, OpNum, NextValueNo, Vec, &FullTy) ||
4133 getValueTypePair(Record, OpNum, NextValueNo, Idx))
4134 return error(
"Invalid record");
4136 return error(
"Invalid type for value");
4139 InstructionList.push_back(I);
4145 Value *Vec, *Elt, *Idx;
4146 if (getValueTypePair(Record, OpNum, NextValueNo, Vec, &FullTy))
4147 return error(
"Invalid record");
4149 return error(
"Invalid type for value");
4150 if (popValue(Record, OpNum, NextValueNo,
4151 cast<VectorType>(Vec->
getType())->getElementType(), Elt) ||
4152 getValueTypePair(Record, OpNum, NextValueNo, Idx))
4153 return error(
"Invalid record");
4155 InstructionList.push_back(I);
4162 if (getValueTypePair(Record, OpNum, NextValueNo, Vec1, &FullTy) ||
4163 popValue(Record, OpNum, NextValueNo, Vec1->
getType(), Vec2))
4164 return error(
"Invalid record");
4166 if (getValueTypePair(Record, OpNum, NextValueNo, Mask))
4167 return error(
"Invalid record");
4169 return error(
"Invalid type for value");
4173 InstructionList.push_back(I);
4186 if (getValueTypePair(Record, OpNum, NextValueNo, LHS) ||
4187 popValue(Record, OpNum, NextValueNo, LHS->
getType(), RHS))
4188 return error(
"Invalid record");
4190 if (OpNum >= Record.
size())
4192 "Invalid record: operand number exceeded available operands");
4194 unsigned PredVal = Record[OpNum];
4197 if (IsFP && Record.
size() > OpNum+1)
4200 if (OpNum+1 != Record.
size())
4201 return error(
"Invalid record");
4210 InstructionList.push_back(I);
4219 InstructionList.push_back(I);
4225 if (getValueTypePair(Record, OpNum, NextValueNo, Op))
4226 return error(
"Invalid record");
4227 if (OpNum != Record.
size())
4228 return error(
"Invalid record");
4231 InstructionList.push_back(I);
4235 if (Record.
size() != 1 && Record.
size() != 3)
4236 return error(
"Invalid record");
4237 BasicBlock *TrueDest = getBasicBlock(Record[0]);
4239 return error(
"Invalid record");
4241 if (Record.
size() == 1) {
4243 InstructionList.push_back(I);
4246 BasicBlock *FalseDest = getBasicBlock(Record[1]);
4247 Value *Cond = getValue(Record, 2, NextValueNo,
4249 if (!FalseDest || !Cond)
4250 return error(
"Invalid record");
4252 InstructionList.push_back(I);
4257 if (Record.
size() != 1 && Record.
size() != 2)
4258 return error(
"Invalid record");
4263 return error(
"Invalid record");
4265 if (Record.
size() == 2) {
4266 UnwindDest = getBasicBlock(Record[Idx++]);
4268 return error(
"Invalid record");
4272 InstructionList.push_back(I);
4276 if (Record.
size() != 2)
4277 return error(
"Invalid record");
4282 return error(
"Invalid record");
4283 BasicBlock *BB = getBasicBlock(Record[Idx++]);
4285 return error(
"Invalid record");
4288 InstructionList.push_back(I);
4293 if (Record.
size() < 2)
4294 return error(
"Invalid record");
4301 unsigned NumHandlers = Record[Idx++];
4304 for (
unsigned Op = 0;
Op != NumHandlers; ++
Op) {
4305 BasicBlock *BB = getBasicBlock(Record[Idx++]);
4307 return error(
"Invalid record");
4312 if (Idx + 1 == Record.
size()) {
4313 UnwindDest = getBasicBlock(Record[Idx++]);
4315 return error(
"Invalid record");
4318 if (Record.
size() != Idx)
4319 return error(
"Invalid record");
4324 CatchSwitch->addHandler(Handler);
4326 InstructionList.push_back(I);
4332 if (Record.
size() < 2)
4333 return error(
"Invalid record");
4340 unsigned NumArgOperands = Record[Idx++];
4343 for (
unsigned Op = 0;
Op != NumArgOperands; ++
Op) {
4345 if (getValueTypePair(Record, Idx, NextValueNo, Val))
4346 return error(
"Invalid record");
4350 if (Record.
size() != Idx)
4351 return error(
"Invalid record");
4357 InstructionList.push_back(I);
4362 if ((Record[0] >> 16) == SWITCH_INST_MAGIC) {
4368 Type *OpTy = getTypeByID(Record[1]);
4369 unsigned ValueBitWidth = cast<IntegerType>(OpTy)->
getBitWidth();
4371 Value *Cond = getValue(Record, 2, NextValueNo, OpTy);
4373 if (!OpTy || !Cond || !Default)
4374 return error(
"Invalid record");
4376 unsigned NumCases = Record[4];
4379 InstructionList.push_back(SI);
4381 unsigned CurIdx = 5;
4382 for (
unsigned i = 0; i != NumCases; ++i) {
4384 unsigned NumItems = Record[CurIdx++];
4385 for (
unsigned ci = 0; ci != NumItems; ++ci) {
4386 bool isSingleNumber = Record[CurIdx++];
4389 unsigned ActiveWords = 1;
4390 if (ValueBitWidth > 64)
4391 ActiveWords = Record[CurIdx++];
4394 CurIdx += ActiveWords;
4396 if (!isSingleNumber) {
4398 if (ValueBitWidth > 64)
4399 ActiveWords = Record[CurIdx++];
4401 makeArrayRef(&Record[CurIdx], ActiveWords), ValueBitWidth);
4402 CurIdx += ActiveWords;
4408 for ( ; Low.
ule(High); ++Low)
4413 BasicBlock *DestBB = getBasicBlock(Record[CurIdx++]);
4415 cve = CaseVals.
end(); cvi != cve; ++cvi)
4424 if (Record.
size() < 3 || (Record.
size() & 1) == 0)
4425 return error(
"Invalid record");
4426 Type *OpTy = getTypeByID(Record[0]);
4427 Value *Cond = getValue(Record, 1, NextValueNo, OpTy);
4429 if (!OpTy || !Cond || !Default)
4430 return error(
"Invalid record");
4431 unsigned NumCases = (Record.
size()-3)/2;
4433 InstructionList.push_back(SI);
4434 for (
unsigned i = 0,
e = NumCases; i !=
e; ++i) {
4436 dyn_cast_or_null<ConstantInt>(getFnValueByID(Record[3+i*2], OpTy));
4437 BasicBlock *DestBB = getBasicBlock(Record[1+3+i*2]);
4438 if (!CaseVal || !DestBB) {
4440 return error(
"Invalid record");
4448 if (Record.
size() < 2)
4449 return error(
"Invalid record");
4450 Type *OpTy = getTypeByID(Record[0]);
4451 Value *
Address = getValue(Record, 1, NextValueNo, OpTy);
4452 if (!OpTy || !Address)
4453 return error(
"Invalid record");
4454 unsigned NumDests = Record.
size()-2;
4456 InstructionList.push_back(IBI);
4457 for (
unsigned i = 0,
e = NumDests; i !=
e; ++i) {
4458 if (
BasicBlock *DestBB = getBasicBlock(Record[2+i])) {
4462 return error(
"Invalid record");
4471 if (Record.
size() < 4)
4472 return error(
"Invalid record");
4475 unsigned CCInfo = Record[OpNum++];
4476 BasicBlock *NormalBB = getBasicBlock(Record[OpNum++]);
4477 BasicBlock *UnwindBB = getBasicBlock(Record[OpNum++]);
4481 if ((CCInfo >> 13) & 1) {
4485 return error(
"Explicit invoke type is not a function type");
4486 FTy = cast<FunctionType>(flattenPointerTypes(FullFTy));
4490 if (getValueTypePair(Record, OpNum, NextValueNo, Callee, &FullTy))
4491 return error(
"Invalid record");
4495 return error(
"Callee is not a pointer");
4500 return error(
"Callee is not of pointer to function type");
4501 FTy = cast<FunctionType>(flattenPointerTypes(FullFTy));
4502 }
else if (getPointerElementFlatType(FullTy) != FTy)
4503 return error(
"Explicit invoke type does not match pointee type of " 4506 return error(
"Insufficient operands to call");
4510 for (
unsigned i = 0,
e = FTy->
getNumParams(); i !=
e; ++i, ++OpNum) {
4511 Ops.
push_back(getValue(Record, OpNum, NextValueNo,
4515 return error(
"Invalid record");
4519 if (Record.
size() != OpNum)
4520 return error(
"Invalid record");
4523 while (OpNum != Record.
size()) {
4526 if (getValueTypePair(Record, OpNum, NextValueNo, Op, &FullTy))
4527 return error(
"Invalid record");
4536 OperandBundles.clear();
4537 InstructionList.push_back(I);
4538 cast<InvokeInst>(
I)->setCallingConv(
4540 cast<InvokeInst>(
I)->setAttributes(PAL);
4541 propagateByValTypes(cast<CallBase>(I), ArgsFullTys);
4547 Value *Val =
nullptr;
4548 if (getValueTypePair(Record, Idx, NextValueNo, Val))
4549 return error(
"Invalid record");
4551 InstructionList.push_back(I);
4558 unsigned CCInfo = Record[OpNum++];
4560 BasicBlock *DefaultDest = getBasicBlock(Record[OpNum++]);
4561 unsigned NumIndirectDests = Record[OpNum++];
4563 for (
unsigned i = 0,
e = NumIndirectDests; i !=
e; ++i)
4564 IndirectDests.
push_back(getBasicBlock(Record[OpNum++]));
4572 return error(
"Explicit call type is not a function type");
4573 FTy = cast<FunctionType>(flattenPointerTypes(FullFTy));
4577 if (getValueTypePair(Record, OpNum, NextValueNo, Callee, &FullTy))
4578 return error(
"Invalid record");
4582 return error(
"Callee is not a pointer type");
4587 return error(
"Callee is not of pointer to function type");
4588 FTy = cast<FunctionType>(flattenPointerTypes(FullFTy));
4589 }
else if (getPointerElementFlatType(FullTy) != FTy)
4590 return error(
"Explicit call type does not match pointee type of " 4593 return error(
"Insufficient operands to call");
4597 for (
unsigned i = 0,
e = FTy->
getNumParams(); i !=
e; ++i, ++OpNum) {
4599 Args.
push_back(getBasicBlock(Record[OpNum]));
4601 Args.
push_back(getValue(Record, OpNum, NextValueNo,
4604 return error(
"Invalid record");
4609 if (OpNum != Record.
size())
4610 return error(
"Invalid record");
4612 while (OpNum != Record.
size()) {
4614 if (getValueTypePair(Record, OpNum, NextValueNo, Op))
4615 return error(
"Invalid record");
4623 OperandBundles.clear();
4624 InstructionList.push_back(I);
4625 cast<CallBrInst>(
I)->setCallingConv(
4627 cast<CallBrInst>(
I)->setAttributes(PAL);
4632 InstructionList.push_back(I);
4635 if (Record.
size() < 1)
4636 return error(
"Invalid record");
4638 FullTy = getFullyStructuredTypeByID(Record[0]);
4639 Type *Ty = flattenPointerTypes(FullTy);
4641 return error(
"Invalid record");
4646 size_t NumArgs = (Record.
size() - 1) / 2;
4648 if ((Record.
size() - 1) % 2 == 1 && !isa<FPMathOperator>(PN))
4649 return error(
"Invalid record");
4650 InstructionList.push_back(PN);
4652 for (
unsigned i = 0; i != NumArgs; i++) {
4658 V = getValueSigned(Record, i * 2 + 1, NextValueNo, Ty);
4660 V = getValue(Record, i * 2 + 1, NextValueNo, Ty);
4661 BasicBlock *BB = getBasicBlock(Record[i * 2 + 2]);
4663 return error(
"Invalid record");
4669 if (Record.
size() % 2 == 0) {
4670 assert(isa<FPMathOperator>(I) &&
"Unexpected phi type");
4684 if (Record.
size() < 3)
4685 return error(
"Invalid record");
4688 if (Record.
size() < 4)
4689 return error(
"Invalid record");
4691 FullTy = getFullyStructuredTypeByID(Record[Idx++]);
4692 Type *Ty = flattenPointerTypes(FullTy);
4694 return error(
"Invalid record");
4696 Value *PersFn =
nullptr;
4697 if (getValueTypePair(Record, Idx, NextValueNo, PersFn))
4698 return error(
"Invalid record");
4703 return error(
"Personality function mismatch");
4706 bool IsCleanup = !!Record[Idx++];
4707 unsigned NumClauses = Record[Idx++];
4710 for (
unsigned J = 0; J != NumClauses; ++J) {
4715 if (getValueTypePair(Record, Idx, NextValueNo, Val)) {
4717 return error(
"Invalid record");
4721 !isa<ArrayType>(Val->
getType())) &&
4722 "Catch clause has a invalid type!");
4724 isa<ArrayType>(Val->
getType())) &&
4725 "Filter clause has invalid type!");
4730 InstructionList.push_back(I);
4735 if (Record.
size() != 4)
4736 return error(
"Invalid record");
4737 uint64_t AlignRecord = Record[3];
4738 const uint64_t InAllocaMask = uint64_t(1) << 5;
4739 const uint64_t ExplicitTypeMask = uint64_t(1) << 6;
4740 const uint64_t SwiftErrorMask = uint64_t(1) << 7;
4741 const uint64_t FlagMask = InAllocaMask | ExplicitTypeMask |
4743 bool InAlloca = AlignRecord & InAllocaMask;
4744 bool SwiftError = AlignRecord & SwiftErrorMask;
4745 FullTy = getFullyStructuredTypeByID(Record[0]);
4746 Type *Ty = flattenPointerTypes(FullTy);
4747 if ((AlignRecord & ExplicitTypeMask) == 0) {
4748 auto *PTy = dyn_cast_or_null<PointerType>(Ty);
4750 return error(
"Old-style alloca with a non-pointer type");
4751 std::tie(FullTy, Ty) = getPointerElementTypes(FullTy);
4753 Type *OpTy = getTypeByID(Record[1]);
4754 Value *
Size = getFnValueByID(Record[2], OpTy);
4756 if (
Error Err = parseAlignmentValue(AlignRecord & ~FlagMask, Align)) {
4760 return error(
"Invalid record");
4763 const DataLayout &DL = TheModule->getDataLayout();
4771 InstructionList.push_back(I);
4777 if (getValueTypePair(Record, OpNum, NextValueNo, Op, &FullTy) ||
4778 (OpNum + 2 != Record.
size() && OpNum + 3 != Record.
size()))
4779 return error(
"Invalid record");
4781 if (!isa<PointerType>(Op->
getType()))
4782 return error(
"Load operand is not a pointer type");
4785 if (OpNum + 3 == Record.
size()) {
4786 FullTy = getFullyStructuredTypeByID(Record[OpNum++]);
4787 Ty = flattenPointerTypes(FullTy);
4789 std::tie(FullTy, Ty) = getPointerElementTypes(FullTy);
4791 if (
Error Err = typeCheckLoadStoreInst(Ty, Op->
getType()))
4795 if (
Error Err = parseAlignmentValue(Record[OpNum], Align))
4797 I =
new LoadInst(Ty, Op,
"", Record[OpNum + 1], Align);
4798 InstructionList.push_back(I);
4805 if (getValueTypePair(Record, OpNum, NextValueNo, Op, &FullTy) ||
4806 (OpNum + 4 != Record.
size() && OpNum + 5 != Record.
size()))
4807 return error(
"Invalid record");
4809 if (!isa<PointerType>(Op->
getType()))
4810 return error(
"Load operand is not a pointer type");
4813 if (OpNum + 5 == Record.
size()) {
4814 FullTy = getFullyStructuredTypeByID(Record[OpNum++]);
4815 Ty = flattenPointerTypes(FullTy);
4817 std::tie(FullTy, Ty) = getPointerElementTypes(FullTy);
4819 if (
Error Err = typeCheckLoadStoreInst(Ty, Op->
getType()))
4826 return error(
"Invalid record");
4828 return error(
"Invalid record");
4829 SyncScope::ID SSID = getDecodedSyncScopeID(Record[OpNum + 3]);
4832 if (
Error Err = parseAlignmentValue(Record[OpNum], Align))
4834 I =
new LoadInst(Ty, Op,
"", Record[OpNum + 1], Align, Ordering, SSID);
4835 InstructionList.push_back(I);
4843 if (getValueTypePair(Record, OpNum, NextValueNo, Ptr, &FullTy) ||
4845 ? getValueTypePair(Record, OpNum, NextValueNo, Val)
4846 : popValue(Record, OpNum, NextValueNo,
4847 getPointerElementFlatType(FullTy), Val)) ||
4848 OpNum + 2 != Record.
size())
4849 return error(
"Invalid record");
4854 if (
Error Err = parseAlignmentValue(Record[OpNum], Align))
4856 I =
new StoreInst(Val, Ptr, Record[OpNum + 1], Align);
4857 InstructionList.push_back(I);
4866 if (getValueTypePair(Record, OpNum, NextValueNo, Ptr, &FullTy) ||
4867 !isa<PointerType>(Ptr->
getType()) ||
4869 ? getValueTypePair(Record, OpNum, NextValueNo, Val)
4870 : popValue(Record, OpNum, NextValueNo,
4871 getPointerElementFlatType(FullTy), Val)) ||
4872 OpNum + 4 != Record.
size())
4873 return error(
"Invalid record");
4881 return error(
"Invalid record");
4882 SyncScope::ID SSID = getDecodedSyncScopeID(Record[OpNum + 3]);
4884 return error(
"Invalid record");
4887 if (
Error Err = parseAlignmentValue(Record[OpNum], Align))
4889 I =
new StoreInst(Val, Ptr, Record[OpNum + 1], Align, Ordering, SSID);
4890 InstructionList.push_back(I);
4898 Value *Ptr, *Cmp, *New;
4899 if (getValueTypePair(Record, OpNum, NextValueNo, Ptr, &FullTy))
4900 return error(
"Invalid record");
4902 if (!isa<PointerType>(Ptr->
getType()))
4903 return error(
"Cmpxchg operand is not a pointer type");
4906 if (getValueTypePair(Record, OpNum, NextValueNo, Cmp, &FullTy))
4907 return error(
"Invalid record");
4908 }
else if (popValue(Record, OpNum, NextValueNo,
4909 getPointerElementFlatType(FullTy), Cmp))
4910 return error(
"Invalid record");
4912 FullTy = cast<PointerType>(FullTy)->getElementType();
4914 if (popValue(Record, OpNum, NextValueNo, Cmp->
getType(), New) ||
4915 Record.
size() < OpNum + 3 || Record.
size() > OpNum + 5)
4916 return error(
"Invalid record");
4921 return error(
"Invalid record");
4922 SyncScope::ID SSID = getDecodedSyncScopeID(Record[OpNum + 2]);
4927 if (Record.
size() < 7)
4936 cast<AtomicCmpXchgInst>(
I)->setVolatile(Record[OpNum]);
4938 if (Record.
size() < 8) {
4944 FullTy = cast<StructType>(FullTy)->getElementType(0);
4946 cast<AtomicCmpXchgInst>(
I)->setWeak(Record[OpNum+4]);
4949 InstructionList.push_back(I);
4956 if (getValueTypePair(Record, OpNum, NextValueNo, Ptr, &FullTy) ||
4957 !isa<PointerType>(Ptr->
getType()) ||
4958 popValue(Record, OpNum, NextValueNo,
4959 getPointerElementFlatType(FullTy), Val) ||
4960 OpNum + 4 != Record.
size())
4961 return error(
"Invalid record");
4965 return error(
"Invalid record");
4969 return error(
"Invalid record");
4970 SyncScope::ID SSID = getDecodedSyncScopeID(Record[OpNum + 3]);
4972 FullTy = getPointerElementFlatType(FullTy);
4973 cast<AtomicRMWInst>(
I)->setVolatile(Record[OpNum+1]);
4974 InstructionList.push_back(I);
4978 if (2 != Record.
size())
4979 return error(
"Invalid record");
4984 return error(
"Invalid record");
4986 I =
new FenceInst(Context, Ordering, SSID);
4987 InstructionList.push_back(I);
4992 if (Record.
size() < 3)
4993 return error(
"Invalid record");
4997 unsigned CCInfo = Record[OpNum++];
5003 return error(
"Fast math flags indicator set for call with no FMF");
5012 return error(
"Explicit call type is not a function type");
5013 FTy = cast<FunctionType>(flattenPointerTypes(FullFTy));
5017 if (getValueTypePair(Record, OpNum, NextValueNo, Callee, &FullTy))
5018 return error(
"Invalid record");
5022 return error(
"Callee is not a pointer type");
5027 return error(
"Callee is not of pointer to function type");
5028 FTy = cast<FunctionType>(flattenPointerTypes(FullFTy));
5029 }
else if (getPointerElementFlatType(FullTy) != FTy)
5030 return error(
"Explicit call type does not match pointee type of " 5033 return error(
"Insufficient operands to call");
5038 for (
unsigned i = 0,
e = FTy->
getNumParams(); i !=
e; ++i, ++OpNum) {
5040 Args.
push_back(getBasicBlock(Record[OpNum]));
5042 Args.
push_back(getValue(Record, OpNum, NextValueNo,
5046 return error(
"Invalid record");
5051 if (OpNum != Record.
size())
5052 return error(
"Invalid record");
5054 while (OpNum != Record.
size()) {
5057 if (getValueTypePair(Record, OpNum, NextValueNo, Op, &FullTy))
5058 return error(
"Invalid record");
5066 OperandBundles.clear();
5067 InstructionList.push_back(I);
5068 cast<CallInst>(
I)->setCallingConv(
5077 cast<CallInst>(
I)->setTailCallKind(TCK);
5078 cast<CallInst>(
I)->setAttributes(PAL);
5079 propagateByValTypes(cast<CallBase>(I), ArgsFullTys);
5081 if (!isa<FPMathOperator>(I))
5082 return error(
"Fast-math-flags specified for call without " 5083 "floating-point scalar or vector return type");
5089 if (Record.
size() < 3)
5090 return error(
"Invalid record");
5091 Type *OpTy = getTypeByID(Record[0]);
5092 Value *
Op = getValue(Record, 1, NextValueNo, OpTy);
5093 FullTy = getFullyStructuredTypeByID(Record[2]);
5094 Type *ResTy = flattenPointerTypes(FullTy);
5095 if (!OpTy || !Op || !ResTy)
5096 return error(
"Invalid record");
5098 InstructionList.push_back(I);
5107 if (Record.
size() < 1 || Record[0] >= BundleTags.
size())
5108 return error(
"Invalid record");
5110 std::vector<Value *> Inputs;
5113 while (OpNum != Record.
size()) {
5115 if (getValueTypePair(Record, OpNum, NextValueNo, Op))
5116 return error(
"Invalid record");
5117 Inputs.push_back(Op);
5120 OperandBundles.emplace_back(BundleTags[Record[0]], std::move(Inputs));
5127 if (getValueTypePair(Record, OpNum, NextValueNo, Op, &FullTy))
5128 return error(
"Invalid record");
5129 if (OpNum != Record.
size())
5130 return error(
"Invalid record");
5133 InstructionList.push_back(I);
5142 return error(
"Invalid instruction with no BB");
5144 if (!OperandBundles.empty()) {
5146 return error(
"Operand bundles found with no consumer");
5153 CurBB = CurBBNo < FunctionBBs.size() ? FunctionBBs[CurBBNo] :
nullptr;
5161 !FullTy->
isPointerTy() && !isa<StructType>(FullTy) &&
5162 !isa<ArrayType>(FullTy) &&
5163 (!isa<VectorType>(FullTy) ||
5166 "Structured types must be assigned with corresponding non-opaque " 5171 "Incorrect fully structured type provided for Instruction");
5172 ValueList.assignValue(I, NextValueNo++, FullTy);
5178 if (!OperandBundles.empty())
5179 return error(
"Operand bundles found with no consumer");
5182 if (
Argument *A = dyn_cast<Argument>(ValueList.back())) {
5183 if (!A->getParent()) {
5185 for (
unsigned i = ModuleValueListSize,
e = ValueList.size(); i !=
e; ++i){
5186 if ((A = dyn_cast_or_null<Argument>(ValueList[i])) && !A->getParent()) {
5191 return error(
"Never resolved value found in function");
5196 if (MDLoader->hasFwdRefs())
5197 return error(
"Invalid function metadata: outgoing forward refs");
5200 ValueList.shrinkTo(ModuleValueListSize);
5201 MDLoader->shrinkTo(ModuleMDLoaderSize);
5202 std::vector<BasicBlock*>().
swap(FunctionBBs);
5207 Error BitcodeReader::findFunctionInStream(
5210 while (DeferredFunctionInfoIterator->second == 0) {
5218 if (
Error Err = rememberAndSkipFunctionBodies())
5224 SyncScope::ID BitcodeReader::getDecodedSyncScopeID(
unsigned Val) {
5227 if (Val >= SSIDs.size())
5243 assert(DFII != DeferredFunctionInfo.
end() &&
"Deferred function not found!");
5246 if (DFII->second == 0)
5247 if (
Error Err = findFunctionInStream(F, DFII))
5251 if (
Error Err = materializeMetadata())
5257 if (
Error Err = parseFunctionBody(F))
5265 for (
auto &
I : UpgradedIntrinsics) {
5266 for (
auto UI =
I.first->materialized_user_begin(), UE =
I.first->user_end();
5270 if (
CallInst *CI = dyn_cast<CallInst>(U))
5276 for (
auto &
I : RemangledIntrinsics)
5277 for (
auto UI =
I.first->materialized_user_begin(), UE =
I.first->user_end();
5287 if (!MDLoader->isStrippingTBAA()) {
5289 MDNode *TBAA =
I.getMetadata(LLVMContext::MD_tbaa);
5290 if (!TBAA || TBAAVerifyHelper.visitTBAAMetadata(
I, TBAA))
5292 MDLoader->setStripTBAA(
true);
5299 return materializeForwardReferencedFunctions();
5302 Error BitcodeReader::materializeModule() {
5303 if (
Error Err = materializeMetadata())
5307 WillMaterializeAllForwardRefs =
true;
5312 if (
Error Err = materialize(&F))
5318 if (LastFunctionBlockBit || NextUnreadBit)
5320 ? LastFunctionBlockBit
5326 if (!BasicBlockFwdRefs.empty())
5327 return error(
"Never resolved function from blockaddress");
5333 for (
auto &
I : UpgradedIntrinsics) {
5334 for (
auto *U :
I.first->users()) {
5335 if (
CallInst *CI = dyn_cast<CallInst>(U))
5338 if (!
I.first->use_empty())
5339 I.first->replaceAllUsesWith(
I.second);
5340 I.first->eraseFromParent();
5342 UpgradedIntrinsics.clear();
5344 for (
auto &
I : RemangledIntrinsics) {
5345 I.first->replaceAllUsesWith(
I.second);
5346 I.first->eraseFromParent();
5348 RemangledIntrinsics.clear();
5359 std::vector<StructType *> BitcodeReader::getIdentifiedStructTypes()
const {
5360 return IdentifiedStructTypes;
5363 ModuleSummaryIndexBitcodeReader::ModuleSummaryIndexBitcodeReader(
5365 StringRef ModulePath,
unsigned ModuleId)
5366 : BitcodeReaderBase(std::move(Cursor), Strtab), TheIndex(TheIndex),
5367 ModulePath(ModulePath), ModuleId(ModuleId) {}
5369 void ModuleSummaryIndexBitcodeReader::addThisModule() {
5370 TheIndex.
addModule(ModulePath, ModuleId);
5374 ModuleSummaryIndexBitcodeReader::getThisModule() {
5378 std::pair<ValueInfo, GlobalValue::GUID>
5379 ModuleSummaryIndexBitcodeReader::getValueInfoFromValueId(
unsigned ValueId) {
5380 auto VGI = ValueIdToValueInfoMap[ValueId];
5385 void ModuleSummaryIndexBitcodeReader::setValueGUID(
5388 std::string GlobalId =
5391 auto OriginalNameID = ValueGUID;
5395 dbgs() <<
"GUID " << ValueGUID <<
"(" << OriginalNameID <<
") is " 5396 << ValueName <<
"\n";
5401 ValueIdToValueInfoMap[ValueID] = std::make_pair(
5404 UseStrtab ? ValueName : TheIndex.
saveString(ValueName)),
5411 Error ModuleSummaryIndexBitcodeReader::parseValueSymbolTable(
5418 assert(Offset > 0 &&
"Expected non-zero VST offset");
5420 if (!MaybeCurrentBit)
5422 uint64_t CurrentBit = MaybeCurrentBit.
get();
5438 switch (Entry.
Kind) {
5441 return error(
"Malformed block");
5457 switch (MaybeRecord.
get()) {
5462 return error(
"Invalid record");
5463 unsigned ValueID = Record[0];
5465 auto VLI = ValueIdToLinkageMap.
find(ValueID);
5466 assert(VLI != ValueIdToLinkageMap.
end() &&
5467 "No linkage found for VST entry?");
5468 auto Linkage = VLI->second;
5469 setValueGUID(ValueID, ValueName, Linkage, SourceFileName);
5476 return error(
"Invalid record");
5477 unsigned ValueID = Record[0];
5479 auto VLI = ValueIdToLinkageMap.
find(ValueID);
5480 assert(VLI != ValueIdToLinkageMap.
end() &&
5481 "No linkage found for VST entry?");
5482 auto Linkage = VLI->second;
5483 setValueGUID(ValueID, ValueName, Linkage, SourceFileName);
5489 unsigned ValueID = Record[0];
5493 ValueIdToValueInfoMap[ValueID] =
5510 unsigned ValueId = 0;
5519 switch (Entry.
Kind) {
5521 return error(
"Malformed block");
5533 if (readBlockInfo())
5534 return error(
"Malformed block");
5539 assert(((SeenValueSymbolTable && VSTOffset > 0) ||
5540 !SeenGlobalValSummary) &&
5541 "Expected early VST parse via VSTOffset record");
5548 if (!SourceFileName.
empty())
5550 assert(!SeenValueSymbolTable &&
5551 "Already read VST when parsing summary block?");
5556 if (VSTOffset > 0) {
5557 if (
Error Err = parseValueSymbolTable(VSTOffset, ValueIdToLinkageMap))
5559 SeenValueSymbolTable =
true;
5561 SeenGlobalValSummary =
true;
5562 if (
Error Err = parseEntireSummary(Entry.
ID))
5566 if (
Error Err = parseModuleStringTable())
5577 switch (MaybeBitCode.
get()) {
5581 if (
Error Err = parseVersionRecord(Record).takeError())
5589 return error(
"Invalid record");
5590 SourceFileName = ValueName.
c_str();
5595 if (Record.
size() != 5)
5596 return error(
"Invalid hash length " +
Twine(Record.
size()).str());
5597 auto &Hash = getThisModule()->second.second;
5599 for (
auto &Val : Record) {
5600 assert(!(Val >> 32) &&
"Unexpected high bits set");
5607 if (Record.
size() < 1)
5608 return error(
"Invalid record");
5612 VSTOffset = Record[0] - 1;
5623 std::tie(Name, GVRecord) = readNameFromStrtab(Record);
5624 if (GVRecord.
size() <= 3)
5625 return error(
"Invalid record");
5626 uint64_t RawLinkage = GVRecord[3];
5629 ValueIdToLinkageMap[ValueId++] =
Linkage;
5633 setValueGUID(ValueId++, Name, Linkage, SourceFileName);
5643 std::vector<ValueInfo>
5645 std::vector<ValueInfo>
Ret;
5646 Ret.reserve(Record.
size());
5647 for (uint64_t RefValueId : Record)
5648 Ret.push_back(getValueInfoFromValueId(RefValueId).
first);
5652 std::vector<FunctionSummary::EdgeTy>
5654 bool IsOldProfileFormat,
5655 bool HasProfile,
bool HasRelBF) {
5656 std::vector<FunctionSummary::EdgeTy>
Ret;
5657 Ret.reserve(Record.
size());
5658 for (
unsigned I = 0,
E = Record.
size();
I !=
E; ++
I) {
5662 if (IsOldProfileFormat) {
5666 }
else if (HasProfile)
5669 RelBF = Record[++
I];
5678 uint64_t ArgNum = Record[Slot++];
5685 B.
Info = Record[Slot++];
5686 B.
Byte = Record[Slot++];
5687 B.
Bit = Record[Slot++];
5693 uint64_t
Id = Record[Slot++];
5698 static_cast<size_t>(Record[Slot + 1])};
5701 uint64_t ResByArgNum = Record[Slot++];
5702 for (uint64_t
I = 0;
I != ResByArgNum; ++
I)
5711 {Strtab.
data() + Record[Slot],
static_cast<size_t>(Record[Slot + 1])});
5721 while (Slot < Record.
size())
5725 void ModuleSummaryIndexBitcodeReader::parseTypeIdCompatibleVtableInfo(
5728 uint64_t Offset = Record[Slot++];
5730 TypeId.push_back({
Offset, Callee});
5733 void ModuleSummaryIndexBitcodeReader::parseTypeIdCompatibleVtableSummaryRecord(
5738 {Strtab.
data() + Record[Slot],
5739 static_cast<size_t>(Record[Slot + 1])});
5742 while (Slot < Record.
size())
5743 parseTypeIdCompatibleVtableInfo(Record, Slot, TypeId);
5749 assert(ROCnt + WOCnt <= Refs.size());
5750 unsigned FirstWORef = Refs.size() - WOCnt;
5751 unsigned RefNo = FirstWORef - ROCnt;
5752 for (; RefNo < FirstWORef; ++RefNo)
5753 Refs[RefNo].setReadOnly();
5754 for (; RefNo < Refs.size(); ++RefNo)
5755 Refs[RefNo].setWriteOnly();
5760 Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(
unsigned ID) {
5773 return error(
"Invalid Summary Block: record for version expected");
5778 return error(
"Invalid Summary Block: version expected");
5780 const uint64_t
Version = Record[0];
5781 const bool IsOldProfileFormat = Version == 1;
5783 return error(
"Invalid summary version " +
Twine(Version) +
5784 ". Version should be in the range [1-" +
5785 Twine(ModuleSummaryIndex::BitcodeSummaryVersion) +
5797 std::vector<GlobalValue::GUID> PendingTypeTests;
5798 std::vector<FunctionSummary::VFuncId> PendingTypeTestAssumeVCalls,
5799 PendingTypeCheckedLoadVCalls;
5800 std::vector<FunctionSummary::ConstVCall> PendingTypeTestAssumeConstVCalls,
5801 PendingTypeCheckedLoadConstVCalls;
5809 switch (Entry.
Kind) {
5812 return error(
"Malformed block");
5831 switch (
unsigned BitCode = MaybeBitCode.
get()) {
5835 uint64_t Flags = Record[0];
5837 assert(Flags <= 0x3f &&
"Unexpected bits in flag");
5867 uint64_t ValueID = Record[0];
5869 ValueIdToValueInfoMap[ValueID] =
5884 unsigned ValueID = Record[0];
5885 uint64_t RawFlags = Record[1];
5886 unsigned InstCount = Record[2];
5887 uint64_t RawFunFlags = 0;
5888 unsigned NumRefs = Record[3];
5889 unsigned NumRORefs = 0, NumWORefs = 0;
5890 int RefListStartIndex = 4;
5892 RawFunFlags = Record[3];
5893 NumRefs = Record[4];
5894 RefListStartIndex = 5;
5896 NumRORefs = Record[5];
5897 RefListStartIndex = 6;
5899 NumWORefs = Record[6];
5900 RefListStartIndex = 7;
5911 int CallGraphEdgeStartIndex = RefListStartIndex + NumRefs;
5912 assert(Record.
size() >= RefListStartIndex + NumRefs &&
5913 "Record size inconsistent with number of references");
5914 std::vector<ValueInfo> Refs = makeRefList(
5918 std::vector<FunctionSummary::EdgeTy> Calls = makeCallList(
5920 IsOldProfileFormat, HasProfile, HasRelBF);
5922 auto FS = std::make_unique<FunctionSummary>(
5924 std::move(Refs), std::move(Calls), std::move(PendingTypeTests),
5925 std::move(PendingTypeTestAssumeVCalls),
5926 std::move(PendingTypeCheckedLoadVCalls),
5927 std::move(PendingTypeTestAssumeConstVCalls),
5928 std::move(PendingTypeCheckedLoadConstVCalls));
5929 auto VIAndOriginalGUID = getValueInfoFromValueId(ValueID);
5930 FS->setModulePath(getThisModule()->
first());
5931 FS->setOriginalName(VIAndOriginalGUID.second);
5939 unsigned ValueID = Record[0];
5940 uint64_t RawFlags = Record[1];
5941 unsigned AliaseeID = Record[2];
5943 auto AS = std::make_unique<AliasSummary>(Flags);
5949 AS->setModulePath(getThisModule()->
first());
5951 auto AliaseeVI = getValueInfoFromValueId(AliaseeID).first;
5953 if (!AliaseeInModule)
5954 return error(
"Alias expects aliasee summary to be parsed");
5955 AS->setAliasee(AliaseeVI, AliaseeInModule);
5957 auto GUID = getValueInfoFromValueId(ValueID);
5958 AS->setOriginalName(GUID.second);
5964 unsigned ValueID = Record[0];
5965 uint64_t RawFlags = Record[1];
5966 unsigned RefArrayStart = 2;
5974 std::vector<ValueInfo> Refs =
5977 std::make_unique<GlobalVarSummary>(Flags, GVF, std::move(Refs));
5978 FS->setModulePath(getThisModule()->
first());
5979 auto GUID = getValueInfoFromValueId(ValueID);
5980 FS->setOriginalName(GUID.second);
5988 unsigned ValueID = Record[0];
5989 uint64_t RawFlags = Record[1];
5991 unsigned NumRefs = Record[3];
5992 unsigned RefListStartIndex = 4;
5993 unsigned VTableListStartIndex = RefListStartIndex + NumRefs;
5995 std::vector<ValueInfo> Refs = makeRefList(
5998 for (
unsigned I = VTableListStartIndex,
E = Record.
size();
I !=
E; ++
I) {
6000 uint64_t Offset = Record[++
I];
6001 VTableFuncs.
push_back({Callee, Offset});
6004 std::make_unique<GlobalVarSummary>(Flags, GVF, std::move(Refs));
6005 VS->setModulePath(getThisModule()->
first());
6006 VS->setVTableFuncs(VTableFuncs);
6007 auto GUID = getValueInfoFromValueId(ValueID);
6008 VS->setOriginalName(GUID.second);
6018 unsigned ValueID = Record[0];
6019 uint64_t ModuleId = Record[1];
6020 uint64_t RawFlags = Record[2];
6021 unsigned InstCount = Record[3];
6022 uint64_t RawFunFlags = 0;
6023 uint64_t EntryCount = 0;
6024 unsigned NumRefs = Record[4];
6025 unsigned NumRORefs = 0, NumWORefs = 0;
6026 int RefListStartIndex = 5;
6029 RawFunFlags = Record[4];
6030 RefListStartIndex = 6;
6031 size_t NumRefsIndex = 5;
6033 unsigned NumRORefsOffset = 1;
6034 RefListStartIndex = 7;
6037 EntryCount = Record[5];
6038 RefListStartIndex = 8;
6040 RefListStartIndex = 9;
6041 NumWORefs = Record[8];
6042 NumRORefsOffset = 2;
6045 NumRORefs = Record[RefListStartIndex - NumRORefsOffset];
6047 NumRefs = Record[NumRefsIndex];
6051 int CallGraphEdgeStartIndex = RefListStartIndex + NumRefs;
6052 assert(Record.
size() >= RefListStartIndex + NumRefs &&
6053 "Record size inconsistent with number of references");
6054 std::vector<ValueInfo> Refs = makeRefList(
6057 std::vector<FunctionSummary::EdgeTy> Edges = makeCallList(
6059 IsOldProfileFormat, HasProfile,
false);
6060 ValueInfo VI = getValueInfoFromValueId(ValueID).first;
6062 auto FS = std::make_unique<FunctionSummary>(
6064 std::move(Refs), std::move(Edges), std::move(PendingTypeTests),
6065 std::move(PendingTypeTestAssumeVCalls),
6066 std::move(PendingTypeCheckedLoadVCalls),
6067 std::move(PendingTypeTestAssumeConstVCalls),
6068 std::move(PendingTypeCheckedLoadConstVCalls));
6069 LastSeenSummary =
FS.get();
6071 FS->setModulePath(ModuleIdMap[ModuleId]);
6079 unsigned ValueID = Record[0];
6080 uint64_t ModuleId = Record[1];
6081 uint64_t RawFlags = Record[2];
6082 unsigned AliaseeValueId = Record[3];
6084 auto AS = std::make_unique<AliasSummary>(Flags);
6085 LastSeenSummary = AS.get();
6088 auto AliaseeVI = getValueInfoFromValueId(AliaseeValueId).first;
6090 AS->setAliasee(AliaseeVI, AliaseeInModule);
6092 ValueInfo VI = getValueInfoFromValueId(ValueID).first;
6099 unsigned ValueID = Record[0];
6100 uint64_t ModuleId = Record[1];
6101 uint64_t RawFlags = Record[2];
6102 unsigned RefArrayStart = 3;
6110 std::vector<ValueInfo> Refs =
6113 std::make_unique<GlobalVarSummary>(Flags, GVF, std::move(Refs));
6114 LastSeenSummary =
FS.get();
6115 FS->setModulePath(ModuleIdMap[ModuleId]);
6116 ValueInfo VI = getValueInfoFromValueId(ValueID).first;
6123 uint64_t OriginalName = Record[0];
6124 if (!LastSeenSummary)
6125 return error(
"Name attachment that does not follow a combined record");
6129 LastSeenSummary =
nullptr;
6134 assert(PendingTypeTests.empty());
6135 PendingTypeTests.insert(PendingTypeTests.end(), Record.
begin(),
6140 assert(PendingTypeTestAssumeVCalls.empty());
6141 for (
unsigned I = 0;
I != Record.
size();
I += 2)
6142 PendingTypeTestAssumeVCalls.push_back({Record[I], Record[I+1]});
6146 assert(PendingTypeCheckedLoadVCalls.empty());
6147 for (
unsigned I = 0;
I != Record.
size();
I += 2)
6148 PendingTypeCheckedLoadVCalls.push_back({Record[I], Record[I+1]});
6152 PendingTypeTestAssumeConstVCalls.push_back(
6153 {{Record[0], Record[1]}, {Record.begin() + 2, Record.end()}});
6157 PendingTypeCheckedLoadConstVCalls.push_back(
6158 {{Record[0], Record[1]}, {Record.begin() + 2, Record.end()}});
6163 for (
unsigned I = 0;
I != Record.
size();
I += 2)
6164 CfiFunctionDefs.insert(
6165 {Strtab.data() + Record[I], static_cast<size_t>(Record[I + 1])});
6171 for (
unsigned I = 0;
I != Record.
size();
I += 2)
6172 CfiFunctionDecls.insert(
6173 {Strtab.data() + Record[I], static_cast<size_t>(Record[I + 1])});
6182 parseTypeIdCompatibleVtableSummaryRecord(Record);
6191 Error ModuleSummaryIndexBitcodeReader::parseModuleStringTable() {
6206 switch (Entry.
Kind) {
6209 return error(
"Malformed block");
6221 switch (MaybeRecord.
get()) {
6226 uint64_t ModuleId = Record[0];
6229 return error(
"Invalid record");
6231 LastSeenModule = TheIndex.
addModule(ModulePath, ModuleId);
6232 ModuleIdMap[ModuleId] = LastSeenModule->
first();
6239 if (Record.
size() != 5)
6240 return error(
"Invalid hash length " +
Twine(Record.
size()).str());
6241 if (!LastSeenModule)
6242 return error(
"Invalid hash that does not follow a module path");
6244 for (
auto &Val : Record) {
6245 assert(!(Val >> 32) &&
"Unexpected high bits set");
6246 LastSeenModule->
second.second[Pos++] = Val;
6249 LastSeenModule =
nullptr;
6263 const char *
name()
const noexcept
override {
6264 return "llvm.bitcode";
6267 std::string message(
int IE)
const override {
6271 return "Corrupted bitcode";
6286 unsigned Block,
unsigned RecordID) {
6288 return std::move(Err);
6297 switch (Entry.
Kind) {
6302 return error(
"Malformed block");
6306 return std::move(Err);
6316 if (MaybeRecord.
get() == RecordID)
6331 return FOrErr.takeError();
6332 return std::move(FOrErr->Mods);
6357 switch (Entry.
Kind) {
6360 return error(
"Malformed block");
6363 uint64_t IdentificationBit = -1ull;
6367 return std::move(Err);
6373 Entry = MaybeEntry.
get();
6378 return error(
"Malformed block");
6384 return std::move(Err);
6402 for (
auto I = F.
Mods.rbegin(),
E = F.
Mods.rend();
I !=
E; ++
I) {
6403 if (!
I->Strtab.empty())
6405 I->Strtab = *Strtab;
6433 return std::move(Err);
6440 return StreamFailed.takeError();
6454 BitcodeModule::getModuleImpl(
LLVMContext &Context,
bool MaterializeAll,
6455 bool ShouldLazyLoadMetadata,
bool IsImporting) {
6458 std::string ProducerIdentification;
6459 if (IdentificationBit != -1ull) {
6461 return std::move(JumpFailed);
6464 if (!ProducerIdentificationOrErr)
6465 return ProducerIdentificationOrErr.
takeError();
6467 ProducerIdentification = *ProducerIdentificationOrErr;
6471 return std::move(JumpFailed);
6472 auto *R =
new BitcodeReader(std::move(Stream), Strtab, ProducerIdentification,
6475 std::unique_ptr<Module> M =
6476 std::make_unique<Module>(ModuleIdentifier,
Context);
6481 R->parseBitcodeInto(M.get(), ShouldLazyLoadMetadata, IsImporting))
6482 return std::move(Err);
6484 if (MaterializeAll) {
6486 if (
Error Err = M->materializeAll())
6487 return std::move(Err);
6490 if (
Error Err = R->materializeForwardReferencedFunctions())
6491 return std::move(Err);
6493 return std::move(M);
6499 return getModuleImpl(Context,
false, ShouldLazyLoadMetadata, IsImporting);
6507 StringRef ModulePath, uint64_t ModuleId) {
6512 ModuleSummaryIndexBitcodeReader R(std::move(Stream), Strtab, CombinedIndex,
6513 ModulePath, ModuleId);
6514 return R.parseModule();
6521 return std::move(JumpFailed);
6523 auto Index = std::make_unique<ModuleSummaryIndex>(
false);
6524 ModuleSummaryIndexBitcodeReader R(std::move(Stream), Strtab, *
Index,
6525 ModuleIdentifier, 0);
6527 if (
Error Err = R.parseModule())
6528 return std::move(Err);
6530 return std::move(
Index);
6536 return std::move(Err);
6545 switch (Entry.
Kind) {
6548 return error(
"Malformed block");
6563 switch (MaybeBitCode.
get()) {
6567 uint64_t Flags = Record[0];
6569 assert(Flags <= 0x3f &&
"Unexpected bits in flag");
6582 return std::move(JumpFailed);
6585 return std::move(Err);
6593 switch (Entry.
Kind) {
6595 return error(
"Malformed block");
6604 if (!EnableSplitLTOUnit)
6607 *EnableSplitLTOUnit};
6613 if (!EnableSplitLTOUnit)
6616 *EnableSplitLTOUnit};
6621 return std::move(Err);
6628 return StreamFailed.takeError();
6638 if (MsOrErr->size() != 1)
6639 return error(
"Expected a single module");
6641 return (*MsOrErr)[0];
6646 bool ShouldLazyLoadMetadata,
bool IsImporting) {
6651 return BM->getLazyModule(Context, ShouldLazyLoadMetadata, IsImporting);
6655 std::unique_ptr<MemoryBuffer> &&Buffer,
LLVMContext &Context,
6656 bool ShouldLazyLoadMetadata,
bool IsImporting) {
6660 (*MOrErr)->setOwnedMemoryBuffer(std::move(Buffer));
6666 return getModuleImpl(Context,
true,
false,
false);
6677 return BM->parseModule(Context);
6706 uint64_t ModuleId) {
6711 return BM->readSummary(CombinedIndex, BM->getModuleIdentifier(), ModuleId);
6720 return BM->getSummary();
6728 return BM->getLTOInfo();
6733 bool IgnoreEmptyThinLTOIndexFile) {
6738 if (IgnoreEmptyThinLTOIndexFile && !(*FileOrErr)->getBufferSize())
void setVisibility(VisibilityTypes V)
Scope
Defines the scope in which this symbol should be visible: Default – Visible in the public interface ...
static AtomicOrdering getDecodedOrdering(unsigned Val)
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
Type * getVectorElementType() const
static const fltSemantics & IEEEquad() LLVM_READNONE
void sortUseList(Compare Cmp)
Sort the use-list.
A parsed version of the target data layout string in and methods for querying it. ...
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
Tracking metadata reference owned by Metadata.
static APInt readWideAPInt(ArrayRef< uint64_t > Vals, unsigned TypeBits)
std::vector< TypeIdOffsetVtableInfo > TypeIdCompatibleVtableInfo
List of vtable definitions decorated by a particular type identifier, and their corresponding offsets...
Represents either an error or a value T.
static Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true)
This method constructs a CDS and initializes it with a text string.
void setFastMathFlags(FastMathFlags FMF)
Convenience function for setting multiple fast-math flags on this instruction, which must be an opera...
void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
removes the attribute from the list of attributes.
static bool isConstant(const MachineInstr &MI)
static Type * getDoubleTy(LLVMContext &C)
static IntegerType * getInt1Ty(LLVMContext &C)
bool hasLocalLinkage() const
DILocation * get() const
Get the underlying DILocation.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
Special purpose, only applies to global arrays.
BLOCKINFO_BLOCK is used to define metadata about blocks, for example, standard abbrevs that should be...
*p = old <signed v ? old : v
This class represents an incoming formal argument to a Function.
void setFast(bool B=true)
void setEnableSplitLTOUnit()
bool supportsCOMDAT() const
Tests whether the target supports comdat.
Atomic ordering constants.
bool isMetadataTy() const
Return true if this is 'metadata'.
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
This class represents lattice values for constants.
uint64_t GetCurrentBitNo() const
Return the bit # of the bit we are reading.
Type * getParamType(unsigned i) const
Parameter type accessors.
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
adds the attribute to the list of attributes for the given arg.
static Expected< std::string > readTriple(BitstreamCursor &Stream)
A Module instance is used to store all the information related to an LLVM module. ...
Expected< std::unique_ptr< Module > > getLazyBitcodeModule(MemoryBufferRef Buffer, LLVMContext &Context, bool ShouldLazyLoadMetadata=false, bool IsImporting=false)
Read the header of the specified bitcode buffer and prepare for lazy deserialization of function bodi...
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant *> IdxList, bool InBounds=false, Optional< unsigned > InRangeIndex=None, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
static ResumeInst * Create(Value *Exn, Instruction *InsertBefore=nullptr)
An instruction for ordering other memory operations.
Same, but only replaced by something equivalent.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
An instruction that atomically checks whether a specified value is in a memory location, and, if it is, stores a new value there.
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
static int getDecodedBinaryOpcode(unsigned Val, Type *Ty)
Available for inspection, not emission.
void push_back(const T &Elt)
void addCase(ConstantInt *OnVal, BasicBlock *Dest)
Add an entry to the switch instruction.
bool isFP128Ty() const
Return true if this is 'fp128'.
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value *> IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
void setMaterializer(GVMaterializer *GVM)
Sets the GVMaterializer to GVM.
void addOperand(MDNode *M)
Error readSummary(ModuleSummaryIndex &CombinedIndex, StringRef ModulePath, uint64_t ModuleId)
Parse the specified bitcode buffer and merge its module summary index into CombinedIndex.
This class represents a function call, abstracting a target machine's calling convention.
SyncScope::ID getOrInsertSyncScopeID(StringRef SSN)
getOrInsertSyncScopeID - Maps synchronization scope name to synchronization scope ID...
void setGC(std::string Str)
void UpgradeARCRuntime(Module &M)
Convert calls to ARC runtime functions to intrinsic calls and upgrade the old retain release marker t...
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space...
The two locations do not alias at all.
detail::ValueMatchesPoly< M > HasValue(M Matcher)
*p = old <unsigned v ? old : v
static Constant * getExtractElement(Constant *Vec, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM...
uint64_t Info
Additional information for the resolution:
Like Internal, but omit from symbol table.
Expected< std::unique_ptr< ModuleSummaryIndex > > getSummary()
Parse the specified bitcode buffer, returning the module summary index.
void UpgradeInlineAsmString(std::string *AsmStr)
Upgrade comment in call to inline asm that represents an objc retain release marker.
*p = old >unsigned v ? old : v
virtual std::string message() const
Return the error message as a string.
This instruction constructs a fixed permutation of two input vectors.
const BasicBlock & back() const
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", Instruction *InsertBefore=nullptr, Instruction *MDFrom=nullptr)
Externally visible function.
Minimum number of bits that can be specified.
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...
bool isTerminator() const
void deleteValue()
Delete a pointer to a generic Value.
The data referenced by the COMDAT must be the same size.
void setNoInfs(bool B=true)
AttrBuilder & addDereferenceableAttr(uint64_t Bytes)
This turns the number of dereferenceable bytes into the form used internally in Attribute.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
bool stripDebugInfo(Function &F)
Type * getStructElementType(unsigned N) const
static bool isLoadableOrStorableType(Type *ElemTy)
Return true if we can load or store from a pointer to this type.
MaybeAlign decodeMaybeAlign(unsigned Value)
Dual operation of the encode function above.
An instruction for reading from memory.
static Attribute::AttrKind getAttrFromCode(uint64_t Code)
bool hasExternalWeakLinkage() const
AttrBuilder & addAttribute(Attribute::AttrKind Val)
Add an attribute to the builder.
an instruction that atomically reads a memory location, combines it with another value, and then stores the result back.
static Type * getMetadataTy(LLVMContext &C)
Kind
Specifies which kind of type check we should emit for this byte array.
bool isVectorTy() const
True if this is an instance of VectorType.
Error takeError()
Take ownership of the stored error.
static bool isValidArgumentType(Type *ArgTy)
Return true if the specified type is valid as an argument type.
std::string getGlobalIdentifier() const
Return the modified name for this global value suitable to be used as the key for a global lookup (e...
Synchronized with respect to signal handlers executing in the same thread.
void UpgradeIntrinsicCall(CallInst *CI, Function *NewFn)
This is the complement to the above, replacing a specific call to an intrinsic function with a call t...
Base class for error info classes.
static Type * getX86_MMXTy(LLVMContext &C)
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.
void setBlockInfo(BitstreamBlockInfo *BI)
Set the block info to be used by this BitstreamCursor to interpret abbreviated records.
bool isPPC_FP128Ty() const
Return true if this is powerpc long double.
*p = old >signed v ? old : v
static CallBrInst * Create(FunctionType *Ty, Value *Func, BasicBlock *DefaultDest, ArrayRef< BasicBlock *> IndirectDests, ArrayRef< Value *> Args, const Twine &NameStr, Instruction *InsertBefore=nullptr)
StringRef StrtabForSymtab
std::map< uint64_t, WholeProgramDevirtResolution > WPDRes
Mapping from byte offset to whole-program devirt resolution for that (typeid, byte offset) pair...
static Type * getX86_FP80Ty(LLVMContext &C)
static GlobalVariable::UnnamedAddr getDecodedUnnamedAddrType(unsigned Val)
static Constant * get(ArrayType *T, ArrayRef< Constant *> V)
static LandingPadInst * Create(Type *RetTy, unsigned NumReservedClauses, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedClauses is a hint for the number of incoming clauses that this landingpad w...
static bool isLocalLinkage(LinkageTypes Linkage)
static Constant * getInsertElement(Constant *Vec, Constant *Elt, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
static ReturnInst * Create(LLVMContext &C, Value *retVal=nullptr, Instruction *InsertBefore=nullptr)
void addOriginalName(GlobalValue::GUID ValueGUID, GlobalValue::GUID OrigGUID)
Add an original name for the value of the given GUID.
bool canSkipToPos(size_t pos) const
void setIndirectSymbol(Constant *Symbol)
These methods set and retrieve indirect symbol.
static void inferDSOLocal(GlobalValue *GV)
unsigned getAllocaAddrSpace() const
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
GlobalValue::GUID getGUID() const
static bool castIsValid(Instruction::CastOps op, Value *S, Type *DstTy)
This method can be used to determine if a cast from S to DstTy using Opcode op is valid or not...
Expected< BitstreamEntry > advance(unsigned Flags=0)
Advance the current bitstream, returning the next entry in the stream.
static Type * getTokenTy(LLVMContext &C)
Expected< std::vector< BitcodeModule > > getBitcodeModuleList(MemoryBufferRef Buffer)
Returns a list of modules in the specified bitcode buffer.
AttrBuilder & addDereferenceableOrNullAttr(uint64_t Bytes)
This turns the number of dereferenceable_or_null bytes into the form used internally in Attribute...
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
ModuleInfo * getModule(StringRef ModPath)
Return module entry for module with the given ModPath.
static Type * getFloatTy(LLVMContext &C)
Expected< BitcodeLTOInfo > getLTOInfo()
Returns information about the module to be used for LTO: whether to compile with ThinLTO, and whether it has a summary.
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
bool isFloatingPointTy() const
Return true if this is one of the six floating-point types.
uint64_t getArrayNumElements() const
StringRef saveString(StringRef String)
Class to represent struct types.
A Use represents the edge between a Value definition and its users.
static bool getDecodedDSOLocal(unsigned Val)
bool isIntegerTy() const
True if this is an instance of IntegerType.
void setThreadLocalMode(ThreadLocalMode Val)
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 setSkipModuleByDistributedBackend()
std::error_code make_error_code(BitcodeError E)
This file contains the simple types necessary to represent the attributes associated with functions a...
No attributes have been set.
The linker may choose any COMDAT.
Error SkipBlock()
Having read the ENTER_SUBBLOCK abbrevid and a BlockID, skip over the body of this block...
bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const
check if an attributes is in the list of attributes.
AttrBuilder & addByValAttr(Type *Ty)
This turns a byval type into the form used internally in Attribute.
static Expected< BitstreamCursor > initStream(MemoryBufferRef Buffer)
void setName(const Twine &Name)
Change the name of the value.
Tagged union holding either a T or a Error.
uint64_t getNumElements() const
For scalable vectors, this will return the minimum number of elements in the vector.
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
static Type * getPPC_FP128Ty(LLVMContext &C)
void setDLLStorageClass(DLLStorageClassTypes C)
static StructType * get(LLVMContext &Context, ArrayRef< Type *> Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Determine whether the argument or parameter has the given attribute.
This file implements a class to represent arbitrary precision integral constant values and operations...
void setWithGlobalValueDeadStripping()
AtomicOrdering
Atomic ordering for LLVM's memory model.
enum llvm::WholeProgramDevirtResolution::Kind TheKind
static GlobalValue::LinkageTypes getDecodedLinkage(unsigned Val)
StringRef str() const
Explicit conversion to StringRef.
static Expected< StringRef > readBlobInRecord(BitstreamCursor &Stream, unsigned Block, unsigned RecordID)
AttributeList getAttributes(LLVMContext &C, ID id)
Return the attributes for an intrinsic.
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
void setPartition(StringRef Part)
void emitError(unsigned LocCookie, const Twine &ErrorStr)
emitError - Emit an error message to the currently installed error handler with optional location inf...
llvm::Optional< Function * > remangleIntrinsicFunction(Function *F)
Class to represent function types.
static Type * getLabelTy(LLVMContext &C)
Expected< unsigned > skipRecord(unsigned AbbrevID)
Read the current record and discard it, returning the code for the record.
void setCleanup(bool V)
Indicate that this landingpad instruction is a cleanup.
Type * getType() const
All values are typed, get the type of this value.
std::pair< ValueInfo, CalleeInfo > EdgeTy
<CalleeValueInfo, CalleeInfo> call edge pair.
BinOp
This enumeration lists the possible modifications atomicrmw can make.
Class to represent array types.
VisibilityTypes
An enumeration for the kinds of visibility of global values.
static void parseTypeIdSummaryRecord(ArrayRef< uint64_t > Record, StringRef Strtab, ModuleSummaryIndex &TheIndex)
Basic information extracted from a bitcode module to be used for LTO.
This instruction compares its operands according to the predicate given to the constructor.
static Constant * getSelect(Constant *C, Constant *V1, Constant *V2, Type *OnlyIfReducedTy=nullptr)
Select constant expr.
void setComdat(Comdat *C)
bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
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"))
TypeIdSummary & getOrInsertTypeIdSummary(StringRef TypeId)
Return an existing or new TypeIdSummary entry for TypeId.
bool UpgradeIntrinsicFunction(Function *F, Function *&NewFn)
This is a more granular function that simply checks an intrinsic function for upgrading, and returns true if it requires upgrading.
An instruction for storing to memory.
ArrayRef< uint8_t > getBitcodeBytes() const
bool hasPersonalityFn() const
Check whether this function has a personality function.
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Maximum number of bits that can be specified.
static const fltSemantics & IEEEdouble() LLVM_READNONE
static constexpr uint64_t BitcodeSummaryVersion
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
void setBody(ArrayRef< Type *> Elements, bool isPacked=false)
Specify a body for an opaque identified type.
Class to hold module path string table and global value map, and encapsulate methods for operating on...
AttrBuilder & addAllocSizeAttrFromRawRepr(uint64_t RawAllocSizeRepr)
Add an allocsize attribute, using the representation returned by Attribute.getIntValue().
static GlobalValue::DLLStorageClassTypes getDecodedDLLStorageClass(unsigned Val)
void setIsMaterializable(bool V)
const std::error_category & BitcodeErrorCategory()
Class to represent pointers.
bool UpgradeModuleFlags(Module &M)
This checks for module flags which should be upgraded.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
iterator find(const_arg_type_t< KeyT > Val)
bool isVoidTy() const
Return true if this is 'void'.
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
ExternalWeak linkage description.
Expected< std::string > getBitcodeProducerString(MemoryBufferRef Buffer)
Read the header of the specified bitcode buffer and extract just the producer string information...
void setCallingConv(CallingConv::ID CC)
Same, but only replaced by something equivalent.
size_t SizeInBytes() const
Return the size of the stream in bytes.
initializer< Ty > init(const Ty &Val)
static Expected< BitcodeModule > getSingleModule(MemoryBufferRef Buffer)
void setSubprogram(DISubprogram *SP)
Set the attached subprogram.
No other Module may specify this COMDAT.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
bool isLabelTy() const
Return true if this is 'label'.
The landingpad instruction holds all of the information necessary to generate correct exception handl...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void setCalledFunction(Value *V)
Set the callee to the specified value.
void setNoSignedZeros(bool B=true)
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
uint64_t getCurrentByteNo() const
size_t getBufferSize() const
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
unsigned arg_size() const
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
static Expected< std::string > readIdentificationCode(BitstreamCursor &Stream)
This is an important class for using LLVM in a threaded context.
static Constant * getFP(LLVMContext &Context, ArrayRef< uint16_t > Elts)
getFP() constructors - Return a constant with array type with an element count and element type of fl...
PowerPC Reduce CR logical Operation
static BlockAddress * get(Function *F, BasicBlock *BB)
Return a BlockAddress for the specified function and basic block.
static void parseWholeProgramDevirtResolution(ArrayRef< uint64_t > Record, StringRef Strtab, size_t &Slot, TypeIdSummary &TypeId)
size_t size() const
size - Get the array size.
This function has undefined behavior.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
static bool hasImplicitComdat(size_t Val)
This represents a position within a bitcode file, implemented on top of a SimpleBitstreamCursor.
static Expected< bool > hasObjCCategory(BitstreamCursor &Stream)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
void setUsedWithInAlloca(bool V)
Specify whether this alloca is used to represent the arguments to a call.
bool isPointerTy() const
True if this is an instance of PointerType.
Indirect Branch Instruction.
static Constant * getFP(LLVMContext &Context, ArrayRef< uint16_t > Elts)
getFP() constructors - Return a constant with vector type with an element count and element type of f...
std::error_code getError() const
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
bool UpgradeDebugInfo(Module &M)
Check the debug info version number, if it is out-dated, drop the debug info.
Class to accumulate and hold information about a callee.
iterator_range< use_iterator > materialized_uses()
static void upgradeDLLImportExportLinkage(GlobalValue *GV, unsigned Val)
static Constant * getShuffleVector(Constant *V1, Constant *V2, Constant *Mask, Type *OnlyIfReducedTy=nullptr)
static ManagedStatic< _object_error_category > error_category
This file declares a class to represent arbitrary precision floating point values and provide a varie...
static Type * getVoidTy(LLVMContext &C)
GlobalVariable * UpgradeGlobalVariable(GlobalVariable *GV)
This checks for global variables which should be upgraded.
Expected< Optional< BitstreamBlockInfo > > ReadBlockInfoBlock(bool ReadBlockInfoNames=false)
Read and return a block info block from the bitstream.
const Instruction & back() const
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
AttrBuilder & addAlignmentAttr(MaybeAlign Align)
This turns an alignment into the form used internally in Attribute.
TypeIdCompatibleVtableInfo & getOrInsertTypeIdCompatibleVtableSummary(StringRef TypeId)
Return an existing or new TypeIdCompatibleVtableMap entry for TypeId.
This instruction compares its operands according to the predicate given to the constructor.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
std::string UpgradeDataLayoutString(StringRef DL, StringRef Triple)
Upgrade the datalayout string by adding a section for address space pointers.
constexpr char TypeName[]
Key for Kernel::Arg::Metadata::mTypeName.
void addClause(Constant *ClauseVal)
Add a catch or filter clause to the landing pad.
Expected< std::string > getBitcodeTargetTriple(MemoryBufferRef Buffer)
Read the header of the specified bitcode buffer and extract just the triple information.
DLLStorageClassTypes
Storage classes of global values for PE targets.
static FunctionType * get(Type *Result, ArrayRef< Type *> Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
static Error error(const Twine &Message)
static Constant * get(StructType *T, ArrayRef< Constant *> V)
static Attribute getWithByValType(LLVMContext &Context, Type *Ty)
unsigned getStructNumElements() const
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
void setPartiallySplitLTOUnits()
Error readModuleSummaryIndex(MemoryBufferRef Buffer, ModuleSummaryIndex &CombinedIndex, uint64_t ModuleId)
Parse the specified bitcode buffer and merge the index into CombinedIndex.
static Constant * getICmp(unsigned short pred, Constant *LHS, Constant *RHS, bool OnlyIfReduced=false)
get* - Return some common constants without having to specify the full Instruction::OPCODE identifier...
static const fltSemantics & x87DoubleExtended() LLVM_READNONE
bool isMaterializable() const
enum llvm::WholeProgramDevirtResolution::ByArg::Kind TheKind
The highest possible calling convention ID. Must be some 2^k - 1.
The data referenced by the COMDAT must be the same.
Expected< BitcodeFileContents > getBitcodeFileContents(MemoryBufferRef Buffer)
Returns the contents of a bitcode file.
Sentinal value useful for loops.
Function and variable summary information to aid decisions and implementation of importing.
static bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
This class represents the va_arg llvm instruction, which returns an argument of the specified type gi...
static Attribute::AttrKind parseAttrKind(StringRef Kind)
unsigned getAbbrevIDWidth() const
Return the number of bits used to encode an abbrev #.
static UnaryOperator * Create(UnaryOps Op, Value *S, const Twine &Name=Twine(), Instruction *InsertBefore=nullptr)
Construct a unary instruction, given the opcode and an operand.
static GlobalValue::VisibilityTypes getDecodedVisibility(unsigned Val)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
std::unique_ptr< Module > parseModule(const uint8_t *Data, size_t Size, LLVMContext &Context)
Fuzzer friendly interface for the llvm bitcode parser.
static IndirectBrInst * Create(Value *Address, unsigned NumDests, Instruction *InsertBefore=nullptr)
void setWithAttributePropagation()
Triple - Helper class for working with autoconf configuration names.
static Error hasInvalidBitcodeHeader(BitstreamCursor &Stream)
static Type * getFP128Ty(LLVMContext &C)
Synchronized with respect to all concurrently executing threads.
Error JumpToBit(uint64_t BitNo)
Reset the stream to the specified bit number.
static Comdat::SelectionKind getDecodedComdatSelectionKind(unsigned Val)
Expected< unsigned > readRecord(unsigned AbbrevID, SmallVectorImpl< uint64_t > &Vals, StringRef *Blob=nullptr)
Struct that holds a reference to a particular GUID in a global value summary.
constexpr bool empty(const T &RangeOrContainer)
Test whether RangeOrContainer is empty. Similar to C++17 std::empty.
static AtomicOrdering getStrongestFailureOrdering(AtomicOrdering SuccessOrdering)
Returns the strongest permitted ordering on failure, given the desired ordering on success...
static Expected< bool > getEnableSplitLTOUnitFlag(BitstreamCursor &Stream, unsigned ID)
static Constant * getFCmp(unsigned short pred, Constant *LHS, Constant *RHS, bool OnlyIfReduced=false)
static Type * getHalfTy(LLVMContext &C)
const InstListType & getInstList() const
Return the underlying instruction list container.
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
static const fltSemantics & IEEEsingle() LLVM_READNONE
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Adds the attribute to the indicated argument.
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...
static void addRawAttributeValue(AttrBuilder &B, uint64_t Val)
static ErrorSuccess success()
Create a success value.
ModuleInfo * addModule(StringRef ModPath, uint64_t ModId, ModuleHash Hash=ModuleHash{{0}})
Add a new module with the given Hash, mapped to the given ModID, and return a reference to the module...
Iterator for intrusive lists based on ilist_node.
Expected< bool > isBitcodeContainingObjCCategory(MemoryBufferRef Buffer)
Return true if Buffer contains a bitcode file with ObjC code (category or class) in it...
void setHasSyntheticEntryCounts()
static const unsigned MaxAlignmentExponent
The maximum alignment for instructions.
static bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
When advancing through a bitstream cursor, each advance can discover a few different kinds of entries...
This is the shared class of boolean and integer constants.
void setSelectionKind(SelectionKind Val)
static void parseWholeProgramDevirtResolutionByArg(ArrayRef< uint64_t > Record, size_t &Slot, WholeProgramDevirtResolution &Wpd)
static const fltSemantics & IEEEhalf() LLVM_READNONE
static CleanupPadInst * Create(Value *ParentPad, ArrayRef< Value *> Args=None, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
static CatchSwitchInst * Create(Value *ParentPad, BasicBlock *UnwindDest, unsigned NumHandlers, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
static SwitchInst * Create(Value *Value, BasicBlock *Default, unsigned NumCases, Instruction *InsertBefore=nullptr)
This struct is a compact representation of a valid (power of two) or undefined (0) alignment...
static Expected< std::string > readIdentificationBlock(BitstreamCursor &Stream)
Read the "IDENTIFICATION_BLOCK_ID" block, do some basic enforcement on the "epoch" encoded in the bit...
Keep one copy of function when linking (inline)
Module.h This file contains the declarations for the Module class.
void setApproxFunc(bool B=true)
This class maintains the abbreviations read from a block info block.
This class represents a freeze function that returns random concrete value if an operand is either a ...
Type * getReturnType() const
virtual std::error_code convertToErrorCode() const =0
Convert this error to a std::error_code.
reference get()
Returns a reference to the stored T value.
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
The linker will choose the largest COMDAT.
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
static Constant * get(Type *Ty, double V)
This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in...
AttrBuilder & addStackAlignmentAttr(MaybeAlign Align)
This turns a stack alignment into the form used internally in Attribute.
void setAttributes(AttributeList Attrs)
Set the attribute list for this Function.
void setLinkage(LinkageTypes LT)
std::string SingleImplName
enum llvm::TypeTestResolution::Kind TheKind
static GlobalVariable::ThreadLocalMode getDecodedThreadLocalMode(unsigned Val)
void setNoNaNs(bool B=true)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
unsigned getVectorNumElements() const
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Class to represent vector types.
Value * getValueFwdRef(unsigned Idx, Type *Ty, Type **FullTy=nullptr)
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...
Class for arbitrary precision integers.
static int getDecodedCastOpcode(unsigned Val)
void push_back(pointer val)
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
LinkageTypes
An enumeration for the kinds of linkage for global values.
amdgpu Simplify well known AMD library false FunctionCallee Callee
static BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name=Twine(), Instruction *InsertBefore=nullptr)
Construct a binary instruction, given the opcode and the two operands.
StringRef getBufferIdentifier() const
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
void setAttributes(AttributeSet A)
Set attribute list for this global.
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array...
void UpgradeFramePointerAttributes(AttrBuilder &B)
Upgrade function attributes "no-frame-pointer-elim" and "no-frame-pointer-elim-non-leaf" to "frame-po...
ValueInfo getOrInsertValueInfo(GlobalValue::GUID GUID)
Return a ValueInfo for GUID.
static CatchPadInst * Create(Value *CatchSwitch, ArrayRef< Value *> Args, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
void setSwiftError(bool V)
Specify whether this alloca is used to represent a swifterror.
bool isX86_FP80Ty() const
Return true if this is x86 long double.
Expected< std::unique_ptr< Module > > parseBitcodeFile(MemoryBufferRef Buffer, LLVMContext &Context)
Read the specified bitcode file, returning the module.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFileOrSTDIN(const Twine &Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true)
Open the specified file as a MemoryBuffer, or open stdin if the Filename is "-".
static const fltSemantics & PPCDoubleDouble() LLVM_READNONE
std::set< std::string > & cfiFunctionDefs()
static CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
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 Expected< bool > hasObjCCategoryInModule(BitstreamCursor &Stream)
Function to be accessible from DLL.
Expected< BitcodeLTOInfo > getBitcodeLTOInfo(MemoryBufferRef Buffer)
Returns LTO information for the specified bitcode file.
Error EnterSubBlock(unsigned BlockID, unsigned *NumWordsP=nullptr)
Having read the ENTER_SUBBLOCK abbrevid, and enter the block.
static AtomicRMWInst::BinOp getDecodedRMWOperation(unsigned Val)
std::map< std::vector< uint64_t >, ByArg > ResByArg
Resolutions for calls with all constant integer arguments (excluding the first argument, "this"), where the key is the argument vector.
bool isFunctionTy() const
True if this is an instance of FunctionType.
ValID - Represents a reference of a definition of some sort with no type.
void setAlignment(MaybeAlign Align)
pointer data()
Return a pointer to the vector's buffer, even if empty().
void setUnnamedAddr(UnnamedAddr Val)
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...
static IntegerType * getInt32Ty(LLVMContext &C)
static int getDecodedUnaryOpcode(unsigned Val, Type *Ty)
Linkage
Describes symbol linkage.
LLVM_NODISCARD bool empty() const
void setAllowContract(bool B=true)
static InvokeInst * Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value *> Args, const Twine &NameStr, Instruction *InsertBefore=nullptr)
void addGlobalValueSummary(const GlobalValue &GV, std::unique_ptr< GlobalValueSummary > Summary)
Add a global value summary for a value.
static bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
static InsertValueInst * Create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
StringRef getName() const
Return a constant reference to the value's name.
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Removes the attribute from the given argument.
Expected< BitstreamEntry > advanceSkippingSubblocks(unsigned Flags=0)
This is a convenience function for clients that don't expect any subblocks.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Type * getValueType() const
void setOriginalName(GlobalValue::GUID Name)
Initialize the original name hash in this summary.
Keep one copy of named function when linking (weak)
Rename collisions when linking (static functions).
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it...
void setAllowReciprocal(bool B=true)
Flags specific to function summaries.
StringMapEntry< Value * > ValueName
static InlineAsm * get(FunctionType *Ty, StringRef AsmString, StringRef Constraints, bool hasSideEffects, bool isAlignStack=false, AsmDialect asmDialect=AD_ATT)
InlineAsm::get - Return the specified uniqued inline asm string.
GlobalValueSummary * findSummaryInModule(ValueInfo VI, StringRef ModuleId) const
Find the summary for ValueInfo VI in module ModuleId, or nullptr if not found.
unsigned SizeM1BitWidth
Range of size-1 expressed as a bit width.
void setModulePath(StringRef ModPath)
Set the path to the module containing this function, for use in the combined index.
Function to be imported from DLL.
std::string str() const
Return the twine contents as a std::string.
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...
OutputIt transform(R &&Range, OutputIt d_first, UnaryPredicate P)
Wrapper function around std::transform to apply a function to a range and store the result elsewhere...
void addDestination(BasicBlock *Dest)
Add a destination.
Provides ErrorOr<T> smart pointer.
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
static void decodeLLVMAttributesForBitcode(AttrBuilder &B, uint64_t EncodedAttrs)
This fills an AttrBuilder object with the LLVM attributes that have been decoded from the given integ...
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Expected< std::unique_ptr< Module > > getOwningLazyBitcodeModule(std::unique_ptr< MemoryBuffer > &&Buffer, LLVMContext &Context, bool ShouldLazyLoadMetadata=false, bool IsImporting=false)
Like getLazyBitcodeModule, except that the module takes ownership of the memory buffer if successful...
static Expected< std::string > readModuleTriple(BitstreamCursor &Stream)
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
std::set< std::string > & cfiFunctionDecls()
static void stripTBAA(Module *M)
const char * getBufferStart() const
std::vector< VirtFuncOffset > VTableFuncList
List of functions referenced by a particular vtable definition.
std::error_code errorToErrorCodeAndEmitErrors(LLVMContext &Ctx, Error Err)
static CatchReturnInst * Create(Value *CatchPad, BasicBlock *BB, Instruction *InsertBefore=nullptr)
Module * getParent()
Get the module that this global value is contained inside of...
Verify that the TBAA Metadatas are valid.
LLVM Value Representation.
Constant * getPersonalityFn() const
Get the personality function associated with this function.
Expected< std::unique_ptr< ModuleSummaryIndex > > getModuleSummaryIndex(MemoryBufferRef Buffer)
Parse the specified bitcode buffer, returning the module summary index.
static StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Lightweight error class with error context and mandatory checking.
static CleanupReturnInst * Create(Value *CleanupPad, BasicBlock *UnwindBB=nullptr, Instruction *InsertBefore=nullptr)
static Expected< uint64_t > jumpToValueSymbolTable(uint64_t Offset, BitstreamCursor &Stream)
Helper to note and return the current location, and jump to the given offset.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
AttributeSet getFnAttributes() const
The function attributes are returned.
static Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
Group flags (Linkage, NotEligibleToImport, etc.) as a bitfield.
bool hasDefaultVisibility() const
Expected< std::unique_ptr< Module > > getLazyModule(LLVMContext &Context, bool ShouldLazyLoadMetadata, bool IsImporting)
Read the bitcode module and prepare for lazy deserialization of function bodies.
Type * getElementType() const
Expected< std::unique_ptr< Module > > parseModule(LLVMContext &Context)
Read the entire bitcode module and return it.
Convenience struct for specifying and reasoning about fast-math flags.
StringRef - Represent a constant reference to a string, i.e.
inst_range instructions(Function *F)
static ManagedStatic< BitcodeErrorCategoryType > ErrorCategory
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
Type * getArrayElementType() const
enum llvm::BitstreamEntry::@159 Kind
void setPersonalityFn(Constant *Fn)
Value * UpgradeBitCastExpr(unsigned Opc, Constant *C, Type *DestTy)
This is an auto-upgrade for bitcast constant expression between pointers with different address space...
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 GlobalValueSummary::GVFlags getDecodedGVSummaryFlags(uint64_t RawFlags, uint64_t Version)
Decode the flags for GlobalValue in the summary.
void setAllowReassoc(bool B=true)
Flag setters.
Expected< word_t > Read(unsigned NumBits)
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
unsigned ReturnDoesNotAlias
static Type * getGEPReturnType(Type *ElTy, Value *Ptr, ArrayRef< Value *> IdxList)
Returns the pointer type returned by the GEP instruction, which may be a vector of pointers...
void setSection(StringRef S)
Change the section for this global.
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 Constant * get(ArrayRef< Constant *> V)
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
static void setSpecialRefs(std::vector< ValueInfo > &Refs, unsigned ROCnt, unsigned WOCnt)
void setDSOLocal(bool Local)
PointerType * getType() const
Global values are always pointers.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
static AttributeList get(LLVMContext &C, ArrayRef< std::pair< unsigned, Attribute >> Attrs)
Create an AttributeList with the specified parameters in it.
iterator_range< arg_iterator > args()
static FastMathFlags getDecodedFastMathFlags(unsigned Val)
std::vector< BitcodeModule > Mods
bool isStructTy() const
True if this is an instance of StructType.
bool empty() const
empty - Check if the array is empty.
bool isArrayTy() const
True if this is an instance of ArrayType.
static GlobalVarSummary::GVarFlags getDecodedGVarFlags(uint64_t RawFlags)
an instruction to allocate memory on the stack
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results...
static Constant * get(unsigned Opcode, Constant *C1, unsigned Flags=0, Type *OnlyIfReducedTy=nullptr)
get - Return a unary operator constant expression, folding if possible.
static FunctionSummary::FFlags getDecodedFFlags(uint64_t RawFlags)
static uint64_t getRawAttributeMask(Attribute::AttrKind Val)