Skip to content

Commit 591bfc2

Browse files
committed
[IR][PGO] Verify the structure of VP metadata.
1 parent 3c77cbc commit 591bfc2

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
@@ -5008,9 +5008,14 @@ void Verifier::visitProfMetadata(Instruction &I, MDNode *MD) {
50085008
Check(mdconst::dyn_extract<ConstantInt>(MDO),
50095009
"!prof brunch_weights operand is not a const int");
50105010
}
5011-
} else {
5012-
Check(ProfName == "VP", "expected either branch_weights or VP profile name",
5011+
} else if (ProfName == "VP") {
5012+
Check(isValueProfileMD(MD),"invalid value profiling metadata",MD);
5013+
Check(isa<CallBase>(I),
5014+
"value profiling !prof metadata is expected to be placed on call "
5015+
"instructions (which may be memops)",
50135016
MD);
5017+
} else {
5018+
CheckFailed("expected either branch_weights or VP profile name", MD);
50145019
}
50155020
}
50165021

0 commit comments

Comments
 (0)