AllocationOrder.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //===-- llvm/CodeGen/AllocationOrder.cpp - Allocation Order ---------------===//
  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 implements an allocation order for virtual registers.
  10. //
  11. // The preferred allocation order for a virtual register depends on allocation
  12. // hints and target hooks. The AllocationOrder class encapsulates all of that.
  13. //
  14. //===----------------------------------------------------------------------===//
  15. #include "AllocationOrder.h"
  16. #include "llvm/CodeGen/MachineFunction.h"
  17. #include "llvm/CodeGen/MachineRegisterInfo.h"
  18. #include "llvm/CodeGen/RegisterClassInfo.h"
  19. #include "llvm/CodeGen/VirtRegMap.h"
  20. #include "llvm/Support/Debug.h"
  21. #include "llvm/Support/raw_ostream.h"
  22. using namespace llvm;
  23. #define DEBUG_TYPE "regalloc"
  24. // Compare VirtRegMap::getRegAllocPref().
  25. AllocationOrder::AllocationOrder(unsigned VirtReg,
  26. const VirtRegMap &VRM,
  27. const RegisterClassInfo &RegClassInfo,
  28. const LiveRegMatrix *Matrix)
  29. : Pos(0), HardHints(false) {
  30. const MachineFunction &MF = VRM.getMachineFunction();
  31. const TargetRegisterInfo *TRI = &VRM.getTargetRegInfo();
  32. Order = RegClassInfo.getOrder(MF.getRegInfo().getRegClass(VirtReg));
  33. if (TRI->getRegAllocationHints(VirtReg, Order, Hints, MF, &VRM, Matrix))
  34. HardHints = true;
  35. rewind();
  36. LLVM_DEBUG({
  37. if (!Hints.empty()) {
  38. dbgs() << "hints:";
  39. for (unsigned I = 0, E = Hints.size(); I != E; ++I)
  40. dbgs() << ' ' << printReg(Hints[I], TRI);
  41. dbgs() << '\n';
  42. }
  43. });
  44. #ifndef NDEBUG
  45. for (unsigned I = 0, E = Hints.size(); I != E; ++I)
  46. assert(is_contained(Order, Hints[I]) &&
  47. "Target hint is outside allocation order.");
  48. #endif
  49. }