@@ -631,7 +631,7 @@ class Verifier : public InstVisitor<Verifier>, VerifierSupport {
631631 void verifyFunctionAttrs (FunctionType *FT, AttributeList Attrs,
632632 const Value *V, bool IsIntrinsic, bool IsInlineAsm);
633633 void verifyFunctionMetadata (ArrayRef<std::pair<unsigned , MDNode *>> MDs);
634-
634+ void verifyUnknownProfileMetadata (MDNode *MD);
635635 void visitConstantExprsRecursively (const Constant *EntryC);
636636 void visitConstantExpr (const ConstantExpr *CE);
637637 void visitConstantPtrAuth (const ConstantPtrAuth *CPA);
@@ -2515,19 +2515,31 @@ void Verifier::verifyFunctionAttrs(FunctionType *FT, AttributeList Attrs,
25152515 V);
25162516 }
25172517}
2518+ void Verifier::verifyUnknownProfileMetadata (MDNode *MD) {
2519+ Check (MD->getNumOperands () == 2 ,
2520+ " 'unknown' !prof should have a single additional operand" , MD);
2521+ auto *PassName = dyn_cast<MDString>(MD->getOperand (1 ));
2522+ Check (PassName != nullptr ,
2523+ " 'unknown' !prof should have an additional operand of type "
2524+ " string" );
2525+ Check (!PassName->getString ().empty (),
2526+ " the 'unknown' !prof operand should not be an empty string" );
2527+ }
25182528
25192529void Verifier::verifyFunctionMetadata (
25202530 ArrayRef<std::pair<unsigned , MDNode *>> MDs) {
25212531 for (const auto &Pair : MDs) {
25222532 if (Pair.first == LLVMContext::MD_prof) {
25232533 MDNode *MD = Pair.second ;
2534+ Check (MD->getNumOperands () >= 2 ,
2535+ " !prof annotations should have no less than 2 operands" , MD);
25242536 // We may have functions that are synthesized by the compiler, e.g. in
25252537 // WPD, that we can't currently determine the entry count.
2526- if (isExplicitlyUnknownProfileMetadata (*MD))
2538+ if (MD->getOperand (0 ).equalsStr (
2539+ MDProfLabels::UnknownBranchWeightsMarker)) {
2540+ verifyUnknownProfileMetadata (MD);
25272541 continue ;
2528-
2529- Check (MD->getNumOperands () >= 2 ,
2530- " !prof annotations should have no less than 2 operands" , MD);
2542+ }
25312543
25322544 // Check first operand.
25332545 Check (MD->getOperand (0 ) != nullptr , " first operand should not be null" ,
@@ -5054,8 +5066,7 @@ void Verifier::visitProfMetadata(Instruction &I, MDNode *MD) {
50545066 " 'unknown' !prof should only appear on instructions on which "
50555067 " 'branch_weights' would" ,
50565068 MD);
5057- Check (MD->getNumOperands () == 1 ,
5058- " 'unknown' !prof should have no additional operands" , MD);
5069+ verifyUnknownProfileMetadata (MD);
50595070 return ;
50605071 }
50615072
0 commit comments