26 #include "llvm/Config/llvm-config.h" 84 #include <system_error> 94 "Print the global id for each value when reading the module summary"));
99 SWITCH_INST_MAGIC = 0x4B5
105 return make_error<StringError>(
113 Stream.
Read(8) !=
'B' ||
114 Stream.
Read(8) !=
'C' ||
115 Stream.
Read(4) != 0x0 ||
116 Stream.
Read(4) != 0xC ||
117 Stream.
Read(4) != 0xE ||
118 Stream.
Read(4) != 0xD)
124 const unsigned char *BufPtr = (
const unsigned char *)Buffer.
getBufferStart();
125 const unsigned char *BufEnd = BufPtr + Buffer.
getBufferSize();
128 return error(
"Invalid bitcode signature");
134 return error(
"Invalid bitcode wrapper header");
138 return error(
"Invalid bitcode signature");
140 return std::move(Stream);
144 template <
typename StrTy>
147 if (Idx > Record.
size())
150 for (
unsigned i = Idx, e = Record.
size(); i != e; ++i)
151 Result += (
char)Record[i];
158 if (
F.isMaterializable())
169 return error(
"Invalid record");
174 std::string ProducerIdentification;
179 switch (Entry.
Kind) {
182 return error(
"Malformed block");
184 return ProducerIdentification;
195 return error(
"Invalid value");
200 unsigned epoch = (
unsigned)Record[0];
203 Twine(
"Incompatible epoch: Bitcode '") +
Twine(epoch) +
219 switch (Entry.
Kind) {
222 return error(
"Malformed block");
230 return error(
"Malformed block");
241 return error(
"Invalid record");
249 switch (Entry.
Kind) {
252 return error(
"Malformed block");
267 return error(
"Invalid record");
269 if (S.find(
"__DATA,__objc_catlist") != std::string::npos ||
270 S.find(
"__OBJC,__category") != std::string::npos)
286 switch (Entry.
Kind) {
288 return error(
"Malformed block");
298 return error(
"Malformed block");
310 return error(
"Invalid record");
320 switch (Entry.
Kind) {
323 return error(
"Malformed block");
337 return error(
"Invalid record");
353 switch (Entry.
Kind) {
355 return error(
"Malformed block");
365 return error(
"Malformed block");
377 class BitcodeReaderBase {
380 : Stream(std::move(Stream)), Strtab(Strtab) {
390 bool UseStrtab =
false;
397 std::pair<StringRef, ArrayRef<uint64_t>>
400 bool readBlockInfo();
403 std::string ProducerIdentification;
411 std::string FullMsg = Message.
str();
412 if (!ProducerIdentification.empty())
413 FullMsg +=
" (Producer: '" + ProducerIdentification +
"' Reader: 'LLVM " +
414 LLVM_VERSION_STRING
"')";
421 return error(
"Invalid record");
422 unsigned ModuleVersion = Record[0];
423 if (ModuleVersion > 2)
424 return error(
"Invalid value");
425 UseStrtab = ModuleVersion >= 2;
426 return ModuleVersion;
429 std::pair<StringRef, ArrayRef<uint64_t>>
434 if (Record[0] + Record[1] > Strtab.
size())
436 return {
StringRef(Strtab.data() + Record[0], Record[1]), Record.
slice(2)};
441 class BitcodeReader :
public BitcodeReaderBase,
public GVMaterializer {
443 Module *TheModule =
nullptr;
445 uint64_t NextUnreadBit = 0;
447 uint64_t LastFunctionBlockBit = 0;
448 bool SeenValueSymbolTable =
false;
449 uint64_t VSTOffset = 0;
451 std::vector<std::string> SectionTable;
452 std::vector<std::string> GCTable;
454 std::vector<Type*> TypeList;
457 std::vector<Comdat *> ComdatList;
460 std::vector<std::pair<GlobalVariable *, unsigned>> GlobalInits;
461 std::vector<std::pair<GlobalIndirectSymbol *, unsigned>> IndirectSymbolInits;
462 std::vector<std::pair<Function *, unsigned>> FunctionPrefixes;
463 std::vector<std::pair<Function *, unsigned>> FunctionPrologues;
464 std::vector<std::pair<Function *, unsigned>> FunctionPersonalityFns;
468 std::vector<AttributeList> MAttributes;
471 std::map<unsigned, AttributeList> MAttributeGroups;
475 std::vector<BasicBlock*> FunctionBBs;
479 std::vector<Function*> FunctionsWithBodies;
484 UpdatedIntrinsicMap UpgradedIntrinsics;
486 UpdatedIntrinsicMap RemangledIntrinsics;
491 bool SeenFirstFunctionBody =
false;
500 std::vector<uint64_t> DeferredMetadataInfo;
506 std::deque<Function *> BasicBlockFwdRefQueue;
514 bool UseRelativeIDs =
false;
518 bool WillMaterializeAllForwardRefs =
false;
523 std::vector<std::string> BundleTags;
530 Error materializeForwardReferencedFunctions();
533 Error materializeModule()
override;
534 std::vector<StructType *> getIdentifiedStructTypes()
const override;
538 Error parseBitcodeInto(
Module *M,
bool ShouldLazyLoadMetadata =
false,
539 bool IsImporting =
false);
541 static uint64_t decodeSignRotatedValue(uint64_t V);
544 Error materializeMetadata()
override;
546 void setStripDebugInfo()
override;
549 std::vector<StructType *> IdentifiedStructTypes;
553 Type *getTypeByID(
unsigned ID);
555 Value *getFnValueByID(
unsigned ID,
Type *Ty) {
561 Metadata *getFnMetadataByID(
unsigned ID) {
565 BasicBlock *getBasicBlock(
unsigned ID)
const {
566 if (ID >= FunctionBBs.size())
return nullptr;
567 return FunctionBBs[
ID];
571 if (i-1 < MAttributes.size())
572 return MAttributes[i-1];
580 unsigned InstNum,
Value *&ResVal) {
581 if (Slot == Record.
size())
return true;
582 unsigned ValNo = (
unsigned)Record[Slot++];
585 ValNo = InstNum - ValNo;
586 if (ValNo < InstNum) {
589 ResVal = getFnValueByID(ValNo,
nullptr);
590 return ResVal ==
nullptr;
592 if (Slot == Record.
size())
595 unsigned TypeNo = (
unsigned)Record[Slot++];
596 ResVal = getFnValueByID(ValNo, getTypeByID(TypeNo));
597 return ResVal ==
nullptr;
604 unsigned InstNum,
Type *Ty,
Value *&ResVal) {
605 if (getValue(Record, Slot, InstNum, Ty, ResVal))
614 unsigned InstNum,
Type *Ty,
Value *&ResVal) {
615 ResVal = getValue(Record, Slot, InstNum, Ty);
616 return ResVal ==
nullptr;
622 unsigned InstNum,
Type *Ty) {
623 if (Slot == Record.
size())
return nullptr;
624 unsigned ValNo = (
unsigned)Record[Slot];
627 ValNo = InstNum - ValNo;
628 return getFnValueByID(ValNo, Ty);
633 unsigned InstNum,
Type *Ty) {
634 if (Slot == Record.
size())
return nullptr;
635 unsigned ValNo = (
unsigned)decodeSignRotatedValue(Record[Slot]);
638 ValNo = InstNum - ValNo;
639 return getFnValueByID(ValNo, Ty);
645 Error parseAlignmentValue(uint64_t
Exponent,
unsigned &Alignment);
652 Error parseGlobalIndirectSymbolRecord(
unsigned BitCode,
655 Error parseAttributeBlock();
656 Error parseAttributeGroupBlock();
657 Error parseTypeTable();
658 Error parseTypeTableBody();
659 Error parseOperandBundleTags();
660 Error parseSyncScopeNames();
663 unsigned NameIndex,
Triple &TT);
664 void setDeferredFunctionInfo(
unsigned FuncBitcodeOffsetDelta,
Function *
F,
667 Error parseGlobalValueSymbolTable();
668 Error parseConstants();
669 Error rememberAndSkipFunctionBodies();
670 Error rememberAndSkipFunctionBody();
672 Error rememberAndSkipMetadata();
675 Error globalCleanup();
676 Error resolveGlobalAndIndirectSymbolInits();
677 Error parseUseLists();
678 Error findFunctionInStream(
687 class ModuleSummaryIndexBitcodeReader :
public BitcodeReaderBase {
693 bool SeenGlobalValSummary =
false;
696 bool SeenValueSymbolTable =
false;
700 uint64_t VSTOffset = 0;
711 ValueIdToValueInfoMap;
720 std::string SourceFileName;
733 StringRef ModulePath,
unsigned ModuleId);
741 Error parseValueSymbolTable(
746 bool IsOldProfileFormat,
749 Error parseEntireSummary(
unsigned ID);
750 Error parseModuleStringTable();
752 std::pair<ValueInfo, GlobalValue::GUID>
753 getValueInfoFromValueId(
unsigned ValueId);
755 void addThisModule();
771 return std::error_code();
777 : BitcodeReaderBase(std::move(Stream), Strtab),
Context(Context),
779 this->ProducerIdentification = ProducerIdentification;
782 Error BitcodeReader::materializeForwardReferencedFunctions() {
783 if (WillMaterializeAllForwardRefs)
787 WillMaterializeAllForwardRefs =
true;
789 while (!BasicBlockFwdRefQueue.empty()) {
790 Function *
F = BasicBlockFwdRefQueue.front();
791 BasicBlockFwdRefQueue.pop_front();
792 assert(F &&
"Expected valid function");
793 if (!BasicBlockFwdRefs.count(F))
802 return error(
"Never resolved function from blockaddress");
805 if (
Error Err = materialize(F))
808 assert(BasicBlockFwdRefs.empty() &&
"Function missing from queue");
811 WillMaterializeAllForwardRefs =
false;
876 Flags.
ReadOnly = (RawFlags >> 1) & 0x1;
879 Flags.
NoInline = (RawFlags >> 4) & 0x1;
890 RawFlags = RawFlags >> 4;
891 bool NotEligibleToImport = (RawFlags & 0x1) || Version < 3;
895 bool Live = (RawFlags & 0x2) || Version < 3;
896 bool Local = (RawFlags & 0x4);
928 case 0:
return false;
982 return IsFP ? Instruction::FNeg : -1;
998 return IsFP ? Instruction::FSub : Instruction::Sub;
1000 return IsFP ? Instruction::FMul : Instruction::Mul;
1002 return IsFP ? -1 : Instruction::UDiv;
1004 return IsFP ? Instruction::FDiv : Instruction::SDiv;
1006 return IsFP ? -1 : Instruction::URem;
1008 return IsFP ? Instruction::FRem : Instruction::SRem;
1010 return IsFP ? -1 : Instruction::Shl;
1012 return IsFP ? -1 : Instruction::LShr;
1014 return IsFP ? -1 : Instruction::AShr;
1016 return IsFP ? -1 : Instruction::And;
1018 return IsFP ? -1 : Instruction::Or;
1020 return IsFP ? -1 : Instruction::Xor;
1098 Type *BitcodeReader::getTypeByID(
unsigned ID) {
1100 if (ID >= TypeList.size())
1103 if (
Type *Ty = TypeList[ID])
1108 return TypeList[
ID] = createIdentifiedStructType(Context);
1114 IdentifiedStructTypes.push_back(
Ret);
1120 IdentifiedStructTypes.push_back(
Ret);
1232 uint64_t EncodedAttrs) {
1237 unsigned Alignment = (EncodedAttrs & (0xffffULL << 16)) >> 16;
1239 "Alignment must be a power of two.");
1244 (EncodedAttrs & 0xffff));
1247 Error BitcodeReader::parseAttributeBlock() {
1249 return error(
"Invalid record");
1251 if (!MAttributes.empty())
1252 return error(
"Invalid multiple blocks");
1262 switch (Entry.
Kind) {
1265 return error(
"Malformed block");
1280 if (Record.
size() & 1)
1281 return error(
"Invalid record");
1283 for (
unsigned i = 0, e = Record.
size(); i != e; i += 2) {
1293 for (
unsigned i = 0, e = Record.
size(); i != e; ++i)
1294 Attrs.
push_back(MAttributeGroups[Record[i]]);
1430 unsigned &Alignment) {
1434 return error(
"Invalid alignment value");
1435 Alignment = (1 <<
static_cast<unsigned>(
Exponent)) >> 1;
1442 return error(
"Unknown attribute kind (" +
Twine(Code) +
")");
1446 Error BitcodeReader::parseAttributeGroupBlock() {
1448 return error(
"Invalid record");
1450 if (!MAttributeGroups.empty())
1451 return error(
"Invalid multiple blocks");
1459 switch (Entry.
Kind) {
1462 return error(
"Malformed block");
1476 if (Record.
size() < 3)
1477 return error(
"Invalid record");
1479 uint64_t GrpID = Record[0];
1480 uint64_t Idx = Record[1];
1483 for (
unsigned i = 2, e = Record.
size(); i != e; ++i) {
1484 if (Record[i] == 0) {
1490 }
else if (Record[i] == 1) {
1505 assert((Record[i] == 3 || Record[i] == 4) &&
1506 "Invalid attribute group entry");
1507 bool HasValue = (Record[i++] == 4);
1511 while (Record[i] != 0 && i != e)
1512 KindStr += Record[i++];
1513 assert(Record[i] == 0 &&
"Kind string not null terminated");
1518 while (Record[i] != 0 && i != e)
1519 ValStr += Record[i++];
1520 assert(Record[i] == 0 &&
"Value string not null terminated");
1534 Error BitcodeReader::parseTypeTable() {
1536 return error(
"Invalid record");
1538 return parseTypeTableBody();
1541 Error BitcodeReader::parseTypeTableBody() {
1542 if (!TypeList.empty())
1543 return error(
"Invalid multiple blocks");
1546 unsigned NumRecords = 0;
1554 switch (Entry.
Kind) {
1557 return error(
"Malformed block");
1559 if (NumRecords != TypeList.size())
1560 return error(
"Malformed block");
1569 Type *ResultTy =
nullptr;
1572 return error(
"Invalid value");
1576 if (Record.
size() < 1)
1577 return error(
"Invalid record");
1578 TypeList.resize(Record[0]);
1614 if (Record.
size() < 1)
1615 return error(
"Invalid record");
1617 uint64_t NumBits = Record[0];
1620 return error(
"Bitwidth for integer type out of range");
1626 if (Record.
size() < 1)
1627 return error(
"Invalid record");
1629 if (Record.
size() == 2)
1630 AddressSpace = Record[1];
1631 ResultTy = getTypeByID(Record[0]);
1634 return error(
"Invalid type");
1641 if (Record.
size() < 3)
1642 return error(
"Invalid record");
1644 for (
unsigned i = 3, e = Record.
size(); i != e; ++i) {
1645 if (
Type *
T = getTypeByID(Record[i]))
1651 ResultTy = getTypeByID(Record[2]);
1652 if (!ResultTy || ArgTys.
size() < Record.
size()-3)
1653 return error(
"Invalid type");
1660 if (Record.
size() < 2)
1661 return error(
"Invalid record");
1663 for (
unsigned i = 2, e = Record.
size(); i != e; ++i) {
1664 if (
Type *
T = getTypeByID(Record[i])) {
1666 return error(
"Invalid function argument type");
1673 ResultTy = getTypeByID(Record[1]);
1674 if (!ResultTy || ArgTys.
size() < Record.
size()-2)
1675 return error(
"Invalid type");
1681 if (Record.
size() < 1)
1682 return error(
"Invalid record");
1684 for (
unsigned i = 1, e = Record.
size(); i != e; ++i) {
1685 if (
Type *
T = getTypeByID(Record[i]))
1690 if (EltTys.
size() != Record.
size()-1)
1691 return error(
"Invalid type");
1697 return error(
"Invalid record");
1701 if (Record.
size() < 1)
1702 return error(
"Invalid record");
1704 if (NumRecords >= TypeList.size())
1705 return error(
"Invalid TYPE table");
1708 StructType *Res = cast_or_null<StructType>(TypeList[NumRecords]);
1711 TypeList[NumRecords] =
nullptr;
1713 Res = createIdentifiedStructType(Context, TypeName);
1717 for (
unsigned i = 1, e = Record.
size(); i != e; ++i) {
1718 if (
Type *
T = getTypeByID(Record[i]))
1723 if (EltTys.
size() != Record.
size()-1)
1724 return error(
"Invalid record");
1725 Res->
setBody(EltTys, Record[0]);
1730 if (Record.
size() != 1)
1731 return error(
"Invalid record");
1733 if (NumRecords >= TypeList.size())
1734 return error(
"Invalid TYPE table");
1737 StructType *Res = cast_or_null<StructType>(TypeList[NumRecords]);
1740 TypeList[NumRecords] =
nullptr;
1742 Res = createIdentifiedStructType(Context, TypeName);
1748 if (Record.
size() < 2)
1749 return error(
"Invalid record");
1750 ResultTy = getTypeByID(Record[1]);
1752 return error(
"Invalid type");
1756 if (Record.
size() < 2)
1757 return error(
"Invalid record");
1759 return error(
"Invalid vector length");
1760 ResultTy = getTypeByID(Record[1]);
1762 return error(
"Invalid type");
1767 if (NumRecords >= TypeList.size())
1768 return error(
"Invalid TYPE table");
1769 if (TypeList[NumRecords])
1771 "Invalid TYPE table: Only named structs can be forward referenced");
1772 assert(ResultTy &&
"Didn't read a type?");
1773 TypeList[NumRecords++] = ResultTy;
1777 Error BitcodeReader::parseOperandBundleTags() {
1779 return error(
"Invalid record");
1781 if (!BundleTags.empty())
1782 return error(
"Invalid multiple blocks");
1789 switch (Entry.
Kind) {
1792 return error(
"Malformed block");
1803 return error(
"Invalid record");
1806 BundleTags.emplace_back();
1808 return error(
"Invalid record");
1813 Error BitcodeReader::parseSyncScopeNames() {
1815 return error(
"Invalid record");
1818 return error(
"Invalid multiple synchronization scope names blocks");
1823 switch (Entry.
Kind) {
1826 return error(
"Malformed block");
1829 return error(
"Invalid empty synchronization scope names block");
1840 return error(
"Invalid record");
1844 return error(
"Invalid record");
1853 unsigned NameIndex,
Triple &TT) {
1856 return error(
"Invalid record");
1857 unsigned ValueID = Record[0];
1858 if (ValueID >= ValueList.size() || !ValueList[ValueID])
1859 return error(
"Invalid record");
1860 Value *V = ValueList[ValueID];
1864 return error(
"Invalid value name");
1868 if (GO->getComdat() ==
reinterpret_cast<Comdat *
>(1)) {
1872 GO->setComdat(
nullptr);
1899 void BitcodeReader::setDeferredFunctionInfo(
unsigned FuncBitcodeOffsetDelta,
1905 uint64_t FuncWordOffset = Record[1] - 1;
1906 uint64_t FuncBitOffset = FuncWordOffset * 32;
1907 DeferredFunctionInfo[
F] = FuncBitOffset + FuncBitcodeOffsetDelta;
1911 if (FuncBitOffset > LastFunctionBlockBit)
1912 LastFunctionBlockBit = FuncBitOffset;
1916 Error BitcodeReader::parseGlobalValueSymbolTable() {
1917 unsigned FuncBitcodeOffsetDelta =
1921 return error(
"Invalid record");
1927 switch (Entry.
Kind) {
1930 return error(
"Malformed block");
1940 setDeferredFunctionInfo(FuncBitcodeOffsetDelta,
1941 cast<Function>(ValueList[Record[0]]), Record);
1949 Error BitcodeReader::parseValueSymbolTable(uint64_t
Offset) {
1950 uint64_t CurrentBit;
1958 if (
Error Err = parseGlobalValueSymbolTable())
1978 unsigned FuncBitcodeOffsetDelta =
1982 return error(
"Invalid record");
1986 Triple TT(TheModule->getTargetTriple());
1994 switch (Entry.
Kind) {
1997 return error(
"Malformed block");
2028 if (
auto *F = dyn_cast<Function>(V))
2029 setDeferredFunctionInfo(FuncBitcodeOffsetDelta, F, Record);
2034 return error(
"Invalid record");
2037 return error(
"Invalid record");
2049 uint64_t BitcodeReader::decodeSignRotatedValue(uint64_t V) {
2059 Error BitcodeReader::resolveGlobalAndIndirectSymbolInits() {
2060 std::vector<std::pair<GlobalVariable *, unsigned>> GlobalInitWorklist;
2061 std::vector<std::pair<GlobalIndirectSymbol *, unsigned>>
2062 IndirectSymbolInitWorklist;
2063 std::vector<std::pair<Function *, unsigned>> FunctionPrefixWorklist;
2064 std::vector<std::pair<Function *, unsigned>> FunctionPrologueWorklist;
2065 std::vector<std::pair<Function *, unsigned>> FunctionPersonalityFnWorklist;
2067 GlobalInitWorklist.swap(GlobalInits);
2068 IndirectSymbolInitWorklist.swap(IndirectSymbolInits);
2069 FunctionPrefixWorklist.swap(FunctionPrefixes);
2070 FunctionPrologueWorklist.swap(FunctionPrologues);
2071 FunctionPersonalityFnWorklist.swap(FunctionPersonalityFns);
2073 while (!GlobalInitWorklist.empty()) {
2074 unsigned ValID = GlobalInitWorklist.back().second;
2075 if (ValID >= ValueList.size()) {
2077 GlobalInits.push_back(GlobalInitWorklist.back());
2079 if (
Constant *
C = dyn_cast_or_null<Constant>(ValueList[ValID]))
2080 GlobalInitWorklist.back().first->setInitializer(
C);
2082 return error(
"Expected a constant");
2084 GlobalInitWorklist.pop_back();
2087 while (!IndirectSymbolInitWorklist.empty()) {
2088 unsigned ValID = IndirectSymbolInitWorklist.back().second;
2089 if (ValID >= ValueList.size()) {
2090 IndirectSymbolInits.push_back(IndirectSymbolInitWorklist.back());
2092 Constant *
C = dyn_cast_or_null<Constant>(ValueList[ValID]);
2094 return error(
"Expected a constant");
2097 return error(
"Alias and aliasee types don't match");
2100 IndirectSymbolInitWorklist.pop_back();
2103 while (!FunctionPrefixWorklist.empty()) {
2104 unsigned ValID = FunctionPrefixWorklist.back().second;
2105 if (ValID >= ValueList.size()) {
2106 FunctionPrefixes.push_back(FunctionPrefixWorklist.back());
2108 if (
Constant *
C = dyn_cast_or_null<Constant>(ValueList[ValID]))
2109 FunctionPrefixWorklist.back().first->setPrefixData(
C);
2111 return error(
"Expected a constant");
2113 FunctionPrefixWorklist.pop_back();
2116 while (!FunctionPrologueWorklist.empty()) {
2117 unsigned ValID = FunctionPrologueWorklist.back().second;
2118 if (ValID >= ValueList.size()) {
2119 FunctionPrologues.push_back(FunctionPrologueWorklist.back());
2121 if (
Constant *
C = dyn_cast_or_null<Constant>(ValueList[ValID]))
2122 FunctionPrologueWorklist.back().first->setPrologueData(
C);
2124 return error(
"Expected a constant");
2126 FunctionPrologueWorklist.pop_back();
2129 while (!FunctionPersonalityFnWorklist.empty()) {
2130 unsigned ValID = FunctionPersonalityFnWorklist.back().second;
2131 if (ValID >= ValueList.size()) {
2132 FunctionPersonalityFns.push_back(FunctionPersonalityFnWorklist.back());
2134 if (
Constant *
C = dyn_cast_or_null<Constant>(ValueList[ValID]))
2135 FunctionPersonalityFnWorklist.back().first->setPersonalityFn(
C);
2137 return error(
"Expected a constant");
2139 FunctionPersonalityFnWorklist.pop_back();
2148 BitcodeReader::decodeSignRotatedValue);
2150 return APInt(TypeBits, Words);
2153 Error BitcodeReader::parseConstants() {
2155 return error(
"Invalid record");
2161 unsigned NextCstNo = ValueList.size();
2166 switch (Entry.
Kind) {
2169 return error(
"Malformed block");
2171 if (NextCstNo != ValueList.size())
2172 return error(
"Invalid constant reference");
2176 ValueList.resolveConstantForwardRefs();
2187 unsigned BitCode = Stream.
readRecord(Entry.
ID, Record);
2195 return error(
"Invalid record");
2196 if (Record[0] >= TypeList.
size() || !TypeList[Record[0]])
2197 return error(
"Invalid record");
2198 if (TypeList[Record[0]] == VoidType)
2199 return error(
"Invalid constant type");
2200 CurTy = TypeList[Record[0]];
2207 return error(
"Invalid record");
2212 return error(
"Invalid record");
2222 return error(
"Invalid record");
2225 APInt(16, (uint16_t)Record[0])));
2231 APInt(64, Record[0])));
2234 uint64_t Rearrange[2];
2235 Rearrange[0] = (Record[1] & 0xffffLL) | (Record[0] << 16);
2236 Rearrange[1] = Record[0] >> 48;
2238 APInt(80, Rearrange)));
2241 APInt(128, Record)));
2244 APInt(128, Record)));
2252 return error(
"Invalid record");
2254 unsigned Size = Record.size();
2257 if (
StructType *STy = dyn_cast<StructType>(CurTy)) {
2258 for (
unsigned i = 0; i !=
Size; ++i)
2259 Elts.
push_back(ValueList.getConstantFwdRef(Record[i],
2260 STy->getElementType(i)));
2262 }
else if (
ArrayType *ATy = dyn_cast<ArrayType>(CurTy)) {
2263 Type *EltTy = ATy->getElementType();
2264 for (
unsigned i = 0; i !=
Size; ++i)
2265 Elts.
push_back(ValueList.getConstantFwdRef(Record[i], EltTy));
2267 }
else if (
VectorType *VTy = dyn_cast<VectorType>(CurTy)) {
2268 Type *EltTy = VTy->getElementType();
2269 for (
unsigned i = 0; i !=
Size; ++i)
2270 Elts.
push_back(ValueList.getConstantFwdRef(Record[i], EltTy));
2280 return error(
"Invalid record");
2289 return error(
"Invalid record");
2291 Type *EltTy = cast<SequentialType>(CurTy)->getElementType();
2294 if (isa<VectorType>(CurTy))
2300 if (isa<VectorType>(CurTy))
2306 if (isa<VectorType>(CurTy))
2312 if (isa<VectorType>(CurTy))
2318 if (isa<VectorType>(CurTy))
2324 if (isa<VectorType>(CurTy))
2330 if (isa<VectorType>(CurTy))
2335 return error(
"Invalid type for value");
2340 if (Record.size() < 2)
2341 return error(
"Invalid record");
2346 Constant *LHS = ValueList.getConstantFwdRef(Record[1], CurTy);
2353 if (Record.size() < 3)
2354 return error(
"Invalid record");
2359 Constant *LHS = ValueList.getConstantFwdRef(Record[1], CurTy);
2360 Constant *RHS = ValueList.getConstantFwdRef(Record[2], CurTy);
2362 if (Record.size() >= 4) {
2364 Opc == Instruction::Sub ||
2365 Opc == Instruction::Mul ||
2366 Opc == Instruction::Shl) {
2371 }
else if (Opc == Instruction::SDiv ||
2372 Opc == Instruction::UDiv ||
2373 Opc == Instruction::LShr ||
2374 Opc == Instruction::AShr) {
2384 if (Record.size() < 3)
2385 return error(
"Invalid record");
2390 Type *OpTy = getTypeByID(Record[1]);
2392 return error(
"Invalid record");
2393 Constant *
Op = ValueList.getConstantFwdRef(Record[2], OpTy);
2404 Type *PointeeType =
nullptr;
2407 PointeeType = getTypeByID(Record[OpNum++]);
2409 bool InBounds =
false;
2412 uint64_t
Op = Record[OpNum++];
2414 InRangeIndex = Op >> 1;
2419 while (OpNum != Record.size()) {
2420 Type *ElTy = getTypeByID(Record[OpNum++]);
2422 return error(
"Invalid record");
2423 Elts.
push_back(ValueList.getConstantFwdRef(Record[OpNum++], ElTy));
2428 cast<PointerType>(Elts[0]->
getType()->getScalarType())
2430 return error(
"Explicit gep operator type does not match pointee type " 2431 "of pointer operand");
2433 if (Elts.
size() < 1)
2434 return error(
"Invalid gep with no operands");
2438 InBounds, InRangeIndex);
2442 if (Record.size() < 3)
2443 return error(
"Invalid record");
2449 if (
VectorType *VTy = dyn_cast<VectorType>(CurTy))
2450 if (
Value *V = ValueList[Record[0]])
2451 if (SelectorTy != V->
getType())
2456 ValueList.getConstantFwdRef(Record[1],CurTy),
2457 ValueList.getConstantFwdRef(Record[2],CurTy));
2462 if (Record.size() < 3)
2463 return error(
"Invalid record");
2465 dyn_cast_or_null<VectorType>(getTypeByID(Record[0]));
2467 return error(
"Invalid record");
2468 Constant *Op0 = ValueList.getConstantFwdRef(Record[1], OpTy);
2470 if (Record.size() == 4) {
2471 Type *IdxTy = getTypeByID(Record[2]);
2473 return error(
"Invalid record");
2474 Op1 = ValueList.getConstantFwdRef(Record[3], IdxTy);
2478 return error(
"Invalid record");
2485 if (Record.size() < 3 || !OpTy)
2486 return error(
"Invalid record");
2487 Constant *Op0 = ValueList.getConstantFwdRef(Record[0], OpTy);
2488 Constant *Op1 = ValueList.getConstantFwdRef(Record[1],
2491 if (Record.size() == 4) {
2492 Type *IdxTy = getTypeByID(Record[2]);
2494 return error(
"Invalid record");
2495 Op2 = ValueList.getConstantFwdRef(Record[3], IdxTy);
2499 return error(
"Invalid record");
2505 if (Record.size() < 3 || !OpTy)
2506 return error(
"Invalid record");
2507 Constant *Op0 = ValueList.getConstantFwdRef(Record[0], OpTy);
2508 Constant *Op1 = ValueList.getConstantFwdRef(Record[1], OpTy);
2511 Constant *Op2 = ValueList.getConstantFwdRef(Record[2], ShufTy);
2518 dyn_cast_or_null<VectorType>(getTypeByID(Record[0]));
2519 if (Record.size() < 4 || !RTy || !OpTy)
2520 return error(
"Invalid record");
2521 Constant *Op0 = ValueList.getConstantFwdRef(Record[1], OpTy);
2522 Constant *Op1 = ValueList.getConstantFwdRef(Record[2], OpTy);
2525 Constant *Op2 = ValueList.getConstantFwdRef(Record[3], ShufTy);
2530 if (Record.size() < 4)
2531 return error(
"Invalid record");
2532 Type *OpTy = getTypeByID(Record[0]);
2534 return error(
"Invalid record");
2535 Constant *Op0 = ValueList.getConstantFwdRef(Record[1], OpTy);
2536 Constant *Op1 = ValueList.getConstantFwdRef(Record[2], OpTy);
2547 if (Record.size() < 2)
2548 return error(
"Invalid record");
2549 std::string AsmStr, ConstrStr;
2550 bool HasSideEffects = Record[0] & 1;
2551 bool IsAlignStack = Record[0] >> 1;
2552 unsigned AsmStrSize = Record[1];
2553 if (2+AsmStrSize >= Record.size())
2554 return error(
"Invalid record");
2555 unsigned ConstStrSize = Record[2+AsmStrSize];
2556 if (3+AsmStrSize+ConstStrSize > Record.size())
2557 return error(
"Invalid record");
2559 for (
unsigned i = 0; i != AsmStrSize; ++i)
2560 AsmStr += (
char)Record[2+i];
2561 for (
unsigned i = 0; i != ConstStrSize; ++i)
2562 ConstrStr += (
char)Record[3+AsmStrSize+i];
2566 AsmStr, ConstrStr, HasSideEffects, IsAlignStack);
2572 if (Record.size() < 2)
2573 return error(
"Invalid record");
2574 std::string AsmStr, ConstrStr;
2575 bool HasSideEffects = Record[0] & 1;
2576 bool IsAlignStack = (Record[0] >> 1) & 1;
2577 unsigned AsmDialect = Record[0] >> 2;
2578 unsigned AsmStrSize = Record[1];
2579 if (2+AsmStrSize >= Record.size())
2580 return error(
"Invalid record");
2581 unsigned ConstStrSize = Record[2+AsmStrSize];
2582 if (3+AsmStrSize+ConstStrSize > Record.size())
2583 return error(
"Invalid record");
2585 for (
unsigned i = 0; i != AsmStrSize; ++i)
2586 AsmStr += (
char)Record[2+i];
2587 for (
unsigned i = 0; i != ConstStrSize; ++i)
2588 ConstrStr += (
char)Record[3+AsmStrSize+i];
2592 AsmStr, ConstrStr, HasSideEffects, IsAlignStack,
2597 if (Record.size() < 3)
2598 return error(
"Invalid record");
2599 Type *FnTy = getTypeByID(Record[0]);
2601 return error(
"Invalid record");
2603 dyn_cast_or_null<Function>(ValueList.getConstantFwdRef(Record[1],FnTy));
2605 return error(
"Invalid record");
2610 unsigned BBID = Record[2];
2613 return error(
"Invalid ID");
2616 for (
size_t I = 0,
E = BBID;
I !=
E; ++
I) {
2618 return error(
"Invalid ID");
2625 auto &FwdBBs = BasicBlockFwdRefs[Fn];
2627 BasicBlockFwdRefQueue.push_back(Fn);
2628 if (FwdBBs.size() < BBID + 1)
2629 FwdBBs.resize(BBID + 1);
2639 ValueList.assignValue(V, NextCstNo);
2644 Error BitcodeReader::parseUseLists() {
2646 return error(
"Invalid record");
2654 switch (Entry.
Kind) {
2657 return error(
"Malformed block");
2675 unsigned RecordLength = Record.
size();
2676 if (RecordLength < 3)
2678 return error(
"Invalid record");
2679 unsigned ID = Record.
back();
2684 assert(ID < FunctionBBs.size() &&
"Basic block not found");
2685 V = FunctionBBs[
ID];
2688 unsigned NumUses = 0;
2691 if (++NumUses > Record.
size())
2693 Order[&U] = Record[NumUses - 1];
2695 if (Order.
size() != Record.
size() || NumUses > Record.
size())
2711 Error BitcodeReader::rememberAndSkipMetadata() {
2714 DeferredMetadataInfo.push_back(CurBit);
2718 return error(
"Invalid record");
2722 Error BitcodeReader::materializeMetadata() {
2723 for (uint64_t BitPos : DeferredMetadataInfo) {
2726 if (
Error Err = MDLoader->parseModuleMetadata())
2732 if (
Metadata *Val = TheModule->getModuleFlag(
"Linker Options")) {
2734 TheModule->getOrInsertNamedMetadata(
"llvm.linker.options");
2735 for (
const MDOperand &MDOptions : cast<MDNode>(Val)->operands())
2736 LinkerOpts->
addOperand(cast<MDNode>(MDOptions));
2739 DeferredMetadataInfo.clear();
2743 void BitcodeReader::setStripDebugInfo() {
StripDebugInfo =
true; }
2747 Error BitcodeReader::rememberAndSkipFunctionBody() {
2749 if (FunctionsWithBodies.empty())
2750 return error(
"Insufficient function protos");
2753 FunctionsWithBodies.pop_back();
2758 (DeferredFunctionInfo[Fn] == 0 || DeferredFunctionInfo[Fn] == CurBit) &&
2759 "Mismatch between VST and scanned function offsets");
2760 DeferredFunctionInfo[Fn] = CurBit;
2764 return error(
"Invalid record");
2768 Error BitcodeReader::globalCleanup() {
2770 if (
Error Err = resolveGlobalAndIndirectSymbolInits())
2772 if (!GlobalInits.empty() || !IndirectSymbolInits.empty())
2773 return error(
"Malformed global initializer set");
2777 MDLoader->upgradeDebugIntrinsics(F);
2780 UpgradedIntrinsics[&
F] = NewFn;
2785 RemangledIntrinsics[&
F] = Remangled.getValue();
2794 std::vector<std::pair<GlobalVariable *, unsigned>>().
swap(GlobalInits);
2795 std::vector<std::pair<GlobalIndirectSymbol *, unsigned>>().
swap(
2796 IndirectSymbolInits);
2804 Error BitcodeReader::rememberAndSkipFunctionBodies() {
2808 return error(
"Could not find function in stream");
2810 if (!SeenFirstFunctionBody)
2811 return error(
"Trying to materialize functions before seeing function blocks");
2815 assert(SeenValueSymbolTable);
2821 switch (Entry.
Kind) {
2823 return error(
"Expect SubBlock");
2827 return error(
"Expect function block");
2829 if (
Error Err = rememberAndSkipFunctionBody())
2838 bool BitcodeReaderBase::readBlockInfo() {
2842 BlockInfo = std::move(*NewBlockInfo);
2850 std::tie(Name, Record) = readNameFromStrtab(Record);
2853 return error(
"Invalid record");
2855 std::string OldFormatName;
2857 if (Record.
size() < 2)
2858 return error(
"Invalid record");
2859 unsigned ComdatNameSize = Record[1];
2860 OldFormatName.reserve(ComdatNameSize);
2861 for (
unsigned i = 0; i != ComdatNameSize; ++i)
2862 OldFormatName += (
char)Record[2 + i];
2863 Name = OldFormatName;
2865 Comdat *
C = TheModule->getOrInsertComdat(Name);
2867 ComdatList.push_back(C);
2884 std::tie(Name, Record) = readNameFromStrtab(Record);
2886 if (Record.
size() < 6)
2887 return error(
"Invalid record");
2888 Type *Ty = getTypeByID(Record[0]);
2890 return error(
"Invalid record");
2892 bool explicitType = Record[1] & 2;
2895 AddressSpace = Record[1] >> 2;
2898 return error(
"Invalid type for value");
2899 AddressSpace = cast<PointerType>(Ty)->getAddressSpace();
2900 Ty = cast<PointerType>(Ty)->getElementType();
2903 uint64_t RawLinkage = Record[3];
2906 if (
Error Err = parseAlignmentValue(Record[4], Alignment))
2910 if (Record[5] - 1 >= SectionTable.
size())
2911 return error(
"Invalid ID");
2912 Section = SectionTable[Record[5] - 1];
2921 if (Record.
size() > 7)
2925 if (Record.
size() > 8)
2928 bool ExternallyInitialized =
false;
2929 if (Record.
size() > 9)
2930 ExternallyInitialized = Record[9];
2933 new GlobalVariable(*TheModule, Ty, isConstant, Linkage,
nullptr, Name,
2934 nullptr, TLM, AddressSpace, ExternallyInitialized);
2936 if (!Section.empty())
2941 if (Record.
size() > 10)
2946 ValueList.push_back(NewGV);
2949 if (
unsigned InitID = Record[2])
2950 GlobalInits.push_back(std::make_pair(NewGV, InitID - 1));
2952 if (Record.
size() > 11) {
2953 if (
unsigned ComdatID = Record[11]) {
2954 if (ComdatID > ComdatList.size())
2955 return error(
"Invalid global variable comdat ID");
2956 NewGV->
setComdat(ComdatList[ComdatID - 1]);
2959 NewGV->
setComdat(reinterpret_cast<Comdat *>(1));
2962 if (Record.
size() > 12) {
2967 if (Record.
size() > 13) {
2981 std::tie(Name, Record) = readNameFromStrtab(Record);
2983 if (Record.
size() < 8)
2984 return error(
"Invalid record");
2985 Type *Ty = getTypeByID(Record[0]);
2987 return error(
"Invalid record");
2988 if (
auto *PTy = dyn_cast<PointerType>(Ty))
2989 Ty = PTy->getElementType();
2992 return error(
"Invalid type for value");
2995 return error(
"Invalid calling convention ID");
2997 unsigned AddrSpace = TheModule->getDataLayout().getProgramAddressSpace();
2998 if (Record.
size() > 16)
2999 AddrSpace = Record[16];
3002 AddrSpace, Name, TheModule);
3005 bool isProto = Record[2];
3006 uint64_t RawLinkage = Record[3];
3011 if (
Error Err = parseAlignmentValue(Record[5], Alignment))
3015 if (Record[6] - 1 >= SectionTable.
size())
3016 return error(
"Invalid ID");
3017 Func->
setSection(SectionTable[Record[6] - 1]);
3023 if (Record.
size() > 8 && Record[8]) {
3024 if (Record[8] - 1 >= GCTable.
size())
3025 return error(
"Invalid ID");
3026 Func->
setGC(GCTable[Record[8] - 1]);
3029 if (Record.
size() > 9)
3032 if (Record.
size() > 10 && Record[10] != 0)
3033 FunctionPrologues.push_back(std::make_pair(Func, Record[10] - 1));
3035 if (Record.
size() > 11)
3040 if (Record.
size() > 12) {
3041 if (
unsigned ComdatID = Record[12]) {
3042 if (ComdatID > ComdatList.size())
3043 return error(
"Invalid function comdat ID");
3044 Func->
setComdat(ComdatList[ComdatID - 1]);
3047 Func->
setComdat(reinterpret_cast<Comdat *>(1));
3050 if (Record.
size() > 13 && Record[13] != 0)
3051 FunctionPrefixes.push_back(std::make_pair(Func, Record[13] - 1));
3053 if (Record.
size() > 14 && Record[14] != 0)
3054 FunctionPersonalityFns.push_back(std::make_pair(Func, Record[14] - 1));
3056 if (Record.
size() > 15) {
3061 ValueList.push_back(Func);
3067 FunctionsWithBodies.push_back(Func);
3068 DeferredFunctionInfo[Func] = 0;
3073 Error BitcodeReader::parseGlobalIndirectSymbolRecord(
3084 std::tie(Name, Record) = readNameFromStrtab(Record);
3088 return error(
"Invalid record");
3090 Type *Ty = getTypeByID(Record[OpNum++]);
3092 return error(
"Invalid record");
3098 return error(
"Invalid type for value");
3099 Ty = PTy->getElementType();
3100 AddrSpace = PTy->getAddressSpace();
3102 AddrSpace = Record[OpNum++];
3105 auto Val = Record[OpNum++];
3106 auto Linkage = Record[OpNum++];
3114 nullptr, TheModule);
3117 if (OpNum != Record.
size()) {
3118 auto VisInd = OpNum++;
3125 if (OpNum != Record.
size())
3129 if (OpNum != Record.
size())
3131 if (OpNum != Record.
size())
3134 if (OpNum != Record.
size())
3138 ValueList.push_back(NewGA);
3139 IndirectSymbolInits.push_back(std::make_pair(NewGA, Val));
3144 bool ShouldLazyLoadMetadata) {
3148 return error(
"Invalid record");
3156 switch (Entry.
Kind) {
3158 return error(
"Malformed block");
3160 return globalCleanup();
3166 return error(
"Invalid record");
3169 if (readBlockInfo())
3170 return error(
"Malformed block");
3173 if (
Error Err = parseAttributeBlock())
3177 if (
Error Err = parseAttributeGroupBlock())
3181 if (
Error Err = parseTypeTable())
3185 if (!SeenValueSymbolTable) {
3191 assert(VSTOffset == 0 || FunctionsWithBodies.empty());
3192 if (
Error Err = parseValueSymbolTable())
3194 SeenValueSymbolTable =
true;
3200 return error(
"Invalid record");
3204 if (
Error Err = parseConstants())
3206 if (
Error Err = resolveGlobalAndIndirectSymbolInits())
3210 if (ShouldLazyLoadMetadata) {
3211 if (
Error Err = rememberAndSkipMetadata())
3215 assert(DeferredMetadataInfo.empty() &&
"Unexpected deferred metadata");
3216 if (
Error Err = MDLoader->parseModuleMetadata())
3220 if (
Error Err = MDLoader->parseMetadataKinds())
3226 if (!SeenFirstFunctionBody) {
3227 std::reverse(FunctionsWithBodies.begin(), FunctionsWithBodies.end());
3228 if (
Error Err = globalCleanup())
3230 SeenFirstFunctionBody =
true;
3233 if (VSTOffset > 0) {
3237 if (!SeenValueSymbolTable) {
3238 if (
Error Err = BitcodeReader::parseValueSymbolTable(VSTOffset))
3240 SeenValueSymbolTable =
true;
3253 return error(
"Invalid record");
3262 if (
Error Err = rememberAndSkipFunctionBody())
3269 if (SeenValueSymbolTable) {
3273 return globalCleanup();
3277 if (
Error Err = parseUseLists())
3281 if (
Error Err = parseOperandBundleTags())
3285 if (
Error Err = parseSyncScopeNames())
3304 UseRelativeIDs = *VersionOrErr >= 1;
3310 return error(
"Invalid record");
3311 TheModule->setTargetTriple(S);
3317 return error(
"Invalid record");
3318 TheModule->setDataLayout(S);
3324 return error(
"Invalid record");
3325 TheModule->setModuleInlineAsm(S);
3332 return error(
"Invalid record");
3339 return error(
"Invalid record");
3340 SectionTable.push_back(S);
3346 return error(
"Invalid record");
3347 GCTable.push_back(S);
3351 if (
Error Err = parseComdatRecord(Record))
3355 if (
Error Err = parseGlobalVarRecord(Record))
3359 if (
Error Err = parseFunctionRecord(Record))
3365 if (
Error Err = parseGlobalIndirectSymbolRecord(BitCode, Record))
3370 if (Record.
size() < 1)
3371 return error(
"Invalid record");
3375 VSTOffset = Record[0] - 1;
3381 return error(
"Invalid record");
3382 TheModule->setSourceFileName(ValueName);
3389 Error BitcodeReader::parseBitcodeInto(
Module *M,
bool ShouldLazyLoadMetadata,
3393 [&](
unsigned ID) {
return getTypeByID(ID); });
3398 if (!isa<PointerType>(PtrType))
3399 return error(
"Load/Store operand is not a pointer type");
3400 Type *ElemType = cast<PointerType>(PtrType)->getElementType();
3402 if (ValType && ValType != ElemType)
3403 return error(
"Explicit load/store type does not match pointee " 3404 "type of pointer operand");
3406 return error(
"Cannot load/store from pointer");
3413 return error(
"Invalid record");
3416 if (MDLoader->hasFwdRefs())
3417 return error(
"Invalid function metadata: incoming forward references");
3419 InstructionList.clear();
3420 unsigned ModuleValueListSize = ValueList.size();
3421 unsigned ModuleMDLoaderSize = MDLoader->size();
3425 ValueList.push_back(&
I);
3427 unsigned NextValueNo = ValueList.size();
3429 unsigned CurBBNo = 0;
3432 auto getLastInstruction = [&]() ->
Instruction * {
3433 if (CurBB && !CurBB->
empty())
3434 return &CurBB->
back();
3435 else if (CurBBNo && FunctionBBs[CurBBNo - 1] &&
3436 !FunctionBBs[CurBBNo - 1]->
empty())
3437 return &FunctionBBs[CurBBNo - 1]->back();
3441 std::vector<OperandBundleDef> OperandBundles;
3449 switch (Entry.
Kind) {
3451 return error(
"Malformed block");
3453 goto OutOfRecordLoop;
3459 return error(
"Invalid record");
3462 if (
Error Err = parseConstants())
3464 NextValueNo = ValueList.size();
3467 if (
Error Err = parseValueSymbolTable())
3471 if (
Error Err = MDLoader->parseMetadataAttachment(*F, InstructionList))
3475 assert(DeferredMetadataInfo.empty() &&
3476 "Must read all module-level metadata before function-level");
3477 if (
Error Err = MDLoader->parseFunctionMetadata())
3481 if (
Error Err = parseUseLists())
3495 unsigned BitCode = Stream.
readRecord(Entry.
ID, Record);
3498 return error(
"Invalid value");
3500 if (Record.
size() < 1 || Record[0] == 0)
3501 return error(
"Invalid record");
3503 FunctionBBs.resize(Record[0]);
3506 auto BBFRI = BasicBlockFwdRefs.find(F);
3507 if (BBFRI == BasicBlockFwdRefs.end()) {
3508 for (
unsigned i = 0, e = FunctionBBs.size(); i != e; ++i)
3511 auto &BBRefs = BBFRI->second;
3513 if (BBRefs.size() > FunctionBBs.size())
3514 return error(
"Invalid ID");
3515 assert(!BBRefs.empty() &&
"Unexpected empty array");
3516 assert(!BBRefs.front() &&
"Invalid reference to entry block");
3517 for (
unsigned I = 0,
E = FunctionBBs.size(), RE = BBRefs.size(); I !=
E;
3519 if (I < RE && BBRefs[I]) {
3520 BBRefs[
I]->insertInto(F);
3521 FunctionBBs[
I] = BBRefs[
I];
3527 BasicBlockFwdRefs.erase(BBFRI);
3530 CurBB = FunctionBBs[0];
3537 I = getLastInstruction();
3540 return error(
"Invalid record");
3546 I = getLastInstruction();
3547 if (!I || Record.
size() < 4)
3548 return error(
"Invalid record");
3550 unsigned Line = Record[0], Col = Record[1];
3551 unsigned ScopeID = Record[2], IAID = Record[3];
3552 bool isImplicitCode = Record.
size() == 5 && Record[4];
3554 MDNode *Scope =
nullptr, *IA =
nullptr;
3556 Scope = dyn_cast_or_null<MDNode>(
3557 MDLoader->getMetadataFwdRefOrLoad(ScopeID - 1));
3559 return error(
"Invalid record");
3562 IA = dyn_cast_or_null<MDNode>(
3563 MDLoader->getMetadataFwdRefOrLoad(IAID - 1));
3565 return error(
"Invalid record");
3567 LastLoc =
DebugLoc::get(Line, Col, Scope, IA, isImplicitCode);
3575 if (getValueTypePair(Record, OpNum, NextValueNo, LHS) ||
3576 OpNum+1 > Record.
size())
3577 return error(
"Invalid record");
3581 return error(
"Invalid record");
3583 InstructionList.push_back(I);
3584 if (OpNum < Record.
size()) {
3585 if (isa<FPMathOperator>(I)) {
3596 if (getValueTypePair(Record, OpNum, NextValueNo, LHS) ||
3597 popValue(Record, OpNum, NextValueNo, LHS->
getType(), RHS) ||
3598 OpNum+1 > Record.
size())
3599 return error(
"Invalid record");
3603 return error(
"Invalid record");
3605 InstructionList.push_back(I);
3606 if (OpNum < Record.
size()) {
3608 Opc == Instruction::Sub ||
3609 Opc == Instruction::Mul ||
3610 Opc == Instruction::Shl) {
3612 cast<BinaryOperator>(I)->setHasNoSignedWrap(
true);
3614 cast<BinaryOperator>(
I)->setHasNoUnsignedWrap(
true);
3615 }
else if (Opc == Instruction::SDiv ||
3616 Opc == Instruction::UDiv ||
3617 Opc == Instruction::LShr ||
3618 Opc == Instruction::AShr) {
3620 cast<BinaryOperator>(
I)->setIsExact(
true);
3621 }
else if (isa<FPMathOperator>(I)) {
3633 if (getValueTypePair(Record, OpNum, NextValueNo, Op) ||
3634 OpNum+2 != Record.
size())
3635 return error(
"Invalid record");
3637 Type *ResTy = getTypeByID(Record[OpNum]);
3639 if (Opc == -1 || !ResTy)
3640 return error(
"Invalid record");
3644 InstructionList.push_back(Temp);
3650 return error(
"Invalid cast");
3653 InstructionList.push_back(I);
3665 InBounds = Record[OpNum++];
3666 Ty = getTypeByID(Record[OpNum++]);
3673 if (getValueTypePair(Record, OpNum, NextValueNo, BasePtr))
3674 return error(
"Invalid record");
3683 "Explicit gep type does not match pointee type of pointer operand");
3686 while (OpNum != Record.
size()) {
3688 if (getValueTypePair(Record, OpNum, NextValueNo, Op))
3689 return error(
"Invalid record");
3695 InstructionList.push_back(I);
3697 cast<GetElementPtrInst>(
I)->setIsInBounds(
true);
3705 if (getValueTypePair(Record, OpNum, NextValueNo, Agg))
3706 return error(
"Invalid record");
3708 unsigned RecSize = Record.
size();
3709 if (OpNum == RecSize)
3710 return error(
"EXTRACTVAL: Invalid instruction with 0 indices");
3714 for (; OpNum != RecSize; ++OpNum) {
3717 uint64_t
Index = Record[OpNum];
3719 if (!IsStruct && !IsArray)
3720 return error(
"EXTRACTVAL: Invalid type");
3721 if ((
unsigned)Index != Index)
3722 return error(
"Invalid value");
3724 return error(
"EXTRACTVAL: Invalid struct index");
3726 return error(
"EXTRACTVAL: Invalid array index");
3727 EXTRACTVALIdx.
push_back((
unsigned)Index);
3736 InstructionList.push_back(I);
3744 if (getValueTypePair(Record, OpNum, NextValueNo, Agg))
3745 return error(
"Invalid record");
3747 if (getValueTypePair(Record, OpNum, NextValueNo, Val))
3748 return error(
"Invalid record");
3750 unsigned RecSize = Record.
size();
3751 if (OpNum == RecSize)
3752 return error(
"INSERTVAL: Invalid instruction with 0 indices");
3756 for (; OpNum != RecSize; ++OpNum) {
3759 uint64_t
Index = Record[OpNum];
3761 if (!IsStruct && !IsArray)
3762 return error(
"INSERTVAL: Invalid type");
3763 if ((
unsigned)Index != Index)
3764 return error(
"Invalid value");
3766 return error(
"INSERTVAL: Invalid struct index");
3768 return error(
"INSERTVAL: Invalid array index");
3770 INSERTVALIdx.
push_back((
unsigned)Index);
3778 return error(
"Inserted value type doesn't match aggregate type");
3781 InstructionList.push_back(I);
3789 Value *TrueVal, *FalseVal, *Cond;
3790 if (getValueTypePair(Record, OpNum, NextValueNo, TrueVal) ||
3791 popValue(Record, OpNum, NextValueNo, TrueVal->
getType(), FalseVal) ||
3793 return error(
"Invalid record");
3796 InstructionList.push_back(I);
3804 Value *TrueVal, *FalseVal, *Cond;
3805 if (getValueTypePair(Record, OpNum, NextValueNo, TrueVal) ||
3806 popValue(Record, OpNum, NextValueNo, TrueVal->
getType(), FalseVal) ||
3807 getValueTypePair(Record, OpNum, NextValueNo, Cond))
3808 return error(
"Invalid record");
3812 dyn_cast<VectorType>(Cond->
getType())) {
3815 return error(
"Invalid type for value");
3819 return error(
"Invalid type for value");
3823 InstructionList.push_back(I);
3830 if (getValueTypePair(Record, OpNum, NextValueNo, Vec) ||
3831 getValueTypePair(Record, OpNum, NextValueNo, Idx))
3832 return error(
"Invalid record");
3834 return error(
"Invalid type for value");
3836 InstructionList.push_back(I);
3842 Value *Vec, *Elt, *Idx;
3843 if (getValueTypePair(Record, OpNum, NextValueNo, Vec))
3844 return error(
"Invalid record");
3846 return error(
"Invalid type for value");
3847 if (popValue(Record, OpNum, NextValueNo,
3848 cast<VectorType>(Vec->
getType())->getElementType(), Elt) ||
3849 getValueTypePair(Record, OpNum, NextValueNo, Idx))
3850 return error(
"Invalid record");
3852 InstructionList.push_back(I);
3859 if (getValueTypePair(Record, OpNum, NextValueNo, Vec1) ||
3860 popValue(Record, OpNum, NextValueNo, Vec1->
getType(), Vec2))
3861 return error(
"Invalid record");
3863 if (getValueTypePair(Record, OpNum, NextValueNo, Mask))
3864 return error(
"Invalid record");
3866 return error(
"Invalid type for value");
3868 InstructionList.push_back(I);
3881 if (getValueTypePair(Record, OpNum, NextValueNo, LHS) ||
3882 popValue(Record, OpNum, NextValueNo, LHS->
getType(), RHS))
3883 return error(
"Invalid record");
3885 unsigned PredVal = Record[OpNum];
3888 if (IsFP && Record.
size() > OpNum+1)
3891 if (OpNum+1 != Record.
size())
3892 return error(
"Invalid record");
3901 InstructionList.push_back(I);
3910 InstructionList.push_back(I);
3916 if (getValueTypePair(Record, OpNum, NextValueNo, Op))
3917 return error(
"Invalid record");
3918 if (OpNum != Record.
size())
3919 return error(
"Invalid record");
3922 InstructionList.push_back(I);
3926 if (Record.
size() != 1 && Record.
size() != 3)
3927 return error(
"Invalid record");
3928 BasicBlock *TrueDest = getBasicBlock(Record[0]);
3930 return error(
"Invalid record");
3932 if (Record.
size() == 1) {
3934 InstructionList.push_back(I);
3937 BasicBlock *FalseDest = getBasicBlock(Record[1]);
3938 Value *Cond = getValue(Record, 2, NextValueNo,
3940 if (!FalseDest || !Cond)
3941 return error(
"Invalid record");
3943 InstructionList.push_back(I);
3948 if (Record.
size() != 1 && Record.
size() != 2)
3949 return error(
"Invalid record");
3954 return error(
"Invalid record");
3956 if (Record.
size() == 2) {
3957 UnwindDest = getBasicBlock(Record[Idx++]);
3959 return error(
"Invalid record");
3963 InstructionList.push_back(I);
3967 if (Record.
size() != 2)
3968 return error(
"Invalid record");
3973 return error(
"Invalid record");
3974 BasicBlock *BB = getBasicBlock(Record[Idx++]);
3976 return error(
"Invalid record");
3979 InstructionList.push_back(I);
3984 if (Record.
size() < 2)
3985 return error(
"Invalid record");
3992 unsigned NumHandlers = Record[Idx++];
3995 for (
unsigned Op = 0;
Op != NumHandlers; ++
Op) {
3996 BasicBlock *BB = getBasicBlock(Record[Idx++]);
3998 return error(
"Invalid record");
4003 if (Idx + 1 == Record.
size()) {
4004 UnwindDest = getBasicBlock(Record[Idx++]);
4006 return error(
"Invalid record");
4009 if (Record.
size() != Idx)
4010 return error(
"Invalid record");
4015 CatchSwitch->addHandler(Handler);
4017 InstructionList.push_back(I);
4023 if (Record.
size() < 2)
4024 return error(
"Invalid record");
4031 unsigned NumArgOperands = Record[Idx++];
4034 for (
unsigned Op = 0;
Op != NumArgOperands; ++
Op) {
4036 if (getValueTypePair(Record, Idx, NextValueNo, Val))
4037 return error(
"Invalid record");
4041 if (Record.
size() != Idx)
4042 return error(
"Invalid record");
4048 InstructionList.push_back(I);
4053 if ((Record[0] >> 16) == SWITCH_INST_MAGIC) {
4059 Type *OpTy = getTypeByID(Record[1]);
4060 unsigned ValueBitWidth = cast<IntegerType>(OpTy)->
getBitWidth();
4062 Value *Cond = getValue(Record, 2, NextValueNo, OpTy);
4064 if (!OpTy || !Cond || !Default)
4065 return error(
"Invalid record");
4067 unsigned NumCases = Record[4];
4070 InstructionList.push_back(SI);
4072 unsigned CurIdx = 5;
4073 for (
unsigned i = 0; i != NumCases; ++i) {
4075 unsigned NumItems = Record[CurIdx++];
4076 for (
unsigned ci = 0; ci != NumItems; ++ci) {
4077 bool isSingleNumber = Record[CurIdx++];
4080 unsigned ActiveWords = 1;
4081 if (ValueBitWidth > 64)
4082 ActiveWords = Record[CurIdx++];
4085 CurIdx += ActiveWords;
4087 if (!isSingleNumber) {
4089 if (ValueBitWidth > 64)
4090 ActiveWords = Record[CurIdx++];
4092 makeArrayRef(&Record[CurIdx], ActiveWords), ValueBitWidth);
4093 CurIdx += ActiveWords;
4099 for ( ; Low.
ule(High); ++Low)
4104 BasicBlock *DestBB = getBasicBlock(Record[CurIdx++]);
4106 cve = CaseVals.
end(); cvi != cve; ++cvi)
4115 if (Record.
size() < 3 || (Record.
size() & 1) == 0)
4116 return error(
"Invalid record");
4117 Type *OpTy = getTypeByID(Record[0]);
4118 Value *Cond = getValue(Record, 1, NextValueNo, OpTy);
4120 if (!OpTy || !Cond || !Default)
4121 return error(
"Invalid record");
4122 unsigned NumCases = (Record.
size()-3)/2;
4124 InstructionList.push_back(SI);
4125 for (
unsigned i = 0, e = NumCases; i != e; ++i) {
4127 dyn_cast_or_null<ConstantInt>(getFnValueByID(Record[3+i*2], OpTy));
4128 BasicBlock *DestBB = getBasicBlock(Record[1+3+i*2]);
4129 if (!CaseVal || !DestBB) {
4131 return error(
"Invalid record");
4139 if (Record.
size() < 2)
4140 return error(
"Invalid record");
4141 Type *OpTy = getTypeByID(Record[0]);
4142 Value *
Address = getValue(Record, 1, NextValueNo, OpTy);
4143 if (!OpTy || !Address)
4144 return error(
"Invalid record");
4145 unsigned NumDests = Record.
size()-2;
4147 InstructionList.push_back(IBI);
4148 for (
unsigned i = 0, e = NumDests; i != e; ++i) {
4149 if (
BasicBlock *DestBB = getBasicBlock(Record[2+i])) {
4153 return error(
"Invalid record");
4162 if (Record.
size() < 4)
4163 return error(
"Invalid record");
4166 unsigned CCInfo = Record[OpNum++];
4167 BasicBlock *NormalBB = getBasicBlock(Record[OpNum++]);
4168 BasicBlock *UnwindBB = getBasicBlock(Record[OpNum++]);
4171 if (CCInfo >> 13 & 1 &&
4172 !(FTy = dyn_cast<FunctionType>(getTypeByID(Record[OpNum++]))))
4173 return error(
"Explicit invoke type is not a function type");
4176 if (getValueTypePair(Record, OpNum, NextValueNo, Callee))
4177 return error(
"Invalid record");
4181 return error(
"Callee is not a pointer");
4185 return error(
"Callee is not of pointer to function type");
4187 return error(
"Explicit invoke type does not match pointee type of " 4190 return error(
"Insufficient operands to call");
4193 for (
unsigned i = 0, e = FTy->
getNumParams(); i != e; ++i, ++OpNum) {
4194 Ops.
push_back(getValue(Record, OpNum, NextValueNo,
4197 return error(
"Invalid record");
4201 if (Record.
size() != OpNum)
4202 return error(
"Invalid record");
4205 while (OpNum != Record.
size()) {
4207 if (getValueTypePair(Record, OpNum, NextValueNo, Op))
4208 return error(
"Invalid record");
4214 OperandBundles.clear();
4215 InstructionList.push_back(I);
4216 cast<InvokeInst>(
I)->setCallingConv(
4218 cast<InvokeInst>(
I)->setAttributes(PAL);
4223 Value *Val =
nullptr;
4224 if (getValueTypePair(Record, Idx, NextValueNo, Val))
4225 return error(
"Invalid record");
4227 InstructionList.push_back(I);
4232 InstructionList.push_back(I);
4235 if (Record.
size() < 1 || ((Record.
size()-1)&1))
4236 return error(
"Invalid record");
4237 Type *Ty = getTypeByID(Record[0]);
4239 return error(
"Invalid record");
4242 InstructionList.push_back(PN);
4244 for (
unsigned i = 0, e = Record.
size()-1; i != e; i += 2) {
4250 V = getValueSigned(Record, 1+i, NextValueNo, Ty);
4252 V = getValue(Record, 1+i, NextValueNo, Ty);
4255 return error(
"Invalid record");
4267 if (Record.
size() < 3)
4268 return error(
"Invalid record");
4271 if (Record.
size() < 4)
4272 return error(
"Invalid record");
4274 Type *Ty = getTypeByID(Record[Idx++]);
4276 return error(
"Invalid record");
4278 Value *PersFn =
nullptr;
4279 if (getValueTypePair(Record, Idx, NextValueNo, PersFn))
4280 return error(
"Invalid record");
4285 return error(
"Personality function mismatch");
4288 bool IsCleanup = !!Record[Idx++];
4289 unsigned NumClauses = Record[Idx++];
4292 for (
unsigned J = 0; J != NumClauses; ++J) {
4297 if (getValueTypePair(Record, Idx, NextValueNo, Val)) {
4299 return error(
"Invalid record");
4303 !isa<ArrayType>(Val->
getType())) &&
4304 "Catch clause has a invalid type!");
4306 isa<ArrayType>(Val->
getType())) &&
4307 "Filter clause has invalid type!");
4312 InstructionList.push_back(I);
4317 if (Record.
size() != 4)
4318 return error(
"Invalid record");
4319 uint64_t AlignRecord = Record[3];
4320 const uint64_t InAllocaMask = uint64_t(1) << 5;
4321 const uint64_t ExplicitTypeMask = uint64_t(1) << 6;
4322 const uint64_t SwiftErrorMask = uint64_t(1) << 7;
4323 const uint64_t FlagMask = InAllocaMask | ExplicitTypeMask |
4325 bool InAlloca = AlignRecord & InAllocaMask;
4326 bool SwiftError = AlignRecord & SwiftErrorMask;
4327 Type *Ty = getTypeByID(Record[0]);
4328 if ((AlignRecord & ExplicitTypeMask) == 0) {
4329 auto *PTy = dyn_cast_or_null<PointerType>(Ty);
4331 return error(
"Old-style alloca with a non-pointer type");
4332 Ty = PTy->getElementType();
4334 Type *OpTy = getTypeByID(Record[1]);
4335 Value *
Size = getFnValueByID(Record[2], OpTy);
4337 if (
Error Err = parseAlignmentValue(AlignRecord & ~FlagMask, Align)) {
4341 return error(
"Invalid record");
4344 const DataLayout &DL = TheModule->getDataLayout();
4351 InstructionList.push_back(I);
4357 if (getValueTypePair(Record, OpNum, NextValueNo, Op) ||
4358 (OpNum + 2 != Record.
size() && OpNum + 3 != Record.
size()))
4359 return error(
"Invalid record");
4362 if (OpNum + 3 == Record.
size())
4363 Ty = getTypeByID(Record[OpNum++]);
4364 if (
Error Err = typeCheckLoadStoreInst(Ty, Op->
getType()))
4367 Ty = cast<PointerType>(Op->
getType())->getElementType();
4370 if (
Error Err = parseAlignmentValue(Record[OpNum], Align))
4372 I =
new LoadInst(Ty, Op,
"", Record[OpNum + 1], Align);
4374 InstructionList.push_back(I);
4381 if (getValueTypePair(Record, OpNum, NextValueNo, Op) ||
4382 (OpNum + 4 != Record.
size() && OpNum + 5 != Record.
size()))
4383 return error(
"Invalid record");
4386 if (OpNum + 5 == Record.
size())
4387 Ty = getTypeByID(Record[OpNum++]);
4388 if (
Error Err = typeCheckLoadStoreInst(Ty, Op->
getType()))
4391 Ty = cast<PointerType>(Op->
getType())->getElementType();
4397 return error(
"Invalid record");
4399 return error(
"Invalid record");
4400 SyncScope::ID SSID = getDecodedSyncScopeID(Record[OpNum + 3]);
4403 if (
Error Err = parseAlignmentValue(Record[OpNum], Align))
4405 I =
new LoadInst(Op,
"", Record[OpNum+1], Align, Ordering, SSID);
4407 InstructionList.push_back(I);
4414 if (getValueTypePair(Record, OpNum, NextValueNo, Ptr) ||
4416 ? getValueTypePair(Record, OpNum, NextValueNo, Val)
4417 : popValue(Record, OpNum, NextValueNo,
4418 cast<PointerType>(Ptr->
getType())->getElementType(),
4420 OpNum + 2 != Record.
size())
4421 return error(
"Invalid record");
4426 if (
Error Err = parseAlignmentValue(Record[OpNum], Align))
4428 I =
new StoreInst(Val, Ptr, Record[OpNum+1], Align);
4429 InstructionList.push_back(I);
4437 if (getValueTypePair(Record, OpNum, NextValueNo, Ptr) ||
4438 !isa<PointerType>(Ptr->
getType()) ||
4440 ? getValueTypePair(Record, OpNum, NextValueNo, Val)
4441 : popValue(Record, OpNum, NextValueNo,
4442 cast<PointerType>(Ptr->
getType())->getElementType(),
4444 OpNum + 4 != Record.
size())
4445 return error(
"Invalid record");
4453 return error(
"Invalid record");
4454 SyncScope::ID SSID = getDecodedSyncScopeID(Record[OpNum + 3]);
4456 return error(
"Invalid record");
4459 if (
Error Err = parseAlignmentValue(Record[OpNum], Align))
4461 I =
new StoreInst(Val, Ptr, Record[OpNum+1], Align, Ordering, SSID);
4462 InstructionList.push_back(I);
4470 Value *Ptr, *Cmp, *New;
4471 if (getValueTypePair(Record, OpNum, NextValueNo, Ptr) ||
4473 ? getValueTypePair(Record, OpNum, NextValueNo, Cmp)
4474 : popValue(Record, OpNum, NextValueNo,
4475 cast<PointerType>(Ptr->
getType())->getElementType(),
4477 popValue(Record, OpNum, NextValueNo, Cmp->
getType(), New) ||
4478 Record.
size() < OpNum + 3 || Record.
size() > OpNum + 5)
4479 return error(
"Invalid record");
4483 return error(
"Invalid record");
4484 SyncScope::ID SSID = getDecodedSyncScopeID(Record[OpNum + 2]);
4489 if (Record.
size() < 7)
4497 cast<AtomicCmpXchgInst>(
I)->setVolatile(Record[OpNum]);
4499 if (Record.
size() < 8) {
4506 cast<AtomicCmpXchgInst>(
I)->setWeak(Record[OpNum+4]);
4509 InstructionList.push_back(I);
4516 if (getValueTypePair(Record, OpNum, NextValueNo, Ptr) ||
4517 !isa<PointerType>(Ptr->
getType()) ||
4518 popValue(Record, OpNum, NextValueNo,
4519 cast<PointerType>(Ptr->
getType())->getElementType(), Val) ||
4520 OpNum+4 != Record.
size())
4521 return error(
"Invalid record");
4525 return error(
"Invalid record");
4529 return error(
"Invalid record");
4530 SyncScope::ID SSID = getDecodedSyncScopeID(Record[OpNum + 3]);
4532 cast<AtomicRMWInst>(
I)->setVolatile(Record[OpNum+1]);
4533 InstructionList.push_back(I);
4537 if (2 != Record.
size())
4538 return error(
"Invalid record");
4543 return error(
"Invalid record");
4545 I =
new FenceInst(Context, Ordering, SSID);
4546 InstructionList.push_back(I);
4551 if (Record.
size() < 3)
4552 return error(
"Invalid record");
4556 unsigned CCInfo = Record[OpNum++];
4562 return error(
"Fast math flags indicator set for call with no FMF");
4567 !(FTy = dyn_cast<FunctionType>(getTypeByID(Record[OpNum++]))))
4568 return error(
"Explicit call type is not a function type");
4571 if (getValueTypePair(Record, OpNum, NextValueNo, Callee))
4572 return error(
"Invalid record");
4576 return error(
"Callee is not a pointer type");
4580 return error(
"Callee is not of pointer to function type");
4582 return error(
"Explicit call type does not match pointee type of " 4585 return error(
"Insufficient operands to call");
4589 for (
unsigned i = 0, e = FTy->
getNumParams(); i != e; ++i, ++OpNum) {
4591 Args.
push_back(getBasicBlock(Record[OpNum]));
4593 Args.
push_back(getValue(Record, OpNum, NextValueNo,
4596 return error(
"Invalid record");
4601 if (OpNum != Record.
size())
4602 return error(
"Invalid record");
4604 while (OpNum != Record.
size()) {
4606 if (getValueTypePair(Record, OpNum, NextValueNo, Op))
4607 return error(
"Invalid record");
4613 OperandBundles.clear();
4614 InstructionList.push_back(I);
4615 cast<CallInst>(
I)->setCallingConv(
4624 cast<CallInst>(
I)->setTailCallKind(TCK);
4625 cast<CallInst>(
I)->setAttributes(PAL);
4627 if (!isa<FPMathOperator>(I))
4628 return error(
"Fast-math-flags specified for call without " 4629 "floating-point scalar or vector return type");
4635 if (Record.
size() < 3)
4636 return error(
"Invalid record");
4637 Type *OpTy = getTypeByID(Record[0]);
4638 Value *
Op = getValue(Record, 1, NextValueNo, OpTy);
4639 Type *ResTy = getTypeByID(Record[2]);
4640 if (!OpTy || !Op || !ResTy)
4641 return error(
"Invalid record");
4643 InstructionList.push_back(I);
4652 if (Record.
size() < 1 || Record[0] >= BundleTags.
size())
4653 return error(
"Invalid record");
4655 std::vector<Value *> Inputs;
4658 while (OpNum != Record.
size()) {
4660 if (getValueTypePair(Record, OpNum, NextValueNo, Op))
4661 return error(
"Invalid record");
4662 Inputs.push_back(Op);
4665 OperandBundles.emplace_back(BundleTags[Record[0]], std::move(Inputs));
4674 return error(
"Invalid instruction with no BB");
4676 if (!OperandBundles.empty()) {
4678 return error(
"Operand bundles found with no consumer");
4685 CurBB = CurBBNo < FunctionBBs.size() ? FunctionBBs[CurBBNo] :
nullptr;
4690 ValueList.assignValue(I, NextValueNo++);
4695 if (!OperandBundles.empty())
4696 return error(
"Operand bundles found with no consumer");
4699 if (
Argument *A = dyn_cast<Argument>(ValueList.back())) {
4700 if (!A->getParent()) {
4702 for (
unsigned i = ModuleValueListSize, e = ValueList.size(); i != e; ++i){
4703 if ((A = dyn_cast_or_null<Argument>(ValueList[i])) && !A->getParent()) {
4708 return error(
"Never resolved value found in function");
4713 if (MDLoader->hasFwdRefs())
4714 return error(
"Invalid function metadata: outgoing forward refs");
4717 ValueList.shrinkTo(ModuleValueListSize);
4718 MDLoader->shrinkTo(ModuleMDLoaderSize);
4719 std::vector<BasicBlock*>().
swap(FunctionBBs);
4724 Error BitcodeReader::findFunctionInStream(
4727 while (DeferredFunctionInfoIterator->second == 0) {
4735 if (
Error Err = rememberAndSkipFunctionBodies())
4741 SyncScope::ID BitcodeReader::getDecodedSyncScopeID(
unsigned Val) {
4744 if (Val >= SSIDs.size())
4760 assert(DFII != DeferredFunctionInfo.
end() &&
"Deferred function not found!");
4763 if (DFII->second == 0)
4764 if (
Error Err = findFunctionInStream(F, DFII))
4768 if (
Error Err = materializeMetadata())
4774 if (
Error Err = parseFunctionBody(F))
4782 for (
auto &
I : UpgradedIntrinsics) {
4783 for (
auto UI =
I.first->materialized_user_begin(), UE =
I.first->user_end();
4787 if (
CallInst *CI = dyn_cast<CallInst>(U))
4793 for (
auto &
I : RemangledIntrinsics)
4794 for (
auto UI =
I.first->materialized_user_begin(), UE =
I.first->user_end();
4804 if (!MDLoader->isStrippingTBAA()) {
4807 if (!TBAA || TBAAVerifyHelper.visitTBAAMetadata(
I, TBAA))
4809 MDLoader->setStripTBAA(
true);
4816 return materializeForwardReferencedFunctions();
4819 Error BitcodeReader::materializeModule() {
4820 if (
Error Err = materializeMetadata())
4824 WillMaterializeAllForwardRefs =
true;
4829 if (
Error Err = materialize(&F))
4835 if (LastFunctionBlockBit || NextUnreadBit)
4837 ? LastFunctionBlockBit
4843 if (!BasicBlockFwdRefs.empty())
4844 return error(
"Never resolved function from blockaddress");
4850 for (
auto &
I : UpgradedIntrinsics) {
4851 for (
auto *U :
I.first->users()) {
4852 if (
CallInst *CI = dyn_cast<CallInst>(U))
4855 if (!
I.first->use_empty())
4856 I.first->replaceAllUsesWith(
I.second);
4857 I.first->eraseFromParent();
4859 UpgradedIntrinsics.clear();
4861 for (
auto &
I : RemangledIntrinsics) {
4862 I.first->replaceAllUsesWith(
I.second);
4863 I.first->eraseFromParent();
4865 RemangledIntrinsics.clear();
4876 std::vector<StructType *> BitcodeReader::getIdentifiedStructTypes()
const {
4877 return IdentifiedStructTypes;
4880 ModuleSummaryIndexBitcodeReader::ModuleSummaryIndexBitcodeReader(
4882 StringRef ModulePath,
unsigned ModuleId)
4883 : BitcodeReaderBase(std::move(Cursor), Strtab), TheIndex(TheIndex),
4884 ModulePath(ModulePath), ModuleId(ModuleId) {}
4886 void ModuleSummaryIndexBitcodeReader::addThisModule() {
4887 TheIndex.
addModule(ModulePath, ModuleId);
4891 ModuleSummaryIndexBitcodeReader::getThisModule() {
4895 std::pair<ValueInfo, GlobalValue::GUID>
4896 ModuleSummaryIndexBitcodeReader::getValueInfoFromValueId(
unsigned ValueId) {
4897 auto VGI = ValueIdToValueInfoMap[ValueId];
4902 void ModuleSummaryIndexBitcodeReader::setValueGUID(
4905 std::string GlobalId =
4908 auto OriginalNameID = ValueGUID;
4912 dbgs() <<
"GUID " << ValueGUID <<
"(" << OriginalNameID <<
") is " 4913 << ValueName <<
"\n";
4918 ValueIdToValueInfoMap[ValueID] = std::make_pair(
4921 UseStrtab ? ValueName : TheIndex.
saveString(ValueName)),
4928 Error ModuleSummaryIndexBitcodeReader::parseValueSymbolTable(
4935 assert(Offset > 0 &&
"Expected non-zero VST offset");
4939 return error(
"Invalid record");
4949 switch (Entry.
Kind) {
4952 return error(
"Malformed block");
4969 return error(
"Invalid record");
4970 unsigned ValueID = Record[0];
4972 auto VLI = ValueIdToLinkageMap.
find(ValueID);
4973 assert(VLI != ValueIdToLinkageMap.
end() &&
4974 "No linkage found for VST entry?");
4975 auto Linkage = VLI->second;
4976 setValueGUID(ValueID, ValueName, Linkage, SourceFileName);
4983 return error(
"Invalid record");
4984 unsigned ValueID = Record[0];
4986 auto VLI = ValueIdToLinkageMap.
find(ValueID);
4987 assert(VLI != ValueIdToLinkageMap.
end() &&
4988 "No linkage found for VST entry?");
4989 auto Linkage = VLI->second;
4990 setValueGUID(ValueID, ValueName, Linkage, SourceFileName);
4996 unsigned ValueID = Record[0];
5000 ValueIdToValueInfoMap[ValueID] =
5013 return error(
"Invalid record");
5017 unsigned ValueId = 0;
5023 switch (Entry.
Kind) {
5025 return error(
"Malformed block");
5033 return error(
"Invalid record");
5037 if (readBlockInfo())
5038 return error(
"Malformed block");
5043 assert(((SeenValueSymbolTable && VSTOffset > 0) ||
5044 !SeenGlobalValSummary) &&
5045 "Expected early VST parse via VSTOffset record");
5047 return error(
"Invalid record");
5052 if (!SourceFileName.
empty())
5054 assert(!SeenValueSymbolTable &&
5055 "Already read VST when parsing summary block?");
5060 if (VSTOffset > 0) {
5061 if (
Error Err = parseValueSymbolTable(VSTOffset, ValueIdToLinkageMap))
5063 SeenValueSymbolTable =
true;
5065 SeenGlobalValSummary =
true;
5066 if (
Error Err = parseEntireSummary(Entry.
ID))
5070 if (
Error Err = parseModuleStringTable())
5083 if (
Error Err = parseVersionRecord(Record).takeError())
5091 return error(
"Invalid record");
5092 SourceFileName = ValueName.
c_str();
5097 if (Record.
size() != 5)
5098 return error(
"Invalid hash length " +
Twine(Record.
size()).str());
5099 auto &Hash = getThisModule()->second.second;
5101 for (
auto &Val : Record) {
5102 assert(!(Val >> 32) &&
"Unexpected high bits set");
5109 if (Record.
size() < 1)
5110 return error(
"Invalid record");
5114 VSTOffset = Record[0] - 1;
5125 std::tie(Name, GVRecord) = readNameFromStrtab(Record);
5126 if (GVRecord.
size() <= 3)
5127 return error(
"Invalid record");
5128 uint64_t RawLinkage = GVRecord[3];
5131 ValueIdToLinkageMap[ValueId++] = Linkage;
5135 setValueGUID(ValueId++, Name, Linkage, SourceFileName);
5145 std::vector<ValueInfo>
5147 std::vector<ValueInfo>
Ret;
5148 Ret.reserve(Record.
size());
5149 for (uint64_t RefValueId : Record)
5150 Ret.push_back(getValueInfoFromValueId(RefValueId).
first);
5154 std::vector<FunctionSummary::EdgeTy>
5156 bool IsOldProfileFormat,
5157 bool HasProfile,
bool HasRelBF) {
5158 std::vector<FunctionSummary::EdgeTy>
Ret;
5159 Ret.reserve(Record.
size());
5160 for (
unsigned I = 0,
E = Record.
size();
I !=
E; ++
I) {
5164 if (IsOldProfileFormat) {
5168 }
else if (HasProfile)
5171 RelBF = Record[++
I];
5180 uint64_t ArgNum = Record[Slot++];
5187 B.
Info = Record[Slot++];
5188 B.
Byte = Record[Slot++];
5189 B.
Bit = Record[Slot++];
5195 uint64_t
Id = Record[Slot++];
5200 static_cast<size_t>(Record[Slot + 1])};
5203 uint64_t ResByArgNum = Record[Slot++];
5204 for (uint64_t
I = 0;
I != ResByArgNum; ++
I)
5213 {Strtab.
data() + Record[Slot],
static_cast<size_t>(Record[Slot + 1])});
5223 while (Slot < Record.
size())
5229 for (
unsigned RefNo = Refs.size() - Count; RefNo < Refs.size(); ++RefNo)
5230 Refs[RefNo].setReadOnly();
5235 Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(
unsigned ID) {
5237 return error(
"Invalid record");
5244 return error(
"Invalid Summary Block: record for version expected");
5246 return error(
"Invalid Summary Block: version expected");
5248 const uint64_t
Version = Record[0];
5249 const bool IsOldProfileFormat = Version == 1;
5250 if (Version < 1 || Version > 6)
5251 return error(
"Invalid summary version " +
Twine(Version) +
5252 ". Version should be in the range [1-6].");
5263 std::vector<GlobalValue::GUID> PendingTypeTests;
5264 std::vector<FunctionSummary::VFuncId> PendingTypeTestAssumeVCalls,
5265 PendingTypeCheckedLoadVCalls;
5266 std::vector<FunctionSummary::ConstVCall> PendingTypeTestAssumeConstVCalls,
5267 PendingTypeCheckedLoadConstVCalls;
5272 switch (Entry.
Kind) {
5275 return error(
"Malformed block");
5296 uint64_t Flags = Record[0];
5298 assert(Flags <= 0x1f &&
"Unexpected bits in flag");
5324 uint64_t ValueID = Record[0];
5326 ValueIdToValueInfoMap[ValueID] =
5341 unsigned ValueID = Record[0];
5342 uint64_t RawFlags = Record[1];
5343 unsigned InstCount = Record[2];
5344 uint64_t RawFunFlags = 0;
5345 unsigned NumRefs = Record[3];
5346 unsigned NumImmutableRefs = 0;
5347 int RefListStartIndex = 4;
5349 RawFunFlags = Record[3];
5350 NumRefs = Record[4];
5351 RefListStartIndex = 5;
5353 NumImmutableRefs = Record[5];
5354 RefListStartIndex = 6;
5364 int CallGraphEdgeStartIndex = RefListStartIndex + NumRefs;
5365 assert(Record.
size() >= RefListStartIndex + NumRefs &&
5366 "Record size inconsistent with number of references");
5367 std::vector<ValueInfo> Refs = makeRefList(
5371 std::vector<FunctionSummary::EdgeTy> Calls = makeCallList(
5373 IsOldProfileFormat, HasProfile, HasRelBF);
5375 auto FS = llvm::make_unique<FunctionSummary>(
5377 std::move(Refs), std::move(Calls), std::move(PendingTypeTests),
5378 std::move(PendingTypeTestAssumeVCalls),
5379 std::move(PendingTypeCheckedLoadVCalls),
5380 std::move(PendingTypeTestAssumeConstVCalls),
5381 std::move(PendingTypeCheckedLoadConstVCalls));
5382 PendingTypeTests.clear();
5383 PendingTypeTestAssumeVCalls.clear();
5384 PendingTypeCheckedLoadVCalls.clear();
5385 PendingTypeTestAssumeConstVCalls.clear();
5386 PendingTypeCheckedLoadConstVCalls.clear();
5387 auto VIAndOriginalGUID = getValueInfoFromValueId(ValueID);
5388 FS->setModulePath(getThisModule()->
first());
5389 FS->setOriginalName(VIAndOriginalGUID.second);
5397 unsigned ValueID = Record[0];
5398 uint64_t RawFlags = Record[1];
5399 unsigned AliaseeID = Record[2];
5401 auto AS = llvm::make_unique<AliasSummary>(Flags);
5407 AS->setModulePath(getThisModule()->
first());
5410 getValueInfoFromValueId(AliaseeID).first.getGUID();
5411 auto AliaseeInModule =
5413 if (!AliaseeInModule)
5414 return error(
"Alias expects aliasee summary to be parsed");
5415 AS->setAliasee(AliaseeInModule);
5416 AS->setAliaseeGUID(AliaseeGUID);
5418 auto GUID = getValueInfoFromValueId(ValueID);
5419 AS->setOriginalName(GUID.second);
5425 unsigned ValueID = Record[0];
5426 uint64_t RawFlags = Record[1];
5427 unsigned RefArrayStart = 2;
5434 std::vector<ValueInfo> Refs =
5437 llvm::make_unique<GlobalVarSummary>(Flags, GVF, std::move(Refs));
5438 FS->setModulePath(getThisModule()->
first());
5439 auto GUID = getValueInfoFromValueId(ValueID);
5440 FS->setOriginalName(GUID.second);
5450 unsigned ValueID = Record[0];
5451 uint64_t ModuleId = Record[1];
5452 uint64_t RawFlags = Record[2];
5453 unsigned InstCount = Record[3];
5454 uint64_t RawFunFlags = 0;
5455 uint64_t EntryCount = 0;
5456 unsigned NumRefs = Record[4];
5457 unsigned NumImmutableRefs = 0;
5458 int RefListStartIndex = 5;
5461 RawFunFlags = Record[4];
5462 RefListStartIndex = 6;
5463 size_t NumRefsIndex = 5;
5465 RefListStartIndex = 7;
5468 EntryCount = Record[5];
5469 RefListStartIndex = 8;
5471 NumImmutableRefs = Record[RefListStartIndex - 1];
5473 NumRefs = Record[NumRefsIndex];
5477 int CallGraphEdgeStartIndex = RefListStartIndex + NumRefs;
5478 assert(Record.
size() >= RefListStartIndex + NumRefs &&
5479 "Record size inconsistent with number of references");
5480 std::vector<ValueInfo> Refs = makeRefList(
5483 std::vector<FunctionSummary::EdgeTy> Edges = makeCallList(
5485 IsOldProfileFormat, HasProfile,
false);
5486 ValueInfo VI = getValueInfoFromValueId(ValueID).first;
5488 auto FS = llvm::make_unique<FunctionSummary>(
5490 std::move(Refs), std::move(Edges), std::move(PendingTypeTests),
5491 std::move(PendingTypeTestAssumeVCalls),
5492 std::move(PendingTypeCheckedLoadVCalls),
5493 std::move(PendingTypeTestAssumeConstVCalls),
5494 std::move(PendingTypeCheckedLoadConstVCalls));
5495 PendingTypeTests.clear();
5496 PendingTypeTestAssumeVCalls.clear();
5497 PendingTypeCheckedLoadVCalls.clear();
5498 PendingTypeTestAssumeConstVCalls.clear();
5499 PendingTypeCheckedLoadConstVCalls.clear();
5500 LastSeenSummary = FS.get();
5502 FS->setModulePath(ModuleIdMap[ModuleId]);
5510 unsigned ValueID = Record[0];
5511 uint64_t ModuleId = Record[1];
5512 uint64_t RawFlags = Record[2];
5513 unsigned AliaseeValueId = Record[3];
5515 auto AS = llvm::make_unique<AliasSummary>(Flags);
5516 LastSeenSummary = AS.get();
5520 getValueInfoFromValueId(AliaseeValueId).first.getGUID();
5521 auto AliaseeInModule =
5523 AS->setAliasee(AliaseeInModule);
5524 AS->setAliaseeGUID(AliaseeGUID);
5526 ValueInfo VI = getValueInfoFromValueId(ValueID).first;
5533 unsigned ValueID = Record[0];
5534 uint64_t ModuleId = Record[1];
5535 uint64_t RawFlags = Record[2];
5536 unsigned RefArrayStart = 3;
5543 std::vector<ValueInfo> Refs =
5546 llvm::make_unique<GlobalVarSummary>(Flags, GVF, std::move(Refs));
5547 LastSeenSummary = FS.get();
5549 ValueInfo VI = getValueInfoFromValueId(ValueID).first;
5556 uint64_t OriginalName = Record[0];
5557 if (!LastSeenSummary)
5558 return error(
"Name attachment that does not follow a combined record");
5562 LastSeenSummary =
nullptr;
5567 assert(PendingTypeTests.empty());
5568 PendingTypeTests.insert(PendingTypeTests.end(), Record.
begin(),
5573 assert(PendingTypeTestAssumeVCalls.empty());
5574 for (
unsigned I = 0;
I != Record.
size();
I += 2)
5575 PendingTypeTestAssumeVCalls.push_back({Record[I], Record[I+1]});
5579 assert(PendingTypeCheckedLoadVCalls.empty());
5580 for (
unsigned I = 0;
I != Record.
size();
I += 2)
5581 PendingTypeCheckedLoadVCalls.push_back({Record[I], Record[I+1]});
5585 PendingTypeTestAssumeConstVCalls.push_back(
5586 {{Record[0], Record[1]}, {Record.begin() + 2, Record.end()}});
5590 PendingTypeCheckedLoadConstVCalls.push_back(
5591 {{Record[0], Record[1]}, {Record.begin() + 2, Record.end()}});
5596 for (
unsigned I = 0;
I != Record.
size();
I += 2)
5597 CfiFunctionDefs.insert(
5598 {Strtab.data() + Record[I], static_cast<size_t>(Record[I + 1])});
5604 for (
unsigned I = 0;
I != Record.
size();
I += 2)
5605 CfiFunctionDecls.insert(
5606 {Strtab.data() + Record[I], static_cast<size_t>(Record[I + 1])});
5620 Error ModuleSummaryIndexBitcodeReader::parseModuleStringTable() {
5622 return error(
"Invalid record");
5632 switch (Entry.
Kind) {
5635 return error(
"Malformed block");
5649 uint64_t ModuleId = Record[0];
5652 return error(
"Invalid record");
5654 LastSeenModule = TheIndex.
addModule(ModulePath, ModuleId);
5655 ModuleIdMap[ModuleId] = LastSeenModule->
first();
5662 if (Record.
size() != 5)
5663 return error(
"Invalid hash length " +
Twine(Record.
size()).str());
5664 if (!LastSeenModule)
5665 return error(
"Invalid hash that does not follow a module path");
5667 for (
auto &Val : Record) {
5668 assert(!(Val >> 32) &&
"Unexpected high bits set");
5669 LastSeenModule->
second.second[Pos++] = Val;
5672 LastSeenModule =
nullptr;
5686 const char *
name()
const noexcept
override {
5687 return "llvm.bitcode";
5690 std::string message(
int IE)
const override {
5694 return "Corrupted bitcode";
5709 unsigned Block,
unsigned RecordID) {
5711 return error(
"Invalid record");
5716 switch (Entry.
Kind) {
5721 return error(
"Malformed block");
5725 return error(
"Malformed block");
5731 if (Stream.
readRecord(Entry.
ID, Record, &Blob) == RecordID)
5746 return FOrErr.takeError();
5747 return std::move(FOrErr->Mods);
5768 switch (Entry.
Kind) {
5771 return error(
"Malformed block");
5774 uint64_t IdentificationBit = -1ull;
5778 return error(
"Malformed block");
5783 return error(
"Malformed block");
5789 return error(
"Malformed block");
5807 for (
auto I = F.
Mods.rbegin(),
E = F.
Mods.rend();
I !=
E; ++
I) {
5808 if (!
I->Strtab.empty())
5810 I->Strtab = *Strtab;
5838 return error(
"Malformed block");
5857 BitcodeModule::getModuleImpl(
LLVMContext &Context,
bool MaterializeAll,
5858 bool ShouldLazyLoadMetadata,
bool IsImporting) {
5861 std::string ProducerIdentification;
5862 if (IdentificationBit != -1ull) {
5866 if (!ProducerIdentificationOrErr)
5867 return ProducerIdentificationOrErr.
takeError();
5869 ProducerIdentification = *ProducerIdentificationOrErr;
5873 auto *R =
new BitcodeReader(std::move(Stream), Strtab, ProducerIdentification,
5876 std::unique_ptr<Module> M =
5877 llvm::make_unique<Module>(ModuleIdentifier,
Context);
5882 R->parseBitcodeInto(M.get(), ShouldLazyLoadMetadata, IsImporting))
5883 return std::move(Err);
5885 if (MaterializeAll) {
5887 if (
Error Err = M->materializeAll())
5888 return std::move(Err);
5891 if (
Error Err = R->materializeForwardReferencedFunctions())
5892 return std::move(Err);
5894 return std::move(M);
5900 return getModuleImpl(Context,
false, ShouldLazyLoadMetadata, IsImporting);
5908 StringRef ModulePath, uint64_t ModuleId) {
5912 ModuleSummaryIndexBitcodeReader R(std::move(Stream), Strtab, CombinedIndex,
5913 ModulePath, ModuleId);
5914 return R.parseModule();
5922 auto Index = llvm::make_unique<ModuleSummaryIndex>(
false);
5923 ModuleSummaryIndexBitcodeReader R(std::move(Stream), Strtab, *
Index,
5924 ModuleIdentifier, 0);
5926 if (
Error Err = R.parseModule())
5927 return std::move(Err);
5929 return std::move(
Index);
5935 return error(
"Invalid record");
5941 switch (Entry.
Kind) {
5944 return error(
"Malformed block");
5961 uint64_t Flags = Record[0];
5963 assert(Flags <= 0x1f &&
"Unexpected bits in flag");
5978 return error(
"Invalid record");
5983 switch (Entry.
Kind) {
5985 return error(
"Malformed block");
5994 if (!EnableSplitLTOUnit)
5997 *EnableSplitLTOUnit};
6003 if (!EnableSplitLTOUnit)
6006 *EnableSplitLTOUnit};
6011 return error(
"Malformed block");
6026 if (MsOrErr->size() != 1)
6027 return error(
"Expected a single module");
6029 return (*MsOrErr)[0];
6034 bool ShouldLazyLoadMetadata,
bool IsImporting) {
6039 return BM->getLazyModule(Context, ShouldLazyLoadMetadata, IsImporting);
6043 std::unique_ptr<MemoryBuffer> &&Buffer,
LLVMContext &Context,
6044 bool ShouldLazyLoadMetadata,
bool IsImporting) {
6048 (*MOrErr)->setOwnedMemoryBuffer(std::move(Buffer));
6054 return getModuleImpl(Context,
true,
false,
false);
6065 return BM->parseModule(Context);
6094 uint64_t ModuleId) {
6099 return BM->readSummary(CombinedIndex, BM->getModuleIdentifier(), ModuleId);
6108 return BM->getSummary();
6116 return BM->getLTOInfo();
6121 bool IgnoreEmptyThinLTOIndexFile) {
6126 if (IgnoreEmptyThinLTOIndexFile && !(*FileOrErr)->getBufferSize())
void setVisibility(VisibilityTypes V)
static AtomicOrdering getDecodedOrdering(unsigned Val)
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
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)
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...
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)
static bool hasValidBitcodeHeader(BitstreamCursor &Stream)
Helper to read the header common to all bitcode files.
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.
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.
GlobalValueSummary * findSummaryInModule(GlobalValue::GUID ValueGUID, StringRef ModuleId) const
Find the summary for global GUID in module ModuleId, or nullptr if not found.
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)
bool UpgradeRetainReleaseMarker(Module &M)
This checks for objc retain release marker which should be upgraded.
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)
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space...
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.
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.
static uint64_t jumpToValueSymbolTable(uint64_t Offset, BitstreamCursor &Stream)
Helper to note and return the current location, and jump to the given offset.
void setNoInfs(bool B=true)
AttrBuilder & addDereferenceableAttr(uint64_t Bytes)
This turns the number of dereferenceable bytes into the form used internally in Attribute.
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.
An instruction for reading from memory.
ELFYAML::ELF_STV Visibility
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...
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...
void setAlignment(unsigned Align)
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
word_t Read(unsigned NumBits)
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)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
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.
Value * getValueFwdRef(unsigned Idx, Type *Ty)
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...
amdgpu Simplify well known AMD library false Value Value const Twine & Name
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.
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.
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
The highest possible calling convention ID. Must be some 2^k - 1.
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.
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 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)
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)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
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.
static const fltSemantics & IEEEdouble() LLVM_READNONE
BitstreamEntry advanceSkippingSubblocks(unsigned Flags=0)
This is a convenience function for clients that don't expect any subblocks.
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().
amdgpu Simplify well known AMD library false Value * Callee
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...
Maximum number of bits that can be specified.
void setCallingConv(CallingConv::ID CC)
Same, but only replaced by something equivalent.
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.
Minimum number of bits that can be specified.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
enum llvm::BitstreamEntry::@149 Kind
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 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.
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.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
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)
const Instruction & back() const
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
This instruction compares its operands according to the predicate given to the constructor.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
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)
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 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.
void JumpToBit(uint64_t BitNo)
Reset the stream to the specified bit number.
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.
bool SkipBlock()
Having read the ENTER_SUBBLOCK abbrevid and a BlockID, skip over the body of this block...
static wasm::ValType getType(const TargetRegisterClass *RC)
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)
Triple - Helper class for working with autoconf configuration names.
static Type * getFP128Ty(LLVMContext &C)
static Comdat::SelectionKind getDecodedComdatSelectionKind(unsigned Val)
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
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)
static Expected< std::string > readIdentificationBlock(BitstreamCursor &Stream)
Read the "IDENTIFICATION_BLOCK_ID" block, do some basic enforcement on the "epoch" encoded in the bit...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Keep one copy of function when linking (inline)
Module.h This file contains the declarations for the Module class.
bool UpgradeGlobalVariable(GlobalVariable *GV)
This checks for global variables which should be upgraded.
unsigned readRecord(unsigned AbbrevID, SmallVectorImpl< uint64_t > &Vals, StringRef *Blob=nullptr)
void setApproxFunc(bool B=true)
This class maintains the abbreviations read from a block info block.
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...
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.
Class to represent vector types.
unsigned skipRecord(unsigned AbbrevID)
Read the current record and discard it, returning the code for the record.
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.
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.
Optional< BitstreamBlockInfo > ReadBlockInfoBlock(bool ReadBlockInfoNames=false)
Read and return a block info block from the bitstream.
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...
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.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
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.
ValID - Represents a reference of a definition of some sort with no type.
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)
bool EnterSubBlock(unsigned BlockID, unsigned *NumWordsP=nullptr)
Having read the ENTER_SUBBLOCK abbrevid, enter the block, and return true if the block has an error...
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 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.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
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 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.
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.
static void setImmutableRefs(std::vector< ValueInfo > &Refs, unsigned Count)
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...
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::error_code errorToErrorCodeAndEmitErrors(LLVMContext &Ctx, Error Err)
Synchronized with respect to signal handlers executing in the same thread.
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 VectorType * get(Type *ElementType, unsigned NumElements)
This static method is the primary way to construct an VectorType.
static StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
Synchronized with respect to all concurrently executing threads.
Lightweight error class with error context and mandatory checking.
static CleanupReturnInst * Create(Value *CleanupPad, BasicBlock *UnwindBB=nullptr, Instruction *InsertBefore=nullptr)
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.
AttrBuilder & addStackAlignmentAttr(unsigned Align)
This turns an int stack alignment (which must be a power of 2) into the form used internally in Attri...
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.
BitstreamEntry advance(unsigned Flags=0)
Advance the current bitstream, returning the next entry in the stream.
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
AttrBuilder & addAlignmentAttr(unsigned Align)
This turns an int alignment (which must be a power of 2) into the form used internally in Attribute...
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
Type * getArrayElementType() const
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.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
unsigned ReturnDoesNotAlias
void setSection(StringRef S)
Change the section for this global.
void setCalledFunction(Value *V)
Set the callee to the specified value.
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.
Type * getElementType() const
void setDSOLocal(bool Local)
PointerType * getType() const
Global values are always pointers.
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)