72 "Can't read textual IR with a Context that discards named Values");
74 return ParseTopLevelEntities() ||
75 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() {
124 for (
const auto &RAG : ForwardRefAttrGroups) {
125 Value *V = RAG.first;
126 const std::vector<unsigned> &
Attrs = RAG.second;
129 for (
const auto &Attr : Attrs)
130 B.
merge(NumberedAttrBuilders[Attr]);
132 if (
Function *Fn = dyn_cast<Function>(V)) {
141 if (FnAttrs.hasAlignmentAttr()) {
142 Fn->setAlignment(FnAttrs.getAlignment());
148 Fn->setAttributes(AS);
149 }
else if (
CallInst *CI = dyn_cast<CallInst>(V)) {
156 CI->setAttributes(AS);
157 }
else if (
InvokeInst *II = dyn_cast<InvokeInst>(V)) {
164 II->setAttributes(AS);
165 }
else if (
auto *GV = dyn_cast<GlobalVariable>(V)) {
176 if (!ForwardRefBlockAddresses.empty())
177 return Error(ForwardRefBlockAddresses.begin()->first.Loc,
178 "expected function name in blockaddress");
180 for (
const auto &NT : NumberedTypes)
181 if (NT.second.second.isValid())
182 return Error(NT.second.second,
183 "use of undefined type '%" +
Twine(NT.first) +
"'");
185 for (
StringMap<std::pair<Type*, LocTy> >::iterator
I =
186 NamedTypes.begin(),
E = NamedTypes.end();
I !=
E; ++
I)
187 if (
I->second.second.isValid())
188 return Error(
I->second.second,
189 "use of undefined type named '" +
I->getKey() +
"'");
191 if (!ForwardRefComdats.empty())
192 return Error(ForwardRefComdats.begin()->second,
193 "use of undefined comdat '$" +
194 ForwardRefComdats.begin()->first +
"'");
196 if (!ForwardRefVals.empty())
197 return Error(ForwardRefVals.begin()->second.second,
198 "use of undefined value '@" + ForwardRefVals.begin()->first +
201 if (!ForwardRefValIDs.empty())
202 return Error(ForwardRefValIDs.begin()->second.second,
203 "use of undefined value '@" +
204 Twine(ForwardRefValIDs.begin()->first) +
"'");
206 if (!ForwardRefMDNodes.empty())
207 return Error(ForwardRefMDNodes.begin()->second.second,
208 "use of undefined metadata '!" +
209 Twine(ForwardRefMDNodes.begin()->first) +
"'");
212 for (
auto &
N : NumberedMetadata) {
213 if (
N.second && !
N.second->isResolved())
214 N.second->resolveCycles();
217 for (
auto *Inst : InstsWithTBAATag) {
219 assert(MD &&
"UpgradeInstWithTBAATag should have a TBAA tag");
221 if (MD != UpgradedMD)
251 for (
const auto &
I : NamedTypes)
252 Slots->
NamedTypes.insert(std::make_pair(
I.getKey(),
I.second.first));
253 for (
const auto &
I : NumberedTypes)
254 Slots->
Types.insert(std::make_pair(
I.first,
I.second.first));
263 bool LLParser::ParseTopLevelEntities() {
266 default:
return TokError(
"expected top-level entity");
273 if (ParseSourceFileName())
282 case lltok::exclaim:
if (ParseStandaloneMetadata())
return true;
break;
287 if (ParseUseListOrderBB())
296 bool LLParser::ParseModuleAsm() {
302 ParseStringConstant(AsmStr))
return true;
311 bool LLParser::ParseTargetDefinition() {
315 default:
return TokError(
"unknown target property");
318 if (ParseToken(
lltok::equal,
"expected '=' after target triple") ||
319 ParseStringConstant(Str))
325 if (ParseToken(
lltok::equal,
"expected '=' after target datalayout") ||
326 ParseStringConstant(Str))
335 bool LLParser::ParseSourceFileName() {
339 if (ParseToken(
lltok::equal,
"expected '=' after source_filename") ||
340 ParseStringConstant(Str))
350 bool LLParser::ParseDepLibs() {
353 if (ParseToken(
lltok::equal,
"expected '=' after deplibs") ||
362 if (ParseStringConstant(Str))
return true;
370 bool LLParser::ParseUnnamedType() {
375 if (ParseToken(
lltok::equal,
"expected '=' after name") ||
379 Type *Result =
nullptr;
380 if (ParseStructDefinition(TypeLoc,
"",
381 NumberedTypes[TypeID], Result))
return true;
383 if (!isa<StructType>(Result)) {
384 std::pair<Type*, LocTy> &Entry = NumberedTypes[
TypeID];
386 return Error(TypeLoc,
"non-struct types may not be recursive");
387 Entry.first = Result;
388 Entry.second =
SMLoc();
396 bool LLParser::ParseNamedType() {
401 if (ParseToken(
lltok::equal,
"expected '=' after name") ||
405 Type *Result =
nullptr;
406 if (ParseStructDefinition(NameLoc, Name,
407 NamedTypes[Name], Result))
return true;
409 if (!isa<StructType>(Result)) {
410 std::pair<Type*, LocTy> &Entry = NamedTypes[
Name];
412 return Error(NameLoc,
"non-struct types may not be recursive");
413 Entry.first = Result;
414 Entry.second =
SMLoc();
422 bool LLParser::ParseDeclare() {
426 std::vector<std::pair<unsigned, MDNode *>> MDs;
430 if (ParseMetadataAttachment(MDK, N))
432 MDs.push_back({MDK, N});
436 if (ParseFunctionHeader(F,
false))
445 bool LLParser::ParseDefine() {
450 return ParseFunctionHeader(F,
true) ||
451 ParseOptionalFunctionMetadata(*F) ||
452 ParseFunctionBody(*F);
458 bool LLParser::ParseGlobalType(
bool &IsConstant) {
465 return TokError(
"expected 'global' or 'constant'");
471 bool LLParser::ParseOptionalUnnamedAddr(
489 bool LLParser::ParseUnnamedGlobal() {
490 unsigned VarID = NumberedVals.size();
497 return Error(Lex.
getLoc(),
"variable expected to be numbered '%" +
501 if (ParseToken(
lltok::equal,
"expected '=' after name"))
506 unsigned Linkage,
Visibility, DLLStorageClass;
509 if (ParseOptionalLinkage(Linkage, HasLinkage, Visibility, DLLStorageClass) ||
510 ParseOptionalThreadLocal(TLM) || ParseOptionalUnnamedAddr(UnnamedAddr))
514 return ParseGlobal(Name, NameLoc, Linkage, HasLinkage, Visibility,
515 DLLStorageClass, TLM, UnnamedAddr);
517 return parseIndirectSymbol(Name, NameLoc, Linkage, Visibility,
518 DLLStorageClass, TLM, UnnamedAddr);
525 bool LLParser::ParseNamedGlobal() {
532 unsigned Linkage,
Visibility, DLLStorageClass;
535 if (ParseToken(
lltok::equal,
"expected '=' in global variable") ||
536 ParseOptionalLinkage(Linkage, HasLinkage, Visibility, DLLStorageClass) ||
537 ParseOptionalThreadLocal(TLM) || ParseOptionalUnnamedAddr(UnnamedAddr))
541 return ParseGlobal(Name, NameLoc, Linkage, HasLinkage, Visibility,
542 DLLStorageClass, TLM, UnnamedAddr);
544 return parseIndirectSymbol(Name, NameLoc, Linkage, Visibility,
545 DLLStorageClass, TLM, UnnamedAddr);
548 bool LLParser::parseComdat() {
558 return TokError(
"expected comdat type");
563 return TokError(
"unknown selection kind");
585 if (I != ComdatSymTab.
end() && !ForwardRefComdats.erase(Name))
586 return Error(NameLoc,
"redefinition of comdat '$" + Name +
"'");
589 if (I != ComdatSymTab.
end())
600 bool LLParser::ParseMDString(
MDString *&Result) {
602 if (ParseStringConstant(Str))
return true;
609 bool LLParser::ParseMDNodeID(
MDNode *&Result) {
613 if (ParseUInt32(MID))
617 if (NumberedMetadata.count(MID)) {
618 Result = NumberedMetadata[MID];
623 auto &FwdRef = ForwardRefMDNodes[MID];
626 Result = FwdRef.first.
get();
627 NumberedMetadata[MID].reset(Result);
633 bool LLParser::ParseNamedMetadata() {
650 if (ParseMDNodeID(N))
return true;
654 return ParseToken(
lltok::rbrace,
"expected end of metadata node");
659 bool LLParser::ParseStandaloneMetadata() {
662 unsigned MetadataID = 0;
665 if (ParseUInt32(MetadataID) ||
671 return TokError(
"unexpected type in metadata definition");
675 if (ParseSpecializedMDNode(Init, IsDistinct))
678 ParseMDTuple(Init, IsDistinct))
682 auto FI = ForwardRefMDNodes.find(MetadataID);
683 if (FI != ForwardRefMDNodes.end()) {
684 FI->second.first->replaceAllUsesWith(Init);
685 ForwardRefMDNodes.erase(FI);
687 assert(NumberedMetadata[MetadataID] == Init &&
"Tracking VH didn't work");
689 if (NumberedMetadata.count(MetadataID))
690 return TokError(
"Metadata id is already used");
691 NumberedMetadata[MetadataID].reset(Init);
712 bool LLParser::parseIndirectSymbol(
713 const std::string &Name, LocTy NameLoc,
unsigned L,
unsigned Visibility,
728 return Error(NameLoc,
"invalid linkage type for alias");
731 return Error(NameLoc,
732 "symbol with local linkage must have default visibility");
737 ParseToken(
lltok::comma,
"expected comma after alias or ifunc's type"))
746 if (ParseGlobalTypeAndValue(Aliasee))
754 return Error(AliaseeLoc,
"invalid aliasee");
761 return Error(AliaseeLoc,
"An alias or ifunc must have pointer type");
762 unsigned AddrSpace = PTy->getAddressSpace();
764 if (IsAlias && Ty != PTy->getElementType())
767 "explicit pointee type doesn't match operand's pointee type");
769 if (!IsAlias && !PTy->getElementType()->isFunctionTy())
772 "explicit pointee type should be a function type");
781 if (!ForwardRefVals.erase(Name))
782 return Error(NameLoc,
"redefinition of global '@" + Name +
"'");
785 auto I = ForwardRefValIDs.find(NumberedVals.size());
786 if (I != ForwardRefValIDs.end()) {
787 GVal = I->second.first;
788 ForwardRefValIDs.erase(I);
793 std::unique_ptr<GlobalIndirectSymbol> GA;
802 GA->setThreadLocalMode(TLM);
805 GA->setUnnamedAddr(UnnamedAddr);
808 NumberedVals.push_back(GA.get());
812 if (GVal->
getType() != GA->getType())
815 "forward reference and definition of alias have different types");
828 assert(GA->getName() == Name &&
"Should not be a name conflict!");
847 bool LLParser::ParseGlobal(
const std::string &Name, LocTy NameLoc,
848 unsigned Linkage,
bool HasLinkage,
849 unsigned Visibility,
unsigned DLLStorageClass,
853 return Error(NameLoc,
854 "symbol with local linkage must have default visibility");
857 bool IsConstant, IsExternallyInitialized;
858 LocTy IsExternallyInitializedLoc;
862 if (ParseOptionalAddrSpace(AddrSpace) ||
864 IsExternallyInitialized,
865 &IsExternallyInitializedLoc) ||
866 ParseGlobalType(IsConstant) ||
867 ParseType(Ty, TyLoc))
876 if (ParseGlobalValue(Ty, Init))
881 return Error(TyLoc,
"invalid type for global variable");
889 if (!ForwardRefVals.erase(Name))
890 return Error(NameLoc,
"redefinition of global '@" + Name +
"'");
893 auto I = ForwardRefValIDs.find(NumberedVals.size());
894 if (I != ForwardRefValIDs.end()) {
895 GVal = I->second.first;
896 ForwardRefValIDs.erase(I);
908 "forward reference and definition of global have different types");
910 GV = cast<GlobalVariable>(GVal);
917 NumberedVals.push_back(GV);
941 if (ParseOptionalAlignment(Alignment))
return true;
944 if (ParseGlobalObjectMetadataAttachment(*GV))
948 if (parseOptionalComdat(Name, C))
953 return TokError(
"unknown global variable property!");
959 std::vector<unsigned> FwdRefAttrGrps;
960 if (ParseFnAttributeValuePairs(Attrs, FwdRefAttrGrps,
false, BuiltinLoc))
964 ForwardRefAttrGroups[GV] = FwdRefAttrGrps;
972 bool LLParser::ParseUnnamedAttrGrp() {
978 return TokError(
"expected attribute group id");
981 std::vector<unsigned> unused;
987 ParseFnAttributeValuePairs(NumberedAttrBuilders[VarID], unused,
true,
989 ParseToken(
lltok::rbrace,
"expected end of attribute group"))
992 if (!NumberedAttrBuilders[VarID].hasAttributes())
993 return Error(AttrGrpLoc,
"attribute group has no attributes");
1000 bool LLParser::ParseFnAttributeValuePairs(
AttrBuilder &B,
1001 std::vector<unsigned> &FwdRefAttrGrps,
1002 bool inAttrGrp, LocTy &BuiltinLoc) {
1003 bool HaveError =
false;
1010 BuiltinLoc = Lex.
getLoc();
1013 if (!inAttrGrp)
return HaveError;
1014 return Error(Lex.
getLoc(),
"unterminated attribute group");
1026 "cannot have an attribute group reference in an attribute group");
1029 if (inAttrGrp)
break;
1032 FwdRefAttrGrps.push_back(AttrGrpNum);
1037 if (ParseStringAttribute(B))
1051 ParseUInt32(Alignment))
1054 if (ParseOptionalAlignment(Alignment))
1065 ParseUInt32(Alignment))
1068 if (ParseOptionalStackAlignment(Alignment))
1075 unsigned ElemSizeArg;
1078 if (parseAllocSizeArguments(ElemSizeArg, NumElemsArg))
1091 B.
addAttribute(Attribute::InaccessibleMemOrArgMemOnly);
break;
1133 "invalid use of attribute on a function");
1149 "invalid use of parameter-only attribute on a function");
1162 const std::string &Name) {
1175 GlobalValue *LLParser::GetGlobalVal(
const std::string &Name,
Type *Ty,
1179 Error(Loc,
"global variable reference must have pointer type");
1190 auto I = ForwardRefVals.find(Name);
1191 if (I != ForwardRefVals.end())
1192 Val = I->second.first;
1197 if (Val->
getType() == Ty)
return Val;
1198 Error(Loc,
"'@" + Name +
"' defined with type '" +
1205 ForwardRefVals[
Name] = std::make_pair(FwdVal, Loc);
1209 GlobalValue *LLParser::GetGlobalVal(
unsigned ID,
Type *Ty, LocTy Loc) {
1212 Error(Loc,
"global variable reference must have pointer type");
1216 GlobalValue *Val = ID < NumberedVals.size() ? NumberedVals[
ID] :
nullptr;
1221 auto I = ForwardRefValIDs.find(ID);
1222 if (I != ForwardRefValIDs.end())
1223 Val = I->second.first;
1228 if (Val->
getType() == Ty)
return Val;
1229 Error(Loc,
"'@" +
Twine(ID) +
"' defined with type '" +
1236 ForwardRefValIDs[
ID] = std::make_pair(FwdVal, Loc);
1244 Comdat *LLParser::getComdat(
const std::string &Name, LocTy Loc) {
1248 if (I != ComdatSymTab.
end())
1253 ForwardRefComdats[
Name] = Loc;
1265 return TokError(ErrMsg);
1272 bool LLParser::ParseStringConstant(std::string &Result) {
1274 return TokError(
"expected string constant");
1282 bool LLParser::ParseUInt32(
uint32_t &Val) {
1284 return TokError(
"expected integer");
1286 if (Val64 !=
unsigned(Val64))
1287 return TokError(
"expected 32-bit integer (too large)");
1295 bool LLParser::ParseUInt64(uint64_t &Val) {
1297 return TokError(
"expected integer");
1310 return TokError(
"expected localdynamic, initialexec or localexec");
1338 return ParseTLSModel(TLM) ||
1339 ParseToken(
lltok::rparen,
"expected ')' after thread local model");
1347 bool LLParser::ParseOptionalAddrSpace(
unsigned &AddrSpace) {
1351 return ParseToken(
lltok::lparen,
"expected '(' in address space") ||
1352 ParseUInt32(AddrSpace) ||
1359 bool LLParser::ParseStringAttribute(
AttrBuilder &B) {
1363 if (EatIfPresent(
lltok::equal) && ParseStringConstant(Val))
1370 bool LLParser::ParseOptionalParamAttrs(
AttrBuilder &B) {
1371 bool HaveError =
false;
1381 if (ParseStringAttribute(B))
1387 if (ParseOptionalAlignment(Alignment))
1450 HaveError |=
Error(Lex.
getLoc(),
"invalid use of function-only attribute");
1459 bool LLParser::ParseOptionalReturnAttrs(
AttrBuilder &B) {
1460 bool HaveError =
false;
1470 if (ParseStringAttribute(B))
1490 if (ParseOptionalAlignment(Alignment))
1510 HaveError |=
Error(Lex.
getLoc(),
"invalid use of parameter-only attribute");
1541 HaveError |=
Error(Lex.
getLoc(),
"invalid use of function-only attribute");
1546 HaveError |=
Error(Lex.
getLoc(),
"invalid use of attribute on return type");
1597 bool LLParser::ParseOptionalLinkage(
unsigned &Res,
bool &HasLinkage,
1598 unsigned &Visibility,
1599 unsigned &DLLStorageClass) {
1603 ParseOptionalVisibility(Visibility);
1604 ParseOptionalDLLStorageClass(DLLStorageClass);
1614 void LLParser::ParseOptionalVisibility(
unsigned &Res) {
1637 void LLParser::ParseOptionalDLLStorageClass(
unsigned &Res) {
1692 bool LLParser::ParseOptionalCallingConv(
unsigned &CC) {
1734 return ParseUInt32(CC);
1744 bool LLParser::ParseMetadataAttachment(
unsigned &
Kind,
MDNode *&MD) {
1751 return ParseMDNode(MD);
1756 bool LLParser::ParseInstructionMetadata(
Instruction &Inst) {
1759 return TokError(
"expected metadata after comma");
1763 if (ParseMetadataAttachment(MDK, N))
1768 InstsWithTBAATag.push_back(&Inst);
1777 bool LLParser::ParseGlobalObjectMetadataAttachment(
GlobalObject &GO) {
1780 if (ParseMetadataAttachment(MDK, N))
1789 bool LLParser::ParseOptionalFunctionMetadata(
Function &F) {
1791 if (ParseGlobalObjectMetadataAttachment(F))
1799 bool LLParser::ParseOptionalAlignment(
unsigned &Alignment) {
1804 if (ParseUInt32(Alignment))
return true;
1806 return Error(AlignLoc,
"alignment is not a power of two");
1808 return Error(AlignLoc,
"huge alignments are not supported yet");
1817 bool LLParser::ParseOptionalDerefAttrBytes(
lltok::Kind AttrKind,
1824 if (!EatIfPresent(AttrKind))
1828 return Error(ParenLoc,
"expected '('");
1830 if (ParseUInt64(Bytes))
return true;
1833 return Error(ParenLoc,
"expected ')'");
1835 return Error(DerefLoc,
"dereferenceable bytes must be non-zero");
1845 bool LLParser::ParseOptionalCommaAlign(
unsigned &Alignment,
1846 bool &AteExtraComma) {
1847 AteExtraComma =
false;
1851 AteExtraComma =
true;
1856 return Error(Lex.
getLoc(),
"expected metadata or 'align'");
1858 if (ParseOptionalAlignment(Alignment))
return true;
1870 bool LLParser::ParseOptionalCommaAddrSpace(
unsigned &AddrSpace,
1872 bool &AteExtraComma) {
1873 AteExtraComma =
false;
1877 AteExtraComma =
true;
1883 return Error(Lex.
getLoc(),
"expected metadata or 'addrspace'");
1885 if (ParseOptionalAddrSpace(AddrSpace))
1892 bool LLParser::parseAllocSizeArguments(
unsigned &BaseSizeArg,
1896 auto StartParen = Lex.
getLoc();
1898 return Error(StartParen,
"expected '('");
1900 if (ParseUInt32(BaseSizeArg))
1904 auto HowManyAt = Lex.
getLoc();
1906 if (ParseUInt32(HowMany))
1908 if (HowMany == BaseSizeArg)
1909 return Error(HowManyAt,
1910 "'allocsize' indices can't refer to the same parameter");
1911 HowManyArg = HowMany;
1915 auto EndParen = Lex.
getLoc();
1917 return Error(EndParen,
"expected ')'");
1931 return ParseScope(SSID) || ParseOrdering(Ordering);
1941 auto StartParenAt = Lex.
getLoc();
1943 return Error(StartParenAt,
"Expected '(' in syncscope");
1946 auto SSNAt = Lex.
getLoc();
1947 if (ParseStringConstant(SSN))
1948 return Error(SSNAt,
"Expected synchronization scope name");
1950 auto EndParenAt = Lex.
getLoc();
1952 return Error(EndParenAt,
"Expected ')' in syncscope");
1966 default:
return TokError(
"Expected ordering on atomic instruction");
1985 bool LLParser::ParseOptionalStackAlignment(
unsigned &Alignment) {
1991 return Error(ParenLoc,
"expected '('");
1993 if (ParseUInt32(Alignment))
return true;
1996 return Error(ParenLoc,
"expected ')'");
1998 return Error(AlignLoc,
"stack alignment is not a power of two");
2012 bool &AteExtraComma) {
2013 AteExtraComma =
false;
2016 return TokError(
"expected ',' as start of index list");
2020 if (Indices.
empty())
return TokError(
"expected index");
2021 AteExtraComma =
true;
2025 if (ParseUInt32(Idx))
return true;
2037 bool LLParser::ParseType(
Type *&Result,
const Twine &Msg,
bool AllowVoid) {
2041 return TokError(Msg);
2049 if (ParseAnonStructType(Result,
false))
2055 if (ParseArrayVectorType(Result,
false))
2062 if (ParseAnonStructType(Result,
true) ||
2063 ParseToken(
lltok::greater,
"expected '>' at end of packed struct"))
2065 }
else if (ParseArrayVectorType(Result,
true))
2070 std::pair<Type*, LocTy> &Entry = NamedTypes[Lex.
getStrVal()];
2076 Entry.second = Lex.
getLoc();
2078 Result = Entry.first;
2085 std::pair<Type*, LocTy> &Entry = NumberedTypes[Lex.
getUIntVal()];
2091 Entry.second = Lex.
getLoc();
2093 Result = Entry.first;
2104 if (!AllowVoid && Result->
isVoidTy())
2105 return Error(TypeLoc,
"void type only allowed for function results");
2111 return TokError(
"basic block pointers are invalid");
2113 return TokError(
"pointers to void are invalid - use i8* instead");
2115 return TokError(
"pointer to this type is invalid");
2123 return TokError(
"basic block pointers are invalid");
2125 return TokError(
"pointers to void are invalid; use i8* instead");
2127 return TokError(
"pointer to this type is invalid");
2129 if (ParseOptionalAddrSpace(AddrSpace) ||
2130 ParseToken(
lltok::star,
"expected '*' in address space"))
2139 if (ParseFunctionType(Result))
2152 PerFunctionState &PFS,
bool IsMustTailCall,
2153 bool InVarArgsFunc) {
2159 if (!ArgList.
empty() &&
2160 ParseToken(
lltok::comma,
"expected ',' in argument list"))
2165 const char *Msg =
"unexpected ellipsis in argument list for ";
2166 if (!IsMustTailCall)
2167 return TokError(
Twine(Msg) +
"non-musttail call");
2169 return TokError(
Twine(Msg) +
"musttail call in non-varargs function");
2171 return ParseToken(
lltok::rparen,
"expected ')' at end of argument list");
2176 Type *ArgTy =
nullptr;
2179 if (ParseType(ArgTy, ArgLoc))
2183 if (ParseMetadataAsValue(V, PFS))
2187 if (ParseOptionalParamAttrs(ArgAttrs) || ParseValue(ArgTy, V, PFS))
2194 if (IsMustTailCall && InVarArgsFunc)
2195 return TokError(
"expected '...' at end of argument list for musttail call "
2196 "in varargs function");
2211 bool LLParser::ParseOptionalOperandBundles(
2219 if (!BundleList.
empty() &&
2220 ParseToken(
lltok::comma,
"expected ',' in input list"))
2224 if (ParseStringConstant(Tag))
2227 if (ParseToken(
lltok::lparen,
"expected '(' in operand bundle"))
2230 std::vector<Value *> Inputs;
2233 if (!Inputs.empty() &&
2234 ParseToken(
lltok::comma,
"expected ',' in input list"))
2238 Value *Input =
nullptr;
2239 if (ParseType(Ty) || ParseValue(Ty, Input, PFS))
2241 Inputs.push_back(Input);
2244 BundleList.
emplace_back(std::move(Tag), std::move(Inputs));
2249 if (BundleList.
empty())
2250 return Error(BeginLoc,
"operand bundle set must not be empty");
2278 Type *ArgTy =
nullptr;
2282 if (ParseType(ArgTy) ||
2283 ParseOptionalParamAttrs(Attrs))
return true;
2286 return Error(TypeLoc,
"argument can not have void type");
2294 return Error(TypeLoc,
"invalid type for function argument");
2309 if (ParseType(ArgTy) || ParseOptionalParamAttrs(Attrs))
return true;
2312 return Error(TypeLoc,
"argument can not have void type");
2322 return Error(TypeLoc,
"invalid type for function argument");
2330 return ParseToken(
lltok::rparen,
"expected ')' at end of argument list");
2335 bool LLParser::ParseFunctionType(
Type *&Result) {
2339 return TokError(
"invalid function return type");
2343 if (ParseArgumentList(ArgList, isVarArg))
2347 for (
unsigned i = 0, e = ArgList.
size(); i != e; ++i) {
2348 if (!ArgList[i].Name.
empty())
2349 return Error(ArgList[i].Loc,
"argument name invalid in function type");
2351 return Error(ArgList[i].Loc,
2352 "argument attributes invalid in function type");
2356 for (
unsigned i = 0, e = ArgList.
size(); i != e; ++i)
2365 bool LLParser::ParseAnonStructType(
Type *&Result,
bool Packed) {
2367 if (ParseStructBody(Elts))
return true;
2374 bool LLParser::ParseStructDefinition(
SMLoc TypeLoc,
StringRef Name,
2375 std::pair<Type*, LocTy> &Entry,
2378 if (Entry.first && !Entry.second.isValid())
2379 return Error(TypeLoc,
"redefinition of type");
2385 Entry.second =
SMLoc();
2390 ResultTy = Entry.first;
2402 return Error(TypeLoc,
"forward references to non-struct type");
2406 return ParseArrayVectorType(ResultTy,
true);
2407 return ParseType(ResultTy);
2411 Entry.second =
SMLoc();
2417 StructType *STy = cast<StructType>(Entry.first);
2420 if (ParseStructBody(Body) ||
2421 (isPacked && ParseToken(
lltok::greater,
"expected '>' in packed struct")))
2445 if (ParseType(Ty))
return true;
2449 return Error(EltTyLoc,
"invalid element type for struct");
2453 if (ParseType(Ty))
return true;
2456 return Error(EltTyLoc,
"invalid element type for struct");
2461 return ParseToken(
lltok::rbrace,
"expected '}' at end of struct");
2469 bool LLParser::ParseArrayVectorType(
Type *&Result,
bool isVector) {
2472 return TokError(
"expected number in address space");
2478 if (ParseToken(
lltok::kw_x,
"expected 'x' after element count"))
2482 Type *EltTy =
nullptr;
2483 if (ParseType(EltTy))
return true;
2486 "expected end of sequential type"))
2491 return Error(SizeLoc,
"zero element vector is illegal");
2492 if ((
unsigned)Size != Size)
2493 return Error(SizeLoc,
"size too large for vector");
2495 return Error(TypeLoc,
"invalid vector element type");
2499 return Error(TypeLoc,
"invalid array element type");
2516 NumberedVals.push_back(&
A);
2519 LLParser::PerFunctionState::~PerFunctionState() {
2522 for (
const auto &
P : ForwardRefVals) {
2523 if (isa<BasicBlock>(
P.second.first))
2525 P.second.first->replaceAllUsesWith(
2527 P.second.first->deleteValue();
2530 for (
const auto &
P : ForwardRefValIDs) {
2531 if (isa<BasicBlock>(
P.second.first))
2533 P.second.first->replaceAllUsesWith(
2535 P.second.first->deleteValue();
2539 bool LLParser::PerFunctionState::FinishFunction() {
2540 if (!ForwardRefVals.empty())
2541 return P.Error(ForwardRefVals.begin()->second.second,
2542 "use of undefined value '%" + ForwardRefVals.begin()->first +
2544 if (!ForwardRefValIDs.empty())
2545 return P.Error(ForwardRefValIDs.begin()->second.second,
2546 "use of undefined value '%" +
2547 Twine(ForwardRefValIDs.begin()->first) +
"'");
2554 Value *LLParser::PerFunctionState::GetVal(
const std::string &Name,
Type *Ty,
2562 auto I = ForwardRefVals.find(Name);
2563 if (I != ForwardRefVals.end())
2564 Val = I->second.first;
2569 if (Val->
getType() == Ty)
return Val;
2571 P.Error(Loc,
"'%" + Name +
"' is not a basic block");
2573 P.Error(Loc,
"'%" + Name +
"' defined with type '" +
2580 P.Error(Loc,
"invalid use of a non-first-class type");
2592 ForwardRefVals[
Name] = std::make_pair(FwdVal, Loc);
2596 Value *LLParser::PerFunctionState::GetVal(
unsigned ID,
Type *Ty, LocTy Loc) {
2598 Value *Val = ID < NumberedVals.size() ? NumberedVals[
ID] :
nullptr;
2603 auto I = ForwardRefValIDs.find(ID);
2604 if (I != ForwardRefValIDs.end())
2605 Val = I->second.first;
2610 if (Val->
getType() == Ty)
return Val;
2612 P.Error(Loc,
"'%" +
Twine(ID) +
"' is not a basic block");
2614 P.Error(Loc,
"'%" +
Twine(ID) +
"' defined with type '" +
2620 P.Error(Loc,
"invalid use of a non-first-class type");
2632 ForwardRefValIDs[
ID] = std::make_pair(FwdVal, Loc);
2638 bool LLParser::PerFunctionState::SetInstName(
int NameID,
2639 const std::string &NameStr,
2643 if (NameID != -1 || !NameStr.empty())
2644 return P.Error(NameLoc,
"instructions returning void cannot have a name");
2650 if (NameStr.empty()) {
2653 NameID = NumberedVals.size();
2655 if (
unsigned(NameID) != NumberedVals.size())
2656 return P.Error(NameLoc,
"instruction expected to be numbered '%" +
2657 Twine(NumberedVals.size()) +
"'");
2659 auto FI = ForwardRefValIDs.find(NameID);
2660 if (FI != ForwardRefValIDs.end()) {
2661 Value *Sentinel = FI->second.first;
2663 return P.Error(NameLoc,
"instruction forward referenced with type '" +
2668 ForwardRefValIDs.erase(FI);
2671 NumberedVals.push_back(Inst);
2676 auto FI = ForwardRefVals.find(NameStr);
2677 if (FI != ForwardRefVals.end()) {
2678 Value *Sentinel = FI->second.first;
2680 return P.Error(NameLoc,
"instruction forward referenced with type '" +
2685 ForwardRefVals.erase(FI);
2691 if (Inst->
getName() != NameStr)
2692 return P.Error(NameLoc,
"multiple definition of local value named '" +
2699 BasicBlock *LLParser::PerFunctionState::GetBB(
const std::string &Name,
2701 return dyn_cast_or_null<BasicBlock>(GetVal(Name,
2705 BasicBlock *LLParser::PerFunctionState::GetBB(
unsigned ID, LocTy Loc) {
2706 return dyn_cast_or_null<BasicBlock>(GetVal(ID,
2713 BasicBlock *LLParser::PerFunctionState::DefineBB(
const std::string &Name,
2717 BB = GetBB(NumberedVals.size(), Loc);
2719 BB = GetBB(Name, Loc);
2720 if (!BB)
return nullptr;
2728 ForwardRefValIDs.erase(NumberedVals.size());
2729 NumberedVals.push_back(BB);
2732 ForwardRefVals.erase(Name);
2748 bool LLParser::ParseValID(
ValID &ID, PerFunctionState *PFS) {
2751 default:
return TokError(
"expected value token");
2793 if (ParseGlobalValueVector(Elts) ||
2794 ParseToken(
lltok::rbrace,
"expected end of struct constant"))
2800 Elts.
size() *
sizeof(Elts[0]));
2812 if (ParseGlobalValueVector(Elts) ||
2814 ParseToken(
lltok::rbrace,
"expected end of packed struct")) ||
2818 if (isPackedStruct) {
2821 Elts.
size() *
sizeof(Elts[0]));
2828 return Error(ID.
Loc,
"constant vector must not be empty");
2830 if (!Elts[0]->
getType()->isIntegerTy() &&
2831 !Elts[0]->getType()->isFloatingPointTy() &&
2832 !Elts[0]->getType()->isPointerTy())
2833 return Error(FirstEltLoc,
2834 "vector elements must have integer, pointer or floating point type");
2837 for (
unsigned i = 1, e = Elts.
size(); i != e; ++i)
2838 if (Elts[i]->
getType() != Elts[0]->getType())
2839 return Error(FirstEltLoc,
2840 "vector element #" +
Twine(i) +
2851 if (ParseGlobalValueVector(Elts) ||
2852 ParseToken(lltok::rsquare,
"expected end of array constant"))
2863 if (!Elts[0]->
getType()->isFirstClassType())
2864 return Error(FirstEltLoc,
"invalid array element type: " +
2870 for (
unsigned i = 0, e = Elts.
size(); i != e; ++i) {
2871 if (Elts[i]->
getType() != Elts[0]->getType())
2872 return Error(FirstEltLoc,
2873 "array element #" +
Twine(i) +
2892 bool HasSideEffect, AlignStack, AsmDialect;
2897 ParseStringConstant(ID.
StrVal) ||
2898 ParseToken(
lltok::comma,
"expected comma in inline asm expression") ||
2903 (
unsigned(AsmDialect)<<2);
2914 if (ParseToken(
lltok::lparen,
"expected '(' in block address expression") ||
2916 ParseToken(
lltok::comma,
"expected comma in block address expression")||
2917 ParseValID(Label) ||
2918 ParseToken(
lltok::rparen,
"expected ')' in block address expression"))
2922 return Error(Fn.
Loc,
"expected function name in blockaddress");
2924 return Error(Label.
Loc,
"expected basic block name in blockaddress");
2929 if (Fn.
UIntVal < NumberedVals.size())
2930 GV = NumberedVals[Fn.
UIntVal];
2931 }
else if (!ForwardRefVals.count(Fn.
StrVal)) {
2937 if (!isa<Function>(GV))
2938 return Error(Fn.
Loc,
"expected function name in blockaddress");
2939 F = cast<Function>(GV);
2941 return Error(Fn.
Loc,
"cannot take blockaddress inside a declaration");
2947 ForwardRefBlockAddresses.insert(std::make_pair(
2949 std::map<ValID, GlobalValue *>()))
2950 .first->second.insert(std::make_pair(std::move(Label),
nullptr))
2963 if (BlockAddressPFS && F == &BlockAddressPFS->getFunction()) {
2965 BB = BlockAddressPFS->GetBB(Label.
UIntVal, Label.
Loc);
2967 BB = BlockAddressPFS->GetBB(Label.
StrVal, Label.
Loc);
2969 return Error(Label.
Loc,
"referenced value is not a basic block");
2972 return Error(Label.
Loc,
"cannot take address of numeric label after "
2973 "the function is defined");
2974 BB = dyn_cast_or_null<BasicBlock>(
2977 return Error(Label.
Loc,
"referenced value is not a basic block");
2999 Type *DestTy =
nullptr;
3002 if (ParseToken(
lltok::lparen,
"expected '(' after constantexpr cast") ||
3003 ParseGlobalTypeAndValue(SrcVal) ||
3004 ParseToken(
lltok::kw_to,
"expected 'to' in constantexpr cast") ||
3005 ParseType(DestTy) ||
3006 ParseToken(
lltok::rparen,
"expected ')' at end of constantexpr cast"))
3009 return Error(ID.
Loc,
"invalid cast opcode for cast from '" +
3021 if (ParseToken(
lltok::lparen,
"expected '(' in extractvalue constantexpr")||
3022 ParseGlobalTypeAndValue(Val) ||
3023 ParseIndexList(Indices) ||
3024 ParseToken(
lltok::rparen,
"expected ')' in extractvalue constantexpr"))
3028 return Error(ID.
Loc,
"extractvalue operand must be aggregate type");
3030 return Error(ID.
Loc,
"invalid indices for extractvalue");
3039 if (ParseToken(
lltok::lparen,
"expected '(' in insertvalue constantexpr")||
3040 ParseGlobalTypeAndValue(Val0) ||
3041 ParseToken(
lltok::comma,
"expected comma in insertvalue constantexpr")||
3042 ParseGlobalTypeAndValue(Val1) ||
3043 ParseIndexList(Indices) ||
3044 ParseToken(
lltok::rparen,
"expected ')' in insertvalue constantexpr"))
3047 return Error(ID.
Loc,
"insertvalue operand must be aggregate type");
3051 return Error(ID.
Loc,
"invalid indices for insertvalue");
3052 if (IndexedType != Val1->
getType())
3053 return Error(ID.
Loc,
"insertvalue operand and field disagree in type: '" +
3066 if (ParseCmpPredicate(PredVal, Opc) ||
3067 ParseToken(
lltok::lparen,
"expected '(' in compare constantexpr") ||
3068 ParseGlobalTypeAndValue(Val0) ||
3069 ParseToken(
lltok::comma,
"expected comma in compare constantexpr") ||
3070 ParseGlobalTypeAndValue(Val1) ||
3071 ParseToken(
lltok::rparen,
"expected ')' in compare constantexpr"))
3075 return Error(ID.
Loc,
"compare operands must have the same type");
3079 if (Opc == Instruction::FCmp) {
3081 return Error(ID.
Loc,
"fcmp requires floating point operands");
3084 assert(Opc == Instruction::ICmp &&
"Unexpected opcode for CmpInst!");
3087 return Error(ID.
Loc,
"icmp requires pointer or integer operands");
3118 Opc == Instruction::Mul || Opc == Instruction::Shl) {
3126 }
else if (Opc == Instruction::SDiv || Opc == Instruction::UDiv ||
3127 Opc == Instruction::LShr || Opc == Instruction::AShr) {
3131 if (ParseToken(
lltok::lparen,
"expected '(' in binary constantexpr") ||
3132 ParseGlobalTypeAndValue(Val0) ||
3133 ParseToken(
lltok::comma,
"expected comma in binary constantexpr") ||
3134 ParseGlobalTypeAndValue(Val1) ||
3135 ParseToken(
lltok::rparen,
"expected ')' in binary constantexpr"))
3138 return Error(ID.
Loc,
"operands of constexpr must have same type");
3141 return Error(ModifierLoc,
"nuw only applies to integer operations");
3143 return Error(ModifierLoc,
"nsw only applies to integer operations");
3148 case Instruction::Sub:
3149 case Instruction::Mul:
3150 case Instruction::UDiv:
3151 case Instruction::SDiv:
3152 case Instruction::URem:
3153 case Instruction::SRem:
3154 case Instruction::Shl:
3155 case Instruction::AShr:
3156 case Instruction::LShr:
3158 return Error(ID.
Loc,
"constexpr requires integer operands");
3160 case Instruction::FAdd:
3161 case Instruction::FSub:
3162 case Instruction::FMul:
3163 case Instruction::FDiv:
3164 case Instruction::FRem:
3166 return Error(ID.
Loc,
"constexpr requires fp operands");
3187 if (ParseToken(
lltok::lparen,
"expected '(' in logical constantexpr") ||
3188 ParseGlobalTypeAndValue(Val0) ||
3189 ParseToken(
lltok::comma,
"expected comma in logical constantexpr") ||
3190 ParseGlobalTypeAndValue(Val1) ||
3191 ParseToken(
lltok::rparen,
"expected ')' in logical constantexpr"))
3194 return Error(ID.
Loc,
"operands of constexpr must have same type");
3197 "constexpr requires integer or integer vector operands");
3210 bool InBounds =
false;
3214 if (Opc == Instruction::GetElementPtr)
3217 if (ParseToken(
lltok::lparen,
"expected '(' in constantexpr"))
3221 if (Opc == Instruction::GetElementPtr) {
3222 if (ParseType(Ty) ||
3223 ParseToken(
lltok::comma,
"expected comma after getelementptr's type"))
3228 if (ParseGlobalValueVector(
3229 Elts, Opc == Instruction::GetElementPtr ? &InRangeOp :
nullptr) ||
3233 if (Opc == Instruction::GetElementPtr) {
3234 if (Elts.
size() == 0 ||
3235 !Elts[0]->getType()->isPtrOrPtrVectorTy())
3236 return Error(ID.
Loc,
"base of getelementptr must be a pointer");
3239 auto *BasePointerType = cast<PointerType>(BaseType->
getScalarType());
3240 if (Ty != BasePointerType->getElementType())
3243 "explicit pointee type doesn't match operand's pointee type");
3252 return Error(ID.
Loc,
"getelementptr index must be an integer");
3255 if (GEPWidth && (ValNumEl != GEPWidth))
3258 "getelementptr vector index has a wrong number of elements");
3261 GEPWidth = ValNumEl;
3266 if (!Indices.empty() && !Ty->
isSized(&Visited))
3267 return Error(ID.
Loc,
"base element of getelementptr must be sized");
3270 return Error(ID.
Loc,
"invalid getelementptr indices");
3273 if (*InRangeOp == 0)
3275 "inrange keyword may not appear on pointer operand");
3280 InBounds, InRangeOp);
3282 if (Elts.
size() != 3)
3283 return Error(ID.
Loc,
"expected three operands to select");
3288 }
else if (Opc == Instruction::ShuffleVector) {
3289 if (Elts.
size() != 3)
3290 return Error(ID.
Loc,
"expected three operands to shufflevector");
3292 return Error(ID.
Loc,
"invalid operands to shufflevector");
3295 }
else if (Opc == Instruction::ExtractElement) {
3296 if (Elts.
size() != 2)
3297 return Error(ID.
Loc,
"expected two operands to extractelement");
3299 return Error(ID.
Loc,
"invalid extractelement operands");
3302 assert(Opc == Instruction::InsertElement &&
"Unknown opcode");
3303 if (Elts.
size() != 3)
3304 return Error(ID.
Loc,
"expected three operands to insertelement");
3306 return Error(ID.
Loc,
"invalid insertelement operands");
3321 bool LLParser::ParseGlobalValue(
Type *Ty,
Constant *&C) {
3325 bool Parsed = ParseValID(ID) ||
3326 ConvertValIDToValue(Ty, ID, V,
nullptr);
3327 if (V && !(C = dyn_cast<Constant>(V)))
3328 return Error(ID.
Loc,
"global values must be constants");
3332 bool LLParser::ParseGlobalTypeAndValue(
Constant *&V) {
3334 return ParseType(Ty) ||
3335 ParseGlobalValue(Ty, V);
3338 bool LLParser::parseOptionalComdat(
StringRef GlobalName,
Comdat *&C) {
3347 return TokError(
"expected comdat variable");
3350 if (ParseToken(
lltok::rparen,
"expected ')' after comdat var"))
3353 if (GlobalName.
empty())
3354 return TokError(
"comdat cannot be unnamed");
3355 C = getComdat(GlobalName, KwLoc);
3368 Lex.
getKind() == lltok::rsquare ||
3375 *InRangeOp = Elts.
size();
3378 if (ParseGlobalTypeAndValue(C))
return true;
3385 bool LLParser::ParseMDTuple(
MDNode *&MD,
bool IsDistinct) {
3387 if (ParseMDNodeVector(Elts))
3398 bool LLParser::ParseMDNode(
MDNode *&N) {
3400 return ParseSpecializedMDNode(N);
3406 bool LLParser::ParseMDNodeTail(
MDNode *&N) {
3409 return ParseMDTuple(N);
3412 return ParseMDNodeID(N);
3418 template <
class FieldTy>
struct MDFieldImpl {
3419 typedef MDFieldImpl ImplTy;
3423 void assign(FieldTy Val) {
3425 this->Val = std::move(Val);
3428 explicit MDFieldImpl(FieldTy
Default)
3429 : Val(std::move(Default)), Seen(
false) {}
3432 struct MDUnsignedField :
public MDFieldImpl<uint64_t> {
3435 MDUnsignedField(uint64_t
Default = 0, uint64_t Max = UINT64_MAX)
3439 struct LineField :
public MDUnsignedField {
3440 LineField() : MDUnsignedField(0, UINT32_MAX) {}
3443 struct ColumnField :
public MDUnsignedField {
3444 ColumnField() : MDUnsignedField(0, UINT16_MAX) {}
3447 struct DwarfTagField :
public MDUnsignedField {
3453 struct DwarfMacinfoTypeField :
public MDUnsignedField {
3459 struct DwarfAttEncodingField :
public MDUnsignedField {
3460 DwarfAttEncodingField() : MDUnsignedField(0, dwarf::
DW_ATE_hi_user) {}
3463 struct DwarfVirtualityField :
public MDUnsignedField {
3467 struct DwarfLangField :
public MDUnsignedField {
3471 struct DwarfCCField :
public MDUnsignedField {
3472 DwarfCCField() : MDUnsignedField(0, dwarf::
DW_CC_hi_user) {}
3475 struct EmissionKindField :
public MDUnsignedField {
3476 EmissionKindField() : MDUnsignedField(0,
DICompileUnit::LastEmissionKind) {}
3479 struct DIFlagField :
public MDFieldImpl<DINode::DIFlags> {
3480 DIFlagField() : MDFieldImpl(
DINode::FlagZero) {}
3483 struct MDSignedField :
public MDFieldImpl<int64_t> {
3487 MDSignedField(int64_t
Default = 0)
3489 MDSignedField(int64_t
Default, int64_t
Min, int64_t Max)
3490 : ImplTy(Default), Min(Min), Max(Max) {}
3493 struct MDBoolField :
public MDFieldImpl<bool> {
3497 struct MDField :
public MDFieldImpl<Metadata *> {
3500 MDField(
bool AllowNull =
true) : ImplTy(nullptr), AllowNull(AllowNull) {}
3503 struct MDConstant :
public MDFieldImpl<ConstantAsMetadata *> {
3504 MDConstant() : ImplTy(nullptr) {}
3507 struct MDStringField :
public MDFieldImpl<MDString *> {
3509 MDStringField(
bool AllowEmpty =
true)
3510 : ImplTy(nullptr), AllowEmpty(AllowEmpty) {}
3513 struct MDFieldList :
public MDFieldImpl<SmallVector<Metadata *, 4>> {
3517 struct ChecksumKindField :
public MDFieldImpl<DIFile::ChecksumKind> {
3518 ChecksumKindField() : ImplTy(
DIFile::CSK_None) {}
3527 bool LLParser::ParseMDField(LocTy Loc,
StringRef Name,
3528 MDUnsignedField &Result) {
3530 return TokError(
"expected unsigned integer");
3533 if (U.ugt(Result.Max))
3534 return TokError(
"value for '" + Name +
"' too large, limit is " +
3536 Result.assign(U.getZExtValue());
3537 assert(Result.Val <= Result.Max &&
"Expected value in range");
3543 bool LLParser::ParseMDField(LocTy Loc,
StringRef Name, LineField &Result) {
3544 return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
3547 bool LLParser::ParseMDField(LocTy Loc,
StringRef Name, ColumnField &Result) {
3548 return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
3552 bool LLParser::ParseMDField(LocTy Loc,
StringRef Name, DwarfTagField &Result) {
3554 return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
3557 return TokError(
"expected DWARF tag");
3561 return TokError(
"invalid DWARF tag" +
Twine(
" '") + Lex.
getStrVal() +
"'");
3562 assert(Tag <= Result.Max &&
"Expected valid DWARF tag");
3570 bool LLParser::ParseMDField(LocTy Loc,
StringRef Name,
3571 DwarfMacinfoTypeField &Result) {
3573 return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
3576 return TokError(
"expected DWARF macinfo type");
3581 "invalid DWARF macinfo type" +
Twine(
" '") + Lex.
getStrVal() +
"'");
3582 assert(Macinfo <= Result.Max &&
"Expected valid DWARF macinfo type");
3584 Result.assign(Macinfo);
3590 bool LLParser::ParseMDField(LocTy Loc,
StringRef Name,
3591 DwarfVirtualityField &Result) {
3593 return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
3596 return TokError(
"expected DWARF virtuality code");
3600 return TokError(
"invalid DWARF virtuality code" +
Twine(
" '") +
3602 assert(Virtuality <= Result.Max &&
"Expected valid DWARF virtuality code");
3603 Result.assign(Virtuality);
3609 bool LLParser::ParseMDField(LocTy Loc,
StringRef Name, DwarfLangField &Result) {
3611 return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
3614 return TokError(
"expected DWARF language");
3618 return TokError(
"invalid DWARF language" +
Twine(
" '") + Lex.
getStrVal() +
3620 assert(Lang <= Result.Max &&
"Expected valid DWARF language");
3621 Result.assign(Lang);
3627 bool LLParser::ParseMDField(LocTy Loc,
StringRef Name, DwarfCCField &Result) {
3629 return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
3632 return TokError(
"expected DWARF calling convention");
3636 return TokError(
"invalid DWARF calling convention" +
Twine(
" '") + Lex.
getStrVal() +
3638 assert(CC <= Result.Max &&
"Expected valid DWARF calling convention");
3645 bool LLParser::ParseMDField(LocTy Loc,
StringRef Name, EmissionKindField &Result) {
3647 return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
3650 return TokError(
"expected emission kind");
3654 return TokError(
"invalid emission kind" +
Twine(
" '") + Lex.
getStrVal() +
3656 assert(*Kind <= Result.Max &&
"Expected valid emission kind");
3657 Result.assign(*Kind);
3663 bool LLParser::ParseMDField(LocTy Loc,
StringRef Name,
3664 DwarfAttEncodingField &Result) {
3666 return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
3669 return TokError(
"expected DWARF type attribute encoding");
3673 return TokError(
"invalid DWARF type attribute encoding" +
Twine(
" '") +
3675 assert(Encoding <= Result.Max &&
"Expected valid DWARF language");
3676 Result.assign(Encoding);
3686 bool LLParser::ParseMDField(LocTy Loc,
StringRef Name, DIFlagField &Result) {
3692 bool Res = ParseUInt32(TempVal);
3698 return TokError(
"expected debug info flag");
3702 return TokError(
Twine(
"invalid debug info flag flag '") +
3717 Result.assign(Combined);
3722 bool LLParser::ParseMDField(LocTy Loc,
StringRef Name,
3723 MDSignedField &Result) {
3725 return TokError(
"expected signed integer");
3729 return TokError(
"value for '" + Name +
"' too small, limit is " +
3732 return TokError(
"value for '" + Name +
"' too large, limit is " +
3734 Result.assign(S.getExtValue());
3735 assert(Result.Val >= Result.Min &&
"Expected value in range");
3736 assert(Result.Val <= Result.Max &&
"Expected value in range");
3742 bool LLParser::ParseMDField(LocTy Loc,
StringRef Name, MDBoolField &Result) {
3745 return TokError(
"expected 'true' or 'false'");
3747 Result.assign(
true);
3750 Result.assign(
false);
3758 bool LLParser::ParseMDField(LocTy Loc,
StringRef Name, MDField &Result) {
3760 if (!Result.AllowNull)
3761 return TokError(
"'" + Name +
"' cannot be null");
3763 Result.assign(
nullptr);
3768 if (ParseMetadata(MD,
nullptr))
3776 bool LLParser::ParseMDField(LocTy Loc,
StringRef Name, MDStringField &Result) {
3779 if (ParseStringConstant(S))
3782 if (!Result.AllowEmpty && S.empty())
3783 return Error(ValueLoc,
"'" + Name +
"' cannot be empty");
3785 Result.assign(S.empty() ?
nullptr :
MDString::get(Context, S));
3790 bool LLParser::ParseMDField(LocTy Loc,
StringRef Name, MDFieldList &Result) {
3792 if (ParseMDNodeVector(MDs))
3795 Result.assign(std::move(MDs));
3800 bool LLParser::ParseMDField(LocTy Loc,
StringRef Name,
3801 ChecksumKindField &Result) {
3808 Result.assign(CSKind);
3815 template <
class ParserTy>
3816 bool LLParser::ParseMDFieldsImplBody(ParserTy
parseField) {
3819 return TokError(
"expected field label here");
3828 template <
class ParserTy>
3829 bool LLParser::ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc) {
3836 if (ParseMDFieldsImplBody(parseField))
3839 ClosingLoc = Lex.
getLoc();
3843 template <
class FieldTy>
3844 bool LLParser::ParseMDField(
StringRef Name, FieldTy &Result) {
3846 return TokError(
"field '" + Name +
"' cannot be specified more than once");
3850 return ParseMDField(Loc, Name, Result);
3853 bool LLParser::ParseSpecializedMDNode(
MDNode *&N,
bool IsDistinct) {
3856 #define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
3857 if (Lex.getStrVal() == #CLASS) \
3858 return Parse##CLASS(N, IsDistinct);
3859 #include "llvm/IR/Metadata.def"
3861 return TokError(
"expected metadata type");
3864 #define DECLARE_FIELD(NAME, TYPE, INIT) TYPE NAME INIT
3865 #define NOP_FIELD(NAME, TYPE, INIT)
3866 #define REQUIRE_FIELD(NAME, TYPE, INIT) \
3868 return Error(ClosingLoc, "missing required field '" #NAME "'");
3869 #define PARSE_MD_FIELD(NAME, TYPE, DEFAULT) \
3870 if (Lex.getStrVal() == #NAME) \
3871 return ParseMDField(#NAME, NAME);
3872 #define PARSE_MD_FIELDS() \
3873 VISIT_MD_FIELDS(DECLARE_FIELD, DECLARE_FIELD) \
3876 if (ParseMDFieldsImpl([&]() -> bool { \
3877 VISIT_MD_FIELDS(PARSE_MD_FIELD, PARSE_MD_FIELD) \
3878 return TokError(Twine("invalid field '") + Lex.getStrVal() + "'"); \
3881 VISIT_MD_FIELDS(NOP_FIELD, REQUIRE_FIELD) \
3883 #define GET_OR_DISTINCT(CLASS, ARGS) \
3884 (IsDistinct ? CLASS::getDistinct ARGS : CLASS::get ARGS)
3888 bool LLParser::ParseDILocation(
MDNode *&Result,
bool IsDistinct) {
3889 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
3890 OPTIONAL(line, LineField, ); \
3891 OPTIONAL(column, ColumnField, ); \
3892 REQUIRED(scope, MDField, ( false)); \
3893 OPTIONAL(inlinedAt, MDField, );
3895 #undef VISIT_MD_FIELDS
3898 DILocation, (Context, line.Val, column.Val, scope.Val, inlinedAt.Val));
3904 bool LLParser::ParseGenericDINode(
MDNode *&Result,
bool IsDistinct) {
3905 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
3906 REQUIRED(tag, DwarfTagField, ); \
3907 OPTIONAL(header, MDStringField, ); \
3908 OPTIONAL(operands, MDFieldList, );
3910 #undef VISIT_MD_FIELDS
3913 (Context, tag.Val, header.Val, operands.Val));
3919 bool LLParser::ParseDISubrange(
MDNode *&Result,
bool IsDistinct) {
3920 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
3921 REQUIRED(count, MDSignedField, (-1, -1, INT64_MAX)); \
3922 OPTIONAL(lowerBound, MDSignedField, );
3924 #undef VISIT_MD_FIELDS
3932 bool LLParser::ParseDIEnumerator(
MDNode *&Result,
bool IsDistinct) {
3933 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
3934 REQUIRED(name, MDStringField, ); \
3935 REQUIRED(value, MDSignedField, );
3937 #undef VISIT_MD_FIELDS
3945 bool LLParser::ParseDIBasicType(
MDNode *&Result,
bool IsDistinct) {
3946 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
3947 OPTIONAL(tag, DwarfTagField, (dwarf::DW_TAG_base_type)); \
3948 OPTIONAL(name, MDStringField, ); \
3949 OPTIONAL(size, MDUnsignedField, (0, UINT64_MAX)); \
3950 OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); \
3951 OPTIONAL(encoding, DwarfAttEncodingField, );
3953 #undef VISIT_MD_FIELDS
3956 align.Val, encoding.Val));
3965 bool LLParser::ParseDIDerivedType(
MDNode *&Result,
bool IsDistinct) {
3966 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
3967 REQUIRED(tag, DwarfTagField, ); \
3968 OPTIONAL(name, MDStringField, ); \
3969 OPTIONAL(file, MDField, ); \
3970 OPTIONAL(line, LineField, ); \
3971 OPTIONAL(scope, MDField, ); \
3972 REQUIRED(baseType, MDField, ); \
3973 OPTIONAL(size, MDUnsignedField, (0, UINT64_MAX)); \
3974 OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); \
3975 OPTIONAL(offset, MDUnsignedField, (0, UINT64_MAX)); \
3976 OPTIONAL(flags, DIFlagField, ); \
3977 OPTIONAL(extraData, MDField, ); \
3978 OPTIONAL(dwarfAddressSpace, MDUnsignedField, (UINT32_MAX, UINT32_MAX));
3980 #undef VISIT_MD_FIELDS
3983 if (dwarfAddressSpace.Val != UINT32_MAX)
3984 DWARFAddressSpace = dwarfAddressSpace.Val;
3987 (Context, tag.Val,
name.Val,
file.Val, line.Val,
3988 scope.Val, baseType.Val, size.Val, align.Val,
3989 offset.Val, DWARFAddressSpace, flags.Val,
3994 bool LLParser::ParseDICompositeType(
MDNode *&Result,
bool IsDistinct) {
3995 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
3996 REQUIRED(tag, DwarfTagField, ); \
3997 OPTIONAL(name, MDStringField, ); \
3998 OPTIONAL(file, MDField, ); \
3999 OPTIONAL(line, LineField, ); \
4000 OPTIONAL(scope, MDField, ); \
4001 OPTIONAL(baseType, MDField, ); \
4002 OPTIONAL(size, MDUnsignedField, (0, UINT64_MAX)); \
4003 OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); \
4004 OPTIONAL(offset, MDUnsignedField, (0, UINT64_MAX)); \
4005 OPTIONAL(flags, DIFlagField, ); \
4006 OPTIONAL(elements, MDField, ); \
4007 OPTIONAL(runtimeLang, DwarfLangField, ); \
4008 OPTIONAL(vtableHolder, MDField, ); \
4009 OPTIONAL(templateParams, MDField, ); \
4010 OPTIONAL(identifier, MDStringField, );
4012 #undef VISIT_MD_FIELDS
4017 Context, *identifier.Val, tag.Val,
name.Val,
file.Val, line.Val,
4018 scope.Val, baseType.Val, size.Val, align.Val, offset.Val, flags.Val,
4019 elements.Val, runtimeLang.Val, vtableHolder.Val,
4020 templateParams.Val)) {
4029 (Context, tag.Val,
name.Val,
file.Val, line.Val, scope.Val, baseType.Val,
4030 size.Val, align.Val, offset.Val, flags.Val, elements.Val,
4031 runtimeLang.Val, vtableHolder.Val, templateParams.Val, identifier.Val));
4035 bool LLParser::ParseDISubroutineType(
MDNode *&Result,
bool IsDistinct) {
4036 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
4037 OPTIONAL(flags, DIFlagField, ); \
4038 OPTIONAL(cc, DwarfCCField, ); \
4039 REQUIRED(types, MDField, );
4041 #undef VISIT_MD_FIELDS
4044 (Context, flags.Val, cc.Val, types.Val));
4052 bool LLParser::ParseDIFile(
MDNode *&Result,
bool IsDistinct) {
4053 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
4054 REQUIRED(filename, MDStringField, ); \
4055 REQUIRED(directory, MDStringField, ); \
4056 OPTIONAL(checksumkind, ChecksumKindField, ); \
4057 OPTIONAL(checksum, MDStringField, );
4059 #undef VISIT_MD_FIELDS
4062 checksumkind.Val, checksum.Val));
4072 bool LLParser::ParseDICompileUnit(
MDNode *&Result,
bool IsDistinct) {
4074 return Lex.
Error(
"missing 'distinct', required for !DICompileUnit");
4076 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
4077 REQUIRED(language, DwarfLangField, ); \
4078 REQUIRED(file, MDField, ( false)); \
4079 OPTIONAL(producer, MDStringField, ); \
4080 OPTIONAL(isOptimized, MDBoolField, ); \
4081 OPTIONAL(flags, MDStringField, ); \
4082 OPTIONAL(runtimeVersion, MDUnsignedField, (0, UINT32_MAX)); \
4083 OPTIONAL(splitDebugFilename, MDStringField, ); \
4084 OPTIONAL(emissionKind, EmissionKindField, ); \
4085 OPTIONAL(enums, MDField, ); \
4086 OPTIONAL(retainedTypes, MDField, ); \
4087 OPTIONAL(globals, MDField, ); \
4088 OPTIONAL(imports, MDField, ); \
4089 OPTIONAL(macros, MDField, ); \
4090 OPTIONAL(dwoId, MDUnsignedField, ); \
4091 OPTIONAL(splitDebugInlining, MDBoolField, = true); \
4092 OPTIONAL(debugInfoForProfiling, MDBoolField, = false);
4094 #undef VISIT_MD_FIELDS
4097 Context, language.Val,
file.Val, producer.Val, isOptimized.Val, flags.Val,
4098 runtimeVersion.Val, splitDebugFilename.Val, emissionKind.Val, enums.Val,
4099 retainedTypes.Val,
globals.Val, imports.Val, macros.Val, dwoId.Val,
4100 splitDebugInlining.Val, debugInfoForProfiling.Val);
4112 bool LLParser::ParseDISubprogram(
MDNode *&Result,
bool IsDistinct) {
4114 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
4115 OPTIONAL(scope, MDField, ); \
4116 OPTIONAL(name, MDStringField, ); \
4117 OPTIONAL(linkageName, MDStringField, ); \
4118 OPTIONAL(file, MDField, ); \
4119 OPTIONAL(line, LineField, ); \
4120 OPTIONAL(type, MDField, ); \
4121 OPTIONAL(isLocal, MDBoolField, ); \
4122 OPTIONAL(isDefinition, MDBoolField, (true)); \
4123 OPTIONAL(scopeLine, LineField, ); \
4124 OPTIONAL(containingType, MDField, ); \
4125 OPTIONAL(virtuality, DwarfVirtualityField, ); \
4126 OPTIONAL(virtualIndex, MDUnsignedField, (0, UINT32_MAX)); \
4127 OPTIONAL(thisAdjustment, MDSignedField, (0, INT32_MIN, INT32_MAX)); \
4128 OPTIONAL(flags, DIFlagField, ); \
4129 OPTIONAL(isOptimized, MDBoolField, ); \
4130 OPTIONAL(unit, MDField, ); \
4131 OPTIONAL(templateParams, MDField, ); \
4132 OPTIONAL(declaration, MDField, ); \
4133 OPTIONAL(variables, MDField, ); \
4134 OPTIONAL(thrownTypes, MDField, );
4136 #undef VISIT_MD_FIELDS
4138 if (isDefinition.Val && !IsDistinct)
4141 "missing 'distinct', required for !DISubprogram when 'isDefinition'");
4145 (Context, scope.Val,
name.Val, linkageName.Val,
file.Val, line.Val,
4146 type.Val, isLocal.Val, isDefinition.Val, scopeLine.Val,
4147 containingType.Val, virtuality.Val, virtualIndex.Val, thisAdjustment.Val,
4148 flags.Val, isOptimized.Val, unit.Val, templateParams.Val,
4149 declaration.Val, variables.Val, thrownTypes.Val));
4155 bool LLParser::ParseDILexicalBlock(
MDNode *&Result,
bool IsDistinct) {
4156 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
4157 REQUIRED(scope, MDField, ( false)); \
4158 OPTIONAL(file, MDField, ); \
4159 OPTIONAL(line, LineField, ); \
4160 OPTIONAL(column, ColumnField, );
4162 #undef VISIT_MD_FIELDS
4171 bool LLParser::ParseDILexicalBlockFile(
MDNode *&Result,
bool IsDistinct) {
4172 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
4173 REQUIRED(scope, MDField, ( false)); \
4174 OPTIONAL(file, MDField, ); \
4175 REQUIRED(discriminator, MDUnsignedField, (0, UINT32_MAX));
4177 #undef VISIT_MD_FIELDS
4180 (Context, scope.Val,
file.Val, discriminator.Val));
4186 bool LLParser::ParseDINamespace(
MDNode *&Result,
bool IsDistinct) {
4187 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
4188 REQUIRED(scope, MDField, ); \
4189 OPTIONAL(name, MDStringField, ); \
4190 OPTIONAL(exportSymbols, MDBoolField, );
4192 #undef VISIT_MD_FIELDS
4195 (Context, scope.Val,
name.Val, exportSymbols.Val));
4201 bool LLParser::ParseDIMacro(
MDNode *&Result,
bool IsDistinct) {
4202 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
4203 REQUIRED(type, DwarfMacinfoTypeField, ); \
4204 OPTIONAL(line, LineField, ); \
4205 REQUIRED(name, MDStringField, ); \
4206 OPTIONAL(value, MDStringField, );
4208 #undef VISIT_MD_FIELDS
4211 (Context, type.Val, line.Val,
name.Val, value.Val));
4217 bool LLParser::ParseDIMacroFile(
MDNode *&Result,
bool IsDistinct) {
4218 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
4219 OPTIONAL(type, DwarfMacinfoTypeField, (dwarf::DW_MACINFO_start_file)); \
4220 OPTIONAL(line, LineField, ); \
4221 REQUIRED(file, MDField, ); \
4222 OPTIONAL(nodes, MDField, );
4224 #undef VISIT_MD_FIELDS
4227 (Context, type.Val, line.Val,
file.Val,
nodes.Val));
4234 bool LLParser::ParseDIModule(
MDNode *&Result,
bool IsDistinct) {
4235 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
4236 REQUIRED(scope, MDField, ); \
4237 REQUIRED(name, MDStringField, ); \
4238 OPTIONAL(configMacros, MDStringField, ); \
4239 OPTIONAL(includePath, MDStringField, ); \
4240 OPTIONAL(isysroot, MDStringField, );
4242 #undef VISIT_MD_FIELDS
4245 configMacros.Val, includePath.Val, isysroot.Val));
4251 bool LLParser::ParseDITemplateTypeParameter(
MDNode *&Result,
bool IsDistinct) {
4252 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
4253 OPTIONAL(name, MDStringField, ); \
4254 REQUIRED(type, MDField, );
4256 #undef VISIT_MD_FIELDS
4266 bool LLParser::ParseDITemplateValueParameter(
MDNode *&Result,
bool IsDistinct) {
4267 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
4268 OPTIONAL(tag, DwarfTagField, (dwarf::DW_TAG_template_value_parameter)); \
4269 OPTIONAL(name, MDStringField, ); \
4270 OPTIONAL(type, MDField, ); \
4271 REQUIRED(value, MDField, );
4273 #undef VISIT_MD_FIELDS
4276 (Context, tag.Val,
name.Val, type.Val, value.Val));
4284 bool LLParser::ParseDIGlobalVariable(
MDNode *&Result,
bool IsDistinct) {
4285 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
4286 REQUIRED(name, MDStringField, ( false)); \
4287 OPTIONAL(scope, MDField, ); \
4288 OPTIONAL(linkageName, MDStringField, ); \
4289 OPTIONAL(file, MDField, ); \
4290 OPTIONAL(line, LineField, ); \
4291 OPTIONAL(type, MDField, ); \
4292 OPTIONAL(isLocal, MDBoolField, ); \
4293 OPTIONAL(isDefinition, MDBoolField, (true)); \
4294 OPTIONAL(declaration, MDField, ); \
4295 OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX));
4297 #undef VISIT_MD_FIELDS
4300 (Context, scope.Val,
name.Val, linkageName.Val,
4301 file.Val, line.Val, type.Val, isLocal.Val,
4302 isDefinition.Val, declaration.Val, align.Val));
4313 bool LLParser::ParseDILocalVariable(
MDNode *&Result,
bool IsDistinct) {
4314 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
4315 REQUIRED(scope, MDField, ( false)); \
4316 OPTIONAL(name, MDStringField, ); \
4317 OPTIONAL(arg, MDUnsignedField, (0, UINT16_MAX)); \
4318 OPTIONAL(file, MDField, ); \
4319 OPTIONAL(line, LineField, ); \
4320 OPTIONAL(type, MDField, ); \
4321 OPTIONAL(flags, DIFlagField, ); \
4322 OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX));
4324 #undef VISIT_MD_FIELDS
4327 (Context, scope.Val,
name.Val,
file.Val, line.Val,
4328 type.Val, arg.Val, flags.Val, align.Val));
4334 bool LLParser::ParseDIExpression(
MDNode *&Result,
bool IsDistinct) {
4350 return TokError(
Twine(
"invalid DWARF op '") + Lex.
getStrVal() +
"'");
4354 return TokError(
"expected unsigned integer");
4357 if (U.ugt(UINT64_MAX))
4358 return TokError(
"element too large, limit is " +
Twine(UINT64_MAX));
4372 bool LLParser::ParseDIGlobalVariableExpression(
MDNode *&Result,
4374 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
4375 REQUIRED(var, MDField, ); \
4376 OPTIONAL(expr, MDField, );
4378 #undef VISIT_MD_FIELDS
4388 bool LLParser::ParseDIObjCProperty(
MDNode *&Result,
bool IsDistinct) {
4389 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
4390 OPTIONAL(name, MDStringField, ); \
4391 OPTIONAL(file, MDField, ); \
4392 OPTIONAL(line, LineField, ); \
4393 OPTIONAL(setter, MDStringField, ); \
4394 OPTIONAL(getter, MDStringField, ); \
4395 OPTIONAL(attributes, MDUnsignedField, (0, UINT32_MAX)); \
4396 OPTIONAL(type, MDField, );
4398 #undef VISIT_MD_FIELDS
4401 (Context,
name.Val,
file.Val, line.Val, setter.Val,
4409 bool LLParser::ParseDIImportedEntity(
MDNode *&Result,
bool IsDistinct) {
4410 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
4411 REQUIRED(tag, DwarfTagField, ); \
4412 REQUIRED(scope, MDField, ); \
4413 OPTIONAL(entity, MDField, ); \
4414 OPTIONAL(file, MDField, ); \
4415 OPTIONAL(line, LineField, ); \
4416 OPTIONAL(name, MDStringField, );
4418 #undef VISIT_MD_FIELDS
4422 (Context, tag.Val, scope.Val, entity.Val,
file.Val, line.Val,
name.Val));
4426 #undef PARSE_MD_FIELD
4428 #undef REQUIRE_FIELD
4429 #undef DECLARE_FIELD
4438 bool LLParser::ParseMetadataAsValue(
Value *&V, PerFunctionState &PFS) {
4441 if (ParseMetadata(MD, &PFS))
4452 bool LLParser::ParseValueAsMetadata(
Metadata *&MD,
const Twine &TypeMsg,
4453 PerFunctionState *PFS) {
4456 if (ParseType(Ty, TypeMsg, Loc))
4459 return Error(Loc,
"invalid metadata-value-metadata roundtrip");
4462 if (ParseValue(Ty, V, PFS))
4477 bool LLParser::ParseMetadata(
Metadata *&MD, PerFunctionState *PFS) {
4480 if (ParseSpecializedMDNode(N))
4489 return ParseValueAsMetadata(MD,
"expected metadata operand", PFS);
4499 if (ParseMDString(S))
4509 if (ParseMDNodeTail(N))
4519 bool LLParser::ConvertValIDToValue(
Type *Ty,
ValID &ID,
Value *&V,
4520 PerFunctionState *PFS) {
4522 return Error(ID.
Loc,
"functions are not values, refer to them as pointers");
4526 if (!PFS)
return Error(ID.
Loc,
"invalid use of function-local name");
4528 return V ==
nullptr;
4530 if (!PFS)
return Error(ID.
Loc,
"invalid use of function-local name");
4532 return V ==
nullptr;
4535 return Error(ID.
Loc,
"invalid type for inline asm constraint string");
4542 V = GetGlobalVal(ID.
StrVal, Ty, ID.
Loc);
4543 return V ==
nullptr;
4546 return V ==
nullptr;
4549 return Error(ID.
Loc,
"integer constant must have integer type");
4556 return Error(ID.
Loc,
"floating point constant invalid for type");
4572 return Error(ID.
Loc,
"floating point constant does not have type '" +
4578 return Error(ID.
Loc,
"null must be a pointer type");
4584 return Error(ID.
Loc,
"invalid type for undef constant");
4588 if (!Ty->
isArrayTy() || cast<ArrayType>(Ty)->getNumElements() != 0)
4589 return Error(ID.
Loc,
"invalid empty array initializer");
4595 return Error(ID.
Loc,
"invalid type for null constant");
4600 return Error(ID.
Loc,
"invalid type for none constant");
4605 return Error(ID.
Loc,
"constant expression type mismatch");
4614 "initializer with struct type has wrong # elements");
4616 return Error(ID.
Loc,
"packed'ness of initializer and type don't match");
4619 for (
unsigned i = 0, e = ID.
UIntVal; i != e; ++i)
4622 " of struct initializer doesn't match struct element type");
4627 return Error(ID.
Loc,
"constant expression type mismatch");
4633 bool LLParser::parseConstantValue(
Type *Ty,
Constant *&C) {
4637 if (ParseValID(ID,
nullptr))
4647 if (ConvertValIDToValue(Ty, ID, V,
nullptr))
4649 assert(isa<Constant>(V) &&
"Expected a constant value");
4650 C = cast<Constant>(V);
4657 return Error(Loc,
"expected a constant value");
4661 bool LLParser::ParseValue(
Type *Ty,
Value *&V, PerFunctionState *PFS) {
4664 return ParseValID(ID, PFS) || ConvertValIDToValue(Ty, ID, V, PFS);
4667 bool LLParser::ParseTypeAndValue(
Value *&V, PerFunctionState *PFS) {
4669 return ParseType(Ty) ||
4670 ParseValue(Ty, V, PFS);
4673 bool LLParser::ParseTypeAndBasicBlock(
BasicBlock *&BB, LocTy &Loc,
4674 PerFunctionState &PFS) {
4677 if (ParseTypeAndValue(V, PFS))
return true;
4678 if (!isa<BasicBlock>(V))
4679 return Error(Loc,
"expected a basic block");
4680 BB = cast<BasicBlock>(V);
4688 bool LLParser::ParseFunctionHeader(
Function *&Fn,
bool isDefine) {
4694 unsigned DLLStorageClass;
4698 Type *RetType =
nullptr;
4700 if (ParseOptionalLinkage(Linkage, HasLinkage, Visibility, DLLStorageClass) ||
4701 ParseOptionalCallingConv(CC) || ParseOptionalReturnAttrs(RetAttrs) ||
4702 ParseType(RetType, RetTypeLoc,
true ))
4711 return Error(LinkageLoc,
"invalid linkage for function definition");
4721 return Error(LinkageLoc,
"invalid linkage for function declaration");
4725 return Error(LinkageLoc,
"invalid function linkage type");
4729 return Error(LinkageLoc,
4730 "symbol with local linkage must have default visibility");
4733 return Error(RetTypeLoc,
"invalid function return type");
4737 std::string FunctionName;
4743 if (NameID != NumberedVals.size())
4744 return TokError(
"function expected to be numbered '%" +
4745 Twine(NumberedVals.size()) +
"'");
4747 return TokError(
"expected function name");
4753 return TokError(
"expected '(' in function argument list");
4758 std::vector<unsigned> FwdRefAttrGrps;
4764 LocTy UnnamedAddrLoc;
4770 if (ParseArgumentList(ArgList, isVarArg) ||
4771 ParseOptionalUnnamedAddr(UnnamedAddr) ||
4772 ParseFnAttributeValuePairs(FuncAttrs, FwdRefAttrGrps,
false,
4775 ParseStringConstant(Section)) ||
4776 parseOptionalComdat(FunctionName, C) ||
4777 ParseOptionalAlignment(Alignment) ||
4779 ParseStringConstant(GC)) ||
4781 ParseGlobalTypeAndValue(Prefix)) ||
4783 ParseGlobalTypeAndValue(Prologue)) ||
4785 ParseGlobalTypeAndValue(PersonalityFn)))
4788 if (FuncAttrs.
contains(Attribute::Builtin))
4789 return Error(BuiltinLoc,
"'builtin' attribute not valid on function");
4799 std::vector<Type*> ParamTypeList;
4802 for (
unsigned i = 0, e = ArgList.
size(); i != e; ++i) {
4803 ParamTypeList.push_back(ArgList[i].Ty);
4812 return Error(RetTypeLoc,
"functions with 'sret' argument must return void");
4819 if (!FunctionName.empty()) {
4822 auto FRVI = ForwardRefVals.find(FunctionName);
4823 if (FRVI != ForwardRefVals.end()) {
4826 return Error(FRVI->second.second,
"invalid forward reference to "
4827 "function as global value!");
4829 return Error(FRVI->second.second,
"invalid forward reference to "
4830 "function '" + FunctionName +
"' with wrong type!");
4832 ForwardRefVals.erase(FRVI);
4835 return Error(NameLoc,
"invalid redefinition of function '" +
4836 FunctionName +
"'");
4838 return Error(NameLoc,
"redefinition of function '@" + FunctionName +
"'");
4844 auto I = ForwardRefValIDs.find(NumberedVals.size());
4845 if (I != ForwardRefValIDs.end()) {
4846 Fn = cast<Function>(I->second.first);
4848 return Error(NameLoc,
"type of definition and forward reference of '@" +
4849 Twine(NumberedVals.size()) +
"' disagree");
4850 ForwardRefValIDs.erase(I);
4859 if (FunctionName.empty())
4860 NumberedVals.push_back(Fn);
4872 if (!GC.empty()) Fn->
setGC(GC);
4875 ForwardRefAttrGroups[Fn] = FwdRefAttrGrps;
4879 for (
unsigned i = 0, e = ArgList.
size(); i != e; ++i, ++ArgIt) {
4881 if (ArgList[i].Name.
empty())
continue;
4884 ArgIt->
setName(ArgList[i].Name);
4886 if (ArgIt->
getName() != ArgList[i].Name)
4887 return Error(ArgList[i].Loc,
"redefinition of argument '%" +
4888 ArgList[i].Name +
"'");
4896 if (FunctionName.empty()) {
4898 ID.
UIntVal = NumberedVals.size() - 1;
4901 ID.
StrVal = FunctionName;
4903 auto Blocks = ForwardRefBlockAddresses.find(ID);
4904 if (Blocks != ForwardRefBlockAddresses.end())
4905 return Error(Blocks->first.Loc,
4906 "cannot take blockaddress inside a declaration");
4910 bool LLParser::PerFunctionState::resolveForwardRefBlockAddresses() {
4920 auto Blocks =
P.ForwardRefBlockAddresses.find(ID);
4921 if (Blocks ==
P.ForwardRefBlockAddresses.end())
4924 for (
const auto &I : Blocks->second) {
4925 const ValID &BBID = I.first;
4929 "Expected local id or name");
4936 return P.Error(BBID.
Loc,
"referenced value is not a basic block");
4942 P.ForwardRefBlockAddresses.erase(Blocks);
4948 bool LLParser::ParseFunctionBody(
Function &Fn) {
4950 return TokError(
"expected '{' in function body");
4954 if (!Fn.
hasName()) FunctionNumber = NumberedVals.size()-1;
4956 PerFunctionState PFS(*
this, Fn, FunctionNumber);
4960 if (PFS.resolveForwardRefBlockAddresses())
4966 return TokError(
"function body requires at least one basic block");
4970 if (ParseBasicBlock(PFS))
return true;
4973 if (ParseUseListOrder(&PFS))
4980 return PFS.FinishFunction();
4985 bool LLParser::ParseBasicBlock(PerFunctionState &PFS) {
4994 BasicBlock *BB = PFS.DefineBB(Name, NameLoc);
4996 return Error(NameLoc,
4997 "unable to create block named '" + Name +
"'");
4999 std::string NameStr;
5013 if (ParseToken(
lltok::equal,
"expected '=' after instruction id"))
5018 if (ParseToken(
lltok::equal,
"expected '=' after instruction name"))
5022 switch (ParseInstruction(Inst, BB, PFS)) {
5024 case InstError:
return true;
5031 if (ParseInstructionMetadata(*Inst))
5034 case InstExtraComma:
5039 if (ParseInstructionMetadata(*Inst))
5045 if (PFS.SetInstName(NameID, NameStr, NameLoc, Inst))
return true;
5046 }
while (!isa<TerminatorInst>(Inst));
5058 PerFunctionState &PFS) {
5061 return TokError(
"found end of file when expecting more instructions");
5067 default:
return Error(Loc,
"expected instruction opcode");
5090 if (ParseArithmetic(Inst, PFS, KeywordVal, 1))
return true;
5092 if (NUW) cast<BinaryOperator>(Inst)->setHasNoUnsignedWrap(
true);
5093 if (NSW) cast<BinaryOperator>(Inst)->setHasNoSignedWrap(
true);
5102 int Res = ParseArithmetic(Inst, PFS, KeywordVal, 2);
5116 if (ParseArithmetic(Inst, PFS, KeywordVal, 1))
return true;
5117 if (Exact) cast<BinaryOperator>(Inst)->setIsExact(
true);
5122 case lltok::kw_srem:
return ParseArithmetic(Inst, PFS, KeywordVal, 1);
5125 case lltok::kw_xor:
return ParseLogical(Inst, PFS, KeywordVal);
5129 int Res = ParseCompare(Inst, PFS, KeywordVal);
5178 bool LLParser::ParseCmpPredicate(
unsigned &
P,
unsigned Opc) {
5179 if (Opc == Instruction::FCmp) {
5181 default:
return TokError(
"expected fcmp predicate (e.g. 'oeq')");
5201 default:
return TokError(
"expected icmp predicate (e.g. 'eq')");
5226 PerFunctionState &PFS) {
5229 if (ParseType(Ty,
true ))
return true;
5231 Type *ResType = PFS.getFunction().getReturnType();
5235 return Error(TypeLoc,
"value doesn't match function result type '" +
5243 if (ParseValue(Ty, RV, PFS))
return true;
5246 return Error(TypeLoc,
"value doesn't match function result type '" +
5256 bool LLParser::ParseBr(
Instruction *&Inst, PerFunctionState &PFS) {
5260 if (ParseTypeAndValue(Op0, Loc, PFS))
return true;
5262 if (
BasicBlock *BB = dyn_cast<BasicBlock>(Op0)) {
5268 return Error(Loc,
"branch condition must have 'i1' type");
5270 if (ParseToken(
lltok::comma,
"expected ',' after branch condition") ||
5271 ParseTypeAndBasicBlock(Op1, Loc, PFS) ||
5272 ParseToken(
lltok::comma,
"expected ',' after true destination") ||
5273 ParseTypeAndBasicBlock(Op2, Loc2, PFS))
5285 bool LLParser::ParseSwitch(
Instruction *&Inst, PerFunctionState &PFS) {
5286 LocTy CondLoc, BBLoc;
5289 if (ParseTypeAndValue(Cond, CondLoc, PFS) ||
5290 ParseToken(
lltok::comma,
"expected ',' after switch condition") ||
5291 ParseTypeAndBasicBlock(DefaultBB, BBLoc, PFS) ||
5296 return Error(CondLoc,
"switch condition must have integer type");
5305 if (ParseTypeAndValue(Constant, CondLoc, PFS) ||
5306 ParseToken(
lltok::comma,
"expected ',' after case value") ||
5307 ParseTypeAndBasicBlock(DestBB, PFS))
5310 if (!SeenCases.
insert(Constant).second)
5311 return Error(CondLoc,
"duplicate case value in switch");
5312 if (!isa<ConstantInt>(Constant))
5313 return Error(CondLoc,
"case value is not a constant integer");
5315 Table.
push_back(std::make_pair(cast<ConstantInt>(Constant), DestBB));
5321 for (
unsigned i = 0, e = Table.
size(); i != e; ++i)
5322 SI->
addCase(Table[i].first, Table[i].second);
5330 bool LLParser::ParseIndirectBr(
Instruction *&Inst, PerFunctionState &PFS) {
5333 if (ParseTypeAndValue(Address, AddrLoc, PFS) ||
5334 ParseToken(
lltok::comma,
"expected ',' after indirectbr address") ||
5339 return Error(AddrLoc,
"indirectbr address must have pointer type");
5346 if (ParseTypeAndBasicBlock(DestBB, PFS))
5351 if (ParseTypeAndBasicBlock(DestBB, PFS))
5357 if (ParseToken(lltok::rsquare,
"expected ']' at end of block list"))
5361 for (
unsigned i = 0, e = DestList.
size(); i != e; ++i)
5370 bool LLParser::ParseInvoke(
Instruction *&Inst, PerFunctionState &PFS) {
5373 std::vector<unsigned> FwdRefAttrGrps;
5376 Type *RetType =
nullptr;
5383 if (ParseOptionalCallingConv(CC) || ParseOptionalReturnAttrs(RetAttrs) ||
5384 ParseType(RetType, RetTypeLoc,
true ) ||
5385 ParseValID(CalleeID) || ParseParameterList(ArgList, PFS) ||
5386 ParseFnAttributeValuePairs(FnAttrs, FwdRefAttrGrps,
false,
5388 ParseOptionalOperandBundles(BundleList, PFS) ||
5390 ParseTypeAndBasicBlock(NormalBB, PFS) ||
5392 ParseTypeAndBasicBlock(UnwindBB, PFS))
5401 std::vector<Type*> ParamTypes;
5402 for (
unsigned i = 0, e = ArgList.
size(); i != e; ++i)
5403 ParamTypes.push_back(ArgList[i].V->getType());
5406 return Error(RetTypeLoc,
"Invalid result type for LLVM function");
5426 for (
unsigned i = 0, e = ArgList.
size(); i != e; ++i) {
5427 Type *ExpectedTy =
nullptr;
5431 return Error(ArgList[i].Loc,
"too many arguments specified");
5434 if (ExpectedTy && ExpectedTy != ArgList[i].V->
getType())
5435 return Error(ArgList[i].Loc,
"argument is not of expected type '" +
5442 return Error(CallLoc,
"not enough parameters specified for call");
5445 return Error(CallLoc,
"invoke instructions may not have an alignment");
5456 ForwardRefAttrGroups[II] = FwdRefAttrGrps;
5463 bool LLParser::ParseResume(
Instruction *&Inst, PerFunctionState &PFS) {
5465 if (ParseTypeAndValue(Exn, ExnLoc, PFS))
5474 PerFunctionState &PFS) {
5475 if (ParseToken(
lltok::lsquare,
"expected '[' in catchpad/cleanuppad"))
5480 if (!Args.
empty() &&
5481 ParseToken(
lltok::comma,
"expected ',' in argument list"))
5486 Type *ArgTy =
nullptr;
5487 if (ParseType(ArgTy, ArgLoc))
5492 if (ParseMetadataAsValue(V, PFS))
5495 if (ParseValue(ArgTy, V, PFS))
5507 bool LLParser::ParseCleanupRet(
Instruction *&Inst, PerFunctionState &PFS) {
5508 Value *CleanupPad =
nullptr;
5510 if (ParseToken(
lltok::kw_from,
"expected 'from' after cleanupret"))
5525 if (ParseTypeAndBasicBlock(UnwindBB, PFS)) {
5536 bool LLParser::ParseCatchRet(
Instruction *&Inst, PerFunctionState &PFS) {
5537 Value *CatchPad =
nullptr;
5539 if (ParseToken(
lltok::kw_from,
"expected 'from' after catchret"))
5546 if (ParseToken(
lltok::kw_to,
"expected 'to' in catchret") ||
5547 ParseTypeAndBasicBlock(BB, PFS))
5556 bool LLParser::ParseCatchSwitch(
Instruction *&Inst, PerFunctionState &PFS) {
5565 return TokError(
"expected scope value for catchswitch");
5570 if (ParseToken(
lltok::lsquare,
"expected '[' with catchswitch labels"))
5576 if (ParseTypeAndBasicBlock(DestBB, PFS))
5581 if (ParseToken(lltok::rsquare,
"expected ']' after catchswitch labels"))
5585 "expected 'unwind' after catchswitch scope"))
5593 if (ParseTypeAndBasicBlock(UnwindBB, PFS))
5607 bool LLParser::ParseCatchPad(
Instruction *&Inst, PerFunctionState &PFS) {
5608 Value *CatchSwitch =
nullptr;
5614 return TokError(
"expected scope value for catchpad");
5620 if (ParseExceptionArgs(Args, PFS))
5629 bool LLParser::ParseCleanupPad(
Instruction *&Inst, PerFunctionState &PFS) {
5630 Value *ParentPad =
nullptr;
5637 return TokError(
"expected scope value for cleanuppad");
5643 if (ParseExceptionArgs(Args, PFS))
5659 bool LLParser::ParseArithmetic(
Instruction *&Inst, PerFunctionState &PFS,
5662 if (ParseTypeAndValue(LHS, Loc, PFS) ||
5663 ParseToken(
lltok::comma,
"expected ',' in arithmetic operation") ||
5664 ParseValue(LHS->
getType(), RHS, PFS))
5668 switch (OperandType) {
5679 return Error(Loc,
"invalid operand type for instruction");
5687 bool LLParser::ParseLogical(
Instruction *&Inst, PerFunctionState &PFS,
5690 if (ParseTypeAndValue(LHS, Loc, PFS) ||
5691 ParseToken(
lltok::comma,
"expected ',' in logical operation") ||
5692 ParseValue(LHS->
getType(), RHS, PFS))
5696 return Error(Loc,
"instruction requires integer or integer vector operands");
5705 bool LLParser::ParseCompare(
Instruction *&Inst, PerFunctionState &PFS,
5711 if (ParseCmpPredicate(Pred, Opc) ||
5712 ParseTypeAndValue(LHS, Loc, PFS) ||
5713 ParseToken(
lltok::comma,
"expected ',' after compare value") ||
5714 ParseValue(LHS->
getType(), RHS, PFS))
5717 if (Opc == Instruction::FCmp) {
5719 return Error(Loc,
"fcmp requires floating point operands");
5722 assert(Opc == Instruction::ICmp &&
"Unknown opcode for CmpInst!");
5725 return Error(Loc,
"icmp requires integer operands");
5738 bool LLParser::ParseCast(
Instruction *&Inst, PerFunctionState &PFS,
5742 Type *DestTy =
nullptr;
5743 if (ParseTypeAndValue(Op, Loc, PFS) ||
5744 ParseToken(
lltok::kw_to,
"expected 'to' after cast value") ||
5750 return Error(Loc,
"invalid cast opcode for cast from '" +
5760 bool LLParser::ParseSelect(
Instruction *&Inst, PerFunctionState &PFS) {
5762 Value *Op0, *Op1, *Op2;
5763 if (ParseTypeAndValue(Op0, Loc, PFS) ||
5764 ParseToken(
lltok::comma,
"expected ',' after select condition") ||
5765 ParseTypeAndValue(Op1, PFS) ||
5766 ParseToken(
lltok::comma,
"expected ',' after select value") ||
5767 ParseTypeAndValue(Op2, PFS))
5771 return Error(Loc, Reason);
5779 bool LLParser::ParseVA_Arg(
Instruction *&Inst, PerFunctionState &PFS) {
5781 Type *EltTy =
nullptr;
5783 if (ParseTypeAndValue(Op, PFS) ||
5784 ParseToken(
lltok::comma,
"expected ',' after vaarg operand") ||
5785 ParseType(EltTy, TypeLoc))
5789 return Error(TypeLoc,
"va_arg requires operand with first class type");
5797 bool LLParser::ParseExtractElement(
Instruction *&Inst, PerFunctionState &PFS) {
5800 if (ParseTypeAndValue(Op0, Loc, PFS) ||
5801 ParseToken(
lltok::comma,
"expected ',' after extract value") ||
5802 ParseTypeAndValue(Op1, PFS))
5806 return Error(Loc,
"invalid extractelement operands");
5814 bool LLParser::ParseInsertElement(
Instruction *&Inst, PerFunctionState &PFS) {
5816 Value *Op0, *Op1, *Op2;
5817 if (ParseTypeAndValue(Op0, Loc, PFS) ||
5818 ParseToken(
lltok::comma,
"expected ',' after insertelement value") ||
5819 ParseTypeAndValue(Op1, PFS) ||
5820 ParseToken(
lltok::comma,
"expected ',' after insertelement value") ||
5821 ParseTypeAndValue(Op2, PFS))
5825 return Error(Loc,
"invalid insertelement operands");
5833 bool LLParser::ParseShuffleVector(
Instruction *&Inst, PerFunctionState &PFS) {
5835 Value *Op0, *Op1, *Op2;
5836 if (ParseTypeAndValue(Op0, Loc, PFS) ||
5837 ParseToken(
lltok::comma,
"expected ',' after shuffle mask") ||
5838 ParseTypeAndValue(Op1, PFS) ||
5839 ParseToken(
lltok::comma,
"expected ',' after shuffle value") ||
5840 ParseTypeAndValue(Op2, PFS))
5844 return Error(Loc,
"invalid shufflevector operands");
5852 int LLParser::ParsePHI(
Instruction *&Inst, PerFunctionState &PFS) {
5856 if (ParseType(Ty, TypeLoc) ||
5858 ParseValue(Ty, Op0, PFS) ||
5859 ParseToken(
lltok::comma,
"expected ',' after insertelement value") ||
5861 ParseToken(lltok::rsquare,
"expected ']' in phi value list"))
5864 bool AteExtraComma =
false;
5868 PHIVals.
push_back(std::make_pair(Op0, cast<BasicBlock>(Op1)));
5874 AteExtraComma =
true;
5878 if (ParseToken(
lltok::lsquare,
"expected '[' in phi value list") ||
5879 ParseValue(Ty, Op0, PFS) ||
5880 ParseToken(
lltok::comma,
"expected ',' after insertelement value") ||
5882 ParseToken(lltok::rsquare,
"expected ']' in phi value list"))
5887 return Error(TypeLoc,
"phi node must have first class type");
5890 for (
unsigned i = 0, e = PHIVals.
size(); i != e; ++i)
5891 PN->
addIncoming(PHIVals[i].first, PHIVals[i].second);
5893 return AteExtraComma ? InstExtraComma : InstNormal;
5902 bool LLParser::ParseLandingPad(
Instruction *&Inst, PerFunctionState &PFS) {
5905 if (ParseType(Ty, TyLoc))
5918 return TokError(
"expected 'catch' or 'filter' clause type");
5922 if (ParseTypeAndValue(V, VLoc, PFS))
5928 if (isa<ArrayType>(V->
getType()))
5929 Error(VLoc,
"'catch' clause has an invalid type");
5931 if (!isa<ArrayType>(V->
getType()))
5932 Error(VLoc,
"'filter' clause has an invalid type");
5935 Constant *CV =
dyn_cast<Constant>(V);
5937 return Error(VLoc,
"clause argument must be a constant");
5941 Inst = LP.release();
5954 bool LLParser::ParseCall(
Instruction *&Inst, PerFunctionState &PFS,
5957 std::vector<unsigned> FwdRefAttrGrps;
5960 Type *RetType =
nullptr;
5969 "expected 'tail call', 'musttail call', or 'notail call'"))
5974 if (ParseOptionalCallingConv(CC) || ParseOptionalReturnAttrs(RetAttrs) ||
5975 ParseType(RetType, RetTypeLoc,
true ) ||
5976 ParseValID(CalleeID) ||
5978 PFS.getFunction().isVarArg()) ||
5979 ParseFnAttributeValuePairs(FnAttrs, FwdRefAttrGrps,
false, BuiltinLoc) ||
5980 ParseOptionalOperandBundles(BundleList, PFS))
5984 return Error(CallLoc,
"fast-math-flags specified for call without "
5985 "floating-point scalar or vector return type");
5993 std::vector<Type*> ParamTypes;
5994 for (
unsigned i = 0, e = ArgList.
size(); i != e; ++i)
5995 ParamTypes.push_back(ArgList[i].V->getType());
5998 return Error(RetTypeLoc,
"Invalid result type for LLVM function");
6019 for (
unsigned i = 0, e = ArgList.
size(); i != e; ++i) {
6020 Type *ExpectedTy =
nullptr;
6024 return Error(ArgList[i].Loc,
"too many arguments specified");
6027 if (ExpectedTy && ExpectedTy != ArgList[i].V->
getType())
6028 return Error(ArgList[i].Loc,
"argument is not of expected type '" +
6035 return Error(CallLoc,
"not enough parameters specified for call");
6038 return Error(CallLoc,
"call instructions may not have an alignment");
6051 ForwardRefAttrGroups[CI] = FwdRefAttrGrps;
6063 int LLParser::ParseAlloc(
Instruction *&Inst, PerFunctionState &PFS) {
6064 Value *Size =
nullptr;
6065 LocTy SizeLoc, TyLoc, ASLoc;
6066 unsigned Alignment = 0;
6067 unsigned AddrSpace = 0;
6073 if (ParseType(Ty, TyLoc))
return true;
6076 return Error(TyLoc,
"invalid type for alloca");
6078 bool AteExtraComma =
false;
6081 if (ParseOptionalAlignment(Alignment))
6083 if (ParseOptionalCommaAddrSpace(AddrSpace, ASLoc, AteExtraComma))
6087 if (ParseOptionalAddrSpace(AddrSpace))
6090 AteExtraComma =
true;
6092 if (ParseTypeAndValue(Size, SizeLoc, PFS) ||
6093 ParseOptionalCommaAlign(Alignment, AteExtraComma) ||
6095 ParseOptionalCommaAddrSpace(AddrSpace, ASLoc, AteExtraComma)))
6101 return Error(SizeLoc,
"element count must have integer type");
6105 if (AS != AddrSpace) {
6107 return Error(ASLoc,
"address space must match datalayout");
6114 return AteExtraComma ? InstExtraComma : InstNormal;
6121 int LLParser::ParseLoad(
Instruction *&Inst, PerFunctionState &PFS) {
6123 unsigned Alignment = 0;
6124 bool AteExtraComma =
false;
6125 bool isAtomic =
false;
6142 if (ParseType(Ty) ||
6143 ParseToken(
lltok::comma,
"expected comma after load's type") ||
6144 ParseTypeAndValue(Val, Loc, PFS) ||
6145 ParseScopeAndOrdering(isAtomic, SSID, Ordering) ||
6146 ParseOptionalCommaAlign(Alignment, AteExtraComma))
6150 return Error(Loc,
"load operand must be a pointer to a first class type");
6151 if (isAtomic && !Alignment)
6152 return Error(Loc,
"atomic load must have explicit non-zero alignment");
6155 return Error(Loc,
"atomic load cannot use Release ordering");
6157 if (Ty != cast<PointerType>(Val->
getType())->getElementType())
6158 return Error(ExplicitTypeLoc,
6159 "explicit pointee type doesn't match operand's pointee type");
6161 Inst =
new LoadInst(Ty, Val,
"", isVolatile, Alignment, Ordering, SSID);
6162 return AteExtraComma ? InstExtraComma : InstNormal;
6170 int LLParser::ParseStore(
Instruction *&Inst, PerFunctionState &PFS) {
6172 unsigned Alignment = 0;
6173 bool AteExtraComma =
false;
6174 bool isAtomic =
false;
6183 bool isVolatile =
false;
6189 if (ParseTypeAndValue(Val, Loc, PFS) ||
6190 ParseToken(
lltok::comma,
"expected ',' after store operand") ||
6191 ParseTypeAndValue(Ptr, PtrLoc, PFS) ||
6192 ParseScopeAndOrdering(isAtomic, SSID, Ordering) ||
6193 ParseOptionalCommaAlign(Alignment, AteExtraComma))
6197 return Error(PtrLoc,
"store operand must be a pointer");
6199 return Error(Loc,
"store operand must be a first class value");
6200 if (cast<PointerType>(Ptr->
getType())->getElementType() != Val->
getType())
6201 return Error(Loc,
"stored value and pointer type do not match");
6202 if (isAtomic && !Alignment)
6203 return Error(Loc,
"atomic store must have explicit non-zero alignment");
6206 return Error(Loc,
"atomic store cannot use Acquire ordering");
6208 Inst =
new StoreInst(Val, Ptr, isVolatile, Alignment, Ordering, SSID);
6209 return AteExtraComma ? InstExtraComma : InstNormal;
6215 int LLParser::ParseCmpXchg(
Instruction *&Inst, PerFunctionState &PFS) {
6217 bool AteExtraComma =
false;
6221 bool isVolatile =
false;
6230 if (ParseTypeAndValue(Ptr, PtrLoc, PFS) ||
6231 ParseToken(
lltok::comma,
"expected ',' after cmpxchg address") ||
6232 ParseTypeAndValue(Cmp, CmpLoc, PFS) ||
6233 ParseToken(
lltok::comma,
"expected ',' after cmpxchg cmp operand") ||
6234 ParseTypeAndValue(New, NewLoc, PFS) ||
6235 ParseScopeAndOrdering(
true , SSID, SuccessOrdering) ||
6236 ParseOrdering(FailureOrdering))
6241 return TokError(
"cmpxchg cannot be unordered");
6243 return TokError(
"cmpxchg failure argument shall be no stronger than the "
6244 "success argument");
6248 "cmpxchg failure ordering cannot include release semantics");
6250 return Error(PtrLoc,
"cmpxchg operand must be a pointer");
6251 if (cast<PointerType>(Ptr->
getType())->getElementType() != Cmp->
getType())
6252 return Error(CmpLoc,
"compare value and pointer type do not match");
6253 if (cast<PointerType>(Ptr->
getType())->getElementType() != New->
getType())
6254 return Error(NewLoc,
"new value and pointer type do not match");
6256 return Error(NewLoc,
"cmpxchg operand must be a first class value");
6258 Ptr, Cmp, New, SuccessOrdering, FailureOrdering, SSID);
6262 return AteExtraComma ? InstExtraComma : InstNormal;
6268 int LLParser::ParseAtomicRMW(
Instruction *&Inst, PerFunctionState &PFS) {
6270 bool AteExtraComma =
false;
6273 bool isVolatile =
false;
6280 default:
return TokError(
"expected binary operation in atomicrmw");
6295 if (ParseTypeAndValue(Ptr, PtrLoc, PFS) ||
6296 ParseToken(
lltok::comma,
"expected ',' after atomicrmw address") ||
6297 ParseTypeAndValue(Val, ValLoc, PFS) ||
6298 ParseScopeAndOrdering(
true , SSID, Ordering))
6302 return TokError(
"atomicrmw cannot be unordered");
6304 return Error(PtrLoc,
"atomicrmw operand must be a pointer");
6305 if (cast<PointerType>(Ptr->
getType())->getElementType() != Val->
getType())
6306 return Error(ValLoc,
"atomicrmw value and pointer type do not match");
6308 return Error(ValLoc,
"atomicrmw operand must be an integer");
6310 if (Size < 8 || (Size & (Size - 1)))
6311 return Error(ValLoc,
"atomicrmw operand must be power-of-two byte-sized"
6318 return AteExtraComma ? InstExtraComma : InstNormal;
6323 int LLParser::ParseFence(
Instruction *&Inst, PerFunctionState &PFS) {
6326 if (ParseScopeAndOrdering(
true , SSID, Ordering))
6330 return TokError(
"fence cannot be unordered");
6332 return TokError(
"fence cannot be monotonic");
6334 Inst =
new FenceInst(Context, Ordering, SSID);
6340 int LLParser::ParseGetElementPtr(
Instruction *&Inst, PerFunctionState &PFS) {
6341 Value *Ptr =
nullptr;
6342 Value *Val =
nullptr;
6349 if (ParseType(Ty) ||
6350 ParseToken(
lltok::comma,
"expected comma after getelementptr's type") ||
6351 ParseTypeAndValue(Ptr, Loc, PFS))
6356 if (!BasePointerType)
6357 return Error(Loc,
"base of getelementptr must be a pointer");
6360 return Error(ExplicitTypeLoc,
6361 "explicit pointee type doesn't match operand's pointee type");
6364 bool AteExtraComma =
false;
6372 AteExtraComma =
true;
6375 if (ParseTypeAndValue(Val, EltLoc, PFS))
return true;
6377 return Error(EltLoc,
"getelementptr index must be an integer");
6381 if (GEPWidth && GEPWidth != ValNumEl)
6382 return Error(EltLoc,
6383 "getelementptr vector index has a wrong number of elements");
6384 GEPWidth = ValNumEl;
6391 return Error(Loc,
"base element of getelementptr must be sized");
6394 return Error(Loc,
"invalid getelementptr indices");
6397 cast<GetElementPtrInst>(Inst)->setIsInBounds(
true);
6398 return AteExtraComma ? InstExtraComma : InstNormal;
6403 int LLParser::ParseExtractValue(
Instruction *&Inst, PerFunctionState &PFS) {
6407 if (ParseTypeAndValue(Val, Loc, PFS) ||
6408 ParseIndexList(Indices, AteExtraComma))
6412 return Error(Loc,
"extractvalue operand must be aggregate type");
6415 return Error(Loc,
"invalid indices for extractvalue");
6417 return AteExtraComma ? InstExtraComma : InstNormal;
6422 int LLParser::ParseInsertValue(
Instruction *&Inst, PerFunctionState &PFS) {
6426 if (ParseTypeAndValue(Val0, Loc0, PFS) ||
6427 ParseToken(
lltok::comma,
"expected comma after insertvalue operand") ||
6428 ParseTypeAndValue(Val1, Loc1, PFS) ||
6429 ParseIndexList(Indices, AteExtraComma))
6433 return Error(Loc0,
"insertvalue operand must be aggregate type");
6437 return Error(Loc0,
"invalid indices for insertvalue");
6438 if (IndexedType != Val1->
getType())
6439 return Error(Loc1,
"insertvalue operand and field disagree in type: '" +
6443 return AteExtraComma ? InstExtraComma : InstNormal;
6470 if (ParseMetadata(MD,
nullptr))
6475 return ParseToken(
lltok::rbrace,
"expected end of metadata node");
6484 return Error(Loc,
"value has no uses");
6486 unsigned NumUses = 0;
6488 for (
const Use &U : V->
uses()) {
6489 if (++NumUses > Indexes.
size())
6491 Order[&U] = Indexes[NumUses - 1];
6494 return Error(Loc,
"value only has one use");
6495 if (Order.
size() != Indexes.
size() || NumUses > Indexes.
size())
6496 return Error(Loc,
"wrong number of indexes, expected " +
6512 return Lex.
Error(
"expected non-empty list of uselistorder indexes");
6519 bool IsOrdered =
true;
6520 assert(Indexes.
empty() &&
"Expected empty order vector");
6523 if (ParseUInt32(Index))
6527 Offset += Index - Indexes.
size();
6529 IsOrdered &= Index == Indexes.
size();
6537 if (Indexes.
size() < 2)
6538 return Error(Loc,
"expected >= 2 uselistorder indexes");
6539 if (Offset != 0 || Max >= Indexes.
size())
6540 return Error(Loc,
"expected distinct uselistorder indexes in range [0, size)");
6542 return Error(Loc,
"expected uselistorder indexes to change the order");
6549 bool LLParser::ParseUseListOrder(PerFunctionState *PFS) {
6556 if (ParseTypeAndValue(V, PFS) ||
6557 ParseToken(
lltok::comma,
"expected comma in uselistorder directive") ||
6558 ParseUseListOrderIndexes(Indexes))
6561 return sortUseListOrder(V, Indexes, Loc);
6566 bool LLParser::ParseUseListOrderBB() {
6573 if (ParseValID(Fn) ||
6574 ParseToken(
lltok::comma,
"expected comma in uselistorder_bb directive") ||
6575 ParseValID(Label) ||
6576 ParseToken(
lltok::comma,
"expected comma in uselistorder_bb directive") ||
6577 ParseUseListOrderIndexes(Indexes))
6585 GV = Fn.
UIntVal < NumberedVals.size() ? NumberedVals[Fn.
UIntVal] :
nullptr;
6587 return Error(Fn.
Loc,
"expected function name in uselistorder_bb");
6589 return Error(Fn.
Loc,
"invalid function forward reference in uselistorder_bb");
6592 return Error(Fn.
Loc,
"expected function name in uselistorder_bb");
6594 return Error(Fn.
Loc,
"invalid declaration in uselistorder_bb");
6598 return Error(Label.
Loc,
"invalid numeric label in uselistorder_bb");
6600 return Error(Label.
Loc,
"expected basic block name in uselistorder_bb");
6603 return Error(Label.
Loc,
"invalid basic block in uselistorder_bb");
6604 if (!isa<BasicBlock>(V))
6605 return Error(Label.
Loc,
"expected basic block in uselistorder_bb");
6607 return sortUseListOrder(V, Indexes, Loc);
void setVisibility(VisibilityTypes V)
Calling convention used for Mesa compute shaders.
The C convention as specified in the x86-64 supplement to the System V ABI, used on most non-Windows ...
void sortUseList(Compare Cmp)
Sort the use-list.
void push_back(const T &Elt)
bool parseStandaloneConstantValue(Constant *&C, const SlotMapping *Slots)
A parsed version of the target data layout string in and methods for querying it. ...
static ConstantInt * getFalse(LLVMContext &Context)
const ValueSymbolTable & getValueSymbolTable() const
Get the symbol table of global variable and function identifiers.
static Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true)
This method constructs a CDS and initializes it with a text string.
void setFastMathFlags(FastMathFlags FMF)
Convenience function for setting multiple fast-math flags on this instruction, which must be an opera...
iterator_range< use_iterator > uses()
static IntegerType * getInt1Ty(LLVMContext &C)
enum llvm::ValID::@272 Kind
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
Special purpose, only applies to global arrays.
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...
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
*p = old <signed v ? old : v
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
This class represents an incoming formal argument to a Function.
uint64_t getZExtValue() const
Get zero extended value.
const char * getPointer() const
const APFloat & getAPFloatVal() const
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 MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static ResumeInst * Create(Value *Exn, Instruction *InsertBefore=nullptr)
Calling convention used for AVR signal routines.
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)
unsigned getUIntVal() const
const GlobalListType & getGlobalList() const
Get the Module's list of global variables (constant).
Available for inspection, not emission.
bool shouldDiscardValueNames() const
Return true if the Context runtime configuration is set to discard all value names.
void addCase(ConstantInt *OnVal, BasicBlock *Dest)
Add an entry to the switch instruction.
Type * getValueType() const
uint64_t getAlignment() const
Retrieve the alignment attribute, if it exists.
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)
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space...
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList, bool InBounds=false, Optional< unsigned > InRangeIndex=None, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
*p = old <unsigned v ? old : v
static Constant * getExtractElement(Constant *Vec, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
void setVolatile(bool V)
Specify whether this is a volatile cmpxchg.
0 1 0 0 True if ordered and less than
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.
static CleanupPadInst * Create(Value *ParentPad, ArrayRef< Value * > Args=None, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
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.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
bool isTokenTy() const
Return true if this is 'token'.
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
PTX_Kernel - Call to a PTX kernel.
AttrBuilder & addDereferenceableAttr(uint64_t Bytes)
This turns the number of dereferenceable bytes into the form used internally in Attribute.
The two locations do not alias at all.
Calling convention used for Mesa geometry shaders.
static bool isValidReturnType(Type *RetTy)
Return true if the specified type is valid as a return type.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
An instruction for reading from memory.
ELFYAML::ELF_STV Visibility
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.
X86_ThisCall - Similar to X86_StdCall.
static bool isValidArgumentType(Type *ArgTy)
Return true if the specified type is valid as an argument type.
static GlobalValue * createGlobalFwdRef(Module *M, PointerType *PTy, const std::string &Name)
Type * getElementType() const
void setAlignment(unsigned Align)
static 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.
unsigned getVirtuality(StringRef VirtualityString)
const AliasListType & getAliasList() const
Get the Module's list of aliases (constant).
bool hasAlignmentAttr() const
Return true if the builder has an alignment attribute.
*p = old >signed v ? old : v
bool contains(Attribute::AttrKind A) const
Return true if the builder has the specified attribute.
const IFuncListType & getIFuncList() const
Get the Module's list of ifuncs (constant).
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...
Tagged DWARF-like metadata node.
static bool isLocalLinkage(LinkageTypes Linkage)
static Constant * getInsertElement(Constant *Vec, Constant *Elt, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
DebugEmissionKind getEmissionKind() const
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.
StringRef getName() const
Return a constant reference to the value's name.
void setCallingConv(CallingConv::ID CC)
static ReturnInst * Create(LLVMContext &C, Value *retVal=nullptr, Instruction *InsertBefore=nullptr)
ARM_AAPCS_VFP - Same as ARM_AAPCS, but uses hard floating point ABI.
X86_INTR - x86 hardware interrupt context.
bool Run()
Run: module ::= toplevelentity*.
1 0 0 1 True if unordered or equal
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
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...
static Type * getTokenTy(LLVMContext &C)
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.
void setInitializer(Constant *InitVal)
setInitializer - Sets the initializer for this global variable, removing any existing initializer if ...
Class to represent struct types.
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...
A Use represents the edge between a Value definition and its users.
param_iterator param_end() const
MSP430_INTR - Calling convention used for MSP430 interrupt routines.
static Constant * get(ArrayRef< Constant * > V)
ARM_APCS - ARM Procedure Calling Standard calling convention (obsolete, but still used on some target...
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...
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.
The linker may choose any COMDAT.
void setName(const Twine &Name)
Change the name of the value.
MSVC calling convention that passes vectors and vector aggregates in SSE registers.
static const unsigned MaximumAlignment
void setDLLStorageClass(DLLStorageClassTypes C)
Calling convention used for Mesa hull shaders.
LLVM_NODISCARD bool empty() const
AtomicOrdering
Atomic ordering for LLVM's memory model.
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 Constant * get(unsigned Opcode, Constant *C1, Constant *C2, unsigned Flags=0, Type *OnlyIfReducedTy=nullptr)
get - Return a binary or shift operator constant expression, folding if possible. ...
llvm::Optional< Function * > remangleIntrinsicFunction(Function *F)
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Return a distinct node.
Class to represent function types.
static Type * getLabelTy(LLVMContext &C)
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
BinOp
This enumeration lists the possible modifications atomicrmw can make.
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
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)
bool isFirstClassType() const
Return true if the type is "first class", meaning it is a valid type for a Value. ...
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
bool isFloatingPointTy() const
Return true if this is one of the six floating-point types.
AttributeSet getAttributes(unsigned Index) const
The attributes for the specified index are returned.
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.
auto count(R &&Range, const E &Element) -> typename std::iterator_traits< decltype(std::begin(Range))>::difference_type
Wrapper function around std::count to count the number of times an element Element occurs in the give...
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
bool isArrayTy() const
True if this is an instance of ArrayType.
static const fltSemantics & IEEEdouble() LLVM_READNONE
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Return a temporary node.
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM...
Used for AVR interrupt routines.
size_t size() const
size - Get the array size.
Class to represent pointers.
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
bool UpgradeModuleFlags(Module &M)
This checks for module flags which should be upgraded.
SPIR_KERNEL - Calling convention for SPIR kernel functions.
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
static ChecksumKind getChecksumKind(StringRef CSKindStr)
ExternalWeak linkage description.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
static Constant * getInsertValue(Constant *Agg, Constant *Val, ArrayRef< unsigned > Idxs, Type *OnlyIfReducedTy=nullptr)
void setCallingConv(CallingConv::ID CC)
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Same, but only replaced by something equivalent.
bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return true if the attribute exists at the given index.
No other Module may specify this COMDAT.
SPIR_FUNC - Calling convention for SPIR non-kernel device functions.
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...
HHVM calling convention for invoking C/C++ helpers.
bool isVectorTy() const
True if this is an instance of VectorType.
static BlockAddress * get(Function *F, BasicBlock *BB)
Return a BlockAddress for the specified function and basic block.
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)
Build a DICompositeType with the given ODR identifier.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
This function has undefined behavior.
This is an important base class in LLVM.
Resume the propagation of an exception.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
unsigned getCallingConvention(StringRef LanguageString)
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
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.
param_iterator param_begin() const
Indirect Branch Instruction.
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
void setExternallyInitialized(bool Val)
unsigned getOperationEncoding(StringRef OperationEncodingString)
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
StringMap< Type * > NamedTypes
bool UpgradeDebugInfo(Module &M)
Check the debug info version number, if it is out-dated, drop the debug info.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
unsigned getAllocaAddrSpace() const
static bool isValidLinkage(LinkageTypes L)
static Constant * getShuffleVector(Constant *V1, Constant *V2, Constant *Mask, Type *OnlyIfReducedTy=nullptr)
A pair of DIGlobalVariable and DIExpression.
void splice(iterator where, iplist_impl &L2)
const InstListType & getInstList() const
Return the underlying instruction list container.
This instruction compares its operands according to the predicate given to the constructor.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
unsigned getBitWidth() const
Return the number of bits in the APInt.
static const unsigned End
DLLStorageClassTypes
Storage classes of global values for PE targets.
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.
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...
static Constant * get(StructType *T, ArrayRef< Constant * > V)
The data referenced by the COMDAT must be the same.
X86_FastCall - 'fast' analog of X86_StdCall.
void setTailCallKind(TailCallKind TCK)
std::vector< GlobalValue * > GlobalValues
void setConstant(bool Val)
unsigned getLanguage(StringRef LanguageString)
dot regions Print regions of function to dot file(with no function bodies)"
1 1 1 1 Always true (always folded)
std::map< unsigned, Type * > Types
static bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
bool isPointerTy() const
True if this is an instance of PointerType.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
bool Error(LocTy L, const Twine &Msg) const
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...
AttributeList removeAttribute(LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const
Remove the specified attribute at the specified index from this attribute list.
AttributeList addAttributes(LLVMContext &C, unsigned Index, const AttrBuilder &B) const
Add attributes to the attribute set at the given index.
LLVMContext & getContext() const
All values hold a context through their type.
Calling convention used for Mesa vertex shaders.
static bool isAtomic(Instruction *I)
static wasm::ValType getType(const TargetRegisterClass *RC)
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
void setBody(ArrayRef< Type * > Elements, bool isPacked=false)
Specify a body for an opaque identified type.
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
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.
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)
static CatchPadInst * Create(Value *CatchSwitch, ArrayRef< Value * > Args, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
An imported module (C++ using directive or similar).
unsigned getTag(StringRef TagString)
ARM_AAPCS - ARM Architecture Procedure Calling Standard calling convention (aka EABI).
BaseType
A given derived pointer can have multiple base pointers through phi/selects.
global_iterator global_end()
static InvokeInst * Create(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, const Twine &NameStr, Instruction *InsertBefore=nullptr)
const FunctionListType & getFunctionList() const
Get the Module's list of functions (constant).
Intel_OCL_BI - Calling conventions for Intel OpenCL built-ins.
static Constant * getFCmp(unsigned short pred, Constant *LHS, Constant *RHS, bool OnlyIfReduced=false)
0 0 1 0 True if ordered and greater than
static const fltSemantics & IEEEsingle() LLVM_READNONE
Synchronized with respect to all concurrently executing threads.
Iterator for intrusive lists based on ilist_node.
const BasicBlockListType & getBasicBlockList() const
Get the underlying elements of the Function...
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)
static const fltSemantics & IEEEhalf() LLVM_READNONE
bool isFunctionTy() const
True if this is an instance of FunctionType.
X86_StdCall - stdcall is the calling conventions mostly used by the Win32 API.
static CatchSwitchInst * Create(Value *ParentPad, BasicBlock *UnwindDest, unsigned NumHandlers, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
const std::string & getStrVal() const
static StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
static SwitchInst * Create(Value *Value, BasicBlock *Default, unsigned NumCases, Instruction *InsertBefore=nullptr)
AttrBuilder & removeAttribute(Attribute::AttrKind Val)
Remove an attribute from the builder.
static CallInst * Create(Value *Func, ArrayRef< Value * > Args, ArrayRef< OperandBundleDef > Bundles=None, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
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)
Calling convention used for Mesa pixel shaders.
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
bool isVector(MCInstrInfo const &MCII, MCInst const &MCI)
Type::subtype_iterator param_iterator
void addMetadata(unsigned KindID, MDNode &MD)
Add a metadata attachment.
APSInt extOrTrunc(uint32_t width) 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.
bool any() const
Whether any flag is set.
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...
AttributeSet getFnAttributes() const
The function attributes are returned.
static ConstantInt * getTrue(LLVMContext &Context)
void setAttributes(AttributeList Attrs)
Set the attribute list for this Function.
Calling convention used by HipHop Virtual Machine (HHVM) to perform calls to and from translation cac...
void setLinkage(LinkageTypes LT)
ValueSymbolTable * getValueSymbolTable()
getSymbolTable() - Return the symbol table if any, otherwise nullptr.
C - The default llvm calling convention, compatible with C.
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"...
static DIFlags getFlag(StringRef Flag)
void setAttributes(AttributeList A)
Set the parameter attributes for this call.
void push_back(pointer val)
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.
bool isIntegerTy() const
True if this is an instance of IntegerType.
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)
unsigned getVectorNumElements() const
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.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
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)
void setSwiftError(bool V)
Specify whether this alloca is used to represent a swifterror.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
The C convention as implemented on Windows/x86-64 and AArch64.
llvm_unreachable("Unknown RegBank!")
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...
Type array for a subprogram.
AttributeList removeAttributes(LLVMContext &C, unsigned Index, const AttrBuilder &AttrsToRemove) const
Remove the specified attributes at the specified index from this attribute list.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static std::vector< std::string > Flags
static std::string getTypeString(Type *T)
static CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
Function to be accessible from DLL.
PointerType * getType() const
Global values are always pointers.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
void eraseFromParent()
This method unlinks 'this' from the containing module and deletes it.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
void emplace_back(ArgTypes &&...Args)
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)
bool isAggregateType() const
Return true if the type is an aggregate type.
void setUnnamedAddr(UnnamedAddr Val)
OperandType
Types of operands to CF instructions.
StringRef filename(StringRef path, Style style=Style::native)
Get filename.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
unsigned greater or equal
static bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
void setSourceFileName(StringRef Name)
Set the module's original source file name.
static InsertValueInst * Create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
const ComdatSymTabType & getComdatSymbolTable() const
Get the Module's symbol table for COMDATs (constant).
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
void setPrologueData(Constant *PrologueData)
void appendModuleInlineAsm(StringRef Asm)
Append to the module-scope inline assembly blocks.
lltok::Kind getKind() const
Deduce function attributes
std::unique_ptr< Constant *[]> ConstantStructElts
0 1 1 0 True if ordered and operands are unequal
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
void setTargetTriple(StringRef T)
Set the target triple.
Fast - This calling convention attempts to make calls as fast as possible (e.g.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
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...
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.
1 0 1 0 True if unordered or greater than
PTX_Device - Call to a PTX device function.
Function to be imported from DLL.
unsigned getMacinfo(StringRef MacinfoString)
const APSInt & getAPSIntVal() const
void addDestination(BasicBlock *Dest)
Add a destination.
AttrBuilder & merge(const AttrBuilder &B)
Add the attributes from the builder.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void setAttributes(AttributeList A)
Set the parameter attributes for this invoke.
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.
bool isLabelTy() const
Return true if this is 'label'.
0 0 0 1 True if ordered and equal
LLVM Value Representation.
1 0 1 1 True if unordered, greater than, or equal
bool hasAttributes() const
Return true if the builder has IR-level attributes.
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.
Lightweight error class with error context and mandatory checking.
static CleanupReturnInst * Create(Value *CleanupPad, BasicBlock *UnwindBB=nullptr, Instruction *InsertBefore=nullptr)
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.
void setCallingConv(CallingConv::ID CC)
#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...
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, const Twine &N="", Module *M=nullptr)
void setPersonalityFn(Constant *Fn)
Register calling convention used for parameters transfer optimization.
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 getMDKindID(StringRef Name) const
Return a unique non-zero ID for the specified metadata kind.
Calling convention for AMDGPU code object kernels.
static IntegerType * getInt8Ty(LLVMContext &C)
void setSection(StringRef S)
Change the section for this global.
const fltSemantics & getSemantics() const
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type. ...
Value * lookup(StringRef Name) const
This method finds the value with the given Name in the the symbol table.
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 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)
bool isVoidTy() const
Return true if this is 'void'.
an instruction to allocate memory on the stack
Basic type, like 'int' or 'float'.
bool isMetadataTy() const
Return true if this is 'metadata'.
static bool parseField(amd_kernel_code_t &C, MCAsmParser &MCParser, raw_ostream &Err)
void setPrefixData(Constant *PrefixData)
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...