[llvm] Move SI Lower Control Flow Up (PR #159557)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 18 10:19:35 PDT 2025


================
@@ -0,0 +1,249 @@
+#pragma once
+
+#include "GCNSubtarget.h"
+#include "MCTargetDesc/AMDGPUMCTargetDesc.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/CodeGen/MachineBasicBlock.h"
+#include "llvm/CodeGen/MachineInstr.h"
+#include "llvm/Support/ErrorHandling.h"
+
+#include "SIInstrInfo.h"
+
+#include <cassert>
+#include <unordered_set>
+
+using namespace llvm;
+
+using std::unordered_set;
+using std::vector;
+
+static inline MachineInstr &get_branch_with_dest(MachineBasicBlock &branching_MBB,
+                                                 MachineBasicBlock &dest_MBB) {
+  auto& TII = *branching_MBB.getParent()->getSubtarget<GCNSubtarget>().getInstrInfo();
+  for (MachineInstr &branch_MI : reverse(branching_MBB.instrs()))
+    if (branch_MI.isBranch() && TII.getBranchDestBlock(branch_MI) == &dest_MBB)
+      return branch_MI;
+
+  llvm_unreachable("Don't call this if there's no branch to the destination.");
+}
+
+static inline void move_ins_before_phis(MachineInstr &MI) {
+  MachineBasicBlock& MBB = *MI.getParent();
+  MachineFunction& MF = *MBB.getParent();
+  auto &TII = *MF.getSubtarget<GCNSubtarget>().getInstrInfo();
+  auto& MRI = MF.getRegInfo();
+
+  bool phi_seen = false;
+  MachineBasicBlock::iterator first_phi;
+  for (first_phi = MBB.begin(); first_phi != MBB.end(); first_phi++)
----------------
alex-t wrote:

`bool phi_seen = !MBB.phis().empty() ?`

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


More information about the llvm-commits mailing list