summaryrefslogtreecommitdiff
path: root/lib/CodeGen/SplitKit.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/CodeGen/SplitKit.h')
-rw-r--r--lib/CodeGen/SplitKit.h84
1 files changed, 58 insertions, 26 deletions
diff --git a/lib/CodeGen/SplitKit.h b/lib/CodeGen/SplitKit.h
index 69c65ff3f61d0..a9684942885eb 100644
--- a/lib/CodeGen/SplitKit.h
+++ b/lib/CodeGen/SplitKit.h
@@ -18,6 +18,7 @@
#include "LiveRangeCalc.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/IntervalMap.h"
#include "llvm/ADT/SmallPtrSet.h"
@@ -37,6 +38,40 @@ class VirtRegMap;
class VNInfo;
class raw_ostream;
+/// Determines the latest safe point in a block in which we can insert a split,
+/// spill or other instruction related with CurLI.
+class LLVM_LIBRARY_VISIBILITY InsertPointAnalysis {
+private:
+ const LiveIntervals &LIS;
+
+ /// Last legal insert point in each basic block in the current function.
+ /// The first entry is the first terminator, the second entry is the
+ /// last valid point to insert a split or spill for a variable that is
+ /// live into a landing pad successor.
+ SmallVector<std::pair<SlotIndex, SlotIndex>, 8> LastInsertPoint;
+
+ SlotIndex computeLastInsertPoint(const LiveInterval &CurLI,
+ const MachineBasicBlock &MBB);
+
+public:
+ InsertPointAnalysis(const LiveIntervals &lis, unsigned BBNum);
+
+ /// Return the base index of the last valid insert point for \pCurLI in \pMBB.
+ SlotIndex getLastInsertPoint(const LiveInterval &CurLI,
+ const MachineBasicBlock &MBB) {
+ unsigned Num = MBB.getNumber();
+ // Inline the common simple case.
+ if (LastInsertPoint[Num].first.isValid() &&
+ !LastInsertPoint[Num].second.isValid())
+ return LastInsertPoint[Num].first;
+ return computeLastInsertPoint(CurLI, MBB);
+ }
+
+ /// Returns the last insert point as an iterator for \pCurLI in \pMBB.
+ MachineBasicBlock::iterator getLastInsertPointIter(const LiveInterval &CurLI,
+ MachineBasicBlock &MBB);
+};
+
/// SplitAnalysis - Analyze a LiveInterval, looking for live range splitting
/// opportunities.
class LLVM_LIBRARY_VISIBILITY SplitAnalysis {
@@ -83,15 +118,12 @@ private:
// Current live interval.
const LiveInterval *CurLI;
+ /// Insert Point Analysis.
+ InsertPointAnalysis IPA;
+
// Sorted slot indexes of using instructions.
SmallVector<SlotIndex, 8> UseSlots;
- /// LastSplitPoint - Last legal split point in each basic block in the current
- /// function. The first entry is the first terminator, the second entry is the
- /// last valid split point for a variable that is live in to a landing pad
- /// successor.
- SmallVector<std::pair<SlotIndex, SlotIndex>, 8> LastSplitPoint;
-
/// UseBlocks - Blocks where CurLI has uses.
SmallVector<BlockInfo, 8> UseBlocks;
@@ -108,8 +140,6 @@ private:
/// DidRepairRange - analyze was forced to shrinkToUses().
bool DidRepairRange;
- SlotIndex computeLastSplitPoint(unsigned Num);
-
// Sumarize statistics by counting instructions using CurLI.
void analyzeUses();
@@ -136,19 +166,6 @@ public:
/// getParent - Return the last analyzed interval.
const LiveInterval &getParent() const { return *CurLI; }
- /// getLastSplitPoint - Return the base index of the last valid split point
- /// in the basic block numbered Num.
- SlotIndex getLastSplitPoint(unsigned Num) {
- // Inline the common simple case.
- if (LastSplitPoint[Num].first.isValid() &&
- !LastSplitPoint[Num].second.isValid())
- return LastSplitPoint[Num].first;
- return computeLastSplitPoint(Num);
- }
-
- /// getLastSplitPointIter - Returns the last split point as an iterator.
- MachineBasicBlock::iterator getLastSplitPointIter(MachineBasicBlock*);
-
/// isOriginalEndpoint - Return true if the original live range was killed or
/// (re-)defined at Idx. Idx should be the 'def' slot for a normal kill/def,
/// and 'use' for an early-clobber def.
@@ -194,6 +211,14 @@ public:
/// @param BI The block to be isolated.
/// @param SingleInstrs True when single instructions should be isolated.
bool shouldSplitSingleBlock(const BlockInfo &BI, bool SingleInstrs) const;
+
+ SlotIndex getLastSplitPoint(unsigned Num) {
+ return IPA.getLastInsertPoint(*CurLI, *MF.getBlockNumbered(Num));
+ }
+
+ MachineBasicBlock::iterator getLastSplitPointIter(MachineBasicBlock *BB) {
+ return IPA.getLastInsertPointIter(*CurLI, *BB);
+ }
};
@@ -210,6 +235,7 @@ public:
///
class LLVM_LIBRARY_VISIBILITY SplitEditor {
SplitAnalysis &SA;
+ AliasAnalysis &AA;
LiveIntervals &LIS;
VirtRegMap &VRM;
MachineRegisterInfo &MRI;
@@ -329,9 +355,14 @@ private:
MachineBasicBlock *findShallowDominator(MachineBasicBlock *MBB,
MachineBasicBlock *DefMBB);
- /// hoistCopiesForSize - Hoist back-copies to the complement interval in a
- /// way that minimizes code size. This implements the SM_Size spill mode.
- void hoistCopiesForSize();
+ /// Find out all the backCopies dominated by others.
+ void computeRedundantBackCopies(DenseSet<unsigned> &NotToHoistSet,
+ SmallVectorImpl<VNInfo *> &BackCopies);
+
+ /// Hoist back-copies to the complement interval. It tries to hoist all
+ /// the back-copies to one BB if it is beneficial, or else simply remove
+ /// redundant backcopies dominated by others.
+ void hoistCopies();
/// transferValues - Transfer values to the new ranges.
/// Return true if any ranges were skipped.
@@ -350,8 +381,9 @@ private:
public:
/// Create a new SplitEditor for editing the LiveInterval analyzed by SA.
/// Newly created intervals will be appended to newIntervals.
- SplitEditor(SplitAnalysis &SA, LiveIntervals&, VirtRegMap&,
- MachineDominatorTree&, MachineBlockFrequencyInfo &);
+ SplitEditor(SplitAnalysis &SA, AliasAnalysis &AA, LiveIntervals&,
+ VirtRegMap&, MachineDominatorTree&,
+ MachineBlockFrequencyInfo &);
/// reset - Prepare for a new split.
void reset(LiveRangeEdit&, ComplementSpillMode = SM_Partition);