-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[IR][PGO] Verify the structure of VP
metadata.
#145584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[IR][PGO] Verify the structure of VP
metadata.
#145584
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
You can test this locally with the following command:git-clang-format --diff HEAD~1 HEAD --extensions cpp,h -- llvm/include/llvm/IR/ProfDataUtils.h llvm/lib/IR/ProfDataUtils.cpp llvm/lib/IR/Verifier.cpp View the diff from clang-format here.diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 26d3b8b49..4cedc1139 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5028,7 +5028,7 @@ void Verifier::visitProfMetadata(Instruction &I, MDNode *MD) {
"!prof brunch_weights operand is not a const int");
}
} else if (ProfName == MDProfLabels::ValueProfile) {
- Check(isValueProfileMD(MD),"invalid value profiling metadata",MD);
+ Check(isValueProfileMD(MD), "invalid value profiling metadata", MD);
ConstantInt *KindInt = mdconst::dyn_extract<ConstantInt>(MD->getOperand(1));
Check(KindInt, "VP !prof missing kind argument", MD);
@@ -5036,7 +5036,8 @@ void Verifier::visitProfMetadata(Instruction &I, MDNode *MD) {
Check(Kind >= InstrProfValueKind::IPVK_First &&
Kind <= InstrProfValueKind::IPVK_Last,
"Invalid VP !prof kind", MD);
- if (Kind == InstrProfValueKind::IPVK_IndirectCallTarget || Kind == InstrProfValueKind::IPVK_MemOPSize)
+ if (Kind == InstrProfValueKind::IPVK_IndirectCallTarget ||
+ Kind == InstrProfValueKind::IPVK_MemOPSize)
Check(isa<CallBase>(I),
"VP !prof indirect call or memop size expected to be applied to "
"CallBase instructions only",
|
1464876
to
3cda0f3
Compare
f144d7f
to
a9742de
Compare
3cda0f3
to
8a91105
Compare
a9742de
to
02b36b7
Compare
8a91105
to
3c77cbc
Compare
02b36b7
to
591bfc2
Compare
591bfc2
to
ff4c690
Compare
llvm/lib/IR/Verifier.cpp
Outdated
Check(isValueProfileMD(MD),"invalid value profiling metadata",MD); | ||
Check(isa<CallBase>(I), | ||
"value profiling !prof metadata is expected to be placed on call " | ||
"instructions (which may be memops)", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't follow the memops comment. Can you elaborate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it was WIP. Fixed.
ff4c690
to
32e82d0
Compare
@llvm/pr-subscribers-llvm-ir Author: Mircea Trofin (mtrofin) ChangesFull diff: https://github.com/llvm/llvm-project/pull/145584.diff 3 Files Affected:
diff --git a/llvm/include/llvm/IR/ProfDataUtils.h b/llvm/include/llvm/IR/ProfDataUtils.h
index 5c0e08b03c245..c24b2aa19a407 100644
--- a/llvm/include/llvm/IR/ProfDataUtils.h
+++ b/llvm/include/llvm/IR/ProfDataUtils.h
@@ -35,6 +35,9 @@ LLVM_ABI bool hasProfMD(const Instruction &I);
/// Checks if an MDNode contains Branch Weight Metadata
LLVM_ABI bool isBranchWeightMD(const MDNode *ProfileData);
+/// Checks if an MDNode contains value profiling Metadata
+LLVM_ABI bool isValueProfileMD(const MDNode *ProfileData);
+
/// Checks if an instructions has Branch Weight Metadata
///
/// \param I The instruction to check
diff --git a/llvm/lib/IR/ProfDataUtils.cpp b/llvm/lib/IR/ProfDataUtils.cpp
index 740023ca6d23b..605208edda70a 100644
--- a/llvm/lib/IR/ProfDataUtils.cpp
+++ b/llvm/lib/IR/ProfDataUtils.cpp
@@ -103,7 +103,7 @@ bool isBranchWeightMD(const MDNode *ProfileData) {
return isTargetMD(ProfileData, MDProfLabels::BranchWeights, MinBWOps);
}
-static bool isValueProfileMD(const MDNode *ProfileData) {
+bool isValueProfileMD(const MDNode *ProfileData) {
return isTargetMD(ProfileData, MDProfLabels::ValueProfile, MinVPOps);
}
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 9cab88b09779a..26d3b8b49598b 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -112,6 +112,7 @@
#include "llvm/IR/Value.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
+#include "llvm/ProfileData/InstrProf.h"
#include "llvm/Support/AMDGPUAddrSpace.h"
#include "llvm/Support/AtomicOrdering.h"
#include "llvm/Support/Casting.h"
@@ -5026,9 +5027,22 @@ void Verifier::visitProfMetadata(Instruction &I, MDNode *MD) {
Check(mdconst::dyn_extract<ConstantInt>(MDO),
"!prof brunch_weights operand is not a const int");
}
+ } else if (ProfName == MDProfLabels::ValueProfile) {
+ Check(isValueProfileMD(MD),"invalid value profiling metadata",MD);
+ ConstantInt *KindInt = mdconst::dyn_extract<ConstantInt>(MD->getOperand(1));
+ Check(KindInt, "VP !prof missing kind argument", MD);
+
+ auto Kind = KindInt->getZExtValue();
+ Check(Kind >= InstrProfValueKind::IPVK_First &&
+ Kind <= InstrProfValueKind::IPVK_Last,
+ "Invalid VP !prof kind", MD);
+ if (Kind == InstrProfValueKind::IPVK_IndirectCallTarget || Kind == InstrProfValueKind::IPVK_MemOPSize)
+ Check(isa<CallBase>(I),
+ "VP !prof indirect call or memop size expected to be applied to "
+ "CallBase instructions only",
+ MD);
} else {
- Check(ProfName == MDProfLabels::ValueProfile,
- "expected either branch_weights or VP profile name", MD);
+ CheckFailed("expected either branch_weights or VP profile name", MD);
}
}
|
No description provided.