[x86] fix assert with horizontal math + broadcast of vector (PR43402)
[llvm-core.git] / lib / CodeGen / LiveRangeUtils.h
blob0e6bfeb0d4a59eb7fff3bf2c5d99c5a81cecf7dd
1 //===-- LiveRangeUtils.h - Live Range modification utilities ----*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
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"
18 namespace llvm {
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)
31 ++J;
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);
37 } else
38 *J++ = *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)
45 ++j;
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);
51 } else {
52 VNI->id = j;
53 LR.valnos[j++] = VNI;
56 LR.valnos.resize(j);
59 } // End llvm namespace
61 #endif