41 SWITCH_INST_MAGIC = 0x4B5
44 class BitcodeReaderValueList {
45 std::vector<WeakVH> ValuePtrs;
54 typedef std::vector<std::pair<Constant*, unsigned> > ResolveConstantsTy;
55 ResolveConstantsTy ResolveConstants;
59 ~BitcodeReaderValueList() {
60 assert(ResolveConstants.empty() &&
"Constants not resolved?");
64 unsigned size()
const {
return ValuePtrs.size(); }
65 void resize(
unsigned N) { ValuePtrs.resize(N); }
66 void push_back(
Value *V) { ValuePtrs.emplace_back(V); }
69 assert(ResolveConstants.empty() &&
"Constants not resolved?");
73 Value *operator[](
unsigned i)
const {
74 assert(i < ValuePtrs.size());
78 Value *back()
const {
return ValuePtrs.back(); }
79 void pop_back() { ValuePtrs.pop_back(); }
80 bool empty()
const {
return ValuePtrs.empty(); }
81 void shrinkTo(
unsigned N) {
82 assert(N <=
size() &&
"Invalid shrinkTo request!");
87 Value *getValueFwdRef(
unsigned Idx,
Type *Ty);
89 void assignValue(
Value *V,
unsigned Idx);
93 void resolveConstantForwardRefs();
96 class BitcodeReaderMDValueList {
101 std::vector<TrackingMDRef> MDValuePtrs;
106 : NumFwdRefs(0), AnyFwdRefs(
false), Context(C) {}
109 unsigned size()
const {
return MDValuePtrs.size(); }
110 void resize(
unsigned N) { MDValuePtrs.resize(N); }
111 void push_back(
Metadata *MD) { MDValuePtrs.emplace_back(MD); }
112 void clear() { MDValuePtrs.clear(); }
113 Metadata *back()
const {
return MDValuePtrs.back(); }
114 void pop_back() { MDValuePtrs.pop_back(); }
115 bool empty()
const {
return MDValuePtrs.empty(); }
117 Metadata *operator[](
unsigned i)
const {
118 assert(i < MDValuePtrs.size());
119 return MDValuePtrs[i];
122 void shrinkTo(
unsigned N) {
123 assert(N <=
size() &&
"Invalid shrinkTo request!");
124 MDValuePtrs.resize(N);
127 Metadata *getValueFwdRef(
unsigned Idx);
128 void assignValue(
Metadata *MD,
unsigned Idx);
129 void tryToResolveCycles();
135 Module *TheModule =
nullptr;
136 std::unique_ptr<MemoryBuffer> Buffer;
137 std::unique_ptr<BitstreamReader> StreamFile;
139 uint64_t NextUnreadBit = 0;
140 bool SeenValueSymbolTable =
false;
142 std::vector<Type*> TypeList;
143 BitcodeReaderValueList ValueList;
144 BitcodeReaderMDValueList MDValueList;
145 std::vector<Comdat *> ComdatList;
148 std::vector<std::pair<GlobalVariable*, unsigned> > GlobalInits;
149 std::vector<std::pair<GlobalAlias*, unsigned> > AliasInits;
150 std::vector<std::pair<Function*, unsigned> > FunctionPrefixes;
151 std::vector<std::pair<Function*, unsigned> > FunctionPrologues;
152 std::vector<std::pair<Function*, unsigned> > FunctionPersonalityFns;
158 std::vector<AttributeSet> MAttributes;
161 std::map<unsigned, AttributeSet> MAttributeGroups;
165 std::vector<BasicBlock*> FunctionBBs;
169 std::vector<Function*> FunctionsWithBodies;
174 UpgradedIntrinsicMap UpgradedIntrinsics;
182 bool SeenFirstFunctionBody =
false;
191 std::vector<uint64_t> DeferredMetadataInfo;
197 std::deque<Function *> BasicBlockFwdRefQueue;
205 bool UseRelativeIDs =
false;
209 bool WillMaterializeAllForwardRefs =
false;
215 bool IsMetadataMaterialized =
false;
228 ~BitcodeReader()
override { freeState(); }
230 std::error_code materializeForwardReferencedFunctions();
234 void releaseBuffer();
236 bool isDematerializable(
const GlobalValue *GV)
const override;
237 std::error_code materialize(
GlobalValue *GV)
override;
238 std::error_code materializeModule(
Module *M)
override;
239 std::vector<StructType *> getIdentifiedStructTypes()
const override;
244 std::error_code parseBitcodeInto(std::unique_ptr<DataStreamer> Streamer,
246 bool ShouldLazyLoadMetadata =
false);
252 static uint64_t decodeSignRotatedValue(uint64_t V);
255 std::error_code materializeMetadata()
override;
257 void setStripDebugInfo()
override;
260 std::vector<StructType *> IdentifiedStructTypes;
264 Type *getTypeByID(
unsigned ID);
268 return ValueList.getValueFwdRef(ID, Ty);
270 Metadata *getFnMetadataByID(
unsigned ID) {
271 return MDValueList.getValueFwdRef(ID);
273 BasicBlock *getBasicBlock(
unsigned ID)
const {
274 if (ID >= FunctionBBs.size())
return nullptr;
275 return FunctionBBs[
ID];
278 if (i-1 < MAttributes.size())
279 return MAttributes[i-1];
287 unsigned InstNum,
Value *&ResVal) {
288 if (Slot == Record.
size())
return true;
289 unsigned ValNo = (
unsigned)Record[Slot++];
292 ValNo = InstNum - ValNo;
293 if (ValNo < InstNum) {
296 ResVal = getFnValueByID(ValNo,
nullptr);
297 return ResVal ==
nullptr;
299 if (Slot == Record.
size())
302 unsigned TypeNo = (
unsigned)Record[Slot++];
303 ResVal = getFnValueByID(ValNo, getTypeByID(TypeNo));
304 return ResVal ==
nullptr;
311 unsigned InstNum,
Type *Ty,
Value *&ResVal) {
312 if (getValue(Record, Slot, InstNum, Ty, ResVal))
321 unsigned InstNum,
Type *Ty,
Value *&ResVal) {
322 ResVal = getValue(Record, Slot, InstNum, Ty);
323 return ResVal ==
nullptr;
329 unsigned InstNum,
Type *Ty) {
330 if (Slot == Record.
size())
return nullptr;
331 unsigned ValNo = (
unsigned)Record[Slot];
334 ValNo = InstNum - ValNo;
335 return getFnValueByID(ValNo, Ty);
340 unsigned InstNum,
Type *Ty) {
341 if (Slot == Record.
size())
return nullptr;
342 unsigned ValNo = (
unsigned)decodeSignRotatedValue(Record[Slot]);
345 ValNo = InstNum - ValNo;
346 return getFnValueByID(ValNo, Ty);
352 std::error_code parseAlignmentValue(uint64_t Exponent,
unsigned &Alignment);
354 std::error_code parseModule(
bool Resume,
bool ShouldLazyLoadMetadata =
false);
355 std::error_code parseAttributeBlock();
356 std::error_code parseAttributeGroupBlock();
357 std::error_code parseTypeTable();
358 std::error_code parseTypeTableBody();
360 std::error_code parseValueSymbolTable();
361 std::error_code parseConstants();
362 std::error_code rememberAndSkipFunctionBody();
364 std::error_code rememberAndSkipMetadata();
365 std::error_code parseFunctionBody(
Function *
F);
366 std::error_code globalCleanup();
367 std::error_code resolveGlobalAndAliasInits();
368 std::error_code parseMetadata();
369 std::error_code parseMetadataAttachment(
Function &
F);
371 std::error_code parseUseLists();
372 std::error_code initStream(std::unique_ptr<DataStreamer> Streamer);
373 std::error_code initStreamFromBuffer();
374 std::error_code initLazyStream(std::unique_ptr<DataStreamer> Streamer);
375 std::error_code findFunctionInStream(
389 std::error_code EC,
const Twine &Message) {
391 DiagnosticHandler(DI);
396 std::error_code EC) {
397 return error(DiagnosticHandler, EC, EC.message());
401 const Twine &Message) {
402 return error(DiagnosticHandler,
430 Buffer(Buffer), ValueList(Context), MDValueList(Context) {}
436 Buffer(nullptr), ValueList(Context), MDValueList(Context) {}
438 std::error_code BitcodeReader::materializeForwardReferencedFunctions() {
439 if (WillMaterializeAllForwardRefs)
440 return std::error_code();
443 WillMaterializeAllForwardRefs =
true;
445 while (!BasicBlockFwdRefQueue.empty()) {
446 Function *
F = BasicBlockFwdRefQueue.front();
447 BasicBlockFwdRefQueue.pop_front();
448 assert(F &&
"Expected valid function");
449 if (!BasicBlockFwdRefs.count(F))
458 return error(
"Never resolved function from blockaddress");
461 if (std::error_code EC = materialize(F))
464 assert(BasicBlockFwdRefs.empty() &&
"Function missing from queue");
467 WillMaterializeAllForwardRefs =
false;
468 return std::error_code();
471 void BitcodeReader::freeState() {
473 std::vector<Type*>().
swap(TypeList);
476 std::vector<Comdat *>().
swap(ComdatList);
478 std::vector<AttributeSet>().
swap(MAttributes);
479 std::vector<BasicBlock*>().
swap(FunctionBBs);
480 std::vector<Function*>().
swap(FunctionsWithBodies);
481 DeferredFunctionInfo.clear();
482 DeferredMetadataInfo.clear();
485 assert(BasicBlockFwdRefs.empty() &&
"Unresolved blockaddress fwd references");
486 BasicBlockFwdRefQueue.clear();
494 template <
typename StrTy>
497 if (Idx > Record.
size())
500 for (
unsigned i = Idx, e = Record.
size(); i != e; ++i)
501 Result += (
char)Record[i];
521 return GlobalValue::ExternalLinkage;
523 return GlobalValue::AppendingLinkage;
525 return GlobalValue::InternalLinkage;
527 return GlobalValue::ExternalLinkage;
529 return GlobalValue::ExternalLinkage;
531 return GlobalValue::ExternalWeakLinkage;
533 return GlobalValue::CommonLinkage;
535 return GlobalValue::PrivateLinkage;
537 return GlobalValue::AvailableExternallyLinkage;
539 return GlobalValue::PrivateLinkage;
541 return GlobalValue::PrivateLinkage;
543 return GlobalValue::ExternalLinkage;
546 return GlobalValue::WeakAnyLinkage;
549 return GlobalValue::WeakODRLinkage;
552 return GlobalValue::LinkOnceAnyLinkage;
555 return GlobalValue::LinkOnceODRLinkage;
562 case 0:
return GlobalValue::DefaultVisibility;
563 case 1:
return GlobalValue::HiddenVisibility;
564 case 2:
return GlobalValue::ProtectedVisibility;
572 case 0:
return GlobalValue::DefaultStorageClass;
573 case 1:
return GlobalValue::DLLImportStorageClass;
574 case 2:
return GlobalValue::DLLExportStorageClass;
580 case 0:
return GlobalVariable::NotThreadLocal;
582 case 1:
return GlobalVariable::GeneralDynamicTLSModel;
583 case 2:
return GlobalVariable::LocalDynamicTLSModel;
584 case 3:
return GlobalVariable::InitialExecTLSModel;
585 case 4:
return GlobalVariable::LocalExecTLSModel;
618 return IsFP ? Instruction::FAdd : Instruction::Add;
620 return IsFP ? Instruction::FSub : Instruction::Sub;
622 return IsFP ? Instruction::FMul : Instruction::Mul;
624 return IsFP ? -1 : Instruction::UDiv;
626 return IsFP ? Instruction::FDiv : Instruction::SDiv;
628 return IsFP ? -1 : Instruction::URem;
630 return IsFP ? Instruction::FRem : Instruction::SRem;
632 return IsFP ? -1 : Instruction::Shl;
634 return IsFP ? -1 : Instruction::LShr;
636 return IsFP ? -1 : Instruction::AShr;
648 default:
return AtomicRMWInst::BAD_BINOP;
690 return Comdat::ExactMatch;
692 return Comdat::Largest;
694 return Comdat::NoDuplicates;
696 return Comdat::SameSize;
702 if (0 != (Val & FastMathFlags::UnsafeAlgebra))
704 if (0 != (Val & FastMathFlags::NoNaNs))
706 if (0 != (Val & FastMathFlags::NoInfs))
708 if (0 != (Val & FastMathFlags::NoSignedZeros))
710 if (0 != (Val & FastMathFlags::AllowReciprocal))
727 void operator=(
const ConstantPlaceHolder &) =
delete;
731 void *
operator new(
size_t s) {
return User::operator
new(s, 1); }
738 static bool classof(
const Value *V) {
739 return isa<ConstantExpr>(V) &&
740 cast<ConstantExpr>(V)->getOpcode() == Instruction::UserOp1;
756 void BitcodeReaderValueList::assignValue(
Value *V,
unsigned Idx) {
765 WeakVH &OldV = ValuePtrs[Idx];
773 if (
Constant *PHC = dyn_cast<Constant>(&*OldV)) {
774 ResolveConstants.push_back(std::make_pair(PHC, Idx));
778 Value *PrevVal = OldV;
779 OldV->replaceAllUsesWith(V);
785 Constant *BitcodeReaderValueList::getConstantFwdRef(
unsigned Idx,
790 if (
Value *V = ValuePtrs[Idx]) {
793 return cast<Constant>(V);
797 Constant *
C =
new ConstantPlaceHolder(Ty, Context);
802 Value *BitcodeReaderValueList::getValueFwdRef(
unsigned Idx,
Type *Ty) {
810 if (
Value *V = ValuePtrs[Idx]) {
818 if (!Ty)
return nullptr;
832 void BitcodeReaderValueList::resolveConstantForwardRefs() {
835 std::sort(ResolveConstants.begin(), ResolveConstants.end());
839 while (!ResolveConstants.empty()) {
840 Value *RealVal = operator[](ResolveConstants.back().second);
841 Constant *Placeholder = ResolveConstants.back().first;
842 ResolveConstants.pop_back();
847 while (!Placeholder->use_empty()) {
853 if (!isa<Constant>(U) || isa<GlobalValue>(U)) {
854 UI.getUse().set(RealVal);
860 Constant *UserC = cast<Constant>(U);
864 if (!isa<ConstantPlaceHolder>(*
I)) {
867 }
else if (*
I == Placeholder) {
872 ResolveConstantsTy::iterator It =
873 std::lower_bound(ResolveConstants.begin(), ResolveConstants.end(),
874 std::pair<Constant*, unsigned>(cast<Constant>(*I),
876 assert(It != ResolveConstants.end() && It->first == *
I);
877 NewOp = operator[](It->second);
880 NewOps.push_back(cast<Constant>(NewOp));
885 if (
ConstantArray *UserCA = dyn_cast<ConstantArray>(UserC)) {
886 NewC = ConstantArray::get(UserCA->getType(), NewOps);
887 }
else if (
ConstantStruct *UserCS = dyn_cast<ConstantStruct>(UserC)) {
888 NewC = ConstantStruct::get(UserCS->getType(), NewOps);
889 }
else if (isa<ConstantVector>(UserC)) {
890 NewC = ConstantVector::get(NewOps);
892 assert(isa<ConstantExpr>(UserC) &&
"Must be a ConstantExpr.");
893 NewC = cast<ConstantExpr>(UserC)->getWithOperands(NewOps);
902 Placeholder->replaceAllUsesWith(RealVal);
907 void BitcodeReaderMDValueList::assignValue(
Metadata *MD,
unsigned Idx) {
923 TempMDTuple PrevMD(cast<MDTuple>(OldMD.
get()));
924 PrevMD->replaceAllUsesWith(MD);
928 Metadata *BitcodeReaderMDValueList::getValueFwdRef(
unsigned Idx) {
932 if (
Metadata *MD = MDValuePtrs[Idx])
937 MinFwdRef =
std::min(MinFwdRef, Idx);
938 MaxFwdRef = std::max(MaxFwdRef, Idx);
941 MinFwdRef = MaxFwdRef = Idx;
946 Metadata *MD = MDNode::getTemporary(Context,
None).release();
947 MDValuePtrs[Idx].reset(MD);
951 void BitcodeReaderMDValueList::tryToResolveCycles() {
961 for (
unsigned I = MinFwdRef, E = MaxFwdRef + 1;
I != E; ++
I) {
962 auto &MD = MDValuePtrs[
I];
963 auto *N = dyn_cast_or_null<MDNode>(MD);
967 assert(!N->isTemporary() &&
"Unexpected forward reference");
975 Type *BitcodeReader::getTypeByID(
unsigned ID) {
977 if (ID >= TypeList.size())
980 if (
Type *Ty = TypeList[ID])
985 return TypeList[
ID] = createIdentifiedStructType(Context);
990 auto *
Ret = StructType::create(Context, Name);
991 IdentifiedStructTypes.push_back(
Ret);
996 auto *
Ret = StructType::create(Context);
997 IdentifiedStructTypes.push_back(
Ret);
1011 uint64_t EncodedAttrs) {
1016 unsigned Alignment = (EncodedAttrs & (0xffffULL << 16)) >> 16;
1018 "Alignment must be a power of two.");
1022 B.
addRawValue(((EncodedAttrs & (0xfffffULL << 32)) >> 11) |
1023 (EncodedAttrs & 0xffff));
1026 std::error_code BitcodeReader::parseAttributeBlock() {
1028 return error(
"Invalid record");
1030 if (!MAttributes.empty())
1031 return error(
"Invalid multiple blocks");
1041 switch (Entry.
Kind) {
1042 case BitstreamEntry::SubBlock:
1044 return error(
"Malformed block");
1045 case BitstreamEntry::EndBlock:
1046 return std::error_code();
1047 case BitstreamEntry::Record:
1054 switch (Stream.readRecord(Entry.
ID, Record)) {
1059 if (Record.
size() & 1)
1060 return error(
"Invalid record");
1062 for (
unsigned i = 0, e = Record.
size(); i != e; i += 2) {
1065 Attrs.
push_back(AttributeSet::get(Context, Record[i], B));
1068 MAttributes.push_back(AttributeSet::get(Context, Attrs));
1073 for (
unsigned i = 0, e = Record.
size(); i != e; ++i)
1074 Attrs.
push_back(MAttributeGroups[Record[i]]);
1076 MAttributes.push_back(AttributeSet::get(Context, Attrs));
1090 return Attribute::Alignment;
1092 return Attribute::AlwaysInline;
1094 return Attribute::ArgMemOnly;
1096 return Attribute::Builtin;
1098 return Attribute::ByVal;
1100 return Attribute::InAlloca;
1106 return Attribute::InlineHint;
1108 return Attribute::InReg;
1112 return Attribute::MinSize;
1114 return Attribute::Naked;
1116 return Attribute::Nest;
1120 return Attribute::NoBuiltin;
1122 return Attribute::NoCapture;
1124 return Attribute::NoDuplicate;
1126 return Attribute::NoImplicitFloat;
1128 return Attribute::NoInline;
1130 return Attribute::NonLazyBind;
1132 return Attribute::NonNull;
1134 return Attribute::Dereferenceable;
1136 return Attribute::DereferenceableOrNull;
1138 return Attribute::NoRedZone;
1140 return Attribute::NoReturn;
1142 return Attribute::NoUnwind;
1144 return Attribute::OptimizeForSize;
1146 return Attribute::OptimizeNone;
1148 return Attribute::ReadNone;
1150 return Attribute::ReadOnly;
1152 return Attribute::Returned;
1154 return Attribute::ReturnsTwice;
1156 return Attribute::SExt;
1158 return Attribute::StackAlignment;
1160 return Attribute::StackProtect;
1162 return Attribute::StackProtectReq;
1164 return Attribute::StackProtectStrong;
1166 return Attribute::SafeStack;
1168 return Attribute::StructRet;
1170 return Attribute::SanitizeAddress;
1172 return Attribute::SanitizeThread;
1174 return Attribute::SanitizeMemory;
1176 return Attribute::UWTable;
1178 return Attribute::ZExt;
1182 std::error_code BitcodeReader::parseAlignmentValue(uint64_t Exponent,
1183 unsigned &Alignment) {
1186 if (Exponent > Value::MaxAlignmentExponent + 1)
1187 return error(
"Invalid alignment value");
1188 Alignment = (1 <<
static_cast<unsigned>(Exponent)) >> 1;
1189 return std::error_code();
1192 std::error_code BitcodeReader::parseAttrKind(uint64_t
Code,
1196 return error(BitcodeError::CorruptedBitcode,
1197 "Unknown attribute kind (" +
Twine(Code) +
")");
1198 return std::error_code();
1201 std::error_code BitcodeReader::parseAttributeGroupBlock() {
1203 return error(
"Invalid record");
1205 if (!MAttributeGroups.empty())
1206 return error(
"Invalid multiple blocks");
1214 switch (Entry.
Kind) {
1215 case BitstreamEntry::SubBlock:
1217 return error(
"Malformed block");
1218 case BitstreamEntry::EndBlock:
1219 return std::error_code();
1220 case BitstreamEntry::Record:
1227 switch (Stream.readRecord(Entry.
ID, Record)) {
1231 if (Record.
size() < 3)
1232 return error(
"Invalid record");
1234 uint64_t GrpID = Record[0];
1235 uint64_t Idx = Record[1];
1238 for (
unsigned i = 2, e = Record.
size(); i != e; ++i) {
1239 if (Record[i] == 0) {
1241 if (std::error_code EC = parseAttrKind(Record[++i], &Kind))
1245 }
else if (Record[i] == 1) {
1247 if (std::error_code EC = parseAttrKind(Record[++i], &Kind))
1249 if (Kind == Attribute::Alignment)
1251 else if (Kind == Attribute::StackAlignment)
1253 else if (Kind == Attribute::Dereferenceable)
1255 else if (Kind == Attribute::DereferenceableOrNull)
1258 assert((Record[i] == 3 || Record[i] == 4) &&
1259 "Invalid attribute group entry");
1260 bool HasValue = (Record[i++] == 4);
1264 while (Record[i] != 0 && i != e)
1265 KindStr += Record[i++];
1266 assert(Record[i] == 0 &&
"Kind string not null terminated");
1271 while (Record[i] != 0 && i != e)
1272 ValStr += Record[i++];
1273 assert(Record[i] == 0 &&
"Value string not null terminated");
1280 MAttributeGroups[GrpID] = AttributeSet::get(Context, Idx, B);
1287 std::error_code BitcodeReader::parseTypeTable() {
1289 return error(
"Invalid record");
1291 return parseTypeTableBody();
1294 std::error_code BitcodeReader::parseTypeTableBody() {
1295 if (!TypeList.empty())
1296 return error(
"Invalid multiple blocks");
1299 unsigned NumRecords = 0;
1307 switch (Entry.
Kind) {
1308 case BitstreamEntry::SubBlock:
1310 return error(
"Malformed block");
1311 case BitstreamEntry::EndBlock:
1312 if (NumRecords != TypeList.size())
1313 return error(
"Malformed block");
1314 return std::error_code();
1315 case BitstreamEntry::Record:
1322 Type *ResultTy =
nullptr;
1323 switch (Stream.readRecord(Entry.
ID, Record)) {
1325 return error(
"Invalid value");
1329 if (Record.
size() < 1)
1330 return error(
"Invalid record");
1331 TypeList.resize(Record[0]);
1334 ResultTy = Type::getVoidTy(Context);
1337 ResultTy = Type::getHalfTy(Context);
1340 ResultTy = Type::getFloatTy(Context);
1343 ResultTy = Type::getDoubleTy(Context);
1346 ResultTy = Type::getX86_FP80Ty(Context);
1349 ResultTy = Type::getFP128Ty(Context);
1352 ResultTy = Type::getPPC_FP128Ty(Context);
1355 ResultTy = Type::getLabelTy(Context);
1358 ResultTy = Type::getMetadataTy(Context);
1361 ResultTy = Type::getX86_MMXTy(Context);
1364 if (Record.
size() < 1)
1365 return error(
"Invalid record");
1367 uint64_t NumBits = Record[0];
1368 if (NumBits < IntegerType::MIN_INT_BITS ||
1369 NumBits > IntegerType::MAX_INT_BITS)
1370 return error(
"Bitwidth for integer type out of range");
1371 ResultTy = IntegerType::get(Context, NumBits);
1376 if (Record.
size() < 1)
1377 return error(
"Invalid record");
1379 if (Record.
size() == 2)
1380 AddressSpace = Record[1];
1381 ResultTy = getTypeByID(Record[0]);
1383 !PointerType::isValidElementType(ResultTy))
1384 return error(
"Invalid type");
1385 ResultTy = PointerType::get(ResultTy, AddressSpace);
1391 if (Record.
size() < 3)
1392 return error(
"Invalid record");
1394 for (
unsigned i = 3, e = Record.
size(); i != e; ++i) {
1395 if (
Type *
T = getTypeByID(Record[i]))
1401 ResultTy = getTypeByID(Record[2]);
1402 if (!ResultTy || ArgTys.
size() < Record.
size()-3)
1403 return error(
"Invalid type");
1405 ResultTy = FunctionType::get(ResultTy, ArgTys, Record[0]);
1410 if (Record.
size() < 2)
1411 return error(
"Invalid record");
1413 for (
unsigned i = 2, e = Record.
size(); i != e; ++i) {
1414 if (
Type *
T = getTypeByID(Record[i])) {
1415 if (!FunctionType::isValidArgumentType(
T))
1416 return error(
"Invalid function argument type");
1423 ResultTy = getTypeByID(Record[1]);
1424 if (!ResultTy || ArgTys.
size() < Record.
size()-2)
1425 return error(
"Invalid type");
1427 ResultTy = FunctionType::get(ResultTy, ArgTys, Record[0]);
1431 if (Record.
size() < 1)
1432 return error(
"Invalid record");
1434 for (
unsigned i = 1, e = Record.
size(); i != e; ++i) {
1435 if (
Type *
T = getTypeByID(Record[i]))
1440 if (EltTys.
size() != Record.
size()-1)
1441 return error(
"Invalid type");
1442 ResultTy = StructType::get(Context, EltTys, Record[0]);
1447 return error(
"Invalid record");
1451 if (Record.
size() < 1)
1452 return error(
"Invalid record");
1454 if (NumRecords >= TypeList.size())
1455 return error(
"Invalid TYPE table");
1458 StructType *Res = cast_or_null<StructType>(TypeList[NumRecords]);
1461 TypeList[NumRecords] =
nullptr;
1463 Res = createIdentifiedStructType(Context, TypeName);
1467 for (
unsigned i = 1, e = Record.
size(); i != e; ++i) {
1468 if (
Type *
T = getTypeByID(Record[i]))
1473 if (EltTys.
size() != Record.
size()-1)
1474 return error(
"Invalid record");
1475 Res->
setBody(EltTys, Record[0]);
1480 if (Record.
size() != 1)
1481 return error(
"Invalid record");
1483 if (NumRecords >= TypeList.size())
1484 return error(
"Invalid TYPE table");
1487 StructType *Res = cast_or_null<StructType>(TypeList[NumRecords]);
1490 TypeList[NumRecords] =
nullptr;
1492 Res = createIdentifiedStructType(Context, TypeName);
1498 if (Record.
size() < 2)
1499 return error(
"Invalid record");
1500 ResultTy = getTypeByID(Record[1]);
1501 if (!ResultTy || !ArrayType::isValidElementType(ResultTy))
1502 return error(
"Invalid type");
1503 ResultTy = ArrayType::get(ResultTy, Record[0]);
1506 if (Record.
size() < 2)
1507 return error(
"Invalid record");
1509 return error(
"Invalid vector length");
1510 ResultTy = getTypeByID(Record[1]);
1511 if (!ResultTy || !StructType::isValidElementType(ResultTy))
1512 return error(
"Invalid type");
1513 ResultTy = VectorType::get(ResultTy, Record[0]);
1517 if (NumRecords >= TypeList.size())
1518 return error(
"Invalid TYPE table");
1519 if (TypeList[NumRecords])
1521 "Invalid TYPE table: Only named structs can be forward referenced");
1522 assert(ResultTy &&
"Didn't read a type?");
1523 TypeList[NumRecords++] = ResultTy;
1527 std::error_code BitcodeReader::parseValueSymbolTable() {
1529 return error(
"Invalid record");
1533 Triple TT(TheModule->getTargetTriple());
1540 switch (Entry.
Kind) {
1541 case BitstreamEntry::SubBlock:
1543 return error(
"Malformed block");
1544 case BitstreamEntry::EndBlock:
1545 return std::error_code();
1546 case BitstreamEntry::Record:
1553 switch (Stream.readRecord(Entry.
ID, Record)) {
1558 return error(
"Invalid record");
1559 unsigned ValueID = Record[0];
1560 if (ValueID >= ValueList.size() || !ValueList[ValueID])
1561 return error(
"Invalid record");
1562 Value *V = ValueList[ValueID];
1565 if (
auto *GO = dyn_cast<GlobalObject>(V)) {
1566 if (GO->getComdat() ==
reinterpret_cast<Comdat *
>(1)) {
1567 if (TT.isOSBinFormatMachO())
1568 GO->setComdat(
nullptr);
1570 GO->setComdat(TheModule->getOrInsertComdat(V->
getName()));
1578 return error(
"Invalid record");
1581 return error(
"Invalid record");
1591 static int64_t
unrotateSign(uint64_t U) {
return U & 1 ? ~(U >> 1) : U >> 1; }
1593 std::error_code BitcodeReader::parseMetadata() {
1594 IsMetadataMaterialized =
true;
1595 unsigned NextMDValueNo = MDValueList.size();
1598 return error(
"Invalid record");
1603 [&](
unsigned ID) ->
Metadata *{
return MDValueList.getValueFwdRef(ID); };
1604 auto getMDOrNull = [&](
unsigned ID) ->
Metadata *{
1606 return getMD(ID - 1);
1609 auto getMDString = [&](
unsigned ID) ->
MDString *{
1612 return cast_or_null<MDString>(getMDOrNull(ID));
1615 #define GET_OR_DISTINCT(CLASS, DISTINCT, ARGS) \
1616 (DISTINCT ? CLASS::getDistinct ARGS : CLASS::get ARGS)
1622 switch (Entry.
Kind) {
1623 case BitstreamEntry::SubBlock:
1625 return error(
"Malformed block");
1626 case BitstreamEntry::EndBlock:
1627 MDValueList.tryToResolveCycles();
1628 return std::error_code();
1629 case BitstreamEntry::Record:
1636 unsigned Code = Stream.readRecord(Entry.
ID, Record);
1637 bool IsDistinct =
false;
1645 Code = Stream.ReadCode();
1647 unsigned NextBitCode = Stream.readRecord(Code, Record);
1649 return error(
"METADATA_NAME not followed by METADATA_NAMED_NODE");
1652 unsigned Size = Record.
size();
1653 NamedMDNode *NMD = TheModule->getOrInsertNamedMetadata(Name);
1654 for (
unsigned i = 0; i != Size; ++i) {
1655 MDNode *MD = dyn_cast_or_null<MDNode>(MDValueList.getValueFwdRef(Record[i]));
1657 return error(
"Invalid record");
1666 if (Record.
size() % 2 == 1)
1667 return error(
"Invalid record");
1671 auto dropRecord = [&] {
1672 MDValueList.assignValue(MDNode::get(Context,
None), NextMDValueNo++);
1674 if (Record.
size() != 2) {
1679 Type *Ty = getTypeByID(Record[0]);
1685 MDValueList.assignValue(
1686 LocalAsMetadata::get(ValueList.getValueFwdRef(Record[1], Ty)),
1692 if (Record.
size() % 2 == 1)
1693 return error(
"Invalid record");
1695 unsigned Size = Record.
size();
1697 for (
unsigned i = 0; i != Size; i += 2) {
1698 Type *Ty = getTypeByID(Record[i]);
1700 return error(
"Invalid record");
1702 Elts.
push_back(MDValueList.getValueFwdRef(Record[i+1]));
1705 ValueAsMetadata::get(ValueList.getValueFwdRef(Record[i + 1], Ty));
1706 assert(isa<ConstantAsMetadata>(MD) &&
1707 "Expected non-function-local metadata");
1712 MDValueList.assignValue(MDNode::get(Context, Elts), NextMDValueNo++);
1716 if (Record.
size() != 2)
1717 return error(
"Invalid record");
1719 Type *Ty = getTypeByID(Record[0]);
1721 return error(
"Invalid record");
1723 MDValueList.assignValue(
1724 ValueAsMetadata::get(ValueList.getValueFwdRef(Record[1], Ty)),
1734 for (
unsigned ID : Record)
1735 Elts.
push_back(ID ? MDValueList.getValueFwdRef(ID - 1) :
nullptr);
1736 MDValueList.assignValue(IsDistinct ? MDNode::getDistinct(Context, Elts)
1737 : MDNode::get(Context, Elts),
1742 if (Record.size() != 5)
1743 return error(
"Invalid record");
1745 unsigned Line = Record[1];
1746 unsigned Column = Record[2];
1747 MDNode *Scope = cast<MDNode>(MDValueList.getValueFwdRef(Record[3]));
1749 Record[4] ? MDValueList.getValueFwdRef(Record[4] - 1) :
nullptr;
1750 MDValueList.assignValue(
1752 (Context, Line, Column, Scope, InlinedAt)),
1757 if (Record.size() < 4)
1758 return error(
"Invalid record");
1760 unsigned Tag = Record[1];
1763 if (Tag >= 1u << 16 || Version != 0)
1764 return error(
"Invalid record");
1766 auto *Header = getMDString(Record[3]);
1768 for (
unsigned I = 4, E = Record.size();
I != E; ++
I)
1769 DwarfOps.
push_back(Record[
I] ? MDValueList.getValueFwdRef(Record[
I] - 1)
1772 (Context, Tag, Header, DwarfOps)),
1777 if (Record.size() != 3)
1778 return error(
"Invalid record");
1780 MDValueList.assignValue(
1787 if (Record.size() != 3)
1788 return error(
"Invalid record");
1792 getMDString(Record[2]))),
1797 if (Record.size() != 6)
1798 return error(
"Invalid record");
1800 MDValueList.assignValue(
1802 (Context, Record[1], getMDString(Record[2]),
1803 Record[3], Record[4], Record[5])),
1808 if (Record.size() != 12)
1809 return error(
"Invalid record");
1811 MDValueList.assignValue(
1813 (Context, Record[1], getMDString(Record[2]),
1814 getMDOrNull(Record[3]), Record[4],
1815 getMDOrNull(Record[5]), getMDOrNull(Record[6]),
1816 Record[7], Record[8], Record[9], Record[10],
1817 getMDOrNull(Record[11]))),
1822 if (Record.size() != 16)
1823 return error(
"Invalid record");
1825 MDValueList.assignValue(
1827 (Context, Record[1], getMDString(Record[2]),
1828 getMDOrNull(Record[3]), Record[4],
1829 getMDOrNull(Record[5]), getMDOrNull(Record[6]),
1830 Record[7], Record[8], Record[9], Record[10],
1831 getMDOrNull(Record[11]), Record[12],
1832 getMDOrNull(Record[13]), getMDOrNull(Record[14]),
1833 getMDString(Record[15]))),
1838 if (Record.size() != 3)
1839 return error(
"Invalid record");
1841 MDValueList.assignValue(
1843 (Context, Record[1], getMDOrNull(Record[2]))),
1849 if (Record.size() != 6)
1850 return error(
"Invalid record");
1852 MDValueList.assignValue(
1854 (Context, getMDOrNull(Record[1]),
1855 getMDString(Record[2]), getMDString(Record[3]),
1856 getMDString(Record[4]), getMDString(Record[5]))),
1862 if (Record.size() != 3)
1863 return error(
"Invalid record");
1865 MDValueList.assignValue(
1867 getMDString(Record[2]))),
1872 if (Record.size() < 14 || Record.size() > 15)
1873 return error(
"Invalid record");
1875 MDValueList.assignValue(
1878 (Context, Record[1], getMDOrNull(Record[2]),
1879 getMDString(Record[3]), Record[4], getMDString(Record[5]),
1880 Record[6], getMDString(Record[7]), Record[8],
1881 getMDOrNull(Record[9]), getMDOrNull(Record[10]),
1882 getMDOrNull(Record[11]), getMDOrNull(Record[12]),
1883 getMDOrNull(Record[13]), Record.size() == 14 ? 0 : Record[14])),
1888 if (Record.size() != 19)
1889 return error(
"Invalid record");
1891 MDValueList.assignValue(
1894 (Context, getMDOrNull(Record[1]), getMDString(Record[2]),
1895 getMDString(Record[3]), getMDOrNull(Record[4]), Record[5],
1896 getMDOrNull(Record[6]), Record[7], Record[8], Record[9],
1897 getMDOrNull(Record[10]), Record[11], Record[12], Record[13],
1898 Record[14], getMDOrNull(Record[15]), getMDOrNull(Record[16]),
1899 getMDOrNull(Record[17]), getMDOrNull(Record[18]))),
1904 if (Record.size() != 5)
1905 return error(
"Invalid record");
1907 MDValueList.assignValue(
1909 (Context, getMDOrNull(Record[1]),
1910 getMDOrNull(Record[2]), Record[3], Record[4])),
1915 if (Record.size() != 4)
1916 return error(
"Invalid record");
1918 MDValueList.assignValue(
1920 (Context, getMDOrNull(Record[1]),
1921 getMDOrNull(Record[2]), Record[3])),
1926 if (Record.size() != 5)
1927 return error(
"Invalid record");
1929 MDValueList.assignValue(
1931 (Context, getMDOrNull(Record[1]),
1932 getMDOrNull(Record[2]), getMDString(Record[3]),
1938 if (Record.size() != 3)
1939 return error(
"Invalid record");
1943 (Context, getMDString(Record[1]),
1944 getMDOrNull(Record[2]))),
1949 if (Record.size() != 5)
1950 return error(
"Invalid record");
1952 MDValueList.assignValue(
1954 (Context, Record[1], getMDString(Record[2]),
1955 getMDOrNull(Record[3]), getMDOrNull(Record[4]))),
1960 if (Record.size() != 11)
1961 return error(
"Invalid record");
1963 MDValueList.assignValue(
1965 (Context, getMDOrNull(Record[1]),
1966 getMDString(Record[2]), getMDString(Record[3]),
1967 getMDOrNull(Record[4]), Record[5],
1968 getMDOrNull(Record[6]), Record[7], Record[8],
1969 getMDOrNull(Record[9]), getMDOrNull(Record[10]))),
1975 if (Record.size() != 9 && Record.size() != 10)
1976 return error(
"Invalid record");
1978 MDValueList.assignValue(
1980 (Context, Record[1], getMDOrNull(Record[2]),
1981 getMDString(Record[3]), getMDOrNull(Record[4]),
1982 Record[5], getMDOrNull(Record[6]), Record[7],
1988 if (Record.size() < 1)
1989 return error(
"Invalid record");
1991 MDValueList.assignValue(
1998 if (Record.size() != 8)
1999 return error(
"Invalid record");
2001 MDValueList.assignValue(
2003 (Context, getMDString(Record[1]),
2004 getMDOrNull(Record[2]), Record[3],
2005 getMDString(Record[4]), getMDString(Record[5]),
2006 Record[6], getMDOrNull(Record[7]))),
2011 if (Record.size() != 6)
2012 return error(
"Invalid record");
2014 MDValueList.assignValue(
2016 (Context, Record[1], getMDOrNull(Record[2]),
2017 getMDOrNull(Record[3]), Record[4],
2018 getMDString(Record[5]))),
2023 std::string
String(Record.begin(), Record.end());
2026 MDValueList.assignValue(MD, NextMDValueNo++);
2030 if (Record.size() < 2)
2031 return error(
"Invalid record");
2033 unsigned Kind = Record[0];
2036 unsigned NewKind = TheModule->getMDKindID(Name.
str());
2037 if (!MDKindMap.insert(std::make_pair(Kind, NewKind)).second)
2038 return error(
"Conflicting METADATA_KIND records");
2043 #undef GET_OR_DISTINCT
2048 uint64_t BitcodeReader::decodeSignRotatedValue(uint64_t V) {
2058 std::error_code BitcodeReader::resolveGlobalAndAliasInits() {
2059 std::vector<std::pair<GlobalVariable*, unsigned> > GlobalInitWorklist;
2060 std::vector<std::pair<GlobalAlias*, unsigned> > AliasInitWorklist;
2061 std::vector<std::pair<Function*, unsigned> > FunctionPrefixWorklist;
2062 std::vector<std::pair<Function*, unsigned> > FunctionPrologueWorklist;
2063 std::vector<std::pair<Function*, unsigned> > FunctionPersonalityFnWorklist;
2065 GlobalInitWorklist.swap(GlobalInits);
2066 AliasInitWorklist.swap(AliasInits);
2067 FunctionPrefixWorklist.swap(FunctionPrefixes);
2068 FunctionPrologueWorklist.swap(FunctionPrologues);
2069 FunctionPersonalityFnWorklist.swap(FunctionPersonalityFns);
2071 while (!GlobalInitWorklist.empty()) {
2072 unsigned ValID = GlobalInitWorklist.back().second;
2073 if (ValID >= ValueList.size()) {
2075 GlobalInits.push_back(GlobalInitWorklist.back());
2077 if (
Constant *
C = dyn_cast_or_null<Constant>(ValueList[ValID]))
2078 GlobalInitWorklist.back().first->setInitializer(
C);
2080 return error(
"Expected a constant");
2082 GlobalInitWorklist.pop_back();
2085 while (!AliasInitWorklist.empty()) {
2086 unsigned ValID = AliasInitWorklist.back().second;
2087 if (ValID >= ValueList.size()) {
2088 AliasInits.push_back(AliasInitWorklist.back());
2090 Constant *
C = dyn_cast_or_null<Constant>(ValueList[ValID]);
2092 return error(
"Expected a constant");
2093 GlobalAlias *Alias = AliasInitWorklist.back().first;
2095 return error(
"Alias and aliasee types don't match");
2098 AliasInitWorklist.pop_back();
2101 while (!FunctionPrefixWorklist.empty()) {
2102 unsigned ValID = FunctionPrefixWorklist.back().second;
2103 if (ValID >= ValueList.size()) {
2104 FunctionPrefixes.push_back(FunctionPrefixWorklist.back());
2106 if (
Constant *C = dyn_cast_or_null<Constant>(ValueList[ValID]))
2107 FunctionPrefixWorklist.back().first->setPrefixData(C);
2109 return error(
"Expected a constant");
2111 FunctionPrefixWorklist.pop_back();
2114 while (!FunctionPrologueWorklist.empty()) {
2115 unsigned ValID = FunctionPrologueWorklist.back().second;
2116 if (ValID >= ValueList.size()) {
2117 FunctionPrologues.push_back(FunctionPrologueWorklist.back());
2119 if (
Constant *C = dyn_cast_or_null<Constant>(ValueList[ValID]))
2120 FunctionPrologueWorklist.back().first->setPrologueData(C);
2122 return error(
"Expected a constant");
2124 FunctionPrologueWorklist.pop_back();
2127 while (!FunctionPersonalityFnWorklist.empty()) {
2128 unsigned ValID = FunctionPersonalityFnWorklist.back().second;
2129 if (ValID >= ValueList.size()) {
2130 FunctionPersonalityFns.push_back(FunctionPersonalityFnWorklist.back());
2132 if (
Constant *C = dyn_cast_or_null<Constant>(ValueList[ValID]))
2133 FunctionPersonalityFnWorklist.back().first->setPersonalityFn(C);
2135 return error(
"Expected a constant");
2137 FunctionPersonalityFnWorklist.pop_back();
2140 return std::error_code();
2145 std::transform(Vals.
begin(), Vals.
end(), Words.begin(),
2146 BitcodeReader::decodeSignRotatedValue);
2148 return APInt(TypeBits, Words);
2151 std::error_code BitcodeReader::parseConstants() {
2153 return error(
"Invalid record");
2158 Type *CurTy = Type::getInt32Ty(Context);
2159 unsigned NextCstNo = ValueList.size();
2163 switch (Entry.
Kind) {
2164 case BitstreamEntry::SubBlock:
2166 return error(
"Malformed block");
2167 case BitstreamEntry::EndBlock:
2168 if (NextCstNo != ValueList.size())
2169 return error(
"Invalid ronstant reference");
2173 ValueList.resolveConstantForwardRefs();
2174 return std::error_code();
2175 case BitstreamEntry::Record:
2183 unsigned BitCode = Stream.readRecord(Entry.
ID, Record);
2187 V = UndefValue::get(CurTy);
2191 return error(
"Invalid record");
2192 if (Record[0] >= TypeList.
size() || !TypeList[Record[0]])
2193 return error(
"Invalid record");
2194 CurTy = TypeList[Record[0]];
2197 V = Constant::getNullValue(CurTy);
2201 return error(
"Invalid record");
2202 V = ConstantInt::get(CurTy, decodeSignRotatedValue(Record[0]));
2206 return error(
"Invalid record");
2210 V = ConstantInt::get(Context, VInt);
2216 return error(
"Invalid record");
2218 V = ConstantFP::get(Context,
APFloat(APFloat::IEEEhalf,
2219 APInt(16, (uint16_t)Record[0])));
2221 V = ConstantFP::get(Context,
APFloat(APFloat::IEEEsingle,
2222 APInt(32, (uint32_t)Record[0])));
2224 V = ConstantFP::get(Context,
APFloat(APFloat::IEEEdouble,
2225 APInt(64, Record[0])));
2228 uint64_t Rearrange[2];
2229 Rearrange[0] = (Record[1] & 0xffffLL) | (Record[0] << 16);
2230 Rearrange[1] = Record[0] >> 48;
2231 V = ConstantFP::get(Context,
APFloat(APFloat::x87DoubleExtended,
2232 APInt(80, Rearrange)));
2234 V = ConstantFP::get(Context,
APFloat(APFloat::IEEEquad,
2235 APInt(128, Record)));
2237 V = ConstantFP::get(Context,
APFloat(APFloat::PPCDoubleDouble,
2238 APInt(128, Record)));
2240 V = UndefValue::get(CurTy);
2246 return error(
"Invalid record");
2248 unsigned Size = Record.size();
2251 if (
StructType *STy = dyn_cast<StructType>(CurTy)) {
2252 for (
unsigned i = 0; i != Size; ++i)
2253 Elts.
push_back(ValueList.getConstantFwdRef(Record[i],
2254 STy->getElementType(i)));
2255 V = ConstantStruct::get(STy, Elts);
2256 }
else if (
ArrayType *ATy = dyn_cast<ArrayType>(CurTy)) {
2257 Type *EltTy = ATy->getElementType();
2258 for (
unsigned i = 0; i != Size; ++i)
2259 Elts.
push_back(ValueList.getConstantFwdRef(Record[i], EltTy));
2260 V = ConstantArray::get(ATy, Elts);
2261 }
else if (
VectorType *VTy = dyn_cast<VectorType>(CurTy)) {
2262 Type *EltTy = VTy->getElementType();
2263 for (
unsigned i = 0; i != Size; ++i)
2264 Elts.
push_back(ValueList.getConstantFwdRef(Record[i], EltTy));
2265 V = ConstantVector::get(Elts);
2267 V = UndefValue::get(CurTy);
2274 return error(
"Invalid record");
2283 return error(
"Invalid record");
2285 Type *EltTy = cast<SequentialType>(CurTy)->getElementType();
2286 unsigned Size = Record.size();
2290 if (isa<VectorType>(CurTy))
2291 V = ConstantDataVector::get(Context, Elts);
2293 V = ConstantDataArray::get(Context, Elts);
2296 if (isa<VectorType>(CurTy))
2297 V = ConstantDataVector::get(Context, Elts);
2299 V = ConstantDataArray::get(Context, Elts);
2302 if (isa<VectorType>(CurTy))
2303 V = ConstantDataVector::get(Context, Elts);
2305 V = ConstantDataArray::get(Context, Elts);
2308 if (isa<VectorType>(CurTy))
2309 V = ConstantDataVector::get(Context, Elts);
2311 V = ConstantDataArray::get(Context, Elts);
2315 if (isa<VectorType>(CurTy))
2316 V = ConstantDataVector::get(Context, Elts);
2318 V = ConstantDataArray::get(Context, Elts);
2321 std::transform(Record.begin(), Record.end(), Elts.
begin(),
2323 if (isa<VectorType>(CurTy))
2324 V = ConstantDataVector::get(Context, Elts);
2326 V = ConstantDataArray::get(Context, Elts);
2328 return error(
"Invalid type for value");
2334 if (Record.size() < 3)
2335 return error(
"Invalid record");
2338 V = UndefValue::get(CurTy);
2340 Constant *LHS = ValueList.getConstantFwdRef(Record[1], CurTy);
2341 Constant *RHS = ValueList.getConstantFwdRef(Record[2], CurTy);
2343 if (Record.size() >= 4) {
2344 if (Opc == Instruction::Add ||
2345 Opc == Instruction::Sub ||
2346 Opc == Instruction::Mul ||
2347 Opc == Instruction::Shl) {
2349 Flags |= OverflowingBinaryOperator::NoSignedWrap;
2351 Flags |= OverflowingBinaryOperator::NoUnsignedWrap;
2352 }
else if (Opc == Instruction::SDiv ||
2353 Opc == Instruction::UDiv ||
2354 Opc == Instruction::LShr ||
2355 Opc == Instruction::AShr) {
2357 Flags |= SDivOperator::IsExact;
2360 V = ConstantExpr::get(Opc, LHS, RHS, Flags);
2365 if (Record.size() < 3)
2366 return error(
"Invalid record");
2369 V = UndefValue::get(CurTy);
2371 Type *OpTy = getTypeByID(Record[1]);
2373 return error(
"Invalid record");
2374 Constant *Op = ValueList.getConstantFwdRef(Record[2], OpTy);
2376 if (!V) V = ConstantExpr::getCast(Opc, Op, CurTy);
2383 Type *PointeeType =
nullptr;
2384 if (Record.size() % 2)
2385 PointeeType = getTypeByID(Record[OpNum++]);
2387 while (OpNum != Record.size()) {
2388 Type *ElTy = getTypeByID(Record[OpNum++]);
2390 return error(
"Invalid record");
2391 Elts.
push_back(ValueList.getConstantFwdRef(Record[OpNum++], ElTy));
2396 cast<SequentialType>(Elts[0]->
getType()->getScalarType())
2398 return error(
"Explicit gep operator type does not match pointee type "
2399 "of pointer operand");
2402 V = ConstantExpr::getGetElementPtr(PointeeType, Elts[0], Indices,
2408 if (Record.size() < 3)
2409 return error(
"Invalid record");
2411 Type *SelectorTy = Type::getInt1Ty(Context);
2415 if (
VectorType *VTy = dyn_cast<VectorType>(CurTy))
2416 SelectorTy = VectorType::get(Type::getInt1Ty(Context),
2417 VTy->getNumElements());
2419 V = ConstantExpr::getSelect(ValueList.getConstantFwdRef(Record[0],
2421 ValueList.getConstantFwdRef(Record[1],CurTy),
2422 ValueList.getConstantFwdRef(Record[2],CurTy));
2427 if (Record.size() < 3)
2428 return error(
"Invalid record");
2430 dyn_cast_or_null<VectorType>(getTypeByID(Record[0]));
2432 return error(
"Invalid record");
2433 Constant *Op0 = ValueList.getConstantFwdRef(Record[1], OpTy);
2435 if (Record.size() == 4) {
2436 Type *IdxTy = getTypeByID(Record[2]);
2438 return error(
"Invalid record");
2439 Op1 = ValueList.getConstantFwdRef(Record[3], IdxTy);
2441 Op1 = ValueList.getConstantFwdRef(Record[2], Type::getInt32Ty(Context));
2443 return error(
"Invalid record");
2444 V = ConstantExpr::getExtractElement(Op0, Op1);
2450 if (Record.size() < 3 || !OpTy)
2451 return error(
"Invalid record");
2452 Constant *Op0 = ValueList.getConstantFwdRef(Record[0], OpTy);
2453 Constant *Op1 = ValueList.getConstantFwdRef(Record[1],
2456 if (Record.size() == 4) {
2457 Type *IdxTy = getTypeByID(Record[2]);
2459 return error(
"Invalid record");
2460 Op2 = ValueList.getConstantFwdRef(Record[3], IdxTy);
2462 Op2 = ValueList.getConstantFwdRef(Record[2], Type::getInt32Ty(Context));
2464 return error(
"Invalid record");
2465 V = ConstantExpr::getInsertElement(Op0, Op1, Op2);
2470 if (Record.size() < 3 || !OpTy)
2471 return error(
"Invalid record");
2472 Constant *Op0 = ValueList.getConstantFwdRef(Record[0], OpTy);
2473 Constant *Op1 = ValueList.getConstantFwdRef(Record[1], OpTy);
2474 Type *ShufTy = VectorType::get(Type::getInt32Ty(Context),
2476 Constant *Op2 = ValueList.getConstantFwdRef(Record[2], ShufTy);
2477 V = ConstantExpr::getShuffleVector(Op0, Op1, Op2);
2483 dyn_cast_or_null<VectorType>(getTypeByID(Record[0]));
2484 if (Record.size() < 4 || !RTy || !OpTy)
2485 return error(
"Invalid record");
2486 Constant *Op0 = ValueList.getConstantFwdRef(Record[1], OpTy);
2487 Constant *Op1 = ValueList.getConstantFwdRef(Record[2], OpTy);
2488 Type *ShufTy = VectorType::get(Type::getInt32Ty(Context),
2490 Constant *Op2 = ValueList.getConstantFwdRef(Record[3], ShufTy);
2491 V = ConstantExpr::getShuffleVector(Op0, Op1, Op2);
2495 if (Record.size() < 4)
2496 return error(
"Invalid record");
2497 Type *OpTy = getTypeByID(Record[0]);
2499 return error(
"Invalid record");
2500 Constant *Op0 = ValueList.getConstantFwdRef(Record[1], OpTy);
2501 Constant *Op1 = ValueList.getConstantFwdRef(Record[2], OpTy);
2504 V = ConstantExpr::getFCmp(Record[3], Op0, Op1);
2506 V = ConstantExpr::getICmp(Record[3], Op0, Op1);
2512 if (Record.size() < 2)
2513 return error(
"Invalid record");
2514 std::string AsmStr, ConstrStr;
2515 bool HasSideEffects = Record[0] & 1;
2516 bool IsAlignStack = Record[0] >> 1;
2517 unsigned AsmStrSize = Record[1];
2518 if (2+AsmStrSize >= Record.size())
2519 return error(
"Invalid record");
2520 unsigned ConstStrSize = Record[2+AsmStrSize];
2521 if (3+AsmStrSize+ConstStrSize > Record.size())
2522 return error(
"Invalid record");
2524 for (
unsigned i = 0; i != AsmStrSize; ++i)
2525 AsmStr += (
char)Record[2+i];
2526 for (
unsigned i = 0; i != ConstStrSize; ++i)
2527 ConstrStr += (
char)Record[3+AsmStrSize+i];
2530 AsmStr, ConstrStr, HasSideEffects, IsAlignStack);
2536 if (Record.size() < 2)
2537 return error(
"Invalid record");
2538 std::string AsmStr, ConstrStr;
2539 bool HasSideEffects = Record[0] & 1;
2540 bool IsAlignStack = (Record[0] >> 1) & 1;
2541 unsigned AsmDialect = Record[0] >> 2;
2542 unsigned AsmStrSize = Record[1];
2543 if (2+AsmStrSize >= Record.size())
2544 return error(
"Invalid record");
2545 unsigned ConstStrSize = Record[2+AsmStrSize];
2546 if (3+AsmStrSize+ConstStrSize > Record.size())
2547 return error(
"Invalid record");
2549 for (
unsigned i = 0; i != AsmStrSize; ++i)
2550 AsmStr += (
char)Record[2+i];
2551 for (
unsigned i = 0; i != ConstStrSize; ++i)
2552 ConstrStr += (
char)Record[3+AsmStrSize+i];
2555 AsmStr, ConstrStr, HasSideEffects, IsAlignStack,
2560 if (Record.size() < 3)
2561 return error(
"Invalid record");
2562 Type *FnTy = getTypeByID(Record[0]);
2564 return error(
"Invalid record");
2566 dyn_cast_or_null<Function>(ValueList.getConstantFwdRef(Record[1],FnTy));
2568 return error(
"Invalid record");
2571 BlockAddressesTaken.insert(Fn);
2576 unsigned BBID = Record[2];
2579 return error(
"Invalid ID");
2582 for (
size_t I = 0, E = BBID;
I != E; ++
I) {
2584 return error(
"Invalid ID");
2591 auto &FwdBBs = BasicBlockFwdRefs[Fn];
2593 BasicBlockFwdRefQueue.push_back(Fn);
2594 if (FwdBBs.size() < BBID + 1)
2595 FwdBBs.resize(BBID + 1);
2597 FwdBBs[BBID] = BasicBlock::Create(Context);
2600 V = BlockAddress::get(Fn, BB);
2605 ValueList.assignValue(V, NextCstNo);
2610 std::error_code BitcodeReader::parseUseLists() {
2612 return error(
"Invalid record");
2619 switch (Entry.
Kind) {
2620 case BitstreamEntry::SubBlock:
2622 return error(
"Malformed block");
2623 case BitstreamEntry::EndBlock:
2624 return std::error_code();
2625 case BitstreamEntry::Record:
2633 switch (Stream.readRecord(Entry.
ID, Record)) {
2640 unsigned RecordLength = Record.
size();
2641 if (RecordLength < 3)
2643 return error(
"Invalid record");
2644 unsigned ID = Record.
back();
2649 assert(ID < FunctionBBs.size() &&
"Basic block not found");
2650 V = FunctionBBs[
ID];
2653 unsigned NumUses = 0;
2655 for (
const Use &U : V->
uses()) {
2656 if (++NumUses > Record.
size())
2658 Order[&U] = Record[NumUses - 1];
2660 if (Order.
size() != Record.
size() || NumUses > Record.
size())
2676 std::error_code BitcodeReader::rememberAndSkipMetadata() {
2678 uint64_t CurBit = Stream.GetCurrentBitNo();
2679 DeferredMetadataInfo.push_back(CurBit);
2682 if (Stream.SkipBlock())
2683 return error(
"Invalid record");
2684 return std::error_code();
2687 std::error_code BitcodeReader::materializeMetadata() {
2688 for (uint64_t BitPos : DeferredMetadataInfo) {
2690 Stream.JumpToBit(BitPos);
2691 if (std::error_code EC = parseMetadata())
2694 DeferredMetadataInfo.clear();
2695 return std::error_code();
2698 void BitcodeReader::setStripDebugInfo() {
StripDebugInfo =
true; }
2702 std::error_code BitcodeReader::rememberAndSkipFunctionBody() {
2704 if (FunctionsWithBodies.empty())
2705 return error(
"Insufficient function protos");
2708 FunctionsWithBodies.pop_back();
2711 uint64_t CurBit = Stream.GetCurrentBitNo();
2712 DeferredFunctionInfo[Fn] = CurBit;
2715 if (Stream.SkipBlock())
2716 return error(
"Invalid record");
2717 return std::error_code();
2720 std::error_code BitcodeReader::globalCleanup() {
2722 resolveGlobalAndAliasInits();
2723 if (!GlobalInits.empty() || !AliasInits.empty())
2724 return error(
"Malformed global initializer set");
2730 UpgradedIntrinsics[&F] = NewFn;
2739 std::vector<std::pair<GlobalVariable*, unsigned> >().
swap(GlobalInits);
2740 std::vector<std::pair<GlobalAlias*, unsigned> >().
swap(AliasInits);
2741 return std::error_code();
2744 std::error_code BitcodeReader::parseModule(
bool Resume,
2745 bool ShouldLazyLoadMetadata) {
2747 Stream.JumpToBit(NextUnreadBit);
2749 return error(
"Invalid record");
2752 std::vector<std::string> SectionTable;
2753 std::vector<std::string> GCTable;
2759 switch (Entry.
Kind) {
2761 return error(
"Malformed block");
2762 case BitstreamEntry::EndBlock:
2763 return globalCleanup();
2765 case BitstreamEntry::SubBlock:
2768 if (Stream.SkipBlock())
2769 return error(
"Invalid record");
2772 if (Stream.ReadBlockInfoBlock())
2773 return error(
"Malformed block");
2776 if (std::error_code EC = parseAttributeBlock())
2780 if (std::error_code EC = parseAttributeGroupBlock())
2784 if (std::error_code EC = parseTypeTable())
2788 if (std::error_code EC = parseValueSymbolTable())
2790 SeenValueSymbolTable =
true;
2793 if (std::error_code EC = parseConstants())
2795 if (std::error_code EC = resolveGlobalAndAliasInits())
2799 if (ShouldLazyLoadMetadata && !IsMetadataMaterialized) {
2800 if (std::error_code EC = rememberAndSkipMetadata())
2804 assert(DeferredMetadataInfo.empty() &&
"Unexpected deferred metadata");
2805 if (std::error_code EC = parseMetadata())
2811 if (!SeenFirstFunctionBody) {
2812 std::reverse(FunctionsWithBodies.begin(), FunctionsWithBodies.end());
2813 if (std::error_code EC = globalCleanup())
2815 SeenFirstFunctionBody =
true;
2818 if (std::error_code EC = rememberAndSkipFunctionBody())
2824 if (SeenValueSymbolTable) {
2825 NextUnreadBit = Stream.GetCurrentBitNo();
2826 return std::error_code();
2830 if (std::error_code EC = parseUseLists())
2836 case BitstreamEntry::Record:
2843 switch (Stream.readRecord(Entry.
ID, Record)) {
2846 if (Record.
size() < 1)
2847 return error(
"Invalid record");
2849 unsigned module_version = Record[0];
2850 switch (module_version) {
2852 return error(
"Invalid value");
2854 UseRelativeIDs =
false;
2857 UseRelativeIDs =
true;
2865 return error(
"Invalid record");
2866 TheModule->setTargetTriple(S);
2872 return error(
"Invalid record");
2873 TheModule->setDataLayout(S);
2879 return error(
"Invalid record");
2880 TheModule->setModuleInlineAsm(S);
2887 return error(
"Invalid record");
2894 return error(
"Invalid record");
2895 SectionTable.push_back(S);
2901 return error(
"Invalid record");
2902 GCTable.push_back(S);
2906 if (Record.
size() < 2)
2907 return error(
"Invalid record");
2909 unsigned ComdatNameSize = Record[1];
2910 std::string ComdatName;
2911 ComdatName.
reserve(ComdatNameSize);
2912 for (
unsigned i = 0; i != ComdatNameSize; ++i)
2913 ComdatName += (
char)Record[2 + i];
2914 Comdat *C = TheModule->getOrInsertComdat(ComdatName);
2916 ComdatList.push_back(C);
2924 if (Record.
size() < 6)
2925 return error(
"Invalid record");
2926 Type *Ty = getTypeByID(Record[0]);
2928 return error(
"Invalid record");
2929 bool isConstant = Record[1] & 1;
2930 bool explicitType = Record[1] & 2;
2933 AddressSpace = Record[1] >> 2;
2936 return error(
"Invalid type for value");
2937 AddressSpace = cast<PointerType>(Ty)->getAddressSpace();
2938 Ty = cast<PointerType>(Ty)->getElementType();
2941 uint64_t RawLinkage = Record[3];
2944 if (std::error_code EC = parseAlignmentValue(Record[4], Alignment))
2948 if (Record[5]-1 >= SectionTable.
size())
2949 return error(
"Invalid ID");
2950 Section = SectionTable[Record[5]-1];
2954 if (Record.
size() > 6 && !GlobalValue::isLocalLinkage(Linkage))
2958 GlobalVariable::ThreadLocalMode
TLM = GlobalVariable::NotThreadLocal;
2959 if (Record.
size() > 7)
2962 bool UnnamedAddr =
false;
2963 if (Record.
size() > 8)
2964 UnnamedAddr = Record[8];
2966 bool ExternallyInitialized =
false;
2967 if (Record.
size() > 9)
2968 ExternallyInitialized = Record[9];
2971 new GlobalVariable(*TheModule, Ty, isConstant, Linkage,
nullptr,
"",
nullptr,
2972 TLM, AddressSpace, ExternallyInitialized);
2974 if (!Section.empty())
2979 if (Record.
size() > 10)
2984 ValueList.push_back(NewGV);
2987 if (
unsigned InitID = Record[2])
2988 GlobalInits.push_back(std::make_pair(NewGV, InitID-1));
2990 if (Record.
size() > 11) {
2991 if (
unsigned ComdatID = Record[11]) {
2992 if (ComdatID > ComdatList.size())
2993 return error(
"Invalid global variable comdat ID");
2994 NewGV->
setComdat(ComdatList[ComdatID - 1]);
2997 NewGV->
setComdat(reinterpret_cast<Comdat *>(1));
3005 if (Record.
size() < 8)
3006 return error(
"Invalid record");
3007 Type *Ty = getTypeByID(Record[0]);
3009 return error(
"Invalid record");
3010 if (
auto *PTy = dyn_cast<PointerType>(Ty))
3014 return error(
"Invalid type for value");
3016 Function *
Func = Function::Create(FTy, GlobalValue::ExternalLinkage,
3020 bool isProto = Record[2];
3021 uint64_t RawLinkage = Record[3];
3026 if (std::error_code EC = parseAlignmentValue(Record[5], Alignment))
3030 if (Record[6]-1 >= SectionTable.
size())
3031 return error(
"Invalid ID");
3038 if (Record.
size() > 8 && Record[8]) {
3039 if (Record[8]-1 >= GCTable.
size())
3040 return error(
"Invalid ID");
3043 bool UnnamedAddr =
false;
3044 if (Record.
size() > 9)
3045 UnnamedAddr = Record[9];
3047 if (Record.
size() > 10 && Record[10] != 0)
3048 FunctionPrologues.push_back(std::make_pair(Func, Record[10]-1));
3050 if (Record.
size() > 11)
3055 if (Record.
size() > 12) {
3056 if (
unsigned ComdatID = Record[12]) {
3057 if (ComdatID > ComdatList.size())
3058 return error(
"Invalid function comdat ID");
3059 Func->
setComdat(ComdatList[ComdatID - 1]);
3062 Func->
setComdat(reinterpret_cast<Comdat *>(1));
3065 if (Record.
size() > 13 && Record[13] != 0)
3066 FunctionPrefixes.push_back(std::make_pair(Func, Record[13]-1));
3068 if (Record.
size() > 14 && Record[14] != 0)
3069 FunctionPersonalityFns.push_back(std::make_pair(Func, Record[14] - 1));
3071 ValueList.push_back(Func);
3077 FunctionsWithBodies.push_back(Func);
3078 DeferredFunctionInfo[
Func] = 0;
3085 if (Record.
size() < 3)
3086 return error(
"Invalid record");
3087 Type *Ty = getTypeByID(Record[0]);
3089 return error(
"Invalid record");
3092 return error(
"Invalid type for value");
3098 if (Record.
size() > 3 && !NewGA->hasLocalLinkage())
3101 if (Record.
size() > 4)
3105 if (Record.
size() > 5)
3107 if (Record.
size() > 6)
3108 NewGA->setUnnamedAddr(Record[6]);
3109 ValueList.push_back(NewGA);
3110 AliasInits.push_back(std::make_pair(NewGA, Record[1]));
3116 if (Record.
size() < 1 || Record[0] > ValueList.
size())
3117 return error(
"Invalid record");
3118 ValueList.shrinkTo(Record[0]);
3126 BitcodeReader::parseBitcodeInto(std::unique_ptr<DataStreamer> Streamer,
3127 Module *M,
bool ShouldLazyLoadMetadata) {
3130 if (std::error_code EC = initStream(std::move(Streamer)))
3134 if (Stream.Read(8) !=
'B' ||
3135 Stream.Read(8) !=
'C' ||
3136 Stream.Read(4) != 0x0 ||
3137 Stream.Read(4) != 0xC ||
3138 Stream.Read(4) != 0xE ||
3139 Stream.Read(4) != 0xD)
3140 return error(
"Invalid bitcode signature");
3145 if (Stream.AtEndOfStream()) {
3147 return error(
"Malformed IR file");
3151 Stream.advance(BitstreamCursor::AF_DontAutoprocessAbbrevs);
3153 if (Entry.
Kind != BitstreamEntry::SubBlock)
3154 return error(
"Malformed block");
3157 return parseModule(
false, ShouldLazyLoadMetadata);
3159 if (Stream.SkipBlock())
3160 return error(
"Invalid record");
3166 return error(
"Invalid record");
3175 switch (Entry.
Kind) {
3176 case BitstreamEntry::SubBlock:
3178 return error(
"Malformed block");
3179 case BitstreamEntry::EndBlock:
3181 case BitstreamEntry::Record:
3187 switch (Stream.readRecord(Entry.
ID, Record)) {
3192 return error(
"Invalid record");
3203 if (std::error_code EC = initStream(
nullptr))
3207 if (Stream.Read(8) !=
'B' ||
3208 Stream.Read(8) !=
'C' ||
3209 Stream.Read(4) != 0x0 ||
3210 Stream.Read(4) != 0xC ||
3211 Stream.Read(4) != 0xE ||
3212 Stream.Read(4) != 0xD)
3213 return error(
"Invalid bitcode signature");
3220 switch (Entry.
Kind) {
3222 return error(
"Malformed block");
3223 case BitstreamEntry::EndBlock:
3224 return std::error_code();
3226 case BitstreamEntry::SubBlock:
3228 return parseModuleTriple();
3231 if (Stream.SkipBlock())
3232 return error(
"Malformed block");
3235 case BitstreamEntry::Record:
3236 Stream.skipRecord(Entry.
ID);
3243 std::error_code BitcodeReader::parseMetadataAttachment(
Function &F) {
3245 return error(
"Invalid record");
3251 switch (Entry.
Kind) {
3252 case BitstreamEntry::SubBlock:
3254 return error(
"Malformed block");
3255 case BitstreamEntry::EndBlock:
3256 return std::error_code();
3257 case BitstreamEntry::Record:
3264 switch (Stream.readRecord(Entry.
ID, Record)) {
3268 unsigned RecordLength = Record.
size();
3270 return error(
"Invalid record");
3271 if (RecordLength % 2 == 0) {
3273 for (
unsigned I = 0;
I != RecordLength;
I += 2) {
3274 auto K = MDKindMap.find(Record[
I]);
3275 if (K == MDKindMap.end())
3276 return error(
"Invalid ID");
3277 Metadata *MD = MDValueList.getValueFwdRef(Record[I + 1]);
3285 for (
unsigned i = 1; i != RecordLength; i = i+2) {
3286 unsigned Kind = Record[i];
3288 MDKindMap.find(Kind);
3289 if (I == MDKindMap.
end())
3290 return error(
"Invalid ID");
3291 Metadata *Node = MDValueList.getValueFwdRef(Record[i + 1]);
3292 if (isa<LocalAsMetadata>(Node))
3297 if (I->second == LLVMContext::MD_tbaa)
3298 InstsWithTBAATag.push_back(Inst);
3308 if (!isa<PointerType>(PtrType))
3309 return error(DH,
"Load/Store operand is not a pointer type");
3310 Type *ElemType = cast<PointerType>(PtrType)->getElementType();
3312 if (ValType && ValType != ElemType)
3313 return error(DH,
"Explicit load/store type does not match pointee type of "
3315 if (!PointerType::isLoadableOrStorableType(ElemType))
3316 return error(DH,
"Cannot load/store from pointer");
3317 return std::error_code();
3321 std::error_code BitcodeReader::parseFunctionBody(
Function *F) {
3323 return error(
"Invalid record");
3325 InstructionList.clear();
3326 unsigned ModuleValueListSize = ValueList.size();
3327 unsigned ModuleMDValueListSize = MDValueList.size();
3331 ValueList.push_back(I);
3333 unsigned NextValueNo = ValueList.size();
3335 unsigned CurBBNo = 0;
3338 auto getLastInstruction = [&]() ->
Instruction * {
3339 if (CurBB && !CurBB->
empty())
3340 return &CurBB->
back();
3341 else if (CurBBNo && FunctionBBs[CurBBNo - 1] &&
3342 !FunctionBBs[CurBBNo - 1]->empty())
3343 return &FunctionBBs[CurBBNo - 1]->back();
3352 switch (Entry.
Kind) {
3354 return error(
"Malformed block");
3355 case BitstreamEntry::EndBlock:
3356 goto OutOfRecordLoop;
3358 case BitstreamEntry::SubBlock:
3361 if (Stream.SkipBlock())
3362 return error(
"Invalid record");
3365 if (std::error_code EC = parseConstants())
3367 NextValueNo = ValueList.size();
3370 if (std::error_code EC = parseValueSymbolTable())
3374 if (std::error_code EC = parseMetadataAttachment(*F))
3378 if (std::error_code EC = parseMetadata())
3382 if (std::error_code EC = parseUseLists())
3388 case BitstreamEntry::Record:
3396 unsigned BitCode = Stream.readRecord(Entry.
ID, Record);
3399 return error(
"Invalid value");
3401 if (Record.
size() < 1 || Record[0] == 0)
3402 return error(
"Invalid record");
3404 FunctionBBs.resize(Record[0]);
3407 auto BBFRI = BasicBlockFwdRefs.find(F);
3408 if (BBFRI == BasicBlockFwdRefs.end()) {
3409 for (
unsigned i = 0, e = FunctionBBs.size(); i != e; ++i)
3410 FunctionBBs[i] = BasicBlock::Create(Context,
"", F);
3412 auto &BBRefs = BBFRI->second;
3414 if (BBRefs.size() > FunctionBBs.size())
3415 return error(
"Invalid ID");
3416 assert(!BBRefs.empty() &&
"Unexpected empty array");
3417 assert(!BBRefs.front() &&
"Invalid reference to entry block");
3418 for (
unsigned I = 0, E = FunctionBBs.size(), RE = BBRefs.size(); I != E;
3420 if (I < RE && BBRefs[I]) {
3421 BBRefs[
I]->insertInto(F);
3422 FunctionBBs[
I] = BBRefs[
I];
3424 FunctionBBs[
I] = BasicBlock::Create(Context,
"", F);
3428 BasicBlockFwdRefs.erase(BBFRI);
3431 CurBB = FunctionBBs[0];
3438 I = getLastInstruction();
3441 return error(
"Invalid record");
3442 I->setDebugLoc(LastLoc);
3447 I = getLastInstruction();
3448 if (!I || Record.
size() < 4)
3449 return error(
"Invalid record");
3451 unsigned Line = Record[0], Col = Record[1];
3452 unsigned ScopeID = Record[2], IAID = Record[3];
3454 MDNode *Scope =
nullptr, *IA =
nullptr;
3455 if (ScopeID) Scope = cast<MDNode>(MDValueList.getValueFwdRef(ScopeID-1));
3456 if (IAID) IA = cast<MDNode>(MDValueList.getValueFwdRef(IAID-1));
3457 LastLoc = DebugLoc::get(Line, Col, Scope, IA);
3458 I->setDebugLoc(LastLoc);
3466 if (getValueTypePair(Record, OpNum, NextValueNo, LHS) ||
3467 popValue(Record, OpNum, NextValueNo, LHS->
getType(), RHS) ||
3468 OpNum+1 > Record.
size())
3469 return error(
"Invalid record");
3473 return error(
"Invalid record");
3475 InstructionList.push_back(I);
3476 if (OpNum < Record.
size()) {
3477 if (Opc == Instruction::Add ||
3478 Opc == Instruction::Sub ||
3479 Opc == Instruction::Mul ||
3480 Opc == Instruction::Shl) {
3482 cast<BinaryOperator>(I)->setHasNoSignedWrap(
true);
3484 cast<BinaryOperator>(
I)->setHasNoUnsignedWrap(
true);
3485 }
else if (Opc == Instruction::SDiv ||
3486 Opc == Instruction::UDiv ||
3487 Opc == Instruction::LShr ||
3488 Opc == Instruction::AShr) {
3490 cast<BinaryOperator>(
I)->setIsExact(
true);
3491 }
else if (isa<FPMathOperator>(I)) {
3494 I->setFastMathFlags(FMF);
3503 if (getValueTypePair(Record, OpNum, NextValueNo, Op) ||
3504 OpNum+2 != Record.
size())
3505 return error(
"Invalid record");
3507 Type *ResTy = getTypeByID(Record[OpNum]);
3509 if (Opc == -1 || !ResTy)
3510 return error(
"Invalid record");
3514 InstructionList.push_back(Temp);
3520 InstructionList.push_back(I);
3532 InBounds = Record[OpNum++];
3533 Ty = getTypeByID(Record[OpNum++]);
3540 if (getValueTypePair(Record, OpNum, NextValueNo, BasePtr))
3541 return error(
"Invalid record");
3550 "Explicit gep type does not match pointee type of pointer operand");
3553 while (OpNum != Record.
size()) {
3555 if (getValueTypePair(Record, OpNum, NextValueNo, Op))
3556 return error(
"Invalid record");
3560 I = GetElementPtrInst::Create(Ty, BasePtr, GEPIdx);
3562 InstructionList.push_back(I);
3564 cast<GetElementPtrInst>(
I)->setIsInBounds(
true);
3572 if (getValueTypePair(Record, OpNum, NextValueNo, Agg))
3573 return error(
"Invalid record");
3575 unsigned RecSize = Record.
size();
3576 if (OpNum == RecSize)
3577 return error(
"EXTRACTVAL: Invalid instruction with 0 indices");
3581 for (; OpNum != RecSize; ++OpNum) {
3584 uint64_t Index = Record[OpNum];
3586 if (!IsStruct && !IsArray)
3587 return error(
"EXTRACTVAL: Invalid type");
3588 if ((
unsigned)Index != Index)
3589 return error(
"Invalid value");
3590 if (IsStruct && Index >= CurTy->
subtypes().size())
3591 return error(
"EXTRACTVAL: Invalid struct index");
3593 return error(
"EXTRACTVAL: Invalid array index");
3594 EXTRACTVALIdx.
push_back((
unsigned)Index);
3602 I = ExtractValueInst::Create(Agg, EXTRACTVALIdx);
3603 InstructionList.push_back(I);
3611 if (getValueTypePair(Record, OpNum, NextValueNo, Agg))
3612 return error(
"Invalid record");
3614 if (getValueTypePair(Record, OpNum, NextValueNo, Val))
3615 return error(
"Invalid record");
3617 unsigned RecSize = Record.
size();
3618 if (OpNum == RecSize)
3619 return error(
"INSERTVAL: Invalid instruction with 0 indices");
3623 for (; OpNum != RecSize; ++OpNum) {
3626 uint64_t Index = Record[OpNum];
3628 if (!IsStruct && !IsArray)
3629 return error(
"INSERTVAL: Invalid type");
3630 if ((
unsigned)Index != Index)
3631 return error(
"Invalid value");
3632 if (IsStruct && Index >= CurTy->
subtypes().size())
3633 return error(
"INSERTVAL: Invalid struct index");
3635 return error(
"INSERTVAL: Invalid array index");
3637 INSERTVALIdx.
push_back((
unsigned)Index);
3645 return error(
"Inserted value type doesn't match aggregate type");
3647 I = InsertValueInst::Create(Agg, Val, INSERTVALIdx);
3648 InstructionList.push_back(I);
3656 Value *TrueVal, *FalseVal, *Cond;
3657 if (getValueTypePair(Record, OpNum, NextValueNo, TrueVal) ||
3658 popValue(Record, OpNum, NextValueNo, TrueVal->
getType(), FalseVal) ||
3659 popValue(Record, OpNum, NextValueNo, Type::getInt1Ty(Context), Cond))
3660 return error(
"Invalid record");
3662 I = SelectInst::Create(Cond, TrueVal, FalseVal);
3663 InstructionList.push_back(I);
3671 Value *TrueVal, *FalseVal, *Cond;
3672 if (getValueTypePair(Record, OpNum, NextValueNo, TrueVal) ||
3673 popValue(Record, OpNum, NextValueNo, TrueVal->
getType(), FalseVal) ||
3674 getValueTypePair(Record, OpNum, NextValueNo, Cond))
3675 return error(
"Invalid record");
3679 dyn_cast<VectorType>(Cond->
getType())) {
3681 if (vector_type->getElementType() != Type::getInt1Ty(Context))
3682 return error(
"Invalid type for value");
3685 if (Cond->
getType() != Type::getInt1Ty(Context))
3686 return error(
"Invalid type for value");
3689 I = SelectInst::Create(Cond, TrueVal, FalseVal);
3690 InstructionList.push_back(I);
3697 if (getValueTypePair(Record, OpNum, NextValueNo, Vec) ||
3698 getValueTypePair(Record, OpNum, NextValueNo, Idx))
3699 return error(
"Invalid record");
3701 return error(
"Invalid type for value");
3702 I = ExtractElementInst::Create(Vec, Idx);
3703 InstructionList.push_back(I);
3709 Value *Vec, *Elt, *Idx;
3710 if (getValueTypePair(Record, OpNum, NextValueNo, Vec))
3711 return error(
"Invalid record");
3713 return error(
"Invalid type for value");
3714 if (popValue(Record, OpNum, NextValueNo,
3715 cast<VectorType>(Vec->
getType())->getElementType(), Elt) ||
3716 getValueTypePair(Record, OpNum, NextValueNo, Idx))
3717 return error(
"Invalid record");
3718 I = InsertElementInst::Create(Vec, Elt, Idx);
3719 InstructionList.push_back(I);
3725 Value *Vec1, *Vec2, *Mask;
3726 if (getValueTypePair(Record, OpNum, NextValueNo, Vec1) ||
3727 popValue(Record, OpNum, NextValueNo, Vec1->
getType(), Vec2))
3728 return error(
"Invalid record");
3730 if (getValueTypePair(Record, OpNum, NextValueNo, Mask))
3731 return error(
"Invalid record");
3733 return error(
"Invalid type for value");
3735 InstructionList.push_back(I);
3748 if (getValueTypePair(Record, OpNum, NextValueNo, LHS) ||
3749 popValue(Record, OpNum, NextValueNo, LHS->
getType(), RHS))
3750 return error(
"Invalid record");
3752 unsigned PredVal = Record[OpNum];
3755 if (IsFP && Record.
size() > OpNum+1)
3758 if (OpNum+1 != Record.
size())
3759 return error(
"Invalid record");
3767 I->setFastMathFlags(FMF);
3768 InstructionList.push_back(I);
3774 unsigned Size = Record.
size();
3776 I = ReturnInst::Create(Context);
3777 InstructionList.push_back(I);
3782 Value *Op =
nullptr;
3783 if (getValueTypePair(Record, OpNum, NextValueNo, Op))
3784 return error(
"Invalid record");
3785 if (OpNum != Record.
size())
3786 return error(
"Invalid record");
3788 I = ReturnInst::Create(Context, Op);
3789 InstructionList.push_back(I);
3793 if (Record.
size() != 1 && Record.
size() != 3)
3794 return error(
"Invalid record");
3795 BasicBlock *TrueDest = getBasicBlock(Record[0]);
3797 return error(
"Invalid record");
3799 if (Record.
size() == 1) {
3800 I = BranchInst::Create(TrueDest);
3801 InstructionList.push_back(I);
3804 BasicBlock *FalseDest = getBasicBlock(Record[1]);
3805 Value *Cond = getValue(Record, 2, NextValueNo,
3806 Type::getInt1Ty(Context));
3807 if (!FalseDest || !Cond)
3808 return error(
"Invalid record");
3809 I = BranchInst::Create(TrueDest, FalseDest, Cond);
3810 InstructionList.push_back(I);
3816 if ((Record[0] >> 16) == SWITCH_INST_MAGIC) {
3822 Type *OpTy = getTypeByID(Record[1]);
3823 unsigned ValueBitWidth = cast<IntegerType>(OpTy)->
getBitWidth();
3825 Value *Cond = getValue(Record, 2, NextValueNo, OpTy);
3827 if (!OpTy || !Cond || !Default)
3828 return error(
"Invalid record");
3830 unsigned NumCases = Record[4];
3832 SwitchInst *
SI = SwitchInst::Create(Cond, Default, NumCases);
3833 InstructionList.push_back(SI);
3835 unsigned CurIdx = 5;
3836 for (
unsigned i = 0; i != NumCases; ++i) {
3838 unsigned NumItems = Record[CurIdx++];
3839 for (
unsigned ci = 0; ci != NumItems; ++ci) {
3840 bool isSingleNumber = Record[CurIdx++];
3843 unsigned ActiveWords = 1;
3844 if (ValueBitWidth > 64)
3845 ActiveWords = Record[CurIdx++];
3848 CurIdx += ActiveWords;
3850 if (!isSingleNumber) {
3852 if (ValueBitWidth > 64)
3853 ActiveWords = Record[CurIdx++];
3855 makeArrayRef(&Record[CurIdx], ActiveWords), ValueBitWidth);
3856 CurIdx += ActiveWords;
3862 for ( ; Low.
ule(High); ++Low)
3863 CaseVals.
push_back(ConstantInt::get(Context, Low));
3865 CaseVals.
push_back(ConstantInt::get(Context, Low));
3867 BasicBlock *DestBB = getBasicBlock(Record[CurIdx++]);
3869 cve = CaseVals.
end(); cvi != cve; ++cvi)
3878 if (Record.
size() < 3 || (Record.
size() & 1) == 0)
3879 return error(
"Invalid record");
3880 Type *OpTy = getTypeByID(Record[0]);
3881 Value *Cond = getValue(Record, 1, NextValueNo, OpTy);
3882 BasicBlock *Default = getBasicBlock(Record[2]);
3883 if (!OpTy || !Cond || !Default)
3884 return error(
"Invalid record");
3885 unsigned NumCases = (Record.
size()-3)/2;
3886 SwitchInst *SI = SwitchInst::Create(Cond, Default, NumCases);
3887 InstructionList.push_back(SI);
3888 for (
unsigned i = 0, e = NumCases; i != e; ++i) {
3890 dyn_cast_or_null<ConstantInt>(getFnValueByID(Record[3+i*2], OpTy));
3891 BasicBlock *DestBB = getBasicBlock(Record[1+3+i*2]);
3892 if (!CaseVal || !DestBB) {
3894 return error(
"Invalid record");
3902 if (Record.
size() < 2)
3903 return error(
"Invalid record");
3904 Type *OpTy = getTypeByID(Record[0]);
3905 Value *
Address = getValue(Record, 1, NextValueNo, OpTy);
3906 if (!OpTy || !Address)
3907 return error(
"Invalid record");
3908 unsigned NumDests = Record.
size()-2;
3910 InstructionList.push_back(IBI);
3911 for (
unsigned i = 0, e = NumDests; i != e; ++i) {
3912 if (
BasicBlock *DestBB = getBasicBlock(Record[2+i])) {
3916 return error(
"Invalid record");
3925 if (Record.
size() < 4)
3926 return error(
"Invalid record");
3929 unsigned CCInfo = Record[OpNum++];
3930 BasicBlock *NormalBB = getBasicBlock(Record[OpNum++]);
3931 BasicBlock *UnwindBB = getBasicBlock(Record[OpNum++]);
3934 if (CCInfo >> 13 & 1 &&
3935 !(FTy = dyn_cast<FunctionType>(getTypeByID(Record[OpNum++]))))
3936 return error(
"Explicit invoke type is not a function type");
3939 if (getValueTypePair(Record, OpNum, NextValueNo, Callee))
3940 return error(
"Invalid record");
3944 return error(
"Callee is not a pointer");
3948 return error(
"Callee is not of pointer to function type");
3950 return error(
"Explicit invoke type does not match pointee type of "
3953 return error(
"Insufficient operands to call");
3956 for (
unsigned i = 0, e = FTy->
getNumParams(); i != e; ++i, ++OpNum) {
3957 Ops.
push_back(getValue(Record, OpNum, NextValueNo,
3960 return error(
"Invalid record");
3964 if (Record.
size() != OpNum)
3965 return error(
"Invalid record");
3968 while (OpNum != Record.
size()) {
3970 if (getValueTypePair(Record, OpNum, NextValueNo, Op))
3971 return error(
"Invalid record");
3976 I = InvokeInst::Create(Callee, NormalBB, UnwindBB, Ops);
3977 InstructionList.push_back(I);
3979 ->setCallingConv(static_cast<CallingConv::ID>(~(1U << 13) & CCInfo));
3980 cast<InvokeInst>(
I)->setAttributes(PAL);
3985 Value *Val =
nullptr;
3986 if (getValueTypePair(Record, Idx, NextValueNo, Val))
3987 return error(
"Invalid record");
3988 I = ResumeInst::Create(Val);
3989 InstructionList.push_back(I);
3994 InstructionList.push_back(I);
3997 if (Record.
size() < 1 || ((Record.
size()-1)&1))
3998 return error(
"Invalid record");
3999 Type *Ty = getTypeByID(Record[0]);
4001 return error(
"Invalid record");
4003 PHINode *PN = PHINode::Create(Ty, (Record.
size()-1)/2);
4004 InstructionList.push_back(PN);
4006 for (
unsigned i = 0, e = Record.
size()-1; i != e; i += 2) {
4012 V = getValueSigned(Record, 1+i, NextValueNo, Ty);
4014 V = getValue(Record, 1+i, NextValueNo, Ty);
4017 return error(
"Invalid record");
4029 if (Record.
size() < 3)
4030 return error(
"Invalid record");
4033 if (Record.
size() < 4)
4034 return error(
"Invalid record");
4036 Type *Ty = getTypeByID(Record[Idx++]);
4038 return error(
"Invalid record");
4040 Value *PersFn =
nullptr;
4041 if (getValueTypePair(Record, Idx, NextValueNo, PersFn))
4042 return error(
"Invalid record");
4047 return error(
"Personality function mismatch");
4050 bool IsCleanup = !!Record[Idx++];
4051 unsigned NumClauses = Record[Idx++];
4054 for (
unsigned J = 0; J != NumClauses; ++J) {
4059 if (getValueTypePair(Record, Idx, NextValueNo, Val)) {
4061 return error(
"Invalid record");
4065 !isa<ArrayType>(Val->
getType())) &&
4066 "Catch clause has a invalid type!");
4067 assert((CT != LandingPadInst::Filter ||
4068 isa<ArrayType>(Val->
getType())) &&
4069 "Filter clause has invalid type!");
4074 InstructionList.push_back(I);
4079 if (Record.
size() != 4)
4080 return error(
"Invalid record");
4081 uint64_t AlignRecord = Record[3];
4082 const uint64_t InAllocaMask = uint64_t(1) << 5;
4083 const uint64_t ExplicitTypeMask = uint64_t(1) << 6;
4084 const uint64_t FlagMask = InAllocaMask | ExplicitTypeMask;
4085 bool InAlloca = AlignRecord & InAllocaMask;
4086 Type *Ty = getTypeByID(Record[0]);
4087 if ((AlignRecord & ExplicitTypeMask) == 0) {
4088 auto *PTy = dyn_cast_or_null<PointerType>(Ty);
4090 return error(
"Old-style alloca with a non-pointer type");
4093 Type *OpTy = getTypeByID(Record[1]);
4094 Value *Size = getFnValueByID(Record[2], OpTy);
4096 if (std::error_code EC =
4097 parseAlignmentValue(AlignRecord & ~FlagMask, Align)) {
4101 return error(
"Invalid record");
4105 InstructionList.push_back(I);
4111 if (getValueTypePair(Record, OpNum, NextValueNo, Op) ||
4112 (OpNum + 2 != Record.
size() && OpNum + 3 != Record.
size()))
4113 return error(
"Invalid record");
4116 if (OpNum + 3 == Record.
size())
4117 Ty = getTypeByID(Record[OpNum++]);
4118 if (std::error_code EC =
4122 Ty = cast<PointerType>(Op->
getType())->getElementType();
4125 if (std::error_code EC = parseAlignmentValue(Record[OpNum], Align))
4127 I =
new LoadInst(Ty, Op,
"", Record[OpNum + 1], Align);
4129 InstructionList.push_back(I);
4136 if (getValueTypePair(Record, OpNum, NextValueNo, Op) ||
4137 (OpNum + 4 != Record.
size() && OpNum + 5 != Record.
size()))
4138 return error(
"Invalid record");
4141 if (OpNum + 5 == Record.
size())
4142 Ty = getTypeByID(Record[OpNum++]);
4143 if (std::error_code EC =
4147 Ty = cast<PointerType>(Op->
getType())->getElementType();
4152 return error(
"Invalid record");
4153 if (Ordering !=
NotAtomic && Record[OpNum] == 0)
4154 return error(
"Invalid record");
4158 if (std::error_code EC = parseAlignmentValue(Record[OpNum], Align))
4160 I =
new LoadInst(Op,
"", Record[OpNum+1], Align, Ordering, SynchScope);
4162 InstructionList.push_back(I);
4169 if (getValueTypePair(Record, OpNum, NextValueNo, Ptr) ||
4171 ? getValueTypePair(Record, OpNum, NextValueNo, Val)
4172 : popValue(Record, OpNum, NextValueNo,
4173 cast<PointerType>(Ptr->
getType())->getElementType(),
4175 OpNum + 2 != Record.
size())
4176 return error(
"Invalid record");
4182 if (std::error_code EC = parseAlignmentValue(Record[OpNum], Align))
4184 I =
new StoreInst(Val, Ptr, Record[OpNum+1], Align);
4185 InstructionList.push_back(I);
4193 if (getValueTypePair(Record, OpNum, NextValueNo, Ptr) ||
4195 ? getValueTypePair(Record, OpNum, NextValueNo, Val)
4196 : popValue(Record, OpNum, NextValueNo,
4197 cast<PointerType>(Ptr->
getType())->getElementType(),
4199 OpNum + 4 != Record.
size())
4200 return error(
"Invalid record");
4208 return error(
"Invalid record");
4210 if (Ordering !=
NotAtomic && Record[OpNum] == 0)
4211 return error(
"Invalid record");
4214 if (std::error_code EC = parseAlignmentValue(Record[OpNum], Align))
4216 I =
new StoreInst(Val, Ptr, Record[OpNum+1], Align, Ordering, SynchScope);
4217 InstructionList.push_back(I);
4225 Value *Ptr, *Cmp, *New;
4226 if (getValueTypePair(Record, OpNum, NextValueNo, Ptr) ||
4228 ? getValueTypePair(Record, OpNum, NextValueNo, Cmp)
4229 : popValue(Record, OpNum, NextValueNo,
4230 cast<PointerType>(Ptr->
getType())->getElementType(),
4232 popValue(Record, OpNum, NextValueNo, Cmp->
getType(), New) ||
4233 Record.
size() < OpNum + 3 || Record.
size() > OpNum + 5)
4234 return error(
"Invalid record");
4237 return error(
"Invalid record");
4244 if (Record.
size() < 7)
4246 AtomicCmpXchgInst::getStrongestFailureOrdering(SuccessOrdering);
4252 cast<AtomicCmpXchgInst>(
I)->setVolatile(Record[OpNum]);
4254 if (Record.
size() < 8) {
4259 I = ExtractValueInst::Create(I, 0);
4261 cast<AtomicCmpXchgInst>(
I)->setWeak(Record[OpNum+4]);
4264 InstructionList.push_back(I);
4271 if (getValueTypePair(Record, OpNum, NextValueNo, Ptr) ||
4272 popValue(Record, OpNum, NextValueNo,
4273 cast<PointerType>(Ptr->
getType())->getElementType(), Val) ||
4274 OpNum+4 != Record.
size())
4275 return error(
"Invalid record");
4277 if (Operation < AtomicRMWInst::FIRST_BINOP ||
4278 Operation > AtomicRMWInst::LAST_BINOP)
4279 return error(
"Invalid record");
4282 return error(
"Invalid record");
4284 I =
new AtomicRMWInst(Operation, Ptr, Val, Ordering, SynchScope);
4285 cast<AtomicRMWInst>(
I)->setVolatile(Record[OpNum+1]);
4286 InstructionList.push_back(I);
4290 if (2 != Record.
size())
4291 return error(
"Invalid record");
4295 return error(
"Invalid record");
4297 I =
new FenceInst(Context, Ordering, SynchScope);
4298 InstructionList.push_back(I);
4303 if (Record.
size() < 3)
4304 return error(
"Invalid record");
4308 unsigned CCInfo = Record[OpNum++];
4311 if (CCInfo >> 15 & 1 &&
4312 !(FTy = dyn_cast<FunctionType>(getTypeByID(Record[OpNum++]))))
4313 return error(
"Explicit call type is not a function type");
4316 if (getValueTypePair(Record, OpNum, NextValueNo, Callee))
4317 return error(
"Invalid record");
4321 return error(
"Callee is not a pointer type");
4325 return error(
"Callee is not of pointer to function type");
4327 return error(
"Explicit call type does not match pointee type of "
4330 return error(
"Insufficient operands to call");
4334 for (
unsigned i = 0, e = FTy->
getNumParams(); i != e; ++i, ++OpNum) {
4336 Args.
push_back(getBasicBlock(Record[OpNum]));
4338 Args.
push_back(getValue(Record, OpNum, NextValueNo,
4341 return error(
"Invalid record");
4346 if (OpNum != Record.
size())
4347 return error(
"Invalid record");
4349 while (OpNum != Record.
size()) {
4351 if (getValueTypePair(Record, OpNum, NextValueNo, Op))
4352 return error(
"Invalid record");
4357 I = CallInst::Create(FTy, Callee, Args);
4358 InstructionList.push_back(I);
4359 cast<CallInst>(
I)->setCallingConv(
4360 static_cast<CallingConv::ID>((~(1U << 14) & CCInfo) >> 1));
4363 TCK = CallInst::TCK_Tail;
4364 if (CCInfo & (1 << 14))
4365 TCK = CallInst::TCK_MustTail;
4366 cast<CallInst>(
I)->setTailCallKind(TCK);
4367 cast<CallInst>(
I)->setAttributes(PAL);
4371 if (Record.
size() < 3)
4372 return error(
"Invalid record");
4373 Type *OpTy = getTypeByID(Record[0]);
4374 Value *Op = getValue(Record, 1, NextValueNo, OpTy);
4375 Type *ResTy = getTypeByID(Record[2]);
4376 if (!OpTy || !Op || !ResTy)
4377 return error(
"Invalid record");
4379 InstructionList.push_back(I);
4388 return error(
"Invalid instruction with no BB");
4393 if (isa<TerminatorInst>(I)) {
4395 CurBB = CurBBNo < FunctionBBs.size() ? FunctionBBs[CurBBNo] :
nullptr;
4399 if (I && !I->getType()->isVoidTy())
4400 ValueList.assignValue(I, NextValueNo++);
4406 if (
Argument *
A = dyn_cast<Argument>(ValueList.back())) {
4407 if (!
A->getParent()) {
4409 for (
unsigned i = ModuleValueListSize, e = ValueList.size(); i != e; ++i){
4410 if ((
A = dyn_cast_or_null<Argument>(ValueList[i])) && !
A->getParent()) {
4411 A->replaceAllUsesWith(UndefValue::get(
A->getType()));
4415 return error(
"Never resolved value found in function");
4423 ValueList.shrinkTo(ModuleValueListSize);
4424 MDValueList.shrinkTo(ModuleMDValueListSize);
4425 std::vector<BasicBlock*>().
swap(FunctionBBs);
4426 return std::error_code();
4430 std::error_code BitcodeReader::findFunctionInStream(
4433 while (DeferredFunctionInfoIterator->second == 0) {
4434 if (Stream.AtEndOfStream())
4435 return error(
"Could not find function in stream");
4438 if (std::error_code EC = parseModule(
true))
4441 return std::error_code();
4448 void BitcodeReader::releaseBuffer() { Buffer.release(); }
4450 std::error_code BitcodeReader::materialize(
GlobalValue *GV) {
4451 if (std::error_code EC = materializeMetadata())
4457 return std::error_code();
4460 assert(DFII != DeferredFunctionInfo.
end() &&
"Deferred function not found!");
4463 if (DFII->second == 0)
4464 if (std::error_code EC = findFunctionInStream(F, DFII))
4468 Stream.JumpToBit(DFII->second);
4470 if (std::error_code EC = parseFunctionBody(F))
4478 for (
auto &I : UpgradedIntrinsics) {
4479 for (
auto UI = I.first->user_begin(), UE = I.first->user_end(); UI != UE;) {
4482 if (
CallInst *CI = dyn_cast<CallInst>(U))
4489 return materializeForwardReferencedFunctions();
4492 bool BitcodeReader::isDematerializable(
const GlobalValue *GV)
const {
4499 if (BlockAddressesTaken.count(F))
4502 return DeferredFunctionInfo.count(const_cast<Function*>(F));
4505 void BitcodeReader::dematerialize(
GlobalValue *GV) {
4508 if (!F || !isDematerializable(F))
4511 assert(DeferredFunctionInfo.count(F) &&
"No info to read function later?");
4518 std::error_code BitcodeReader::materializeModule(
Module *M) {
4519 assert(M == TheModule &&
4520 "Can only Materialize the Module this BitcodeReader is attached to.");
4522 if (std::error_code EC = materializeMetadata())
4526 WillMaterializeAllForwardRefs =
true;
4532 if (std::error_code EC = materialize(F))
4543 if (!BasicBlockFwdRefs.empty())
4544 return error(
"Never resolved function from blockaddress");
4550 for (
auto &I : UpgradedIntrinsics) {
4551 for (
auto *U : I.first->
users()) {
4552 if (
CallInst *CI = dyn_cast<CallInst>(U))
4555 if (!I.first->use_empty())
4556 I.first->replaceAllUsesWith(I.second);
4557 I.first->eraseFromParent();
4559 UpgradedIntrinsics.clear();
4561 for (
unsigned I = 0, E = InstsWithTBAATag.size(); I < E; I++)
4565 return std::error_code();
4568 std::vector<StructType *> BitcodeReader::getIdentifiedStructTypes()
const {
4569 return IdentifiedStructTypes;
4573 BitcodeReader::initStream(std::unique_ptr<DataStreamer> Streamer) {
4575 return initLazyStream(std::move(Streamer));
4576 return initStreamFromBuffer();
4579 std::error_code BitcodeReader::initStreamFromBuffer() {
4580 const unsigned char *BufPtr = (
const unsigned char*)Buffer->getBufferStart();
4581 const unsigned char *BufEnd = BufPtr+Buffer->getBufferSize();
4583 if (Buffer->getBufferSize() & 3)
4584 return error(
"Invalid bitcode signature");
4590 return error(
"Invalid bitcode wrapper header");
4593 Stream.init(&*StreamFile);
4595 return std::error_code();
4599 BitcodeReader::initLazyStream(std::unique_ptr<DataStreamer> Streamer) {
4603 llvm::make_unique<StreamingMemoryObject>(std::move(Streamer));
4605 StreamFile = llvm::make_unique<BitstreamReader>(std::move(OwnedBytes));
4606 Stream.init(&*StreamFile);
4608 unsigned char buf[16];
4609 if (Bytes.readBytes(buf, 16, 0) != 16)
4610 return error(
"Invalid bitcode signature");
4613 return error(
"Invalid bitcode signature");
4616 const unsigned char *bitcodeStart = buf;
4617 const unsigned char *bitcodeEnd = buf + 16;
4619 Bytes.dropLeadingBytes(bitcodeStart - buf);
4620 Bytes.setKnownObjectSize(bitcodeEnd - bitcodeStart);
4622 return std::error_code();
4628 return "llvm.bitcode";
4630 std::string message(
int IE)
const override {
4633 case BitcodeError::InvalidBitcodeSignature:
4634 return "Invalid bitcode signature";
4635 case BitcodeError::CorruptedBitcode:
4636 return "Corrupted bitcode";
4656 bool MaterializeAll,
bool ShouldLazyLoadMetadata) {
4657 std::unique_ptr<Module> M = make_unique<Module>(
Name, Context);
4660 auto cleanupOnError = [&](std::error_code EC) {
4666 if (std::error_code EC = R->parseBitcodeInto(std::move(Streamer), M.get(),
4667 ShouldLazyLoadMetadata))
4668 return cleanupOnError(EC);
4670 if (MaterializeAll) {
4672 if (std::error_code EC = M->materializeAllPermanently())
4673 return cleanupOnError(EC);
4676 if (std::error_code EC = R->materializeForwardReferencedFunctions())
4677 return cleanupOnError(EC);
4679 return std::move(M);
4694 bool ShouldLazyLoadMetadata =
false) {
4696 new BitcodeReader(Buffer.get(), Context, DiagnosticHandler);
4700 MaterializeAll, ShouldLazyLoadMetadata);
4709 std::unique_ptr<MemoryBuffer> &&Buffer,
LLVMContext &Context,
4712 DiagnosticHandler, ShouldLazyLoadMetadata);
4716 StringRef Name, std::unique_ptr<DataStreamer> Streamer,
4718 std::unique_ptr<Module> M = make_unique<Module>(
Name, Context);
4719 BitcodeReader *R =
new BitcodeReader(Context, DiagnosticHandler);
4728 std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(Buffer,
false);
4738 std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(Buffer,
false);
4739 auto R = llvm::make_unique<BitcodeReader>(Buf.release(), Context,
4742 if (Triple.getError())
4744 return Triple.
get();
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 (if unknown returns 0).
void setPersonalityFn(Constant *C)
void sortUseList(Compare Cmp)
Sort the use-list.
void push_back(const T &Elt)
static APInt readWideAPInt(ArrayRef< uint64_t > Vals, unsigned TypeBits)
Represents either an error or a value T.
iterator_range< use_iterator > uses()
void addIncoming(Value *V, BasicBlock *BB)
addIncoming - Add an incoming value to the end of the PHI list
BLOCKINFO_BLOCK is used to define metadata about blocks, for example, standard abbrevs that should be...
LLVM Argument representation.
const Instruction & back() const
ValueT lookup(const KeyT &Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
This class is used to read from an LLVM bitcode stream, maintaining information that is global to dec...
A Module instance is used to store all the information related to an LLVM module. ...
unsigned getNumParams() const
getNumParams - Return the number of fixed parameters this function type requires. ...
void setNoNaNs()
Flag setters.
FenceInst - an instruction for ordering other memory operations.
AtomicCmpXchgInst - an instruction that atomically checks whether a specified value is in a memory lo...
Tracking metadata reference.
static int getDecodedBinaryOpcode(unsigned Val, Type *Ty)
DiagnosticSeverity
Defines the different supported severity of a diagnostic.
void addCase(ConstantInt *OnVal, BasicBlock *Dest)
addCase - Add an entry to the switch instruction...
void setMaterializer(GVMaterializer *GVM)
Sets the GVMaterializer to GVM.
void addOperand(MDNode *M)
CallInst - This class represents a function call, abstracting a target machine's calling convention...
void UpgradeMDStringConstant(std::string &String)
Upgrade a metadata string constant in place.
float BitsToFloat(uint32_t Bits)
BitsToFloat - This function takes a 32-bit integer and returns the bit equivalent float...
ShuffleVectorInst - This instruction constructs a fixed permutation of two input vectors.
bool isDoubleTy() const
isDoubleTy - Return true if this is 'double', a 64-bit IEEE fp type.
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...
std::string str() const
str - Get the contents as an std::string.
AttrBuilder & addDereferenceableAttr(uint64_t Bytes)
This turns the number of dereferenceable bytes into the form used internally in Attribute.
The two locations do not alias at all.
bool stripDebugInfo(Function &F)
LoadInst - an instruction for reading from memory.
ELFYAML::ELF_STV Visibility
static Attribute::AttrKind getAttrFromCode(uint64_t Code)
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > Tys=None)
Return the function type for an intrinsic.
AttrBuilder & addAttribute(Attribute::AttrKind Val)
Add an attribute to the builder.
AtomicRMWInst - an instruction that atomically reads a memory location, combines it with another valu...
static std::error_code typeCheckLoadStoreInst(DiagnosticHandlerFunction DH, Type *ValType, Type *PtrType)
void reserve(size_type N)
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)
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.
ErrorOr< std::unique_ptr< Module > > getStreamedBitcodeModule(StringRef Name, std::unique_ptr< DataStreamer > Streamer, LLVMContext &Context, DiagnosticHandlerFunction DiagnosticHandler=nullptr)
Read the header of the specified stream and prepare for lazy deserialization and streaming of functio...
AttrBuilder & addRawValue(uint64_t Val)
Add the raw value to the internal representation.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, bool gen_crash_diag=true)
Reports a serious error, calling any installed error handler.
bool isMaterializable() const
StringRef getName() const
Return a constant reference to the value's name.
void push_back(NodeTy *val)
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...
enum llvm::BitstreamEntry::@28 Kind
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
StructType - Class to represent struct types.
static ErrorOr< std::unique_ptr< Module > > getBitcodeModuleImpl(std::unique_ptr< DataStreamer > Streamer, StringRef Name, BitcodeReader *R, LLVMContext &Context, bool MaterializeAll, bool ShouldLazyLoadMetadata)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
A Use represents the edge between a Value definition and its users.
std::error_code make_error_code(BitcodeError E)
void setMetadata(unsigned KindID, MDNode *MD)
Set a particular kind of metadata attachment.
Number of individual test Apply this number of consecutive mutations to each input exit after the first new interesting input is found the minimized corpus is saved into the first input directory Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
void setName(const Twine &Name)
Change the name of the value.
Interface for custom diagnostic printing.
void setDLLStorageClass(DLLStorageClassTypes C)
static GlobalValue::LinkageTypes getDecodedLinkage(unsigned Val)
#define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS)
Macro for generating out-of-class operand accessor definitions.
FunctionType - Class to represent function types.
ConstantExpr - a constant value that is initialized with an expression using other constant values...
void setCleanup(bool V)
setCleanup - Indicate that this landingpad instruction is a cleanup.
LLVMContext & getContext() const
getContext - Return the LLVMContext in which this type was uniqued.
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
const BasicBlock & back() const
BinOp
This enumeration lists the possible modifications atomicrmw can make.
bool isHalfTy() const
isHalfTy - Return true if this is 'half', a 16-bit IEEE fp type.
Value handle that is nullable, but tries to track the Value.
ArrayType - Class to represent array types.
VisibilityTypes
An enumeration for the kinds of visibility of global values.
This instruction compares its operands according to the predicate given to the constructor.
void setComdat(Comdat *C)
bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
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.
Interface to data which is actually streamed from a DataStreamer.
static std::error_code error(DiagnosticHandlerFunction DiagnosticHandler, std::error_code EC, const Twine &Message)
StoreInst - an instruction for storing to memory.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
bool isArrayTy() const
isArrayTy - True if this is an instance of ArrayType.
unsigned getNumElements() const
Return the number of elements in the Vector type.
bool isPPC_FP128Ty() const
isPPC_FP128Ty - Return true if this is powerpc long double.
Type * getElementType() const
size_t size() const
size - Get the array size.
static GlobalValue::DLLStorageClassTypes getDecodedDLLStorageClass(unsigned Val)
const std::error_category & BitcodeErrorCategory()
PointerType - Class to represent pointers.
BitcodeDiagnosticInfo(std::error_code EC, DiagnosticSeverity Severity, const Twine &Msg)
void setCallingConv(CallingConv::ID CC)
bool isIntOrIntVectorTy() const
isIntOrIntVectorTy - Return true if this is an integer type or a vector of integer types...
Type * getParamType(unsigned i) const
Parameter type accessors.
This is the base abstract class for diagnostic reporting in the backend.
LandingPadInst - The landingpad instruction holds all of the information necessary to generate correc...
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
bool isVectorTy() const
isVectorTy - True if this is an instance of VectorType.
UnreachableInst - This function has undefined behavior.
This is an important base class in LLVM.
static bool hasImplicitComdat(size_t Val)
This represents a position within a bitcode file.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
ErrorOr< std::unique_ptr< Module > > parseBitcodeFile(MemoryBufferRef Buffer, LLVMContext &Context, DiagnosticHandlerFunction DiagnosticHandler=nullptr)
Read the specified bitcode file, returning the module.
void setUsedWithInAlloca(bool V)
Specify whether this alloca is used to represent the arguments to a call.
IndirectBrInst - Indirect Branch Instruction.
bool isFloatTy() const
isFloatTy - Return true if this is 'float', a 32-bit IEEE fp type.
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
bool UpgradeDebugInfo(Module &M)
Check the debug info version number, if it is out-dated, drop the debug info.
APInt Xor(const APInt &LHS, const APInt &RHS)
Bitwise XOR function for APInt.
bool hasPersonalityFn() const
Get the personality function associated with this function.
static ManagedStatic< _object_error_category > error_category
const InstListType & getInstList() const
Return the underlying instruction list container.
This instruction compares its operands according to the predicate given to the constructor.
void addClause(Constant *ClauseVal)
Add a catch or filter clause to the landing pad.
DLLStorageClassTypes
Storage classes of global values for PE targets.
static ErrorOr< std::unique_ptr< Module > > getLazyBitcodeModuleImpl(std::unique_ptr< MemoryBuffer > &&Buffer, LLVMContext &Context, bool MaterializeAll, DiagnosticHandlerFunction DiagnosticHandler, bool ShouldLazyLoadMetadata=false)
Get a lazy one-at-time loading module from bitcode.
#define DECLARE_TRANSPARENT_OPERAND_ACCESSORS(VALUECLASS)
Macro for generating in-class operand accessor declarations.
bool isFP128Ty() const
isFP128Ty - Return true if this is 'fp128'.
bool isPointerTy() const
isPointerTy - True if this is an instance of PointerType.
static UndefValue * get(Type *T)
get() - Static factory methods - Return an 'undef' object of the specified type.
VAArgInst - This class represents the va_arg llvm instruction, which returns an argument of the speci...
bool isFPOrFPVectorTy() const
isFPOrFPVectorTy - Return true if this is a FP type or a vector of FP.
static GlobalValue::VisibilityTypes getDecodedVisibility(unsigned Val)
void setBody(ArrayRef< Type * > Elements, bool isPacked=false)
setBody - Specify a body for an opaque identified type.
void setMetadata(unsigned KindID, MDNode *Node)
setMetadata - Set the metadata of the specified kind to the specified node.
Triple - Helper class for working with autoconf configuration names.
An imported module (C++ using directive or similar).
static Comdat::SelectionKind getDecodedComdatSelectionKind(unsigned Val)
#define GET_OR_DISTINCT(CLASS, DISTINCT, ARGS)
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...
SmallVectorImpl< T >::const_pointer c_str(SmallVectorImpl< T > &str)
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
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)
void setAllowReciprocal()
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
bool UpgradeGlobalVariable(GlobalVariable *GV)
This checks for global variables which should be upgraded.
bool isBitcode(const unsigned char *BufPtr, const unsigned char *BufEnd)
isBitcode - Return true if the given bytes are the magic bytes for LLVM IR bitcode, either with or without a wrapper.
void print(DiagnosticPrinter &DP) const override
Print using the given DP a user-friendly message.
void setUnnamedAddr(bool Val)
std::function< void(const DiagnosticInfo &)> DiagnosticHandlerFunction
void dropAllReferences()
dropAllReferences() - This method causes all the subinstructions to "let go" of all references that t...
static SynchronizationScope getDecodedSynchScope(unsigned Val)
bool any() const
Whether any flag is set.
std::string getBitcodeTargetTriple(MemoryBufferRef Buffer, LLVMContext &Context, DiagnosticHandlerFunction DiagnosticHandler=nullptr)
Read the header of the specified bitcode buffer and extract just the triple information.
static cl::opt< AlignMode > Align(cl::desc("Load/store alignment support"), cl::Hidden, cl::init(NoStrictAlign), cl::values(clEnumValN(StrictAlign,"aarch64-strict-align","Disallow all unaligned memory accesses"), clEnumValN(NoStrictAlign,"aarch64-no-strict-align","Allow unaligned memory accesses"), clEnumValEnd))
double BitsToDouble(uint64_t Bits)
BitsToDouble - This function takes a 64-bit integer and returns the bit equivalent double...
void setLinkage(LinkageTypes LT)
This interface provides simple read-only access to a block of memory, and provides simple methods for...
static int64_t unrotateSign(uint64_t U)
static GlobalVariable::ThreadLocalMode getDecodedThreadLocalMode(unsigned Val)
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
VectorType - Class to represent vector types.
Class for arbitrary precision integers.
ConstantArray - Constant Array Declarations.
static int getDecodedCastOpcode(unsigned Val)
StringRef str() const
Explicit conversion to StringRef.
LinkageTypes
An enumeration for the kinds of linkage for global values.
A (clang) module that has been imported by the compile unit.
bool isIntegerTy() const
isIntegerTy - True if this is an instance of IntegerType.
iterator_range< user_iterator > users()
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
void setGC(const char *Str)
Generic tagged DWARF-like metadata node.
void setIsMaterializable(bool V)
const Type * getScalarType() const LLVM_READONLY
getScalarType - If this is a vector type, return the element type, otherwise return 'this'...
static DiagnosticHandlerFunction getDiagHandler(DiagnosticHandlerFunction F, LLVMContext &C)
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
bool isStructTy() const
isStructTy - True if this is an instance of StructType.
Type array for a subprogram.
void setName(StringRef Name)
setName - Change the name of this type to the specified name, or to a name with a suffix if there is ...
PointerType * getType() const
Global values are always pointers.
static AtomicRMWInst::BinOp getDecodedRMWOperation(unsigned Val)
bool isX86_FP80Ty() const
isX86_FP80Ty - Return true if this is x86 long double.
ValID - Represents a reference of a definition of some sort with no type.
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)
Constant * getPersonalityFn() const
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
iterator find(const KeyT &Val)
Compile-time customization of User operands.
void destroyConstant()
Called if some element of this constant is no longer valid.
uint64_t getArrayNumElements() const
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
AttributeSet getAttributes(LLVMContext &C, ID id)
Return the attributes for an intrinsic.
void setAttributes(AttributeSet attrs)
Set the attribute list for this Function.
static void upgradeDLLImportExportLinkage(llvm::GlobalValue *GV, unsigned Val)
bool hasLocalLinkage() const
void addDestination(BasicBlock *Dest)
addDestination - Add a destination.
SwitchInst - Multiway switch.
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...
user_iterator user_begin()
const ARM::ArchExtKind Kind
StringMapEntry< Value * > ValueName
bool isLabelTy() const
isLabelTy - Return true if this is 'label'.
LLVM Value Representation.
ErrorOr< std::unique_ptr< Module > > getLazyBitcodeModule(std::unique_ptr< MemoryBuffer > &&Buffer, LLVMContext &Context, DiagnosticHandlerFunction DiagnosticHandler=nullptr, bool ShouldLazyLoadMetadata=false)
Read the header of the specified bitcode buffer and prepare for lazy deserialization of function bodi...
AttrBuilder & addStackAlignmentAttr(unsigned Align)
This turns an int stack alignment (which must be a power of 2) into the form used internally in Attri...
void UpgradeInstWithTBAATag(Instruction *I)
If the TBAA tag for the given instruction uses the scalar TBAA format, we upgrade it to the struct-pa...
C - The default llvm calling convention, compatible with C.
bool isPowerOf2_32(uint32_t Value)
isPowerOf2_32 - This function returns true if the argument is a power of two > 0. ...
Convenience struct for specifying and reasoning about fast-math flags.
StringRef - Represent a constant reference to a string, i.e.
static ManagedStatic< BitcodeErrorCategoryType > ErrorCategory
FixedNumOperandTraits - determine the allocation regime of the Use array when it is a prefix to the U...
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...
Value * UpgradeBitCastExpr(unsigned Opc, Constant *C, Type *DestTy)
This is an auto-upgrade for bitcast constant expression between pointers with different address space...
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
void setSection(StringRef S)
void setAliasee(Constant *Aliasee)
These methods retrive and set alias target.
static FastMathFlags getDecodedFastMathFlags(unsigned Val)
ArrayRef< Type * > subtypes() const
bool isVoidTy() const
isVoidTy - Return true if this is 'void'.
AllocaInst - an instruction to allocate memory on the stack.
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results...
Basic type, like 'int' or 'float'.
bool isMetadataTy() const
isMetadataTy - Return true if this is 'metadata'.