diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2022-03-20 11:40:34 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2022-05-14 11:43:05 +0000 |
commit | 349cc55c9796c4596a5b9904cd3281af295f878f (patch) | |
tree | 410c5a785075730a35f1272ca6a7adf72222ad03 /contrib/llvm-project/llvm/lib/AsmParser/LLParser.cpp | |
parent | cb2ae6163174b90e999326ecec3699ee093a5d43 (diff) | |
parent | c0981da47d5696fe36474fcf86b4ce03ae3ff818 (diff) |
Diffstat (limited to 'contrib/llvm-project/llvm/lib/AsmParser/LLParser.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/AsmParser/LLParser.cpp | 315 |
1 files changed, 161 insertions, 154 deletions
diff --git a/contrib/llvm-project/llvm/lib/AsmParser/LLParser.cpp b/contrib/llvm-project/llvm/lib/AsmParser/LLParser.cpp index 799cb03c8c8c..5bce1eaa59a0 100644 --- a/contrib/llvm-project/llvm/lib/AsmParser/LLParser.cpp +++ b/contrib/llvm-project/llvm/lib/AsmParser/LLParser.cpp @@ -140,8 +140,8 @@ bool LLParser::validateEndOfModule(bool UpgradeDebugInfo) { if (Function *Fn = dyn_cast<Function>(V)) { AttributeList AS = Fn->getAttributes(); - AttrBuilder FnAttrs(AS.getFnAttributes()); - AS = AS.removeAttributes(Context, AttributeList::FunctionIndex); + AttrBuilder FnAttrs(AS.getFnAttrs()); + AS = AS.removeFnAttributes(Context); FnAttrs.merge(B); @@ -152,32 +152,28 @@ bool LLParser::validateEndOfModule(bool UpgradeDebugInfo) { FnAttrs.removeAttribute(Attribute::Alignment); } - AS = AS.addAttributes(Context, AttributeList::FunctionIndex, - AttributeSet::get(Context, FnAttrs)); + AS = AS.addFnAttributes(Context, AttributeSet::get(Context, FnAttrs)); Fn->setAttributes(AS); } else if (CallInst *CI = dyn_cast<CallInst>(V)) { AttributeList AS = CI->getAttributes(); - AttrBuilder FnAttrs(AS.getFnAttributes()); - AS = AS.removeAttributes(Context, AttributeList::FunctionIndex); + AttrBuilder FnAttrs(AS.getFnAttrs()); + AS = AS.removeFnAttributes(Context); FnAttrs.merge(B); - AS = AS.addAttributes(Context, AttributeList::FunctionIndex, - AttributeSet::get(Context, FnAttrs)); + AS = AS.addFnAttributes(Context, AttributeSet::get(Context, FnAttrs)); CI->setAttributes(AS); } else if (InvokeInst *II = dyn_cast<InvokeInst>(V)) { AttributeList AS = II->getAttributes(); - AttrBuilder FnAttrs(AS.getFnAttributes()); - AS = AS.removeAttributes(Context, AttributeList::FunctionIndex); + AttrBuilder FnAttrs(AS.getFnAttrs()); + AS = AS.removeFnAttributes(Context); FnAttrs.merge(B); - AS = AS.addAttributes(Context, AttributeList::FunctionIndex, - AttributeSet::get(Context, FnAttrs)); + AS = AS.addFnAttributes(Context, AttributeSet::get(Context, FnAttrs)); II->setAttributes(AS); } else if (CallBrInst *CBI = dyn_cast<CallBrInst>(V)) { AttributeList AS = CBI->getAttributes(); - AttrBuilder FnAttrs(AS.getFnAttributes()); - AS = AS.removeAttributes(Context, AttributeList::FunctionIndex); + AttrBuilder FnAttrs(AS.getFnAttrs()); + AS = AS.removeFnAttributes(Context); FnAttrs.merge(B); - AS = AS.addAttributes(Context, AttributeList::FunctionIndex, - AttributeSet::get(Context, FnAttrs)); + AS = AS.addFnAttributes(Context, AttributeSet::get(Context, FnAttrs)); CBI->setAttributes(AS); } else if (auto *GV = dyn_cast<GlobalVariable>(V)) { AttrBuilder Attrs(GV->getAttributes()); @@ -239,18 +235,18 @@ bool LLParser::validateEndOfModule(bool UpgradeDebugInfo) { Inst->setMetadata(LLVMContext::MD_tbaa, UpgradedMD); } - // Look for intrinsic functions and CallInst that need to be upgraded - for (Module::iterator FI = M->begin(), FE = M->end(); FI != FE; ) - UpgradeCallsToIntrinsic(&*FI++); // must be post-increment, as we remove + // Look for intrinsic functions and CallInst that need to be upgraded. We use + // make_early_inc_range here because we may remove some functions. + for (Function &F : llvm::make_early_inc_range(*M)) + UpgradeCallsToIntrinsic(&F); // Some types could be renamed during loading if several modules are // loaded in the same LLVMContext (LTO scenario). In this case we should // remangle intrinsics names as well. - for (Module::iterator FI = M->begin(), FE = M->end(); FI != FE; ) { - Function *F = &*FI++; - if (auto Remangled = Intrinsic::remangleIntrinsicFunction(F)) { - F->replaceAllUsesWith(Remangled.getValue()); - F->eraseFromParent(); + for (Function &F : llvm::make_early_inc_range(*M)) { + if (auto Remangled = Intrinsic::remangleIntrinsicFunction(&F)) { + F.replaceAllUsesWith(Remangled.getValue()); + F.eraseFromParent(); } } @@ -605,12 +601,15 @@ bool LLParser::parseUnnamedGlobal() { parseOptionalThreadLocal(TLM) || parseOptionalUnnamedAddr(UnnamedAddr)) return true; - if (Lex.getKind() != lltok::kw_alias && Lex.getKind() != lltok::kw_ifunc) + switch (Lex.getKind()) { + default: return parseGlobal(Name, NameLoc, Linkage, HasLinkage, Visibility, DLLStorageClass, DSOLocal, TLM, UnnamedAddr); - - return parseIndirectSymbol(Name, NameLoc, Linkage, Visibility, + case lltok::kw_alias: + case lltok::kw_ifunc: + return parseAliasOrIFunc(Name, NameLoc, Linkage, Visibility, DLLStorageClass, DSOLocal, TLM, UnnamedAddr); + } } /// parseNamedGlobal: @@ -635,12 +634,15 @@ bool LLParser::parseNamedGlobal() { parseOptionalThreadLocal(TLM) || parseOptionalUnnamedAddr(UnnamedAddr)) return true; - if (Lex.getKind() != lltok::kw_alias && Lex.getKind() != lltok::kw_ifunc) + switch (Lex.getKind()) { + default: return parseGlobal(Name, NameLoc, Linkage, HasLinkage, Visibility, DLLStorageClass, DSOLocal, TLM, UnnamedAddr); - - return parseIndirectSymbol(Name, NameLoc, Linkage, Visibility, + case lltok::kw_alias: + case lltok::kw_ifunc: + return parseAliasOrIFunc(Name, NameLoc, Linkage, Visibility, DLLStorageClass, DSOLocal, TLM, UnnamedAddr); + } } bool LLParser::parseComdat() { @@ -913,25 +915,25 @@ static std::string typeComparisonErrorMessage(StringRef Message, Type *Ty1, return ErrOS.str(); } -/// parseIndirectSymbol: +/// parseAliasOrIFunc: /// ::= GlobalVar '=' OptionalLinkage OptionalPreemptionSpecifier /// OptionalVisibility OptionalDLLStorageClass /// OptionalThreadLocal OptionalUnnamedAddr -/// 'alias|ifunc' IndirectSymbol IndirectSymbolAttr* +/// 'alias|ifunc' AliaseeOrResolver SymbolAttrs* /// -/// IndirectSymbol +/// AliaseeOrResolver /// ::= TypeAndValue /// -/// IndirectSymbolAttr +/// SymbolAttrs /// ::= ',' 'partition' StringConstant /// /// Everything through OptionalUnnamedAddr has already been parsed. /// -bool LLParser::parseIndirectSymbol(const std::string &Name, LocTy NameLoc, - unsigned L, unsigned Visibility, - unsigned DLLStorageClass, bool DSOLocal, - GlobalVariable::ThreadLocalMode TLM, - GlobalVariable::UnnamedAddr UnnamedAddr) { +bool LLParser::parseAliasOrIFunc(const std::string &Name, LocTy NameLoc, + unsigned L, unsigned Visibility, + unsigned DLLStorageClass, bool DSOLocal, + GlobalVariable::ThreadLocalMode TLM, + GlobalVariable::UnnamedAddr UnnamedAddr) { bool IsAlias; if (Lex.getKind() == lltok::kw_alias) IsAlias = true; @@ -1013,21 +1015,26 @@ bool LLParser::parseIndirectSymbol(const std::string &Name, LocTy NameLoc, } } - // Okay, create the alias but do not insert it into the module yet. - std::unique_ptr<GlobalIndirectSymbol> GA; - if (IsAlias) + // Okay, create the alias/ifunc but do not insert it into the module yet. + std::unique_ptr<GlobalAlias> GA; + std::unique_ptr<GlobalIFunc> GI; + GlobalValue *GV; + if (IsAlias) { GA.reset(GlobalAlias::create(Ty, AddrSpace, (GlobalValue::LinkageTypes)Linkage, Name, Aliasee, /*Parent*/ nullptr)); - else - GA.reset(GlobalIFunc::create(Ty, AddrSpace, + GV = GA.get(); + } else { + GI.reset(GlobalIFunc::create(Ty, AddrSpace, (GlobalValue::LinkageTypes)Linkage, Name, Aliasee, /*Parent*/ nullptr)); - GA->setThreadLocalMode(TLM); - GA->setVisibility((GlobalValue::VisibilityTypes)Visibility); - GA->setDLLStorageClass((GlobalValue::DLLStorageClassTypes)DLLStorageClass); - GA->setUnnamedAddr(UnnamedAddr); - maybeSetDSOLocal(DSOLocal, *GA); + GV = GI.get(); + } + GV->setThreadLocalMode(TLM); + GV->setVisibility((GlobalValue::VisibilityTypes)Visibility); + GV->setDLLStorageClass((GlobalValue::DLLStorageClassTypes)DLLStorageClass); + GV->setUnnamedAddr(UnnamedAddr); + maybeSetDSOLocal(DSOLocal, *GV); // At this point we've parsed everything except for the IndirectSymbolAttrs. // Now parse them if there are any. @@ -1036,7 +1043,7 @@ bool LLParser::parseIndirectSymbol(const std::string &Name, LocTy NameLoc, if (Lex.getKind() == lltok::kw_partition) { Lex.Lex(); - GA->setPartition(Lex.getStrVal()); + GV->setPartition(Lex.getStrVal()); if (parseToken(lltok::StringConstant, "expected partition string")) return true; } else { @@ -1045,30 +1052,27 @@ bool LLParser::parseIndirectSymbol(const std::string &Name, LocTy NameLoc, } if (Name.empty()) - NumberedVals.push_back(GA.get()); + NumberedVals.push_back(GV); if (GVal) { // Verify that types agree. - if (GVal->getType() != GA->getType()) + if (GVal->getType() != GV->getType()) return error( ExplicitTypeLoc, "forward reference and definition of alias have different types"); // If they agree, just RAUW the old value with the alias and remove the // forward ref info. - GVal->replaceAllUsesWith(GA.get()); + GVal->replaceAllUsesWith(GV); GVal->eraseFromParent(); } // Insert into the module, we know its name won't collide now. if (IsAlias) - M->getAliasList().push_back(cast<GlobalAlias>(GA.get())); + M->getAliasList().push_back(GA.release()); else - M->getIFuncList().push_back(cast<GlobalIFunc>(GA.get())); - assert(GA->getName() == Name && "Should not be a name conflict!"); - - // The module owns this now - GA.release(); + M->getIFuncList().push_back(GI.release()); + assert(GV->getName() == Name && "Should not be a name conflict!"); return false; } @@ -1408,14 +1412,10 @@ static inline GlobalValue *createGlobalFwdRef(Module *M, PointerType *PTy) { } Value *LLParser::checkValidVariableType(LocTy Loc, const Twine &Name, Type *Ty, - Value *Val, bool IsCall) { + Value *Val) { Type *ValTy = Val->getType(); if (ValTy == Ty) return Val; - // For calls, we also allow opaque pointers. - if (IsCall && ValTy == PointerType::get(Ty->getContext(), - Ty->getPointerAddressSpace())) - return Val; if (Ty->isLabelTy()) error(Loc, "'" + Name + "' is not a basic block"); else @@ -1429,7 +1429,7 @@ Value *LLParser::checkValidVariableType(LocTy Loc, const Twine &Name, Type *Ty, /// forward reference record if needed. This can return null if the value /// exists but does not have the right type. GlobalValue *LLParser::getGlobalVal(const std::string &Name, Type *Ty, - LocTy Loc, bool IsCall) { + LocTy Loc) { PointerType *PTy = dyn_cast<PointerType>(Ty); if (!PTy) { error(Loc, "global variable reference must have pointer type"); @@ -1451,7 +1451,7 @@ GlobalValue *LLParser::getGlobalVal(const std::string &Name, Type *Ty, // If we have the value in the symbol table or fwd-ref table, return it. if (Val) return cast_or_null<GlobalValue>( - checkValidVariableType(Loc, "@" + Name, Ty, Val, IsCall)); + checkValidVariableType(Loc, "@" + Name, Ty, Val)); // Otherwise, create a new forward reference for this value and remember it. GlobalValue *FwdVal = createGlobalFwdRef(M, PTy); @@ -1459,8 +1459,7 @@ GlobalValue *LLParser::getGlobalVal(const std::string &Name, Type *Ty, return FwdVal; } -GlobalValue *LLParser::getGlobalVal(unsigned ID, Type *Ty, LocTy Loc, - bool IsCall) { +GlobalValue *LLParser::getGlobalVal(unsigned ID, Type *Ty, LocTy Loc) { PointerType *PTy = dyn_cast<PointerType>(Ty); if (!PTy) { error(Loc, "global variable reference must have pointer type"); @@ -1480,7 +1479,7 @@ GlobalValue *LLParser::getGlobalVal(unsigned ID, Type *Ty, LocTy Loc, // If we have the value in the symbol table or fwd-ref table, return it. if (Val) return cast_or_null<GlobalValue>( - checkValidVariableType(Loc, "@" + Twine(ID), Ty, Val, IsCall)); + checkValidVariableType(Loc, "@" + Twine(ID), Ty, Val)); // Otherwise, create a new forward reference for this value and remember it. GlobalValue *FwdVal = createGlobalFwdRef(M, PTy); @@ -1936,7 +1935,7 @@ bool LLParser::parseOptionalAlignment(MaybeAlign &Alignment, bool AllowParens) { if (!EatIfPresent(lltok::kw_align)) return false; LocTy AlignLoc = Lex.getLoc(); - uint32_t Value = 0; + uint64_t Value = 0; LocTy ParenLoc = Lex.getLoc(); bool HaveParens = false; @@ -1945,13 +1944,13 @@ bool LLParser::parseOptionalAlignment(MaybeAlign &Alignment, bool AllowParens) { HaveParens = true; } - if (parseUInt32(Value)) + if (parseUInt64(Value)) return true; if (HaveParens && !EatIfPresent(lltok::rparen)) return error(ParenLoc, "expected ')'"); - if (!isPowerOf2_32(Value)) + if (!isPowerOf2_64(Value)) return error(AlignLoc, "alignment is not a power of two"); if (Value > Value::MaximumAlignment) return error(AlignLoc, "huge alignments are not supported yet"); @@ -2221,6 +2220,26 @@ bool LLParser::parseType(Type *&Result, const Twine &Msg, bool AllowVoid) { // Type ::= 'float' | 'void' (etc) Result = Lex.getTyVal(); Lex.Lex(); + + // Handle "ptr" opaque pointer type. + // + // Type ::= ptr ('addrspace' '(' uint32 ')')? + if (Result->isOpaquePointerTy()) { + unsigned AddrSpace; + if (parseOptionalAddrSpace(AddrSpace)) + return true; + Result = PointerType::get(getContext(), AddrSpace); + + // Give a nice error for 'ptr*'. + if (Lex.getKind() == lltok::star) + return tokError("ptr* is invalid - use ptr instead"); + + // Fall through to parsing the type suffixes only if this 'ptr' is a + // function return. Otherwise, return success, implicitly rejecting other + // suffixes. + if (Lex.getKind() != lltok::lparen) + return false; + } break; case lltok::lbrace: // Type ::= StructType @@ -2274,26 +2293,6 @@ bool LLParser::parseType(Type *&Result, const Twine &Msg, bool AllowVoid) { } } - // Handle (explicit) opaque pointer types (not --force-opaque-pointers). - // - // Type ::= ptr ('addrspace' '(' uint32 ')')? - if (Result->isOpaquePointerTy()) { - unsigned AddrSpace; - if (parseOptionalAddrSpace(AddrSpace)) - return true; - Result = PointerType::get(getContext(), AddrSpace); - - // Give a nice error for 'ptr*'. - if (Lex.getKind() == lltok::star) - return tokError("ptr* is invalid - use ptr instead"); - - // Fall through to parsing the type suffixes only if this 'ptr' is a - // function return. Otherwise, return success, implicitly rejecting other - // suffixes. - if (Lex.getKind() != lltok::lparen) - return false; - } - // parse the type suffixes. while (true) { switch (Lex.getKind()) { @@ -2798,7 +2797,7 @@ bool LLParser::PerFunctionState::finishFunction() { /// forward reference record if needed. This can return null if the value /// exists but does not have the right type. Value *LLParser::PerFunctionState::getVal(const std::string &Name, Type *Ty, - LocTy Loc, bool IsCall) { + LocTy Loc) { // Look this name up in the normal function symbol table. Value *Val = F.getValueSymbolTable()->lookup(Name); @@ -2812,7 +2811,7 @@ Value *LLParser::PerFunctionState::getVal(const std::string &Name, Type *Ty, // If we have the value in the symbol table or fwd-ref table, return it. if (Val) - return P.checkValidVariableType(Loc, "%" + Name, Ty, Val, IsCall); + return P.checkValidVariableType(Loc, "%" + Name, Ty, Val); // Don't make placeholders with invalid type. if (!Ty->isFirstClassType()) { @@ -2832,8 +2831,7 @@ Value *LLParser::PerFunctionState::getVal(const std::string &Name, Type *Ty, return FwdVal; } -Value *LLParser::PerFunctionState::getVal(unsigned ID, Type *Ty, LocTy Loc, - bool IsCall) { +Value *LLParser::PerFunctionState::getVal(unsigned ID, Type *Ty, LocTy Loc) { // Look this name up in the normal function symbol table. Value *Val = ID < NumberedVals.size() ? NumberedVals[ID] : nullptr; @@ -2847,7 +2845,7 @@ Value *LLParser::PerFunctionState::getVal(unsigned ID, Type *Ty, LocTy Loc, // If we have the value in the symbol table or fwd-ref table, return it. if (Val) - return P.checkValidVariableType(Loc, "%" + Twine(ID), Ty, Val, IsCall); + return P.checkValidVariableType(Loc, "%" + Twine(ID), Ty, Val); if (!Ty->isFirstClassType()) { P.error(Loc, "invalid use of a non-first-class type"); @@ -2934,12 +2932,12 @@ bool LLParser::PerFunctionState::setInstName(int NameID, BasicBlock *LLParser::PerFunctionState::getBB(const std::string &Name, LocTy Loc) { return dyn_cast_or_null<BasicBlock>( - getVal(Name, Type::getLabelTy(F.getContext()), Loc, /*IsCall=*/false)); + getVal(Name, Type::getLabelTy(F.getContext()), Loc)); } BasicBlock *LLParser::PerFunctionState::getBB(unsigned ID, LocTy Loc) { return dyn_cast_or_null<BasicBlock>( - getVal(ID, Type::getLabelTy(F.getContext()), Loc, /*IsCall=*/false)); + getVal(ID, Type::getLabelTy(F.getContext()), Loc)); } /// defineBB - Define the specified basic block, which is either named or @@ -3652,7 +3650,7 @@ bool LLParser::parseGlobalValue(Type *Ty, Constant *&C) { ValID ID; Value *V = nullptr; bool Parsed = parseValID(ID, /*PFS=*/nullptr, Ty) || - convertValIDToValue(Ty, ID, V, nullptr, /*IsCall=*/false); + convertValIDToValue(Ty, ID, V, nullptr); if (V && !(C = dyn_cast<Constant>(V))) return error(ID.Loc, "global values must be constants"); return Parsed; @@ -3876,10 +3874,6 @@ struct MDField : public MDFieldImpl<Metadata *> { MDField(bool AllowNull = true) : ImplTy(nullptr), AllowNull(AllowNull) {} }; -struct MDConstant : public MDFieldImpl<ConstantAsMetadata *> { - MDConstant() : ImplTy(nullptr) {} -}; - struct MDStringField : public MDFieldImpl<MDString *> { bool AllowEmpty; MDStringField(bool AllowEmpty = true) @@ -3914,22 +3908,6 @@ struct MDSignedOrMDField : MDEitherFieldImpl<MDSignedField, MDField> { } }; -struct MDSignedOrUnsignedField - : MDEitherFieldImpl<MDSignedField, MDUnsignedField> { - MDSignedOrUnsignedField() : ImplTy(MDSignedField(0), MDUnsignedField(0)) {} - - bool isMDSignedField() const { return WhatIs == IsTypeA; } - bool isMDUnsignedField() const { return WhatIs == IsTypeB; } - int64_t getMDSignedValue() const { - assert(isMDSignedField() && "Wrong field type"); - return A.Val; - } - uint64_t getMDUnsignedValue() const { - assert(isMDUnsignedField() && "Wrong field type"); - return B.Val; - } -}; - } // end anonymous namespace namespace llvm { @@ -4578,7 +4556,8 @@ bool LLParser::parseDIDerivedType(MDNode *&Result, bool IsDistinct) { OPTIONAL(offset, MDUnsignedField, (0, UINT64_MAX)); \ OPTIONAL(flags, DIFlagField, ); \ OPTIONAL(extraData, MDField, ); \ - OPTIONAL(dwarfAddressSpace, MDUnsignedField, (UINT32_MAX, UINT32_MAX)); + OPTIONAL(dwarfAddressSpace, MDUnsignedField, (UINT32_MAX, UINT32_MAX)); \ + OPTIONAL(annotations, MDField, ); PARSE_MD_FIELDS(); #undef VISIT_MD_FIELDS @@ -4590,7 +4569,7 @@ bool LLParser::parseDIDerivedType(MDNode *&Result, bool IsDistinct) { (Context, tag.Val, name.Val, file.Val, line.Val, scope.Val, baseType.Val, size.Val, align.Val, offset.Val, DWARFAddressSpace, flags.Val, - extraData.Val)); + extraData.Val, annotations.Val)); return false; } @@ -4615,7 +4594,8 @@ bool LLParser::parseDICompositeType(MDNode *&Result, bool IsDistinct) { OPTIONAL(dataLocation, MDField, ); \ OPTIONAL(associated, MDField, ); \ OPTIONAL(allocated, MDField, ); \ - OPTIONAL(rank, MDSignedOrMDField, ); + OPTIONAL(rank, MDSignedOrMDField, ); \ + OPTIONAL(annotations, MDField, ); PARSE_MD_FIELDS(); #undef VISIT_MD_FIELDS @@ -4633,7 +4613,7 @@ bool LLParser::parseDICompositeType(MDNode *&Result, bool IsDistinct) { scope.Val, baseType.Val, size.Val, align.Val, offset.Val, flags.Val, elements.Val, runtimeLang.Val, vtableHolder.Val, templateParams.Val, discriminator.Val, dataLocation.Val, associated.Val, allocated.Val, - Rank)) { + Rank, annotations.Val)) { Result = CT; return false; } @@ -4645,8 +4625,8 @@ bool LLParser::parseDICompositeType(MDNode *&Result, bool IsDistinct) { (Context, tag.Val, name.Val, file.Val, line.Val, scope.Val, baseType.Val, size.Val, align.Val, offset.Val, flags.Val, elements.Val, runtimeLang.Val, vtableHolder.Val, templateParams.Val, identifier.Val, - discriminator.Val, dataLocation.Val, associated.Val, allocated.Val, - Rank)); + discriminator.Val, dataLocation.Val, associated.Val, allocated.Val, Rank, + annotations.Val)); return false; } @@ -4746,7 +4726,8 @@ bool LLParser::parseDICompileUnit(MDNode *&Result, bool IsDistinct) { /// virtuality: DW_VIRTUALTIY_pure_virtual, /// virtualIndex: 10, thisAdjustment: 4, flags: 11, /// spFlags: 10, isOptimized: false, templateParams: !4, -/// declaration: !5, retainedNodes: !6, thrownTypes: !7) +/// declaration: !5, retainedNodes: !6, thrownTypes: !7, +/// annotations: !8) bool LLParser::parseDISubprogram(MDNode *&Result, bool IsDistinct) { auto Loc = Lex.getLoc(); #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ @@ -4770,7 +4751,8 @@ bool LLParser::parseDISubprogram(MDNode *&Result, bool IsDistinct) { OPTIONAL(templateParams, MDField, ); \ OPTIONAL(declaration, MDField, ); \ OPTIONAL(retainedNodes, MDField, ); \ - OPTIONAL(thrownTypes, MDField, ); + OPTIONAL(thrownTypes, MDField, ); \ + OPTIONAL(annotations, MDField, ); PARSE_MD_FIELDS(); #undef VISIT_MD_FIELDS @@ -4789,7 +4771,7 @@ bool LLParser::parseDISubprogram(MDNode *&Result, bool IsDistinct) { (Context, scope.Val, name.Val, linkageName.Val, file.Val, line.Val, type.Val, scopeLine.Val, containingType.Val, virtualIndex.Val, thisAdjustment.Val, flags.Val, SPFlags, unit.Val, templateParams.Val, - declaration.Val, retainedNodes.Val, thrownTypes.Val)); + declaration.Val, retainedNodes.Val, thrownTypes.Val, annotations.Val)); return false; } @@ -4966,7 +4948,8 @@ bool LLParser::parseDIGlobalVariable(MDNode *&Result, bool IsDistinct) { OPTIONAL(isDefinition, MDBoolField, (true)); \ OPTIONAL(templateParams, MDField, ); \ OPTIONAL(declaration, MDField, ); \ - OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); + OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); \ + OPTIONAL(annotations, MDField, ); PARSE_MD_FIELDS(); #undef VISIT_MD_FIELDS @@ -4974,7 +4957,8 @@ bool LLParser::parseDIGlobalVariable(MDNode *&Result, bool IsDistinct) { GET_OR_DISTINCT(DIGlobalVariable, (Context, scope.Val, name.Val, linkageName.Val, file.Val, line.Val, type.Val, isLocal.Val, isDefinition.Val, - declaration.Val, templateParams.Val, align.Val)); + declaration.Val, templateParams.Val, align.Val, + annotations.Val)); return false; } @@ -4994,13 +4978,15 @@ bool LLParser::parseDILocalVariable(MDNode *&Result, bool IsDistinct) { OPTIONAL(line, LineField, ); \ OPTIONAL(type, MDField, ); \ OPTIONAL(flags, DIFlagField, ); \ - OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); + OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); \ + OPTIONAL(annotations, MDField, ); PARSE_MD_FIELDS(); #undef VISIT_MD_FIELDS Result = GET_OR_DISTINCT(DILocalVariable, (Context, scope.Val, name.Val, file.Val, line.Val, - type.Val, arg.Val, flags.Val, align.Val)); + type.Val, arg.Val, flags.Val, align.Val, + annotations.Val)); return false; } @@ -5136,7 +5122,7 @@ bool LLParser::parseDIObjCProperty(MDNode *&Result, bool IsDistinct) { /// parseDIImportedEntity: /// ::= !DIImportedEntity(tag: DW_TAG_imported_module, scope: !0, entity: !1, -/// line: 7, name: "foo") +/// line: 7, name: "foo", elements: !2) bool LLParser::parseDIImportedEntity(MDNode *&Result, bool IsDistinct) { #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ REQUIRED(tag, DwarfTagField, ); \ @@ -5144,13 +5130,14 @@ bool LLParser::parseDIImportedEntity(MDNode *&Result, bool IsDistinct) { OPTIONAL(entity, MDField, ); \ OPTIONAL(file, MDField, ); \ OPTIONAL(line, LineField, ); \ - OPTIONAL(name, MDStringField, ); + OPTIONAL(name, MDStringField, ); \ + OPTIONAL(elements, MDField, ); PARSE_MD_FIELDS(); #undef VISIT_MD_FIELDS - Result = GET_OR_DISTINCT( - DIImportedEntity, - (Context, tag.Val, scope.Val, entity.Val, file.Val, line.Val, name.Val)); + Result = GET_OR_DISTINCT(DIImportedEntity, + (Context, tag.Val, scope.Val, entity.Val, file.Val, + line.Val, name.Val, elements.Val)); return false; } @@ -5254,7 +5241,7 @@ bool LLParser::parseMetadata(Metadata *&MD, PerFunctionState *PFS) { //===----------------------------------------------------------------------===// bool LLParser::convertValIDToValue(Type *Ty, ValID &ID, Value *&V, - PerFunctionState *PFS, bool IsCall) { + PerFunctionState *PFS) { if (Ty->isFunctionTy()) return error(ID.Loc, "functions are not values, refer to them as pointers"); @@ -5262,12 +5249,12 @@ bool LLParser::convertValIDToValue(Type *Ty, ValID &ID, Value *&V, case ValID::t_LocalID: if (!PFS) return error(ID.Loc, "invalid use of function-local name"); - V = PFS->getVal(ID.UIntVal, Ty, ID.Loc, IsCall); + V = PFS->getVal(ID.UIntVal, Ty, ID.Loc); return V == nullptr; case ValID::t_LocalName: if (!PFS) return error(ID.Loc, "invalid use of function-local name"); - V = PFS->getVal(ID.StrVal, Ty, ID.Loc, IsCall); + V = PFS->getVal(ID.StrVal, Ty, ID.Loc); return V == nullptr; case ValID::t_InlineAsm: { if (!ID.FTy || !InlineAsm::Verify(ID.FTy, ID.StrVal2)) @@ -5278,10 +5265,10 @@ bool LLParser::convertValIDToValue(Type *Ty, ValID &ID, Value *&V, return false; } case ValID::t_GlobalName: - V = getGlobalVal(ID.StrVal, Ty, ID.Loc, IsCall); + V = getGlobalVal(ID.StrVal, Ty, ID.Loc); return V == nullptr; case ValID::t_GlobalID: - V = getGlobalVal(ID.UIntVal, Ty, ID.Loc, IsCall); + V = getGlobalVal(ID.UIntVal, Ty, ID.Loc); return V == nullptr; case ValID::t_APSInt: if (!Ty->isIntegerTy()) @@ -5405,7 +5392,7 @@ bool LLParser::parseConstantValue(Type *Ty, Constant *&C) { case ValID::t_ConstantStruct: case ValID::t_PackedConstantStruct: { Value *V; - if (convertValIDToValue(Ty, ID, V, /*PFS=*/nullptr, /*IsCall=*/false)) + if (convertValIDToValue(Ty, ID, V, /*PFS=*/nullptr)) return true; assert(isa<Constant>(V) && "Expected a constant value"); C = cast<Constant>(V); @@ -5423,7 +5410,7 @@ bool LLParser::parseValue(Type *Ty, Value *&V, PerFunctionState *PFS) { V = nullptr; ValID ID; return parseValID(ID, PFS, Ty) || - convertValIDToValue(Ty, ID, V, PFS, /*IsCall=*/false); + convertValIDToValue(Ty, ID, V, PFS); } bool LLParser::parseTypeAndValue(Value *&V, PerFunctionState *PFS) { @@ -5571,7 +5558,7 @@ bool LLParser::parseFunctionHeader(Function *&Fn, bool IsDefine) { AttributeList::get(Context, AttributeSet::get(Context, FuncAttrs), AttributeSet::get(Context, RetAttrs), Attrs); - if (PAL.hasAttribute(1, Attribute::StructRet) && !RetType->isVoidTy()) + if (PAL.hasParamAttr(0, Attribute::StructRet) && !RetType->isVoidTy()) return error(RetTypeLoc, "functions with 'sret' argument must return void"); FunctionType *FT = FunctionType::get(RetType, ParamTypeList, IsVarArg); @@ -5718,7 +5705,7 @@ bool LLParser::PerFunctionState::resolveForwardRefBlockAddresses() { Value *ResolvedVal = BlockAddress::get(&F, BB); ResolvedVal = P.checkValidVariableType(BBID.Loc, BBID.StrVal, GV->getType(), - ResolvedVal, false); + ResolvedVal); if (!ResolvedVal) return true; GV->replaceAllUsesWith(ResolvedVal); @@ -6287,7 +6274,7 @@ bool LLParser::parseInvoke(Instruction *&Inst, PerFunctionState &PFS) { // Look up the callee. Value *Callee; if (convertValIDToValue(PointerType::get(Ty, InvokeAddrSpace), CalleeID, - Callee, &PFS, /*IsCall=*/true)) + Callee, &PFS)) return true; // Set up the Attribute for the function. @@ -6612,8 +6599,7 @@ bool LLParser::parseCallBr(Instruction *&Inst, PerFunctionState &PFS) { // Look up the callee. Value *Callee; - if (convertValIDToValue(PointerType::getUnqual(Ty), CalleeID, Callee, &PFS, - /*IsCall=*/true)) + if (convertValIDToValue(PointerType::getUnqual(Ty), CalleeID, Callee, &PFS)) return true; // Set up the Attribute for the function. @@ -7019,7 +7005,7 @@ bool LLParser::parseCall(Instruction *&Inst, PerFunctionState &PFS, // Look up the callee. Value *Callee; if (convertValIDToValue(PointerType::get(Ty, CallAddrSpace), CalleeID, Callee, - &PFS, /*IsCall=*/true)) + &PFS)) return true; // Set up the Attribute for the function. @@ -8543,12 +8529,15 @@ bool LLParser::parseFlag(unsigned &Val) { /// [',' 'returnDoesNotAlias' ':' Flag]? ')' /// [',' 'noInline' ':' Flag]? ')' /// [',' 'alwaysInline' ':' Flag]? ')' +/// [',' 'noUnwind' ':' Flag]? ')' +/// [',' 'mayThrow' ':' Flag]? ')' +/// [',' 'hasUnknownCall' ':' Flag]? ')' bool LLParser::parseOptionalFFlags(FunctionSummary::FFlags &FFlags) { assert(Lex.getKind() == lltok::kw_funcFlags); Lex.Lex(); - if (parseToken(lltok::colon, "expected ':' in funcFlags") | + if (parseToken(lltok::colon, "expected ':' in funcFlags") || parseToken(lltok::lparen, "expected '(' in funcFlags")) return true; @@ -8591,6 +8580,24 @@ bool LLParser::parseOptionalFFlags(FunctionSummary::FFlags &FFlags) { return true; FFlags.AlwaysInline = Val; break; + case lltok::kw_noUnwind: + Lex.Lex(); + if (parseToken(lltok::colon, "expected ':'") || parseFlag(Val)) + return true; + FFlags.NoUnwind = Val; + break; + case lltok::kw_mayThrow: + Lex.Lex(); + if (parseToken(lltok::colon, "expected ':'") || parseFlag(Val)) + return true; + FFlags.MayThrow = Val; + break; + case lltok::kw_hasUnknownCall: + Lex.Lex(); + if (parseToken(lltok::colon, "expected ':'") || parseFlag(Val)) + return true; + FFlags.HasUnknownCall = Val; + break; default: return error(Lex.getLoc(), "expected function flag type"); } @@ -8610,7 +8617,7 @@ bool LLParser::parseOptionalCalls(std::vector<FunctionSummary::EdgeTy> &Calls) { assert(Lex.getKind() == lltok::kw_calls); Lex.Lex(); - if (parseToken(lltok::colon, "expected ':' in calls") | + if (parseToken(lltok::colon, "expected ':' in calls") || parseToken(lltok::lparen, "expected '(' in calls")) return true; @@ -8702,7 +8709,7 @@ bool LLParser::parseOptionalVTableFuncs(VTableFuncList &VTableFuncs) { assert(Lex.getKind() == lltok::kw_vTableFuncs); Lex.Lex(); - if (parseToken(lltok::colon, "expected ':' in vTableFuncs") | + if (parseToken(lltok::colon, "expected ':' in vTableFuncs") || parseToken(lltok::lparen, "expected '(' in vTableFuncs")) return true; |