[PATCH] D115171: code size reduction using ext-tsp block placement

Sergey Pupyrev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 6 11:19:43 PST 2021


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

[this is an experimental diff]


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115171

Files:
  llvm/lib/CodeGen/MachineBlockPlacement.cpp


Index: llvm/lib/CodeGen/MachineBlockPlacement.cpp
===================================================================
--- llvm/lib/CodeGen/MachineBlockPlacement.cpp
+++ llvm/lib/CodeGen/MachineBlockPlacement.cpp
@@ -3454,13 +3454,19 @@
     CurrentBlockOrder.push_back(&MBB);
   }
 
+  bool OptForSize = F->getFunction().hasOptSize() ||
+                    llvm::shouldOptimizeForSize(F, PSI, &MBFI->getMBFI());
+
   auto BlockSizes = std::vector<uint64_t>(F->size());
   auto BlockCounts = std::vector<uint64_t>(F->size());
   DenseMap<std::pair<uint64_t, uint64_t>, uint64_t> JumpCounts;
   for (MachineBasicBlock &MBB : *F) {
     // Getting the block frequency.
     BlockFrequency BlockFreq = MBFI->getBlockFreq(&MBB);
-    BlockCounts[BlockIndex[&MBB]] = BlockFreq.getFrequency();
+    if (!OptForSize)
+      BlockCounts[BlockIndex[&MBB]] = BlockFreq.getFrequency();
+    else
+      BlockCounts[BlockIndex[&MBB]] = MBB.pred_size();
     // Getting the block size:
     // - approximate the size of an instruction by 4 bytes, and
     // - ignore debug instructions.
@@ -3476,7 +3482,10 @@
       auto EP = MBPI->getEdgeProbability(&MBB, Succ);
       BlockFrequency EdgeFreq = BlockFreq * EP;
       auto Edge = std::make_pair(BlockIndex[&MBB], BlockIndex[Succ]);
-      JumpCounts[Edge] = EdgeFreq.getFrequency();
+      if (!OptForSize)
+        JumpCounts[Edge] = EdgeFreq.getFrequency();
+      else
+        JumpCounts[Edge] = MBB.succ_size() == 1 ? 100 : 1;
     }
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115171.392134.patch
Type: text/x-patch
Size: 1487 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211206/136149a0/attachment.bin>


More information about the llvm-commits mailing list