Skip to content

Commit ff4c690

Browse files
committed
[IR][PGO] Verify the structure of VP metadata.
1 parent 62f8281 commit ff4c690

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

llvm/include/llvm/IR/ProfDataUtils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ LLVM_ABI bool hasProfMD(const Instruction &I);
2828
/// Checks if an MDNode contains Branch Weight Metadata
2929
LLVM_ABI bool isBranchWeightMD(const MDNode *ProfileData);
3030

31+
/// Checks if an MDNode contains value profiling Metadata
32+
LLVM_ABI bool isValueProfileMD(const MDNode *ProfileData);
33+
3134
/// Checks if an instructions has Branch Weight Metadata
3235
///
3336
/// \param I The instruction to check

llvm/lib/IR/ProfDataUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ bool isBranchWeightMD(const MDNode *ProfileData) {
9696
return isTargetMD(ProfileData, "branch_weights", MinBWOps);
9797
}
9898

99-
static bool isValueProfileMD(const MDNode *ProfileData) {
99+
bool isValueProfileMD(const MDNode *ProfileData) {
100100
return isTargetMD(ProfileData, "VP", MinVPOps);
101101
}
102102

llvm/lib/IR/Verifier.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5026,9 +5026,14 @@ void Verifier::visitProfMetadata(Instruction &I, MDNode *MD) {
50265026
Check(mdconst::dyn_extract<ConstantInt>(MDO),
50275027
"!prof brunch_weights operand is not a const int");
50285028
}
5029-
} else {
5030-
Check(ProfName == "VP", "expected either branch_weights or VP profile name",
5029+
} else if (ProfName == "VP") {
5030+
Check(isValueProfileMD(MD),"invalid value profiling metadata",MD);
5031+
Check(isa<CallBase>(I),
5032+
"value profiling !prof metadata is expected to be placed on call "
5033+
"instructions (which may be memops)",
50315034
MD);
5035+
} else {
5036+
CheckFailed("expected either branch_weights or VP profile name", MD);
50325037
}
50335038
}
50345039

0 commit comments

Comments
 (0)