+void Verifier::VerifyFunctionMetadata(
+ const SmallVector<std::pair<unsigned, MDNode *>, 4> MDs) {
+ if (MDs.empty())
+ return;
+
+ for (unsigned i = 0; i < MDs.size(); i++) {
+ if (MDs[i].first == LLVMContext::MD_prof) {
+ MDNode *MD = MDs[i].second;
+ Assert(MD->getNumOperands() == 2,
+ "!prof annotations should have exactly 2 operands", MD);
+
+ // Check first operand.
+ Assert(MD->getOperand(0) != nullptr, "first operand should not be null",
+ MD);
+ Assert(isa<MDString>(MD->getOperand(0)),
+ "expected string with name of the !prof annotation", MD);
+ MDString *MDS = cast<MDString>(MD->getOperand(0));
+ StringRef ProfName = MDS->getString();
+ Assert(ProfName.equals("function_entry_count"),
+ "first operand should be 'function_entry_count'", MD);
+
+ // Check second operand.
+ Assert(MD->getOperand(1) != nullptr, "second operand should not be null",
+ MD);
+ Assert(isa<ConstantAsMetadata>(MD->getOperand(1)),
+ "expected integer argument to function_entry_count", MD);
+ }
+ }
+}
+