-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Transforms] Migrate to a new version of getValueProfDataFromInst #96380
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
Merged
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:cleanup_ProfileData_getValueProfDataFromInst_Transforms
Jun 30, 2024
Merged
[Transforms] Migrate to a new version of getValueProfDataFromInst #96380
kazutakahirata
merged 1 commit into
llvm:main
from
kazutakahirata:cleanup_ProfileData_getValueProfDataFromInst_Transforms
Jun 30, 2024
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-pgo @llvm/pr-subscribers-llvm-transforms Author: Kazu Hirata (kazutakahirata) ChangesFull diff: https://github.com/llvm/llvm-project/pull/96380.diff 3 Files Affected:
diff --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp
index 61078c4194b81..d11b0b76b28c5 100644
--- a/llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp
@@ -788,25 +788,23 @@ SampleProfileLoader::findFunctionSamples(const Instruction &Inst) const {
/// NOMORE_ICP_MAGICNUM count values in the value profile of \p Inst, we
/// cannot promote for \p Inst anymore.
static bool doesHistoryAllowICP(const Instruction &Inst, StringRef Candidate) {
- uint32_t NumVals = 0;
uint64_t TotalCount = 0;
- auto ValueData =
- getValueProfDataFromInst(Inst, IPVK_IndirectCallTarget, MaxNumPromotions,
- NumVals, TotalCount, true);
+ auto ValueData = getValueProfDataFromInst(Inst, IPVK_IndirectCallTarget,
+ MaxNumPromotions, TotalCount, true);
// No valid value profile so no promoted targets have been recorded
// before. Ok to do ICP.
- if (!ValueData)
+ if (ValueData.empty())
return true;
unsigned NumPromoted = 0;
- for (uint32_t I = 0; I < NumVals; I++) {
- if (ValueData[I].Count != NOMORE_ICP_MAGICNUM)
+ for (const auto &V : ValueData) {
+ if (V.Count != NOMORE_ICP_MAGICNUM)
continue;
// If the promotion candidate has NOMORE_ICP_MAGICNUM count in the
// metadata, it means the candidate has been promoted for this
// indirect call.
- if (ValueData[I].Value == Function::getGUID(Candidate))
+ if (V.Value == Function::getGUID(Candidate))
return false;
NumPromoted++;
// If already have MaxNumPromotions promotion, don't do it anymore.
@@ -832,11 +830,10 @@ updateIDTMetaData(Instruction &Inst,
// `MaxNumPromotions` inside it.
if (MaxNumPromotions == 0)
return;
- uint32_t NumVals = 0;
// OldSum is the existing total count in the value profile data.
uint64_t OldSum = 0;
- auto ValueData = getValueProfDataFromInst(
- Inst, IPVK_IndirectCallTarget, MaxNumPromotions, NumVals, OldSum, true);
+ auto ValueData = getValueProfDataFromInst(Inst, IPVK_IndirectCallTarget,
+ MaxNumPromotions, OldSum, true);
DenseMap<uint64_t, uint64_t> ValueCountMap;
if (Sum == 0) {
@@ -845,10 +842,8 @@ updateIDTMetaData(Instruction &Inst,
"If sum is 0, assume only one element in CallTargets "
"with count being NOMORE_ICP_MAGICNUM");
// Initialize ValueCountMap with existing value profile data.
- if (ValueData) {
- for (uint32_t I = 0; I < NumVals; I++)
- ValueCountMap[ValueData[I].Value] = ValueData[I].Count;
- }
+ for (const auto &V : ValueData)
+ ValueCountMap[V.Value] = V.Count;
auto Pair =
ValueCountMap.try_emplace(CallTargets[0].Value, CallTargets[0].Count);
// If the target already exists in value profile, decrease the total
@@ -861,11 +856,9 @@ updateIDTMetaData(Instruction &Inst,
} else {
// Initialize ValueCountMap with existing NOMORE_ICP_MAGICNUM
// counts in the value profile.
- if (ValueData) {
- for (uint32_t I = 0; I < NumVals; I++) {
- if (ValueData[I].Count == NOMORE_ICP_MAGICNUM)
- ValueCountMap[ValueData[I].Value] = ValueData[I].Count;
- }
+ for (const auto &V : ValueData) {
+ if (V.Count == NOMORE_ICP_MAGICNUM)
+ ValueCountMap[V.Value] = V.Count;
}
for (const auto &Data : CallTargets) {
diff --git a/llvm/lib/Transforms/Instrumentation/CGProfile.cpp b/llvm/lib/Transforms/Instrumentation/CGProfile.cpp
index 651239bee91f9..1b07321c4f355 100644
--- a/llvm/lib/Transforms/Instrumentation/CGProfile.cpp
+++ b/llvm/lib/Transforms/Instrumentation/CGProfile.cpp
@@ -78,16 +78,11 @@ static bool runCGProfilePass(Module &M, FunctionAnalysisManager &FAM,
if (!CB)
continue;
if (CB->isIndirectCall()) {
- uint32_t ActualNumValueData;
uint64_t TotalC;
- auto ValueData = getValueProfDataFromInst(
- *CB, IPVK_IndirectCallTarget, 8, ActualNumValueData, TotalC);
- if (!ValueData)
- continue;
- for (const auto &VD : ArrayRef<InstrProfValueData>(
- ValueData.get(), ActualNumValueData)) {
+ auto ValueData =
+ getValueProfDataFromInst(*CB, IPVK_IndirectCallTarget, 8, TotalC);
+ for (const auto &VD : ValueData)
UpdateCounts(TTI, &F, Symtab.getFunction(VD.Value), VD.Count);
- }
continue;
}
UpdateCounts(TTI, &F, CB->getCalledFunction(), *BBCount);
diff --git a/llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp b/llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp
index ec19942c1d5f4..dc51c564fbe0d 100644
--- a/llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp
+++ b/llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp
@@ -247,12 +247,11 @@ bool MemOPSizeOpt::perform(MemOp MO) {
if (!MemOPOptMemcmpBcmp && (MO.isMemcmp(TLI) || MO.isBcmp(TLI)))
return false;
- uint32_t NumVals = INSTR_PROF_NUM_BUCKETS;
uint32_t MaxNumVals = INSTR_PROF_NUM_BUCKETS;
uint64_t TotalCount;
- auto ValueDataArray = getValueProfDataFromInst(
- *MO.I, IPVK_MemOPSize, MaxNumVals, NumVals, TotalCount);
- if (!ValueDataArray)
+ auto VDs =
+ getValueProfDataFromInst(*MO.I, IPVK_MemOPSize, MaxNumVals, TotalCount);
+ if (VDs.empty())
return false;
uint64_t ActualCount = TotalCount;
@@ -264,7 +263,6 @@ bool MemOPSizeOpt::perform(MemOp MO) {
ActualCount = *BBEdgeCount;
}
- ArrayRef<InstrProfValueData> VDs(ValueDataArray.get(), NumVals);
LLVM_DEBUG(dbgs() << "Read one memory intrinsic profile with count "
<< ActualCount << "\n");
LLVM_DEBUG(
@@ -397,10 +395,10 @@ bool MemOPSizeOpt::perform(MemOp MO) {
// Clear the value profile data.
MO.I->setMetadata(LLVMContext::MD_prof, nullptr);
// If all promoted, we don't need the MD.prof metadata.
- if (SavedRemainCount > 0 || Version != NumVals) {
+ if (SavedRemainCount > 0 || Version != VDs.size()) {
// Otherwise we need update with the un-promoted records back.
annotateValueSite(*Func.getParent(), *MO.I, RemainingVDs, SavedRemainCount,
- IPVK_MemOPSize, NumVals);
+ IPVK_MemOPSize, VDs.size());
}
LLVM_DEBUG(dbgs() << "\n\n== Basic Block After==\n");
|
Friendly ping. Thanks! |
mingmingl-llvm
approved these changes
Jun 30, 2024
lravenclaw
pushed a commit
to lravenclaw/llvm-project
that referenced
this pull request
Jul 3, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.