[PATCH] D156323: [TargetLowering] Remove unused basic block parameter from `getMaxPermittedBytesForAlignment` (NFC)

Momchil Velikov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 26 05:40:23 PDT 2023


chill created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
chill requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The `MachineBlockPlacement` computes and sets the alignment and the
maximum allowed padding for each basic block. It makes no sense to
split these parts of computation that depend on the specific basic
block across different components of the compiler.


https://reviews.llvm.org/D156323

Files:
  llvm/include/llvm/CodeGen/TargetLowering.h
  llvm/lib/CodeGen/MachineBlockPlacement.cpp
  llvm/lib/CodeGen/TargetLoweringBase.cpp


Index: llvm/lib/CodeGen/TargetLoweringBase.cpp
===================================================================
--- llvm/lib/CodeGen/TargetLoweringBase.cpp
+++ llvm/lib/CodeGen/TargetLoweringBase.cpp
@@ -2058,8 +2058,7 @@
   return PrefLoopAlignment;
 }
 
-unsigned TargetLoweringBase::getMaxPermittedBytesForAlignment(
-    MachineBasicBlock *MBB) const {
+unsigned TargetLoweringBase::getMaxPermittedBytesForAlignment() const {
   return MaxBytesForAlignment;
 }
 
Index: llvm/lib/CodeGen/MachineBlockPlacement.cpp
===================================================================
--- llvm/lib/CodeGen/MachineBlockPlacement.cpp
+++ llvm/lib/CodeGen/MachineBlockPlacement.cpp
@@ -399,6 +399,8 @@
 
   ProfileSummaryInfo *PSI = nullptr;
 
+  unsigned MaxBytesForAlignment = 0;
+
   /// Duplicator used to duplicate tails during placement.
   ///
   /// Placement decisions can open up new tail duplication opportunities, but
@@ -2945,21 +2947,10 @@
     MachineBasicBlock *LayoutPred =
         &*std::prev(MachineFunction::iterator(ChainBB));
 
-    auto DetermineMaxAlignmentPadding = [&]() {
-      // Set the maximum bytes allowed to be emitted for alignment.
-      unsigned MaxBytes;
-      if (MaxBytesForAlignmentOverride.getNumOccurrences() > 0)
-        MaxBytes = MaxBytesForAlignmentOverride;
-      else
-        MaxBytes = TLI->getMaxPermittedBytesForAlignment(ChainBB);
-      ChainBB->setMaxBytesForAlignment(MaxBytes);
-    };
-
     // Force alignment if all the predecessors are jumps. We already checked
     // that the block isn't cold above.
     if (!LayoutPred->isSuccessor(ChainBB)) {
-      ChainBB->setAlignment(Align);
-      DetermineMaxAlignmentPadding();
+      ChainBB->setAlignment(Align, MaxBytesForAlignment);
       continue;
     }
 
@@ -2970,10 +2961,8 @@
     BranchProbability LayoutProb =
         MBPI->getEdgeProbability(LayoutPred, ChainBB);
     BlockFrequency LayoutEdgeFreq = MBFI->getBlockFreq(LayoutPred) * LayoutProb;
-    if (LayoutEdgeFreq <= (Freq * ColdProb)) {
-      ChainBB->setAlignment(Align);
-      DetermineMaxAlignmentPadding();
-    }
+    if (LayoutEdgeFreq <= (Freq * ColdProb))
+      ChainBB->setAlignment(Align, MaxBytesForAlignment);
   }
 }
 
@@ -3356,6 +3345,12 @@
   MPDT = nullptr;
   PSI = &getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI();
 
+  // Set the maximum bytes allowed to be emitted for alignment.
+  if (MaxBytesForAlignmentOverride.getNumOccurrences() > 0)
+    MaxBytesForAlignment = MaxBytesForAlignmentOverride;
+  else
+    MaxBytesForAlignment = TLI->getMaxPermittedBytesForAlignment();
+
   initDupThreshold();
 
   // Initialize PreferredLoopExit to nullptr here since it may never be set if
Index: llvm/include/llvm/CodeGen/TargetLowering.h
===================================================================
--- llvm/include/llvm/CodeGen/TargetLowering.h
+++ llvm/include/llvm/CodeGen/TargetLowering.h
@@ -1893,8 +1893,7 @@
 
   /// Return the maximum amount of bytes allowed to be emitted when padding for
   /// alignment
-  virtual unsigned
-  getMaxPermittedBytesForAlignment(MachineBasicBlock *MBB) const;
+  virtual unsigned getMaxPermittedBytesForAlignment() const;
 
   /// Should loops be aligned even when the function is marked OptSize (but not
   /// MinSize).


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156323.544325.patch
Type: text/x-patch
Size: 3280 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230726/710ec179/attachment.bin>


More information about the llvm-commits mailing list