[PATCH] D142645: [llvm][misexpect][NFC] Small code cleanups in MisExpect.cpp

Paul Kirth via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 26 10:11:06 PST 2023


paulkirth updated this revision to Diff 492502.
paulkirth added a comment.

Rebase.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142645/new/

https://reviews.llvm.org/D142645

Files:
  llvm/lib/IR/ProfDataUtils.cpp
  llvm/lib/Transforms/Utils/MisExpect.cpp


Index: llvm/lib/Transforms/Utils/MisExpect.cpp
===================================================================
--- llvm/lib/Transforms/Utils/MisExpect.cpp
+++ llvm/lib/Transforms/Utils/MisExpect.cpp
@@ -80,8 +80,8 @@
 Instruction *getInstCondition(Instruction *I) {
   assert(I != nullptr && "MisExpect target Instruction cannot be nullptr");
   Instruction *Ret = nullptr;
-  if (auto *B = dyn_cast<BranchInst>(I)) {
-    Ret = dyn_cast<Instruction>(B->getCondition());
+  if (auto *BI = dyn_cast<BranchInst>(I)) {
+    Ret = dyn_cast<Instruction>(BI->getCondition());
   }
   // TODO: Find a way to resolve condition location for switches
   // Using the condition of the switch seems to often resolve to an earlier
@@ -92,8 +92,8 @@
   // for branch instructions, then we should remove this function and directly
   // use the instruction
   //
-  else if (auto *S = dyn_cast<SwitchInst>(I)) {
-    Ret = dyn_cast<Instruction>(S->getCondition());
+  else if (auto *SI = dyn_cast<SwitchInst>(I)) {
+    Ret = dyn_cast<Instruction>(SI->getCondition());
   }
   return Ret ? Ret : I;
 }
@@ -163,13 +163,13 @@
   // To determine our threshold value we need to obtain the branch probability
   // for the weights added by llvm.expect and use that proportion to calculate
   // our threshold based on the collected profile data.
-  auto LikelyProbablilty = BranchProbability::getBranchProbability(
+  BranchProbability LikelyProbablilty = BranchProbability::getBranchProbability(
       LikelyBranchWeight, TotalBranchWeight);
 
   uint64_t ScaledThreshold = LikelyProbablilty.scale(RealWeightsTotal);
 
   // clamp tolerance range to [0, 100)
-  auto Tolerance = getMisExpectTolerance(I.getContext());
+  uint32_t Tolerance = getMisExpectTolerance(I.getContext());
   Tolerance = std::clamp(Tolerance, 0u, 99u);
 
   // Allow users to relax checking by N%  i.e., if they use a 5% tolerance,
Index: llvm/lib/IR/ProfDataUtils.cpp
===================================================================
--- llvm/lib/IR/ProfDataUtils.cpp
+++ llvm/lib/IR/ProfDataUtils.cpp
@@ -114,7 +114,8 @@
 
 MDNode *getValidBranchWeightMDNode(const Instruction &I) {
   auto *ProfileData = getBranchWeightMDNode(I);
-  if (ProfileData && ProfileData->getNumOperands() == 1 + I.getNumSuccessors())
+  if (ProfileData &&
+      ProfileData->getNumOperands() == WeightsIdx + I.getNumSuccessors())
     return ProfileData;
   return nullptr;
 }
@@ -128,7 +129,7 @@
 
 bool extractBranchWeights(const Instruction &I,
                           SmallVectorImpl<uint32_t> &Weights) {
-  auto *ProfileData = I.getMetadata(LLVMContext::MD_prof);
+  MDNode *ProfileData = I.getMetadata(LLVMContext::MD_prof);
   return extractBranchWeights(ProfileData, Weights);
 }
 
@@ -140,7 +141,7 @@
          "switch");
 
   SmallVector<uint32_t, 2> Weights;
-  auto *ProfileData = I.getMetadata(LLVMContext::MD_prof);
+  MDNode *ProfileData = I.getMetadata(LLVMContext::MD_prof);
   if (!extractBranchWeights(ProfileData, Weights))
     return false;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142645.492502.patch
Type: text/x-patch
Size: 3014 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230126/1a17217d/attachment.bin>


More information about the llvm-commits mailing list