72 "Can't read textual IR with a Context that discards named Values");
74 return ParseTopLevelEntities() || ValidateEndOfModule() ||
80 restoreParsingState(Slots);
84 if (ParseType(Ty) || parseConstantValue(Ty, C))
87 return Error(Lex.
getLoc(),
"expected end of string");
93 restoreParsingState(Slots);
107 void LLParser::restoreParsingState(
const SlotMapping *Slots) {
114 std::make_pair(
I.getKey(), std::make_pair(
I.second,
LocTy())));
115 for (
const auto &
I : Slots->
Types)
116 NumberedTypes.insert(
117 std::make_pair(
I.first, std::make_pair(
I.second,
LocTy())));
122 bool LLParser::ValidateEndOfModule() {
126 for (
const auto &RAG : ForwardRefAttrGroups) {
127 Value *V = RAG.first;
128 const std::vector<unsigned> &
Attrs = RAG.second;
131 for (
const auto &Attr : Attrs)
132 B.
merge(NumberedAttrBuilders[Attr]);
134 if (
Function *Fn = dyn_cast<Function>(V)) {
143 if (FnAttrs.hasAlignmentAttr()) {
144 Fn->setAlignment(FnAttrs.getAlignment());
150 Fn->setAttributes(AS);
151 }
else if (
CallInst *CI = dyn_cast<CallInst>(V)) {
158 CI->setAttributes(AS);
159 }
else if (
InvokeInst *II = dyn_cast<InvokeInst>(V)) {
166 II->setAttributes(AS);
167 }
else if (
auto *GV = dyn_cast<GlobalVariable>(V)) {
178 if (!ForwardRefBlockAddresses.empty())
179 return Error(ForwardRefBlockAddresses.begin()->first.Loc,
180 "expected function name in blockaddress");
182 for (
const auto &NT : NumberedTypes)
183 if (NT.second.second.isValid())
184 return Error(NT.second.second,
185 "use of undefined type '%" +
Twine(NT.first) +
"'");
187 for (
StringMap<std::pair<Type*, LocTy> >::iterator
I =
188 NamedTypes.begin(),
E = NamedTypes.end();
I !=
E; ++
I)
189 if (
I->second.second.isValid())
190 return Error(
I->second.second,
191 "use of undefined type named '" +
I->getKey() +
"'");
193 if (!ForwardRefComdats.empty())
194 return Error(ForwardRefComdats.begin()->second,
195 "use of undefined comdat '$" +
196 ForwardRefComdats.begin()->first +
"'");
198 if (!ForwardRefVals.empty())
199 return Error(ForwardRefVals.begin()->second.second,
200 "use of undefined value '@" + ForwardRefVals.begin()->first +
203 if (!ForwardRefValIDs.empty())
204 return Error(ForwardRefValIDs.begin()->second.second,
205 "use of undefined value '@" +
206 Twine(ForwardRefValIDs.begin()->first) +
"'");
208 if (!ForwardRefMDNodes.empty())
209 return Error(ForwardRefMDNodes.begin()->second.second,
210 "use of undefined metadata '!" +
211 Twine(ForwardRefMDNodes.begin()->first) +
"'");
214 for (
auto &
N : NumberedMetadata) {
215 if (
N.second && !
N.second->isResolved())
216 N.second->resolveCycles();
219 for (
auto *Inst : InstsWithTBAATag) {
221 assert(MD &&
"UpgradeInstWithTBAATag should have a TBAA tag");
223 if (MD != UpgradedMD)
242 if (UpgradeDebugInfo)
255 for (
const auto &
I : NamedTypes)
256 Slots->
NamedTypes.insert(std::make_pair(
I.getKey(),
I.second.first));
257 for (
const auto &
I : NumberedTypes)
258 Slots->
Types.insert(std::make_pair(
I.first,
I.second.first));
264 bool LLParser::ValidateEndOfIndex() {
268 if (!ForwardRefValueInfos.empty())
269 return Error(ForwardRefValueInfos.begin()->second.front().second,
270 "use of undefined summary '^" +
271 Twine(ForwardRefValueInfos.begin()->first) +
"'");
273 if (!ForwardRefAliasees.empty())
274 return Error(ForwardRefAliasees.begin()->second.front().second,
275 "use of undefined summary '^" +
276 Twine(ForwardRefAliasees.begin()->first) +
"'");
278 if (!ForwardRefTypeIds.empty())
279 return Error(ForwardRefTypeIds.begin()->second.front().second,
280 "use of undefined type id summary '^" +
281 Twine(ForwardRefTypeIds.begin()->first) +
"'");
290 bool LLParser::ParseTopLevelEntities() {
298 if (ParseSummaryEntry())
302 if (ParseSourceFileName())
313 default:
return TokError(
"expected top-level entity");
320 if (ParseSourceFileName())
329 case lltok::exclaim:
if (ParseStandaloneMetadata())
return true;
break;
331 if (ParseSummaryEntry())
338 if (ParseUseListOrderBB())
347 bool LLParser::ParseModuleAsm() {
353 ParseStringConstant(AsmStr))
return true;
362 bool LLParser::ParseTargetDefinition() {
366 default:
return TokError(
"unknown target property");
369 if (ParseToken(
lltok::equal,
"expected '=' after target triple") ||
370 ParseStringConstant(Str))
376 if (ParseToken(
lltok::equal,
"expected '=' after target datalayout") ||
377 ParseStringConstant(Str))
379 if (DataLayoutStr.
empty())
387 bool LLParser::ParseSourceFileName() {
390 if (ParseToken(
lltok::equal,
"expected '=' after source_filename") ||
391 ParseStringConstant(SourceFileName))
402 bool LLParser::ParseDepLibs() {
405 if (ParseToken(
lltok::equal,
"expected '=' after deplibs") ||
414 if (ParseStringConstant(Str))
return true;
422 bool LLParser::ParseUnnamedType() {
427 if (ParseToken(
lltok::equal,
"expected '=' after name") ||
431 Type *Result =
nullptr;
432 if (ParseStructDefinition(TypeLoc,
"",
433 NumberedTypes[TypeID], Result))
return true;
435 if (!isa<StructType>(Result)) {
436 std::pair<Type*, LocTy> &Entry = NumberedTypes[
TypeID];
438 return Error(TypeLoc,
"non-struct types may not be recursive");
439 Entry.first = Result;
440 Entry.second =
SMLoc();
448 bool LLParser::ParseNamedType() {
453 if (ParseToken(
lltok::equal,
"expected '=' after name") ||
457 Type *Result =
nullptr;
458 if (ParseStructDefinition(NameLoc, Name,
459 NamedTypes[Name], Result))
return true;
461 if (!isa<StructType>(Result)) {
462 std::pair<Type*, LocTy> &Entry = NamedTypes[
Name];
464 return Error(NameLoc,
"non-struct types may not be recursive");
465 Entry.first = Result;
466 Entry.second =
SMLoc();
474 bool LLParser::ParseDeclare() {
478 std::vector<std::pair<unsigned, MDNode *>> MDs;
482 if (ParseMetadataAttachment(MDK, N))
484 MDs.push_back({MDK, N});
488 if (ParseFunctionHeader(F,
false))
497 bool LLParser::ParseDefine() {
502 return ParseFunctionHeader(F,
true) ||
503 ParseOptionalFunctionMetadata(*F) ||
504 ParseFunctionBody(*F);
510 bool LLParser::ParseGlobalType(
bool &IsConstant) {
517 return TokError(
"expected 'global' or 'constant'");
523 bool LLParser::ParseOptionalUnnamedAddr(
543 bool LLParser::ParseUnnamedGlobal() {
544 unsigned VarID = NumberedVals.size();
551 return Error(Lex.
getLoc(),
"variable expected to be numbered '%" +
555 if (ParseToken(
lltok::equal,
"expected '=' after name"))
560 unsigned Linkage,
Visibility, DLLStorageClass;
564 if (ParseOptionalLinkage(Linkage, HasLinkage, Visibility, DLLStorageClass,
566 ParseOptionalThreadLocal(TLM) || ParseOptionalUnnamedAddr(UnnamedAddr))
570 return ParseGlobal(Name, NameLoc, Linkage, HasLinkage, Visibility,
571 DLLStorageClass, DSOLocal, TLM, UnnamedAddr);
573 return parseIndirectSymbol(Name, NameLoc, Linkage, Visibility,
574 DLLStorageClass, DSOLocal, TLM, UnnamedAddr);
582 bool LLParser::ParseNamedGlobal() {
589 unsigned Linkage,
Visibility, DLLStorageClass;
593 if (ParseToken(
lltok::equal,
"expected '=' in global variable") ||
594 ParseOptionalLinkage(Linkage, HasLinkage, Visibility, DLLStorageClass,
596 ParseOptionalThreadLocal(TLM) || ParseOptionalUnnamedAddr(UnnamedAddr))
600 return ParseGlobal(Name, NameLoc, Linkage, HasLinkage, Visibility,
601 DLLStorageClass, DSOLocal, TLM, UnnamedAddr);
603 return parseIndirectSymbol(Name, NameLoc, Linkage, Visibility,
604 DLLStorageClass, DSOLocal, TLM, UnnamedAddr);
607 bool LLParser::parseComdat() {
617 return TokError(
"expected comdat type");
622 return TokError(
"unknown selection kind");
644 if (I != ComdatSymTab.
end() && !ForwardRefComdats.erase(Name))
645 return Error(NameLoc,
"redefinition of comdat '$" + Name +
"'");
648 if (I != ComdatSymTab.
end())
659 bool LLParser::ParseMDString(
MDString *&Result) {
661 if (ParseStringConstant(Str))
return true;
668 bool LLParser::ParseMDNodeID(
MDNode *&Result) {
672 if (ParseUInt32(MID))
676 if (NumberedMetadata.count(MID)) {
677 Result = NumberedMetadata[MID];
682 auto &FwdRef = ForwardRefMDNodes[MID];
685 Result = FwdRef.first.
get();
686 NumberedMetadata[MID].reset(Result);
692 bool LLParser::ParseNamedMetadata() {
711 if (ParseDIExpression(N,
false))
720 return ParseToken(
lltok::rbrace,
"expected end of metadata node");
725 bool LLParser::ParseStandaloneMetadata() {
728 unsigned MetadataID = 0;
731 if (ParseUInt32(MetadataID) ||
737 return TokError(
"unexpected type in metadata definition");
741 if (ParseSpecializedMDNode(Init, IsDistinct))
744 ParseMDTuple(Init, IsDistinct))
748 auto FI = ForwardRefMDNodes.find(MetadataID);
749 if (FI != ForwardRefMDNodes.end()) {
750 FI->second.first->replaceAllUsesWith(Init);
751 ForwardRefMDNodes.erase(FI);
753 assert(NumberedMetadata[MetadataID] == Init &&
"Tracking VH didn't work");
755 if (NumberedMetadata.count(MetadataID))
756 return TokError(
"Metadata id is already used");
757 NumberedMetadata[MetadataID].reset(Init);
764 bool LLParser::SkipModuleSummaryEntry() {
772 "Expected 'gv', 'module', or 'typeid' at the start of summary entry");
774 if (ParseToken(
lltok::colon,
"expected ':' at start of summary entry") ||
775 ParseToken(
lltok::lparen,
"expected '(' at start of summary entry"))
779 unsigned NumOpenParen = 1;
789 return TokError(
"found end of file while parsing summary entry");
795 }
while (NumOpenParen > 0);
801 bool LLParser::ParseSummaryEntry() {
815 return SkipModuleSummaryEntry();
819 return ParseGVEntry(SummaryID);
821 return ParseModuleEntry(SummaryID);
823 return ParseTypeIdEntry(SummaryID);
826 return Error(Lex.
getLoc(),
"unexpected summary kind");
855 bool LLParser::parseIndirectSymbol(
const std::string &
Name,
LocTy NameLoc,
857 unsigned DLLStorageClass,
bool DSOLocal,
872 return Error(NameLoc,
"invalid linkage type for alias");
875 return Error(NameLoc,
876 "symbol with local linkage must have default visibility");
881 ParseToken(
lltok::comma,
"expected comma after alias or ifunc's type"))
890 if (ParseGlobalTypeAndValue(Aliasee))
898 return Error(AliaseeLoc,
"invalid aliasee");
905 return Error(AliaseeLoc,
"An alias or ifunc must have pointer type");
906 unsigned AddrSpace = PTy->getAddressSpace();
908 if (IsAlias && Ty != PTy->getElementType())
911 "explicit pointee type doesn't match operand's pointee type");
913 if (!IsAlias && !PTy->getElementType()->isFunctionTy())
916 "explicit pointee type should be a function type");
925 if (!ForwardRefVals.erase(
Name))
926 return Error(NameLoc,
"redefinition of global '@" +
Name +
"'");
929 auto I = ForwardRefValIDs.find(NumberedVals.size());
930 if (
I != ForwardRefValIDs.end()) {
931 GVal =
I->second.first;
932 ForwardRefValIDs.erase(
I);
937 std::unique_ptr<GlobalIndirectSymbol> GA;
946 GA->setThreadLocalMode(
TLM);
949 GA->setUnnamedAddr(UnnamedAddr);
953 NumberedVals.push_back(GA.get());
957 if (GVal->
getType() != GA->getType())
960 "forward reference and definition of alias have different types");
973 assert(GA->getName() ==
Name &&
"Should not be a name conflict!");
994 bool LLParser::ParseGlobal(
const std::string &
Name,
LocTy NameLoc,
995 unsigned Linkage,
bool HasLinkage,
996 unsigned Visibility,
unsigned DLLStorageClass,
1000 return Error(NameLoc,
1001 "symbol with local linkage must have default visibility");
1004 bool IsConstant, IsExternallyInitialized;
1005 LocTy IsExternallyInitializedLoc;
1009 if (ParseOptionalAddrSpace(AddrSpace) ||
1011 IsExternallyInitialized,
1012 &IsExternallyInitializedLoc) ||
1013 ParseGlobalType(IsConstant) ||
1014 ParseType(Ty, TyLoc))
1023 if (ParseGlobalValue(Ty, Init))
1028 return Error(TyLoc,
"invalid type for global variable");
1033 if (!
Name.empty()) {
1036 if (!ForwardRefVals.erase(
Name))
1037 return Error(NameLoc,
"redefinition of global '@" +
Name +
"'");
1040 auto I = ForwardRefValIDs.find(NumberedVals.size());
1041 if (
I != ForwardRefValIDs.end()) {
1042 GVal =
I->second.first;
1043 ForwardRefValIDs.erase(
I);
1055 "forward reference and definition of global have different types");
1057 GV = cast<GlobalVariable>(GVal);
1064 NumberedVals.push_back(GV);
1089 if (ParseOptionalAlignment(Alignment))
return true;
1092 if (ParseGlobalObjectMetadataAttachment(*GV))
1096 if (parseOptionalComdat(
Name, C))
1101 return TokError(
"unknown global variable property!");
1107 std::vector<unsigned> FwdRefAttrGrps;
1108 if (ParseFnAttributeValuePairs(Attrs, FwdRefAttrGrps,
false, BuiltinLoc))
1112 ForwardRefAttrGroups[GV] = FwdRefAttrGrps;
1120 bool LLParser::ParseUnnamedAttrGrp() {
1126 return TokError(
"expected attribute group id");
1129 std::vector<unsigned> unused;
1135 ParseFnAttributeValuePairs(NumberedAttrBuilders[VarID], unused,
true,
1137 ParseToken(
lltok::rbrace,
"expected end of attribute group"))
1140 if (!NumberedAttrBuilders[VarID].hasAttributes())
1141 return Error(AttrGrpLoc,
"attribute group has no attributes");
1148 bool LLParser::ParseFnAttributeValuePairs(
AttrBuilder &
B,
1149 std::vector<unsigned> &FwdRefAttrGrps,
1150 bool inAttrGrp,
LocTy &BuiltinLoc) {
1151 bool HaveError =
false;
1158 BuiltinLoc = Lex.
getLoc();
1161 if (!inAttrGrp)
return HaveError;
1162 return Error(Lex.
getLoc(),
"unterminated attribute group");
1174 "cannot have an attribute group reference in an attribute group");
1177 if (inAttrGrp)
break;
1180 FwdRefAttrGrps.push_back(AttrGrpNum);
1185 if (ParseStringAttribute(B))
1199 ParseUInt32(Alignment))
1202 if (ParseOptionalAlignment(Alignment))
1213 ParseUInt32(Alignment))
1216 if (ParseOptionalStackAlignment(Alignment))
1223 unsigned ElemSizeArg;
1226 if (parseAllocSizeArguments(ElemSizeArg, NumElemsArg))
1292 "invalid use of attribute on a function");
1308 "invalid use of parameter-only attribute on a function");
1321 const std::string &
Name) {
1333 Value *Val,
bool IsCall) {
1337 Type *SuggestedTy = Ty;
1338 if (IsCall && isa<PointerType>(Ty)) {
1341 SuggestedTy = TyInProgAS;
1342 if (Val->
getType() == TyInProgAS)
1346 Error(Loc,
"'" + Name +
"' is not a basic block");
1348 Error(Loc,
"'" + Name +
"' defined with type '" +
1357 GlobalValue *LLParser::GetGlobalVal(
const std::string &Name,
Type *Ty,
1358 LocTy Loc,
bool IsCall) {
1361 Error(Loc,
"global variable reference must have pointer type");
1372 auto I = ForwardRefVals.find(Name);
1373 if (
I != ForwardRefVals.end())
1374 Val =
I->second.first;
1379 return cast_or_null<GlobalValue>(
1380 checkValidVariableType(Loc,
"@" + Name, Ty, Val, IsCall));
1384 ForwardRefVals[
Name] = std::make_pair(FwdVal, Loc);
1392 Error(Loc,
"global variable reference must have pointer type");
1396 GlobalValue *Val = ID < NumberedVals.size() ? NumberedVals[
ID] :
nullptr;
1401 auto I = ForwardRefValIDs.find(ID);
1402 if (
I != ForwardRefValIDs.end())
1403 Val =
I->second.first;
1408 return cast_or_null<GlobalValue>(
1409 checkValidVariableType(Loc,
"@" +
Twine(ID), Ty, Val, IsCall));
1413 ForwardRefValIDs[
ID] = std::make_pair(FwdVal, Loc);
1421 Comdat *LLParser::getComdat(
const std::string &Name,
LocTy Loc) {
1425 if (I != ComdatSymTab.
end())
1430 ForwardRefComdats[
Name] = Loc;
1440 bool LLParser::ParseToken(
lltok::Kind T,
const char *ErrMsg) {
1442 return TokError(ErrMsg);
1449 bool LLParser::ParseStringConstant(std::string &Result) {
1451 return TokError(
"expected string constant");
1459 bool LLParser::ParseUInt32(
uint32_t &Val) {
1461 return TokError(
"expected integer");
1463 if (Val64 !=
unsigned(Val64))
1464 return TokError(
"expected 32-bit integer (too large)");
1472 bool LLParser::ParseUInt64(uint64_t &Val) {
1474 return TokError(
"expected integer");
1487 return TokError(
"expected localdynamic, initialexec or localexec");
1515 return ParseTLSModel(TLM) ||
1516 ParseToken(
lltok::rparen,
"expected ')' after thread local model");
1524 bool LLParser::ParseOptionalAddrSpace(
unsigned &AddrSpace,
unsigned DefaultAS) {
1528 return ParseToken(
lltok::lparen,
"expected '(' in address space") ||
1529 ParseUInt32(AddrSpace) ||
1536 bool LLParser::ParseStringAttribute(
AttrBuilder &B) {
1540 if (EatIfPresent(
lltok::equal) && ParseStringConstant(Val))
1547 bool LLParser::ParseOptionalParamAttrs(
AttrBuilder &B) {
1548 bool HaveError =
false;
1558 if (ParseStringAttribute(B))
1564 if (ParseOptionalAlignment(Alignment))
1633 HaveError |=
Error(Lex.
getLoc(),
"invalid use of function-only attribute");
1642 bool LLParser::ParseOptionalReturnAttrs(
AttrBuilder &B) {
1643 bool HaveError =
false;
1653 if (ParseStringAttribute(B))
1673 if (ParseOptionalAlignment(Alignment))
1693 HaveError |=
Error(Lex.
getLoc(),
"invalid use of parameter-only attribute");
1730 HaveError |=
Error(Lex.
getLoc(),
"invalid use of function-only attribute");
1735 HaveError |=
Error(Lex.
getLoc(),
"invalid use of attribute on return type");
1786 bool LLParser::ParseOptionalLinkage(
unsigned &Res,
bool &HasLinkage,
1787 unsigned &Visibility,
1788 unsigned &DLLStorageClass,
1793 ParseOptionalDSOLocal(DSOLocal);
1794 ParseOptionalVisibility(Visibility);
1795 ParseOptionalDLLStorageClass(DLLStorageClass);
1798 return Error(Lex.
getLoc(),
"dso_location and DLL-StorageClass mismatch");
1804 void LLParser::ParseOptionalDSOLocal(
bool &DSOLocal) {
1826 void LLParser::ParseOptionalVisibility(
unsigned &Res) {
1849 void LLParser::ParseOptionalDLLStorageClass(
unsigned &Res) {
1907 bool LLParser::ParseOptionalCallingConv(
unsigned &CC) {
1952 return ParseUInt32(CC);
1962 bool LLParser::ParseMetadataAttachment(
unsigned &
Kind,
MDNode *&MD) {
1969 return ParseMDNode(MD);
1974 bool LLParser::ParseInstructionMetadata(
Instruction &Inst) {
1977 return TokError(
"expected metadata after comma");
1981 if (ParseMetadataAttachment(MDK, N))
1986 InstsWithTBAATag.push_back(&Inst);
1995 bool LLParser::ParseGlobalObjectMetadataAttachment(
GlobalObject &GO) {
1998 if (ParseMetadataAttachment(MDK, N))
2007 bool LLParser::ParseOptionalFunctionMetadata(
Function &
F) {
2009 if (ParseGlobalObjectMetadataAttachment(F))
2017 bool LLParser::ParseOptionalAlignment(
unsigned &Alignment) {
2022 if (ParseUInt32(Alignment))
return true;
2024 return Error(AlignLoc,
"alignment is not a power of two");
2026 return Error(AlignLoc,
"huge alignments are not supported yet");
2035 bool LLParser::ParseOptionalDerefAttrBytes(
lltok::Kind AttrKind,
2042 if (!EatIfPresent(AttrKind))
2046 return Error(ParenLoc,
"expected '('");
2048 if (ParseUInt64(Bytes))
return true;
2051 return Error(ParenLoc,
"expected ')'");
2053 return Error(DerefLoc,
"dereferenceable bytes must be non-zero");
2063 bool LLParser::ParseOptionalCommaAlign(
unsigned &Alignment,
2064 bool &AteExtraComma) {
2065 AteExtraComma =
false;
2069 AteExtraComma =
true;
2074 return Error(Lex.
getLoc(),
"expected metadata or 'align'");
2076 if (ParseOptionalAlignment(Alignment))
return true;
2088 bool LLParser::ParseOptionalCommaAddrSpace(
unsigned &AddrSpace,
2090 bool &AteExtraComma) {
2091 AteExtraComma =
false;
2095 AteExtraComma =
true;
2101 return Error(Lex.
getLoc(),
"expected metadata or 'addrspace'");
2103 if (ParseOptionalAddrSpace(AddrSpace))
2110 bool LLParser::parseAllocSizeArguments(
unsigned &BaseSizeArg,
2114 auto StartParen = Lex.
getLoc();
2116 return Error(StartParen,
"expected '('");
2118 if (ParseUInt32(BaseSizeArg))
2122 auto HowManyAt = Lex.
getLoc();
2124 if (ParseUInt32(HowMany))
2126 if (HowMany == BaseSizeArg)
2127 return Error(HowManyAt,
2128 "'allocsize' indices can't refer to the same parameter");
2129 HowManyArg = HowMany;
2133 auto EndParen = Lex.
getLoc();
2135 return Error(EndParen,
"expected ')'");
2149 return ParseScope(SSID) || ParseOrdering(Ordering);
2159 auto StartParenAt = Lex.
getLoc();
2161 return Error(StartParenAt,
"Expected '(' in syncscope");
2164 auto SSNAt = Lex.
getLoc();
2165 if (ParseStringConstant(SSN))
2166 return Error(SSNAt,
"Expected synchronization scope name");
2168 auto EndParenAt = Lex.
getLoc();
2170 return Error(EndParenAt,
"Expected ')' in syncscope");
2184 default:
return TokError(
"Expected ordering on atomic instruction");
2203 bool LLParser::ParseOptionalStackAlignment(
unsigned &Alignment) {
2209 return Error(ParenLoc,
"expected '('");
2211 if (ParseUInt32(Alignment))
return true;
2214 return Error(ParenLoc,
"expected ')'");
2216 return Error(AlignLoc,
"stack alignment is not a power of two");
2230 bool &AteExtraComma) {
2231 AteExtraComma =
false;
2234 return TokError(
"expected ',' as start of index list");
2238 if (Indices.
empty())
return TokError(
"expected index");
2239 AteExtraComma =
true;
2243 if (ParseUInt32(Idx))
return true;
2255 bool LLParser::ParseType(
Type *&Result,
const Twine &Msg,
bool AllowVoid) {
2259 return TokError(Msg);
2267 if (ParseAnonStructType(Result,
false))
2273 if (ParseArrayVectorType(Result,
false))
2280 if (ParseAnonStructType(Result,
true) ||
2281 ParseToken(
lltok::greater,
"expected '>' at end of packed struct"))
2283 }
else if (ParseArrayVectorType(Result,
true))
2288 std::pair<Type*, LocTy> &Entry = NamedTypes[Lex.
getStrVal()];
2294 Entry.second = Lex.
getLoc();
2296 Result = Entry.first;
2303 std::pair<Type*, LocTy> &Entry = NumberedTypes[Lex.
getUIntVal()];
2309 Entry.second = Lex.
getLoc();
2311 Result = Entry.first;
2322 if (!AllowVoid && Result->
isVoidTy())
2323 return Error(TypeLoc,
"void type only allowed for function results");
2329 return TokError(
"basic block pointers are invalid");
2331 return TokError(
"pointers to void are invalid - use i8* instead");
2333 return TokError(
"pointer to this type is invalid");
2341 return TokError(
"basic block pointers are invalid");
2343 return TokError(
"pointers to void are invalid; use i8* instead");
2345 return TokError(
"pointer to this type is invalid");
2347 if (ParseOptionalAddrSpace(AddrSpace) ||
2348 ParseToken(
lltok::star,
"expected '*' in address space"))
2357 if (ParseFunctionType(Result))
2370 PerFunctionState &PFS,
bool IsMustTailCall,
2371 bool InVarArgsFunc) {
2377 if (!ArgList.
empty() &&
2378 ParseToken(
lltok::comma,
"expected ',' in argument list"))
2383 const char *Msg =
"unexpected ellipsis in argument list for ";
2384 if (!IsMustTailCall)
2385 return TokError(
Twine(Msg) +
"non-musttail call");
2387 return TokError(
Twine(Msg) +
"musttail call in non-varargs function");
2389 return ParseToken(
lltok::rparen,
"expected ')' at end of argument list");
2394 Type *ArgTy =
nullptr;
2397 if (ParseType(ArgTy, ArgLoc))
2401 if (ParseMetadataAsValue(V, PFS))
2405 if (ParseOptionalParamAttrs(ArgAttrs) || ParseValue(ArgTy, V, PFS))
2412 if (IsMustTailCall && InVarArgsFunc)
2413 return TokError(
"expected '...' at end of argument list for musttail call " 2414 "in varargs function");
2429 bool LLParser::ParseOptionalOperandBundles(
2437 if (!BundleList.
empty() &&
2438 ParseToken(
lltok::comma,
"expected ',' in input list"))
2442 if (ParseStringConstant(Tag))
2445 if (ParseToken(
lltok::lparen,
"expected '(' in operand bundle"))
2448 std::vector<Value *> Inputs;
2451 if (!Inputs.empty() &&
2452 ParseToken(
lltok::comma,
"expected ',' in input list"))
2456 Value *Input =
nullptr;
2457 if (ParseType(Ty) || ParseValue(Ty, Input, PFS))
2459 Inputs.push_back(Input);
2462 BundleList.
emplace_back(std::move(Tag), std::move(Inputs));
2467 if (BundleList.
empty())
2468 return Error(BeginLoc,
"operand bundle set must not be empty");
2496 Type *ArgTy =
nullptr;
2500 if (ParseType(ArgTy) ||
2501 ParseOptionalParamAttrs(Attrs))
return true;
2504 return Error(TypeLoc,
"argument can not have void type");
2512 return Error(TypeLoc,
"invalid type for function argument");
2527 if (ParseType(ArgTy) || ParseOptionalParamAttrs(Attrs))
return true;
2530 return Error(TypeLoc,
"argument can not have void type");
2540 return Error(TypeLoc,
"invalid type for function argument");
2548 return ParseToken(
lltok::rparen,
"expected ')' at end of argument list");
2553 bool LLParser::ParseFunctionType(
Type *&Result) {
2557 return TokError(
"invalid function return type");
2561 if (ParseArgumentList(ArgList, isVarArg))
2565 for (
unsigned i = 0, e = ArgList.
size(); i != e; ++i) {
2566 if (!ArgList[i].Name.empty())
2567 return Error(ArgList[i].Loc,
"argument name invalid in function type");
2568 if (ArgList[i].
Attrs.hasAttributes())
2569 return Error(ArgList[i].Loc,
2570 "argument attributes invalid in function type");
2574 for (
unsigned i = 0, e = ArgList.
size(); i != e; ++i)
2583 bool LLParser::ParseAnonStructType(
Type *&Result,
bool Packed) {
2585 if (ParseStructBody(Elts))
return true;
2592 bool LLParser::ParseStructDefinition(
SMLoc TypeLoc,
StringRef Name,
2593 std::pair<Type*, LocTy> &Entry,
2596 if (Entry.first && !Entry.second.isValid())
2597 return Error(TypeLoc,
"redefinition of type");
2603 Entry.second =
SMLoc();
2608 ResultTy = Entry.first;
2620 return Error(TypeLoc,
"forward references to non-struct type");
2624 return ParseArrayVectorType(ResultTy,
true);
2625 return ParseType(ResultTy);
2629 Entry.second =
SMLoc();
2635 StructType *STy = cast<StructType>(Entry.first);
2638 if (ParseStructBody(Body) ||
2639 (isPacked && ParseToken(
lltok::greater,
"expected '>' in packed struct")))
2663 if (ParseType(Ty))
return true;
2667 return Error(EltTyLoc,
"invalid element type for struct");
2671 if (ParseType(Ty))
return true;
2674 return Error(EltTyLoc,
"invalid element type for struct");
2679 return ParseToken(
lltok::rbrace,
"expected '}' at end of struct");
2687 bool LLParser::ParseArrayVectorType(
Type *&Result,
bool isVector) {
2690 return TokError(
"expected number in address space");
2696 if (ParseToken(
lltok::kw_x,
"expected 'x' after element count"))
2700 Type *EltTy =
nullptr;
2701 if (ParseType(EltTy))
return true;
2704 "expected end of sequential type"))
2709 return Error(SizeLoc,
"zero element vector is illegal");
2710 if ((
unsigned)Size != Size)
2711 return Error(SizeLoc,
"size too large for vector");
2713 return Error(TypeLoc,
"invalid vector element type");
2717 return Error(TypeLoc,
"invalid array element type");
2734 NumberedVals.push_back(&A);
2737 LLParser::PerFunctionState::~PerFunctionState() {
2740 for (
const auto &
P : ForwardRefVals) {
2741 if (isa<BasicBlock>(
P.second.first))
2743 P.second.first->replaceAllUsesWith(
2745 P.second.first->deleteValue();
2748 for (
const auto &
P : ForwardRefValIDs) {
2749 if (isa<BasicBlock>(
P.second.first))
2751 P.second.first->replaceAllUsesWith(
2753 P.second.first->deleteValue();
2757 bool LLParser::PerFunctionState::FinishFunction() {
2758 if (!ForwardRefVals.empty())
2759 return P.Error(ForwardRefVals.begin()->second.second,
2760 "use of undefined value '%" + ForwardRefVals.begin()->first +
2762 if (!ForwardRefValIDs.empty())
2763 return P.Error(ForwardRefValIDs.begin()->second.second,
2764 "use of undefined value '%" +
2765 Twine(ForwardRefValIDs.begin()->first) +
"'");
2772 Value *LLParser::PerFunctionState::GetVal(
const std::string &Name,
Type *Ty,
2773 LocTy Loc,
bool IsCall) {
2775 Value *Val =
F.getValueSymbolTable()->lookup(Name);
2780 auto I = ForwardRefVals.find(Name);
2781 if (
I != ForwardRefVals.end())
2782 Val =
I->second.first;
2787 return P.checkValidVariableType(Loc,
"%" + Name, Ty, Val, IsCall);
2791 P.Error(Loc,
"invalid use of a non-first-class type");
2803 ForwardRefVals[
Name] = std::make_pair(FwdVal, Loc);
2807 Value *LLParser::PerFunctionState::GetVal(
unsigned ID,
Type *Ty,
LocTy Loc,
2810 Value *Val = ID < NumberedVals.size() ? NumberedVals[
ID] :
nullptr;
2815 auto I = ForwardRefValIDs.find(ID);
2816 if (
I != ForwardRefValIDs.end())
2817 Val =
I->second.first;
2822 return P.checkValidVariableType(Loc,
"%" +
Twine(ID), Ty, Val, IsCall);
2825 P.Error(Loc,
"invalid use of a non-first-class type");
2837 ForwardRefValIDs[
ID] = std::make_pair(FwdVal, Loc);
2843 bool LLParser::PerFunctionState::SetInstName(
int NameID,
2844 const std::string &NameStr,
2848 if (NameID != -1 || !NameStr.empty())
2849 return P.Error(NameLoc,
"instructions returning void cannot have a name");
2855 if (NameStr.empty()) {
2858 NameID = NumberedVals.size();
2860 if (
unsigned(NameID) != NumberedVals.size())
2861 return P.Error(NameLoc,
"instruction expected to be numbered '%" +
2862 Twine(NumberedVals.size()) +
"'");
2864 auto FI = ForwardRefValIDs.find(NameID);
2865 if (FI != ForwardRefValIDs.end()) {
2866 Value *Sentinel = FI->second.first;
2868 return P.Error(NameLoc,
"instruction forward referenced with type '" +
2873 ForwardRefValIDs.erase(FI);
2876 NumberedVals.push_back(Inst);
2881 auto FI = ForwardRefVals.find(NameStr);
2882 if (FI != ForwardRefVals.end()) {
2883 Value *Sentinel = FI->second.first;
2885 return P.Error(NameLoc,
"instruction forward referenced with type '" +
2890 ForwardRefVals.erase(FI);
2896 if (Inst->
getName() != NameStr)
2897 return P.Error(NameLoc,
"multiple definition of local value named '" +
2904 BasicBlock *LLParser::PerFunctionState::GetBB(
const std::string &Name,
2906 return dyn_cast_or_null<BasicBlock>(
2910 BasicBlock *LLParser::PerFunctionState::GetBB(
unsigned ID,
LocTy Loc) {
2911 return dyn_cast_or_null<BasicBlock>(
2918 BasicBlock *LLParser::PerFunctionState::DefineBB(
const std::string &Name,
2922 BB = GetBB(NumberedVals.size(), Loc);
2924 BB = GetBB(Name, Loc);
2925 if (!BB)
return nullptr;
2929 F.getBasicBlockList().splice(
F.end(),
F.getBasicBlockList(), BB);
2933 ForwardRefValIDs.erase(NumberedVals.size());
2934 NumberedVals.push_back(BB);
2937 ForwardRefVals.erase(Name);
2953 bool LLParser::ParseValID(
ValID &ID, PerFunctionState *PFS) {
2956 default:
return TokError(
"expected value token");
2998 if (ParseGlobalValueVector(Elts) ||
2999 ParseToken(
lltok::rbrace,
"expected end of struct constant"))
3005 Elts.
size() *
sizeof(Elts[0]));
3017 if (ParseGlobalValueVector(Elts) ||
3019 ParseToken(
lltok::rbrace,
"expected end of packed struct")) ||
3023 if (isPackedStruct) {
3026 Elts.
size() *
sizeof(Elts[0]));
3033 return Error(ID.
Loc,
"constant vector must not be empty");
3035 if (!Elts[0]->
getType()->isIntegerTy() &&
3036 !Elts[0]->getType()->isFloatingPointTy() &&
3037 !Elts[0]->getType()->isPointerTy())
3038 return Error(FirstEltLoc,
3039 "vector elements must have integer, pointer or floating point type");
3042 for (
unsigned i = 1, e = Elts.
size(); i != e; ++i)
3043 if (Elts[i]->
getType() != Elts[0]->getType())
3044 return Error(FirstEltLoc,
3045 "vector element #" +
Twine(i) +
3056 if (ParseGlobalValueVector(Elts) ||
3068 if (!Elts[0]->
getType()->isFirstClassType())
3069 return Error(FirstEltLoc,
"invalid array element type: " +
3075 for (
unsigned i = 0, e = Elts.
size(); i != e; ++i) {
3076 if (Elts[i]->
getType() != Elts[0]->getType())
3077 return Error(FirstEltLoc,
3078 "array element #" +
Twine(i) +
3097 bool HasSideEffect, AlignStack, AsmDialect;
3102 ParseStringConstant(ID.
StrVal) ||
3103 ParseToken(
lltok::comma,
"expected comma in inline asm expression") ||
3108 (
unsigned(AsmDialect)<<2);
3119 if (ParseToken(
lltok::lparen,
"expected '(' in block address expression") ||
3121 ParseToken(
lltok::comma,
"expected comma in block address expression")||
3122 ParseValID(Label) ||
3123 ParseToken(
lltok::rparen,
"expected ')' in block address expression"))
3127 return Error(Fn.
Loc,
"expected function name in blockaddress");
3129 return Error(Label.
Loc,
"expected basic block name in blockaddress");
3134 if (Fn.
UIntVal < NumberedVals.size())
3135 GV = NumberedVals[Fn.
UIntVal];
3136 }
else if (!ForwardRefVals.count(Fn.
StrVal)) {
3142 if (!isa<Function>(GV))
3143 return Error(Fn.
Loc,
"expected function name in blockaddress");
3144 F = cast<Function>(GV);
3146 return Error(Fn.
Loc,
"cannot take blockaddress inside a declaration");
3152 ForwardRefBlockAddresses.insert(std::make_pair(
3154 std::map<ValID, GlobalValue *>()))
3155 .first->second.insert(std::make_pair(std::move(Label),
nullptr))
3168 if (BlockAddressPFS && F == &BlockAddressPFS->getFunction()) {
3170 BB = BlockAddressPFS->GetBB(Label.
UIntVal, Label.
Loc);
3172 BB = BlockAddressPFS->GetBB(Label.
StrVal, Label.
Loc);
3174 return Error(Label.
Loc,
"referenced value is not a basic block");
3177 return Error(Label.
Loc,
"cannot take address of numeric label after " 3178 "the function is defined");
3179 BB = dyn_cast_or_null<BasicBlock>(
3182 return Error(Label.
Loc,
"referenced value is not a basic block");
3204 Type *DestTy =
nullptr;
3207 if (ParseToken(
lltok::lparen,
"expected '(' after constantexpr cast") ||
3208 ParseGlobalTypeAndValue(SrcVal) ||
3209 ParseToken(
lltok::kw_to,
"expected 'to' in constantexpr cast") ||
3210 ParseType(DestTy) ||
3211 ParseToken(
lltok::rparen,
"expected ')' at end of constantexpr cast"))
3214 return Error(ID.
Loc,
"invalid cast opcode for cast from '" +
3226 if (ParseToken(
lltok::lparen,
"expected '(' in extractvalue constantexpr")||
3227 ParseGlobalTypeAndValue(Val) ||
3228 ParseIndexList(Indices) ||
3229 ParseToken(
lltok::rparen,
"expected ')' in extractvalue constantexpr"))
3233 return Error(ID.
Loc,
"extractvalue operand must be aggregate type");
3235 return Error(ID.
Loc,
"invalid indices for extractvalue");
3244 if (ParseToken(
lltok::lparen,
"expected '(' in insertvalue constantexpr")||
3245 ParseGlobalTypeAndValue(Val0) ||
3246 ParseToken(
lltok::comma,
"expected comma in insertvalue constantexpr")||
3247 ParseGlobalTypeAndValue(Val1) ||
3248 ParseIndexList(Indices) ||
3249 ParseToken(
lltok::rparen,
"expected ')' in insertvalue constantexpr"))
3252 return Error(ID.
Loc,
"insertvalue operand must be aggregate type");
3256 return Error(ID.
Loc,
"invalid indices for insertvalue");
3257 if (IndexedType != Val1->
getType())
3258 return Error(ID.
Loc,
"insertvalue operand and field disagree in type: '" +
3271 if (ParseCmpPredicate(PredVal, Opc) ||
3272 ParseToken(
lltok::lparen,
"expected '(' in compare constantexpr") ||
3273 ParseGlobalTypeAndValue(Val0) ||
3274 ParseToken(
lltok::comma,
"expected comma in compare constantexpr") ||
3275 ParseGlobalTypeAndValue(Val1) ||
3276 ParseToken(
lltok::rparen,
"expected ')' in compare constantexpr"))
3280 return Error(ID.
Loc,
"compare operands must have the same type");
3284 if (Opc == Instruction::FCmp) {
3286 return Error(ID.
Loc,
"fcmp requires floating point operands");
3289 assert(Opc == Instruction::ICmp &&
"Unexpected opcode for CmpInst!");
3292 return Error(ID.
Loc,
"icmp requires pointer or integer operands");
3304 if (ParseToken(
lltok::lparen,
"expected '(' in unary constantexpr") ||
3305 ParseGlobalTypeAndValue(Val) ||
3306 ParseToken(
lltok::rparen,
"expected ')' in unary constantexpr"))
3311 case Instruction::FNeg:
3313 return Error(ID.
Loc,
"constexpr requires fp operands");
3347 Opc == Instruction::Mul || Opc == Instruction::Shl) {
3355 }
else if (Opc == Instruction::SDiv || Opc == Instruction::UDiv ||
3356 Opc == Instruction::LShr || Opc == Instruction::AShr) {
3360 if (ParseToken(
lltok::lparen,
"expected '(' in binary constantexpr") ||
3361 ParseGlobalTypeAndValue(Val0) ||
3362 ParseToken(
lltok::comma,
"expected comma in binary constantexpr") ||
3363 ParseGlobalTypeAndValue(Val1) ||
3364 ParseToken(
lltok::rparen,
"expected ')' in binary constantexpr"))
3367 return Error(ID.
Loc,
"operands of constexpr must have same type");
3370 return Error(ModifierLoc,
"nuw only applies to integer operations");
3372 return Error(ModifierLoc,
"nsw only applies to integer operations");
3377 case Instruction::Sub:
3378 case Instruction::Mul:
3379 case Instruction::UDiv:
3380 case Instruction::SDiv:
3381 case Instruction::URem:
3382 case Instruction::SRem:
3383 case Instruction::Shl:
3384 case Instruction::AShr:
3385 case Instruction::LShr:
3387 return Error(ID.
Loc,
"constexpr requires integer operands");
3389 case Instruction::FAdd:
3390 case Instruction::FSub:
3391 case Instruction::FMul:
3392 case Instruction::FDiv:
3393 case Instruction::FRem:
3395 return Error(ID.
Loc,
"constexpr requires fp operands");
3416 if (ParseToken(
lltok::lparen,
"expected '(' in logical constantexpr") ||
3417 ParseGlobalTypeAndValue(Val0) ||
3418 ParseToken(
lltok::comma,
"expected comma in logical constantexpr") ||
3419 ParseGlobalTypeAndValue(Val1) ||
3420 ParseToken(
lltok::rparen,
"expected ')' in logical constantexpr"))
3423 return Error(ID.
Loc,
"operands of constexpr must have same type");
3426 "constexpr requires integer or integer vector operands");
3439 bool InBounds =
false;
3443 if (Opc == Instruction::GetElementPtr)
3446 if (ParseToken(
lltok::lparen,
"expected '(' in constantexpr"))
3450 if (Opc == Instruction::GetElementPtr) {
3451 if (ParseType(Ty) ||
3452 ParseToken(
lltok::comma,
"expected comma after getelementptr's type"))
3457 if (ParseGlobalValueVector(
3458 Elts, Opc == Instruction::GetElementPtr ? &InRangeOp :
nullptr) ||
3462 if (Opc == Instruction::GetElementPtr) {
3463 if (Elts.
size() == 0 ||
3464 !Elts[0]->getType()->isPtrOrPtrVectorTy())
3465 return Error(ID.
Loc,
"base of getelementptr must be a pointer");
3468 auto *BasePointerType = cast<PointerType>(BaseType->
getScalarType());
3469 if (Ty != BasePointerType->getElementType())
3472 "explicit pointee type doesn't match operand's pointee type");
3479 Type *ValTy = Val->getType();
3481 return Error(ID.
Loc,
"getelementptr index must be an integer");
3484 if (GEPWidth && (ValNumEl != GEPWidth))
3487 "getelementptr vector index has a wrong number of elements");
3490 GEPWidth = ValNumEl;
3495 if (!Indices.empty() && !Ty->
isSized(&Visited))
3496 return Error(ID.
Loc,
"base element of getelementptr must be sized");
3499 return Error(ID.
Loc,
"invalid getelementptr indices");
3502 if (*InRangeOp == 0)
3504 "inrange keyword may not appear on pointer operand");
3509 InBounds, InRangeOp);
3511 if (Elts.
size() != 3)
3512 return Error(ID.
Loc,
"expected three operands to select");
3517 }
else if (Opc == Instruction::ShuffleVector) {
3518 if (Elts.
size() != 3)
3519 return Error(ID.
Loc,
"expected three operands to shufflevector");
3521 return Error(ID.
Loc,
"invalid operands to shufflevector");
3524 }
else if (Opc == Instruction::ExtractElement) {
3525 if (Elts.
size() != 2)
3526 return Error(ID.
Loc,
"expected two operands to extractelement");
3528 return Error(ID.
Loc,
"invalid extractelement operands");
3531 assert(Opc == Instruction::InsertElement &&
"Unknown opcode");
3532 if (Elts.
size() != 3)
3533 return Error(ID.
Loc,
"expected three operands to insertelement");
3535 return Error(ID.
Loc,
"invalid insertelement operands");
3554 bool Parsed = ParseValID(ID) ||
3555 ConvertValIDToValue(Ty, ID, V,
nullptr,
false);
3556 if (V && !(C = dyn_cast<Constant>(V)))
3557 return Error(ID.
Loc,
"global values must be constants");
3561 bool LLParser::ParseGlobalTypeAndValue(
Constant *&V) {
3563 return ParseType(Ty) ||
3564 ParseGlobalValue(Ty, V);
3567 bool LLParser::parseOptionalComdat(
StringRef GlobalName,
Comdat *&C) {
3576 return TokError(
"expected comdat variable");
3579 if (ParseToken(
lltok::rparen,
"expected ')' after comdat var"))
3582 if (GlobalName.
empty())
3583 return TokError(
"comdat cannot be unnamed");
3584 C = getComdat(GlobalName, KwLoc);
3604 *InRangeOp = Elts.
size();
3607 if (ParseGlobalTypeAndValue(C))
return true;
3614 bool LLParser::ParseMDTuple(
MDNode *&MD,
bool IsDistinct) {
3616 if (ParseMDNodeVector(Elts))
3627 bool LLParser::ParseMDNode(
MDNode *&
N) {
3629 return ParseSpecializedMDNode(N);
3635 bool LLParser::ParseMDNodeTail(
MDNode *&N) {
3638 return ParseMDTuple(N);
3641 return ParseMDNodeID(N);
3647 template <
class FieldTy>
struct MDFieldImpl {
3648 typedef MDFieldImpl ImplTy;
3652 void assign(FieldTy Val) {
3654 this->Val = std::move(Val);
3657 explicit MDFieldImpl(FieldTy
Default)
3658 : Val(std::move(Default)), Seen(
false) {}
3665 template <
class FieldTypeA,
class FieldTypeB>
struct MDEitherFieldImpl {
3666 typedef MDEitherFieldImpl<FieldTypeA, FieldTypeB> ImplTy;
3677 void assign(FieldTypeA A) {
3679 this->A = std::move(A);
3683 void assign(FieldTypeB B) {
3685 this->B = std::move(B);
3689 explicit MDEitherFieldImpl(FieldTypeA DefaultA, FieldTypeB DefaultB)
3690 : A(std::move(DefaultA)),
B(std::move(DefaultB)), Seen(
false),
3691 WhatIs(IsInvalid) {}
3694 struct MDUnsignedField :
public MDFieldImpl<uint64_t> {
3698 : ImplTy(
Default), Max(Max) {}
3701 struct LineField :
public MDUnsignedField {
3702 LineField() : MDUnsignedField(0, UINT32_MAX) {}
3705 struct ColumnField :
public MDUnsignedField {
3706 ColumnField() : MDUnsignedField(0, UINT16_MAX) {}
3709 struct DwarfTagField :
public MDUnsignedField {
3715 struct DwarfMacinfoTypeField :
public MDUnsignedField {
3721 struct DwarfAttEncodingField :
public MDUnsignedField {
3725 struct DwarfVirtualityField :
public MDUnsignedField {
3729 struct DwarfLangField :
public MDUnsignedField {
3733 struct DwarfCCField :
public MDUnsignedField {
3737 struct EmissionKindField :
public MDUnsignedField {
3741 struct NameTableKindField :
public MDUnsignedField {
3742 NameTableKindField()
3748 struct DIFlagField :
public MDFieldImpl<DINode::DIFlags> {
3749 DIFlagField() : MDFieldImpl(DINode::FlagZero) {}
3752 struct DISPFlagField :
public MDFieldImpl<DISubprogram::DISPFlags> {
3753 DISPFlagField() : MDFieldImpl(DISubprogram::SPFlagZero) {}
3756 struct MDSignedField :
public MDFieldImpl<int64_t> {
3760 MDSignedField(int64_t
Default = 0)
3762 MDSignedField(int64_t
Default, int64_t Min, int64_t Max)
3763 : ImplTy(Default), Min(Min), Max(Max) {}
3766 struct MDBoolField :
public MDFieldImpl<bool> {
3770 struct MDField :
public MDFieldImpl<Metadata *> {
3773 MDField(
bool AllowNull =
true) : ImplTy(
nullptr), AllowNull(AllowNull) {}
3776 struct MDConstant :
public MDFieldImpl<ConstantAsMetadata *> {
3777 MDConstant() : ImplTy(
nullptr) {}
3780 struct MDStringField :
public MDFieldImpl<MDString *> {
3782 MDStringField(
bool AllowEmpty =
true)
3783 : ImplTy(
nullptr), AllowEmpty(AllowEmpty) {}
3786 struct MDFieldList :
public MDFieldImpl<SmallVector<Metadata *, 4>> {
3790 struct ChecksumKindField :
public MDFieldImpl<DIFile::ChecksumKind> {
3794 struct MDSignedOrMDField : MDEitherFieldImpl<MDSignedField, MDField> {
3795 MDSignedOrMDField(int64_t
Default = 0,
bool AllowNull =
true)
3796 : ImplTy(MDSignedField(
Default), MDField(AllowNull)) {}
3798 MDSignedOrMDField(int64_t
Default, int64_t Min, int64_t Max,
3799 bool AllowNull =
true)
3800 : ImplTy(MDSignedField(Default, Min, Max), MDField(AllowNull)) {}
3802 bool isMDSignedField()
const {
return WhatIs == IsTypeA; }
3803 bool isMDField()
const {
return WhatIs == IsTypeB; }
3804 int64_t getMDSignedValue()
const {
3805 assert(isMDSignedField() &&
"Wrong field type");
3808 Metadata *getMDFieldValue()
const {
3809 assert(isMDField() &&
"Wrong field type");
3814 struct MDSignedOrUnsignedField
3815 : MDEitherFieldImpl<MDSignedField, MDUnsignedField> {
3816 MDSignedOrUnsignedField() : ImplTy(MDSignedField(0), MDUnsignedField(0)) {}
3818 bool isMDSignedField()
const {
return WhatIs == IsTypeA; }
3819 bool isMDUnsignedField()
const {
return WhatIs == IsTypeB; }
3820 int64_t getMDSignedValue()
const {
3821 assert(isMDSignedField() &&
"Wrong field type");
3824 uint64_t getMDUnsignedValue()
const {
3825 assert(isMDUnsignedField() &&
"Wrong field type");
3836 MDUnsignedField &Result) {
3837 if (Lex.getKind() !=
lltok::APSInt || Lex.getAPSIntVal().isSigned())
3838 return TokError(
"expected unsigned integer");
3840 auto &U = Lex.getAPSIntVal();
3841 if (U.ugt(Result.Max))
3842 return TokError(
"value for '" + Name +
"' too large, limit is " +
3844 Result.assign(U.getZExtValue());
3845 assert(Result.Val <= Result.Max &&
"Expected value in range");
3851 bool LLParser::ParseMDField(
LocTy Loc,
StringRef Name, LineField &Result) {
3852 return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
3855 bool LLParser::ParseMDField(
LocTy Loc,
StringRef Name, ColumnField &Result) {
3856 return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
3860 bool LLParser::ParseMDField(
LocTy Loc,
StringRef Name, DwarfTagField &Result) {
3862 return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
3865 return TokError(
"expected DWARF tag");
3869 return TokError(
"invalid DWARF tag" +
Twine(
" '") + Lex.getStrVal() +
"'");
3870 assert(Tag <= Result.Max &&
"Expected valid DWARF tag");
3879 DwarfMacinfoTypeField &Result) {
3881 return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
3884 return TokError(
"expected DWARF macinfo type");
3889 "invalid DWARF macinfo type" +
Twine(
" '") + Lex.getStrVal() +
"'");
3890 assert(Macinfo <= Result.Max &&
"Expected valid DWARF macinfo type");
3892 Result.assign(Macinfo);
3899 DwarfVirtualityField &Result) {
3901 return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
3904 return TokError(
"expected DWARF virtuality code");
3908 return TokError(
"invalid DWARF virtuality code" +
Twine(
" '") +
3909 Lex.getStrVal() +
"'");
3910 assert(Virtuality <= Result.Max &&
"Expected valid DWARF virtuality code");
3911 Result.assign(Virtuality);
3917 bool LLParser::ParseMDField(
LocTy Loc,
StringRef Name, DwarfLangField &Result) {
3919 return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
3922 return TokError(
"expected DWARF language");
3926 return TokError(
"invalid DWARF language" +
Twine(
" '") + Lex.getStrVal() +
3928 assert(Lang <= Result.Max &&
"Expected valid DWARF language");
3929 Result.assign(Lang);
3935 bool LLParser::ParseMDField(
LocTy Loc,
StringRef Name, DwarfCCField &Result) {
3937 return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
3940 return TokError(
"expected DWARF calling convention");
3944 return TokError(
"invalid DWARF calling convention" +
Twine(
" '") + Lex.getStrVal() +
3946 assert(CC <= Result.Max &&
"Expected valid DWARF calling convention");
3953 bool LLParser::ParseMDField(
LocTy Loc,
StringRef Name, EmissionKindField &Result) {
3955 return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
3958 return TokError(
"expected emission kind");
3962 return TokError(
"invalid emission kind" +
Twine(
" '") + Lex.getStrVal() +
3964 assert(*
Kind <= Result.Max &&
"Expected valid emission kind");
3965 Result.assign(*
Kind);
3972 NameTableKindField &Result) {
3974 return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
3977 return TokError(
"expected nameTable kind");
3981 return TokError(
"invalid nameTable kind" +
Twine(
" '") + Lex.getStrVal() +
3983 assert(((
unsigned)*
Kind) <= Result.Max &&
"Expected valid nameTable kind");
3984 Result.assign((
unsigned)*Kind);
3991 DwarfAttEncodingField &Result) {
3993 return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
3996 return TokError(
"expected DWARF type attribute encoding");
4000 return TokError(
"invalid DWARF type attribute encoding" +
Twine(
" '") +
4001 Lex.getStrVal() +
"'");
4002 assert(Encoding <= Result.Max &&
"Expected valid DWARF language");
4003 Result.assign(Encoding);
4013 bool LLParser::ParseMDField(
LocTy Loc,
StringRef Name, DIFlagField &Result) {
4017 if (Lex.getKind() ==
lltok::APSInt && !Lex.getAPSIntVal().isSigned()) {
4019 bool Res = ParseUInt32(TempVal);
4025 return TokError(
"expected debug info flag");
4029 return TokError(
Twine(
"invalid debug info flag flag '") +
4030 Lex.getStrVal() +
"'");
4044 Result.assign(Combined);
4053 bool LLParser::ParseMDField(
LocTy Loc,
StringRef Name, DISPFlagField &Result) {
4057 if (Lex.getKind() ==
lltok::APSInt && !Lex.getAPSIntVal().isSigned()) {
4059 bool Res = ParseUInt32(TempVal);
4065 return TokError(
"expected debug info flag");
4069 return TokError(
Twine(
"invalid subprogram debug info flag '") +
4070 Lex.getStrVal() +
"'");
4084 Result.assign(Combined);
4090 MDSignedField &Result) {
4092 return TokError(
"expected signed integer");
4094 auto &S = Lex.getAPSIntVal();
4096 return TokError(
"value for '" + Name +
"' too small, limit is " +
4099 return TokError(
"value for '" + Name +
"' too large, limit is " +
4101 Result.assign(S.getExtValue());
4102 assert(Result.Val >= Result.Min &&
"Expected value in range");
4103 assert(Result.Val <= Result.Max &&
"Expected value in range");
4109 bool LLParser::ParseMDField(
LocTy Loc,
StringRef Name, MDBoolField &Result) {
4110 switch (Lex.getKind()) {
4112 return TokError(
"expected 'true' or 'false'");
4114 Result.assign(
true);
4117 Result.assign(
false);
4125 bool LLParser::ParseMDField(
LocTy Loc,
StringRef Name, MDField &Result) {
4127 if (!Result.AllowNull)
4128 return TokError(
"'" + Name +
"' cannot be null");
4130 Result.assign(
nullptr);
4135 if (ParseMetadata(MD,
nullptr))
4144 MDSignedOrMDField &Result) {
4147 MDSignedField Res = Result.A;
4148 if (!ParseMDField(Loc, Name, Res)) {
4156 MDField Res = Result.B;
4157 if (!ParseMDField(Loc, Name, Res)) {
4167 MDSignedOrUnsignedField &Result) {
4171 if (Lex.getAPSIntVal().isSigned()) {
4172 MDSignedField Res = Result.A;
4173 if (ParseMDField(Loc, Name, Res))
4179 MDUnsignedField Res = Result.B;
4180 if (ParseMDField(Loc, Name, Res))
4187 bool LLParser::ParseMDField(
LocTy Loc,
StringRef Name, MDStringField &Result) {
4188 LocTy ValueLoc = Lex.getLoc();
4190 if (ParseStringConstant(S))
4193 if (!Result.AllowEmpty && S.empty())
4194 return Error(ValueLoc,
"'" + Name +
"' cannot be empty");
4201 bool LLParser::ParseMDField(
LocTy Loc,
StringRef Name, MDFieldList &Result) {
4203 if (ParseMDNodeVector(MDs))
4206 Result.assign(std::move(MDs));
4212 ChecksumKindField &Result) {
4218 "invalid checksum kind" +
Twine(
" '") + Lex.getStrVal() +
"'");
4220 Result.assign(*CSKind);
4227 template <
class ParserTy>
4228 bool LLParser::ParseMDFieldsImplBody(ParserTy
parseField) {
4231 return TokError(
"expected field label here");
4240 template <
class ParserTy>
4241 bool LLParser::ParseMDFieldsImpl(ParserTy
parseField,
LocTy &ClosingLoc) {
4251 ClosingLoc = Lex.getLoc();
4255 template <
class FieldTy>
4256 bool LLParser::ParseMDField(
StringRef Name, FieldTy &Result) {
4258 return TokError(
"field '" + Name +
"' cannot be specified more than once");
4260 LocTy Loc = Lex.getLoc();
4262 return ParseMDField(Loc, Name, Result);
4265 bool LLParser::ParseSpecializedMDNode(
MDNode *&N,
bool IsDistinct) {
4268 #define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \ 4269 if (Lex.getStrVal() == #CLASS) \ 4270 return Parse##CLASS(N, IsDistinct); 4271 #include "llvm/IR/Metadata.def" 4273 return TokError(
"expected metadata type");
4276 #define DECLARE_FIELD(NAME, TYPE, INIT) TYPE NAME INIT 4277 #define NOP_FIELD(NAME, TYPE, INIT) 4278 #define REQUIRE_FIELD(NAME, TYPE, INIT) \ 4280 return Error(ClosingLoc, "missing required field '" #NAME "'"); 4281 #define PARSE_MD_FIELD(NAME, TYPE, DEFAULT) \ 4282 if (Lex.getStrVal() == #NAME) \ 4283 return ParseMDField(#NAME, NAME); 4284 #define PARSE_MD_FIELDS() \ 4285 VISIT_MD_FIELDS(DECLARE_FIELD, DECLARE_FIELD) \ 4288 if (ParseMDFieldsImpl([&]() -> bool { \ 4289 VISIT_MD_FIELDS(PARSE_MD_FIELD, PARSE_MD_FIELD) \ 4290 return TokError(Twine("invalid field '") + Lex.getStrVal() + "'"); \ 4293 VISIT_MD_FIELDS(NOP_FIELD, REQUIRE_FIELD) \ 4295 #define GET_OR_DISTINCT(CLASS, ARGS) \ 4296 (IsDistinct ? CLASS::getDistinct ARGS : CLASS::get ARGS) 4301 bool LLParser::ParseDILocation(
MDNode *&Result,
bool IsDistinct) {
4302 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4303 OPTIONAL(line, LineField, ); \ 4304 OPTIONAL(column, ColumnField, ); \ 4305 REQUIRED(scope, MDField, ( false)); \ 4306 OPTIONAL(inlinedAt, MDField, ); \ 4307 OPTIONAL(isImplicitCode, MDBoolField, (false)); 4309 #undef VISIT_MD_FIELDS 4313 inlinedAt.Val, isImplicitCode.Val));
4319 bool LLParser::ParseGenericDINode(
MDNode *&Result,
bool IsDistinct) {
4320 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4321 REQUIRED(tag, DwarfTagField, ); \ 4322 OPTIONAL(header, MDStringField, ); \ 4323 OPTIONAL(operands, MDFieldList, ); 4325 #undef VISIT_MD_FIELDS 4328 (
Context, tag.Val, header.Val, operands.Val));
4335 bool LLParser::ParseDISubrange(
MDNode *&Result,
bool IsDistinct) {
4336 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4337 REQUIRED(count, MDSignedOrMDField, (-1, -1, INT64_MAX, false)); \ 4338 OPTIONAL(lowerBound, MDSignedField, ); 4340 #undef VISIT_MD_FIELDS 4342 if (
count.isMDSignedField())
4345 else if (
count.isMDField())
4356 bool LLParser::ParseDIEnumerator(
MDNode *&Result,
bool IsDistinct) {
4357 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4358 REQUIRED(name, MDStringField, ); \ 4359 REQUIRED(value, MDSignedOrUnsignedField, ); \ 4360 OPTIONAL(isUnsigned, MDBoolField, (false)); 4362 #undef VISIT_MD_FIELDS 4364 if (isUnsigned.Val && value.isMDSignedField())
4365 return TokError(
"unsigned enumerator with negative value");
4367 int64_t
Value = value.isMDSignedField()
4368 ? value.getMDSignedValue()
4369 :
static_cast<int64_t
>(value.getMDUnsignedValue());
4379 bool LLParser::ParseDIBasicType(
MDNode *&Result,
bool IsDistinct) {
4380 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4381 OPTIONAL(tag, DwarfTagField, (dwarf::DW_TAG_base_type)); \ 4382 OPTIONAL(name, MDStringField, ); \ 4383 OPTIONAL(size, MDUnsignedField, (0, UINT64_MAX)); \ 4384 OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); \ 4385 OPTIONAL(encoding, DwarfAttEncodingField, ); \ 4386 OPTIONAL(flags, DIFlagField, ); 4388 #undef VISIT_MD_FIELDS 4391 align.Val, encoding.Val, flags.Val));
4400 bool LLParser::ParseDIDerivedType(
MDNode *&Result,
bool IsDistinct) {
4401 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4402 REQUIRED(tag, DwarfTagField, ); \ 4403 OPTIONAL(name, MDStringField, ); \ 4404 OPTIONAL(file, MDField, ); \ 4405 OPTIONAL(line, LineField, ); \ 4406 OPTIONAL(scope, MDField, ); \ 4407 REQUIRED(baseType, MDField, ); \ 4408 OPTIONAL(size, MDUnsignedField, (0, UINT64_MAX)); \ 4409 OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); \ 4410 OPTIONAL(offset, MDUnsignedField, (0, UINT64_MAX)); \ 4411 OPTIONAL(flags, DIFlagField, ); \ 4412 OPTIONAL(extraData, MDField, ); \ 4413 OPTIONAL(dwarfAddressSpace, MDUnsignedField, (UINT32_MAX, UINT32_MAX)); 4415 #undef VISIT_MD_FIELDS 4418 if (dwarfAddressSpace.Val != UINT32_MAX)
4419 DWARFAddressSpace = dwarfAddressSpace.Val;
4423 scope.Val, baseType.Val,
size.Val, align.Val,
4424 offset.Val, DWARFAddressSpace, flags.Val,
4429 bool LLParser::ParseDICompositeType(
MDNode *&Result,
bool IsDistinct) {
4430 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4431 REQUIRED(tag, DwarfTagField, ); \ 4432 OPTIONAL(name, MDStringField, ); \ 4433 OPTIONAL(file, MDField, ); \ 4434 OPTIONAL(line, LineField, ); \ 4435 OPTIONAL(scope, MDField, ); \ 4436 OPTIONAL(baseType, MDField, ); \ 4437 OPTIONAL(size, MDUnsignedField, (0, UINT64_MAX)); \ 4438 OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); \ 4439 OPTIONAL(offset, MDUnsignedField, (0, UINT64_MAX)); \ 4440 OPTIONAL(flags, DIFlagField, ); \ 4441 OPTIONAL(elements, MDField, ); \ 4442 OPTIONAL(runtimeLang, DwarfLangField, ); \ 4443 OPTIONAL(vtableHolder, MDField, ); \ 4444 OPTIONAL(templateParams, MDField, ); \ 4445 OPTIONAL(identifier, MDStringField, ); \ 4446 OPTIONAL(discriminator, MDField, ); 4448 #undef VISIT_MD_FIELDS 4454 scope.Val, baseType.Val,
size.Val, align.Val, offset.Val, flags.Val,
4455 elements.Val, runtimeLang.Val, vtableHolder.Val,
4456 templateParams.Val, discriminator.Val)) {
4465 (
Context, tag.Val,
name.Val,
file.Val, line.Val, scope.Val, baseType.Val,
4466 size.Val, align.Val, offset.Val, flags.Val, elements.Val,
4467 runtimeLang.Val, vtableHolder.Val, templateParams.Val, identifier.Val,
4468 discriminator.Val));
4472 bool LLParser::ParseDISubroutineType(
MDNode *&Result,
bool IsDistinct) {
4473 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4474 OPTIONAL(flags, DIFlagField, ); \ 4475 OPTIONAL(cc, DwarfCCField, ); \ 4476 REQUIRED(types, MDField, ); 4478 #undef VISIT_MD_FIELDS 4481 (
Context, flags.Val, cc.Val, types.Val));
4490 bool LLParser::ParseDIFile(
MDNode *&Result,
bool IsDistinct) {
4494 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4495 REQUIRED(filename, MDStringField, ); \ 4496 REQUIRED(directory, MDStringField, ); \ 4497 OPTIONAL(checksumkind, ChecksumKindField, (DIFile::CSK_MD5)); \ 4498 OPTIONAL(checksum, MDStringField, ); \ 4499 OPTIONAL(source, MDStringField, ); 4501 #undef VISIT_MD_FIELDS 4504 if (checksumkind.Seen && checksum.Seen)
4505 OptChecksum.
emplace(checksumkind.Val, checksum.Val);
4506 else if (checksumkind.Seen || checksum.Seen)
4507 return Lex.Error(
"'checksumkind' and 'checksum' must be provided together");
4511 OptSource = source.Val;
4513 OptChecksum, OptSource));
4523 bool LLParser::ParseDICompileUnit(
MDNode *&Result,
bool IsDistinct) {
4525 return Lex.Error(
"missing 'distinct', required for !DICompileUnit");
4527 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4528 REQUIRED(language, DwarfLangField, ); \ 4529 REQUIRED(file, MDField, ( false)); \ 4530 OPTIONAL(producer, MDStringField, ); \ 4531 OPTIONAL(isOptimized, MDBoolField, ); \ 4532 OPTIONAL(flags, MDStringField, ); \ 4533 OPTIONAL(runtimeVersion, MDUnsignedField, (0, UINT32_MAX)); \ 4534 OPTIONAL(splitDebugFilename, MDStringField, ); \ 4535 OPTIONAL(emissionKind, EmissionKindField, ); \ 4536 OPTIONAL(enums, MDField, ); \ 4537 OPTIONAL(retainedTypes, MDField, ); \ 4538 OPTIONAL(globals, MDField, ); \ 4539 OPTIONAL(imports, MDField, ); \ 4540 OPTIONAL(macros, MDField, ); \ 4541 OPTIONAL(dwoId, MDUnsignedField, ); \ 4542 OPTIONAL(splitDebugInlining, MDBoolField, = true); \ 4543 OPTIONAL(debugInfoForProfiling, MDBoolField, = false); \ 4544 OPTIONAL(nameTableKind, NameTableKindField, ); \ 4545 OPTIONAL(debugBaseAddress, MDBoolField, = false); 4547 #undef VISIT_MD_FIELDS 4550 Context, language.Val,
file.Val, producer.Val, isOptimized.Val, flags.Val,
4551 runtimeVersion.Val, splitDebugFilename.Val, emissionKind.Val, enums.Val,
4552 retainedTypes.Val,
globals.Val, imports.Val, macros.Val, dwoId.Val,
4553 splitDebugInlining.Val, debugInfoForProfiling.Val, nameTableKind.Val,
4554 debugBaseAddress.Val);
4566 bool LLParser::ParseDISubprogram(
MDNode *&Result,
bool IsDistinct) {
4567 auto Loc = Lex.getLoc();
4568 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4569 OPTIONAL(scope, MDField, ); \ 4570 OPTIONAL(name, MDStringField, ); \ 4571 OPTIONAL(linkageName, MDStringField, ); \ 4572 OPTIONAL(file, MDField, ); \ 4573 OPTIONAL(line, LineField, ); \ 4574 OPTIONAL(type, MDField, ); \ 4575 OPTIONAL(isLocal, MDBoolField, ); \ 4576 OPTIONAL(isDefinition, MDBoolField, (true)); \ 4577 OPTIONAL(scopeLine, LineField, ); \ 4578 OPTIONAL(containingType, MDField, ); \ 4579 OPTIONAL(virtuality, DwarfVirtualityField, ); \ 4580 OPTIONAL(virtualIndex, MDUnsignedField, (0, UINT32_MAX)); \ 4581 OPTIONAL(thisAdjustment, MDSignedField, (0, INT32_MIN, INT32_MAX)); \ 4582 OPTIONAL(flags, DIFlagField, ); \ 4583 OPTIONAL(spFlags, DISPFlagField, ); \ 4584 OPTIONAL(isOptimized, MDBoolField, ); \ 4585 OPTIONAL(unit, MDField, ); \ 4586 OPTIONAL(templateParams, MDField, ); \ 4587 OPTIONAL(declaration, MDField, ); \ 4588 OPTIONAL(retainedNodes, MDField, ); \ 4589 OPTIONAL(thrownTypes, MDField, ); 4591 #undef VISIT_MD_FIELDS 4596 spFlags.Seen ? spFlags.Val
4598 isOptimized.Val, virtuality.Val);
4599 if ((SPFlags & DISubprogram::SPFlagDefinition) && !IsDistinct)
4602 "missing 'distinct', required for !DISubprogram that is a Definition");
4606 type.Val, scopeLine.Val, containingType.Val, virtualIndex.Val,
4607 thisAdjustment.Val, flags.Val, SPFlags, unit.Val, templateParams.Val,
4608 declaration.Val, retainedNodes.Val, thrownTypes.Val));
4614 bool LLParser::ParseDILexicalBlock(
MDNode *&Result,
bool IsDistinct) {
4615 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4616 REQUIRED(scope, MDField, ( false)); \ 4617 OPTIONAL(file, MDField, ); \ 4618 OPTIONAL(line, LineField, ); \ 4619 OPTIONAL(column, ColumnField, ); 4621 #undef VISIT_MD_FIELDS 4630 bool LLParser::ParseDILexicalBlockFile(
MDNode *&Result,
bool IsDistinct) {
4631 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4632 REQUIRED(scope, MDField, ( false)); \ 4633 OPTIONAL(file, MDField, ); \ 4634 REQUIRED(discriminator, MDUnsignedField, (0, UINT32_MAX)); 4636 #undef VISIT_MD_FIELDS 4639 (
Context, scope.Val,
file.Val, discriminator.Val));
4645 bool LLParser::ParseDINamespace(
MDNode *&Result,
bool IsDistinct) {
4646 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4647 REQUIRED(scope, MDField, ); \ 4648 OPTIONAL(name, MDStringField, ); \ 4649 OPTIONAL(exportSymbols, MDBoolField, ); 4651 #undef VISIT_MD_FIELDS 4654 (
Context, scope.Val,
name.Val, exportSymbols.Val));
4660 bool LLParser::ParseDIMacro(
MDNode *&Result,
bool IsDistinct) {
4661 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4662 REQUIRED(type, DwarfMacinfoTypeField, ); \ 4663 OPTIONAL(line, LineField, ); \ 4664 REQUIRED(name, MDStringField, ); \ 4665 OPTIONAL(value, MDStringField, ); 4667 #undef VISIT_MD_FIELDS 4676 bool LLParser::ParseDIMacroFile(
MDNode *&Result,
bool IsDistinct) {
4677 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4678 OPTIONAL(type, DwarfMacinfoTypeField, (dwarf::DW_MACINFO_start_file)); \ 4679 OPTIONAL(line, LineField, ); \ 4680 REQUIRED(file, MDField, ); \ 4681 OPTIONAL(nodes, MDField, ); 4683 #undef VISIT_MD_FIELDS 4693 bool LLParser::ParseDIModule(
MDNode *&Result,
bool IsDistinct) {
4694 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4695 REQUIRED(scope, MDField, ); \ 4696 REQUIRED(name, MDStringField, ); \ 4697 OPTIONAL(configMacros, MDStringField, ); \ 4698 OPTIONAL(includePath, MDStringField, ); \ 4699 OPTIONAL(isysroot, MDStringField, ); 4701 #undef VISIT_MD_FIELDS 4704 configMacros.Val, includePath.Val, isysroot.Val));
4710 bool LLParser::ParseDITemplateTypeParameter(
MDNode *&Result,
bool IsDistinct) {
4711 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4712 OPTIONAL(name, MDStringField, ); \ 4713 REQUIRED(type, MDField, ); 4715 #undef VISIT_MD_FIELDS 4725 bool LLParser::ParseDITemplateValueParameter(
MDNode *&Result,
bool IsDistinct) {
4726 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4727 OPTIONAL(tag, DwarfTagField, (dwarf::DW_TAG_template_value_parameter)); \ 4728 OPTIONAL(name, MDStringField, ); \ 4729 OPTIONAL(type, MDField, ); \ 4730 REQUIRED(value, MDField, ); 4732 #undef VISIT_MD_FIELDS 4744 bool LLParser::ParseDIGlobalVariable(
MDNode *&Result,
bool IsDistinct) {
4745 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4746 REQUIRED(name, MDStringField, ( false)); \ 4747 OPTIONAL(scope, MDField, ); \ 4748 OPTIONAL(linkageName, MDStringField, ); \ 4749 OPTIONAL(file, MDField, ); \ 4750 OPTIONAL(line, LineField, ); \ 4751 OPTIONAL(type, MDField, ); \ 4752 OPTIONAL(isLocal, MDBoolField, ); \ 4753 OPTIONAL(isDefinition, MDBoolField, (true)); \ 4754 OPTIONAL(templateParams, MDField, ); \ 4755 OPTIONAL(declaration, MDField, ); \ 4756 OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); 4758 #undef VISIT_MD_FIELDS 4763 line.Val,
type.Val, isLocal.Val, isDefinition.Val,
4764 declaration.Val, templateParams.Val, align.Val));
4775 bool LLParser::ParseDILocalVariable(
MDNode *&Result,
bool IsDistinct) {
4776 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4777 REQUIRED(scope, MDField, ( false)); \ 4778 OPTIONAL(name, MDStringField, ); \ 4779 OPTIONAL(arg, MDUnsignedField, (0, UINT16_MAX)); \ 4780 OPTIONAL(file, MDField, ); \ 4781 OPTIONAL(line, LineField, ); \ 4782 OPTIONAL(type, MDField, ); \ 4783 OPTIONAL(flags, DIFlagField, ); \ 4784 OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); 4786 #undef VISIT_MD_FIELDS 4790 type.Val, arg.Val, flags.Val, align.Val));
4796 bool LLParser::ParseDILabel(
MDNode *&Result,
bool IsDistinct) {
4797 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4798 REQUIRED(scope, MDField, ( false)); \ 4799 REQUIRED(name, MDStringField, ); \ 4800 REQUIRED(file, MDField, ); \ 4801 REQUIRED(line, LineField, ); 4803 #undef VISIT_MD_FIELDS 4812 bool LLParser::ParseDIExpression(
MDNode *&Result,
bool IsDistinct) {
4828 return TokError(
Twine(
"invalid DWARF op '") + Lex.getStrVal() +
"'");
4831 if (Lex.getKind() !=
lltok::APSInt || Lex.getAPSIntVal().isSigned())
4832 return TokError(
"expected unsigned integer");
4834 auto &U = Lex.getAPSIntVal();
4850 bool LLParser::ParseDIGlobalVariableExpression(
MDNode *&Result,
4852 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4853 REQUIRED(var, MDField, ); \ 4854 REQUIRED(expr, MDField, ); 4856 #undef VISIT_MD_FIELDS 4866 bool LLParser::ParseDIObjCProperty(
MDNode *&Result,
bool IsDistinct) {
4867 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4868 OPTIONAL(name, MDStringField, ); \ 4869 OPTIONAL(file, MDField, ); \ 4870 OPTIONAL(line, LineField, ); \ 4871 OPTIONAL(setter, MDStringField, ); \ 4872 OPTIONAL(getter, MDStringField, ); \ 4873 OPTIONAL(attributes, MDUnsignedField, (0, UINT32_MAX)); \ 4874 OPTIONAL(type, MDField, ); 4876 #undef VISIT_MD_FIELDS 4887 bool LLParser::ParseDIImportedEntity(
MDNode *&Result,
bool IsDistinct) {
4888 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ 4889 REQUIRED(tag, DwarfTagField, ); \ 4890 REQUIRED(scope, MDField, ); \ 4891 OPTIONAL(entity, MDField, ); \ 4892 OPTIONAL(file, MDField, ); \ 4893 OPTIONAL(line, LineField, ); \ 4894 OPTIONAL(name, MDStringField, ); 4896 #undef VISIT_MD_FIELDS 4900 (
Context, tag.Val, scope.Val, entity.Val,
file.Val, line.Val,
name.Val));
4904 #undef PARSE_MD_FIELD 4906 #undef REQUIRE_FIELD 4907 #undef DECLARE_FIELD 4916 bool LLParser::ParseMetadataAsValue(
Value *&V, PerFunctionState &PFS) {
4919 if (ParseMetadata(MD, &PFS))
4930 bool LLParser::ParseValueAsMetadata(
Metadata *&MD,
const Twine &TypeMsg,
4931 PerFunctionState *PFS) {
4934 if (ParseType(Ty, TypeMsg, Loc))
4937 return Error(Loc,
"invalid metadata-value-metadata roundtrip");
4940 if (ParseValue(Ty, V, PFS))
4955 bool LLParser::ParseMetadata(
Metadata *&MD, PerFunctionState *PFS) {
4958 if (ParseSpecializedMDNode(N))
4967 return ParseValueAsMetadata(MD,
"expected metadata operand", PFS);
4977 if (ParseMDString(S))
4987 if (ParseMDNodeTail(N))
4997 bool LLParser::ConvertValIDToValue(
Type *Ty,
ValID &ID,
Value *&V,
4998 PerFunctionState *PFS,
bool IsCall) {
5000 return Error(ID.
Loc,
"functions are not values, refer to them as pointers");
5004 if (!PFS)
return Error(ID.
Loc,
"invalid use of function-local name");
5005 V = PFS->GetVal(ID.
UIntVal, Ty, ID.
Loc, IsCall);
5006 return V ==
nullptr;
5008 if (!PFS)
return Error(ID.
Loc,
"invalid use of function-local name");
5009 V = PFS->GetVal(ID.
StrVal, Ty, ID.
Loc, IsCall);
5010 return V ==
nullptr;
5013 return Error(ID.
Loc,
"invalid type for inline asm constraint string");
5020 V = GetGlobalVal(ID.
StrVal, Ty, ID.
Loc, IsCall);
5021 return V ==
nullptr;
5023 V = GetGlobalVal(ID.
UIntVal, Ty, ID.
Loc, IsCall);
5024 return V ==
nullptr;
5027 return Error(ID.
Loc,
"integer constant must have integer type");
5034 return Error(ID.
Loc,
"floating point constant invalid for type");
5050 return Error(ID.
Loc,
"floating point constant does not have type '" +
5056 return Error(ID.
Loc,
"null must be a pointer type");
5062 return Error(ID.
Loc,
"invalid type for undef constant");
5066 if (!Ty->
isArrayTy() || cast<ArrayType>(Ty)->getNumElements() != 0)
5067 return Error(ID.
Loc,
"invalid empty array initializer");
5073 return Error(ID.
Loc,
"invalid type for null constant");
5078 return Error(ID.
Loc,
"invalid type for none constant");
5083 return Error(ID.
Loc,
"constant expression type mismatch");
5092 "initializer with struct type has wrong # elements");
5094 return Error(ID.
Loc,
"packed'ness of initializer and type don't match");
5097 for (
unsigned i = 0, e = ID.
UIntVal; i != e; ++i)
5100 " of struct initializer doesn't match struct element type");
5105 return Error(ID.
Loc,
"constant expression type mismatch");
5111 bool LLParser::parseConstantValue(
Type *Ty,
Constant *&C) {
5114 auto Loc = Lex.getLoc();
5115 if (ParseValID(ID,
nullptr))
5125 if (ConvertValIDToValue(Ty, ID, V,
nullptr,
false))
5127 assert(isa<Constant>(V) &&
"Expected a constant value");
5128 C = cast<Constant>(V);
5135 return Error(Loc,
"expected a constant value");
5139 bool LLParser::ParseValue(
Type *Ty,
Value *&V, PerFunctionState *PFS) {
5142 return ParseValID(ID, PFS) ||
5143 ConvertValIDToValue(Ty, ID, V, PFS,
false);
5146 bool LLParser::ParseTypeAndValue(
Value *&V, PerFunctionState *PFS) {
5148 return ParseType(Ty) ||
5149 ParseValue(Ty, V, PFS);
5153 PerFunctionState &PFS) {
5156 if (ParseTypeAndValue(V, PFS))
return true;
5157 if (!isa<BasicBlock>(V))
5158 return Error(Loc,
"expected a basic block");
5159 BB = cast<BasicBlock>(V);
5168 bool LLParser::ParseFunctionHeader(
Function *&Fn,
bool isDefine) {
5170 LocTy LinkageLoc = Lex.getLoc();
5173 unsigned DLLStorageClass;
5178 Type *RetType =
nullptr;
5179 LocTy RetTypeLoc = Lex.getLoc();
5180 if (ParseOptionalLinkage(Linkage, HasLinkage, Visibility, DLLStorageClass,
5182 ParseOptionalCallingConv(CC) || ParseOptionalReturnAttrs(RetAttrs) ||
5183 ParseType(RetType, RetTypeLoc,
true ))
5192 return Error(LinkageLoc,
"invalid linkage for function definition");
5202 return Error(LinkageLoc,
"invalid linkage for function declaration");
5206 return Error(LinkageLoc,
"invalid function linkage type");
5210 return Error(LinkageLoc,
5211 "symbol with local linkage must have default visibility");
5214 return Error(RetTypeLoc,
"invalid function return type");
5216 LocTy NameLoc = Lex.getLoc();
5218 std::string FunctionName;
5220 FunctionName = Lex.getStrVal();
5222 unsigned NameID = Lex.getUIntVal();
5224 if (NameID != NumberedVals.size())
5225 return TokError(
"function expected to be numbered '%" +
5226 Twine(NumberedVals.size()) +
"'");
5228 return TokError(
"expected function name");
5234 return TokError(
"expected '(' in function argument list");
5239 std::vector<unsigned> FwdRefAttrGrps;
5245 unsigned AddrSpace = 0;
5251 if (ParseArgumentList(ArgList, isVarArg) ||
5252 ParseOptionalUnnamedAddr(UnnamedAddr) ||
5253 ParseOptionalProgramAddrSpace(AddrSpace) ||
5254 ParseFnAttributeValuePairs(FuncAttrs, FwdRefAttrGrps,
false,
5257 ParseStringConstant(Section)) ||
5258 parseOptionalComdat(FunctionName, C) ||
5259 ParseOptionalAlignment(Alignment) ||
5261 ParseStringConstant(GC)) ||
5263 ParseGlobalTypeAndValue(Prefix)) ||
5265 ParseGlobalTypeAndValue(Prologue)) ||
5267 ParseGlobalTypeAndValue(PersonalityFn)))
5271 return Error(BuiltinLoc,
"'builtin' attribute not valid on function");
5281 std::vector<Type*> ParamTypeList;
5284 for (
unsigned i = 0, e = ArgList.
size(); i != e; ++i) {
5285 ParamTypeList.push_back(ArgList[i].Ty);
5294 return Error(RetTypeLoc,
"functions with 'sret' argument must return void");
5301 if (!FunctionName.empty()) {
5304 auto FRVI = ForwardRefVals.find(FunctionName);
5305 if (FRVI != ForwardRefVals.end()) {
5306 Fn = M->getFunction(FunctionName);
5308 return Error(FRVI->second.second,
"invalid forward reference to " 5309 "function as global value!");
5311 return Error(FRVI->second.second,
"invalid forward reference to " 5312 "function '" + FunctionName +
"' with wrong type: " 5315 ForwardRefVals.erase(FRVI);
5316 }
else if ((Fn = M->getFunction(FunctionName))) {
5318 return Error(NameLoc,
"invalid redefinition of function '" +
5319 FunctionName +
"'");
5320 }
else if (M->getNamedValue(FunctionName)) {
5321 return Error(NameLoc,
"redefinition of function '@" + FunctionName +
"'");
5327 auto I = ForwardRefValIDs.find(NumberedVals.size());
5328 if (
I != ForwardRefValIDs.end()) {
5329 Fn = cast<Function>(
I->second.first);
5331 return Error(NameLoc,
"type of definition and forward reference of '@" +
5332 Twine(NumberedVals.size()) +
"' disagree: " 5335 ForwardRefValIDs.erase(
I);
5343 M->getFunctionList().splice(M->end(), M->getFunctionList(), Fn);
5347 if (FunctionName.empty())
5348 NumberedVals.push_back(Fn);
5361 if (!GC.empty()) Fn->
setGC(GC);
5364 ForwardRefAttrGroups[Fn] = FwdRefAttrGrps;
5368 for (
unsigned i = 0, e = ArgList.
size(); i != e; ++i, ++ArgIt) {
5370 if (ArgList[i].Name.
empty())
continue;
5373 ArgIt->
setName(ArgList[i].Name);
5375 if (ArgIt->
getName() != ArgList[i].Name)
5376 return Error(ArgList[i].Loc,
"redefinition of argument '%" +
5377 ArgList[i].Name +
"'");
5385 if (FunctionName.empty()) {
5387 ID.
UIntVal = NumberedVals.size() - 1;
5390 ID.
StrVal = FunctionName;
5392 auto Blocks = ForwardRefBlockAddresses.find(ID);
5393 if (Blocks != ForwardRefBlockAddresses.end())
5394 return Error(Blocks->first.Loc,
5395 "cannot take blockaddress inside a declaration");
5399 bool LLParser::PerFunctionState::resolveForwardRefBlockAddresses() {
5409 auto Blocks =
P.ForwardRefBlockAddresses.find(ID);
5410 if (Blocks ==
P.ForwardRefBlockAddresses.end())
5413 for (
const auto &
I : Blocks->second) {
5414 const ValID &BBID =
I.first;
5418 "Expected local id or name");
5425 return P.Error(BBID.
Loc,
"referenced value is not a basic block");
5431 P.ForwardRefBlockAddresses.erase(Blocks);
5437 bool LLParser::ParseFunctionBody(
Function &Fn) {
5439 return TokError(
"expected '{' in function body");
5443 if (!Fn.
hasName()) FunctionNumber = NumberedVals.size()-1;
5445 PerFunctionState PFS(*
this, Fn, FunctionNumber);
5449 if (PFS.resolveForwardRefBlockAddresses())
5455 return TokError(
"function body requires at least one basic block");
5459 if (ParseBasicBlock(PFS))
return true;
5462 if (ParseUseListOrder(&PFS))
5469 return PFS.FinishFunction();
5474 bool LLParser::ParseBasicBlock(PerFunctionState &PFS) {
5477 LocTy NameLoc = Lex.getLoc();
5479 Name = Lex.getStrVal();
5483 BasicBlock *BB = PFS.DefineBB(Name, NameLoc);
5485 return Error(NameLoc,
5486 "unable to create block named '" + Name +
"'");
5488 std::string NameStr;
5495 LocTy NameLoc = Lex.getLoc();
5500 NameID = Lex.getUIntVal();
5502 if (ParseToken(
lltok::equal,
"expected '=' after instruction id"))
5505 NameStr = Lex.getStrVal();
5507 if (ParseToken(
lltok::equal,
"expected '=' after instruction name"))
5511 switch (ParseInstruction(Inst, BB, PFS)) {
5513 case InstError:
return true;
5520 if (ParseInstructionMetadata(*Inst))
5523 case InstExtraComma:
5528 if (ParseInstructionMetadata(*Inst))
5534 if (PFS.SetInstName(NameID, NameStr, NameLoc, Inst))
return true;
5547 PerFunctionState &PFS) {
5550 return TokError(
"found end of file when expecting more instructions");
5551 LocTy Loc = Lex.getLoc();
5552 unsigned KeywordVal = Lex.getUIntVal();
5556 default:
return Error(Loc,
"expected instruction opcode");
5573 int Res = ParseUnaryOp(Inst, PFS, KeywordVal, 2);
5589 if (ParseArithmetic(Inst, PFS, KeywordVal, 1))
return true;
5591 if (NUW) cast<BinaryOperator>(Inst)->setHasNoUnsignedWrap(
true);
5592 if (NSW) cast<BinaryOperator>(Inst)->setHasNoSignedWrap(
true);
5601 int Res = ParseArithmetic(Inst, PFS, KeywordVal, 2);
5615 if (ParseArithmetic(Inst, PFS, KeywordVal, 1))
return true;
5616 if (Exact) cast<BinaryOperator>(Inst)->setIsExact(
true);
5621 case lltok::kw_srem:
return ParseArithmetic(Inst, PFS, KeywordVal, 1);
5624 case lltok::kw_xor:
return ParseLogical(Inst, PFS, KeywordVal);
5628 int Res = ParseCompare(Inst, PFS, KeywordVal);
5677 bool LLParser::ParseCmpPredicate(
unsigned &
P,
unsigned Opc) {
5678 if (Opc == Instruction::FCmp) {
5679 switch (Lex.getKind()) {
5680 default:
return TokError(
"expected fcmp predicate (e.g. 'oeq')");
5699 switch (Lex.getKind()) {
5700 default:
return TokError(
"expected icmp predicate (e.g. 'eq')");
5725 PerFunctionState &PFS) {
5726 SMLoc TypeLoc = Lex.getLoc();
5728 if (ParseType(Ty,
true ))
return true;
5730 Type *ResType = PFS.getFunction().getReturnType();
5734 return Error(TypeLoc,
"value doesn't match function result type '" +
5742 if (ParseValue(Ty, RV, PFS))
return true;
5745 return Error(TypeLoc,
"value doesn't match function result type '" +
5755 bool LLParser::ParseBr(
Instruction *&Inst, PerFunctionState &PFS) {
5759 if (ParseTypeAndValue(Op0, Loc, PFS))
return true;
5761 if (
BasicBlock *BB = dyn_cast<BasicBlock>(Op0)) {
5767 return Error(Loc,
"branch condition must have 'i1' type");
5769 if (ParseToken(
lltok::comma,
"expected ',' after branch condition") ||
5770 ParseTypeAndBasicBlock(Op1, Loc, PFS) ||
5771 ParseToken(
lltok::comma,
"expected ',' after true destination") ||
5772 ParseTypeAndBasicBlock(Op2, Loc2, PFS))
5784 bool LLParser::ParseSwitch(
Instruction *&Inst, PerFunctionState &PFS) {
5785 LocTy CondLoc, BBLoc;
5788 if (ParseTypeAndValue(Cond, CondLoc, PFS) ||
5789 ParseToken(
lltok::comma,
"expected ',' after switch condition") ||
5790 ParseTypeAndBasicBlock(DefaultBB, BBLoc, PFS) ||
5795 return Error(CondLoc,
"switch condition must have integer type");
5804 if (ParseTypeAndValue(Constant, CondLoc, PFS) ||
5805 ParseToken(
lltok::comma,
"expected ',' after case value") ||
5806 ParseTypeAndBasicBlock(DestBB, PFS))
5809 if (!SeenCases.
insert(Constant).second)
5810 return Error(CondLoc,
"duplicate case value in switch");
5811 if (!isa<ConstantInt>(Constant))
5812 return Error(CondLoc,
"case value is not a constant integer");
5814 Table.
push_back(std::make_pair(cast<ConstantInt>(Constant), DestBB));
5820 for (
unsigned i = 0, e = Table.
size(); i != e; ++i)
5821 SI->
addCase(Table[i].first, Table[i].second);
5829 bool LLParser::ParseIndirectBr(
Instruction *&Inst, PerFunctionState &PFS) {
5832 if (ParseTypeAndValue(Address, AddrLoc, PFS) ||
5833 ParseToken(
lltok::comma,
"expected ',' after indirectbr address") ||
5838 return Error(AddrLoc,
"indirectbr address must have pointer type");
5845 if (ParseTypeAndBasicBlock(DestBB, PFS))
5850 if (ParseTypeAndBasicBlock(DestBB, PFS))
5856 if (ParseToken(
lltok::rsquare,
"expected ']' at end of block list"))
5860 for (
unsigned i = 0, e = DestList.
size(); i != e; ++i)
5869 bool LLParser::ParseInvoke(
Instruction *&Inst, PerFunctionState &PFS) {
5870 LocTy CallLoc = Lex.getLoc();
5872 std::vector<unsigned> FwdRefAttrGrps;
5875 unsigned InvokeAddrSpace;
5876 Type *RetType =
nullptr;
5883 if (ParseOptionalCallingConv(CC) || ParseOptionalReturnAttrs(RetAttrs) ||
5884 ParseOptionalProgramAddrSpace(InvokeAddrSpace) ||
5885 ParseType(RetType, RetTypeLoc,
true ) ||
5886 ParseValID(CalleeID) || ParseParameterList(ArgList, PFS) ||
5887 ParseFnAttributeValuePairs(FnAttrs, FwdRefAttrGrps,
false,
5889 ParseOptionalOperandBundles(BundleList, PFS) ||
5891 ParseTypeAndBasicBlock(NormalBB, PFS) ||
5893 ParseTypeAndBasicBlock(UnwindBB, PFS))
5902 std::vector<Type*> ParamTypes;
5903 for (
unsigned i = 0, e = ArgList.
size(); i != e; ++i)
5904 ParamTypes.push_back(ArgList[i].V->getType());
5907 return Error(RetTypeLoc,
"Invalid result type for LLVM function");
5917 Callee, &PFS,
true))
5928 for (
unsigned i = 0, e = ArgList.
size(); i != e; ++i) {
5929 Type *ExpectedTy =
nullptr;
5933 return Error(ArgList[i].Loc,
"too many arguments specified");
5936 if (ExpectedTy && ExpectedTy != ArgList[i].V->
getType())
5937 return Error(ArgList[i].Loc,
"argument is not of expected type '" +
5944 return Error(CallLoc,
"not enough parameters specified for call");
5947 return Error(CallLoc,
"invoke instructions may not have an alignment");
5958 ForwardRefAttrGroups[II] = FwdRefAttrGrps;
5965 bool LLParser::ParseResume(
Instruction *&Inst, PerFunctionState &PFS) {
5967 if (ParseTypeAndValue(Exn, ExnLoc, PFS))
5976 PerFunctionState &PFS) {
5977 if (ParseToken(
lltok::lsquare,
"expected '[' in catchpad/cleanuppad"))
5982 if (!Args.
empty() &&
5983 ParseToken(
lltok::comma,
"expected ',' in argument list"))
5988 Type *ArgTy =
nullptr;
5989 if (ParseType(ArgTy, ArgLoc))
5994 if (ParseMetadataAsValue(V, PFS))
5997 if (ParseValue(ArgTy, V, PFS))
6009 bool LLParser::ParseCleanupRet(
Instruction *&Inst, PerFunctionState &PFS) {
6010 Value *CleanupPad =
nullptr;
6012 if (ParseToken(
lltok::kw_from,
"expected 'from' after cleanupret"))
6027 if (ParseTypeAndBasicBlock(UnwindBB, PFS)) {
6038 bool LLParser::ParseCatchRet(
Instruction *&Inst, PerFunctionState &PFS) {
6039 Value *CatchPad =
nullptr;
6041 if (ParseToken(
lltok::kw_from,
"expected 'from' after catchret"))
6048 if (ParseToken(
lltok::kw_to,
"expected 'to' in catchret") ||
6049 ParseTypeAndBasicBlock(BB, PFS))
6058 bool LLParser::ParseCatchSwitch(
Instruction *&Inst, PerFunctionState &PFS) {
6066 return TokError(
"expected scope value for catchswitch");
6071 if (ParseToken(
lltok::lsquare,
"expected '[' with catchswitch labels"))
6077 if (ParseTypeAndBasicBlock(DestBB, PFS))
6082 if (ParseToken(
lltok::rsquare,
"expected ']' after catchswitch labels"))
6086 "expected 'unwind' after catchswitch scope"))
6094 if (ParseTypeAndBasicBlock(UnwindBB, PFS))
6108 bool LLParser::ParseCatchPad(
Instruction *&Inst, PerFunctionState &PFS) {
6109 Value *CatchSwitch =
nullptr;
6115 return TokError(
"expected scope value for catchpad");
6121 if (ParseExceptionArgs(Args, PFS))
6130 bool LLParser::ParseCleanupPad(
Instruction *&Inst, PerFunctionState &PFS) {
6131 Value *ParentPad =
nullptr;
6138 return TokError(
"expected scope value for cleanuppad");
6144 if (ParseExceptionArgs(Args, PFS))
6160 bool LLParser::ParseUnaryOp(
Instruction *&Inst, PerFunctionState &PFS,
6163 if (ParseTypeAndValue(LHS, Loc, PFS))
6167 switch (OperandType) {
6182 return Error(Loc,
"invalid operand type for instruction");
6197 bool LLParser::ParseArithmetic(
Instruction *&Inst, PerFunctionState &PFS,
6198 unsigned Opc,
unsigned OperandType) {
6200 if (ParseTypeAndValue(LHS, Loc, PFS) ||
6201 ParseToken(
lltok::comma,
"expected ',' in arithmetic operation") ||
6202 ParseValue(LHS->
getType(), RHS, PFS))
6206 switch (OperandType) {
6217 return Error(Loc,
"invalid operand type for instruction");
6225 bool LLParser::ParseLogical(
Instruction *&Inst, PerFunctionState &PFS,
6228 if (ParseTypeAndValue(LHS, Loc, PFS) ||
6229 ParseToken(
lltok::comma,
"expected ',' in logical operation") ||
6230 ParseValue(LHS->
getType(), RHS, PFS))
6234 return Error(Loc,
"instruction requires integer or integer vector operands");
6243 bool LLParser::ParseCompare(
Instruction *&Inst, PerFunctionState &PFS,
6249 if (ParseCmpPredicate(Pred, Opc) ||
6250 ParseTypeAndValue(LHS, Loc, PFS) ||
6251 ParseToken(
lltok::comma,
"expected ',' after compare value") ||
6252 ParseValue(LHS->
getType(), RHS, PFS))
6255 if (Opc == Instruction::FCmp) {
6257 return Error(Loc,
"fcmp requires floating point operands");
6260 assert(Opc == Instruction::ICmp &&
"Unknown opcode for CmpInst!");
6263 return Error(Loc,
"icmp requires integer operands");
6276 bool LLParser::ParseCast(
Instruction *&Inst, PerFunctionState &PFS,
6280 Type *DestTy =
nullptr;
6281 if (ParseTypeAndValue(Op, Loc, PFS) ||
6282 ParseToken(
lltok::kw_to,
"expected 'to' after cast value") ||
6288 return Error(Loc,
"invalid cast opcode for cast from '" +
6298 bool LLParser::ParseSelect(
Instruction *&Inst, PerFunctionState &PFS) {
6300 Value *Op0, *Op1, *Op2;
6301 if (ParseTypeAndValue(Op0, Loc, PFS) ||
6302 ParseToken(
lltok::comma,
"expected ',' after select condition") ||
6303 ParseTypeAndValue(Op1, PFS) ||
6304 ParseToken(
lltok::comma,
"expected ',' after select value") ||
6305 ParseTypeAndValue(Op2, PFS))
6309 return Error(Loc, Reason);
6317 bool LLParser::ParseVA_Arg(
Instruction *&Inst, PerFunctionState &PFS) {
6319 Type *EltTy =
nullptr;
6321 if (ParseTypeAndValue(Op, PFS) ||
6322 ParseToken(
lltok::comma,
"expected ',' after vaarg operand") ||
6323 ParseType(EltTy, TypeLoc))
6327 return Error(TypeLoc,
"va_arg requires operand with first class type");
6335 bool LLParser::ParseExtractElement(
Instruction *&Inst, PerFunctionState &PFS) {
6338 if (ParseTypeAndValue(Op0, Loc, PFS) ||
6339 ParseToken(
lltok::comma,
"expected ',' after extract value") ||
6340 ParseTypeAndValue(Op1, PFS))
6344 return Error(Loc,
"invalid extractelement operands");
6352 bool LLParser::ParseInsertElement(
Instruction *&Inst, PerFunctionState &PFS) {
6354 Value *Op0, *Op1, *Op2;
6355 if (ParseTypeAndValue(Op0, Loc, PFS) ||
6356 ParseToken(
lltok::comma,
"expected ',' after insertelement value") ||
6357 ParseTypeAndValue(Op1, PFS) ||
6358 ParseToken(
lltok::comma,
"expected ',' after insertelement value") ||
6359 ParseTypeAndValue(Op2, PFS))
6363 return Error(Loc,
"invalid insertelement operands");
6371 bool LLParser::ParseShuffleVector(
Instruction *&Inst, PerFunctionState &PFS) {
6373 Value *Op0, *Op1, *Op2;
6374 if (ParseTypeAndValue(Op0, Loc, PFS) ||
6375 ParseToken(
lltok::comma,
"expected ',' after shuffle mask") ||
6376 ParseTypeAndValue(Op1, PFS) ||
6377 ParseToken(
lltok::comma,
"expected ',' after shuffle value") ||
6378 ParseTypeAndValue(Op2, PFS))
6382 return Error(Loc,
"invalid shufflevector operands");
6390 int LLParser::ParsePHI(
Instruction *&Inst, PerFunctionState &PFS) {
6394 if (ParseType(Ty, TypeLoc) ||
6396 ParseValue(Ty, Op0, PFS) ||
6397 ParseToken(
lltok::comma,
"expected ',' after insertelement value") ||
6402 bool AteExtraComma =
false;
6406 PHIVals.
push_back(std::make_pair(Op0, cast<BasicBlock>(Op1)));
6412 AteExtraComma =
true;
6416 if (ParseToken(
lltok::lsquare,
"expected '[' in phi value list") ||
6417 ParseValue(Ty, Op0, PFS) ||
6418 ParseToken(
lltok::comma,
"expected ',' after insertelement value") ||
6425 return Error(TypeLoc,
"phi node must have first class type");
6428 for (
unsigned i = 0, e = PHIVals.
size(); i != e; ++i)
6429 PN->
addIncoming(PHIVals[i].first, PHIVals[i].second);
6431 return AteExtraComma ? InstExtraComma : InstNormal;
6440 bool LLParser::ParseLandingPad(
Instruction *&Inst, PerFunctionState &PFS) {
6443 if (ParseType(Ty, TyLoc))
6456 return TokError(
"expected 'catch' or 'filter' clause type");
6460 if (ParseTypeAndValue(V, VLoc, PFS))
6466 if (isa<ArrayType>(V->
getType()))
6467 Error(VLoc,
"'catch' clause has an invalid type");
6469 if (!isa<ArrayType>(V->
getType()))
6470 Error(VLoc,
"'filter' clause has an invalid type");
6475 return Error(VLoc,
"clause argument must be a constant");
6479 Inst = LP.release();
6492 bool LLParser::ParseCall(
Instruction *&Inst, PerFunctionState &PFS,
6495 std::vector<unsigned> FwdRefAttrGrps;
6497 unsigned CallAddrSpace;
6499 Type *RetType =
nullptr;
6504 LocTy CallLoc = Lex.getLoc();
6508 "expected 'tail call', 'musttail call', or 'notail call'"))
6513 if (ParseOptionalCallingConv(CC) || ParseOptionalReturnAttrs(RetAttrs) ||
6514 ParseOptionalProgramAddrSpace(CallAddrSpace) ||
6515 ParseType(RetType, RetTypeLoc,
true ) ||
6516 ParseValID(CalleeID) ||
6518 PFS.getFunction().isVarArg()) ||
6519 ParseFnAttributeValuePairs(FnAttrs, FwdRefAttrGrps,
false, BuiltinLoc) ||
6520 ParseOptionalOperandBundles(BundleList, PFS))
6524 return Error(CallLoc,
"fast-math-flags specified for call without " 6525 "floating-point scalar or vector return type");
6533 std::vector<Type*> ParamTypes;
6534 for (
unsigned i = 0, e = ArgList.
size(); i != e; ++i)
6535 ParamTypes.push_back(ArgList[i].V->getType());
6538 return Error(RetTypeLoc,
"Invalid result type for LLVM function");
6547 if (ConvertValIDToValue(
PointerType::get(Ty, CallAddrSpace), CalleeID, Callee,
6560 for (
unsigned i = 0, e = ArgList.
size(); i != e; ++i) {
6561 Type *ExpectedTy =
nullptr;
6565 return Error(ArgList[i].Loc,
"too many arguments specified");
6568 if (ExpectedTy && ExpectedTy != ArgList[i].V->
getType())
6569 return Error(ArgList[i].Loc,
"argument is not of expected type '" +
6576 return Error(CallLoc,
"not enough parameters specified for call");
6579 return Error(CallLoc,
"call instructions may not have an alignment");
6592 ForwardRefAttrGroups[CI] = FwdRefAttrGrps;
6604 int LLParser::ParseAlloc(
Instruction *&Inst, PerFunctionState &PFS) {
6606 LocTy SizeLoc, TyLoc, ASLoc;
6607 unsigned Alignment = 0;
6608 unsigned AddrSpace = 0;
6614 if (ParseType(Ty, TyLoc))
return true;
6617 return Error(TyLoc,
"invalid type for alloca");
6619 bool AteExtraComma =
false;
6622 if (ParseOptionalAlignment(Alignment))
6624 if (ParseOptionalCommaAddrSpace(AddrSpace, ASLoc, AteExtraComma))
6627 ASLoc = Lex.getLoc();
6628 if (ParseOptionalAddrSpace(AddrSpace))
6631 AteExtraComma =
true;
6633 if (ParseTypeAndValue(Size, SizeLoc, PFS))
6637 if (ParseOptionalAlignment(Alignment))
6639 if (ParseOptionalCommaAddrSpace(AddrSpace, ASLoc, AteExtraComma))
6642 ASLoc = Lex.getLoc();
6643 if (ParseOptionalAddrSpace(AddrSpace))
6646 AteExtraComma =
true;
6653 return Error(SizeLoc,
"element count must have integer type");
6659 return AteExtraComma ? InstExtraComma : InstNormal;
6666 int LLParser::ParseLoad(
Instruction *&Inst, PerFunctionState &PFS) {
6668 unsigned Alignment = 0;
6669 bool AteExtraComma =
false;
6686 LocTy ExplicitTypeLoc = Lex.getLoc();
6687 if (ParseType(Ty) ||
6688 ParseToken(
lltok::comma,
"expected comma after load's type") ||
6689 ParseTypeAndValue(Val, Loc, PFS) ||
6690 ParseScopeAndOrdering(isAtomic, SSID, Ordering) ||
6691 ParseOptionalCommaAlign(Alignment, AteExtraComma))
6695 return Error(Loc,
"load operand must be a pointer to a first class type");
6696 if (isAtomic && !Alignment)
6697 return Error(Loc,
"atomic load must have explicit non-zero alignment");
6700 return Error(Loc,
"atomic load cannot use Release ordering");
6702 if (Ty != cast<PointerType>(Val->
getType())->getElementType())
6703 return Error(ExplicitTypeLoc,
6704 "explicit pointee type doesn't match operand's pointee type");
6706 Inst =
new LoadInst(Ty, Val,
"", isVolatile, Alignment, Ordering, SSID);
6707 return AteExtraComma ? InstExtraComma : InstNormal;
6715 int LLParser::ParseStore(
Instruction *&Inst, PerFunctionState &PFS) {
6717 unsigned Alignment = 0;
6718 bool AteExtraComma =
false;
6734 if (ParseTypeAndValue(Val, Loc, PFS) ||
6735 ParseToken(
lltok::comma,
"expected ',' after store operand") ||
6736 ParseTypeAndValue(Ptr, PtrLoc, PFS) ||
6737 ParseScopeAndOrdering(isAtomic, SSID, Ordering) ||
6738 ParseOptionalCommaAlign(Alignment, AteExtraComma))
6742 return Error(PtrLoc,
"store operand must be a pointer");
6744 return Error(Loc,
"store operand must be a first class value");
6745 if (cast<PointerType>(Ptr->
getType())->getElementType() != Val->
getType())
6746 return Error(Loc,
"stored value and pointer type do not match");
6747 if (isAtomic && !Alignment)
6748 return Error(Loc,
"atomic store must have explicit non-zero alignment");
6751 return Error(Loc,
"atomic store cannot use Acquire ordering");
6753 Inst =
new StoreInst(Val, Ptr, isVolatile, Alignment, Ordering, SSID);
6754 return AteExtraComma ? InstExtraComma : InstNormal;
6760 int LLParser::ParseCmpXchg(
Instruction *&Inst, PerFunctionState &PFS) {
6761 Value *Ptr, *Cmp, *New;
LocTy PtrLoc, CmpLoc, NewLoc;
6762 bool AteExtraComma =
false;
6775 if (ParseTypeAndValue(Ptr, PtrLoc, PFS) ||
6776 ParseToken(
lltok::comma,
"expected ',' after cmpxchg address") ||
6777 ParseTypeAndValue(Cmp, CmpLoc, PFS) ||
6778 ParseToken(
lltok::comma,
"expected ',' after cmpxchg cmp operand") ||
6779 ParseTypeAndValue(New, NewLoc, PFS) ||
6780 ParseScopeAndOrdering(
true , SSID, SuccessOrdering) ||
6781 ParseOrdering(FailureOrdering))
6786 return TokError(
"cmpxchg cannot be unordered");
6788 return TokError(
"cmpxchg failure argument shall be no stronger than the " 6789 "success argument");
6793 "cmpxchg failure ordering cannot include release semantics");
6795 return Error(PtrLoc,
"cmpxchg operand must be a pointer");
6796 if (cast<PointerType>(Ptr->
getType())->getElementType() != Cmp->
getType())
6797 return Error(CmpLoc,
"compare value and pointer type do not match");
6798 if (cast<PointerType>(Ptr->
getType())->getElementType() != New->
getType())
6799 return Error(NewLoc,
"new value and pointer type do not match");
6801 return Error(NewLoc,
"cmpxchg operand must be a first class value");
6803 Ptr, Cmp, New, SuccessOrdering, FailureOrdering, SSID);
6807 return AteExtraComma ? InstExtraComma : InstNormal;
6813 int LLParser::ParseAtomicRMW(
Instruction *&Inst, PerFunctionState &PFS) {
6815 bool AteExtraComma =
false;
6824 switch (Lex.getKind()) {
6825 default:
return TokError(
"expected binary operation in atomicrmw");
6840 if (ParseTypeAndValue(Ptr, PtrLoc, PFS) ||
6841 ParseToken(
lltok::comma,
"expected ',' after atomicrmw address") ||
6842 ParseTypeAndValue(Val, ValLoc, PFS) ||
6843 ParseScopeAndOrdering(
true , SSID, Ordering))
6847 return TokError(
"atomicrmw cannot be unordered");
6849 return Error(PtrLoc,
"atomicrmw operand must be a pointer");
6850 if (cast<PointerType>(Ptr->
getType())->getElementType() != Val->
getType())
6851 return Error(ValLoc,
"atomicrmw value and pointer type do not match");
6854 return Error(ValLoc,
"atomicrmw " +
6856 " operand must be an integer");
6860 if (Size < 8 || (Size & (Size - 1)))
6861 return Error(ValLoc,
"atomicrmw operand must be power-of-two byte-sized" 6868 return AteExtraComma ? InstExtraComma : InstNormal;
6873 int LLParser::ParseFence(
Instruction *&Inst, PerFunctionState &PFS) {
6876 if (ParseScopeAndOrdering(
true , SSID, Ordering))
6880 return TokError(
"fence cannot be unordered");
6882 return TokError(
"fence cannot be monotonic");
6890 int LLParser::ParseGetElementPtr(
Instruction *&Inst, PerFunctionState &PFS) {
6891 Value *Ptr =
nullptr;
6892 Value *Val =
nullptr;
6898 LocTy ExplicitTypeLoc = Lex.getLoc();
6899 if (ParseType(Ty) ||
6900 ParseToken(
lltok::comma,
"expected comma after getelementptr's type") ||
6901 ParseTypeAndValue(Ptr, Loc, PFS))
6906 if (!BasePointerType)
6907 return Error(Loc,
"base of getelementptr must be a pointer");
6910 return Error(ExplicitTypeLoc,
6911 "explicit pointee type doesn't match operand's pointee type");
6914 bool AteExtraComma =
false;
6922 AteExtraComma =
true;
6925 if (ParseTypeAndValue(Val, EltLoc, PFS))
return true;
6927 return Error(EltLoc,
"getelementptr index must be an integer");
6931 if (GEPWidth && GEPWidth != ValNumEl)
6932 return Error(EltLoc,
6933 "getelementptr vector index has a wrong number of elements");
6934 GEPWidth = ValNumEl;
6941 return Error(Loc,
"base element of getelementptr must be sized");
6944 return Error(Loc,
"invalid getelementptr indices");
6947 cast<GetElementPtrInst>(Inst)->setIsInBounds(
true);
6948 return AteExtraComma ? InstExtraComma : InstNormal;
6953 int LLParser::ParseExtractValue(
Instruction *&Inst, PerFunctionState &PFS) {
6957 if (ParseTypeAndValue(Val, Loc, PFS) ||
6958 ParseIndexList(Indices, AteExtraComma))
6962 return Error(Loc,
"extractvalue operand must be aggregate type");
6965 return Error(Loc,
"invalid indices for extractvalue");
6967 return AteExtraComma ? InstExtraComma : InstNormal;
6972 int LLParser::ParseInsertValue(
Instruction *&Inst, PerFunctionState &PFS) {
6976 if (ParseTypeAndValue(Val0, Loc0, PFS) ||
6977 ParseToken(
lltok::comma,
"expected comma after insertvalue operand") ||
6978 ParseTypeAndValue(Val1, Loc1, PFS) ||
6979 ParseIndexList(Indices, AteExtraComma))
6983 return Error(Loc0,
"insertvalue operand must be aggregate type");
6987 return Error(Loc0,
"invalid indices for insertvalue");
6988 if (IndexedType != Val1->
getType())
6989 return Error(Loc1,
"insertvalue operand and field disagree in type: '" +
6993 return AteExtraComma ? InstExtraComma : InstNormal;
7020 if (ParseMetadata(MD,
nullptr))
7025 return ParseToken(
lltok::rbrace,
"expected end of metadata node");
7034 return Error(Loc,
"value has no uses");
7036 unsigned NumUses = 0;
7038 for (
const Use &U : V->
uses()) {
7039 if (++NumUses > Indexes.
size())
7041 Order[&U] = Indexes[NumUses - 1];
7044 return Error(Loc,
"value only has one use");
7045 if (Order.
size() != Indexes.
size() || NumUses > Indexes.
size())
7058 SMLoc Loc = Lex.getLoc();
7062 return Lex.Error(
"expected non-empty list of uselistorder indexes");
7069 bool IsOrdered =
true;
7070 assert(Indexes.
empty() &&
"Expected empty order vector");
7073 if (ParseUInt32(Index))
7077 Offset += Index - Indexes.
size();
7079 IsOrdered &= Index == Indexes.
size();
7087 if (Indexes.
size() < 2)
7088 return Error(Loc,
"expected >= 2 uselistorder indexes");
7089 if (Offset != 0 || Max >= Indexes.
size())
7090 return Error(Loc,
"expected distinct uselistorder indexes in range [0, size)");
7092 return Error(Loc,
"expected uselistorder indexes to change the order");
7099 bool LLParser::ParseUseListOrder(PerFunctionState *PFS) {
7100 SMLoc Loc = Lex.getLoc();
7106 if (ParseTypeAndValue(V, PFS) ||
7107 ParseToken(
lltok::comma,
"expected comma in uselistorder directive") ||
7108 ParseUseListOrderIndexes(Indexes))
7111 return sortUseListOrder(V, Indexes, Loc);
7116 bool LLParser::ParseUseListOrderBB() {
7118 SMLoc Loc = Lex.getLoc();
7123 if (ParseValID(Fn) ||
7124 ParseToken(
lltok::comma,
"expected comma in uselistorder_bb directive") ||
7125 ParseValID(Label) ||
7126 ParseToken(
lltok::comma,
"expected comma in uselistorder_bb directive") ||
7127 ParseUseListOrderIndexes(Indexes))
7133 GV = M->getNamedValue(Fn.
StrVal);
7135 GV = Fn.
UIntVal < NumberedVals.size() ? NumberedVals[Fn.
UIntVal] :
nullptr;
7137 return Error(Fn.
Loc,
"expected function name in uselistorder_bb");
7139 return Error(Fn.
Loc,
"invalid function forward reference in uselistorder_bb");
7142 return Error(Fn.
Loc,
"expected function name in uselistorder_bb");
7143 if (
F->isDeclaration())
7144 return Error(Fn.
Loc,
"invalid declaration in uselistorder_bb");
7148 return Error(Label.
Loc,
"invalid numeric label in uselistorder_bb");
7150 return Error(Label.
Loc,
"expected basic block name in uselistorder_bb");
7151 Value *V =
F->getValueSymbolTable()->lookup(Label.
StrVal);
7153 return Error(Label.
Loc,
"invalid basic block in uselistorder_bb");
7154 if (!isa<BasicBlock>(V))
7155 return Error(Label.
Loc,
"expected basic block in uselistorder_bb");
7157 return sortUseListOrder(V, Indexes, Loc);
7163 bool LLParser::ParseModuleEntry(
unsigned ID) {
7172 ParseStringConstant(Path) ||
7180 if (ParseUInt32(Hash[0]) || ParseToken(
lltok::comma,
"expected ',' here") ||
7181 ParseUInt32(Hash[1]) || ParseToken(
lltok::comma,
"expected ',' here") ||
7182 ParseUInt32(Hash[2]) || ParseToken(
lltok::comma,
"expected ',' here") ||
7183 ParseUInt32(Hash[3]) || ParseToken(
lltok::comma,
"expected ',' here") ||
7184 ParseUInt32(Hash[4]))
7191 auto ModuleEntry = Index->addModule(Path, ID, Hash);
7192 ModuleIdMap[
ID] = ModuleEntry->first();
7199 bool LLParser::ParseTypeIdEntry(
unsigned ID) {
7208 ParseStringConstant(Name))
7213 ParseTypeIdSummary(TIS) || ParseToken(
lltok::rparen,
"expected ')' here"))
7218 auto FwdRefTIDs = ForwardRefTypeIds.find(ID);
7219 if (FwdRefTIDs != ForwardRefTypeIds.end()) {
7220 for (
auto TIDRef : FwdRefTIDs->second) {
7222 "Forward referenced type id GUID expected to be 0");
7225 ForwardRefTypeIds.erase(FwdRefTIDs);
7237 ParseTypeTestResolution(TIS.
TTRes))
7242 if (ParseOptionalWpdResolutions(TIS.
WPDRes))
7266 switch (Lex.getKind()) {
7283 return Error(Lex.getLoc(),
"unexpected TypeTestResolution kind");
7295 switch (Lex.getKind()) {
7310 if (ParseToken(
lltok::colon,
"expected ':'") || ParseUInt32(Val))
7323 return Error(Lex.getLoc(),
"expected optional TypeTestResolution field");
7336 bool LLParser::ParseOptionalWpdResolutions(
7337 std::map<uint64_t, WholeProgramDevirtResolution> &WPDResMap) {
7348 ParseToken(
lltok::colon,
"expected ':' here") || ParseUInt64(Offset) ||
7349 ParseToken(
lltok::comma,
"expected ',' here") || ParseWpdRes(WPDRes) ||
7352 WPDResMap[
Offset] = WPDRes;
7377 switch (Lex.getKind()) {
7388 return Error(Lex.getLoc(),
"unexpected WholeProgramDevirtResolution kind");
7394 switch (Lex.getKind()) {
7402 if (ParseOptionalResByArg(WPDRes.
ResByArg))
7406 return Error(Lex.getLoc(),
7407 "expected optional WholeProgramDevirtResolution field");
7424 bool LLParser::ParseOptionalResByArg(
7433 std::vector<uint64_t>
Args;
7434 if (ParseArgs(Args) || ParseToken(
lltok::comma,
"expected ',' here") ||
7443 switch (Lex.getKind()) {
7457 return Error(Lex.getLoc(),
7458 "unexpected WholeProgramDevirtResolution::ByArg kind");
7464 switch (Lex.getKind()) {
7468 ParseUInt64(ByArg.
Info))
7474 ParseUInt32(ByArg.
Byte))
7480 ParseUInt32(ByArg.
Bit))
7484 return Error(Lex.getLoc(),
7485 "expected optional whole program devirt field");
7492 ResByArg[
Args] = ByArg;
7503 bool LLParser::ParseArgs(std::vector<uint64_t> &Args) {
7511 if (ParseUInt64(Val))
7513 Args.push_back(Val);
7522 static const auto FwdVIRef = (GlobalValueSummaryMapTy::value_type *)-8;
7533 void LLParser::AddGlobalValueToIndex(
7535 unsigned ID, std::unique_ptr<GlobalValueSummary> Summary) {
7540 VI = Index->getOrInsertValueInfo(GUID);
7544 auto *GV = M->getNamedValue(Name);
7546 VI = Index->getOrInsertValueInfo(GV);
7550 "Need a source_filename to compute GUID for local");
7553 VI = Index->getOrInsertValueInfo(GUID, Index->saveString(Name));
7559 Index->addGlobalValueSummary(VI, std::move(Summary));
7562 auto FwdRefVIs = ForwardRefValueInfos.find(ID);
7563 if (FwdRefVIs != ForwardRefValueInfos.end()) {
7564 for (
auto VIRef : FwdRefVIs->second) {
7565 assert(VIRef.first->getRef() == FwdVIRef &&
7566 "Forward referenced ValueInfo expected to be empty");
7569 ForwardRefValueInfos.erase(FwdRefVIs);
7573 auto FwdRefAliasees = ForwardRefAliasees.find(ID);
7574 if (FwdRefAliasees != ForwardRefAliasees.end()) {
7575 for (
auto AliaseeRef : FwdRefAliasees->second) {
7576 assert(!AliaseeRef.first->hasAliasee() &&
7577 "Forward referencing alias already has aliasee");
7580 ForwardRefAliasees.erase(FwdRefAliasees);
7584 if (ID == NumberedValueInfos.size())
7585 NumberedValueInfos.push_back(VI);
7588 if (ID > NumberedValueInfos.size())
7589 NumberedValueInfos.resize(ID + 1);
7590 NumberedValueInfos[
ID] =
VI;
7598 bool LLParser::ParseGVEntry(
unsigned ID) {
7608 switch (Lex.getKind()) {
7612 ParseStringConstant(Name))
7618 if (ParseToken(
lltok::colon,
"expected ':' here") || ParseUInt64(GUID))
7622 return Error(Lex.getLoc(),
"expected name or guid tag");
7648 switch (Lex.getKind()) {
7650 if (ParseFunctionSummary(Name, GUID, ID))
7654 if (ParseVariableSummary(Name, GUID, ID))
7658 if (ParseAliasSummary(Name, GUID, ID))
7662 return Error(Lex.getLoc(),
"expected summary type");
7688 std::vector<FunctionSummary::EdgeTy> Calls;
7690 std::vector<ValueInfo> Refs;
7695 ParseModuleReference(ModulePath) ||
7696 ParseToken(
lltok::comma,
"expected ',' here") || ParseGVFlags(GVFlags) ||
7699 ParseToken(
lltok::colon,
"expected ':' here") || ParseUInt32(InstCount))
7704 switch (Lex.getKind()) {
7706 if (ParseOptionalFFlags(FFlags))
7710 if (ParseOptionalCalls(Calls))
7714 if (ParseOptionalTypeIdInfo(TypeIdInfo))
7718 if (ParseOptionalRefs(Refs))
7722 return Error(Lex.getLoc(),
"expected optional function summary field");
7729 auto FS = llvm::make_unique<FunctionSummary>(
7730 GVFlags, InstCount, FFlags, 0, std::move(Refs),
7731 std::move(Calls), std::move(TypeIdInfo.
TypeTests),
7737 FS->setModulePath(ModulePath);
7758 std::vector<ValueInfo> Refs;
7761 ParseModuleReference(ModulePath) ||
7762 ParseToken(
lltok::comma,
"expected ',' here") || ParseGVFlags(GVFlags) ||
7764 ParseGVarFlags(GVarFlags))
7769 if (ParseOptionalRefs(Refs))
7777 llvm::make_unique<GlobalVarSummary>(GVFlags, GVarFlags, std::move(Refs));
7779 GS->setModulePath(ModulePath);
7793 LocTy Loc = Lex.getLoc();
7802 ParseModuleReference(ModulePath) ||
7803 ParseToken(
lltok::comma,
"expected ',' here") || ParseGVFlags(GVFlags) ||
7811 if (ParseGVReference(AliaseeVI, GVId))
7817 auto AS = llvm::make_unique<AliasSummary>(GVFlags);
7819 AS->setModulePath(ModulePath);
7822 if (AliaseeVI.
getRef() == FwdVIRef) {
7823 auto FwdRef = ForwardRefAliasees.insert(
7824 std::make_pair(GVId, std::vector<std::pair<AliasSummary *, LocTy>>()));
7825 FwdRef.first->second.push_back(std::make_pair(AS.get(), Loc));
7837 bool LLParser::ParseFlag(
unsigned &Val) {
7838 if (Lex.getKind() !=
lltok::APSInt || Lex.getAPSIntVal().isSigned())
7839 return TokError(
"expected integer");
7840 Val = (
unsigned)Lex.getAPSIntVal().getBoolValue();
7854 if (ParseToken(
lltok::colon,
"expected ':' in funcFlags") |
7860 switch (Lex.getKind()) {
7863 if (ParseToken(
lltok::colon,
"expected ':'") || ParseFlag(Val))
7869 if (ParseToken(
lltok::colon,
"expected ':'") || ParseFlag(Val))
7875 if (ParseToken(
lltok::colon,
"expected ':'") || ParseFlag(Val))
7881 if (ParseToken(
lltok::colon,
"expected ':'") || ParseFlag(Val))
7887 if (ParseToken(
lltok::colon,
"expected ':'") || ParseFlag(Val))
7892 return Error(Lex.getLoc(),
"expected function flag type");
7906 bool LLParser::ParseOptionalCalls(std::vector<FunctionSummary::EdgeTy> &Calls) {
7910 if (ParseToken(
lltok::colon,
"expected ':' in calls") |
7914 IdToIndexMapType IdToIndexMap;
7923 LocTy Loc = Lex.getLoc();
7925 if (ParseGVReference(VI, GVId))
7933 if (ParseToken(
lltok::colon,
"expected ':'") || ParseHotness(Hotness))
7937 ParseToken(
lltok::colon,
"expected ':'") || ParseUInt32(RelBF))
7944 if (VI.
getRef() == FwdVIRef)
7945 IdToIndexMap[GVId].push_back(std::make_pair(Calls.size(), Loc));
7954 for (
auto I : IdToIndexMap) {
7955 for (
auto P :
I.second) {
7956 assert(Calls[P.first].first.getRef() == FwdVIRef &&
7957 "Forward referenced ValueInfo expected to be empty");
7958 auto FwdRef = ForwardRefValueInfos.insert(std::make_pair(
7959 I.first, std::vector<std::pair<ValueInfo *, LocTy>>()));
7960 FwdRef.first->second.push_back(
7961 std::make_pair(&Calls[P.first].first, P.second));
7974 switch (Lex.getKind()) {
7991 return Error(Lex.getLoc(),
"invalid call edge hotness");
7999 bool LLParser::ParseOptionalRefs(std::vector<ValueInfo> &Refs) {
8007 struct ValueContext {
8012 std::vector<ValueContext> VContexts;
8016 VC.Loc = Lex.getLoc();
8017 if (ParseGVReference(VC.VI, VC.GVId))
8019 VContexts.push_back(VC);
8024 llvm::sort(VContexts, [](
const ValueContext &VC1,
const ValueContext &VC2) {
8025 return VC1.VI.isReadOnly() < VC2.VI.isReadOnly();
8028 IdToIndexMapType IdToIndexMap;
8029 for (
auto &
VC : VContexts) {
8033 if (
VC.VI.getRef() == FwdVIRef)
8034 IdToIndexMap[
VC.GVId].push_back(std::make_pair(Refs.size(),
VC.Loc));
8035 Refs.push_back(
VC.VI);
8040 for (
auto I : IdToIndexMap) {
8041 for (
auto P :
I.second) {
8042 assert(Refs[P.first].getRef() == FwdVIRef &&
8043 "Forward referenced ValueInfo expected to be empty");
8044 auto FwdRef = ForwardRefValueInfos.insert(std::make_pair(
8045 I.first, std::vector<std::pair<ValueInfo *, LocTy>>()));
8046 FwdRef.first->second.push_back(std::make_pair(&Refs[P.first], P.second));
8060 bool LLParser::ParseOptionalTypeIdInfo(
8070 switch (Lex.getKind()) {
8072 if (ParseTypeTests(TypeIdInfo.
TypeTests))
8096 return Error(Lex.getLoc(),
"invalid typeIdInfo list type");
8100 if (ParseToken(
lltok::rparen,
"expected ')' in typeIdInfo"))
8109 bool LLParser::ParseTypeTests(std::vector<GlobalValue::GUID> &TypeTests) {
8117 IdToIndexMapType IdToIndexMap;
8121 unsigned ID = Lex.getUIntVal();
8122 LocTy Loc = Lex.getLoc();
8126 IdToIndexMap[
ID].push_back(std::make_pair(TypeTests.size(), Loc));
8128 }
else if (ParseUInt64(GUID))
8130 TypeTests.push_back(GUID);
8135 for (
auto I : IdToIndexMap) {
8136 for (
auto P :
I.second) {
8137 assert(TypeTests[P.first] == 0 &&
8138 "Forward referenced type id GUID expected to be 0");
8139 auto FwdRef = ForwardRefTypeIds.insert(std::make_pair(
8140 I.first, std::vector<std::pair<GlobalValue::GUID *, LocTy>>()));
8141 FwdRef.first->second.push_back(
8142 std::make_pair(&TypeTests[P.first], P.second));
8146 if (ParseToken(
lltok::rparen,
"expected ')' in typeIdInfo"))
8154 bool LLParser::ParseVFuncIdList(
8155 lltok::Kind Kind, std::vector<FunctionSummary::VFuncId> &VFuncIdList) {
8163 IdToIndexMapType IdToIndexMap;
8166 if (ParseVFuncId(VFuncId, IdToIndexMap, VFuncIdList.size()))
8168 VFuncIdList.push_back(VFuncId);
8176 for (
auto I : IdToIndexMap) {
8177 for (
auto P :
I.second) {
8178 assert(VFuncIdList[P.first].GUID == 0 &&
8179 "Forward referenced type id GUID expected to be 0");
8180 auto FwdRef = ForwardRefTypeIds.insert(std::make_pair(
8181 I.first, std::vector<std::pair<GlobalValue::GUID *, LocTy>>()));
8182 FwdRef.first->second.push_back(
8183 std::make_pair(&VFuncIdList[P.first].GUID, P.second));
8192 bool LLParser::ParseConstVCallList(
8194 std::vector<FunctionSummary::ConstVCall> &ConstVCallList) {
8202 IdToIndexMapType IdToIndexMap;
8205 if (ParseConstVCall(ConstVCall, IdToIndexMap, ConstVCallList.size()))
8207 ConstVCallList.push_back(ConstVCall);
8215 for (
auto I : IdToIndexMap) {
8216 for (
auto P :
I.second) {
8217 assert(ConstVCallList[P.first].VFunc.GUID == 0 &&
8218 "Forward referenced type id GUID expected to be 0");
8219 auto FwdRef = ForwardRefTypeIds.insert(std::make_pair(
8220 I.first, std::vector<std::pair<GlobalValue::GUID *, LocTy>>()));
8221 FwdRef.first->second.push_back(
8222 std::make_pair(&ConstVCallList[P.first].VFunc.GUID, P.second));
8232 IdToIndexMapType &IdToIndexMap,
unsigned Index) {
8234 ParseVFuncId(ConstVCall.
VFunc, IdToIndexMap, Index))
8238 if (ParseArgs(ConstVCall.
Args))
8251 IdToIndexMapType &IdToIndexMap,
unsigned Index) {
8261 unsigned ID = Lex.getUIntVal();
8262 LocTy Loc = Lex.getLoc();
8266 IdToIndexMap[
ID].push_back(std::make_pair(Index, Loc));
8270 ParseUInt64(VFuncId.
GUID))
8276 ParseUInt64(VFuncId.
Offset) ||
8299 assert(HasLinkage &&
"Linkage not optional in summary entry");
8305 "expected 'notEligibleToImport' here") ||
8306 ParseToken(
lltok::colon,
"expected ':' here") || ParseFlag(Flag))
8312 ParseToken(
lltok::colon,
"expected ':' here") || ParseFlag(Flag))
8318 ParseToken(
lltok::colon,
"expected ':' here") || ParseFlag(Flag))
8351 bool LLParser::ParseModuleReference(
StringRef &ModulePath) {
8358 unsigned ModuleID = Lex.getUIntVal();
8359 auto I = ModuleIdMap.find(ModuleID);
8361 assert(
I != ModuleIdMap.end());
8362 ModulePath =
I->second;
8368 bool LLParser::ParseGVReference(
ValueInfo &
VI,
unsigned &GVId) {
8373 GVId = Lex.getUIntVal();
8375 if (GVId < NumberedValueInfos.size()) {
8376 assert(NumberedValueInfos[GVId].getRef() != FwdVIRef);
8377 VI = NumberedValueInfos[GVId];
void setVisibility(VisibilityTypes V)
void sortUseList(Compare Cmp)
Sort the use-list.
bool parseStandaloneConstantValue(Constant *&C, const SlotMapping *Slots)
Used for AVR interrupt routines.
static ConstantInt * getFalse(LLVMContext &Context)
*ViewGraph Emit a dot run run gv on the postscript file
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()
ARM_AAPCS - ARM Architecture Procedure Calling Standard calling convention (aka EABI).
static IntegerType * getInt1Ty(LLVMContext &C)
C - The default llvm calling convention, compatible with 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.
uint64_t getZExtValue() const
Get zero extended value.
*p = old <signed v ? old : v
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
This class represents an incoming formal argument to a Function.
void UpgradeSectionAttributes(Module &M)
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.
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.
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)
HHVM calling convention for invoking C/C++ helpers.
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 PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space...
*p = old <unsigned v ? old : v
Register calling convention used for parameters transfer optimization.
The C convention as implemented on Windows/x86-64 and AArch64.
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.
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)
ELFYAML::ELF_STV Visibility
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.
bool isVectorTy() const
True if this is an instance of VectorType.
const APFloat & getAPFloatVal() const
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)
void setAlignment(unsigned Align)
unsigned getVirtuality(StringRef VirtualityString)
*p = old >signed v ? old : v
Virtual constant propagation.
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)
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...
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
Calling convention used for Mesa/AMDPAL geometry shaders.
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...
amdgpu Simplify well known AMD library false Value Value const Twine & Name
static Type * getTokenTy(LLVMContext &C)
bool hasAttributes() const
Return true if the builder has IR-level attributes.
Calling convention used for Mesa/AMDPAL compute shaders.
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.
SPIR_KERNEL - Calling convention for SPIR kernel functions.
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.
void setName(const Twine &Name)
Change the name of the value.
static const unsigned MaximumAlignment
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)
Uniform return value optimization.
llvm::Optional< Function * > remangleIntrinsicFunction(Function *F)
Fast - This calling convention attempts to make calls as fast as possible (e.g.
Class to represent function types.
Calling convention used for AMDPAL shader stage before geometry shader if geometry is in use...
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)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
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.
void setBody(ArrayRef< Type *> Elements, bool isPacked=false)
Specify a body for an opaque identified type.
amdgpu Simplify well known AMD library false Value * Callee
ArrayRef< std::unique_ptr< GlobalValueSummary > > getSummaryList() const
Calling convention used for Mesa vertex shaders, or AMDPAL last shader stage before rasterization (ve...
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...
ARM_AAPCS_VFP - Same as ARM_AAPCS, but uses hard floating point ABI.
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.
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.
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.
static DISPFlags toSPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized, unsigned Virtuality=SPFlagNonvirtual)
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.
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.
MSVC calling convention that passes vectors and vector aggregates in SSE registers.
Resume the propagation of an exception.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
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.
PTX_Kernel - Call to a PTX kernel.
void setExternallyInitialized(bool Val)
unsigned getOperationEncoding(StringRef OperationEncodingString)
uint64_t getAlignment() const
Retrieve the alignment attribute, if it exists.
StringMap< Type * > NamedTypes
ARM_APCS - ARM Procedure Calling Standard calling convention (obsolete, but still used on some target...
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.
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.
Calling convention used for AMDPAL vertex shader if tessellation is in use.
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.
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...
The C convention as specified in the x86-64 supplement to the System V ABI, used on most non-Windows ...
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.
Calling convention used for Mesa/AMDPAL pixel shaders.
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)
static wasm::ValType getType(const TargetRegisterClass *RC)
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).
An imported module (C++ using directive or similar).
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()
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
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)
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)
X86_ThisCall - Similar to X86_StdCall.
AttrBuilder & removeAttribute(Attribute::AttrKind Val)
Remove an attribute from the builder.
Calling convention used for AVR signal routines.
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.
bool isVector(MCInstrInfo const &MCII, MCInst const &MCI)
Type::subtype_iterator param_iterator
Single implementation devirtualization.
void addMetadata(unsigned KindID, MDNode &MD)
Add a metadata attachment.
bool isAggregateType() const
Return true if the type is an aggregate type.
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...
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)
X86_FastCall - 'fast' analog of X86_StdCall.
void push_back(pointer val)
A specification for a virtual function call with all constant integer arguments.
static bool isWeak(const MCSymbolELF &Sym)
LinkageTypes
An enumeration for the kinds of linkage for global values.
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)
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 ...
Intel_OCL_BI - Calling conventions for Intel OpenCL built-ins.
Function to be accessible from DLL.
PTX_Device - Call to a PTX device function.
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.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
OperandType
Operands are tagged with one of the values of this enum.
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.
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)
void emplace_back(ArgTypes &&... Args)
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...
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.
Calling convention used for Mesa/AMDPAL hull shaders (= tessellation control shaders).
void setSourceFileName(StringRef Name)
Set the module's original source file name.
static InsertValueInst * Create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
StringRef getName() const
Return a constant reference to the value's name.
LLVM_NODISCARD AttributeList removeAttribute(LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const
Remove the specified attribute at the specified index from this attribute list.
void setPrologueData(Constant *PrologueData)
void appendModuleInlineAsm(StringRef Asm)
Append to the module-scope inline assembly blocks.
Deduce function attributes
std::unique_ptr< Constant *[]> ConstantStructElts
0 1 1 0 True if ordered and operands are unequal
SPIR_FUNC - Calling convention for SPIR non-kernel device functions.
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 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.
Calling convention used by HipHop Virtual Machine (HHVM) to perform calls to and from translation cac...
Inlined bit vector ("Short Inline Bit Vectors")
X86_INTR - x86 hardware interrupt context.
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.
unsigned getMDKindID(StringRef Name) const
Return a unique non-zero ID for the specified metadata kind.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
X86_StdCall - stdcall is the calling conventions mostly used by the Win32 API.
A raw_ostream that writes to an std::string.
static CatchReturnInst * Create(Value *CatchPad, BasicBlock *BB, Instruction *InsertBefore=nullptr)
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
0 0 0 1 True if ordered and equal
LLVM Value Representation.
1 0 1 1 True if unordered, greater than, or equal
Just do a regular virtual call.
static VectorType * get(Type *ElementType, unsigned NumElements)
This static method is the primary way to construct an VectorType.
static StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
Synchronized with respect to all concurrently executing threads.
Lightweight error class with error context and mandatory checking.
static CleanupReturnInst * Create(Value *CleanupPad, BasicBlock *UnwindBB=nullptr, Instruction *InsertBefore=nullptr)
AttributeSet getFnAttributes() const
The function attributes are returned.
unsigned getAttributeEncoding(StringRef EncodingString)
AttrBuilder & addStackAlignmentAttr(unsigned Align)
This turns an int stack alignment (which must be a power of 2) into the form used internally in Attri...
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.
AttrBuilder & addAlignmentAttr(unsigned Align)
This turns an int alignment (which must be a power of 2) into the form used internally in Attribute...
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
enum llvm::ValID::@335 Kind
static IntegerType * getInt8Ty(LLVMContext &C)
void setSection(StringRef S)
Change the section for this global.
Calling convention for AMDGPU code object kernels.
static GlobalAlias * create(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name, Constant *Aliasee, Module *Parent)
If a parent module is specified, the alias is automatically inserted into the end of the specified mo...
static Constant * get(ArrayRef< Constant *> V)
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Type * getElementType() const
void setDSOLocal(bool Local)
PointerType * getType() const
Global values are always pointers.
static AttributeList get(LLVMContext &C, ArrayRef< std::pair< unsigned, Attribute >> Attrs)
Create an AttributeList with the specified parameters in it.
iterator_range< arg_iterator > args()
0 0 0 0 Always false (always folded)
Unique return value optimization.
bool isArrayTy() const
True if this is an instance of ArrayType.
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
MSP430_INTR - Calling convention used for MSP430 interrupt routines.
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...