[CodeGen] Support (and default to) expanding READCYCLECOUNTER to 0.
[oota-llvm.git] / lib / CodeGen / LiveRangeCalc.h
index fd494797918053983e852d7d7fa006316d15a6f8..34d99534834be6cfc4e7e7b79ac5ad3f879bb7d0 100644 (file)
@@ -47,44 +47,30 @@ class LiveRangeCalc {
   /// LiveOutMap - Map basic blocks to the value leaving the block.
   typedef IndexedMap<LiveOutPair, MBB2NumberFunctor> LiveOutMap;
 
-  struct LiveOutData {
-    /// Seen - Bit vector of active entries in LiveOut, also used as a visited
-    /// set by findReachingDefs.  One entry per basic block, indexed by block
-    /// number.  This is kept as a separate bit vector because it can be cleared
-    /// quickly when switching live ranges.
-    BitVector Seen;
-
-    /// LiveOut - Map each basic block where a live range is live out to the
-    /// live-out value and its defining block.
-    ///
-    /// For every basic block, MBB, one of these conditions shall be true:
-    ///
-    ///  1. !Seen.count(MBB->getNumber())
-    ///     Blocks without a Seen bit are ignored.
-    ///  2. LiveOut[MBB].second.getNode() == MBB
-    ///     The live-out value is defined in MBB.
-    ///  3. forall P in preds(MBB): LiveOut[P] == LiveOut[MBB]
-    ///     The live-out value passses through MBB. All predecessors must carry
-    ///     the same value.
-    ///
-    /// The domtree node may be null, it can be computed.
-    ///
-    /// The map can be shared by multiple live ranges as long as no two are
-    /// live-out of the same block.
-    LiveOutMap Map;
-
-    void reset(unsigned NumBlocks) {
-      Seen.clear();
-      Seen.resize(NumBlocks);
-      Map.resize(NumBlocks);
-    }
-
-    void setLiveOutValue(MachineBasicBlock *MBB, VNInfo *VNI) {
-      Seen.set(MBB->getNumber());
-      Map[MBB] = LiveOutPair(VNI, nullptr);
-    }
-  };
-  LiveOutData MainLiveOutData;
+  /// Bit vector of active entries in LiveOut, also used as a visited set by
+  /// findReachingDefs.  One entry per basic block, indexed by block number.
+  /// This is kept as a separate bit vector because it can be cleared quickly
+  /// when switching live ranges.
+  BitVector Seen;
+
+  /// Map each basic block where a live range is live out to the live-out value
+  /// and its defining block.
+  ///
+  /// For every basic block, MBB, one of these conditions shall be true:
+  ///
+  ///  1. !Seen.count(MBB->getNumber())
+  ///     Blocks without a Seen bit are ignored.
+  ///  2. LiveOut[MBB].second.getNode() == MBB
+  ///     The live-out value is defined in MBB.
+  ///  3. forall P in preds(MBB): LiveOut[P] == LiveOut[MBB]
+  ///     The live-out value passses through MBB. All predecessors must carry
+  ///     the same value.
+  ///
+  /// The domtree node may be null, it can be computed.
+  ///
+  /// The map can be shared by multiple live ranges as long as no two are
+  /// live-out of the same block.
+  LiveOutMap Map;
 
   /// LiveInBlock - Information about a basic block where a live range is known
   /// to be live-in, but the value has not yet been determined.
@@ -115,30 +101,38 @@ class LiveRangeCalc {
   /// used to add entries directly.
   SmallVector<LiveInBlock, 16> LiveIn;
 
-  /// Assuming that LI is live-in to KillMBB and killed at Kill, find the set
-  /// of defs that can reach it.
+  /// Assuming that @p LR is live-in to @p UseMBB, find the set of defs that can
+  /// reach it.
   ///
-  /// If only one def can reach Kill, all paths from the def to kill are added
-  /// to LI, and the function returns true.
+  /// If only one def can reach @p UseMBB, all paths from the def to @p UseMBB
+  /// are added to @p LR, and the function returns true.
   ///
-  /// If multiple values can reach Kill, the blocks that need LI to be live in
-  /// are added to the LiveIn array, and the function returns false.
+  /// If multiple values can reach @p UseMBB, the blocks that need @p LR to be
+  /// live in are added to the LiveIn array, and the function returns false.
   ///
   /// PhysReg, when set, is used to verify live-in lists on basic blocks.
-  bool findReachingDefs(LiveRange &LR, MachineBasicBlock &KillMBB,
-                        SlotIndex Kill, unsigned PhysReg,
-                        LiveOutData &LiveOuts);
+  bool findReachingDefs(LiveRange &LR, MachineBasicBlock &UseMBB,
+                        SlotIndex Kill, unsigned PhysReg);
 
   /// updateSSA - Compute the values that will be live in to all requested
   /// blocks in LiveIn.  Create PHI-def values as required to preserve SSA form.
   ///
   /// Every live-in block must be jointly dominated by the added live-out
   /// blocks.  No values are read from the live ranges.
-  void updateSSA(LiveOutData &LiveOuts);
+  void updateSSA();
 
   /// Transfer information from the LiveIn vector to the live ranges and update
   /// the given @p LiveOuts.
-  void updateFromLiveIns(LiveOutData &LiveOuts);
+  void updateFromLiveIns();
+
+  /// Extend the live range of @p LR to reach all uses of Reg.
+  ///
+  /// All uses must be jointly dominated by existing liveness.  PHI-defs are
+  /// inserted as needed to preserve SSA form.
+  void extendToUses(LiveRange &LR, unsigned Reg, unsigned LaneMask);
+
+  /// Reset Map and Seen fields.
+  void resetLiveOutMap();
 
 public:
   LiveRangeCalc() : MF(nullptr), MRI(nullptr), Indexes(nullptr),
@@ -168,47 +162,32 @@ public:
   // Modify existing live ranges.
   //
 
-  /// extend - Extend the live range of LI to reach Kill.
+  /// Extend the live range of @p LR to reach @p Use.
   ///
-  /// The existing values in LI must be live so they jointly dominate Kill.  If
-  /// Kill is not dominated by a single existing value, PHI-defs are inserted
-  /// as required to preserve SSA form.  If Kill is known to be dominated by a
-  /// single existing value, Alloc may be null.
+  /// The existing values in @p LR must be live so they jointly dominate @p Use.
+  /// If @p Use is not dominated by a single existing value, PHI-defs are
+  /// inserted as required to preserve SSA form.
   ///
   /// PhysReg, when set, is used to verify live-in lists on basic blocks.
-  void extend(LiveRange &LR, SlotIndex Kill, unsigned PhysReg,
-              LiveOutData &LiveOuts);
-
-  void extend(LiveRange &LR, SlotIndex Kill) {
-    extend(LR, Kill, 0, MainLiveOutData);
-  }
+  void extend(LiveRange &LR, SlotIndex Use, unsigned PhysReg = 0);
 
   /// createDeadDefs - Create a dead def in LI for every def operand of Reg.
   /// Each instruction defining Reg gets a new VNInfo with a corresponding
   /// minimal live range.
   void createDeadDefs(LiveRange &LR, unsigned Reg);
 
-  /// Subregister aware version of createDeadDefs(LiveRange &LR, unsigned Reg).
-  /// If subregister liveness tracking is enabled new subranges are created as
-  /// necessary when subregister defs are found. As with
-  /// createDeadDefs(LiveRange &LR, unsigned Reg) new short live segments are
-  /// created for every def of LI.reg. The new segments start and end at the
-  /// defining instruction (hence the name "DeadDef").
-  void createDeadDefs(LiveInterval &LI);
-
-  /// extendToUses - Extend the live range of LI to reach all uses of Reg.
+  /// Extend the live range of @p LR to reach all uses of Reg.
   ///
   /// All uses must be jointly dominated by existing liveness.  PHI-defs are
   /// inserted as needed to preserve SSA form.
-  void extendToUses(LiveRange &LR, unsigned Reg);
+  void extendToUses(LiveRange &LR, unsigned PhysReg) {
+    extendToUses(LR, PhysReg, ~0u);
+  }
 
-  /// Subregister aware version of extendToUses(LiveRange &LR, unsigned Reg).
-  /// If subregister liveness tracking is enabled new subranges are created
-  /// as necessary when subregister uses are found. As with
-  /// extendToUses(LiveRange &LR, unsigned Reg) the segments existing at the
-  /// defs are extend until they reach all uses. New value numbers are created
-  /// at CFG joins as necessary (SSA construction).
-  void extendToUses(LiveInterval &LI);
+  /// Calculates liveness for the register specified in live interval @p LI.
+  /// Creates subregister live ranges as needed if subreg liveness tracking is
+  /// enabled.
+  void calculate(LiveInterval &LI, bool TrackSubRegs);
 
   //===--------------------------------------------------------------------===//
   // Low-level interface.
@@ -230,7 +209,8 @@ public:
   /// VNI may be null only if MBB is a live-through block also passed to
   /// addLiveInBlock().
   void setLiveOutValue(MachineBasicBlock *MBB, VNInfo *VNI) {
-    MainLiveOutData.setLiveOutValue(MBB, VNI);
+    Seen.set(MBB->getNumber());
+    Map[MBB] = LiveOutPair(VNI, nullptr);
   }
 
   /// addLiveInBlock - Add a block with an unknown live-in value.  This
@@ -255,11 +235,7 @@ public:
   ///
   /// Every predecessor of a live-in block must have been given a value with
   /// setLiveOutValue, the value may be null for live-trough blocks.
-  void calculateValues(LiveOutData &LiveOuts);
-
-  void calculateValues() {
-    calculateValues(MainLiveOutData);
-  }
+  void calculateValues();
 };
 
 } // end namespace llvm