Detect and enumerate bypass loops.
authorJakob Stoklund Olesen <stoklund@2pi.dk>
Wed, 15 Dec 2010 17:49:52 +0000 (17:49 +0000)
committerJakob Stoklund Olesen <stoklund@2pi.dk>
Wed, 15 Dec 2010 17:49:52 +0000 (17:49 +0000)
Bypass loops have the current live range live through, but contain no uses or
defs. Splitting around a bypass loop can free registers for other uses inside
the loop by spilling the split range.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121871 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/SplitKit.cpp
lib/CodeGen/SplitKit.h

index fd18729b85b6479a25df42e5d94a1f246a042d71..e14251ee3d1ae89da3445277992b770fcfe7e132 100644 (file)
@@ -325,6 +325,36 @@ const MachineLoop *SplitAnalysis::getBestSplitLoop() {
   return Best;
 }
 
+/// isBypassLoop - Return true if curli is live through Loop and has no uses
+/// inside the loop. Bypass loops are candidates for splitting because it can
+/// prevent interference inside the loop.
+bool SplitAnalysis::isBypassLoop(const MachineLoop *Loop) {
+  // If curli is live into the loop header and there are no uses in the loop, it
+  // must be live in the entire loop and live on at least one exiting edge.
+  return !usingLoops_.count(Loop) &&
+         lis_.isLiveInToMBB(*curli_, Loop->getHeader());
+}
+
+/// getBypassLoops - Get all the maximal bypass loops. These are the bypass
+/// loops whose parent is not a bypass loop.
+void SplitAnalysis::getBypassLoops(LoopPtrSet &BypassLoops) {
+  SmallVector<MachineLoop*, 8> Todo(loops_.begin(), loops_.end());
+  while (!Todo.empty) {
+    MachineLoop *Loop = Todo.pop_back_val();
+    if (!usingLoops_.count(Loop)) {
+      // This is either a bypass loop or completely irrelevant.
+      if (lis_.isLiveInToMBB(*curli_, Loop->getHeader()))
+        BypassLoops.insert(Loop);
+      // Either way, skip the child loops.
+      continue;
+    }
+
+    // The child loops may be bypass loops.
+    Todo.append(Loop->begin(), Loop->end());
+  }
+}
+
+
 //===----------------------------------------------------------------------===//
 //                               LiveIntervalMap
 //===----------------------------------------------------------------------===//
index f290eb646101b2ede3525d745d2095edf29feb73..0930b3974cdbd87ee195dac5e5e244602a92949b 100644 (file)
@@ -141,6 +141,15 @@ public:
   /// separate register, or NULL.
   const MachineLoop *getBestSplitLoop();
 
+  /// isBypassLoop - Return true if curli is live through Loop and has no uses
+  /// inside the loop. Bypass loops are candidates for splitting because it can
+  /// prevent interference inside the loop.
+  bool isBypassLoop(const MachineLoop *Loop);
+
+  /// getBypassLoops - Get all the maximal bypass loops. These are the bypass
+  /// loops whose parent is not a bypass loop.
+  void getBypassLoops(LoopPtrSet&);
+
   /// getMultiUseBlocks - Add basic blocks to Blocks that may benefit from
   /// having curli split to a new live interval. Return true if Blocks can be
   /// passed to SplitEditor::splitSingleBlocks.