AllocationOrder.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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::create(unsigned VirtReg, const VirtRegMap &VRM,
  26. const RegisterClassInfo &RegClassInfo,
  27. const LiveRegMatrix *Matrix) {
  28. const MachineFunction &MF = VRM.getMachineFunction();
  29. const TargetRegisterInfo *TRI = &VRM.getTargetRegInfo();
  30. auto Order = RegClassInfo.getOrder(MF.getRegInfo().getRegClass(VirtReg));
  31. SmallVector<MCPhysReg, 16> Hints;
  32. bool HardHints =
  33. TRI->getRegAllocationHints(VirtReg, Order, Hints, MF, &VRM, Matrix);
  34. LLVM_DEBUG({
  35. if (!Hints.empty()) {
  36. dbgs() << "hints:";
  37. for (unsigned I = 0, E = Hints.size(); I != E; ++I)
  38. dbgs() << ' ' << printReg(Hints[I], TRI);
  39. dbgs() << '\n';
  40. }
  41. });
  42. #ifndef NDEBUG
  43. for (unsigned I = 0, E = Hints.size(); I != E; ++I)
  44. assert(is_contained(Order, Hints[I]) &&
  45. "Target hint is outside allocation order.");
  46. #endif
  47. return AllocationOrder(std::move(Hints), Order, HardHints);
  48. }