]> granicus.if.org Git - llvm/commitdiff
[GlobalISel] Move isTriviallyDead to Utils. NFC.
authorVolkan Keles <vkeles@apple.com>
Tue, 21 Mar 2017 10:47:35 +0000 (10:47 +0000)
committerVolkan Keles <vkeles@apple.com>
Tue, 21 Mar 2017 10:47:35 +0000 (10:47 +0000)
Make it accessible by the targets to avoid code duplication.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298358 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/GlobalISel/Utils.h
lib/CodeGen/GlobalISel/InstructionSelect.cpp
lib/CodeGen/GlobalISel/Utils.cpp

index c4389632d48c81e0d155e15ac0c41660b802871c..52bf965a3cb3f953e4a27783ce388e59f208b083 100644 (file)
@@ -45,6 +45,10 @@ unsigned constrainOperandRegClass(const MachineFunction &MF,
                                   MachineInstr &InsertPt, const MCInstrDesc &II,
                                   unsigned Reg, unsigned OpIdx);
 
+/// Check whether an instruction \p MI is dead: it only defines dead virtual
+/// registers, and doesn't have other side effects.
+bool isTriviallyDead(const MachineInstr &MI, const MachineRegisterInfo &MRI);
+
 /// Report an ISel error as a missed optimization remark to the LLVMContext's
 /// diagnostic stream.  Set the FailedISel MachineFunction property.
 void reportGISelFailure(MachineFunction &MF, const TargetPassConfig &TPC,
index c59b200298e33bf1e5db9abfe4ee8d8449493b8e..69ad59ade083a6404999693627bdaf77937cdbad 100644 (file)
@@ -48,29 +48,6 @@ void InstructionSelect::getAnalysisUsage(AnalysisUsage &AU) const {
   MachineFunctionPass::getAnalysisUsage(AU);
 }
 
-/// Check whether an instruction \p MI is dead: it only defines dead virtual
-/// registers, and doesn't have other side effects.
-static bool isTriviallyDead(const MachineInstr &MI,
-                            const MachineRegisterInfo &MRI) {
-  // If we can move an instruction, we can remove it.  Otherwise, it has
-  // a side-effect of some sort.
-  bool SawStore = false;
-  if (!MI.isSafeToMove(/*AA=*/nullptr, SawStore))
-    return false;
-
-  // Instructions without side-effects are dead iff they only define dead vregs.
-  for (auto &MO : MI.operands()) {
-    if (!MO.isReg() || !MO.isDef())
-      continue;
-
-    unsigned Reg = MO.getReg();
-    // Keep Debug uses live: we don't want to have an effect on debug info.
-    if (TargetRegisterInfo::isPhysicalRegister(Reg) || !MRI.use_empty(Reg))
-      return false;
-  }
-  return true;
-}
-
 bool InstructionSelect::runOnMachineFunction(MachineFunction &MF) {
   const MachineRegisterInfo &MRI = MF.getRegInfo();
 
index 282b6789eb438c74610ddb4f7312991ed0d51a63..2e2f519ab2b1203132b952f057dbc344e8aeefa9 100644 (file)
@@ -47,6 +47,27 @@ unsigned llvm::constrainOperandRegClass(
   return Reg;
 }
 
+bool llvm::isTriviallyDead(const MachineInstr &MI,
+                           const MachineRegisterInfo &MRI) {
+  // If we can move an instruction, we can remove it.  Otherwise, it has
+  // a side-effect of some sort.
+  bool SawStore = false;
+  if (!MI.isSafeToMove(/*AA=*/nullptr, SawStore))
+    return false;
+
+  // Instructions without side-effects are dead iff they only define dead vregs.
+  for (auto &MO : MI.operands()) {
+    if (!MO.isReg() || !MO.isDef())
+      continue;
+
+    unsigned Reg = MO.getReg();
+    // Keep Debug uses live: we don't want to have an effect on debug info.
+    if (TargetRegisterInfo::isPhysicalRegister(Reg) || !MRI.use_empty(Reg))
+      return false;
+  }
+  return true;
+}
+
 void llvm::reportGISelFailure(MachineFunction &MF, const TargetPassConfig &TPC,
                               MachineOptimizationRemarkEmitter &MORE,
                               MachineOptimizationRemarkMissed &R) {