LinearScanner hotspot.
[oota-llvm.git] / lib / CodeGen / TwoAddressInstructionPass.cpp
index df632100de6c1d6d9191415503fa2372c6ad3aed..7db9958bc00b6c0440f0dce43896d494ca89062a 100644 (file)
 #include "llvm/Target/TargetInstrInfo.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Support/Debug.h"
+#include "llvm/Support/Compiler.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/ADT/STLExtras.h"
+#include <iostream>
 using namespace llvm;
 
 namespace {
-  Statistic<> NumTwoAddressInstrs("twoaddressinstruction",
+  static Statistic<> NumTwoAddressInstrs("twoaddressinstruction",
                                   "Number of two-address instructions");
-  Statistic<> NumCommuted("twoaddressinstruction",
-                          "Number of instructions commuted to coallesce");
-  Statistic<> NumConvertedTo3Addr("twoaddressinstruction",
+  static Statistic<> NumCommuted("twoaddressinstruction",
+                          "Number of instructions commuted to coalesce");
+  static Statistic<> NumConvertedTo3Addr("twoaddressinstruction",
                                 "Number of instructions promoted to 3-address");
 
-  struct TwoAddressInstructionPass : public MachineFunctionPass {
+  struct VISIBILITY_HIDDEN TwoAddressInstructionPass
+   : public MachineFunctionPass {
     virtual void getAnalysisUsage(AnalysisUsage &AU) const;
 
     /// runOnMachineFunction - pass entry point
     bool runOnMachineFunction(MachineFunction&);
   };
 
-  RegisterPass<TwoAddressInstructionPass> 
+  RegisterPass<TwoAddressInstructionPass>
   X("twoaddressinstruction", "Two-Address instruction pass");
-};
+}
 
 const PassInfo *llvm::TwoAddressInstructionPassID = X.getPassInfo();
 
@@ -127,7 +130,7 @@ bool TwoAddressInstructionPass::runOnMachineFunction(MachineFunction &MF) {
 
         // If this instruction is not the killing user of B, see if we can
         // rearrange the code to make it so.  Making it the killing user will
-        // allow us to coallesce A and B together, eliminating the copy we are
+        // allow us to coalesce A and B together, eliminating the copy we are
         // about to insert.
         if (!LV.KillsRegister(mi, regB)) {
           const TargetInstrDescriptor &TID = TII.get(opcode);
@@ -152,7 +155,7 @@ bool TwoAddressInstructionPass::runOnMachineFunction(MachineFunction &MF) {
                   mbbi->insert(mi, NewMI);           // Insert the new inst
                   mbbi->erase(mi);                   // Nuke the old inst.
                   mi = NewMI;
-                }                  
+                }
 
                 ++NumCommuted;
                 regB = regC;
@@ -161,7 +164,7 @@ bool TwoAddressInstructionPass::runOnMachineFunction(MachineFunction &MF) {
             }
           }
           // If this instruction is potentially convertible to a true
-          // three-address instruction, 
+          // three-address instruction,
           if (TID.Flags & M_CONVERTIBLE_TO_3_ADDR)
             if (MachineInstr *New = TII.convertToThreeAddress(mi)) {
               DEBUG(std::cerr << "2addr: CONVERTING 2-ADDR: " << *mi);
@@ -197,15 +200,14 @@ bool TwoAddressInstructionPass::runOnMachineFunction(MachineFunction &MF) {
 
         // replace all occurences of regB with regA
         for (unsigned i = 1, e = mi->getNumOperands(); i != e; ++i) {
-          if (mi->getOperand(i).isRegister() && 
+          if (mi->getOperand(i).isRegister() &&
               mi->getOperand(i).getReg() == regB)
-            mi->SetMachineOperandReg(i, regA);
+            mi->getOperand(i).setReg(regA);
         }
       }
 
-      assert(mi->getOperand(0).isDef());
-      mi->getOperand(0).setUse();
-      mi->RemoveOperand(1);
+      assert(mi->getOperand(0).isDef() && mi->getOperand(1).isUse());
+      mi->getOperand(1).setReg(mi->getOperand(0).getReg());
       MadeChange = true;
 
       DEBUG(std::cerr << "\t\trewrite to:\t"; mi->print(std::cerr, &TM));