1 //===-- LiveRangeUtils.h - Live Range modification utilities ----*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 /// This file contains helper functions to modify live ranges.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_LIB_CODEGEN_LIVERANGEUTILS_H
14 #define LLVM_LIB_CODEGEN_LIVERANGEUTILS_H
16 #include "llvm/CodeGen/LiveInterval.h"
20 /// Helper function that distributes live range value numbers and the
21 /// corresponding segments of a master live range \p LR to a list of newly
22 /// created live ranges \p SplitLRs. \p VNIClasses maps each value number in \p
23 /// LR to 0 meaning it should stay or to 1..N meaning it should go to a specific
24 /// live range in the \p SplitLRs array.
25 template<typename LiveRangeT
, typename EqClassesT
>
26 static void DistributeRange(LiveRangeT
&LR
, LiveRangeT
*SplitLRs
[],
27 EqClassesT VNIClasses
) {
28 // Move segments to new intervals.
29 typename
LiveRangeT::iterator J
= LR
.begin(), E
= LR
.end();
30 while (J
!= E
&& VNIClasses
[J
->valno
->id
] == 0)
32 for (typename
LiveRangeT::iterator I
= J
; I
!= E
; ++I
) {
33 if (unsigned eq
= VNIClasses
[I
->valno
->id
]) {
34 assert((SplitLRs
[eq
-1]->empty() || SplitLRs
[eq
-1]->expiredAt(I
->start
)) &&
35 "New intervals should be empty");
36 SplitLRs
[eq
-1]->segments
.push_back(*I
);
40 LR
.segments
.erase(J
, E
);
42 // Transfer VNInfos to their new owners and renumber them.
43 unsigned j
= 0, e
= LR
.getNumValNums();
44 while (j
!= e
&& VNIClasses
[j
] == 0)
46 for (unsigned i
= j
; i
!= e
; ++i
) {
47 VNInfo
*VNI
= LR
.getValNumInfo(i
);
48 if (unsigned eq
= VNIClasses
[i
]) {
49 VNI
->id
= SplitLRs
[eq
-1]->getNumValNums();
50 SplitLRs
[eq
-1]->valnos
.push_back(VNI
);
59 } // End llvm namespace