[llvm-commits] [llvm] r160977 - in /llvm/trunk: include/llvm/CodeGen/MachineInstr.h lib/CodeGen/MachineTraceMetrics.cpp

Jakob Stoklund Olesen stoklund at 2pi.dk
Mon Jul 30 11:34:14 PDT 2012


Author: stoklund
Date: Mon Jul 30 13:34:14 2012
New Revision: 160977

URL: http://llvm.org/viewvc/llvm-project?rev=160977&view=rev
Log:
Add MachineInstr::isTransient().

This is a cleaned up version of the isFree() function in
MachineTraceMetrics.cpp.

Transient instructions are very unlikely to produce any code in the
final output. Either because they get eliminated by RegisterCoalescing,
or because they are pseudo-instructions like labels and debug values.

Modified:
    llvm/trunk/include/llvm/CodeGen/MachineInstr.h
    llvm/trunk/lib/CodeGen/MachineTraceMetrics.cpp

Modified: llvm/trunk/include/llvm/CodeGen/MachineInstr.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineInstr.h?rev=160977&r1=160976&r2=160977&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineInstr.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineInstr.h Mon Jul 30 13:34:14 2012
@@ -635,6 +635,30 @@
       getOperand(0).getSubReg() == getOperand(1).getSubReg();
   }
 
+  /// isTransient - Return true if this is a transient instruction that is
+  /// either very likely to be eliminated during register allocation (such as
+  /// copy-like instructions), or if this instruction doesn't have an
+  /// execution-time cost.
+  bool isTransient() const {
+    switch(getOpcode()) {
+    default: return false;
+    // Copy-like instructions are usually eliminated during register allocation.
+    case TargetOpcode::PHI:
+    case TargetOpcode::COPY:
+    case TargetOpcode::INSERT_SUBREG:
+    case TargetOpcode::SUBREG_TO_REG:
+    case TargetOpcode::REG_SEQUENCE:
+    // Pseudo-instructions that don't produce any real output.
+    case TargetOpcode::IMPLICIT_DEF:
+    case TargetOpcode::KILL:
+    case TargetOpcode::PROLOG_LABEL:
+    case TargetOpcode::EH_LABEL:
+    case TargetOpcode::GC_LABEL:
+    case TargetOpcode::DBG_VALUE:
+      return true;
+    }
+  }
+
   /// getBundleSize - Return the number of instructions inside the MI bundle.
   unsigned getBundleSize() const;
 

Modified: llvm/trunk/lib/CodeGen/MachineTraceMetrics.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineTraceMetrics.cpp?rev=160977&r1=160976&r2=160977&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineTraceMetrics.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineTraceMetrics.cpp Mon Jul 30 13:34:14 2012
@@ -69,28 +69,6 @@
 // The number of instructions in a basic block and the CPU resources used by
 // those instructions don't depend on any given trace strategy.
 
-/// Is MI an instruction that should be considered free because it will likely
-/// be eliminated by later passes?
-static bool isFree(const MachineInstr *MI) {
-  switch(MI->getOpcode()) {
-  default: return false;
-  case TargetOpcode::PHI:
-  case TargetOpcode::PROLOG_LABEL:
-  case TargetOpcode::EH_LABEL:
-  case TargetOpcode::GC_LABEL:
-  case TargetOpcode::KILL:
-  case TargetOpcode::EXTRACT_SUBREG:
-  case TargetOpcode::INSERT_SUBREG:
-  case TargetOpcode::IMPLICIT_DEF:
-  case TargetOpcode::SUBREG_TO_REG:
-  case TargetOpcode::COPY_TO_REGCLASS:
-  case TargetOpcode::DBG_VALUE:
-  case TargetOpcode::REG_SEQUENCE:
-  case TargetOpcode::COPY:
-    return true;
-  }
-}
-
 /// Compute the resource usage in basic block MBB.
 const MachineTraceMetrics::FixedBlockInfo*
 MachineTraceMetrics::getResources(const MachineBasicBlock *MBB) {
@@ -106,7 +84,7 @@
   for (MachineBasicBlock::const_iterator I = MBB->begin(), E = MBB->end();
        I != E; ++I) {
     const MachineInstr *MI = I;
-    if (isFree(MI))
+    if (MI->isTransient())
       continue;
     ++InstrCount;
     if (MI->isCall())





More information about the llvm-commits mailing list