Remove Value::getNameLen
[oota-llvm.git] / lib / CodeGen / MachineLICM.cpp
index dd32977f90b6c6f6a8ec9b8ec38664b4a8097339..b69311f9265d4a93b6e03c19e87b83df18621c25 100644 (file)
@@ -33,6 +33,7 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/Debug.h"
+#include "llvm/Support/raw_ostream.h"
 
 using namespace llvm;
 
@@ -288,6 +289,9 @@ static bool HasPHIUses(unsigned Reg, MachineRegisterInfo *RegInfo) {
 /// IsProfitableToHoist - Return true if it is potentially profitable to hoist
 /// the given loop invariant.
 bool MachineLICM::IsProfitableToHoist(MachineInstr &MI) {
+  if (MI.getOpcode() == TargetInstrInfo::IMPLICIT_DEF)
+    return false;
+
   const TargetInstrDesc &TID = MI.getDesc();
 
   // FIXME: For now, only hoist re-materilizable instructions. LICM will
@@ -312,7 +316,8 @@ bool MachineLICM::IsProfitableToHoist(MachineInstr &MI) {
 }
 
 static const MachineInstr *LookForDuplicate(const MachineInstr *MI,
-                                      std::vector<const MachineInstr*> &PrevMIs) {
+                                      std::vector<const MachineInstr*> &PrevMIs,
+                                      MachineRegisterInfo *RegInfo) {
   unsigned NumOps = MI->getNumOperands();
   for (unsigned i = 0, e = PrevMIs.size(); i != e; ++i) {
     const MachineInstr *PrevMI = PrevMIs[i];
@@ -322,8 +327,14 @@ static const MachineInstr *LookForDuplicate(const MachineInstr *MI,
     bool IsSame = true;
     for (unsigned j = 0; j != NumOps; ++j) {
       const MachineOperand &MO = MI->getOperand(j);
-      if (MO.isReg() && MO.isDef()) 
+      if (MO.isReg() && MO.isDef()) {
+        if (RegInfo->getRegClass(MO.getReg()) !=
+            RegInfo->getRegClass(PrevMI->getOperand(j).getReg())) {
+          IsSame = false;
+          break;
+        }
         continue;
+      }
       if (!MO.isIdenticalTo(PrevMI->getOperand(j))) {
         IsSame = false;
         break;
@@ -345,14 +356,14 @@ void MachineLICM::Hoist(MachineInstr &MI) {
   // Now move the instructions to the predecessor, inserting it before any
   // terminator instructions.
   DEBUG({
-      DOUT << "Hoisting " << MI;
+      errs() << "Hoisting " << MI;
       if (CurPreheader->getBasicBlock())
-        DOUT << " to MachineBasicBlock "
-             << CurPreheader->getBasicBlock()->getName();
+        errs() << " to MachineBasicBlock "
+               << CurPreheader->getBasicBlock()->getName();
       if (MI.getParent()->getBasicBlock())
-        DOUT << " from MachineBasicBlock "
-             << MI.getParent()->getBasicBlock()->getName();
-      DOUT << "\n";
+        errs() << " from MachineBasicBlock "
+               << MI.getParent()->getBasicBlock()->getName();
+      errs() << "\n";
     });
 
   // Look for opportunity to CSE the hoisted instruction.
@@ -362,7 +373,7 @@ void MachineLICM::Hoist(MachineInstr &MI) {
     std::vector<const MachineInstr*> >::iterator CI = CSEMap.find(BBOpcPair);
   bool DoneCSE = false;
   if (CI != CSEMap.end()) {
-    const MachineInstr *Dup = LookForDuplicate(&MI, CI->second);
+    const MachineInstr *Dup = LookForDuplicate(&MI, CI->second, RegInfo);
     if (Dup) {
       DOUT << "CSEing " << MI;
       DOUT << " with " << *Dup;