• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- LiveRangeUtils.h - Live Range modification utilities ----*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 /// This file contains helper functions to modify live ranges.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_LIB_CODEGEN_LIVERANGEUTILS_H
15 #define LLVM_LIB_CODEGEN_LIVERANGEUTILS_H
16 
17 #include "llvm/CodeGen/LiveInterval.h"
18 
19 namespace llvm {
20 
21 /// Helper function that distributes live range value numbers and the
22 /// corresponding segments of a master live range \p LR to a list of newly
23 /// created live ranges \p SplitLRs. \p VNIClasses maps each value number in \p
24 /// LR to 0 meaning it should stay or to 1..N meaning it should go to a specific
25 /// live range in the \p SplitLRs array.
26 template<typename LiveRangeT, typename EqClassesT>
DistributeRange(LiveRangeT & LR,LiveRangeT * SplitLRs[],EqClassesT VNIClasses)27 static void DistributeRange(LiveRangeT &LR, LiveRangeT *SplitLRs[],
28                             EqClassesT VNIClasses) {
29   // Move segments to new intervals.
30   typename LiveRangeT::iterator J = LR.begin(), E = LR.end();
31   while (J != E && VNIClasses[J->valno->id] == 0)
32     ++J;
33   for (typename LiveRangeT::iterator I = J; I != E; ++I) {
34     if (unsigned eq = VNIClasses[I->valno->id]) {
35       assert((SplitLRs[eq-1]->empty() || SplitLRs[eq-1]->expiredAt(I->start)) &&
36              "New intervals should be empty");
37       SplitLRs[eq-1]->segments.push_back(*I);
38     } else
39       *J++ = *I;
40   }
41   LR.segments.erase(J, E);
42 
43   // Transfer VNInfos to their new owners and renumber them.
44   unsigned j = 0, e = LR.getNumValNums();
45   while (j != e && VNIClasses[j] == 0)
46     ++j;
47   for (unsigned i = j; i != e; ++i) {
48     VNInfo *VNI = LR.getValNumInfo(i);
49     if (unsigned eq = VNIClasses[i]) {
50       VNI->id = SplitLRs[eq-1]->getNumValNums();
51       SplitLRs[eq-1]->valnos.push_back(VNI);
52     } else {
53       VNI->id = j;
54       LR.valnos[j++] = VNI;
55     }
56   }
57   LR.valnos.resize(j);
58 }
59 
60 } // End llvm namespace
61 
62 #endif
63