[llvm] [CodeGen] Extract copy-paste on PHI MachineInstr income removal. (PR #158634)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 18 05:22:38 PDT 2025


================
@@ -0,0 +1,28 @@
+//===- llvm/CodeGen/MachineInstr.h - MachineInstr class ---------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CODEGEN_MACHINEINSTRUTILS_H
+#define LLVM_CODEGEN_MACHINEINSTRUTILS_H
+
+namespace llvm {
+class MachineBasicBlock;
+class MachineInstr;
+
+/// Remove all incoming values of Phi instruction for the given block.
+///
+/// Return deleted operands count.
+///
+/// Function does not erase PHI instruction itself if its operands list is empty
+/// after deletion and does not replace PHI with COPY if it will have only
+/// single input. It is a caller responsibility.
+unsigned removePHIIncomingValueForMBB(MachineInstr &Phi,
+                                      const MachineBasicBlock &MBB);
----------------
arsenm wrote:

You could also just put this directly into MachineInstr (or alternatively, into MachineBasicBlock and have it handle all phis in the block) 

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


More information about the llvm-commits mailing list