47 return ParseTopLevelEntities() ||
48 ValidateEndOfModule();
53 bool LLParser::ValidateEndOfModule() {
54 for (
unsigned I = 0, E = InstsWithTBAATag.size();
I < E;
I++)
58 for (std::map<
Value*, std::vector<unsigned> >::iterator
59 I = ForwardRefAttrGroups.begin(), E = ForwardRefAttrGroups.end();
62 std::vector<unsigned> &Vec = I->second;
65 for (std::vector<unsigned>::iterator
VI = Vec.begin(), VE = Vec.end();
67 B.
merge(NumberedAttrBuilders[*
VI]);
69 if (
Function *Fn = dyn_cast<Function>(V)) {
73 AS.getFnAttributes());
79 if (FnAttrs.hasAlignmentAttr()) {
80 Fn->setAlignment(FnAttrs.getAlignment());
85 AttributeSet::get(Context,
88 Fn->setAttributes(AS);
89 }
else if (
CallInst *CI = dyn_cast<CallInst>(V)) {
93 AS.getFnAttributes());
96 AttributeSet::get(Context,
99 CI->setAttributes(AS);
100 }
else if (
InvokeInst *II = dyn_cast<InvokeInst>(V)) {
104 AS.getFnAttributes());
107 AttributeSet::get(Context,
110 II->setAttributes(AS);
118 if (!ForwardRefBlockAddresses.empty())
119 return Error(ForwardRefBlockAddresses.begin()->first.Loc,
120 "expected function name in blockaddress");
122 for (
const auto &NT : NumberedTypes)
123 if (NT.second.second.isValid())
124 return Error(NT.second.second,
125 "use of undefined type '%" +
Twine(NT.first) +
"'");
127 for (
StringMap<std::pair<Type*, LocTy> >::iterator I =
128 NamedTypes.begin(), E = NamedTypes.end(); I != E; ++
I)
129 if (I->second.second.isValid())
130 return Error(I->second.second,
131 "use of undefined type named '" + I->getKey() +
"'");
133 if (!ForwardRefComdats.empty())
134 return Error(ForwardRefComdats.begin()->second,
135 "use of undefined comdat '$" +
136 ForwardRefComdats.begin()->first +
"'");
138 if (!ForwardRefVals.empty())
139 return Error(ForwardRefVals.begin()->second.second,
140 "use of undefined value '@" + ForwardRefVals.begin()->first +
143 if (!ForwardRefValIDs.empty())
144 return Error(ForwardRefValIDs.begin()->second.second,
145 "use of undefined value '@" +
146 Twine(ForwardRefValIDs.begin()->first) +
"'");
148 if (!ForwardRefMDNodes.empty())
149 return Error(ForwardRefMDNodes.begin()->second.second,
150 "use of undefined metadata '!" +
151 Twine(ForwardRefMDNodes.begin()->first) +
"'");
154 for (
auto &
N : NumberedMetadata) {
155 if (
N.second && !
N.second->isResolved())
156 N.second->resolveCycles();
180 bool LLParser::ParseTopLevelEntities() {
183 default:
return TokError(
"expected top-level entity");
195 case lltok::exclaim:
if (ParseStandaloneMetadata())
return true;
break;
222 unsigned Linkage,
Visibility, DLLStorageClass;
226 if (ParseOptionalLinkage(Linkage, HasLinkage) ||
227 ParseOptionalVisibility(Visibility) ||
228 ParseOptionalDLLStorageClass(DLLStorageClass) ||
229 ParseOptionalThreadLocal(TLM) ||
230 parseOptionalUnnamedAddr(UnnamedAddr) ||
231 ParseGlobal(
"",
SMLoc(), Linkage, HasLinkage, Visibility,
232 DLLStorageClass, TLM, UnnamedAddr))
240 if (ParseUseListOrderBB())
return true;
break;
248 bool LLParser::ParseModuleAsm() {
254 ParseStringConstant(AsmStr))
return true;
263 bool LLParser::ParseTargetDefinition() {
267 default:
return TokError(
"unknown target property");
270 if (ParseToken(
lltok::equal,
"expected '=' after target triple") ||
271 ParseStringConstant(Str))
277 if (ParseToken(
lltok::equal,
"expected '=' after target datalayout") ||
278 ParseStringConstant(Str))
289 bool LLParser::ParseDepLibs() {
292 if (ParseToken(
lltok::equal,
"expected '=' after deplibs") ||
301 if (ParseStringConstant(Str))
return true;
309 bool LLParser::ParseUnnamedType() {
314 if (ParseToken(
lltok::equal,
"expected '=' after name") ||
318 Type *Result =
nullptr;
319 if (ParseStructDefinition(TypeLoc,
"",
320 NumberedTypes[TypeID], Result))
return true;
322 if (!isa<StructType>(Result)) {
323 std::pair<Type*, LocTy> &Entry = NumberedTypes[
TypeID];
325 return Error(TypeLoc,
"non-struct types may not be recursive");
326 Entry.first = Result;
327 Entry.second =
SMLoc();
336 bool LLParser::ParseNamedType() {
341 if (ParseToken(
lltok::equal,
"expected '=' after name") ||
345 Type *Result =
nullptr;
346 if (ParseStructDefinition(NameLoc, Name,
347 NamedTypes[Name], Result))
return true;
349 if (!isa<StructType>(Result)) {
350 std::pair<Type*, LocTy> &Entry = NamedTypes[
Name];
352 return Error(NameLoc,
"non-struct types may not be recursive");
353 Entry.first = Result;
354 Entry.second =
SMLoc();
363 bool LLParser::ParseDeclare() {
368 return ParseFunctionHeader(F,
false);
373 bool LLParser::ParseDefine() {
378 return ParseFunctionHeader(F,
true) ||
379 ParseOptionalFunctionMetadata(*F) ||
380 ParseFunctionBody(*F);
386 bool LLParser::ParseGlobalType(
bool &IsConstant) {
393 return TokError(
"expected 'global' or 'constant'");
406 bool LLParser::ParseUnnamedGlobal() {
407 unsigned VarID = NumberedVals.size();
414 return Error(Lex.
getLoc(),
"variable expected to be numbered '%" +
418 if (ParseToken(
lltok::equal,
"expected '=' after name"))
423 unsigned Linkage,
Visibility, DLLStorageClass;
426 if (ParseOptionalLinkage(Linkage, HasLinkage) ||
427 ParseOptionalVisibility(Visibility) ||
428 ParseOptionalDLLStorageClass(DLLStorageClass) ||
429 ParseOptionalThreadLocal(TLM) ||
430 parseOptionalUnnamedAddr(UnnamedAddr))
434 return ParseGlobal(Name, NameLoc, Linkage, HasLinkage, Visibility,
435 DLLStorageClass, TLM, UnnamedAddr);
436 return ParseAlias(Name, NameLoc, Linkage, Visibility, DLLStorageClass, TLM,
444 bool LLParser::ParseNamedGlobal() {
451 unsigned Linkage,
Visibility, DLLStorageClass;
454 if (ParseToken(
lltok::equal,
"expected '=' in global variable") ||
455 ParseOptionalLinkage(Linkage, HasLinkage) ||
456 ParseOptionalVisibility(Visibility) ||
457 ParseOptionalDLLStorageClass(DLLStorageClass) ||
458 ParseOptionalThreadLocal(TLM) ||
459 parseOptionalUnnamedAddr(UnnamedAddr))
463 return ParseGlobal(Name, NameLoc, Linkage, HasLinkage, Visibility,
464 DLLStorageClass, TLM, UnnamedAddr);
466 return ParseAlias(Name, NameLoc, Linkage, Visibility, DLLStorageClass, TLM,
470 bool LLParser::parseComdat() {
480 return TokError(
"expected comdat type");
485 return TokError(
"unknown selection kind");
507 if (I != ComdatSymTab.
end() && !ForwardRefComdats.erase(Name))
508 return Error(NameLoc,
"redefinition of comdat '$" + Name +
"'");
511 if (I != ComdatSymTab.
end())
522 bool LLParser::ParseMDString(
MDString *&Result) {
524 if (ParseStringConstant(Str))
return true;
532 bool LLParser::ParseMDNodeID(
MDNode *&Result) {
535 if (ParseUInt32(MID))
539 if (NumberedMetadata.count(MID)) {
540 Result = NumberedMetadata[MID];
545 auto &FwdRef = ForwardRefMDNodes[MID];
548 Result = FwdRef.first.
get();
549 NumberedMetadata[MID].reset(Result);
555 bool LLParser::ParseNamedMetadata() {
572 if (ParseMDNodeID(N))
return true;
576 return ParseToken(
lltok::rbrace,
"expected end of metadata node");
581 bool LLParser::ParseStandaloneMetadata() {
584 unsigned MetadataID = 0;
587 if (ParseUInt32(MetadataID) ||
593 return TokError(
"unexpected type in metadata definition");
597 if (ParseSpecializedMDNode(Init, IsDistinct))
600 ParseMDTuple(Init, IsDistinct))
604 auto FI = ForwardRefMDNodes.find(MetadataID);
605 if (FI != ForwardRefMDNodes.end()) {
606 FI->second.first->replaceAllUsesWith(Init);
607 ForwardRefMDNodes.erase(FI);
609 assert(NumberedMetadata[MetadataID] == Init &&
"Tracking VH didn't work");
611 if (NumberedMetadata.count(MetadataID))
612 return TokError(
"Metadata id is already used");
613 NumberedMetadata[MetadataID].reset(Init);
634 bool LLParser::ParseAlias(
const std::string &Name, LocTy NameLoc,
unsigned L,
635 unsigned Visibility,
unsigned DLLStorageClass,
644 return Error(NameLoc,
"invalid linkage type for alias");
647 return Error(NameLoc,
648 "symbol with local linkage must have default visibility");
656 if (ParseGlobalTypeAndValue(Aliasee))
664 return Error(AliaseeLoc,
"invalid aliasee");
671 return Error(AliaseeLoc,
"An alias must have pointer type");
674 std::unique_ptr<GlobalAlias> GA(
677 GA->setThreadLocalMode(TLM);
680 GA->setUnnamedAddr(UnnamedAddr);
683 NumberedVals.push_back(GA.get());
690 std::map<std::string, std::pair<GlobalValue*, LocTy> >::iterator
691 I = ForwardRefVals.find(Name);
692 if (I == ForwardRefVals.end())
693 return Error(NameLoc,
"redefinition of global named '@" + Name +
"'");
697 if (Val->getType() != GA->getType())
698 return Error(NameLoc,
699 "forward reference and definition of alias have different types");
703 Val->replaceAllUsesWith(GA.get());
704 Val->eraseFromParent();
705 ForwardRefVals.erase(I);
710 assert(GA->getName() == Name &&
"Should not be a name conflict!");
729 bool LLParser::ParseGlobal(
const std::string &Name, LocTy NameLoc,
730 unsigned Linkage,
bool HasLinkage,
731 unsigned Visibility,
unsigned DLLStorageClass,
735 return Error(NameLoc,
736 "symbol with local linkage must have default visibility");
739 bool IsConstant, IsExternallyInitialized;
740 LocTy IsExternallyInitializedLoc;
744 if (ParseOptionalAddrSpace(AddrSpace) ||
746 IsExternallyInitialized,
747 &IsExternallyInitializedLoc) ||
748 ParseGlobalType(IsConstant) ||
749 ParseType(Ty, TyLoc))
757 if (ParseGlobalValue(Ty, Init))
762 return Error(TyLoc,
"invalid type for global variable");
770 if (!ForwardRefVals.erase(Name) || !isa<GlobalValue>(GVal))
771 return Error(NameLoc,
"redefinition of global '@" + Name +
"'");
774 std::map<unsigned, std::pair<GlobalValue*, LocTy> >::iterator
775 I = ForwardRefValIDs.find(NumberedVals.size());
776 if (I != ForwardRefValIDs.end()) {
777 GVal = I->second.first;
778 ForwardRefValIDs.erase(I);
790 "forward reference and definition of global have different types");
792 GV = cast<GlobalVariable>(GVal);
799 NumberedVals.push_back(GV);
823 if (ParseOptionalAlignment(Alignment))
return true;
827 if (parseOptionalComdat(Name, C))
832 return TokError(
"unknown global variable property!");
841 bool LLParser::ParseUnnamedAttrGrp() {
847 return TokError(
"expected attribute group id");
850 std::vector<unsigned> unused;
856 ParseFnAttributeValuePairs(NumberedAttrBuilders[VarID], unused,
true,
858 ParseToken(
lltok::rbrace,
"expected end of attribute group"))
861 if (!NumberedAttrBuilders[VarID].hasAttributes())
862 return Error(AttrGrpLoc,
"attribute group has no attributes");
869 bool LLParser::ParseFnAttributeValuePairs(
AttrBuilder &B,
870 std::vector<unsigned> &FwdRefAttrGrps,
871 bool inAttrGrp, LocTy &BuiltinLoc) {
872 bool HaveError =
false;
879 BuiltinLoc = Lex.
getLoc();
882 if (!inAttrGrp)
return HaveError;
883 return Error(Lex.
getLoc(),
"unterminated attribute group");
895 "cannot have an attribute group reference in an attribute group");
898 if (inAttrGrp)
break;
901 FwdRefAttrGrps.push_back(AttrGrpNum);
910 ParseStringConstant(Val))
926 ParseUInt32(Alignment))
929 if (ParseOptionalAlignment(Alignment))
940 ParseUInt32(Alignment))
943 if (ParseOptionalStackAlignment(Alignment))
992 "invalid use of attribute on a function");
1006 "invalid use of parameter-only attribute on a function");
1021 GlobalValue *LLParser::GetGlobalVal(
const std::string &Name,
Type *Ty,
1025 Error(Loc,
"global variable reference must have pointer type");
1036 std::map<std::string, std::pair<GlobalValue*, LocTy> >::iterator
1037 I = ForwardRefVals.find(Name);
1038 if (I != ForwardRefVals.end())
1039 Val = I->second.first;
1044 if (Val->
getType() == Ty)
return Val;
1045 Error(Loc,
"'@" + Name +
"' defined with type '" +
1060 ForwardRefVals[
Name] = std::make_pair(FwdVal, Loc);
1064 GlobalValue *LLParser::GetGlobalVal(
unsigned ID,
Type *Ty, LocTy Loc) {
1067 Error(Loc,
"global variable reference must have pointer type");
1071 GlobalValue *Val = ID < NumberedVals.size() ? NumberedVals[
ID] :
nullptr;
1076 std::map<unsigned, std::pair<GlobalValue*, LocTy> >::iterator
1077 I = ForwardRefValIDs.find(ID);
1078 if (I != ForwardRefValIDs.end())
1079 Val = I->second.first;
1084 if (Val->
getType() == Ty)
return Val;
1085 Error(Loc,
"'@" +
Twine(ID) +
"' defined with type '" +
1098 ForwardRefValIDs[
ID] = std::make_pair(FwdVal, Loc);
1107 Comdat *LLParser::getComdat(
const std::string &Name, LocTy Loc) {
1111 if (I != ComdatSymTab.
end())
1116 ForwardRefComdats[
Name] = Loc;
1127 bool LLParser::ParseToken(
lltok::Kind T,
const char *ErrMsg) {
1129 return TokError(ErrMsg);
1136 bool LLParser::ParseStringConstant(std::string &Result) {
1138 return TokError(
"expected string constant");
1146 bool LLParser::ParseUInt32(
unsigned &Val) {
1148 return TokError(
"expected integer");
1150 if (Val64 !=
unsigned(Val64))
1151 return TokError(
"expected 32-bit integer (too large)");
1159 bool LLParser::ParseUInt64(uint64_t &Val) {
1161 return TokError(
"expected integer");
1174 return TokError(
"expected localdynamic, initialexec or localexec");
1202 return ParseTLSModel(TLM) ||
1203 ParseToken(
lltok::rparen,
"expected ')' after thread local model");
1211 bool LLParser::ParseOptionalAddrSpace(
unsigned &AddrSpace) {
1215 return ParseToken(
lltok::lparen,
"expected '(' in address space") ||
1216 ParseUInt32(AddrSpace) ||
1221 bool LLParser::ParseOptionalParamAttrs(
AttrBuilder &B) {
1222 bool HaveError =
false;
1233 if (ParseOptionalAlignment(Alignment))
1293 HaveError |= Error(Lex.
getLoc(),
"invalid use of function-only attribute");
1302 bool LLParser::ParseOptionalReturnAttrs(
AttrBuilder &B) {
1303 bool HaveError =
false;
1340 HaveError |= Error(Lex.
getLoc(),
"invalid use of parameter-only attribute");
1371 HaveError |= Error(Lex.
getLoc(),
"invalid use of function-only attribute");
1376 HaveError |= Error(Lex.
getLoc(),
"invalid use of attribute on return type");
1396 bool LLParser::ParseOptionalLinkage(
unsigned &Res,
bool &HasLinkage) {
1425 bool LLParser::ParseOptionalVisibility(
unsigned &Res) {
1441 bool LLParser::ParseOptionalDLLStorageClass(
unsigned &Res) {
1478 bool LLParser::ParseOptionalCallingConv(
unsigned &CC) {
1506 return ParseUInt32(CC);
1516 bool LLParser::ParseMetadataAttachment(
unsigned &
Kind,
MDNode *&MD) {
1523 return ParseMDNode(MD);
1528 bool LLParser::ParseInstructionMetadata(
Instruction &Inst) {
1531 return TokError(
"expected metadata after comma");
1535 if (ParseMetadataAttachment(MDK, N))
1540 InstsWithTBAATag.push_back(&Inst);
1549 bool LLParser::ParseOptionalFunctionMetadata(
Function &
F) {
1553 if (ParseMetadataAttachment(MDK, N))
1564 bool LLParser::ParseOptionalAlignment(
unsigned &Alignment) {
1569 if (ParseUInt32(Alignment))
return true;
1571 return Error(AlignLoc,
"alignment is not a power of two");
1573 return Error(AlignLoc,
"huge alignments are not supported yet");
1582 bool LLParser::ParseOptionalDerefAttrBytes(
lltok::Kind AttrKind,
1589 if (!EatIfPresent(AttrKind))
1593 return Error(ParenLoc,
"expected '('");
1595 if (ParseUInt64(Bytes))
return true;
1598 return Error(ParenLoc,
"expected ')'");
1600 return Error(DerefLoc,
"dereferenceable bytes must be non-zero");
1610 bool LLParser::ParseOptionalCommaAlign(
unsigned &Alignment,
1611 bool &AteExtraComma) {
1612 AteExtraComma =
false;
1616 AteExtraComma =
true;
1621 return Error(Lex.
getLoc(),
"expected metadata or 'align'");
1623 if (ParseOptionalAlignment(Alignment))
return true;
1643 return ParseOrdering(Ordering);
1652 default:
return TokError(
"Expected ordering on atomic instruction");
1667 bool LLParser::ParseOptionalStackAlignment(
unsigned &Alignment) {
1673 return Error(ParenLoc,
"expected '('");
1675 if (ParseUInt32(Alignment))
return true;
1678 return Error(ParenLoc,
"expected ')'");
1680 return Error(AlignLoc,
"stack alignment is not a power of two");
1694 bool &AteExtraComma) {
1695 AteExtraComma =
false;
1698 return TokError(
"expected ',' as start of index list");
1702 if (Indices.
empty())
return TokError(
"expected index");
1703 AteExtraComma =
true;
1707 if (ParseUInt32(Idx))
return true;
1719 bool LLParser::ParseType(
Type *&Result,
const Twine &Msg,
bool AllowVoid) {
1723 return TokError(Msg);
1731 if (ParseAnonStructType(Result,
false))
1737 if (ParseArrayVectorType(Result,
false))
1744 if (ParseAnonStructType(Result,
true) ||
1745 ParseToken(
lltok::greater,
"expected '>' at end of packed struct"))
1747 }
else if (ParseArrayVectorType(Result,
true))
1752 std::pair<Type*, LocTy> &Entry = NamedTypes[Lex.
getStrVal()];
1758 Entry.second = Lex.
getLoc();
1760 Result = Entry.first;
1767 std::pair<Type*, LocTy> &Entry = NumberedTypes[Lex.
getUIntVal()];
1773 Entry.second = Lex.
getLoc();
1775 Result = Entry.first;
1786 if (!AllowVoid && Result->
isVoidTy())
1787 return Error(TypeLoc,
"void type only allowed for function results");
1793 return TokError(
"basic block pointers are invalid");
1795 return TokError(
"pointers to void are invalid - use i8* instead");
1797 return TokError(
"pointer to this type is invalid");
1805 return TokError(
"basic block pointers are invalid");
1807 return TokError(
"pointers to void are invalid; use i8* instead");
1809 return TokError(
"pointer to this type is invalid");
1811 if (ParseOptionalAddrSpace(AddrSpace) ||
1812 ParseToken(
lltok::star,
"expected '*' in address space"))
1821 if (ParseFunctionType(Result))
1834 PerFunctionState &PFS,
bool IsMustTailCall,
1835 bool InVarArgsFunc) {
1839 unsigned AttrIndex = 1;
1842 if (!ArgList.
empty() &&
1843 ParseToken(
lltok::comma,
"expected ',' in argument list"))
1848 const char *Msg =
"unexpected ellipsis in argument list for ";
1849 if (!IsMustTailCall)
1850 return TokError(
Twine(Msg) +
"non-musttail call");
1852 return TokError(
Twine(Msg) +
"musttail call in non-varargs function");
1854 return ParseToken(
lltok::rparen,
"expected ')' at end of argument list");
1859 Type *ArgTy =
nullptr;
1862 if (ParseType(ArgTy, ArgLoc))
1866 if (ParseMetadataAsValue(V, PFS))
1870 if (ParseOptionalParamAttrs(ArgAttrs) || ParseValue(ArgTy, V, PFS))
1878 if (IsMustTailCall && InVarArgsFunc)
1879 return TokError(
"expected '...' at end of argument list for musttail call "
1880 "in varargs function");
1910 Type *ArgTy =
nullptr;
1914 if (ParseType(ArgTy) ||
1915 ParseOptionalParamAttrs(Attrs))
return true;
1918 return Error(TypeLoc,
"argument can not have void type");
1926 return Error(TypeLoc,
"invalid type for function argument");
1928 unsigned AttrIndex = 1;
1930 AttrIndex++, Attrs),
1942 if (ParseType(ArgTy) || ParseOptionalParamAttrs(Attrs))
return true;
1945 return Error(TypeLoc,
"argument can not have void type");
1955 return Error(TypeLoc,
"invalid type for function argument");
1959 AttributeSet::get(ArgTy->
getContext(), AttrIndex++, Attrs),
1964 return ParseToken(
lltok::rparen,
"expected ')' at end of argument list");
1969 bool LLParser::ParseFunctionType(
Type *&Result) {
1973 return TokError(
"invalid function return type");
1977 if (ParseArgumentList(ArgList, isVarArg))
1981 for (
unsigned i = 0, e = ArgList.
size(); i != e; ++i) {
1982 if (!ArgList[i].Name.
empty())
1983 return Error(ArgList[i].Loc,
"argument name invalid in function type");
1985 return Error(ArgList[i].Loc,
1986 "argument attributes invalid in function type");
1990 for (
unsigned i = 0, e = ArgList.
size(); i != e; ++i)
1999 bool LLParser::ParseAnonStructType(
Type *&Result,
bool Packed) {
2001 if (ParseStructBody(Elts))
return true;
2008 bool LLParser::ParseStructDefinition(
SMLoc TypeLoc,
StringRef Name,
2009 std::pair<Type*, LocTy> &Entry,
2012 if (Entry.first && !Entry.second.isValid())
2013 return Error(TypeLoc,
"redefinition of type");
2019 Entry.second =
SMLoc();
2024 ResultTy = Entry.first;
2036 return Error(TypeLoc,
"forward references to non-struct type");
2040 return ParseArrayVectorType(ResultTy,
true);
2041 return ParseType(ResultTy);
2045 Entry.second =
SMLoc();
2051 StructType *STy = cast<StructType>(Entry.first);
2054 if (ParseStructBody(Body) ||
2055 (isPacked && ParseToken(
lltok::greater,
"expected '>' in packed struct")))
2080 if (ParseType(Ty))
return true;
2084 return Error(EltTyLoc,
"invalid element type for struct");
2088 if (ParseType(Ty))
return true;
2091 return Error(EltTyLoc,
"invalid element type for struct");
2096 return ParseToken(
lltok::rbrace,
"expected '}' at end of struct");
2104 bool LLParser::ParseArrayVectorType(
Type *&Result,
bool isVector) {
2107 return TokError(
"expected number in address space");
2113 if (ParseToken(
lltok::kw_x,
"expected 'x' after element count"))
2117 Type *EltTy =
nullptr;
2118 if (ParseType(EltTy))
return true;
2121 "expected end of sequential type"))
2126 return Error(SizeLoc,
"zero element vector is illegal");
2127 if ((
unsigned)Size != Size)
2128 return Error(SizeLoc,
"size too large for vector");
2130 return Error(TypeLoc,
"invalid vector element type");
2134 return Error(TypeLoc,
"invalid array element type");
2152 NumberedVals.push_back(AI);
2155 LLParser::PerFunctionState::~PerFunctionState() {
2157 for (std::map<std::string, std::pair<Value*, LocTy> >::iterator
2158 I = ForwardRefVals.begin(), E = ForwardRefVals.end(); I != E; ++
I)
2159 if (!isa<BasicBlock>(I->second.first)) {
2160 I->second.first->replaceAllUsesWith(
2162 delete I->second.first;
2163 I->second.first =
nullptr;
2166 for (std::map<
unsigned, std::pair<Value*, LocTy> >::iterator
2167 I = ForwardRefValIDs.begin(), E = ForwardRefValIDs.end(); I != E; ++
I)
2168 if (!isa<BasicBlock>(I->second.first)) {
2169 I->second.first->replaceAllUsesWith(
2171 delete I->second.first;
2172 I->second.first =
nullptr;
2176 bool LLParser::PerFunctionState::FinishFunction() {
2177 if (!ForwardRefVals.empty())
2178 return P.Error(ForwardRefVals.begin()->second.second,
2179 "use of undefined value '%" + ForwardRefVals.begin()->first +
2181 if (!ForwardRefValIDs.empty())
2182 return P.Error(ForwardRefValIDs.begin()->second.second,
2183 "use of undefined value '%" +
2184 Twine(ForwardRefValIDs.begin()->first) +
"'");
2192 Value *LLParser::PerFunctionState::GetVal(
const std::string &Name,
2193 Type *Ty, LocTy Loc) {
2200 std::map<std::string, std::pair<Value*, LocTy> >::iterator
2201 I = ForwardRefVals.find(Name);
2202 if (I != ForwardRefVals.end())
2203 Val = I->second.first;
2208 if (Val->
getType() == Ty)
return Val;
2210 P.Error(Loc,
"'%" + Name +
"' is not a basic block");
2212 P.Error(Loc,
"'%" + Name +
"' defined with type '" +
2219 P.Error(Loc,
"invalid use of a non-first-class type");
2230 ForwardRefVals[
Name] = std::make_pair(FwdVal, Loc);
2234 Value *LLParser::PerFunctionState::GetVal(
unsigned ID,
Type *Ty,
2237 Value *Val = ID < NumberedVals.size() ? NumberedVals[
ID] :
nullptr;
2242 std::map<unsigned, std::pair<Value*, LocTy> >::iterator
2243 I = ForwardRefValIDs.find(ID);
2244 if (I != ForwardRefValIDs.end())
2245 Val = I->second.first;
2250 if (Val->
getType() == Ty)
return Val;
2252 P.Error(Loc,
"'%" +
Twine(ID) +
"' is not a basic block");
2254 P.Error(Loc,
"'%" +
Twine(ID) +
"' defined with type '" +
2260 P.Error(Loc,
"invalid use of a non-first-class type");
2271 ForwardRefValIDs[
ID] = std::make_pair(FwdVal, Loc);
2277 bool LLParser::PerFunctionState::SetInstName(
int NameID,
2278 const std::string &NameStr,
2282 if (NameID != -1 || !NameStr.empty())
2283 return P.Error(NameLoc,
"instructions returning void cannot have a name");
2289 if (NameStr.empty()) {
2292 NameID = NumberedVals.size();
2294 if (
unsigned(NameID) != NumberedVals.size())
2295 return P.Error(NameLoc,
"instruction expected to be numbered '%" +
2296 Twine(NumberedVals.size()) +
"'");
2298 std::map<unsigned, std::pair<Value*, LocTy> >::iterator FI =
2299 ForwardRefValIDs.find(NameID);
2300 if (FI != ForwardRefValIDs.end()) {
2301 if (FI->second.first->getType() != Inst->
getType())
2302 return P.Error(NameLoc,
"instruction forward referenced with type '" +
2304 FI->second.first->replaceAllUsesWith(Inst);
2305 delete FI->second.first;
2306 ForwardRefValIDs.erase(FI);
2309 NumberedVals.push_back(Inst);
2314 std::map<std::string, std::pair<Value*, LocTy> >::iterator
2315 FI = ForwardRefVals.find(NameStr);
2316 if (FI != ForwardRefVals.end()) {
2317 if (FI->second.first->getType() != Inst->
getType())
2318 return P.Error(NameLoc,
"instruction forward referenced with type '" +
2320 FI->second.first->replaceAllUsesWith(Inst);
2321 delete FI->second.first;
2322 ForwardRefVals.erase(FI);
2328 if (Inst->
getName() != NameStr)
2329 return P.Error(NameLoc,
"multiple definition of local value named '" +
2336 BasicBlock *LLParser::PerFunctionState::GetBB(
const std::string &Name,
2338 return dyn_cast_or_null<BasicBlock>(GetVal(Name,
2342 BasicBlock *LLParser::PerFunctionState::GetBB(
unsigned ID, LocTy Loc) {
2343 return dyn_cast_or_null<BasicBlock>(GetVal(ID,
2350 BasicBlock *LLParser::PerFunctionState::DefineBB(
const std::string &Name,
2354 BB = GetBB(NumberedVals.size(), Loc);
2356 BB = GetBB(Name, Loc);
2357 if (!BB)
return nullptr;
2365 ForwardRefValIDs.erase(NumberedVals.size());
2366 NumberedVals.push_back(BB);
2369 ForwardRefVals.erase(Name);
2385 bool LLParser::ParseValID(
ValID &ID, PerFunctionState *PFS) {
2388 default:
return TokError(
"expected value token");
2429 if (ParseGlobalValueVector(Elts) ||
2430 ParseToken(
lltok::rbrace,
"expected end of struct constant"))
2447 if (ParseGlobalValueVector(Elts) ||
2449 ParseToken(
lltok::rbrace,
"expected end of packed struct")) ||
2453 if (isPackedStruct) {
2462 return Error(ID.
Loc,
"constant vector must not be empty");
2465 !Elts[0]->getType()->isFloatingPointTy() &&
2466 !Elts[0]->getType()->isPointerTy())
2467 return Error(FirstEltLoc,
2468 "vector elements must have integer, pointer or floating point type");
2471 for (
unsigned i = 1, e = Elts.
size(); i != e; ++i)
2472 if (Elts[i]->
getType() != Elts[0]->getType())
2473 return Error(FirstEltLoc,
2474 "vector element #" +
Twine(i) +
2485 if (ParseGlobalValueVector(Elts) ||
2486 ParseToken(lltok::rsquare,
"expected end of array constant"))
2498 return Error(FirstEltLoc,
"invalid array element type: " +
2504 for (
unsigned i = 0, e = Elts.
size(); i != e; ++i) {
2505 if (Elts[i]->
getType() != Elts[0]->getType())
2506 return Error(FirstEltLoc,
2507 "array element #" +
Twine(i) +
2526 bool HasSideEffect, AlignStack, AsmDialect;
2531 ParseStringConstant(ID.
StrVal) ||
2532 ParseToken(
lltok::comma,
"expected comma in inline asm expression") ||
2537 (
unsigned(AsmDialect)<<2);
2548 if (ParseToken(
lltok::lparen,
"expected '(' in block address expression") ||
2550 ParseToken(
lltok::comma,
"expected comma in block address expression")||
2551 ParseValID(Label) ||
2552 ParseToken(
lltok::rparen,
"expected ')' in block address expression"))
2556 return Error(Fn.
Loc,
"expected function name in blockaddress");
2558 return Error(Label.
Loc,
"expected basic block name in blockaddress");
2563 if (Fn.
UIntVal < NumberedVals.size())
2564 GV = NumberedVals[Fn.
UIntVal];
2565 }
else if (!ForwardRefVals.count(Fn.
StrVal)) {
2571 if (!isa<Function>(GV))
2572 return Error(Fn.
Loc,
"expected function name in blockaddress");
2573 F = cast<Function>(GV);
2575 return Error(Fn.
Loc,
"cannot take blockaddress inside a declaration");
2581 ForwardRefBlockAddresses.insert(std::make_pair(
2583 std::map<ValID, GlobalValue *>()))
2584 .first->second.insert(std::make_pair(std::move(Label),
nullptr))
2597 if (BlockAddressPFS && F == &BlockAddressPFS->getFunction()) {
2599 BB = BlockAddressPFS->GetBB(Label.
UIntVal, Label.
Loc);
2601 BB = BlockAddressPFS->GetBB(Label.
StrVal, Label.
Loc);
2603 return Error(Label.
Loc,
"referenced value is not a basic block");
2606 return Error(Label.
Loc,
"cannot take address of numeric label after "
2607 "the function is defined");
2608 BB = dyn_cast_or_null<BasicBlock>(
2611 return Error(Label.
Loc,
"referenced value is not a basic block");
2633 Type *DestTy =
nullptr;
2636 if (ParseToken(
lltok::lparen,
"expected '(' after constantexpr cast") ||
2637 ParseGlobalTypeAndValue(SrcVal) ||
2638 ParseToken(
lltok::kw_to,
"expected 'to' in constantexpr cast") ||
2639 ParseType(DestTy) ||
2640 ParseToken(
lltok::rparen,
"expected ')' at end of constantexpr cast"))
2643 return Error(ID.
Loc,
"invalid cast opcode for cast from '" +
2655 if (ParseToken(
lltok::lparen,
"expected '(' in extractvalue constantexpr")||
2656 ParseGlobalTypeAndValue(Val) ||
2657 ParseIndexList(Indices) ||
2658 ParseToken(
lltok::rparen,
"expected ')' in extractvalue constantexpr"))
2662 return Error(ID.
Loc,
"extractvalue operand must be aggregate type");
2664 return Error(ID.
Loc,
"invalid indices for extractvalue");
2673 if (ParseToken(
lltok::lparen,
"expected '(' in insertvalue constantexpr")||
2674 ParseGlobalTypeAndValue(Val0) ||
2675 ParseToken(
lltok::comma,
"expected comma in insertvalue constantexpr")||
2676 ParseGlobalTypeAndValue(Val1) ||
2677 ParseIndexList(Indices) ||
2678 ParseToken(
lltok::rparen,
"expected ')' in insertvalue constantexpr"))
2681 return Error(ID.
Loc,
"insertvalue operand must be aggregate type");
2685 return Error(ID.
Loc,
"invalid indices for insertvalue");
2686 if (IndexedType != Val1->
getType())
2687 return Error(ID.
Loc,
"insertvalue operand and field disagree in type: '" +
2700 if (ParseCmpPredicate(PredVal, Opc) ||
2701 ParseToken(
lltok::lparen,
"expected '(' in compare constantexpr") ||
2702 ParseGlobalTypeAndValue(Val0) ||
2703 ParseToken(
lltok::comma,
"expected comma in compare constantexpr") ||
2704 ParseGlobalTypeAndValue(Val1) ||
2705 ParseToken(
lltok::rparen,
"expected ')' in compare constantexpr"))
2709 return Error(ID.
Loc,
"compare operands must have the same type");
2713 if (Opc == Instruction::FCmp) {
2715 return Error(ID.
Loc,
"fcmp requires floating point operands");
2718 assert(Opc == Instruction::ICmp &&
"Unexpected opcode for CmpInst!");
2721 return Error(ID.
Loc,
"icmp requires pointer or integer operands");
2751 if (Opc == Instruction::Add || Opc == Instruction::Sub ||
2752 Opc == Instruction::Mul || Opc == Instruction::Shl) {
2760 }
else if (Opc == Instruction::SDiv || Opc == Instruction::UDiv ||
2761 Opc == Instruction::LShr || Opc == Instruction::AShr) {
2765 if (ParseToken(
lltok::lparen,
"expected '(' in binary constantexpr") ||
2766 ParseGlobalTypeAndValue(Val0) ||
2767 ParseToken(
lltok::comma,
"expected comma in binary constantexpr") ||
2768 ParseGlobalTypeAndValue(Val1) ||
2769 ParseToken(
lltok::rparen,
"expected ')' in binary constantexpr"))
2772 return Error(ID.
Loc,
"operands of constexpr must have same type");
2775 return Error(ModifierLoc,
"nuw only applies to integer operations");
2777 return Error(ModifierLoc,
"nsw only applies to integer operations");
2781 case Instruction::Add:
2782 case Instruction::Sub:
2783 case Instruction::Mul:
2784 case Instruction::UDiv:
2785 case Instruction::SDiv:
2786 case Instruction::URem:
2787 case Instruction::SRem:
2788 case Instruction::Shl:
2789 case Instruction::AShr:
2790 case Instruction::LShr:
2792 return Error(ID.
Loc,
"constexpr requires integer operands");
2794 case Instruction::FAdd:
2795 case Instruction::FSub:
2796 case Instruction::FMul:
2797 case Instruction::FDiv:
2798 case Instruction::FRem:
2800 return Error(ID.
Loc,
"constexpr requires fp operands");
2821 if (ParseToken(
lltok::lparen,
"expected '(' in logical constantexpr") ||
2822 ParseGlobalTypeAndValue(Val0) ||
2823 ParseToken(
lltok::comma,
"expected comma in logical constantexpr") ||
2824 ParseGlobalTypeAndValue(Val1) ||
2825 ParseToken(
lltok::rparen,
"expected ')' in logical constantexpr"))
2828 return Error(ID.
Loc,
"operands of constexpr must have same type");
2830 return Error(ID.
Loc,
2831 "constexpr requires integer or integer vector operands");
2844 bool InBounds =
false;
2848 if (Opc == Instruction::GetElementPtr)
2851 if (ParseToken(
lltok::lparen,
"expected '(' in constantexpr"))
2855 if (Opc == Instruction::GetElementPtr) {
2856 if (ParseType(Ty) ||
2857 ParseToken(
lltok::comma,
"expected comma after getelementptr's type"))
2861 if (ParseGlobalValueVector(Elts) ||
2865 if (Opc == Instruction::GetElementPtr) {
2866 if (Elts.
size() == 0 ||
2867 !Elts[0]->getType()->getScalarType()->isPointerTy())
2868 return Error(ID.
Loc,
"base of getelementptr must be a pointer");
2870 Type *BaseType = Elts[0]->getType();
2871 auto *BasePointerType = cast<PointerType>(BaseType->
getScalarType());
2872 if (Ty != BasePointerType->getElementType())
2875 "explicit pointee type doesn't match operand's pointee type");
2881 return Error(ID.
Loc,
"getelementptr index must be an integer");
2883 return Error(ID.
Loc,
"getelementptr index type missmatch");
2887 if (ValNumEl != PtrNumEl)
2890 "getelementptr vector index has a wrong number of elements");
2895 if (!Indices.empty() && !Ty->
isSized(&Visited))
2896 return Error(ID.
Loc,
"base element of getelementptr must be sized");
2899 return Error(ID.
Loc,
"invalid getelementptr indices");
2903 if (Elts.
size() != 3)
2904 return Error(ID.
Loc,
"expected three operands to select");
2907 return Error(ID.
Loc, Reason);
2909 }
else if (Opc == Instruction::ShuffleVector) {
2910 if (Elts.
size() != 3)
2911 return Error(ID.
Loc,
"expected three operands to shufflevector");
2913 return Error(ID.
Loc,
"invalid operands to shufflevector");
2917 if (Elts.
size() != 2)
2918 return Error(ID.
Loc,
"expected two operands to extractelement");
2920 return Error(ID.
Loc,
"invalid extractelement operands");
2923 assert(Opc == Instruction::InsertElement &&
"Unknown opcode");
2924 if (Elts.
size() != 3)
2925 return Error(ID.
Loc,
"expected three operands to insertelement");
2927 return Error(ID.
Loc,
"invalid insertelement operands");
2942 bool LLParser::ParseGlobalValue(
Type *Ty,
Constant *&C) {
2946 bool Parsed = ParseValID(ID) ||
2947 ConvertValIDToValue(Ty, ID, V,
nullptr);
2948 if (V && !(C = dyn_cast<Constant>(V)))
2949 return Error(ID.
Loc,
"global values must be constants");
2953 bool LLParser::ParseGlobalTypeAndValue(
Constant *&V) {
2955 return ParseType(Ty) ||
2956 ParseGlobalValue(Ty, V);
2959 bool LLParser::parseOptionalComdat(
StringRef GlobalName,
Comdat *&C) {
2968 return TokError(
"expected comdat variable");
2971 if (ParseToken(
lltok::rparen,
"expected ')' after comdat var"))
2974 if (GlobalName.
empty())
2975 return TokError(
"comdat cannot be unnamed");
2976 C = getComdat(GlobalName, KwLoc);
2988 Lex.
getKind() == lltok::rsquare ||
2994 if (ParseGlobalTypeAndValue(C))
return true;
2998 if (ParseGlobalTypeAndValue(C))
return true;
3005 bool LLParser::ParseMDTuple(
MDNode *&MD,
bool IsDistinct) {
3007 if (ParseMDNodeVector(Elts))
3018 bool LLParser::ParseMDNode(
MDNode *&N) {
3020 return ParseSpecializedMDNode(N);
3026 bool LLParser::ParseMDNodeTail(
MDNode *&N) {
3029 return ParseMDTuple(N);
3032 return ParseMDNodeID(N);
3038 template <
class FieldTy>
struct MDFieldImpl {
3039 typedef MDFieldImpl ImplTy;
3043 void assign(FieldTy Val) {
3045 this->Val = std::move(Val);
3048 explicit MDFieldImpl(FieldTy
Default)
3049 : Val(std::move(Default)), Seen(
false) {}
3052 struct MDUnsignedField :
public MDFieldImpl<uint64_t> {
3055 MDUnsignedField(uint64_t
Default = 0, uint64_t
Max = UINT64_MAX)
3058 struct LineField :
public MDUnsignedField {
3059 LineField() : MDUnsignedField(0, UINT32_MAX) {}
3061 struct ColumnField :
public MDUnsignedField {
3062 ColumnField() : MDUnsignedField(0, UINT16_MAX) {}
3064 struct DwarfTagField :
public MDUnsignedField {
3069 struct DwarfAttEncodingField :
public MDUnsignedField {
3070 DwarfAttEncodingField() : MDUnsignedField(0, dwarf::
DW_ATE_hi_user) {}
3072 struct DwarfVirtualityField :
public MDUnsignedField {
3075 struct DwarfLangField :
public MDUnsignedField {
3079 struct DIFlagField :
public MDUnsignedField {
3080 DIFlagField() : MDUnsignedField(0, UINT32_MAX) {}
3083 struct MDSignedField :
public MDFieldImpl<int64_t> {
3087 MDSignedField(int64_t
Default = 0)
3088 : ImplTy(
Default), Min(INT64_MIN),
Max(INT64_MAX) {}
3089 MDSignedField(int64_t
Default, int64_t Min, int64_t
Max)
3090 : ImplTy(Default), Min(Min), Max(Max) {}
3093 struct MDBoolField :
public MDFieldImpl<bool> {
3096 struct MDField :
public MDFieldImpl<Metadata *> {
3099 MDField(
bool AllowNull =
true) : ImplTy(nullptr), AllowNull(AllowNull) {}
3101 struct MDConstant :
public MDFieldImpl<ConstantAsMetadata *> {
3102 MDConstant() : ImplTy(nullptr) {}
3104 struct MDStringField :
public MDFieldImpl<MDString *> {
3106 MDStringField(
bool AllowEmpty =
true)
3107 : ImplTy(nullptr), AllowEmpty(AllowEmpty) {}
3109 struct MDFieldList :
public MDFieldImpl<SmallVector<Metadata *, 4>> {
3118 bool LLParser::ParseMDField(LocTy Loc,
StringRef Name,
3119 MDUnsignedField &Result) {
3121 return TokError(
"expected unsigned integer");
3124 if (U.ugt(Result.Max))
3125 return TokError(
"value for '" + Name +
"' too large, limit is " +
3127 Result.assign(U.getZExtValue());
3128 assert(Result.Val <= Result.Max &&
"Expected value in range");
3134 bool LLParser::ParseMDField(LocTy Loc,
StringRef Name, LineField &Result) {
3135 return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
3138 bool LLParser::ParseMDField(LocTy Loc,
StringRef Name, ColumnField &Result) {
3139 return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
3143 bool LLParser::ParseMDField(LocTy Loc,
StringRef Name, DwarfTagField &Result) {
3145 return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
3148 return TokError(
"expected DWARF tag");
3152 return TokError(
"invalid DWARF tag" +
Twine(
" '") + Lex.
getStrVal() +
"'");
3153 assert(Tag <= Result.Max &&
"Expected valid DWARF tag");
3161 bool LLParser::ParseMDField(LocTy Loc,
StringRef Name,
3162 DwarfVirtualityField &Result) {
3164 return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
3167 return TokError(
"expected DWARF virtuality code");
3171 return TokError(
"invalid DWARF virtuality code" +
Twine(
" '") +
3173 assert(Virtuality <= Result.Max &&
"Expected valid DWARF virtuality code");
3174 Result.assign(Virtuality);
3180 bool LLParser::ParseMDField(LocTy Loc,
StringRef Name, DwarfLangField &Result) {
3182 return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
3185 return TokError(
"expected DWARF language");
3189 return TokError(
"invalid DWARF language" +
Twine(
" '") + Lex.
getStrVal() +
3191 assert(Lang <= Result.Max &&
"Expected valid DWARF language");
3192 Result.assign(Lang);
3198 bool LLParser::ParseMDField(LocTy Loc,
StringRef Name,
3199 DwarfAttEncodingField &Result) {
3201 return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
3204 return TokError(
"expected DWARF type attribute encoding");
3208 return TokError(
"invalid DWARF type attribute encoding" +
Twine(
" '") +
3210 assert(Encoding <= Result.Max &&
"Expected valid DWARF language");
3211 Result.assign(Encoding);
3221 bool LLParser::ParseMDField(LocTy Loc,
StringRef Name, DIFlagField &Result) {
3222 assert(Result.Max == UINT32_MAX &&
"Expected only 32-bits");
3225 auto parseFlag = [&](
unsigned &Val) {
3227 return ParseUInt32(Val);
3230 return TokError(
"expected debug info flag");
3234 return TokError(
Twine(
"invalid debug info flag flag '") +
3241 unsigned Combined = 0;
3249 Result.assign(Combined);
3254 bool LLParser::ParseMDField(LocTy Loc,
StringRef Name,
3255 MDSignedField &Result) {
3257 return TokError(
"expected signed integer");
3261 return TokError(
"value for '" + Name +
"' too small, limit is " +
3264 return TokError(
"value for '" + Name +
"' too large, limit is " +
3266 Result.assign(S.getExtValue());
3267 assert(Result.Val >= Result.Min &&
"Expected value in range");
3268 assert(Result.Val <= Result.Max &&
"Expected value in range");
3274 bool LLParser::ParseMDField(LocTy Loc,
StringRef Name, MDBoolField &Result) {
3277 return TokError(
"expected 'true' or 'false'");
3279 Result.assign(
true);
3282 Result.assign(
false);
3290 bool LLParser::ParseMDField(LocTy Loc,
StringRef Name, MDField &Result) {
3292 if (!Result.AllowNull)
3293 return TokError(
"'" + Name +
"' cannot be null");
3295 Result.assign(
nullptr);
3300 if (ParseMetadata(MD,
nullptr))
3308 bool LLParser::ParseMDField(LocTy Loc,
StringRef Name, MDConstant &Result) {
3310 if (ParseValueAsMetadata(MD,
"expected constant",
nullptr))
3313 Result.assign(cast<ConstantAsMetadata>(MD));
3318 bool LLParser::ParseMDField(LocTy Loc,
StringRef Name, MDStringField &Result) {
3321 if (ParseStringConstant(S))
3324 if (!Result.AllowEmpty && S.empty())
3325 return Error(ValueLoc,
"'" + Name +
"' cannot be empty");
3327 Result.assign(S.empty() ?
nullptr :
MDString::get(Context, S));
3332 bool LLParser::ParseMDField(LocTy Loc,
StringRef Name, MDFieldList &Result) {
3334 if (ParseMDNodeVector(MDs))
3337 Result.assign(std::move(MDs));
3343 template <
class ParserTy>
3344 bool LLParser::ParseMDFieldsImplBody(ParserTy parseField) {
3347 return TokError(
"expected field label here");
3356 template <
class ParserTy>
3357 bool LLParser::ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc) {
3364 if (ParseMDFieldsImplBody(parseField))
3367 ClosingLoc = Lex.
getLoc();
3371 template <
class FieldTy>
3372 bool LLParser::ParseMDField(
StringRef Name, FieldTy &Result) {
3374 return TokError(
"field '" + Name +
"' cannot be specified more than once");
3378 return ParseMDField(Loc, Name, Result);
3381 bool LLParser::ParseSpecializedMDNode(
MDNode *&N,
bool IsDistinct) {
3384 #define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
3385 if (Lex.getStrVal() == #CLASS) \
3386 return Parse##CLASS(N, IsDistinct);
3387 #include "llvm/IR/Metadata.def"
3389 return TokError(
"expected metadata type");
3392 #define DECLARE_FIELD(NAME, TYPE, INIT) TYPE NAME INIT
3393 #define NOP_FIELD(NAME, TYPE, INIT)
3394 #define REQUIRE_FIELD(NAME, TYPE, INIT) \
3396 return Error(ClosingLoc, "missing required field '" #NAME "'");
3397 #define PARSE_MD_FIELD(NAME, TYPE, DEFAULT) \
3398 if (Lex.getStrVal() == #NAME) \
3399 return ParseMDField(#NAME, NAME);
3400 #define PARSE_MD_FIELDS() \
3401 VISIT_MD_FIELDS(DECLARE_FIELD, DECLARE_FIELD) \
3404 if (ParseMDFieldsImpl([&]() -> bool { \
3405 VISIT_MD_FIELDS(PARSE_MD_FIELD, PARSE_MD_FIELD) \
3406 return TokError(Twine("invalid field '") + Lex.getStrVal() + "'"); \
3409 VISIT_MD_FIELDS(NOP_FIELD, REQUIRE_FIELD) \
3411 #define GET_OR_DISTINCT(CLASS, ARGS) \
3412 (IsDistinct ? CLASS::getDistinct ARGS : CLASS::get ARGS)
3416 bool LLParser::ParseDILocation(
MDNode *&Result,
bool IsDistinct) {
3417 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
3418 OPTIONAL(line, LineField, ); \
3419 OPTIONAL(column, ColumnField, ); \
3420 REQUIRED(scope, MDField, ( false)); \
3421 OPTIONAL(inlinedAt, MDField, );
3423 #undef VISIT_MD_FIELDS
3426 DILocation, (Context, line.Val, column.Val, scope.Val, inlinedAt.Val));
3432 bool LLParser::ParseGenericDINode(
MDNode *&Result,
bool IsDistinct) {
3433 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
3434 REQUIRED(tag, DwarfTagField, ); \
3435 OPTIONAL(header, MDStringField, ); \
3436 OPTIONAL(operands, MDFieldList, );
3438 #undef VISIT_MD_FIELDS
3441 (Context, tag.Val, header.Val, operands.Val));
3447 bool LLParser::ParseDISubrange(
MDNode *&Result,
bool IsDistinct) {
3448 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
3449 REQUIRED(count, MDSignedField, (-1, -1, INT64_MAX)); \
3450 OPTIONAL(lowerBound, MDSignedField, );
3452 #undef VISIT_MD_FIELDS
3460 bool LLParser::ParseDIEnumerator(
MDNode *&Result,
bool IsDistinct) {
3461 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
3462 REQUIRED(name, MDStringField, ); \
3463 REQUIRED(value, MDSignedField, );
3465 #undef VISIT_MD_FIELDS
3473 bool LLParser::ParseDIBasicType(
MDNode *&Result,
bool IsDistinct) {
3474 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
3475 OPTIONAL(tag, DwarfTagField, (dwarf::DW_TAG_base_type)); \
3476 OPTIONAL(name, MDStringField, ); \
3477 OPTIONAL(size, MDUnsignedField, (0, UINT64_MAX)); \
3478 OPTIONAL(align, MDUnsignedField, (0, UINT64_MAX)); \
3479 OPTIONAL(encoding, DwarfAttEncodingField, );
3481 #undef VISIT_MD_FIELDS
3484 align.Val, encoding.Val));
3492 bool LLParser::ParseDIDerivedType(
MDNode *&Result,
bool IsDistinct) {
3493 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
3494 REQUIRED(tag, DwarfTagField, ); \
3495 OPTIONAL(name, MDStringField, ); \
3496 OPTIONAL(file, MDField, ); \
3497 OPTIONAL(line, LineField, ); \
3498 OPTIONAL(scope, MDField, ); \
3499 REQUIRED(baseType, MDField, ); \
3500 OPTIONAL(size, MDUnsignedField, (0, UINT64_MAX)); \
3501 OPTIONAL(align, MDUnsignedField, (0, UINT64_MAX)); \
3502 OPTIONAL(offset, MDUnsignedField, (0, UINT64_MAX)); \
3503 OPTIONAL(flags, DIFlagField, ); \
3504 OPTIONAL(extraData, MDField, );
3506 #undef VISIT_MD_FIELDS
3509 (Context, tag.Val,
name.Val,
file.Val, line.Val,
3510 scope.Val, baseType.Val,
size.Val, align.Val,
3511 offset.Val, flags.Val, extraData.Val));
3515 bool LLParser::ParseDICompositeType(
MDNode *&Result,
bool IsDistinct) {
3516 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
3517 REQUIRED(tag, DwarfTagField, ); \
3518 OPTIONAL(name, MDStringField, ); \
3519 OPTIONAL(file, MDField, ); \
3520 OPTIONAL(line, LineField, ); \
3521 OPTIONAL(scope, MDField, ); \
3522 OPTIONAL(baseType, MDField, ); \
3523 OPTIONAL(size, MDUnsignedField, (0, UINT64_MAX)); \
3524 OPTIONAL(align, MDUnsignedField, (0, UINT64_MAX)); \
3525 OPTIONAL(offset, MDUnsignedField, (0, UINT64_MAX)); \
3526 OPTIONAL(flags, DIFlagField, ); \
3527 OPTIONAL(elements, MDField, ); \
3528 OPTIONAL(runtimeLang, DwarfLangField, ); \
3529 OPTIONAL(vtableHolder, MDField, ); \
3530 OPTIONAL(templateParams, MDField, ); \
3531 OPTIONAL(identifier, MDStringField, );
3533 #undef VISIT_MD_FIELDS
3537 (Context, tag.Val,
name.Val,
file.Val, line.Val, scope.Val, baseType.Val,
3538 size.Val, align.Val, offset.Val, flags.Val, elements.Val,
3539 runtimeLang.Val, vtableHolder.Val, templateParams.Val, identifier.Val));
3543 bool LLParser::ParseDISubroutineType(
MDNode *&Result,
bool IsDistinct) {
3544 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
3545 OPTIONAL(flags, DIFlagField, ); \
3546 REQUIRED(types, MDField, );
3548 #undef VISIT_MD_FIELDS
3556 bool LLParser::ParseDIFile(
MDNode *&Result,
bool IsDistinct) {
3557 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
3558 REQUIRED(filename, MDStringField, ); \
3559 REQUIRED(directory, MDStringField, );
3561 #undef VISIT_MD_FIELDS
3573 bool LLParser::ParseDICompileUnit(
MDNode *&Result,
bool IsDistinct) {
3574 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
3575 REQUIRED(language, DwarfLangField, ); \
3576 REQUIRED(file, MDField, ( false)); \
3577 OPTIONAL(producer, MDStringField, ); \
3578 OPTIONAL(isOptimized, MDBoolField, ); \
3579 OPTIONAL(flags, MDStringField, ); \
3580 OPTIONAL(runtimeVersion, MDUnsignedField, (0, UINT32_MAX)); \
3581 OPTIONAL(splitDebugFilename, MDStringField, ); \
3582 OPTIONAL(emissionKind, MDUnsignedField, (0, UINT32_MAX)); \
3583 OPTIONAL(enums, MDField, ); \
3584 OPTIONAL(retainedTypes, MDField, ); \
3585 OPTIONAL(subprograms, MDField, ); \
3586 OPTIONAL(globals, MDField, ); \
3587 OPTIONAL(imports, MDField, ); \
3588 OPTIONAL(dwoId, MDUnsignedField, );
3590 #undef VISIT_MD_FIELDS
3593 (Context, language.Val,
file.Val, producer.Val,
3594 isOptimized.Val, flags.Val, runtimeVersion.Val,
3595 splitDebugFilename.Val, emissionKind.Val, enums.Val,
3596 retainedTypes.Val, subprograms.Val,
globals.Val,
3597 imports.Val, dwoId.Val));
3609 bool LLParser::ParseDISubprogram(
MDNode *&Result,
bool IsDistinct) {
3610 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
3611 OPTIONAL(scope, MDField, ); \
3612 OPTIONAL(name, MDStringField, ); \
3613 OPTIONAL(linkageName, MDStringField, ); \
3614 OPTIONAL(file, MDField, ); \
3615 OPTIONAL(line, LineField, ); \
3616 OPTIONAL(type, MDField, ); \
3617 OPTIONAL(isLocal, MDBoolField, ); \
3618 OPTIONAL(isDefinition, MDBoolField, (true)); \
3619 OPTIONAL(scopeLine, LineField, ); \
3620 OPTIONAL(containingType, MDField, ); \
3621 OPTIONAL(virtuality, DwarfVirtualityField, ); \
3622 OPTIONAL(virtualIndex, MDUnsignedField, (0, UINT32_MAX)); \
3623 OPTIONAL(flags, DIFlagField, ); \
3624 OPTIONAL(isOptimized, MDBoolField, ); \
3625 OPTIONAL(function, MDConstant, ); \
3626 OPTIONAL(templateParams, MDField, ); \
3627 OPTIONAL(declaration, MDField, ); \
3628 OPTIONAL(variables, MDField, );
3630 #undef VISIT_MD_FIELDS
3634 line.Val, type.Val, isLocal.Val, isDefinition.Val,
3635 scopeLine.Val, containingType.Val, virtuality.Val,
3636 virtualIndex.Val, flags.Val, isOptimized.Val,
function.Val,
3637 templateParams.Val, declaration.Val,
variables.Val));
3643 bool LLParser::ParseDILexicalBlock(
MDNode *&Result,
bool IsDistinct) {
3644 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
3645 REQUIRED(scope, MDField, ( false)); \
3646 OPTIONAL(file, MDField, ); \
3647 OPTIONAL(line, LineField, ); \
3648 OPTIONAL(column, ColumnField, );
3650 #undef VISIT_MD_FIELDS
3659 bool LLParser::ParseDILexicalBlockFile(
MDNode *&Result,
bool IsDistinct) {
3660 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
3661 REQUIRED(scope, MDField, ( false)); \
3662 OPTIONAL(file, MDField, ); \
3663 REQUIRED(discriminator, MDUnsignedField, (0, UINT32_MAX));
3665 #undef VISIT_MD_FIELDS
3668 (Context, scope.Val,
file.Val, discriminator.Val));
3674 bool LLParser::ParseDINamespace(
MDNode *&Result,
bool IsDistinct) {
3675 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
3676 REQUIRED(scope, MDField, ); \
3677 OPTIONAL(file, MDField, ); \
3678 OPTIONAL(name, MDStringField, ); \
3679 OPTIONAL(line, LineField, );
3681 #undef VISIT_MD_FIELDS
3684 (Context, scope.Val,
file.Val,
name.Val, line.Val));
3691 bool LLParser::ParseDIModule(
MDNode *&Result,
bool IsDistinct) {
3692 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
3693 REQUIRED(scope, MDField, ); \
3694 REQUIRED(name, MDStringField, ); \
3695 OPTIONAL(configMacros, MDStringField, ); \
3696 OPTIONAL(includePath, MDStringField, ); \
3697 OPTIONAL(isysroot, MDStringField, );
3699 #undef VISIT_MD_FIELDS
3702 configMacros.Val, includePath.Val, isysroot.Val));
3708 bool LLParser::ParseDITemplateTypeParameter(
MDNode *&Result,
bool IsDistinct) {
3709 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
3710 OPTIONAL(name, MDStringField, ); \
3711 REQUIRED(type, MDField, );
3713 #undef VISIT_MD_FIELDS
3723 bool LLParser::ParseDITemplateValueParameter(
MDNode *&Result,
bool IsDistinct) {
3724 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
3725 OPTIONAL(tag, DwarfTagField, (dwarf::DW_TAG_template_value_parameter)); \
3726 OPTIONAL(name, MDStringField, ); \
3727 OPTIONAL(type, MDField, ); \
3728 REQUIRED(value, MDField, );
3730 #undef VISIT_MD_FIELDS
3733 (Context, tag.Val,
name.Val, type.Val, value.Val));
3742 bool LLParser::ParseDIGlobalVariable(
MDNode *&Result,
bool IsDistinct) {
3743 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
3744 REQUIRED(name, MDStringField, ( false)); \
3745 OPTIONAL(scope, MDField, ); \
3746 OPTIONAL(linkageName, MDStringField, ); \
3747 OPTIONAL(file, MDField, ); \
3748 OPTIONAL(line, LineField, ); \
3749 OPTIONAL(type, MDField, ); \
3750 OPTIONAL(isLocal, MDBoolField, ); \
3751 OPTIONAL(isDefinition, MDBoolField, (true)); \
3752 OPTIONAL(variable, MDConstant, ); \
3753 OPTIONAL(declaration, MDField, );
3755 #undef VISIT_MD_FIELDS
3758 (Context, scope.Val,
name.Val, linkageName.Val,
3759 file.Val, line.Val, type.Val, isLocal.Val,
3760 isDefinition.Val, variable.Val, declaration.Val));
3767 bool LLParser::ParseDILocalVariable(
MDNode *&Result,
bool IsDistinct) {
3768 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
3769 REQUIRED(tag, DwarfTagField, ); \
3770 REQUIRED(scope, MDField, ( false)); \
3771 OPTIONAL(name, MDStringField, ); \
3772 OPTIONAL(file, MDField, ); \
3773 OPTIONAL(line, LineField, ); \
3774 OPTIONAL(type, MDField, ); \
3775 OPTIONAL(arg, MDUnsignedField, (0, UINT16_MAX)); \
3776 OPTIONAL(flags, DIFlagField, );
3778 #undef VISIT_MD_FIELDS
3781 (Context, tag.Val, scope.Val,
name.Val,
file.Val,
3782 line.Val, type.Val, arg.Val, flags.Val));
3788 bool LLParser::ParseDIExpression(
MDNode *&Result,
bool IsDistinct) {
3804 return TokError(
Twine(
"invalid DWARF op '") + Lex.
getStrVal() +
"'");
3808 return TokError(
"expected unsigned integer");
3811 if (U.ugt(UINT64_MAX))
3812 return TokError(
"element too large, limit is " +
Twine(UINT64_MAX));
3827 bool LLParser::ParseDIObjCProperty(
MDNode *&Result,
bool IsDistinct) {
3828 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
3829 OPTIONAL(name, MDStringField, ); \
3830 OPTIONAL(file, MDField, ); \
3831 OPTIONAL(line, LineField, ); \
3832 OPTIONAL(setter, MDStringField, ); \
3833 OPTIONAL(getter, MDStringField, ); \
3834 OPTIONAL(attributes, MDUnsignedField, (0, UINT32_MAX)); \
3835 OPTIONAL(type, MDField, );
3837 #undef VISIT_MD_FIELDS
3840 (Context,
name.Val,
file.Val, line.Val, setter.Val,
3848 bool LLParser::ParseDIImportedEntity(
MDNode *&Result,
bool IsDistinct) {
3849 #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
3850 REQUIRED(tag, DwarfTagField, ); \
3851 REQUIRED(scope, MDField, ); \
3852 OPTIONAL(entity, MDField, ); \
3853 OPTIONAL(line, LineField, ); \
3854 OPTIONAL(name, MDStringField, );
3856 #undef VISIT_MD_FIELDS
3859 entity.Val, line.Val,
name.Val));
3863 #undef PARSE_MD_FIELD
3865 #undef REQUIRE_FIELD
3866 #undef DECLARE_FIELD
3875 bool LLParser::ParseMetadataAsValue(
Value *&V, PerFunctionState &PFS) {
3878 if (ParseMetadata(MD, &PFS))
3889 bool LLParser::ParseValueAsMetadata(
Metadata *&MD,
const Twine &TypeMsg,
3890 PerFunctionState *PFS) {
3893 if (ParseType(Ty, TypeMsg, Loc))
3896 return Error(Loc,
"invalid metadata-value-metadata roundtrip");
3899 if (ParseValue(Ty, V, PFS))
3914 bool LLParser::ParseMetadata(
Metadata *&MD, PerFunctionState *PFS) {
3917 if (ParseSpecializedMDNode(N))
3926 return ParseValueAsMetadata(MD,
"expected metadata operand", PFS);
3936 if (ParseMDString(S))
3946 if (ParseMDNodeTail(N))
3957 bool LLParser::ConvertValIDToValue(
Type *Ty,
ValID &ID,
Value *&V,
3958 PerFunctionState *PFS) {
3960 return Error(ID.
Loc,
"functions are not values, refer to them as pointers");
3964 if (!PFS)
return Error(ID.
Loc,
"invalid use of function-local name");
3966 return V ==
nullptr;
3968 if (!PFS)
return Error(ID.
Loc,
"invalid use of function-local name");
3970 return V ==
nullptr;
3976 return Error(ID.
Loc,
"invalid type for inline asm constraint string");
3982 V = GetGlobalVal(ID.
StrVal, Ty, ID.
Loc);
3983 return V ==
nullptr;
3986 return V ==
nullptr;
3989 return Error(ID.
Loc,
"integer constant must have integer type");
3996 return Error(ID.
Loc,
"floating point constant invalid for type");
4012 return Error(ID.
Loc,
"floating point constant does not have type '" +
4018 return Error(ID.
Loc,
"null must be a pointer type");
4024 return Error(ID.
Loc,
"invalid type for undef constant");
4028 if (!Ty->
isArrayTy() || cast<ArrayType>(Ty)->getNumElements() != 0)
4029 return Error(ID.
Loc,
"invalid empty array initializer");
4035 return Error(ID.
Loc,
"invalid type for null constant");
4040 return Error(ID.
Loc,
"constant expression type mismatch");
4048 return Error(ID.
Loc,
4049 "initializer with struct type has wrong # elements");
4051 return Error(ID.
Loc,
"packed'ness of initializer and type don't match");
4054 for (
unsigned i = 0, e = ID.
UIntVal; i != e; ++i)
4056 return Error(ID.
Loc,
"element " +
Twine(i) +
4057 " of struct initializer doesn't match struct element type");
4062 return Error(ID.
Loc,
"constant expression type mismatch");
4068 bool LLParser::ParseValue(
Type *Ty,
Value *&V, PerFunctionState *PFS) {
4071 return ParseValID(ID, PFS) ||
4072 ConvertValIDToValue(Ty, ID, V, PFS);
4075 bool LLParser::ParseTypeAndValue(
Value *&V, PerFunctionState *PFS) {
4077 return ParseType(Ty) ||
4078 ParseValue(Ty, V, PFS);
4081 bool LLParser::ParseTypeAndBasicBlock(
BasicBlock *&BB, LocTy &Loc,
4082 PerFunctionState &PFS) {
4085 if (ParseTypeAndValue(V, PFS))
return true;
4086 if (!isa<BasicBlock>(V))
4087 return Error(Loc,
"expected a basic block");
4088 BB = cast<BasicBlock>(V);
4097 bool LLParser::ParseFunctionHeader(
Function *&Fn,
bool isDefine) {
4103 unsigned DLLStorageClass;
4106 Type *RetType =
nullptr;
4108 if (ParseOptionalLinkage(Linkage) ||
4109 ParseOptionalVisibility(Visibility) ||
4110 ParseOptionalDLLStorageClass(DLLStorageClass) ||
4111 ParseOptionalCallingConv(CC) ||
4112 ParseOptionalReturnAttrs(RetAttrs) ||
4113 ParseType(RetType, RetTypeLoc,
true ))
4122 return Error(LinkageLoc,
"invalid linkage for function definition");
4132 return Error(LinkageLoc,
"invalid linkage for function declaration");
4136 return Error(LinkageLoc,
"invalid function linkage type");
4140 return Error(LinkageLoc,
4141 "symbol with local linkage must have default visibility");
4144 return Error(RetTypeLoc,
"invalid function return type");
4148 std::string FunctionName;
4154 if (NameID != NumberedVals.size())
4155 return TokError(
"function expected to be numbered '%" +
4156 Twine(NumberedVals.size()) +
"'");
4158 return TokError(
"expected function name");
4164 return TokError(
"expected '(' in function argument list");
4169 std::vector<unsigned> FwdRefAttrGrps;
4175 LocTy UnnamedAddrLoc;
4181 if (ParseArgumentList(ArgList, isVarArg) ||
4184 ParseFnAttributeValuePairs(FuncAttrs, FwdRefAttrGrps,
false,
4187 ParseStringConstant(Section)) ||
4188 parseOptionalComdat(FunctionName, C) ||
4189 ParseOptionalAlignment(Alignment) ||
4191 ParseStringConstant(GC)) ||
4193 ParseGlobalTypeAndValue(Prefix)) ||
4195 ParseGlobalTypeAndValue(Prologue)) ||
4197 ParseGlobalTypeAndValue(PersonalityFn)))
4201 return Error(BuiltinLoc,
"'builtin' attribute not valid on function");
4211 std::vector<Type*> ParamTypeList;
4219 for (
unsigned i = 0, e = ArgList.
size(); i != e; ++i) {
4220 ParamTypeList.push_back(ArgList[i].Ty);
4221 if (ArgList[i].Attrs.hasAttributes(i + 1)) {
4235 return Error(RetTypeLoc,
"functions with 'sret' argument must return void");
4242 if (!FunctionName.empty()) {
4245 std::map<std::string, std::pair<GlobalValue*, LocTy> >::iterator FRVI =
4246 ForwardRefVals.find(FunctionName);
4247 if (FRVI != ForwardRefVals.end()) {
4250 return Error(FRVI->second.second,
"invalid forward reference to "
4251 "function as global value!");
4253 return Error(FRVI->second.second,
"invalid forward reference to "
4254 "function '" + FunctionName +
"' with wrong type!");
4256 ForwardRefVals.erase(FRVI);
4259 return Error(NameLoc,
"invalid redefinition of function '" +
4260 FunctionName +
"'");
4262 return Error(NameLoc,
"redefinition of function '@" + FunctionName +
"'");
4268 std::map<unsigned, std::pair<GlobalValue*, LocTy> >::iterator I
4269 = ForwardRefValIDs.find(NumberedVals.size());
4270 if (I != ForwardRefValIDs.end()) {
4271 Fn = cast<Function>(I->second.first);
4273 return Error(NameLoc,
"type of definition and forward reference of '@" +
4274 Twine(NumberedVals.size()) +
"' disagree");
4275 ForwardRefValIDs.erase(I);
4284 if (FunctionName.empty())
4285 NumberedVals.push_back(Fn);
4297 if (!GC.empty()) Fn->
setGC(GC.c_str());
4300 ForwardRefAttrGroups[Fn] = FwdRefAttrGrps;
4304 for (
unsigned i = 0, e = ArgList.
size(); i != e; ++i, ++ArgIt) {
4306 if (ArgList[i].Name.
empty())
continue;
4309 ArgIt->setName(ArgList[i].Name);
4311 if (ArgIt->getName() != ArgList[i].Name)
4312 return Error(ArgList[i].Loc,
"redefinition of argument '%" +
4313 ArgList[i].Name +
"'");
4321 if (FunctionName.empty()) {
4323 ID.
UIntVal = NumberedVals.size() - 1;
4326 ID.
StrVal = FunctionName;
4328 auto Blocks = ForwardRefBlockAddresses.find(ID);
4329 if (Blocks != ForwardRefBlockAddresses.end())
4330 return Error(Blocks->first.Loc,
4331 "cannot take blockaddress inside a declaration");
4335 bool LLParser::PerFunctionState::resolveForwardRefBlockAddresses() {
4345 auto Blocks =
P.ForwardRefBlockAddresses.find(ID);
4346 if (Blocks ==
P.ForwardRefBlockAddresses.end())
4349 for (
const auto &I : Blocks->second) {
4350 const ValID &BBID = I.first;
4354 "Expected local id or name");
4361 return P.Error(BBID.
Loc,
"referenced value is not a basic block");
4367 P.ForwardRefBlockAddresses.erase(Blocks);
4373 bool LLParser::ParseFunctionBody(
Function &Fn) {
4375 return TokError(
"expected '{' in function body");
4379 if (!Fn.
hasName()) FunctionNumber = NumberedVals.size()-1;
4381 PerFunctionState PFS(*
this, Fn, FunctionNumber);
4385 if (PFS.resolveForwardRefBlockAddresses())
4391 return TokError(
"function body requires at least one basic block");
4395 if (ParseBasicBlock(PFS))
return true;
4398 if (ParseUseListOrder(&PFS))
4405 return PFS.FinishFunction();
4410 bool LLParser::ParseBasicBlock(PerFunctionState &PFS) {
4419 BasicBlock *BB = PFS.DefineBB(Name, NameLoc);
4421 return Error(NameLoc,
4422 "unable to create block named '" + Name +
"'");
4424 std::string NameStr;
4438 if (ParseToken(
lltok::equal,
"expected '=' after instruction id"))
4443 if (ParseToken(
lltok::equal,
"expected '=' after instruction name"))
4447 switch (ParseInstruction(Inst, BB, PFS)) {
4449 case InstError:
return true;
4456 if (ParseInstructionMetadata(*Inst))
4459 case InstExtraComma:
4464 if (ParseInstructionMetadata(*Inst))
4470 if (PFS.SetInstName(NameID, NameStr, NameLoc, Inst))
return true;
4471 }
while (!isa<TerminatorInst>(Inst));
4483 PerFunctionState &PFS) {
4486 return TokError(
"found end of file when expecting more instructions");
4492 default:
return Error(Loc,
"expected instruction opcode");
4510 if (ParseArithmetic(Inst, PFS, KeywordVal, 1))
return true;
4512 if (NUW) cast<BinaryOperator>(Inst)->setHasNoUnsignedWrap(
true);
4513 if (NSW) cast<BinaryOperator>(Inst)->setHasNoSignedWrap(
true);
4522 int Res = ParseArithmetic(Inst, PFS, KeywordVal, 2);
4536 if (ParseArithmetic(Inst, PFS, KeywordVal, 1))
return true;
4537 if (Exact) cast<BinaryOperator>(Inst)->setIsExact(
true);
4542 case lltok::kw_srem:
return ParseArithmetic(Inst, PFS, KeywordVal, 1);
4545 case lltok::kw_xor:
return ParseLogical(Inst, PFS, KeywordVal);
4549 int Res = ParseCompare(Inst, PFS, KeywordVal);
4597 bool LLParser::ParseCmpPredicate(
unsigned &
P,
unsigned Opc) {
4598 if (Opc == Instruction::FCmp) {
4600 default:
return TokError(
"expected fcmp predicate (e.g. 'oeq')");
4620 default:
return TokError(
"expected icmp predicate (e.g. 'eq')");
4645 PerFunctionState &PFS) {
4648 if (ParseType(Ty,
true ))
return true;
4650 Type *ResType = PFS.getFunction().getReturnType();
4654 return Error(TypeLoc,
"value doesn't match function result type '" +
4662 if (ParseValue(Ty, RV, PFS))
return true;
4665 return Error(TypeLoc,
"value doesn't match function result type '" +
4676 bool LLParser::ParseBr(
Instruction *&Inst, PerFunctionState &PFS) {
4680 if (ParseTypeAndValue(Op0, Loc, PFS))
return true;
4682 if (
BasicBlock *BB = dyn_cast<BasicBlock>(Op0)) {
4688 return Error(Loc,
"branch condition must have 'i1' type");
4690 if (ParseToken(
lltok::comma,
"expected ',' after branch condition") ||
4691 ParseTypeAndBasicBlock(Op1, Loc, PFS) ||
4692 ParseToken(
lltok::comma,
"expected ',' after true destination") ||
4693 ParseTypeAndBasicBlock(Op2, Loc2, PFS))
4705 bool LLParser::ParseSwitch(
Instruction *&Inst, PerFunctionState &PFS) {
4706 LocTy CondLoc, BBLoc;
4709 if (ParseTypeAndValue(Cond, CondLoc, PFS) ||
4710 ParseToken(
lltok::comma,
"expected ',' after switch condition") ||
4711 ParseTypeAndBasicBlock(DefaultBB, BBLoc, PFS) ||
4716 return Error(CondLoc,
"switch condition must have integer type");
4725 if (ParseTypeAndValue(Constant, CondLoc, PFS) ||
4726 ParseToken(
lltok::comma,
"expected ',' after case value") ||
4727 ParseTypeAndBasicBlock(DestBB, PFS))
4730 if (!SeenCases.
insert(Constant).second)
4731 return Error(CondLoc,
"duplicate case value in switch");
4732 if (!isa<ConstantInt>(Constant))
4733 return Error(CondLoc,
"case value is not a constant integer");
4735 Table.
push_back(std::make_pair(cast<ConstantInt>(Constant), DestBB));
4741 for (
unsigned i = 0, e = Table.
size(); i != e; ++i)
4742 SI->
addCase(Table[i].first, Table[i].second);
4750 bool LLParser::ParseIndirectBr(
Instruction *&Inst, PerFunctionState &PFS) {
4753 if (ParseTypeAndValue(Address, AddrLoc, PFS) ||
4754 ParseToken(
lltok::comma,
"expected ',' after indirectbr address") ||
4759 return Error(AddrLoc,
"indirectbr address must have pointer type");
4766 if (ParseTypeAndBasicBlock(DestBB, PFS))
4771 if (ParseTypeAndBasicBlock(DestBB, PFS))
4777 if (ParseToken(lltok::rsquare,
"expected ']' at end of block list"))
4781 for (
unsigned i = 0, e = DestList.
size(); i != e; ++i)
4791 bool LLParser::ParseInvoke(
Instruction *&Inst, PerFunctionState &PFS) {
4794 std::vector<unsigned> FwdRefAttrGrps;
4797 Type *RetType =
nullptr;
4803 if (ParseOptionalCallingConv(CC) ||
4804 ParseOptionalReturnAttrs(RetAttrs) ||
4805 ParseType(RetType, RetTypeLoc,
true ) ||
4806 ParseValID(CalleeID) ||
4807 ParseParameterList(ArgList, PFS) ||
4808 ParseFnAttributeValuePairs(FnAttrs, FwdRefAttrGrps,
false,
4811 ParseTypeAndBasicBlock(NormalBB, PFS) ||
4813 ParseTypeAndBasicBlock(UnwindBB, PFS))
4822 std::vector<Type*> ParamTypes;
4823 for (
unsigned i = 0, e = ArgList.
size(); i != e; ++i)
4824 ParamTypes.push_back(ArgList[i].V->getType());
4827 return Error(RetTypeLoc,
"Invalid result type for LLVM function");
4850 for (
unsigned i = 0, e = ArgList.
size(); i != e; ++i) {
4851 Type *ExpectedTy =
nullptr;
4855 return Error(ArgList[i].Loc,
"too many arguments specified");
4858 if (ExpectedTy && ExpectedTy != ArgList[i].V->
getType())
4859 return Error(ArgList[i].Loc,
"argument is not of expected type '" +
4862 if (ArgList[i].Attrs.hasAttributes(i + 1)) {
4869 return Error(CallLoc,
"not enough parameters specified for call");
4873 return Error(CallLoc,
"invoke instructions may not have an alignment");
4886 ForwardRefAttrGroups[II] = FwdRefAttrGrps;
4893 bool LLParser::ParseResume(
Instruction *&Inst, PerFunctionState &PFS) {
4895 if (ParseTypeAndValue(Exn, ExnLoc, PFS))
4912 bool LLParser::ParseArithmetic(
Instruction *&Inst, PerFunctionState &PFS,
4915 if (ParseTypeAndValue(LHS, Loc, PFS) ||
4916 ParseToken(
lltok::comma,
"expected ',' in arithmetic operation") ||
4917 ParseValue(LHS->
getType(), RHS, PFS))
4921 switch (OperandType) {
4932 return Error(Loc,
"invalid operand type for instruction");
4940 bool LLParser::ParseLogical(
Instruction *&Inst, PerFunctionState &PFS,
4943 if (ParseTypeAndValue(LHS, Loc, PFS) ||
4944 ParseToken(
lltok::comma,
"expected ',' in logical operation") ||
4945 ParseValue(LHS->
getType(), RHS, PFS))
4949 return Error(Loc,
"instruction requires integer or integer vector operands");
4959 bool LLParser::ParseCompare(
Instruction *&Inst, PerFunctionState &PFS,
4965 if (ParseCmpPredicate(Pred, Opc) ||
4966 ParseTypeAndValue(LHS, Loc, PFS) ||
4967 ParseToken(
lltok::comma,
"expected ',' after compare value") ||
4968 ParseValue(LHS->
getType(), RHS, PFS))
4971 if (Opc == Instruction::FCmp) {
4973 return Error(Loc,
"fcmp requires floating point operands");
4976 assert(Opc == Instruction::ICmp &&
"Unknown opcode for CmpInst!");
4979 return Error(Loc,
"icmp requires integer operands");
4992 bool LLParser::ParseCast(
Instruction *&Inst, PerFunctionState &PFS,
4996 Type *DestTy =
nullptr;
4997 if (ParseTypeAndValue(Op, Loc, PFS) ||
4998 ParseToken(
lltok::kw_to,
"expected 'to' after cast value") ||
5004 return Error(Loc,
"invalid cast opcode for cast from '" +
5014 bool LLParser::ParseSelect(
Instruction *&Inst, PerFunctionState &PFS) {
5016 Value *Op0, *Op1, *Op2;
5017 if (ParseTypeAndValue(Op0, Loc, PFS) ||
5018 ParseToken(
lltok::comma,
"expected ',' after select condition") ||
5019 ParseTypeAndValue(Op1, PFS) ||
5020 ParseToken(
lltok::comma,
"expected ',' after select value") ||
5021 ParseTypeAndValue(Op2, PFS))
5025 return Error(Loc, Reason);
5033 bool LLParser::ParseVA_Arg(
Instruction *&Inst, PerFunctionState &PFS) {
5035 Type *EltTy =
nullptr;
5037 if (ParseTypeAndValue(Op, PFS) ||
5038 ParseToken(
lltok::comma,
"expected ',' after vaarg operand") ||
5039 ParseType(EltTy, TypeLoc))
5043 return Error(TypeLoc,
"va_arg requires operand with first class type");
5051 bool LLParser::ParseExtractElement(
Instruction *&Inst, PerFunctionState &PFS) {
5054 if (ParseTypeAndValue(Op0, Loc, PFS) ||
5055 ParseToken(
lltok::comma,
"expected ',' after extract value") ||
5056 ParseTypeAndValue(Op1, PFS))
5060 return Error(Loc,
"invalid extractelement operands");
5068 bool LLParser::ParseInsertElement(
Instruction *&Inst, PerFunctionState &PFS) {
5070 Value *Op0, *Op1, *Op2;
5071 if (ParseTypeAndValue(Op0, Loc, PFS) ||
5072 ParseToken(
lltok::comma,
"expected ',' after insertelement value") ||
5073 ParseTypeAndValue(Op1, PFS) ||
5074 ParseToken(
lltok::comma,
"expected ',' after insertelement value") ||
5075 ParseTypeAndValue(Op2, PFS))
5079 return Error(Loc,
"invalid insertelement operands");
5087 bool LLParser::ParseShuffleVector(
Instruction *&Inst, PerFunctionState &PFS) {
5089 Value *Op0, *Op1, *Op2;
5090 if (ParseTypeAndValue(Op0, Loc, PFS) ||
5091 ParseToken(
lltok::comma,
"expected ',' after shuffle mask") ||
5092 ParseTypeAndValue(Op1, PFS) ||
5093 ParseToken(
lltok::comma,
"expected ',' after shuffle value") ||
5094 ParseTypeAndValue(Op2, PFS))
5098 return Error(Loc,
"invalid shufflevector operands");
5106 int LLParser::ParsePHI(
Instruction *&Inst, PerFunctionState &PFS) {
5110 if (ParseType(Ty, TypeLoc) ||
5112 ParseValue(Ty, Op0, PFS) ||
5113 ParseToken(
lltok::comma,
"expected ',' after insertelement value") ||
5115 ParseToken(lltok::rsquare,
"expected ']' in phi value list"))
5118 bool AteExtraComma =
false;
5121 PHIVals.
push_back(std::make_pair(Op0, cast<BasicBlock>(Op1)));
5127 AteExtraComma =
true;
5131 if (ParseToken(
lltok::lsquare,
"expected '[' in phi value list") ||
5132 ParseValue(Ty, Op0, PFS) ||
5133 ParseToken(
lltok::comma,
"expected ',' after insertelement value") ||
5135 ParseToken(lltok::rsquare,
"expected ']' in phi value list"))
5140 return Error(TypeLoc,
"phi node must have first class type");
5143 for (
unsigned i = 0, e = PHIVals.
size(); i != e; ++i)
5144 PN->
addIncoming(PHIVals[i].first, PHIVals[i].second);
5146 return AteExtraComma ? InstExtraComma : InstNormal;
5155 bool LLParser::ParseLandingPad(
Instruction *&Inst, PerFunctionState &PFS) {
5158 if (ParseType(Ty, TyLoc))
5171 return TokError(
"expected 'catch' or 'filter' clause type");
5175 if (ParseTypeAndValue(V, VLoc, PFS))
5181 if (isa<ArrayType>(V->
getType()))
5182 Error(VLoc,
"'catch' clause has an invalid type");
5184 if (!isa<ArrayType>(V->
getType()))
5185 Error(VLoc,
"'filter' clause has an invalid type");
5188 Constant *CV =
dyn_cast<Constant>(V);
5190 return Error(VLoc,
"clause argument must be a constant");
5194 Inst = LP.release();
5205 bool LLParser::ParseCall(
Instruction *&Inst, PerFunctionState &PFS,
5208 std::vector<unsigned> FwdRefAttrGrps;
5211 Type *RetType =
nullptr;
5219 ParseOptionalCallingConv(CC) ||
5220 ParseOptionalReturnAttrs(RetAttrs) ||
5221 ParseType(RetType, RetTypeLoc,
true ) ||
5222 ParseValID(CalleeID) ||
5224 PFS.getFunction().isVarArg()) ||
5225 ParseFnAttributeValuePairs(FnAttrs, FwdRefAttrGrps,
false,
5235 std::vector<Type*> ParamTypes;
5236 for (
unsigned i = 0, e = ArgList.
size(); i != e; ++i)
5237 ParamTypes.push_back(ArgList[i].V->getType());
5240 return Error(RetTypeLoc,
"Invalid result type for LLVM function");
5263 for (
unsigned i = 0, e = ArgList.
size(); i != e; ++i) {
5264 Type *ExpectedTy =
nullptr;
5268 return Error(ArgList[i].Loc,
"too many arguments specified");
5271 if (ExpectedTy && ExpectedTy != ArgList[i].V->
getType())
5272 return Error(ArgList[i].Loc,
"argument is not of expected type '" +
5275 if (ArgList[i].Attrs.hasAttributes(i + 1)) {
5282 return Error(CallLoc,
"not enough parameters specified for call");
5286 return Error(CallLoc,
"call instructions may not have an alignment");
5300 ForwardRefAttrGroups[CI] = FwdRefAttrGrps;
5311 int LLParser::ParseAlloc(
Instruction *&Inst, PerFunctionState &PFS) {
5312 Value *Size =
nullptr;
5313 LocTy SizeLoc, TyLoc;
5314 unsigned Alignment = 0;
5319 if (ParseType(Ty, TyLoc))
return true;
5322 return Error(TyLoc,
"invalid type for alloca");
5324 bool AteExtraComma =
false;
5327 if (ParseOptionalAlignment(Alignment))
return true;
5329 AteExtraComma =
true;
5331 if (ParseTypeAndValue(Size, SizeLoc, PFS) ||
5332 ParseOptionalCommaAlign(Alignment, AteExtraComma))
5338 return Error(SizeLoc,
"element count must have integer type");
5343 return AteExtraComma ? InstExtraComma : InstNormal;
5350 int LLParser::ParseLoad(
Instruction *&Inst, PerFunctionState &PFS) {
5352 unsigned Alignment = 0;
5353 bool AteExtraComma =
false;
5354 bool isAtomic =
false;
5371 if (ParseType(Ty) ||
5372 ParseToken(
lltok::comma,
"expected comma after load's type") ||
5373 ParseTypeAndValue(Val, Loc, PFS) ||
5374 ParseScopeAndOrdering(isAtomic, Scope, Ordering) ||
5375 ParseOptionalCommaAlign(Alignment, AteExtraComma))
5379 return Error(Loc,
"load operand must be a pointer to a first class type");
5380 if (isAtomic && !Alignment)
5381 return Error(Loc,
"atomic load must have explicit non-zero alignment");
5383 return Error(Loc,
"atomic load cannot use Release ordering");
5385 if (Ty != cast<PointerType>(Val->
getType())->getElementType())
5386 return Error(ExplicitTypeLoc,
5387 "explicit pointee type doesn't match operand's pointee type");
5389 Inst =
new LoadInst(Ty, Val,
"", isVolatile, Alignment, Ordering, Scope);
5390 return AteExtraComma ? InstExtraComma : InstNormal;
5398 int LLParser::ParseStore(
Instruction *&Inst, PerFunctionState &PFS) {
5400 unsigned Alignment = 0;
5401 bool AteExtraComma =
false;
5402 bool isAtomic =
false;
5411 bool isVolatile =
false;
5417 if (ParseTypeAndValue(Val, Loc, PFS) ||
5418 ParseToken(
lltok::comma,
"expected ',' after store operand") ||
5419 ParseTypeAndValue(Ptr, PtrLoc, PFS) ||
5420 ParseScopeAndOrdering(isAtomic, Scope, Ordering) ||
5421 ParseOptionalCommaAlign(Alignment, AteExtraComma))
5425 return Error(PtrLoc,
"store operand must be a pointer");
5427 return Error(Loc,
"store operand must be a first class value");
5428 if (cast<PointerType>(Ptr->
getType())->getElementType() != Val->
getType())
5429 return Error(Loc,
"stored value and pointer type do not match");
5430 if (isAtomic && !Alignment)
5431 return Error(Loc,
"atomic store must have explicit non-zero alignment");
5433 return Error(Loc,
"atomic store cannot use Acquire ordering");
5435 Inst =
new StoreInst(Val, Ptr, isVolatile, Alignment, Ordering, Scope);
5436 return AteExtraComma ? InstExtraComma : InstNormal;
5442 int LLParser::ParseCmpXchg(
Instruction *&Inst, PerFunctionState &PFS) {
5443 Value *Ptr, *Cmp, *New;
LocTy PtrLoc, CmpLoc, NewLoc;
5444 bool AteExtraComma =
false;
5448 bool isVolatile =
false;
5457 if (ParseTypeAndValue(Ptr, PtrLoc, PFS) ||
5458 ParseToken(
lltok::comma,
"expected ',' after cmpxchg address") ||
5459 ParseTypeAndValue(Cmp, CmpLoc, PFS) ||
5460 ParseToken(
lltok::comma,
"expected ',' after cmpxchg cmp operand") ||
5461 ParseTypeAndValue(New, NewLoc, PFS) ||
5462 ParseScopeAndOrdering(
true , Scope, SuccessOrdering) ||
5463 ParseOrdering(FailureOrdering))
5467 return TokError(
"cmpxchg cannot be unordered");
5468 if (SuccessOrdering < FailureOrdering)
5469 return TokError(
"cmpxchg must be at least as ordered on success as failure");
5471 return TokError(
"cmpxchg failure ordering cannot include release semantics");
5473 return Error(PtrLoc,
"cmpxchg operand must be a pointer");
5474 if (cast<PointerType>(Ptr->
getType())->getElementType() != Cmp->
getType())
5475 return Error(CmpLoc,
"compare value and pointer type do not match");
5476 if (cast<PointerType>(Ptr->
getType())->getElementType() != New->
getType())
5477 return Error(NewLoc,
"new value and pointer type do not match");
5479 return Error(NewLoc,
"cmpxchg operand must be an integer");
5481 if (Size < 8 || (Size & (Size - 1)))
5482 return Error(NewLoc,
"cmpxchg operand must be power-of-two byte-sized"
5486 Ptr, Cmp, New, SuccessOrdering, FailureOrdering, Scope);
5490 return AteExtraComma ? InstExtraComma : InstNormal;
5496 int LLParser::ParseAtomicRMW(
Instruction *&Inst, PerFunctionState &PFS) {
5498 bool AteExtraComma =
false;
5501 bool isVolatile =
false;
5508 default:
return TokError(
"expected binary operation in atomicrmw");
5523 if (ParseTypeAndValue(Ptr, PtrLoc, PFS) ||
5524 ParseToken(
lltok::comma,
"expected ',' after atomicrmw address") ||
5525 ParseTypeAndValue(Val, ValLoc, PFS) ||
5526 ParseScopeAndOrdering(
true , Scope, Ordering))
5530 return TokError(
"atomicrmw cannot be unordered");
5532 return Error(PtrLoc,
"atomicrmw operand must be a pointer");
5533 if (cast<PointerType>(Ptr->
getType())->getElementType() != Val->
getType())
5534 return Error(ValLoc,
"atomicrmw value and pointer type do not match");
5536 return Error(ValLoc,
"atomicrmw operand must be an integer");
5538 if (Size < 8 || (Size & (Size - 1)))
5539 return Error(ValLoc,
"atomicrmw operand must be power-of-two byte-sized"
5546 return AteExtraComma ? InstExtraComma : InstNormal;
5551 int LLParser::ParseFence(
Instruction *&Inst, PerFunctionState &PFS) {
5554 if (ParseScopeAndOrdering(
true , Scope, Ordering))
5558 return TokError(
"fence cannot be unordered");
5560 return TokError(
"fence cannot be monotonic");
5562 Inst =
new FenceInst(Context, Ordering, Scope);
5568 int LLParser::ParseGetElementPtr(
Instruction *&Inst, PerFunctionState &PFS) {
5569 Value *Ptr =
nullptr;
5570 Value *Val =
nullptr;
5577 if (ParseType(Ty) ||
5578 ParseToken(
lltok::comma,
"expected comma after getelementptr's type") ||
5579 ParseTypeAndValue(Ptr, Loc, PFS))
5584 if (!BasePointerType)
5585 return Error(Loc,
"base of getelementptr must be a pointer");
5588 return Error(ExplicitTypeLoc,
5589 "explicit pointee type doesn't match operand's pointee type");
5592 bool AteExtraComma =
false;
5600 AteExtraComma =
true;
5603 if (ParseTypeAndValue(Val, EltLoc, PFS))
return true;
5605 return Error(EltLoc,
"getelementptr index must be an integer");
5609 if (GEPWidth && GEPWidth != ValNumEl)
5610 return Error(EltLoc,
5611 "getelementptr vector index has a wrong number of elements");
5612 GEPWidth = ValNumEl;
5619 return Error(Loc,
"base element of getelementptr must be sized");
5622 return Error(Loc,
"invalid getelementptr indices");
5625 cast<GetElementPtrInst>(Inst)->setIsInBounds(
true);
5626 return AteExtraComma ? InstExtraComma : InstNormal;
5631 int LLParser::ParseExtractValue(
Instruction *&Inst, PerFunctionState &PFS) {
5635 if (ParseTypeAndValue(Val, Loc, PFS) ||
5636 ParseIndexList(Indices, AteExtraComma))
5640 return Error(Loc,
"extractvalue operand must be aggregate type");
5643 return Error(Loc,
"invalid indices for extractvalue");
5645 return AteExtraComma ? InstExtraComma : InstNormal;
5650 int LLParser::ParseInsertValue(
Instruction *&Inst, PerFunctionState &PFS) {
5654 if (ParseTypeAndValue(Val0, Loc0, PFS) ||
5655 ParseToken(
lltok::comma,
"expected comma after insertvalue operand") ||
5656 ParseTypeAndValue(Val1, Loc1, PFS) ||
5657 ParseIndexList(Indices, AteExtraComma))
5661 return Error(Loc0,
"insertvalue operand must be aggregate type");
5665 return Error(Loc0,
"invalid indices for insertvalue");
5666 if (IndexedType != Val1->
getType())
5667 return Error(Loc1,
"insertvalue operand and field disagree in type: '" +
5671 return AteExtraComma ? InstExtraComma : InstNormal;
5698 if (ParseMetadata(MD,
nullptr))
5703 return ParseToken(
lltok::rbrace,
"expected end of metadata node");
5712 return Error(Loc,
"value has no uses");
5714 unsigned NumUses = 0;
5716 for (
const Use &U : V->
uses()) {
5717 if (++NumUses > Indexes.
size())
5719 Order[&U] = Indexes[NumUses - 1];
5722 return Error(Loc,
"value only has one use");
5723 if (Order.
size() != Indexes.
size() || NumUses > Indexes.
size())
5724 return Error(Loc,
"wrong number of indexes, expected " +
5740 return Lex.
Error(
"expected non-empty list of uselistorder indexes");
5745 unsigned Offset = 0;
5747 bool IsOrdered =
true;
5748 assert(Indexes.
empty() &&
"Expected empty order vector");
5751 if (ParseUInt32(Index))
5755 Offset += Index - Indexes.
size();
5756 Max = std::max(Max, Index);
5757 IsOrdered &= Index == Indexes.
size();
5765 if (Indexes.
size() < 2)
5766 return Error(Loc,
"expected >= 2 uselistorder indexes");
5767 if (Offset != 0 || Max >= Indexes.
size())
5768 return Error(Loc,
"expected distinct uselistorder indexes in range [0, size)");
5770 return Error(Loc,
"expected uselistorder indexes to change the order");
5777 bool LLParser::ParseUseListOrder(PerFunctionState *PFS) {
5784 if (ParseTypeAndValue(V, PFS) ||
5785 ParseToken(
lltok::comma,
"expected comma in uselistorder directive") ||
5786 ParseUseListOrderIndexes(Indexes))
5789 return sortUseListOrder(V, Indexes, Loc);
5794 bool LLParser::ParseUseListOrderBB() {
5801 if (ParseValID(Fn) ||
5802 ParseToken(
lltok::comma,
"expected comma in uselistorder_bb directive") ||
5803 ParseValID(Label) ||
5804 ParseToken(
lltok::comma,
"expected comma in uselistorder_bb directive") ||
5805 ParseUseListOrderIndexes(Indexes))
5813 GV = Fn.
UIntVal < NumberedVals.size() ? NumberedVals[Fn.
UIntVal] :
nullptr;
5815 return Error(Fn.
Loc,
"expected function name in uselistorder_bb");
5817 return Error(Fn.
Loc,
"invalid function forward reference in uselistorder_bb");
5820 return Error(Fn.
Loc,
"expected function name in uselistorder_bb");
5822 return Error(Fn.
Loc,
"invalid declaration in uselistorder_bb");
5826 return Error(Label.
Loc,
"invalid numeric label in uselistorder_bb");
5828 return Error(Label.
Loc,
"expected basic block name in uselistorder_bb");
5831 return Error(Label.
Loc,
"invalid basic block in uselistorder_bb");
5832 if (!isa<BasicBlock>(V))
5833 return Error(Label.
Loc,
"expected basic block in uselistorder_bb");
5835 return sortUseListOrder(V, Indexes, Loc);
void setVisibility(VisibilityTypes V)
void setPersonalityFn(Constant *C)
void setAttributes(const AttributeSet &Attrs)
setAttributes - Set the parameter attributes for this invoke.
void sortUseList(Compare Cmp)
Sort the use-list.
void push_back(const T &Elt)
static ConstantInt * getFalse(LLVMContext &Context)
Intel_OCL_BI - Calling conventions for Intel OpenCL built-ins.
The C convention as specified in the x86-64 supplement to the System V ABI, used on most non-Windows ...
const ValueSymbolTable & getValueSymbolTable() const
Get the symbol table of global variable and function identifiers.
static Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true)
getString - This method constructs a CDS and initializes it with a text string.
void setFastMathFlags(FastMathFlags FMF)
Convenience function for setting multiple fast-math flags on this instruction, which must be an opera...
iterator_range< use_iterator > uses()
static IntegerType * getInt1Ty(LLVMContext &C)
void addIncoming(Value *V, BasicBlock *BB)
addIncoming - Add an incoming value to the end of the PHI list
Special purpose, only applies to global arrays.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
*p = old <signed v ? old : v
LLVM Argument representation.
uint64_t getZExtValue() const
Get zero extended value.
ValueT lookup(const KeyT &Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
const APFloat & getAPFloatVal() const
Sign extended before/after call.
static bool isValidOperands(const Value *Vec, const Value *NewElt, const Value *Idx)
isValidOperands - Return true if an insertelement instruction can be formed with the specified operan...
static const fltSemantics IEEEdouble
Force argument to be passed in register.
Function is called early and/or often, so lazy binding isn't worthwhile.
static ResumeInst * Create(Value *Exn, Instruction *InsertBefore=nullptr)
FenceInst - an instruction for ordering other memory operations.
ARM_APCS - ARM Procedure Calling Standard calling convention (obsolete, but still used on some target...
Same, but only replaced by something equivalent.
AtomicCmpXchgInst - an instruction that atomically checks whether a specified value is in a memory lo...
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.
Nested function static chain.
Type::subtype_iterator param_iterator
void addCase(ConstantInt *OnVal, BasicBlock *Dest)
addCase - Add an entry to the switch instruction...
PTX_Device - Call to a PTX device function.
Type * getValueType() const
uint64_t getAlignment() const
Retrieve the alignment attribute, if it exists.
void addOperand(MDNode *M)
CallInst - This class represents a function call, abstracting a target machine's calling convention...
void UpgradeMDStringConstant(std::string &String)
Upgrade a metadata string constant in place.
static PointerType * get(Type *ElementType, unsigned AddressSpace)
PointerType::get - This constructs a pointer to an object of the specified type in a numbered address...
*p = old <unsigned v ? old : v
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList, bool InBounds=false, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
static Constant * getExtractElement(Constant *Vec, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
void setVolatile(bool V)
setVolatile - 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)
Source said inlining was desirable.
*p = old >unsigned v ? old : v
ShuffleVectorInst - This instruction constructs a fixed permutation of two input vectors.
Externally visible function.
NamedMDNode * getOrInsertNamedMetadata(StringRef Name)
Return the named MDNode in the module with the specified name.
uint64_t getLimitedValue(uint64_t Limit=~0ULL) const
If this value is smaller than the specified limit, return it, otherwise return the limit value...
void setDataLayout(StringRef Desc)
Set the data layout.
1 1 1 0 True if unordered or not equal
The data referenced by the COMDAT must be the same size.
AttrBuilder & addDereferenceableAttr(uint64_t Bytes)
This turns the number of dereferenceable bytes into the form used internally in Attribute.
static bool isValidReturnType(Type *RetTy)
isValidReturnType - Return true if the specified type is valid as a return type.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
LoadInst - an instruction for reading from memory.
ELFYAML::ELF_STV Visibility
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > Tys=None)
Return the function type for an intrinsic.
AttrBuilder & addAttribute(Attribute::AttrKind Val)
Add an attribute to the builder.
AtomicRMWInst - an instruction that atomically reads a memory location, combines it with another valu...
static bool isValidArgumentType(Type *ArgTy)
isValidArgumentType - Return true if the specified type is valid as an argument type.
void setAlignment(unsigned Align)
bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return true if the attribute exists at the given index.
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.
static LandingPadInst * Create(Type *RetTy, unsigned NumReservedClauses, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedClauses is a hint for the number of incoming clauses that this landingpad w...
static bool isLocalLinkage(LinkageTypes Linkage)
static Constant * getInsertElement(Constant *Vec, Constant *Elt, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
void setVolatile(bool V)
setVolatile - Specify whether this is a volatile RMW or not.
static Constant * getNullValue(Type *Ty)
StringRef getName() const
Return a constant reference to the value's name.
global Merge global variables
void setCallingConv(CallingConv::ID CC)
static ReturnInst * Create(LLVMContext &C, Value *retVal=nullptr, Instruction *InsertBefore=nullptr)
bool Run()
Run: module ::= toplevelentity*.
1 0 0 1 True if unordered or equal
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
std::map< unsigned, TrackingMDNodeRef > MetadataNodes
AttributeSet removeAttribute(LLVMContext &C, unsigned Index, Attribute::AttrKind Attr) const
Remove the specified attribute at the specified index from this attribute list.
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...
void push_back(NodeTy *val)
AttrBuilder & addDereferenceableOrNullAttr(uint64_t Bytes)
This turns the number of dereferenceable_or_null bytes into the form used internally in Attribute...
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static CallInst * Create(Value *Func, ArrayRef< Value * > Args, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
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 ...
MSP430_INTR - Calling convention used for MSP430 interrupt routines.
StructType - Class to represent struct types.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
A Use represents the edge between a Value definition and its users.
param_iterator param_end() const
static Constant * get(ArrayRef< Constant * > V)
void setThreadLocalMode(ThreadLocalMode Val)
Number of individual test Apply this number of consecutive mutations to each input exit after the first new interesting input is found the minimized corpus is saved into the first input directory Number of jobs to run If Reload the main corpus periodically to get new units discovered by other processes Read the given input file
0 1 0 1 True if ordered and less than or equal
void setMetadata(unsigned KindID, MDNode *MD)
Set a particular kind of metadata attachment.
TypeID
Definitions of all of the base types for the Type system.
bool isSized(SmallPtrSetImpl< const Type * > *Visited=nullptr) const
isSized - Return true if it makes sense to take the size of this type.
The linker may choose any COMDAT.
Function must be in a unwind table.
void setName(const Twine &Name)
Change the name of the value.
static ConstantInt * ExtractElement(Constant *V, Constant *Idx)
static const unsigned MaximumAlignment
void setDLLStorageClass(DLLStorageClassTypes C)
Function does not access memory.
Hidden pointer to structure to return.
Function creates no aliases of pointer.
static bool isValidOperands(const Value *V1, const Value *V2, const Value *Mask)
isValidOperands - Return true if a shufflevector instruction can be formed with the specified operand...
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. ...
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Return a distinct node.
FunctionType - Class to represent function types.
static Type * getLabelTy(LLVMContext &C)
globalsmodref Simple mod ref analysis for globals
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
LLVMContext & getContext() const
getContext - Return the LLVMContext in which this type was uniqued.
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
BinOp
This enumeration lists the possible modifications atomicrmw can make.
bool isHalfTy() const
isHalfTy - Return true if this is 'half', a 16-bit IEEE fp type.
ArrayType - Class to represent array types.
VisibilityTypes
An enumeration for the kinds of visibility of global values.
static bool isValidElementType(Type *ElemTy)
isValidElementType - 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.
PTX_Kernel - Call to a PTX kernel.
static Constant * getSelect(Constant *C, Constant *V1, Constant *V2, Type *OnlyIfReducedTy=nullptr)
Select constant expr.
void setComdat(Comdat *C)
bool isFirstClassType() const
isFirstClassType - 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)
FunctionType::get - 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
isFloatingPointTy - Return true if this is one of the six floating point types
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...
StoreInst - an instruction for storing to memory.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
bool isArrayTy() const
isArrayTy - True if this is an instance of ArrayType.
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Return a temporary node.
ValueSymbolTable & getValueSymbolTable()
getSymbolTable() - Return the symbol table...
Type * getElementType() const
size_t size() const
size - Get the array size.
Considered to not alias after call.
PointerType - Class to represent pointers.
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
ExternalWeak linkage description.
static Constant * getInsertValue(Constant *Agg, Constant *Val, ArrayRef< unsigned > Idxs, Type *OnlyIfReducedTy=nullptr)
void setCallingConv(CallingConv::ID CC)
bool isIntOrIntVectorTy() const
isIntOrIntVectorTy - Return true if this is an integer type or a vector of integer types...
StringRef filename(StringRef path)
Get filename.
Same, but only replaced by something equivalent.
SPIR_FUNC - Calling convention for SPIR non-kernel device functions.
No other Module may specify this COMDAT.
static ConstantPointerNull * get(PointerType *T)
get() - Static factory methods - Return objects of the specified value
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
ARM_AAPCS_VFP - Same as ARM_AAPCS, but uses hard floating point ABI.
bool isVectorTy() const
isVectorTy - True if this is an instance of VectorType.
static GlobalAlias * create(PointerType *Ty, 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 BlockAddress * get(Function *F, BasicBlock *BB)
get - Return a BlockAddress for the specified function and basic block.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
UnreachableInst - This function has undefined behavior.
This is an important base class in LLVM.
ResumeInst - Resume the propagation of an exception.
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
IndirectBrInst - Indirect Branch Instruction.
bool isFloatTy() const
isFloatTy - 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)
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.
X86_StdCall - stdcall is the calling conventions mostly used by the Win32 API.
Return value is always equal to this argument.
static bool isValidLinkage(LinkageTypes L)
static Constant * getShuffleVector(Constant *V1, Constant *V2, Constant *Mask, Type *OnlyIfReducedTy=nullptr)
Pass structure in an alloca.
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.
opStatus convert(const fltSemantics &, roundingMode, bool *)
APFloat::convert - convert a value of one floating point type to another.
DLLStorageClassTypes
Storage classes of global values for PE targets.
Zero extended before/after call.
0 1 1 1 True if ordered (no nans)
static bool isValueValidForType(Type *Ty, const APFloat &V)
isValueValidForType - 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...
Function doesn't unwind stack.
static Constant * get(StructType *T, ArrayRef< Constant * > V)
The data referenced by the COMDAT must be the same.
void setTailCallKind(TailCallKind TCK)
Marks function as being in a cold path.
std::vector< GlobalValue * > GlobalValues
void setConstant(bool Val)
unsigned getLanguage(StringRef LanguageString)
1 1 1 1 Always true (always folded)
Mark the function as not returning.
static bool isValidElementType(Type *ElemTy)
isValidElementType - Return true if the specified type is valid as a element type.
bool isPointerTy() const
isPointerTy - True if this is an instance of PointerType.
static UndefValue * get(Type *T)
get() - Static factory methods - Return an 'undef' object of the specified type.
bool Error(LocTy L, const Twine &Msg) const
Comdat * getOrInsertComdat(StringRef Name)
Return the Comdat in the module with the specified name.
VAArgInst - This class represents the va_arg llvm instruction, which returns an argument of the speci...
LLVMContext & getContext() const
All values hold a context through their type.
static bool isAtomic(Instruction *I)
bool isFPOrFPVectorTy() const
isFPOrFPVectorTy - Return true if this is a FP type or a vector of FP.
ARM_AAPCS - ARM Architecture Procedure Calling Standard calling convention (aka EABI).
void setBody(ArrayRef< Type * > Elements, bool isPacked=false)
setBody - 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
static const fltSemantics IEEEhalf
std::string & str()
Flushes the stream contents to the target string and returns the string's reference.
Call cannot be duplicated.
void setMetadata(unsigned KindID, MDNode *Node)
setMetadata - Set the metadata of the specified kind to the specified node.
static IndirectBrInst * Create(Value *Address, unsigned NumDests, Instruction *InsertBefore=nullptr)
Pointer is known to be not null.
An imported module (C++ using directive or similar).
Constant ** ConstantStructElts
unsigned getTag(StringRef TagString)
global_iterator global_end()
const FunctionListType & getFunctionList() const
Get the Module's list of functions (constant).
static Constant * getFCmp(unsigned short pred, Constant *LHS, Constant *RHS, bool OnlyIfReduced=false)
0 0 1 0 True if ordered and greater than
static InvokeInst * Create(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
const BasicBlockListType & getBasicBlockList() const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
static PointerType * getUnqual(Type *ElementType)
PointerType::getUnqual - This constructs a pointer to an object of the specified type in the generic ...
static bool isValidElementType(Type *ElemTy)
isValidElementType - Return true if the specified type is valid as a element type.
static bool isValidVisibilityForLinkage(unsigned V, unsigned L)
void setSelectionKind(SelectionKind Val)
SPIR_KERNEL - Calling convention for SPIR kernel functions.
bool isFunctionTy() const
isFunctionTy - True if this is an instance of FunctionType.
APSInt LLVM_ATTRIBUTE_UNUSED_RESULT extOrTrunc(uint32_t width) const
const std::string & getStrVal() const
unsigned getVectorNumElements() const
static StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
StructType::get - 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.
1 1 0 0 True if unordered or less than
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Keep one copy of function when linking (inline)
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
Callee is recognized as a builtin, despite nobuiltin attribute on its declaration.
void setUnnamedAddr(bool Val)
#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.
X86_FastCall - 'fast' analog of X86_StdCall.
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)
get() - This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in the specified type.
static ConstantInt * getTrue(LLVMContext &Context)
void setLinkage(LinkageTypes LT)
void splice(iterator where, iplist &L2)
Alignment of parameter (5 bits) stored as log2 of alignment with +1 bias 0 means unaligned (different...
AttributeSet removeAttributes(LLVMContext &C, unsigned Index, AttributeSet Attrs) const
Remove the specified attributes at the specified index from this attribute list.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
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.
Function must not be optimized.
bool isIntegerTy() const
isIntegerTy - 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)
Function only reads from memory.
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
void setGC(const char *Str)
Generic tagged DWARF-like metadata node.
A utility class that uses RAII to save and restore the value of a variable.
FunctionNumber(functionNumber)
const Type * getScalarType() const LLVM_READONLY
getScalarType - If this is a vector type, return the element type, otherwise return 'this'...
static unsigned getFlag(StringRef Flag)
static Type * getIndexedType(Type *Ty, ArrayRef< Value * > IdxList)
getIndexedType - Returns the type of the element that would be loaded with a load instruction with th...
Type array for a subprogram.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
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.
static const fltSemantics IEEEsingle
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().
bool isAggregateType() const
isAggregateType - Return true if the type is an aggregate type.
OperandType
Types of operands to CF instructions.
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)
isValidElementType - Return true if the specified type is valid as a element type.
static InsertValueInst * Create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
MSVC calling convention that passes vectors and vector aggregates in SSE registers.
Callee isn't recognized as a builtin.
const ComdatSymTabType & getComdatSymbolTable() const
Get the Module's symbol table for COMDATs (constant).
enum llvm::ValID::@195 Kind
Fast - This calling convention attempts to make calls as fast as possible (e.g.
void setPrologueData(Constant *PrologueData)
void appendModuleInlineAsm(StringRef Asm)
Append to the module-scope inline assembly blocks.
lltok::Kind getKind() const
Deduce function attributes
0 1 1 0 True if ordered and operands are unequal
static ArrayType * get(Type *ElementType, uint64_t NumElements)
ArrayType::get - This static method is the primary way to construct an ArrayType. ...
void setTargetTriple(StringRef T)
Set the target triple.
X86_ThisCall - Similar to X86_StdCall.
Keep one copy of named function when linking (weak)
Rename collisions when linking (static functions).
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
void setAttributes(AttributeSet attrs)
Set the attribute list for this Function.
Function to be imported from DLL.
Funciton can access memory only using pointers based on its arguments.
const APSInt & getAPSIntVal() const
void addDestination(BasicBlock *Dest)
addDestination - Add a destination.
AttrBuilder & merge(const AttrBuilder &B)
Add the attributes from the builder.
SwitchInst - Multiway switch.
void setAttributes(const AttributeSet &Attrs)
setAttributes - Set the parameter attributes for this call.
Function can return twice.
const ARM::ArchExtKind Kind
A raw_ostream that writes to an std::string.
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
getPrimitiveSizeInBits - Return the basic size of this type if it is a primitive type.
bool isLabelTy() const
isLabelTy - 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)
VectorType::get - This static method is the primary way to construct an VectorType.
static StructType * create(LLVMContext &Context, StringRef Name)
StructType::create - This creates an identified struct.
Disable implicit floating point insts.
virtual void eraseFromParent()=0
This method unlinks 'this' from the containing module and deletes it.
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)
The C convention as implemented on Windows/x86-64.
InvokeInst - Invoke instruction.
void UpgradeInstWithTBAATag(Instruction *I)
If the TBAA tag for the given instruction uses the scalar TBAA format, we upgrade it to the struct-pa...
#define PARSE_MD_FIELDS()
C - The default llvm calling convention, compatible with C.
bool isPowerOf2_32(uint32_t Value)
isPowerOf2_32 - This function returns true if the argument is a power of two > 0. ...
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)
static bool isVolatile(Instruction *Inst)
Represents a location in source code.
AttributeSet addAttributes(LLVMContext &C, unsigned Index, AttributeSet Attrs) const
Add attributes to the attribute set at the given index.
0 0 1 1 True if ordered and greater than or equal
Can only be moved to control-equivalent blocks.
unsigned getMDKindID(StringRef Name) const
Return a unique non-zero ID for the specified metadata kind.
Stack protection required.
static IntegerType * getInt8Ty(LLVMContext &C)
void setSection(StringRef S)
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.
Build jump-instruction tables and replace refs.
0 0 0 0 Always false (always folded)
bool isVoidTy() const
isVoidTy - Return true if this is 'void'.
AllocaInst - an instruction to allocate memory on the stack.
bool empty() const
empty - Check if the string is empty.
Basic type, like 'int' or 'float'.
bool isMetadataTy() const
isMetadataTy - Return true if this is 'metadata'.
void setPrefixData(Constant *PrefixData)
AttributeSet getFnAttributes() const
The function attributes are returned.
static const char * areInvalidOperands(Value *Cond, Value *True, Value *False)
areInvalidOperands - Return a string if the specified operands are invalid for a select operation...
Function must be optimized for size first.