[PATCH] D151805: [MBP] Insert target hook to allow targets to decide about MBB movements

Andreu Carminati via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 31 07:27:45 PDT 2023


andcarminati created this revision.
andcarminati added reviewers: Eugene.Zelenko, iteratee.
Herald added subscribers: hiraditya, kristof.beyls.
Herald added a project: All.
andcarminati requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This patch includes a mechanism to give the target the final decision about moving a block up. The rationale behind this is that some targets have hardware low-overhead loop instructions that can benefit from the change, ie,  loop instructions that perform better for backward targets. Some targets, like Arm have a custom block reordering pass to improve the layout, but this change simplifies the approach.


https://reviews.llvm.org/D151805

Files:
  llvm/include/llvm/CodeGen/TargetInstrInfo.h
  llvm/lib/CodeGen/MachineBlockPlacement.cpp


Index: llvm/lib/CodeGen/MachineBlockPlacement.cpp
===================================================================
--- llvm/lib/CodeGen/MachineBlockPlacement.cpp
+++ llvm/lib/CodeGen/MachineBlockPlacement.cpp
@@ -1907,6 +1907,10 @@
 MachineBlockPlacement::canMoveBottomBlockToTop(
     const MachineBasicBlock *BottomBlock,
     const MachineBasicBlock *OldTop) {
+
+  if (!TII->isProfitableToMoveUp(BottomBlock))
+    return false;
+
   if (BottomBlock->pred_size() != 1)
     return true;
   MachineBasicBlock *Pred = *BottomBlock->pred_begin();
Index: llvm/include/llvm/CodeGen/TargetInstrInfo.h
===================================================================
--- llvm/include/llvm/CodeGen/TargetInstrInfo.h
+++ llvm/include/llvm/CodeGen/TargetInstrInfo.h
@@ -612,6 +612,13 @@
     llvm_unreachable("target did not implement");
   }
 
+  /// Analyze a basic block \p Block and its instructions and tell if it
+  /// is profitable to move it up in the final layout of a function. Some
+  /// hardware loop instructions can work better with backward branches.
+  virtual bool isProfitableToMoveUp(const MachineBasicBlock *Block) const {
+    return true;
+  }
+
   /// Analyze the branching code at the end of MBB, returning
   /// true if it cannot be understood (e.g. it's a switch dispatch or isn't
   /// implemented for a target).  Upon success, this returns false and returns


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151805.527023.patch
Type: text/x-patch
Size: 1390 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230531/6f094f3c/attachment.bin>


More information about the llvm-commits mailing list