[llvm] [Transforms] Migrate to a new version of getValueProfDataFromInst (PR #95442)
Mingming Liu via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 14 09:30:16 PDT 2024
https://github.com/minglotus-6 updated https://github.com/llvm/llvm-project/pull/95442
>From 6b551beac9a17b20948bfec134f60a2bda5c25dc Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Wed, 12 Jun 2024 22:08:07 -0700
Subject: [PATCH 1/2] [Transforms] Migrate to a new version of
getValueProfDataFromInst
Note that the version of getValueProfDataFromInst that returns bool
has been "deprecated" since:
commit 1e15371dd8843dfc52b9435afaa133997c1773d8
Author: Mingming Liu <mingmingl at google.com>
Date: Mon Apr 1 15:14:49 2024 -0700
---
.../Transforms/Instrumentation/PGOMemOPSizeOpt.cpp | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp b/llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp
index fa93f4bd63ce6..2bf1737237964 100644
--- a/llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp
+++ b/llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp
@@ -177,10 +177,7 @@ class MemOPSizeOpt : public InstVisitor<MemOPSizeOpt> {
MemOPSizeOpt(Function &Func, BlockFrequencyInfo &BFI,
OptimizationRemarkEmitter &ORE, DominatorTree *DT,
TargetLibraryInfo &TLI)
- : Func(Func), BFI(BFI), ORE(ORE), DT(DT), TLI(TLI), Changed(false) {
- ValueDataArray =
- std::make_unique<InstrProfValueData[]>(INSTR_PROF_NUM_BUCKETS);
- }
+ : Func(Func), BFI(BFI), ORE(ORE), DT(DT), TLI(TLI), Changed(false) {}
bool isChanged() const { return Changed; }
void perform() {
WorkList.clear();
@@ -222,8 +219,6 @@ class MemOPSizeOpt : public InstVisitor<MemOPSizeOpt> {
TargetLibraryInfo &TLI;
bool Changed;
std::vector<MemOp> WorkList;
- // The space to read the profile annotation.
- std::unique_ptr<InstrProfValueData[]> ValueDataArray;
bool perform(MemOp MO);
};
@@ -254,8 +249,9 @@ bool MemOPSizeOpt::perform(MemOp MO) {
uint32_t NumVals, MaxNumVals = INSTR_PROF_NUM_BUCKETS;
uint64_t TotalCount;
- if (!getValueProfDataFromInst(*MO.I, IPVK_MemOPSize, MaxNumVals,
- ValueDataArray.get(), NumVals, TotalCount))
+ auto ValueDataArray = getValueProfDataFromInst(
+ *MO.I, IPVK_MemOPSize, MaxNumVals, NumVals, TotalCount);
+ if (!ValueDataArray)
return false;
uint64_t ActualCount = TotalCount;
>From 7248e8e4045e7ef6f333561b5e66bde9ac5cb24b Mon Sep 17 00:00:00 2001
From: Mingming Liu <minglotus6 at gmail.com>
Date: Fri, 14 Jun 2024 09:30:08 -0700
Subject: [PATCH 2/2] Prefer explicit initialization of each variable.
I don't have a pointer of code style discouraging `int a, b = c;` but let's make it a no-brainer.
---
llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp b/llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp
index 2bf1737237964..ec19942c1d5f4 100644
--- a/llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp
+++ b/llvm/lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp
@@ -247,7 +247,8 @@ bool MemOPSizeOpt::perform(MemOp MO) {
if (!MemOPOptMemcmpBcmp && (MO.isMemcmp(TLI) || MO.isBcmp(TLI)))
return false;
- uint32_t NumVals, MaxNumVals = INSTR_PROF_NUM_BUCKETS;
+ 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);
More information about the llvm-commits
mailing list