[llvm] [CodeLayout] Size-aware machine block placement (PR #109711)

via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 23 13:10:00 PDT 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 62f3eae466cc6af101a9bfa21e2af4ff5c95658d 19211550fb847b4ec869de63047d34e6d85947d7 --extensions cpp -- llvm/lib/CodeGen/MachineBlockPlacement.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/lib/CodeGen/MachineBlockPlacement.cpp b/llvm/lib/CodeGen/MachineBlockPlacement.cpp
index 3ee10381ee..a37509b90c 100644
--- a/llvm/lib/CodeGen/MachineBlockPlacement.cpp
+++ b/llvm/lib/CodeGen/MachineBlockPlacement.cpp
@@ -2969,7 +2969,7 @@ void MachineBlockPlacement::alignBlocks() {
   BlockChain &FunctionChain = *BlockToChain[&F->front()];
   // Empty chain.
   if (FunctionChain.begin() == FunctionChain.end())
-    return; 
+    return;
 
   const BranchProbability ColdProb(1, 5); // 20%
   BlockFrequency EntryFreq = MBFI->getBlockFreq(&F->front());
@@ -3455,7 +3455,7 @@ void MachineBlockPlacement::initTailDupThreshold() {
     if (HotThreshold != UINT64_MAX) {
       UseProfileCount = true;
       DupThreshold =
-          BlockFrequency(HotThreshold * TailDupProfilePercentThreshold / 100);      
+          BlockFrequency(HotThreshold * TailDupProfilePercentThreshold / 100);
     } else {
       // Profile count is not available, we can use block frequency instead.
       BlockFrequency MaxFreq = BlockFrequency(0);
@@ -3526,11 +3526,11 @@ bool MachineBlockPlacement::runOnMachineFunction(MachineFunction &MF) {
 
   // Initialize tail duplication thresholds.
   initTailDupThreshold();
-	
+
   const bool OptForSize =
       MF.getFunction().hasOptSize() ||
       llvm::shouldOptimizeForSize(&MF, PSI, &MBFI->getMBFI());
-  // Use ext-tsp for size optimization is possible only when the function 
+  // Use ext-tsp for size optimization is possible only when the function
   // contains more than two basic blocks.
   const bool UseExtTspForSize =
       OptForSize && ApplyExtTspForSize && MF.size() >= 3;
@@ -3543,7 +3543,7 @@ bool MachineBlockPlacement::runOnMachineFunction(MachineFunction &MF) {
     const bool PreRegAlloc = false;
     TailDup.initMF(MF, PreRegAlloc, MBPI, MBFI.get(), PSI,
                    /* LayoutMode */ true, TailDupSize);
-    if (!UseExtTspForSize)               
+    if (!UseExtTspForSize)
       precomputeTriangleChains();
   }
 
@@ -3555,9 +3555,8 @@ bool MachineBlockPlacement::runOnMachineFunction(MachineFunction &MF) {
   // TailMerge can create jump into if branches that make CFG irreducible for
   // HW that requires structured CFG.
   const bool EnableTailMerge = !MF.getTarget().requiresStructuredCFG() &&
-                         PassConfig->getEnableTailMerge() &&
-                         BranchFoldPlacement && 
-                         MF.size() > 3;
+                               PassConfig->getEnableTailMerge() &&
+                               BranchFoldPlacement && MF.size() > 3;
   // No tail merging opportunities if the block number is less than four.
   if (EnableTailMerge) {
     const unsigned TailMergeSize = TailDupSize + 1;
@@ -3577,7 +3576,6 @@ bool MachineBlockPlacement::runOnMachineFunction(MachineFunction &MF) {
     }
   }
 
-	
   // Apply a post-processing optimizing block placement:
   // - find a new placement and modify the layout of the blocks in the function;
   // - re-create CFG chains so that we can optimizeBranches and alignBlocks.
@@ -3630,7 +3628,7 @@ void MachineBlockPlacement::applyExtTsp(bool OptForSize) {
   std::vector<uint64_t> BlockSizes(F->size());
   std::vector<codelayout::EdgeCount> JumpCounts;
   SmallVector<MachineOperand, 4> Cond; // For analyzeBranch.
-  SmallVector<const MachineBasicBlock *, 4> Succs;  
+  SmallVector<const MachineBasicBlock *, 4> Succs;
   for (MachineBasicBlock &MBB : *F) {
     // Getting the block frequency.
     BlockFrequency BlockFreq = MBFI->getBlockFreq(&MBB);
@@ -3646,7 +3644,7 @@ void MachineBlockPlacement::applyExtTsp(bool OptForSize) {
     size_t NumInsts = std::distance(NonDbgInsts.begin(), NonDbgInsts.end());
     BlockSizes[BlockIndex[&MBB]] = 4 * NumInsts;
     // Getting jump frequencies.
-	
+
     if (!OptForSize) {
       for (MachineBasicBlock *Succ : MBB.successors()) {
         auto EP = MBPI->getEdgeProbability(&MBB, Succ);
@@ -3677,15 +3675,15 @@ void MachineBlockPlacement::applyExtTsp(bool OptForSize) {
         JumpCounts.push_back({BlockIndex[&MBB], BlockIndex[Succ], Freq});
       }
     }
-  }    
+  }
 
   LLVM_DEBUG(dbgs() << "Applying ext-tsp layout for |V| = " << F->size()
                     << " with profile = " << F->getFunction().hasProfileData()
                     << " (" << F->getName().str() << ")"
                     << "\n");
-	
+
   const double OrgScore = calcExtTspScore(BlockSizes, BlockCounts, JumpCounts);
-  LLVM_DEBUG(dbgs() << format("  original  layout score: %0.2f\n", OrgScore));                    
+  LLVM_DEBUG(dbgs() << format("  original  layout score: %0.2f\n", OrgScore));
 
   // Run the layout algorithm.
   auto NewOrder = computeExtTspLayout(BlockSizes, BlockCounts, JumpCounts);
@@ -3696,7 +3694,7 @@ void MachineBlockPlacement::applyExtTsp(bool OptForSize) {
   }
   const double OptScore =
       calcExtTspScore(NewOrder, BlockSizes, BlockCounts, JumpCounts);
-  LLVM_DEBUG(dbgs() << format("  optimized layout score: %0.2f\n", OptScore));  
+  LLVM_DEBUG(dbgs() << format("  optimized layout score: %0.2f\n", OptScore));
 
   // If the optimization is unsuccessful, fall back to the original block order.
   if (OptForSize && OrgScore > OptScore)

``````````

</details>


https://github.com/llvm/llvm-project/pull/109711


More information about the llvm-commits mailing list