[llvm] [MachineVerifier] Query TargetInstrInfo for PHI nodes. (PR #110507)

Nathan Gauër via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 30 09:31:52 PDT 2024


================
@@ -2278,6 +2278,32 @@ class TargetInstrInfo : public MCInstrInfo {
     llvm_unreachable("unknown number of operands necessary");
   }
 
+  // This this instruction a PHI node.
+  // This function should be favored over MI.isPHI() as it allows backends to
+  // define additional PHI instructions.
+  virtual bool isPhiInstr(const MachineInstr &MI) const {
+    return MI.getOpcode() == TargetOpcode::G_PHI ||
+           MI.getOpcode() == TargetOpcode::PHI;
+  }
+
+  // Returns the number of [Value, Src] pairs this phi instruction has.
+  // Only valid to call on a phi node.
+  virtual unsigned getNumPhiIncomingPair(const MachineInstr &MI) const {
+    assert(isPhiInstr(MI));
+    // G_PHI/PHI only have a single operand before the pairs. 2 Operands per
+    // pair.
+    return (MI.getNumOperands() - 1) / 2;
+  }
+
+  // Returns the |index|'th [Value, Src] pair of this phi instruction.
+  virtual std::pair<MachineOperand, MachineBasicBlock *>
+  getPhiIncomingPair(const MachineInstr &MI, unsigned index) const {
+    // Behavior for G_PHI/PHI instructions.
+    MachineOperand Operand = MI.getOperand(index * 2 + 1);
+    MachineBasicBlock *MBB = MI.getOperand(index * 2 + 2).getMBB();
+    return {Operand, MBB};
+  }
----------------
Keenuts wrote:

> I don't think the special case SPIRV operator should be treated like a generic phi like this (at least, not in any actual codegen uses).

Why that? It's also a PHI node, exact same behavior & requirements (beginning of a BB, 1 pair by predecessor, only labels as predecessor argument, etc)



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


More information about the llvm-commits mailing list