LiveRangeUtils.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. /// \file
  9. /// This file contains helper functions to modify live ranges.
  10. ///
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_LIB_CODEGEN_LIVERANGEUTILS_H
  13. #define LLVM_LIB_CODEGEN_LIVERANGEUTILS_H
  14. #include "llvm/CodeGen/LiveInterval.h"
  15. namespace llvm {
  16. /// Helper function that distributes live range value numbers and the
  17. /// corresponding segments of a primary live range \p LR to a list of newly
  18. /// created live ranges \p SplitLRs. \p VNIClasses maps each value number in \p
  19. /// LR to 0 meaning it should stay or to 1..N meaning it should go to a specific
  20. /// live range in the \p SplitLRs array.
  21. template<typename LiveRangeT, typename EqClassesT>
  22. static void DistributeRange(LiveRangeT &LR, LiveRangeT *SplitLRs[],
  23. EqClassesT VNIClasses) {
  24. // Move segments to new intervals.
  25. typename LiveRangeT::iterator J = LR.begin(), E = LR.end();
  26. while (J != E && VNIClasses[J->valno->id] == 0)
  27. ++J;
  28. for (typename LiveRangeT::iterator I = J; I != E; ++I) {
  29. if (unsigned eq = VNIClasses[I->valno->id]) {
  30. assert((SplitLRs[eq-1]->empty() || SplitLRs[eq-1]->expiredAt(I->start)) &&
  31. "New intervals should be empty");
  32. SplitLRs[eq-1]->segments.push_back(*I);
  33. } else
  34. *J++ = *I;
  35. }
  36. LR.segments.erase(J, E);
  37. // Transfer VNInfos to their new owners and renumber them.
  38. unsigned j = 0, e = LR.getNumValNums();
  39. while (j != e && VNIClasses[j] == 0)
  40. ++j;
  41. for (unsigned i = j; i != e; ++i) {
  42. VNInfo *VNI = LR.getValNumInfo(i);
  43. if (unsigned eq = VNIClasses[i]) {
  44. VNI->id = SplitLRs[eq-1]->getNumValNums();
  45. SplitLRs[eq-1]->valnos.push_back(VNI);
  46. } else {
  47. VNI->id = j;
  48. LR.valnos[j++] = VNI;
  49. }
  50. }
  51. LR.valnos.resize(j);
  52. }
  53. } // End llvm namespace
  54. #endif