42 return ParseTopLevelEntities() ||
43 ValidateEndOfModule();
48 bool LLParser::ValidateEndOfModule() {
50 if (!ForwardRefInstMetadata.empty()) {
52 I = ForwardRefInstMetadata.begin(), E = ForwardRefInstMetadata.end();
55 const std::vector<MDRef> &MDList =
I->second;
57 for (
unsigned i = 0, e = MDList.size(); i != e; ++i) {
58 unsigned SlotNo = MDList[i].MDSlot;
60 if (SlotNo >= NumberedMetadata.size() || NumberedMetadata[SlotNo] == 0)
61 return Error(MDList[i].Loc,
"use of undefined metadata '!" +
63 Inst->
setMetadata(MDList[i].MDKind, NumberedMetadata[SlotNo]);
66 ForwardRefInstMetadata.clear();
69 for (
unsigned I = 0, E = InstsWithTBAATag.size();
I < E;
I++)
73 for (std::map<
Value*, std::vector<unsigned> >::iterator
74 I = ForwardRefAttrGroups.begin(), E = ForwardRefAttrGroups.end();
77 std::vector<unsigned> &Vec = I->second;
80 for (std::vector<unsigned>::iterator VI = Vec.begin(), VE = Vec.end();
82 B.
merge(NumberedAttrBuilders[*VI]);
84 if (
Function *Fn = dyn_cast<Function>(V)) {
88 AS.getFnAttributes());
94 if (FnAttrs.hasAlignmentAttr()) {
95 Fn->setAlignment(FnAttrs.getAlignment());
100 AttributeSet::get(Context,
101 AttributeSet::FunctionIndex,
103 Fn->setAttributes(AS);
104 }
else if (
CallInst *CI = dyn_cast<CallInst>(V)) {
108 AS.getFnAttributes());
111 AttributeSet::get(Context,
112 AttributeSet::FunctionIndex,
114 CI->setAttributes(AS);
115 }
else if (
InvokeInst *II = dyn_cast<InvokeInst>(V)) {
119 AS.getFnAttributes());
122 AttributeSet::get(Context,
123 AttributeSet::FunctionIndex,
125 II->setAttributes(AS);
133 while (!ForwardRefBlockAddresses.empty()) {
136 const ValID &Fn = ForwardRefBlockAddresses.begin()->first;
139 else if (Fn.
UIntVal < NumberedVals.size())
140 TheFn = dyn_cast<Function>(NumberedVals[Fn.
UIntVal]);
143 return Error(Fn.
Loc,
"unknown function referenced by blockaddress");
146 if (ResolveForwardRefBlockAddresses(TheFn,
147 ForwardRefBlockAddresses.begin()->second,
151 ForwardRefBlockAddresses.erase(ForwardRefBlockAddresses.begin());
154 for (
unsigned i = 0, e = NumberedTypes.size(); i != e; ++i)
155 if (NumberedTypes[i].second.isValid())
156 return Error(NumberedTypes[i].second,
157 "use of undefined type '%" +
Twine(i) +
"'");
159 for (
StringMap<std::pair<Type*, LocTy> >::iterator I =
160 NamedTypes.begin(), E = NamedTypes.end(); I != E; ++
I)
161 if (I->second.second.isValid())
162 return Error(I->second.second,
163 "use of undefined type named '" + I->getKey() +
"'");
165 if (!ForwardRefVals.empty())
166 return Error(ForwardRefVals.begin()->second.second,
167 "use of undefined value '@" + ForwardRefVals.begin()->first +
170 if (!ForwardRefValIDs.empty())
171 return Error(ForwardRefValIDs.begin()->second.second,
172 "use of undefined value '@" +
173 Twine(ForwardRefValIDs.begin()->first) +
"'");
175 if (!ForwardRefMDNodes.empty())
176 return Error(ForwardRefMDNodes.begin()->second.second,
177 "use of undefined metadata '!" +
178 Twine(ForwardRefMDNodes.begin()->first) +
"'");
188 bool LLParser::ResolveForwardRefBlockAddresses(
Function *TheFn,
189 std::vector<std::pair<ValID, GlobalValue*> > &Refs,
190 PerFunctionState *PFS) {
192 for (
unsigned i = 0, e = Refs.size(); i != e; ++i) {
196 Res = PFS->GetBB(Refs[i].first.StrVal, Refs[i].first.Loc);
198 Res = PFS->GetBB(Refs[i].first.UIntVal, Refs[i].first.Loc);
200 return Error(Refs[i].first.Loc,
201 "cannot take address of numeric label after the function is defined");
203 Res = dyn_cast_or_null<BasicBlock>(
208 return Error(Refs[i].first.Loc,
209 "referenced value is not a basic block");
213 Refs[i].second->replaceAllUsesWith(BA);
214 Refs[i].second->eraseFromParent();
224 bool LLParser::ParseTopLevelEntities() {
227 default:
return TokError(
"expected top-level entity");
238 case lltok::exclaim:
if (ParseStandaloneMetadata())
return true;
break;
260 unsigned Linkage, Visibility;
261 if (ParseOptionalLinkage(Linkage) ||
262 ParseOptionalVisibility(Visibility) ||
263 ParseGlobal(
"",
SMLoc(), Linkage,
true, Visibility))
271 if (ParseOptionalVisibility(Visibility) ||
272 ParseGlobal(
"",
SMLoc(), 0,
false, Visibility))
281 if (ParseGlobal(
"",
SMLoc(), 0,
false, 0))
return true;
292 bool LLParser::ParseModuleAsm() {
298 ParseStringConstant(AsmStr))
return true;
307 bool LLParser::ParseTargetDefinition() {
311 default:
return TokError(
"unknown target property");
314 if (ParseToken(
lltok::equal,
"expected '=' after target triple") ||
315 ParseStringConstant(Str))
321 if (ParseToken(
lltok::equal,
"expected '=' after target datalayout") ||
322 ParseStringConstant(Str))
333 bool LLParser::ParseDepLibs() {
336 if (ParseToken(
lltok::equal,
"expected '=' after deplibs") ||
345 if (ParseStringConstant(Str))
return true;
353 bool LLParser::ParseUnnamedType() {
358 if (ParseToken(
lltok::equal,
"expected '=' after name") ||
362 if (TypeID >= NumberedTypes.size())
363 NumberedTypes.resize(TypeID+1);
366 if (ParseStructDefinition(TypeLoc,
"",
367 NumberedTypes[TypeID], Result))
return true;
369 if (!isa<StructType>(Result)) {
370 std::pair<Type*, LocTy> &Entry = NumberedTypes[
TypeID];
372 return Error(TypeLoc,
"non-struct types may not be recursive");
373 Entry.first = Result;
374 Entry.second =
SMLoc();
383 bool LLParser::ParseNamedType() {
388 if (ParseToken(
lltok::equal,
"expected '=' after name") ||
393 if (ParseStructDefinition(NameLoc, Name,
394 NamedTypes[Name], Result))
return true;
396 if (!isa<StructType>(Result)) {
397 std::pair<Type*, LocTy> &Entry = NamedTypes[
Name];
399 return Error(NameLoc,
"non-struct types may not be recursive");
400 Entry.first = Result;
401 Entry.second =
SMLoc();
410 bool LLParser::ParseDeclare() {
415 return ParseFunctionHeader(F,
false);
420 bool LLParser::ParseDefine() {
425 return ParseFunctionHeader(F,
true) ||
426 ParseFunctionBody(*F);
432 bool LLParser::ParseGlobalType(
bool &IsConstant) {
439 return TokError(
"expected 'global' or 'constant'");
450 bool LLParser::ParseUnnamedGlobal() {
451 unsigned VarID = NumberedVals.size();
458 return Error(Lex.
getLoc(),
"variable expected to be numbered '%" +
462 if (ParseToken(
lltok::equal,
"expected '=' after name"))
467 unsigned Linkage, Visibility;
468 if (ParseOptionalLinkage(Linkage, HasLinkage) ||
469 ParseOptionalVisibility(Visibility))
473 return ParseGlobal(Name, NameLoc, Linkage, HasLinkage, Visibility);
474 return ParseAlias(Name, NameLoc, Visibility);
480 bool LLParser::ParseNamedGlobal() {
487 unsigned Linkage, Visibility;
488 if (ParseToken(
lltok::equal,
"expected '=' in global variable") ||
489 ParseOptionalLinkage(Linkage, HasLinkage) ||
490 ParseOptionalVisibility(Visibility))
494 return ParseGlobal(Name, NameLoc, Linkage, HasLinkage, Visibility);
495 return ParseAlias(Name, NameLoc, Visibility);
500 bool LLParser::ParseMDString(
MDString *&Result) {
502 if (ParseStringConstant(Str))
return true;
512 bool LLParser::ParseMDNodeID(
MDNode *&Result,
unsigned &SlotNo) {
514 if (ParseUInt32(SlotNo))
return true;
517 if (SlotNo < NumberedMetadata.size() && NumberedMetadata[SlotNo] != 0)
518 Result = NumberedMetadata[SlotNo];
524 bool LLParser::ParseMDNodeID(
MDNode *&Result) {
527 if (ParseMDNodeID(Result, MID))
return true;
530 if (Result)
return false;
534 ForwardRefMDNodes[MID] = std::make_pair(FwdNode, Lex.
getLoc());
536 if (NumberedMetadata.size() <= MID)
537 NumberedMetadata.resize(MID+1);
538 NumberedMetadata[MID] = FwdNode;
545 bool LLParser::ParseNamedMetadata() {
562 if (ParseMDNodeID(N))
return true;
566 if (ParseToken(
lltok::rbrace,
"expected end of metadata node"))
574 bool LLParser::ParseStandaloneMetadata() {
577 unsigned MetadataID = 0;
582 if (ParseUInt32(MetadataID) ||
584 ParseType(Ty, TyLoc) ||
587 ParseMDNodeVector(Elts, NULL) ||
594 std::map<unsigned, std::pair<TrackingVH<MDNode>,
LocTy> >::iterator
595 FI = ForwardRefMDNodes.find(MetadataID);
596 if (FI != ForwardRefMDNodes.end()) {
597 MDNode *Temp = FI->second.first;
600 ForwardRefMDNodes.erase(FI);
602 assert(NumberedMetadata[MetadataID] == Init &&
"Tracking VH didn't work");
604 if (MetadataID >= NumberedMetadata.size())
605 NumberedMetadata.resize(MetadataID+1);
607 if (NumberedMetadata[MetadataID] != 0)
608 return TokError(
"Metadata id is already used");
609 NumberedMetadata[MetadataID] = Init;
624 bool LLParser::ParseAlias(
const std::string &Name, LocTy NameLoc,
625 unsigned Visibility) {
630 if (ParseOptionalLinkage(L))
636 return Error(LinkageLoc,
"invalid linkage type for alias");
642 if (ParseGlobalTypeAndValue(Aliasee))
return true;
646 if (ParseValID(ID))
return true;
648 return Error(AliaseeLoc,
"invalid aliasee");
653 return Error(AliaseeLoc,
"alias must have pointer type");
666 std::map<std::string, std::pair<GlobalValue*, LocTy> >::iterator
667 I = ForwardRefVals.find(Name);
668 if (I == ForwardRefVals.end())
669 return Error(NameLoc,
"redefinition of global named '@" + Name +
"'");
673 if (Val->getType() != GA->
getType())
674 return Error(NameLoc,
675 "forward reference and definition of alias have different types");
679 Val->replaceAllUsesWith(GA);
680 Val->eraseFromParent();
681 ForwardRefVals.erase(I);
686 assert(GA->
getName() == Name &&
"Should not be a name conflict!");
701 bool LLParser::ParseGlobal(
const std::string &Name, LocTy NameLoc,
702 unsigned Linkage,
bool HasLinkage,
703 unsigned Visibility) {
705 bool IsConstant, UnnamedAddr, IsExternallyInitialized;
707 LocTy UnnamedAddrLoc;
708 LocTy IsExternallyInitializedLoc;
712 if (ParseOptionalThreadLocal(TLM) ||
713 ParseOptionalAddrSpace(AddrSpace) ||
717 IsExternallyInitialized,
718 &IsExternallyInitializedLoc) ||
719 ParseGlobalType(IsConstant) ||
720 ParseType(Ty, TyLoc))
729 if (ParseGlobalValue(Ty, Init))
734 return Error(TyLoc,
"invalid type for global variable");
741 if (!ForwardRefVals.erase(Name) || !isa<GlobalValue>(GVal))
742 return Error(NameLoc,
"redefinition of global '@" + Name +
"'");
743 GV = cast<GlobalVariable>(GVal);
746 std::map<unsigned, std::pair<GlobalValue*, LocTy> >::iterator
747 I = ForwardRefValIDs.find(NumberedVals.size());
748 if (I != ForwardRefValIDs.end()) {
749 GV = cast<GlobalVariable>(I->second.first);
750 ForwardRefValIDs.erase(I);
761 "forward reference and definition of global have different types");
768 NumberedVals.push_back(GV);
791 if (ParseOptionalAlignment(Alignment))
return true;
794 TokError(
"unknown global variable property!");
803 bool LLParser::ParseUnnamedAttrGrp() {
810 std::vector<unsigned> unused;
816 ParseFnAttributeValuePairs(NumberedAttrBuilders[VarID], unused,
true,
818 ParseToken(
lltok::rbrace,
"expected end of attribute group"))
821 if (!NumberedAttrBuilders[VarID].hasAttributes())
822 return Error(AttrGrpLoc,
"attribute group has no attributes");
829 bool LLParser::ParseFnAttributeValuePairs(
AttrBuilder &B,
830 std::vector<unsigned> &FwdRefAttrGrps,
831 bool inAttrGrp, LocTy &BuiltinLoc) {
832 bool HaveError =
false;
839 BuiltinLoc = Lex.
getLoc();
842 if (!inAttrGrp)
return HaveError;
843 return Error(Lex.
getLoc(),
"unterminated attribute group");
855 "cannot have an attribute group reference in an attribute group");
858 if (inAttrGrp)
break;
861 FwdRefAttrGrps.push_back(AttrGrpNum);
870 ParseStringConstant(Val))
886 ParseUInt32(Alignment))
889 if (ParseOptionalAlignment(Alignment))
900 ParseUInt32(Alignment))
903 if (ParseOptionalStackAlignment(Alignment))
942 "invalid use of attribute on a function");
952 "invalid use of parameter-only attribute on a function");
971 Error(Loc,
"global variable reference must have pointer type");
982 std::map<std::string, std::pair<GlobalValue*, LocTy> >::iterator
983 I = ForwardRefVals.find(Name);
984 if (I != ForwardRefVals.end())
985 Val = I->second.first;
990 if (Val->
getType() == Ty)
return Val;
991 Error(Loc,
"'@" + Name +
"' defined with type '" +
1006 ForwardRefVals[
Name] = std::make_pair(FwdVal, Loc);
1010 GlobalValue *LLParser::GetGlobalVal(
unsigned ID,
Type *Ty, LocTy Loc) {
1013 Error(Loc,
"global variable reference must have pointer type");
1017 GlobalValue *Val = ID < NumberedVals.size() ? NumberedVals[
ID] : 0;
1022 std::map<unsigned, std::pair<GlobalValue*, LocTy> >::iterator
1023 I = ForwardRefValIDs.find(ID);
1024 if (I != ForwardRefValIDs.end())
1025 Val = I->second.first;
1030 if (Val->
getType() == Ty)
return Val;
1031 Error(Loc,
"'@" +
Twine(ID) +
"' defined with type '" +
1044 ForwardRefValIDs[
ID] = std::make_pair(FwdVal, Loc);
1055 bool LLParser::ParseToken(
lltok::Kind T,
const char *ErrMsg) {
1057 return TokError(ErrMsg);
1064 bool LLParser::ParseStringConstant(std::string &Result) {
1066 return TokError(
"expected string constant");
1074 bool LLParser::ParseUInt32(
unsigned &Val) {
1076 return TokError(
"expected integer");
1078 if (Val64 !=
unsigned(Val64))
1079 return TokError(
"expected 32-bit integer (too large)");
1092 return TokError(
"expected localdynamic, initialexec or localexec");
1120 return ParseTLSModel(TLM) ||
1121 ParseToken(
lltok::rparen,
"expected ')' after thread local model");
1129 bool LLParser::ParseOptionalAddrSpace(
unsigned &AddrSpace) {
1133 return ParseToken(
lltok::lparen,
"expected '(' in address space") ||
1134 ParseUInt32(AddrSpace) ||
1139 bool LLParser::ParseOptionalParamAttrs(
AttrBuilder &B) {
1140 bool HaveError =
false;
1151 if (ParseOptionalAlignment(Alignment))
1192 HaveError |= Error(Lex.
getLoc(),
"invalid use of function-only attribute");
1201 bool LLParser::ParseOptionalReturnAttrs(
AttrBuilder &B) {
1202 bool HaveError =
false;
1223 HaveError |= Error(Lex.
getLoc(),
"invalid use of parameter-only attribute");
1251 HaveError |= Error(Lex.
getLoc(),
"invalid use of function-only attribute");
1256 HaveError |= Error(Lex.
getLoc(),
"invalid use of attribute on return type");
1280 bool LLParser::ParseOptionalLinkage(
unsigned &Res,
bool &HasLinkage) {
1315 bool LLParser::ParseOptionalVisibility(
unsigned &Res) {
1372 unsigned ArbitraryCC;
1374 if (ParseUInt32(ArbitraryCC))
1387 bool LLParser::ParseInstructionMetadata(
Instruction *Inst,
1388 PerFunctionState *PFS) {
1391 return TokError(
"expected metadata after comma");
1409 if (ParseMetadataListValue(ID, PFS))
1414 unsigned NodeID = 0;
1415 if (ParseMDNodeID(Node, NodeID))
1421 MDRef R = { Loc, MDK, NodeID };
1423 ForwardRefInstMetadata[Inst].push_back(R);
1428 InstsWithTBAATag.push_back(Inst);
1438 bool LLParser::ParseOptionalAlignment(
unsigned &Alignment) {
1443 if (ParseUInt32(Alignment))
return true;
1445 return Error(AlignLoc,
"alignment is not a power of two");
1447 return Error(AlignLoc,
"huge alignments are not supported yet");
1457 bool LLParser::ParseOptionalCommaAlign(
unsigned &Alignment,
1458 bool &AteExtraComma) {
1459 AteExtraComma =
false;
1463 AteExtraComma =
true;
1468 return Error(Lex.
getLoc(),
"expected metadata or 'align'");
1470 if (ParseOptionalAlignment(Alignment))
return true;
1490 default:
return TokError(
"Expected ordering on atomic instruction");
1505 bool LLParser::ParseOptionalStackAlignment(
unsigned &Alignment) {
1511 return Error(ParenLoc,
"expected '('");
1513 if (ParseUInt32(Alignment))
return true;
1516 return Error(ParenLoc,
"expected ')'");
1518 return Error(AlignLoc,
"stack alignment is not a power of two");
1532 bool &AteExtraComma) {
1533 AteExtraComma =
false;
1536 return TokError(
"expected ',' as start of index list");
1540 AteExtraComma =
true;
1544 if (ParseUInt32(Idx))
return true;
1556 bool LLParser::ParseType(
Type *&Result,
bool AllowVoid) {
1560 return TokError(
"expected type");
1568 if (ParseAnonStructType(Result,
false))
1574 if (ParseArrayVectorType(Result,
false))
1581 if (ParseAnonStructType(Result,
true) ||
1582 ParseToken(
lltok::greater,
"expected '>' at end of packed struct"))
1584 }
else if (ParseArrayVectorType(Result,
true))
1589 std::pair<Type*, LocTy> &Entry = NamedTypes[Lex.
getStrVal()];
1593 if (Entry.first == 0) {
1595 Entry.second = Lex.
getLoc();
1597 Result = Entry.first;
1604 if (Lex.
getUIntVal() >= NumberedTypes.size())
1606 std::pair<Type*, LocTy> &Entry = NumberedTypes[Lex.
getUIntVal()];
1610 if (Entry.first == 0) {
1612 Entry.second = Lex.
getLoc();
1614 Result = Entry.first;
1625 if (!AllowVoid && Result->
isVoidTy())
1626 return Error(TypeLoc,
"void type only allowed for function results");
1632 return TokError(
"basic block pointers are invalid");
1634 return TokError(
"pointers to void are invalid - use i8* instead");
1636 return TokError(
"pointer to this type is invalid");
1644 return TokError(
"basic block pointers are invalid");
1646 return TokError(
"pointers to void are invalid; use i8* instead");
1648 return TokError(
"pointer to this type is invalid");
1650 if (ParseOptionalAddrSpace(AddrSpace) ||
1651 ParseToken(
lltok::star,
"expected '*' in address space"))
1660 if (ParseFunctionType(Result))
1673 PerFunctionState &PFS) {
1677 unsigned AttrIndex = 1;
1680 if (!ArgList.
empty() &&
1681 ParseToken(
lltok::comma,
"expected ',' in argument list"))
1689 if (ParseType(ArgTy, ArgLoc))
1693 if (ParseOptionalParamAttrs(ArgAttrs) || ParseValue(ArgTy, V, PFS))
1732 if (ParseType(ArgTy) ||
1733 ParseOptionalParamAttrs(Attrs))
return true;
1736 return Error(TypeLoc,
"argument can not have void type");
1744 return Error(TypeLoc,
"invalid type for function argument");
1746 unsigned AttrIndex = 1;
1747 ArgList.
push_back(ArgInfo(TypeLoc, ArgTy,
1749 AttrIndex++, Attrs), Name));
1760 if (ParseType(ArgTy) || ParseOptionalParamAttrs(Attrs))
return true;
1763 return Error(TypeLoc,
"argument can not have void type");
1773 return Error(TypeLoc,
"invalid type for function argument");
1775 ArgList.
push_back(ArgInfo(TypeLoc, ArgTy,
1777 AttrIndex++, Attrs),
1782 return ParseToken(
lltok::rparen,
"expected ')' at end of argument list");
1787 bool LLParser::ParseFunctionType(
Type *&Result) {
1791 return TokError(
"invalid function return type");
1795 if (ParseArgumentList(ArgList, isVarArg))
1799 for (
unsigned i = 0, e = ArgList.
size(); i != e; ++i) {
1800 if (!ArgList[i].Name.
empty())
1801 return Error(ArgList[i].Loc,
"argument name invalid in function type");
1803 return Error(ArgList[i].Loc,
1804 "argument attributes invalid in function type");
1808 for (
unsigned i = 0, e = ArgList.
size(); i != e; ++i)
1817 bool LLParser::ParseAnonStructType(
Type *&Result,
bool Packed) {
1819 if (ParseStructBody(Elts))
return true;
1826 bool LLParser::ParseStructDefinition(
SMLoc TypeLoc,
StringRef Name,
1827 std::pair<Type*, LocTy> &Entry,
1830 if (Entry.first && !Entry.second.isValid())
1831 return Error(TypeLoc,
"redefinition of type");
1837 Entry.second =
SMLoc();
1840 if (Entry.first == 0)
1842 ResultTy = Entry.first;
1854 return Error(TypeLoc,
"forward references to non-struct type");
1858 return ParseArrayVectorType(ResultTy,
true);
1859 return ParseType(ResultTy);
1863 Entry.second =
SMLoc();
1866 if (Entry.first == 0)
1869 StructType *STy = cast<StructType>(Entry.first);
1872 if (ParseStructBody(Body) ||
1873 (isPacked && ParseToken(
lltok::greater,
"expected '>' in packed struct")))
1898 if (ParseType(Ty))
return true;
1902 return Error(EltTyLoc,
"invalid element type for struct");
1906 if (ParseType(Ty))
return true;
1909 return Error(EltTyLoc,
"invalid element type for struct");
1914 return ParseToken(
lltok::rbrace,
"expected '}' at end of struct");
1922 bool LLParser::ParseArrayVectorType(
Type *&Result,
bool isVector) {
1925 return TokError(
"expected number in address space");
1931 if (ParseToken(
lltok::kw_x,
"expected 'x' after element count"))
1936 if (ParseType(EltTy))
return true;
1939 "expected end of sequential type"))
1944 return Error(SizeLoc,
"zero element vector is illegal");
1945 if ((
unsigned)Size != Size)
1946 return Error(SizeLoc,
"size too large for vector");
1948 return Error(TypeLoc,
"invalid vector element type");
1952 return Error(TypeLoc,
"invalid array element type");
1970 NumberedVals.push_back(AI);
1973 LLParser::PerFunctionState::~PerFunctionState() {
1975 for (std::map<std::string, std::pair<Value*, LocTy> >::iterator
1976 I = ForwardRefVals.begin(), E = ForwardRefVals.end(); I != E; ++
I)
1977 if (!isa<BasicBlock>(I->second.first)) {
1978 I->second.first->replaceAllUsesWith(
1980 delete I->second.first;
1981 I->second.first = 0;
1984 for (std::map<
unsigned, std::pair<Value*, LocTy> >::iterator
1985 I = ForwardRefValIDs.begin(), E = ForwardRefValIDs.end(); I != E; ++
I)
1986 if (!isa<BasicBlock>(I->second.first)) {
1987 I->second.first->replaceAllUsesWith(
1989 delete I->second.first;
1990 I->second.first = 0;
1994 bool LLParser::PerFunctionState::FinishFunction() {
1996 if (!
P.ForwardRefBlockAddresses.empty()) {
1998 if (!
F.getName().empty()) {
2000 FunctionID.
StrVal =
F.getName();
2006 std::map<ValID, std::vector<std::pair<ValID, GlobalValue*> > >::iterator
2007 FRBAI =
P.ForwardRefBlockAddresses.find(FunctionID);
2008 if (FRBAI !=
P.ForwardRefBlockAddresses.end()) {
2010 if (
P.ResolveForwardRefBlockAddresses(&
F, FRBAI->second,
this))
2013 P.ForwardRefBlockAddresses.erase(FRBAI);
2017 if (!ForwardRefVals.empty())
2018 return P.Error(ForwardRefVals.begin()->second.second,
2019 "use of undefined value '%" + ForwardRefVals.begin()->first +
2021 if (!ForwardRefValIDs.empty())
2022 return P.Error(ForwardRefValIDs.begin()->second.second,
2023 "use of undefined value '%" +
2024 Twine(ForwardRefValIDs.begin()->first) +
"'");
2032 Value *LLParser::PerFunctionState::GetVal(
const std::string &Name,
2033 Type *Ty, LocTy Loc) {
2035 Value *Val =
F.getValueSymbolTable().lookup(Name);
2040 std::map<std::string, std::pair<Value*, LocTy> >::iterator
2041 I = ForwardRefVals.find(Name);
2042 if (I != ForwardRefVals.end())
2043 Val = I->second.first;
2048 if (Val->
getType() == Ty)
return Val;
2050 P.Error(Loc,
"'%" + Name +
"' is not a basic block");
2052 P.Error(Loc,
"'%" + Name +
"' defined with type '" +
2059 P.Error(Loc,
"invalid use of a non-first-class type");
2070 ForwardRefVals[
Name] = std::make_pair(FwdVal, Loc);
2074 Value *LLParser::PerFunctionState::GetVal(
unsigned ID,
Type *Ty,
2077 Value *Val = ID < NumberedVals.size() ? NumberedVals[
ID] : 0;
2082 std::map<unsigned, std::pair<Value*, LocTy> >::iterator
2083 I = ForwardRefValIDs.find(ID);
2084 if (I != ForwardRefValIDs.end())
2085 Val = I->second.first;
2090 if (Val->
getType() == Ty)
return Val;
2092 P.Error(Loc,
"'%" +
Twine(ID) +
"' is not a basic block");
2094 P.Error(Loc,
"'%" +
Twine(ID) +
"' defined with type '" +
2100 P.Error(Loc,
"invalid use of a non-first-class type");
2111 ForwardRefValIDs[
ID] = std::make_pair(FwdVal, Loc);
2117 bool LLParser::PerFunctionState::SetInstName(
int NameID,
2118 const std::string &NameStr,
2122 if (NameID != -1 || !NameStr.empty())
2123 return P.Error(NameLoc,
"instructions returning void cannot have a name");
2129 if (NameStr.empty()) {
2132 NameID = NumberedVals.size();
2134 if (
unsigned(NameID) != NumberedVals.size())
2135 return P.Error(NameLoc,
"instruction expected to be numbered '%" +
2136 Twine(NumberedVals.size()) +
"'");
2138 std::map<unsigned, std::pair<Value*, LocTy> >::iterator FI =
2139 ForwardRefValIDs.find(NameID);
2140 if (FI != ForwardRefValIDs.end()) {
2141 if (FI->second.first->getType() != Inst->
getType())
2142 return P.Error(NameLoc,
"instruction forward referenced with type '" +
2144 FI->second.first->replaceAllUsesWith(Inst);
2145 delete FI->second.first;
2146 ForwardRefValIDs.erase(FI);
2149 NumberedVals.push_back(Inst);
2154 std::map<std::string, std::pair<Value*, LocTy> >::iterator
2155 FI = ForwardRefVals.find(NameStr);
2156 if (FI != ForwardRefVals.end()) {
2157 if (FI->second.first->getType() != Inst->
getType())
2158 return P.Error(NameLoc,
"instruction forward referenced with type '" +
2160 FI->second.first->replaceAllUsesWith(Inst);
2161 delete FI->second.first;
2162 ForwardRefVals.erase(FI);
2168 if (Inst->
getName() != NameStr)
2169 return P.Error(NameLoc,
"multiple definition of local value named '" +
2176 BasicBlock *LLParser::PerFunctionState::GetBB(
const std::string &Name,
2178 return cast_or_null<BasicBlock>(GetVal(Name,
2182 BasicBlock *LLParser::PerFunctionState::GetBB(
unsigned ID, LocTy Loc) {
2183 return cast_or_null<BasicBlock>(GetVal(ID,
2190 BasicBlock *LLParser::PerFunctionState::DefineBB(
const std::string &Name,
2194 BB = GetBB(NumberedVals.size(), Loc);
2196 BB = GetBB(Name, Loc);
2197 if (BB == 0)
return 0;
2201 F.getBasicBlockList().splice(
F.end(),
F.getBasicBlockList(), BB);
2205 ForwardRefValIDs.erase(NumberedVals.size());
2206 NumberedVals.push_back(BB);
2209 ForwardRefVals.erase(Name);
2225 bool LLParser::ParseValID(
ValID &ID, PerFunctionState *PFS) {
2228 default:
return TokError(
"expected value token");
2246 return ParseMetadataValue(ID, PFS);
2271 if (ParseGlobalValueVector(Elts) ||
2272 ParseToken(
lltok::rbrace,
"expected end of struct constant"))
2289 if (ParseGlobalValueVector(Elts) ||
2291 ParseToken(
lltok::rbrace,
"expected end of packed struct")) ||
2295 if (isPackedStruct) {
2304 return Error(ID.
Loc,
"constant vector must not be empty");
2307 !Elts[0]->getType()->isFloatingPointTy() &&
2308 !Elts[0]->getType()->isPointerTy())
2309 return Error(FirstEltLoc,
2310 "vector elements must have integer, pointer or floating point type");
2313 for (
unsigned i = 1, e = Elts.
size(); i != e; ++i)
2314 if (Elts[i]->
getType() != Elts[0]->getType())
2315 return Error(FirstEltLoc,
2316 "vector element #" +
Twine(i) +
2327 if (ParseGlobalValueVector(Elts) ||
2328 ParseToken(lltok::rsquare,
"expected end of array constant"))
2340 return Error(FirstEltLoc,
"invalid array element type: " +
2346 for (
unsigned i = 0, e = Elts.
size(); i != e; ++i) {
2347 if (Elts[i]->
getType() != Elts[0]->getType())
2348 return Error(FirstEltLoc,
2349 "array element #" +
Twine(i) +
2368 bool HasSideEffect, AlignStack, AsmDialect;
2373 ParseStringConstant(ID.
StrVal) ||
2374 ParseToken(
lltok::comma,
"expected comma in inline asm expression") ||
2379 (
unsigned(AsmDialect)<<2);
2390 if (ParseToken(
lltok::lparen,
"expected '(' in block address expression") ||
2392 ParseToken(
lltok::comma,
"expected comma in block address expression")||
2393 ParseValID(Label) ||
2394 ParseToken(
lltok::rparen,
"expected ')' in block address expression"))
2398 return Error(Fn.
Loc,
"expected function name in blockaddress");
2400 return Error(Label.
Loc,
"expected basic block name in blockaddress");
2406 ForwardRefBlockAddresses[Fn].push_back(std::make_pair(Label, FwdRef));
2429 if (ParseToken(
lltok::lparen,
"expected '(' after constantexpr cast") ||
2430 ParseGlobalTypeAndValue(SrcVal) ||
2431 ParseToken(
lltok::kw_to,
"expected 'to' in constantexpr cast") ||
2432 ParseType(DestTy) ||
2433 ParseToken(
lltok::rparen,
"expected ')' at end of constantexpr cast"))
2436 return Error(ID.
Loc,
"invalid cast opcode for cast from '" +
2448 if (ParseToken(
lltok::lparen,
"expected '(' in extractvalue constantexpr")||
2449 ParseGlobalTypeAndValue(Val) ||
2450 ParseIndexList(Indices) ||
2451 ParseToken(
lltok::rparen,
"expected ')' in extractvalue constantexpr"))
2455 return Error(ID.
Loc,
"extractvalue operand must be aggregate type");
2457 return Error(ID.
Loc,
"invalid indices for extractvalue");
2466 if (ParseToken(
lltok::lparen,
"expected '(' in insertvalue constantexpr")||
2467 ParseGlobalTypeAndValue(Val0) ||
2468 ParseToken(
lltok::comma,
"expected comma in insertvalue constantexpr")||
2469 ParseGlobalTypeAndValue(Val1) ||
2470 ParseIndexList(Indices) ||
2471 ParseToken(
lltok::rparen,
"expected ')' in insertvalue constantexpr"))
2474 return Error(ID.
Loc,
"insertvalue operand must be aggregate type");
2476 return Error(ID.
Loc,
"invalid indices for insertvalue");
2486 if (ParseCmpPredicate(PredVal, Opc) ||
2487 ParseToken(
lltok::lparen,
"expected '(' in compare constantexpr") ||
2488 ParseGlobalTypeAndValue(Val0) ||
2489 ParseToken(
lltok::comma,
"expected comma in compare constantexpr") ||
2490 ParseGlobalTypeAndValue(Val1) ||
2491 ParseToken(
lltok::rparen,
"expected ')' in compare constantexpr"))
2495 return Error(ID.
Loc,
"compare operands must have the same type");
2499 if (Opc == Instruction::FCmp) {
2501 return Error(ID.
Loc,
"fcmp requires floating point operands");
2504 assert(Opc == Instruction::ICmp &&
"Unexpected opcode for CmpInst!");
2507 return Error(ID.
Loc,
"icmp requires pointer or integer operands");
2537 if (Opc == Instruction::Add || Opc == Instruction::Sub ||
2538 Opc == Instruction::Mul || Opc == Instruction::Shl) {
2546 }
else if (Opc == Instruction::SDiv || Opc == Instruction::UDiv ||
2547 Opc == Instruction::LShr || Opc == Instruction::AShr) {
2551 if (ParseToken(
lltok::lparen,
"expected '(' in binary constantexpr") ||
2552 ParseGlobalTypeAndValue(Val0) ||
2553 ParseToken(
lltok::comma,
"expected comma in binary constantexpr") ||
2554 ParseGlobalTypeAndValue(Val1) ||
2555 ParseToken(
lltok::rparen,
"expected ')' in binary constantexpr"))
2558 return Error(ID.
Loc,
"operands of constexpr must have same type");
2561 return Error(ModifierLoc,
"nuw only applies to integer operations");
2563 return Error(ModifierLoc,
"nsw only applies to integer operations");
2567 case Instruction::Add:
2568 case Instruction::Sub:
2569 case Instruction::Mul:
2570 case Instruction::UDiv:
2571 case Instruction::SDiv:
2572 case Instruction::URem:
2573 case Instruction::SRem:
2574 case Instruction::Shl:
2575 case Instruction::AShr:
2576 case Instruction::LShr:
2578 return Error(ID.
Loc,
"constexpr requires integer operands");
2580 case Instruction::FAdd:
2581 case Instruction::FSub:
2582 case Instruction::FMul:
2583 case Instruction::FDiv:
2584 case Instruction::FRem:
2586 return Error(ID.
Loc,
"constexpr requires fp operands");
2607 if (ParseToken(
lltok::lparen,
"expected '(' in logical constantexpr") ||
2608 ParseGlobalTypeAndValue(Val0) ||
2609 ParseToken(
lltok::comma,
"expected comma in logical constantexpr") ||
2610 ParseGlobalTypeAndValue(Val1) ||
2611 ParseToken(
lltok::rparen,
"expected ')' in logical constantexpr"))
2614 return Error(ID.
Loc,
"operands of constexpr must have same type");
2616 return Error(ID.
Loc,
2617 "constexpr requires integer or integer vector operands");
2630 bool InBounds =
false;
2632 if (Opc == Instruction::GetElementPtr)
2634 if (ParseToken(
lltok::lparen,
"expected '(' in constantexpr") ||
2635 ParseGlobalValueVector(Elts) ||
2639 if (Opc == Instruction::GetElementPtr) {
2640 if (Elts.
size() == 0 ||
2641 !Elts[0]->getType()->getScalarType()->isPointerTy())
2642 return Error(ID.
Loc,
"getelementptr requires pointer operand");
2646 return Error(ID.
Loc,
"invalid indices for getelementptr");
2650 if (Elts.
size() != 3)
2651 return Error(ID.
Loc,
"expected three operands to select");
2654 return Error(ID.
Loc, Reason);
2656 }
else if (Opc == Instruction::ShuffleVector) {
2657 if (Elts.
size() != 3)
2658 return Error(ID.
Loc,
"expected three operands to shufflevector");
2660 return Error(ID.
Loc,
"invalid operands to shufflevector");
2664 if (Elts.
size() != 2)
2665 return Error(ID.
Loc,
"expected two operands to extractelement");
2667 return Error(ID.
Loc,
"invalid extractelement operands");
2670 assert(Opc == Instruction::InsertElement &&
"Unknown opcode");
2671 if (Elts.
size() != 3)
2672 return Error(ID.
Loc,
"expected three operands to insertelement");
2674 return Error(ID.
Loc,
"invalid insertelement operands");
2693 bool Parsed = ParseValID(ID) ||
2694 ConvertValIDToValue(Ty, ID, V, NULL);
2695 if (V && !(C = dyn_cast<Constant>(V)))
2696 return Error(ID.
Loc,
"global values must be constants");
2700 bool LLParser::ParseGlobalTypeAndValue(
Constant *&V) {
2702 return ParseType(Ty) ||
2703 ParseGlobalValue(Ty, V);
2712 Lex.
getKind() == lltok::rsquare ||
2718 if (ParseGlobalTypeAndValue(C))
return true;
2722 if (ParseGlobalTypeAndValue(C))
return true;
2729 bool LLParser::ParseMetadataListValue(
ValID &ID, PerFunctionState *PFS) {
2734 if (ParseMDNodeVector(Elts, PFS) ||
2747 bool LLParser::ParseMetadataValue(
ValID &ID, PerFunctionState *PFS) {
2754 return ParseMetadataListValue(ID, PFS);
2759 if (ParseMDNodeID(ID.
MDNodeVal))
return true;
2776 bool LLParser::ConvertValIDToValue(
Type *Ty,
ValID &ID,
Value *&V,
2777 PerFunctionState *PFS) {
2779 return Error(ID.
Loc,
"functions are not values, refer to them as pointers");
2783 if (!PFS)
return Error(ID.
Loc,
"invalid use of function-local name");
2787 if (!PFS)
return Error(ID.
Loc,
"invalid use of function-local name");
2795 return Error(ID.
Loc,
"invalid type for inline asm constraint string");
2802 return Error(ID.
Loc,
"metadata value must have metadata type");
2807 return Error(ID.
Loc,
"metadata value must have metadata type");
2811 V = GetGlobalVal(ID.
StrVal, Ty, ID.
Loc);
2818 return Error(ID.
Loc,
"integer constant must have integer type");
2825 return Error(ID.
Loc,
"floating point constant invalid for type");
2841 return Error(ID.
Loc,
"floating point constant does not have type '" +
2847 return Error(ID.
Loc,
"null must be a pointer type");
2853 return Error(ID.
Loc,
"invalid type for undef constant");
2857 if (!Ty->
isArrayTy() || cast<ArrayType>(Ty)->getNumElements() != 0)
2858 return Error(ID.
Loc,
"invalid empty array initializer");
2864 return Error(ID.
Loc,
"invalid type for null constant");
2869 return Error(ID.
Loc,
"constant expression type mismatch");
2877 return Error(ID.
Loc,
2878 "initializer with struct type has wrong # elements");
2880 return Error(ID.
Loc,
"packed'ness of initializer and type don't match");
2883 for (
unsigned i = 0, e = ID.
UIntVal; i != e; ++i)
2885 return Error(ID.
Loc,
"element " +
Twine(i) +
2886 " of struct initializer doesn't match struct element type");
2891 return Error(ID.
Loc,
"constant expression type mismatch");
2897 bool LLParser::ParseValue(
Type *Ty,
Value *&V, PerFunctionState *PFS) {
2900 return ParseValID(ID, PFS) ||
2901 ConvertValIDToValue(Ty, ID, V, PFS);
2904 bool LLParser::ParseTypeAndValue(
Value *&V, PerFunctionState *PFS) {
2906 return ParseType(Ty) ||
2907 ParseValue(Ty, V, PFS);
2910 bool LLParser::ParseTypeAndBasicBlock(
BasicBlock *&BB, LocTy &Loc,
2911 PerFunctionState &PFS) {
2914 if (ParseTypeAndValue(V, PFS))
return true;
2915 if (!isa<BasicBlock>(V))
2916 return Error(Loc,
"expected a basic block");
2917 BB = cast<BasicBlock>(V);
2926 bool LLParser::ParseFunctionHeader(
Function *&Fn,
bool isDefine) {
2931 unsigned Visibility;
2936 if (ParseOptionalLinkage(Linkage) ||
2937 ParseOptionalVisibility(Visibility) ||
2938 ParseOptionalCallingConv(CC) ||
2939 ParseOptionalReturnAttrs(RetAttrs) ||
2940 ParseType(RetType, RetTypeLoc,
true ))
2950 return Error(LinkageLoc,
"invalid linkage for function definition");
2963 return Error(LinkageLoc,
"invalid linkage for function declaration");
2967 return Error(LinkageLoc,
"invalid function linkage type");
2971 return Error(RetTypeLoc,
"invalid function return type");
2975 std::string FunctionName;
2981 if (NameID != NumberedVals.size())
2982 return TokError(
"function expected to be numbered '%" +
2983 Twine(NumberedVals.size()) +
"'");
2985 return TokError(
"expected function name");
2991 return TokError(
"expected '(' in function argument list");
2996 std::vector<unsigned> FwdRefAttrGrps;
3002 LocTy UnnamedAddrLoc;
3005 if (ParseArgumentList(ArgList, isVarArg) ||
3008 ParseFnAttributeValuePairs(FuncAttrs, FwdRefAttrGrps,
false,
3011 ParseStringConstant(Section)) ||
3012 ParseOptionalAlignment(Alignment) ||
3014 ParseStringConstant(GC)) ||
3016 ParseGlobalTypeAndValue(Prefix)))
3020 return Error(BuiltinLoc,
"'builtin' attribute not valid on function");
3030 std::vector<Type*> ParamTypeList;
3035 AttributeSet::ReturnIndex,
3038 for (
unsigned i = 0, e = ArgList.
size(); i != e; ++i) {
3039 ParamTypeList.push_back(ArgList[i].Ty);
3040 if (ArgList[i].Attrs.hasAttributes(i + 1)) {
3048 AttributeSet::FunctionIndex,
3054 return Error(RetTypeLoc,
"functions with 'sret' argument must return void");
3061 if (!FunctionName.empty()) {
3064 std::map<std::string, std::pair<GlobalValue*, LocTy> >::iterator FRVI =
3065 ForwardRefVals.find(FunctionName);
3066 if (FRVI != ForwardRefVals.end()) {
3069 return Error(FRVI->second.second,
"invalid forward reference to "
3070 "function as global value!");
3072 return Error(FRVI->second.second,
"invalid forward reference to "
3073 "function '" + FunctionName +
"' with wrong type!");
3075 ForwardRefVals.erase(FRVI);
3078 return Error(NameLoc,
"invalid redefinition of function '" +
3079 FunctionName +
"'");
3081 return Error(NameLoc,
"redefinition of function '@" + FunctionName +
"'");
3087 std::map<unsigned, std::pair<GlobalValue*, LocTy> >::iterator I
3088 = ForwardRefValIDs.find(NumberedVals.size());
3089 if (I != ForwardRefValIDs.end()) {
3090 Fn = cast<Function>(I->second.first);
3092 return Error(NameLoc,
"type of definition and forward reference of '@" +
3093 Twine(NumberedVals.size()) +
"' disagree");
3094 ForwardRefValIDs.erase(I);
3103 if (FunctionName.empty())
3104 NumberedVals.push_back(Fn);
3113 if (!GC.empty()) Fn->
setGC(GC.c_str());
3115 ForwardRefAttrGroups[Fn] = FwdRefAttrGrps;
3119 for (
unsigned i = 0, e = ArgList.
size(); i != e; ++i, ++ArgIt) {
3121 if (ArgList[i].Name.
empty())
continue;
3124 ArgIt->setName(ArgList[i].Name);
3126 if (ArgIt->getName() != ArgList[i].Name)
3127 return Error(ArgList[i].Loc,
"redefinition of argument '%" +
3128 ArgList[i].Name +
"'");
3138 bool LLParser::ParseFunctionBody(
Function &Fn) {
3140 return TokError(
"expected '{' in function body");
3144 if (!Fn.
hasName()) FunctionNumber = NumberedVals.size()-1;
3146 PerFunctionState PFS(*
this, Fn, FunctionNumber);
3150 return TokError(
"function body requires at least one basic block");
3153 if (ParseBasicBlock(PFS))
return true;
3159 return PFS.FinishFunction();
3164 bool LLParser::ParseBasicBlock(PerFunctionState &PFS) {
3173 BasicBlock *BB = PFS.DefineBB(Name, NameLoc);
3174 if (BB == 0)
return true;
3176 std::string NameStr;
3190 if (ParseToken(
lltok::equal,
"expected '=' after instruction id"))
3195 if (ParseToken(
lltok::equal,
"expected '=' after instruction name"))
3199 switch (ParseInstruction(Inst, BB, PFS)) {
3201 case InstError:
return true;
3208 if (ParseInstructionMetadata(Inst, &PFS))
3211 case InstExtraComma:
3216 if (ParseInstructionMetadata(Inst, &PFS))
3222 if (PFS.SetInstName(NameID, NameStr, NameLoc, Inst))
return true;
3223 }
while (!isa<TerminatorInst>(Inst));
3235 PerFunctionState &PFS) {
3238 return TokError(
"found end of file when expecting more instructions");
3244 default:
return Error(Loc,
"expected instruction opcode");
3262 if (ParseArithmetic(Inst, PFS, KeywordVal, 1))
return true;
3264 if (NUW) cast<BinaryOperator>(Inst)->setHasNoUnsignedWrap(
true);
3265 if (NSW) cast<BinaryOperator>(Inst)->setHasNoSignedWrap(
true);
3274 int Res = ParseArithmetic(Inst, PFS, KeywordVal, 2);
3288 if (ParseArithmetic(Inst, PFS, KeywordVal, 1))
return true;
3289 if (Exact) cast<BinaryOperator>(Inst)->setIsExact(
true);
3294 case lltok::kw_srem:
return ParseArithmetic(Inst, PFS, KeywordVal, 1);
3297 case lltok::kw_xor:
return ParseLogical(Inst, PFS, KeywordVal);
3338 bool LLParser::ParseCmpPredicate(
unsigned &
P,
unsigned Opc) {
3339 if (Opc == Instruction::FCmp) {
3341 default:
return TokError(
"expected fcmp predicate (e.g. 'oeq')");
3361 default:
return TokError(
"expected icmp predicate (e.g. 'eq')");
3386 PerFunctionState &PFS) {
3389 if (ParseType(Ty,
true ))
return true;
3391 Type *ResType = PFS.getFunction().getReturnType();
3395 return Error(TypeLoc,
"value doesn't match function result type '" +
3403 if (ParseValue(Ty, RV, PFS))
return true;
3406 return Error(TypeLoc,
"value doesn't match function result type '" +
3417 bool LLParser::ParseBr(
Instruction *&Inst, PerFunctionState &PFS) {
3421 if (ParseTypeAndValue(Op0, Loc, PFS))
return true;
3423 if (
BasicBlock *BB = dyn_cast<BasicBlock>(Op0)) {
3429 return Error(Loc,
"branch condition must have 'i1' type");
3431 if (ParseToken(
lltok::comma,
"expected ',' after branch condition") ||
3432 ParseTypeAndBasicBlock(Op1, Loc, PFS) ||
3433 ParseToken(
lltok::comma,
"expected ',' after true destination") ||
3434 ParseTypeAndBasicBlock(Op2, Loc2, PFS))
3446 bool LLParser::ParseSwitch(
Instruction *&Inst, PerFunctionState &PFS) {
3447 LocTy CondLoc, BBLoc;
3450 if (ParseTypeAndValue(Cond, CondLoc, PFS) ||
3451 ParseToken(
lltok::comma,
"expected ',' after switch condition") ||
3452 ParseTypeAndBasicBlock(DefaultBB, BBLoc, PFS) ||
3457 return Error(CondLoc,
"switch condition must have integer type");
3466 if (ParseTypeAndValue(Constant, CondLoc, PFS) ||
3467 ParseToken(
lltok::comma,
"expected ',' after case value") ||
3468 ParseTypeAndBasicBlock(DestBB, PFS))
3471 if (!SeenCases.
insert(Constant))
3472 return Error(CondLoc,
"duplicate case value in switch");
3473 if (!isa<ConstantInt>(Constant))
3474 return Error(CondLoc,
"case value is not a constant integer");
3476 Table.
push_back(std::make_pair(cast<ConstantInt>(Constant), DestBB));
3482 for (
unsigned i = 0, e = Table.
size(); i != e; ++i)
3483 SI->
addCase(Table[i].first, Table[i].second);
3491 bool LLParser::ParseIndirectBr(
Instruction *&Inst, PerFunctionState &PFS) {
3494 if (ParseTypeAndValue(Address, AddrLoc, PFS) ||
3495 ParseToken(
lltok::comma,
"expected ',' after indirectbr address") ||
3500 return Error(AddrLoc,
"indirectbr address must have pointer type");
3507 if (ParseTypeAndBasicBlock(DestBB, PFS))
3512 if (ParseTypeAndBasicBlock(DestBB, PFS))
3518 if (ParseToken(lltok::rsquare,
"expected ']' at end of block list"))
3522 for (
unsigned i = 0, e = DestList.
size(); i != e; ++i)
3532 bool LLParser::ParseInvoke(
Instruction *&Inst, PerFunctionState &PFS) {
3535 std::vector<unsigned> FwdRefAttrGrps;
3544 if (ParseOptionalCallingConv(CC) ||
3545 ParseOptionalReturnAttrs(RetAttrs) ||
3546 ParseType(RetType, RetTypeLoc,
true ) ||
3547 ParseValID(CalleeID) ||
3548 ParseParameterList(ArgList, PFS) ||
3549 ParseFnAttributeValuePairs(FnAttrs, FwdRefAttrGrps,
false,
3552 ParseTypeAndBasicBlock(NormalBB, PFS) ||
3554 ParseTypeAndBasicBlock(UnwindBB, PFS))
3562 if (!(PFTy = dyn_cast<PointerType>(RetType)) ||
3565 std::vector<Type*> ParamTypes;
3566 for (
unsigned i = 0, e = ArgList.
size(); i != e; ++i)
3567 ParamTypes.push_back(ArgList[i].V->getType());
3570 return Error(RetTypeLoc,
"Invalid result type for LLVM function");
3578 if (ConvertValIDToValue(PFTy, CalleeID, Callee, &PFS))
return true;
3584 AttributeSet::ReturnIndex,
3593 for (
unsigned i = 0, e = ArgList.
size(); i != e; ++i) {
3594 Type *ExpectedTy = 0;
3598 return Error(ArgList[i].Loc,
"too many arguments specified");
3601 if (ExpectedTy && ExpectedTy != ArgList[i].V->
getType())
3602 return Error(ArgList[i].Loc,
"argument is not of expected type '" +
3605 if (ArgList[i].Attrs.hasAttributes(i + 1)) {
3612 return Error(CallLoc,
"not enough parameters specified for call");
3616 AttributeSet::FunctionIndex,
3625 ForwardRefAttrGroups[II] = FwdRefAttrGrps;
3632 bool LLParser::ParseResume(
Instruction *&Inst, PerFunctionState &PFS) {
3634 if (ParseTypeAndValue(Exn, ExnLoc, PFS))
3651 bool LLParser::ParseArithmetic(
Instruction *&Inst, PerFunctionState &PFS,
3654 if (ParseTypeAndValue(LHS, Loc, PFS) ||
3655 ParseToken(
lltok::comma,
"expected ',' in arithmetic operation") ||
3656 ParseValue(LHS->
getType(), RHS, PFS))
3660 switch (OperandType) {
3671 return Error(Loc,
"invalid operand type for instruction");
3679 bool LLParser::ParseLogical(
Instruction *&Inst, PerFunctionState &PFS,
3682 if (ParseTypeAndValue(LHS, Loc, PFS) ||
3683 ParseToken(
lltok::comma,
"expected ',' in logical operation") ||
3684 ParseValue(LHS->
getType(), RHS, PFS))
3688 return Error(Loc,
"instruction requires integer or integer vector operands");
3698 bool LLParser::ParseCompare(
Instruction *&Inst, PerFunctionState &PFS,
3704 if (ParseCmpPredicate(Pred, Opc) ||
3705 ParseTypeAndValue(LHS, Loc, PFS) ||
3706 ParseToken(
lltok::comma,
"expected ',' after compare value") ||
3707 ParseValue(LHS->
getType(), RHS, PFS))
3710 if (Opc == Instruction::FCmp) {
3712 return Error(Loc,
"fcmp requires floating point operands");
3715 assert(Opc == Instruction::ICmp &&
"Unknown opcode for CmpInst!");
3718 return Error(Loc,
"icmp requires integer operands");
3731 bool LLParser::ParseCast(
Instruction *&Inst, PerFunctionState &PFS,
3736 if (ParseTypeAndValue(Op, Loc, PFS) ||
3737 ParseToken(
lltok::kw_to,
"expected 'to' after cast value") ||
3743 return Error(Loc,
"invalid cast opcode for cast from '" +
3753 bool LLParser::ParseSelect(
Instruction *&Inst, PerFunctionState &PFS) {
3755 Value *Op0, *Op1, *Op2;
3756 if (ParseTypeAndValue(Op0, Loc, PFS) ||
3757 ParseToken(
lltok::comma,
"expected ',' after select condition") ||
3758 ParseTypeAndValue(Op1, PFS) ||
3759 ParseToken(
lltok::comma,
"expected ',' after select value") ||
3760 ParseTypeAndValue(Op2, PFS))
3764 return Error(Loc, Reason);
3772 bool LLParser::ParseVA_Arg(
Instruction *&Inst, PerFunctionState &PFS) {
3776 if (ParseTypeAndValue(Op, PFS) ||
3777 ParseToken(
lltok::comma,
"expected ',' after vaarg operand") ||
3778 ParseType(EltTy, TypeLoc))
3782 return Error(TypeLoc,
"va_arg requires operand with first class type");
3790 bool LLParser::ParseExtractElement(
Instruction *&Inst, PerFunctionState &PFS) {
3793 if (ParseTypeAndValue(Op0, Loc, PFS) ||
3794 ParseToken(
lltok::comma,
"expected ',' after extract value") ||
3795 ParseTypeAndValue(Op1, PFS))
3799 return Error(Loc,
"invalid extractelement operands");
3807 bool LLParser::ParseInsertElement(
Instruction *&Inst, PerFunctionState &PFS) {
3809 Value *Op0, *Op1, *Op2;
3810 if (ParseTypeAndValue(Op0, Loc, PFS) ||
3811 ParseToken(
lltok::comma,
"expected ',' after insertelement value") ||
3812 ParseTypeAndValue(Op1, PFS) ||
3813 ParseToken(
lltok::comma,
"expected ',' after insertelement value") ||
3814 ParseTypeAndValue(Op2, PFS))
3818 return Error(Loc,
"invalid insertelement operands");
3826 bool LLParser::ParseShuffleVector(
Instruction *&Inst, PerFunctionState &PFS) {
3828 Value *Op0, *Op1, *Op2;
3829 if (ParseTypeAndValue(Op0, Loc, PFS) ||
3830 ParseToken(
lltok::comma,
"expected ',' after shuffle mask") ||
3831 ParseTypeAndValue(Op1, PFS) ||
3832 ParseToken(
lltok::comma,
"expected ',' after shuffle value") ||
3833 ParseTypeAndValue(Op2, PFS))
3837 return Error(Loc,
"invalid shufflevector operands");
3845 int LLParser::ParsePHI(
Instruction *&Inst, PerFunctionState &PFS) {
3849 if (ParseType(Ty, TypeLoc) ||
3851 ParseValue(Ty, Op0, PFS) ||
3852 ParseToken(
lltok::comma,
"expected ',' after insertelement value") ||
3854 ParseToken(lltok::rsquare,
"expected ']' in phi value list"))
3857 bool AteExtraComma =
false;
3860 PHIVals.
push_back(std::make_pair(Op0, cast<BasicBlock>(Op1)));
3866 AteExtraComma =
true;
3870 if (ParseToken(
lltok::lsquare,
"expected '[' in phi value list") ||
3871 ParseValue(Ty, Op0, PFS) ||
3872 ParseToken(
lltok::comma,
"expected ',' after insertelement value") ||
3874 ParseToken(lltok::rsquare,
"expected ']' in phi value list"))
3879 return Error(TypeLoc,
"phi node must have first class type");
3882 for (
unsigned i = 0, e = PHIVals.
size(); i != e; ++i)
3883 PN->
addIncoming(PHIVals[i].first, PHIVals[i].second);
3885 return AteExtraComma ? InstExtraComma : InstNormal;
3894 bool LLParser::ParseLandingPad(
Instruction *&Inst, PerFunctionState &PFS) {
3898 if (ParseType(Ty, TyLoc) ||
3900 ParseTypeAndValue(PersFn, PersFnLoc, PFS))
3913 return TokError(
"expected 'catch' or 'filter' clause type");
3916 if (ParseTypeAndValue(V, VLoc, PFS)) {
3924 if (isa<ArrayType>(V->
getType()))
3925 Error(VLoc,
"'catch' clause has an invalid type");
3927 if (!isa<ArrayType>(V->
getType()))
3928 Error(VLoc,
"'filter' clause has an invalid type");
3941 bool LLParser::ParseCall(
Instruction *&Inst, PerFunctionState &PFS,
3944 std::vector<unsigned> FwdRefAttrGrps;
3953 if ((isTail && ParseToken(
lltok::kw_call,
"expected 'tail call'")) ||
3954 ParseOptionalCallingConv(CC) ||
3955 ParseOptionalReturnAttrs(RetAttrs) ||
3956 ParseType(RetType, RetTypeLoc,
true ) ||
3957 ParseValID(CalleeID) ||
3958 ParseParameterList(ArgList, PFS) ||
3959 ParseFnAttributeValuePairs(FnAttrs, FwdRefAttrGrps,
false,
3968 if (!(PFTy = dyn_cast<PointerType>(RetType)) ||
3971 std::vector<Type*> ParamTypes;
3972 for (
unsigned i = 0, e = ArgList.
size(); i != e; ++i)
3973 ParamTypes.push_back(ArgList[i].V->getType());
3976 return Error(RetTypeLoc,
"Invalid result type for LLVM function");
3984 if (ConvertValIDToValue(PFTy, CalleeID, Callee, &PFS))
return true;
3990 AttributeSet::ReturnIndex,
3999 for (
unsigned i = 0, e = ArgList.
size(); i != e; ++i) {
4000 Type *ExpectedTy = 0;
4004 return Error(ArgList[i].Loc,
"too many arguments specified");
4007 if (ExpectedTy && ExpectedTy != ArgList[i].V->
getType())
4008 return Error(ArgList[i].Loc,
"argument is not of expected type '" +
4011 if (ArgList[i].Attrs.hasAttributes(i + 1)) {
4018 return Error(CallLoc,
"not enough parameters specified for call");
4022 AttributeSet::FunctionIndex,
4032 ForwardRefAttrGroups[CI] = FwdRefAttrGrps;
4043 int LLParser::ParseAlloc(
Instruction *&Inst, PerFunctionState &PFS) {
4046 unsigned Alignment = 0;
4048 if (ParseType(Ty))
return true;
4050 bool AteExtraComma =
false;
4053 if (ParseOptionalAlignment(Alignment))
return true;
4055 AteExtraComma =
true;
4057 if (ParseTypeAndValue(Size, SizeLoc, PFS) ||
4058 ParseOptionalCommaAlign(Alignment, AteExtraComma))
4064 return Error(SizeLoc,
"element count must have integer type");
4067 return AteExtraComma ? InstExtraComma : InstNormal;
4074 int LLParser::ParseLoad(
Instruction *&Inst, PerFunctionState &PFS) {
4076 unsigned Alignment = 0;
4077 bool AteExtraComma =
false;
4078 bool isAtomic =
false;
4087 bool isVolatile =
false;
4093 if (ParseTypeAndValue(Val, Loc, PFS) ||
4094 ParseScopeAndOrdering(isAtomic, Scope, Ordering) ||
4095 ParseOptionalCommaAlign(Alignment, AteExtraComma))
4099 !cast<PointerType>(Val->
getType())->getElementType()->isFirstClassType())
4100 return Error(Loc,
"load operand must be a pointer to a first class type");
4101 if (isAtomic && !Alignment)
4102 return Error(Loc,
"atomic load must have explicit non-zero alignment");
4104 return Error(Loc,
"atomic load cannot use Release ordering");
4106 Inst =
new LoadInst(Val,
"", isVolatile, Alignment, Ordering, Scope);
4107 return AteExtraComma ? InstExtraComma : InstNormal;
4115 int LLParser::ParseStore(
Instruction *&Inst, PerFunctionState &PFS) {
4117 unsigned Alignment = 0;
4118 bool AteExtraComma =
false;
4119 bool isAtomic =
false;
4128 bool isVolatile =
false;
4134 if (ParseTypeAndValue(Val, Loc, PFS) ||
4135 ParseToken(
lltok::comma,
"expected ',' after store operand") ||
4136 ParseTypeAndValue(Ptr, PtrLoc, PFS) ||
4137 ParseScopeAndOrdering(isAtomic, Scope, Ordering) ||
4138 ParseOptionalCommaAlign(Alignment, AteExtraComma))
4142 return Error(PtrLoc,
"store operand must be a pointer");
4144 return Error(Loc,
"store operand must be a first class value");
4145 if (cast<PointerType>(Ptr->
getType())->getElementType() != Val->
getType())
4146 return Error(Loc,
"stored value and pointer type do not match");
4147 if (isAtomic && !Alignment)
4148 return Error(Loc,
"atomic store must have explicit non-zero alignment");
4150 return Error(Loc,
"atomic store cannot use Acquire ordering");
4152 Inst =
new StoreInst(Val, Ptr, isVolatile, Alignment, Ordering, Scope);
4153 return AteExtraComma ? InstExtraComma : InstNormal;
4159 int LLParser::ParseCmpXchg(
Instruction *&Inst, PerFunctionState &PFS) {
4160 Value *Ptr, *Cmp, *New;
LocTy PtrLoc, CmpLoc, NewLoc;
4161 bool AteExtraComma =
false;
4164 bool isVolatile =
false;
4169 if (ParseTypeAndValue(Ptr, PtrLoc, PFS) ||
4170 ParseToken(
lltok::comma,
"expected ',' after cmpxchg address") ||
4171 ParseTypeAndValue(Cmp, CmpLoc, PFS) ||
4172 ParseToken(
lltok::comma,
"expected ',' after cmpxchg cmp operand") ||
4173 ParseTypeAndValue(New, NewLoc, PFS) ||
4174 ParseScopeAndOrdering(
true , Scope, Ordering))
4178 return TokError(
"cmpxchg cannot be unordered");
4180 return Error(PtrLoc,
"cmpxchg operand must be a pointer");
4181 if (cast<PointerType>(Ptr->
getType())->getElementType() != Cmp->
getType())
4182 return Error(CmpLoc,
"compare value and pointer type do not match");
4183 if (cast<PointerType>(Ptr->
getType())->getElementType() != New->
getType())
4184 return Error(NewLoc,
"new value and pointer type do not match");
4186 return Error(NewLoc,
"cmpxchg operand must be an integer");
4188 if (Size < 8 || (Size & (Size - 1)))
4189 return Error(NewLoc,
"cmpxchg operand must be power-of-two byte-sized"
4196 return AteExtraComma ? InstExtraComma : InstNormal;
4202 int LLParser::ParseAtomicRMW(
Instruction *&Inst, PerFunctionState &PFS) {
4204 bool AteExtraComma =
false;
4207 bool isVolatile =
false;
4214 default:
return TokError(
"expected binary operation in atomicrmw");
4229 if (ParseTypeAndValue(Ptr, PtrLoc, PFS) ||
4230 ParseToken(
lltok::comma,
"expected ',' after atomicrmw address") ||
4231 ParseTypeAndValue(Val, ValLoc, PFS) ||
4232 ParseScopeAndOrdering(
true , Scope, Ordering))
4236 return TokError(
"atomicrmw cannot be unordered");
4238 return Error(PtrLoc,
"atomicrmw operand must be a pointer");
4239 if (cast<PointerType>(Ptr->
getType())->getElementType() != Val->
getType())
4240 return Error(ValLoc,
"atomicrmw value and pointer type do not match");
4242 return Error(ValLoc,
"atomicrmw operand must be an integer");
4244 if (Size < 8 || (Size & (Size - 1)))
4245 return Error(ValLoc,
"atomicrmw operand must be power-of-two byte-sized"
4252 return AteExtraComma ? InstExtraComma : InstNormal;
4257 int LLParser::ParseFence(
Instruction *&Inst, PerFunctionState &PFS) {
4260 if (ParseScopeAndOrdering(
true , Scope, Ordering))
4264 return TokError(
"fence cannot be unordered");
4266 return TokError(
"fence cannot be monotonic");
4268 Inst =
new FenceInst(Context, Ordering, Scope);
4274 int LLParser::ParseGetElementPtr(
Instruction *&Inst, PerFunctionState &PFS) {
4281 if (ParseTypeAndValue(Ptr, Loc, PFS))
return true;
4285 if (!BasePointerType)
4286 return Error(Loc,
"base of getelementptr must be a pointer");
4289 bool AteExtraComma =
false;
4292 AteExtraComma =
true;
4295 if (ParseTypeAndValue(Val, EltLoc, PFS))
return true;
4297 return Error(EltLoc,
"getelementptr index must be an integer");
4299 return Error(EltLoc,
"getelementptr index type missmatch");
4301 unsigned ValNumEl = cast<VectorType>(Val->
getType())->getNumElements();
4302 unsigned PtrNumEl = cast<VectorType>(Ptr->
getType())->getNumElements();
4303 if (ValNumEl != PtrNumEl)
4304 return Error(EltLoc,
4305 "getelementptr vector index has a wrong number of elements");
4311 return Error(Loc,
"base element of getelementptr must be sized");
4314 return Error(Loc,
"invalid getelementptr indices");
4317 cast<GetElementPtrInst>(Inst)->setIsInBounds(
true);
4318 return AteExtraComma ? InstExtraComma : InstNormal;
4323 int LLParser::ParseExtractValue(
Instruction *&Inst, PerFunctionState &PFS) {
4327 if (ParseTypeAndValue(Val, Loc, PFS) ||
4328 ParseIndexList(Indices, AteExtraComma))
4332 return Error(Loc,
"extractvalue operand must be aggregate type");
4335 return Error(Loc,
"invalid indices for extractvalue");
4337 return AteExtraComma ? InstExtraComma : InstNormal;
4342 int LLParser::ParseInsertValue(
Instruction *&Inst, PerFunctionState &PFS) {
4346 if (ParseTypeAndValue(Val0, Loc0, PFS) ||
4347 ParseToken(
lltok::comma,
"expected comma after insertvalue operand") ||
4348 ParseTypeAndValue(Val1, Loc1, PFS) ||
4349 ParseIndexList(Indices, AteExtraComma))
4353 return Error(Loc0,
"insertvalue operand must be aggregate type");
4356 return Error(Loc0,
"invalid indices for insertvalue");
4358 return AteExtraComma ? InstExtraComma : InstNormal;
4370 PerFunctionState *PFS) {
4383 if (ParseTypeAndValue(V, PFS))
return true;
void setVisibility(VisibilityTypes V)
void setAttributes(const AttributeSet &Attrs)
void push_back(const T &Elt)
static void deleteTemporary(MDNode *N)
static ConstantInt * getFalse(LLVMContext &Context)
The C convention as specified in the x86-64 supplement to the System V ABI, used on most non-Windows ...
static MDNode * getTemporary(LLVMContext &Context, ArrayRef< Value * > Vals)
const ValueSymbolTable & getValueSymbolTable() const
Get the symbol table of global variable and function identifiers.
static Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true)
void setFastMathFlags(FastMathFlags FMF)
Like Private, but linker removes.
void setDataLayout(StringRef DL)
Set the data layout.
static IntegerType * getInt1Ty(LLVMContext &C)
static Constant * getShuffleVector(Constant *V1, Constant *V2, Constant *Mask)
void addIncoming(Value *V, BasicBlock *BB)
Special purpose, only applies to global arrays.
*p = old <signed v ? old : v
LLVM Argument representation.
uint64_t getZExtValue() const
Get zero extended value.
const APFloat & getAPFloatVal() const
Sign extended before/after call.
static bool isValidOperands(const Value *Vec, const Value *NewElt, const Value *Idx)
static const fltSemantics IEEEdouble
Force argument to be passed in register.
Same, but only replaced by something equivalent.
static MDString * get(LLVMContext &Context, StringRef Str)
static Constant * getSelect(Constant *C, Constant *V1, Constant *V2)
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", Instruction *InsertBefore=0)
unsigned getUIntVal() const
enable_if_c<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
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)
static Constant * getGetElementPtr(Constant *C, ArrayRef< Constant * > IdxList, bool InBounds=false)
ARM_AAPCS_VFP - Same as ARM_AAPCS, but uses hard floating point ABI.
uint64_t getAlignment() const
Retrieve the alignment attribute, if it exists.
void addOperand(MDNode *M)
addOperand - Add metadata operand.
static PointerType * get(Type *ElementType, unsigned AddressSpace)
*p = old <unsigned v ? old : v
static Constant * getExtractElement(Constant *Vec, Constant *Idx)
0 1 0 0 True if ordered and less than
Like Internal, but omit from symbol table.
Source said inlining was desirable.
*p = old >unsigned v ? old : v
Externally visible function.
NamedMDNode * getOrInsertNamedMetadata(StringRef Name)
uint64_t getLimitedValue(uint64_t Limit=~0ULL) const
1 1 1 0 True if unordered or not equal
void setSection(StringRef S)
MDNode - a tuple of other values.
static bool isValidReturnType(Type *RetTy)
unsigned getAddressSpace() const
Return the address space of the Pointer type.
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > Tys=None)
static Constant * getFCmp(unsigned short pred, Constant *LHS, Constant *RHS)
AttrBuilder & addAttribute(Attribute::AttrKind Val)
Add an attribute to the builder.
static IndirectBrInst * Create(Value *Address, unsigned NumDests, Instruction *InsertBefore=0)
static bool isValidArgumentType(Type *ArgTy)
bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return true if the attribute exists at the given index.
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 MDNode * get(LLVMContext &Context, ArrayRef< Value * > Vals)
static Constant * getNullValue(Type *Ty)
StringRef getName() const
void setCallingConv(CallingConv::ID CC)
bool Run()
Run: module ::= toplevelentity*.
1 0 0 1 True if unordered or equal
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
AttributeSet removeAttribute(LLVMContext &C, unsigned Index, Attribute::AttrKind Attr) const
Remove the specified attribute at the specified index from this attribute list. Since attribute lists...
static bool castIsValid(Instruction::CastOps op, Value *S, Type *DstTy)
Determine if a cast is valid without creating one.
void push_back(NodeTy *val)
void UpgradeCallsToIntrinsic(Function *F)
static Constant * get(unsigned Opcode, Constant *C1, Constant *C2, unsigned Flags=0)
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
void setInitializer(Constant *InitVal)
#define llvm_unreachable(msg)
param_iterator param_end() const
static Constant * get(ArrayRef< Constant * > V)
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=0)
0 1 0 1 True if ordered and less than or equal
static Constant * getExtractValue(Constant *Agg, ArrayRef< unsigned > Idxs)
Function must be in a unwind table.
void setName(const Twine &Name)
bool any()
Whether any flag is set.
static ConstantInt * ExtractElement(Constant *V, Constant *Idx)
ID
LLVM Calling Convention Representation.
static const unsigned MaximumAlignment
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)
static Type * getLabelTy(LLVMContext &C)
void setCleanup(bool V)
setCleanup - Indicate that this landingpad instruction is a cleanup.
LLVMContext & getContext() const
getContext - Return the LLVMContext in which this type was uniqued.
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
bool isHalfTy() const
isHalfTy - Return true if this is 'half', a 16-bit IEEE fp type.
static Constant * getICmp(unsigned short pred, Constant *LHS, Constant *RHS)
VisibilityTypes
An enumeration for the kinds of visibility of global values.
Function to be imported from DLL.
static bool isValidElementType(Type *ElemTy)
Represents a floating point comparison operator.
static LandingPadInst * Create(Type *RetTy, Value *PersonalityFn, unsigned NumReservedClauses, const Twine &NameStr="", Instruction *InsertBefore=0)
bool isFirstClassType() const
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
bool isFloatingPointTy() const
static bool Verify(FunctionType *Ty, StringRef Constraints)
void replaceAllUsesWith(Value *V)
ValueSymbolTable & getValueSymbolTable()
void addClause(Value *ClauseVal)
addClause - Add a catch or filter clause to the landing pad.
Type * getElementType() const
Considered to not alias after call.
Function * getFunction(StringRef Name) const
static CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=0)
Construct any of the CastInst subclasses.
ExternalWeak linkage description.
void setCallingConv(CallingConv::ID CC)
bool isIntOrIntVectorTy() const
Same, but only replaced by something equivalent.
static ConstantPointerNull * get(PointerType *T)
get() - Static factory methods - Return objects of the specified value
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr="", Instruction *InsertBefore=0)
LLVM Basic Block Representation.
static BlockAddress * get(Function *F, BasicBlock *BB)
get - Return a BlockAddress for the specified function and basic block.
LLVM Constant Representation.
param_iterator param_begin() const
bool isFloatTy() const
isFloatTy - Return true if this is 'float', a 32-bit IEEE fp type.
void setExternallyInitialized(bool Val)
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
static InvokeInst * Create(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, const Twine &NameStr="", Instruction *InsertBefore=0)
Return value is always equal to this argument.
static bool isValidLinkage(LinkageTypes L)
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=0)
const InstListType & getInstList() const
Return the underlying instruction list container.
Represent an integer comparison operator.
unsigned getBitWidth() const
Return the number of bits in the APInt.
opStatus convert(const fltSemantics &, roundingMode, bool *)
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.
Function to be accessible from DLL.
Function doesn't unwind stack.
static Constant * get(StructType *T, ArrayRef< Constant * > V)
Marks function as being in a cold path.
void setConstant(bool Val)
1 1 1 1 Always true (always folded)
Mark the function as not returning.
MSP430_INTR - Calling convention used for MSP430 interrupt routines.
static bool isValidElementType(Type *ElemTy)
void setTailCall(bool isTC=true)
static UndefValue * get(Type *T)
LLVMContext & getContext() const
All values hold a context through their type.
static bool isAtomic(Instruction *I)
bool isFPOrFPVectorTy() const
void setBody(ArrayRef< Type * > Elements, bool isPacked=false)
setBody - Specify a body for an opaque identified type.
1 1 0 1 True if unordered, less than, or equal
static const fltSemantics IEEEhalf
Call cannot be duplicated.
void setMetadata(unsigned KindID, MDNode *Node)
void setThreadLocalMode(ThreadLocalMode Val)
Constant ** ConstantStructElts
static CallInst * Create(Value *Func, ArrayRef< Value * > Args, const Twine &NameStr="", Instruction *InsertBefore=0)
global_iterator global_end()
const FunctionListType & getFunctionList() const
Get the Module's list of functions (constant).
0 0 1 0 True if ordered and greater than
static PointerType * getUnqual(Type *ElementType)
static bool isValidElementType(Type *ElemTy)
bool isFunctionTy() const
APSInt LLVM_ATTRIBUTE_UNUSED_RESULT extOrTrunc(uint32_t width) const
const std::string & getStrVal() const
static StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
AttrBuilder & removeAttribute(Attribute::AttrKind Val)
Remove an attribute from the builder.
void setAlignment(unsigned Align)
enum llvm::ValID::@149 Kind
1 1 0 0 True if unordered or less than
Keep one copy of function when linking (inline)
void setUnnamedAddr(bool Val)
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
static GetElementPtrInst * Create(Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", Instruction *InsertBefore=0)
static Constant * get(Type *Ty, double V)
static ConstantInt * getTrue(LLVMContext &Context)
void setLinkage(LinkageTypes LT)
void splice(iterator where, iplist &L2)
AttributeSet removeAttributes(LLVMContext &C, unsigned Index, AttributeSet Attrs) const
Remove the specified attributes at the specified index from this attribute list. Since attribute list...
LinkageTypes
An enumeration for the kinds of linkage for global values.
Function must not be optimized.
Function only reads from memory.
void setGC(const char *Str)
FunctionNumber(functionNumber)
Like LinkerPrivate, but weak.
static InsertValueInst * Create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &NameStr="", Instruction *InsertBefore=0)
static std::string getTypeString(Type *T)
PointerType * getType() const
getType - Global values are always pointers.
static const fltSemantics IEEEsingle
pointer data()
data - Return a pointer to the vector's buffer, even if empty().
bool isAggregateType() const
unsigned greater or equal
static bool isValidElementType(Type *ElemTy)
Callee isn't recognized as a builtin.
void appendModuleInlineAsm(StringRef Asm)
lltok::Kind getKind() const
0 1 1 0 True if ordered and operands are unequal
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=0, BasicBlock *InsertBefore=0)
Creates a new BasicBlock.
static ArrayType * get(Type *ElementType, uint64_t NumElements)
void setTargetTriple(StringRef T)
Set the target triple.
Keep one copy of named function when linking (weak)
const Type * getScalarType() const
Rename collisions when linking (static functions).
static BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name=Twine(), Instruction *InsertBefore=0)
unsigned getPrimitiveSizeInBits() const
static Constant * getInsertValue(Constant *Agg, Constant *Val, ArrayRef< unsigned > Idxs)
static InlineAsm * get(FunctionType *Ty, StringRef AsmString, StringRef Constraints, bool hasSideEffects, bool isAlignStack=false, AsmDialect asmDialect=AD_ATT)
1 0 1 0 True if unordered or greater than
static ReturnInst * Create(LLVMContext &C, Value *retVal=0, Instruction *InsertBefore=0)
void setAttributes(AttributeSet attrs)
Set the attribute list for this Function.
const APSInt & getAPSIntVal() const
void addDestination(BasicBlock *Dest)
AttrBuilder & merge(const AttrBuilder &B)
Add the attributes from the builder.
The C convention as implemented on Windows/x86-64. This convention differs from the more common X86_6...
void setAttributes(const AttributeSet &Attrs)
Function can return twice.
static Type * getIndexedType(Type *Ptr, ArrayRef< Value * > IdxList)
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)
static StructType * create(LLVMContext &Context, StringRef Name)
StructType::create - This creates an identified struct.
Disable implicit floating point insts.
AttrBuilder & addStackAlignmentAttr(unsigned Align)
This turns an int stack alignment (which must be a power of 2) into the form used internally in Attri...
void setCallingConv(CallingConv::ID CC)
void UpgradeInstWithTBAATag(Instruction *I)
bool isPowerOf2_32(uint32_t Value)
Convenience struct for specifying and reasoning about fast-math flags.
AttrBuilder & addAlignmentAttr(unsigned Align)
This turns an int alignment (which must be a power of 2) into the form used internally in Attribute...
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. Since attribute sets are immutable, this returns a new set.
0 0 1 1 True if ordered and greater than or equal
unsigned getMDKindID(StringRef Name) const
static Constant * getCast(unsigned ops, Constant *C, Type *Ty)
Intel_OCL_BI - Calling conventions for Intel OpenCL built-ins.
Stack protection required.
static IntegerType * getInt8Ty(LLVMContext &C)
static ResumeInst * Create(Value *Exn, Instruction *InsertBefore=0)
static SwitchInst * Create(Value *Value, BasicBlock *Default, unsigned NumCases, Instruction *InsertBefore=0)
const fltSemantics & getSemantics() const
GlobalValue * getNamedValue(StringRef Name) const
Value * lookup(StringRef Name) const
Lookup a named Value.
static Constant * getInsertElement(Constant *Vec, Constant *Elt, Constant *Idx)
0 0 0 0 Always false (always folded)
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, const Twine &N="", Module *M=0)
bool isVoidTy() const
isVoidTy - Return true if this is 'void'.
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)
Function must be optimized for size first.