1 //===-- LiveRangeUtils.h - Live Range modification utilities ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 /// This file contains helper functions to modify live ranges.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_CODEGEN_LIVERANGEUTILS_H
15 #define LLVM_LIB_CODEGEN_LIVERANGEUTILS_H
17 #include "llvm/CodeGen/LiveInterval.h"
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
>
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)
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
);
41 LR
.segments
.erase(J
, E
);
43 // Transfer VNInfos to their new owners and renumber them.
44 unsigned j
= 0, e
= LR
.getNumValNums();
45 while (j
!= e
&& VNIClasses
[j
] == 0)
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
);
60 } // End llvm namespace