71 "Can't read textual IR with a Context that discards named Values");
73 return ParseTopLevelEntities() || ValidateEndOfModule() ||
79 restoreParsingState(Slots);
83 if (ParseType(Ty) || parseConstantValue(Ty, C))
86 return Error(Lex.
getLoc(),
"expected end of string");
92 restoreParsingState(Slots);
106 void LLParser::restoreParsingState(
const SlotMapping *Slots) {
113 std::make_pair(
I.getKey(), std::make_pair(
I.second,
LocTy())));
114 for (
const auto &
I : Slots->
Types)
115 NumberedTypes.insert(
116 std::make_pair(
I.first, std::make_pair(
I.second,
LocTy())));
121 bool LLParser::ValidateEndOfModule() {
125 for (
const auto &RAG : ForwardRefAttrGroups) {
126 Value *V = RAG.first;
127 const std::vector<unsigned> &
Attrs = RAG.second;
130 for (
const auto &Attr : Attrs)
131 B.
merge(NumberedAttrBuilders[Attr]);
133 if (
Function *Fn = dyn_cast<Function>(V)) {
142 if (FnAttrs.hasAlignmentAttr()) {
143 Fn->setAlignment(FnAttrs.getAlignment());
149 Fn->setAttributes(AS);
150 }
else if (
CallInst *CI = dyn_cast<CallInst>(V)) {
157 CI->setAttributes(AS);
158 }
else if (
InvokeInst *II = dyn_cast<InvokeInst>(V)) {
165 II->setAttributes(AS);
166 }
else if (
CallBrInst *CBI = dyn_cast<CallBrInst>(V)) {
173 CBI->setAttributes(AS);
174 }
else if (
auto *GV = dyn_cast<GlobalVariable>(V)) {
185 if (!ForwardRefBlockAddresses.empty())
186 return Error(ForwardRefBlockAddresses.begin()->first.Loc,
187 "expected function name in blockaddress");
189 for (
const auto &NT : NumberedTypes)
190 if (NT.second.second.isValid())
191 return Error(NT.second.second,
192 "use of undefined type '%" +
Twine(NT.first) +
"'");
194 for (
StringMap<std::pair<Type*, LocTy> >::iterator
I =
195 NamedTypes.begin(),
E = NamedTypes.end();
I !=
E; ++
I)
196 if (
I->second.second.isValid())
197 return Error(
I->second.second,
198 "use of undefined type named '" +
I->getKey() +
"'");
200 if (!ForwardRefComdats.empty())
201 return Error(ForwardRefComdats.begin()->second,
202 "use of undefined comdat '$" +
203 ForwardRefComdats.begin()->first +
"'");
205 if (!ForwardRefVals.empty())
206 return Error(ForwardRefVals.begin()->second.second,
207 "use of undefined value '@" + ForwardRefVals.begin()->first +
210 if (!ForwardRefValIDs.empty())
211 return Error(ForwardRefValIDs.begin()->second.second,
212 "use of undefined value '@" +
213 Twine(ForwardRefValIDs.begin()->first) +
"'");
215 if (!ForwardRefMDNodes.empty())
216 return Error(ForwardRefMDNodes.begin()->second.second,
217 "use of undefined metadata '!" +
218 Twine(ForwardRefMDNodes.begin()->first) +
"'");
221 for (
auto &
N : NumberedMetadata) {
222 if (
N.second && !
N.second->isResolved())
223 N.second->resolveCycles();
226 for (
auto *Inst : InstsWithTBAATag) {
227 MDNode *MD = Inst->getMetadata(LLVMContext::MD_tbaa);
228 assert(MD &&
"UpgradeInstWithTBAATag should have a TBAA tag");
230 if (MD != UpgradedMD)
231 Inst->setMetadata(LLVMContext::MD_tbaa, UpgradedMD);
249 if (UpgradeDebugInfo)
262 for (
const auto &
I : NamedTypes)
263 Slots->
NamedTypes.insert(std::make_pair(
I.getKey(),
I.second.first));
264 for (
const auto &
I : NumberedTypes)
265 Slots->
Types.insert(std::make_pair(
I.first,
I.second.first));
271 bool LLParser::ValidateEndOfIndex() {
275 if (!ForwardRefValueInfos.empty())
276 return Error(ForwardRefValueInfos.begin()->second.front().second,
277 "use of undefined summary '^" +
278 Twine(ForwardRefValueInfos.begin()->first) +
"'");
280 if (!ForwardRefAliasees.empty())
281 return Error(ForwardRefAliasees.begin()->second.front().second,
282 "use of undefined summary '^" +
283 Twine(ForwardRefAliasees.begin()->first) +
"'");
285 if (!ForwardRefTypeIds.empty())
286 return Error(ForwardRefTypeIds.begin()->second.front().second,
287 "use of undefined type id summary '^" +
288 Twine(ForwardRefTypeIds.begin()->first) +
"'");
297 bool LLParser::ParseTopLevelEntities() {
305 if (ParseSummaryEntry())
309 if (ParseSourceFileName())
320 default:
return TokError(
"expected top-level entity");
327 if (ParseSourceFileName())
336 case lltok::exclaim:
if (ParseStandaloneMetadata())
return true;
break;
338 if (ParseSummaryEntry())
345 if (ParseUseListOrderBB())
354 bool LLParser::ParseModuleAsm() {
360 ParseStringConstant(AsmStr))
return true;
369 bool LLParser::ParseTargetDefinition() {
373 default:
return TokError(
"unknown target property");
376 if (ParseToken(
lltok::equal,
"expected '=' after target triple") ||
377 ParseStringConstant(Str))
383 if (ParseToken(
lltok::equal,
"expected '=' after target datalayout") ||
384 ParseStringConstant(Str))
386 if (DataLayoutStr.
empty())
394 bool LLParser::ParseSourceFileName() {
397 if (ParseToken(
lltok::equal,
"expected '=' after source_filename") ||
398 ParseStringConstant(SourceFileName))
409 bool LLParser::ParseDepLibs() {
412 if (ParseToken(
lltok::equal,
"expected '=' after deplibs") ||
421 if (ParseStringConstant(Str))
return true;
429 bool LLParser::ParseUnnamedType() {
434 if (ParseToken(
lltok::equal,
"expected '=' after name") ||
438 Type *Result =
nullptr;
439 if (ParseStructDefinition(TypeLoc,
"",
440 NumberedTypes[TypeID], Result))
return true;
442 if (!isa<StructType>(Result)) {
443 std::pair<Type*, LocTy> &
Entry = NumberedTypes[
TypeID];
445 return Error(TypeLoc,
"non-struct types may not be recursive");
446 Entry.first = Result;
447 Entry.second =
SMLoc();
455 bool LLParser::ParseNamedType() {
460 if (ParseToken(
lltok::equal,
"expected '=' after name") ||
464 Type *Result =
nullptr;
465 if (ParseStructDefinition(NameLoc, Name,
466 NamedTypes[Name], Result))
return true;
468 if (!isa<StructType>(Result)) {
469 std::pair<Type*, LocTy> &
Entry = NamedTypes[
Name];
471 return Error(NameLoc,
"non-struct types may not be recursive");
472 Entry.first = Result;
473 Entry.second =
SMLoc();
481 bool LLParser::ParseDeclare() {
485 std::vector<std::pair<unsigned, MDNode *>> MDs;
489 if (ParseMetadataAttachment(MDK, N))
491 MDs.push_back({MDK, N});
495 if (ParseFunctionHeader(F,
false))
504 bool LLParser::ParseDefine() {
509 return ParseFunctionHeader(F,
true) ||
510 ParseOptionalFunctionMetadata(*F) ||
511 ParseFunctionBody(*F);
517 bool LLParser::ParseGlobalType(
bool &IsConstant) {
524 return TokError(
"expected 'global' or 'constant'");
530 bool LLParser::ParseOptionalUnnamedAddr(
550 bool LLParser::ParseUnnamedGlobal() {
551 unsigned VarID = NumberedVals.size();
558 return Error(Lex.
getLoc(),
"variable expected to be numbered '%" +
562 if (ParseToken(
lltok::equal,
"expected '=' after name"))
567 unsigned Linkage, Visibility, DLLStorageClass;
571 if (ParseOptionalLinkage(Linkage, HasLinkage, Visibility, DLLStorageClass,
573 ParseOptionalThreadLocal(TLM) || ParseOptionalUnnamedAddr(UnnamedAddr))
577 return ParseGlobal(Name, NameLoc, Linkage, HasLinkage, Visibility,
578 DLLStorageClass, DSOLocal, TLM, UnnamedAddr);
580 return parseIndirectSymbol(Name, NameLoc, Linkage, Visibility,
581 DLLStorageClass, DSOLocal, TLM, UnnamedAddr);
589 bool LLParser::ParseNamedGlobal() {
596 unsigned Linkage, Visibility, DLLStorageClass;
600 if (ParseToken(
lltok::equal,
"expected '=' in global variable") ||
601 ParseOptionalLinkage(Linkage, HasLinkage, Visibility, DLLStorageClass,
603 ParseOptionalThreadLocal(TLM) || ParseOptionalUnnamedAddr(UnnamedAddr))
607 return ParseGlobal(Name, NameLoc, Linkage, HasLinkage, Visibility,
608 DLLStorageClass, DSOLocal, TLM, UnnamedAddr);
610 return parseIndirectSymbol(Name, NameLoc, Linkage, Visibility,
611 DLLStorageClass, DSOLocal, TLM, UnnamedAddr);
614 bool LLParser::parseComdat() {
624 return TokError(
"expected comdat type");
629 return TokError(
"unknown selection kind");
651 if (I != ComdatSymTab.
end() && !ForwardRefComdats.erase(Name))
652 return Error(NameLoc,
"redefinition of comdat '$" + Name +
"'");
655 if (I != ComdatSymTab.
end())
666 bool LLParser::ParseMDString(
MDString *&Result) {
668 if (ParseStringConstant(Str))
return true;
675 bool LLParser::ParseMDNodeID(
MDNode *&Result) {
679 if (ParseUInt32(MID))
683 if (NumberedMetadata.count(MID)) {
684 Result = NumberedMetadata[MID];
689 auto &FwdRef = ForwardRefMDNodes[MID];
692 Result = FwdRef.first.
get();
693 NumberedMetadata[MID].reset(Result);
699 bool LLParser::ParseNamedMetadata() {
718 if (ParseDIExpression(N,
false))
727 return ParseToken(
lltok::rbrace,
"expected end of metadata node");
732 bool LLParser::ParseStandaloneMetadata() {
735 unsigned MetadataID = 0;
738 if (ParseUInt32(MetadataID) ||
744 return TokError(
"unexpected type in metadata definition");
748 if (ParseSpecializedMDNode(Init, IsDistinct))
751 ParseMDTuple(Init, IsDistinct))
755 auto FI = ForwardRefMDNodes.find(MetadataID);
756 if (FI != ForwardRefMDNodes.end()) {
757 FI->second.first->replaceAllUsesWith(Init);
758 ForwardRefMDNodes.erase(FI);
760 assert(NumberedMetadata[MetadataID] == Init &&
"Tracking VH didn't work");
762 if (NumberedMetadata.count(MetadataID))
763 return TokError(
"Metadata id is already used");
764 NumberedMetadata[MetadataID].reset(Init);
771 bool LLParser::SkipModuleSummaryEntry() {
779 "Expected 'gv', 'module', or 'typeid' at the start of summary entry");
781 if (ParseToken(
lltok::colon,
"expected ':' at start of summary entry") ||
782 ParseToken(
lltok::lparen,
"expected '(' at start of summary entry"))
786 unsigned NumOpenParen = 1;
796 return TokError(
"found end of file while parsing summary entry");
802 }
while (NumOpenParen > 0);
808 bool LLParser::ParseSummaryEntry() {
822 return SkipModuleSummaryEntry();
827 result = ParseGVEntry(SummaryID);
830 result = ParseModuleEntry(SummaryID);
833 result = ParseTypeIdEntry(SummaryID);
836 result = ParseTypeIdCompatibleVtableEntry(SummaryID);
839 result =
Error(Lex.
getLoc(),
"unexpected summary kind");
872 bool LLParser::parseIndirectSymbol(
const std::string &
Name,
LocTy NameLoc,
873 unsigned L,
unsigned Visibility,
874 unsigned DLLStorageClass,
bool DSOLocal,
889 return Error(NameLoc,
"invalid linkage type for alias");
892 return Error(NameLoc,
893 "symbol with local linkage must have default visibility");
898 ParseToken(
lltok::comma,
"expected comma after alias or ifunc's type"))
907 if (ParseGlobalTypeAndValue(Aliasee))
915 return Error(AliaseeLoc,
"invalid aliasee");
922 return Error(AliaseeLoc,
"An alias or ifunc must have pointer type");
923 unsigned AddrSpace = PTy->getAddressSpace();
925 if (IsAlias && Ty != PTy->getElementType())
928 "explicit pointee type doesn't match operand's pointee type");
930 if (!IsAlias && !PTy->getElementType()->isFunctionTy())
933 "explicit pointee type should be a function type");
942 if (!ForwardRefVals.erase(
Name))
943 return Error(NameLoc,
"redefinition of global '@" +
Name +
"'");
946 auto I = ForwardRefValIDs.find(NumberedVals.size());
947 if (
I != ForwardRefValIDs.end()) {
948 GVal =
I->second.first;
949 ForwardRefValIDs.erase(
I);
954 std::unique_ptr<GlobalIndirectSymbol> GA;
963 GA->setThreadLocalMode(
TLM);
966 GA->setUnnamedAddr(UnnamedAddr);
980 return TokError(
"unknown alias or ifunc property!");
985 NumberedVals.push_back(GA.get());
989 if (GVal->
getType() != GA->getType())
992 "forward reference and definition of alias have different types");
1005 assert(GA->getName() ==
Name &&
"Should not be a name conflict!");
1026 bool LLParser::ParseGlobal(
const std::string &
Name,
LocTy NameLoc,
1027 unsigned Linkage,
bool HasLinkage,
1028 unsigned Visibility,
unsigned DLLStorageClass,
1032 return Error(NameLoc,
1033 "symbol with local linkage must have default visibility");
1036 bool IsConstant, IsExternallyInitialized;
1037 LocTy IsExternallyInitializedLoc;
1041 if (ParseOptionalAddrSpace(AddrSpace) ||
1043 IsExternallyInitialized,
1044 &IsExternallyInitializedLoc) ||
1045 ParseGlobalType(IsConstant) ||
1046 ParseType(Ty, TyLoc))
1055 if (ParseGlobalValue(Ty, Init))
1060 return Error(TyLoc,
"invalid type for global variable");
1065 if (!
Name.empty()) {
1068 if (!ForwardRefVals.erase(
Name))
1069 return Error(NameLoc,
"redefinition of global '@" +
Name +
"'");
1072 auto I = ForwardRefValIDs.find(NumberedVals.size());
1073 if (
I != ForwardRefValIDs.end()) {
1074 GVal =
I->second.first;
1075 ForwardRefValIDs.erase(
I);
1087 "forward reference and definition of global have different types");
1089 GV = cast<GlobalVariable>(GVal);
1096 NumberedVals.push_back(GV);
1126 if (ParseOptionalAlignment(Alignment))
return true;
1129 if (ParseGlobalObjectMetadataAttachment(*GV))
1133 if (parseOptionalComdat(
Name, C))
1138 return TokError(
"unknown global variable property!");
1144 std::vector<unsigned> FwdRefAttrGrps;
1145 if (ParseFnAttributeValuePairs(Attrs, FwdRefAttrGrps,
false, BuiltinLoc))
1149 ForwardRefAttrGroups[GV] = FwdRefAttrGrps;
1157 bool LLParser::ParseUnnamedAttrGrp() {
1163 return TokError(
"expected attribute group id");
1166 std::vector<unsigned> unused;
1172 ParseFnAttributeValuePairs(NumberedAttrBuilders[VarID], unused,
true,
1174 ParseToken(
lltok::rbrace,
"expected end of attribute group"))
1177 if (!NumberedAttrBuilders[VarID].hasAttributes())
1178 return Error(AttrGrpLoc,
"attribute group has no attributes");
1185 bool LLParser::ParseFnAttributeValuePairs(
AttrBuilder &
B,
1186 std::vector<unsigned> &FwdRefAttrGrps,
1187 bool inAttrGrp,
LocTy &BuiltinLoc) {
1188 bool HaveError =
false;
1195 BuiltinLoc = Lex.
getLoc();
1198 if (!inAttrGrp)
return HaveError;
1199 return Error(Lex.
getLoc(),
"unterminated attribute group");
1211 "cannot have an attribute group reference in an attribute group");
1214 if (inAttrGrp)
break;
1217 FwdRefAttrGrps.push_back(AttrGrpNum);
1222 if (ParseStringAttribute(B))
1236 if (ParseToken(
lltok::equal,
"expected '=' here") || ParseUInt32(Value))
1238 Alignment =
Align(Value);
1240 if (ParseOptionalAlignment(Alignment))
1251 ParseUInt32(Alignment))
1254 if (ParseOptionalStackAlignment(Alignment))
1261 unsigned ElemSizeArg;
1264 if (parseAllocSizeArguments(ElemSizeArg, NumElemsArg))
1277 B.
addAttribute(Attribute::InaccessibleMemOrArgMemOnly);
break;
1335 "invalid use of attribute on a function");
1352 "invalid use of parameter-only attribute on a function");
1365 const std::string &
Name) {
1377 Value *Val,
bool IsCall) {
1381 Type *SuggestedTy = Ty;
1382 if (IsCall && isa<PointerType>(Ty)) {
1385 SuggestedTy = TyInProgAS;
1386 if (Val->
getType() == TyInProgAS)
1390 Error(Loc,
"'" + Name +
"' is not a basic block");
1392 Error(Loc,
"'" + Name +
"' defined with type '" +
1401 GlobalValue *LLParser::GetGlobalVal(
const std::string &Name,
Type *Ty,
1402 LocTy Loc,
bool IsCall) {
1405 Error(Loc,
"global variable reference must have pointer type");
1416 auto I = ForwardRefVals.find(Name);
1417 if (
I != ForwardRefVals.end())
1418 Val =
I->second.first;
1423 return cast_or_null<GlobalValue>(
1424 checkValidVariableType(Loc,
"@" + Name, Ty, Val, IsCall));
1428 ForwardRefVals[
Name] = std::make_pair(FwdVal, Loc);
1436 Error(Loc,
"global variable reference must have pointer type");
1440 GlobalValue *Val = ID < NumberedVals.size() ? NumberedVals[
ID] :
nullptr;
1445 auto I = ForwardRefValIDs.find(ID);
1446 if (
I != ForwardRefValIDs.end())
1447 Val =
I->second.first;
1452 return cast_or_null<GlobalValue>(
1453 checkValidVariableType(Loc,
"@" +
Twine(ID), Ty, Val, IsCall));
1457 ForwardRefValIDs[
ID] = std::make_pair(FwdVal, Loc);
1465 Comdat *LLParser::getComdat(
const std::string &Name,
LocTy Loc) {
1469 if (I != ComdatSymTab.
end())
1474 ForwardRefComdats[
Name] = Loc;
1484 bool LLParser::ParseToken(
lltok::Kind T,
const char *ErrMsg) {
1486 return TokError(ErrMsg);
1493 bool LLParser::ParseStringConstant(std::string &Result) {
1495 return TokError(
"expected string constant");
1503 bool LLParser::ParseUInt32(
uint32_t &Val) {
1505 return TokError(
"expected integer");
1507 if (Val64 !=
unsigned(Val64))
1508 return TokError(
"expected 32-bit integer (too large)");
1516 bool LLParser::ParseUInt64(uint64_t &Val) {
1518 return TokError(
"expected integer");
1531 return TokError(
"expected localdynamic, initialexec or localexec");
1559 return ParseTLSModel(TLM) ||
1560 ParseToken(
lltok::rparen,
"expected ')' after thread local model");
1568 bool LLParser::ParseOptionalAddrSpace(
unsigned &AddrSpace,
unsigned DefaultAS) {
1572 return ParseToken(
lltok::lparen,
"expected '(' in address space") ||
1573 ParseUInt32(AddrSpace) ||
1580 bool LLParser::ParseStringAttribute(
AttrBuilder &B) {
1584 if (EatIfPresent(
lltok::equal) && ParseStringConstant(Val))
1591 bool LLParser::ParseOptionalParamAttrs(
AttrBuilder &B) {
1592 bool HaveError =
false;
1602 if (ParseStringAttribute(B))
1608 if (ParseOptionalAlignment(Alignment))
1615 if (ParseByValWithOptionalType(Ty))
1686 HaveError |=
Error(Lex.
getLoc(),
"invalid use of function-only attribute");
1695 bool LLParser::ParseOptionalReturnAttrs(
AttrBuilder &B) {
1696 bool HaveError =
false;
1706 if (ParseStringAttribute(B))
1726 if (ParseOptionalAlignment(Alignment))
1747 HaveError |=
Error(Lex.
getLoc(),
"invalid use of parameter-only attribute");
1785 HaveError |=
Error(Lex.
getLoc(),
"invalid use of function-only attribute");
1790 HaveError |=
Error(Lex.
getLoc(),
"invalid use of attribute on return type");
1841 bool LLParser::ParseOptionalLinkage(
unsigned &Res,
bool &HasLinkage,
1842 unsigned &Visibility,
1843 unsigned &DLLStorageClass,
1848 ParseOptionalDSOLocal(DSOLocal);
1849 ParseOptionalVisibility(Visibility);
1850 ParseOptionalDLLStorageClass(DLLStorageClass);
1853 return Error(Lex.
getLoc(),
"dso_location and DLL-StorageClass mismatch");
1859 void LLParser::ParseOptionalDSOLocal(
bool &DSOLocal) {
1881 void LLParser::ParseOptionalVisibility(
unsigned &Res) {
1904 void LLParser::ParseOptionalDLLStorageClass(
unsigned &Res) {
1965 bool LLParser::ParseOptionalCallingConv(
unsigned &CC) {
2015 return ParseUInt32(CC);
2025 bool LLParser::ParseMetadataAttachment(
unsigned &
Kind,
MDNode *&MD) {
2032 return ParseMDNode(MD);
2037 bool LLParser::ParseInstructionMetadata(
Instruction &Inst) {
2040 return TokError(
"expected metadata after comma");
2044 if (ParseMetadataAttachment(MDK, N))
2048 if (MDK == LLVMContext::MD_tbaa)
2049 InstsWithTBAATag.push_back(&Inst);
2058 bool LLParser::ParseGlobalObjectMetadataAttachment(
GlobalObject &GO) {
2061 if (ParseMetadataAttachment(MDK, N))
2070 bool LLParser::ParseOptionalFunctionMetadata(
Function &
F) {
2072 if (ParseGlobalObjectMetadataAttachment(F))
2080 bool LLParser::ParseOptionalAlignment(
MaybeAlign &Alignment) {
2086 if (ParseUInt32(Value))
2089 return Error(AlignLoc,
"alignment is not a power of two");
2091 return Error(AlignLoc,
"huge alignments are not supported yet");
2092 Alignment =
Align(Value);
2101 bool LLParser::ParseOptionalDerefAttrBytes(
lltok::Kind AttrKind,
2108 if (!EatIfPresent(AttrKind))
2112 return Error(ParenLoc,
"expected '('");
2114 if (ParseUInt64(Bytes))
return true;
2117 return Error(ParenLoc,
"expected ')'");
2119 return Error(DerefLoc,
"dereferenceable bytes must be non-zero");
2129 bool LLParser::ParseOptionalCommaAlign(
MaybeAlign &Alignment,
2130 bool &AteExtraComma) {
2131 AteExtraComma =
false;
2135 AteExtraComma =
true;
2140 return Error(Lex.
getLoc(),
"expected metadata or 'align'");
2142 if (ParseOptionalAlignment(Alignment))
return true;
2154 bool LLParser::ParseOptionalCommaAddrSpace(
unsigned &AddrSpace,
2156 bool &AteExtraComma) {
2157 AteExtraComma =
false;
2161 AteExtraComma =
true;
2167 return Error(Lex.
getLoc(),
"expected metadata or 'addrspace'");
2169 if (ParseOptionalAddrSpace(AddrSpace))
2176 bool LLParser::parseAllocSizeArguments(
unsigned &BaseSizeArg,
2180 auto StartParen = Lex.
getLoc();
2182 return Error(StartParen,
"expected '('");
2184 if (ParseUInt32(BaseSizeArg))
2188 auto HowManyAt = Lex.
getLoc();
2190 if (ParseUInt32(HowMany))
2192 if (HowMany == BaseSizeArg)
2193 return Error(HowManyAt,
2194 "'allocsize' indices can't refer to the same parameter");
2195 HowManyArg = HowMany;
2199 auto EndParen = Lex.
getLoc();
2201 return Error(EndParen,
"expected ')'");
2215 return ParseScope(SSID) || ParseOrdering(Ordering);
2225 auto StartParenAt = Lex.
getLoc();
2227 return Error(StartParenAt,
"Expected '(' in syncscope");
2230 auto SSNAt = Lex.
getLoc();
2231 if (ParseStringConstant(SSN))
2232 return Error(SSNAt,
"Expected synchronization scope name");
2234 auto EndParenAt = Lex.
getLoc();
2236 return Error(EndParenAt,
"Expected ')' in syncscope");
2250 default:
return TokError(
"Expected ordering on atomic instruction");
2269 bool LLParser::ParseOptionalStackAlignment(
unsigned &Alignment) {
2275 return Error(ParenLoc,
"expected '('");
2277 if (ParseUInt32(Alignment))
return true;
2280 return Error(ParenLoc,
"expected ')'");
2282 return Error(AlignLoc,
"stack alignment is not a power of two");
2296 bool &AteExtraComma) {
2297 AteExtraComma =
false;
2300 return TokError(
"expected ',' as start of index list");
2304 if (Indices.
empty())
return TokError(
"expected index");
2305 AteExtraComma =
true;
2309 if (ParseUInt32(Idx))
return true;
2321 bool LLParser::ParseType(
Type *&Result,
const Twine &Msg,
bool AllowVoid) {
2325 return TokError(Msg);
2333 if (ParseAnonStructType(Result,
false))
2339 if (ParseArrayVectorType(Result,
false))
2346 if (ParseAnonStructType(Result,
true) ||
2347 ParseToken(
lltok::greater,
"expected '>' at end of packed struct"))
2349 }
else if (ParseArrayVectorType(Result,
true))
2360 Entry.second = Lex.
getLoc();
2362 Result = Entry.first;
2375 Entry.second = Lex.
getLoc();
2377 Result = Entry.first;
2388 if (!AllowVoid && Result->
isVoidTy())
2389 return Error(TypeLoc,
"void type only allowed for function results");
2395 return TokError(
"basic block pointers are invalid");
2397 return TokError(
"pointers to void are invalid - use i8* instead");
2399 return TokError(
"pointer to this type is invalid");
2407 return TokError(
"basic block pointers are invalid");
2409 return TokError(
"pointers to void are invalid; use i8* instead");
2411 return TokError(
"pointer to this type is invalid");
2413 if (ParseOptionalAddrSpace(AddrSpace) ||
2414 ParseToken(
lltok::star,
"expected '*' in address space"))
2423 if (ParseFunctionType(Result))
2436 PerFunctionState &PFS,
bool IsMustTailCall,
2437 bool InVarArgsFunc) {
2443 if (!ArgList.
empty() &&
2444 ParseToken(
lltok::comma,
"expected ',' in argument list"))
2449 const char *Msg =
"unexpected ellipsis in argument list for ";
2450 if (!IsMustTailCall)
2451 return TokError(
Twine(Msg) +
"non-musttail call");
2453 return TokError(
Twine(Msg) +
"musttail call in non-varargs function");
2455 return ParseToken(
lltok::rparen,
"expected ')' at end of argument list");
2460 Type *ArgTy =
nullptr;
2463 if (ParseType(ArgTy, ArgLoc))
2467 if (ParseMetadataAsValue(V, PFS))
2471 if (ParseOptionalParamAttrs(ArgAttrs) || ParseValue(ArgTy, V, PFS))
2478 if (IsMustTailCall && InVarArgsFunc)
2479 return TokError(
"expected '...' at end of argument list for musttail call " 2480 "in varargs function");
2489 bool LLParser::ParseByValWithOptionalType(
Type *&Result) {
2495 if (ParseType(Result))
2511 bool LLParser::ParseOptionalOperandBundles(
2519 if (!BundleList.
empty() &&
2520 ParseToken(
lltok::comma,
"expected ',' in input list"))
2524 if (ParseStringConstant(Tag))
2527 if (ParseToken(
lltok::lparen,
"expected '(' in operand bundle"))
2530 std::vector<Value *> Inputs;
2533 if (!Inputs.empty() &&
2534 ParseToken(
lltok::comma,
"expected ',' in input list"))
2538 Value *Input =
nullptr;
2539 if (ParseType(Ty) || ParseValue(Ty, Input, PFS))
2541 Inputs.push_back(Input);
2544 BundleList.
emplace_back(std::move(Tag), std::move(Inputs));
2549 if (BundleList.
empty())
2550 return Error(BeginLoc,
"operand bundle set must not be empty");
2567 unsigned CurValID = 0;
2579 Type *ArgTy =
nullptr;
2583 if (ParseType(ArgTy) ||
2584 ParseOptionalParamAttrs(Attrs))
return true;
2587 return Error(TypeLoc,
"argument can not have void type");
2594 return Error(TypeLoc,
"argument expected to be numbered '%" +
2595 Twine(CurValID) +
"'");
2601 return Error(TypeLoc,
"invalid type for function argument");
2616 if (ParseType(ArgTy) || ParseOptionalParamAttrs(Attrs))
return true;
2619 return Error(TypeLoc,
"argument can not have void type");
2627 return Error(TypeLoc,
"argument expected to be numbered '%" +
2628 Twine(CurValID) +
"'");
2636 return Error(TypeLoc,
"invalid type for function argument");
2644 return ParseToken(
lltok::rparen,
"expected ')' at end of argument list");
2649 bool LLParser::ParseFunctionType(
Type *&Result) {
2653 return TokError(
"invalid function return type");
2657 if (ParseArgumentList(ArgList, isVarArg))
2661 for (
unsigned i = 0,
e = ArgList.
size(); i !=
e; ++i) {
2662 if (!ArgList[i].Name.empty())
2663 return Error(ArgList[i].Loc,
"argument name invalid in function type");
2664 if (ArgList[i].
Attrs.hasAttributes())
2665 return Error(ArgList[i].Loc,
2666 "argument attributes invalid in function type");
2670 for (
unsigned i = 0,
e = ArgList.
size(); i !=
e; ++i)
2679 bool LLParser::ParseAnonStructType(
Type *&Result,
bool Packed) {
2681 if (ParseStructBody(Elts))
return true;
2688 bool LLParser::ParseStructDefinition(
SMLoc TypeLoc,
StringRef Name,
2689 std::pair<Type*, LocTy> &
Entry,
2692 if (Entry.first && !Entry.second.isValid())
2693 return Error(TypeLoc,
"redefinition of type");
2699 Entry.second =
SMLoc();
2704 ResultTy = Entry.first;
2716 return Error(TypeLoc,
"forward references to non-struct type");
2720 return ParseArrayVectorType(ResultTy,
true);
2721 return ParseType(ResultTy);
2725 Entry.second =
SMLoc();
2731 StructType *STy = cast<StructType>(Entry.first);
2734 if (ParseStructBody(Body) ||
2735 (isPacked && ParseToken(
lltok::greater,
"expected '>' in packed struct")))
2759 if (ParseType(Ty))
return true;
2763 return Error(EltTyLoc,
"invalid element type for struct");
2767 if (ParseType(Ty))
return true;
2770 return Error(EltTyLoc,
"invalid element type for struct");
2775 return ParseToken(
lltok::rbrace,
"expected '}' at end of struct");
2784 bool LLParser::ParseArrayVectorType(
Type *&Result,
bool isVector) {
2785 bool Scalable =
false;
2789 if (ParseToken(
lltok::kw_x,
"expected 'x' after vscale"))
2797 return TokError(
"expected number in address space");
2803 if (ParseToken(
lltok::kw_x,
"expected 'x' after element count"))
2807 Type *EltTy =
nullptr;
2808 if (ParseType(EltTy))
return true;
2811 "expected end of sequential type"))
2816 return Error(SizeLoc,
"zero element vector is illegal");
2817 if ((
unsigned)Size != Size)
2818 return Error(SizeLoc,
"size too large for vector");
2820 return Error(TypeLoc,
"invalid vector element type");
2824 return Error(TypeLoc,
"invalid array element type");
2841 NumberedVals.push_back(&A);
2844 LLParser::PerFunctionState::~PerFunctionState() {
2847 for (
const auto &
P : ForwardRefVals) {
2848 if (isa<BasicBlock>(
P.second.first))
2850 P.second.first->replaceAllUsesWith(
2852 P.second.first->deleteValue();
2855 for (
const auto &
P : ForwardRefValIDs) {
2856 if (isa<BasicBlock>(
P.second.first))
2858 P.second.first->replaceAllUsesWith(
2860 P.second.first->deleteValue();
2864 bool LLParser::PerFunctionState::FinishFunction() {
2865 if (!ForwardRefVals.empty())
2866 return P.Error(ForwardRefVals.begin()->second.second,
2867 "use of undefined value '%" + ForwardRefVals.begin()->first +
2869 if (!ForwardRefValIDs.empty())
2870 return P.Error(ForwardRefValIDs.begin()->second.second,
2871 "use of undefined value '%" +
2872 Twine(ForwardRefValIDs.begin()->first) +
"'");
2879 Value *LLParser::PerFunctionState::GetVal(
const std::string &Name,
Type *Ty,
2880 LocTy Loc,
bool IsCall) {
2882 Value *Val =
F.getValueSymbolTable()->lookup(Name);
2887 auto I = ForwardRefVals.find(Name);
2888 if (
I != ForwardRefVals.end())
2889 Val =
I->second.first;
2894 return P.checkValidVariableType(Loc,
"%" + Name, Ty, Val, IsCall);
2898 P.Error(Loc,
"invalid use of a non-first-class type");
2910 ForwardRefVals[
Name] = std::make_pair(FwdVal, Loc);
2914 Value *LLParser::PerFunctionState::GetVal(
unsigned ID,
Type *Ty,
LocTy Loc,
2917 Value *Val = ID < NumberedVals.size() ? NumberedVals[
ID] :
nullptr;
2922 auto I = ForwardRefValIDs.find(ID);
2923 if (
I != ForwardRefValIDs.end())
2924 Val =
I->second.first;
2929 return P.checkValidVariableType(Loc,
"%" +
Twine(ID), Ty, Val, IsCall);
2932 P.Error(Loc,
"invalid use of a non-first-class type");
2944 ForwardRefValIDs[
ID] = std::make_pair(FwdVal, Loc);
2950 bool LLParser::PerFunctionState::SetInstName(
int NameID,
2951 const std::string &NameStr,
2955 if (NameID != -1 || !NameStr.empty())
2956 return P.Error(NameLoc,
"instructions returning void cannot have a name");
2962 if (NameStr.empty()) {
2965 NameID = NumberedVals.size();
2967 if (
unsigned(NameID) != NumberedVals.size())
2968 return P.Error(NameLoc,
"instruction expected to be numbered '%" +
2969 Twine(NumberedVals.size()) +
"'");
2971 auto FI = ForwardRefValIDs.find(NameID);
2972 if (FI != ForwardRefValIDs.end()) {
2973 Value *Sentinel = FI->second.first;
2975 return P.Error(NameLoc,
"instruction forward referenced with type '" +
2980 ForwardRefValIDs.erase(FI);
2983 NumberedVals.push_back(Inst);
2988 auto FI = ForwardRefVals.find(NameStr);
2989 if (FI != ForwardRefVals.end()) {
2990 Value *Sentinel = FI->second.first;
2992 return P.Error(NameLoc,
"instruction forward referenced with type '" +
2997 ForwardRefVals.erase(FI);
3003 if (Inst->
getName() != NameStr)
3004 return P.Error(NameLoc,
"multiple definition of local value named '" +
3011 BasicBlock *LLParser::PerFunctionState::GetBB(
const std::string &Name,
3013 return dyn_cast_or_null<BasicBlock>(
3017 BasicBlock *LLParser::PerFunctionState::GetBB(
unsigned ID,
LocTy Loc) {
3018 return dyn_cast_or_null<BasicBlock>(
3025 BasicBlock *LLParser::PerFunctionState::DefineBB(
const std::string &Name,
3026 int NameID,
LocTy Loc) {
3029 if (NameID != -1 &&
unsigned(NameID) != NumberedVals.size()) {
3030 P.Error(Loc,
"label expected to be numbered '" +
3031 Twine(NumberedVals.size()) +
"'");
3034 BB = GetBB(NumberedVals.size(), Loc);
3036 P.Error(Loc,
"unable to create block numbered '" +
3037 Twine(NumberedVals.size()) +
"'");
3041 BB = GetBB(Name, Loc);
3043 P.Error(Loc,
"unable to create block named '" + Name +
"'");
3050 F.getBasicBlockList().splice(
F.end(),
F.getBasicBlockList(), BB);
3054 ForwardRefValIDs.erase(NumberedVals.size());
3055 NumberedVals.push_back(BB);
3058 ForwardRefVals.erase(Name);
3074 bool LLParser::ParseValID(
ValID &ID, PerFunctionState *PFS) {
3077 default:
return TokError(
"expected value token");
3119 if (ParseGlobalValueVector(Elts) ||
3120 ParseToken(
lltok::rbrace,
"expected end of struct constant"))
3126 Elts.
size() *
sizeof(Elts[0]));
3138 if (ParseGlobalValueVector(Elts) ||
3140 ParseToken(
lltok::rbrace,
"expected end of packed struct")) ||
3144 if (isPackedStruct) {
3147 Elts.
size() *
sizeof(Elts[0]));
3154 return Error(ID.
Loc,
"constant vector must not be empty");
3156 if (!Elts[0]->
getType()->isIntegerTy() &&
3157 !Elts[0]->getType()->isFloatingPointTy() &&
3158 !Elts[0]->getType()->isPointerTy())
3159 return Error(FirstEltLoc,
3160 "vector elements must have integer, pointer or floating point type");
3163 for (
unsigned i = 1,
e = Elts.
size(); i !=
e; ++i)
3164 if (Elts[i]->
getType() != Elts[0]->getType())
3165 return Error(FirstEltLoc,
3166 "vector element #" +
Twine(i) +
3177 if (ParseGlobalValueVector(Elts) ||
3189 if (!Elts[0]->
getType()->isFirstClassType())
3190 return Error(FirstEltLoc,
"invalid array element type: " +
3196 for (
unsigned i = 0,
e = Elts.
size(); i !=
e; ++i) {
3197 if (Elts[i]->
getType() != Elts[0]->getType())
3198 return Error(FirstEltLoc,
3199 "array element #" +
Twine(i) +
3218 bool HasSideEffect, AlignStack, AsmDialect;
3223 ParseStringConstant(ID.
StrVal) ||
3224 ParseToken(
lltok::comma,
"expected comma in inline asm expression") ||
3229 (
unsigned(AsmDialect)<<2);
3240 if (ParseToken(
lltok::lparen,
"expected '(' in block address expression") ||
3242 ParseToken(
lltok::comma,
"expected comma in block address expression")||
3243 ParseValID(Label) ||
3244 ParseToken(
lltok::rparen,
"expected ')' in block address expression"))
3248 return Error(Fn.
Loc,
"expected function name in blockaddress");
3250 return Error(Label.
Loc,
"expected basic block name in blockaddress");
3255 if (Fn.
UIntVal < NumberedVals.size())
3256 GV = NumberedVals[Fn.
UIntVal];
3257 }
else if (!ForwardRefVals.count(Fn.
StrVal)) {
3263 if (!isa<Function>(GV))
3264 return Error(Fn.
Loc,
"expected function name in blockaddress");
3265 F = cast<Function>(GV);
3267 return Error(Fn.
Loc,
"cannot take blockaddress inside a declaration");
3273 ForwardRefBlockAddresses.insert(std::make_pair(
3275 std::map<ValID, GlobalValue *>()))
3276 .first->second.insert(std::make_pair(std::move(Label),
nullptr))
3289 if (BlockAddressPFS && F == &BlockAddressPFS->getFunction()) {
3291 BB = BlockAddressPFS->GetBB(Label.
UIntVal, Label.
Loc);
3293 BB = BlockAddressPFS->GetBB(Label.
StrVal, Label.
Loc);
3295 return Error(Label.
Loc,
"referenced value is not a basic block");
3298 return Error(Label.
Loc,
"cannot take address of numeric label after " 3299 "the function is defined");
3300 BB = dyn_cast_or_null<BasicBlock>(
3303 return Error(Label.
Loc,
"referenced value is not a basic block");
3325 Type *DestTy =
nullptr;
3328 if (ParseToken(
lltok::lparen,
"expected '(' after constantexpr cast") ||
3329 ParseGlobalTypeAndValue(SrcVal) ||
3330 ParseToken(
lltok::kw_to,
"expected 'to' in constantexpr cast") ||
3331 ParseType(DestTy) ||
3332 ParseToken(
lltok::rparen,
"expected ')' at end of constantexpr cast"))
3335 return Error(ID.
Loc,
"invalid cast opcode for cast from '" +
3347 if (ParseToken(
lltok::lparen,
"expected '(' in extractvalue constantexpr")||
3348 ParseGlobalTypeAndValue(Val) ||
3349 ParseIndexList(Indices) ||
3350 ParseToken(
lltok::rparen,
"expected ')' in extractvalue constantexpr"))
3354 return Error(ID.
Loc,
"extractvalue operand must be aggregate type");
3356 return Error(ID.
Loc,
"invalid indices for extractvalue");
3365 if (ParseToken(
lltok::lparen,
"expected '(' in insertvalue constantexpr")||
3366 ParseGlobalTypeAndValue(Val0) ||
3367 ParseToken(
lltok::comma,
"expected comma in insertvalue constantexpr")||
3368 ParseGlobalTypeAndValue(Val1) ||
3369 ParseIndexList(Indices) ||
3370 ParseToken(
lltok::rparen,
"expected ')' in insertvalue constantexpr"))
3373 return Error(ID.
Loc,
"insertvalue operand must be aggregate type");
3377 return Error(ID.
Loc,
"invalid indices for insertvalue");
3378 if (IndexedType != Val1->
getType())
3379 return Error(ID.
Loc,
"insertvalue operand and field disagree in type: '" +
3392 if (ParseCmpPredicate(PredVal, Opc) ||
3393 ParseToken(
lltok::lparen,
"expected '(' in compare constantexpr") ||
3394 ParseGlobalTypeAndValue(Val0) ||
3395 ParseToken(
lltok::comma,
"expected comma in compare constantexpr") ||
3396 ParseGlobalTypeAndValue(Val1) ||
3397 ParseToken(
lltok::rparen,
"expected ')' in compare constantexpr"))
3401 return Error(ID.
Loc,
"compare operands must have the same type");
3405 if (Opc == Instruction::FCmp) {
3407 return Error(ID.
Loc,
"fcmp requires floating point operands");
3410 assert(Opc == Instruction::ICmp &&
"Unexpected opcode for CmpInst!");
3413 return Error(ID.
Loc,
"icmp requires pointer or integer operands");
3425 if (ParseToken(
lltok::lparen,
"expected '(' in unary constantexpr") ||
3426 ParseGlobalTypeAndValue(Val) ||
3427 ParseToken(
lltok::rparen,
"expected ')' in unary constantexpr"))
3432 case Instruction::FNeg:
3434 return Error(ID.
Loc,
"constexpr requires fp operands");
3467 Opc == Instruction::Mul || Opc == Instruction::Shl) {
3475 }
else if (Opc == Instruction::SDiv || Opc == Instruction::UDiv ||
3476 Opc == Instruction::LShr || Opc == Instruction::AShr) {
3480 if (ParseToken(
lltok::lparen,
"expected '(' in binary constantexpr") ||
3481 ParseGlobalTypeAndValue(Val0) ||
3482 ParseToken(
lltok::comma,
"expected comma in binary constantexpr") ||
3483 ParseGlobalTypeAndValue(Val1) ||
3484 ParseToken(
lltok::rparen,
"expected ')' in binary constantexpr"))
3487 return Error(ID.
Loc,
"operands of constexpr must have same type");
3491 case Instruction::Sub:
3492 case Instruction::Mul:
3493 case Instruction::UDiv:
3494 case Instruction::SDiv:
3495 case Instruction::URem:
3496 case Instruction::SRem:
3497 case Instruction::Shl:
3498 case Instruction::AShr:
3499 case Instruction::LShr:
3501 return Error(ID.
Loc,
"constexpr requires integer operands");
3503 case Instruction::FAdd:
3504 case Instruction::FSub:
3505 case Instruction::FMul:
3506 case Instruction::FDiv:
3507 case Instruction::FRem:
3509 return Error(ID.
Loc,
"constexpr requires fp operands");
3530 if (ParseToken(
lltok::lparen,
"expected '(' in logical constantexpr") ||
3531 ParseGlobalTypeAndValue(Val0) ||
3532 ParseToken(
lltok::comma,
"expected comma in logical constantexpr") ||
3533 ParseGlobalTypeAndValue(Val1) ||
3534 ParseToken(
lltok::rparen,
"expected ')' in logical constantexpr"))
3537 return Error(ID.
Loc,
"operands of constexpr must have same type");
3540 "constexpr requires integer or integer vector operands");
3553 bool InBounds =
false;
3557 if (Opc == Instruction::GetElementPtr)
3560 if (ParseToken(
lltok::lparen,
"expected '(' in constantexpr"))
3564 if (Opc == Instruction::GetElementPtr) {
3565 if (ParseType(Ty) ||
3566 ParseToken(
lltok::comma,
"expected comma after getelementptr's type"))
3571 if (ParseGlobalValueVector(
3572 Elts, Opc == Instruction::GetElementPtr ? &InRangeOp :
nullptr) ||
3576 if (Opc == Instruction::GetElementPtr) {
3577 if (Elts.
size() == 0 ||
3578 !Elts[0]->getType()->isPtrOrPtrVectorTy())
3579 return Error(ID.
Loc,
"base of getelementptr must be a pointer");
3582 auto *BasePointerType = cast<PointerType>(BaseType->
getScalarType());
3583 if (Ty != BasePointerType->getElementType())
3586 "explicit pointee type doesn't match operand's pointee type");
3593 Type *ValTy = Val->getType();
3595 return Error(ID.
Loc,
"getelementptr index must be an integer");
3598 if (GEPWidth && (ValNumEl != GEPWidth))
3601 "getelementptr vector index has a wrong number of elements");
3604 GEPWidth = ValNumEl;
3609 if (!Indices.empty() && !Ty->
isSized(&Visited))
3610 return Error(ID.
Loc,
"base element of getelementptr must be sized");
3613 return Error(ID.
Loc,
"invalid getelementptr indices");
3616 if (*InRangeOp == 0)
3618 "inrange keyword may not appear on pointer operand");
3623 InBounds, InRangeOp);
3625 if (Elts.
size() != 3)
3626 return Error(ID.
Loc,
"expected three operands to select");
3631 }
else if (Opc == Instruction::ShuffleVector) {
3632 if (Elts.
size() != 3)
3633 return Error(ID.
Loc,
"expected three operands to shufflevector");
3635 return Error(ID.
Loc,
"invalid operands to shufflevector");
3638 }
else if (Opc == Instruction::ExtractElement) {
3639 if (Elts.
size() != 2)
3640 return Error(ID.
Loc,
"expected two operands to extractelement");
3642 return Error(ID.
Loc,
"invalid extractelement operands");
3645 assert(Opc == Instruction::InsertElement &&
"Unknown opcode");
3646 if (Elts.
size() != 3)
3647 return Error(ID.
Loc,
"expected three operands to insertelement");
3649 return Error(ID.
Loc,
"invalid insertelement operands");
3668 bool Parsed = ParseValID(ID) ||
3669 ConvertValIDToValue(Ty, ID, V,
nullptr,
false);
3670 if (V && !(C = dyn_cast<Constant>(V)))
3671 return Error(ID.
Loc,
"global values must be constants");
3675 bool LLParser::ParseGlobalTypeAndValue(
Constant *&V) {
3677 return ParseType(Ty) ||
3678 ParseGlobalValue(Ty, V);
3681 bool LLParser::parseOptionalComdat(
StringRef GlobalName,
Comdat *&C) {
3690 return TokError(
"expected comdat variable");
3693 if (ParseToken(
lltok::rparen,
"expected ')' after comdat var"))
3696 if (GlobalName.
empty())
3697 return TokError(
"comdat cannot be unnamed");
3698 C = getComdat(GlobalName, KwLoc);
3718 *InRangeOp = Elts.
size();
3721 if (ParseGlobalTypeAndValue(C))
return true;
3728 bool LLParser::ParseMDTuple(
MDNode *&MD,
bool IsDistinct) {
3730 if (ParseMDNodeVector(Elts))
3741 bool LLParser::ParseMDNode(
MDNode *&
N) {
3743 return ParseSpecializedMDNode(N);
3749 bool LLParser::ParseMDNodeTail(
MDNode *&N) {
3752 return ParseMDTuple(N);
3755 return ParseMDNodeID(N);
3761 template <
class FieldTy>
struct MDFieldImpl {
3762 typedef MDFieldImpl ImplTy;
3766 void assign(FieldTy Val) {
3768 this->Val = std::move(Val);
3771 explicit MDFieldImpl(FieldTy
Default)
3772 : Val(std::move(Default)), Seen(
false) {}
3779 template <
class FieldTypeA,
class FieldTypeB>
struct MDEitherFieldImpl {
3780 typedef MDEitherFieldImpl<FieldTypeA, FieldTypeB> ImplTy;
3791 void assign(FieldTypeA A) {
3793 this->A = std::move(A);
3797 void assign(FieldTypeB B) {
3799 this->B = std::move(B);
3803 explicit MDEitherFieldImpl(FieldTypeA DefaultA, FieldTypeB DefaultB)
3804 : A(std::move(DefaultA)),
B(std::move(DefaultB)), Seen(
false),
3805 WhatIs(IsInvalid) {}
3808 struct MDUnsignedField :
public MDFieldImpl<uint64_t> {
3812 : ImplTy(
Default), Max(Max) {}
3815 struct LineField :
public MDUnsignedField {
3816 LineField() : MDUnsignedField(0, UINT32_MAX) {}
3819 struct ColumnField :
public MDUnsignedField {
3820 ColumnField() : MDUnsignedField(0, UINT16_MAX) {}
3823 struct DwarfTagField :
public MDUnsignedField {
3829 struct DwarfMacinfoTypeField :
public MDUnsignedField {
3835 struct DwarfAttEncodingField :
public MDUnsignedField {
3839 struct DwarfVirtualityField :
public MDUnsignedField {
3843 struct DwarfLangField :
public MDUnsignedField {
3847 struct DwarfCCField :
public MDUnsignedField {
3851 struct EmissionKindField :
public MDUnsignedField {
3855 struct NameTableKindField :
public MDUnsignedField {
3856 NameTableKindField()
3862 struct DIFlagField :
public MDFieldImpl<DINode::DIFlags> {
3863 DIFlagField() : MDFieldImpl(DINode::FlagZero) {}
3866 struct DISPFlagField :
public MDFieldImpl<DISubprogram::DISPFlags> {
3867 DISPFlagField() : MDFieldImpl(DISubprogram::SPFlagZero) {}
3870 struct MDSignedField :
public MDFieldImpl<int64_t> {
3874 MDSignedField(int64_t
Default = 0)
3876 MDSignedField(int64_t
Default, int64_t Min, int64_t Max)
3877 : ImplTy(Default), Min(Min), Max(Max) {}
3880 struct MDBoolField :
public MDFieldImpl<bool> {
3884 struct MDField :
public MDFieldImpl<Metadata *> {
3887 MDField(
bool AllowNull =
true) : ImplTy(
nullptr), AllowNull(AllowNull) {}
3890 struct MDConstant :
public MDFieldImpl<ConstantAsMetadata *> {
3891 MDConstant() : ImplTy(
nullptr) {}
3894 struct MDStringField :
public MDFieldImpl<MDString *> {
3896 MDStringField(
bool AllowEmpty =
true)
3897 : ImplTy(
nullptr), AllowEmpty(AllowEmpty) {}
3900 struct MDFieldList :
public MDFieldImpl<SmallVector<Metadata *, 4>> {
3904 struct ChecksumKindField :
public MDFieldImpl<DIFile::ChecksumKind> {
3908 struct MDSignedOrMDField : MDEitherFieldImpl<MDSignedField, MDField> {
3909 MDSignedOrMDField(int64_t
Default = 0,
bool AllowNull =
true)
3910 : ImplTy(MDSignedField(
Default), MDField(AllowNull)) {}
3912 MDSignedOrMDField(int64_t
Default, int64_t Min, int64_t Max,
3913 bool AllowNull =
true)
3914 : ImplTy(MDSignedField(Default, Min, Max), MDField(AllowNull)) {}
3916 bool isMDSignedField()
const {
return WhatIs == IsTypeA; }
3917 bool isMDField()
const {
return WhatIs == IsTypeB; }
3918 int64_t getMDSignedValue()
const {
3919 assert(isMDSignedField() &&
"Wrong field type");
3922 Metadata *getMDFieldValue()
const {
3923 assert(isMDField() &&
"Wrong field type");
3928 struct MDSignedOrUnsignedField
3929 : MDEitherFieldImpl<MDSignedField, MDUnsignedField> {
3930 MDSignedOrUnsignedField() : ImplTy(MDSignedField(0), MDUnsignedField(0)) {}
3932 bool isMDSignedField()
const {
return WhatIs == IsTypeA; }
3933 bool isMDUnsignedField()
const {
return WhatIs == IsTypeB; }
3934 int64_t getMDSignedValue()
const {
3935 assert(isMDSignedField() &&
"Wrong field type");
3938 uint64_t getMDUnsignedValue()
const {
3939 assert(isMDUnsignedField() &&
"Wrong field type");
3950 MDUnsignedField &Result) {
3951 if (Lex.getKind() !=
lltok::APSInt || Lex.getAPSIntVal().isSigned())
3952 return TokError(
"expected unsigned integer");
3954 auto &U = Lex.getAPSIntVal();
3955 if (U.ugt(Result.Max))
3956 return TokError(
"value for '" + Name +
"' too large, limit is " +
3958 Result.assign(U.getZExtValue());
3959 assert(Result.Val <= Result.Max &&
"Expected value in range");
3965 bool LLParser::ParseMDField(
LocTy Loc,
StringRef Name, LineField &Result) {
3966 return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
3969 bool LLParser::ParseMDField(
LocTy Loc,
StringRef Name, ColumnField &Result) {
3970 return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
3974 bool LLParser::ParseMDField(
LocTy Loc,
StringRef Name, DwarfTagField &Result) {
3976 return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
3979 return TokError(
"expected DWARF tag");
3983 return TokError(
"invalid DWARF tag" +
Twine(
" '") + Lex.getStrVal() +
"'");
3984 assert(Tag <= Result.Max &&
"Expected valid DWARF tag");
3993 DwarfMacinfoTypeField &Result) {
3995 return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
3998 return TokError(
"expected DWARF macinfo type");
4003 "invalid DWARF macinfo type" +
Twine(
" '") + Lex.getStrVal() +
"'");
4004 assert(Macinfo <= Result.Max &&
"Expected valid DWARF macinfo type");
4006 Result.assign(Macinfo);
4013 DwarfVirtualityField &Result) {
4015 return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
4018 return TokError(
"expected DWARF virtuality code");
4022 return TokError(
"invalid DWARF virtuality code" +
Twine(
" '") +
4023 Lex.getStrVal() +
"'");
4024 assert(Virtuality <= Result.Max &&
"Expected valid DWARF virtuality code");
4025 Result.assign(Virtuality);
4031 bool LLParser::ParseMDField(
LocTy Loc,
StringRef Name, DwarfLangField &Result) {
4033 return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
4036 return TokError(
"expected DWARF language");
4040 return TokError(
"invalid DWARF language" +
Twine(
" '") + Lex.getStrVal() +
4042 assert(Lang <= Result.Max &&
"Expected valid DWARF language");
4043 Result.assign(Lang);
4049 bool LLParser::ParseMDField(
LocTy Loc,
StringRef Name, DwarfCCField &Result) {
4051 return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
4054 return TokError(
"expected DWARF calling convention");
4058 return TokError(
"invalid DWARF calling convention" +
Twine(
" '") + Lex.getStrVal() +
4060 assert(CC <= Result.Max &&
"Expected valid DWARF calling convention");
4067 bool LLParser::ParseMDField(
LocTy Loc,
StringRef Name, EmissionKindField &Result) {
4069 return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
4072 return TokError(
"expected emission kind");
4076 return TokError(
"invalid emission kind" +
Twine(
" '") + Lex.getStrVal() +
4078 assert(*
Kind <= Result.Max &&
"Expected valid emission kind");
4079 Result.assign(*
Kind);
4086 NameTableKindField &Result) {
4088 return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
4091 return TokError(
"expected nameTable kind");
4095 return TokError(
"invalid nameTable kind" +
Twine(
" '") + Lex.getStrVal() +
4097 assert(((
unsigned)*
Kind) <= Result.Max &&
"Expected valid nameTable kind");
4098 Result.assign((
unsigned)*Kind);
4105 DwarfAttEncodingField &Result) {
4107 return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
4110 return TokError(
"expected DWARF type attribute encoding");
4114 return TokError(
"invalid DWARF type attribute encoding" +
Twine(
" '") +
4115 Lex.getStrVal() +
"'");
4116 assert(Encoding <= Result.Max &&
"Expected valid DWARF language");
4117 Result.assign(Encoding);
4127 bool LLParser::ParseMDField(
LocTy Loc,
StringRef Name, DIFlagField &Result) {
4131 if (Lex.getKind() ==
lltok::APSInt && !Lex.getAPSIntVal().isSigned()) {
4133 bool Res = ParseUInt32(TempVal);
4139 return TokError(
"expected debug info flag");
4143 return TokError(
Twine(
"invalid debug info flag flag '") +
4144 Lex.getStrVal() +
"'");
4158 Result.assign(Combined);
4167 bool LLParser::ParseMDField(
LocTy Loc,
StringRef Name, DISPFlagField &Result) {
4171 if (Lex.getKind() ==
lltok::APSInt && !Lex.getAPSIntVal().isSigned()) {
4173 bool Res = ParseUInt32(TempVal);
4179 return TokError(
"expected debug info flag");
4183 return TokError(
Twine(
"invalid subprogram debug info flag '") +
4184 Lex.getStrVal() +
"'");
4198 Result.assign(Combined);
4204 MDSignedField &Result) {
4206 return TokError(
"expected signed integer");
4208 auto &S = Lex.getAPSIntVal();
4210 return TokError(
"value for '" + Name +
"' too small, limit is " +
4213 return TokError(
"value for '" + Name +
"' too large, limit is " +
4215 Result.assign(S.getExtValue());
4216 assert(Result.Val >= Result.Min &&
"Expected value in range");
4217 assert(Result.Val <= Result.Max &&
"Expected value in range");
4223 bool LLParser::ParseMDField(
LocTy Loc,
StringRef Name, MDBoolField &Result) {
4224 switch (Lex.getKind()) {
4226 return TokError(
"expected 'true' or 'false'");
4228 Result.assign(
true);
4231 Result.assign(
false);
4239 bool LLParser::ParseMDField(
LocTy Loc,
StringRef Name, MDField &Result) {
4241 if (!Result.AllowNull)
4242 return TokError(
"'" + Name +
"' cannot be null");
4244 Result.assign(
nullptr);
4249 if (ParseMetadata(MD,
nullptr))
4258 MDSignedOrMDField &Result) {
4261 MDSignedField Res = Result.A;
4262 if (!ParseMDField(Loc, Name, Res)) {
4270 MDField Res = Result.B;
4271 if (!ParseMDField(Loc, Name, Res)) {
4281 MDSignedOrUnsignedField &Result) {
4285 if (Lex.getAPSIntVal().isSigned()) {
4286 MDSignedField Res = Result.A;
4287 if (ParseMDField(Loc, Name, Res))
4293 MDUnsignedField Res = Result.B;
4294 if (ParseMDField(Loc, Name, Res))
4301 bool LLParser::ParseMDField(
LocTy Loc,
StringRef Name, MDStringField &Result) {
4302 LocTy ValueLoc = Lex.getLoc();
4304 if (ParseStringConstant(S))
4307 if (!Result.AllowEmpty && S.empty())
4308 return Error(ValueLoc,
"'" + Name +
"' cannot be empty");
4315 bool LLParser::ParseMDField(
LocTy Loc,
StringRef Name, MDFieldList &Result) {
4317 if (ParseMDNodeVector(MDs))
4320 Result.assign(std::move(MDs));
4326 ChecksumKindField &Result) {
4332 "invalid checksum kind" +
Twine(
" '") + Lex.getStrVal() +
"'");
4334 Result.assign(*CSKind);
4341 template <
class ParserTy>
4342 bool LLParser::ParseMDFieldsImplBody(ParserTy
parseField) {
4345 return TokError(
"expected field label here");
4354 template <
class ParserTy>
4355 bool LLParser::ParseMDFieldsImpl(ParserTy
parseField,
LocTy &ClosingLoc) {
4365 ClosingLoc = Lex.getLoc();
4369 template <
class FieldTy>
4370 bool LLParser::ParseMDField(
StringRef Name, FieldTy &Result) {
4372 return TokError(
"field '" + Name +
"' cannot be specified more than once");
4374 LocTy Loc = Lex.getLoc();
4376 return ParseMDField(Loc, Name, Result);
4379 bool LLParser::ParseSpecializedMDNode(
MDNode *&N,
bool IsDistinct) {
4382 #define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \ 4383 if (Lex.getStrVal() == #CLASS) \ 4384 return Parse##CLASS(N, IsDistinct); 4385 #include "llvm/IR/Metadata.def" 4387 return TokError(
"expected metadata type");
4390 #define DECLARE_FIELD(NAME, TYPE, INIT) TYPE NAME INIT 4391 #define NOP_FIELD(NAME, TYPE, INIT) 4392 #define REQUIRE_FIELD(NAME, TYPE, INIT) \ 4394 return Error(ClosingLoc, "missing required field '" #NAME "'"); 4395 #define PARSE_MD_FIELD(NAME, TYPE, DEFAULT) \ 4396 if (Lex.getStrVal() == #NAME) \ 4397 return ParseMDField(#NAME, NAME); 4398 #define PARSE_MD_FIELDS() \ 4399 VISIT_MD_FIELDS(DECLARE_FIELD, DECLARE_FIELD) \ 4402 if (ParseMDFieldsImpl([&]() -> bool { \ 4403 VISIT_MD_FIELDS(PARSE_MD_FIELD, PARSE_MD_FIELD) \ 4404 return TokError(Twine("invalid field '") + Lex.getStrVal() + "'"); \ 4407 VISIT_MD_FIELDS(NOP_FIELD, REQUIRE_FIELD) \ 4409 #define GET_OR_DISTINCT(CLASS, ARGS) \ 4410 (IsDistinct ? CLASS::getDistinct ARGS : CLASS::get ARGS) 4415 bool LLParser::ParseDILocation(
MDNode *&Result,
bool IsDistinct) {
4416 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4417 OPTIONAL(line, LineField, ); \ 4418 OPTIONAL(column, ColumnField, ); \ 4419 REQUIRED(scope, MDField, ( false)); \ 4420 OPTIONAL(inlinedAt, MDField, ); \ 4421 OPTIONAL(isImplicitCode, MDBoolField, (false)); 4423 #undef VISIT_MD_FIELDS 4427 inlinedAt.Val, isImplicitCode.Val));
4433 bool LLParser::ParseGenericDINode(
MDNode *&Result,
bool IsDistinct) {
4434 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4435 REQUIRED(tag, DwarfTagField, ); \ 4436 OPTIONAL(header, MDStringField, ); \ 4437 OPTIONAL(operands, MDFieldList, ); 4439 #undef VISIT_MD_FIELDS 4442 (
Context, tag.Val, header.Val, operands.Val));
4449 bool LLParser::ParseDISubrange(
MDNode *&Result,
bool IsDistinct) {
4450 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4451 REQUIRED(count, MDSignedOrMDField, (-1, -1, INT64_MAX, false)); \ 4452 OPTIONAL(lowerBound, MDSignedField, ); 4454 #undef VISIT_MD_FIELDS 4456 if (
count.isMDSignedField())
4459 else if (
count.isMDField())
4470 bool LLParser::ParseDIEnumerator(
MDNode *&Result,
bool IsDistinct) {
4471 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4472 REQUIRED(name, MDStringField, ); \ 4473 REQUIRED(value, MDSignedOrUnsignedField, ); \ 4474 OPTIONAL(isUnsigned, MDBoolField, (false)); 4476 #undef VISIT_MD_FIELDS 4478 if (isUnsigned.Val && value.isMDSignedField())
4479 return TokError(
"unsigned enumerator with negative value");
4481 int64_t
Value = value.isMDSignedField()
4482 ? value.getMDSignedValue()
4483 :
static_cast<int64_t
>(value.getMDUnsignedValue());
4493 bool LLParser::ParseDIBasicType(
MDNode *&Result,
bool IsDistinct) {
4494 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4495 OPTIONAL(tag, DwarfTagField, (dwarf::DW_TAG_base_type)); \ 4496 OPTIONAL(name, MDStringField, ); \ 4497 OPTIONAL(size, MDUnsignedField, (0, UINT64_MAX)); \ 4498 OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); \ 4499 OPTIONAL(encoding, DwarfAttEncodingField, ); \ 4500 OPTIONAL(flags, DIFlagField, ); 4502 #undef VISIT_MD_FIELDS 4505 align.Val, encoding.Val, flags.Val));
4514 bool LLParser::ParseDIDerivedType(
MDNode *&Result,
bool IsDistinct) {
4515 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4516 REQUIRED(tag, DwarfTagField, ); \ 4517 OPTIONAL(name, MDStringField, ); \ 4518 OPTIONAL(file, MDField, ); \ 4519 OPTIONAL(line, LineField, ); \ 4520 OPTIONAL(scope, MDField, ); \ 4521 REQUIRED(baseType, MDField, ); \ 4522 OPTIONAL(size, MDUnsignedField, (0, UINT64_MAX)); \ 4523 OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); \ 4524 OPTIONAL(offset, MDUnsignedField, (0, UINT64_MAX)); \ 4525 OPTIONAL(flags, DIFlagField, ); \ 4526 OPTIONAL(extraData, MDField, ); \ 4527 OPTIONAL(dwarfAddressSpace, MDUnsignedField, (UINT32_MAX, UINT32_MAX)); 4529 #undef VISIT_MD_FIELDS 4532 if (dwarfAddressSpace.Val != UINT32_MAX)
4533 DWARFAddressSpace = dwarfAddressSpace.Val;
4537 scope.Val, baseType.Val,
size.Val, align.Val,
4538 offset.Val, DWARFAddressSpace, flags.Val,
4543 bool LLParser::ParseDICompositeType(
MDNode *&Result,
bool IsDistinct) {
4544 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4545 REQUIRED(tag, DwarfTagField, ); \ 4546 OPTIONAL(name, MDStringField, ); \ 4547 OPTIONAL(file, MDField, ); \ 4548 OPTIONAL(line, LineField, ); \ 4549 OPTIONAL(scope, MDField, ); \ 4550 OPTIONAL(baseType, MDField, ); \ 4551 OPTIONAL(size, MDUnsignedField, (0, UINT64_MAX)); \ 4552 OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); \ 4553 OPTIONAL(offset, MDUnsignedField, (0, UINT64_MAX)); \ 4554 OPTIONAL(flags, DIFlagField, ); \ 4555 OPTIONAL(elements, MDField, ); \ 4556 OPTIONAL(runtimeLang, DwarfLangField, ); \ 4557 OPTIONAL(vtableHolder, MDField, ); \ 4558 OPTIONAL(templateParams, MDField, ); \ 4559 OPTIONAL(identifier, MDStringField, ); \ 4560 OPTIONAL(discriminator, MDField, ); 4562 #undef VISIT_MD_FIELDS 4568 scope.Val, baseType.Val,
size.Val, align.Val, offset.Val, flags.Val,
4569 elements.Val, runtimeLang.Val, vtableHolder.Val,
4570 templateParams.Val, discriminator.Val)) {
4579 (
Context, tag.Val,
name.Val,
file.Val, line.Val, scope.Val, baseType.Val,
4580 size.Val, align.Val, offset.Val, flags.Val, elements.Val,
4581 runtimeLang.Val, vtableHolder.Val, templateParams.Val, identifier.Val,
4582 discriminator.Val));
4586 bool LLParser::ParseDISubroutineType(
MDNode *&Result,
bool IsDistinct) {
4587 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4588 OPTIONAL(flags, DIFlagField, ); \ 4589 OPTIONAL(cc, DwarfCCField, ); \ 4590 REQUIRED(types, MDField, ); 4592 #undef VISIT_MD_FIELDS 4595 (
Context, flags.Val, cc.Val, types.Val));
4604 bool LLParser::ParseDIFile(
MDNode *&Result,
bool IsDistinct) {
4608 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4609 REQUIRED(filename, MDStringField, ); \ 4610 REQUIRED(directory, MDStringField, ); \ 4611 OPTIONAL(checksumkind, ChecksumKindField, (DIFile::CSK_MD5)); \ 4612 OPTIONAL(checksum, MDStringField, ); \ 4613 OPTIONAL(source, MDStringField, ); 4615 #undef VISIT_MD_FIELDS 4618 if (checksumkind.Seen && checksum.Seen)
4619 OptChecksum.
emplace(checksumkind.Val, checksum.Val);
4620 else if (checksumkind.Seen || checksum.Seen)
4621 return Lex.Error(
"'checksumkind' and 'checksum' must be provided together");
4625 OptSource = source.Val;
4627 OptChecksum, OptSource));
4637 bool LLParser::ParseDICompileUnit(
MDNode *&Result,
bool IsDistinct) {
4639 return Lex.Error(
"missing 'distinct', required for !DICompileUnit");
4641 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4642 REQUIRED(language, DwarfLangField, ); \ 4643 REQUIRED(file, MDField, ( false)); \ 4644 OPTIONAL(producer, MDStringField, ); \ 4645 OPTIONAL(isOptimized, MDBoolField, ); \ 4646 OPTIONAL(flags, MDStringField, ); \ 4647 OPTIONAL(runtimeVersion, MDUnsignedField, (0, UINT32_MAX)); \ 4648 OPTIONAL(splitDebugFilename, MDStringField, ); \ 4649 OPTIONAL(emissionKind, EmissionKindField, ); \ 4650 OPTIONAL(enums, MDField, ); \ 4651 OPTIONAL(retainedTypes, MDField, ); \ 4652 OPTIONAL(globals, MDField, ); \ 4653 OPTIONAL(imports, MDField, ); \ 4654 OPTIONAL(macros, MDField, ); \ 4655 OPTIONAL(dwoId, MDUnsignedField, ); \ 4656 OPTIONAL(splitDebugInlining, MDBoolField, = true); \ 4657 OPTIONAL(debugInfoForProfiling, MDBoolField, = false); \ 4658 OPTIONAL(nameTableKind, NameTableKindField, ); \ 4659 OPTIONAL(debugBaseAddress, MDBoolField, = false); 4661 #undef VISIT_MD_FIELDS 4664 Context, language.Val,
file.Val, producer.Val, isOptimized.Val, flags.Val,
4665 runtimeVersion.Val, splitDebugFilename.Val, emissionKind.Val, enums.Val,
4666 retainedTypes.Val,
globals.Val, imports.Val, macros.Val, dwoId.Val,
4667 splitDebugInlining.Val, debugInfoForProfiling.Val, nameTableKind.Val,
4668 debugBaseAddress.Val);
4680 bool LLParser::ParseDISubprogram(
MDNode *&Result,
bool IsDistinct) {
4681 auto Loc = Lex.getLoc();
4682 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4683 OPTIONAL(scope, MDField, ); \ 4684 OPTIONAL(name, MDStringField, ); \ 4685 OPTIONAL(linkageName, MDStringField, ); \ 4686 OPTIONAL(file, MDField, ); \ 4687 OPTIONAL(line, LineField, ); \ 4688 OPTIONAL(type, MDField, ); \ 4689 OPTIONAL(isLocal, MDBoolField, ); \ 4690 OPTIONAL(isDefinition, MDBoolField, (true)); \ 4691 OPTIONAL(scopeLine, LineField, ); \ 4692 OPTIONAL(containingType, MDField, ); \ 4693 OPTIONAL(virtuality, DwarfVirtualityField, ); \ 4694 OPTIONAL(virtualIndex, MDUnsignedField, (0, UINT32_MAX)); \ 4695 OPTIONAL(thisAdjustment, MDSignedField, (0, INT32_MIN, INT32_MAX)); \ 4696 OPTIONAL(flags, DIFlagField, ); \ 4697 OPTIONAL(spFlags, DISPFlagField, ); \ 4698 OPTIONAL(isOptimized, MDBoolField, ); \ 4699 OPTIONAL(unit, MDField, ); \ 4700 OPTIONAL(templateParams, MDField, ); \ 4701 OPTIONAL(declaration, MDField, ); \ 4702 OPTIONAL(retainedNodes, MDField, ); \ 4703 OPTIONAL(thrownTypes, MDField, ); 4705 #undef VISIT_MD_FIELDS 4710 spFlags.Seen ? spFlags.Val
4712 isOptimized.Val, virtuality.Val);
4713 if ((SPFlags & DISubprogram::SPFlagDefinition) && !IsDistinct)
4716 "missing 'distinct', required for !DISubprogram that is a Definition");
4720 type.Val, scopeLine.Val, containingType.Val, virtualIndex.Val,
4721 thisAdjustment.Val, flags.Val, SPFlags, unit.Val, templateParams.Val,
4722 declaration.Val, retainedNodes.Val, thrownTypes.Val));
4728 bool LLParser::ParseDILexicalBlock(
MDNode *&Result,
bool IsDistinct) {
4729 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4730 REQUIRED(scope, MDField, ( false)); \ 4731 OPTIONAL(file, MDField, ); \ 4732 OPTIONAL(line, LineField, ); \ 4733 OPTIONAL(column, ColumnField, ); 4735 #undef VISIT_MD_FIELDS 4744 bool LLParser::ParseDILexicalBlockFile(
MDNode *&Result,
bool IsDistinct) {
4745 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4746 REQUIRED(scope, MDField, ( false)); \ 4747 OPTIONAL(file, MDField, ); \ 4748 REQUIRED(discriminator, MDUnsignedField, (0, UINT32_MAX)); 4750 #undef VISIT_MD_FIELDS 4753 (
Context, scope.Val,
file.Val, discriminator.Val));
4759 bool LLParser::ParseDICommonBlock(
MDNode *&Result,
bool IsDistinct) {
4760 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4761 REQUIRED(scope, MDField, ); \ 4762 OPTIONAL(declaration, MDField, ); \ 4763 OPTIONAL(name, MDStringField, ); \ 4764 OPTIONAL(file, MDField, ); \ 4765 OPTIONAL(line, LineField, ); 4767 #undef VISIT_MD_FIELDS 4771 file.Val, line.Val));
4777 bool LLParser::ParseDINamespace(
MDNode *&Result,
bool IsDistinct) {
4778 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4779 REQUIRED(scope, MDField, ); \ 4780 OPTIONAL(name, MDStringField, ); \ 4781 OPTIONAL(exportSymbols, MDBoolField, ); 4783 #undef VISIT_MD_FIELDS 4786 (
Context, scope.Val,
name.Val, exportSymbols.Val));
4792 bool LLParser::ParseDIMacro(
MDNode *&Result,
bool IsDistinct) {
4793 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4794 REQUIRED(type, DwarfMacinfoTypeField, ); \ 4795 OPTIONAL(line, LineField, ); \ 4796 REQUIRED(name, MDStringField, ); \ 4797 OPTIONAL(value, MDStringField, ); 4799 #undef VISIT_MD_FIELDS 4808 bool LLParser::ParseDIMacroFile(
MDNode *&Result,
bool IsDistinct) {
4809 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4810 OPTIONAL(type, DwarfMacinfoTypeField, (dwarf::DW_MACINFO_start_file)); \ 4811 OPTIONAL(line, LineField, ); \ 4812 REQUIRED(file, MDField, ); \ 4813 OPTIONAL(nodes, MDField, ); 4815 #undef VISIT_MD_FIELDS 4825 bool LLParser::ParseDIModule(
MDNode *&Result,
bool IsDistinct) {
4826 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4827 REQUIRED(scope, MDField, ); \ 4828 REQUIRED(name, MDStringField, ); \ 4829 OPTIONAL(configMacros, MDStringField, ); \ 4830 OPTIONAL(includePath, MDStringField, ); \ 4831 OPTIONAL(sysroot, MDStringField, ); 4833 #undef VISIT_MD_FIELDS 4836 configMacros.Val, includePath.Val, sysroot.Val));
4842 bool LLParser::ParseDITemplateTypeParameter(
MDNode *&Result,
bool IsDistinct) {
4843 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4844 OPTIONAL(name, MDStringField, ); \ 4845 REQUIRED(type, MDField, ); 4847 #undef VISIT_MD_FIELDS 4857 bool LLParser::ParseDITemplateValueParameter(
MDNode *&Result,
bool IsDistinct) {
4858 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4859 OPTIONAL(tag, DwarfTagField, (dwarf::DW_TAG_template_value_parameter)); \ 4860 OPTIONAL(name, MDStringField, ); \ 4861 OPTIONAL(type, MDField, ); \ 4862 REQUIRED(value, MDField, ); 4864 #undef VISIT_MD_FIELDS 4876 bool LLParser::ParseDIGlobalVariable(
MDNode *&Result,
bool IsDistinct) {
4877 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4878 REQUIRED(name, MDStringField, ( false)); \ 4879 OPTIONAL(scope, MDField, ); \ 4880 OPTIONAL(linkageName, MDStringField, ); \ 4881 OPTIONAL(file, MDField, ); \ 4882 OPTIONAL(line, LineField, ); \ 4883 OPTIONAL(type, MDField, ); \ 4884 OPTIONAL(isLocal, MDBoolField, ); \ 4885 OPTIONAL(isDefinition, MDBoolField, (true)); \ 4886 OPTIONAL(templateParams, MDField, ); \ 4887 OPTIONAL(declaration, MDField, ); \ 4888 OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); 4890 #undef VISIT_MD_FIELDS 4895 line.Val,
type.Val, isLocal.Val, isDefinition.Val,
4896 declaration.Val, templateParams.Val, align.Val));
4907 bool LLParser::ParseDILocalVariable(
MDNode *&Result,
bool IsDistinct) {
4908 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4909 REQUIRED(scope, MDField, ( false)); \ 4910 OPTIONAL(name, MDStringField, ); \ 4911 OPTIONAL(arg, MDUnsignedField, (0, UINT16_MAX)); \ 4912 OPTIONAL(file, MDField, ); \ 4913 OPTIONAL(line, LineField, ); \ 4914 OPTIONAL(type, MDField, ); \ 4915 OPTIONAL(flags, DIFlagField, ); \ 4916 OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); 4918 #undef VISIT_MD_FIELDS 4922 type.Val, arg.Val, flags.Val, align.Val));
4928 bool LLParser::ParseDILabel(
MDNode *&Result,
bool IsDistinct) {
4929 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4930 REQUIRED(scope, MDField, ( false)); \ 4931 REQUIRED(name, MDStringField, ); \ 4932 REQUIRED(file, MDField, ); \ 4933 REQUIRED(line, LineField, ); 4935 #undef VISIT_MD_FIELDS 4944 bool LLParser::ParseDIExpression(
MDNode *&Result,
bool IsDistinct) {
4960 return TokError(
Twine(
"invalid DWARF op '") + Lex.getStrVal() +
"'");
4969 return TokError(
Twine(
"invalid DWARF attribute encoding '") + Lex.getStrVal() +
"'");
4972 if (Lex.getKind() !=
lltok::APSInt || Lex.getAPSIntVal().isSigned())
4973 return TokError(
"expected unsigned integer");
4975 auto &U = Lex.getAPSIntVal();
4991 bool LLParser::ParseDIGlobalVariableExpression(
MDNode *&Result,
4993 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4994 REQUIRED(var, MDField, ); \ 4995 REQUIRED(expr, MDField, ); 4997 #undef VISIT_MD_FIELDS 5007 bool LLParser::ParseDIObjCProperty(
MDNode *&Result,
bool IsDistinct) {
5008 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 5009 OPTIONAL(name, MDStringField, ); \ 5010 OPTIONAL(file, MDField, ); \ 5011 OPTIONAL(line, LineField, ); \ 5012 OPTIONAL(setter, MDStringField, ); \ 5013 OPTIONAL(getter, MDStringField, ); \ 5014 OPTIONAL(attributes, MDUnsignedField, (0, UINT32_MAX)); \ 5015 OPTIONAL(type, MDField, ); 5017 #undef VISIT_MD_FIELDS 5028 bool LLParser::ParseDIImportedEntity(
MDNode *&Result,
bool IsDistinct) {
5029 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 5030 REQUIRED(tag, DwarfTagField, ); \ 5031 REQUIRED(scope, MDField, ); \ 5032 OPTIONAL(entity, MDField, ); \ 5033 OPTIONAL(file, MDField, ); \ 5034 OPTIONAL(line, LineField, ); \ 5035 OPTIONAL(name, MDStringField, ); 5037 #undef VISIT_MD_FIELDS 5041 (
Context, tag.Val, scope.Val, entity.Val,
file.Val, line.Val,
name.Val));
5045 #undef PARSE_MD_FIELD 5047 #undef REQUIRE_FIELD 5048 #undef DECLARE_FIELD 5057 bool LLParser::ParseMetadataAsValue(
Value *&V, PerFunctionState &PFS) {
5060 if (ParseMetadata(MD, &PFS))
5071 bool LLParser::ParseValueAsMetadata(
Metadata *&MD,
const Twine &TypeMsg,
5072 PerFunctionState *PFS) {
5075 if (ParseType(Ty, TypeMsg, Loc))
5078 return Error(Loc,
"invalid metadata-value-metadata roundtrip");
5081 if (ParseValue(Ty, V, PFS))
5096 bool LLParser::ParseMetadata(
Metadata *&MD, PerFunctionState *PFS) {
5099 if (ParseSpecializedMDNode(N))
5108 return ParseValueAsMetadata(MD,
"expected metadata operand", PFS);
5118 if (ParseMDString(S))
5128 if (ParseMDNodeTail(N))
5138 bool LLParser::ConvertValIDToValue(
Type *Ty,
ValID &ID,
Value *&V,
5139 PerFunctionState *PFS,
bool IsCall) {
5141 return Error(ID.
Loc,
"functions are not values, refer to them as pointers");
5145 if (!PFS)
return Error(ID.
Loc,
"invalid use of function-local name");
5146 V = PFS->GetVal(ID.
UIntVal, Ty, ID.
Loc, IsCall);
5147 return V ==
nullptr;
5149 if (!PFS)
return Error(ID.
Loc,
"invalid use of function-local name");
5150 V = PFS->GetVal(ID.
StrVal, Ty, ID.
Loc, IsCall);
5151 return V ==
nullptr;
5154 return Error(ID.
Loc,
"invalid type for inline asm constraint string");
5161 V = GetGlobalVal(ID.
StrVal, Ty, ID.
Loc, IsCall);
5162 return V ==
nullptr;
5164 V = GetGlobalVal(ID.
UIntVal, Ty, ID.
Loc, IsCall);
5165 return V ==
nullptr;
5168 return Error(ID.
Loc,
"integer constant must have integer type");
5175 return Error(ID.
Loc,
"floating point constant invalid for type");
5191 return Error(ID.
Loc,
"floating point constant does not have type '" +
5197 return Error(ID.
Loc,
"null must be a pointer type");
5203 return Error(ID.
Loc,
"invalid type for undef constant");
5207 if (!Ty->
isArrayTy() || cast<ArrayType>(Ty)->getNumElements() != 0)
5208 return Error(ID.
Loc,
"invalid empty array initializer");
5214 return Error(ID.
Loc,
"invalid type for null constant");
5219 return Error(ID.
Loc,
"invalid type for none constant");
5224 return Error(ID.
Loc,
"constant expression type mismatch");
5233 "initializer with struct type has wrong # elements");
5235 return Error(ID.
Loc,
"packed'ness of initializer and type don't match");
5238 for (
unsigned i = 0,
e = ID.
UIntVal; i !=
e; ++i)
5241 " of struct initializer doesn't match struct element type");
5246 return Error(ID.
Loc,
"constant expression type mismatch");
5252 bool LLParser::parseConstantValue(
Type *Ty,
Constant *&C) {
5255 auto Loc = Lex.getLoc();
5256 if (ParseValID(ID,
nullptr))
5266 if (ConvertValIDToValue(Ty, ID, V,
nullptr,
false))
5268 assert(isa<Constant>(V) &&
"Expected a constant value");
5269 C = cast<Constant>(V);
5276 return Error(Loc,
"expected a constant value");
5280 bool LLParser::ParseValue(
Type *Ty,
Value *&V, PerFunctionState *PFS) {
5283 return ParseValID(ID, PFS) ||
5284 ConvertValIDToValue(Ty, ID, V, PFS,
false);
5287 bool LLParser::ParseTypeAndValue(
Value *&V, PerFunctionState *PFS) {
5289 return ParseType(Ty) ||
5290 ParseValue(Ty, V, PFS);
5294 PerFunctionState &PFS) {
5297 if (ParseTypeAndValue(V, PFS))
return true;
5298 if (!isa<BasicBlock>(V))
5299 return Error(Loc,
"expected a basic block");
5300 BB = cast<BasicBlock>(V);
5309 bool LLParser::ParseFunctionHeader(
Function *&Fn,
bool isDefine) {
5311 LocTy LinkageLoc = Lex.getLoc();
5313 unsigned Visibility;
5314 unsigned DLLStorageClass;
5319 Type *RetType =
nullptr;
5320 LocTy RetTypeLoc = Lex.getLoc();
5321 if (ParseOptionalLinkage(Linkage, HasLinkage, Visibility, DLLStorageClass,
5323 ParseOptionalCallingConv(CC) || ParseOptionalReturnAttrs(RetAttrs) ||
5324 ParseType(RetType, RetTypeLoc,
true ))
5333 return Error(LinkageLoc,
"invalid linkage for function definition");
5343 return Error(LinkageLoc,
"invalid linkage for function declaration");
5347 return Error(LinkageLoc,
"invalid function linkage type");
5351 return Error(LinkageLoc,
5352 "symbol with local linkage must have default visibility");
5355 return Error(RetTypeLoc,
"invalid function return type");
5357 LocTy NameLoc = Lex.getLoc();
5359 std::string FunctionName;
5361 FunctionName = Lex.getStrVal();
5363 unsigned NameID = Lex.getUIntVal();
5365 if (NameID != NumberedVals.size())
5366 return TokError(
"function expected to be numbered '%" +
5367 Twine(NumberedVals.size()) +
"'");
5369 return TokError(
"expected function name");
5375 return TokError(
"expected '(' in function argument list");
5380 std::vector<unsigned> FwdRefAttrGrps;
5383 std::string Partition;
5387 unsigned AddrSpace = 0;
5393 if (ParseArgumentList(ArgList, isVarArg) ||
5394 ParseOptionalUnnamedAddr(UnnamedAddr) ||
5395 ParseOptionalProgramAddrSpace(AddrSpace) ||
5396 ParseFnAttributeValuePairs(FuncAttrs, FwdRefAttrGrps,
false,
5399 ParseStringConstant(Section)) ||
5401 ParseStringConstant(Partition)) ||
5402 parseOptionalComdat(FunctionName, C) ||
5403 ParseOptionalAlignment(Alignment) ||
5405 ParseStringConstant(GC)) ||
5407 ParseGlobalTypeAndValue(Prefix)) ||
5409 ParseGlobalTypeAndValue(Prologue)) ||
5411 ParseGlobalTypeAndValue(PersonalityFn)))
5414 if (FuncAttrs.
contains(Attribute::Builtin))
5415 return Error(BuiltinLoc,
"'builtin' attribute not valid on function");
5425 std::vector<Type*> ParamTypeList;
5428 for (
unsigned i = 0,
e = ArgList.
size(); i !=
e; ++i) {
5429 ParamTypeList.push_back(ArgList[i].Ty);
5438 return Error(RetTypeLoc,
"functions with 'sret' argument must return void");
5445 if (!FunctionName.empty()) {
5448 auto FRVI = ForwardRefVals.find(FunctionName);
5449 if (FRVI != ForwardRefVals.end()) {
5450 Fn = M->getFunction(FunctionName);
5452 return Error(FRVI->second.second,
"invalid forward reference to " 5453 "function as global value!");
5455 return Error(FRVI->second.second,
"invalid forward reference to " 5456 "function '" + FunctionName +
"' with wrong type: " 5459 ForwardRefVals.erase(FRVI);
5460 }
else if ((Fn = M->getFunction(FunctionName))) {
5462 return Error(NameLoc,
"invalid redefinition of function '" +
5463 FunctionName +
"'");
5464 }
else if (M->getNamedValue(FunctionName)) {
5465 return Error(NameLoc,
"redefinition of function '@" + FunctionName +
"'");
5471 auto I = ForwardRefValIDs.find(NumberedVals.size());
5472 if (
I != ForwardRefValIDs.end()) {
5473 Fn = cast<Function>(
I->second.first);
5475 return Error(NameLoc,
"type of definition and forward reference of '@" +
5476 Twine(NumberedVals.size()) +
"' disagree: " 5479 ForwardRefValIDs.erase(
I);
5487 M->getFunctionList().splice(M->end(), M->getFunctionList(), Fn);
5491 if (FunctionName.empty())
5492 NumberedVals.push_back(Fn);
5506 if (!GC.empty()) Fn->
setGC(GC);
5509 ForwardRefAttrGroups[Fn] = FwdRefAttrGrps;
5513 for (
unsigned i = 0,
e = ArgList.
size(); i !=
e; ++i, ++ArgIt) {
5515 if (ArgList[i].Name.
empty())
continue;
5518 ArgIt->
setName(ArgList[i].Name);
5520 if (ArgIt->
getName() != ArgList[i].Name)
5521 return Error(ArgList[i].Loc,
"redefinition of argument '%" +
5522 ArgList[i].Name +
"'");
5530 if (FunctionName.empty()) {
5532 ID.
UIntVal = NumberedVals.size() - 1;
5535 ID.
StrVal = FunctionName;
5537 auto Blocks = ForwardRefBlockAddresses.find(ID);
5538 if (Blocks != ForwardRefBlockAddresses.end())
5539 return Error(Blocks->first.Loc,
5540 "cannot take blockaddress inside a declaration");
5544 bool LLParser::PerFunctionState::resolveForwardRefBlockAddresses() {
5554 auto Blocks =
P.ForwardRefBlockAddresses.find(ID);
5555 if (Blocks ==
P.ForwardRefBlockAddresses.end())
5558 for (
const auto &
I : Blocks->second) {
5559 const ValID &BBID =
I.first;
5563 "Expected local id or name");
5570 return P.Error(BBID.
Loc,
"referenced value is not a basic block");
5576 P.ForwardRefBlockAddresses.erase(Blocks);
5582 bool LLParser::ParseFunctionBody(
Function &Fn) {
5584 return TokError(
"expected '{' in function body");
5588 if (!Fn.
hasName()) FunctionNumber = NumberedVals.size()-1;
5590 PerFunctionState PFS(*
this, Fn, FunctionNumber);
5594 if (PFS.resolveForwardRefBlockAddresses())
5600 return TokError(
"function body requires at least one basic block");
5604 if (ParseBasicBlock(PFS))
return true;
5607 if (ParseUseListOrder(&PFS))
5614 return PFS.FinishFunction();
5619 bool LLParser::ParseBasicBlock(PerFunctionState &PFS) {
5623 LocTy NameLoc = Lex.getLoc();
5625 Name = Lex.getStrVal();
5628 NameID = Lex.getUIntVal();
5632 BasicBlock *BB = PFS.DefineBB(Name, NameID, NameLoc);
5636 std::string NameStr;
5643 LocTy NameLoc = Lex.getLoc();
5648 NameID = Lex.getUIntVal();
5650 if (ParseToken(
lltok::equal,
"expected '=' after instruction id"))
5653 NameStr = Lex.getStrVal();
5655 if (ParseToken(
lltok::equal,
"expected '=' after instruction name"))
5659 switch (ParseInstruction(Inst, BB, PFS)) {
5661 case InstError:
return true;
5668 if (ParseInstructionMetadata(*Inst))
5671 case InstExtraComma:
5676 if (ParseInstructionMetadata(*Inst))
5682 if (PFS.SetInstName(NameID, NameStr, NameLoc, Inst))
return true;
5695 PerFunctionState &PFS) {
5698 return TokError(
"found end of file when expecting more instructions");
5699 LocTy Loc = Lex.getLoc();
5700 unsigned KeywordVal = Lex.getUIntVal();
5704 default:
return Error(Loc,
"expected instruction opcode");
5722 int Res = ParseUnaryOp(Inst, PFS, KeywordVal,
true);
5738 if (ParseArithmetic(Inst, PFS, KeywordVal,
false))
return true;
5740 if (NUW) cast<BinaryOperator>(Inst)->setHasNoUnsignedWrap(
true);
5741 if (NSW) cast<BinaryOperator>(Inst)->setHasNoSignedWrap(
true);
5750 int Res = ParseArithmetic(Inst, PFS, KeywordVal,
true);
5764 if (ParseArithmetic(Inst, PFS, KeywordVal,
false))
return true;
5765 if (Exact) cast<BinaryOperator>(Inst)->setIsExact(
true);
5770 case lltok::kw_srem:
return ParseArithmetic(Inst, PFS, KeywordVal,
5774 case lltok::kw_xor:
return ParseLogical(Inst, PFS, KeywordVal);
5778 int Res = ParseCompare(Inst, PFS, KeywordVal);
5803 int Res = ParseSelect(Inst, PFS);
5807 if (!isa<FPMathOperator>(Inst))
5808 return Error(Loc,
"fast-math-flags specified for select without " 5809 "floating-point scalar or vector return type");
5820 int Res = ParsePHI(Inst, PFS);
5824 if (!isa<FPMathOperator>(Inst))
5825 return Error(Loc,
"fast-math-flags specified for phi without " 5826 "floating-point scalar or vector return type");
5852 bool LLParser::ParseCmpPredicate(
unsigned &
P,
unsigned Opc) {
5853 if (Opc == Instruction::FCmp) {
5854 switch (Lex.getKind()) {
5855 default:
return TokError(
"expected fcmp predicate (e.g. 'oeq')");
5874 switch (Lex.getKind()) {
5875 default:
return TokError(
"expected icmp predicate (e.g. 'eq')");
5900 PerFunctionState &PFS) {
5901 SMLoc TypeLoc = Lex.getLoc();
5903 if (ParseType(Ty,
true ))
return true;
5905 Type *ResType = PFS.getFunction().getReturnType();
5909 return Error(TypeLoc,
"value doesn't match function result type '" +
5917 if (ParseValue(Ty, RV, PFS))
return true;
5920 return Error(TypeLoc,
"value doesn't match function result type '" +
5930 bool LLParser::ParseBr(
Instruction *&Inst, PerFunctionState &PFS) {
5934 if (ParseTypeAndValue(Op0, Loc, PFS))
return true;
5936 if (
BasicBlock *BB = dyn_cast<BasicBlock>(Op0)) {
5942 return Error(Loc,
"branch condition must have 'i1' type");
5944 if (ParseToken(
lltok::comma,
"expected ',' after branch condition") ||
5945 ParseTypeAndBasicBlock(Op1, Loc, PFS) ||
5946 ParseToken(
lltok::comma,
"expected ',' after true destination") ||
5947 ParseTypeAndBasicBlock(Op2, Loc2, PFS))
5959 bool LLParser::ParseSwitch(
Instruction *&Inst, PerFunctionState &PFS) {
5960 LocTy CondLoc, BBLoc;
5963 if (ParseTypeAndValue(Cond, CondLoc, PFS) ||
5964 ParseToken(
lltok::comma,
"expected ',' after switch condition") ||
5965 ParseTypeAndBasicBlock(DefaultBB, BBLoc, PFS) ||
5970 return Error(CondLoc,
"switch condition must have integer type");
5979 if (ParseTypeAndValue(Constant, CondLoc, PFS) ||
5980 ParseToken(
lltok::comma,
"expected ',' after case value") ||
5981 ParseTypeAndBasicBlock(DestBB, PFS))
5984 if (!SeenCases.
insert(Constant).second)
5985 return Error(CondLoc,
"duplicate case value in switch");
5986 if (!isa<ConstantInt>(Constant))
5987 return Error(CondLoc,
"case value is not a constant integer");
5989 Table.
push_back(std::make_pair(cast<ConstantInt>(Constant), DestBB));
5995 for (
unsigned i = 0,
e = Table.
size(); i !=
e; ++i)
5996 SI->
addCase(Table[i].first, Table[i].second);
6004 bool LLParser::ParseIndirectBr(
Instruction *&Inst, PerFunctionState &PFS) {
6007 if (ParseTypeAndValue(Address, AddrLoc, PFS) ||
6008 ParseToken(
lltok::comma,
"expected ',' after indirectbr address") ||
6013 return Error(AddrLoc,
"indirectbr address must have pointer type");
6020 if (ParseTypeAndBasicBlock(DestBB, PFS))
6025 if (ParseTypeAndBasicBlock(DestBB, PFS))
6031 if (ParseToken(
lltok::rsquare,
"expected ']' at end of block list"))
6035 for (
unsigned i = 0,
e = DestList.
size(); i !=
e; ++i)
6044 bool LLParser::ParseInvoke(
Instruction *&Inst, PerFunctionState &PFS) {
6045 LocTy CallLoc = Lex.getLoc();
6047 std::vector<unsigned> FwdRefAttrGrps;
6050 unsigned InvokeAddrSpace;
6051 Type *RetType =
nullptr;
6058 if (ParseOptionalCallingConv(CC) || ParseOptionalReturnAttrs(RetAttrs) ||
6059 ParseOptionalProgramAddrSpace(InvokeAddrSpace) ||
6060 ParseType(RetType, RetTypeLoc,
true ) ||
6061 ParseValID(CalleeID) || ParseParameterList(ArgList, PFS) ||
6062 ParseFnAttributeValuePairs(FnAttrs, FwdRefAttrGrps,
false,
6064 ParseOptionalOperandBundles(BundleList, PFS) ||
6066 ParseTypeAndBasicBlock(NormalBB, PFS) ||
6068 ParseTypeAndBasicBlock(UnwindBB, PFS))
6077 std::vector<Type*> ParamTypes;
6078 for (
unsigned i = 0,
e = ArgList.
size(); i !=
e; ++i)
6079 ParamTypes.push_back(ArgList[i].V->getType());
6082 return Error(RetTypeLoc,
"Invalid result type for LLVM function");
6092 Callee, &PFS,
true))
6103 for (
unsigned i = 0,
e = ArgList.
size(); i !=
e; ++i) {
6104 Type *ExpectedTy =
nullptr;
6108 return Error(ArgList[i].Loc,
"too many arguments specified");
6111 if (ExpectedTy && ExpectedTy != ArgList[i].V->
getType())
6112 return Error(ArgList[i].Loc,
"argument is not of expected type '" +
6119 return Error(CallLoc,
"not enough parameters specified for call");
6122 return Error(CallLoc,
"invoke instructions may not have an alignment");
6133 ForwardRefAttrGroups[II] = FwdRefAttrGrps;
6140 bool LLParser::ParseResume(
Instruction *&Inst, PerFunctionState &PFS) {
6142 if (ParseTypeAndValue(Exn, ExnLoc, PFS))
6151 PerFunctionState &PFS) {
6152 if (ParseToken(
lltok::lsquare,
"expected '[' in catchpad/cleanuppad"))
6157 if (!Args.
empty() &&
6158 ParseToken(
lltok::comma,
"expected ',' in argument list"))
6163 Type *ArgTy =
nullptr;
6164 if (ParseType(ArgTy, ArgLoc))
6169 if (ParseMetadataAsValue(V, PFS))
6172 if (ParseValue(ArgTy, V, PFS))
6184 bool LLParser::ParseCleanupRet(
Instruction *&Inst, PerFunctionState &PFS) {
6185 Value *CleanupPad =
nullptr;
6187 if (ParseToken(
lltok::kw_from,
"expected 'from' after cleanupret"))
6202 if (ParseTypeAndBasicBlock(UnwindBB, PFS)) {
6213 bool LLParser::ParseCatchRet(
Instruction *&Inst, PerFunctionState &PFS) {
6214 Value *CatchPad =
nullptr;
6216 if (ParseToken(
lltok::kw_from,
"expected 'from' after catchret"))
6223 if (ParseToken(
lltok::kw_to,
"expected 'to' in catchret") ||
6224 ParseTypeAndBasicBlock(BB, PFS))
6233 bool LLParser::ParseCatchSwitch(
Instruction *&Inst, PerFunctionState &PFS) {
6241 return TokError(
"expected scope value for catchswitch");
6246 if (ParseToken(
lltok::lsquare,
"expected '[' with catchswitch labels"))
6252 if (ParseTypeAndBasicBlock(DestBB, PFS))
6257 if (ParseToken(
lltok::rsquare,
"expected ']' after catchswitch labels"))
6261 "expected 'unwind' after catchswitch scope"))
6269 if (ParseTypeAndBasicBlock(UnwindBB, PFS))
6283 bool LLParser::ParseCatchPad(
Instruction *&Inst, PerFunctionState &PFS) {
6284 Value *CatchSwitch =
nullptr;
6290 return TokError(
"expected scope value for catchpad");
6296 if (ParseExceptionArgs(Args, PFS))
6305 bool LLParser::ParseCleanupPad(
Instruction *&Inst, PerFunctionState &PFS) {
6306 Value *ParentPad =
nullptr;
6313 return TokError(
"expected scope value for cleanuppad");
6319 if (ParseExceptionArgs(Args, PFS))
6335 bool LLParser::ParseUnaryOp(
Instruction *&Inst, PerFunctionState &PFS,
6336 unsigned Opc,
bool IsFP) {
6338 if (ParseTypeAndValue(LHS, Loc, PFS))
6345 return Error(Loc,
"invalid operand type for instruction");
6355 bool LLParser::ParseCallBr(
Instruction *&Inst, PerFunctionState &PFS) {
6356 LocTy CallLoc = Lex.getLoc();
6358 std::vector<unsigned> FwdRefAttrGrps;
6361 Type *RetType =
nullptr;
6368 if (ParseOptionalCallingConv(CC) || ParseOptionalReturnAttrs(RetAttrs) ||
6369 ParseType(RetType, RetTypeLoc,
true ) ||
6370 ParseValID(CalleeID) || ParseParameterList(ArgList, PFS) ||
6371 ParseFnAttributeValuePairs(FnAttrs, FwdRefAttrGrps,
false,
6373 ParseOptionalOperandBundles(BundleList, PFS) ||
6375 ParseTypeAndBasicBlock(DefaultDest, PFS) ||
6384 if (ParseTypeAndBasicBlock(DestBB, PFS))
6389 if (ParseTypeAndBasicBlock(DestBB, PFS))
6395 if (ParseToken(
lltok::rsquare,
"expected ']' at end of block list"))
6404 std::vector<Type *> ParamTypes;
6405 for (
unsigned i = 0,
e = ArgList.
size(); i !=
e; ++i)
6406 ParamTypes.push_back(ArgList[i].V->getType());
6409 return Error(RetTypeLoc,
"Invalid result type for LLVM function");
6423 return Error(RetTypeLoc,
"asm-goto outputs not supported");
6433 for (
unsigned i = 0,
e = ArgList.
size(); i !=
e; ++i) {
6434 Type *ExpectedTy =
nullptr;
6438 return Error(ArgList[i].Loc,
"too many arguments specified");
6441 if (ExpectedTy && ExpectedTy != ArgList[i].V->
getType())
6442 return Error(ArgList[i].Loc,
"argument is not of expected type '" +
6449 return Error(CallLoc,
"not enough parameters specified for call");
6452 return Error(CallLoc,
"callbr instructions may not have an alignment");
6464 ForwardRefAttrGroups[CBI] = FwdRefAttrGrps;
6478 bool LLParser::ParseArithmetic(
Instruction *&Inst, PerFunctionState &PFS,
6479 unsigned Opc,
bool IsFP) {
6481 if (ParseTypeAndValue(LHS, Loc, PFS) ||
6482 ParseToken(
lltok::comma,
"expected ',' in arithmetic operation") ||
6483 ParseValue(LHS->
getType(), RHS, PFS))
6490 return Error(Loc,
"invalid operand type for instruction");
6498 bool LLParser::ParseLogical(
Instruction *&Inst, PerFunctionState &PFS,
6501 if (ParseTypeAndValue(LHS, Loc, PFS) ||
6502 ParseToken(
lltok::comma,
"expected ',' in logical operation") ||
6503 ParseValue(LHS->
getType(), RHS, PFS))
6507 return Error(Loc,
"instruction requires integer or integer vector operands");
6516 bool LLParser::ParseCompare(
Instruction *&Inst, PerFunctionState &PFS,
6522 if (ParseCmpPredicate(Pred, Opc) ||
6523 ParseTypeAndValue(LHS, Loc, PFS) ||
6524 ParseToken(
lltok::comma,
"expected ',' after compare value") ||
6525 ParseValue(LHS->
getType(), RHS, PFS))
6528 if (Opc == Instruction::FCmp) {
6530 return Error(Loc,
"fcmp requires floating point operands");
6533 assert(Opc == Instruction::ICmp &&
"Unknown opcode for CmpInst!");
6536 return Error(Loc,
"icmp requires integer operands");
6549 bool LLParser::ParseCast(
Instruction *&Inst, PerFunctionState &PFS,
6553 Type *DestTy =
nullptr;
6554 if (ParseTypeAndValue(Op, Loc, PFS) ||
6555 ParseToken(
lltok::kw_to,
"expected 'to' after cast value") ||
6561 return Error(Loc,
"invalid cast opcode for cast from '" +
6571 bool LLParser::ParseSelect(
Instruction *&Inst, PerFunctionState &PFS) {
6573 Value *Op0, *Op1, *Op2;
6574 if (ParseTypeAndValue(Op0, Loc, PFS) ||
6575 ParseToken(
lltok::comma,
"expected ',' after select condition") ||
6576 ParseTypeAndValue(Op1, PFS) ||
6577 ParseToken(
lltok::comma,
"expected ',' after select value") ||
6578 ParseTypeAndValue(Op2, PFS))
6582 return Error(Loc, Reason);
6590 bool LLParser::ParseVA_Arg(
Instruction *&Inst, PerFunctionState &PFS) {
6592 Type *EltTy =
nullptr;
6594 if (ParseTypeAndValue(Op, PFS) ||
6595 ParseToken(
lltok::comma,
"expected ',' after vaarg operand") ||
6596 ParseType(EltTy, TypeLoc))
6600 return Error(TypeLoc,
"va_arg requires operand with first class type");
6608 bool LLParser::ParseExtractElement(
Instruction *&Inst, PerFunctionState &PFS) {
6611 if (ParseTypeAndValue(Op0, Loc, PFS) ||
6612 ParseToken(
lltok::comma,
"expected ',' after extract value") ||
6613 ParseTypeAndValue(Op1, PFS))
6617 return Error(Loc,
"invalid extractelement operands");
6625 bool LLParser::ParseInsertElement(
Instruction *&Inst, PerFunctionState &PFS) {
6627 Value *Op0, *Op1, *Op2;
6628 if (ParseTypeAndValue(Op0, Loc, PFS) ||
6629 ParseToken(
lltok::comma,
"expected ',' after insertelement value") ||
6630 ParseTypeAndValue(Op1, PFS) ||
6631 ParseToken(
lltok::comma,
"expected ',' after insertelement value") ||
6632 ParseTypeAndValue(Op2, PFS))
6636 return Error(Loc,
"invalid insertelement operands");
6644 bool LLParser::ParseShuffleVector(
Instruction *&Inst, PerFunctionState &PFS) {
6646 Value *Op0, *Op1, *Op2;
6647 if (ParseTypeAndValue(Op0, Loc, PFS) ||
6648 ParseToken(
lltok::comma,
"expected ',' after shuffle mask") ||
6649 ParseTypeAndValue(Op1, PFS) ||
6650 ParseToken(
lltok::comma,
"expected ',' after shuffle value") ||
6651 ParseTypeAndValue(Op2, PFS))
6655 return Error(Loc,
"invalid shufflevector operands");
6663 int LLParser::ParsePHI(
Instruction *&Inst, PerFunctionState &PFS) {
6667 if (ParseType(Ty, TypeLoc) ||
6669 ParseValue(Ty, Op0, PFS) ||
6670 ParseToken(
lltok::comma,
"expected ',' after insertelement value") ||
6675 bool AteExtraComma =
false;
6679 PHIVals.
push_back(std::make_pair(Op0, cast<BasicBlock>(Op1)));
6685 AteExtraComma =
true;
6689 if (ParseToken(
lltok::lsquare,
"expected '[' in phi value list") ||
6690 ParseValue(Ty, Op0, PFS) ||
6691 ParseToken(
lltok::comma,
"expected ',' after insertelement value") ||
6698 return Error(TypeLoc,
"phi node must have first class type");
6701 for (
unsigned i = 0,
e = PHIVals.
size(); i !=
e; ++i)
6702 PN->
addIncoming(PHIVals[i].first, PHIVals[i].second);
6704 return AteExtraComma ? InstExtraComma : InstNormal;
6713 bool LLParser::ParseLandingPad(
Instruction *&Inst, PerFunctionState &PFS) {
6716 if (ParseType(Ty, TyLoc))
6729 return TokError(
"expected 'catch' or 'filter' clause type");
6733 if (ParseTypeAndValue(V, VLoc, PFS))
6739 if (isa<ArrayType>(V->
getType()))
6740 Error(VLoc,
"'catch' clause has an invalid type");
6742 if (!isa<ArrayType>(V->
getType()))
6743 Error(VLoc,
"'filter' clause has an invalid type");
6748 return Error(VLoc,
"clause argument must be a constant");
6752 Inst = LP.release();
6758 bool LLParser::ParseFreeze(
Instruction *&Inst, PerFunctionState &PFS) {
6761 if (ParseTypeAndValue(Op, Loc, PFS))
6777 bool LLParser::ParseCall(
Instruction *&Inst, PerFunctionState &PFS,
6780 std::vector<unsigned> FwdRefAttrGrps;
6782 unsigned CallAddrSpace;
6784 Type *RetType =
nullptr;
6789 LocTy CallLoc = Lex.getLoc();
6793 "expected 'tail call', 'musttail call', or 'notail call'"))
6798 if (ParseOptionalCallingConv(CC) || ParseOptionalReturnAttrs(RetAttrs) ||
6799 ParseOptionalProgramAddrSpace(CallAddrSpace) ||
6800 ParseType(RetType, RetTypeLoc,
true ) ||
6801 ParseValID(CalleeID) ||
6803 PFS.getFunction().isVarArg()) ||
6804 ParseFnAttributeValuePairs(FnAttrs, FwdRefAttrGrps,
false, BuiltinLoc) ||
6805 ParseOptionalOperandBundles(BundleList, PFS))
6814 std::vector<Type*> ParamTypes;
6815 for (
unsigned i = 0,
e = ArgList.
size(); i !=
e; ++i)
6816 ParamTypes.push_back(ArgList[i].V->getType());
6819 return Error(RetTypeLoc,
"Invalid result type for LLVM function");
6828 if (ConvertValIDToValue(
PointerType::get(Ty, CallAddrSpace), CalleeID, Callee,
6841 for (
unsigned i = 0,
e = ArgList.
size(); i !=
e; ++i) {
6842 Type *ExpectedTy =
nullptr;
6846 return Error(ArgList[i].Loc,
"too many arguments specified");
6849 if (ExpectedTy && ExpectedTy != ArgList[i].V->
getType())
6850 return Error(ArgList[i].Loc,
"argument is not of expected type '" +
6857 return Error(CallLoc,
"not enough parameters specified for call");
6860 return Error(CallLoc,
"call instructions may not have an alignment");
6871 if (!isa<FPMathOperator>(CI))
6872 return Error(CallLoc,
"fast-math-flags specified for call without " 6873 "floating-point scalar or vector return type");
6877 ForwardRefAttrGroups[CI] = FwdRefAttrGrps;
6889 int LLParser::ParseAlloc(
Instruction *&Inst, PerFunctionState &PFS) {
6891 LocTy SizeLoc, TyLoc, ASLoc;
6893 unsigned AddrSpace = 0;
6899 if (ParseType(Ty, TyLoc))
return true;
6902 return Error(TyLoc,
"invalid type for alloca");
6904 bool AteExtraComma =
false;
6907 if (ParseOptionalAlignment(Alignment))
6909 if (ParseOptionalCommaAddrSpace(AddrSpace, ASLoc, AteExtraComma))
6912 ASLoc = Lex.getLoc();
6913 if (ParseOptionalAddrSpace(AddrSpace))
6916 AteExtraComma =
true;
6918 if (ParseTypeAndValue(Size, SizeLoc, PFS))
6922 if (ParseOptionalAlignment(Alignment))
6924 if (ParseOptionalCommaAddrSpace(AddrSpace, ASLoc, AteExtraComma))
6927 ASLoc = Lex.getLoc();
6928 if (ParseOptionalAddrSpace(AddrSpace))
6931 AteExtraComma =
true;
6938 return Error(SizeLoc,
"element count must have integer type");
6944 return AteExtraComma ? InstExtraComma : InstNormal;
6951 int LLParser::ParseLoad(
Instruction *&Inst, PerFunctionState &PFS) {
6954 bool AteExtraComma =
false;
6971 LocTy ExplicitTypeLoc = Lex.getLoc();
6972 if (ParseType(Ty) ||
6973 ParseToken(
lltok::comma,
"expected comma after load's type") ||
6974 ParseTypeAndValue(Val, Loc, PFS) ||
6975 ParseScopeAndOrdering(isAtomic, SSID, Ordering) ||
6976 ParseOptionalCommaAlign(Alignment, AteExtraComma))
6980 return Error(Loc,
"load operand must be a pointer to a first class type");
6981 if (isAtomic && !Alignment)
6982 return Error(Loc,
"atomic load must have explicit non-zero alignment");
6985 return Error(Loc,
"atomic load cannot use Release ordering");
6987 if (Ty != cast<PointerType>(Val->
getType())->getElementType())
6988 return Error(ExplicitTypeLoc,
6989 "explicit pointee type doesn't match operand's pointee type");
6991 Inst =
new LoadInst(Ty, Val,
"", isVolatile, Alignment, Ordering, SSID);
6992 return AteExtraComma ? InstExtraComma : InstNormal;
7000 int LLParser::ParseStore(
Instruction *&Inst, PerFunctionState &PFS) {
7003 bool AteExtraComma =
false;
7019 if (ParseTypeAndValue(Val, Loc, PFS) ||
7020 ParseToken(
lltok::comma,
"expected ',' after store operand") ||
7021 ParseTypeAndValue(Ptr, PtrLoc, PFS) ||
7022 ParseScopeAndOrdering(isAtomic, SSID, Ordering) ||
7023 ParseOptionalCommaAlign(Alignment, AteExtraComma))
7027 return Error(PtrLoc,
"store operand must be a pointer");
7029 return Error(Loc,
"store operand must be a first class value");
7030 if (cast<PointerType>(Ptr->
getType())->getElementType() != Val->
getType())
7031 return Error(Loc,
"stored value and pointer type do not match");
7032 if (isAtomic && !Alignment)
7033 return Error(Loc,
"atomic store must have explicit non-zero alignment");
7036 return Error(Loc,
"atomic store cannot use Acquire ordering");
7038 Inst =
new StoreInst(Val, Ptr, isVolatile, Alignment, Ordering, SSID);
7039 return AteExtraComma ? InstExtraComma : InstNormal;
7045 int LLParser::ParseCmpXchg(
Instruction *&Inst, PerFunctionState &PFS) {
7046 Value *Ptr, *Cmp, *New;
LocTy PtrLoc, CmpLoc, NewLoc;
7047 bool AteExtraComma =
false;
7052 bool isWeak =
false;
7060 if (ParseTypeAndValue(Ptr, PtrLoc, PFS) ||
7061 ParseToken(
lltok::comma,
"expected ',' after cmpxchg address") ||
7062 ParseTypeAndValue(Cmp, CmpLoc, PFS) ||
7063 ParseToken(
lltok::comma,
"expected ',' after cmpxchg cmp operand") ||
7064 ParseTypeAndValue(New, NewLoc, PFS) ||
7065 ParseScopeAndOrdering(
true , SSID, SuccessOrdering) ||
7066 ParseOrdering(FailureOrdering))
7071 return TokError(
"cmpxchg cannot be unordered");
7073 return TokError(
"cmpxchg failure argument shall be no stronger than the " 7074 "success argument");
7078 "cmpxchg failure ordering cannot include release semantics");
7080 return Error(PtrLoc,
"cmpxchg operand must be a pointer");
7081 if (cast<PointerType>(Ptr->
getType())->getElementType() != Cmp->
getType())
7082 return Error(CmpLoc,
"compare value and pointer type do not match");
7083 if (cast<PointerType>(Ptr->
getType())->getElementType() != New->
getType())
7084 return Error(NewLoc,
"new value and pointer type do not match");
7086 return Error(NewLoc,
"cmpxchg operand must be a first class value");
7088 Ptr, Cmp, New, SuccessOrdering, FailureOrdering, SSID);
7092 return AteExtraComma ? InstExtraComma : InstNormal;
7098 int LLParser::ParseAtomicRMW(
Instruction *&Inst, PerFunctionState &PFS) {
7100 bool AteExtraComma =
false;
7110 switch (Lex.getKind()) {
7111 default:
return TokError(
"expected binary operation in atomicrmw");
7134 if (ParseTypeAndValue(Ptr, PtrLoc, PFS) ||
7135 ParseToken(
lltok::comma,
"expected ',' after atomicrmw address") ||
7136 ParseTypeAndValue(Val, ValLoc, PFS) ||
7137 ParseScopeAndOrdering(
true , SSID, Ordering))
7141 return TokError(
"atomicrmw cannot be unordered");
7143 return Error(PtrLoc,
"atomicrmw operand must be a pointer");
7144 if (cast<PointerType>(Ptr->
getType())->getElementType() != Val->
getType())
7145 return Error(ValLoc,
"atomicrmw value and pointer type do not match");
7150 return Error(ValLoc,
"atomicrmw " +
7152 " operand must be an integer or floating point type");
7156 return Error(ValLoc,
"atomicrmw " +
7158 " operand must be a floating point type");
7162 return Error(ValLoc,
"atomicrmw " +
7164 " operand must be an integer");
7169 if (Size < 8 || (Size & (Size - 1)))
7170 return Error(ValLoc,
"atomicrmw operand must be power-of-two byte-sized" 7177 return AteExtraComma ? InstExtraComma : InstNormal;
7182 int LLParser::ParseFence(
Instruction *&Inst, PerFunctionState &PFS) {
7185 if (ParseScopeAndOrdering(
true , SSID, Ordering))
7189 return TokError(
"fence cannot be unordered");
7191 return TokError(
"fence cannot be monotonic");
7199 int LLParser::ParseGetElementPtr(
Instruction *&Inst, PerFunctionState &PFS) {
7200 Value *Ptr =
nullptr;
7201 Value *Val =
nullptr;
7207 LocTy ExplicitTypeLoc = Lex.getLoc();
7208 if (ParseType(Ty) ||
7209 ParseToken(
lltok::comma,
"expected comma after getelementptr's type") ||
7210 ParseTypeAndValue(Ptr, Loc, PFS))
7215 if (!BasePointerType)
7216 return Error(Loc,
"base of getelementptr must be a pointer");
7219 return Error(ExplicitTypeLoc,
7220 "explicit pointee type doesn't match operand's pointee type");
7223 bool AteExtraComma =
false;
7231 AteExtraComma =
true;
7234 if (ParseTypeAndValue(Val, EltLoc, PFS))
return true;
7236 return Error(EltLoc,
"getelementptr index must be an integer");
7240 if (GEPWidth && GEPWidth != ValNumEl)
7241 return Error(EltLoc,
7242 "getelementptr vector index has a wrong number of elements");
7243 GEPWidth = ValNumEl;
7250 return Error(Loc,
"base element of getelementptr must be sized");
7253 return Error(Loc,
"invalid getelementptr indices");
7256 cast<GetElementPtrInst>(Inst)->setIsInBounds(
true);
7257 return AteExtraComma ? InstExtraComma : InstNormal;
7262 int LLParser::ParseExtractValue(
Instruction *&Inst, PerFunctionState &PFS) {
7266 if (ParseTypeAndValue(Val, Loc, PFS) ||
7267 ParseIndexList(Indices, AteExtraComma))
7271 return Error(Loc,
"extractvalue operand must be aggregate type");
7274 return Error(Loc,
"invalid indices for extractvalue");
7276 return AteExtraComma ? InstExtraComma : InstNormal;
7281 int LLParser::ParseInsertValue(
Instruction *&Inst, PerFunctionState &PFS) {
7285 if (ParseTypeAndValue(Val0, Loc0, PFS) ||
7286 ParseToken(
lltok::comma,
"expected comma after insertvalue operand") ||
7287 ParseTypeAndValue(Val1, Loc1, PFS) ||
7288 ParseIndexList(Indices, AteExtraComma))
7292 return Error(Loc0,
"insertvalue operand must be aggregate type");
7296 return Error(Loc0,
"invalid indices for insertvalue");
7297 if (IndexedType != Val1->
getType())
7298 return Error(Loc1,
"insertvalue operand and field disagree in type: '" +
7302 return AteExtraComma ? InstExtraComma : InstNormal;
7329 if (ParseMetadata(MD,
nullptr))
7334 return ParseToken(
lltok::rbrace,
"expected end of metadata node");
7343 return Error(Loc,
"value has no uses");
7345 unsigned NumUses = 0;
7347 for (
const Use &U : V->
uses()) {
7348 if (++NumUses > Indexes.
size())
7350 Order[&U] = Indexes[NumUses - 1];
7353 return Error(Loc,
"value only has one use");
7354 if (Order.
size() != Indexes.
size() || NumUses > Indexes.
size())
7367 SMLoc Loc = Lex.getLoc();
7371 return Lex.Error(
"expected non-empty list of uselistorder indexes");
7378 bool IsOrdered =
true;
7379 assert(Indexes.
empty() &&
"Expected empty order vector");
7382 if (ParseUInt32(Index))
7386 Offset += Index - Indexes.
size();
7388 IsOrdered &= Index == Indexes.
size();
7396 if (Indexes.
size() < 2)
7397 return Error(Loc,
"expected >= 2 uselistorder indexes");
7398 if (Offset != 0 || Max >= Indexes.
size())
7399 return Error(Loc,
"expected distinct uselistorder indexes in range [0, size)");
7401 return Error(Loc,
"expected uselistorder indexes to change the order");
7408 bool LLParser::ParseUseListOrder(PerFunctionState *PFS) {
7409 SMLoc Loc = Lex.getLoc();
7415 if (ParseTypeAndValue(V, PFS) ||
7416 ParseToken(
lltok::comma,
"expected comma in uselistorder directive") ||
7417 ParseUseListOrderIndexes(Indexes))
7420 return sortUseListOrder(V, Indexes, Loc);
7425 bool LLParser::ParseUseListOrderBB() {
7427 SMLoc Loc = Lex.getLoc();
7432 if (ParseValID(Fn) ||
7433 ParseToken(
lltok::comma,
"expected comma in uselistorder_bb directive") ||
7434 ParseValID(Label) ||
7435 ParseToken(
lltok::comma,
"expected comma in uselistorder_bb directive") ||
7436 ParseUseListOrderIndexes(Indexes))
7442 GV = M->getNamedValue(Fn.
StrVal);
7444 GV = Fn.
UIntVal < NumberedVals.size() ? NumberedVals[Fn.
UIntVal] :
nullptr;
7446 return Error(Fn.
Loc,
"expected function name in uselistorder_bb");
7448 return Error(Fn.
Loc,
"invalid function forward reference in uselistorder_bb");
7451 return Error(Fn.
Loc,
"expected function name in uselistorder_bb");
7452 if (
F->isDeclaration())
7453 return Error(Fn.
Loc,
"invalid declaration in uselistorder_bb");
7457 return Error(Label.
Loc,
"invalid numeric label in uselistorder_bb");
7459 return Error(Label.
Loc,
"expected basic block name in uselistorder_bb");
7460 Value *V =
F->getValueSymbolTable()->lookup(Label.
StrVal);
7462 return Error(Label.
Loc,
"invalid basic block in uselistorder_bb");
7463 if (!isa<BasicBlock>(V))
7464 return Error(Label.
Loc,
"expected basic block in uselistorder_bb");
7466 return sortUseListOrder(V, Indexes, Loc);
7472 bool LLParser::ParseModuleEntry(
unsigned ID) {
7481 ParseStringConstant(Path) ||
7489 if (ParseUInt32(Hash[0]) || ParseToken(
lltok::comma,
"expected ',' here") ||
7490 ParseUInt32(Hash[1]) || ParseToken(
lltok::comma,
"expected ',' here") ||
7491 ParseUInt32(Hash[2]) || ParseToken(
lltok::comma,
"expected ',' here") ||
7492 ParseUInt32(Hash[3]) || ParseToken(
lltok::comma,
"expected ',' here") ||
7493 ParseUInt32(Hash[4]))
7500 auto ModuleEntry = Index->addModule(Path, ID, Hash);
7501 ModuleIdMap[
ID] = ModuleEntry->first();
7508 bool LLParser::ParseTypeIdEntry(
unsigned ID) {
7517 ParseStringConstant(Name))
7522 ParseTypeIdSummary(TIS) || ParseToken(
lltok::rparen,
"expected ')' here"))
7527 auto FwdRefTIDs = ForwardRefTypeIds.find(ID);
7528 if (FwdRefTIDs != ForwardRefTypeIds.end()) {
7529 for (
auto TIDRef : FwdRefTIDs->second) {
7531 "Forward referenced type id GUID expected to be 0");
7534 ForwardRefTypeIds.erase(FwdRefTIDs);
7546 ParseTypeTestResolution(TIS.
TTRes))
7551 if (ParseOptionalWpdResolutions(TIS.
WPDRes))
7562 ValueInfo(
false, (GlobalValueSummaryMapTy::value_type *)-8);
7568 bool LLParser::ParseTypeIdCompatibleVtableEntry(
unsigned ID) {
7577 ParseStringConstant(Name))
7581 Index->getOrInsertTypeIdCompatibleVtableSummary(Name);
7588 IdToIndexMapType IdToIndexMap;
7594 ParseToken(
lltok::colon,
"expected ':' here") || ParseUInt64(Offset) ||
7598 LocTy Loc = Lex.getLoc();
7601 if (ParseGVReference(VI, GVId))
7608 IdToIndexMap[GVId].push_back(std::make_pair(TI.size(), Loc));
7609 TI.push_back({
Offset, VI});
7617 for (
auto I : IdToIndexMap) {
7618 for (
auto P :
I.second) {
7619 assert(TI[P.first].VTableVI == EmptyVI &&
7620 "Forward referenced ValueInfo expected to be empty");
7621 auto FwdRef = ForwardRefValueInfos.insert(std::make_pair(
7622 I.first, std::vector<std::pair<ValueInfo *, LocTy>>()));
7623 FwdRef.first->second.push_back(
7624 std::make_pair(&TI[P.first].VTableVI, P.second));
7634 auto FwdRefTIDs = ForwardRefTypeIds.find(ID);
7635 if (FwdRefTIDs != ForwardRefTypeIds.end()) {
7636 for (
auto TIDRef : FwdRefTIDs->second) {
7638 "Forward referenced type id GUID expected to be 0");
7641 ForwardRefTypeIds.erase(FwdRefTIDs);
7661 switch (Lex.getKind()) {
7678 return Error(Lex.getLoc(),
"unexpected TypeTestResolution kind");
7690 switch (Lex.getKind()) {
7705 if (ParseToken(
lltok::colon,
"expected ':'") || ParseUInt32(Val))
7718 return Error(Lex.getLoc(),
"expected optional TypeTestResolution field");
7731 bool LLParser::ParseOptionalWpdResolutions(
7732 std::map<uint64_t, WholeProgramDevirtResolution> &WPDResMap) {
7743 ParseToken(
lltok::colon,
"expected ':' here") || ParseUInt64(Offset) ||
7744 ParseToken(
lltok::comma,
"expected ',' here") || ParseWpdRes(WPDRes) ||
7747 WPDResMap[
Offset] = WPDRes;
7772 switch (Lex.getKind()) {
7783 return Error(Lex.getLoc(),
"unexpected WholeProgramDevirtResolution kind");
7789 switch (Lex.getKind()) {
7797 if (ParseOptionalResByArg(WPDRes.
ResByArg))
7801 return Error(Lex.getLoc(),
7802 "expected optional WholeProgramDevirtResolution field");
7819 bool LLParser::ParseOptionalResByArg(
7828 std::vector<uint64_t>
Args;
7829 if (ParseArgs(Args) || ParseToken(
lltok::comma,
"expected ',' here") ||
7838 switch (Lex.getKind()) {
7852 return Error(Lex.getLoc(),
7853 "unexpected WholeProgramDevirtResolution::ByArg kind");
7859 switch (Lex.getKind()) {
7863 ParseUInt64(ByArg.
Info))
7869 ParseUInt32(ByArg.
Byte))
7875 ParseUInt32(ByArg.
Bit))
7879 return Error(Lex.getLoc(),
7880 "expected optional whole program devirt field");
7887 ResByArg[
Args] = ByArg;
7898 bool LLParser::ParseArgs(std::vector<uint64_t> &Args) {
7906 if (ParseUInt64(Val))
7908 Args.push_back(Val);
7917 static const auto FwdVIRef = (GlobalValueSummaryMapTy::value_type *)-8;
7922 assert(!(ReadOnly && WriteOnly));
7932 void LLParser::AddGlobalValueToIndex(
7934 unsigned ID, std::unique_ptr<GlobalValueSummary> Summary) {
7939 VI = Index->getOrInsertValueInfo(GUID);
7943 auto *GV = M->getNamedValue(Name);
7945 VI = Index->getOrInsertValueInfo(GV);
7949 "Need a source_filename to compute GUID for local");
7952 VI = Index->getOrInsertValueInfo(GUID, Index->saveString(Name));
7957 auto FwdRefVIs = ForwardRefValueInfos.find(ID);
7958 if (FwdRefVIs != ForwardRefValueInfos.end()) {
7959 for (
auto VIRef : FwdRefVIs->second) {
7961 "Forward referenced ValueInfo expected to be empty");
7964 ForwardRefValueInfos.erase(FwdRefVIs);
7968 auto FwdRefAliasees = ForwardRefAliasees.find(ID);
7969 if (FwdRefAliasees != ForwardRefAliasees.end()) {
7970 for (
auto AliaseeRef : FwdRefAliasees->second) {
7971 assert(!AliaseeRef.first->hasAliasee() &&
7972 "Forward referencing alias already has aliasee");
7973 assert(Summary &&
"Aliasee must be a definition");
7974 AliaseeRef.first->setAliasee(VI, Summary.get());
7976 ForwardRefAliasees.erase(FwdRefAliasees);
7981 Index->addGlobalValueSummary(VI, std::move(Summary));
7984 if (ID == NumberedValueInfos.size())
7985 NumberedValueInfos.push_back(VI);
7988 if (ID > NumberedValueInfos.size())
7989 NumberedValueInfos.resize(ID + 1);
7990 NumberedValueInfos[
ID] =
VI;
7998 bool LLParser::ParseGVEntry(
unsigned ID) {
8008 switch (Lex.getKind()) {
8012 ParseStringConstant(Name))
8018 if (ParseToken(
lltok::colon,
"expected ':' here") || ParseUInt64(GUID))
8022 return Error(Lex.getLoc(),
"expected name or guid tag");
8048 switch (Lex.getKind()) {
8050 if (ParseFunctionSummary(Name, GUID, ID))
8054 if (ParseVariableSummary(Name, GUID, ID))
8058 if (ParseAliasSummary(Name, GUID, ID))
8062 return Error(Lex.getLoc(),
"expected summary type");
8086 false,
false,
false);
8088 std::vector<FunctionSummary::EdgeTy> Calls;
8090 std::vector<ValueInfo> Refs;
8095 ParseModuleReference(ModulePath) ||
8096 ParseToken(
lltok::comma,
"expected ',' here") || ParseGVFlags(GVFlags) ||
8099 ParseToken(
lltok::colon,
"expected ':' here") || ParseUInt32(InstCount))
8104 switch (Lex.getKind()) {
8106 if (ParseOptionalFFlags(FFlags))
8110 if (ParseOptionalCalls(Calls))
8114 if (ParseOptionalTypeIdInfo(TypeIdInfo))
8118 if (ParseOptionalRefs(Refs))
8122 return Error(Lex.getLoc(),
"expected optional function summary field");
8129 auto FS = std::make_unique<FunctionSummary>(
8130 GVFlags, InstCount, FFlags, 0, std::move(Refs),
8131 std::move(Calls), std::move(TypeIdInfo.
TypeTests),
8137 FS->setModulePath(ModulePath);
8156 false,
false,
false);
8159 std::vector<ValueInfo> Refs;
8163 ParseModuleReference(ModulePath) ||
8164 ParseToken(
lltok::comma,
"expected ',' here") || ParseGVFlags(GVFlags) ||
8166 ParseGVarFlags(GVarFlags))
8171 switch (Lex.getKind()) {
8173 if (ParseOptionalVTableFuncs(VTableFuncs))
8177 if (ParseOptionalRefs(Refs))
8181 return Error(Lex.getLoc(),
"expected optional variable summary field");
8189 std::make_unique<GlobalVarSummary>(GVFlags, GVarFlags, std::move(Refs));
8191 GS->setModulePath(ModulePath);
8192 GS->setVTableFuncs(std::move(VTableFuncs));
8206 LocTy Loc = Lex.getLoc();
8212 false,
false,
false);
8215 ParseModuleReference(ModulePath) ||
8216 ParseToken(
lltok::comma,
"expected ',' here") || ParseGVFlags(GVFlags) ||
8224 if (ParseGVReference(AliaseeVI, GVId))
8230 auto AS = std::make_unique<AliasSummary>(GVFlags);
8232 AS->setModulePath(ModulePath);
8236 auto FwdRef = ForwardRefAliasees.insert(
8237 std::make_pair(GVId, std::vector<std::pair<AliasSummary *, LocTy>>()));
8238 FwdRef.first->second.push_back(std::make_pair(AS.get(), Loc));
8240 auto Summary = Index->findSummaryInModule(AliaseeVI, ModulePath);
8241 assert(Summary &&
"Aliasee must be a definition");
8242 AS->setAliasee(AliaseeVI, Summary);
8253 bool LLParser::ParseFlag(
unsigned &Val) {
8254 if (Lex.getKind() !=
lltok::APSInt || Lex.getAPSIntVal().isSigned())
8255 return TokError(
"expected integer");
8256 Val = (
unsigned)Lex.getAPSIntVal().getBoolValue();
8272 if (ParseToken(
lltok::colon,
"expected ':' in funcFlags") |
8278 switch (Lex.getKind()) {
8281 if (ParseToken(
lltok::colon,
"expected ':'") || ParseFlag(Val))
8287 if (ParseToken(
lltok::colon,
"expected ':'") || ParseFlag(Val))
8293 if (ParseToken(
lltok::colon,
"expected ':'") || ParseFlag(Val))
8299 if (ParseToken(
lltok::colon,
"expected ':'") || ParseFlag(Val))
8305 if (ParseToken(
lltok::colon,
"expected ':'") || ParseFlag(Val))
8311 if (ParseToken(
lltok::colon,
"expected ':'") || ParseFlag(Val))
8316 return Error(Lex.getLoc(),
"expected function flag type");
8330 bool LLParser::ParseOptionalCalls(std::vector<FunctionSummary::EdgeTy> &Calls) {
8334 if (ParseToken(
lltok::colon,
"expected ':' in calls") |
8338 IdToIndexMapType IdToIndexMap;
8347 LocTy Loc = Lex.getLoc();
8349 if (ParseGVReference(VI, GVId))
8357 if (ParseToken(
lltok::colon,
"expected ':'") || ParseHotness(Hotness))
8361 ParseToken(
lltok::colon,
"expected ':'") || ParseUInt32(RelBF))
8369 IdToIndexMap[GVId].push_back(std::make_pair(Calls.size(), Loc));
8378 for (
auto I : IdToIndexMap) {
8379 for (
auto P :
I.second) {
8381 "Forward referenced ValueInfo expected to be empty");
8382 auto FwdRef = ForwardRefValueInfos.insert(std::make_pair(
8383 I.first, std::vector<std::pair<ValueInfo *, LocTy>>()));
8384 FwdRef.first->second.push_back(
8385 std::make_pair(&Calls[P.first].first, P.second));
8398 switch (Lex.getKind()) {
8415 return Error(Lex.getLoc(),
"invalid call edge hotness");
8424 bool LLParser::ParseOptionalVTableFuncs(
VTableFuncList &VTableFuncs) {
8428 if (ParseToken(
lltok::colon,
"expected ':' in vTableFuncs") |
8432 IdToIndexMapType IdToIndexMap;
8436 if (ParseToken(
lltok::lparen,
"expected '(' in vTableFunc") ||
8441 LocTy Loc = Lex.getLoc();
8443 if (ParseGVReference(VI, GVId))
8449 ParseToken(
lltok::colon,
"expected ':'") || ParseUInt64(Offset))
8456 IdToIndexMap[GVId].push_back(std::make_pair(VTableFuncs.size(), Loc));
8457 VTableFuncs.push_back({
VI, Offset});
8459 if (ParseToken(
lltok::rparen,
"expected ')' in vTableFunc"))
8465 for (
auto I : IdToIndexMap) {
8466 for (
auto P :
I.second) {
8467 assert(VTableFuncs[P.first].FuncVI == EmptyVI &&
8468 "Forward referenced ValueInfo expected to be empty");
8469 auto FwdRef = ForwardRefValueInfos.insert(std::make_pair(
8470 I.first, std::vector<std::pair<ValueInfo *, LocTy>>()));
8471 FwdRef.first->second.push_back(
8472 std::make_pair(&VTableFuncs[P.first].FuncVI, P.second));
8476 if (ParseToken(
lltok::rparen,
"expected ')' in vTableFuncs"))
8484 bool LLParser::ParseOptionalRefs(std::vector<ValueInfo> &Refs) {
8492 struct ValueContext {
8497 std::vector<ValueContext> VContexts;
8501 VC.Loc = Lex.getLoc();
8502 if (ParseGVReference(VC.VI, VC.GVId))
8504 VContexts.push_back(VC);
8510 llvm::sort(VContexts, [](
const ValueContext &VC1,
const ValueContext &VC2) {
8511 return VC1.VI.getAccessSpecifier() < VC2.VI.getAccessSpecifier();
8514 IdToIndexMapType IdToIndexMap;
8515 for (
auto &
VC : VContexts) {
8520 IdToIndexMap[
VC.GVId].push_back(std::make_pair(Refs.size(),
VC.Loc));
8521 Refs.push_back(
VC.VI);
8526 for (
auto I : IdToIndexMap) {
8527 for (
auto P :
I.second) {
8529 "Forward referenced ValueInfo expected to be empty");
8530 auto FwdRef = ForwardRefValueInfos.insert(std::make_pair(
8531 I.first, std::vector<std::pair<ValueInfo *, LocTy>>()));
8532 FwdRef.first->second.push_back(std::make_pair(&Refs[P.first], P.second));
8546 bool LLParser::ParseOptionalTypeIdInfo(
8556 switch (Lex.getKind()) {
8558 if (ParseTypeTests(TypeIdInfo.
TypeTests))
8582 return Error(Lex.getLoc(),
"invalid typeIdInfo list type");
8586 if (ParseToken(
lltok::rparen,
"expected ')' in typeIdInfo"))
8595 bool LLParser::ParseTypeTests(std::vector<GlobalValue::GUID> &TypeTests) {
8603 IdToIndexMapType IdToIndexMap;
8607 unsigned ID = Lex.getUIntVal();
8608 LocTy Loc = Lex.getLoc();
8612 IdToIndexMap[
ID].push_back(std::make_pair(TypeTests.size(), Loc));
8614 }
else if (ParseUInt64(GUID))
8616 TypeTests.push_back(GUID);
8621 for (
auto I : IdToIndexMap) {
8622 for (
auto P :
I.second) {
8623 assert(TypeTests[P.first] == 0 &&
8624 "Forward referenced type id GUID expected to be 0");
8625 auto FwdRef = ForwardRefTypeIds.insert(std::make_pair(
8626 I.first, std::vector<std::pair<GlobalValue::GUID *, LocTy>>()));
8627 FwdRef.first->second.push_back(
8628 std::make_pair(&TypeTests[P.first], P.second));
8632 if (ParseToken(
lltok::rparen,
"expected ')' in typeIdInfo"))
8640 bool LLParser::ParseVFuncIdList(
8641 lltok::Kind Kind, std::vector<FunctionSummary::VFuncId> &VFuncIdList) {
8649 IdToIndexMapType IdToIndexMap;
8652 if (ParseVFuncId(VFuncId, IdToIndexMap, VFuncIdList.size()))
8654 VFuncIdList.push_back(VFuncId);
8662 for (
auto I : IdToIndexMap) {
8663 for (
auto P :
I.second) {
8664 assert(VFuncIdList[P.first].GUID == 0 &&
8665 "Forward referenced type id GUID expected to be 0");
8666 auto FwdRef = ForwardRefTypeIds.insert(std::make_pair(
8667 I.first, std::vector<std::pair<GlobalValue::GUID *, LocTy>>()));
8668 FwdRef.first->second.push_back(
8669 std::make_pair(&VFuncIdList[P.first].GUID, P.second));
8678 bool LLParser::ParseConstVCallList(
8680 std::vector<FunctionSummary::ConstVCall> &ConstVCallList) {
8688 IdToIndexMapType IdToIndexMap;
8691 if (ParseConstVCall(ConstVCall, IdToIndexMap, ConstVCallList.size()))
8693 ConstVCallList.push_back(ConstVCall);
8701 for (
auto I : IdToIndexMap) {
8702 for (
auto P :
I.second) {
8703 assert(ConstVCallList[P.first].VFunc.GUID == 0 &&
8704 "Forward referenced type id GUID expected to be 0");
8705 auto FwdRef = ForwardRefTypeIds.insert(std::make_pair(
8706 I.first, std::vector<std::pair<GlobalValue::GUID *, LocTy>>()));
8707 FwdRef.first->second.push_back(
8708 std::make_pair(&ConstVCallList[P.first].VFunc.GUID, P.second));
8718 IdToIndexMapType &IdToIndexMap,
unsigned Index) {
8720 ParseVFuncId(ConstVCall.
VFunc, IdToIndexMap, Index))
8724 if (ParseArgs(ConstVCall.
Args))
8737 IdToIndexMapType &IdToIndexMap,
unsigned Index) {
8747 unsigned ID = Lex.getUIntVal();
8748 LocTy Loc = Lex.getLoc();
8752 IdToIndexMap[
ID].push_back(std::make_pair(Index, Loc));
8756 ParseUInt64(VFuncId.
GUID))
8762 ParseUInt64(VFuncId.
Offset) ||
8783 switch (Lex.getKind()) {
8790 assert(HasLinkage &&
"Linkage not optional in summary entry");
8795 if (ParseToken(
lltok::colon,
"expected ':'") || ParseFlag(Flag))
8801 if (ParseToken(
lltok::colon,
"expected ':'") || ParseFlag(Flag))
8807 if (ParseToken(
lltok::colon,
"expected ':'") || ParseFlag(Flag))
8813 if (ParseToken(
lltok::colon,
"expected ':'") || ParseFlag(Flag))
8818 return Error(Lex.getLoc(),
"expected gv flag type");
8839 auto ParseRest = [
this](
unsigned int &Val) {
8843 return ParseFlag(Val);
8848 switch (Lex.getKind()) {
8850 if (ParseRest(Flag))
8855 if (ParseRest(Flag))
8860 return Error(Lex.getLoc(),
"expected gvar flag type");
8868 bool LLParser::ParseModuleReference(
StringRef &ModulePath) {
8875 unsigned ModuleID = Lex.getUIntVal();
8876 auto I = ModuleIdMap.find(ModuleID);
8878 assert(
I != ModuleIdMap.end());
8879 ModulePath =
I->second;
8885 bool LLParser::ParseGVReference(
ValueInfo &
VI,
unsigned &GVId) {
8892 GVId = Lex.getUIntVal();
8894 if (GVId < NumberedValueInfos.size()) {
8896 VI = NumberedValueInfos[GVId];
void setVisibility(VisibilityTypes V)
MSVC calling convention that passes vectors and vector aggregates in SSE registers.
void sortUseList(Compare Cmp)
Sort the use-list.
bool parseStandaloneConstantValue(Constant *&C, const SlotMapping *Slots)
static ConstantInt * getFalse(LLVMContext &Context)
reference emplace_back(ArgTypes &&... Args)
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
*ViewGraph Emit a dot run run gv on the postscript file
std::vector< TypeIdOffsetVtableInfo > TypeIdCompatibleVtableInfo
List of vtable definitions decorated by a particular type identifier, and their corresponding offsets...
Calling convention used for Mesa/AMDPAL hull shaders (= tessellation control shaders).
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
unsigned Live
In per-module summary, indicate that the global value must be considered a live root for index-based ...
static Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true)
This method constructs a CDS and initializes it with a text string.
void setFastMathFlags(FastMathFlags FMF)
Convenience function for setting multiple fast-math flags on this instruction, which must be an opera...
iterator_range< use_iterator > uses()
static IntegerType * getInt1Ty(LLVMContext &C)
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
Special purpose, only applies to global arrays.
MaybeAlign getAlignment() const
Retrieve the alignment attribute, if it exists.
uint64_t getZExtValue() const
Get zero extended value.
*p = old <signed v ? old : v
This class represents an incoming formal argument to a Function.
void UpgradeSectionAttributes(Module &M)
The C convention as specified in the x86-64 supplement to the System V ABI, used on most non-Windows ...
bool isMetadataTy() const
Return true if this is 'metadata'.
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
This class represents lattice values for constants.
unsigned Linkage
The linkage type of the associated global value.
static bool isValidOperands(const Value *Vec, const Value *NewElt, const Value *Idx)
Return true if an insertelement instruction can be formed with the specified operands.
Calling convention used by HipHop Virtual Machine (HHVM) to perform calls to and from translation cac...
A Module instance is used to store all the information related to an LLVM module. ...
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant *> IdxList, bool InBounds=false, Optional< unsigned > InRangeIndex=None, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
bool isSized(SmallPtrSetImpl< Type *> *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
static ResumeInst * Create(Value *Exn, Instruction *InsertBefore=nullptr)
An instruction for ordering other memory operations.
Same, but only replaced by something equivalent.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
An instruction that atomically checks whether a specified value is in a memory location, and, if it is, stores a new value there.
static MDString * get(LLVMContext &Context, StringRef Str)
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Unsatisfiable type (i.e. no global has this type metadata)
Available for inspection, not emission.
void push_back(const T &Elt)
void addCase(ConstantInt *OnVal, BasicBlock *Dest)
Add an entry to the switch instruction.
const ValueSymbolTable & getValueSymbolTable() const
Get the symbol table of global variable and function identifiers.
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value *> IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
void addOperand(MDNode *M)
This class represents a function call, abstracting a target machine's calling convention.
SyncScope::ID getOrInsertSyncScopeID(StringRef SSN)
getOrInsertSyncScopeID - Maps synchronization scope name to synchronization scope ID...
void setGC(std::string Str)
void emplace(ArgTypes &&... Args)
Create a new object by constructing it in place with the given arguments.
static DISPFlags toSPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized, unsigned Virtuality=SPFlagNonvirtual, bool IsMainSubprogram=false)
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space...
The two locations do not alias at all.
*p = old <unsigned v ? old : v
static Constant * getExtractElement(Constant *Vec, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
void setVolatile(bool V)
Specify whether this is a volatile cmpxchg.
0 1 0 0 True if ordered and less than
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM...
uint64_t Info
Additional information for the resolution:
Like Internal, but omit from symbol table.
iterator find(StringRef Key)
bool parseTypeAtBeginning(Type *&Ty, unsigned &Read, const SlotMapping *Slots)
*p = old >unsigned v ? old : v
This instruction constructs a fixed permutation of two input vectors.
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", Instruction *InsertBefore=nullptr, Instruction *MDFrom=nullptr)
Externally visible function.
NamedMDNode * getOrInsertNamedMetadata(StringRef Name)
Return the named MDNode in the module with the specified name.
LLVMContext & getContext() const
All values hold a context through their type.
bool isTerminator() const
std::vector< VFuncId > TypeTestAssumeVCalls
List of virtual calls made by this function using (respectively) llvm.assume(llvm.type.test) or llvm.type.checked.load intrinsics that do not have all constant integer arguments.
void setDataLayout(StringRef Desc)
Set the data layout.
1 1 1 0 True if unordered or not equal
void deleteValue()
Delete a pointer to a generic Value.
The data referenced by the COMDAT must be the same size.
C - The default llvm calling convention, compatible with C.
AttrBuilder & addDereferenceableAttr(uint64_t Bytes)
This turns the number of dereferenceable bytes into the form used internally in Attribute.
static bool isValidReturnType(Type *RetTy)
Return true if the specified type is valid as a return type.
const fltSemantics & getSemantics() const
param_iterator param_end() const
An instruction for reading from memory.
void setIgnoreColonInIdentifiers(bool val)
const GlobalListType & getGlobalList() const
Get the Module's list of global variables (constant).
AttrBuilder & addAttribute(Attribute::AttrKind Val)
Add an attribute to the builder.
an instruction that atomically reads a memory location, combines it with another value, and then stores the result back.
Calling convention used for AMDPAL vertex shader if tessellation is in use.
bool isVectorTy() const
True if this is an instance of VectorType.
const APFloat & getAPFloatVal() const
Calling convention between AArch64 SVE functions.
static bool isValidArgumentType(Type *ArgTy)
Return true if the specified type is valid as an argument type.
std::string getGlobalIdentifier() const
Return the modified name for this global value suitable to be used as the key for a global lookup (e...
static GlobalValue * createGlobalFwdRef(Module *M, PointerType *PTy, const std::string &Name)
unsigned getVirtuality(StringRef VirtualityString)
*p = old >signed v ? old : v
Virtual constant propagation.
static CallBrInst * Create(FunctionType *Ty, Value *Func, BasicBlock *DefaultDest, ArrayRef< BasicBlock *> IndirectDests, ArrayRef< Value *> Args, const Twine &NameStr, Instruction *InsertBefore=nullptr)
std::map< uint64_t, WholeProgramDevirtResolution > WPDRes
Mapping from byte offset to whole-program devirt resolution for that (typeid, byte offset) pair...
bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return true if the attribute exists at the given index.
static Constant * get(ArrayType *T, ArrayRef< Constant *> V)
LegalityPredicate isVector(unsigned TypeIdx)
True iff the specified type index is a vector.
static Optional< ChecksumKind > getChecksumKind(StringRef CSKindStr)
static LandingPadInst * Create(Type *RetTy, unsigned NumReservedClauses, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedClauses is a hint for the number of incoming clauses that this landingpad w...
Calling convention used for Mesa/AMDPAL geometry shaders.
unsigned getBitWidth() const
Return the number of bits in the APInt.
static bool isLocalLinkage(LinkageTypes Linkage)
static Constant * getInsertElement(Constant *Vec, Constant *Elt, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
void setVolatile(bool V)
Specify whether this is a volatile RMW or not.
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
const AliasListType & getAliasList() const
Get the Module's list of aliases (constant).
static ReturnInst * Create(LLVMContext &C, Value *retVal=nullptr, Instruction *InsertBefore=nullptr)
bool Run()
Run: module ::= toplevelentity*.
1 0 0 1 True if unordered or equal
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
unsigned NotEligibleToImport
Indicate if the global value cannot be imported (e.g.
std::map< unsigned, TrackingMDNodeRef > MetadataNodes
static bool castIsValid(Instruction::CastOps op, Value *S, Type *DstTy)
This method can be used to determine if a cast from S to DstTy using Opcode op is valid or not...
SPIR_KERNEL - Calling convention for SPIR kernel functions.
static Type * getTokenTy(LLVMContext &C)
bool hasAttributes() const
Return true if the builder has IR-level attributes.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
bool hasAlignmentAttr() const
Return true if the builder has an alignment attribute.
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...
void UpgradeCallsToIntrinsic(Function *F)
This is an auto-upgrade hook for any old intrinsic function syntaxes which need to have both the func...
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
bool isFloatingPointTy() const
Return true if this is one of the six floating-point types.
void setInitializer(Constant *InitVal)
setInitializer - Sets the initializer for this global variable, removing any existing initializer if ...
When retpoline mitigation is enabled, use a branch funnel that is defined in the merged module...
bool isStrongerThan(AtomicOrdering ao, AtomicOrdering other)
Returns true if ao is stronger than other as defined by the AtomicOrdering lattice, which is based on C++'s definition.
const ComdatSymTabType & getComdatSymbolTable() const
Get the Module's symbol table for COMDATs (constant).
Class to represent struct types.
APSInt extOrTrunc(uint32_t width) const
A Use represents the edge between a Value definition and its users.
PointerType * getPointerTo(unsigned AddrSpace=0) const
Return a pointer to the current type.
std::vector< ConstVCall > TypeCheckedLoadConstVCalls
bool isIntegerTy() const
True if this is an instance of IntegerType.
void setThreadLocalMode(ThreadLocalMode Val)
static GlobalIFunc * create(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name, Constant *Resolver, Module *Parent)
If a parent module is specified, the ifunc is automatically inserted into the end of the specified mo...
std::array< uint32_t, 5 > ModuleHash
160 bits SHA1
AttrBuilder & addAllocSizeAttr(unsigned ElemSizeArg, const Optional< unsigned > &NumElemsArg)
This turns one (or two) ints into the form used internally in Attribute.
0 1 0 1 True if ordered and less than or equal
TypeID
Definitions of all of the base types for the Type system.
Just do a regular virtual call.
The linker may choose any COMDAT.
AttrBuilder & addByValAttr(Type *Ty)
This turns a byval type into the form used internally in Attribute.
void setName(const Twine &Name)
Change the name of the value.
static const unsigned MaximumAlignment
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
void setDLLStorageClass(DLLStorageClassTypes C)
static StructType * get(LLVMContext &Context, ArrayRef< Type *> Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
AtomicOrdering
Atomic ordering for LLVM's memory model.
enum llvm::WholeProgramDevirtResolution::Kind TheKind
static bool isValidOperands(const Value *V1, const Value *V2, const Value *Mask)
Return true if a shufflevector instruction can be formed with the specified operands.
void addHandler(BasicBlock *Dest)
Add an entry to the switch instruction...
static StringRef getOperationName(BinOp Op)
void setPartition(StringRef Part)
Uniform return value optimization.
llvm::Optional< Function * > remangleIntrinsicFunction(Function *F)
Class to represent function types.
static Type * getLabelTy(LLVMContext &C)
Type * getType() const
All values are typed, get the type of this value.
bool isFirstClassType() const
Return true if the type is "first class", meaning it is a valid type for a Value. ...
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
LLVM_NODISCARD AttributeList removeAttributes(LLVMContext &C, unsigned Index, const AttrBuilder &AttrsToRemove) const
Remove the specified attributes at the specified index from this attribute list.
std::pair< ValueInfo, CalleeInfo > EdgeTy
<CalleeValueInfo, CalleeInfo> call edge pair.
BinOp
This enumeration lists the possible modifications atomicrmw can make.
Class to represent array types.
VisibilityTypes
An enumeration for the kinds of visibility of global values.
static bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
This instruction compares its operands according to the predicate given to the constructor.
static Constant * getSelect(Constant *C, Constant *V1, Constant *V2, Type *OnlyIfReducedTy=nullptr)
Select constant expr.
void setComdat(Comdat *C)
unsigned getUIntVal() const
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type. ...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
static bool Verify(FunctionType *Ty, StringRef Constraints)
Verify - This static method can be used by the parser to check to see if the specified constraint str...
An instruction for storing to memory.
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
static const fltSemantics & IEEEdouble() LLVM_READNONE
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
PTX_Kernel - Call to a PTX kernel.
void setBody(ArrayRef< Type *> Elements, bool isPacked=false)
Specify a body for an opaque identified type.
Calling convention used for AVR signal routines.
Class to represent pointers.
auto count(R &&Range, const E &Element) -> typename std::iterator_traits< decltype(adl_begin(Range))>::difference_type
Wrapper function around std::count to count the number of times an element Element occurs in the give...
Flag
These should be considered private to the implementation of the MCInstrDesc class.
bool UpgradeModuleFlags(Module &M)
This checks for module flags which should be upgraded.
Calling convention used for Mesa/AMDPAL compute shaders.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
AttributeSet getAttributes(unsigned Index) const
The attributes for the specified index are returned.
The C convention as implemented on Windows/x86-64 and AArch64.
X86_INTR - x86 hardware interrupt context.
bool isVoidTy() const
Return true if this is 'void'.
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
ExternalWeak linkage description.
static Constant * getInsertValue(Constant *Agg, Constant *Val, ArrayRef< unsigned > Idxs, Type *OnlyIfReducedTy=nullptr)
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata *> MDs)
Return a temporary node.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
void setCallingConv(CallingConv::ID CC)
const char * getPointer() const
Same, but only replaced by something equivalent.
Intel_OCL_BI - Calling conventions for Intel OpenCL built-ins.
No other Module may specify this COMDAT.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
bool isLabelTy() const
Return true if this is 'label'.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static AttributeSet get(LLVMContext &C, const AttrBuilder &B)
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
LLVM Basic Block Representation.
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
static unsigned parseOptionalLinkageAux(lltok::Kind Kind, bool &HasLinkage)
The instances of the Type class are immutable: once they are created, they are never changed...
PowerPC Reduce CR logical Operation
bool shouldDiscardValueNames() const
Return true if the Context runtime configuration is set to discard all value names.
static BlockAddress * get(Function *F, BasicBlock *BB)
Return a BlockAddress for the specified function and basic block.
size_t size() const
size - Get the array size.
This function has undefined behavior.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
Resume the propagation of an exception.
const APSInt & getAPSIntVal() const
unsigned getCallingConvention(StringRef LanguageString)
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata *> MDs)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
void setUsedWithInAlloca(bool V)
Specify whether this alloca is used to represent the arguments to a call.
std::vector< uint64_t > Args
bool isPointerTy() const
True if this is an instance of PointerType.
Indirect Branch Instruction.
ARM_AAPCS - ARM Architecture Procedure Calling Standard calling convention (aka EABI).
void setExternallyInitialized(bool Val)
unsigned getOperationEncoding(StringRef OperationEncodingString)
StringMap< Type * > NamedTypes
bool UpgradeDebugInfo(Module &M)
Check the debug info version number, if it is out-dated, drop the debug info.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Class to accumulate and hold information about a callee.
static bool isValidLinkage(LinkageTypes L)
static Constant * getShuffleVector(Constant *V1, Constant *V2, Constant *Mask, Type *OnlyIfReducedTy=nullptr)
param_iterator param_begin() const
A pair of DIGlobalVariable and DIExpression.
void splice(iterator where, iplist_impl &L2)
Single element (last example in "Short Inline Bit Vectors")
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
AttrBuilder & addAlignmentAttr(MaybeAlign Align)
This turns an alignment into the form used internally in Attribute.
This instruction compares its operands according to the predicate given to the constructor.
unsigned getAddressSpace() const
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
void setCallingConv(CallingConv::ID CC)
DLLStorageClassTypes
Storage classes of global values for PE targets.
static FunctionType * get(Type *Result, ArrayRef< Type *> Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
static Constant * get(StructType *T, ArrayRef< Constant *> V)
0 1 1 1 True if ordered (no nans)
static bool isValueValidForType(Type *Ty, const APFloat &V)
Return true if Ty is big enough to represent V.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
MSP430_INTR - Calling convention used for MSP430 interrupt routines.
static Constant * getICmp(unsigned short pred, Constant *LHS, Constant *RHS, bool OnlyIfReduced=false)
get* - Return some common constants without having to specify the full Instruction::OPCODE identifier...
ChecksumKind
Which algorithm (e.g.
enum llvm::WholeProgramDevirtResolution::ByArg::Kind TheKind
The data referenced by the COMDAT must be the same.
All type identifier related information.
void setTailCallKind(TailCallKind TCK)
std::vector< GlobalValue * > GlobalValues
void setConstant(bool Val)
lltok::Kind getKind() const
unsigned getLanguage(StringRef LanguageString)
1 1 1 1 Always true (always folded)
DebugNameTableKind getNameTableKind() const
std::map< unsigned, Type * > Types
static bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Comdat * getOrInsertComdat(StringRef Name)
Return the Comdat in the module with the specified name.
This class represents the va_arg llvm instruction, which returns an argument of the specified type gi...
static UnaryOperator * Create(UnaryOps Op, Value *S, const Twine &Name=Twine(), Instruction *InsertBefore=nullptr)
Construct a unary instruction, given the opcode and an operand.
static bool isAtomic(Instruction *I)
enum llvm::ValID::@356 Kind
static wasm::ValType getType(const TargetRegisterClass *RC)
PTX_Device - Call to a PTX device function.
1 1 0 1 True if unordered, less than, or equal
std::string & str()
Flushes the stream contents to the target string and returns the string's reference.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
static IndirectBrInst * Create(Value *Address, unsigned NumDests, Instruction *InsertBefore=nullptr)
const IFuncListType & getIFuncList() const
Get the Module's list of ifuncs (constant).
CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...
An imported module (C++ using directive or similar).
Synchronized with respect to all concurrently executing threads.
unsigned getTag(StringRef TagString)
An "identifier" for a virtual function.
void sort(IteratorTy Start, IteratorTy End)
Struct that holds a reference to a particular GUID in a global value summary.
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata *> MDs)
Return a distinct node.
BaseType
A given derived pointer can have multiple base pointers through phi/selects.
global_iterator global_end()
Register calling convention used for parameters transfer optimization.
static Constant * getFCmp(unsigned short pred, Constant *LHS, Constant *RHS, bool OnlyIfReduced=false)
0 0 1 0 True if ordered and greater than
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
const InstListType & getInstList() const
Return the underlying instruction list container.
std::vector< VFuncId > TypeCheckedLoadVCalls
static const fltSemantics & IEEEsingle() LLVM_READNONE
Iterator for intrusive lists based on ilist_node.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the generic address space (address sp...
static bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
static bool isValidVisibilityForLinkage(unsigned V, unsigned L)
void setSelectionKind(SelectionKind Val)
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
static DISPFlags getFlag(StringRef Flag)
static const fltSemantics & IEEEhalf() LLVM_READNONE
Align max(MaybeAlign Lhs, Align Rhs)
static CleanupPadInst * Create(Value *ParentPad, ArrayRef< Value *> Args=None, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
static CatchSwitchInst * Create(Value *ParentPad, BasicBlock *UnwindDest, unsigned NumHandlers, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
ARM_AAPCS_VFP - Same as ARM_AAPCS, but uses hard floating point ABI.
bool contains(Attribute::AttrKind A) const
Return true if the builder has the specified attribute.
static SwitchInst * Create(Value *Value, BasicBlock *Default, unsigned NumCases, Instruction *InsertBefore=nullptr)
This struct is a compact representation of a valid (power of two) or undefined (0) alignment...
AttrBuilder & removeAttribute(Attribute::AttrKind Val)
Remove an attribute from the builder.
ARM_APCS - ARM Procedure Calling Standard calling convention (obsolete, but still used on some target...
Calling convention used for Mesa/AMDPAL pixel shaders.
1 1 0 0 True if unordered or less than
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Keep one copy of function when linking (inline)
Module.h This file contains the declarations for the Module class.
Type::subtype_iterator param_iterator
X86_StdCall - stdcall is the calling conventions mostly used by the Win32 API.
Single implementation devirtualization.
void addMetadata(unsigned KindID, MDNode &MD)
Add a metadata attachment.
This class represents a freeze function that returns random concrete value if an operand is either a ...
bool isAggregateType() const
Return true if the type is an aggregate type.
Type * getReturnType() const
unsigned getProgramAddressSpace() const
#define GET_OR_DISTINCT(CLASS, ARGS)
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
The linker will choose the largest COMDAT.
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
static Constant * get(Type *Ty, double V)
This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in...
AttrBuilder & addStackAlignmentAttr(MaybeAlign Align)
This turns a stack alignment into the form used internally in Attribute.
static ConstantInt * getTrue(LLVMContext &Context)
void setAttributes(AttributeList Attrs)
Set the attribute list for this Function.
void setLinkage(LinkageTypes LT)
std::string SingleImplName
enum llvm::TypeTestResolution::Kind TheKind
ValueSymbolTable * getValueSymbolTable()
getSymbolTable() - Return the symbol table if any, otherwise nullptr.
DebugEmissionKind getEmissionKind() const
unsigned getVectorNumElements() const
MDNode * UpgradeTBAANode(MDNode &TBAANode)
If the given TBAA tag uses the scalar TBAA format, create a new node corresponding to the upgrade to ...
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
This file contains constants used for implementing Dwarf debug support.
static DIFlags getFlag(StringRef Flag)
void push_back(pointer val)
A specification for a virtual function call with all constant integer arguments.
LinkageTypes
An enumeration for the kinds of linkage for global values.
X86_FastCall - 'fast' analog of X86_StdCall.
amdgpu Simplify well known AMD library false FunctionCallee Callee
A (clang) module that has been imported by the compile unit.
static BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name=Twine(), Instruction *InsertBefore=nullptr)
Construct a binary instruction, given the opcode and the two operands.
void setWeak(bool IsWeak)
SPIR_FUNC - Calling convention for SPIR non-kernel device functions.
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
void setAttributes(AttributeSet A)
Set attribute list for this global.
Generic tagged DWARF-like metadata node.
This struct contains the mappings from the slot numbers to unnamed metadata nodes, global values and types.
A utility class that uses RAII to save and restore the value of a variable.
FunctionNumber(functionNumber)
static CatchPadInst * Create(Value *CatchSwitch, ArrayRef< Value *> Args, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
void setSwiftError(bool V)
Specify whether this alloca is used to represent a swifterror.
const std::string & getStrVal() const
Type array for a subprogram.
Test a byte array (first example)
static std::string getTypeString(Type *T)
static CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
Function to be accessible from DLL.
void eraseFromParent()
This method unlinks 'this' from the containing module and deletes it.
unsigned getNumUses() const
This method computes the number of uses of this Value.
std::map< std::vector< uint64_t >, ByArg > ResByArg
Resolutions for calls with all constant integer arguments (excluding the first argument, "this"), where the key is the argument vector.
bool isFunctionTy() const
True if this is an instance of FunctionType.
ValID - Represents a reference of a definition of some sort with no type.
void setAlignment(MaybeAlign Align)
pointer data()
Return a pointer to the vector's buffer, even if empty().
iterator_range< typename GraphTraits< GraphType >::nodes_iterator > nodes(const GraphType &G)
void setUnnamedAddr(UnnamedAddr Val)
StringRef filename(StringRef path, Style style=Style::native)
Get filename.
static Type * getIndexedType(Type *Ty, ArrayRef< Value *> IdxList)
Returns the type of the element that would be loaded with a load instruction with the specified param...
Linkage
Describes symbol linkage.
LLVM_NODISCARD bool empty() const
unsigned greater or equal
uint64_t getLimitedValue(uint64_t Limit=UINT64_MAX) const
If this value is smaller than the specified limit, return it, otherwise return the limit value...
static InvokeInst * Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value *> Args, const Twine &NameStr, Instruction *InsertBefore=nullptr)
All-ones bit vector ("Eliminating Bit Vector Checks for All-Ones Bit Vectors") ...
unsigned DSOLocal
Indicates that the linker resolved the symbol to a definition from within the same linkage unit...
bool isTokenTy() const
Return true if this is 'token'.
static bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
void setSourceFileName(StringRef Name)
Set the module's original source file name.
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
static InsertValueInst * Create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
ParseRet
Utilities for the Vector Function ABI name parser.
StringRef getName() const
Return a constant reference to the value's name.
LLVM_NODISCARD AttributeList removeAttribute(LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const
Remove the specified attribute at the specified index from this attribute list.
unsigned CanAutoHide
In the per-module summary, indicates that the global value is linkonce_odr and global unnamed addr (s...
Calling convention used for Mesa vertex shaders, or AMDPAL last shader stage before rasterization (ve...
void setPrologueData(Constant *PrologueData)
void appendModuleInlineAsm(StringRef Asm)
Append to the module-scope inline assembly blocks.
std::unique_ptr< Constant *[]> ConstantStructElts
0 1 1 0 True if ordered and operands are unequal
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
void setAttributes(AttributeList A)
Set the parameter attributes for this call.
void setTargetTriple(StringRef T)
Set the target triple.
static const auto FwdVIRef
static void resolveFwdRef(ValueInfo *Fwd, ValueInfo &Resolved)
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Type * getValueType() const
Keep one copy of named function when linking (weak)
Rename collisions when linking (static functions).
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it...
Flags specific to function summaries.
static InlineAsm * get(FunctionType *Ty, StringRef AsmString, StringRef Constraints, bool hasSideEffects, bool isAlignStack=false, AsmDialect asmDialect=AD_ATT)
InlineAsm::get - Return the specified uniqued inline asm string.
Tail - This calling convention attemps to make calls as fast as possible while guaranteeing that tail...
Inlined bit vector ("Short Inline Bit Vectors")
unsigned SizeM1BitWidth
Range of size-1 expressed as a bit width.
1 0 1 0 True if unordered or greater than
Value * lookup(StringRef Name) const
This method finds the value with the given Name in the the symbol table.
DISPFlags
Debug info subprogram flags.
Function to be imported from DLL.
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
unsigned getMacinfo(StringRef MacinfoString)
LLVM_NODISCARD AttributeList addAttributes(LLVMContext &C, unsigned Index, const AttrBuilder &B) const
Add attributes to the attribute set at the given index.
void addDestination(BasicBlock *Dest)
Add a destination.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
AttrBuilder & merge(const AttrBuilder &B)
Add the attributes from the builder.
static DICompositeType * buildODRType(LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name, Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, DIFlags Flags, Metadata *Elements, unsigned RuntimeLang, Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator)
Build a DICompositeType with the given ODR identifier.
Deduce and propagate attributes
unsigned getMDKindID(StringRef Name) const
Return a unique non-zero ID for the specified metadata kind.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Special calling convention on Windows for calling the Control Guard Check ICall funtion.
std::vector< VirtFuncOffset > VTableFuncList
List of functions referenced by a particular vtable definition.
A raw_ostream that writes to an std::string.
static CatchReturnInst * Create(Value *CatchPad, BasicBlock *BB, Instruction *InsertBefore=nullptr)
0 0 0 1 True if ordered and equal
LLVM Value Representation.
Fast - This calling convention attempts to make calls as fast as possible (e.g.
1 0 1 1 True if unordered, greater than, or equal
Just do a regular virtual call.
static StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
Lightweight error class with error context and mandatory checking.
static CleanupReturnInst * Create(Value *CleanupPad, BasicBlock *UnwindBB=nullptr, Instruction *InsertBefore=nullptr)
AttributeSet getFnAttributes() const
The function attributes are returned.
unsigned getAttributeEncoding(StringRef EncodingString)
This file provides utility classes that use RAII to save and restore values.
Group flags (Linkage, NotEligibleToImport, etc.) as a bitfield.
#define PARSE_MD_FIELDS()
static Constant * getExtractValue(Constant *Agg, ArrayRef< unsigned > Idxs, Type *OnlyIfReducedTy=nullptr)
Convenience struct for specifying and reasoning about fast-math flags.
StringRef - Represent a constant reference to a string, i.e.
void setPersonalityFn(Constant *Fn)
const GlobalValueSummaryMapTy::value_type * getRef() const
static void maybeSetDSOLocal(bool DSOLocal, GlobalValue &GV)
static bool isVolatile(Instruction *Inst)
Represents a location in source code.
static bool isValidDeclarationLinkage(LinkageTypes Linkage)
0 0 1 1 True if ordered and greater than or equal
unsigned ReturnDoesNotAlias
Calling convention for AMDGPU code object kernels.
Used for AVR interrupt routines.
static IntegerType * getInt8Ty(LLVMContext &C)
void setSection(StringRef S)
Change the section for this global.
HHVM calling convention for invoking C/C++ helpers.
static GlobalAlias * create(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name, Constant *Aliasee, Module *Parent)
If a parent module is specified, the alias is automatically inserted into the end of the specified mo...
static Constant * get(ArrayRef< Constant *> V)
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Type * getElementType() const
void setDSOLocal(bool Local)
PointerType * getType() const
Global values are always pointers.
X86_ThisCall - Similar to X86_StdCall.
static AttributeList get(LLVMContext &C, ArrayRef< std::pair< unsigned, Attribute >> Attrs)
Create an AttributeList with the specified parameters in it.
iterator_range< arg_iterator > args()
0 0 0 0 Always false (always folded)
Unique return value optimization.
bool isArrayTy() const
True if this is an instance of ArrayType.
Calling convention used for AMDPAL shader stage before geometry shader if geometry is in use...
std::vector< GlobalValue::GUID > TypeTests
List of type identifiers used by this function in llvm.type.test intrinsics referenced by something o...
an instruction to allocate memory on the stack
Basic type, like 'int' or 'float'.
static bool parseField(amd_kernel_code_t &C, MCAsmParser &MCParser, raw_ostream &Err)
void setPrefixData(Constant *PrefixData)
std::vector< ConstVCall > TypeTestAssumeConstVCalls
List of virtual calls made by this function using (respectively) llvm.assume(llvm.type.test) or llvm.type.checked.load intrinsics with all constant integer arguments.
static Constant * get(unsigned Opcode, Constant *C1, unsigned Flags=0, Type *OnlyIfReducedTy=nullptr)
get - Return a unary operator constant expression, folding if possible.
static const char * areInvalidOperands(Value *Cond, Value *True, Value *False)
Return a string if the specified operands are invalid for a select operation, otherwise return null...