Use MachineBasicBlock::transferSuccessors.
[oota-llvm.git] / include / llvm / CodeGen / LiveVariables.h
index 47b1b20e37037003cc0a45b8ddfccdaddcea207e..efa5f3c869fdd4b17f2e540b9e1e5d2817aeb347 100644 (file)
 
 #include "llvm/CodeGen/MachineFunctionPass.h"
 #include "llvm/ADT/BitVector.h"
+#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/SmallVector.h"
-#include <map>
 
 namespace llvm {
 
+class MachineRegisterInfo;
 class TargetRegisterInfo;
 
 class LiveVariables : public MachineFunctionPass {
@@ -102,13 +103,12 @@ public:
     /// machine instruction. Returns true if there was a kill
     /// corresponding to this instruction, false otherwise.
     bool removeKill(MachineInstr *MI) {
-      for (std::vector<MachineInstr*>::iterator i = Kills.begin(),
-             e = Kills.end(); i != e; ++i)
-        if (*i == MI) {
-          Kills.erase(i);
-          return true;
-        }
-      return false;
+      std::vector<MachineInstr*>::iterator
+        I = std::find(Kills.begin(), Kills.end(), MI);
+      if (I == Kills.end())
+        return false;
+      Kills.erase(I);
+      return true;
     }
     
     void dump() const;
@@ -130,42 +130,43 @@ private:
 private:   // Intermediate data structures
   MachineFunction *MF;
 
-  const TargetRegisterInfo *RegInfo;
-
-  // PhysRegInfo - Keep track of which instruction was the last def/use of a
-  // physical register. This is a purely local property, because all physical
-  // register references as presumed dead across basic blocks.
-  MachineInstr **PhysRegInfo;
+  MachineRegisterInfo* MRI;
 
-  // PhysRegUsed - Keep track whether the physical register has been used after
-  // its last definition. This is local property.
-  bool          *PhysRegUsed;
+  const TargetRegisterInfo *TRI;
 
-  // PhysRegPartUse - Keep track of which instruction was the last partial use
-  // of a physical register (e.g. on X86 a def of EAX followed by a use of AX).
-  // This is a purely local property.
-  MachineInstr **PhysRegPartUse;
+  // PhysRegInfo - Keep track of which instruction was the last def of a
+  // physical register. This is a purely local property, because all physical
+  // register references are presumed dead across basic blocks.
+  MachineInstr **PhysRegDef;
 
-  // PhysRegPartDef - Keep track of a list of instructions which "partially"
-  // defined the physical register (e.g. on X86 AX partially defines EAX).
-  // These are turned into use/mod/write if there is a use of the register
-  // later in the same block. This is local property.
-  SmallVector<MachineInstr*, 4> *PhysRegPartDef;
+  // PhysRegInfo - Keep track of which instruction was the last use of a
+  // physical register. This is a purely local property, because all physical
+  // register references are presumed dead across basic blocks.
+  MachineInstr **PhysRegUse;
 
   SmallVector<unsigned, 4> *PHIVarInfo;
 
-  void addRegisterKills(unsigned Reg, MachineInstr *MI,
-                        SmallSet<unsigned, 4> &SubKills);
+  // DistanceMap - Keep track the distance of a MI from the start of the
+  // current basic block.
+  DenseMap<MachineInstr*, unsigned> DistanceMap;
 
   /// HandlePhysRegKill - Add kills of Reg and its sub-registers to the
   /// uses. Pay special attention to the sub-register uses which may come below
   /// the last use of the whole register.
-  bool HandlePhysRegKill(unsigned Reg, MachineInstr *MI,
-                         SmallSet<unsigned, 4> &SubKills);
-  bool HandlePhysRegKill(unsigned Reg, MachineInstr *MI);
+  bool HandlePhysRegKill(unsigned Reg);
+
   void HandlePhysRegUse(unsigned Reg, MachineInstr *MI);
   void HandlePhysRegDef(unsigned Reg, MachineInstr *MI);
 
+  /// FindLastPartialDef - Return the last partial def of the specified register.
+  /// Also returns the sub-register that's defined.
+  MachineInstr *FindLastPartialDef(unsigned Reg, unsigned &PartDefReg);
+
+  /// hasRegisterUseBelow - Return true if the specified register is used after
+  /// the current instruction and before it's next definition.
+  bool hasRegisterUseBelow(unsigned Reg, MachineBasicBlock::iterator I,
+                           MachineBasicBlock *MBB);
+
   /// analyzePHINodes - Gather information about the PHI nodes in here. In
   /// particular, we want to map the variable information of a virtual
   /// register which is used in a PHI node. We map that to the BB the vreg
@@ -175,18 +176,10 @@ public:
 
   virtual bool runOnMachineFunction(MachineFunction &MF);
 
-  /// KillsRegister - Return true if the specified instruction kills the
-  /// specified register.
-  bool KillsRegister(MachineInstr *MI, unsigned Reg) const;
-  
   /// RegisterDefIsDead - Return true if the specified instruction defines the
   /// specified register, but that definition is dead.
   bool RegisterDefIsDead(MachineInstr *MI, unsigned Reg) const;
 
-  /// ModifiesRegister - Return true if the specified instruction modifies the
-  /// specified register.
-  bool ModifiesRegister(MachineInstr *MI, unsigned Reg) const;
-  
   //===--------------------------------------------------------------------===//
   //  API to update live variable information
 
@@ -202,7 +195,7 @@ public:
   /// not found.
   void addVirtualRegisterKilled(unsigned IncomingReg, MachineInstr *MI,
                                 bool AddIfNotFound = false) {
-    if (MI->addRegisterKilled(IncomingReg, RegInfo, AddIfNotFound))
+    if (MI->addRegisterKilled(IncomingReg, TRI, AddIfNotFound))
       getVarInfo(IncomingReg).Kills.push_back(MI); 
   }
 
@@ -239,7 +232,7 @@ public:
   /// AddIfNotFound is true, add a implicit operand if it's not found.
   void addVirtualRegisterDead(unsigned IncomingReg, MachineInstr *MI,
                               bool AddIfNotFound = false) {
-    if (MI->addRegisterDead(IncomingReg, RegInfo, AddIfNotFound))
+    if (MI->addRegisterDead(IncomingReg, TRI, AddIfNotFound))
         getVarInfo(IncomingReg).Kills.push_back(MI);
   }